angr.knowledge_plugins.cfg.spilling_cfg

CFG graph storage: CFGNode instances live in SpillingCFGNodeDict (LRU caching + LMDB spilling, following the SpillingFunctionDict pattern); the graph structure and edge attributes live in the packed Rust store CfgGraph.

class angr.knowledge_plugins.cfg.spilling_cfg.SpillingCFGNodeDict

Bases: object

A dict-like container for CFGNode instances with LRU caching and LMDB spilling.

This class keeps only the most recently accessed N nodes in memory, spilling others to an LMDB database on disk.

Variables:
__init__(rtdb, cfg_model=None, cache_limit=1000, db_batch_size=200)
Parameters:
get(block_key, default=None)
Return type:

CFGNode | None

Parameters:
keys()
Return type:

Iterator[tuple[int, int] | tuple[BlockID, int, int] | SootAddressDescriptor]

values()
Return type:

Iterator[CFGNode]

items()
Return type:

Iterator[tuple[tuple[int, int] | tuple[BlockID, int, int] | SootAddressDescriptor, CFGNode]]

clear()
Return type:

None

copy()
Return type:

SpillingCFGNodeDict

property cache_limit: int
property db_batch_size: int
property cached_count: int
property spilled_count: int
property total_count: int
is_cached(block_key)
Return type:

bool

Parameters:

block_key (tuple[int, int] | tuple[BlockID, int, int] | SootAddressDescriptor)

bulk_import_serialized(items)

Bulk-import already-serialized CFG nodes directly into the LMDB backing store and register them as spilled, without deserializing them. Each payload must be in the format that _save_to_lmdb() writes: a type byte (0x00 for CFGNode, 0x01 for CFGENode) followed by the serialized protobuf message.

Parameters:

items (list[tuple[tuple[int, int] | tuple[BlockID, int, int] | SootAddressDescriptor, bytes]]) – A list of (block key, serialized node payload) tuples.

Return type:

None

load_all_spilled()
Return type:

None

evict_all_cached()
Return type:

None

class angr.knowledge_plugins.cfg.spilling_cfg.CFGSegmentStore

Bases: object

Backend for paged CfgGraph segments on the RuntimeDb: one LMDB sub-database shared by every graph of the knowledge base, keys prefixed with a per-graph random id.

DB_NAME = 'cfgsegments'
__init__(rtdb)
Parameters:

rtdb (RuntimeDb)

get(window)
Return type:

bytes | None

Parameters:

window (int)

put(window, data)
Return type:

None

Parameters:
delete(window)
Return type:

None

Parameters:

window (int)

delete_all()
Return type:

None

angr.knowledge_plugins.cfg.spilling_cfg.get_block_key(node)

Get the unique identifier for a CFGNode. Typically this unique identifier contains the address of the block and the looping_times of the block (in case there are multiple blocks with the same address, which may happen after loop unrolling in a CFGEmulated instance).

Overloads:
Parameters:

node (CFGNode | CFGENode) – The CFGNode or CFGENode instance to get the block key for.

Returns:

The unique identifier.

Return type:

tuple[int, int] | tuple[BlockID, int, int] | SootAddressDescriptor

angr.knowledge_plugins.cfg.spilling_cfg.block_key_to_addr(block_key)

Extract the address from a block key.

Overloads:
Parameters:

block_key (tuple[int, int] | tuple[BlockID, int, int] | SootAddressDescriptor)

Return type:

int | SootAddressDescriptor

angr.knowledge_plugins.cfg.spilling_cfg.block_key_to_size(block_key)

Extract the size from a block key, if present.

Return type:

int | None

Parameters:

block_key (tuple[int, int] | tuple[BlockID, int, int] | SootAddressDescriptor)

class angr.knowledge_plugins.cfg.spilling_cfg.SpillingCFG

Bases: object

A graph wrapper that stores CFGNode instances in a spilling dict while keeping the graph structure in a packed Rust store (CfgGraph) keyed by block keys.

This provides a networkx-compatible interface while supporting disk-backed storage for the nodes of large CFGs.

addr_type must be “int”, “block_id”, or “soot”. You can change addr_type before the first node is inserted but not after, since it affects how keys are mapped onto the store.

__init__(rtdb=None, cfg_model=None, cache_limit=None, db_batch_size=800, addr_type='int', segment_budget=None)
Parameters:
  • segment_budget (int | None) – Byte budget for resident graph segments; the graph is paged to the RuntimeDb from the start. Setting this parameter to None means the whole graph will be kept resident in RAM.

  • rtdb (RuntimeDb | None)

  • cfg_model (CFGModel | None)

  • cache_limit (int | None)

  • db_batch_size (int)

  • addr_type (CFG_ADDR_TYPES)

property addr_type: str
property paged: bool

Whether graph segments are paged to the RuntimeDb.

property segment_budget: int | None
segment_stats()

Segment paging counters: loads, evictions, writebacks, resident/total segments, resident bytes.

Return type:

dict

flush()

Compact resident segments and write dirty ones back to the backend (no-op when not paged).

Return type:

None

get_node_by_key(block_key)

Get a CFGNode by block key.

Return type:

CFGNode

Parameters:

block_key (tuple[int, int] | tuple[BlockID, int, int] | SootAddressDescriptor)

property node_keys: Iterator[tuple[int, int] | tuple[BlockID, int, int] | SootAddressDescriptor]

Get an iterator over all block_keys in the graph.

add_node(node, **attr)
Return type:

None

Parameters:

node (CFGNode)

export_serialized_nodes()

Export every node as the serialized bytes of its CFGNode/CFGENode protobuf message (without the LMDB type byte), e.g. for dumping into an angr database.

Nodes are byte-copied directly out of the LMDB backing store without being deserialized and re-serialized.

Return type:

list[tuple[tuple[int, int] | tuple[BlockID, int, int] | SootAddressDescriptor, bytes, bool]]

Returns:

A list of (block key, serialized CFGNode message bytes, copied_from_lmdb) tuples.

bulk_import_serialized_nodes(items)

Bulk-import already-serialized nodes directly into the LMDB backing store as spilled entries, without constructing any CFGNode objects.

Parameters:

items (list[tuple[tuple[int, int] | tuple[BlockID, int, int] | SootAddressDescriptor, int | SootAddressDescriptor, bytes]]) – A list of (block key, node address, serialized node payload) tuples. See SpillingCFGNodeDict.bulk_import_serialized() for the payload format.

Return type:

None

remove_node(node)
Return type:

None

Parameters:

node (CFGNode)

has_node(node)
Return type:

bool

Parameters:

node (CFGNode)

nodes_by_addr(addr)
Return type:

Iterator[CFGNode]

Parameters:

addr (int)

first_key_at_addr(addr)

The block key of the first node at the given address, or None.

Return type:

tuple[int, int] | tuple[BlockID, int, int] | SootAddressDescriptor | None

Parameters:

addr (int | SootAddressDescriptor)

has_node_addr(addr)
Return type:

bool

Parameters:

addr (int)

node_addrs()

Distinct addresses of all nodes.

Return type:

list[int | SootAddressDescriptor]

number_of_nodes()
Return type:

int

property nodes: _NodeView

Return a view of nodes supporting len(), iteration, and call with data=True.

add_edge(src, dst, **attr)
Return type:

None

Parameters:
add_edge_by_key(src_block_key, dst_block_key, **attr)
Return type:

None

Parameters:
remove_edge(src, dst)
Return type:

None

Parameters:
remove_edge_by_key(src_block_key, dst_block_key)
Return type:

None

Parameters:
has_edge(src, dst)
Return type:

bool

Parameters:
has_edge_by_key(src_block_key, dst_block_key)
Return type:

bool

Parameters:
get_edge_data(src, dst, default=None)
Return type:

dict | None

Parameters:
number_of_edges()
Return type:

int

property edges: _EdgeView

Return a view of edges supporting len(), iteration, and call with data=True.

property call_destination_keys: set[tuple[int, int] | tuple[BlockID, int, int] | SootAddressDescriptor]

Return the set of block keys that are destinations of call/syscall edges.

call_destination_nodes()

Yield CFGNode for each call/syscall destination.

Return type:

Iterator[CFGNode]

predecessors(node)
Return type:

Iterator[CFGNode]

Parameters:

node (CFGNode)

successors(node)
Return type:

Iterator[CFGNode]

Parameters:

node (CFGNode)

property in_edges: _InEdgeView

Return a view of in-edges supporting call, subscript, len, and iteration.

property out_edges: _OutEdgeView

Return a view of out-edges supporting call, subscript, len, and iteration.

property in_degree: _InDegreeView

Return a view of in-degrees supporting call, subscript, len, and iteration.

property out_degree: _OutDegreeView

Return a view of out-degrees supporting call, subscript, len, and iteration.

out_edges_by_key(key, data=False)
Overloads:
Parameters:
Return type:

Generator[tuple[tuple[int, int] | tuple[BlockID, int, int] | SootAddressDescriptor, tuple[int, int] | tuple[BlockID, int, int] | SootAddressDescriptor] | tuple[tuple[int, int] | tuple[BlockID, int, int] | SootAddressDescriptor, tuple[int, int] | tuple[BlockID, int, int] | SootAddressDescriptor, dict]]

out_degree_by_key(key)
Return type:

int

Parameters:

key (tuple[int, int] | tuple[BlockID, int, int] | SootAddressDescriptor)

copy()
Return type:

SpillingCFG

subgraph(nodes)

Return a subgraph as a regular networkx DiGraph with CFGNode instances. This is useful for algorithms that need a pure networkx graph.

Return type:

DiGraph

to_networkx()

Convert to a pure networkx DiGraph with CFGNode instances as nodes. Warning: This loads all spilled nodes into memory.

Return type:

DiGraph

from_networkx(nx_graph)

Load graph structure from a networkx DiGraph with CFGNode instances as nodes.

Return type:

None

Parameters:

nx_graph (DiGraph)

property cache_limit: int | None
property db_batch_size: int
property cached_count: int
property spilled_count: int
load_all_spilled()
Return type:

None

evict_all_cached()
Return type:

None

set_rtdb(rtdb)

(Re-)attach a RuntimeDb to this graph and its node store. This is used after unpickling (rtdb references are not preserved across pickling) so that node spilling works again.

Return type:

None

Parameters:

rtdb (RuntimeDb | None)