angr.analyses.decompiler.structured_codegen.go¶
Go-flavored structured code generator. A fork of the C backend (c.py) that renders Go syntax.
- type angr.analyses.decompiler.structured_codegen.go.RenderResult = tuple[str, PositionMapping, PositionMapping, InstructionMapping, dict[Any, set[Any]]]¶
- angr.analyses.decompiler.structured_codegen.go.qualifies_for_simple_cast(ty1, ty2)¶
- angr.analyses.decompiler.structured_codegen.go.qualifies_for_width_cast(ty)¶
- angr.analyses.decompiler.structured_codegen.go.qualifies_for_implicit_cast(ty1, ty2)¶
- angr.analyses.decompiler.structured_codegen.go.extract_terms(expr)¶
- Return type:
- Parameters:
expr (GoExpression)
- angr.analyses.decompiler.structured_codegen.go.is_machine_word_size_type(type_, arch)¶
- Return type:
- Parameters:
type_ (SimType)
arch (archinfo.Arch)
- angr.analyses.decompiler.structured_codegen.go.guess_value_type(value, project)¶
- angr.analyses.decompiler.structured_codegen.go.type_equals(t0, t1)¶
- angr.analyses.decompiler.structured_codegen.go.type_layout_key(ty, _seen=frozenset({}))¶
A structural sort key for a type, derived purely from its memory layout (sizes, field offsets, and the layouts of field/element/pointee types) and not from any user-renamable struct or field name. This lets the code generator order type definitions stably without their order changing when the user renames a struct or a field. Cycles through recursive struct/pointer references are broken with a marker.
- angr.analyses.decompiler.structured_codegen.go.cextern_sort_key(cextern)¶
A stable sort key for extern variables, based on the variable’s address. Unlike the variable name, the address does not change when the user renames the variable, so the ordering of extern definitions stays put across renames.
- Return type:
- angr.analyses.decompiler.structured_codegen.go.go_type_str(ty, memo=None)¶
Spell a SimType the Go way. Only C-flavored SimTypes reach here until Go-specific SimTypes exist; they are mapped onto the closest Go builtin by size and signedness.
- angr.analyses.decompiler.structured_codegen.go.type_to_go_repr_chunks(ty, name=None, name_type=None, full=False, indent_str='', indent_delta=4, memo=None)¶
Helper generator function to turn a SimType into generated tuples of (Go-string, AST node).
Go declarations put the name first (
name T); a full struct definition renders astype Name struct {...}.
- class angr.analyses.decompiler.structured_codegen.go.GoConstruct¶
Bases:
objectRepresents a program construct in C. Acts as the base class for all other representation constructions.
- __init__(codegen, tags=None)¶
- Parameters:
codegen (GoStructuredCodeGenerator)
- tags
- codegen: GoStructuredCodeGenerator
- ident: str
- idx: int
- c_repr(initial_pos=0, indent=0, pos_to_node=None, pos_to_addr=None, addr_to_pos=None)¶
Creates the C representation of the code and displays it by constructing a large string. This function is called by each program function that needs to be decompiled. The map_pos_to_node and map_pos_to_addr act as position maps for the location of each variable and statement to be tracked for later GUI operations. The map_pos_to_addr also contains expressions that are nested inside of statements.
- c_repr_chunks(indent=0, asexpr=False)¶
- static indent_str(indent=0)¶
- class angr.analyses.decompiler.structured_codegen.go.GoFunction¶
Bases:
GoConstruct,FunctionNodeRepresents a function in C.
- __init__(addr, name, functy, arg_list, statements, variables_in_use, variable_manager, demangled_name=None, show_demangled_name=True, omit_header=False, **kwargs)¶
- Parameters:
addr (int)
name (str)
functy (SimTypeFunction)
arg_list (list[GoVariable])
- addr
- name
- functy
- arg_list
- statements
- variables_in_use
- variable_manager: VariableManagerInternal
- demangled_name
- unified_local_vars: dict[SimVariable, set[tuple[GoVariable, SimType]]]
- show_demangled_name
- omit_header
- short_declared: set
- refresh()¶
- get_unified_local_vars()¶
- Return type:
dict[SimVariable,set[tuple[GoVariable,SimType]]]
- variable_list_repr_chunks(indent=0)¶
- c_repr_chunks(indent=0, asexpr=False)¶
- headerless_c_repr_chunks(indent=0)¶
- full_c_repr_chunks(indent=0, asexpr=False)¶
- static sort_local_vars(local_vars)¶
- Return type:
- Parameters:
local_vars (Iterable[SimVariable])
- class angr.analyses.decompiler.structured_codegen.go.GoStatement¶
Bases:
GoConstructRepresents a statement in C.
- __init__(tags=None, *, codegen)¶
- Parameters:
codegen (GoStructuredCodeGenerator)
- codegen: GoStructuredCodeGenerator
- ident: str
- idx: int
- tags
- class angr.analyses.decompiler.structured_codegen.go.GoExpression¶
Bases:
GoConstruct,ExpressionNodeBase class for C expressions.
- __init__(collapsed=False, tags=None, *, codegen)¶
- Parameters:
codegen (GoStructuredCodeGenerator)
- collapsed
- set_type(v)¶
- class angr.analyses.decompiler.structured_codegen.go.GoStatements¶
Bases:
GoStatementRepresents a sequence of statements in C.
- __init__(statements, addr=None, **kwargs)¶
- Parameters:
statements (Sequence[GoStatement])
- statements
- addr
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoAILBlock¶
Bases:
GoStatementRepresents a block of AIL statements.
- __init__(block, **kwargs)¶
- Parameters:
block (Block)
- block
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoLoop¶
Bases:
GoStatementRepresents a loop in C.
- class angr.analyses.decompiler.structured_codegen.go.GoWhileLoop¶
Bases:
GoLoopRepresents a while loop in C.
- __init__(condition, body, **kwargs)¶
- Parameters:
condition (GoExpression)
body (GoStatements | None)
- condition
- body
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoDoWhileLoop¶
Bases:
GoLoopRepresents a do-while loop in C.
- __init__(condition, body, **kwargs)¶
- Parameters:
condition (GoExpression)
body (GoStatements | None)
- condition
- body
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoForLoop¶
Bases:
GoStatementRepresents a for-loop in C.
- __init__(initializer, condition, iterator, body, **kwargs)¶
- Parameters:
condition (GoExpression | None)
body (GoStatements | None)
- initializer
- condition
- iterator
- body
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoRangeLoop¶
Bases:
GoStatementfor i, v = range coll { ... };index/valuemay be None (rendered as_).- __init__(index, value, collection, body, **kwargs)¶
- Parameters:
collection (GoExpression)
body (GoStatements | None)
- index
- value
- collection
- body
- declares
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoIfElse¶
Bases:
GoStatementRepresents an if-else construct in C.
- __init__(condition_and_nodes, else_node=None, simplify_else_scope=False, cstyle_ifs=True, **kwargs)¶
- Parameters:
condition_and_nodes (list[tuple[GoExpression, GoStatement | None]])
- condition_and_nodes
- else_node
- simplify_else_scope
- cstyle_ifs
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoIfBreak¶
Bases:
GoStatementRepresents an if-break statement in C.
- __init__(condition, cstyle_ifs=True, **kwargs)¶
- Parameters:
condition (GoExpression)
- condition
- cstyle_ifs
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoBreak¶
Bases:
GoStatementRepresents a break statement in C.
- __init__(**kwargs)¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoContinue¶
Bases:
GoStatementRepresents a continue statement in C.
- __init__(**kwargs)¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoSwitchCase¶
Bases:
GoStatementRepresents a switch-case statement in C.
- __init__(switch, cases, default, **kwargs)¶
- Parameters:
switch (GoExpression)
cases (Sequence[tuple[int | tuple[int, ...], GoStatements]])
default (GoStatements | None)
- switch
- cases
- default
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoIncompleteSwitchCase¶
Bases:
GoStatementRepresents an incomplete switch-case construct; this only appear in the decompilation output when switch-case structuring fails (for whatever reason).
- __init__(head, cases, **kwargs)¶
- head
- cases: list[tuple[int, GoStatements]]
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoAssignment¶
Bases:
GoStatementa = b
- __init__(lhs, rhs, **kwargs)¶
- Parameters:
rhs (GoExpression)
- lhs
- rhs
- declares
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoMethodCall¶
Bases:
GoExpressionrecv.Method(args)through an interface’s method table.- __init__(receiver, method, args, signature=None, **kwargs)¶
- Parameters:
method (str)
args (Sequence[GoExpression])
- receiver
- method
- args
- signature
- property type¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoMultiAssignment¶
Bases:
GoStatementa, b = f()- __init__(lhs, rhs, **kwargs)¶
- lhs
- rhs
- declares
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoSelectCase¶
Bases:
objectOne
selectcase: a receive (v, ok := <-ch), a send (ch <- x) or the default.- kind
- channel
- value
- ok
- c_repr_chunks()¶
- class angr.analyses.decompiler.structured_codegen.go.GoSelect¶
Bases:
GoStatementselect { case ...: ... }- __init__(cases, **kwargs)¶
- cases
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoTypeSwitch¶
Bases:
GoStatementswitch x := v.(type) { case T: ... default: ... }- value
- bound_name
- cases
- default
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoExpressionStatement¶
Bases:
GoStatementWraps a GoExpression so it can be used as a standalone statement.
expr;
- __init__(expr, returning=True, **kwargs)¶
- Parameters:
expr (GoExpression)
returning (bool | None)
- expr
- returning
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoFunctionCall¶
Bases:
GoExpression,FunctionCallNodefunc(arg0, arg1)
- Variables:
callee_func (Function) – The function getting called.
- __init__(callee_target, callee_func, args, show_demangled_name=True, show_disambiguated_name=True, tags=None, *, codegen, **kwargs)¶
- Parameters:
show_disambiguated_name (bool)
- callee_target
- args
- show_demangled_name
- show_disambiguated_name
- property prototype: SimTypeFunction | None¶
- property prototype_returnty: SimType¶
Returns returnty and avoids creating the SimTypeFunction instance if the function prototype is not available. Instead of self.prototype.returnty, you should use self.prototype_returnty for better performance.
- property type¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoReturn¶
Bases:
GoStatementreturnwith zero, one or several result expressions.- __init__(retval, **kwargs)¶
- Parameters:
retval (GoExpression | None)
- retvals
- property retval¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoGoto¶
Bases:
GoStatement- __init__(target, target_idx, **kwargs)¶
- Parameters:
target (GoExpression | int)
target_idx (int)
- target: int | GoExpression
- target_idx
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoUnsupportedStatement¶
Bases:
GoStatementA wrapper for unsupported AIL statement.
- __init__(stmt, **kwargs)¶
- stmt
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoDirtyStatement¶
Bases:
GoExpression- __init__(dirty, **kwargs)¶
- Parameters:
dirty (GoDirtyExpression)
- dirty
- property type¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoLabel¶
Bases:
GoStatement,LabelNodeRepresents a label in C code.
- name
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoStructField¶
Bases:
GoExpression,StructFieldNode- __init__(struct_type, offset, field, **kwargs)¶
- struct_type
- offset
- field
- property type¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoFakeVariable¶
Bases:
GoExpressionAn uninterpreted name to display in the decompilation output. Pretty much always represents an error?
- name
- property type¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoVariable¶
Bases:
GoExpression,VariableNodeGoVariable represents access to a variable with the specified type (variable_type).
variable must be a SimVariable.
- __init__(variable, unified_variable=None, variable_type=None, vvar_id=None, **kwargs)¶
- Parameters:
variable (SimVariable)
- variable: SimVariable
- unified_variable: SimVariable | None
- vvar_id
- property type¶
- property name¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoIndexedVariable¶
Bases:
GoExpression,IndexedVariableNodeRepresent a variable (an array) that is indexed.
- __init__(variable, index, variable_type=None, **kwargs)¶
- Parameters:
variable (GoExpression)
index (GoExpression)
- index: GoExpression
- property type¶
- c_repr_chunks(indent=0, asexpr=False)¶
- collapsed
- class angr.analyses.decompiler.structured_codegen.go.GoVariableField¶
Bases:
GoExpression,VariableFieldNodeRepresent a field of a variable.
- __init__(variable, field, var_is_ptr=False, **kwargs)¶
- Parameters:
variable (GoExpression)
field (GoStructField)
var_is_ptr (bool)
- property type¶
- c_repr_chunks(indent=0, asexpr=False)¶
- collapsed
- class angr.analyses.decompiler.structured_codegen.go.GoUnaryOp¶
Bases:
GoExpression,UnaryOpNodeUnary operations.
- __init__(op, operand, **kwargs)¶
- Parameters:
operand (GoExpression)
- op
- operand
- property type¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoBinaryOp¶
Bases:
GoExpression,BinaryOpNodeBinary operations.
- __init__(op, lhs, rhs, **kwargs)¶
- op
- lhs
- rhs
- common_type
- static compute_common_type(op, lhs_ty, rhs_ty)¶
- property type¶
- property op_precedence¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoTypeCast¶
Bases:
GoExpression- __init__(src_type, dst_type, expr, **kwargs)¶
- Parameters:
src_type (SimType | None)
dst_type (SimType)
expr (GoExpression)
- src_type
- dst_type
- expr
- property type¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoConstant¶
Bases:
GoExpression,ConstantNode- property raw_reference_values: dict | None¶
The reference values, without loading the functions a parsed constant refers to.
- property fmt¶
- property fmt_hex¶
- property fmt_neg¶
- property type¶
- static str_to_c_str(_str, prefix='', maxlen=None)¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoRegister¶
Bases:
GoExpression- __init__(reg, **kwargs)¶
- reg
- property type¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoITE¶
Bases:
GoExpression- __init__(cond, iftrue, iffalse, **kwargs)¶
- cond
- iftrue
- iffalse
- property type¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoMultiStatementExpression¶
Bases:
GoExpression(stmt0, stmt1, stmt2, expr)
- __init__(stmts, expr, **kwargs)¶
- Parameters:
stmts (GoStatements)
expr (GoExpression)
- stmts
- expr
- property type¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoVEXCCallExpression¶
Bases:
GoExpressionccall_name(arg0, arg1, …)
- __init__(callee, operands, **kwargs)¶
- Parameters:
callee (str)
operands (list[GoExpression])
- callee
- operands
- property type¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoDirtyExpression¶
Bases:
GoExpressionIdeally all dirty expressions should be handled and converted to proper conversions during conversion from VEX to AIL. Eventually this class should not be used at all.
- __init__(dirty, **kwargs)¶
- dirty
- property type¶
- intrinsic_name()¶
Return the dirty callee if it is a clean C identifier, else None.
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoStringLiteral¶
Bases:
GoExpressionA Go string constant (pointer, length) known at decompilation time.
- data
- property type¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoStructLiteral¶
Bases:
GoExpressionA struct-shaped value assembled from its fields: a composite literal
T{a: x, b: y}, ornil/""when every field is zero.- name
- fields
- field_names
- property type¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoBoxedValue¶
Bases:
GoExpressionA value converted to an interface:
xwhen its static type already is the boxed type,T(x)otherwise.- __init__(expr, iface_name, concrete, tags=None, **kwargs)¶
- expr
- iface_name
- concrete
- property type¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoTypeAssertion¶
Bases:
GoExpressionx.(T), or the interface conversionT(x)whenconversionis set.- __init__(expr, type_name, tags=None, conversion=False, **kwargs)¶
- expr
- type_name
- conversion
- property type¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoSliceLiteral¶
Bases:
GoExpression[]T{a, b, c}- elem_type
- elems
- property type¶
- elem_chunks()¶
- c_repr_chunks(indent=0, asexpr=False)¶
- class angr.analyses.decompiler.structured_codegen.go.GoClosingObject¶
Bases:
ClosingObjectNodeA class to represent all objects that can be closed by it’s correspodning character. Examples: (), {}, []
- __init__(opening_symbol)¶
- opening_symbol
- class angr.analyses.decompiler.structured_codegen.go.GoArrayTypeLength¶
Bases:
objectA class to represent the type information of fixed-size array lengths. Examples: In “char foo[20]”, this would be the “[20]”.
- __init__(text)¶
- text
- class angr.analyses.decompiler.structured_codegen.go.GoStructFieldNameDef¶
Bases:
objectA class to represent the name of a defined field in a struct. Needed because it’s not a GoVariable or a GoStructField (because GoStructField is the access of a GoStructField). Example: In “struct foo { int bar; }, this would be “bar”.
- __init__(name)¶
- name
- class angr.analyses.decompiler.structured_codegen.go.GoStructuredCodeGenerator¶
Bases:
BaseStructuredCodeGenerator,Analysis,Serializable- __init__(func, sequence, indent=0, cfg=None, func_args=None, binop_depth_cutoff=16, show_casts=True, braces_on_own_lines=False, use_compound_assignments=True, show_local_types=True, comment_gotos=False, cstyle_null_cmp=True, flavor=None, stmt_comments=None, expr_comments=None, show_externs=True, externs=None, const_formats=None, show_demangled_name=True, show_disambiguated_name=True, ail_graph=None, simplify_else_scope=True, cstyle_ifs=True, omit_func_header=False, display_block_addrs=False, display_vvar_ids=False, min_data_addr=4194304, notes=None, display_notes=True, max_str_len=None, prettify_thiscall=False, cstyle_void_param=True, indent_size=4, variable_map=None, stl_accessor_calls=False)¶
- ailexpr2cnode: dict[tuple[Expression | Statement, bool], GoExpression] | None
- cnode2ailexpr: dict[GoExpression, Expression | Statement] | None
- cfunc: GoFunction | None
- cexterns: set[GoVariable] | None
- reapply_options(options)¶
- cleanup()¶
Remove existing rendering results.
- regenerate_text()¶
Re-render text and re-generate all sorts of mapping information.
- Return type:
- render_text(cfunc)¶
- Return type:
- Parameters:
cfunc (GoFunction)
- render_notes()¶
Render decompilation notes.
- Return type:
- Returns:
A string containing all notes.
- variables_unify(v1, v2)¶
- Return type:
- Parameters:
v1 (VirtualVariable)
v2 (VirtualVariable)
- class angr.analyses.decompiler.structured_codegen.go.GoStructuredCodeWalker¶
Bases:
object- handle(obj)¶
- handle_default(obj)¶
- handle_GoFunction(obj)¶
- handle_GoStatements(obj)¶
- handle_GoWhileLoop(obj)¶
- handle_GoDoWhileLoop(obj)¶
- handle_GoRangeLoop(obj)¶
- handle_GoMethodCall(obj)¶
- handle_GoMultiAssignment(obj)¶
- handle_GoStructLiteral(obj)¶
- handle_GoBoxedValue(obj)¶
- handle_GoTypeSwitch(obj)¶
- handle_GoSelect(obj)¶
- handle_GoTypeAssertion(obj)¶
- handle_GoSliceLiteral(obj)¶
- handle_GoForLoop(obj)¶
- handle_GoIfElse(obj)¶
- handle_GoIfBreak(obj)¶
- handle_GoSwitchCase(obj)¶
- handle_GoAssignment(obj)¶
- handle_GoExpressionStatement(obj)¶
- handle_GoFunctionCall(obj)¶
- handle_GoReturn(obj)¶
- handle_GoGoto(obj)¶
- handle_GoIndexedVariable(obj)¶
- handle_GoVariableField(obj)¶
- handle_GoUnaryOp(obj)¶
- handle_GoBinaryOp(obj)¶
- handle_GoTypeCast(obj)¶
- handle_GoITE(obj)¶
- class angr.analyses.decompiler.structured_codegen.go.RangeLoopRecovery¶
Bases:
GoStructuredCodeWalkerTurn a counting loop over a slice or string into
for i, x = range s: the index starts at zero (in the loop initializer or just before the loop), the condition isi < len(s)(the length possibly hoisted into a variable or the initializer) and the index advances by one per iteration. The range value is bound fromx = s.ptr[i]at the top of the body, or from a pointer that starts ats.ptrand advances by one element at the end of the body.- __init__(codegen)¶
- handle_GoFunction(obj)¶
- handle_GoStatements(obj)¶
- class angr.analyses.decompiler.structured_codegen.go.TupleDestructuring¶
Bases:
GoStructuredCodeWalkerv = f()followed byv.~r0/v.~r1accesses of a multi-result value becomesa, err = f()with one variable per result, when the value is only ever read through its fields.- __init__(codegen, cfunc)¶
- Parameters:
cfunc (GoFunction)
- collect(node, chain=())¶
chainis the ancestry as (node, attribute, index-or-key) triples, innermost last.- Parameters:
chain (tuple)
- run()¶
- handle_GoAssignment(obj)¶
- handle_GoVariableField(obj)¶
- handle_GoVariable(obj)¶
- handle_GoUnaryOp(obj)¶
- handle_GoBinaryOp(obj)¶
- class angr.analyses.decompiler.structured_codegen.go.PrintFolding¶
Bases:
GoStructuredCodeWalkerFold the
printlock; print<T>(a); printsp; ...; printnl; printunlocksequence the compiler emits for theprint/printlnbuiltins back into one call.- __init__(codegen)¶
- handle_GoStatements(obj)¶
- class angr.analyses.decompiler.structured_codegen.go.InterfaceMethodCalls¶
Bases:
GoStructuredCodeWalkerx.tab.fun[i](x.data, args...)becomesx.Method(args...)using the interface’s method set.- __init__(codegen)¶
- handle_GoFunction(obj)¶
- handle_GoFunctionCall(obj)¶
- class angr.analyses.decompiler.structured_codegen.go.TypeAssertionRecovery¶
Bases:
GoStructuredCodeWalkerif v.tab == &type:Tguarding reads ofv.databecomesx, ok := v.(T)followed byif ok; the same check guarding only aruntime.panicdottype*call is the panicking formv.(T).- PANIC_NAMES = frozenset({'runtime.panicdottypeE', 'runtime.panicdottypeI', 'runtime.panicnildottype'})¶
- __init__(codegen, cfunc)¶
- Parameters:
cfunc (GoFunction)
- run()¶
- handle_GoStatements(obj)¶
- class angr.analyses.decompiler.structured_codegen.go.InterfaceAssertionRecovery¶
Bases:
TypeAssertionRecoveryAssertions and conversions to interface types, which go through
runtime.typeAssert. Runs late: the holder needs its interface type and the spill copies around the call must be gone.- changed = False¶
- handle_GoStatements(obj)¶
- class angr.analyses.decompiler.structured_codegen.go.ITEHoisting¶
Bases:
objectx = c ? a : brenders as an immediately invoked closure in Go. Inside a statement list the value is hoisted into a temporary assigned by anif/elseplaced before the statement; ITEs in loop headers stay as they are.- __init__(codegen, cfunc)¶
- Parameters:
cfunc (GoFunction)
- run()¶
- class angr.analyses.decompiler.structured_codegen.go.NamedFieldRetyping¶
Bases:
objectField accesses built on register copies carry the copy’s inferred struct; once copy cleanup has folded them onto an expression whose type is a named Go struct, name the fields after that struct. Variables defined by such a read take its type, so the fix propagates through chains of copies and indexing.
- MAX_ROUNDS = 4¶
- __init__(codegen, cfunc)¶
- Parameters:
cfunc (GoFunction)
- run()¶
- class angr.analyses.decompiler.structured_codegen.go.StringSwitchRecovery¶
Bases:
GoStructuredCodeWalkerAn if/else-if chain whose conditions all compare one string with literals is a
switchon it.- __init__(codegen)¶
- handle_GoIfElse(obj)¶
- handle_GoBinaryOp(obj)¶
- class angr.analyses.decompiler.structured_codegen.go.TypeSwitchRecovery¶
Bases:
GoStructuredCodeWalkerAn if/else-if chain comparing one interface value’s type word against type descriptors becomes
switch x := v.(type); a trailingruntime.interfaceSwitchdispatch adds the interface cases.- __init__(codegen, cfunc)¶
- Parameters:
cfunc (GoFunction)
- run()¶
- handle_GoStatements(obj)¶
- handle_GoSwitchCase(obj)¶
- class angr.analyses.decompiler.structured_codegen.go.MapRangeRecovery¶
Bases:
GoStructuredCodeWalkerruntime.mapiterinit(T, m, &it)followed by a loop onit.key != nilthat ends withruntime.mapiternext(&it)becomesfor k, v = range m; reads through the iterator’s key and element pointers becomekandv.- __init__(codegen, cfunc)¶
- Parameters:
cfunc (GoFunction)
- run()¶
- handle_GoStatements(obj)¶
- class angr.analyses.decompiler.structured_codegen.go.ChannelRangeRecovery¶
Bases:
GoStructuredCodeWalkerfor { S; v, ok = <-ch; if !ok { break }; R }becomesS; for v = range ch { R; S }: the statements ahead of the receive also run on the final, failed receive, so they move before the loop and to the end of the body.- __init__(codegen, cfunc)¶
- Parameters:
cfunc (GoFunction)
- run()¶
- handle_GoStatements(obj)¶
- class angr.analyses.decompiler.structured_codegen.go.SingleTripLoops¶
Bases:
GoStructuredCodeWalkerfor i = 0; i <= 0; i = 1 { body }runs its body exactly once (a range over a one-element array, e.g. an inlinedappendof one value): emit the body (and the iterator) without the loop. The flag variable must be written only by the initializer and unconditional constant stores, and read only by the condition.- __init__(codegen, cfunc)¶
- Parameters:
cfunc (GoFunction)
- run()¶
- handle_GoStatements(obj)¶
- class angr.analyses.decompiler.structured_codegen.go.UnreachableAfterReturn¶
Bases:
GoStructuredCodeWalkerStatements after a
returnin the same block that no goto can reach are dropped.- handle_GoStatements(obj)¶
- class angr.analyses.decompiler.structured_codegen.go.CopyCleanup¶
Bases:
objectRemove the register shuffling that phi elimination and spilling leave in structured code:
a value spilled before a loop and reloaded inside it (
x = y…y = x) never changes, so the spill and the reloads go andxreads asy;x = ywhose every read follows in the same block, withyunchanged in between, is folded into the reads;single-assignment locals nobody reads are dropped.
A loop whose iterator statement went away takes the body’s final update of a condition variable as its iterator.
- MAX_ROUNDS = 8¶
- __init__(codegen, cfunc)¶
- Parameters:
cfunc (GoFunction)
- run()¶
- class angr.analyses.decompiler.structured_codegen.go.ShortDeclarations¶
Bases:
objectTurn the first assignment of a local into
x := ewhen it sits in the innermost block enclosing every use ofx(Go’s scoping for short declarations), and drop thevarline. Loop initializers and range loops declare their variables the same way.- __init__(codegen, cfunc)¶
- Parameters:
cfunc (GoFunction)
- run()¶
- class angr.analyses.decompiler.structured_codegen.go.StringLiteralLengths¶
Bases:
objectGo string data is not NUL-terminated, so a constant data pointer renders the rest of the string pool. Clip it to the length it travels with: the next word of a struct literal, the next call argument or result, or the length word stored next to it (
x.len = n; x.ptr = por two adjacent stack slots).- __init__(codegen, cfunc)¶
- Parameters:
cfunc (GoFunction)
- run()¶
- class angr.analyses.decompiler.structured_codegen.go.SelectRecovery¶
Bases:
GoStructuredCodeWalkerruntime.selectgo(&cases, &order, pc, nsends, nrecvs, block)with its case records built on the stack and the dispatch on the chosen index becomesselect { case v := <-ch: ... case ch <- x: ... default: ... }.- __init__(codegen, cfunc)¶
- Parameters:
cfunc (GoFunction)
- run()¶
- handle_GoStatements(obj)¶
- class angr.analyses.decompiler.structured_codegen.go.MakeTypecastsImplicit¶
Bases:
GoStructuredCodeWalker- classmethod collapse(dst_ty, child)¶
- Return type:
- Parameters:
dst_ty (SimType)
child (GoExpression)
- handle_GoAssignment(obj)¶
- handle_GoFunctionCall(obj)¶
- Parameters:
obj (GoFunctionCall)
- handle_GoBinaryOp(obj)¶
- Parameters:
obj (GoBinaryOp)
- handle_GoTypeCast(obj)¶
- Parameters:
obj (GoTypeCast)
- class angr.analyses.decompiler.structured_codegen.go.FieldReferenceCleanup¶
Bases:
GoStructuredCodeWalker- handle_GoTypeCast(obj)¶
- class angr.analyses.decompiler.structured_codegen.go.PointerArithmeticFixer¶
Bases:
GoStructuredCodeWalkerBefore calling this fixer class, pointer arithmetics are purely integer-based and ignoring the pointer type.
For example, in the following case:
struct A* a_ptr; // assume struct A is 24 bytes in size a_ptr = a_ptr + 24;
It means adding 24 to the address of a_ptr, without considering the size of struct A. This fixer class will make pointer arithmetics aware of the pointer type. In this case, the fixer class will convert the code to a_ptr = a_ptr + 1.
- handle_GoAssignment(obj)¶
- Parameters:
obj (GoAssignment)
- handle_GoBinaryOp(obj)¶
- Parameters:
obj (GoBinaryOp)