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

alias of tuple[str | int, …]

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: object

A KnownPattern under edit.

__init__(pattern)
Parameters:

pattern (KnownPattern)

node_at(path)
Return type:

PatternNode

Parameters:

path (tuple[str | int, ...])

restorable(path)

The most recent form the wildcard at path had 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:

PatternNode | None

Parameters:

path (tuple[str | int, ...])

children(path)

The pattern nodes directly under the node at path, in field order.

Return type:

list[tuple[tuple[str | int, ...], PatternNode]]

Parameters:

path (tuple[str | int, ...])

leaves()

Every leaf statement with its path, in the order the matcher aligns them.

Return type:

list[tuple[tuple[str | int, ...], PAssign | PStore | PCallStmt | PCondJump | PReturn | PAnyStmt]]

static leaf_mode(leaf)
Return type:

str

Parameters:

leaf (PAssign | PStore | PCallStmt | PCondJump | PReturn | PAnyStmt)

replace_node(path, new_node)
Return type:

None

Parameters:
set_leaf_mode(path, mode)

required or optional keep the statement’s shape; wildcard drops it for a PAnyStmt that keeps the weight and optionality. Leaving wildcard brings back the shape the statement had before, when the history has one.

Return type:

None

Parameters:
restore_node(path)

Put back the form the wildcard at path had before it became one, as one undoable edit; a statement keeps its current weight and optionality. Returns whether it could.

Return type:

bool

Parameters:

path (tuple[str | int, ...])

set_leaf_weight(path, weight)
Return type:

None

Parameters:
set_expr_wildcard(path)

Replace an expression node by PAny, keeping its capture name and width if it had them.

Return type:

None

Parameters:

path (tuple[str | int, ...])

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.

Return type:

None

Parameters:
set_vvar(path, bits, categories)
Return type:

None

Parameters:
set_load_size(path, size)
Return type:

None

Parameters:
set_ops(path, ops)
Return type:

None

Parameters:
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:

int

cut_depth(max_depth=5)

Replace every expression deeper than max_depth below 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.

Return type:

int

Parameters:

max_depth (int)

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:

int

set_call_name(call_name)
Return type:

None

Parameters:

call_name (str)

set_name(name)
Return type:

None

Parameters:

name (str)

set_display_name(display_name)
Return type:

None

Parameters:

display_name (str)

set_returnty(returnty)
Return type:

None

Parameters:

returnty (str | CppRef | None)

set_param_type(capture, typeref)
Return type:

None

Parameters:
add_param(capture, typeref=None)
Return type:

None

Parameters:
remove_param(capture)
Return type:

None

Parameters:

capture (str)

property can_undo: bool
undo()
Return type:

bool

to_dict()
Return type:

dict[str, Any]

classmethod from_dict(data)
Return type:

PatternEditor

Parameters:

data (dict[str, Any])

angr.analyses.decompiler.known_patterns.edit.describe(node)

A short label for a node: what it is and what it constrains.

Return type:

str

Parameters:

node (PatternNode)