angr.analyses.decompiler.known_patterns.finder¶
KnownPatternFinder: find occurrences of KnownPatterns in a Clinic AIL graph and outline them into calls via the Outliner analysis.
- exception angr.analyses.decompiler.known_patterns.finder.UnsupportedOutlineError¶
Bases:
ExceptionRaised when a match cannot be safely outlined (e.g. side-effecting statements interleave with the matched span, or the recovered callee interface does not agree with the pattern’s declared parameters).
- class angr.analyses.decompiler.known_patterns.finder.KnownPatternMatch¶
Bases:
objectOne occurrence of a KnownPattern in an AIL graph.
For expression-level matches, the boundary is
consumed_stmt_idxs(statements wholly owned by the match, e.g. chased definitions) plusexpr_path(the location of the matched sub-expression inside the anchor statement). For statement-sequence matches,stmt_spanholds the ordered matched statement indices (the anchor is the first) andmatched_expris None.duplicated_stmt_idxsholds chased definitions that are copied into the outlined region instead of moved: the originals stay where they are (other code still uses them) and the copies make the pattern’s captured values the region’s live-ins. It is always disjoint fromconsumed_stmt_idxs.recomputed_defsdoes the same for definitions that live in another block (a CSE’d value, possibly reaching the anchor through a phi): the expression is pure, so the region recomputes it from the captured operands.- pattern: KnownPattern
- anchor_stmt_idx: int
- captures: dict[str, Expression]
- matched_expr: Expression | None
- recomputed_defs: tuple[tuple[int, Expression], ...] = ()¶
- __init__(pattern, block_loc, anchor_stmt_idx, expr_path, consumed_stmt_idxs, captures, matched_expr, duplicated_stmt_idxs=frozenset({}), recomputed_defs=(), base_aliases=(), stmt_span=None, block_map=None, consumed_by_block=None, frontier_locs=None)¶
- Parameters:
pattern (KnownPattern)
anchor_stmt_idx (int)
captures (dict[str, Expression])
matched_expr (Expression | None)
recomputed_defs (tuple[tuple[int, Expression], ...])
consumed_by_block (dict[tuple[int, int], frozenset[int]] | None)
- Return type:
None
- class angr.analyses.decompiler.known_patterns.finder.OutlineResult¶
Bases:
objectThe outcome of outlining one KnownPatternMatch.
- graph: DiGraph
- match: KnownPatternMatch
- call_stmt: Statement
- child_graph: DiGraph | None
- child_funcargs: list[VirtualVariable]
- __init__(graph, match, call_stmt, child_func, child_graph, child_funcargs)¶
- Parameters:
graph (DiGraph)
match (KnownPatternMatch)
call_stmt (Statement)
child_func (Function | None)
child_graph (DiGraph | None)
child_funcargs (list[VirtualVariable])
- Return type:
None
- class angr.analyses.decompiler.known_patterns.finder.KnownPatternFinder¶
Bases:
AnalysisFinds occurrences of KnownPatterns in a Clinic AIL graph.
The graph to match on is the final (SSA-form) Clinic graph, i.e.
decompiler.ail_graph/clinic.cc_graph. Matches are reported inself.matches;outline()turns a match into a synthesized call by invoking the Outliner analysis on a copy of the graph.- MAX_REMOTE_CHASE_DEPTH = 6¶
- __init__(func, ail_graph, patterns=None, chase_defs=True, chase_remote_defs=True, skip_conversions=True, vvar_id_start=48879, block_addr_start=2864381952, ail_manager=None, force_patterns=None)¶
patternsmay be pattern templates (KnownPatternTemplate) and/or already-concrete KnownPatterns; templates are instantiated for this binary’s PatternContext. When None, the registry is used, filtered down to the templates that are enabled for this target: default-on ones, ones named byforce_patterns, and ones whose gate opens (seegating).force_patternsis the user’s force-enable selection,"all"or an iterable of template names / call names, and is only consulted whenpatternsis None (an explicit pattern list is already a selection).
- matches: list[KnownPatternMatch]
- call_target_names(call)¶
Public face of
_resolve_call_target(), for the outliner’s clean-up of calls a pattern declared pure.
- apply_matches(matches, ail_graph)¶
Apply as many of
matchesas possible, batching where it matters.Applying one match at a time is fine until several of them interleave in one block, which is exactly what consecutive field swaps do:
- t1 = x->b; t2 = y->b; y->b = t1; x->b = t2;
^ the next field’s load sits in this one’s gap
Rewrite the first and the second’s statements have moved; rewrite it anyway and the third now has an opaque call sitting in its gap, which no disjointness test will let it move across. So the void statement-span matches of a block, which the finder has already checked do not conflict, are spliced in together, against the statement indices they were found at. Everything else keeps the one-at-a-time path.
Returns the new graph and the ids of the matches that were applied.
- Return type:
- Parameters:
matches (list[KnownPatternMatch])
ail_graph (DiGraph)
- outline(match, ail_graph=None)¶
Outline one match: split the anchor block so the matched span forms its own block, invoke the Outliner analysis on it, and rewrite the synthesized callsite into the pattern’s call. Operates on (and returns) a copy; neither
self._graphnorail_graphis mutated.- Return type:
- Parameters:
match (KnownPatternMatch)
ail_graph (DiGraph | None)
- MAX_LIFTED_EXPR_NODES = 8¶
Node budget for a lifted parameter expression; see _is_liftable.
- outline_at(location, pattern, ail_graph)¶
Find
patternatlocation((block_addr, block_idx)or(block_addr, block_idx, stmt_idx)) inail_graphand outline it.- Return type:
- Parameters: