public static void main(String[] args) { if (args.length != 1) { System.out.println("Usage: java Disassembler [filename]"); System.exit(0); } String filename = args[0]; Disassembler d = new Disassembler(filename); d.run(); }
public long getParameterValue(InstructionParameter p) { long value = 0; for (int i = 0; i < words.length; i++) { InstructionWord iword = descriptor.instruction.getWords().get(i); List<InstructionSection> sections = iword.getSections(); int length = 0; for (int j = sections.size() - 1; j >= 0; j--) { InstructionSection section = sections.get(j); if (section instanceof ParameterSection) { ParameterSection psection = ((ParameterSection) section); if (p.equals(psection.getParameter())) { long mask = Disassembler.mask(psection.getSize(), length); long psectionvalue = (words[i] & mask); psectionvalue = psectionvalue >> length; value |= psectionvalue << psection.getShift(); } } length += section.getSize(); } } return value; }
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(); } } }