/** * Get the statement at a specific label. If there is no statement stored, attempts to disassemble * the instruction at the label's virtual address. If the address is outside of the file area, * logs an error and returns a Halt statement by default. * * @param label The label for which to get the statement * @return The statement object at label. */ public final RTLStatement getStatement(RTLLabel label) { if (!statementMap.containsKey(label)) { AbsoluteAddress address = label.getAddress(); Instruction instr = getInstruction(address); // If we did not get an instruction, add an artificial Halt for recovery if (instr == null) { RTLHalt halt = new RTLHalt(); halt.setLabel(label); putStatement(halt); logger.error("ERROR: Replacing unknown instruction with HALT."); if (Options.debug.getValue()) throw new DisassemblyException("Disassembly failed at " + address); } else { try { StatementSequence seq = arch.getRTLEquivalent(address, instr); for (RTLStatement s : seq) { putStatement(s); } } catch (Exception e) { logger.error("Error during translation of instruction to IL"); e.printStackTrace(); RTLStatement skip = new RTLSkip(); skip.setLabel(label); skip.setNextLabel(new RTLLabel(new AbsoluteAddress(address.getValue() + 1))); putStatement(skip); } assert statementMap.containsKey(label) : "Disassembly did not produce label: " + label; } } return statementMap.get(label); }
/** * Get the string representation of the specified assembly instruction assuming it is located at * the given address. * * @param addr a virtual address * @param instr an assembly instruction * @return a string representation of the assembly code at the given address */ public String getInstructionString(AbsoluteAddress addr, Instruction instr) { if (instr == null) return "NON_EXISTENT"; return instr.toString(addr.getValue(), symbolFinder(addr)); }
public boolean isStub(AbsoluteAddress a) { return a.getValue() >= StubProvider.STUB_BASE; }
@Override public AbsoluteAddress getVirtualAddress(long fp) { return new AbsoluteAddress(baseAddress.getValue() + fp); }
@Override public AbsoluteAddress getMaxAddress() { return new AbsoluteAddress(baseAddress.getValue() + inBuf.getSize()); }
@Override public long getFilePointer(AbsoluteAddress va) { return va.getValue() - baseAddress.getValue(); }
/** * Returns the number of the section the given virtual address is in. * * @param va the virtual address * @return the section number */ protected final int getSectionNumber(AbsoluteAddress va) { return getSectionNumberByRVA(va.getValue() - getBaseAddress()); }
@Override public final long getFilePointer(AbsoluteAddress va) { long fp = getFilePointerFromRVA(va.getValue() - getBaseAddress()); if (fp >= 0) return fp; else return -1; }