decompiler
1.0.0
|
An implementation of Translate that queries a Ghidra client for p-code information. More...
#include <ghidra_translate.hh>
Public Member Functions | |
GhidraTranslate (ArchitectureGhidra *g) | |
Constructor. | |
virtual void | initialize (DocumentStorage &store) |
Initialize the translator given XML configuration documents. More... | |
virtual const VarnodeData & | getRegister (const string &nm) const |
Get a register as VarnodeData given its name. More... | |
virtual string | getRegisterName (AddrSpace *base, uintb off, int4 size) const |
Get the name of a register given its location. More... | |
virtual void | getAllRegisters (map< VarnodeData, string > ®list) const |
Get a list of all register names and the corresponding location. More... | |
virtual void | getUserOpNames (vector< string > &res) const |
Get a list of all user-defined pcode ops. More... | |
virtual int4 | oneInstruction (PcodeEmit &emit, const Address &baseaddr) const |
Transform a single machine instruction into pcode. More... | |
virtual int4 | instructionLength (const Address &baseaddr) const |
Get the length of a machine instruction. More... | |
virtual int4 | printAssembly (AssemblyEmit &emit, const Address &baseaddr) const |
Disassemble a single machine instruction. More... | |
Public Member Functions inherited from ghidra::Translate | |
Translate (void) | |
Constructor for the translator. More... | |
void | setDefaultFloatFormats (void) |
If no explicit float formats, set up default formats. More... | |
bool | isBigEndian (void) const |
Is the processor big endian? More... | |
const FloatFormat * | getFloatFormat (int4 size) const |
Get format for a particular floating point encoding. More... | |
int4 | getAlignment (void) const |
Get the instruction alignment for the processor. More... | |
uint4 | getUniqueBase (void) const |
Get the base offset for new temporary registers. More... | |
uint4 | getUniqueStart (UniqueLayout layout) const |
Get a tagged address within the unique space. More... | |
virtual void | registerContext (const string &name, int4 sbit, int4 ebit) |
Add a new context variable to the model for this processor. More... | |
virtual void | setContextDefault (const string &name, uintm val) |
Set the default value for a particular context variable. More... | |
virtual void | allowContextSet (bool val) const |
Toggle whether disassembly is allowed to affect context. More... | |
Public Member Functions inherited from ghidra::AddrSpaceManager | |
AddrSpaceManager (void) | |
Construct an empty address space manager. More... | |
virtual | ~AddrSpaceManager (void) |
Destroy the manager. More... | |
int4 | getDefaultSize (void) const |
Get size of addresses for the default space. More... | |
AddrSpace * | getSpaceByName (const string &nm) const |
Get address space by name. More... | |
AddrSpace * | getSpaceByShortcut (char sc) const |
Get address space from its shortcut. More... | |
AddrSpace * | getIopSpace (void) const |
Get the internal pcode op space. More... | |
AddrSpace * | getFspecSpace (void) const |
Get the internal callspec space. More... | |
AddrSpace * | getJoinSpace (void) const |
Get the joining space. More... | |
AddrSpace * | getStackSpace (void) const |
Get the stack space for this processor. More... | |
AddrSpace * | getUniqueSpace (void) const |
Get the temporary register space for this processor. More... | |
AddrSpace * | getDefaultCodeSpace (void) const |
Get the default address space of this processor. More... | |
AddrSpace * | getDefaultDataSpace (void) const |
Get the default address space where data is stored. More... | |
AddrSpace * | getConstantSpace (void) const |
Get the constant space. More... | |
Address | getConstant (uintb val) const |
Get a constant encoded as an Address. More... | |
Address | createConstFromSpace (AddrSpace *spc) const |
Create a constant address encoding an address space. More... | |
Address | resolveConstant (AddrSpace *spc, uintb val, int4 sz, const Address &point, uintb &fullEncoding) const |
Resolve a native constant into an Address. More... | |
int4 | numSpaces (void) const |
Get the number of address spaces for this processor. More... | |
AddrSpace * | getSpace (int4 i) const |
Get an address space via its index. More... | |
AddrSpace * | getNextSpaceInOrder (AddrSpace *spc) const |
Get the next contiguous address space. More... | |
JoinRecord * | findAddJoin (const vector< VarnodeData > &pieces, uint4 logicalsize) |
Get (or create) JoinRecord for pieces. More... | |
JoinRecord * | findJoin (uintb offset) const |
Find JoinRecord for offset in the join space. More... | |
void | setDeadcodeDelay (AddrSpace *spc, int4 delaydelta) |
Set the deadcodedelay for a specific space. More... | |
void | truncateSpace (const TruncationTag &tag) |
Mark a space as truncated from its original size. More... | |
Address | constructFloatExtensionAddress (const Address &realaddr, int4 realsize, int4 logicalsize) |
Build a logically lower precision storage location for a bigger floating point register. More... | |
Address | constructJoinAddress (const Translate *translate, const Address &hiaddr, int4 hisz, const Address &loaddr, int4 losz) |
Build a logical whole from register pairs. More... | |
void | renormalizeJoinAddress (Address &addr, int4 size) |
Make sure a possibly offset join address has a proper JoinRecord. More... | |
Address | parseAddressSimple (const string &val) |
Parse a string with just an address space name and a hex offset. More... | |
Private Member Functions | |
const VarnodeData & | cacheRegister (const string &nm, const VarnodeData &data) const |
Associate a Varnode with a register name. More... | |
void | decode (Decoder &decoder) |
Initialize this Translate from a stream. More... | |
Private Attributes | |
ArchitectureGhidra * | glb |
The Ghidra Architecture and connection to the client. | |
map< string, VarnodeData > | nm2addr |
Mapping from register name to Varnode. | |
map< VarnodeData, string > | addr2nm |
Mapping rom Varnode to register name. | |
Additional Inherited Members | |
Public Types inherited from ghidra::Translate | |
enum | UniqueLayout { RUNTIME_BOOLEAN_INVERT =0, RUNTIME_RETURN_LOCATION =0x80, RUNTIME_BITRANGE_EA =0x100, INJECT =0x200, ANALYSIS =0x10000000 } |
Tagged addresses in the unique address space. More... | |
Protected Member Functions inherited from ghidra::Translate | |
void | setBigEndian (bool val) |
Set general endianness to big if val is true. More... | |
void | setUniqueBase (uint4 val) |
Set the base offset for new temporary registers. More... | |
Protected Member Functions inherited from ghidra::AddrSpaceManager | |
AddrSpace * | decodeSpace (Decoder &decoder, const Translate *trans) |
Add a space to the model based an on XML tag. More... | |
void | decodeSpaces (Decoder &decoder, const Translate *trans) |
Restore address spaces in the model from an XML tag. More... | |
void | setDefaultCodeSpace (int4 index) |
Set the default address space (for code) More... | |
void | setDefaultDataSpace (int4 index) |
Set the default address space for data. More... | |
void | setReverseJustified (AddrSpace *spc) |
Set reverse justified property on this space. More... | |
void | assignShortcut (AddrSpace *spc) |
Select a shortcut character for a new space. More... | |
void | markNearPointers (AddrSpace *spc, int4 size) |
Mark that given space can be accessed with near pointers. More... | |
void | insertSpace (AddrSpace *spc) |
Add a new address space to the model. More... | |
void | copySpaces (const AddrSpaceManager *op2) |
Copy spaces from another manager. More... | |
void | addSpacebasePointer (SpacebaseSpace *basespace, const VarnodeData &ptrdata, int4 truncSize, bool stackGrowth) |
Set the base register of a spacebase space. More... | |
void | insertResolver (AddrSpace *spc, AddressResolver *rsolv) |
Override the base resolver for a space. More... | |
void | setInferPtrBounds (const Range &range) |
Set the range of addresses that can be inferred as pointers. More... | |
JoinRecord * | findJoinInternal (uintb offset) const |
Find JoinRecord for offset in the join space. More... | |
Protected Attributes inherited from ghidra::Translate | |
int4 | alignment |
Byte modulo on which instructions are aligned. | |
vector< FloatFormat > | floatformats |
Floating point formats utilized by the processor. | |
An implementation of Translate that queries a Ghidra client for p-code information.
This class provides:
by sending a request to a Ghidra client and decoding the response. Messages are generally based on an XML format, but p-code responses in particular have a tight internal encoding.
|
private |
Associate a Varnode with a register name.
nm | is the register name |
data | is the Varnode description |
References addr2nm, and nm2addr.
Referenced by getRegister().
|
private |
Initialize this Translate from a stream.
Parse the <sleigh> element passed back by the Ghidra client, describing address spaces and other information that needs to be cached by the decompiler.
decoder | is the stream decoder |
References ghidra::Decoder::closeElement(), ghidra::TruncationTag::decode(), ghidra::AddrSpaceManager::decodeSpaces(), ghidra::Decoder::openElement(), ghidra::Decoder::peekElement(), ghidra::Decoder::readBool(), ghidra::Decoder::readUnsignedInteger(), ghidra::Translate::setBigEndian(), ghidra::Translate::setUniqueBase(), and ghidra::AddrSpaceManager::truncateSpace().
Referenced by initialize().
|
inlinevirtual |
Get a list of all register names and the corresponding location.
Most processors have a list of named registers and possibly other memory locations that are specific to it. This function populates a map from the location information to the name, for every named location known by the translator
reglist | is the map which will be populated by the call |
Implements ghidra::Translate.
References getUserOpNames(), and oneInstruction().
|
virtual |
Get a register as VarnodeData given its name.
Retrieve the location and size of a register given its name
nm | is the name of the register |
Implements ghidra::Translate.
References cacheRegister(), ghidra::Address::decode(), ghidra::DecoderError::explain, ghidra::ArchitectureGhidra::getRegister(), glb, nm2addr, ghidra::VarnodeData::offset, ghidra::VarnodeData::size, and ghidra::VarnodeData::space.
Referenced by getRegisterName(), and GhidraTranslate().
|
virtual |
Get the name of a register given its location.
Generic references to locations in a register space can be translated into the associated register name. If the location doesn't match a register exactly, an empty string is returned.
base | is the address space containing the location |
off | is the offset of the location |
size | is the size of the location |
Implements ghidra::Translate.
References addr2nm, getRegister(), ghidra::ArchitectureGhidra::getRegisterName(), ghidra::AddrSpace::getType(), glb, ghidra::IPTR_PROCESSOR, ghidra::VarnodeData::offset, ghidra::VarnodeData::size, and ghidra::VarnodeData::space.
Referenced by GhidraTranslate().
|
virtual |
Get a list of all user-defined pcode ops.
The pcode model allows processors to define new pcode instructions that are specific to that processor. These user-defined instructions are all identified by a name and an index. This method returns a list of these ops in index order.
res | is the resulting vector of user op names |
Implements ghidra::Translate.
References ghidra::ArchitectureGhidra::getUserOpName(), and glb.
Referenced by getAllRegisters().
|
virtual |
Initialize the translator given XML configuration documents.
A translator gets initialized once, possibly using XML documents to configure it.
store | is a set of configuration documents |
Implements ghidra::Translate.
References decode(), and ghidra::DocumentStorage::getTag().
Referenced by GhidraTranslate().
|
inlinevirtual |
Get the length of a machine instruction.
This method decodes an instruction at a specific address just enough to find the number of bytes it uses within the instruction stream.
baseaddr | is the Address of the instruction |
Implements ghidra::Translate.
|
virtual |
Transform a single machine instruction into pcode.
This is the main interface to the pcode translation engine. The dump method in the emit object is invoked exactly once for each pcode operation in the translation for the machine instruction at the given address. This routine can throw either
emit | is the tailored pcode emitting object |
baseaddr | is the Address of the machine instruction |
Implements ghidra::Translate.
References ghidra::Address::decode(), ghidra::PcodeEmit::decodeOp(), ghidra::ArchitectureGhidra::getPcode(), ghidra::Address::getShortcut(), glb, ghidra::PackedDecode::openElement(), ghidra::PackedDecode::peekElement(), ghidra::Address::printRaw(), and ghidra::PackedDecode::readSignedInteger().
Referenced by getAllRegisters().
|
inlinevirtual |
Disassemble a single machine instruction.
This is the main interface to the disassembler for the processor. It disassembles a single instruction and returns the result to the application via the dump method in the emit object.
emit | is the disassembly emitting object |
baseaddr | is the address of the machine instruction to disassemble |
Implements ghidra::Translate.