decompiler  1.0.0
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Attributes | Static Private Attributes | List of all members
ghidra::SleighBase Class Reference

Common core of classes that read or write SLEIGH specification files natively. More...

#include <sleighbase.hh>

Inheritance diagram for ghidra::SleighBase:
ghidra::Translate ghidra::AddrSpaceManager ghidra::Sleigh ghidra::SleighCompile

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 VarnodeDatagetRegister (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 > &reglist) 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...
 
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 saveXml (ostream &s) const
 Write out the SLEIGH specification as an XML <sleigh> tag. 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 FloatFormatgetFloatFormat (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 initialize (DocumentStorage &store)=0
 Initialize the translator given XML configuration documents. 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...
 
virtual int4 instructionLength (const Address &baseaddr) const =0
 Get the length of a machine instruction. More...
 
virtual int4 oneInstruction (PcodeEmit &emit, const Address &baseaddr) const =0
 Transform a single machine instruction into pcode. More...
 
virtual int4 printAssembly (AssemblyEmit &emit, const Address &baseaddr) const =0
 Disassemble a single machine instruction. 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...
 
AddrSpacegetSpaceByName (const string &nm) const
 Get address space by name. More...
 
AddrSpacegetSpaceByShortcut (char sc) const
 Get address space from its shortcut. More...
 
AddrSpacegetIopSpace (void) const
 Get the internal pcode op space. More...
 
AddrSpacegetFspecSpace (void) const
 Get the internal callspec space. More...
 
AddrSpacegetJoinSpace (void) const
 Get the joining space. More...
 
AddrSpacegetStackSpace (void) const
 Get the stack space for this processor. More...
 
AddrSpacegetUniqueSpace (void) const
 Get the temporary register space for this processor. More...
 
AddrSpacegetDefaultCodeSpace (void) const
 Get the default address space of this processor. More...
 
AddrSpacegetDefaultDataSpace (void) const
 Get the default address space where data is stored. More...
 
AddrSpacegetConstantSpace (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...
 
AddrSpacegetSpace (int4 i) const
 Get an address space via its index. More...
 
AddrSpacegetNextSpaceInOrder (AddrSpace *spc) const
 Get the next contiguous address space. More...
 
JoinRecordfindAddJoin (const vector< VarnodeData > &pieces, uint4 logicalsize)
 Get (or create) JoinRecord for pieces. More...
 
JoinRecordfindJoin (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...
 

Static Public Attributes

static const uint4 MAX_UNIQUE_SIZE = 128
 Maximum size of a varnode in the unique space (should match value in SleighBase.java)
 

Protected Member Functions

void buildXrefs (vector< string > &errorPairs)
 Build register map. Collect user-ops and context-fields. More...
 
void reregisterContext (void)
 Reregister context fields for a new executable. More...
 
void restoreXml (const Element *el)
 Read a SLEIGH specification from XML. 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
AddrSpacedecodeSpace (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...
 
JoinRecordfindJoinInternal (uintb offset) const
 Find JoinRecord for offset in the join space. More...
 

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< FloatFormatfloatformats
 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.
 

Static Private Attributes

static const int4 SLA_FORMAT_VERSION = 3
 Current version of the .sla file read/written by SleighBash.
 

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...
 

Detailed Description

Common core of classes that read or write SLEIGH specification files natively.

This class represents what's in common across the SLEIGH infrastructure between:

Member Function Documentation

◆ buildXrefs()

void ghidra::SleighBase::buildXrefs ( vector< string > &  errorPairs)
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::SourceFileIndexer::index().

Referenced by ghidra::SleighCompile::process().

◆ getAllRegisters()

void ghidra::SleighBase::getAllRegisters ( map< VarnodeData, string > &  reglist) const
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

Parameters
reglistis the map which will be populated by the call

Implements ghidra::Translate.

◆ getRegister()

const VarnodeData & ghidra::SleighBase::getRegister ( const string &  nm) const
virtual

Get a register as VarnodeData given its name.

Retrieve the location and size of a register given its name

Parameters
nmis the name of the register
Returns
the VarnodeData for the register

Implements ghidra::Translate.

◆ getRegisterName()

string ghidra::SleighBase::getRegisterName ( AddrSpace base,
uintb  off,
int4  size 
) const
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.

Parameters
baseis the address space containing the location
offis the offset of the location
sizeis the size of the location
Returns
the name of the register, or an empty string

Implements ghidra::Translate.

References ghidra::VarnodeData::offset, ghidra::VarnodeData::size, and ghidra::VarnodeData::space.

◆ getUserOpNames()

void ghidra::SleighBase::getUserOpNames ( vector< string > &  res) const
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.

Parameters
resis the resulting vector of user op names

Implements ghidra::Translate.

◆ reregisterContext()

void ghidra::SleighBase::reregisterContext ( void  )
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

Referenced by ghidra::Sleigh::initialize().

◆ restoreXml()

void ghidra::SleighBase::restoreXml ( const Element el)
protected

Read a SLEIGH specification from XML.

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

Parameters
elis the root XML element

References ghidra::Element::getAttributeName(), ghidra::Element::getAttributeValue(), ghidra::Element::getChildren(), ghidra::Element::getNumAttributes(), and ghidra::xml_readbool().

Referenced by ghidra::Sleigh::initialize().

◆ saveXml()

void ghidra::SleighBase::saveXml ( ostream &  s) const

Write out the SLEIGH specification as an XML <sleigh> tag.

This does the bulk of the work of creating a .sla file

Parameters
sis the output stream

References ghidra::a_v(), ghidra::a_v_b(), ghidra::a_v_i(), ghidra::a_v_u(), ghidra::AddrSpace::getType(), ghidra::IPTR_CONSTANT, ghidra::IPTR_FSPEC, ghidra::IPTR_IOP, ghidra::IPTR_JOIN, and ghidra::AddrSpace::saveXml().

Referenced by ghidra::SleighCompile::run_compilation().


The documentation for this class was generated from the following files: