Class PairedPcodeArithmetic<L,R>

java.lang.Object
ghidra.pcode.exec.PairedPcodeArithmetic<L,R>
Type Parameters:
L - the type of the left ("control") element
R - the type of the right ("auxiliary") element
All Implemented Interfaces:
PcodeArithmetic<org.apache.commons.lang3.tuple.Pair<L,R>>

public class PairedPcodeArithmetic<L,R> extends Object implements PcodeArithmetic<org.apache.commons.lang3.tuple.Pair<L,R>>
An arithmetic composed from two.

The new arithmetic operates on tuples where each is subject to its respective arithmetic. One exception is toConcrete(Pair, Purpose). This arithmetic defers to left ("control") arithmetic. Thus, conventionally, when part of the pair represents the concrete value, it should be the left.

See PairedPcodeExecutorStatePiece regarding composing three or more elements. Generally, it's recommended the client provide its own "record" type and the corresponding arithmetic and state piece to manipulate it. Nesting pairs would work, but is not recommended.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface ghidra.pcode.exec.PcodeArithmetic

    PcodeArithmetic.Purpose
  • Field Summary

    Fields inherited from interface ghidra.pcode.exec.PcodeArithmetic

    SIZEOF_SIZEOF
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct a composed arithmetic from the given two
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.commons.lang3.tuple.Pair<L,R>
    binaryOp(int opcode, int sizeout, int sizein1, org.apache.commons.lang3.tuple.Pair<L,R> in1, int sizein2, org.apache.commons.lang3.tuple.Pair<L,R> in2)
    Apply a binary operator to the given inputs
    org.apache.commons.lang3.tuple.Pair<L,R>
    binaryOp(PcodeOp op, org.apache.commons.lang3.tuple.Pair<L,R> in1, org.apache.commons.lang3.tuple.Pair<L,R> in2)
    Apply a binary operator to the given input
    boolean
     
    org.apache.commons.lang3.tuple.Pair<L,R>
    fromConst(byte[] value)
    Convert the given constant concrete value to type T having the same size.
    org.apache.commons.lang3.tuple.Pair<L,R>
    fromConst(long value, int size)
    Convert the given constant concrete value to type T having the given size.
    org.apache.commons.lang3.tuple.Pair<L,R>
    fromConst(BigInteger value, int size)
    Convert the given constant concrete value to type T having the given size.
    org.apache.commons.lang3.tuple.Pair<L,R>
    fromConst(BigInteger value, int size, boolean isContextreg)
    Convert the given constant concrete value to type T having the given size.
    Class<org.apache.commons.lang3.tuple.Pair<L,R>>
    Get the type of values over which this arithmetic operates.
    Get the endianness of this arithmetic
    Get the left ("control") arithmetic
    Get the right ("rider") arithmetic
    org.apache.commons.lang3.tuple.Pair<L,R>
    modAfterLoad(int sizeinOffset, AddressSpace space, org.apache.commons.lang3.tuple.Pair<L,R> inOffset, int sizeinValue, org.apache.commons.lang3.tuple.Pair<L,R> inValue)
    Apply any modifications after a value is loaded
    org.apache.commons.lang3.tuple.Pair<L,R>
    modAfterLoad(PcodeOp op, AddressSpace space, org.apache.commons.lang3.tuple.Pair<L,R> inOffset, org.apache.commons.lang3.tuple.Pair<L,R> inValue)
    Apply any modifications after a value is loaded
    org.apache.commons.lang3.tuple.Pair<L,R>
    modBeforeStore(int sizeinOffset, AddressSpace space, org.apache.commons.lang3.tuple.Pair<L,R> inOffset, int sizeinValue, org.apache.commons.lang3.tuple.Pair<L,R> inValue)
    Apply any modifications before a value is stored
    org.apache.commons.lang3.tuple.Pair<L,R>
    modBeforeStore(PcodeOp op, AddressSpace space, org.apache.commons.lang3.tuple.Pair<L,R> inOffset, org.apache.commons.lang3.tuple.Pair<L,R> inValue)
    Apply any modifications before a value is stored
    long
    sizeOf(org.apache.commons.lang3.tuple.Pair<L,R> value)
    Get the size in bytes, if possible, of the given abstract value
    byte[]
    toConcrete(org.apache.commons.lang3.tuple.Pair<L,R> value, PcodeArithmetic.Purpose purpose)
    Convert, if possible, the given abstract value to a concrete byte array
    org.apache.commons.lang3.tuple.Pair<L,R>
    unaryOp(int opcode, int sizeout, int sizein1, org.apache.commons.lang3.tuple.Pair<L,R> in1)
    Apply a unary operator to the given input
    org.apache.commons.lang3.tuple.Pair<L,R>
    unaryOp(PcodeOp op, org.apache.commons.lang3.tuple.Pair<L,R> in1)
    Apply a unary operator to the given input

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PairedPcodeArithmetic

      public PairedPcodeArithmetic(PcodeArithmetic<L> leftArith, PcodeArithmetic<R> rightArith)
      Construct a composed arithmetic from the given two
      Parameters:
      leftArith - the left ("control") arithmetic
      rightArith - the right ("rider") arithmetic
  • Method Details

    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getDomain

      public Class<org.apache.commons.lang3.tuple.Pair<L,R>> getDomain()
      Description copied from interface: PcodeArithmetic
      Get the type of values over which this arithmetic operates.
      Specified by:
      getDomain in interface PcodeArithmetic<L>
      Returns:
      the domain
    • getEndian

      public Endian getEndian()
      Description copied from interface: PcodeArithmetic
      Get the endianness of this arithmetic

      Often 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) and PcodeArithmetic.fromConst(long, int) must be overridden. Furthermore, unless PcodeArithmetic.toConcrete(Object, Purpose) is guaranteed to throw an exception, then PcodeArithmetic.toBigInteger(Object, Purpose) and PcodeArithmetic.toLong(Object, Purpose) must also be overridden.

      Specified by:
      getEndian in interface PcodeArithmetic<L>
      Returns:
      the endianness or null
    • unaryOp

      public org.apache.commons.lang3.tuple.Pair<L,R> unaryOp(int opcode, int sizeout, int sizein1, org.apache.commons.lang3.tuple.Pair<L,R> in1)
      Description copied from interface: PcodeArithmetic
      Apply a unary operator to the given input

      Note the sizes of variables are given, because values don't necessarily have an intrinsic size. For example, a BigInteger may have a minimum encoding size, but that does not necessarily reflect the size of the variable from which is was read.

      Specified by:
      unaryOp in interface PcodeArithmetic<L>
      Parameters:
      opcode - the p-code opcode
      sizeout - the size (in bytes) of the output variable
      sizein1 - the size (in bytes) of the input variable
      in1 - the input value
      Returns:
      the output value
    • unaryOp

      public org.apache.commons.lang3.tuple.Pair<L,R> unaryOp(PcodeOp op, org.apache.commons.lang3.tuple.Pair<L,R> in1)
      Description copied from interface: PcodeArithmetic
      Apply a unary operator to the given input

      This 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.unaryOp(int, int, int, Object).

      Specified by:
      unaryOp in interface PcodeArithmetic<L>
      Parameters:
      op - the operation
      in1 - the input value
      Returns:
      the output value
    • binaryOp

      public org.apache.commons.lang3.tuple.Pair<L,R> binaryOp(int opcode, int sizeout, int sizein1, org.apache.commons.lang3.tuple.Pair<L,R> in1, int sizein2, org.apache.commons.lang3.tuple.Pair<L,R> in2)
      Description copied from interface: PcodeArithmetic
      Apply a binary operator to the given inputs

      Note the sizes of variables are given, because values don't necessarily have an intrinsic size. For example, a BigInteger may have a minimum encoding size, but that does not necessarily reflect the size of the variable from which is was read.

      Specified by:
      binaryOp in interface PcodeArithmetic<L>
      Parameters:
      opcode - the operation's opcode. See PcodeOp.
      sizeout - the size (in bytes) of the output variable
      sizein1 - the size (in bytes) of the first (left) input variable
      in1 - the first (left) input value
      sizein2 - the size (in bytes) of the second (right) input variable
      in2 - the second (right) input value
      Returns:
      the output value
    • binaryOp

      public org.apache.commons.lang3.tuple.Pair<L,R> binaryOp(PcodeOp op, org.apache.commons.lang3.tuple.Pair<L,R> in1, org.apache.commons.lang3.tuple.Pair<L,R> in2)
      Description copied from interface: PcodeArithmetic
      Apply a binary operator to the given input

      This 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).

      Specified by:
      binaryOp in interface PcodeArithmetic<L>
      Parameters:
      op - the operation
      in1 - the first (left) input value
      in2 - the second (right) input value
      Returns:
      the output value
    • modBeforeStore

      public org.apache.commons.lang3.tuple.Pair<L,R> modBeforeStore(PcodeOp op, AddressSpace space, org.apache.commons.lang3.tuple.Pair<L,R> inOffset, org.apache.commons.lang3.tuple.Pair<L,R> inValue)
      Description copied from interface: PcodeArithmetic
      Apply any modifications before a value is stored

      This provides the full p-code op, allowing deeper inspection of the code. NOTE: STORE ops always quantize the offset.

      Specified by:
      modBeforeStore in interface PcodeArithmetic<L>
      Parameters:
      op - the operation
      space - the address space
      inOffset - the value used as the offset
      inValue - the value to store
      Returns:
      the modified value to store
    • modBeforeStore

      public org.apache.commons.lang3.tuple.Pair<L,R> modBeforeStore(int sizeinOffset, AddressSpace space, org.apache.commons.lang3.tuple.Pair<L,R> inOffset, int sizeinValue, org.apache.commons.lang3.tuple.Pair<L,R> inValue)
      Description copied from interface: PcodeArithmetic
      Apply any modifications before a value is stored

      This 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.

      Specified by:
      modBeforeStore in interface PcodeArithmetic<L>
      Parameters:
      sizeinOffset - the size (in bytes) of the variable used for indirection
      space - the address space
      inOffset - the value used as the address (or offset)
      sizeinValue - the size (in bytes) of the variable to store and of the output variable
      inValue - the value to store
      Returns:
      the modified value to store
    • modAfterLoad

      public org.apache.commons.lang3.tuple.Pair<L,R> modAfterLoad(PcodeOp op, AddressSpace space, org.apache.commons.lang3.tuple.Pair<L,R> inOffset, org.apache.commons.lang3.tuple.Pair<L,R> inValue)
      Description copied from interface: PcodeArithmetic
      Apply any modifications after a value is loaded

      This provides the full p-code op, allowing deeper inspection of the code. NOTE: LOAD ops always quantize the offset.

      Specified by:
      modAfterLoad in interface PcodeArithmetic<L>
      Parameters:
      op - the operation
      space - the address space
      inOffset - the value used as the offset
      inValue - the value loaded
      Returns:
      the modified value loaded
    • modAfterLoad

      public org.apache.commons.lang3.tuple.Pair<L,R> modAfterLoad(int sizeinOffset, AddressSpace space, org.apache.commons.lang3.tuple.Pair<L,R> inOffset, int sizeinValue, org.apache.commons.lang3.tuple.Pair<L,R> inValue)
      Description copied from interface: PcodeArithmetic
      Apply any modifications after a value is loaded

      This 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.

      Specified by:
      modAfterLoad in interface PcodeArithmetic<L>
      Parameters:
      sizeinOffset - the size (in bytes) of the variable used for indirection
      space - the address space
      inOffset - the value used as the offset
      sizeinValue - the size (in bytes) of the variable loaded and of the output variable
      inValue - the value loaded
      Returns:
      the modified value loaded
    • fromConst

      public org.apache.commons.lang3.tuple.Pair<L,R> fromConst(byte[] value)
      Description copied from interface: PcodeArithmetic
      Convert the given constant concrete value to type T having the same size.
      Specified by:
      fromConst in interface PcodeArithmetic<L>
      Parameters:
      value - the constant value
      Returns:
      the value as a T
    • fromConst

      public org.apache.commons.lang3.tuple.Pair<L,R> fromConst(long value, int size)
      Description copied from interface: PcodeArithmetic
      Convert the given constant concrete value to type T having the given size.

      Note that the size may not be applicable to T. It is given to ensure the value can be held in a variable of that size when passed to downstream operators or stored in the executor state.

      Specified by:
      fromConst in interface PcodeArithmetic<L>
      Parameters:
      value - the constant value
      size - the size (in bytes) of the variable into which the value is to be stored
      Returns:
      the value as a T
    • fromConst

      public org.apache.commons.lang3.tuple.Pair<L,R> fromConst(BigInteger value, int size, boolean isContextreg)
      Description copied from interface: PcodeArithmetic
      Convert the given constant concrete value to type T having the given size.

      Note that the size may not be applicable to T. It is given to ensure the value can be held in a variable of that size when passed to downstream operators or stored in the executor state.

      Specified by:
      fromConst in interface PcodeArithmetic<L>
      Parameters:
      value - the constant value
      size - the size (in bytes) of the variable into which the value is to be stored
      isContextreg - true to indicate the value is from the disassembly context register. If T represents bytes, and the value is the contextreg, then the bytes are in big endian, no matter the machine language's endianness.
      Returns:
      the value as a T
    • fromConst

      public org.apache.commons.lang3.tuple.Pair<L,R> fromConst(BigInteger value, int size)
      Description copied from interface: PcodeArithmetic
      Convert the given constant concrete value to type T having the given size.

      The value is assumed not to be for the disassembly context register.

      Specified by:
      fromConst in interface PcodeArithmetic<L>
      Parameters:
      value - the constant value
      size - the size (in bytes) of the variable into which the value is to be stored
      Returns:
      the value as a T
      See Also:
    • toConcrete

      public byte[] toConcrete(org.apache.commons.lang3.tuple.Pair<L,R> value, PcodeArithmetic.Purpose purpose)
      Description copied from interface: PcodeArithmetic
      Convert, if possible, the given abstract value to a concrete byte array
      Specified by:
      toConcrete in interface PcodeArithmetic<L>
      Parameters:
      value - the abstract value
      purpose - the purpose for which the emulator needs a concrete value
      Returns:
      the array
    • sizeOf

      public long sizeOf(org.apache.commons.lang3.tuple.Pair<L,R> value)
      Description copied from interface: PcodeArithmetic
      Get the size in bytes, if possible, of the given abstract value

      If the abstract value does not conceptually have a size, throw an exception.

      Specified by:
      sizeOf in interface PcodeArithmetic<L>
      Parameters:
      value - the abstract value
      Returns:
      the size in bytes
    • getLeft

      public PcodeArithmetic<L> getLeft()
      Get the left ("control") arithmetic
      Returns:
      the arithmetic
    • getRight

      public PcodeArithmetic<R> getRight()
      Get the right ("rider") arithmetic
      Returns:
      the arithmetic