angr 9.2.131__py3-none-win_amd64.whl → 9.2.133__py3-none-win_amd64.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 +128 -128
- angr/analyses/__init__.py +38 -38
- angr/analyses/analysis.py +6 -2
- angr/analyses/backward_slice.py +3 -4
- angr/analyses/binary_optimizer.py +5 -12
- angr/analyses/bindiff.py +3 -6
- angr/analyses/calling_convention.py +3 -4
- angr/analyses/cfg/__init__.py +3 -3
- angr/analyses/cfg/cfg_base.py +1 -1
- angr/analyses/cfg/cfg_emulated.py +5 -5
- angr/analyses/cfg/cfg_fast.py +19 -17
- angr/analyses/cfg/indirect_jump_resolvers/__init__.py +5 -5
- angr/analyses/cfg/indirect_jump_resolvers/amd64_elf_got.py +1 -1
- angr/analyses/cfg/indirect_jump_resolvers/jumptable.py +148 -101
- angr/analyses/cfg/indirect_jump_resolvers/x86_elf_pic_plt.py +1 -1
- angr/analyses/data_dep/__init__.py +4 -4
- angr/analyses/datagraph_meta.py +1 -1
- angr/analyses/ddg.py +16 -17
- angr/analyses/decompiler/__init__.py +12 -12
- angr/analyses/decompiler/ail_simplifier.py +24 -12
- angr/analyses/decompiler/block_similarity.py +2 -4
- angr/analyses/decompiler/block_simplifier.py +10 -21
- angr/analyses/decompiler/callsite_maker.py +1 -1
- angr/analyses/decompiler/ccall_rewriters/rewriter_base.py +1 -1
- angr/analyses/decompiler/clinic.py +122 -41
- angr/analyses/decompiler/condition_processor.py +57 -39
- angr/analyses/decompiler/counters/__init__.py +3 -3
- angr/analyses/decompiler/decompilation_cache.py +7 -7
- angr/analyses/decompiler/dephication/__init__.py +1 -1
- angr/analyses/decompiler/dephication/graph_rewriting.py +1 -1
- angr/analyses/decompiler/dephication/graph_vvar_mapping.py +11 -3
- angr/analyses/decompiler/dephication/rewriting_engine.py +169 -45
- angr/analyses/decompiler/dephication/seqnode_dephication.py +5 -4
- angr/analyses/decompiler/expression_narrower.py +1 -1
- angr/analyses/decompiler/graph_region.py +8 -8
- angr/analyses/decompiler/optimization_passes/__init__.py +20 -20
- angr/analyses/decompiler/optimization_passes/const_derefs.py +1 -0
- angr/analyses/decompiler/optimization_passes/deadblock_remover.py +1 -2
- angr/analyses/decompiler/optimization_passes/div_simplifier.py +41 -16
- angr/analyses/decompiler/optimization_passes/duplication_reverter/duplication_reverter.py +8 -7
- angr/analyses/decompiler/optimization_passes/duplication_reverter/utils.py +1 -3
- angr/analyses/decompiler/optimization_passes/engine_base.py +262 -84
- angr/analyses/decompiler/optimization_passes/inlined_string_transformation_simplifier.py +175 -39
- angr/analyses/decompiler/optimization_passes/ite_region_converter.py +2 -5
- angr/analyses/decompiler/optimization_passes/lowered_switch_simplifier.py +5 -5
- angr/analyses/decompiler/optimization_passes/mod_simplifier.py +12 -3
- angr/analyses/decompiler/optimization_passes/optimization_pass.py +42 -19
- angr/analyses/decompiler/optimization_passes/stack_canary_simplifier.py +9 -5
- angr/analyses/decompiler/peephole_optimizations/__init__.py +1 -1
- angr/analyses/decompiler/peephole_optimizations/base.py +6 -6
- angr/analyses/decompiler/peephole_optimizations/remove_noop_conversions.py +2 -0
- angr/analyses/decompiler/peephole_optimizations/rewrite_bit_extractions.py +1 -1
- angr/analyses/decompiler/presets/__init__.py +1 -1
- angr/analyses/decompiler/region_simplifiers/expr_folding.py +3 -3
- angr/analyses/decompiler/region_simplifiers/switch_cluster_simplifier.py +8 -12
- angr/analyses/decompiler/ssailification/rewriting.py +1 -2
- angr/analyses/decompiler/ssailification/rewriting_engine.py +139 -56
- angr/analyses/decompiler/ssailification/ssailification.py +2 -1
- angr/analyses/decompiler/ssailification/traversal.py +4 -6
- angr/analyses/decompiler/ssailification/traversal_engine.py +125 -42
- angr/analyses/decompiler/structured_codegen/__init__.py +5 -5
- angr/analyses/decompiler/structured_codegen/base.py +3 -3
- angr/analyses/decompiler/structured_codegen/c.py +39 -40
- angr/analyses/decompiler/structuring/__init__.py +3 -3
- angr/analyses/decompiler/structuring/phoenix.py +45 -29
- angr/analyses/decompiler/structuring/structurer_base.py +2 -2
- angr/analyses/decompiler/structuring/structurer_nodes.py +23 -14
- angr/analyses/deobfuscator/__init__.py +3 -3
- angr/analyses/deobfuscator/irsb_reg_collector.py +29 -60
- angr/analyses/deobfuscator/string_obf_finder.py +2 -2
- angr/analyses/deobfuscator/string_obf_opt_passes.py +1 -1
- angr/analyses/disassembly.py +4 -4
- angr/analyses/forward_analysis/__init__.py +1 -1
- angr/analyses/forward_analysis/visitors/graph.py +6 -6
- angr/analyses/init_finder.py +47 -22
- angr/analyses/loop_analysis.py +1 -1
- angr/analyses/loopfinder.py +1 -1
- angr/analyses/propagator/engine_base.py +21 -14
- angr/analyses/propagator/engine_vex.py +149 -179
- angr/analyses/propagator/outdated_definition_walker.py +12 -6
- angr/analyses/propagator/propagator.py +10 -28
- angr/analyses/propagator/top_checker_mixin.py +211 -5
- angr/analyses/propagator/vex_vars.py +4 -4
- angr/analyses/reaching_definitions/__init__.py +9 -9
- angr/analyses/reaching_definitions/call_trace.py +2 -2
- angr/analyses/reaching_definitions/dep_graph.py +1 -1
- angr/analyses/reaching_definitions/engine_ail.py +304 -329
- angr/analyses/reaching_definitions/engine_vex.py +243 -229
- angr/analyses/reaching_definitions/function_handler.py +3 -3
- angr/analyses/reaching_definitions/function_handler_library/__init__.py +1 -1
- angr/analyses/reaching_definitions/rd_state.py +47 -42
- angr/analyses/reassembler.py +26 -31
- angr/analyses/s_liveness.py +8 -0
- angr/analyses/s_propagator.py +18 -3
- angr/analyses/s_reaching_definitions/s_rda_view.py +2 -5
- angr/analyses/s_reaching_definitions/s_reaching_definitions.py +9 -5
- angr/analyses/stack_pointer_tracker.py +4 -4
- angr/analyses/typehoon/simple_solver.py +14 -14
- angr/analyses/typehoon/translator.py +10 -2
- angr/analyses/typehoon/typeconsts.py +11 -3
- angr/analyses/typehoon/typevars.py +26 -26
- angr/analyses/unpacker/__init__.py +1 -1
- angr/analyses/variable_recovery/engine_ail.py +299 -259
- angr/analyses/variable_recovery/engine_base.py +138 -121
- angr/analyses/variable_recovery/engine_vex.py +175 -185
- angr/analyses/variable_recovery/irsb_scanner.py +49 -38
- angr/analyses/variable_recovery/variable_recovery.py +28 -5
- angr/analyses/variable_recovery/variable_recovery_base.py +33 -34
- angr/analyses/variable_recovery/variable_recovery_fast.py +4 -8
- angr/analyses/veritesting.py +2 -2
- angr/analyses/vfg.py +5 -5
- angr/analyses/xrefs.py +46 -19
- angr/angrdb/serializers/__init__.py +1 -1
- angr/annocfg.py +20 -15
- angr/blade.py +2 -2
- angr/block.py +20 -25
- angr/calling_conventions.py +12 -14
- angr/code_location.py +6 -10
- angr/codenode.py +3 -3
- angr/engines/__init__.py +12 -14
- angr/engines/engine.py +24 -61
- angr/engines/light/__init__.py +13 -5
- angr/engines/light/data.py +1 -1
- angr/engines/light/engine.py +1003 -1185
- angr/engines/pcode/__init__.py +1 -1
- angr/engines/pcode/behavior.py +1 -1
- angr/engines/pcode/cc.py +2 -0
- angr/engines/pcode/lifter.py +13 -15
- angr/engines/soot/expressions/__init__.py +12 -12
- angr/engines/soot/statements/__init__.py +6 -6
- angr/engines/soot/values/__init__.py +6 -6
- angr/engines/soot/values/arrayref.py +2 -2
- angr/engines/soot/values/constants.py +1 -1
- angr/engines/soot/values/instancefieldref.py +1 -1
- angr/engines/soot/values/paramref.py +1 -1
- angr/engines/soot/values/staticfieldref.py +1 -1
- angr/engines/successors.py +15 -14
- angr/engines/vex/__init__.py +5 -5
- angr/engines/vex/claripy/ccall.py +2 -2
- angr/engines/vex/claripy/datalayer.py +1 -1
- angr/engines/vex/claripy/irop.py +19 -19
- angr/engines/vex/heavy/__init__.py +2 -2
- angr/engines/vex/heavy/actions.py +1 -3
- angr/engines/vex/heavy/heavy.py +4 -6
- angr/engines/vex/lifter.py +2 -4
- angr/engines/vex/light/light.py +0 -2
- angr/engines/vex/light/slicing.py +5 -5
- angr/exploration_techniques/__init__.py +19 -142
- angr/exploration_techniques/base.py +126 -0
- angr/exploration_techniques/bucketizer.py +1 -1
- angr/exploration_techniques/dfs.py +3 -1
- angr/exploration_techniques/director.py +2 -3
- angr/exploration_techniques/driller_core.py +1 -1
- angr/exploration_techniques/explorer.py +4 -2
- angr/exploration_techniques/lengthlimiter.py +2 -1
- angr/exploration_techniques/local_loop_seer.py +2 -1
- angr/exploration_techniques/loop_seer.py +5 -5
- angr/exploration_techniques/manual_mergepoint.py +2 -1
- angr/exploration_techniques/memory_watcher.py +3 -1
- angr/exploration_techniques/oppologist.py +4 -5
- angr/exploration_techniques/slicecutor.py +4 -2
- angr/exploration_techniques/spiller.py +1 -1
- angr/exploration_techniques/stochastic.py +2 -1
- angr/exploration_techniques/stub_stasher.py +2 -1
- angr/exploration_techniques/suggestions.py +3 -1
- angr/exploration_techniques/symbion.py +3 -1
- angr/exploration_techniques/tech_builder.py +2 -1
- angr/exploration_techniques/threading.py +2 -11
- angr/exploration_techniques/timeout.py +4 -2
- angr/exploration_techniques/tracer.py +4 -3
- angr/exploration_techniques/unique.py +3 -2
- angr/exploration_techniques/veritesting.py +1 -1
- angr/factory.py +36 -6
- angr/keyed_region.py +4 -4
- angr/knowledge_base.py +1 -1
- angr/knowledge_plugins/__init__.py +11 -11
- angr/knowledge_plugins/cfg/__init__.py +5 -5
- angr/knowledge_plugins/cfg/cfg_manager.py +2 -2
- angr/knowledge_plugins/cfg/cfg_model.py +8 -8
- angr/knowledge_plugins/cfg/cfg_node.py +19 -19
- angr/knowledge_plugins/cfg/indirect_jump.py +6 -6
- angr/knowledge_plugins/cfg/memory_data.py +5 -7
- angr/knowledge_plugins/functions/function.py +48 -52
- angr/knowledge_plugins/functions/function_parser.py +4 -4
- angr/knowledge_plugins/key_definitions/__init__.py +3 -3
- angr/knowledge_plugins/key_definitions/atoms.py +8 -8
- angr/knowledge_plugins/key_definitions/definition.py +1 -1
- angr/knowledge_plugins/key_definitions/live_definitions.py +30 -27
- angr/knowledge_plugins/labels.py +1 -1
- angr/knowledge_plugins/propagations/__init__.py +1 -1
- angr/knowledge_plugins/propagations/prop_value.py +2 -2
- angr/knowledge_plugins/propagations/propagation_model.py +7 -8
- angr/knowledge_plugins/propagations/states.py +44 -39
- angr/knowledge_plugins/variables/variable_access.py +2 -2
- angr/knowledge_plugins/variables/variable_manager.py +24 -10
- angr/knowledge_plugins/xrefs/xref.py +5 -8
- angr/lib/angr_native.dll +0 -0
- angr/misc/__init__.py +4 -4
- angr/misc/hookset.py +4 -5
- angr/misc/loggers.py +2 -2
- angr/misc/telemetry.py +1 -1
- angr/procedures/__init__.py +1 -1
- angr/procedures/cgc/fdwait.py +2 -2
- angr/procedures/definitions/__init__.py +2 -2
- angr/procedures/definitions/linux_kernel.py +0 -1
- angr/procedures/definitions/parse_syscalls_from_local_system.py +1 -1
- angr/procedures/definitions/parse_win32json.py +0 -1
- angr/procedures/ntdll/exceptions.py +1 -1
- angr/procedures/stubs/format_parser.py +3 -3
- angr/procedures/win32/dynamic_loading.py +1 -1
- angr/protos/__init__.py +3 -3
- angr/sim_manager.py +3 -5
- angr/sim_state.py +40 -42
- angr/sim_state_options.py +3 -3
- angr/sim_type.py +15 -14
- angr/sim_variable.py +42 -45
- angr/simos/__init__.py +4 -4
- angr/simos/cgc.py +1 -1
- angr/simos/simos.py +1 -1
- angr/simos/userland.py +1 -1
- angr/slicer.py +4 -7
- angr/state_plugins/__init__.py +34 -34
- angr/state_plugins/callstack.py +5 -12
- angr/state_plugins/heap/__init__.py +2 -2
- angr/state_plugins/heap/heap_brk.py +2 -4
- angr/state_plugins/heap/heap_ptmalloc.py +1 -1
- angr/state_plugins/jni_references.py +3 -2
- angr/state_plugins/scratch.py +1 -1
- angr/state_plugins/sim_action.py +1 -4
- angr/state_plugins/sim_event.py +1 -1
- angr/state_plugins/solver.py +7 -9
- angr/state_plugins/uc_manager.py +1 -1
- angr/state_plugins/view.py +2 -2
- angr/storage/__init__.py +1 -1
- angr/storage/file.py +10 -10
- angr/storage/memory_mixins/__init__.py +46 -46
- angr/storage/memory_mixins/default_filler_mixin.py +1 -3
- angr/storage/memory_mixins/javavm_memory_mixin.py +2 -2
- angr/storage/memory_mixins/name_resolution_mixin.py +2 -2
- angr/storage/memory_mixins/paged_memory/paged_memory_mixin.py +1 -3
- angr/storage/memory_mixins/paged_memory/pages/__init__.py +6 -6
- angr/storage/memory_mixins/paged_memory/pages/list_page.py +1 -1
- angr/storage/memory_mixins/paged_memory/pages/multi_values.py +1 -1
- angr/storage/memory_mixins/paged_memory/pages/mv_list_page.py +1 -1
- angr/storage/memory_mixins/paged_memory/pages/ultra_page.py +2 -4
- angr/storage/memory_mixins/regioned_memory/__init__.py +3 -3
- angr/storage/memory_mixins/regioned_memory/region_data.py +5 -5
- angr/storage/memory_mixins/regioned_memory/region_meta_mixin.py +7 -9
- angr/storage/memory_mixins/regioned_memory/regioned_memory_mixin.py +4 -4
- angr/storage/memory_object.py +4 -4
- angr/utils/__init__.py +3 -3
- angr/utils/bits.py +12 -0
- angr/utils/dynamic_dictlist.py +1 -1
- angr/utils/graph.py +1 -1
- angr/utils/orderedset.py +4 -1
- angr/utils/segment_list.py +2 -2
- angr/utils/ssa/__init__.py +33 -8
- {angr-9.2.131.dist-info → angr-9.2.133.dist-info}/METADATA +6 -6
- {angr-9.2.131.dist-info → angr-9.2.133.dist-info}/RECORD +263 -264
- angr/analyses/propagator/engine_ail.py +0 -1562
- angr/storage/memory_mixins/__init__.pyi +0 -48
- {angr-9.2.131.dist-info → angr-9.2.133.dist-info}/LICENSE +0 -0
- {angr-9.2.131.dist-info → angr-9.2.133.dist-info}/WHEEL +0 -0
- {angr-9.2.131.dist-info → angr-9.2.133.dist-info}/entry_points.txt +0 -0
- {angr-9.2.131.dist-info → angr-9.2.133.dist-info}/top_level.txt +0 -0
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
from __future__ import annotations
|
|
3
3
|
import logging
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import ailment
|
|
6
6
|
|
|
7
|
-
from angr.engines.light import
|
|
8
|
-
from angr.engines.light import SimEngineLight
|
|
7
|
+
from angr.engines.light import SimEngineLightAIL
|
|
9
8
|
|
|
10
9
|
_l = logging.getLogger(name=__name__)
|
|
11
10
|
|
|
@@ -31,11 +30,11 @@ class SimplifierAILState:
|
|
|
31
30
|
def merge(self, *others):
|
|
32
31
|
raise NotImplementedError
|
|
33
32
|
|
|
34
|
-
def store_variable(self, old:
|
|
33
|
+
def store_variable(self, old: ailment.expression.VirtualVariable, new):
|
|
35
34
|
if new is not None:
|
|
36
35
|
self._variables[old.varid] = new
|
|
37
36
|
|
|
38
|
-
def get_variable(self, old:
|
|
37
|
+
def get_variable(self, old: ailment.expression.VirtualVariable):
|
|
39
38
|
return self._variables.get(old.varid, None)
|
|
40
39
|
|
|
41
40
|
def remove_variable(self, old):
|
|
@@ -43,76 +42,77 @@ class SimplifierAILState:
|
|
|
43
42
|
|
|
44
43
|
|
|
45
44
|
class SimplifierAILEngine(
|
|
46
|
-
|
|
47
|
-
SimEngineLight,
|
|
45
|
+
SimEngineLightAIL[SimplifierAILState, ailment.expression.Expression, ailment.statement.Statement, ailment.Block]
|
|
48
46
|
):
|
|
49
47
|
"""
|
|
50
48
|
Essentially implements a peephole optimization engine for AIL statements (because we do not perform memory or
|
|
51
49
|
register loads).
|
|
52
50
|
"""
|
|
53
51
|
|
|
54
|
-
def
|
|
55
|
-
|
|
52
|
+
def _process_block_end(self, block, stmt_data, whitelist):
|
|
53
|
+
if whitelist is None:
|
|
54
|
+
block.statements = stmt_data
|
|
55
|
+
else:
|
|
56
|
+
for stmt_idx, stmt in zip(sorted(whitelist), stmt_data):
|
|
57
|
+
block.statements[stmt_idx] = stmt
|
|
58
|
+
return block
|
|
56
59
|
|
|
57
|
-
def
|
|
58
|
-
|
|
59
|
-
super().process(state, *args, **kwargs)
|
|
60
|
-
return self.block
|
|
60
|
+
def _top(self, bits):
|
|
61
|
+
assert False, "This code should be unreachable"
|
|
61
62
|
|
|
62
|
-
def
|
|
63
|
-
|
|
64
|
-
whitelist = set(whitelist)
|
|
65
|
-
|
|
66
|
-
for stmt_idx, stmt in enumerate(self.block.statements):
|
|
67
|
-
if whitelist is not None and stmt_idx not in whitelist:
|
|
68
|
-
continue
|
|
69
|
-
|
|
70
|
-
self.ins_addr = stmt.ins_addr
|
|
71
|
-
self.stmt_idx = stmt_idx
|
|
72
|
-
new_stmt = self._ail_handle_Stmt(stmt)
|
|
73
|
-
if new_stmt and new_stmt != stmt:
|
|
74
|
-
self.block.statements[stmt_idx] = new_stmt
|
|
63
|
+
def _is_top(self, expr):
|
|
64
|
+
assert False, "This code should be unreachable"
|
|
75
65
|
|
|
76
66
|
# handle stmt
|
|
77
|
-
def _ail_handle_Stmt(self, stmt):
|
|
78
|
-
handler = f"_ail_handle_{type(stmt).__name__}"
|
|
79
|
-
if hasattr(self, handler):
|
|
80
|
-
return getattr(self, handler)(stmt)
|
|
81
|
-
_l.debug("Unsupported statement type %s.", type(stmt).__name__)
|
|
82
|
-
return stmt
|
|
83
67
|
|
|
84
|
-
def
|
|
68
|
+
def _handle_stmt_Assignment(self, stmt):
|
|
85
69
|
src = self._expr(stmt.src)
|
|
86
70
|
dst = self._expr(stmt.dst)
|
|
87
71
|
|
|
88
|
-
if isinstance(dst,
|
|
72
|
+
if isinstance(dst, ailment.expression.VirtualVariable) and not isinstance(src, ailment.expression.Phi):
|
|
89
73
|
self.state.store_variable(dst, src)
|
|
90
74
|
|
|
91
75
|
if (src, dst) != (stmt.src, stmt.dst):
|
|
92
|
-
return
|
|
76
|
+
return ailment.statement.Assignment(stmt.idx, dst, src, **stmt.tags)
|
|
93
77
|
|
|
94
78
|
return stmt
|
|
95
79
|
|
|
96
|
-
def
|
|
80
|
+
def _handle_stmt_Store(self, stmt):
|
|
97
81
|
addr = self._expr(stmt.addr)
|
|
98
82
|
data = self._expr(stmt.data)
|
|
99
83
|
|
|
100
84
|
# replace
|
|
101
85
|
if (addr, data) != (stmt.addr, stmt.data):
|
|
102
|
-
return
|
|
86
|
+
return ailment.statement.Store(
|
|
87
|
+
stmt.idx, addr, data, stmt.size, stmt.endness, variable=stmt.variable, **stmt.tags
|
|
88
|
+
)
|
|
103
89
|
|
|
104
90
|
return stmt
|
|
105
91
|
|
|
106
|
-
def
|
|
92
|
+
def _handle_stmt_Jump(self, stmt):
|
|
107
93
|
target = self._expr(stmt.target)
|
|
108
94
|
|
|
109
|
-
return
|
|
110
|
-
|
|
111
|
-
def
|
|
95
|
+
return ailment.statement.Jump(stmt.idx, target, **stmt.tags)
|
|
96
|
+
|
|
97
|
+
def _handle_stmt_ConditionalJump(self, stmt): # pylint: disable=no-self-use
|
|
98
|
+
condition = self._expr(stmt.condition)
|
|
99
|
+
iftrue = self._expr(stmt.true_target) if stmt.true_target is not None else None
|
|
100
|
+
iffalse = self._expr(stmt.false_target) if stmt.false_target is not None else None
|
|
101
|
+
|
|
102
|
+
if (condition, iftrue, iffalse) != (stmt.condition, stmt.true_target, stmt.false_target):
|
|
103
|
+
return ailment.statement.ConditionalJump(
|
|
104
|
+
stmt.idx,
|
|
105
|
+
condition,
|
|
106
|
+
iftrue,
|
|
107
|
+
iffalse,
|
|
108
|
+
true_target_idx=stmt.true_target_idx,
|
|
109
|
+
false_target_idx=stmt.false_target_idx,
|
|
110
|
+
**stmt.tags,
|
|
111
|
+
)
|
|
112
112
|
return stmt
|
|
113
113
|
|
|
114
|
-
def
|
|
115
|
-
target = self._expr(stmt.target)
|
|
114
|
+
def _handle_stmt_Call(self, stmt):
|
|
115
|
+
target = self._expr(stmt.target) if isinstance(stmt.target, ailment.Expr.Expression) else stmt.target
|
|
116
116
|
|
|
117
117
|
new_args = None
|
|
118
118
|
|
|
@@ -122,7 +122,7 @@ class SimplifierAILEngine(
|
|
|
122
122
|
new_arg = self._expr(arg)
|
|
123
123
|
new_args.append(new_arg)
|
|
124
124
|
|
|
125
|
-
return
|
|
125
|
+
return ailment.statement.Call(
|
|
126
126
|
stmt.idx,
|
|
127
127
|
target,
|
|
128
128
|
calling_convention=stmt.calling_convention,
|
|
@@ -134,7 +134,7 @@ class SimplifierAILEngine(
|
|
|
134
134
|
**stmt.tags,
|
|
135
135
|
)
|
|
136
136
|
|
|
137
|
-
def
|
|
137
|
+
def _handle_stmt_Return(self, stmt):
|
|
138
138
|
if stmt.ret_exprs:
|
|
139
139
|
new_retexprs = []
|
|
140
140
|
for ret_expr in stmt.ret_exprs:
|
|
@@ -147,67 +147,71 @@ class SimplifierAILEngine(
|
|
|
147
147
|
return new_stmt
|
|
148
148
|
return stmt
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
def _handle_stmt_DirtyStatement(self, stmt):
|
|
151
|
+
expr = self._expr(stmt.dirty)
|
|
152
|
+
if expr != stmt.dirty:
|
|
153
|
+
return ailment.statement.DirtyStatement(stmt.idx, expr, **stmt.tags)
|
|
154
|
+
return stmt
|
|
151
155
|
|
|
152
|
-
def
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if v is None:
|
|
157
|
-
return expr
|
|
158
|
-
return v
|
|
159
|
-
_l.debug("Unsupported expression type %s.", type(expr).__name__)
|
|
160
|
-
return expr
|
|
156
|
+
def _handle_stmt_Label(self, stmt):
|
|
157
|
+
return stmt
|
|
158
|
+
|
|
159
|
+
# handle expr
|
|
161
160
|
|
|
162
|
-
def
|
|
161
|
+
def _handle_expr_StackBaseOffset(self, expr): # pylint:disable=no-self-use
|
|
163
162
|
return expr
|
|
164
163
|
|
|
165
|
-
def
|
|
164
|
+
def _handle_expr_VirtualVariable(self, expr): # pylint:disable=no-self-use
|
|
166
165
|
# We don't want to return new values and construct new AIL expressions in caller methods without def-use
|
|
167
166
|
# information. Otherwise, we may end up creating incorrect expressions.
|
|
168
167
|
# Therefore, we do not perform vvar load, which essentially turns SimplifierAILEngine into a peephole
|
|
169
168
|
# optimization engine.
|
|
170
169
|
return expr
|
|
171
170
|
|
|
172
|
-
def
|
|
171
|
+
def _handle_expr_Phi(self, expr): # pylint:disable=no-self-use
|
|
173
172
|
return expr
|
|
174
173
|
|
|
175
|
-
def
|
|
174
|
+
def _handle_expr_Load(self, expr):
|
|
176
175
|
# We don't want to load new values and construct new AIL expressions in caller methods without def-use
|
|
177
176
|
# information. Otherwise, we may end up creating incorrect expressions.
|
|
178
177
|
# Therefore, we do not perform memory load, which essentially turns SimplifierAILEngine into a peephole
|
|
179
178
|
# optimization engine.
|
|
180
179
|
addr = self._expr(expr.addr)
|
|
181
180
|
if addr != expr.addr:
|
|
182
|
-
return
|
|
181
|
+
return ailment.expression.Load(expr.idx, addr, expr.size, expr.endness, **expr.tags)
|
|
183
182
|
return expr
|
|
184
183
|
|
|
185
|
-
def
|
|
184
|
+
def _handle_expr_Register(self, expr): # pylint:disable=no-self-use
|
|
186
185
|
# We don't want to return new values and construct new AIL expressions in caller methods without def-use
|
|
187
186
|
# information. Otherwise, we may end up creating incorrect expressions.
|
|
188
187
|
# Therefore, we do not perform register load, which essentially turns SimplifierAILEngine into a peephole
|
|
189
188
|
# optimization engine.
|
|
190
189
|
return expr
|
|
191
190
|
|
|
192
|
-
def
|
|
191
|
+
def _handle_binop_Mul(self, expr):
|
|
193
192
|
operand_0 = self._expr(expr.operands[0])
|
|
194
193
|
operand_1 = self._expr(expr.operands[1])
|
|
195
194
|
|
|
196
195
|
if (operand_0, operand_1) != (expr.operands[0], expr.operands[1]):
|
|
197
|
-
return
|
|
196
|
+
return ailment.expression.BinaryOp(expr.idx, "Mul", [operand_0, operand_1], expr.signed, **expr.tags)
|
|
198
197
|
return expr
|
|
199
198
|
|
|
200
|
-
def
|
|
199
|
+
def _handle_binop_Mull(self, expr):
|
|
200
|
+
operand_0 = self._expr(expr.operands[0])
|
|
201
|
+
operand_1 = self._expr(expr.operands[1])
|
|
202
|
+
|
|
203
|
+
if (operand_0, operand_1) != (expr.operands[0], expr.operands[1]):
|
|
204
|
+
return ailment.expression.BinaryOp(expr.idx, "Mull", [operand_0, operand_1], expr.signed, **expr.tags)
|
|
201
205
|
return expr
|
|
202
206
|
|
|
203
|
-
def
|
|
207
|
+
def _handle_expr_Convert(self, expr):
|
|
204
208
|
operand_expr = self._expr(expr.operand)
|
|
205
209
|
|
|
206
|
-
if
|
|
210
|
+
if isinstance(operand_expr, ailment.expression.Convert):
|
|
207
211
|
if expr.from_bits == operand_expr.to_bits and expr.to_bits == operand_expr.from_bits:
|
|
208
212
|
# eliminate the redundant Convert
|
|
209
213
|
return operand_expr.operand
|
|
210
|
-
return
|
|
214
|
+
return ailment.expression.Convert(
|
|
211
215
|
expr.idx,
|
|
212
216
|
operand_expr.from_bits,
|
|
213
217
|
expr.to_bits,
|
|
@@ -219,40 +223,39 @@ class SimplifierAILEngine(
|
|
|
219
223
|
**expr.tags,
|
|
220
224
|
)
|
|
221
225
|
if (
|
|
222
|
-
type(operand_expr) is
|
|
223
|
-
and expr.from_type ==
|
|
224
|
-
and expr.to_type ==
|
|
226
|
+
type(operand_expr) is ailment.expression.Const
|
|
227
|
+
and expr.from_type == ailment.expression.Convert.TYPE_INT
|
|
228
|
+
and expr.to_type == ailment.expression.Convert.TYPE_INT
|
|
225
229
|
):
|
|
226
230
|
# do the conversion right away
|
|
227
231
|
value = operand_expr.value
|
|
228
232
|
mask = (2**expr.to_bits) - 1
|
|
229
233
|
value &= mask
|
|
230
|
-
return
|
|
231
|
-
if type(operand_expr) is
|
|
234
|
+
return ailment.expression.Const(expr.idx, operand_expr.variable, value, expr.to_bits, **expr.tags)
|
|
235
|
+
if type(operand_expr) is ailment.expression.BinaryOp and operand_expr.op in {
|
|
232
236
|
"Mul",
|
|
233
237
|
"Shl",
|
|
234
238
|
"Div",
|
|
235
|
-
"DivMod",
|
|
236
239
|
"Mod",
|
|
237
240
|
"Add",
|
|
238
241
|
"Sub",
|
|
239
242
|
}:
|
|
240
|
-
if isinstance(operand_expr.operands[1],
|
|
243
|
+
if isinstance(operand_expr.operands[1], ailment.expression.Const):
|
|
241
244
|
if (
|
|
242
|
-
isinstance(operand_expr.operands[0],
|
|
245
|
+
isinstance(operand_expr.operands[0], ailment.expression.Register)
|
|
243
246
|
and expr.from_bits == operand_expr.operands[0].bits
|
|
244
247
|
):
|
|
245
|
-
converted =
|
|
248
|
+
converted = ailment.expression.Convert(
|
|
246
249
|
expr.idx, expr.from_bits, expr.to_bits, expr.is_signed, operand_expr.operands[0]
|
|
247
250
|
)
|
|
248
|
-
converted_const =
|
|
251
|
+
converted_const = ailment.expression.Const(
|
|
249
252
|
operand_expr.operands[1].idx,
|
|
250
253
|
operand_expr.operands[1].variable,
|
|
251
254
|
operand_expr.operands[1].value,
|
|
252
255
|
expr.to_bits,
|
|
253
256
|
**operand_expr.operands[1].tags,
|
|
254
257
|
)
|
|
255
|
-
return
|
|
258
|
+
return ailment.expression.BinaryOp(
|
|
256
259
|
operand_expr.idx,
|
|
257
260
|
operand_expr.op,
|
|
258
261
|
[converted, converted_const],
|
|
@@ -263,23 +266,23 @@ class SimplifierAILEngine(
|
|
|
263
266
|
# Conv(32->64, (Conv(64->32, r14<8>) + 0x1<32>)) became Add(r14<8>, 0x1<32>)
|
|
264
267
|
# ideally it should become Conv(32->64, Conv(64->32, r14<8> + 0x1<64>))
|
|
265
268
|
# and then the double convert can be pretty-printed away
|
|
266
|
-
# elif isinstance(operand_expr.operands[0],
|
|
269
|
+
# elif isinstance(operand_expr.operands[0], ailment.expression.Convert) and \
|
|
267
270
|
# expr.from_bits == operand_expr.operands[0].to_bits and \
|
|
268
271
|
# expr.to_bits == operand_expr.operands[0].from_bits:
|
|
269
|
-
# return
|
|
272
|
+
# return ailment.expression.BinaryOp(operand_expr.idx, operand_expr.op,
|
|
270
273
|
# [operand_expr.operands[0].operand, operand_expr.operands[1]],
|
|
271
274
|
# operand_expr.signed,
|
|
272
275
|
# **operand_expr.tags)
|
|
273
276
|
elif (
|
|
274
|
-
isinstance(operand_expr.operands[0],
|
|
275
|
-
and isinstance(operand_expr.operands[1],
|
|
277
|
+
isinstance(operand_expr.operands[0], ailment.expression.Convert)
|
|
278
|
+
and isinstance(operand_expr.operands[1], ailment.expression.Convert)
|
|
276
279
|
and operand_expr.operands[0].from_bits == operand_expr.operands[1].from_bits
|
|
277
280
|
) and (
|
|
278
281
|
operand_expr.operands[0].to_bits == operand_expr.operands[1].to_bits
|
|
279
282
|
and expr.from_bits == operand_expr.operands[0].to_bits
|
|
280
283
|
and expr.to_bits == operand_expr.operands[1].from_bits
|
|
281
284
|
):
|
|
282
|
-
return
|
|
285
|
+
return ailment.expression.BinaryOp(
|
|
283
286
|
operand_expr.idx,
|
|
284
287
|
operand_expr.op,
|
|
285
288
|
[operand_expr.operands[0].operand, operand_expr.operands[1].operand],
|
|
@@ -287,7 +290,7 @@ class SimplifierAILEngine(
|
|
|
287
290
|
**operand_expr.tags,
|
|
288
291
|
)
|
|
289
292
|
|
|
290
|
-
return
|
|
293
|
+
return ailment.expression.Convert(
|
|
291
294
|
expr.idx,
|
|
292
295
|
expr.from_bits,
|
|
293
296
|
expr.to_bits,
|
|
@@ -298,3 +301,178 @@ class SimplifierAILEngine(
|
|
|
298
301
|
rounding_mode=expr.rounding_mode,
|
|
299
302
|
**expr.tags,
|
|
300
303
|
)
|
|
304
|
+
|
|
305
|
+
def _handle_expr_Const(self, expr):
|
|
306
|
+
return expr
|
|
307
|
+
|
|
308
|
+
def _handle_expr_Tmp(self, expr):
|
|
309
|
+
return expr
|
|
310
|
+
|
|
311
|
+
def _handle_expr_Reinterpret(self, expr):
|
|
312
|
+
return expr
|
|
313
|
+
|
|
314
|
+
def _handle_expr_ITE(self, expr):
|
|
315
|
+
return expr
|
|
316
|
+
|
|
317
|
+
def _handle_expr_Call(self, expr):
|
|
318
|
+
return expr
|
|
319
|
+
|
|
320
|
+
def _handle_expr_DirtyExpression(self, expr):
|
|
321
|
+
return expr
|
|
322
|
+
|
|
323
|
+
def _handle_expr_VEXCCallExpression(self, expr):
|
|
324
|
+
return expr
|
|
325
|
+
|
|
326
|
+
def _handle_expr_MultiStatementExpression(self, expr):
|
|
327
|
+
return expr
|
|
328
|
+
|
|
329
|
+
def _handle_expr_BasePointerOffset(self, expr):
|
|
330
|
+
return expr
|
|
331
|
+
|
|
332
|
+
def _handle_unop_Default(self, expr):
|
|
333
|
+
operand = self._expr(expr.operand)
|
|
334
|
+
if operand != expr.operand:
|
|
335
|
+
return ailment.expression.UnaryOp(
|
|
336
|
+
expr.idx, expr.op, operand, variable=expr.variable, variable_offset=expr.variable_offset, **expr.tags
|
|
337
|
+
)
|
|
338
|
+
return expr
|
|
339
|
+
|
|
340
|
+
_handle_unop_Not = _handle_unop_Default
|
|
341
|
+
_handle_unop_Neg = _handle_unop_Default
|
|
342
|
+
_handle_unop_BitwiseNeg = _handle_unop_Default
|
|
343
|
+
_handle_unop_Reference = _handle_unop_Default
|
|
344
|
+
_handle_unop_Dereference = _handle_unop_Default
|
|
345
|
+
_handle_unop_Clz = _handle_unop_Default
|
|
346
|
+
_handle_unop_Ctz = _handle_unop_Default
|
|
347
|
+
_handle_unop_GetMSBs = _handle_unop_Default
|
|
348
|
+
_handle_unop_unpack = _handle_unop_Default
|
|
349
|
+
_handle_unop_Sqrt = _handle_unop_Default
|
|
350
|
+
_handle_unop_RSqrtEst = _handle_unop_Default
|
|
351
|
+
|
|
352
|
+
def _handle_binop_Default(self, expr):
|
|
353
|
+
lhs = self._expr(expr.operands[0])
|
|
354
|
+
rhs = self._expr(expr.operands[1])
|
|
355
|
+
if (lhs, rhs) != tuple(expr.operands):
|
|
356
|
+
return ailment.expression.BinaryOp(
|
|
357
|
+
expr.idx,
|
|
358
|
+
expr.op,
|
|
359
|
+
(lhs, rhs),
|
|
360
|
+
expr.signed,
|
|
361
|
+
variable=expr.variable,
|
|
362
|
+
variable_offset=expr.variable_offset,
|
|
363
|
+
bits=expr.bits,
|
|
364
|
+
floating_point=expr.floating_point,
|
|
365
|
+
rounding_mode=expr.rounding_mode,
|
|
366
|
+
vector_count=expr.vector_count,
|
|
367
|
+
vector_size=expr.vector_size,
|
|
368
|
+
**expr.tags,
|
|
369
|
+
)
|
|
370
|
+
return expr
|
|
371
|
+
|
|
372
|
+
_handle_binop_Add = _handle_binop_Default
|
|
373
|
+
|
|
374
|
+
_handle_binop_AddF = _handle_binop_Default
|
|
375
|
+
|
|
376
|
+
_handle_binop_AddV = _handle_binop_Default
|
|
377
|
+
|
|
378
|
+
_handle_binop_Sub = _handle_binop_Default
|
|
379
|
+
|
|
380
|
+
_handle_binop_SubF = _handle_binop_Default
|
|
381
|
+
|
|
382
|
+
_handle_binop_SubV = _handle_binop_Default
|
|
383
|
+
|
|
384
|
+
_handle_binop_MulF = _handle_binop_Default
|
|
385
|
+
|
|
386
|
+
_handle_binop_MulV = _handle_binop_Default
|
|
387
|
+
|
|
388
|
+
_handle_binop_MulHiV = _handle_binop_Default
|
|
389
|
+
|
|
390
|
+
_handle_binop_Div = _handle_binop_Default
|
|
391
|
+
|
|
392
|
+
_handle_binop_DivV = _handle_binop_Default
|
|
393
|
+
|
|
394
|
+
_handle_binop_DivF = _handle_binop_Default
|
|
395
|
+
|
|
396
|
+
_handle_binop_Mod = _handle_binop_Default
|
|
397
|
+
|
|
398
|
+
_handle_binop_Xor = _handle_binop_Default
|
|
399
|
+
|
|
400
|
+
_handle_binop_And = _handle_binop_Default
|
|
401
|
+
|
|
402
|
+
_handle_binop_Or = _handle_binop_Default
|
|
403
|
+
|
|
404
|
+
_handle_binop_LogicalAnd = _handle_binop_Default
|
|
405
|
+
|
|
406
|
+
_handle_binop_LogicalOr = _handle_binop_Default
|
|
407
|
+
|
|
408
|
+
_handle_binop_Shl = _handle_binop_Default
|
|
409
|
+
|
|
410
|
+
_handle_binop_Shr = _handle_binop_Default
|
|
411
|
+
|
|
412
|
+
_handle_binop_Sar = _handle_binop_Default
|
|
413
|
+
|
|
414
|
+
_handle_binop_CmpF = _handle_binop_Default
|
|
415
|
+
|
|
416
|
+
_handle_binop_CmpEQ = _handle_binop_Default
|
|
417
|
+
|
|
418
|
+
_handle_binop_CmpNE = _handle_binop_Default
|
|
419
|
+
|
|
420
|
+
_handle_binop_CmpLT = _handle_binop_Default
|
|
421
|
+
|
|
422
|
+
_handle_binop_CmpLE = _handle_binop_Default
|
|
423
|
+
|
|
424
|
+
_handle_binop_CmpGT = _handle_binop_Default
|
|
425
|
+
|
|
426
|
+
_handle_binop_CmpGE = _handle_binop_Default
|
|
427
|
+
|
|
428
|
+
_handle_binop_Concat = _handle_binop_Default
|
|
429
|
+
|
|
430
|
+
_handle_binop_Ror = _handle_binop_Default
|
|
431
|
+
|
|
432
|
+
_handle_binop_Rol = _handle_binop_Default
|
|
433
|
+
|
|
434
|
+
_handle_binop_Carry = _handle_binop_Default
|
|
435
|
+
|
|
436
|
+
_handle_binop_SCarry = _handle_binop_Default
|
|
437
|
+
|
|
438
|
+
_handle_binop_SBorrow = _handle_binop_Default
|
|
439
|
+
|
|
440
|
+
_handle_binop_InterleaveLOV = _handle_binop_Default
|
|
441
|
+
|
|
442
|
+
_handle_binop_InterleaveHIV = _handle_binop_Default
|
|
443
|
+
|
|
444
|
+
_handle_binop_CasCmpEQ = _handle_binop_Default
|
|
445
|
+
|
|
446
|
+
_handle_binop_CasCmpNE = _handle_binop_Default
|
|
447
|
+
|
|
448
|
+
_handle_binop_ExpCmpNE = _handle_binop_Default
|
|
449
|
+
|
|
450
|
+
_handle_binop_SarNV = _handle_binop_Default
|
|
451
|
+
|
|
452
|
+
_handle_binop_ShrNV = _handle_binop_Default
|
|
453
|
+
|
|
454
|
+
_handle_binop_ShlNV = _handle_binop_Default
|
|
455
|
+
|
|
456
|
+
_handle_binop_CmpEQV = _handle_binop_Default
|
|
457
|
+
|
|
458
|
+
_handle_binop_CmpNEV = _handle_binop_Default
|
|
459
|
+
|
|
460
|
+
_handle_binop_CmpGEV = _handle_binop_Default
|
|
461
|
+
|
|
462
|
+
_handle_binop_CmpGTV = _handle_binop_Default
|
|
463
|
+
|
|
464
|
+
_handle_binop_CmpLEV = _handle_binop_Default
|
|
465
|
+
|
|
466
|
+
_handle_binop_CmpLTV = _handle_binop_Default
|
|
467
|
+
|
|
468
|
+
_handle_binop_MinV = _handle_binop_Default
|
|
469
|
+
|
|
470
|
+
_handle_binop_MaxV = _handle_binop_Default
|
|
471
|
+
|
|
472
|
+
_handle_binop_QAddV = _handle_binop_Default
|
|
473
|
+
|
|
474
|
+
_handle_binop_QNarrowBinV = _handle_binop_Default
|
|
475
|
+
|
|
476
|
+
_handle_binop_PermV = _handle_binop_Default
|
|
477
|
+
|
|
478
|
+
_handle_binop_Set = _handle_binop_Default
|