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:

tuple[int, list[tuple[int, GoExpression]]]

Parameters:

expr (GoExpression)

angr.analyses.decompiler.structured_codegen.go.is_machine_word_size_type(type_, arch)
Return type:

bool

Parameters:
angr.analyses.decompiler.structured_codegen.go.guess_value_type(value, project)
Return type:

SimType | None

Parameters:
  • value (int)

  • project (angr.Project)

angr.analyses.decompiler.structured_codegen.go.type_equals(t0, t1)
Return type:

bool

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

Return type:

str

Parameters:

_seen (frozenset)

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:

tuple

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.

Return type:

str

Parameters:
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 as type Name struct {...}.

Parameters:
class angr.analyses.decompiler.structured_codegen.go.GoConstruct

Bases: object

Represents 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, FunctionNode

Represents 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
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
extra_decls: list[tuple[str, SimType]]
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:

list[SimVariable]

Parameters:

local_vars (Iterable[SimVariable])

class angr.analyses.decompiler.structured_codegen.go.GoStatement

Bases: GoConstruct

Represents 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, ExpressionNode

Base class for C expressions.

__init__(collapsed=False, tags=None, *, codegen)
Parameters:

codegen (GoStructuredCodeGenerator)

collapsed
property type: SimType | None
set_type(v)
class angr.analyses.decompiler.structured_codegen.go.GoStatements

Bases: GoStatement

Represents 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: GoStatement

Represents 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: GoStatement

Represents a loop in C.

class angr.analyses.decompiler.structured_codegen.go.GoWhileLoop

Bases: GoLoop

Represents a while loop in C.

__init__(condition, body, **kwargs)
Parameters:
condition
body
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoDoWhileLoop

Bases: GoLoop

Represents a do-while loop in C.

__init__(condition, body, **kwargs)
Parameters:
condition
body
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoForLoop

Bases: GoStatement

Represents a for-loop in C.

__init__(initializer, condition, iterator, body, **kwargs)
Parameters:
initializer
condition
iterator
body
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoRangeLoop

Bases: GoStatement

for i, v = range coll { ... }; index/value may be None (rendered as _).

__init__(index, value, collection, body, **kwargs)
Parameters:
index
value
collection
body
declares
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoIfElse

Bases: GoStatement

Represents 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: GoStatement

Represents 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: GoStatement

Represents a break statement in C.

__init__(**kwargs)
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoContinue

Bases: GoStatement

Represents a continue statement in C.

__init__(**kwargs)
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoSwitchCase

Bases: GoStatement

Represents a switch-case statement in C.

__init__(switch, cases, default, **kwargs)
Parameters:
switch
cases
default
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoIncompleteSwitchCase

Bases: GoStatement

Represents 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: GoStatement

a = 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: GoExpression

recv.Method(args) through an interface’s method table.

__init__(receiver, method, args, signature=None, **kwargs)
Parameters:
receiver
method
args
signature
property type
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoMultiAssignment

Bases: GoStatement

a, 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: object

One select case: a receive (v, ok := <-ch), a send (ch <- x) or the default.

__init__(kind, channel=None, value=None, ok=None)
Parameters:

kind (str)

kind
channel
value
ok
c_repr_chunks()
class angr.analyses.decompiler.structured_codegen.go.GoSelect

Bases: GoStatement

select { case ...: ... }

__init__(cases, **kwargs)
cases
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoTypeSwitch

Bases: GoStatement

switch x := v.(type) { case T: ... default: ... }

__init__(value, bound_name, cases, default, **kwargs)
Parameters:

bound_name (str | None)

value
bound_name
cases
default
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoExpressionStatement

Bases: GoStatement

Wraps a GoExpression so it can be used as a standalone statement.

expr;

__init__(expr, returning=True, **kwargs)
Parameters:
expr
returning
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoFunctionCall

Bases: GoExpression, FunctionCallNode

func(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
site_returnty: SimType | None
property callee_func: Function | None
property callee_func_addr: int | None

The callee’s address, without loading the callee.

property prettify_thiscall: bool
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: GoStatement

return with 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: int | GoExpression
target_idx
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoUnsupportedStatement

Bases: GoStatement

A 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, LabelNode

Represents a label in C code.

__init__(name, **kwargs)
Parameters:

name (str)

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)
Parameters:
struct_type
offset
field
property type
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoFakeVariable

Bases: GoExpression

An uninterpreted name to display in the decompilation output. Pretty much always represents an error?

__init__(name, ty, **kwargs)
Parameters:
name
property type
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoVariable

Bases: GoExpression, VariableNode

GoVariable 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
variable_type: SimType | None
vvar_id
property type
property name
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoIndexedVariable

Bases: GoExpression, IndexedVariableNode

Represent a variable (an array) that is indexed.

__init__(variable, index, variable_type=None, **kwargs)
Parameters:
index: GoExpression
property type
c_repr_chunks(indent=0, asexpr=False)
collapsed
class angr.analyses.decompiler.structured_codegen.go.GoVariableField

Bases: GoExpression, VariableFieldNode

Represent a field of a variable.

__init__(variable, field, var_is_ptr=False, **kwargs)
Parameters:
property type
c_repr_chunks(indent=0, asexpr=False)
collapsed
class angr.analyses.decompiler.structured_codegen.go.GoUnaryOp

Bases: GoExpression, UnaryOpNode

Unary 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, BinaryOpNode

Binary operations.

__init__(op, lhs, rhs, **kwargs)
op
lhs
rhs
signed: bool | None
common_type
static compute_common_type(op, lhs_ty, rhs_ty)
Return type:

SimType

Parameters:
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
dst_type
expr
property type
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoConstant

Bases: GoExpression, ConstantNode

__init__(value, type_, reference_values=None, **kwargs)
Parameters:

type_ (SimType)

value: int | float | str
string_data: str | None
property reference_values: dict | None
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 fmt_char
Setter accepts:

bool

property fmt_float
Setter accepts:

bool

property fmt_double
Setter accepts:

bool

property type
static str_to_c_str(_str, prefix='', maxlen=None)
Return type:

str

Parameters:
  • prefix (str)

  • maxlen (int | None)

c_repr_chunks(indent=0, asexpr=False)
fmt_int(value)

Format an integer using the format setup of the current node.

Parameters:

value (int) – The integer value to format.

Return type:

str

Returns:

The formatted string.

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
expr
property type
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoVEXCCallExpression

Bases: GoExpression

ccall_name(arg0, arg1, …)

__init__(callee, operands, **kwargs)
Parameters:
callee
operands
property type
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoDirtyExpression

Bases: GoExpression

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

Return type:

str | None

c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoStringLiteral

Bases: GoExpression

A Go string constant (pointer, length) known at decompilation time.

__init__(data, tags=None, **kwargs)
Parameters:

data (str)

data
property type
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoStructLiteral

Bases: GoExpression

A struct-shaped value assembled from its fields: a composite literal T{a: x, b: y}, or nil/"" when every field is zero.

__init__(name, fields, field_names, tags=None, **kwargs)
Parameters:

name (str)

name
fields
field_names
property type
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoBoxedValue

Bases: GoExpression

A value converted to an interface: x when its static type already is the boxed type, T(x) otherwise.

__init__(expr, iface_name, concrete, tags=None, **kwargs)
Parameters:
  • iface_name (str)

  • concrete (str | None)

expr
iface_name
concrete
property type
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoTypeAssertion

Bases: GoExpression

x.(T), or the interface conversion T(x) when conversion is set.

__init__(expr, type_name, tags=None, conversion=False, **kwargs)
Parameters:
  • type_name (str)

  • conversion (bool)

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}

__init__(elem_type, elems, tags=None, **kwargs)
Parameters:

elem_type (str)

elem_type
elems
property type
elem_chunks()
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.go.GoClosingObject

Bases: ClosingObjectNode

A 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: object

A 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: object

A 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)
Parameters:
ailexpr2cnode: dict[tuple[Expression | Statement, bool], GoExpression] | None
cnode2ailexpr: dict[GoExpression, Expression | Statement] | None
map_addr_to_label: dict[tuple[int, int | None], GoLabel]
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:

None

render_text(cfunc)
Return type:

RenderResult

Parameters:

cfunc (GoFunction)

render_notes()

Render decompilation notes.

Return type:

str

Returns:

A string containing all notes.

reload_variable_types()
Return type:

None

default_simtype_from_bits(n, signed=True)
Return type:

SimType

Parameters:
variables_unify(v1, v2)
Return type:

bool

Parameters:
property map_ast_to_pos: dict[Any, set[PositionMappingElement]] | None
resolve_callee(addr)

The function at addr for a parsed call, the same object for every call to it.

Return type:

Function | None

Parameters:

addr (int)

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: GoStructuredCodeWalker

Turn 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 is i < 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 from x = s.ptr[i] at the top of the body, or from a pointer that starts at s.ptr and 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: GoStructuredCodeWalker

v = f() followed by v.~r0 / v.~r1 accesses of a multi-result value becomes a, 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=())

chain is 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: GoStructuredCodeWalker

Fold the printlock; print<T>(a); printsp; ...; printnl; printunlock sequence the compiler emits for the print/println builtins back into one call.

__init__(codegen)
handle_GoStatements(obj)
class angr.analyses.decompiler.structured_codegen.go.InterfaceMethodCalls

Bases: GoStructuredCodeWalker

x.tab.fun[i](x.data, args...) becomes x.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: GoStructuredCodeWalker

if v.tab == &type:T guarding reads of v.data becomes x, ok := v.(T) followed by if ok; the same check guarding only a runtime.panicdottype* call is the panicking form v.(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: TypeAssertionRecovery

Assertions 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: object

x = c ? a : b renders as an immediately invoked closure in Go. Inside a statement list the value is hoisted into a temporary assigned by an if/else placed 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: object

Field 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: GoStructuredCodeWalker

An if/else-if chain whose conditions all compare one string with literals is a switch on it.

__init__(codegen)
handle_GoIfElse(obj)
handle_GoBinaryOp(obj)
class angr.analyses.decompiler.structured_codegen.go.TypeSwitchRecovery

Bases: GoStructuredCodeWalker

An if/else-if chain comparing one interface value’s type word against type descriptors becomes switch x := v.(type); a trailing runtime.interfaceSwitch dispatch 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: GoStructuredCodeWalker

runtime.mapiterinit(T, m, &it) followed by a loop on it.key != nil that ends with runtime.mapiternext(&it) becomes for k, v = range m; reads through the iterator’s key and element pointers become k and v.

__init__(codegen, cfunc)
Parameters:

cfunc (GoFunction)

run()
handle_GoStatements(obj)
class angr.analyses.decompiler.structured_codegen.go.ChannelRangeRecovery

Bases: GoStructuredCodeWalker

for { S; v, ok = <-ch; if !ok { break }; R } becomes S; 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: GoStructuredCodeWalker

for i = 0; i <= 0; i = 1 { body } runs its body exactly once (a range over a one-element array, e.g. an inlined append of 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: GoStructuredCodeWalker

Statements after a return in the same block that no goto can reach are dropped.

handle_GoStatements(obj)
class angr.analyses.decompiler.structured_codegen.go.CopyCleanup

Bases: object

Remove 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 and x reads as y;

  • x = y whose every read follows in the same block, with y unchanged 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: object

Turn the first assignment of a local into x := e when it sits in the innermost block enclosing every use of x (Go’s scoping for short declarations), and drop the var line. 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: object

Go 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 = p or two adjacent stack slots).

__init__(codegen, cfunc)
Parameters:

cfunc (GoFunction)

run()
class angr.analyses.decompiler.structured_codegen.go.SelectRecovery

Bases: GoStructuredCodeWalker

runtime.selectgo(&cases, &order, pc, nsends, nrecvs, block) with its case records built on the stack and the dispatch on the chosen index becomes select { 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:

GoExpression

Parameters:
handle_GoAssignment(obj)
handle_GoFunctionCall(obj)
Parameters:

obj (GoFunctionCall)

handle_GoReturn(obj)
Parameters:

obj (GoReturn)

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: GoStructuredCodeWalker

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