public static void main(String[] args) {
   System.out.println("********** mJAM Disassembler (1.0) **********");
   String objectFileName = "obj.mJAM";
   if (args.length == 1) objectFileName = args[0];
   Disassembler d = new Disassembler(objectFileName);
   d.disassemble();
 }
Example #2
0
 private void openBin() {
   fileChooser.resetChoosableFileFilters();
   fileChooser.addChoosableFileFilter(binFilter);
   fileChooser.setFileFilter(binFilter);
   if (fileChooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
     try {
       FileInputStream inbinf = new FileInputStream(fileChooser.getSelectedFile());
       int len = inbinf.available();
       if (len % 2 == 1) throw new IOException(String.format("Odd file size (0x%x)\n", len));
       len /= 2;
       if (len > 0x10000) throw new IOException(String.format("Too large file (0x%x)\n", len));
       binary = new char[len];
       for (int i = 0; i < len; i++) {
         int lo = inbinf.read();
         int hi = inbinf.read();
         if (lo == -1 || hi == -1) throw new IOException("Unable to read\n");
         binary[i] = (char) ((hi << 8) | lo);
       }
       asmMap = new AsmMap();
       Disassembler dasm = new Disassembler();
       dasm.init(binary);
       // TODO attach asmmap
       StringBuilder sb = new StringBuilder();
       while (dasm.getAddress() < binary.length) {
         int addr = dasm.getAddress();
         sb.append(String.format("%-26s ; [%04x] =", dasm.next(true), addr));
         int addr2 = dasm.getAddress();
         while (addr < addr2) {
           char i = binary[addr++];
           sb.append(
               String.format(" %04x '%s'", (int) i, (i >= 0x20 && i < 0x7f) ? (char) i : '.'));
         }
         sb.append("\n");
       }
       srcBreakpoints.clear();
       sourceRowHeader.breakpointsChanged();
       sourceTextarea.setText(sb.toString());
     } catch (IOException e1) {
       JOptionPane.showMessageDialog(
           frame, "Unable to open file: %s" + e1.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
       e1.printStackTrace();
     }
   }
 }