// Path: src/main/java/redress/abi/generic/AbstractABI.java
// public abstract class AbstractABI implements IStructure {
// 
//     protected AbstractABI(byte[] raw) {
//         this.raw=raw;
//     }
// 
//     public abstract ABIType getType();
//     public abstract ABIArch getArch();
// 
//     protected final byte[] raw;
//     protected final LinkedList<IStructure> children = new LinkedList<>();
//     protected final IStructure parent = null;
//     protected AbstractAddress beginAddress;
//     protected AbstractAddress endAddress;
//     protected final HashSet<String> comment = new HashSet<>();
//     public byte[] getRaw(){return raw;}
// 
//     public AbstractSegment getSegment(String name){
//         for(IStructure s : getChildren()){
//             if(s instanceof AbstractSegment && ((AbstractSegment) s).getName().equals(name)){
//                 return (AbstractSegment)s;
//             }
//         }
//         return null;
//     }
// 
//     @Override
//     public int compareTo(IAddressable o) {
//         if(o == null)
//             return 0;
// 
//         return this.beginAddress.compareTo(o.getBeginAddress());
//     }
// 
//     @Override
//     public void accept(AbstractStructureVisitor visitor) {
//         if(visitor.preVisit())
//             visitor.visit(this);
//         visitor.postVisit();
//         for(IStructure child : getChildren()){
//             child.accept(visitor);
//         }
//     }
// 
//     @Override
//     public IStructure getParent() {
//         return parent;
//     }
// 
//     @Override
//     public LinkedList<IStructure> getChildren() {
//         return children;
//     }
// 
//     @Override
//     public AbstractAddress getBeginAddress() {
//         return beginAddress;
//     }
// 
//     @Override
//     public AbstractAddress getEndAddress() {
//         return endAddress;
//     }
// 
//     @Override
//     public void setBeginAddress(AbstractAddress in){
//         this.beginAddress = in;
//     }
// 
//     @Override
//     public void setEndAddress(AbstractAddress in){
//         this.endAddress = in;
//     }
// 
//     @Override
//     public void addComments(String... comment) {
//         for(String s:comment)
//             this.comment.add(s);
//     }
// 
//     @Override
//     public HashSet<String> getComments() {
//         return comment;
//     }
// }
// 
// Path: src/main/java/redress/abi/mach/parse/Reader.java
// public class Reader {
// 
//     private final static Logger LOGGER = Logger.getLogger(Reader.class.getName());
// 
//     private Reader(){}
// 
//     public static Mach Read(final File in) throws Exception{
// 
//         final FileInputStream fis = new FileInputStream(in);
// 
//         return Read(fis);
//     }
// 
//     public static Mach Read(final InputStream inputStream) throws Exception{
// 
//         LOGGER.log(Level.INFO,"Reading binary");
// 
//         final byte[] binary = IOUtils.toByteArray(inputStream);
// 
//         return getMach(binary);
//     }
// 
//     private static Mach getMach(byte[] binary) throws Exception {
//         final DWord dWordAtAddress = B.getDWordAtAddress(binary, new Address64("0x0000000000000000"), null, AbstractData.Type.DATA_BYTE, ByteOrder.LITTLE_ENDIAN);
// 
//         if(dWordAtAddress == null)
//             return null;
// 
//         Mach ret = null;
// 
//         if(Loader.MH_MAGIC_64.equals(dWordAtAddress) || Loader.MH_CIGAM_64.equals(dWordAtAddress)){
//             ret = new MachO64(binary);
//             MachParser64.parse((MachO64) ret);
//         } else if(Loader.MH_MAGIC.equals(dWordAtAddress) || Loader.MH_CIGAM.equals(dWordAtAddress)){
//             ret = new MachO32(binary);
//             MachParser32.parse((MachO32) ret);
//         }
// 
//         return ret;
//     }
// }


import redress.abi.generic.AbstractABI;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.input.KeyCombination;
import javafx.stage.FileChooser;
import redress.abi.mach.parse.Reader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
    public MenuBarController(MenuBar in){
        this.menuBar=in;

        initFileMenu();
        initEditMenu();
        initWindowMenu();
        initHelpMenu();

        fileMenu.getItems().addAll(openTestMenuItem,openMenuItem,saveMenuItem,preferencesMenuItem,quitMenuItem);
        editMenu.getItems().addAll(deleteMenuItem);
        windowMenu.getItems().addAll(codeWindowMenuItem,leftWindowMenuItem,rightWindowMenuItem);
        helpMenu.getItems().addAll(aboutMenuItem);
        menuBar.getMenus().addAll(fileMenu,editMenu,windowMenu,helpMenu);
    }

    private void initFileMenu(){
        openMenuItem.setAccelerator(KeyCombination.keyCombination(KeyCombination.META_DOWN+"+o"));
        openMenuItem.setOnAction((ae) -> {
            FileChooser fileChooser = new FileChooser();
            fileChooser.setTitle("Open Binary");
            fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
            InputStream resourceAsStream = null;
            try {
                resourceAsStream = new FileInputStream(fileChooser.showOpenDialog(MainController.getSharedMainController().getPrimaryStage()));
            }catch(Exception e){
                LOGGER.log(Level.SEVERE,"Unable to open file: "+e);
            }
            openStream(resourceAsStream);
        });
        openTestMenuItem.setAccelerator(KeyCombination.keyCombination(KeyCombination.META_DOWN+"+"+KeyCombination.SHIFT_ANY+"+o"));
// Path: src/main/java/redress/abi/generic/AbstractABI.java
// public abstract class AbstractABI implements IStructure {
// 
//     protected AbstractABI(byte[] raw) {
//         this.raw=raw;
//     }
// 
//     public abstract ABIType getType();
//     public abstract ABIArch getArch();
// 
//     protected final byte[] raw;
//     protected final LinkedList<IStructure> children = new LinkedList<>();
//     protected final IStructure parent = null;
//     protected AbstractAddress beginAddress;
//     protected AbstractAddress endAddress;
//     protected final HashSet<String> comment = new HashSet<>();
//     public byte[] getRaw(){return raw;}
// 
//     public AbstractSegment getSegment(String name){
//         for(IStructure s : getChildren()){
//             if(s instanceof AbstractSegment && ((AbstractSegment) s).getName().equals(name)){
//                 return (AbstractSegment)s;
//             }
//         }
//         return null;
//     }
// 
//     @Override
//     public int compareTo(IAddressable o) {
//         if(o == null)
//             return 0;
// 
//         return this.beginAddress.compareTo(o.getBeginAddress());
//     }
// 
//     @Override
//     public void accept(AbstractStructureVisitor visitor) {
//         if(visitor.preVisit())
//             visitor.visit(this);
//         visitor.postVisit();
//         for(IStructure child : getChildren()){
//             child.accept(visitor);
//         }
//     }
// 
//     @Override
//     public IStructure getParent() {
//         return parent;
//     }
// 
//     @Override
//     public LinkedList<IStructure> getChildren() {
//         return children;
//     }
// 
//     @Override
//     public AbstractAddress getBeginAddress() {
//         return beginAddress;
//     }
// 
//     @Override
//     public AbstractAddress getEndAddress() {
//         return endAddress;
//     }
// 
//     @Override
//     public void setBeginAddress(AbstractAddress in){
//         this.beginAddress = in;
//     }
// 
//     @Override
//     public void setEndAddress(AbstractAddress in){
//         this.endAddress = in;
//     }
// 
//     @Override
//     public void addComments(String... comment) {
//         for(String s:comment)
//             this.comment.add(s);
//     }
// 
//     @Override
//     public HashSet<String> getComments() {
//         return comment;
//     }
// }
// 
// Path: src/main/java/redress/abi/mach/parse/Reader.java
// public class Reader {
// 
//     private final static Logger LOGGER = Logger.getLogger(Reader.class.getName());
// 
//     private Reader(){}
// 
//     public static Mach Read(final File in) throws Exception{
// 
//         final FileInputStream fis = new FileInputStream(in);
// 
//         return Read(fis);
//     }
// 
//     public static Mach Read(final InputStream inputStream) throws Exception{
// 
//         LOGGER.log(Level.INFO,"Reading binary");
// 
//         final byte[] binary = IOUtils.toByteArray(inputStream);
// 
//         return getMach(binary);
//     }
// 
//     private static Mach getMach(byte[] binary) throws Exception {
//         final DWord dWordAtAddress = B.getDWordAtAddress(binary, new Address64("0x0000000000000000"), null, AbstractData.Type.DATA_BYTE, ByteOrder.LITTLE_ENDIAN);
// 
//         if(dWordAtAddress == null)
//             return null;
// 
//         Mach ret = null;
// 
//         if(Loader.MH_MAGIC_64.equals(dWordAtAddress) || Loader.MH_CIGAM_64.equals(dWordAtAddress)){
//             ret = new MachO64(binary);
//             MachParser64.parse((MachO64) ret);
//         } else if(Loader.MH_MAGIC.equals(dWordAtAddress) || Loader.MH_CIGAM.equals(dWordAtAddress)){
//             ret = new MachO32(binary);
//             MachParser32.parse((MachO32) ret);
//         }
// 
//         return ret;
//     }
// }


// Path: src/main/java/redress/gui/MenuBarController.java
import redress.abi.generic.AbstractABI;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.input.KeyCombination;
import javafx.stage.FileChooser;
import redress.abi.mach.parse.Reader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

    public MenuBarController(MenuBar in){
        this.menuBar=in;

        initFileMenu();
        initEditMenu();
        initWindowMenu();
        initHelpMenu();

        fileMenu.getItems().addAll(openTestMenuItem,openMenuItem,saveMenuItem,preferencesMenuItem,quitMenuItem);
        editMenu.getItems().addAll(deleteMenuItem);
        windowMenu.getItems().addAll(codeWindowMenuItem,leftWindowMenuItem,rightWindowMenuItem);
        helpMenu.getItems().addAll(aboutMenuItem);
        menuBar.getMenus().addAll(fileMenu,editMenu,windowMenu,helpMenu);
    }

    private void initFileMenu(){
        openMenuItem.setAccelerator(KeyCombination.keyCombination(KeyCombination.META_DOWN+"+o"));
        openMenuItem.setOnAction((ae) -> {
            FileChooser fileChooser = new FileChooser();
            fileChooser.setTitle("Open Binary");
            fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
            InputStream resourceAsStream = null;
            try {
                resourceAsStream = new FileInputStream(fileChooser.showOpenDialog(MainController.getSharedMainController().getPrimaryStage()));
            }catch(Exception e){
                LOGGER.log(Level.SEVERE,"Unable to open file: "+e);
            }
            openStream(resourceAsStream);
        });
        openTestMenuItem.setAccelerator(KeyCombination.keyCombination(KeyCombination.META_DOWN+"+"+KeyCombination.SHIFT_ANY+"+o"));
        openTestMenuItem.setOnAction((ae)->{