ROSE 0.11.145.147
|
Virtual base class for instruction assemblers.
The Assembler class is a virtual class providing all non-architecture-specific functionality for the assembly of instructions; architecture-specific components are in subclasses such as AssemblerAarch64, AssemblerPowerpc, and AssemblerX86.
This example shows how to test the disassembler against the assembler by disassembling and then reassembling all instructions. Generate debugging output for instructions that cannot be reassembled into an encoding identical to the original bytes:
Definition at line 58 of file Assembler.h.
#include <frontend/Disassemblers/Assembler.h>
Classes | |
class | Exception |
Exception thrown by the assemblers. More... | |
Public Types | |
enum | EncodingType { ET_SHORTEST , ET_LONGEST , ET_MATCHES } |
Assemblers can often assemble a single instruction various ways. More... | |
Public Member Functions | |
virtual SgUnsignedCharList | assembleOne (SgAsmInstruction *insn)=0 |
This is the lowest level architecture-independent assembly function and is implemented in the architecture-specific subclasses (there may be other architecture-dependent assembly methods also). | |
SgUnsignedCharList | assembleBlock (SgAsmBlock *) |
Assembles a single basic block of instructions, packing them together and adjusting their virtual addresses. | |
SgUnsignedCharList | assembleBlock (const std::vector< SgAsmInstruction * > &insns, rose_addr_t starting_rva) |
Assembles a single basic block of instructions like the version that takes an SgAsmBlock pointer. | |
virtual SgUnsignedCharList | assembleProgram (const std::string &source)=0 |
Assembles a program from an assembly listing. | |
void | set_encoding_type (EncodingType et) |
Controls how the assembleOne() method determines which encoding to return. | |
EncodingType | get_encoding_type () const |
Returns the encoding type employed by this assembler. | |
void | set_debug (FILE *f) |
Sends assembler diagnostics to the specified output stream. | |
FILE * | get_debug () const |
Returns the file currently used for debugging; null implies no debugging. | |
Static Public Member Functions | |
static Assembler * | create (SgAsmInterpretation *interp) |
Creates an assembler that is appropriate for assembling instructions in the specified interpretation. | |
static Assembler * | create (SgAsmGenericHeader *) |
Creates an assembler that is appropriate for assembling instructions in the specified header. | |
Protected Attributes | |
FILE * | p_debug |
Set to non-null to get debugging info. | |
EncodingType | p_encoding_type |
Which encoding should be returned by assembleOne. | |
Assemblers can often assemble a single instruction various ways.
For instance, on x86 the immediate value -53 can be assembled into a single byte, or sign extended into 2, 4, or 8 bytes. These enumeration constants control how the assembleOne() method determines which encoding to return.
Definition at line 80 of file Assembler.h.
|
inline |
Definition at line 89 of file Assembler.h.
|
inlinevirtual |
Definition at line 93 of file Assembler.h.
|
pure virtual |
This is the lowest level architecture-independent assembly function and is implemented in the architecture-specific subclasses (there may be other architecture-dependent assembly methods also).
It assembles one instruction and returns the encoding, throwing an exception if anything goes wrong.
Implemented in Rose::BinaryAnalysis::AssemblerX86.
SgUnsignedCharList Rose::BinaryAnalysis::Assembler::assembleBlock | ( | SgAsmBlock * | ) |
Assembles a single basic block of instructions, packing them together and adjusting their virtual addresses.
The virtual address of the first instruction of the block determines the starting address. An exception is thrown if any of the instructions cannot be assembled.
SgUnsignedCharList Rose::BinaryAnalysis::Assembler::assembleBlock | ( | const std::vector< SgAsmInstruction * > & | insns, |
rose_addr_t | starting_rva | ||
) |
Assembles a single basic block of instructions like the version that takes an SgAsmBlock pointer.
In this case, the instructions are stored in a vector instead. The will be treated like a single basic block: no control flow adjustments will be made. An exception is thrown if any of the instructions cannot be disassembled.
|
pure virtual |
Assembles a program from an assembly listing.
This method may call an external assembler to do its work.
Implemented in Rose::BinaryAnalysis::AssemblerX86.
|
inline |
Controls how the assembleOne() method determines which encoding to return.
Definition at line 128 of file Assembler.h.
References p_encoding_type.
|
inline |
Returns the encoding type employed by this assembler.
See set_encoding_type().
Definition at line 133 of file Assembler.h.
References p_encoding_type.
|
inline |
Sends assembler diagnostics to the specified output stream.
Null (the default) turns off debugging.
Definition at line 138 of file Assembler.h.
References p_debug.
|
inline |
Returns the file currently used for debugging; null implies no debugging.
Definition at line 143 of file Assembler.h.
References p_debug.
|
protected |
Set to non-null to get debugging info.
Definition at line 151 of file Assembler.h.
Referenced by get_debug(), and set_debug().
|
protected |
Which encoding should be returned by assembleOne.
Definition at line 152 of file Assembler.h.
Referenced by get_encoding_type(), and set_encoding_type().