Enum Class TaintPartsFactory
- All Implemented Interfaces:
AuxEmulatorPartsFactory<TaintVec>,Serializable,Comparable<TaintPartsFactory>,Constable
This is probably the most straightforward means of implementing a concrete-plus-auxiliary
emulator in Ghidra. For our case, the auxiliary piece is the TaintVec. Ideally, the
auxiliary piece implements the analog of a byte array, so that each byte in the concrete piece
corresponds to an element in the abstract piece. We've done that here by letting each taint set
in the vector be the taint on the corresponding byte. Each part we implement must adhere to that
rule. For an overview of the parts of a p-code emulator, see PcodeEmulator.
As recommended by the documentation, we've implemented the factory as a singleton. As presented in the source, we'll visit each component in this order:
- P-code Arithmetic:
TaintPcodeArithmetic - Userop Library:
TaintPcodeUseropLibrary - P-code Executor:
TaintPcodeThreadExecutor - Machine State:
TaintPcodeExecutorState
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptionDefaultPcodeThread.PcodeThreadExecutor<org.apache.commons.lang3.tuple.Pair<byte[], TaintVec>> createExecutor(AuxPcodeEmulator<TaintVec> emulator, DefaultPcodeThread<org.apache.commons.lang3.tuple.Pair<byte[], TaintVec>> thread) Create an executor for the given threadPcodeExecutorState<org.apache.commons.lang3.tuple.Pair<byte[], TaintVec>> createLocalState(AuxPcodeEmulator<TaintVec> emulator, PcodeThread<org.apache.commons.lang3.tuple.Pair<byte[], TaintVec>> thread, BytesPcodeExecutorStatePiece concrete, PcodeStateCallbacks cb) Create the local (register) state of a new emulatorPcodeUseropLibrary<org.apache.commons.lang3.tuple.Pair<byte[], TaintVec>> createLocalUseropLibrary(AuxPcodeEmulator<TaintVec> emulator, PcodeThread<org.apache.commons.lang3.tuple.Pair<byte[], TaintVec>> thread) Create a userop library for a given threadPcodeUseropLibrary<org.apache.commons.lang3.tuple.Pair<byte[], TaintVec>> createLocalUseropStub(AuxPcodeEmulator<TaintVec> emulator) Create a stub userop library for the emulator's threadsPcodeExecutorState<org.apache.commons.lang3.tuple.Pair<byte[], TaintVec>> createSharedState(AuxPcodeEmulator<TaintVec> emulator, BytesPcodeExecutorStatePiece concrete, PcodeStateCallbacks cb) Create the shared (memory) state of a new emulatorPcodeUseropLibrary<org.apache.commons.lang3.tuple.Pair<byte[], TaintVec>> createSharedUseropLibrary(AuxPcodeEmulator<TaintVec> emulator) Create the userop library for the emulator (used by all threads)getArithmetic(Language language) Get the arithmetic for the emulator given a target languagestatic TaintPartsFactoryReturns the enum constant of this class with the specified name.static TaintPartsFactory[]values()Returns an array containing the constants of this enum class, in the order they are declared.Methods inherited from class java.lang.Enum
clone, compareTo, describeConstable, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOfMethods inherited from interface ghidra.pcode.emu.auxiliary.AuxEmulatorPartsFactory
createThread
-
Enum Constant Details
-
INSTANCE
This singleton factory instance
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
getArithmetic
Get the arithmetic for the emulator given a target languageHere we simply return the arithmetic for taint vectors for the emulator's language.
- Specified by:
getArithmeticin interfaceAuxEmulatorPartsFactory<TaintVec>- Parameters:
language- the language- Returns:
- the arithmetic
-
createLocalUseropStub
public PcodeUseropLibrary<org.apache.commons.lang3.tuple.Pair<byte[],TaintVec>> createLocalUseropStub(AuxPcodeEmulator<TaintVec> emulator) Create a stub userop library for the emulator's threadsWe have no thread-specific userops to add, which means we also have no need for stubs, so here we just return the empty library.
- Specified by:
createLocalUseropStubin interfaceAuxEmulatorPartsFactory<TaintVec>- Parameters:
emulator- the emulator- Returns:
- the library of stubs
-
createLocalUseropLibrary
public PcodeUseropLibrary<org.apache.commons.lang3.tuple.Pair<byte[],TaintVec>> createLocalUseropLibrary(AuxPcodeEmulator<TaintVec> emulator, PcodeThread<org.apache.commons.lang3.tuple.Pair<byte[], TaintVec>> thread) Create a userop library for a given threadWe have no thread-specific userops to add, so here we just return the empty library.
- Specified by:
createLocalUseropLibraryin interfaceAuxEmulatorPartsFactory<TaintVec>- Parameters:
emulator- the emulatorthread- the thread- Returns:
- the userop library
-
createExecutor
public DefaultPcodeThread.PcodeThreadExecutor<org.apache.commons.lang3.tuple.Pair<byte[],TaintVec>> createExecutor(AuxPcodeEmulator<TaintVec> emulator, DefaultPcodeThread<org.apache.commons.lang3.tuple.Pair<byte[], TaintVec>> thread) Create an executor for the given threadThis allows the implementor to override or intercept the logic for individual p-code operations that would not otherwise be possible in the arithmetic, e.g., to print diagnostics on a conditional branch.
We'd like to instrument conditional branches to check for taint, so we'll need a custom executor. We construct it here.
- Specified by:
createExecutorin interfaceAuxEmulatorPartsFactory<TaintVec>- Parameters:
emulator- the emulatorthread- the thread- Returns:
- the executor
-
createLocalState
public PcodeExecutorState<org.apache.commons.lang3.tuple.Pair<byte[],TaintVec>> createLocalState(AuxPcodeEmulator<TaintVec> emulator, PcodeThread<org.apache.commons.lang3.tuple.Pair<byte[], TaintVec>> thread, BytesPcodeExecutorStatePiece concrete, PcodeStateCallbacks cb) Create the local (register) state of a new emulatorThis is usually composed of pieces using
PairedPcodeExecutorStatePiece, but it does not have to be. It must incorporate the concrete piece provided. It should be self contained and relatively fast.To track what variables in the machine state are tainted, we need a taint state. We construct the part for a thread's registers and temporary (unique) variables here.
- Specified by:
createLocalStatein interfaceAuxEmulatorPartsFactory<TaintVec>- Parameters:
emulator- the emulatorthread- the threadconcrete- the concrete piececb- callbacks to receive emulation events- Returns:
- the composed state
-