angr.analyses.decompiler.known_patterns.generator¶
PatternGenerator: build a KnownPattern from a decompilation text selection.
This is the inverse of KnownPatternFinder. Given a range of the
generated C source (Decompiler.codegen) and a target call, it resolves the
selection back to AIL statements/expressions and emits the corresponding DSL
pattern:
an expression selection (a sub-expression of one statement) becomes a
PatternExprtree;a straight-line statement selection (statements of one basic block) becomes a
PStmtSeq;a selection spanning several basic blocks becomes a
PGraphPat(requires the finder’sail_graphfor the block/edge structure).
Text offsets are resolved through the codegen position maps
(map_pos_to_node / ailexpr2cnode / cnode2ailexpr); the rendered AIL
objects are .likes()-equal to the finder’s graph objects, so a generated
pattern re-matches via KnownPatternFinder on the same ail_graph (the
round-trip is the acceptance test).
- angr.analyses.decompiler.known_patterns.generator.stmt_ins_addrs(stmt)¶
The instruction addresses a statement and its subexpressions carry.
- exception angr.analyses.decompiler.known_patterns.generator.PatternGenerationError¶
Bases:
ExceptionRaised when a selection cannot be turned into a KnownPattern (ambiguous, unsupported, or inconsistent with the given arguments).
- class angr.analyses.decompiler.known_patterns.generator.PatternGenerator¶
Bases:
objectGenerate a
KnownPatternfrom a text selection incodegen.text.- Parameters:
codegen – the
Decompiler.codegen(aCStructuredCodeGenerator).ail_graph (
DiGraph|None) – the graph the generated pattern will be matched against (Decompiler.ail_graph). Required for multi-block (control-flow-spanning) selections; optional otherwise.
- __init__(codegen, ail_graph=None)¶
- Parameters:
ail_graph (networkx.DiGraph | None)
- vvar_id_at(offset)¶
The AIL vvar id of the variable rendered at
offset, or None.
- offset_of(needle, start=0)¶
Convenience: the offset of
needlein the rendered text.
- generate(start_offset, end_offset, call_name, arg_offsets, *, name=None, display_name=None, returnty=None, param_types=None, const_arg_offsets=(), arches=None, platforms=None, binary_guard=None, default_enabled=False)¶
- generate_pattern(start_offset, end_offset, call_name, *, name=None, display_name=None, returnty=None, param_types=None)¶
A pattern for the fuzzy matcher from the statements the selection covers.
Unlike
generate(), this asks nothing of the user beyond the span: every whole statement inside it becomes a leaf, a statement the DSL cannot express becomes aPAnyStmtrather than an error, and the call’s parameters are the variables the statements read without defining, in the order they are first read. Constants stay exact; the editor is where they are loosened.
- generate_pattern_from_statements(stmts, call_name, *, name=None, display_name=None, returnty=None, param_types=None)¶
generate_pattern()for a caller that already holds the statements, in order.