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

An implementation of the Architecture interface and connection to a Ghidra client. More...

#include <ghidra_arch.hh>

Inheritance diagram for ghidra::ArchitectureGhidra:
ghidra::Architecture ghidra::AddrSpaceManager

Public Member Functions

 ArchitectureGhidra (const string &pspec, const string &cspec, const string &tspec, const string &corespec, istream &i, ostream &o)
 Construct given specification files and i/o streams. More...
 
const string & getWarnings (void) const
 Get warnings produced by the last decompilation.
 
void clearWarnings (void)
 Clear warnings.
 
bool getRegister (const string &regname, Decoder &decoder)
 Retrieve a register description given a name. More...
 
string getRegisterName (const VarnodeData &vndata)
 Retrieve a register name given its storage location. More...
 
bool getTrackedRegisters (const Address &addr, Decoder &decoder)
 Retrieve tracked register values at the given address. More...
 
string getUserOpName (int4 index)
 Get the name of a user-defined p-code op. More...
 
bool getPcode (const Address &addr, Decoder &decoder)
 Get p-code for a single instruction. More...
 
bool getMappedSymbolsXML (const Address &addr, Decoder &decoder)
 Get symbols associated with the given address. More...
 
bool getExternalRef (const Address &addr, Decoder &decoder)
 Retrieve a description of an external function. More...
 
bool getNamespacePath (uint8 id, Decoder &decoder)
 Get a description of a namespace path. More...
 
bool isNameUsed (const string &nm, uint8 startId, uint8 stopId)
 Is given name used along namespace path.
 
string getCodeLabel (const Address &addr)
 Retrieve a label at the given address. More...
 
bool getDataType (const string &name, uint8 id, Decoder &decoder)
 Retrieve a data-type description for the given name and id. More...
 
bool getComments (const Address &fad, uint4 flags, Decoder &decoder)
 Retrieve comments for a particular function. More...
 
void getBytes (uint1 *buf, int4 size, const Address &inaddr)
 Retrieve bytes in the LoadImage at the given address. More...
 
bool getPcodeInject (const string &name, int4 type, const InjectContext &con, Decoder &decoder)
 Retrieve p-code to inject for a specific context. More...
 
bool getCPoolRef (const vector< uintb > &refs, Decoder &decoder)
 Resolve a constant pool reference. More...
 
void setSendSyntaxTree (bool val)
 Toggle whether the data-flow and control-flow is emitted as part of the main decompile action. More...
 
bool getSendSyntaxTree (void) const
 Get the current setting for emitting data/control-flow.
 
void setSendCCode (bool val)
 Toggle whether the recovered source code is emitted as part of the main decompile action. More...
 
bool getSendCCode (void) const
 Get the current setting for emitting source code.
 
void setSendParamMeasures (bool val)
 Toggle whether recovered parameter information is emitted as part of the main decompile action. More...
 
bool getSendParamMeasures (void) const
 Get the current setting for emitting parameter info.
 
void getStringData (vector< uint1 > &buffer, const Address &addr, Datatype *ct, int4 maxBytes, bool &isTrunc)
 Get string data at a specific address. More...
 
virtual void printMessage (const string &message) const
 Print an error message to console. More...
 
- Public Member Functions inherited from ghidra::Architecture
 Architecture (void)
 Construct an uninitialized Architecture. More...
 
void init (DocumentStorage &store)
 Load the image and configure architecture. More...
 
void resetDefaultsInternal (void)
 Reset default values for options specific to Architecture.
 
void resetDefaults (void)
 Reset defaults values for options owned by this. More...
 
ProtoModelgetModel (const string &nm) const
 Get a specific PrototypeModel. More...
 
bool hasModel (const string &nm) const
 Does this Architecture have a specific PrototypeModel. More...
 
ProtoModelcreateUnknownModel (const string &modelName)
 Create a model for an unrecognized name. More...
 
bool highPtrPossible (const Address &loc, int4 size) const
 Are pointers possible to the given location? More...
 
AddrSpacegetSpaceBySpacebase (const Address &loc, int4 size) const
 Get space associated with a spacebase register. More...
 
const LanedRegistergetLanedRegister (const Address &loc, int4 size) const
 Get LanedRegister associated with storage. More...
 
int4 getMinimumLanedRegisterSize (void) const
 Get the minimum size of a laned register in bytes. More...
 
void setDefaultModel (ProtoModel *model)
 Set the default PrototypeModel. More...
 
void clearAnalysis (Funcdata *fd)
 Clear analysis specific to a function. More...
 
void readLoaderSymbols (const string &delim)
 Read any symbols from loader into database. More...
 
void collectBehaviors (vector< OpBehavior *> &behave) const
 Provide a list of OpBehavior objects. More...
 
SegmentOpgetSegmentOp (AddrSpace *spc) const
 Retrieve the segment op for the given space if any. More...
 
void setPrototype (const PrototypePieces &pieces)
 Set the prototype for a particular function. More...
 
void setPrintLanguage (const string &nm)
 Establish a particular output language. More...
 
void globalify (void)
 Mark all spaces as global. More...
 
void decodeFlowOverride (Decoder &decoder)
 Set flow overrides from XML. More...
 
virtual ~Architecture (void)
 Destructor. More...
 
virtual string getDescription (void) const
 Get a string describing this architecture.
 
virtual void encode (Encoder &encoder) const
 Encode this architecture to a stream. More...
 
virtual void restoreXml (DocumentStorage &store)
 Restore the Architecture state from XML documents. More...
 
virtual void nameFunction (const Address &addr, string &name) const
 Pick a default name for a function. 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 Member Functions

static void segvHandler (int4 sig)
 Handler for a segment violation (SIGSEGV) signal. More...
 
static int4 readToAnyBurst (istream &s)
 Read the next message protocol marker. More...
 
static bool readBoolStream (istream &s)
 Read a boolean value from the client. More...
 
static void readStringStream (istream &s, string &res)
 Receive a string from the client. More...
 
static bool readStringStream (istream &s, Decoder &decoder)
 Receive an encoded string from the client. More...
 
static void writeStringStream (ostream &s, const string &msg)
 Send a string to the client. More...
 
static void readToResponse (istream &s)
 Read the query response protocol marker. More...
 
static void readResponseEnd (istream &s)
 Read the ending query response protocol marker. More...
 
static bool readAll (istream &s, Decoder &decoder)
 Read a whole response as an XML document. More...
 
static void passJavaException (ostream &s, const string &tp, const string &msg)
 Send an exception message to the Ghidra client. More...
 
static bool isDynamicSymbolName (const string &nm)
 Check if name is of form FUN_.. or DAT_..
 

Private Member Functions

virtual ScopebuildDatabase (DocumentStorage &store)
 Build the database and global scope for this executable. More...
 
virtual TranslatebuildTranslator (DocumentStorage &store)
 Build the Translator object. More...
 
virtual void buildLoader (DocumentStorage &store)
 Build the LoadImage object and load the executable image. More...
 
virtual PcodeInjectLibrarybuildPcodeInjectLibrary (void)
 Build the injection library. More...
 
virtual void buildTypegrp (DocumentStorage &store)
 Build the data-type factory/container. More...
 
virtual void buildCommentDB (DocumentStorage &store)
 Build the comment database. More...
 
virtual void buildStringManager (DocumentStorage &store)
 Build the string manager. More...
 
virtual void buildConstantPool (DocumentStorage &store)
 Build the constant pool. More...
 
virtual void buildContext (DocumentStorage &store)
 Build the Context database. More...
 
virtual void buildSymbols (DocumentStorage &store)
 Build any symbols from spec files. More...
 
virtual void buildSpecFile (DocumentStorage &store)
 Load any relevant specification files. More...
 
virtual void modifySpaces (Translate *trans)
 Modify address spaces as required by this Architecture. More...
 
virtual void postSpecFile (void)
 Let components initialize after Translate is built.
 
virtual void resolveArchitecture (void)
 Figure out the processor and compiler of the target executable.
 

Private Attributes

istream & sin
 Input stream for interfacing with Ghidra.
 
ostream & sout
 Output stream for interfacing with Ghidra.
 
string warnings
 Warnings accumulated by the decompiler.
 
string pspecxml
 XML pspec passed from Ghidra.
 
string cspecxml
 XML cspec passed from Ghidra.
 
string tspecxml
 Stripped down .sla file passed from Ghidra.
 
string corespecxml
 A specification of the core data-types.
 
bool sendsyntaxtree
 True if the syntax tree should be sent with function output.
 
bool sendCcode
 True if C code should be sent with function output.
 
bool sendParamMeasures
 True if measurements for argument and return parameters should be sent.
 

Additional Inherited Members

- Public Attributes inherited from ghidra::Architecture
string archid
 ID string uniquely describing this architecture.
 
int4 trim_recurse_max
 How many levels to let parameter trims recurse.
 
int4 max_implied_ref
 Maximum number of references to an implied var.
 
int4 max_term_duplication
 Max terms duplicated without a new variable.
 
int4 max_basetype_size
 Maximum size of an "integer" type before creating an array type.
 
int4 min_funcsymbol_size
 Minimum size of a function symbol.
 
uint4 max_jumptable_size
 Maximum number of entries in a single JumpTable.
 
bool aggressive_ext_trim
 Aggressively trim inputs that look like they are sign extended.
 
bool readonlypropagate
 true if readonly values should be treated as constants
 
bool infer_pointers
 True if we should infer pointers from constants that are likely addresses.
 
bool analyze_for_loops
 True if we should attempt conversion of whiledo loops to for loops.
 
vector< AddrSpace * > inferPtrSpaces
 Set of address spaces in which a pointer constant is inferable.
 
int4 funcptr_align
 How many bits of alignment a function ptr has.
 
uint4 flowoptions
 options passed to flow following engine
 
uint4 max_instructions
 Maximum instructions that can be processed in one function.
 
int4 alias_block_level
 Aliases blocked by 0=none, 1=struct, 2=array, 3=all.
 
uint4 split_datatype_config
 Toggle for data-types splitting: Bit 0=structs, 1=arrays, 2=pointers.
 
vector< Rule * > extra_pool_rules
 Extra rules that go in the main pool (cpu specific, experimental)
 
Databasesymboltab
 Memory map of global variables and functions.
 
ContextDatabasecontext
 Map from addresses to context settings.
 
map< string, ProtoModel * > protoModels
 Parsed forms of possible prototypes.
 
ProtoModeldefaultfp
 Parsed form of default prototype.
 
VarnodeData defaultReturnAddr
 Default storage location of return address (for current function)
 
ProtoModelevalfp_current
 Function proto to use when evaluating current function.
 
ProtoModelevalfp_called
 Function proto to use when evaluating called functions.
 
TypeFactorytypes
 List of types for this binary.
 
const Translatetranslate
 Translation method for this binary.
 
LoadImageloader
 Method for loading portions of binary.
 
PcodeInjectLibrarypcodeinjectlib
 Pcode injection manager.
 
RangeList nohighptr
 Ranges for which high-level pointers are not possible.
 
CommentDatabasecommentdb
 Comments for this architecture.
 
StringManagerstringManager
 Manager of decoded strings.
 
ConstantPoolcpool
 Deferred constant values.
 
PrintLanguageprint
 Current high-level language printer.
 
vector< PrintLanguage * > printlist
 List of high-level language printers supported.
 
OptionDatabaseoptions
 Options that can be configured.
 
vector< TypeOp * > inst
 Registered p-code instructions.
 
UserOpManage userops
 Specifically registered user-defined p-code ops.
 
vector< PreferSplitRecord > splitrecords
 registers that we would prefer to see split for this processor
 
vector< LanedRegisterlanerecords
 Vector registers that have preferred lane sizes.
 
ActionDatabase allacts
 Actions that can be applied in this architecture.
 
bool loadersymbols_parsed
 True if loader symbols have been read.
 
- Protected Member Functions inherited from ghidra::Architecture
void addSpacebase (AddrSpace *basespace, const string &nm, const VarnodeData &ptrdata, int4 truncSize, bool isreversejustified, bool stackGrowth, bool isFormal)
 Create a new address space associated with a pointer register. More...
 
void addNoHighPtr (const Range &rng)
 Add a new region where pointers do not exist. More...
 
virtual void buildInstructions (DocumentStorage &store)
 Register the p-code operations. More...
 
virtual void buildAction (DocumentStorage &store)
 Build the Action framework. More...
 
void restoreFromSpec (DocumentStorage &store)
 Fully initialize the Translate object. More...
 
void fillinReadOnlyFromLoader (void)
 Load info about read-only sections. More...
 
void initializeSegments ()
 Set up segment resolvers. More...
 
void cacheAddrSpaceProperties (void)
 Calculate some frequently used space properties and cache them. More...
 
void createModelAlias (const string &aliasName, const string &parentName)
 Create name alias for a ProtoModel. More...
 
void parseProcessorConfig (DocumentStorage &store)
 Apply processor specific configuration. More...
 
void parseCompilerConfig (DocumentStorage &store)
 Apply compiler specific configuration. More...
 
void parseExtraRules (DocumentStorage &store)
 Apply any Rule tags. More...
 
void decodeDynamicRule (Decoder &decoder)
 Apply details of a dynamic Rule object. More...
 
ProtoModeldecodeProto (Decoder &decoder)
 Parse a proto-type model from a stream. More...
 
void decodeProtoEval (Decoder &decoder)
 Apply prototype evaluation configuration. More...
 
void decodeDefaultProto (Decoder &decoder)
 Apply default prototype model configuration. More...
 
void decodeGlobal (Decoder &decoder, vector< RangeProperties > &rangeProps)
 Parse information about global ranges. More...
 
void addToGlobalScope (const RangeProperties &props)
 Add a memory range to the set of addresses considered global. More...
 
void addOtherSpace (void)
 Add OTHER space and all of its overlays to the symboltab.
 
void decodeReadOnly (Decoder &decoder)
 Apply read-only region configuration. More...
 
void decodeVolatile (Decoder &decoder)
 Apply volatile region configuration. More...
 
void decodeReturnAddress (Decoder &decoder)
 Apply return address configuration. More...
 
void decodeIncidentalCopy (Decoder &decoder)
 Apply incidental copy configuration. More...
 
void decodeLaneSizes (Decoder &decoder)
 Apply lane size configuration. More...
 
void decodeStackPointer (Decoder &decoder)
 Apply stack pointer configuration. More...
 
void decodeDeadcodeDelay (Decoder &decoder)
 Apply dead-code delay configuration. More...
 
void decodeInferPtrBounds (Decoder &decoder)
 Apply pointer inference bounds. More...
 
void decodeFuncPtrAlign (Decoder &decoder)
 Apply function pointer alignment configuration. More...
 
void decodeSpacebase (Decoder &decoder)
 Create an additional indexed space. More...
 
void decodeNoHighPtr (Decoder &decoder)
 Apply memory alias configuration. More...
 
void decodePreferSplit (Decoder &decoder)
 Designate registers to be split. More...
 
void decodeAggressiveTrim (Decoder &decoder)
 Designate how to trim extension p-code ops. 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...
 

Detailed Description

An implementation of the Architecture interface and connection to a Ghidra client.

In addition to managing the major pieces of the architecture (LoadImage, Translate, Database, TypeFactory, ContextDatbase, CommentDatabase etc.), this class manages a communication channel between the decompiler and a Ghidra client for a single executable. The protocol supports a simple query/response format with exceptions. On top of the low level protocol, this class manages a higher level interface that performs specific queries, providing addresses, names, and other info as input, and returning an XML document or other structure as a result.

This class overrides the build* methods to produce Architecture components that are also backed by the Ghidra client. These all use this same object to do their communication.

This class acts as a main control point for what information gets sent back to the Ghidra client when it requests the main decompilation action. Generally the decompiler sends back the recovered source representation of the function but optionally it can send back:

Constructor & Destructor Documentation

◆ ArchitectureGhidra()

ghidra::ArchitectureGhidra::ArchitectureGhidra ( const string &  pspec,
const string &  cspec,
const string &  tspec,
const string &  corespec,
istream &  i,
ostream &  o 
)

Construct given specification files and i/o streams.

Parameters
pspecis the processor specification presented as an XML string
cspecis the compiler specification presented as an XML string
tspecis a stripped down form of the SLEIGH specification presented as an XML string
corespecis a list of core data-types presented as a <coretypes> XML tag
iis the input stream from the Ghidra client
ois the output stream to the Ghidra client

References corespecxml, cspecxml, ghidra::Architecture::print, pspecxml, sendCcode, sendParamMeasures, sendsyntaxtree, ghidra::PrintLanguage::setMarkup(), ghidra::PrintLanguage::setOutputStream(), sout, and tspecxml.

Member Function Documentation

◆ buildCommentDB()

void ghidra::ArchitectureGhidra::buildCommentDB ( DocumentStorage store)
privatevirtual

Build the comment database.

Build the container that holds comments in this Architecture.

Parameters
storemay hold configuration information

Implements ghidra::Architecture.

References ghidra::Architecture::commentdb.

◆ buildConstantPool()

void ghidra::ArchitectureGhidra::buildConstantPool ( DocumentStorage store)
privatevirtual

Build the constant pool.

Some processor models (Java byte-code) need a database of constants. The database is always built, but may remain empty.

Parameters
storemay hold configuration information

Implements ghidra::Architecture.

References ghidra::Architecture::cpool.

◆ buildContext()

void ghidra::ArchitectureGhidra::buildContext ( DocumentStorage store)
privatevirtual

Build the Context database.

Build the database which holds status register settings and other information that can affect disassembly depending on context.

Parameters
storemay hold configuration information

Implements ghidra::Architecture.

References ghidra::Architecture::context.

◆ buildDatabase()

Scope * ghidra::ArchitectureGhidra::buildDatabase ( DocumentStorage store)
privatevirtual

Build the database and global scope for this executable.

Create the database object, which currently doesn't not depend on any configuration data. Then create the root (global) scope and attach it to the database.

Parameters
storeis the storage for any configuration data
Returns
the global Scope object

Reimplemented from ghidra::Architecture.

References ghidra::Database::attachScope(), and ghidra::Architecture::symboltab.

◆ buildLoader()

void ghidra::ArchitectureGhidra::buildLoader ( DocumentStorage store)
privatevirtual

Build the LoadImage object and load the executable image.

Parameters
storemay hold configuration information

Implements ghidra::Architecture.

References ghidra::Architecture::loader.

◆ buildPcodeInjectLibrary()

PcodeInjectLibrary * ghidra::ArchitectureGhidra::buildPcodeInjectLibrary ( void  )
privatevirtual

Build the injection library.

This creates the container for p-code injections. It is initially empty.

Returns
the PcodeInjectLibrary object

Implements ghidra::Architecture.

◆ buildSpecFile()

void ghidra::ArchitectureGhidra::buildSpecFile ( DocumentStorage store)
privatevirtual

Load any relevant specification files.

Processor/architecture specific configuration files are loaded into the XML store

Parameters
storeis the document store that will hold the configuration

Implements ghidra::Architecture.

References corespecxml, cspecxml, ghidra::Document::getRoot(), ghidra::DocumentStorage::parseDocument(), pspecxml, ghidra::DocumentStorage::registerTag(), and tspecxml.

◆ buildStringManager()

void ghidra::ArchitectureGhidra::buildStringManager ( DocumentStorage store)
privatevirtual

Build the string manager.

Build container that holds decoded strings for this Architecture.

Parameters
storemay hold configuration information

Implements ghidra::Architecture.

References ghidra::Architecture::stringManager.

◆ buildSymbols()

void ghidra::ArchitectureGhidra::buildSymbols ( DocumentStorage store)
privatevirtual

◆ buildTranslator()

Translate * ghidra::ArchitectureGhidra::buildTranslator ( DocumentStorage store)
privatevirtual

Build the Translator object.

This builds the main disassembly component for the Architecture This does not initially the engine for a specific processor.

Parameters
storemay hold configuration information
Returns
the Translate object

Implements ghidra::Architecture.

◆ buildTypegrp()

void ghidra::ArchitectureGhidra::buildTypegrp ( DocumentStorage store)
privatevirtual

Build the data-type factory/container.

Build the TypeFactory object specific to this Architecture and prepopulate it with the core types. Core types may be pulled from the configuration information, or default core types are used.

Parameters
storecontains possible configuration information

Implements ghidra::Architecture.

References ghidra::TypeFactory::cacheCoreTypes(), ghidra::TypeFactory::decodeCoreTypes(), ghidra::DocumentStorage::getTag(), ghidra::TypeFactory::setCoreType(), ghidra::TYPE_BOOL, ghidra::TYPE_CODE, ghidra::TYPE_FLOAT, ghidra::TYPE_INT, ghidra::TYPE_UINT, ghidra::TYPE_UNKNOWN, ghidra::TYPE_VOID, and ghidra::Architecture::types.

◆ getBytes()

void ghidra::ArchitectureGhidra::getBytes ( uint1 *  buf,
int4  size,
const Address inaddr 
)

Retrieve bytes in the LoadImage at the given address.

The Ghidra client is queried for a range of bytes, which are returned in the given array. This method throws a DataUnavailError if the provided address doesn't make sense.

Parameters
bufis the preallocated array in which to store the bytes
sizeis the number of bytes requested
inaddris the address in the LoadImage from which to grab bytes

References ghidra::PackedEncode::closeElement(), ghidra::Address::encode(), ghidra::Address::getShortcut(), ghidra::PackedEncode::openElement(), ghidra::Address::printRaw(), readResponseEnd(), readToAnyBurst(), readToResponse(), sin, and sout.

Referenced by ghidra::LoadImageGhidra::loadFill().

◆ getCodeLabel()

string ghidra::ArchitectureGhidra::getCodeLabel ( const Address addr)

Retrieve a label at the given address.

Get the name of the primary symbol at the given address. This is used to fetch within function labels. Only a name is returned.

Parameters
addris the given address
Returns
the symbol name or ""

References ghidra::PackedEncode::closeElement(), ghidra::Address::encode(), ghidra::PackedEncode::openElement(), readResponseEnd(), readStringStream(), readToResponse(), sin, and sout.

◆ getComments()

bool ghidra::ArchitectureGhidra::getComments ( const Address fad,
uint4  flags,
Decoder decoder 
)

Retrieve comments for a particular function.

Ask Ghidra client for all comments associated with one function. The caller must provide the sub-set of properties (Comment::comment_type) for the query to match. A <commentdb> element with <comment> element child for each comment found will be passed back in the given stream decoder.

Parameters
fadis the address of the function to query
flagsspecifies the properties the query will match (must be non-zero)
decoderis the given stream decoder that will hold the result
Returns
true if the query completed successfully

References ghidra::PackedEncode::closeElement(), ghidra::Address::encode(), ghidra::PackedEncode::openElement(), readAll(), sin, sout, and ghidra::PackedEncode::writeUnsignedInteger().

◆ getCPoolRef()

bool ghidra::ArchitectureGhidra::getCPoolRef ( const vector< uintb > &  refs,
Decoder decoder 
)

Resolve a constant pool reference.

The Ghidra client is provided a sequence of 1 or more integer values extracted from a CPOOLREF op. A description of the constant pool record referenced by the integer(s) is passed back in the given stream decoder, or an exception is thrown if the record isn't properly referenced.

Parameters
refsis an array of 1 or more integer values referencing a constant pool record
decoderis the given stream decoder that will hold the result
Returns
true if the query completed successfully

References ghidra::PackedEncode::closeElement(), ghidra::PackedEncode::openElement(), readAll(), sin, sout, ghidra::PackedEncode::writeSignedInteger(), and ghidra::PackedEncode::writeUnsignedInteger().

◆ getDataType()

bool ghidra::ArchitectureGhidra::getDataType ( const string &  name,
uint8  id,
Decoder decoder 
)

Retrieve a data-type description for the given name and id.

The Ghidra client will pass back a <type> element giving details about the data-type.

Parameters
nameis the name of the data-type
idis a unique id associated with the data-type, pass 0 if unknown
decoderis the stream decoder that will hold the result
Returns
true if the query completed successfully

References ghidra::PackedEncode::closeElement(), ghidra::PackedEncode::openElement(), readAll(), sin, sout, ghidra::PackedEncode::writeSignedInteger(), and ghidra::PackedEncode::writeString().

Referenced by ghidra::TypeFactoryGhidra::findById().

◆ getExternalRef()

bool ghidra::ArchitectureGhidra::getExternalRef ( const Address addr,
Decoder decoder 
)

Retrieve a description of an external function.

This asks the Ghidra client to resolve an external reference. This is an address for which the client holds a reference to a function that is elsewhere in memory or not in memory at all. The client should unravel the reference from the given address and pass back either a <function> element describing the referred to function symbol or a <hole> element if the reference can't be resolved.

Parameters
addris the given address
decoderis the stream decoder that will hold the result
Returns
true if the query completes successfully

References ghidra::PackedEncode::closeElement(), ghidra::Address::encode(), ghidra::PackedEncode::openElement(), readAll(), sin, and sout.

◆ getMappedSymbolsXML()

bool ghidra::ArchitectureGhidra::getMappedSymbolsXML ( const Address addr,
Decoder decoder 
)

Get symbols associated with the given address.

The Ghidra client will pass back a <symbol> element, <function> element, or some other related Symbol information, in the given stream decoder. If there is no symbol at the address the client will return a <hole> element describing the size of the memory region that is free of symbols.

Parameters
addris the given address
decoderis the given stream decoder that will hold the result
Returns
true if the query completes successfully

References ghidra::PackedEncode::closeElement(), ghidra::Address::encode(), ghidra::PackedEncode::openElement(), readAll(), sin, and sout.

◆ getNamespacePath()

bool ghidra::ArchitectureGhidra::getNamespacePath ( uint8  id,
Decoder decoder 
)

Get a description of a namespace path.

Ask the Ghidra client to list all namespace elements between the global root and the namespace of the given id. The client will pass back a <parent> element with a <val> child for each namespace in the path, in the given stream decoder

Parameters
idis the given id of the namespace to resolve
decoderis the given stream decoder that will hold the result
Returns
true if the query completed successfully

References ghidra::PackedEncode::closeElement(), ghidra::PackedEncode::openElement(), readAll(), sin, sout, and ghidra::PackedEncode::writeUnsignedInteger().

◆ getPcode()

bool ghidra::ArchitectureGhidra::getPcode ( const Address addr,
Decoder decoder 
)

Get p-code for a single instruction.

Get a description of all the p-code ops for the instruction at the given address.

Parameters
addris the address of the instruction
decoderis the stream decoder for holding the result
Returns
true if the request is successful and ops are ready to be decoded

References ghidra::PackedEncode::closeElement(), ghidra::Address::encode(), ghidra::PackedEncode::openElement(), readAll(), sin, and sout.

Referenced by ghidra::GhidraTranslate::oneInstruction().

◆ getPcodeInject()

bool ghidra::ArchitectureGhidra::getPcodeInject ( const string &  name,
int4  type,
const InjectContext con,
Decoder decoder 
)

Retrieve p-code to inject for a specific context.

The particular injection is named and is of one of the types:

  • CALLFIXUP_TYPE
  • CALLOTHERFIXUP_TYPE
  • CALLMECHANISM_TYPE
  • EXECUTABLEPCODE_TYPE

This and additional context is provided to the Ghidra client which passes back an <inst> element containing individual <op> tags corresponding to individual p-code ops.

Parameters
nameis the name of the injection
typeis the type of injection
conis the context object
decoderis the stream decoder which will hold the result
Returns
true if the query completed successfully

References ghidra::InjectPayload::CALLFIXUP_TYPE, ghidra::InjectPayload::CALLMECHANISM_TYPE, ghidra::InjectPayload::CALLOTHERFIXUP_TYPE, ghidra::PackedEncode::closeElement(), ghidra::InjectContext::encode(), ghidra::PackedEncode::openElement(), readAll(), sin, sout, and ghidra::PackedEncode::writeString().

Referenced by ghidra::InjectPayloadGhidra::inject(), and ghidra::ExecutablePcodeGhidra::inject().

◆ getRegister()

bool ghidra::ArchitectureGhidra::getRegister ( const string &  regname,
Decoder decoder 
)

Retrieve a register description given a name.

Ask the Ghidra client if it knows about a specific processor register. The client responds with a <addr> element describing the storage location of the register.

Parameters
regnameis the name to query for
decoderis the stream decoder that will hold the result
Returns
true if the query completed successfully

References ghidra::PackedEncode::closeElement(), ghidra::PackedEncode::openElement(), readAll(), sin, sout, and ghidra::PackedEncode::writeString().

Referenced by ghidra::GhidraTranslate::getRegister().

◆ getRegisterName()

string ghidra::ArchitectureGhidra::getRegisterName ( const VarnodeData vndata)

Retrieve a register name given its storage location.

Given a storage location and size, ask the Ghidra client if it knows of a register that occupies those bytes. The register name is passed back. The name may not exactly match the given memory range, it may contain it.

Parameters
vndatais the location and size
Returns
the register name or ""

References ghidra::PackedEncode::closeElement(), ghidra::Address::encode(), ghidra::VarnodeData::offset, ghidra::PackedEncode::openElement(), readResponseEnd(), readStringStream(), readToResponse(), sin, ghidra::VarnodeData::size, sout, and ghidra::VarnodeData::space.

Referenced by ghidra::GhidraTranslate::getRegisterName().

◆ getStringData()

void ghidra::ArchitectureGhidra::getStringData ( vector< uint1 > &  buffer,
const Address addr,
Datatype ct,
int4  maxBytes,
bool &  isTrunc 
)

Get string data at a specific address.

The data is always returned as a sequence of bytes in UTF-8 format. The in-memory form of the string may be different than UTF-8 but is always translated into UTF-8 by this method. The caller can inform the in-memory format of the string by specifying a specific string data-type. A maximum number of bytes to return is specified. If this is exceeded, a boolean reference is set to true.

Parameters
bufferwill hold the string bytes in UTF-8 format
addris program Address that holds the string data in memory
ctis string data-type expected
maxBytesis the maximum number of bytes to return
isTruncis the boolean reference indicating whether the data is truncated

References ghidra::PackedEncode::closeElement(), ghidra::Address::encode(), ghidra::Datatype::getId(), ghidra::Datatype::getName(), ghidra::PackedEncode::openElement(), readToAnyBurst(), readToResponse(), sin, sout, ghidra::PackedEncode::writeSignedInteger(), ghidra::PackedEncode::writeString(), and ghidra::PackedEncode::writeUnsignedInteger().

Referenced by ghidra::GhidraStringManager::getStringData().

◆ getTrackedRegisters()

bool ghidra::ArchitectureGhidra::getTrackedRegisters ( const Address addr,
Decoder decoder 
)

Retrieve tracked register values at the given address.

The Ghidra client will pass back a description of registers that have known values at the given address. The response is generally a <tracked_pointset> which contains <set> children which contains a storage location and value.

Parameters
addris the given address
decoderis the stream decoder which will hold the result
Returns
true if the query completed successfully

References ghidra::PackedEncode::closeElement(), ghidra::Address::encode(), ghidra::PackedEncode::openElement(), readAll(), sin, and sout.

Referenced by ghidra::ContextGhidra::getTrackedSet().

◆ getUserOpName()

string ghidra::ArchitectureGhidra::getUserOpName ( int4  index)

Get the name of a user-defined p-code op.

The first operand to a CALLOTHER op indicates the specific user-defined op. This method queries the Ghidra client and passes back the name of the op.

Parameters
indexis the value of the CALLOTHER operand
Returns
the recovered name or ""

References ghidra::PackedEncode::closeElement(), ghidra::PackedEncode::openElement(), readResponseEnd(), readStringStream(), readToResponse(), sin, sout, and ghidra::PackedEncode::writeSignedInteger().

Referenced by ghidra::GhidraTranslate::getUserOpNames().

◆ modifySpaces()

virtual void ghidra::ArchitectureGhidra::modifySpaces ( Translate trans)
inlineprivatevirtual

Modify address spaces as required by this Architecture.

If spaces need to be truncated or otherwise changed from processor defaults, this routine performs the modification.

Parameters
transis the processor disassembly object

Implements ghidra::Architecture.

◆ passJavaException()

void ghidra::ArchitectureGhidra::passJavaException ( ostream &  s,
const string &  tp,
const string &  msg 
)
static

Send an exception message to the Ghidra client.

This generally called because of some sort of alignment issue in the message protocol and lets the client know to abort (and hopefully resync)

Parameters
sis the output stream to the client
tpis the type of exception
msgis the exception message

References writeStringStream().

Referenced by ghidra::GhidraCommand::doit().

◆ printMessage()

void ghidra::ArchitectureGhidra::printMessage ( const string &  message) const
virtual

Print an error message to console.

Write the given message to whatever the registered error stream is

Parameters
messageis the error message

Implements ghidra::Architecture.

References warnings.

◆ readAll()

bool ghidra::ArchitectureGhidra::readAll ( istream &  s,
Decoder decoder 
)
static

Read a whole response as an XML document.

Read up to the beginning of a query response, check for an exception record, otherwise pass back an element for decoding.

Parameters
sis the input stream from the client
decoderis the stream decoder that will hold the result
Returns
true if we received a valid response

References readResponseEnd(), readStringStream(), and readToResponse().

Referenced by getComments(), getCPoolRef(), getDataType(), getExternalRef(), getMappedSymbolsXML(), getNamespacePath(), getPcode(), getPcodeInject(), getRegister(), and getTrackedRegisters().

◆ readBoolStream()

bool ghidra::ArchitectureGhidra::readBoolStream ( istream &  s)
static

Read a boolean value from the client.

Read the string protocol start, a single character, then the protocol end. If the character is a 't', return true, otherwise false.

Parameters
sis the input stream from the client
Returns
the passed back boolean value

References readToAnyBurst().

Referenced by isNameUsed().

◆ readResponseEnd()

void ghidra::ArchitectureGhidra::readResponseEnd ( istream &  s)
static

Read the ending query response protocol marker.

Read the next protocol marker. If it does not indicate the end of a query response, throw an exception

Parameters
sis the input stream from the client

References readToAnyBurst().

Referenced by getBytes(), getCodeLabel(), getRegisterName(), getUserOpName(), isNameUsed(), and readAll().

◆ readStringStream() [1/2]

void ghidra::ArchitectureGhidra::readStringStream ( istream &  s,
string &  res 
)
static

Receive a string from the client.

Characters are read up to the next protocol marked and placed into a string. The protocol marker is consumed and must indicate the end of a string or an exception is thrown.

Parameters
sis the input stream from the client
reswill hold the string

References readToAnyBurst().

Referenced by getCodeLabel(), getRegisterName(), getUserOpName(), ghidra::RegisterProgram::loadParameters(), ghidra::DecompileAt::loadParameters(), ghidra::StructureGraph::loadParameters(), ghidra::SetAction::loadParameters(), ghidra::SetOptions::loadParameters(), readAll(), ghidra::GhidraCapability::readCommand(), and readToResponse().

◆ readStringStream() [2/2]

bool ghidra::ArchitectureGhidra::readStringStream ( istream &  s,
Decoder decoder 
)
static

Receive an encoded string from the client.

The method expects to see protocol markers indicating a string from the client, otherwise it throws and exception. The string is read into the given stream decoder.

Parameters
sis the input stream from the client.
decoderis the given stream decoder that will hold the result
Returns
true if a response was received

References ghidra::Decoder::ingestStream(), and readToAnyBurst().

◆ readToAnyBurst()

int4 ghidra::ArchitectureGhidra::readToAnyBurst ( istream &  s)
static

Read the next message protocol marker.

All communications between the Ghidra client and the decompiler are surrounded by alignment bursts. A burst is 1 or more zero bytes followed by an 0x01 byte, then followed by a code byte. Open alignment (as in open paren) is even. Close alignment is odd. Code bytes are as follows:

  • Command open=2 close=3
  • Query open=4 close=5
  • Command response open=6 close=7
  • Query response open=8 close=9
  • Exception open=a close=b
  • Byte stream open=c close=d
  • String stream open=e close=f

The protocol is as follows:

  • ghidra sends a command
    • [ decompiler sends a query
    • ghidra sends a query response ] zero or more occurences
  • decompiler sends a command response

Commands, queries, and responses all consist of zero or more string streams or byte streams.

In place of any response an exception can be sent. The decompiler can interrupt a command response with a query or exception once the query is finished the response picks up where it left off an exception however permanently cancels the query. Ghidra cannot interrupt either of its responses.

Parameters
sis the input stream from the client
Returns
the command code

Referenced by ghidra::GhidraCommand::doit(), getBytes(), getStringData(), ghidra::GhidraCommand::loadParameters(), ghidra::DeregisterProgram::loadParameters(), readBoolStream(), ghidra::GhidraCapability::readCommand(), readResponseEnd(), readStringStream(), and readToResponse().

◆ readToResponse()

void ghidra::ArchitectureGhidra::readToResponse ( istream &  s)
static

Read the query response protocol marker.

Consume the query response header. If it indicates an exception, read details of the exception and throw JavaError.

Parameters
sis the input stream from the client

References readStringStream(), and readToAnyBurst().

Referenced by getBytes(), getCodeLabel(), getRegisterName(), getStringData(), getUserOpName(), isNameUsed(), and readAll().

◆ segvHandler()

void ghidra::ArchitectureGhidra::segvHandler ( int4  sig)
static

Handler for a segment violation (SIGSEGV) signal.

Catch the signal so the OS doesn't pop up a dialog

Parameters
sigis the OS signal (should always be SIGSEGV)

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

◆ setSendCCode()

void ghidra::ArchitectureGhidra::setSendCCode ( bool  val)
inline

Toggle whether the recovered source code is emitted as part of the main decompile action.

If the toggle is on, the decompiler will emit source code (marked up in an XML document)

Parameters
valis true to enable emitting

◆ setSendParamMeasures()

void ghidra::ArchitectureGhidra::setSendParamMeasures ( bool  val)
inline

Toggle whether recovered parameter information is emitted as part of the main decompile action.

If the toggle is on, the decompiler will emit a more detailed description of what it thinks the input parameters to the function are.

Parameters
valis true enable emitting

◆ setSendSyntaxTree()

void ghidra::ArchitectureGhidra::setSendSyntaxTree ( bool  val)
inline

Toggle whether the data-flow and control-flow is emitted as part of the main decompile action.

If the toggle is on, the decompiler will emit complete descriptions of the graphs.

Parameters
valis true to enable emitting

◆ writeStringStream()

void ghidra::ArchitectureGhidra::writeStringStream ( ostream &  s,
const string &  msg 
)
static

Send a string to the client.

Write out a string with correct protocol markers

Parameters
sis the output stream to the client
msgis the string to send

Referenced by passJavaException(), ghidra::SetAction::sendResult(), and ghidra::SetOptions::sendResult().


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