Class Level1Features

  • All Implemented Interfaces:
    FeatureVector

    public class Level1Features
    extends Object
    implements FeatureVector
    Stable fingerprint features: loop and block-count shape plus branch, arithmetic, and invoke histograms.
    • Constructor Detail

      • Level1Features

        public Level1Features​(int loopCount,
                              int maxLoopNestingDepth,
                              int blockCount,
                              Map<String,​Integer> branchTypes,
                              Map<String,​Integer> arithmeticOps,
                              Map<String,​Integer> invokeTypes,
                              int arrayFlags)
        Creates a level-1 feature set, bucketing the block count and normalizing the histograms to percentages.
        Parameters:
        loopCount - the estimated number of loops
        maxLoopNestingDepth - the deepest loop nesting
        blockCount - the raw basic-block count
        branchTypes - counts per branch category
        arithmeticOps - counts per arithmetic category
        invokeTypes - counts per invoke kind
        arrayFlags - the ARRAY_* usage flag bits
    • Method Detail

      • bucketize

        public static int bucketize​(int count)
        Maps a block count onto one of five coarse size buckets.
        Parameters:
        count - the raw basic-block count
        Returns:
        the bucket index, 0 through 4
      • computeHash

        public byte[] computeHash()
        Description copied from interface: FeatureVector
        Digests every extracted feature into a hash usable for equality and lookup.
        Specified by:
        computeHash in interface FeatureVector
        Returns:
        the digest bytes
      • isValid

        public boolean isValid()
        Specified by:
        isValid in interface FeatureVector
        Returns:
        true if extraction produced features that can be matched against
      • similarity

        public double similarity​(Level1Features other)
        Scores similarity to another level-1 feature set, mixing exact and near matches with histogram overlaps.
        Parameters:
        other - the feature set to compare against
        Returns:
        a score in [0, 1], 0 if other is null
      • histogramSimilarity

        public static double histogramSimilarity​(Map<String,​Integer> a,
                                                 Map<String,​Integer> b)
        Scores two histograms by the ratio of summed per-key minima to summed per-key maxima.
        Parameters:
        a - the first histogram, may be null
        b - the second histogram, may be null
        Returns:
        a score in [0, 1]; 1 when both are empty
      • getLoopCount

        public int getLoopCount()
        Returns:
        the loop count
      • getMaxLoopNestingDepth

        public int getMaxLoopNestingDepth()
        Returns:
        the max loop nesting depth
      • getBlockCountBucket

        public int getBlockCountBucket()
        Returns:
        the block count bucket
      • getBranchTypeHistogram

        public Map<String,​Integer> getBranchTypeHistogram()
        Returns:
        an unmodifiable view of the normalized branch-type histogram
      • getArithmeticOpHistogram

        public Map<String,​Integer> getArithmeticOpHistogram()
        Returns:
        an unmodifiable view of the normalized arithmetic-op histogram
      • getInvokeTypeHistogram

        public Map<String,​Integer> getInvokeTypeHistogram()
        Returns:
        an unmodifiable view of the normalized invoke-type histogram
      • getArrayUsageFlags

        public int getArrayUsageFlags()
        Returns:
        the array usage flags