Class DPatternMatcher
java.lang.Object
com.pnfsoftware.jeb.core.units.code.android.ir.compiler.DPatternMatcher
IR pattern search and replace.
Current limitation: matching is limited by basic block boundaries.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionDPatternMatcher(DPatternCompiler.DPattern pattern, CFG<IDInstruction> cfg, IDMethodContext ctx) Create a matcher for a control-flow graph.DPatternMatcher(DPatternCompiler.DPattern pattern, IDExpression exp, IDMethodContext ctx) Create a matcher for a single expression. -
Method Summary
Modifier and TypeMethodDescriptionRetrieve the method context used by this matcher.Retrieve the input control-flow graph.Retrieve the input expression.Retrieve the expression depth map used during matching.longgetMatchAddress(DPatternMatcher.Result result, int index) Retrieve the address of a matched pattern line.Retrieve the pattern used by this matcher.booleanDetermine whether deep associativity matching is allowed.booleanreplace(DPatternMatcher.Result r, boolean preferBuiltinReplacer) Replace a previously found match.search()Search for the first match.search(DPatternMatcher.Result lastResult) Search for the next match.Search for the first match and replace it.searchAndReplace(DPatternMatcher.Result lastResult) Search for the next match and replace it.intSearch and replace all matches.intsearchAndReplaceAll(DPatternMatcher.Result[] aresult) Search and replace all matches.voidsetAllowDeepAssociativity(boolean allowDeepAssociativity) Allow to modify inner expression to check alternative associativity.voidsetIRDepthsMap(Map<IDExpression, Integer> iRDepthsMap) Set precomputed expression depths used during matching.toString()
-
Constructor Details
-
DPatternMatcher
public DPatternMatcher(DPatternCompiler.DPattern pattern, CFG<IDInstruction> cfg, IDMethodContext ctx) Create a matcher for a control-flow graph.- Parameters:
pattern- compiled patterncfg- input CFGctx- method context
-
DPatternMatcher
Create a matcher for a single expression.- Parameters:
pattern- compiled patternexp- input expressionctx- method context
-
-
Method Details
-
getPattern
Retrieve the pattern used by this matcher.- Returns:
- the pattern
-
getContext
Retrieve the method context used by this matcher.- Returns:
- the method context
-
getInputCfg
Retrieve the input control-flow graph.- Returns:
- the input CFG, or null for expression-only matching
-
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, matchingV0 * (#1 + $2)onr0 * ((r1 + 4) + r2)will attempt any associativity, matching onV0 = 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
Set precomputed expression depths used during matching.- Parameters:
iRDepthsMap- expression depth map
-
getIRDepthsMap
Retrieve the expression depth map used during matching.- Returns:
- the expression depth map, or null if none was set
-
toString
-
search
Search for the first match.- Returns:
- the first match, or null if none was found
-
search
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
Search for the first match and replace it.- Returns:
- the replacement result, or null if no match was found
-
searchAndReplace
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
Replace a previously found match.- Parameters:
r- match result to replacepreferBuiltinReplacer- 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
Search and replace all matches.- Parameters:
aresult- (optional) last successful search-and-replace- Returns:
- the number of replacements
-
getMatchAddress
Retrieve the address of a matched pattern line.- Parameters:
result- match resultindex- line index relative to the matched input pattern; negative values are relative to the pattern end- Returns:
- the IR address of the matched line
-