Ghidra Decompiler Analysis Engine
Public Member Functions | List of all members
ContextGhidra Class Reference

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

#include <ghidra_context.hh>

Inheritance diagram for ContextGhidra:
Inheritance graph
[legend]
Collaboration diagram for ContextGhidra:
Collaboration graph
[legend]

Public Member Functions

virtual const TrackedSetgetTrackedSet (const Address &addr) const
 Get the set of tracked register values associated with the given address. More...
 
virtual void restoreXml (const Element *el, const AddrSpaceManager *manage)
 Restore the state of this database object from a serialized XML stream. More...
 
virtual void restoreFromSpec (const Element *el, const AddrSpaceManager *manage)
 Add initial context state from XML tags in 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 saveXml (ostream &s) const
 Serialize the entire database to an XML 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 ContextDatabase
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...
 

Additional Inherited Members

- Static Protected Member Functions inherited from ContextDatabase
static void saveTracked (ostream &s, const Address &addr, const TrackedSet &vec)
 Save all tracked register values for a specific address to an XML stream. More...
 
static void restoreTracked (const Element *el, const AddrSpaceManager *manage, TrackedSet &vec)
 Restore a sequence of tracked register values from an XML stream. 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& 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 ContextDatabase.

◆ getContext() [1/2]

virtual const uintm* 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 ContextDatabase.

◆ getContext() [2/2]

virtual const uintm* 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 ContextDatabase.

◆ getContextSize()

virtual int ContextGhidra::getContextSize ( void  ) const
inlinevirtual

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

Returns
the number of words

Implements ContextDatabase.

◆ getTrackedDefault()

virtual TrackedSet& ContextGhidra::getTrackedDefault ( void  )
inlinevirtual

Get the set of default values for all tracked registers.

Returns
the list of TrackedContext objects

Implements ContextDatabase.

◆ getTrackedSet()

const TrackedSet & 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 ContextDatabase.

◆ registerVariable()

virtual void 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 ContextDatabase.

◆ restoreFromSpec()

virtual void ContextGhidra::restoreFromSpec ( const Element el,
const AddrSpaceManager manage 
)
inlinevirtual

Add initial context state from XML tags in compiler/processor specifications.

The database can be configured with a consistent initial state by providing <context_data> tags in either the compiler or processor specification file for the architecture

Parameters
elis a <context_data> tag
manageis used to resolve address space references

Implements ContextDatabase.

◆ restoreXml()

virtual void ContextGhidra::restoreXml ( const Element el,
const AddrSpaceManager manage 
)
inlinevirtual

Restore the state of this database object from a serialized XML stream.

Parameters
elis the root element of the XML describing the database state
manageis used to resolve address space references

Implements ContextDatabase.

◆ saveXml()

virtual void ContextGhidra::saveXml ( ostream &  s) const
inlinevirtual

Serialize the entire database to an XML stream.

Parameters
sis the output stream

Implements ContextDatabase.


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