|
Ghidra 11.4.2
Ghidra internal decompiler documentation.
|
Common core of classes that read or write SLEIGH specification files natively. More...
#include <sleighbase.hh>
Public Member Functions | |
| SleighBase (void) | |
| Construct an uninitialized translator. | |
| bool | isInitialized (void) const |
| Return true if this is initialized. | |
| virtual | ~SleighBase (void) |
| Destructor. | |
| virtual const VarnodeData & | getRegister (const string &nm) const |
| Get a register as VarnodeData given its name. | |
| virtual string | getRegisterName (AddrSpace *base, uintb off, int4 size) const |
| Get the name of the smallest containing register given a location and size. | |
| virtual string | getExactRegisterName (AddrSpace *base, uintb off, int4 size) const |
| Get the name of a register with an exact location and size. | |
| virtual void | getAllRegisters (map< VarnodeData, string > ®list) const |
| Get a list of all register names and the corresponding location. | |
| virtual void | getUserOpNames (vector< string > &res) const |
| Get a list of all user-defined pcode ops. | |
| SleighSymbol * | findSymbol (const string &nm) const |
| Find a specific SLEIGH symbol by name in the current scope. | |
| SleighSymbol * | findSymbol (uintm id) const |
| Find a specific SLEIGH symbol by id. | |
| SleighSymbol * | findGlobalSymbol (const string &nm) const |
| Find a specific global SLEIGH symbol by name. | |
| void | encodeSlaSpace (Encoder &encoder, AddrSpace *spc) const |
| Write the details of given space in .sla format. | |
| void | encode (Encoder &encoder) const |
| Write out the SLEIGH specification as a <sleigh> tag. | |
Public Member Functions inherited from ghidra::Translate | |
| Translate (void) | |
| Constructor for the translator. | |
| void | setDefaultFloatFormats (void) |
| If no explicit float formats, set up default formats. | |
| bool | isBigEndian (void) const |
| Is the processor big endian? | |
| const FloatFormat * | getFloatFormat (int4 size) const |
| Get format for a particular floating point encoding. | |
| int4 | getAlignment (void) const |
| Get the instruction alignment for the processor. | |
| uint4 | getUniqueBase (void) const |
| Get the base offset for new temporary registers. | |
| uint4 | getUniqueStart (UniqueLayout layout) const |
| Get a tagged address within the unique space. | |
| virtual void | initialize (DocumentStorage &store)=0 |
| Initialize the translator given XML configuration documents. | |
| virtual void | registerContext (const string &name, int4 sbit, int4 ebit) |
| Add a new context variable to the model for this processor. | |
| virtual void | setContextDefault (const string &name, uintm val) |
| Set the default value for a particular context variable. | |
| virtual void | allowContextSet (bool val) const |
| Toggle whether disassembly is allowed to affect context. | |
| virtual int4 | instructionLength (const Address &baseaddr) const =0 |
| Get the length of a machine instruction. | |
| virtual int4 | oneInstruction (PcodeEmit &emit, const Address &baseaddr) const =0 |
| Transform a single machine instruction into pcode. | |
| virtual int4 | printAssembly (AssemblyEmit &emit, const Address &baseaddr) const =0 |
| Disassemble a single machine instruction. | |
Public Member Functions inherited from ghidra::AddrSpaceManager | |
| AddrSpaceManager (void) | |
| Construct an empty address space manager. | |
| virtual | ~AddrSpaceManager (void) |
| Destroy the manager. | |
| int4 | getDefaultSize (void) const |
| Get size of addresses for the default space. | |
| AddrSpace * | getSpaceByName (const string &nm) const |
| Get address space by name. | |
| AddrSpace * | getSpaceByShortcut (char sc) const |
| Get address space from its shortcut. | |
| AddrSpace * | getIopSpace (void) const |
| Get the internal pcode op space. | |
| AddrSpace * | getFspecSpace (void) const |
| Get the internal callspec space. | |
| AddrSpace * | getJoinSpace (void) const |
| Get the joining space. | |
| AddrSpace * | getStackSpace (void) const |
| Get the stack space for this processor. | |
| AddrSpace * | getUniqueSpace (void) const |
| Get the temporary register space for this processor. | |
| AddrSpace * | getDefaultCodeSpace (void) const |
| Get the default address space of this processor. | |
| AddrSpace * | getDefaultDataSpace (void) const |
| Get the default address space where data is stored. | |
| AddrSpace * | getConstantSpace (void) const |
| Get the constant space. | |
| Address | getConstant (uintb val) const |
| Get a constant encoded as an Address. | |
| Address | createConstFromSpace (AddrSpace *spc) const |
| Create a constant address encoding an address space. | |
| Address | resolveConstant (AddrSpace *spc, uintb val, int4 sz, const Address &point, uintb &fullEncoding) const |
| Resolve a native constant into an Address. | |
| int4 | numSpaces (void) const |
| Get the number of address spaces for this processor. | |
| AddrSpace * | getSpace (int4 i) const |
| Get an address space via its index. | |
| AddrSpace * | getNextSpaceInOrder (AddrSpace *spc) const |
| Get the next contiguous address space. | |
| JoinRecord * | findAddJoin (const vector< VarnodeData > &pieces, uint4 logicalsize) |
| Get (or create) JoinRecord for pieces. | |
| JoinRecord * | findJoin (uintb offset) const |
| Find JoinRecord for offset in the join space. | |
| void | setDeadcodeDelay (AddrSpace *spc, int4 delaydelta) |
| Set the deadcodedelay for a specific space. | |
| void | truncateSpace (const TruncationTag &tag) |
| Mark a space as truncated from its original size. | |
| Address | constructFloatExtensionAddress (const Address &realaddr, int4 realsize, int4 logicalsize) |
| Build a logically lower precision storage location for a bigger floating point register. | |
| Address | constructJoinAddress (const Translate *translate, const Address &hiaddr, int4 hisz, const Address &loaddr, int4 losz) |
| Build a logical whole from register pairs. | |
| void | renormalizeJoinAddress (Address &addr, int4 size) |
| Make sure a possibly offset join address has a proper JoinRecord. | |
| Address | parseAddressSimple (const string &val) |
| Parse a string with just an address space name and a hex offset. | |
Static Public Attributes | |
| static const uint4 | MAX_UNIQUE_SIZE = 128 |
| Decode a SELIGH specification from a stream. | |
Protected Member Functions | |
| void | buildXrefs (vector< string > &errorPairs) |
| Build register map. Collect user-ops and context-fields. | |
| void | reregisterContext (void) |
| Reregister context fields for a new executable. | |
| AddrSpace * | decodeSlaSpace (Decoder &decoder, const Translate *trans) |
| Add a space parsed from a .sla file. | |
| void | decodeSlaSpaces (Decoder &decoder, const Translate *trans) |
| Restore address spaces from a .sla file. | |
| void | decode (Decoder &decoder) |
Protected Member Functions inherited from ghidra::Translate | |
| void | setBigEndian (bool val) |
| Set general endianness to big if val is true. | |
| void | setUniqueBase (uint4 val) |
| Set the base offset for new temporary registers. | |
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. | |
| void | decodeSpaces (Decoder &decoder, const Translate *trans) |
| Restore address spaces in the model from a stream. | |
| void | setDefaultCodeSpace (int4 index) |
| Set the default address space (for code) | |
| void | setDefaultDataSpace (int4 index) |
| Set the default address space for data. | |
| void | setReverseJustified (AddrSpace *spc) |
| Set reverse justified property on this space. | |
| void | assignShortcut (AddrSpace *spc) |
| Select a shortcut character for a new space. | |
| void | markNearPointers (AddrSpace *spc, int4 size) |
| Mark that given space can be accessed with near pointers. | |
| void | insertSpace (AddrSpace *spc) |
| Add a new address space to the model. | |
| void | copySpaces (const AddrSpaceManager *op2) |
| Copy spaces from another manager. | |
| void | addSpacebasePointer (SpacebaseSpace *basespace, const VarnodeData &ptrdata, int4 truncSize, bool stackGrowth) |
| Set the base register of a spacebase space. | |
| void | insertResolver (AddrSpace *spc, AddressResolver *rsolv) |
| Override the base resolver for a space. | |
| void | setInferPtrBounds (const Range &range) |
| Set the range of addresses that can be inferred as pointers. | |
| JoinRecord * | findJoinInternal (uintb offset) const |
| Find JoinRecord for offset in the join space. | |
Protected Attributes | |
| SubtableSymbol * | root |
| The root SLEIGH decoding symbol. | |
| SymbolTable | symtab |
| The SLEIGH symbol table. | |
| uint4 | maxdelayslotbytes |
| Maximum number of bytes in a delay-slot directive. | |
| uint4 | unique_allocatemask |
| Bits that are guaranteed to be zero in the unique allocation scheme. | |
| uint4 | numSections |
| Number of named sections. | |
| SourceFileIndexer | indexer |
| source file index used when generating SLEIGH constructor debug info | |
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. | |
Private Attributes | |
| vector< string > | userop |
| Names of user-define p-code ops for this Translate object. | |
| map< VarnodeData, string > | varnode_xref |
| A map from Varnodes in the register space to register names. | |
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... | |
Common core of classes that read or write SLEIGH specification files natively.
This class represents what's in common across the SLEIGH infrastructure between:
|
protected |
Build register map. Collect user-ops and context-fields.
Assuming the symbol table is populated, iterate through the table collecting registers (for the map), user-op names, and context fields.
References ghidra::Translate::registerContext(), symtab, userop, and varnode_xref.
Referenced by decode().
|
protected |
This parses the main <sleigh> tag (from a .sla file), which includes the description of address spaces and the symbol table, with its associated decoding tables
| decoder | is the stream to decode |
References ghidra::Translate::alignment, buildXrefs(), ghidra::Decoder::closeElement(), ghidra::SourceFileIndexer::decode(), decodeSlaSpaces(), ghidra::Decoder::getNextAttributeId(), indexer, maxdelayslotbytes, numSections, ghidra::Decoder::openElement(), ghidra::Decoder::readBool(), ghidra::Decoder::readSignedInteger(), ghidra::Decoder::readUnsignedInteger(), root, ghidra::Translate::setBigEndian(), ghidra::Translate::setUniqueBase(), symtab, and unique_allocatemask.
Referenced by ghidra::Sleigh::initialize().
|
protected |
Add a space parsed from a .sla file.
This is identical to the functionality of decodeSpace, but the AddrSpace information is stored in the .sla file format.
| decoder | is the stream decoder |
| trans | is the translator object to be associated with the new space |
References ghidra::Decoder::closeElement(), ghidra::Decoder::getNextAttributeId(), ghidra::AddrSpace::hasphysical, ghidra::IPTR_PROCESSOR, ghidra::Decoder::openElement(), ghidra::Decoder::readBool(), ghidra::Decoder::readSignedInteger(), and ghidra::Decoder::readString().
Referenced by decodeSlaSpaces().
Restore address spaces from a .sla file.
This is identical in functionality to decodeSpaces but the AddrSpace information is stored in the .sla file format.
| decoder | is the stream decoder |
| trans | is the processor translator to be associated with the spaces |
References ghidra::Decoder::closeElement(), decodeSlaSpace(), ghidra::AddrSpace::getIndex(), ghidra::AddrSpaceManager::getSpaceByName(), ghidra::AddrSpaceManager::insertSpace(), ghidra::Decoder::openElement(), ghidra::Decoder::peekElement(), ghidra::Decoder::readString(), and ghidra::AddrSpaceManager::setDefaultCodeSpace().
Referenced by decode().
| void ghidra::SleighBase::encode | ( | Encoder & | encoder | ) | const |
Write out the SLEIGH specification as a <sleigh> tag.
This does the bulk of the work of creating a .sla file
| encoder | is the stream encoder |
References ghidra::Translate::alignment, ghidra::Encoder::closeElement(), ghidra::SourceFileIndexer::encode(), encodeSlaSpace(), ghidra::AddrSpaceManager::getDefaultCodeSpace(), ghidra::AddrSpaceManager::getSpace(), ghidra::AddrSpace::getType(), ghidra::Translate::getUniqueBase(), indexer, ghidra::IPTR_CONSTANT, ghidra::IPTR_FSPEC, ghidra::IPTR_IOP, ghidra::IPTR_JOIN, ghidra::Translate::isBigEndian(), maxdelayslotbytes, numSections, ghidra::AddrSpaceManager::numSpaces(), ghidra::Encoder::openElement(), symtab, unique_allocatemask, ghidra::Encoder::writeBool(), ghidra::Encoder::writeSignedInteger(), ghidra::Encoder::writeString(), and ghidra::Encoder::writeUnsignedInteger().
Write the details of given space in .sla format.
Write a tag fully describing the details of the space.
| encoder | is the stream being written |
| spc | is the given address space |
References ghidra::Encoder::closeElement(), ghidra::AddrSpace::getAddrSize(), ghidra::AddrSpace::getDelay(), ghidra::AddrSpace::getIndex(), ghidra::AddrSpace::getName(), ghidra::AddrSpace::getType(), ghidra::AddrSpace::getWordSize(), ghidra::AddrSpace::hasPhysical(), ghidra::IPTR_INTERNAL, ghidra::Translate::isBigEndian(), ghidra::AddrSpace::isOtherSpace(), ghidra::Encoder::openElement(), ghidra::Encoder::writeBool(), ghidra::Encoder::writeSignedInteger(), and ghidra::Encoder::writeString().
Referenced by encode().
|
virtual |
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 varnode_xref.
|
virtual |
Get the name of a register with an exact location and size.
If a register exists with the given location and size, return the name of the register. Otherwise return the empty string.
| 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 ghidra::VarnodeData::offset, ghidra::VarnodeData::size, ghidra::VarnodeData::space, and varnode_xref.
|
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 findSymbol().
|
virtual |
Get the name of the smallest containing register given a location and size.
Generic references to locations in a register space are translated into the register name. If a containing register isn't found, 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 ghidra::VarnodeData::offset, ghidra::VarnodeData::size, ghidra::VarnodeData::space, and varnode_xref.
|
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 userop.
|
protected |
Reregister context fields for a new executable.
If this SleighBase is being reused with a new program, the context variables need to be registered with the new program's database
References ghidra::Translate::registerContext(), and symtab.
Referenced by ghidra::Sleigh::initialize().
|
static |
Decode a SELIGH specification from a stream.
Maximum size of a varnode in the unique space (should match value in SleighBase.java)