decompiler
1.0.0
|
Emulation based on (existing) PcodeOps and Varnodes. More...
#include <emulateutil.hh>
Public Member Functions | |
EmulatePcodeOp (Architecture *g) | |
Constructor. More... | |
void | setCurrentOp (PcodeOp *op) |
Establish the current PcodeOp being emulated. More... | |
virtual Address | getExecuteAddress (void) const |
Get the address of the current instruction being executed. | |
virtual void | setVarnodeValue (Varnode *vn, uintb val)=0 |
Given a specific Varnode, set the given value for it in the current machine state. More... | |
virtual uintb | getVarnodeValue (Varnode *vn) const =0 |
Given a specific Varnode, retrieve the current value for it from the machine state. More... | |
Public Member Functions inherited from Emulate | |
Emulate (void) | |
generic emulator constructor | |
void | setHalt (bool val) |
Set the halt state of the emulator. More... | |
bool | getHalt (void) const |
Get the halt state of the emulator. More... | |
virtual void | setExecuteAddress (const Address &addr)=0 |
Set the address of the next instruction to emulate. | |
void | executeCurrentOp (void) |
Do a single pcode op step. More... | |
Protected Member Functions | |
virtual uintb | getLoadImageValue (AddrSpace *spc, uintb offset, int4 sz) const |
Pull a value from the load-image given a specific address. More... | |
virtual void | executeUnary (void) |
Execute a unary arithmetic/logical operation. | |
virtual void | executeBinary (void) |
Execute a binary arithmetic/logical operation. | |
virtual void | executeLoad (void) |
Standard behavior for a p-code LOAD. | |
virtual void | executeStore (void) |
Standard behavior for a p-code STORE. | |
virtual bool | executeCbranch (void) |
Check if the conditional of a CBRANCH is true. More... | |
virtual void | executeMultiequal (void) |
Standard behavior for a MULTIEQUAL (phi-node) | |
virtual void | executeIndirect (void) |
Standard behavior for an INDIRECT op. | |
virtual void | executeSegmentOp (void) |
Behavior for a SEGMENTOP. | |
virtual void | executeCpoolRef (void) |
Standard behavior for a CPOOLREF (constant pool reference) op. | |
virtual void | executeNew (void) |
Standard behavior for (low-level) NEW op. | |
Protected Member Functions inherited from Emulate | |
virtual void | executeBranch (void)=0 |
Standard behavior for a BRANCH. More... | |
virtual void | executeBranchind (void)=0 |
Standard behavior for a BRANCHIND. | |
virtual void | executeCall (void)=0 |
Standard behavior for a p-code CALL. | |
virtual void | executeCallind (void)=0 |
Standard behavior for a CALLIND. | |
virtual void | executeCallother (void)=0 |
Standard behavior for a user-defined p-code op. | |
virtual void | fallthruOp (void)=0 |
Standard p-code fall-thru semantics. | |
Protected Attributes | |
Architecture * | glb |
The underlying Architecture for the program being emulated. | |
PcodeOp * | currentOp |
Current PcodeOp being executed. | |
PcodeOp * | lastOp |
Last PcodeOp that was executed. | |
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. | |
Emulation based on (existing) PcodeOps and Varnodes.
This is still an abstract class. It does most of the work of emulating p-code using PcodeOp and Varnode objects (as opposed to PcodeOpRaw and VarnodeData). This class leaves implementation of control-flow to the derived class. This class implements most operations by going through new virtual methods:
The default executeLoad() implementation pulls values from the underlying LoadImage object. The following p-code ops are provided NULL implementations, as some tasks don't need hard emulation of them:
EmulatePcodeOp::EmulatePcodeOp | ( | Architecture * | g | ) |
Constructor.
g | is the Architecture providing the LoadImage |
|
protectedvirtual |
Check if the conditional of a CBRANCH is true.
This routine only checks if the condition for a p-code CBRANCH is true. It does not perform the actual branch.
Implements Emulate.
References currentOp, PcodeOp::getIn(), getVarnodeValue(), and PcodeOp::isBooleanFlip().
|
protectedvirtual |
Pull a value from the load-image given a specific address.
A contiguous chunk of memory is pulled from the load-image and returned as a constant value, respecting the endianess of the address space. The default implementation of this method pulls the value directly from the LoadImage object.
spc | is the address space to pull the value from |
offset | is the starting address offset (from within the space) to pull the value from |
sz | is the number of bytes to pull from memory |
References byte_swap(), calc_mask(), glb, AddrSpace::isBigEndian(), Architecture::loader, and LoadImage::loadFill().
Referenced by executeLoad(), EmulateSnippet::executeLoad(), EmulateFunction::getVarnodeValue(), and EmulateSnippet::getVarnodeValue().
|
pure virtual |
Given a specific Varnode, retrieve the current value for it from the machine state.
This is the placeholder internal operation for obtaining a Varnode value during emulation. The value is loaded using the Varnode as the address and storage size.
vn | is the specific Varnode |
Implemented in EmulateFunction.
Referenced by executeBinary(), EmulateSnippet::executeBinary(), executeCbranch(), EmulateSnippet::executeCbranch(), executeIndirect(), executeLoad(), EmulateSnippet::executeLoad(), executeMultiequal(), executeSegmentOp(), executeUnary(), EmulateSnippet::executeUnary(), getExecuteAddress(), and EmulateSnippet::setVarnodeValue().
|
inline |
Establish the current PcodeOp being emulated.
op | is the PcodeOp that will next be executed via executeCurrentOp() |
References Emulate::currentBehave, TypeOp::getBehavior(), and PcodeOp::getOpcode().
Referenced by EmulateFunction::emulatePath(), EmulateSnippet::executeBranch(), EmulateSnippet::fallthruOp(), EmulateSnippet::resetMemory(), and EmulateSnippet::setExecuteAddress().
|
pure virtual |
Given a specific Varnode, set the given value for it in the current machine state.
This is the placeholder internal operation for setting a Varnode value during emulation. The value is stored using the Varnode as the address and storage size.
vn | is the specific Varnode |
val | is the constant value to store |
Implemented in EmulateFunction.
Referenced by executeBinary(), EmulateSnippet::executeBinary(), executeIndirect(), executeLoad(), EmulateSnippet::executeLoad(), executeMultiequal(), executeSegmentOp(), executeUnary(), EmulateSnippet::executeUnary(), and getExecuteAddress().