angr.analyses.decompiler.optimization_passes.pattern_outliner

class angr.analyses.decompiler.optimization_passes.pattern_outliner.PatternOutliner

Bases: OptimizationPass

Finds occurrences of the user’s patterns (kb.patterns) in the AIL graph and outlines each into a call named after its pattern.

Where the KnownPatternOutliner matches library idioms exactly, this pass aligns a pattern the user selected and edited, so an occurrence may differ from it in the ways the pattern allows: a different operator of the same class, a statement it marked optional, an extra statement in between. An occurrence is outlined when it verifies structurally and reaches the pattern’s similarity threshold. Runs right before variable recovery so the calls’ declared types flow into Typehoon.

ARCHES = None
PLATFORMS = None
STAGE = 7
NAME = "Outline the user's patterns into calls"
DESCRIPTION = "Finds occurrences of the user's patterns (kb.patterns) in the AIL\n    graph and outlines each into a call named after its pattern.\n\n    Where the KnownPatternOutliner matches library idioms exactly, this pass aligns a\n    pattern the user selected and edited, so an occurrence may differ from it in the\n    ways the pattern allows: a different operator of the same class, a statement it\n    marked optional, an extra statement in between. An occurrence is outlined when it\n    verifies structurally and reaches the pattern's similarity threshold. Runs right\n    before variable recovery so the calls' declared types flow into Typehoon."
MAX_ROUNDS = 32
MAX_AUTO_BLOCKS = 3

with a derived frontier, reject a callee larger than this many times the region

MIN_AUTO_RATIO = 0.5

…or smaller than this fraction of it

MIN_SUBRUN_RATIO = 0.5

a single-entry sub-run of an occurrence must cover this share of its tokens to be outlined under the pattern’s name

__init__(func, manager, **kwargs)
outlined: list[tuple[str, tuple[int, int | None], float]]

(pattern name, block location of the call, share of the occurrence’s tokens covered) for every occurrence outlined; the share is below 1 when only a sub-run could be

skipped: list[tuple[str, str]]

(pattern name, reason) for every occurrence that was found but not outlined

lossy: list[tuple[str, tuple[int, int | None], int]]

(pattern name, call location, values dropped) for every occurrence outlined although the region leaves more values live than the call can return: the output there is wrong

new_block_addr()

A block address no block of the graph being rewritten has.

The base class allocates from a map of the blocks built once per stage, before any pass of the stage ran, so it hands out addresses an earlier pass of this stage (the KnownPatternOutliner, say) has already given its own new blocks; the outline is then rolled back as a duplicate block location.

Return type:

int