Enum Class TaintPcodeArithmetic
- All Implemented Interfaces:
PcodeArithmetic<TaintVec>,Serializable,Comparable<TaintPcodeArithmetic>,Constable
The p-code arithmetic serves as the bridge between p-code and the domain of analysis. Technically, the state itself also contributes minimally to that bridge.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>Nested classes/interfaces inherited from interface ghidra.pcode.exec.PcodeArithmetic
PcodeArithmetic.Purpose -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionThe instance for big-endian languagesThe instance for little-endian languages -
Field Summary
Fields inherited from interface ghidra.pcode.exec.PcodeArithmetic
SIZEOF_SIZEOF -
Method Summary
Modifier and TypeMethodDescriptionApply a binary operator to the given inputsApply a binary operator to the given inputstatic TaintPcodeArithmeticforEndian(boolean bigEndian) Get the taint arithmetic for the given endiannessstatic TaintPcodeArithmeticforLanguage(Language language) Get the taint arithmetic for the given langaugefromConst(byte[] value) Convert the given constant concrete value to typeThaving the same size.Get the type of values over which this arithmetic operates.Get the endianness of this arithmeticmodAfterLoad(int sizeinOffset, AddressSpace space, TaintVec inOffset, int sizeinValue, TaintVec inValue) Apply any modifications after a value is loadedmodBeforeStore(int sizeinOffset, AddressSpace space, TaintVec inOffset, int sizeinValue, TaintVec inValue) Apply any modifications before a value is storedlongGet the size in bytes, if possible, of the given abstract valuebyte[]toConcrete(TaintVec value, PcodeArithmetic.Purpose purpose) Convert, if possible, the given abstract value to a concrete byte arrayApply a unary operator to the given inputstatic TaintPcodeArithmeticReturns the enum constant of this class with the specified name.static TaintPcodeArithmetic[]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.exec.PcodeArithmetic
fromConst, fromConst, fromConst, fromConst, fromConst, fromConst, fromConst, fromConst, fromConst, fromConst, fromConst, isTrue, modAfterLoad, modBeforeStore, ptrAdd, ptrSub, sizeOfAbstract, toAddress, toBigInteger, toDouble, toFloat, toLong, toRegisterValue, unaryOp
-
Enum Constant Details
-
BIG_ENDIAN
The instance for big-endian languages -
LITTLE_ENDIAN
The instance for little-endian languages
-
-
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
-
forEndian
Get the taint arithmetic for the given endiannessThis method is provided since clients of this class may expect it, as they would for any realization of
PcodeArithmetic.- Parameters:
bigEndian- true for big endian, false for little- Returns:
- the arithmetic
-
forLanguage
Get the taint arithmetic for the given langaugeThis method is provided since clients of this class may expect it, as they would for any realization of
PcodeArithmetic.- Parameters:
language- the langauge- Returns:
- the arithmetic
-
getDomain
Description copied from interface:PcodeArithmeticGet the type of values over which this arithmetic operates.- Specified by:
getDomainin interfacePcodeArithmetic<TaintVec>- Returns:
- the domain
-
getEndian
Description copied from interface:PcodeArithmeticGet the endianness of this arithmeticOften T is a byte array, or at least represents one abstractly. Ideally, it is an array where each element is an abstraction of a byte. If that is the case, then the arithmetic likely has to interpret those bytes as integral values according to an endianness. This should return that endianness.
If the abstraction has no notion of endianness, return null. In that case, the both
PcodeArithmetic.fromConst(BigInteger, int, boolean)andPcodeArithmetic.fromConst(long, int)must be overridden. Furthermore, unlessPcodeArithmetic.toConcrete(Object, Purpose)is guaranteed to throw an exception, thenPcodeArithmetic.toBigInteger(Object, Purpose)andPcodeArithmetic.toLong(Object, Purpose)must also be overridden.- Specified by:
getEndianin interfacePcodeArithmetic<TaintVec>- Returns:
- the endianness or null
-
unaryOp
Apply a unary operator to the given inputNote the sizes of variables are given, because values don't necessarily have an intrinsic size. For example, a
BigIntegermay have a minimum encoding size, but that does not necessarily reflect the size of the variable from which is was read.We can't just naively return
in1, because each unary op may mix the bytes of the operand a little differently. ForPcodeOp.COPY, we can, since no mixing happens at all. This is also the case of bothNEGATEoperations ("negate" is a bit of a misnomer, as they merely inverts the bits.) ForPcodeOp.INT_ZEXT, we append empties to the correct end of the vector. Similarly, we replicate the most-significant element and append forPcodeOp.INT_SEXT. ForPcodeOp.INT_2COMP(which negates an integer in 2's complement), we have to consider that the "add one" step may cause a cascade of carries. All others, we assume every byte could be tainted by any other byte in the vector, so we union and broadcast.- Specified by:
unaryOpin interfacePcodeArithmetic<TaintVec>- Parameters:
opcode- the p-code opcodesizeout- the size (in bytes) of the output variablesizein1- the size (in bytes) of the input variablein1- the input value- Returns:
- the output value
-
binaryOp
Apply a binary operator to the given inputThis provides the full p-code op, allowing deeper inspection of the code. For example, an arithmetic may wish to distinguish immediate (constant) values from variables. By default, this unpacks the details and defers to
PcodeArithmetic.binaryOp(int, int, int, Object, int, Object).We override the form taking the full p-code op, so that we can treat certain idioms. Notably, on x86,
XOR RAX,RAXis a common optimization ofMOV RAX,0, since it takes fewer bytes to encode. Thus, we must examine the input variables, not their values, to detect this. Note that, while less common,SUB RAX,RAXwould accomplish the same. Additionally, in p-codePcodeOp.INT_XORis identical toPcodeOp.BOOL_XOR. When we detect these idioms, we want to clear any taints, since the value output is constant. This is achieved intuitively, by deferring toPcodeArithmetic.fromConst(long, int), passing in 0 and the output size.- Specified by:
binaryOpin interfacePcodeArithmetic<TaintVec>- Parameters:
op- the operationin1- the first (left) input valuein2- the second (right) input value- Returns:
- the output value
-
binaryOp
public TaintVec binaryOp(int opcode, int sizeout, int sizein1, TaintVec in1, int sizein2, TaintVec in2) Apply a binary operator to the given inputsNote the sizes of variables are given, because values don't necessarily have an intrinsic size. For example, a
BigIntegermay have a minimum encoding size, but that does not necessarily reflect the size of the variable from which is was read.For bitwise operations, we pair-wise union corresponding elements of the two input taint vectors. For integer add and subtract, we do the same, but account for the carry bits possibly cascading into bytes of higher significance. For
PcodeOp.PIECE, we perform the analog as on concrete state, since the operand sizes are constant. For all others, we must consider that every output byte is potentially affected by any or all bytes of both input operands. Thus, we union and broadcast.- Specified by:
binaryOpin interfacePcodeArithmetic<TaintVec>- Parameters:
opcode- the operation's opcode. SeePcodeOp.sizeout- the size (in bytes) of the output variablesizein1- the size (in bytes) of the first (left) input variablein1- the first (left) input valuesizein2- the size (in bytes) of the second (right) input variablein2- the second (right) input value- Returns:
- the output value
-
modBeforeStore
public TaintVec modBeforeStore(int sizeinOffset, AddressSpace space, TaintVec inOffset, int sizeinValue, TaintVec inValue) Apply any modifications before a value is storedThis implements any abstractions associated with
PcodeOp.STORE. This is called on the offset and the value before the value is actually stored into the state. NOTE: STORE ops always quantize the offset.Here we handle indirect taint for indirect writes
- Specified by:
modBeforeStorein interfacePcodeArithmetic<TaintVec>- Parameters:
sizeinOffset- the size (in bytes) of the variable used for indirectionspace- the address spaceinOffset- the value used as the address (or offset)sizeinValue- the size (in bytes) of the variable to store and of the output variableinValue- the value to store- Returns:
- the modified value to store
-
modAfterLoad
public TaintVec modAfterLoad(int sizeinOffset, AddressSpace space, TaintVec inOffset, int sizeinValue, TaintVec inValue) Apply any modifications after a value is loadedThis implements any abstractions associated with
PcodeOp.LOAD. This is called on the address/offset and the value after the value is actually loaded from the state. NOTE: LOAD ops always quantize the offset.Here we handle indirect taint for indirect reads
- Specified by:
modAfterLoadin interfacePcodeArithmetic<TaintVec>- Parameters:
sizeinOffset- the size (in bytes) of the variable used for indirectionspace- the address spaceinOffset- the value used as the offsetsizeinValue- the size (in bytes) of the variable loaded and of the output variableinValue- the value loaded- Returns:
- the modified value loaded
-
fromConst
Convert the given constant concrete value to typeThaving the same size.Constant values have no taint, so we just return a vector of empty taint sets
- Specified by:
fromConstin interfacePcodeArithmetic<TaintVec>- Parameters:
value- the constant value- Returns:
- the value as a
T
-
toConcrete
Convert, if possible, the given abstract value to a concrete byte arrayTaint vectors have no values. We're expect the taint arithmetic to be used as an auxiliary to concrete bytes, so the paired arithmetic should always defer to its concrete element. Thus, an
AssertionErrormight also be fitting here, but we'll stick to convention, since technically a user script could attempt to concretize taint.- Specified by:
toConcretein interfacePcodeArithmetic<TaintVec>- Parameters:
value- the abstract valuepurpose- the purpose for which the emulator needs a concrete value- Returns:
- the array
-
sizeOf
Get the size in bytes, if possible, of the given abstract valueIf the abstract value does not conceptually have a size, throw an exception.
Taint vectors do have length, so return it here.
- Specified by:
sizeOfin interfacePcodeArithmetic<TaintVec>- Parameters:
value- the abstract value- Returns:
- the size in bytes
-