angr.analyses.decompiler.known_patterns.edit¶
Edit a pattern the way a visual editor does: by node, with undo.
Pattern nodes are frozen, so an edit rebuilds the spine from the root down to the node it touches and leaves everything else shared. A node is addressed by its path, the sequence of field names, tuple indices and block labels that leads to it from the root, which is what a UI holds on to across rebuilds.
- angr.analyses.decompiler.known_patterns.edit.NodePath¶
field names, tuple indices, block labels
- Type:
how a node is reached from the pattern root
- angr.analyses.decompiler.known_patterns.edit.LEAF_MODES = ('required', 'optional', 'wildcard')¶
the three ways a leaf statement takes part in matching
- class angr.analyses.decompiler.known_patterns.edit.PatternEditor¶
Bases:
objectA
KnownPatternunder edit.- __init__(pattern)¶
- Parameters:
pattern (KnownPattern)
- node_at(path)¶
- Return type:
- Parameters:
- restorable(path)¶
The most recent form the wildcard at
pathhad before it became one, from the edit history, or None if it has always been a wildcard (as a generator-made one is).- Return type:
- Parameters:
- children(path)¶
The pattern nodes directly under the node at
path, in field order.
- leaves()¶
Every leaf statement with its path, in the order the matcher aligns them.
- static leaf_mode(leaf)¶
- replace_node(path, new_node)¶
- Return type:
- Parameters:
new_node (PatternNode)
- set_leaf_mode(path, mode)¶
requiredoroptionalkeep the statement’s shape;wildcarddrops it for a PAnyStmt that keeps the weight and optionality. Leavingwildcardbrings back the shape the statement had before, when the history has one.
- restore_node(path)¶
Put back the form the wildcard at
pathhad before it became one, as one undoable edit; a statement keeps its current weight and optionality. Returns whether it could.
- set_leaf_weight(path, weight)¶
- set_expr_wildcard(path)¶
Replace an expression node by PAny, keeping its capture name and width if it had them.
- set_const(path, value, bits=None, *, symbol=None)¶
Pin a constant to a value, or to a symbol’s address in whatever binary is matched. One or the other: a symbol names the value, so giving both is refused.
- set_vvar(path, bits, categories)¶
- set_load_size(path, size)¶
- set_ops(path, ops)¶
- loosen_constants()¶
Drop the value of every pinned constant, as one undoable edit. Copies of an idiom that differ only in their constants, a decryption loop’s keys and sizes, say, are exactly what a fuzzy pattern is for, and pinning them is what a lifted pattern starts out doing. Returns how many constants were loosened.
- Return type:
- cut_depth(max_depth=5)¶
Replace every expression deeper than
max_depthbelow its statement by a wildcard, as one undoable edit. Shape search is cut at that depth, so anything below it never affects where an occurrence is found; it only bites at verification, where two copies of an idiom that differ in how they spell a deep subexpression part ways. Returns how many subtrees were cut.
- loosen_interior_captures()¶
Drop the names of interior captures (the
_t*ones the generator gives values defined inside the selection), as one undoable edit. A name ties every use to one variable; a copy that routes the same value through another register then fails to verify. Parameters keep their names. Returns how many captures were loosened.- Return type:
- set_param_type(capture, typeref)¶
- add_param(capture, typeref=None)¶
- classmethod from_dict(data)¶
- Return type:
- Parameters:
- angr.analyses.decompiler.known_patterns.edit.describe(node)¶
A short label for a node: what it is and what it constrains.
- Return type:
- Parameters:
node (PatternNode)