angr.go.optimization_passes.builtin_rewriter¶
- class angr.go.optimization_passes.builtin_rewriter.GoBuiltinRewriter¶
Bases:
OptimizationPass,CFGTransformationMixinTurn calls into the Go runtime back into the builtins and operators the compiler lowered them from:
new,make,append,copy,panic, string concatenation/comparison and the string/slice conversions.growsliceis special: the compiler only calls it when the slice must grow, so the call sits under anif newLen > capdiamond whose join block stores the appended elements (go1.25+ nests a stack-buffer choice under the check). The diamond is folded into one unconditionalappend(s, elems...)(append grows on demand itself) and the element stores are dropped; amemmove/typedslicecopyof the new elements isappend(s, t...). The slice may be a tracked value, a field of a struct in memory, a header the compiler keeps in three scalars, or an array (arr[:n]). When the elements cannot be matched the call still becomesappend(s)with a comment giving the element count.- ARCHES = None¶
- PLATFORMS = None¶
- STAGE: OptimizationPassStage = 7¶
- NAME = 'Rewrite Go runtime calls into builtins'¶
- values: _Values
- __init__(func, manager, **kwargs)¶
- type_name(expr)¶
- Return type:
- Parameters:
expr (Expression)
- type_size(expr)¶
- Return type:
- Parameters:
expr (Expression)
- builtin(call, name, args, bits=None, arg_types=None, **extra)¶
- length_facts()¶
- Return type:
- cond_targets(block)¶
The (true, false) target blocks of the conditional jump ending
block.
- string_length(facts, ptr, n, prefix=False)¶
The length word that goes with the string bytes at
ptrwhen the guards pin it ton(or, withprefix, bound it below byn), and whether it is pinned. The tracked string’s own length when there is one; else the value of the nearest such guard.- Return type:
tuple[Expression,bool] |None- Parameters:
facts (list)
ptr (Expression)
n (int)
prefix (bool)
- string_value(ptr, length)¶
The string with the given pointer and length words: the tracked value, else spelled field by field.
- Return type:
- Parameters:
ptr (Expression)
length (Expression)
- to_bits(expr, bits)¶
- Return type:
- Parameters:
expr (Expression)
bits (int | None)
- compare(op, lhs, rhs, bits, tags)¶
- Return type:
- Parameters:
op (str)
lhs (Expression)
rhs (Expression)
bits (int | None)
- rewrite_call(call, block=None, stmt=None)¶
- Return type:
- Parameters:
- rewrite_call_stmt(stmt)¶
- Return type:
- Parameters:
stmt (SideEffectStatement)