angr.analyses.decompiler.known_patterns.pattern¶
KnownPattern: declarative metadata around a pattern-AST.
A KnownPattern couples a structural pattern (see dsl) with the
information needed to turn a match into a synthesized call: the call name, the
ordered parameters (mapping captures to call arguments and types), the return
type, and applicability guards.
- class angr.analyses.decompiler.known_patterns.pattern.CppRef¶
Bases:
objectA reference to a C++ class type registered in the
cpp::stdSimTypeCollection, keyed by its unique (mangled-style) name.- unique_name: str
- resolve(arch)¶
- Return type:
- Parameters:
arch (archinfo.Arch)
- angr.analyses.decompiler.known_patterns.pattern.resolve_typeref(ref, arch)¶
Resolve a TypeRef into a SimType: a C declaration string is parsed with
parse_type; a CppRef is looked up in the cpp::std collection.- Return type:
- Parameters:
ref (TypeRef | None)
arch (archinfo.Arch)
- class angr.analyses.decompiler.known_patterns.pattern.PatternParam¶
Bases:
objectOne parameter of the synthesized call.
- Variables:
capture (
str) – Name of the pattern capture bound to this parameter.type (
str|CppRef|None) – Argument type for the synthesized call’s prototype; flows into Typehoon as a per-argument subtype constraint.type_hint – Optional cpp::std unique name emitted as a direct vvar type hint (for by-value captures where the vvar is the object rather than a pointer to it).
- capture: str
- class angr.analyses.decompiler.known_patterns.pattern.KnownPattern¶
Bases:
objectA known code idiom, described declaratively.
- Variables:
name (
str) – Identifier, e.g."std_string_length".display_name (
str) – Human-readable name, e.g."std::string::length".call_name (
str) – Target name of the synthesized Call.pattern (
PatternExpr|PatternStmt|PGraphPat) – The structural pattern to match.params (
tuple[PatternParam,...]) – Ordered parameters; their captures become the call arguments, in order.returnty (
str|CppRef|None) – Return type of the synthesized call.returnty_factory (
Callable[[Arch,dict[str,int]],SimType|None] |None) – Optional callable building a call-site-specific return type from the values of the constantextra_argscaptures (e.g. CONTAINING_RECORD returns a pointer to a record whose layout depends on the matched field offset). Falls back toreturntywhen it returns None or when the constant values are unavailable.extra_args (
tuple[str,...]) – Names of (typically constant) captures appended to the call arguments afterparams.arches (
tuple[str,...] |None) – Allowedarchinfo.Arch.namevalues; None = any.platforms (
tuple[str,...] |None) – Allowed OS names (project.simos.name, lowercased); None = any.where (
Callable[[dict[str,Expression]],bool] |None) – Optional cross-capture predicate evaluated on the bindings after a structural match.collapse_capture (
str|None) – Optional capture name identifying the idiom that a match belongs to: within one function, matches binding it to the same virtual variable all describe one source-level idiom, and only the one with the largestcollapse_max_captureconstant is kept. The compiler folds CONTAINING_RECORD’s subtraction into every field displacement, so one source idiom otherwise emits a call per field, each naming a different (and mostly wrong) record base.collapse_max_capture (
str|None) – Capture whose constant value orders the collapsing; required whencollapse_captureis set.binary_guard (
Callable[[Project],bool] |None) – Optional predicate on the Project; the pattern is only used when it returns True (e.g. require C++ evidence for STL patterns to avoid false positives on plain C binaries).default_enabled (
bool) – Whether the pattern is used when the caller does not explicitly select patterns. Generic patterns prone to false positives should set this False.
- name: str
- display_name: str
- call_name: str
- pattern: PatternExpr | PatternStmt | PGraphPat
- params: tuple[PatternParam, ...]
- suppressed_by: tuple[str, str, str] | None = None¶
Drop a match of this pattern when a pattern whose name matches the regex matched on the same object:
(name regex, my capture, their capture). The two captures must bind.likes()-equal expressions. This is how a generic accessor yields to a specific one on the same base: a bareLoad(s + 8)is std::string::length on a string and _M_finish on a vector, and the vector’s other fields say which. Judged against every match of the suppressing family, selected or not, so it cannot interact with largest-match selection.
- claims_only: bool = False¶
Match only to claim a base for
suppressed_bypurposes; never outlined, never rewritten, never reported. For shapes that identify an object beyond doubt but are not worth naming: a vector’s capacity check says “this is a vector” and nothing a reader wants a call for.
- pure_calls: frozenset[str] = frozenset({})¶
Callees this pattern reads through
PCallResultwhose only effect is their result: once the pattern has consumed that result and nothing else does, the call goes too. Naming a callee in a pattern is already a claim about what it computes; this is the claim that it computes nothing else.__ctype_b_locreturns a table pointer, and a bare__ctype_b_loc();left behind afterisspace(c)is noise.
- applicable(arch_name, platform)¶
- const_args_of_call(call)¶
Recover the
extra_argsconstant values from a synthesized call’s trailing arguments. Returns None when the call does not carry them.
- prototype(arch, const_args=None)¶
Build the synthesized call’s prototype.
const_args(the values of the constantextra_argscaptures, seeconst_args_of_call()) enables call-site-specific return types viareturnty_factory. Returns None if any declared type fails to resolve.- Return type:
- Parameters:
arch (archinfo.Arch)
- __init__(name, display_name, call_name, pattern, params, returnty=None, returnty_factory=None, extra_args=(), arches=None, platforms=None, where=None, collapse_capture=None, collapse_max_capture=None, binary_guard=None, default_enabled=True, suppressed_by=None, claims_only=False, pure_calls=frozenset({}))¶
- Parameters:
name (str)
display_name (str)
call_name (str)
pattern (PatternExpr | PatternStmt | PGraphPat)
params (tuple[PatternParam, ...])
returnty (TypeRef | None)
returnty_factory (Callable[[archinfo.Arch, dict[str, int]], SimType | None] | None)
where (Callable[[dict[str, Expression]], bool] | None)
collapse_capture (str | None)
collapse_max_capture (str | None)
default_enabled (bool)
claims_only (bool)
- Return type:
None