|
decompiler 1.0.0
|
An implementation of an injection library using the internal SLEIGH engine to build payloads. More...
#include <inject_sleigh.hh>
Public Member Functions | |
| PcodeInjectLibrarySleigh (Architecture *g) | |
| Constructor. | |
| virtual void | decodeDebug (Decoder &decoder) |
| A method for parsing p-code generated externally for use in debugging. | |
| virtual int4 | manualCallFixup (const string &name, const string &snippetstring) |
| Manually add a call-fixup payload given a compilable snippet of p-code source. | |
| virtual int4 | manualCallOtherFixup (const string &name, const string &outname, const vector< string > &inname, const string &snippet) |
| Manually add a callother-fixup payload given a compilable snippet of p-code source. | |
| virtual InjectContext & | getCachedContext (void) |
| Retrieve a reusable context object for this library. | |
| virtual const vector< OpBehavior * > & | getBehaviors (void) |
| Get the array of op-code behaviors for initializing and emulator. | |
Public Member Functions inherited from ghidra::PcodeInjectLibrary | |
| PcodeInjectLibrary (Architecture *g, uint4 tmpbase) | |
| Constructor. | |
| virtual | ~PcodeInjectLibrary (void) |
| Destructor. | |
| uint4 | getUniqueBase (void) const |
| Get the (current) offset for building temporary registers. | |
| int4 | getPayloadId (int4 type, const string &nm) const |
| Map name and type to the payload id. | |
| InjectPayload * | getPayload (int4 id) const |
| Get the InjectPayload by id. | |
| string | getCallFixupName (int4 injectid) const |
| Get the call-fixup name associated with an id. | |
| string | getCallOtherTarget (int4 injectid) const |
| Get the callother-fixup name associated with an id. | |
| string | getCallMechanismName (int4 injectid) const |
| Get the call mechanism name associated with an id. | |
| int4 | decodeInject (const string &src, const string &suffix, int4 tp, Decoder &decoder) |
| Parse and register an injection payload from a stream element. | |
Protected Member Functions | |
| virtual int4 | allocateInject (const string &sourceName, const string &name, int4 type) |
| Allocate a new InjectPayload object. | |
| virtual void | registerInject (int4 injectid) |
| Finalize a payload within the library, once the payload is initialized. | |
Protected Member Functions inherited from ghidra::PcodeInjectLibrary | |
| void | registerCallFixup (const string &fixupName, int4 injectid) |
| Map a call-fixup name to a payload id. | |
| void | registerCallOtherFixup (const string &fixupName, int4 injectid) |
| Map a callother-fixup name to a payload id. | |
| void | registerCallMechanism (const string &fixupName, int4 injectid) |
| Map a call mechanism name to a payload id. | |
| void | registerExeScript (const string &scriptName, int4 injectid) |
| Map a p-code script name to a payload id. | |
Private Member Functions | |
| InjectPayloadDynamic * | forceDebugDynamic (int4 injectid) |
| Force a payload to be dynamic for debug purposes. | |
| void | parseInject (InjectPayload *payload) |
| Convert SLEIGH syntax to p-code templates for the given InjectPayload. | |
Private Attributes | |
| const SleighBase * | slgh |
| The SLEIGH engine for parsing payloads. | |
| vector< OpBehavior * > | inst |
| P-code behaviors used for p-code scripts. | |
| InjectContextSleigh | contextCache |
| Reusable context for emitting p-code payloads. | |
Additional Inherited Members | |
Protected Attributes inherited from ghidra::PcodeInjectLibrary | |
| Architecture * | glb |
| The Architecture to which the injection payloads apply. | |
| uint4 | tempbase |
| Offset within unique space for allocating temporaries within a payload. | |
| vector< InjectPayload * > | injection |
| Registered injections. | |
| map< string, int4 > | callFixupMap |
| Map of registered call-fixup names to injection id. | |
| map< string, int4 > | callOtherFixupMap |
| Map of registered callother-fixup names to injection id. | |
| map< string, int4 > | callMechFixupMap |
| Map of registered mechanism names to injection id. | |
| map< string, int4 > | scriptMap |
| Map of registered script names to ExecutablePcode id. | |
| vector< string > | callFixupNames |
| Map from injectid to call-fixup name. | |
| vector< string > | callOtherTarget |
| Map from injectid to callother-fixup target-op name. | |
| vector< string > | callMechTarget |
| Map from injectid to call-mech name. | |
| vector< string > | scriptNames |
| Map from injectid to script name. | |
An implementation of an injection library using the internal SLEIGH engine to build payloads.
Payloads from compiler specs and other sources are parsed as SLEIGH syntax and stored internally as InjectPayloadSleigh objects.
|
protectedvirtual |
Allocate a new InjectPayload object.
This acts as an InjectPayload factory. The formal name and type of the payload are given, this library allocates a new object that fits with its storage scheme and returns the id.
| sourceName | is a string describing the source of the new payload |
| name | is the formal name of the payload |
| type | is the formal type (CALLFIXUP_TYPE, CALLOTHERFIXUP_TYPE, etc.) of the payload |
Implements ghidra::PcodeInjectLibrary.
References ghidra::InjectPayload::CALLFIXUP_TYPE, ghidra::InjectPayload::CALLOTHERFIXUP_TYPE, ghidra::InjectPayload::EXECUTABLEPCODE_TYPE, ghidra::PcodeInjectLibrary::glb, and ghidra::PcodeInjectLibrary::injection.
Referenced by manualCallFixup(), and manualCallOtherFixup().
|
virtual |
A method for parsing p-code generated externally for use in debugging.
Instantiate a special InjectPayloadDynamic object initialized with an <injectdebug> element. Within the library, this replaces the original InjectPayload, allowing its p-code to be replayed for debugging purposes.
| decoder | is the stream decoder |
Reimplemented from ghidra::PcodeInjectLibrary.
References ghidra::Decoder::closeElement(), ghidra::InjectPayloadDynamic::decodeEntry(), forceDebugDynamic(), ghidra::PcodeInjectLibrary::getPayload(), ghidra::PcodeInjectLibrary::getPayloadId(), ghidra::Decoder::openElement(), ghidra::Decoder::readSignedInteger(), and ghidra::Decoder::readString().
|
private |
Force a payload to be dynamic for debug purposes.
Debug information may include inject information for payloads that aren't dynamic. We substitute a dynamic payload so that analysis uses the debug info to inject, rather than the hard-coded payload information.
| injectid | is the id of the payload to treat dynamic |
References ghidra::PcodeInjectLibrary::glb, and ghidra::PcodeInjectLibrary::injection.
Referenced by decodeDebug().
|
virtual |
Get the array of op-code behaviors for initializing and emulator.
Behaviors are pulled from the underlying architecture in order to initialize the Emulate object which services the p-code script payloads.
Implements ghidra::PcodeInjectLibrary.
References ghidra::Architecture::collectBehaviors(), ghidra::PcodeInjectLibrary::glb, and inst.
|
inlinevirtual |
Retrieve a reusable context object for this library.
The object returned by this method gets passed to the payload inject() method. The clear() method must be called between uses.
Implements ghidra::PcodeInjectLibrary.
References contextCache.
|
virtual |
Manually add a call-fixup payload given a compilable snippet of p-code source.
The snippet is compiled immediately to produce the payload.
| name | is the formal name of the new payload |
| snippetstring | is the compilable snippet of p-code source |
Implements ghidra::PcodeInjectLibrary.
References allocateInject(), ghidra::InjectPayload::CALLFIXUP_TYPE, ghidra::PcodeInjectLibrary::getPayload(), ghidra::InjectPayloadSleigh::parsestring, and registerInject().
|
virtual |
Manually add a callother-fixup payload given a compilable snippet of p-code source.
The snippet is compiled immediately to produce the payload. Symbol names for input and output parameters must be provided to the compiler.
| name | is the formal name of the new payload |
| outname | is the name of the output symbol |
| inname | is the ordered list of input symbol names |
| snippet | is the compilable snippet of p-code source |
Implements ghidra::PcodeInjectLibrary.
References allocateInject(), ghidra::InjectPayload::CALLOTHERFIXUP_TYPE, ghidra::PcodeInjectLibrary::getPayload(), ghidra::InjectPayload::inputlist, ghidra::InjectPayload::orderParameters(), ghidra::InjectPayload::output, ghidra::InjectPayloadSleigh::parsestring, and registerInject().
|
private |
Convert SLEIGH syntax to p-code templates for the given InjectPayload.
The payload parsestring must be populated with SLEIGH synatax. The SLEIGH translator is used to parse the syntax and produce the p-code templates that are then ready to be injected via InjectPayload::inject.
| payload | is the given InjectPayload |
References contextCache, ghidra::InjectPayload::EXECUTABLEPCODE_TYPE, ghidra::AddrSpaceManager::getConstantSpace(), ghidra::InjectParameter::getIndex(), ghidra::InjectPayload::getInput(), ghidra::InjectParameter::getName(), ghidra::InjectPayload::getOutput(), ghidra::InjectPayload::getSource(), ghidra::InjectPayload::getType(), ghidra::PcodeInjectLibrary::glb, ghidra::InjectPayload::isDynamic(), ghidra::InjectPayloadSleigh::parsestring, ghidra::ExecutablePcodeSleigh::parsestring, ghidra::InjectContextSleigh::pos, ghidra::InjectPayload::sizeInput(), ghidra::InjectPayload::sizeOutput(), slgh, ghidra::PcodeInjectLibrary::tempbase, ghidra::InjectPayloadSleigh::tpl, ghidra::ExecutablePcodeSleigh::tpl, and ghidra::Architecture::translate.
Referenced by registerInject().
|
protectedvirtual |
Finalize a payload within the library, once the payload is initialized.
This provides the derived class the opportunity to add the payload name to the symbol tables or do anything else it needs to once the InjectPayload object has been fully initialized.
| injectid | is the id of the InjectPayload to finalize |
Implements ghidra::PcodeInjectLibrary.
References ghidra::InjectPayload::CALLFIXUP_TYPE, ghidra::InjectPayload::CALLMECHANISM_TYPE, ghidra::InjectPayload::CALLOTHERFIXUP_TYPE, ghidra::InjectPayload::EXECUTABLEPCODE_TYPE, ghidra::InjectPayload::getName(), ghidra::InjectPayload::getType(), ghidra::PcodeInjectLibrary::glb, ghidra::PcodeInjectLibrary::injection, ghidra::InjectPayload::isDynamic(), parseInject(), ghidra::PcodeInjectLibrary::registerCallFixup(), ghidra::PcodeInjectLibrary::registerCallMechanism(), ghidra::PcodeInjectLibrary::registerCallOtherFixup(), and ghidra::PcodeInjectLibrary::registerExeScript().
Referenced by manualCallFixup(), and manualCallOtherFixup().