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
Modifier and TypeFieldDescriptionprotected final PcodeArithmetic
<T> protected final SleighLanguage
protected final Register
protected final int
protected final PcodeExecutorStatePiece.Reason
protected final PcodeExecutorState
<T> -
Constructor Summary
ConstructorDescriptionPcodeExecutor
(SleighLanguage language, PcodeArithmetic<T> arithmetic, PcodeExecutorState<T> state, PcodeExecutorStatePiece.Reason reason) Construct an executor with the given bindings -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Handle an unrecognized or unimplemented p-code opbegin
(PcodeProgram program) Begin execution of the given programBegin execution of a list of p-code opsprotected void
branchToAddress
(Address target) Extension point: Called when execution branches to a target addressprotected void
branchToOffset
(T offset, PcodeFrame frame) Set the state's pc to the given offset and finish the frameprotected void
checkLoad
(AddressSpace space, T offset, int size) Extension point: logic preceding a loadprotected void
checkStore
(AddressSpace space, T offset, int size) Extension point: logic preceding a storeprotected void
doExecuteBranch
(PcodeOp op, PcodeFrame frame) Perform the actual logic of a branch p-code opprotected void
doExecuteIndirectBranch
(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 opsvoid
Execute the given binary opvoid
executeBranch
(PcodeOp op, PcodeFrame frame) Execute a branchvoid
executeCall
(PcodeOp op, PcodeFrame frame, PcodeUseropLibrary<T> library) Execute a callvoid
executeCallother
(PcodeOp op, PcodeFrame frame, PcodeUseropLibrary<T> library) Execute a userop callvoid
executeConditionalBranch
(PcodeOp op, PcodeFrame frame) Execute a conditional branchvoid
executeIndirectBranch
(PcodeOp op, PcodeFrame frame) Execute an indirect branchvoid
executeIndirectCall
(PcodeOp op, PcodeFrame frame) Execute an indirect callvoid
executeLoad
(PcodeOp op) Execute a loadvoid
executeReturn
(PcodeOp op, PcodeFrame frame) Execute a returnvoid
executeSleigh
(String source) Compile and execute a block of Sleighvoid
executeStore
(PcodeOp op) Execute a storevoid
executeUnaryOp
(PcodeOp op, UnaryOpBehavior b) Execute the given unary opvoid
finish
(PcodeFrame frame, PcodeUseropLibrary<T> library) Finish execution of a frameGet the arithmetic applied by the executorprotected int
getIntConst
(Varnode vn) Assert that a varnode is constant and get its value as an integer.Get the executor's Sleigh language (processor model)Get the reason for reading state with this executorgetState()
Get the state bound to this executorgetUseropName
(int opNo, PcodeFrame frame) Get the name of a useropprotected void
onMissingUseropDef
(PcodeOp op, PcodeFrame frame, String opName, PcodeUseropLibrary<T> library) Extension point: Behavior when a userop definition was not found in the libraryvoid
skip
(PcodeFrame frame) Skip a single p-code opvoid
step
(PcodeFrame frame, PcodeUseropLibrary<T> library) Step a single p-code opvoid
stepOp
(PcodeOp op, PcodeFrame frame, PcodeUseropLibrary<T> library) Step on 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 on 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
-
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
-
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
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(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:
offset
- the offset (the new value of the program counter)frame
- the frame to finish
-
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(Object, PcodeFrame)
, and/orbranchToAddress(Address)
.- Parameters:
op
- the opframe
- the frame
-
executeConditionalBranch
Execute a conditional branch- Parameters:
op
- the opframe
- the frame
-
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 frame
-
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
-
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
-