ROSE
0.9.6a
|
Disassembler for the ARM architecture. More...
#include <DisassemblerArm.h>
Classes | |
class | ExceptionArm |
Same as Disassembler::Exception except with a different constructor for ease of use in DisassemblerArm. More... | |
Public Member Functions | |
DisassemblerArm () | |
DisassemblerArm (const DisassemblerArm &other) | |
virtual | ~DisassemblerArm () |
virtual Disassembler * | clone () const |
Creates a new copy of a disassembler. More... | |
virtual bool | can_disassemble (SgAsmGenericHeader *) const |
See Disassembler::can_disassemble. More... | |
virtual SgAsmInstruction * | disassembleOne (const MemoryMap *map, rose_addr_t start_va, AddressSet *successors=NULL) |
See Disassembler::disassembleOne. More... | |
virtual void | assembleOne (SgAsmInstruction *, SgUnsignedCharList &) |
See Disassembler::assembleOne. More... | |
virtual SgAsmInstruction * | make_unknown_instruction (const Exception &) |
See Disassembler::can_disassemble. More... | |
Public Member Functions inherited from Disassembler | |
Disassembler () | |
Disassembler (const Disassembler &other) | |
virtual | ~Disassembler () |
void | disassemble (SgAsmInterpretation *, AddressSet *successors=NULL, BadMap *bad=NULL) |
This high-level method disassembles instructions belonging to part of a file described by an executable file header as indicated by the specified interpretation. More... | |
void | set_registers (const RegisterDictionary *rdict) |
Specifies the registers available on this architecture. More... | |
const RegisterDictionary * | get_registers () const |
Returns the dictionary used for looking up register names. More... | |
void | set_partitioner (class Partitioner *p) |
Specifies the instruction partitioner to use when partitioning instructions into functions. More... | |
class Partitioner * | get_partitioner () const |
Returns the partitioner object set by set_partitioner(). More... | |
void | set_search (unsigned bits) |
Specifies the heuristics used when searching for instructions. More... | |
unsigned | get_search () const |
Returns a bit mask of SearchHeuristic bits representing which heuristics would be used when searching for instructions. More... | |
void | set_wordsize (size_t) |
Specifies the word size for the SEARCH_WORDS heuristic. More... | |
size_t | get_wordsize () const |
Returns the word size used by the SEARCH_WORDS heuristic. More... | |
void | set_alignment (size_t) |
Specifies the alignment for the SEARCH_WORDS heuristic. More... | |
size_t | get_alignment () const |
Returns the alignment used by the SEARCH_WORDS heuristic. More... | |
void | set_sex (ByteOrder::Endianness sex) |
Specifies the byte order for the SEARCH_WORDS heuristic. More... | |
ByteOrder::Endianness | get_sex () const |
Returns the byte order used by the SEARCH_WORDS heuristic. More... | |
void | set_debug (FILE *f) |
Sends disassembler diagnostics to the specified output stream. More... | |
FILE * | get_debug () const |
Returns the file currently used for debugging; null implies no debugging. More... | |
size_t | get_ndisassembled () const |
Returns the number of instructions successfully disassembled. More... | |
void | set_protection (unsigned bitvec) |
Normally the disassembler will only read memory when the execute permission is turned on for the memory. More... | |
unsigned | get_protection () const |
Returns a bit vector describing which bits must be enabled in the MemoryMap in order for the disassembler to read from that memory. More... | |
void | set_progress_reporting (FILE *, unsigned min_interval) |
Set progress reporting properties. More... | |
SgAsmInstruction * | disassembleOne (const unsigned char *buf, rose_addr_t buf_va, size_t buf_size, rose_addr_t start_va, AddressSet *successors=NULL) |
Similar in functionality to the disassembleOne method that takes a MemoryMap argument, except the content buffer is mapped 1:1 to virtual memory beginning at the specified address. More... | |
InstructionMap | disassembleBlock (const MemoryMap *map, rose_addr_t start_va, AddressSet *successors=NULL, InstructionMap *cache=NULL) |
Like the disassembleOne method except it disassembles a basic block's worth of instructions beginning at the specified virtual address. More... | |
InstructionMap | disassembleBlock (const unsigned char *buf, rose_addr_t buf_va, size_t buf_size, rose_addr_t start_va, AddressSet *successors=NULL, InstructionMap *cache=NULL) |
Similar in functionality to the disassembleBlock method that takes a MemoryMap argument, except the supplied buffer is mapped 1:1 to virtual memory beginning at the specified address. More... | |
InstructionMap | disassembleBuffer (const MemoryMap *map, size_t start_va, AddressSet *successors=NULL, BadMap *bad=NULL) |
Disassembles instructions from the content buffer beginning at the specified virtual address and including all instructions that are direct or indirect successors of the first instruction. More... | |
InstructionMap | disassembleBuffer (const unsigned char *buf, rose_addr_t buf_va, size_t buf_size, rose_addr_t start_va, AddressSet *successors=NULL, BadMap *bad=NULL) |
Similar in functionality to the disassembleBuffer methods that take a MemoryMap argument, except the supplied buffer is mapped 1:1 to virtual memory beginning at the specified address. More... | |
InstructionMap | disassembleBuffer (const MemoryMap *map, AddressSet workset, AddressSet *successors=NULL, BadMap *bad=NULL) |
Similar in functionality to the disassembleBuffer methods that take a single starting virtual address, except this one tries to disassemble from all the addresses specified in the workset. More... | |
InstructionMap | disassembleSection (SgAsmGenericSection *section, rose_addr_t section_va, rose_addr_t start_offset, AddressSet *successors=NULL, BadMap *bad=NULL) |
Disassembles instructions in the specified section by assuming that it's mapped to a particular starting address. More... | |
InstructionMap | disassembleInterp (SgAsmInterpretation *interp, AddressSet *successors=NULL, BadMap *bad=NULL) |
Disassembles instructions in a particular binary interpretation. More... | |
void | search_following (AddressSet *worklist, const InstructionMap &bb, rose_addr_t bb_va, const MemoryMap *map, const InstructionMap &tried) |
Adds the address following a basic block to the list of addresses that should be disassembled. More... | |
void | search_immediate (AddressSet *worklist, const InstructionMap &bb, const MemoryMap *map, const InstructionMap &tried) |
Adds values of immediate operands to the list of addresses that should be disassembled. More... | |
void | search_words (AddressSet *worklist, const MemoryMap *map, const InstructionMap &tried) |
Adds all word-aligned values to work list, provided they specify a virtual address in the map . More... | |
void | search_next_address (AddressSet *worklist, rose_addr_t start_va, const MemoryMap *map, const InstructionMap &insns, const InstructionMap &tried, bool avoid_overlaps) |
Finds the lowest virtual address, greater than or equal to start_va , which does not correspond to a previous disassembly attempt as evidenced by its presence in the supplied instructions or bad map. More... | |
void | search_function_symbols (AddressSet *worklist, const MemoryMap *, SgAsmGenericHeader *) |
Adds addresses that correspond to function symbols. More... | |
void | update_progress (SgAsmInstruction *) |
Updates progress information. More... | |
void | progress (FILE *, const char *fmt,...) const __attribute__((format(printf |
Conditionally prints a progress report. More... | |
void | mark_referenced_instructions (SgAsmInterpretation *, const MemoryMap *, const InstructionMap &) |
Marks parts of the file that correspond to instructions as having been referenced. More... | |
AddressSet | get_block_successors (const InstructionMap &, bool *complete) |
Calculates the successor addresses of a basic block and adds them to a successors set. More... | |
Static Private Member Functions | |
static SgAsmArmInstruction * | makeInstructionWithoutOperands (uint32_t address, const std::string &mnemonic, int condPos, ArmInstructionKind kind, ArmInstructionCondition cond, uint32_t insn) |
Private Attributes | |
bool | decodeUnconditionalInstructions |
set by init() More... | |
uint32_t | ip |
instruction pointer More... | |
uint32_t | insn |
4-byte instruction word More... | |
ArmInstructionCondition | cond |
Additional Inherited Members | |
Public Types inherited from Disassembler | |
enum | SearchHeuristic { SEARCH_FOLLOWING = 0x0001, SEARCH_IMMEDIATE = 0x0002, SEARCH_WORDS = 0x0004, SEARCH_ALLBYTES = 0x0008, SEARCH_UNUSED = 0x0010, SEARCH_NONEXE = 0x0020, SEARCH_DEADEND = 0x0040, SEARCH_UNKNOWN = 0x0080, SEARCH_FUNCSYMS = 0x0100, SEARCH_DEFAULT = 0x0101 } |
Heuristics used to find instructions to disassemble. More... | |
typedef std::set< rose_addr_t > | AddressSet |
An AddressSet contains virtual addresses (alternatively, relative virtual addresses) for such things as specifying which virtual addresses should be disassembled. More... | |
typedef Map< rose_addr_t, SgAsmInstruction * > | InstructionMap |
The InstructionMap is a mapping from (absolute) virtual address to disassembled instruction. More... | |
typedef Map< rose_addr_t, Exception > | BadMap |
The BadMap is a mapping from (absolute) virtual address to information about a failed disassembly attempt at that address. More... | |
Static Public Member Functions inherited from Disassembler | |
static unsigned | parse_switches (const std::string &s, unsigned initial=SEARCH_DEFAULT) |
Given a string (presumably from the ROSE command-line), parse it and return the bit vector describing which search heuristics should be employed by the disassembler. More... | |
static void | register_subclass (Disassembler *) |
Register a disassembler instance. More... | |
static Disassembler * | lookup (SgAsmGenericHeader *) |
Finds a suitable disassembler. More... | |
static Disassembler * | lookup (SgAsmInterpretation *) |
Finds a suitable disassembler. More... | |
static void | disassembleInterpretation (SgAsmInterpretation *) |
This class method is for backward compatibility with the disassembleInterpretation() function in the old Disassembler namespace. More... | |
Protected Attributes inherited from Disassembler | |
const RegisterDictionary * | p_registers |
Description of registers available for this platform. More... | |
class Partitioner * | p_partitioner |
Used for placing instructions into blocks and functions. More... | |
unsigned | p_search |
Mask of SearchHeuristic bits specifying instruction searching. More... | |
FILE * | p_debug |
Set to non-null to get debugging info. More... | |
size_t | p_wordsize |
Word size used by SEARCH_WORDS. More... | |
ByteOrder::Endianness | p_sex |
Byte order for SEARCH_WORDS. More... | |
size_t | p_alignment |
Word alignment constraint for SEARCH_WORDS (0 and 1 imply byte). More... | |
size_t | p_ndisassembled |
Total number of instructions disassembled by disassembleBlock() More... | |
unsigned | p_protection |
Memory protection bits that must be set to disassemble. More... | |
Static Protected Attributes inherited from Disassembler | |
static std::vector < Disassembler * > | disassemblers |
List of disassembler subclasses. More... | |
static time_t | progress_interval = 10 |
Minimum interval between progress reports. More... | |
static time_t | progress_time = 0 |
Time of last report, or zero if no report has been generated. More... | |
static FILE * | progress_file = stderr |
File to which reports are made. More... | |
static RTS_mutex_t | class_mutex = RTS_MUTEX_INITIALIZER(RTS_LAYER_DISASSEMBLER_CLASS) |
Mutex for class-wide thread safety. More... | |
Disassembler for the ARM architecture.
Most of the useful disassembly methods can be found in the superclass.
Definition at line 7 of file DisassemblerArm.h.
|
inline |
|
inline |
Definition at line 14 of file DisassemblerArm.h.
|
inlinevirtual |
Definition at line 19 of file DisassemblerArm.h.
|
inlinevirtual |
Creates a new copy of a disassembler.
The new copy has all the same settings as the original.
Thread safety: The thread safety of this virtual method depends on the implementation in the subclass.
Implements Disassembler.
Definition at line 21 of file DisassemblerArm.h.
References DisassemblerArm().
|
virtual |
See Disassembler::can_disassemble.
Implements Disassembler.
Definition at line 12 of file DisassemblerArm.C.
References SgAsmGenericHeader::get_isa(), SgAsmExecutableFileFormat::ISA_ARM_Family, and SgAsmExecutableFileFormat::ISA_FAMILY_MASK.
|
virtual |
See Disassembler::disassembleOne.
Implements Disassembler.
Definition at line 30 of file DisassemblerArm.C.
References disassemble(), Disassembler::get_protection(), SgAsmArmInstruction::get_successors(), insn, MemoryMap::read(), startInstruction(), and Disassembler::update_progress().
|
inlinevirtual |
See Disassembler::assembleOne.
Definition at line 32 of file DisassemblerArm.h.
|
virtual |
See Disassembler::can_disassemble.
Implements Disassembler.
Definition at line 64 of file DisassemblerArm.C.
References Disassembler::Exception::bytes, insn, Disassembler::Exception::ip, SgAsmInstruction::set_operandList(), SgNode::set_parent(), and SgAsmInstruction::set_raw_bytes().
|
staticprivate |
Definition at line 77 of file DisassemblerArm.C.
References SgAsmInstruction::set_operandList(), SgNode::set_parent(), and SgAsmInstruction::set_raw_bytes().
|
private |
Creates a general-purpose register reference expression.
Definition at line 99 of file DisassemblerArm.C.
References Disassembler::get_registers(), RegisterDictionary::lookup(), name, and StringUtility::numberToString().
Referenced by decodeExtraLoadStores(), decodeMiscInstruction(), decodeMultiplyInstruction(), disassemble(), and makeShifterField().
|
private |
Create a reference to one of the program status registers.
If useSPSR
is true then create a reference to the saved program status register, otherwise create a reference to the current program status register. The fields
is a 4-bit mask indicating which individual fields of the register are selected.
The field bits are 0x01 => c control field mask bit 0x02 => x extension field mask bit 0x04 => s status field mask bit 0x08 => f flags field mask bit
Definition at line 121 of file DisassemblerArm.C.
References Disassembler::get_registers(), RegisterDictionary::lookup(), name, and SgAsmArmRegisterReferenceExpression::set_psr_mask().
Referenced by decodeMiscInstruction(), disassemble(), and makePsr().
|
private |
Definition at line 134 of file DisassemblerArm.C.
References makePsrFields().
Referenced by decodeMiscInstruction().
|
private |
Definition at line 141 of file DisassemblerArm.C.
References insn, and SageBuilderAsm::makeDWordValue().
Referenced by disassemble(), and makeShifterField().
|
private |
Decode last 12 bits and bit 25 (I)
Definition at line 154 of file DisassemblerArm.C.
References insn, SageBuilderAsm::makeAsr(), SageBuilderAsm::makeByteValue(), SageBuilderAsm::makeLsl(), SageBuilderAsm::makeLsr(), makeRegister(), SageBuilderAsm::makeRor(), makeRotatedImmediate(), and SageBuilderAsm::makeRrx().
Referenced by decodeMemoryAddress(), and disassemble().
|
private |
Definition at line 195 of file DisassemblerArm.C.
References cfgUtils::add, MAKE_INSN2, and MAKE_INSN3.
Referenced by disassemble().
|
private |
Definition at line 238 of file DisassemblerArm.C.
References insn, and SageBuilderAsm::makeDWordValue().
Referenced by decodeExtraLoadStores().
|
private |
Definition at line 247 of file DisassemblerArm.C.
References insn, ip, and SageBuilderAsm::makeDWordValue().
Referenced by disassemble().
|
private |
Definition at line 257 of file DisassemblerArm.C.
References insn, SageBuilderAsm::makeAdd(), SageBuilderAsm::makeAddPostupdate(), SageBuilderAsm::makeAddPreupdate(), SageBuilderAsm::makeDWordValue(), makeShifterField(), SageBuilderAsm::makeSubtract(), SageBuilderAsm::makeSubtractPostupdate(), SageBuilderAsm::makeSubtractPreupdate(), and offset.
Referenced by disassemble().
|
private |
Definition at line 282 of file DisassemblerArm.C.
References insn, and StringUtility::intToHex().
Referenced by disassemble().
|
private |
Definition at line 289 of file DisassemblerArm.C.
References insn, MAKE_INSN3, MAKE_INSN4, and makeRegister().
Referenced by disassemble().
|
private |
Definition at line 319 of file DisassemblerArm.C.
References insn, MAKE_INSN2, SageBuilderAsm::makeAdd(), SageBuilderAsm::makeAddPostupdate(), SageBuilderAsm::makeAddPreupdate(), SageBuilderAsm::makeMemoryReference(), makeRegister(), makeSplit8bitOffset(), SageBuilderAsm::makeSubtract(), SageBuilderAsm::makeSubtractPostupdate(), SageBuilderAsm::makeSubtractPreupdate(), and offset.
Referenced by disassemble().
|
private |
Definition at line 365 of file DisassemblerArm.C.
References insn, MAKE_INSN1, MAKE_INSN2, MAKE_INSN3, MAKE_INSN4, makePsr(), makePsrFields(), makeRegister(), and SageBuilderAsm::makeWordValue().
Referenced by disassemble().
|
private |
Definition at line 453 of file DisassemblerArm.C.
References cond, decodeExtraLoadStores(), decodeMediaInstruction(), decodeMemoryAddress(), decodeMiscInstruction(), decodeMultiplyInstruction(), decodeUnconditionalInstructions, SgAsmExprListExp::get_expressions(), insn, StringUtility::intToHex(), MAKE_INSN0, MAKE_INSN1, MAKE_INSN2, SageBuilderAsm::makeAddPostupdate(), SageBuilderAsm::makeArmSpecialRegisterList(), makeBranchTarget(), SageBuilderAsm::makeByteValue(), makeDataProcInstruction(), SageBuilderAsm::makeDWordValue(), SageBuilderAsm::makeExprListExp(), SageBuilderAsm::makeMemoryReference(), makePsrFields(), makeRegister(), makeRotatedImmediate(), makeShifterField(), SageBuilderAsm::makeSubtractPostupdate(), offset, and SgNode::set_parent().
Referenced by disassembleOne().
|
private |
Initialize instances of this class.
Called by constructor.
Definition at line 19 of file DisassemblerArm.C.
References decodeUnconditionalInstructions, RegisterDictionary::dictionary_arm7(), ByteOrder::ORDER_LSB, Disassembler::set_alignment(), Disassembler::set_registers(), Disassembler::set_sex(), and Disassembler::set_wordsize().
Referenced by DisassemblerArm().
|
inlineprivate |
Resets disassembler state to beginning of an instruction.
Definition at line 78 of file DisassemblerArm.h.
References cond, insn, and ip.
Referenced by disassembleOne().
|
private |
set by init()
Definition at line 85 of file DisassemblerArm.h.
Referenced by disassemble(), and init().
|
private |
instruction pointer
Definition at line 86 of file DisassemblerArm.h.
Referenced by makeBranchTarget(), and startInstruction().
|
private |
4-byte instruction word
Definition at line 87 of file DisassemblerArm.h.
Referenced by decodeExtraLoadStores(), decodeMediaInstruction(), decodeMemoryAddress(), decodeMiscInstruction(), decodeMultiplyInstruction(), disassemble(), disassembleOne(), DisassemblerArm::ExceptionArm::ExceptionArm(), make_unknown_instruction(), makeBranchTarget(), makeRotatedImmediate(), makeShifterField(), makeSplit8bitOffset(), and startInstruction().
|
private |
Definition at line 88 of file DisassemblerArm.h.
Referenced by disassemble(), and startInstruction().