angr 9.2.130__py3-none-manylinux2014_aarch64.whl → 9.2.131__py3-none-manylinux2014_aarch64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of angr might be problematic. Click here for more details.
- angr/__init__.py +1 -1
- angr/analyses/decompiler/clinic.py +283 -4
- angr/analyses/decompiler/optimization_passes/__init__.py +0 -3
- angr/analyses/decompiler/peephole_optimizations/__init__.py +5 -1
- angr/analyses/decompiler/peephole_optimizations/a_mul_const_sub_a.py +34 -0
- angr/analyses/decompiler/peephole_optimizations/a_shl_const_sub_a.py +3 -1
- angr/analyses/decompiler/peephole_optimizations/bswap.py +10 -6
- angr/analyses/decompiler/peephole_optimizations/eager_eval.py +100 -19
- angr/analyses/decompiler/peephole_optimizations/remove_noop_conversions.py +15 -0
- angr/analyses/decompiler/peephole_optimizations/remove_redundant_conversions.py +42 -3
- angr/analyses/decompiler/peephole_optimizations/remove_redundant_shifts.py +4 -2
- angr/analyses/decompiler/peephole_optimizations/rol_ror.py +37 -10
- angr/analyses/decompiler/peephole_optimizations/shl_to_mul.py +25 -0
- angr/analyses/decompiler/peephole_optimizations/utils.py +18 -0
- angr/analyses/decompiler/presets/fast.py +0 -2
- angr/analyses/decompiler/presets/full.py +0 -2
- angr/analyses/decompiler/ssailification/rewriting_engine.py +2 -2
- angr/analyses/decompiler/structured_codegen/c.py +74 -13
- angr/analyses/decompiler/structuring/phoenix.py +14 -5
- angr/analyses/s_propagator.py +20 -2
- angr/analyses/typehoon/simple_solver.py +9 -2
- angr/analyses/typehoon/typehoon.py +4 -1
- angr/analyses/variable_recovery/engine_ail.py +15 -15
- angr/analyses/variable_recovery/engine_base.py +3 -0
- angr/engines/light/engine.py +3 -3
- angr/engines/vex/claripy/irop.py +13 -2
- angr/utils/bits.py +5 -0
- angr/utils/formatting.py +4 -1
- {angr-9.2.130.dist-info → angr-9.2.131.dist-info}/METADATA +6 -6
- {angr-9.2.130.dist-info → angr-9.2.131.dist-info}/RECORD +34 -32
- angr/analyses/decompiler/optimization_passes/multi_simplifier.py +0 -223
- {angr-9.2.130.dist-info → angr-9.2.131.dist-info}/LICENSE +0 -0
- {angr-9.2.130.dist-info → angr-9.2.131.dist-info}/WHEEL +0 -0
- {angr-9.2.130.dist-info → angr-9.2.131.dist-info}/entry_points.txt +0 -0
- {angr-9.2.130.dist-info → angr-9.2.131.dist-info}/top_level.txt +0 -0
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
import logging
|
|
3
|
-
|
|
4
|
-
from ailment import Expr
|
|
5
|
-
from unique_log_filter import UniqueLogFilter
|
|
6
|
-
|
|
7
|
-
from .engine_base import SimplifierAILEngine, SimplifierAILState
|
|
8
|
-
from .optimization_pass import OptimizationPass, OptimizationPassStage
|
|
9
|
-
|
|
10
|
-
_l = logging.getLogger(name=__name__)
|
|
11
|
-
_l.addFilter(UniqueLogFilter())
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class MultiSimplifierAILEngine(SimplifierAILEngine):
|
|
15
|
-
"""
|
|
16
|
-
An AIL pass for the multi simplifier
|
|
17
|
-
"""
|
|
18
|
-
|
|
19
|
-
def _ail_handle_Add(self, expr):
|
|
20
|
-
operand_0 = self._expr(expr.operands[0])
|
|
21
|
-
operand_1 = self._expr(expr.operands[1])
|
|
22
|
-
|
|
23
|
-
# x + x = 2*x
|
|
24
|
-
if (
|
|
25
|
-
type(operand_0) in [Expr.Convert, Expr.VirtualVariable]
|
|
26
|
-
and isinstance(operand_1, (Expr.Convert, Expr.VirtualVariable))
|
|
27
|
-
and operand_0 == operand_1
|
|
28
|
-
):
|
|
29
|
-
count = Expr.Const(expr.idx, None, 2, operand_1.bits)
|
|
30
|
-
return Expr.BinaryOp(expr.idx, "Mul", [operand_1, count], expr.signed, **expr.tags)
|
|
31
|
-
# 2*x + x = 3*x
|
|
32
|
-
if Expr.BinaryOp in [type(operand_0), type(operand_1)]:
|
|
33
|
-
if (
|
|
34
|
-
isinstance(operand_1, Expr.BinaryOp)
|
|
35
|
-
and operand_1.op == "Mul"
|
|
36
|
-
and (
|
|
37
|
-
not isinstance(operand_0, Expr.BinaryOp)
|
|
38
|
-
or (isinstance(operand_0, Expr.BinaryOp) and operand_0.op != "Mul")
|
|
39
|
-
)
|
|
40
|
-
):
|
|
41
|
-
x0 = operand_0
|
|
42
|
-
x1_index = 0 if isinstance(operand_1.operands[1], Expr.Const) else 1
|
|
43
|
-
x1 = operand_1.operands[x1_index]
|
|
44
|
-
const_x1 = operand_1.operands[1 - x1_index]
|
|
45
|
-
if x0 == x1:
|
|
46
|
-
new_const = Expr.Const(const_x1.idx, None, const_x1.value + 1, const_x1.bits)
|
|
47
|
-
return Expr.BinaryOp(expr.idx, "Mul", [x0, new_const], expr.signed, **expr.tags)
|
|
48
|
-
elif (
|
|
49
|
-
isinstance(operand_0, Expr.BinaryOp)
|
|
50
|
-
and operand_0.op == "Mul"
|
|
51
|
-
and (
|
|
52
|
-
not isinstance(operand_1, Expr.BinaryOp)
|
|
53
|
-
or (isinstance(operand_1, Expr.BinaryOp) and operand_1.op != "Mul")
|
|
54
|
-
)
|
|
55
|
-
):
|
|
56
|
-
x1 = operand_1
|
|
57
|
-
x0_index = 0 if isinstance(operand_0.operands[1], Expr.Const) else 1
|
|
58
|
-
x0 = operand_0.operands[x0_index]
|
|
59
|
-
const_x0 = operand_0.operands[1 - x0_index]
|
|
60
|
-
if x0 == x1:
|
|
61
|
-
new_const = Expr.Const(const_x0.idx, None, const_x0.value + 1, const_x0.bits)
|
|
62
|
-
return Expr.BinaryOp(expr.idx, "Mul", [x1, new_const], expr.signed, **expr.tags)
|
|
63
|
-
# 2*x + 3*x = 5*x
|
|
64
|
-
elif (
|
|
65
|
-
isinstance(operand_0, Expr.BinaryOp)
|
|
66
|
-
and isinstance(operand_1, Expr.BinaryOp)
|
|
67
|
-
and operand_0.op == "Mul"
|
|
68
|
-
and operand_1.op == "Mul"
|
|
69
|
-
):
|
|
70
|
-
if Expr.Const in [type(operand_0.operands[0]), type(operand_0.operands[1])] and Expr.Const in [
|
|
71
|
-
type(operand_1.operands[0]),
|
|
72
|
-
type(operand_1.operands[1]),
|
|
73
|
-
]:
|
|
74
|
-
x0_index = 0 if isinstance(operand_0.operands[1], Expr.Const) else 1
|
|
75
|
-
x0 = operand_0.operands[x0_index]
|
|
76
|
-
const_x0 = operand_0.operands[1 - x0_index]
|
|
77
|
-
|
|
78
|
-
x1_index = 0 if isinstance(operand_1.operands[1], Expr.Const) else 1
|
|
79
|
-
x1 = operand_1.operands[x1_index]
|
|
80
|
-
const_x1 = operand_1.operands[1 - x1_index]
|
|
81
|
-
if x0 == x1:
|
|
82
|
-
new_const = Expr.Const(const_x1.idx, None, const_x1.value + const_x0.value, const_x1.bits)
|
|
83
|
-
return Expr.BinaryOp(expr.idx, "Mul", [x0, new_const], expr.signed, **expr.tags)
|
|
84
|
-
|
|
85
|
-
if (operand_0, operand_1) != (expr.operands[0], expr.operands[1]):
|
|
86
|
-
return Expr.BinaryOp(expr.idx, "Add", [operand_0, operand_1], expr.signed, **expr.tags)
|
|
87
|
-
return expr
|
|
88
|
-
|
|
89
|
-
def _ail_handle_Sub(self, expr):
|
|
90
|
-
operand_0 = self._expr(expr.operands[0])
|
|
91
|
-
operand_1 = self._expr(expr.operands[1])
|
|
92
|
-
|
|
93
|
-
# x + x = 2*x
|
|
94
|
-
if (
|
|
95
|
-
type(operand_0) in [Expr.Convert, Expr.VirtualVariable]
|
|
96
|
-
and isinstance(operand_1, (Expr.Convert, Expr.VirtualVariable))
|
|
97
|
-
and operand_0 == operand_1
|
|
98
|
-
):
|
|
99
|
-
count = Expr.Const(expr.idx, None, 0, 8)
|
|
100
|
-
return Expr.BinaryOp(expr.idx, "Mul", [operand_1, count], expr.signed, **expr.tags)
|
|
101
|
-
|
|
102
|
-
# 2*x - x = x
|
|
103
|
-
if Expr.BinaryOp in [type(operand_0), type(operand_1)]:
|
|
104
|
-
if (
|
|
105
|
-
isinstance(operand_1, Expr.BinaryOp)
|
|
106
|
-
and operand_1.op == "Mul"
|
|
107
|
-
and (
|
|
108
|
-
not isinstance(operand_0, Expr.BinaryOp)
|
|
109
|
-
or (isinstance(operand_0, Expr.BinaryOp) and operand_0.op != "Mul")
|
|
110
|
-
)
|
|
111
|
-
):
|
|
112
|
-
x0 = operand_0
|
|
113
|
-
x1_index = 0 if isinstance(operand_1.operands[1], Expr.Const) else 1
|
|
114
|
-
x1 = operand_1.operands[x1_index]
|
|
115
|
-
const_x1 = operand_1.operands[1 - x1_index]
|
|
116
|
-
if x0 == x1:
|
|
117
|
-
new_const = Expr.Const(const_x1.idx, None, const_x1.value - 1, const_x1.bits)
|
|
118
|
-
return Expr.BinaryOp(expr.idx, "Mul", [x0, new_const], expr.signed, **expr.tags)
|
|
119
|
-
elif (
|
|
120
|
-
isinstance(operand_0, Expr.BinaryOp)
|
|
121
|
-
and operand_0.op == "Mul"
|
|
122
|
-
and (
|
|
123
|
-
not isinstance(operand_1, Expr.BinaryOp)
|
|
124
|
-
or (isinstance(operand_1, Expr.BinaryOp) and operand_1.op != "Mul")
|
|
125
|
-
)
|
|
126
|
-
):
|
|
127
|
-
x1 = operand_1
|
|
128
|
-
x0_index = 0 if isinstance(operand_0.operands[1], Expr.Const) else 1
|
|
129
|
-
x0 = operand_0.operands[x0_index]
|
|
130
|
-
const_x0 = operand_0.operands[1 - x0_index]
|
|
131
|
-
if x0 == x1:
|
|
132
|
-
new_const = Expr.Const(const_x0.idx, None, const_x0.value - 1, const_x0.bits)
|
|
133
|
-
return Expr.BinaryOp(expr.idx, "Mul", [x1, new_const], expr.signed, **expr.tags)
|
|
134
|
-
# 3*x - 2*x = x
|
|
135
|
-
elif (
|
|
136
|
-
isinstance(operand_0, Expr.BinaryOp)
|
|
137
|
-
and isinstance(operand_1, Expr.BinaryOp)
|
|
138
|
-
and operand_0.op == "Mul"
|
|
139
|
-
and operand_1.op == "Mul"
|
|
140
|
-
):
|
|
141
|
-
if Expr.Const in [type(operand_0.operands[0]), type(operand_0.operands[1])] and Expr.Const in [
|
|
142
|
-
type(operand_1.operands[0]),
|
|
143
|
-
type(operand_1.operands[1]),
|
|
144
|
-
]:
|
|
145
|
-
x0_index = 0 if isinstance(operand_0.operands[1], Expr.Const) else 1
|
|
146
|
-
x0 = operand_0.operands[x0_index]
|
|
147
|
-
const_x0 = operand_0.operands[1 - x0_index]
|
|
148
|
-
|
|
149
|
-
x1_index = 0 if isinstance(operand_1.operands[1], Expr.Const) else 1
|
|
150
|
-
x1 = operand_1.operands[x1_index]
|
|
151
|
-
const_x1 = operand_1.operands[1 - x1_index]
|
|
152
|
-
if x0 == x1:
|
|
153
|
-
new_const = Expr.Const(const_x1.idx, None, const_x0.value - const_x1.value, const_x1.bits)
|
|
154
|
-
return Expr.BinaryOp(expr.idx, "Mul", [x0, new_const], expr.signed, **expr.tags)
|
|
155
|
-
|
|
156
|
-
if (operand_0, operand_1) != (expr.operands[0], expr.operands[1]):
|
|
157
|
-
return Expr.BinaryOp(expr.idx, "Sub", [operand_0, operand_1], expr.signed, **expr.tags)
|
|
158
|
-
return expr
|
|
159
|
-
|
|
160
|
-
def _ail_handle_Shl(self, expr):
|
|
161
|
-
operand_0 = self._expr(expr.operands[0])
|
|
162
|
-
operand_1 = self._expr(expr.operands[1])
|
|
163
|
-
|
|
164
|
-
if isinstance(operand_1, Expr.Const):
|
|
165
|
-
new_operand = Expr.Const(operand_1.idx, None, 2**operand_1.value, operand_0.bits)
|
|
166
|
-
return Expr.BinaryOp(expr.idx, "Mul", [operand_0, new_operand], expr.signed, **expr.tags)
|
|
167
|
-
|
|
168
|
-
if (operand_0, operand_1) != (expr.operands[0], expr.operands[1]):
|
|
169
|
-
return Expr.BinaryOp(expr.idx, "Shl", [operand_0, operand_1], expr.signed, **expr.tags)
|
|
170
|
-
return expr
|
|
171
|
-
|
|
172
|
-
def _ail_handle_Mul(self, expr):
|
|
173
|
-
operand_0 = self._expr(expr.operands[0])
|
|
174
|
-
operand_1 = self._expr(expr.operands[1])
|
|
175
|
-
|
|
176
|
-
if Expr.Const in [type(operand_0), type(operand_1)] and Expr.BinaryOp in [type(operand_0), type(operand_1)]:
|
|
177
|
-
const_, x0 = (operand_0, operand_1) if isinstance(operand_0, Expr.Const) else (operand_1, operand_0)
|
|
178
|
-
if x0.op == "Mul" and Expr.Const in [type(x0.operands[0]), type(x0.operands[1])]:
|
|
179
|
-
if isinstance(x0.operands[0], Expr.Const):
|
|
180
|
-
const_x0, x = x0.operands[0], x0.operands[1]
|
|
181
|
-
else:
|
|
182
|
-
const_x0, x = x0.operands[1], x0.operands[0]
|
|
183
|
-
new_const = Expr.Const(const_.idx, None, const_.value * const_x0.value, const_.bits)
|
|
184
|
-
return Expr.BinaryOp(expr.idx, "Mul", [x, new_const], expr.signed, **expr.tags)
|
|
185
|
-
|
|
186
|
-
if (operand_0, operand_1) != (expr.operands[0], expr.operands[1]):
|
|
187
|
-
return Expr.BinaryOp(expr.idx, "Mul", [operand_0, operand_1], expr.signed, **expr.tags)
|
|
188
|
-
return expr
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
class MultiSimplifier(OptimizationPass):
|
|
192
|
-
"""
|
|
193
|
-
Implements several different arithmetic optimizations.
|
|
194
|
-
"""
|
|
195
|
-
|
|
196
|
-
ARCHES = ["X86", "AMD64"]
|
|
197
|
-
PLATFORMS = ["linux", "windows"]
|
|
198
|
-
STAGE = OptimizationPassStage.AFTER_GLOBAL_SIMPLIFICATION
|
|
199
|
-
NAME = "Simplify various arithmetic expressions"
|
|
200
|
-
DESCRIPTION = __doc__.strip()
|
|
201
|
-
|
|
202
|
-
def __init__(self, func, **kwargs):
|
|
203
|
-
super().__init__(func, **kwargs)
|
|
204
|
-
|
|
205
|
-
self.state = SimplifierAILState(self.project.arch)
|
|
206
|
-
self.engine = MultiSimplifierAILEngine()
|
|
207
|
-
|
|
208
|
-
self.analyze()
|
|
209
|
-
|
|
210
|
-
def _check(self):
|
|
211
|
-
return True, None
|
|
212
|
-
|
|
213
|
-
def _analyze(self, cache=None):
|
|
214
|
-
for block in list(self._graph.nodes()):
|
|
215
|
-
new_block = block
|
|
216
|
-
old_block = None
|
|
217
|
-
|
|
218
|
-
while new_block != old_block:
|
|
219
|
-
old_block = new_block
|
|
220
|
-
new_block = self.engine.process(state=self.state.copy(), block=old_block.copy())
|
|
221
|
-
_l.debug("new block: %s", new_block.statements)
|
|
222
|
-
|
|
223
|
-
self._update_block(block, new_block)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|