Ghidra Decompiler Analysis Engine
|
Emulate a snippet of PcodeOps out of a functional context. More...
#include <emulateutil.hh>
Public Member Functions | |
virtual | ~EmulateSnippet (void) |
Destructor. | |
virtual void | setExecuteAddress (const Address &addr) |
Set the address of the next instruction to emulate. | |
virtual Address | getExecuteAddress (void) const |
Get the address of the current instruction being executed. | |
void | resetMemory (void) |
Reset the emulation snippet. More... | |
PcodeEmit * | buildEmitter (const vector< OpBehavior * > &inst, uintb uniqReserve) |
Provide the caller with an emitter for building the p-code snippet. More... | |
bool | checkForLegalCode (void) const |
Check for p-code that is deemed illegal for a snippet. More... | |
void | setCurrentOp (int4 i) |
Set the current executing p-code op by index. More... | |
void | setVarnodeValue (uintb offset, uintb val) |
Set a temporary register value in the machine state. More... | |
uintb | getVarnodeValue (VarnodeData *vn) const |
Retrieve the value of a Varnode from the current machine state. More... | |
uintb | getTempValue (uintb offset) const |
Retrieve a temporary register value directly. More... | |
Public Member Functions inherited from Emulate | |
void | setHalt (bool val) |
Set the halt state of the emulator. More... | |
bool | getHalt (void) const |
Get the halt state of the emulator. More... | |
void | executeCurrentOp (void) |
Do a single pcode op step. More... | |
Additional Inherited Members | |
Protected Attributes inherited from Emulate | |
bool | emu_halted |
Set to true if the emulator is halted. | |
OpBehavior * | currentBehave |
Behavior of the next op to execute. | |
Emulate a snippet of PcodeOps out of a functional context.
Emulation is performed on a short sequence (snippet) of PcodeOpRaw objects. Control-flow emulation is limited to this snippet; BRANCH and CBRANCH operations can happen using p-code relative branching. Executing BRANCHIND, CALL, CALLIND, CALLOTHER, STORE, MULTIEQUAL, INDIRECT, SEGMENTOP, CPOOLOP, and NEW ops is treated as illegal and an exception is thrown. Expressions can only use temporary registers or read from the LoadImage.
The set of PcodeOpRaw objects in the snippet is provided by emitting p-code to the object returned by buildEmitter(). This is designed for one-time initialization of this class, which can be repeatedly used by calling resetMemory() between executions.
PcodeEmit * EmulateSnippet::buildEmitter | ( | const vector< OpBehavior * > & | inst, |
uintb | uniqReserve | ||
) |
Provide the caller with an emitter for building the p-code snippet.
Any p-code produced by the PcodeEmit, when triggered by the caller, becomes part of the snippet that will get emulated by this. The caller should free the PcodeEmit object immediately after use.
inst | is the opcode to behavior map the emitter will use |
uniqReserve | is the starting offset within the unique address space for any temporary registers |
bool EmulateSnippet::checkForLegalCode | ( | void | ) | const |
Check for p-code that is deemed illegal for a snippet.
This method facilitates enforcement of the formal rules for snippet code.
uintb EmulateSnippet::getTempValue | ( | uintb | offset | ) | const |
Retrieve a temporary register value directly.
This allows the user to obtain the final value of the snippet calculation, without having to have the Varnode object in hand.
offset | is the offset of the temporary register to retrieve |
uintb EmulateSnippet::getVarnodeValue | ( | VarnodeData * | vn | ) | const |
Retrieve the value of a Varnode from the current machine state.
If the Varnode is a temporary registers, the storage offset is used to look up the value from the machine state cache. If the Varnode represents a RAM location, the value is pulled directly out of the load-image. If the value does not exist, a "Read before write" exception is thrown.
vn | is the Varnode to read |
|
inline |
Reset the emulation snippet.
Reset the memory state, and set the first p-code op as current.
|
inline |
Set the current executing p-code op by index.
The i-th p-code op in the snippet sequence is set as the currently executing op.
i | is the index |
|
inline |
Set a temporary register value in the machine state.
The temporary Varnode's storage offset is used as key into the machine state map.
offset | is the temporary storage offset |
val | is the value to put into the machine state |