angr.analyses.decompiler.region_overlay

class angr.analyses.decompiler.region_overlay.RegionBound

Bases: Protocol

The protocol indicating the minimum capabilities of graph nodes to be managed by an overlay region.

property addr: int
__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_entry merged with an untagged edge keeps the tag and gains normal_entry: The jump into the body still becomes a goto later, but the edge must be kept.

Return type:

dict[str, Any]

Parameters:
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
property version: int
owner_of(node)
Return type:

Optional[RegionOverlay[T]]

Parameters:

node (Tx[T])

checkpoint()
Return type:

int

rollback(to)
Return type:

None

Parameters:

to (int)

commit(to)

Discard undo information past the given checkpoint. If the checkpoint is 0, stop recording entirely.

Return type:

None

Parameters:

to (int)

graph_add_edge(src, dst, **data)
Return type:

None

graph_strip_entry_tags(src, dst)

Drop the abnormal_entry / normal_entry tags of an edge.

Return type:

None

graph_remove_edge(src, dst)
Return type:

None

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/successors are 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_edge removes 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:
head
cyclic
cyclic_ancestor
parent
children: list[RegionOverlay]
edge_marks: defaultdict[str, set[tuple[Tx[T], Tx[T]]]]
replacement
property addr
property manager: OverlayManager[T]
property members: set[Tx[T]]
ancestors()

All overlays enclosing this one, including this one itself.

Return type:

set[RegionOverlay]

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. members must be a subset of this overlay’s members (complete-graph nodes owned by this overlay and/or existing child overlays); head must be one of them.

Return type:

RegionOverlay[T]

Parameters:
  • head (Tx[T])

  • members (Iterable)

  • cyclic (bool)

  • cyclic_ancestor (bool)

representative(node)

The node standing for a complete-graph node in this overlay’s with-successors view.

Return type:

Tx[T] | None

Parameters:

node (T)

successor_nodes()

The derived successor set of this region: representatives of all complete-graph nodes targeted by edges leaving the region.

Return type:

set[Tx[T]]

view_graph(full=False, include_marked=False, blacklisted_edges=frozenset({}))

A zero-copy, networkx-compatible view of this region (see RegionOverlayGraph).

Return type:

RegionOverlayGraph[T]

Parameters:
view()

The region graph (members only): a zero-copy networkx-compatible view; treat it as read-only.

Return type:

RegionOverlayGraph[T]

view_with_successors()

The region graph including successor nodes: a zero-copy view; treat it as read-only.

Return type:

RegionOverlayGraph[T]

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.

property graph: networkx.DiGraph[Tx[T]]
property graph_with_successors: networkx.DiGraph[Tx[T]]
property successors: set[Tx[T]]
property full_graph: None
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).

Return type:

int

Parameters:

node (Tx[T])

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.

Return type:

int

Parameters:

node (Tx[T])

add_node(node)

Insert a new node into the complete graph as a direct member of this region.

Return type:

None

remove_node(node, absorbed_into=None, absorb_out_edges=True)

Remove a node. If node is 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. With absorb_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.

Return type:

None

Parameters:
  • node (Tx[T])

  • absorbed_into (Tx[T] | None)

  • absorb_out_edges (bool)

hide_edge_to_successor(succ)
Return type:

None

underlying_edge_pairs(src, dst)
Return type:

list[tuple[Tx[T], Tx[T]]]

Parameters:
  • src (Tx[T])

  • dst (Tx[T])

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).

Return type:

None

Parameters:
  • src (Tx[T])

  • dst (Tx[T])

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:

None

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.

Return type:

None

Parameters:
  • src (Tx[T])

  • dst (Tx[T])

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.

Return type:

None

Parameters:
  • src (Tx[T])

  • dst (Tx[T])

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.

Return type:

None

Parameters:
  • succ (Tx[T])

  • new_node (Tx[T])

drop_edge_marks_from(node, key)

Clear marks on all out-edges of a node (the new_node after a replace), undoably.

Return type:

None

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

Return type:

None

Parameters:
  • src (Tx[T])

  • dst (Tx[T])

successors_only_hidden_edges()

The view-level edges that remove_edge_with_successors_only() hid from the with-successors view.

Return type:

set[tuple[Tx[T], Tx[T]]]

hide_edge(src, dst)

Remove an edge from this overlay’s views only. Enclosing regions still see the underlying edge(s).

Return type:

None

Parameters:
  • src (Tx[T])

  • dst (Tx[T])

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_1 from outside this region are rewired to new_node instead of being dropped (they are entry edges owned by enclosing regions, e.g. abnormal loop entries).

Return type:

None

Parameters:
  • old_node_0 (Tx[T])

  • new_node (Tx[T])

  • old_node_1 (Tx[T] | None)

  • self_loop (bool)

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()).

Return type:

dict[Tx[T], int]

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 err is 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.

Parameters:
  • result_node (Tx[T] | None)

  • succ_snapshot (set[Tx[T]] | None)

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_node and 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])

dissolve()

Merge this region back into its parent (the failure path of structuring): members are reparented, and edges hidden in this region stay hidden in the parent (matching how partially-structured region graphs were merged back before).

Return type:

None

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.

  • full selects 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=True to 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:

RegionOverlayGraph[T]

filtered()

A sibling view that hides edges marked through RegionOverlay.mark_edge (the default).

Return type:

RegionOverlayGraph[T]

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:

RegionOverlayGraph[T]

Parameters:

node_order (Mapping[Tx[T], int])

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:

RegionOverlayGraph[T]

Parameters:

blacklisted_edges (Sequence[tuple[Tx[T], Tx[T]]])

reverse_view()

The reversed view of this graph (zero-copy).

Return type:

RegionOverlayGraph[T]

materialize()

An independent networkx.DiGraph copy of this view.

Return type:

networkx.DiGraph[Tx[T]]

edge_marked(u, v, mark_name=None)
Return type:

bool

Parameters:
  • u (Tx[T])

  • v (Tx[T])

  • mark_name (str | None)