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.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):Small negative values (
-255 <= value < 0) are always shown in decimal.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).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).The value is a common error code (e.g.
0xc0000005) in a 32- or 64-bit context.
Otherwise the value is shown in decimal (returns
False).- Parameters:
- Return type:
- Returns:
Trueif the value should be displayed in hexadecimal,Falsefor decimal.