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.
    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 sizeout, int sizeinAddress, org.apache.commons.lang3.tuple.Pair<L,R> inAddress, 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>
    modBeforeStore(int sizeout, int sizeinAddress, org.apache.commons.lang3.tuple.Pair<L,R> inAddress, int sizeinValue, 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

    Methods inherited from interface ghidra.pcode.exec.PcodeArithmetic

    fromConst, fromConst, fromConst, isTrue, ptrAdd, ptrSub, sizeOfAbstract, toBigInteger, toLong
  • 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
    • 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(int sizeout, int sizeinAddress, org.apache.commons.lang3.tuple.Pair<L,R> inAddress, 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 address/offset and the value before the value is actually stored into the state.

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

      public org.apache.commons.lang3.tuple.Pair<L,R> modAfterLoad(int sizeout, int sizeinAddress, org.apache.commons.lang3.tuple.Pair<L,R> inAddress, 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.

      Specified by:
      modAfterLoad in interface PcodeArithmetic<L>
      Parameters:
      sizeout - the size (in bytes) of the output variable
      sizeinAddress - the size (in bytes) of the variable used for indirection
      inAddress - the value used as the address (or offset)
      sizeinValue - the size (in bytes) of the variable loaded
      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
    • 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