angr.analyses.decompiler.known_patterns.templates

KnownPatternTemplate: a single, context-parameterized definition of an idiom that instantiates itself into a concrete KnownPattern for a target’s PatternContext.

One template replaces the per-architecture / per-runtime copies of a pattern: its build(ctx) computes the concrete field offsets, load sizes, and return types from the context, so the same definition covers 32- and 64-bit, libstdc++ and MSVC, and so on.

class angr.analyses.decompiler.known_patterns.templates.KnownPatternTemplate

Bases: object

A context-aware pattern definition.

Variables:
  • call_name (str) – The synthesized call name (unique across templates).

  • build (Callable[[PatternContext], KnownPattern | None]) – build(ctx) -> KnownPattern | None; emits the concrete pattern for ctx (None if it cannot).

  • arches (frozenset[str] | None) – Allowed Arch.name values; None = any.

  • languages (frozenset[str] | None) – Allowed languages ({“c”,”cpp”}); None = any.

  • runtimes (frozenset[str] | None) – Allowed C++ runtimes ({“libstdcxx”,”msvc”}); None = any.

  • platforms (frozenset[str] | None) – Allowed platforms ({“linux”,”windows”}); None = any.

  • default_enabled (bool) – Whether the template is used when the caller does not explicitly select patterns.

  • gate – Optional PatternGate that turns an opt-in template on for targets (or functions) where the evidence says the idiom is real; see gating. A gate can only open a template, never close a default-on one.

call_name: str
build: Callable[[PatternContext], KnownPattern | None]
arches: frozenset[str] | None = None
languages: frozenset[str] | None = None
runtimes: frozenset[str] | None = None
platforms: frozenset[str] | None = None
default_enabled: bool = False
name: str = ''
gate: PatternGate | None = None
enabled_for(gate_ctx)
Return type:

bool

Parameters:

gate_ctx (GateContext)

applicable(ctx)
Return type:

bool

Parameters:

ctx (PatternContext)

instantiate(ctx)

The concrete pattern for ctx, or None if this template does not apply there. Memoized: a KnownPattern is a frozen tree that depends on nothing but the context, and callers treat it read-only.

Return type:

KnownPattern | None

Parameters:

ctx (PatternContext)

__init__(call_name, build, arches=None, languages=None, runtimes=None, platforms=None, default_enabled=False, name='', gate=None, _cache=<factory>)
Parameters:
Return type:

None

angr.analyses.decompiler.known_patterns.templates.make_template(call_name, build, *, arches=None, languages=None, runtimes=None, platforms=None, default_enabled=False, name='', gate=None)
Return type:

KnownPatternTemplate

Parameters: