Class PcodeExecutor<T>
- Type Parameters:
T- the type of values processed by the executor
- Direct Known Subclasses:
DefaultPcodeThread.PcodeThreadExecutor
This is the kernel of Sleigh expression evaluation and p-code emulation. For a complete example
of a p-code emulator, see PcodeEmulator.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final PcodeArithmetic<T> protected final SleighLanguageprotected final Registerprotected final intprotected final PcodeExecutorStatePiece.Reasonprotected final PcodeExecutorState<T> -
Constructor Summary
ConstructorsConstructorDescriptionPcodeExecutor(SleighLanguage language, PcodeArithmetic<T> arithmetic, PcodeExecutorState<T> state, PcodeExecutorStatePiece.Reason reason) Construct an executor with the given bindings -
Method Summary
Modifier and TypeMethodDescriptionprotected voidHandle an unrecognized or unimplemented p-code opbegin(PcodeProgram program) Begin execution of the given programBegin execution of a list of p-code opsprotected voidbranchInternal(PcodeOp op, PcodeFrame frame, int relative) Branch internallyprotected voidbranchToAddress(PcodeOp op, Address target) Extension point: Called when execution branches to a target addressprotected voidbranchToOffset(PcodeOp op, long offset, PcodeFrame frame) Convert the given offset to the machine's type and delegate tobranchToOffset(PcodeOp, Object, PcodeFrame).protected voidbranchToOffset(PcodeOp op, T offset, PcodeFrame frame) Set the state's pc to the given offset and finish the frameprotected AddresscheckInjectedTarget(Address target) Check and correct the given target address, if it resides in "NO ADDRESS" space.protected voidcheckLoad(AddressSpace space, T offset, int size) Extension point: logic preceding a loadprotected voidcheckStore(AddressSpace space, T offset, int size) Extension point: logic preceding a storeprotected voiddoExecuteBranch(PcodeOp op, PcodeFrame frame) Perform the actual logic of a branch p-code opprotected voiddoExecuteIndirectBranch(PcodeOp op, PcodeFrame frame) Perform the actual logic of an indirect branch p-code opexecute(PcodeProgram program, PcodeUseropLibrary<T> library) Execute a program using the given libraryExecute a list of p-code opsvoidExecute the given binary opvoidexecuteBranch(PcodeOp op, PcodeFrame frame) Execute a branchvoidexecuteCall(PcodeOp op, PcodeFrame frame, PcodeUseropLibrary<T> library) Execute a callvoidexecuteCallother(PcodeOp op, PcodeFrame frame, PcodeUseropLibrary<T> library) Execute a userop callvoidexecuteConditionalBranch(PcodeOp op, PcodeFrame frame) Execute a conditional branchvoidexecuteIndirectBranch(PcodeOp op, PcodeFrame frame) Execute an indirect branchvoidexecuteIndirectCall(PcodeOp op, PcodeFrame frame) Execute an indirect callvoidexecuteLoad(PcodeOp op) Execute a loadvoidexecuteReturn(PcodeOp op, PcodeFrame frame) Execute a returnvoidexecuteSleigh(String source) Compile and execute a block of SleighvoidexecuteStore(PcodeOp op) Execute a storevoidexecuteUnaryOp(PcodeOp op, UnaryOpBehavior b) Execute the given unary opvoidfinish(PcodeFrame frame, PcodeUseropLibrary<T> library) Finish execution of a frameGet the arithmetic applied by the executorprotected Addressprotected intGet the userop number of acallotheropprotected VarnodeGet the predicate varnode of aconditional branchopprotected Varnodeprotected intgetIntConst(Varnode vn) Assert that a varnode is constant and get its value as an integer.Get the executor's Sleigh language (processor model)protected Varnodeprotected AddressSpaceGet the reason for reading state with this executorgetState()Get the state bound to this executorprotected VarnodegetStoreValue(PcodeOp op) Get the value varnode for astoreopgetUseropName(int opNo, PcodeFrame frame) Get the name of a useropprotected voidonMissingUseropDef(PcodeOp op, PcodeFrame frame, String opName, PcodeUseropLibrary<T> library) Extension point: Behavior when a userop definition was not found in the libraryvoidskip(PcodeFrame frame) Skip a single p-code opvoidstep(PcodeFrame frame, PcodeUseropLibrary<T> library) Step a single p-code opvoidstepOp(PcodeOp op, PcodeFrame frame, PcodeUseropLibrary<T> library) Step one p-code op
-
Field Details
-
language
-
arithmetic
-
state
-
reason
-
pc
-
pcSize
protected final int pcSize
-
-
Constructor Details
-
PcodeExecutor
public PcodeExecutor(SleighLanguage language, PcodeArithmetic<T> arithmetic, PcodeExecutorState<T> state, PcodeExecutorStatePiece.Reason reason) Construct an executor with the given bindings- Parameters:
language- the processor languagearithmetic- an implementation of arithmetic p-code opsstate- an implementation of load/store p-code opsreason- a reason for reading the state with this executor
-
-
Method Details
-
getLanguage
Get the executor's Sleigh language (processor model)- Returns:
- the language
-
getArithmetic
Get the arithmetic applied by the executor- Returns:
- the arithmetic
-
getState
Get the state bound to this executor- Returns:
- the state
-
getReason
Get the reason for reading state with this executor- Returns:
- the reason
-
executeSleigh
Compile and execute a block of Sleigh- Parameters:
source- the Sleigh source
-
begin
Begin execution of the given program- Parameters:
program- the program, e.g., from an injection, or a decoded instruction- Returns:
- the frame
-
execute
Execute a program using the given library- Parameters:
program- the program, e.g., from an injection, or a decoded instructionlibrary- the library- Returns:
- the frame
-
begin
Begin execution of a list of p-code ops- Parameters:
code- the opsuseropNames- the map of userop numbers to names- Returns:
- the frame
-
execute
public PcodeFrame execute(List<PcodeOp> code, Map<Integer, String> useropNames, PcodeUseropLibrary<T> library) Execute a list of p-code ops- Parameters:
code- the opsuseropNames- the map of userop numbers to nameslibrary- the library of userops- Returns:
- the frame
-
finish
Finish execution of a frameTODO: This is not really sufficient for continuation after a break, esp. if that break occurs within a nested call back into the executor. This would likely become common when using pCode injection.
- Parameters:
frame- the incomplete framelibrary- the library of userops to use
-
badOp
Handle an unrecognized or unimplemented p-code op- Parameters:
op- the op
-
stepOp
Step one p-code op- Parameters:
op- the opframe- the current framelibrary- the library, invoked in case ofPcodeOp.CALLOTHER
-
step
Step a single p-code op- Parameters:
frame- the frame whose next op to executelibrary- the userop library
-
skip
Skip a single p-code op- Parameters:
frame- the frame whose next op to skip
-
getIntConst
Assert that a varnode is constant and get its value as an integer.Here "constant" means a literal or immediate value. It does not read from the state.
- Parameters:
vn- the varnode- Returns:
- the value
-
executeUnaryOp
Execute the given unary op- Parameters:
op- the opb- the op behavior
-
executeBinaryOp
Execute the given binary op- Parameters:
op- the opb- the op behavior
-
checkLoad
Extension point: logic preceding a load- Parameters:
space- the address space to be loaded fromoffset- the offset about to be loaded fromsize- the size in bytes to be loaded
-
getLoadStoreSpace
- Parameters:
op- the op- Returns:
- the address space (derived from const input 0)
-
getLoadStoreOffset
- Parameters:
op- the op- Returns:
- the offset varnode (input 1)
-
executeLoad
Execute a load- Parameters:
op- the op
-
checkStore
Extension point: logic preceding a store- Parameters:
space- the address space to be stored tooffset- the offset about to be stored tosize- the size in bytes to be stored
-
getStoreValue
Get the value varnode for astoreop- Parameters:
op- the op- Returns:
- the value varnode (input 2)
-
executeStore
Execute a store- Parameters:
op- the op
-
branchToAddress
Extension point: Called when execution branches to a target addressNOTE: This is not called for the fall-through case
- Parameters:
target- the target address
-
branchToOffset
Convert the given offset to the machine's type and delegate tobranchToOffset(PcodeOp, Object, PcodeFrame).Overriding this allows extension to avert attempted uses of the arithmetic, when it may not be applicable.
- Parameters:
op- the opoffset- the offset (the new value of the program counter)frame- the frame to finish
-
branchToOffset
Set the state's pc to the given offset and finish the frameThis implements only part of the p-code control flow semantics. An emulator must also override
branchToAddress(PcodeOp, Address), so that it can update its internal program counter. The emulator could just read the program counter from the state after every completed frame, but receiving it "out of band" is faster.- Parameters:
op- the opoffset- the offset (the new value of the program counter)frame- the frame to finish
-
branchInternal
Branch internally- Parameters:
frame- the framerelative- the relative offset to branch
-
getBranchTarget
- Parameters:
op- the op- Returns:
- the target address (input 0's address)
-
doExecuteBranch
Perform the actual logic of a branch p-code opThis is a separate method, so that overriding
executeBranch(PcodeOp, PcodeFrame)does not implicitly modifyexecuteConditionalBranch(PcodeOp, PcodeFrame).- Parameters:
op- the opframe- the frame
-
executeBranch
Execute a branchThis merely defers to
doExecuteBranch(PcodeOp, PcodeFrame). To instrument the operation, override this. To modify or instrument branching in general, overridedoExecuteBranch(PcodeOp, PcodeFrame),branchToOffset(PcodeOp, Object, PcodeFrame), and/orbranchToAddress(PcodeOp, Address).- Parameters:
op- the opframe- the frame
-
getConditionalBranchPredicate
Get the predicate varnode of aconditional branchop- Parameters:
op- the op- Returns:
- the predicate varnode (input 1)
-
executeConditionalBranch
Execute a conditional branch- Parameters:
op- the opframe- the frame
-
getIndirectBranchTarget
- Parameters:
op- the op- Returns:
- the target varnode (input 0)
-
checkInjectedTarget
Check and correct the given target address, if it resides in "NO ADDRESS" space.At some point, we made a change to set the "target address" of compiled p-code userops to
Address.NO_ADDRESSinstead of pretending its atram:00000000. This is philosophically cleaner, but leads to a practical issue in that the p-code compiler sets the target address of any branch to be in the same space, which for injects, will wind up in "NO ADDRESS." I don't know the use case for having target addresses anywhere but default space, so I'll maintain that behavior, but if it ever lands in "NO ADDRESS," we're going to assume it was an inject, and that the intended target was the default space.- Parameters:
target- the proposed target address- Returns:
- the same or corrected target address
-
doExecuteIndirectBranch
Perform the actual logic of an indirect branch p-code opThis is a separate method, so that overriding
executeIndirectBranch(PcodeOp, PcodeFrame)does not implicitly modifyexecuteIndirectCall(PcodeOp, PcodeFrame)andexecuteReturn(PcodeOp, PcodeFrame).- Parameters:
op- the opframe- the frame
-
executeIndirectBranch
Execute an indirect branchThis merely defers to
doExecuteIndirectBranch(PcodeOp, PcodeFrame). To instrument the operation, override this. To modify or instrument indirect branching in general, overridedoExecuteIndirectBranch(PcodeOp, PcodeFrame).- Parameters:
op- the opframe- the frame
-
executeCall
Execute a call- Parameters:
op- the opframe- the framelibrary- the userop library
-
executeIndirectCall
Execute an indirect call- Parameters:
op- the opframe- the frame
-
getUseropName
Get the name of a userop- Parameters:
opNo- the userop numberframe- the frame- Returns:
- the name, or null if it is not defined
-
getCallotherOpNumber
Get the userop number of acallotherop- Parameters:
op- the op- Returns:
- the userop number (const input 0)
-
executeCallother
Execute a userop call- Parameters:
op- the opframe- the framelibrary- the library of userops
-
onMissingUseropDef
protected void onMissingUseropDef(PcodeOp op, PcodeFrame frame, String opName, PcodeUseropLibrary<T> library) Extension point: Behavior when a userop definition was not found in the libraryThe default behavior is to throw a
SleighLinkException.- Parameters:
op- the opframe- the frameopName- the name of the p-code useroplibrary- the library
-
executeReturn
Execute a return- Parameters:
op- the opframe- the frame
-