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

An implementation of a ContextDatabase obtaining context information via a Ghidra client. More...

#include <ghidra_context.hh>

Inheritance diagram for ghidra::ContextGhidra:
ghidra::ContextDatabase

Public Member Functions

 ContextGhidra (ArchitectureGhidra *g)
 Construct with a specific client.
 
virtual const TrackedSetgetTrackedSet (const Address &addr) const
 Get the set of tracked register values associated with the given address. More...
 
virtual void decode (Decoder &decoder)
 Restore the state of this database object from the given stream decoder. More...
 
virtual void decodeFromSpec (Decoder &decoder)
 Add initial context state from elements in the compiler/processor specifications. More...
 
virtual int getContextSize (void) const
 Retrieve the number of words (uintm) in a context blob. More...
 
virtual const uintm * getContext (const Address &addr) const
 Get the context blob of values associated with a given address. More...
 
virtual const uintm * getContext (const Address &addr, uintb &first, uintb &last) const
 Get the context blob of values associated with a given address and its bounding offsets. More...
 
virtual void registerVariable (const string &nm, int4 sbit, int4 ebit)
 Register a new named context variable (as a bit range) with the database. More...
 
virtual void encode (Encoder &encoder) const
 Encode the entire database to a stream. More...
 
virtual TrackedSetcreateSet (const Address &addr1, const Address &addr2)
 Create a tracked register set that is valid over the given range. More...
 
virtual TrackedSetgetTrackedDefault (void)
 Get the set of default values for all tracked registers. More...
 
- Public Member Functions inherited from ghidra::ContextDatabase
virtual ~ContextDatabase ()
 Destructor.
 
void setVariableDefault (const string &nm, uintm val)
 Provide a default value for a context variable. More...
 
uintm getDefaultValue (const string &nm) const
 Retrieve the default value for a context variable. More...
 
void setVariable (const string &nm, const Address &addr, uintm value)
 Set a context value at the given address. More...
 
uintm getVariable (const string &nm, const Address &addr) const
 Retrieve a context value at the given address. More...
 
void setContextChangePoint (const Address &addr, int4 num, uintm mask, uintm value)
 Set a specific context value starting at the given address. More...
 
void setContextRegion (const Address &addr1, const Address &addr2, int4 num, uintm mask, uintm value)
 Set a context variable value over a given range of addresses. More...
 
void setVariableRegion (const string &nm, const Address &begad, const Address &endad, uintm value)
 Set a context variable by name over a given range of addresses. More...
 
uintb getTrackedValue (const VarnodeData &mem, const Address &point) const
 Get the value of a tracked register at a specific address. More...
 

Private Member Functions

virtual ContextBitRangegetVariable (const string &nm)
 Retrieve the context variable description object by name. More...
 
virtual const ContextBitRangegetVariable (const string &nm) const
 Retrieve the context variable description object by name. More...
 
virtual void getRegionForSet (vector< uintm *> &res, const Address &addr1, const Address &addr2, int4 num, uintm mask)
 Grab the context blob(s) for the given address range, marking bits that will be set. More...
 
virtual void getRegionToChangePoint (vector< uintm *> &res, const Address &addr, int4 num, uintm mask)
 Grab the context blob(s) starting at the given address up to the first point of change. More...
 
virtual const uintm * getDefaultValue (void) const
 Retrieve the memory region holding all default context values. More...
 
virtual uintm * getDefaultValue (void)
 Retrieve the memory region holding all default context values. More...
 

Private Attributes

ArchitectureGhidraglb
 Architecture and connection to the Ghidra client.
 
TrackedSet cache
 A cache of previously fetched tracked registers.
 

Additional Inherited Members

- Static Protected Member Functions inherited from ghidra::ContextDatabase
static void encodeTracked (Encoder &encoder, const Address &addr, const TrackedSet &vec)
 Encode all tracked register values for a specific address to a stream. More...
 
static void decodeTracked (Decoder &decoder, TrackedSet &vec)
 Restore a sequence of tracked register values from the given stream decoder. More...
 

Detailed Description

An implementation of a ContextDatabase obtaining context information via a Ghidra client.

This only implements the tracked register parts of the interface. In fact, this only implements the single method getTrackedSet(). Other methods that get or set the low-level (disassembly) context variables will throw an exception. The low-level context is only needed by the Sleigh disassembly engine, which is being provided by the Ghidra client in this use case.

Member Function Documentation

◆ createSet()

virtual TrackedSet& ghidra::ContextGhidra::createSet ( const Address addr1,
const Address addr2 
)
inlinevirtual

Create a tracked register set that is valid over the given range.

This really should be an internal routine. The created set is empty, old values are blown away. If old/default values are to be preserved, they must be copied back in.

Parameters
addr1is the starting address of the given range
addr2is (1 past) the ending address of the given range
Returns
the empty set of tracked register values

Implements ghidra::ContextDatabase.

◆ decode()

void ghidra::ContextGhidra::decode ( Decoder decoder)
virtual

Restore the state of this database object from the given stream decoder.

Parameters
decoderis the given stream decoder

Implements ghidra::ContextDatabase.

References ghidra::Decoder::skipElement().

Referenced by ContextGhidra().

◆ decodeFromSpec()

void ghidra::ContextGhidra::decodeFromSpec ( Decoder decoder)
virtual

Add initial context state from elements in the compiler/processor specifications.

Parse a <context_data> element from the given stream decoder from either the compiler or processor specification file for the architecture, initializing this database.

Parameters
decoderis the given stream decoder

Implements ghidra::ContextDatabase.

References ghidra::Decoder::skipElement().

Referenced by ContextGhidra().

◆ encode()

virtual void ghidra::ContextGhidra::encode ( Encoder encoder) const
inlinevirtual

Encode the entire database to a stream.

Parameters
encoderis the stream encoder

Implements ghidra::ContextDatabase.

◆ getContext() [1/2]

virtual const uintm* ghidra::ContextGhidra::getContext ( const Address addr) const
inlinevirtual

Get the context blob of values associated with a given address.

Parameters
addris the given address
Returns
the memory region holding the context values for the address

Implements ghidra::ContextDatabase.

◆ getContext() [2/2]

virtual const uintm* ghidra::ContextGhidra::getContext ( const Address addr,
uintb &  first,
uintb &  last 
) const
inlinevirtual

Get the context blob of values associated with a given address and its bounding offsets.

In addition to the memory region, the range of addresses for which the region is valid is passed back as offsets into the address space.

Parameters
addris the given address
firstwill hold the starting offset of the valid range
lastwill hold the ending offset of the valid range
Returns
the memory region holding the context values for the address

Implements ghidra::ContextDatabase.

◆ getContextSize()

virtual int ghidra::ContextGhidra::getContextSize ( void  ) const
inlinevirtual

Retrieve the number of words (uintm) in a context blob.

Returns
the number of words

Implements ghidra::ContextDatabase.

◆ getDefaultValue() [1/2]

virtual const uintm* ghidra::ContextGhidra::getDefaultValue ( void  ) const
inlineprivatevirtual

Retrieve the memory region holding all default context values.

This fetches the active memory holding the default context values on top of which all other context values are overlaid.

Returns
the memory region holding all the default context values

Implements ghidra::ContextDatabase.

◆ getDefaultValue() [2/2]

virtual uintm* ghidra::ContextGhidra::getDefaultValue ( void  )
inlineprivatevirtual

Retrieve the memory region holding all default context values.

This fetches the active memory holding the default context values on top of which all other context values are overlaid.

Returns
the memory region holding all the default context values

Implements ghidra::ContextDatabase.

◆ getRegionForSet()

virtual void ghidra::ContextGhidra::getRegionForSet ( vector< uintm *> &  res,
const Address addr1,
const Address addr2,
int4  num,
uintm  mask 
)
inlineprivatevirtual

Grab the context blob(s) for the given address range, marking bits that will be set.

This is an internal routine for obtaining the actual memory regions holding context values for the address range. This also informs the system which bits are getting set. A split is forced at the first address, and at least one memory region is passed back. The second address can be invalid in which case the memory region passed back is valid from the first address to whatever the next split point is.

Parameters
reswill hold pointers to memory regions for the given range
addr1is the starting address of the range
addr2is (1 past) the last address of the range or is invalid
numis the word index for the context value that will be set
maskis a mask of the value being set (within its word)

Implements ghidra::ContextDatabase.

◆ getRegionToChangePoint()

virtual void ghidra::ContextGhidra::getRegionToChangePoint ( vector< uintm *> &  res,
const Address addr,
int4  num,
uintm  mask 
)
inlineprivatevirtual

Grab the context blob(s) starting at the given address up to the first point of change.

This is an internal routine for obtaining the actual memory regions holding context values starting at the given address. A specific context value is specified, and all memory regions are returned up to the first address where that particular context value changes.

Parameters
reswill hold pointers to memory regions being passed back
addris the starting address of the regions to fetch
numis the word index for the specific context value being set
maskis a mask of the context value being set (within its word)

Implements ghidra::ContextDatabase.

◆ getTrackedDefault()

virtual TrackedSet& ghidra::ContextGhidra::getTrackedDefault ( void  )
inlinevirtual

Get the set of default values for all tracked registers.

Returns
the list of TrackedContext objects

Implements ghidra::ContextDatabase.

◆ getTrackedSet()

const TrackedSet & ghidra::ContextGhidra::getTrackedSet ( const Address addr) const
virtual

Get the set of tracked register values associated with the given address.

Parameters
addris the given address
Returns
the list of TrackedContext objects

Implements ghidra::ContextDatabase.

References cache, ghidra::PackedDecode::closeElement(), ghidra::ContextDatabase::decodeTracked(), ghidra::ArchitectureGhidra::getTrackedRegisters(), glb, and ghidra::PackedDecode::openElement().

Referenced by ContextGhidra().

◆ getVariable() [1/2]

virtual ContextBitRange& ghidra::ContextGhidra::getVariable ( const string &  nm)
inlineprivatevirtual

Retrieve the context variable description object by name.

If the variable doesn't exist an exception is thrown.

Parameters
nmis the name of the context value
Returns
the ContextBitRange object matching the name

Implements ghidra::ContextDatabase.

◆ getVariable() [2/2]

virtual const ContextBitRange& ghidra::ContextGhidra::getVariable ( const string &  nm) const
inlineprivatevirtual

Retrieve the context variable description object by name.

If the variable doesn't exist an exception is thrown.

Parameters
nmis the name of the context value
Returns
the ContextBitRange object matching the name

Implements ghidra::ContextDatabase.

◆ registerVariable()

virtual void ghidra::ContextGhidra::registerVariable ( const string &  nm,
int4  sbit,
int4  ebit 
)
inlinevirtual

Register a new named context variable (as a bit range) with the database.

A new variable is registered by providing a name and the range of bits the value will occupy within the context blob. The full blob size is automatically increased if necessary. The variable must be contained within a single word, and all variables must be registered before any values can be set.

Parameters
nmis the name of the new variable
sbitis the position of the variable's most significant bit within the blob
ebitis the position of the variable's least significant bit within the blob

Implements ghidra::ContextDatabase.


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