angr.analyses.decompiler.structured_codegen.c_serialize

Protobuf serialization helpers for the C AST defined in c.

The AST is serialized as a flat indexed table of CConstructNode cmessages: every CConstruct instance is assigned a non-zero uint32 node_id at serialize time, and child CConstructs are referenced by id. This avoids unbounded recursion in protobuf encoding and lets PositionMapping, cexterns, and map_addr_to_label reference into the AST without duplicating subtrees.

class angr.analyses.decompiler.structured_codegen.c_serialize.SerializeContext

Bases: object

Tracks which nodes have been serialized while walking the C AST.

__init__()
Return type:

None

nodes: list[CConstructNode]
intern_type(t)

Intern a SimType’s JSON encoding and return its ref (index+1 into the type pool); 0 for None.

Return type:

int

Parameters:

t (SimType | None)

property type_pool: list[str]
intern_tags(tags)

Intern a sanitized tags dict and return its ref (index+1 into the tag pool); 0 for no tags.

Return type:

int

Parameters:

tags (dict | None)

property tag_pool: list[CConstructTags]
intern_simvar(v)

Intern a SimVariable’s polymorphic payload and return its ref (index+1 into the pool); 0 for None.

Return type:

int

Parameters:

v (SimVariable | None)

property simvar_pool: list[bytes]
add_cfuncall_config(node_id, show_demangled_name, show_disambiguated_name)
Return type:

None

Parameters:
  • node_id (int)

  • show_demangled_name (bool)

  • show_disambiguated_name (bool)

property node_config: list[NodeConfigEntry]
serialize(node)

Serialize node (recursively) and return its node_id (== node.idx). 0 indicates absent.

Return type:

int

Parameters:

node (CConstruct | None)

class angr.analyses.decompiler.structured_codegen.c_serialize.ParseContext

Bases: object

Tracks and resolves node.idx to the corresponding C AST.

__init__(nodes_msg, project=None, kb=None, type_pool=(), tag_pool=(), simvar_pool=(), node_config=None)
Return type:

None

project
kb
cfuncall_config(node_id)

(show_demangled_name, show_disambiguated_name) for a CFunctionCall node; defaults to (True, True).

Return type:

tuple[bool, bool]

Parameters:

node_id (int)

resolve_type(ref)

Resolve a type-pool ref (index+1; 0 means absent) into a fresh SimType instance, arch-bound so it can report its size when re-rendered.

Return type:

SimType | None

Parameters:

ref (int)

resolve_simvar(ref)

Resolve a simvar-pool ref (index+1; 0 means absent) into a fresh SimVariable instance.

Return type:

SimVariable | None

Parameters:

ref (int)

resolve_tags(ref)

Resolve a tag-pool ref (index+1; 0 means no tags) into a fresh tags dict.

Return type:

dict

Parameters:

ref (int)

resolve(node_id)
Parameters:

node_id (int)

set_codegen(codegen)
Return type:

None

angr.analyses.decompiler.structured_codegen.c_serialize.serialize_subtree(root)

Serialize an AST subtree as a Codegen envelope carrying only the indexed table + root_id. For testing and any caller that wants to round-trip a CConstruct without a full codegen object.

Return type:

bytes

Parameters:

root (CConstruct)

angr.analyses.decompiler.structured_codegen.c_serialize.parse_subtree(data, project=None, kb=None)
Return type:

CConstruct | None

Parameters:

data (bytes)

angr.analyses.decompiler.structured_codegen.c_serialize.serialize_codegen(codegen)

Build a Codegen cmessage from a live CStructuredCodeGenerator instance.

Return type:

Codegen

angr.analyses.decompiler.structured_codegen.c_serialize.parse_codegen(msg, *, project=None, kb=None, func=None)

Create a CStructuredCodeGenerator from a Codegen cmessage. Bypasses __init__ (which runs the full decompilation pipeline) and populates the attributes directly. The parsed instance is suitable for display, navigation, and cache-validity checks; re-rendering and re-running analyses require project / func / kb to be reattached. Decompilation variables are read from kb.dec_variables.

angr.analyses.decompiler.structured_codegen.c_serialize.register_all()

Registers serializer/parser pairs for every concrete CConstruct subclass. Called from c.py at import time.

Return type:

None