java.lang.Object
com.pnfsoftware.jeb.core.units.code.android.ir.compiler.DPatternMatcher

public class DPatternMatcher extends Object
IR pattern search and replace.

Current limitation: matching is limited by basic block boundaries.

  • Constructor Details

  • Method Details

    • getPattern

      public DPatternCompiler.DPattern getPattern()
      Retrieve the pattern used by this matcher.
      Returns:
      the pattern
    • getContext

      public IDMethodContext getContext()
      Retrieve the method context used by this matcher.
      Returns:
      the method context
    • getInputCfg

      public CFG<IDInstruction> getInputCfg()
      Retrieve the input control-flow graph.
      Returns:
      the input CFG, or null for expression-only matching
    • getInputExpression

      public IDExpression getInputExpression()
      Retrieve the input expression.
      Returns:
      the input expression, or null for CFG matching
    • isAllowDeepAssociativity

      public boolean isAllowDeepAssociativity()
      Determine whether deep associativity matching is allowed.
      Returns:
      true if deep associativity matching is allowed
    • setAllowDeepAssociativity

      public void setAllowDeepAssociativity(boolean allowDeepAssociativity)
      Allow to modify inner expression to check alternative associativity. For example, matching V0 * (#1 + $2) on r0 * ((r1 + 4) + r2) will attempt any associativity, matching on
       V0 = r0
       #1 = 4
       $2 = (r1 + r2)
       
      even if (r1 + r2) does not exists in inner expression.
      Parameters:
      allowDeepAssociativity - true to allow deep associativity matching
    • setIRDepthsMap

      public void setIRDepthsMap(Map<IDExpression,Integer> iRDepthsMap)
      Set precomputed expression depths used during matching.
      Parameters:
      iRDepthsMap - expression depth map
    • getIRDepthsMap

      public Map<IDExpression,Integer> getIRDepthsMap()
      Retrieve the expression depth map used during matching.
      Returns:
      the expression depth map, or null if none was set
    • toString

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

      public DPatternMatcher.Result search()
      Search for the first match.
      Returns:
      the first match, or null if none was found
    • search

      public DPatternMatcher.Result search(DPatternMatcher.Result lastResult)
      Search for the next match.
      Parameters:
      lastResult - previous match, or null to start from the beginning
      Returns:
      the next match, or null if none was found
    • searchAndReplace

      public DPatternMatcher.Result searchAndReplace()
      Search for the first match and replace it.
      Returns:
      the replacement result, or null if no match was found
    • searchAndReplace

      public DPatternMatcher.Result searchAndReplace(DPatternMatcher.Result lastResult)
      Search for the next match and replace it.
      Parameters:
      lastResult - previous replacement result, or null to start from the beginning
      Returns:
      the replacement result, or null if no match was found
    • replace

      public boolean replace(DPatternMatcher.Result r, boolean preferBuiltinReplacer)
      Replace a previously found match.
      Parameters:
      r - match result to replace
      preferBuiltinReplacer - true to use the built-in replacer before any custom replacer
      Returns:
      true if replacement succeeded
    • searchAndReplaceAll

      public int searchAndReplaceAll()
      Search and replace all matches.
      Returns:
      the number of replacements
    • searchAndReplaceAll

      public int searchAndReplaceAll(DPatternMatcher.Result[] aresult)
      Search and replace all matches.
      Parameters:
      aresult - (optional) last successful search-and-replace
      Returns:
      the number of replacements
    • getMatchAddress

      public long getMatchAddress(DPatternMatcher.Result result, int index)
      Retrieve the address of a matched pattern line.
      Parameters:
      result - match result
      index - line index relative to the matched input pattern; negative values are relative to the pattern end
      Returns:
      the IR address of the matched line