Class ValueLocation

java.lang.Object
ghidra.pcode.exec.ValueLocation

public class ValueLocation extends Object
The location of a value

This is an analog to VariableStorage, except that this records the actual storage location of the evaluated variable or expression. This does not incorporate storage of intermediate dereferenced values. For example, suppose R0 = 0xdeadbeef, and we want to evaluate *:4 R0. The storage would be ram:deadbeef:4, not R0,ram:deadbeef:4.

  • Constructor Details

    • ValueLocation

      public ValueLocation(Varnode... nodes)
      Construct a location from a list of varnodes

      Any leading varnodes which are constant 0s are removed.

      Parameters:
      nodes - the varnodes
    • ValueLocation

      public ValueLocation(List<Varnode> nodes)
      Construct a location from a list of varnodes

      Any leading varnodes which are constant 0s are removed.

      Parameters:
      nodes - the varnodes
  • Method Details

    • vnToString

      public static String vnToString(Varnode vn, Language language)
    • fromConst

      public static ValueLocation fromConst(long value, int size)
      Generate the "location" of a constant
      Parameters:
      value - the value
      size - the size of the constant in bytes
      Returns:
      the "location"
    • fromVarnode

      public static ValueLocation fromVarnode(Address address, int size)
      Generate a location from a varnode
      Parameters:
      address - the dynamic address of the variable
      size - the size of the variable in bytes
      Returns:
      the location
    • nodeCount

      public int nodeCount()
      Get the number of varnodes for this location
      Returns:
      the count
    • getAddress

      public Address getAddress()
      Get the address of the first varnode
      Returns:
      the address, or null if this location has no varnodes
    • toString

      public String toString(Language language)
      Render this location as a string, substituting registers where applicable
      Parameters:
      language - the optional language for register substitution
      Returns:
      the string
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • intOr

      public ValueLocation intOr(ValueLocation that)
      Apply a PcodeOp.INT_OR operator

      There is a very restrictive set of constraints for which this yields a non-null location. If either this or that is empty, the other is returned. Otherwise, the varnodes are arranged in pairs by taking one from each storage starting at the right, or least-significant varnode. Each pair must match in length, and one of the pair must be a constant zero. The non-zero varnode is taken. The unpaired varnodes to the left, if any, are all taken. If any pair does not match in length, or if neither is zero, the resulting location is null. This logic is to ensure location information is accrued during concatenation.

      Parameters:
      that - the other location
      Returns:
      the location
    • getConst

      public BigInteger getConst()
      If the location represents a constant, get its value
      Returns:
      the constant value
    • shiftLeft

      public ValueLocation shiftLeft(int amount)
      Apply a PcodeOp.INT_LEFT operator

      This requires the shift amount to represent an integral number of bytes. Otherwise, the result is null. This simply inserts a constant zero to the right, having the number of bytes indicated by the shift amount. This logic is to ensure location information is accrued during concatenation.

      Parameters:
      amount - the number of bits to shift
      Returns:
      the location.
    • size

      public int size()
      Get the total size of this location in bytes
      Returns:
      the size in bytes
    • isEmpty

      public boolean isEmpty()
      Check if this location includes any varnodes

      Note that a location cannot consist entirely of constant zeros and be non-empty. The constructor will have removed them all.

      Returns:
      true if empty