Class DynamicHash

java.lang.Object
ghidra.program.model.pcode.DynamicHash

public class DynamicHash extends Object
A hash utility to uniquely identify a temporary Varnode in data-flow Most Varnodes can be identified within the data-flow graph by their storage address and the address of the PcodeOp that defines them. For temporary registers, this does not work because the storage address is ephemeral. This class allows Varnodes like temporary registers (and constants) to be robustly identified by hashing details of the local data-flow. This class, when presented with a Varnode (via constructor), calculates a hash (getHash()) and an address (getAddress()) of the PcodeOp most closely associated with the Varnode, either the defining op or the op directly reading the Varnode. There are actually four hash variants that can be calculated, labeled 0, 1, 2, or 3, which incrementally hash in a larger portion of data-flow.
  • Field Details

    • transtable

      public static final int[] transtable
  • Constructor Details

    • DynamicHash

      public DynamicHash(Varnode root, int method)
      Construct a hash of the given Varnode with a specific hash method.
      Parameters:
      root - is the given Varnode
      method - is the method (0, 1, 2, 3)
    • DynamicHash

      public DynamicHash(Varnode root, PcodeSyntaxTree fd)
      Construct a unique hash for the given Varnode, which must be in a syntax tree. The hash method is cycled until a uniquely identifying one is found.
      Parameters:
      root - is the given Varnode
      fd - is the PcodeSyntaxTree containing the Varnode
    • DynamicHash

      public DynamicHash(PcodeOp op, int slot, PcodeSyntaxTree fd)
      Construct a unique hash that allows recovery of a specific PcodeOp and slot from the syntax tree. The hash method is cycled until a uniquely identifying one is found.
      Parameters:
      op - is the specific PcodeOp to hash
      slot - is the specific slot (-1 is the output, >=0 is an input)
      fd - is the PcodeSyntaxTree containing the PcodeOp
    • DynamicHash

      public DynamicHash(PcodeOp op, int inputIndex)
      Construct a level 0 hash on the input Varnode to the given PcodeOp The PcodeOp can be raw, no linked into a PcodeSyntaxTree
      Parameters:
      op - is the given PcodeOp
      inputIndex - is the index of the input Varnode to hash
  • Method Details

    • getHash

      public long getHash()
    • getAddress

      public Address getAddress()
    • findVarnode

      public static Varnode findVarnode(PcodeSyntaxTree fd, Address addr, long h)
    • findOp

      public static PcodeOp findOp(PcodeSyntaxTree fd, Address addr, long h)
    • gatherOpsAtAddress

      public static void gatherOpsAtAddress(ArrayList<PcodeOp> oplist, PcodeSyntaxTree fd, Address addr)
    • gatherFirstLevelVars

      public static void gatherFirstLevelVars(ArrayList<Varnode> varlist, PcodeSyntaxTree fd, Address addr, long h)
    • getSlotFromHash

      public static int getSlotFromHash(long h)
    • getMethodFromHash

      public static int getMethodFromHash(long h)
    • getOpCodeFromHash

      public static int getOpCodeFromHash(long h)
    • getPositionFromHash

      public static int getPositionFromHash(long h)
    • getTotalFromHash

      public static int getTotalFromHash(long h)
    • getIsNotAttached

      public static boolean getIsNotAttached(long h)
    • clearTotalPosition

      public static long clearTotalPosition(long h)
    • getComparable

      public static int getComparable(long h)
    • calcConstantHash

      public static long[] calcConstantHash(Instruction instr, long value)
      Given a constant value accessed as an operand by a particular instruction, calculate a (level 0) hash for (any) corresponding constant varnode
      Parameters:
      instr - is the instruction referencing the constant
      value - of the constant
      Returns:
      array of hash values (may be zero length)