Class Block


  • public class Block
    extends java.lang.Object
    This class holds basic-block information for matching algorithms. It is used as a node to traverse the control-flow graph. It serves as a container for hashing information associated with Instructions in the block. It holds disambiguating hashes (calculated primarily from basic-block parent/child relationships) to help separate identical or near identical sequences of Instructions within one function.
    • Constructor Summary

      Constructors 
      Constructor Description
      Block​(CodeBlock codeBlock)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean allUnknown​(int startindex, int length)
      If the indicated n-gram, within this block, consists of unmatched instructions
      protected void calcHashes​(int minLength, int maxLength, boolean wholeBlock, boolean matchOnly, HashCalculator hashCalc)
      Calculate n-gram hashes used for matching (for Instructions in this basic-block).
      protected void clearSort()
      Clear out structures associated with main sort
      int getMatchHash()  
      int hashGram​(int gramSize, InstructHash instHash, HashCalculator hashCalc)
      Calculate an n-gram hash, given a particular hash function
      protected void setMatched​(int index)
      Set up block match deconfliction value matchHash.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • isMatched

        protected boolean isMatched
      • isVisited

        protected boolean isVisited
    • Constructor Detail

      • Block

        public Block​(CodeBlock codeBlock)
    • Method Detail

      • clearSort

        protected void clearSort()
        Clear out structures associated with main sort
      • setMatched

        protected void setMatched​(int index)
        Set up block match deconfliction value matchHash. This is fed into the n-gram hashes for Instructions contained by this block to uniquely associate the n-grams with this block (and the matching block on the other side)
        Parameters:
        index - is the 1-up index used to uniquely label this block
      • getMatchHash

        public int getMatchHash()
        Returns:
        the main deconfliction hash feed
      • allUnknown

        protected boolean allUnknown​(int startindex,
                                     int length)
        If the indicated n-gram, within this block, consists of unmatched instructions
        Parameters:
        startindex - is the index of the first Instruction in the n-gram
        length - is the number of instructions in the n-gram
        Returns:
        true if all Instructions in the n-gram are not matched, false otherwise.
      • hashGram

        public int hashGram​(int gramSize,
                            InstructHash instHash,
                            HashCalculator hashCalc)
                     throws MemoryAccessException
        Calculate an n-gram hash, given a particular hash function
        Parameters:
        gramSize - is the size of the n-gram
        instHash - is the first Instruction in the n-gram
        hashCalc - is the hash function
        Returns:
        the final 32-bit hash
        Throws:
        MemoryAccessException
      • calcHashes

        protected void calcHashes​(int minLength,
                                  int maxLength,
                                  boolean wholeBlock,
                                  boolean matchOnly,
                                  HashCalculator hashCalc)
                           throws MemoryAccessException
        Calculate n-gram hashes used for matching (for Instructions in this basic-block). The exact hashes generated can be changed to get different looks at the data over multiple matching passes.
        Parameters:
        minLength - is the minimum length of an n-gram to calculate
        maxLength - is the maximum length of an n-gram
        wholeBlock - , true indicates a hash of the whole block should be calculated even if its size is below minLength
        matchOnly - , true indicates hashes should only be calculated for previously matched, or small, blocks
        hashCalc - is the hash function for this matching pass
        Throws:
        MemoryAccessException