angr.utils.constants¶
- angr.utils.constants.MAGIC_CONSTANTS = frozenset({195948557, 2343432205, 2880289470, 3131961357, 3135097598, 3405691582, 3405697037, 3735927486, 3735928559, 3735929054, 3735936685, 4207869677, 4276215469, 4277009102})¶
Well-known “magic” constants that are universally recognized in hexadecimal.
- angr.utils.constants.NUMERIC_BOUNDARY_VALUES = frozenset({2147483647, 4294967295, 9223372036854775807, 18446744073709551615})¶
Values sitting on a standard integer-type boundary (
INT_MAX/UINT_MAXfor 32- and 64-bit). These read better as signed decimal (e.g.-1,2147483647) than as a long run of set bits, regardless of the width inferred for the surrounding expression.
- angr.utils.constants.is_alignment_mask(n)¶
- angr.utils.constants.should_use_hex(value, bits=None)¶
Heuristically decide whether an integer constant reads better in hexadecimal than in decimal in decompiled output.
The rules are checked in priority order:
Hexadecimal (returns
True):The value is a well-known “magic” constant (e.g.
0xdeadbeef); seeMAGIC_CONSTANTS.The value is a known alignment mask; see
is_alignment_mask().The binary representation contains a run of >= 8 consecutive
1bits – typical of sub-word bitmasks (e.g.0xff,0xfff). Type-saturating values (e.g.-1/0xffffffff,INT_MAX/0x7fffffff) are intentionally excluded: those read better as signed decimal, which the codegen renders separately.The binary representation is a short bit pattern (period 2, 3, 4, or 8) repeated to fill a byte-aligned width – typical of mask/flag constants (e.g.
0x55/0xaaaafor0101...,0x1111,0xabab).The value is a single set bit (power of two) that is >= 256 – a bit flag (e.g.
0x100,0x4000).
Decimal (returns
False):The decimal representation of
abs(value)contains a run of > 3 (i.e. >= 4) identical digits (e.g.10000,11111,1000000).The value is a nonzero multiple of 1000 – a “round” human-authored decimal number (e.g.
5000,20000).The magnitude is small (
abs(value) <= 9) – e.g. small loop counters and offsets.
Hexadecimal (weak signal, returns
True):The low byte is zero and the value is
> 0xff– a “round” hex number (e.g.0x1200).
Otherwise the value is shown in decimal (returns
False).- Parameters:
value (
int) – The integer value to format.bits (
int|None) – The bit-width of the value’s type. Used to normalize negative values to their unsigned form and to detect type-saturating values (rule 3). IfNone, the value’s own bit length is used and only the absolute boundary values inNUMERIC_BOUNDARY_VALUESare treated as saturating.
- Return type:
- Returns:
Trueif the value should be displayed in hexadecimal,Falsefor decimal.