angr 9.2.131__py3-none-manylinux2014_aarch64.whl → 9.2.133__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 +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/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 +262 -263
- 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
angr/analyses/ddg.py
CHANGED
|
@@ -2,8 +2,10 @@ from __future__ import annotations
|
|
|
2
2
|
import logging
|
|
3
3
|
from collections import defaultdict
|
|
4
4
|
|
|
5
|
+
import claripy
|
|
5
6
|
import networkx
|
|
6
7
|
import pyvex
|
|
8
|
+
|
|
7
9
|
from . import Analysis
|
|
8
10
|
|
|
9
11
|
from angr.code_location import CodeLocation
|
|
@@ -93,7 +95,7 @@ class DDGJob:
|
|
|
93
95
|
self.call_depth = call_depth
|
|
94
96
|
|
|
95
97
|
def __repr__(self):
|
|
96
|
-
return "<DDGJob
|
|
98
|
+
return f"<DDGJob {self.cfg_node}, call_depth {self.call_depth}>"
|
|
97
99
|
|
|
98
100
|
|
|
99
101
|
class LiveDefinitions:
|
|
@@ -340,11 +342,7 @@ class DDGViewItem:
|
|
|
340
342
|
return None
|
|
341
343
|
|
|
342
344
|
def __repr__(self):
|
|
343
|
-
return "[
|
|
344
|
-
self._variable,
|
|
345
|
-
len(self.dependents),
|
|
346
|
-
len(self.depends_on),
|
|
347
|
-
)
|
|
345
|
+
return f"[{self._variable}, {len(self.dependents)} dependents, depends on {len(self.depends_on)}]"
|
|
348
346
|
|
|
349
347
|
def __eq__(self, other):
|
|
350
348
|
return (
|
|
@@ -1030,9 +1028,9 @@ class DDG(Analysis):
|
|
|
1030
1028
|
|
|
1031
1029
|
if not action.data.reg_deps and not action.data.tmp_deps:
|
|
1032
1030
|
# might be a constant assignment
|
|
1033
|
-
v = action.data.ast
|
|
1031
|
+
v: claripy.ast.BV = action.data.ast
|
|
1034
1032
|
if not v.symbolic:
|
|
1035
|
-
const_var = SimConstantVariable(v.concrete_value)
|
|
1033
|
+
const_var = SimConstantVariable(value=v.concrete_value, size=v.size())
|
|
1036
1034
|
const_progvar = ProgramVariable(const_var, prog_var.location)
|
|
1037
1035
|
self._data_graph_add_edge(const_progvar, prog_var, type="mem_data")
|
|
1038
1036
|
|
|
@@ -1109,7 +1107,8 @@ class DDG(Analysis):
|
|
|
1109
1107
|
elif isinstance(statement.data, pyvex.IRExpr.Const):
|
|
1110
1108
|
# assignment
|
|
1111
1109
|
const = statement.data.con.value
|
|
1112
|
-
|
|
1110
|
+
size = statement.data.con.size
|
|
1111
|
+
self._ast_graph.add_edge(ProgramVariable(SimConstantVariable(value=const, size=size), location), pv)
|
|
1113
1112
|
|
|
1114
1113
|
def _handle_reg_read(self, action, location, state, statement): # pylint:disable=unused-argument
|
|
1115
1114
|
reg_offset = action.offset
|
|
@@ -1140,7 +1139,7 @@ class DDG(Analysis):
|
|
|
1140
1139
|
elif reg_offset == self.project.arch.bp_offset:
|
|
1141
1140
|
self._custom_data_per_statement = ("bp", 0)
|
|
1142
1141
|
|
|
1143
|
-
def _handle_reg_write(self, action, location, state, statement): # pylint:disable=unused-argument
|
|
1142
|
+
def _handle_reg_write(self, action, location, state, statement: pyvex.stmt.Put): # pylint:disable=unused-argument
|
|
1144
1143
|
reg_offset = action.offset
|
|
1145
1144
|
variable = SimRegisterVariable(reg_offset, action.data.ast.size() // 8)
|
|
1146
1145
|
|
|
@@ -1157,9 +1156,9 @@ class DDG(Analysis):
|
|
|
1157
1156
|
if not action.reg_deps and not action.tmp_deps:
|
|
1158
1157
|
# moving a constant into the register
|
|
1159
1158
|
# try to parse out the constant from statement
|
|
1160
|
-
const_variable = SimConstantVariable()
|
|
1159
|
+
const_variable = SimConstantVariable(size=1)
|
|
1161
1160
|
if statement is not None and isinstance(statement.data, pyvex.IRExpr.Const):
|
|
1162
|
-
const_variable = SimConstantVariable(value=statement.data.con.value)
|
|
1161
|
+
const_variable = SimConstantVariable(value=statement.data.con.value, size=statement.data.con.size)
|
|
1163
1162
|
const_pv = ProgramVariable(const_variable, location, arch=self.project.arch)
|
|
1164
1163
|
self._data_graph_add_edge(const_pv, pv)
|
|
1165
1164
|
|
|
@@ -1187,7 +1186,7 @@ class DDG(Analysis):
|
|
|
1187
1186
|
ast = None
|
|
1188
1187
|
|
|
1189
1188
|
tmp = action.tmp
|
|
1190
|
-
pv = ProgramVariable(SimTemporaryVariable(tmp), location, arch=self.project.arch)
|
|
1189
|
+
pv = ProgramVariable(SimTemporaryVariable(tmp, len(action.data)), location, arch=self.project.arch)
|
|
1191
1190
|
|
|
1192
1191
|
if ast is not None:
|
|
1193
1192
|
for operand in ast.operands:
|
|
@@ -1230,12 +1229,12 @@ class DDG(Analysis):
|
|
|
1230
1229
|
if not action.tmp_deps and not self._variables_per_statement and not ast:
|
|
1231
1230
|
# read in a constant
|
|
1232
1231
|
# try to parse out the constant from statement
|
|
1233
|
-
const_variable = SimConstantVariable()
|
|
1232
|
+
const_variable = SimConstantVariable(size=1)
|
|
1234
1233
|
if statement is not None:
|
|
1235
1234
|
if isinstance(statement, pyvex.IRStmt.Dirty):
|
|
1236
1235
|
l.warning("Dirty statements are not supported in DDG for now.")
|
|
1237
1236
|
elif isinstance(statement.data, pyvex.IRExpr.Const):
|
|
1238
|
-
const_variable = SimConstantVariable(value=statement.data.con.value)
|
|
1237
|
+
const_variable = SimConstantVariable(value=statement.data.con.value, size=statement.data.con.size)
|
|
1239
1238
|
const_pv = ProgramVariable(const_variable, location, arch=self.project.arch)
|
|
1240
1239
|
self._data_graph_add_edge(const_pv, pv)
|
|
1241
1240
|
|
|
@@ -1296,7 +1295,7 @@ class DDG(Analysis):
|
|
|
1296
1295
|
const_value = expr_1.ast.args[0]
|
|
1297
1296
|
tmp = next(iter(expr_0.tmp_deps))
|
|
1298
1297
|
|
|
1299
|
-
const_def = ProgramVariable(SimConstantVariable(const_value), location)
|
|
1298
|
+
const_def = ProgramVariable(SimConstantVariable(value=const_value, size=len(expr_1.ast)), location)
|
|
1300
1299
|
tmp_def = self._temp_variables[tmp]
|
|
1301
1300
|
return AST("-", tmp_def, const_def)
|
|
1302
1301
|
|
|
@@ -1310,7 +1309,7 @@ class DDG(Analysis):
|
|
|
1310
1309
|
const_value = expr_1.ast.args[0]
|
|
1311
1310
|
tmp = next(iter(expr_0.tmp_deps))
|
|
1312
1311
|
|
|
1313
|
-
const_def = ProgramVariable(SimConstantVariable(const_value), location)
|
|
1312
|
+
const_def = ProgramVariable(SimConstantVariable(value=const_value, size=len(expr_1.ast)), location)
|
|
1314
1313
|
tmp_def = self._temp_variables[tmp]
|
|
1315
1314
|
return AST("+", tmp_def, const_def)
|
|
1316
1315
|
|
|
@@ -20,22 +20,22 @@ StructuredCodeGenerator = CStructuredCodeGenerator
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
__all__ = (
|
|
23
|
-
"
|
|
23
|
+
"DECOMPILATION_PRESETS",
|
|
24
|
+
"AILSimplifier",
|
|
25
|
+
"BlockSimplifier",
|
|
24
26
|
"CStructuredCodeGenerator",
|
|
25
|
-
"
|
|
27
|
+
"CallSiteMaker",
|
|
26
28
|
"Clinic",
|
|
27
|
-
"RegionSimplifier",
|
|
28
29
|
"Decompiler",
|
|
29
|
-
"options",
|
|
30
|
-
"options_by_category",
|
|
31
|
-
"BlockSimplifier",
|
|
32
|
-
"CallSiteMaker",
|
|
33
|
-
"AILSimplifier",
|
|
34
|
-
"Ssailification",
|
|
35
30
|
"GraphDephication",
|
|
31
|
+
"ImportSourceCode",
|
|
32
|
+
"RegionIdentifier",
|
|
33
|
+
"RegionSimplifier",
|
|
36
34
|
"SeqNodeDephication",
|
|
37
|
-
"
|
|
38
|
-
"structuring",
|
|
39
|
-
"optimization_passes",
|
|
35
|
+
"Ssailification",
|
|
40
36
|
"StructuredCodeGenerator",
|
|
37
|
+
"optimization_passes",
|
|
38
|
+
"options",
|
|
39
|
+
"options_by_category",
|
|
40
|
+
"structuring",
|
|
41
41
|
)
|
|
@@ -24,6 +24,7 @@ from ailment.expression import (
|
|
|
24
24
|
VirtualVariable,
|
|
25
25
|
)
|
|
26
26
|
|
|
27
|
+
from angr.analyses.s_propagator import SPropagatorAnalysis
|
|
27
28
|
from angr.analyses.s_reaching_definitions import SRDAModel
|
|
28
29
|
from angr.utils.ail import is_phi_assignment, HasExprWalker
|
|
29
30
|
from angr.code_location import CodeLocation, ExternalCodeLocation
|
|
@@ -96,6 +97,7 @@ class AILSimplifier(Analysis):
|
|
|
96
97
|
rewrite_ccalls=True,
|
|
97
98
|
removed_vvar_ids: set[int] | None = None,
|
|
98
99
|
arg_vvars: dict[int, tuple[VirtualVariable, SimVariable]] | None = None,
|
|
100
|
+
avoid_vvar_ids: set[int] | None = None,
|
|
99
101
|
):
|
|
100
102
|
self.func = func
|
|
101
103
|
self.func_graph = func_graph if func_graph is not None else func.graph
|
|
@@ -114,6 +116,7 @@ class AILSimplifier(Analysis):
|
|
|
114
116
|
self._should_rewrite_ccalls = rewrite_ccalls
|
|
115
117
|
self._removed_vvar_ids = removed_vvar_ids if removed_vvar_ids is not None else set()
|
|
116
118
|
self._arg_vvars = arg_vvars
|
|
119
|
+
self._avoid_vvar_ids = avoid_vvar_ids
|
|
117
120
|
|
|
118
121
|
self._calls_to_remove: set[CodeLocation] = set()
|
|
119
122
|
self._assignments_to_remove: set[CodeLocation] = set()
|
|
@@ -213,11 +216,11 @@ class AILSimplifier(Analysis):
|
|
|
213
216
|
self._reaching_definitions = rd
|
|
214
217
|
return rd
|
|
215
218
|
|
|
216
|
-
def _compute_propagation(self, immediate_stmt_removal: bool = False):
|
|
219
|
+
def _compute_propagation(self, immediate_stmt_removal: bool = False) -> SPropagatorAnalysis:
|
|
217
220
|
# Propagate expressions or return the existing result
|
|
218
221
|
if self._propagator is not None:
|
|
219
222
|
return self._propagator
|
|
220
|
-
prop = self.project.analyses.
|
|
223
|
+
prop = self.project.analyses[SPropagatorAnalysis].prep()(
|
|
221
224
|
subject=self.func,
|
|
222
225
|
func_graph=self.func_graph,
|
|
223
226
|
# gp=self._gp,
|
|
@@ -551,7 +554,9 @@ class AILSimplifier(Analysis):
|
|
|
551
554
|
if (
|
|
552
555
|
first_op.op == "And"
|
|
553
556
|
and isinstance(first_op.operands[1], Const)
|
|
554
|
-
and (
|
|
557
|
+
and (
|
|
558
|
+
second_op is None or (isinstance(second_op, BinaryOp) and isinstance(second_op.operands[1], Const))
|
|
559
|
+
)
|
|
555
560
|
):
|
|
556
561
|
mask = first_op.operands[1].value
|
|
557
562
|
if mask == 0xFF:
|
|
@@ -614,6 +619,17 @@ class AILSimplifier(Analysis):
|
|
|
614
619
|
stmt.ins_addr for stmt in block.statements
|
|
615
620
|
}.intersection(insn_addrs_using_stack_args)
|
|
616
621
|
|
|
622
|
+
# remove virtual variables in the avoid list
|
|
623
|
+
if self._avoid_vvar_ids:
|
|
624
|
+
filtered_reps = {}
|
|
625
|
+
for loc, rep_dict in reps.items():
|
|
626
|
+
filtered_reps[loc] = {
|
|
627
|
+
k: v
|
|
628
|
+
for k, v in rep_dict.items()
|
|
629
|
+
if not (isinstance(k, VirtualVariable) and k.varid in self._avoid_vvar_ids)
|
|
630
|
+
}
|
|
631
|
+
reps = filtered_reps
|
|
632
|
+
|
|
617
633
|
r, new_block = BlockSimplifier._replace_and_build(block, reps, gp=self._gp, replace_loads=replace_loads)
|
|
618
634
|
replaced |= r
|
|
619
635
|
self.blocks[block] = new_block
|
|
@@ -747,10 +763,8 @@ class AILSimplifier(Analysis):
|
|
|
747
763
|
# the definition is in a callee function
|
|
748
764
|
continue
|
|
749
765
|
|
|
750
|
-
if (
|
|
751
|
-
isinstance(
|
|
752
|
-
or isinstance(eq.atom1, VirtualVariable)
|
|
753
|
-
and eq.atom1.was_parameter
|
|
766
|
+
if isinstance(the_def.codeloc, ExternalCodeLocation) or (
|
|
767
|
+
isinstance(eq.atom1, VirtualVariable) and eq.atom1.was_parameter
|
|
754
768
|
):
|
|
755
769
|
# this is a function argument. we enter a slightly different logic and try to eliminate copies of this
|
|
756
770
|
# argument if
|
|
@@ -764,10 +778,8 @@ class AILSimplifier(Analysis):
|
|
|
764
778
|
|
|
765
779
|
if defs and len(defs) == 1:
|
|
766
780
|
arg_copy_def = defs[0]
|
|
767
|
-
if (
|
|
768
|
-
isinstance(arg_copy_def.atom, atoms.VirtualVariable)
|
|
769
|
-
and arg_copy_def.atom.was_stack
|
|
770
|
-
or (isinstance(arg_copy_def.atom, atoms.VirtualVariable) and arg_copy_def.atom.was_reg)
|
|
781
|
+
if (isinstance(arg_copy_def.atom, atoms.VirtualVariable) and arg_copy_def.atom.was_stack) or (
|
|
782
|
+
isinstance(arg_copy_def.atom, atoms.VirtualVariable) and arg_copy_def.atom.was_reg
|
|
771
783
|
):
|
|
772
784
|
# found the copied definition (either a stack variable or a register variable)
|
|
773
785
|
|
|
@@ -918,7 +930,7 @@ class AILSimplifier(Analysis):
|
|
|
918
930
|
continue
|
|
919
931
|
block = addr_and_idx_to_block[(use_loc.block_addr, use_loc.block_idx)]
|
|
920
932
|
stmt = block.statements[use_loc.stmt_idx]
|
|
921
|
-
if isinstance(stmt, Assignment) or isinstance(replace_with, Load) and isinstance(stmt, Store):
|
|
933
|
+
if isinstance(stmt, Assignment) or (isinstance(replace_with, Load) and isinstance(stmt, Store)):
|
|
922
934
|
assignment_ctr += 1
|
|
923
935
|
if assignment_ctr > 1:
|
|
924
936
|
continue
|
|
@@ -127,10 +127,8 @@ def _kmp_search_ail_obj(search_pattern, stmt_seq, graph=None, partial=True):
|
|
|
127
127
|
start_pos = 0
|
|
128
128
|
match_len = 0
|
|
129
129
|
for c in stmt_seq:
|
|
130
|
-
while (
|
|
131
|
-
match_len
|
|
132
|
-
or match_len >= 0
|
|
133
|
-
and not is_similar(search_pattern[match_len], c, graph=graph, partial=partial)
|
|
130
|
+
while match_len == len(search_pattern) or (
|
|
131
|
+
match_len >= 0 and not is_similar(search_pattern[match_len], c, graph=graph, partial=partial)
|
|
134
132
|
):
|
|
135
133
|
start_pos += shifts[match_len]
|
|
136
134
|
match_len -= shifts[match_len]
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
from __future__ import annotations
|
|
3
3
|
import logging
|
|
4
4
|
from typing import TYPE_CHECKING
|
|
5
|
-
from collections.abc import Iterable
|
|
5
|
+
from collections.abc import Iterable, Mapping
|
|
6
6
|
|
|
7
7
|
from ailment.statement import Statement, Assignment, Call, Store, Jump
|
|
8
|
-
from ailment.expression import Tmp, Load, Const, Register, Convert
|
|
8
|
+
from ailment.expression import Tmp, Load, Const, Register, Convert, Expression
|
|
9
9
|
from ailment import AILBlockWalkerBase
|
|
10
10
|
|
|
11
11
|
from angr.code_location import ExternalCodeLocation, CodeLocation
|
|
@@ -139,7 +139,7 @@ class BlockSimplifier(Analysis):
|
|
|
139
139
|
|
|
140
140
|
self.result_block = block
|
|
141
141
|
|
|
142
|
-
def _compute_propagation(self, block):
|
|
142
|
+
def _compute_propagation(self, block) -> SPropagatorAnalysis:
|
|
143
143
|
if self._propagator is None:
|
|
144
144
|
self._propagator = self.project.analyses[SPropagatorAnalysis].prep()(
|
|
145
145
|
subject=block,
|
|
@@ -155,7 +155,6 @@ class BlockSimplifier(Analysis):
|
|
|
155
155
|
.prep()(
|
|
156
156
|
subject=block,
|
|
157
157
|
track_tmps=True,
|
|
158
|
-
stack_pointer_tracker=self._stack_pointer_tracker,
|
|
159
158
|
func_addr=self.func_addr,
|
|
160
159
|
)
|
|
161
160
|
.model
|
|
@@ -201,8 +200,8 @@ class BlockSimplifier(Analysis):
|
|
|
201
200
|
|
|
202
201
|
@staticmethod
|
|
203
202
|
def _replace_and_build(
|
|
204
|
-
block,
|
|
205
|
-
replacements,
|
|
203
|
+
block: Block,
|
|
204
|
+
replacements: Mapping[CodeLocation, Mapping[Expression, Expression]],
|
|
206
205
|
replace_assignment_dsts: bool = False,
|
|
207
206
|
replace_loads: bool = False,
|
|
208
207
|
gp: int | None = None,
|
|
@@ -211,14 +210,9 @@ class BlockSimplifier(Analysis):
|
|
|
211
210
|
new_statements = block.statements[::]
|
|
212
211
|
replaced = False
|
|
213
212
|
|
|
214
|
-
stmts_to_remove = set()
|
|
215
213
|
for codeloc, repls in replacements.items():
|
|
216
214
|
for old, new in repls.items():
|
|
217
|
-
|
|
218
|
-
if isinstance(new, dict):
|
|
219
|
-
stmt_to_remove = new["stmt_to_remove"]
|
|
220
|
-
new = new["expr"]
|
|
221
|
-
|
|
215
|
+
assert codeloc.stmt_idx is not None
|
|
222
216
|
stmt = new_statements[codeloc.stmt_idx]
|
|
223
217
|
if (
|
|
224
218
|
not replace_loads
|
|
@@ -229,7 +223,9 @@ class BlockSimplifier(Analysis):
|
|
|
229
223
|
# skip memory-based replacement for non-Call and non-gp-loading statements
|
|
230
224
|
continue
|
|
231
225
|
if stmt == old:
|
|
232
|
-
#
|
|
226
|
+
# the replacement must be a call, since replacements can only be expressions
|
|
227
|
+
# and call is the only thing which is both a statement and an expression
|
|
228
|
+
assert isinstance(new, Call)
|
|
233
229
|
r = True
|
|
234
230
|
new_stmt = new
|
|
235
231
|
else:
|
|
@@ -257,20 +253,13 @@ class BlockSimplifier(Analysis):
|
|
|
257
253
|
r, new_stmt = stmt.replace(old, new)
|
|
258
254
|
|
|
259
255
|
if r:
|
|
256
|
+
assert new_stmt is not None
|
|
260
257
|
replaced = True
|
|
261
258
|
new_statements[codeloc.stmt_idx] = new_stmt
|
|
262
|
-
if stmt_to_remove is not None:
|
|
263
|
-
stmts_to_remove.add(stmt_to_remove)
|
|
264
259
|
|
|
265
260
|
if not replaced:
|
|
266
261
|
return False, block
|
|
267
262
|
|
|
268
|
-
if stmts_to_remove:
|
|
269
|
-
stmt_ids_to_remove = {a.stmt_idx for a in stmts_to_remove}
|
|
270
|
-
all_stmts = {idx: stmt for idx, stmt in enumerate(new_statements) if idx not in stmt_ids_to_remove}
|
|
271
|
-
filtered_stmts = sorted(all_stmts.items(), key=lambda x: x[0])
|
|
272
|
-
new_statements = [stmt for _, stmt in filtered_stmts]
|
|
273
|
-
|
|
274
263
|
new_block = block.copy()
|
|
275
264
|
new_block.statements = new_statements
|
|
276
265
|
return True, new_block
|
|
@@ -392,7 +392,7 @@ class CallSiteMaker(Analysis):
|
|
|
392
392
|
return s
|
|
393
393
|
|
|
394
394
|
def _determine_variadic_arguments(self, func: Function | None, cc: SimCC, call_stmt) -> int | None:
|
|
395
|
-
if func is not None and "printf" in func.name or "scanf" in func.name:
|
|
395
|
+
if (func is not None and "printf" in func.name) or "scanf" in func.name:
|
|
396
396
|
return self._determine_variadic_arguments_for_format_strings(func, cc, call_stmt)
|
|
397
397
|
return None
|
|
398
398
|
|