decompiler  1.0.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
ghidra::Translate Class Referenceabstract

The interface to a translation engine for a processor. More...

#include <translate.hh>

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

Public Types

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

Public Member Functions

 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 const VarnodeDatagetRegister (const string &nm) const =0
 Get a register as VarnodeData given its name. More...
 
virtual string getRegisterName (AddrSpace *base, uintb off, int4 size) const =0
 Get the name of a register given its location. More...
 
virtual void getAllRegisters (map< VarnodeData, string > &reglist) const =0
 Get a list of all register names and the corresponding location. More...
 
virtual void getUserOpNames (vector< string > &res) const =0
 Get a list of all user-defined pcode ops. 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...
 

Protected Member Functions

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

int4 alignment
 Byte modulo on which instructions are aligned.
 
vector< FloatFormatfloatformats
 Floating point formats utilized by the processor.
 

Private Attributes

bool target_isbigendian
 true if the general endianness of the process is big endian
 
uint4 unique_base
 Starting offset into unique space.
 

Detailed Description

The interface to a translation engine for a processor.

This interface performs translations of instruction data for a particular processor. It has two main functions

It is also the repository for information about the exact configuration of the reverse engineering model associated with the processor. In particular, it knows about all the address spaces, registers, and spacebases for the processor.

Member Enumeration Documentation

◆ UniqueLayout

Tagged addresses in the unique address space.

Enumerator
RUNTIME_BOOLEAN_INVERT 

Location of the runtime temporary for boolean inversion.

RUNTIME_RETURN_LOCATION 

Location of the runtime temporary storing the return value.

RUNTIME_BITRANGE_EA 

Location of the runtime temporary for storing an effective address.

INJECT 

Range of temporaries for use in compiling p-code snippets.

ANALYSIS 

Range of temporaries for use during decompiler analysis.

Constructor & Destructor Documentation

◆ Translate()

ghidra::Translate::Translate ( void  )

Constructor for the translator.

This constructs only a shell for the Translate object. It won't be usable until it is initialized for a specific processor The main entry point for this is the Translate::initialize method, which must be overridden by a derived class

Member Function Documentation

◆ allowContextSet()

virtual void ghidra::Translate::allowContextSet ( bool  val) const
inlinevirtual

Toggle whether disassembly is allowed to affect context.

By default the disassembly/pcode translation engine can change the global context, thereby affecting later disassembly. Context may be getting determined by something other than control flow in, the disassembly, in which case this function can turn off changes made by the disassembly

Parameters
valis true to allow context changes, false prevents changes

Reimplemented in ghidra::Sleigh.

Referenced by ghidra::OptionAllowContextSet::apply().

◆ getAlignment()

int4 ghidra::Translate::getAlignment ( void  ) const
inline

Get the instruction alignment for the processor.

If machine instructions need to have a specific alignment for this processor, this routine returns it. I.e. a return value of 4, means that the address of all instructions must be a multiple of 4. If there is no specific alignment requirement, this routine returns 1.

Returns
the instruction alignment

◆ getAllRegisters()

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

Implemented in ghidra::SleighBase, and ghidra::GhidraTranslate.

◆ getFloatFormat()

const FloatFormat * ghidra::Translate::getFloatFormat ( int4  size) const

Get format for a particular floating point encoding.

The pcode model for floating point encoding assumes that a consistent encoding is used for all values of a given size. This routine fetches the FloatFormat object given the size, in bytes, of the desired encoding.

Parameters
sizeis the size of the floating-point value in bytes
Returns
a pointer to the floating-point format

Referenced by ghidra::PrintC::push_float(), and ghidra::SubfloatFlow::SubfloatFlow().

◆ getRegister()

virtual const VarnodeData& ghidra::Translate::getRegister ( const string &  nm) const
pure 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

Implemented in ghidra::SleighBase, and ghidra::GhidraTranslate.

Referenced by ghidra::JoinSpace::decodeAttributes(), ghidra::VarnodeData::decodeFromAttributes(), ghidra::Range::decodeFromAttributes(), ghidra::Varnode::printRawNoMarkup(), ghidra::Range::Range(), ghidra::AddrSpace::read(), and ghidra::JoinSpace::read().

◆ getRegisterName()

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

Implemented in ghidra::SleighBase, and ghidra::GhidraTranslate.

Referenced by ghidra::ScopeInternal::buildVariableName(), ghidra::AddrSpaceManager::constructJoinAddress(), ghidra::Varnode::printRawNoMarkup(), and ghidra::PrintC::pushAnnotation().

◆ getUniqueBase()

uint4 ghidra::Translate::getUniqueBase ( void  ) const
inline

Get the base offset for new temporary registers.

Return the first offset within the unique space after the range statically reserved by Translate. This is generally the starting offset where dynamic temporary registers can start to be allocated.

Returns
the first allocatable offset

Referenced by ghidra::SleighCompile::checkUniqueAllocation(), and ghidra::SleighCompile::getUniqueAddr().

◆ getUniqueStart()

uint4 ghidra::Translate::getUniqueStart ( UniqueLayout  layout) const
inline

Get a tagged address within the unique space.

Regions of the unique space are reserved for specific uses. We select the start of a specific region based on the given tag.

Parameters
layoutis the given tag
Returns
the absolute offset into the unique space

Referenced by ghidra::VarnodeBank::VarnodeBank().

◆ getUserOpNames()

virtual void ghidra::Translate::getUserOpNames ( vector< string > &  res) const
pure 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

Implemented in ghidra::SleighBase, and ghidra::GhidraTranslate.

Referenced by ghidra::UserOpManage::initialize(), and ghidra::BreakTableCallBack::registerPcodeCallback().

◆ initialize()

virtual void ghidra::Translate::initialize ( DocumentStorage store)
pure virtual

Initialize the translator given XML configuration documents.

A translator gets initialized once, possibly using XML documents to configure it.

Parameters
storeis a set of configuration documents

Implemented in ghidra::SleighCompile, ghidra::Sleigh, and ghidra::GhidraTranslate.

Referenced by ghidra::Architecture::restoreFromSpec().

◆ instructionLength()

virtual int4 ghidra::Translate::instructionLength ( const Address baseaddr) const
pure virtual

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.

Parameters
baseaddris the Address of the instruction
Returns
the number of bytes in the instruction

Implemented in ghidra::SleighCompile, ghidra::Sleigh, and ghidra::GhidraTranslate.

◆ isBigEndian()

bool ghidra::Translate::isBigEndian ( void  ) const
inline

Is the processor big endian?

Processors can usually be described as using a big endian encoding or a little endian encoding. This routine returns true if the processor globally uses big endian encoding.

Returns
true if big endian

Referenced by ghidra::AddrSpace::AddrSpace(), ghidra::FuncCallSpecs::buildInputFromTrials(), ghidra::StringManagerUnicode::checkCharacters(), ghidra::SleighCompile::defineBitrange(), ghidra::SleighCompile::defineToken(), ghidra::PrintC::printCharacterConstant(), and ghidra::StringManagerUnicode::writeUnicode().

◆ oneInstruction()

virtual int4 ghidra::Translate::oneInstruction ( PcodeEmit emit,
const Address baseaddr 
) const
pure 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

Parameters
emitis the tailored pcode emitting object
baseaddris the Address of the machine instruction
Returns
the number of bytes in the machine instruction

Implemented in ghidra::SleighCompile, ghidra::Sleigh, and ghidra::GhidraTranslate.

Referenced by ghidra::EmulatePcodeCache::createInstruction(), and ghidra::FlowInfo::processInstruction().

◆ printAssembly()

virtual int4 ghidra::Translate::printAssembly ( AssemblyEmit emit,
const Address baseaddr 
) const
pure virtual

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.

Parameters
emitis the disassembly emitting object
baseaddris the address of the machine instruction to disassemble

Implemented in ghidra::SleighCompile, ghidra::Sleigh, and ghidra::GhidraTranslate.

Referenced by ghidra::IfcPrintdisasm::execute().

◆ registerContext()

virtual void ghidra::Translate::registerContext ( const string &  name,
int4  sbit,
int4  ebit 
)
inlinevirtual

Add a new context variable to the model for this processor.

Add the name of a context register used by the processor and how that register is packed into the context state. This information is used by a ContextDatabase to associate names with context information and to pack context into a single state variable for the translation engine.

Parameters
nameis the name of the new context variable
sbitis the first bit of the variable in the packed state
ebitis the last bit of the variable in the packed state

Reimplemented in ghidra::Sleigh.

◆ setBigEndian()

void ghidra::Translate::setBigEndian ( bool  val)
inlineprotected

Set general endianness to big if val is true.

Although endianness is usually specified on the space, most languages set an endianness across the entire processor. This routine sets the endianness to big if the -val- is passed in as true. Otherwise, the endianness is set to small.

Parameters
valis true if the endianness should be set to big

Referenced by ghidra::GhidraTranslate::decode(), and ghidra::SleighCompile::setEndian().

◆ setContextDefault()

virtual void ghidra::Translate::setContextDefault ( const string &  name,
uintm  val 
)
inlinevirtual

Set the default value for a particular context variable.

Set the value to be returned for a context variable when there are no explicit address ranges specifying a value for the variable.

Parameters
nameis the name of the context variable
valis the value to be considered default

Reimplemented in ghidra::Sleigh.

◆ setDefaultFloatFormats()

void ghidra::Translate::setDefaultFloatFormats ( void  )

If no explicit float formats, set up default formats.

If no floating-point format objects were registered by the initialize method, this method will fill in some suitable default formats. These defaults are based on the 4-byte and 8-byte encoding specified by the IEEE 754 standard.

Referenced by ghidra::Architecture::restoreFromSpec().

◆ setUniqueBase()

void ghidra::Translate::setUniqueBase ( uint4  val)
inlineprotected

Set the base offset for new temporary registers.

The unique address space, for allocating temporary registers, is used for both registers needed by the pcode translation engine and, later, by the simplification engine. This routine sets the boundary of the portion of the space allocated for the pcode engine, and sets the base offset where registers created by the simplification process can start being allocated.

Parameters
valis the boundary offset

Referenced by ghidra::SleighCompile::checkUniqueAllocation(), ghidra::GhidraTranslate::decode(), and ghidra::SleighCompile::getUniqueAddr().


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