ROSE 0.11.145.192
|
This class contains methods for assembling x86 instructions (SgAsmX86Instruction).
End users will generally not need to use the AssemblerX86 class directly. Instead, they will call Assembler::create() to create an assembler that's appropriate for a particular binary file header or interpretation and then use that assembler to assemble instructions.
The assembler itself is quite small compared to the disassembler (about one third the size) and doesn't actually know about any instructions; it only knows how to encode various prefixes and operand addressing modes. For each instruction to be assembled, the assembler consults a dictionary of assembly definitions. The instruction is looked up in this dictionary and the chosen definition then drives the assembly. If the instruction being assembled matches multiple definitions then each valid definition is tried and the "best" one (see Assembler::set_encoding_type()) is returned.
The dictionary is generated directly from the Intel "Instruction Set Reference" PDF documentation as augmented by a small text file in this directory. The IntelAssemblyBuilder perl script generates AssemblerX86Init.h and AssemblerX86Init.C, which contain the X86InstructionKind enumeration, and a function to initialize the dictionary (AssemblerX86::initAssemblyRules()).
Definition at line 31 of file AssemblerX86.h.
#include <frontend/Disassemblers/AssemblerX86.h>
Public Member Functions | |
virtual SgUnsignedCharList | assembleOne (SgAsmInstruction *) |
Assemble an instruction (SgAsmInstruction) into byte code. | |
void | set_honor_operand_types (bool b) |
Causes the assembler to honor (if true) or disregard (if false) the data types of operands when assembling. | |
bool | get_honor_operand_types () const |
Returns true if the assembler is honoring operand data types, or false if the assembler is using the smallest possible encoding. | |
virtual SgUnsignedCharList | assembleProgram (const std::string &source) |
Assemble an x86 program from assembly source code using the nasm assembler. | |
Public Member Functions inherited from Rose::BinaryAnalysis::Assembler | |
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. | |
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. | |
Additional Inherited Members | |
Public Types inherited from Rose::BinaryAnalysis::Assembler | |
enum | EncodingType { ET_SHORTEST , ET_LONGEST , ET_MATCHES } |
Assemblers can often assemble a single instruction various ways. More... | |
Static Public Member Functions inherited from Rose::BinaryAnalysis::Assembler | |
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 inherited from Rose::BinaryAnalysis::Assembler | |
FILE * | p_debug |
Set to non-null to get debugging info. | |
EncodingType | p_encoding_type |
Which encoding should be returned by assembleOne. | |
|
inline |
Definition at line 33 of file AssemblerX86.h.
|
inlinevirtual |
Definition at line 39 of file AssemblerX86.h.
|
virtual |
Assemble an instruction (SgAsmInstruction) into byte code.
The new bytes are added to the end of the vector.
Implements Rose::BinaryAnalysis::Assembler.
|
inline |
Causes the assembler to honor (if true) or disregard (if false) the data types of operands when assembling.
For instance, when honoring operand data types, if an operand is a 32-bit SgAsmIntegerValueExpression then the assembler will attempt to encode it as four bytes even if its value could be encoded as a single byte. This is turned on automatically if the Assembler::set_encoding_type() is set to Assembler::ET_MATCHES, but can also be turned on independently.
Definition at line 49 of file AssemblerX86.h.
|
inline |
Returns true if the assembler is honoring operand data types, or false if the assembler is using the smallest possible encoding.
Definition at line 55 of file AssemblerX86.h.
|
virtual |
Assemble an x86 program from assembly source code using the nasm assembler.
Implements Rose::BinaryAnalysis::Assembler.