angr.analyses.decompiler.region_overlay¶
- class angr.analyses.decompiler.region_overlay.RegionBound¶
Bases:
ProtocolThe protocol indicating the minimum capabilities of graph nodes to be managed by an overlay region.
- __init__(*args, **kwargs)
- type angr.analyses.decompiler.region_overlay.Tx[U: RegionBound] = U | RegionOverlay[U]¶
- angr.analyses.decompiler.region_overlay.merge_edge_data(acc, data)¶
Merge the data of two complete-graph edges that are about to be merged.
abnormal_entrymerged with an untagged edge keeps the tag and gainsnormal_entry: The jump into the body still becomes a goto later, but the edge must be kept.
- class angr.analyses.decompiler.region_overlay.OverlayManager¶
Bases:
Generic[T]OverlayManager owns the single (complete) control-flow graph that all RegionOverlay objects are views of, plus the node-to-innermost-overlay ownership map.
All structural mutations of the complete graph must go through this class (usually via RegionOverlay methods) so that ownership, caches, and the undo log stay consistent.
- __init__(graph, expose_loop_head_backedges=False)¶
- Parameters:
graph (networkx.DiGraph[T])
expose_loop_head_backedges (bool)
- graph
- expose_loop_head_backedges
- root
- commit(to)¶
Discard undo information past the given checkpoint. If the checkpoint is 0, stop recording entirely.
- graph_strip_entry_tags(src, dst)¶
Drop the abnormal_entry / normal_entry tags of an edge.
- Return type:
- class angr.analyses.decompiler.region_overlay.RegionOverlay¶
Bases:
Generic[T]A single-entry region marked over the complete graph held by an OverlayManager. The region tree is built out of RegionOverlay objects (RegionIdentifier emits them) and they are the only region type the decompiler uses.
Overlays form a tree (nested, never overlapping). An overlay’s members are either complete-graph nodes it owns directly or child overlays. The region graph and the region graph-with-successors are derived on demand from the complete graph by quotienting child overlays into single nodes; successors are likewise derived from edges that cross the region boundary, so they can never go stale.
Read-only API (
head,graph,graph_with_successors,successors,cyclic,addr) mirrors the region container consumers expect;graph/graph_with_successors/successorsare lazy zero-copy views.Mutation verbs:
true structural changes (
add_node,remove_node,add_edge,detach_edge,replace_nodes) pass through to the complete graph, so the effects are immediately visible to all enclosing regions;hide_edgeremoves an edge from this overlay’s views only (the old “remove it from region graphs but keep the parent edge” pattern);finalize(result_node)collapses a fully-structured region into a single node of its parent;dissolve()merges an unsuccessfully-structured region back into its parent.
- __init__(mgr, head, cyclic, cyclic_ancestor=False, parent=None)¶
- Parameters:
mgr (OverlayManager[T])
head (Tx[T] | None)
cyclic (bool)
cyclic_ancestor (bool)
parent (RegionOverlay | None)
- head
- cyclic
- cyclic_ancestor
- parent
- children: list[RegionOverlay]
- replacement
- property addr¶
- property manager: OverlayManager[T]¶
- ancestors()¶
All overlays enclosing this one, including this one itself.
- Return type:
- underlying_nodes()¶
All complete-graph nodes inside this region (including nodes of nested regions).
- Return type:
set[T]
- create_subregion(head, members, cyclic, cyclic_ancestor=False)¶
Carve a new child overlay out of this overlay.
membersmust be a subset of this overlay’s members (complete-graph nodes owned by this overlay and/or existing child overlays);headmust be one of them.- Return type:
- Parameters:
- representative(node)¶
The node standing for a complete-graph node in this overlay’s with-successors view.
- successor_nodes()¶
The derived successor set of this region: representatives of all complete-graph nodes targeted by edges leaving the region.
- view_graph(full=False, include_marked=False, blacklisted_edges=frozenset({}))¶
A zero-copy, networkx-compatible view of this region (see RegionOverlayGraph).
- Return type:
- Parameters:
- view()¶
The region graph (members only): a zero-copy networkx-compatible view; treat it as read-only.
- Return type:
- view_with_successors()¶
The region graph including successor nodes: a zero-copy view; treat it as read-only.
- Return type:
- property raw_graph: RegionOverlayGraph[T]¶
The member view including marked edges (the old graph with cyclic_refinement_outgoing attrs present).
- property raw_graph_with_successors: RegionOverlayGraph[T]¶
The with-successors view including marked edges.
- complete_graph_entry_count(node)¶
The number of edges entering a node in the complete graph, counted over every region. For a region object, the entries of its head from outside the region (its own back edges do not count).
- external_entry_count(node)¶
The number of edges entering a node (a successor of this region) from nodes that are not under this region: the entries it keeps once every edge from this region to it has been virtualized.
- add_node(node)¶
Insert a new node into the complete graph as a direct member of this region.
- Return type:
- remove_node(node, absorbed_into=None, absorb_out_edges=True)¶
Remove a node. If
nodeis a member (or a member overlay’s node), it is removed from the complete graph for real. If it is a successor of this region, the removal is interpreted as hiding all edges from this region to it (the successor belongs to an enclosing region and must survive).When the node’s content has been absorbed into another node during structuring, pass that node as
absorbed_into: in-edges from outside this region (e.g. abnormal loop entries) are then rewired to it instead of being dropped, so enclosing regions keep their entry edges. Withabsorb_out_edges(the default), out-edges crossing the region boundary (e.g. loop exits) are rewired to it as well, so the complete graph never loses the region’s exit flow; pass False only when the caller re-establishes every successor edge explicitly.
- underlying_edge_pairs(src, dst)¶
- add_edge(src, dst, **data)¶
Add a real edge to the complete graph. Overlay endpoints are resolved to underlying nodes: the destination resolves to its entry (head chain); overlay sources are not supported. Endpoints that are not in the complete graph yet become members of this region (mirroring networkx’s implicit node creation).
- detach_raw_edge(u, v)¶
Remove exactly one complete-graph edge. Unlike detach_edge, other edges between the view nodes representing u and v are kept (e.g. a block that jumps both to a loop’s entry and into its body).
- Return type:
- Parameters:
u (T)
v (T)
- detach_edge(src, dst)¶
Remove an edge from the complete graph for real (e.g., when the edge has been virtualized into a goto). Overlay endpoints remove all underlying edges between the two node sets.
- mark_edge(src, dst, **attrs)¶
Mark a view-level edge (e.g. cyclic_refinement_outgoing) so RegionOverlayGraph hides it by default. Marks live in overlay state, never reach the complete graph, and are remapped/cleared with the region.
- absorb_successor_into(succ, new_node)¶
Absorb a successor node into a structured member node in this region’s with-successors view only (the successor still belongs to an enclosing region): the successor’s view out-edges are re-attached to the member node as view-only extra edges, then the successor disappears from this region’s views.
- drop_edge_marks_from(node, key)¶
Clear marks on all out-edges of a node (the new_node after a replace), undoably.
- remove_edge_with_successors_only(src, dst)¶
Hide an edge from the with-successors view only, leaving the member view and the complete graph alone (a rare asymmetric bookkeeping pattern in Phoenix’s switch-case structuring).
The view-level edges that remove_edge_with_successors_only() hid from the with-successors view.
- hide_edge(src, dst)¶
Remove an edge from this overlay’s views only. Enclosing regions still see the underlying edge(s).
- replace_nodes(old_node_0, new_node, old_node_1=None, self_loop=True)¶
Replace one or two member nodes with a new node, preserving and rewiring all underlying edges (including edges from/to nodes outside this region, which is how results become visible to enclosing regions).
Mirrors StructurerBase.replace_nodes, with one deliberate difference: in-edges of
old_node_1from outside this region are rewired tonew_nodeinstead of being dropped (they are entry edges owned by enclosing regions, e.g. abnormal loop entries).
- snapshot_successors()¶
Capture this region’s structural successors and how many member edges reach each, taken before the region is structured. finalize() uses it to re-establish the region-to-successor edges that structuring removes when it refines the corresponding control-flow edges into breaks, and to tell successors whose every member edge was virtualized into a goto (see detach_edge()).
- finalize(result_node=None, succ_snapshot=None)¶
Collapse this fully-structured region into its parent: the region must consist of a single member node (the structuring result), which takes the region’s place among the parent’s members. Returns that node.
succ_snapshot(from snapshot_successors() before structuring) is used to re-establish the edges from result_node to the region’s successors: structuring may have removed the live control-flow edges (refining them into breaks), but the structured region still flows to those successors and enclosing regions must see that.A successor whose every member edge was virtualized into a goto (detach_edge()) is a pure goto target and must NOT be reconnected. Consider a loop with two exits, where
erris shared with other loops of the function:while (1) { if (s->bsLive >= 8) break; // exit A: the loop successor if (s->strm->avail_in == 0) goto err; // exit B: virtualized into a goto by cyclic refinement refill(); } uc = take_bits(); // A ... err: retVal = BZ_DATA_ERROR; goto save_state_and_return;
The loop region has successors A and err. Cyclic refinement keeps A as the loop successor (a break) and turns the exit to err into a goto statement, removing that edge from the complete graph. Reconnecting err here would give the loop node two successors in the parent region, one real and one fictitious: the ITE schema finds no conditions on them, the sequence schema needs a single successor, and last-resort refinement keeps both edges because each target would be orphaned, so the parent region can never be structured. With only A reconnected, the loop node is sequenced with A as usual and err stays reachable through its gotos. Cyclic refinement never virtualizes an exit that is its target’s only entry in the complete graph: the region bails and dissolves into its parent, where the target is a member and the acyclic schemas structure it with the loop.
- collapse_to(result_node)¶
Collapse this region into its parent by replacing all of its member nodes with a single external result node (the structuring result). Used by structurers that compute their result without destructively reducing the complete graph (e.g. DreamStructurer): the region’s members are still present, so their crossing in/out edges are rewired onto
result_nodeand the members are removed. Returns result_node.This is the non-self-collapsing counterpart of finalize(); the legacy GraphRegion path called replace_region() for the same purpose.
- Parameters:
result_node (RegionOverlay[T])
- class angr.analyses.decompiler.region_overlay.RegionOverlayGraph¶
Bases:
DiGraph,Generic[T]A read-only, networkx-compatible view of a RegionOverlay that stores no copy of the region’s subgraph: all queries traverse the original complete graph through the overlay’s membership. Compatible with every networkx algorithm and DiGraph read method because the graph’s storage mappings are replaced with lazy atlases.
fullselects the with-successors view (the old graph_with_successors) over the member view.Edges marked through RegionOverlay.mark_edge (e.g. cyclic_refinement_outgoing) are filtered out by default; pass
all_edges=Trueto the query methods, or use with_all_edges(), to include them.to_acyclic() derives a view with additional edges blacklisted (e.g. the region head’s in-edges), replacing the acyclic graph copies that structuring used to make.
- property full_view: RegionOverlayGraph[T]¶
The with-successors sibling of this view (zero-copy).
- property member_view: RegionOverlayGraph[T]¶
The members-only sibling of this view (zero-copy).
- with_all_edges()¶
A sibling view that includes edges marked through RegionOverlay.mark_edge.
- Return type:
- filtered()¶
A sibling view that hides edges marked through RegionOverlay.mark_edge (the default).
- Return type:
- to_acyclic_by_order(node_order)¶
An acyclic view of this graph, obtained by blacklisting back edges (edges whose source is ordered at or after their destination in
node_order). Replaces utils.graph.to_acyclic_graph without a copy.- Return type:
- Parameters:
- to_acyclic(blacklisted_edges)¶
A new view with the given (view-level) edges additionally blacklisted; used to traverse the region as an acyclic graph without copying it.
- Return type:
- Parameters:
- reverse_view()¶
The reversed view of this graph (zero-copy).
- Return type:
- materialize()¶
An independent networkx.DiGraph copy of this view.
- Return type:
networkx.DiGraph[Tx[T]]