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:
objectTracks 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.
- intern_tags(tags)¶
Intern a sanitized tags dict and return its ref (index+1 into the tag pool); 0 for no tags.
- 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:
- Parameters:
v (SimVariable | None)
- add_cfuncall_config(node_id, show_demangled_name, show_disambiguated_name)¶
- property node_config: list[NodeConfigEntry]¶
- serialize(node)¶
Serialize
node(recursively) and return its node_id (== node.idx). 0 indicates absent.- Return type:
- Parameters:
node (CConstruct | None)
- class angr.analyses.decompiler.structured_codegen.c_serialize.ParseContext¶
Bases:
objectTracks 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).
- 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.
- resolve_simvar(ref)¶
Resolve a simvar-pool ref (index+1; 0 means absent) into a fresh SimVariable instance.
- Return type:
- Parameters:
ref (int)
- resolve_tags(ref)¶
Resolve a tag-pool ref (index+1; 0 means no tags) into a fresh tags dict.
- 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:
- Parameters:
root (CConstruct)
- angr.analyses.decompiler.structured_codegen.c_serialize.parse_subtree(data, project=None, kb=None)¶
- Return type:
- Parameters:
data (bytes)
- angr.analyses.decompiler.structured_codegen.c_serialize.serialize_codegen(codegen)¶
Build a Codegen cmessage from a live CStructuredCodeGenerator instance.
- Return type:
- 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/kbto be reattached. Decompilation variables are read fromkb.dec_variables.