decompiler
1.0.0
|
An implementation of the Architecture interface and connection to a Ghidra client. More...
#include <ghidra_arch.hh>
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 ®name, 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... | |
ProtoModel * | getModel (const string &nm) const |
Get a specific PrototypeModel. More... | |
bool | hasModel (const string &nm) const |
Does this Architecture have a specific PrototypeModel. More... | |
ProtoModel * | createUnknownModel (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... | |
AddrSpace * | getSpaceBySpacebase (const Address &loc, int4 size) const |
Get space associated with a spacebase register. More... | |
const LanedRegister * | getLanedRegister (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... | |
SegmentOp * | getSegmentOp (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... | |
AddrSpace * | getSpaceByName (const string &nm) const |
Get address space by name. More... | |
AddrSpace * | getSpaceByShortcut (char sc) const |
Get address space from its shortcut. More... | |
AddrSpace * | getIopSpace (void) const |
Get the internal pcode op space. More... | |
AddrSpace * | getFspecSpace (void) const |
Get the internal callspec space. More... | |
AddrSpace * | getJoinSpace (void) const |
Get the joining space. More... | |
AddrSpace * | getStackSpace (void) const |
Get the stack space for this processor. More... | |
AddrSpace * | getUniqueSpace (void) const |
Get the temporary register space for this processor. More... | |
AddrSpace * | getDefaultCodeSpace (void) const |
Get the default address space of this processor. More... | |
AddrSpace * | getDefaultDataSpace (void) const |
Get the default address space where data is stored. More... | |
AddrSpace * | getConstantSpace (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... | |
AddrSpace * | getSpace (int4 i) const |
Get an address space via its index. More... | |
AddrSpace * | getNextSpaceInOrder (AddrSpace *spc) const |
Get the next contiguous address space. More... | |
JoinRecord * | findAddJoin (const vector< VarnodeData > &pieces, uint4 logicalsize) |
Get (or create) JoinRecord for pieces. More... | |
JoinRecord * | findJoin (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 Scope * | buildDatabase (DocumentStorage &store) |
Build the database and global scope for this executable. More... | |
virtual Translate * | buildTranslator (DocumentStorage &store) |
Build the Translator object. More... | |
virtual void | buildLoader (DocumentStorage &store) |
Build the LoadImage object and load the executable image. More... | |
virtual PcodeInjectLibrary * | buildPcodeInjectLibrary (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) | |
Database * | symboltab |
Memory map of global variables and functions. | |
ContextDatabase * | context |
Map from addresses to context settings. | |
map< string, ProtoModel * > | protoModels |
Parsed forms of possible prototypes. | |
ProtoModel * | defaultfp |
Parsed form of default prototype. | |
VarnodeData | defaultReturnAddr |
Default storage location of return address (for current function) | |
ProtoModel * | evalfp_current |
Function proto to use when evaluating current function. | |
ProtoModel * | evalfp_called |
Function proto to use when evaluating called functions. | |
TypeFactory * | types |
List of types for this binary. | |
const Translate * | translate |
Translation method for this binary. | |
LoadImage * | loader |
Method for loading portions of binary. | |
PcodeInjectLibrary * | pcodeinjectlib |
Pcode injection manager. | |
RangeList | nohighptr |
Ranges for which high-level pointers are not possible. | |
CommentDatabase * | commentdb |
Comments for this architecture. | |
StringManager * | stringManager |
Manager of decoded strings. | |
ConstantPool * | cpool |
Deferred constant values. | |
PrintLanguage * | |
Current high-level language printer. | |
vector< PrintLanguage * > | printlist |
List of high-level language printers supported. | |
OptionDatabase * | options |
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< LanedRegister > | lanerecords |
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... | |
ProtoModel * | decodeProto (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 | |
AddrSpace * | decodeSpace (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... | |
JoinRecord * | findJoinInternal (uintb offset) const |
Find JoinRecord for offset in the join space. More... | |
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:
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.
pspec | is the processor specification presented as an XML string |
cspec | is the compiler specification presented as an XML string |
tspec | is a stripped down form of the SLEIGH specification presented as an XML string |
corespec | is a list of core data-types presented as a <coretypes> XML tag |
i | is the input stream from the Ghidra client |
o | is 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.
|
privatevirtual |
Build the comment database.
Build the container that holds comments in this Architecture.
store | may hold configuration information |
Implements ghidra::Architecture.
References ghidra::Architecture::commentdb.
|
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.
store | may hold configuration information |
Implements ghidra::Architecture.
References ghidra::Architecture::cpool.
|
privatevirtual |
Build the Context database.
Build the database which holds status register settings and other information that can affect disassembly depending on context.
store | may hold configuration information |
Implements ghidra::Architecture.
References ghidra::Architecture::context.
|
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.
store | is the storage for any configuration data |
Reimplemented from ghidra::Architecture.
References ghidra::Database::attachScope(), and ghidra::Architecture::symboltab.
|
privatevirtual |
Build the LoadImage object and load the executable image.
store | may hold configuration information |
Implements ghidra::Architecture.
References ghidra::Architecture::loader.
|
privatevirtual |
Build the injection library.
This creates the container for p-code injections. It is initially empty.
Implements ghidra::Architecture.
|
privatevirtual |
Load any relevant specification files.
Processor/architecture specific configuration files are loaded into the XML store
store | is 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.
|
privatevirtual |
Build the string manager.
Build container that holds decoded strings for this Architecture.
store | may hold configuration information |
Implements ghidra::Architecture.
References ghidra::Architecture::stringManager.
|
privatevirtual |
Build any symbols from spec files.
Formal symbols described in a spec file are added to the global scope.
store | may hold symbol elements |
Implements ghidra::Architecture.
References ghidra::Database::clearPropertyRange(), ghidra::XmlDecode::closeElement(), ghidra::ElementId::getName(), ghidra::XmlDecode::getNextAttributeId(), ghidra::Address::getOffset(), ghidra::Address::getSpace(), ghidra::DocumentStorage::getTag(), ghidra::AddrSpace::getWordSize(), ghidra::XmlDecode::openElement(), ghidra::AddrSpaceManager::parseAddressSimple(), ghidra::XmlDecode::peekElement(), ghidra::XmlDecode::readBool(), ghidra::XmlDecode::readSignedInteger(), ghidra::XmlDecode::readString(), ghidra::Database::setPropertyRange(), ghidra::Architecture::symboltab, and ghidra::Varnode::volatil.
|
privatevirtual |
Build the Translator object.
This builds the main disassembly component for the Architecture This does not initially the engine for a specific processor.
store | may hold configuration information |
Implements ghidra::Architecture.
|
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.
store | contains 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.
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.
buf | is the preallocated array in which to store the bytes |
size | is the number of bytes requested |
inaddr | is 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().
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.
addr | is the given address |
References ghidra::PackedEncode::closeElement(), ghidra::Address::encode(), ghidra::PackedEncode::openElement(), readResponseEnd(), readStringStream(), readToResponse(), sin, and sout.
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.
fad | is the address of the function to query |
flags | specifies the properties the query will match (must be non-zero) |
decoder | is the given stream decoder that will hold the result |
References ghidra::PackedEncode::closeElement(), ghidra::Address::encode(), ghidra::PackedEncode::openElement(), readAll(), sin, sout, and ghidra::PackedEncode::writeUnsignedInteger().
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.
refs | is an array of 1 or more integer values referencing a constant pool record |
decoder | is the given stream decoder that will hold the result |
References ghidra::PackedEncode::closeElement(), ghidra::PackedEncode::openElement(), readAll(), sin, sout, ghidra::PackedEncode::writeSignedInteger(), and ghidra::PackedEncode::writeUnsignedInteger().
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.
name | is the name of the data-type |
id | is a unique id associated with the data-type, pass 0 if unknown |
decoder | is the stream decoder that will hold the result |
References ghidra::PackedEncode::closeElement(), ghidra::PackedEncode::openElement(), readAll(), sin, sout, ghidra::PackedEncode::writeSignedInteger(), and ghidra::PackedEncode::writeString().
Referenced by ghidra::TypeFactoryGhidra::findById().
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.
addr | is the given address |
decoder | is the stream decoder that will hold the result |
References ghidra::PackedEncode::closeElement(), ghidra::Address::encode(), ghidra::PackedEncode::openElement(), readAll(), sin, and sout.
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.
addr | is the given address |
decoder | is the given stream decoder that will hold the result |
References ghidra::PackedEncode::closeElement(), ghidra::Address::encode(), ghidra::PackedEncode::openElement(), readAll(), sin, and sout.
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
id | is the given id of the namespace to resolve |
decoder | is the given stream decoder that will hold the result |
References ghidra::PackedEncode::closeElement(), ghidra::PackedEncode::openElement(), readAll(), sin, sout, and ghidra::PackedEncode::writeUnsignedInteger().
Get p-code for a single instruction.
Get a description of all the p-code ops for the instruction at the given address.
addr | is the address of the instruction |
decoder | is the stream decoder for holding the result |
References ghidra::PackedEncode::closeElement(), ghidra::Address::encode(), ghidra::PackedEncode::openElement(), readAll(), sin, and sout.
Referenced by ghidra::GhidraTranslate::oneInstruction().
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:
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.
name | is the name of the injection |
type | is the type of injection |
con | is the context object |
decoder | is the stream decoder which will hold the result |
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().
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.
regname | is the name to query for |
decoder | is the stream decoder that will hold the result |
References ghidra::PackedEncode::closeElement(), ghidra::PackedEncode::openElement(), readAll(), sin, sout, and ghidra::PackedEncode::writeString().
Referenced by ghidra::GhidraTranslate::getRegister().
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.
vndata | is the location and size |
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().
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.
buffer | will hold the string bytes in UTF-8 format |
addr | is program Address that holds the string data in memory |
ct | is string data-type expected |
maxBytes | is the maximum number of bytes to return |
isTrunc | is 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().
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.
addr | is the given address |
decoder | is the stream decoder which will hold the result |
References ghidra::PackedEncode::closeElement(), ghidra::Address::encode(), ghidra::PackedEncode::openElement(), readAll(), sin, and sout.
Referenced by ghidra::ContextGhidra::getTrackedSet().
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.
index | is the value of the CALLOTHER operand |
References ghidra::PackedEncode::closeElement(), ghidra::PackedEncode::openElement(), readResponseEnd(), readStringStream(), readToResponse(), sin, sout, and ghidra::PackedEncode::writeSignedInteger().
Referenced by ghidra::GhidraTranslate::getUserOpNames().
|
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.
trans | is the processor disassembly object |
Implements ghidra::Architecture.
|
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)
s | is the output stream to the client |
tp | is the type of exception |
msg | is the exception message |
References writeStringStream().
Referenced by ghidra::GhidraCommand::doit().
|
virtual |
Print an error message to console.
Write the given message to whatever the registered error stream is
message | is the error message |
Implements ghidra::Architecture.
References warnings.
|
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.
s | is the input stream from the client |
decoder | is the stream decoder that will hold the result |
References readResponseEnd(), readStringStream(), and readToResponse().
Referenced by getComments(), getCPoolRef(), getDataType(), getExternalRef(), getMappedSymbolsXML(), getNamespacePath(), getPcode(), getPcodeInject(), getRegister(), and getTrackedRegisters().
|
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.
s | is the input stream from the client |
References readToAnyBurst().
Referenced by isNameUsed().
|
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
s | is the input stream from the client |
References readToAnyBurst().
Referenced by getBytes(), getCodeLabel(), getRegisterName(), getUserOpName(), isNameUsed(), and readAll().
|
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.
s | is the input stream from the client |
res | will 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().
|
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.
s | is the input stream from the client. |
decoder | is the given stream decoder that will hold the result |
References ghidra::Decoder::ingestStream(), and readToAnyBurst().
|
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:
The protocol is as follows:
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.
s | is the input stream from the client |
Referenced by ghidra::GhidraCommand::doit(), getBytes(), getStringData(), ghidra::GhidraCommand::loadParameters(), ghidra::DeregisterProgram::loadParameters(), readBoolStream(), ghidra::GhidraCapability::readCommand(), readResponseEnd(), readStringStream(), and readToResponse().
|
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.
s | is the input stream from the client |
References readStringStream(), and readToAnyBurst().
Referenced by getBytes(), getCodeLabel(), getRegisterName(), getStringData(), getUserOpName(), isNameUsed(), and readAll().
|
static |
Handler for a segment violation (SIGSEGV) signal.
Catch the signal so the OS doesn't pop up a dialog
sig | is the OS signal (should always be SIGSEGV) |
Referenced by ghidra::GhidraDecompCapability::initialize().
|
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)
val | is true to enable emitting |
|
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.
val | is true enable emitting |
|
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.
val | is true to enable emitting |
|
static |
Send a string to the client.
Write out a string with correct protocol markers
s | is the output stream to the client |
msg | is the string to send |
Referenced by passJavaException(), ghidra::SetAction::sendResult(), and ghidra::SetOptions::sendResult().