angr.analyses.decompiler.structured_codegen.rust

angr.analyses.decompiler.structured_codegen.rust.unpack_typeref(ty)
angr.analyses.decompiler.structured_codegen.rust.unpack_pointer(ty)
Return type:

SimType | None

angr.analyses.decompiler.structured_codegen.rust.unpack_array(ty)
Return type:

SimType | None

angr.analyses.decompiler.structured_codegen.rust.squash_array_reference(ty)
angr.analyses.decompiler.structured_codegen.rust.qualifies_for_simple_cast(ty1, ty2)
angr.analyses.decompiler.structured_codegen.rust.qualifies_for_implicit_cast(ty1, ty2)
angr.analyses.decompiler.structured_codegen.rust.extract_terms(expr)
Return type:

tuple[int, list[tuple[int, RustExpression]]]

Parameters:

expr (RustExpression)

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

bool

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

SimType | None

Parameters:
angr.analyses.decompiler.structured_codegen.rust.type_to_rust_repr_chunks(ty, name=None, name_type=None, full=False, indent_str='')

Helper generator function to turn a SimType into generated tuples of (C-string, AST node).

Parameters:

ty (SimType | RustSimType)

class angr.analyses.decompiler.structured_codegen.rust.RustConstruct

Bases: object

Represents a program construct in C. Acts as the base class for all other representation constructions.

__init__(codegen)
codegen: RustStructuredCodeGenerator
c_repr(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.rust.RustFunction

Bases: RustConstruct

Represents a function in Rust.

__init__(addr, name, functy, arg_list, statements, variables_in_use, variable_manager, demangled_name=None, show_demangled_name=True, **kwargs)
Parameters:
addr
name
functy
arg_list
statements
variables_in_use
variable_manager: VariableManagerInternal
demangled_name
unified_local_vars: dict[SimVariable, set[tuple[RustVariable, SimType]]]
show_demangled_name
get_unified_local_vars()
Return type:

dict[SimVariable, set[tuple[RustVariable, SimType]]]

variable_list_repr_chunks(indent=0)
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustStatement

Bases: RustConstruct

Represents a statement in C.

class angr.analyses.decompiler.structured_codegen.rust.RustExpression

Bases: RustConstruct

Base class for C expressions.

__init__(collapsed=False, **kwargs)
collapsed
property type
set_type(v)
class angr.analyses.decompiler.structured_codegen.rust.RustStatements

Bases: RustStatement

Represents a sequence of statements in C.

__init__(statements, **kwargs)
statements
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustAILBlock

Bases: RustStatement

Represents a block of AIL statements.

__init__(block, **kwargs)
block
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustLoop

Bases: RustStatement

Represents a loop in Rust.

class angr.analyses.decompiler.structured_codegen.rust.RustInfiniteLoop

Bases: RustLoop

Represents an infinite loop in Rust.

__init__(body, tags=None, **kwargs)
body
tags
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustWhileLoop

Bases: RustLoop

Represents a while loop in C.

__init__(condition, body, tags=None, **kwargs)
condition
body
tags
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustDoWhileLoop

Bases: RustLoop

Represents a do-while loop in C.

__init__(condition, body, tags=None, **kwargs)
condition
body
tags
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustForLoop

Bases: RustStatement

Represents a for-loop in C.

__init__(initializer, condition, iterator, body, tags=None, **kwargs)
initializer
condition
iterator
body
tags
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustIfElse

Bases: RustStatement

Represents an if-else construct in Rust.

__init__(condition_and_nodes, else_node=None, simplify_else_scope=False, cstyle_ifs=True, tags=None, **kwargs)
Parameters:

condition_and_nodes (list[tuple[RustExpression, RustStatement | None]])

condition_and_nodes
else_node
simplify_else_scope
cstyle_ifs
tags
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustIfBreak

Bases: RustStatement

Represents an if-break statement in C.

__init__(condition, cstyle_ifs=True, tags=None, **kwargs)
condition
cstyle_ifs
tags
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustBreak

Bases: RustStatement

Represents a break statement in C.

__init__(tags=None, **kwargs)
tags
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustContinue

Bases: RustStatement

Represents a continue statement in C.

__init__(tags=None, **kwargs)
tags
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustSwitchCase

Bases: RustStatement

Represents a switch-case statement in C.

__init__(switch, cases, default, tags=None, **kwargs)
switch
cases: list[tuple[int | tuple[int], RustStatements]]
default
tags
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustPatternMatch

Bases: RustStatement

Represents a pattern-match statement in Rust.

__init__(match_expr, cases, default, tags=None, **kwargs)
scrutinee
arms: list[tuple[tuple[EnumVariant, tuple[RustExpression, ...]], RustStatements]]
default
tags
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustIfLet

Bases: RustStatement

Represents an if let statement in Rust.

__init__(pattern, scrutinee, true_node, false_node, tags=None, **kwargs)
pattern
scrutinee
true_node
false_node
tags
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustAssignment

Bases: RustStatement

a = b

__init__(lhs, rhs, tags=None, **kwargs)
lhs
rhs
tags
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustFunctionLikeMacro

Bases: RustStatement, RustExpression

__init__(name, args, delimiter, is_expr, returnty=None, tags=None, **kwargs)
c_repr_chunks(indent=0, asexpr=False)
property type
class angr.analyses.decompiler.structured_codegen.rust.RustFunctionCall

Bases: RustStatement, RustExpression

func(arg0, arg1)

Variables:
  • callee_func (Function) – The function getting called.

  • is_expr – True if the return value of the function is written to ret_expr; Essentially, ret_expr = call().

__init__(callee_target, callee_func, args, returning=True, ret_expr=None, receiver=None, tags=None, is_expr=False, show_demangled_name=True, show_disambiguated_name=True, callsite_prototype=None, **kwargs)
Parameters:
callee_target
callee_func: Function | None
args
returning
ret_expr
receiver
tags
is_expr
show_demangled_name
show_disambiguated_name
callsite_prototype
property prototype: SimTypeFunction | None
property type
c_repr_chunks(indent=0, asexpr=False)
Parameters:
  • indent – Number of whitespace indentation characters.

  • asexpr (bool) – True if this call is used as an expression (which means we will skip the generation of semicolons and newlines at the end of the call).

class angr.analyses.decompiler.structured_codegen.rust.RustReturn

Bases: RustStatement

__init__(retval, tags=None, **kwargs)
retval
tags
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustGoto

Bases: RustStatement

__init__(target, target_idx, tags=None, **kwargs)
target: int | RustExpression
target_idx
tags
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustUnsupportedStatement

Bases: RustStatement

A wrapper for unsupported AIL statement.

__init__(stmt, **kwargs)
stmt
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustLabel

Bases: RustStatement

Represents a label in C code.

__init__(name, ins_addr, block_idx, tags=None, **kwargs)
Parameters:
  • name (str)

  • ins_addr (int | None)

  • block_idx (int | None)

name
ins_addr
block_idx
tags
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustStruct

Bases: RustExpression

__init__(name, fields, field_names, tags=None, **kwargs)
name
fields
field_names
tags
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustEnum

Bases: RustExpression

__init__(name, fields, tags=None, **kwargs)
name
fields
tags
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustStructField

Bases: RustExpression

__init__(struct_type, offset, field, tags=None, **kwargs)
Parameters:

struct_type (SimStruct)

struct_type
offset
field
tags
property type
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustArray

Bases: RustExpression

__init__(elements, tags=None, **kwargs)
elements
tags
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustLet

Bases: RustExpression

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

let_expr (Let)

let_expr
property type
c_repr_chunks(indent=0, asexpr=False)
tags
class angr.analyses.decompiler.structured_codegen.rust.RustStringLiteral

Bases: RustExpression

__init__(data, tags=None, **kwargs)
data
property type
c_repr_chunks(indent=0, asexpr=False)
tags
class angr.analyses.decompiler.structured_codegen.rust.RustFakeVariable

Bases: RustExpression

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

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

Bases: RustExpression

CVariable represents access to a variable with the specified type (variable_type).

variable must be a SimVariable.

__init__(variable, unified_variable=None, variable_type=None, tags=None, **kwargs)
Parameters:

variable (SimVariable)

variable: SimVariable
unified_variable: SimVariable | None
variable_type: SimType
tags
property type
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustIndexedVariable

Bases: RustExpression

Represent a variable (an array) that is indexed.

__init__(variable, index, variable_type=None, tags=None, **kwargs)
Parameters:
index: RustExpression
property type
c_repr_chunks(indent=0, asexpr=False)
collapsed
class angr.analyses.decompiler.structured_codegen.rust.RustVariableField

Bases: RustExpression

Represent a field of a variable.

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

Bases: RustExpression

Unary operations.

__init__(op, operand, tags=None, **kwargs)
Parameters:

operand (RustExpression)

op
operand
tags
property type
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustBinaryOp

Bases: RustExpression

Binary operations.

__init__(op, lhs, rhs, tags=None, **kwargs)
op
lhs
rhs
tags
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.rust.RustTypeCast

Bases: RustExpression

__init__(src_type, dst_type, expr, tags=None, **kwargs)
Parameters:
src_type
dst_type
expr
tags
property type
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustConstant

Bases: RustExpression

__init__(value, type_, reference_values=None, tags=None, **kwargs)
Parameters:
value
reference_values
tags
property fmt
property fmt_hex
property fmt_neg
property fmt_char
property type
static str_to_rust_str(_str, is_heap_str=False, prefix='')
Parameters:

prefix (str)

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.rust.RustRegister

Bases: RustExpression

__init__(reg, tags=None, **kwargs)
reg
tags
property type
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustITE

Bases: RustExpression

__init__(cond, iftrue, iffalse, tags=None, **kwargs)
cond
iftrue
iffalse
tags
property type
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustMultiStatementExpression

Bases: RustExpression

(stmt0, stmt1, stmt2, expr)

__init__(stmts, expr, tags=None, **kwargs)
Parameters:
stmts
expr
tags
property type
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustVEXCCallExpression

Bases: RustExpression

ccall_name(arg0, arg1, …)

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

Bases: RustExpression

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
c_repr_chunks(indent=0, asexpr=False)
class angr.analyses.decompiler.structured_codegen.rust.RustClosingObject

Bases: object

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.rust.RustArrayTypeLength

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.rust.RustStructFieldNameDef

Bases: object

A class to represent the name of a defined field in a struct. Needed because it’s not a CVariable or a CStructField (because CStructField is the access of a CStructField). Example: In “struct foo { int bar; }, this would be “bar”.

__init__(name)
name
class angr.analyses.decompiler.structured_codegen.rust.RustStructuredCodeGenerator

Bases: BaseStructuredCodeGenerator, Analysis

__init__(func, sequence, indent=0, cfg=None, variable_kb=None, func_args=None, binop_depth_cutoff=16, show_casts=True, braces_on_own_lines=False, use_compound_assignments=True, show_local_types=False, comment_gotos=False, cstyle_null_cmp=True, flavor=None, stmt_comments=None, expr_comments=None, show_externs=False, 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)
Parameters:
ailexpr2cnode: dict[tuple[Expression, bool], RustExpression] | None
cnode2ailexpr: dict[RustExpression, Expression] | None
expr_comments: dict[int, str]
stmt_comments: dict[int, str]
const_formats: dict[Any, dict[str, Any]]
map_ast_to_pos: dict[SimVariable, set[PositionMappingElement]] | None
map_addr_to_label: dict[tuple[int | None, int | None], RustLabel]
rust_func: RustFunction | None
cexterns: set[RustVariable] | 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_TYPE

alias of tuple[str, PositionMapping, PositionMapping, InstructionMapping, dict[Any, set[Any]]]

render_text(rust_func)
Return type:

RENDER_TYPE

Parameters:

rust_func (RustFunction)

render_notes()

Render decompilation notes.

Return type:

str

Returns:

A string containing all notes.

reload_variable_types()
Return type:

None

default_simtype_from_size(n, signed=True)
Return type:

RustSimTypeInt

Parameters:
class angr.analyses.decompiler.structured_codegen.rust.RustStructuredCodeWalker

Bases: object

classmethod handle(obj)
classmethod handle_default(obj)
classmethod handle_RustFunction(obj)
classmethod handle_RustStatements(obj)
classmethod handle_RustWhileLoop(obj)
classmethod handle_RustInfiniteLoop(obj)
classmethod handle_RustDoWhileLoop(obj)
classmethod handle_RustForLoop(obj)
classmethod handle_RustIfElse(obj)
classmethod handle_RustIfBreak(obj)
classmethod handle_RustSwitchCase(obj)
classmethod handle_RustAssignment(obj)
classmethod handle_RustFunctionCall(obj)
classmethod handle_RustReturn(obj)
classmethod handle_RustGoto(obj)
classmethod handle_RustIndexedVariable(obj)
classmethod handle_RustVariableField(obj)
classmethod handle_RustUnaryOp(obj)
classmethod handle_RustBinaryOp(obj)
classmethod handle_RustTypeCast(obj)
classmethod handle_RustITE(obj)
class angr.analyses.decompiler.structured_codegen.rust.MakeTypecastsImplicit

Bases: RustStructuredCodeWalker

classmethod collapse(dst_ty, child)
Return type:

RustExpression

Parameters:
classmethod handle_RustAssignment(obj)
classmethod handle_RustFunctionCall(obj)
Parameters:

obj (RustFunctionCall)

classmethod handle_RustReturn(obj)
Parameters:

obj (RustReturn)

classmethod handle_RustBinaryOp(obj)
Parameters:

obj (RustBinaryOp)

classmethod handle_RustTypeCast(obj)
Parameters:

obj (RustTypeCast)

class angr.analyses.decompiler.structured_codegen.rust.FieldReferenceCleanup

Bases: RustStructuredCodeWalker

classmethod handle_RustTypeCast(obj)
class angr.analyses.decompiler.structured_codegen.rust.PointerArithmeticFixer

Bases: RustStructuredCodeWalker

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.

classmethod handle_RustBinaryOp(obj)
Parameters:

obj (RustBinaryOp)