angr 9.2.134__py3-none-macosx_10_9_x86_64.whl → 9.2.136__py3-none-macosx_10_9_x86_64.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/__init__.py +5 -8
- angr/analyses/analysis.py +4 -0
- angr/analyses/backward_slice.py +1 -2
- angr/analyses/binary_optimizer.py +3 -4
- angr/analyses/bindiff.py +4 -6
- angr/analyses/boyscout.py +1 -3
- angr/analyses/callee_cleanup_finder.py +4 -4
- angr/analyses/calling_convention/__init__.py +6 -0
- angr/analyses/{calling_convention.py → calling_convention/calling_convention.py} +32 -64
- angr/analyses/calling_convention/fact_collector.py +502 -0
- angr/analyses/calling_convention/utils.py +57 -0
- angr/analyses/cdg.py +1 -2
- angr/analyses/cfg/cfb.py +1 -3
- angr/analyses/cfg/cfg.py +2 -2
- angr/analyses/cfg/cfg_base.py +37 -35
- angr/analyses/cfg/cfg_emulated.py +1 -1
- angr/analyses/cfg/cfg_fast.py +62 -15
- angr/analyses/cfg/cfg_fast_soot.py +1 -1
- angr/analyses/cfg/indirect_jump_resolvers/__init__.py +2 -0
- angr/analyses/cfg/indirect_jump_resolvers/const_resolver.py +46 -10
- angr/analyses/cfg/indirect_jump_resolvers/default_resolvers.py +5 -1
- angr/analyses/cfg/indirect_jump_resolvers/jumptable.py +50 -14
- angr/analyses/cfg/indirect_jump_resolvers/memload_resolver.py +81 -0
- angr/analyses/cfg/indirect_jump_resolvers/propagator_utils.py +24 -5
- angr/analyses/cfg/indirect_jump_resolvers/x86_pe_iat.py +2 -5
- angr/analyses/complete_calling_conventions.py +32 -3
- angr/analyses/congruency_check.py +2 -3
- angr/analyses/data_dep/data_dependency_analysis.py +2 -2
- angr/analyses/ddg.py +1 -4
- angr/analyses/decompiler/ail_simplifier.py +3 -4
- angr/analyses/decompiler/clinic.py +42 -7
- angr/analyses/decompiler/optimization_passes/duplication_reverter/ail_merge_graph.py +2 -2
- angr/analyses/decompiler/optimization_passes/duplication_reverter/duplication_reverter.py +2 -2
- angr/analyses/decompiler/optimization_passes/ite_region_converter.py +1 -1
- angr/analyses/decompiler/optimization_passes/lowered_switch_simplifier.py +1 -1
- angr/analyses/decompiler/optimization_passes/register_save_area_simplifier.py +0 -6
- angr/analyses/decompiler/optimization_passes/stack_canary_simplifier.py +2 -7
- angr/analyses/decompiler/optimization_passes/switch_default_case_duplicator.py +0 -6
- angr/analyses/decompiler/optimization_passes/win_stack_canary_simplifier.py +0 -6
- angr/analyses/decompiler/structuring/phoenix.py +1 -1
- angr/analyses/disassembly.py +5 -5
- angr/analyses/fcp/__init__.py +4 -0
- angr/analyses/fcp/fcp.py +429 -0
- angr/analyses/identifier/identify.py +1 -3
- angr/analyses/loopfinder.py +4 -3
- angr/analyses/patchfinder.py +1 -1
- angr/analyses/propagator/engine_base.py +4 -3
- angr/analyses/propagator/propagator.py +14 -53
- angr/analyses/reassembler.py +1 -2
- angr/analyses/s_propagator.py +1 -3
- angr/analyses/soot_class_hierarchy.py +1 -2
- angr/analyses/stack_pointer_tracker.py +18 -2
- angr/analyses/static_hooker.py +1 -2
- angr/analyses/typehoon/simple_solver.py +2 -2
- angr/analyses/variable_recovery/engine_vex.py +5 -0
- angr/analyses/variable_recovery/variable_recovery_fast.py +1 -2
- angr/analyses/veritesting.py +4 -7
- angr/analyses/vfg.py +1 -1
- angr/analyses/vsa_ddg.py +1 -2
- angr/block.py +3 -2
- angr/callable.py +1 -3
- angr/calling_conventions.py +15 -7
- angr/codenode.py +5 -1
- angr/concretization_strategies/__init__.py +1 -83
- angr/concretization_strategies/any.py +2 -1
- angr/concretization_strategies/any_named.py +1 -1
- angr/concretization_strategies/base.py +81 -0
- angr/concretization_strategies/controlled_data.py +2 -1
- angr/concretization_strategies/eval.py +2 -1
- angr/concretization_strategies/logging.py +3 -1
- angr/concretization_strategies/max.py +2 -1
- angr/concretization_strategies/nonzero.py +2 -1
- angr/concretization_strategies/nonzero_range.py +2 -1
- angr/concretization_strategies/norepeats.py +2 -1
- angr/concretization_strategies/norepeats_range.py +2 -1
- angr/concretization_strategies/range.py +2 -1
- angr/concretization_strategies/signed_add.py +2 -1
- angr/concretization_strategies/single.py +2 -1
- angr/concretization_strategies/solutions.py +2 -1
- angr/concretization_strategies/unlimited_range.py +2 -1
- angr/engines/__init__.py +8 -5
- angr/engines/engine.py +3 -5
- angr/engines/failure.py +4 -5
- angr/engines/procedure.py +5 -7
- angr/engines/soot/expressions/__init__.py +22 -23
- angr/engines/soot/expressions/base.py +4 -4
- angr/engines/soot/expressions/invoke.py +1 -2
- angr/engines/soot/statements/__init__.py +9 -10
- angr/engines/soot/values/__init__.py +9 -10
- angr/engines/soot/values/arrayref.py +3 -3
- angr/engines/soot/values/instancefieldref.py +3 -2
- angr/engines/successors.py +7 -6
- angr/engines/syscall.py +4 -6
- angr/engines/unicorn.py +3 -2
- angr/engines/vex/claripy/ccall.py +8 -10
- angr/engines/vex/claripy/datalayer.py +4 -5
- angr/exploration_techniques/__init__.py +0 -2
- angr/exploration_techniques/spiller.py +1 -3
- angr/exploration_techniques/stochastic.py +2 -3
- angr/factory.py +3 -9
- angr/knowledge_plugins/cfg/cfg_model.py +20 -17
- angr/knowledge_plugins/functions/function.py +74 -77
- angr/knowledge_plugins/functions/function_manager.py +14 -7
- angr/knowledge_plugins/functions/function_parser.py +1 -1
- angr/knowledge_plugins/functions/soot_function.py +16 -16
- angr/knowledge_plugins/propagations/propagation_model.py +4 -5
- angr/knowledge_plugins/propagations/states.py +0 -511
- angr/lib/angr_native.dylib +0 -0
- angr/procedures/libc/memcpy.py +4 -4
- angr/procedures/procedure_dict.py +3 -2
- angr/protos/__init__.py +2 -5
- angr/protos/cfg_pb2.py +21 -18
- angr/protos/function_pb2.py +17 -14
- angr/protos/primitives_pb2.py +44 -39
- angr/protos/variables_pb2.py +36 -31
- angr/protos/xrefs_pb2.py +15 -12
- angr/sim_procedure.py +15 -16
- angr/sim_variable.py +13 -1
- angr/simos/__init__.py +2 -0
- angr/simos/javavm.py +4 -6
- angr/simos/xbox.py +32 -0
- angr/state_plugins/__init__.py +0 -2
- angr/state_plugins/callstack.py +4 -4
- angr/state_plugins/cgc.py +3 -2
- angr/state_plugins/gdb.py +6 -5
- angr/state_plugins/globals.py +1 -2
- angr/state_plugins/heap/heap_brk.py +1 -2
- angr/state_plugins/history.py +10 -12
- angr/state_plugins/inspect.py +3 -5
- angr/state_plugins/libc.py +2 -2
- angr/state_plugins/log.py +8 -10
- angr/state_plugins/loop_data.py +1 -2
- angr/state_plugins/posix.py +7 -7
- angr/state_plugins/preconstrainer.py +2 -3
- angr/state_plugins/scratch.py +5 -8
- angr/state_plugins/sim_action.py +3 -3
- angr/state_plugins/solver.py +8 -3
- angr/state_plugins/symbolizer.py +5 -4
- angr/state_plugins/uc_manager.py +3 -3
- angr/state_plugins/unicorn_engine.py +5 -1
- angr/state_plugins/view.py +3 -5
- angr/storage/file.py +3 -5
- angr/storage/memory_mixins/address_concretization_mixin.py +2 -2
- angr/storage/memory_mixins/bvv_conversion_mixin.py +3 -3
- angr/storage/memory_mixins/clouseau_mixin.py +1 -3
- angr/storage/memory_mixins/name_resolution_mixin.py +1 -3
- angr/storage/memory_mixins/paged_memory/paged_memory_mixin.py +13 -15
- angr/storage/memory_mixins/paged_memory/pages/__init__.py +1 -22
- angr/storage/memory_mixins/paged_memory/pages/base.py +31 -0
- angr/storage/memory_mixins/paged_memory/pages/list_page.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/paged_memory/privileged_mixin.py +3 -4
- angr/storage/memory_mixins/regioned_memory/abstract_merger_mixin.py +4 -2
- angr/storage/memory_mixins/smart_find_mixin.py +1 -1
- angr/storage/memory_mixins/underconstrained_mixin.py +1 -1
- angr/storage/memory_mixins/unwrapper_mixin.py +1 -3
- angr/utils/bits.py +13 -0
- angr/utils/enums_conv.py +28 -12
- angr/utils/segment_list.py +25 -22
- angr/utils/timing.py +18 -1
- angr/vaults.py +5 -6
- {angr-9.2.134.dist-info → angr-9.2.136.dist-info}/METADATA +6 -6
- {angr-9.2.134.dist-info → angr-9.2.136.dist-info}/RECORD +169 -165
- {angr-9.2.134.dist-info → angr-9.2.136.dist-info}/WHEEL +1 -1
- angr/analyses/propagator/outdated_definition_walker.py +0 -159
- angr/analyses/propagator/tmpvar_finder.py +0 -18
- angr/engines/concrete.py +0 -180
- angr/exploration_techniques/symbion.py +0 -80
- angr/state_plugins/concrete.py +0 -295
- {angr-9.2.134.dist-info → angr-9.2.136.dist-info}/LICENSE +0 -0
- {angr-9.2.134.dist-info → angr-9.2.136.dist-info}/entry_points.txt +0 -0
- {angr-9.2.134.dist-info → angr-9.2.136.dist-info}/top_level.txt +0 -0
angr/__init__.py
CHANGED
angr/analyses/__init__.py
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
# " pylint:disable=wrong-import-position
|
|
2
2
|
from __future__ import annotations
|
|
3
3
|
|
|
4
|
-
from .analysis import Analysis, AnalysesHub
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def register_analysis(cls, name):
|
|
8
|
-
AnalysesHub.register_default(name, cls)
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
from .analysis import Analysis, AnalysesHub, register_analysis
|
|
11
5
|
from .forward_analysis import ForwardAnalysis, visitors
|
|
12
6
|
from .propagator import PropagatorAnalysis
|
|
13
7
|
from .cfg import CFGFast, CFGEmulated, CFG, CFGArchOptions, CFGFastSoot
|
|
@@ -30,7 +24,7 @@ from .variable_recovery import VariableRecovery, VariableRecoveryFast
|
|
|
30
24
|
from .identifier import Identifier
|
|
31
25
|
from .callee_cleanup_finder import CalleeCleanupFinder
|
|
32
26
|
from .reaching_definitions import ReachingDefinitionsAnalysis
|
|
33
|
-
from .calling_convention import CallingConventionAnalysis
|
|
27
|
+
from .calling_convention import CallingConventionAnalysis, FactCollector
|
|
34
28
|
from .code_tagging import CodeTagging
|
|
35
29
|
from .stack_pointer_tracker import StackPointerTracker
|
|
36
30
|
from .dominance_frontier import DominanceFrontier
|
|
@@ -54,6 +48,7 @@ from .patchfinder import PatchFinderAnalysis
|
|
|
54
48
|
from .pathfinder import Pathfinder
|
|
55
49
|
from .smc import SelfModifyingCodeAnalysis
|
|
56
50
|
from .unpacker import PackingDetector
|
|
51
|
+
from .fcp import FastConstantPropagation
|
|
57
52
|
from . import deobfuscator
|
|
58
53
|
|
|
59
54
|
|
|
@@ -84,6 +79,8 @@ __all__ = (
|
|
|
84
79
|
"Decompiler",
|
|
85
80
|
"Disassembly",
|
|
86
81
|
"DominanceFrontier",
|
|
82
|
+
"FactCollector",
|
|
83
|
+
"FastConstantPropagation",
|
|
87
84
|
"FlirtAnalysis",
|
|
88
85
|
"ForwardAnalysis",
|
|
89
86
|
"Identifier",
|
angr/analyses/analysis.py
CHANGED
angr/analyses/backward_slice.py
CHANGED
|
@@ -6,6 +6,7 @@ import networkx
|
|
|
6
6
|
import pyvex
|
|
7
7
|
from . import Analysis
|
|
8
8
|
|
|
9
|
+
from angr.analyses import AnalysesHub
|
|
9
10
|
from angr.code_location import CodeLocation
|
|
10
11
|
from angr.annocfg import AnnotatedCFG
|
|
11
12
|
from angr.errors import AngrBackwardSlicingError
|
|
@@ -682,6 +683,4 @@ class BackwardSlice(Analysis):
|
|
|
682
683
|
return cmp_stmt_id, cmp_tmp_id
|
|
683
684
|
|
|
684
685
|
|
|
685
|
-
from angr.analyses import AnalysesHub
|
|
686
|
-
|
|
687
686
|
AnalysesHub.register_default("BackwardSlice", BackwardSlice)
|
|
@@ -4,6 +4,7 @@ import re
|
|
|
4
4
|
from typing import TYPE_CHECKING
|
|
5
5
|
from collections import defaultdict
|
|
6
6
|
|
|
7
|
+
from angr.analyses import AnalysesHub
|
|
7
8
|
from angr.knowledge_base import KnowledgeBase
|
|
8
9
|
from angr.codenode import HookNode
|
|
9
10
|
from angr.sim_variable import SimConstantVariable, SimRegisterVariable, SimMemoryVariable, SimStackVariable
|
|
@@ -430,7 +431,7 @@ class BinaryOptimizer(Analysis):
|
|
|
430
431
|
|
|
431
432
|
# find out all call instructions
|
|
432
433
|
call_insns = set()
|
|
433
|
-
for src,
|
|
434
|
+
for src, _dst, data in function.transition_graph.edges(data=True):
|
|
434
435
|
if "type" in data and data["type"] == "call":
|
|
435
436
|
src_block = function._get_block(src.addr)
|
|
436
437
|
call_insns.add(src_block.instruction_addrs[-1])
|
|
@@ -460,7 +461,7 @@ class BinaryOptimizer(Analysis):
|
|
|
460
461
|
# make sure we never gets the address of those stack variables into any register
|
|
461
462
|
# say, lea edx, [ebp-0x4] is forbidden
|
|
462
463
|
# check all edges in data graph
|
|
463
|
-
for src, dst
|
|
464
|
+
for src, dst in data_graph.edges():
|
|
464
465
|
if (
|
|
465
466
|
isinstance(dst.variable, SimRegisterVariable)
|
|
466
467
|
and dst.variable.reg != ebp_offset
|
|
@@ -666,6 +667,4 @@ class BinaryOptimizer(Analysis):
|
|
|
666
667
|
self.dead_assignments.append(da)
|
|
667
668
|
|
|
668
669
|
|
|
669
|
-
from angr.analyses import AnalysesHub
|
|
670
|
-
|
|
671
670
|
AnalysesHub.register_default("BinaryOptimizer", BinaryOptimizer)
|
angr/analyses/bindiff.py
CHANGED
|
@@ -3,17 +3,17 @@ import logging
|
|
|
3
3
|
import math
|
|
4
4
|
import types
|
|
5
5
|
from collections import deque, defaultdict
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
6
7
|
|
|
7
8
|
import networkx
|
|
8
9
|
|
|
9
|
-
from
|
|
10
|
+
from angr.analyses import AnalysesHub, Analysis, CFGEmulated
|
|
11
|
+
from angr.errors import SimEngineError, SimMemoryError
|
|
12
|
+
|
|
10
13
|
|
|
11
14
|
if TYPE_CHECKING:
|
|
12
15
|
from angr.knowledge_plugins import Function
|
|
13
16
|
|
|
14
|
-
from . import Analysis, CFGEmulated
|
|
15
|
-
|
|
16
|
-
from angr.errors import SimEngineError, SimMemoryError
|
|
17
17
|
|
|
18
18
|
# todo include an explanation of the algorithm
|
|
19
19
|
# todo include a method that detects any change other than constants
|
|
@@ -1234,6 +1234,4 @@ class BinDiff(Analysis):
|
|
|
1234
1234
|
return matches
|
|
1235
1235
|
|
|
1236
1236
|
|
|
1237
|
-
from angr.analyses import AnalysesHub
|
|
1238
|
-
|
|
1239
1237
|
AnalysesHub.register_default("BinDiff", BinDiff)
|
angr/analyses/boyscout.py
CHANGED
|
@@ -6,7 +6,7 @@ from collections import defaultdict
|
|
|
6
6
|
from archinfo import all_arches
|
|
7
7
|
from archinfo.arch_arm import is_arm_arch
|
|
8
8
|
|
|
9
|
-
from . import Analysis
|
|
9
|
+
from angr.analyses import AnalysesHub, Analysis
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
l = logging.getLogger(name=__name__)
|
|
@@ -73,6 +73,4 @@ class BoyScout(Analysis):
|
|
|
73
73
|
l.debug("The architecture should be %s with %s", self.arch, self.endianness)
|
|
74
74
|
|
|
75
75
|
|
|
76
|
-
from angr.analyses import AnalysesHub
|
|
77
|
-
|
|
78
76
|
AnalysesHub.register_default("BoyScout", BoyScout)
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
|
-
from . import Analysis
|
|
3
|
-
from angr import SIM_PROCEDURES
|
|
4
2
|
|
|
5
3
|
import logging
|
|
6
4
|
|
|
5
|
+
from angr import SIM_PROCEDURES
|
|
6
|
+
from angr.analyses import AnalysesHub, Analysis
|
|
7
|
+
|
|
8
|
+
|
|
7
9
|
l = logging.getLogger(name=__name__)
|
|
8
10
|
|
|
9
11
|
|
|
@@ -69,6 +71,4 @@ class CalleeCleanupFinder(Analysis):
|
|
|
69
71
|
return None
|
|
70
72
|
|
|
71
73
|
|
|
72
|
-
from angr.analyses import AnalysesHub
|
|
73
|
-
|
|
74
74
|
AnalysesHub.register_default("CalleeCleanupFinder", CalleeCleanupFinder)
|
|
@@ -9,7 +9,6 @@ import capstone
|
|
|
9
9
|
|
|
10
10
|
from pyvex.stmt import Put
|
|
11
11
|
from pyvex.expr import RdTmp
|
|
12
|
-
from archinfo.arch_arm import is_arm_arch, ArchARMHF
|
|
13
12
|
import ailment
|
|
14
13
|
|
|
15
14
|
from angr.code_location import ExternalCodeLocation
|
|
@@ -35,8 +34,9 @@ from angr.knowledge_plugins.variables.variable_access import VariableAccessSort
|
|
|
35
34
|
from angr.knowledge_plugins.functions import Function
|
|
36
35
|
from angr.utils.constants import DEFAULT_STATEMENT
|
|
37
36
|
from angr import SIM_PROCEDURES
|
|
38
|
-
from .
|
|
39
|
-
from . import
|
|
37
|
+
from angr.analyses import Analysis, register_analysis, ReachingDefinitionsAnalysis
|
|
38
|
+
from angr.analyses.reaching_definitions import get_all_definitions
|
|
39
|
+
from .utils import is_sane_register_variable
|
|
40
40
|
|
|
41
41
|
if TYPE_CHECKING:
|
|
42
42
|
from angr.knowledge_plugins.cfg import CFGModel
|
|
@@ -95,6 +95,8 @@ class CallingConventionAnalysis(Analysis):
|
|
|
95
95
|
callsite_block_addr: int | None = None,
|
|
96
96
|
callsite_insn_addr: int | None = None,
|
|
97
97
|
func_graph: networkx.DiGraph | None = None,
|
|
98
|
+
input_args: list[SimRegArg | SimStackArg] | None = None,
|
|
99
|
+
retval_size: int | None = None,
|
|
98
100
|
):
|
|
99
101
|
if func is not None and not isinstance(func, Function):
|
|
100
102
|
func = self.kb.functions[func]
|
|
@@ -106,6 +108,15 @@ class CallingConventionAnalysis(Analysis):
|
|
|
106
108
|
self.callsite_block_addr = callsite_block_addr
|
|
107
109
|
self.callsite_insn_addr = callsite_insn_addr
|
|
108
110
|
self._func_graph = func_graph
|
|
111
|
+
self._input_args = input_args
|
|
112
|
+
self._retval_size = retval_size
|
|
113
|
+
|
|
114
|
+
if self._retval_size is not None and self._input_args is None:
|
|
115
|
+
# retval size will be ignored if input_args is not specified - user error?
|
|
116
|
+
raise TypeError(
|
|
117
|
+
"input_args must be provided to use retval_size. Otherwise please set both input_args and "
|
|
118
|
+
"retval_size to None."
|
|
119
|
+
)
|
|
109
120
|
|
|
110
121
|
self.cc: SimCC | None = None
|
|
111
122
|
self.prototype: SimTypeFunction | None = None
|
|
@@ -308,9 +319,17 @@ class CallingConventionAnalysis(Analysis):
|
|
|
308
319
|
# we do not analyze SimProcedures or PLT stubs
|
|
309
320
|
return None
|
|
310
321
|
|
|
311
|
-
if
|
|
312
|
-
|
|
313
|
-
|
|
322
|
+
if self._input_args is None:
|
|
323
|
+
if not self._variable_manager.has_function_manager(self._function.addr):
|
|
324
|
+
l.warning("Please run variable recovery on %r before analyzing its calling convention.", self._function)
|
|
325
|
+
return None
|
|
326
|
+
vm = self._variable_manager[self._function.addr]
|
|
327
|
+
retval_size = vm.ret_val_size
|
|
328
|
+
input_variables = vm.input_variables()
|
|
329
|
+
input_args = self._args_from_vars(input_variables, vm)
|
|
330
|
+
else:
|
|
331
|
+
input_args = self._input_args
|
|
332
|
+
retval_size = self._retval_size
|
|
314
333
|
|
|
315
334
|
# check if this function is a variadic function
|
|
316
335
|
if self.project.arch.name == "AMD64":
|
|
@@ -319,11 +338,6 @@ class CallingConventionAnalysis(Analysis):
|
|
|
319
338
|
is_variadic = False
|
|
320
339
|
fixed_args = None
|
|
321
340
|
|
|
322
|
-
vm = self._variable_manager[self._function.addr]
|
|
323
|
-
|
|
324
|
-
input_variables = vm.input_variables()
|
|
325
|
-
input_args = self._args_from_vars(input_variables, vm)
|
|
326
|
-
|
|
327
341
|
# TODO: properly determine sp_delta
|
|
328
342
|
sp_delta = self.project.arch.bytes if self.project.arch.call_pushes_ret else 0
|
|
329
343
|
|
|
@@ -342,7 +356,7 @@ class CallingConventionAnalysis(Analysis):
|
|
|
342
356
|
args = args[:fixed_args]
|
|
343
357
|
|
|
344
358
|
# guess the type of the return value -- it's going to be a wild guess...
|
|
345
|
-
ret_type = self._guess_retval_type(cc,
|
|
359
|
+
ret_type = self._guess_retval_type(cc, retval_size)
|
|
346
360
|
if self._function.name == "main" and self.project.arch.bits == 64 and isinstance(ret_type, SimTypeLongLong):
|
|
347
361
|
# hack - main must return an int even in 64-bit binaries
|
|
348
362
|
ret_type = SimTypeInt()
|
|
@@ -698,14 +712,14 @@ class CallingConventionAnalysis(Analysis):
|
|
|
698
712
|
args.add(arg)
|
|
699
713
|
elif isinstance(variable, SimRegisterVariable):
|
|
700
714
|
# a register variable, convert it to a register argument
|
|
701
|
-
if not self.
|
|
715
|
+
if not is_sane_register_variable(self.project.arch, variable.reg, variable.size, def_cc=def_cc):
|
|
702
716
|
continue
|
|
703
|
-
reg_name = self.project.arch.translate_register_name(variable.reg, size=variable.size)
|
|
704
717
|
if self.project.arch.name in {"AMD64", "X86"} and variable.size < self.project.arch.bytes:
|
|
705
718
|
# use complete registers on AMD64 and X86
|
|
706
719
|
reg_name = self.project.arch.translate_register_name(variable.reg, size=self.project.arch.bytes)
|
|
707
720
|
arg = SimRegArg(reg_name, self.project.arch.bytes)
|
|
708
721
|
else:
|
|
722
|
+
reg_name = self.project.arch.translate_register_name(variable.reg, size=variable.size)
|
|
709
723
|
arg = SimRegArg(reg_name, variable.size)
|
|
710
724
|
args.add(arg)
|
|
711
725
|
|
|
@@ -748,53 +762,6 @@ class CallingConventionAnalysis(Analysis):
|
|
|
748
762
|
|
|
749
763
|
return args.difference(restored_reg_vars)
|
|
750
764
|
|
|
751
|
-
def _is_sane_register_variable(self, variable: SimRegisterVariable, def_cc: SimCC | None = None) -> bool:
|
|
752
|
-
"""
|
|
753
|
-
Filters all registers that are surly not members of function arguments.
|
|
754
|
-
This can be seen as a workaround, since VariableRecoveryFast sometimes gives input variables of cc_ndep (which
|
|
755
|
-
is a VEX-specific register) :-(
|
|
756
|
-
|
|
757
|
-
:param variable: The variable to test.
|
|
758
|
-
:return: True if it is an acceptable function argument, False otherwise.
|
|
759
|
-
:rtype: bool
|
|
760
|
-
"""
|
|
761
|
-
|
|
762
|
-
arch = self.project.arch
|
|
763
|
-
arch_name = arch.name
|
|
764
|
-
if ":" in arch_name:
|
|
765
|
-
# for pcode architectures, we only leave registers that are known to be used as input arguments
|
|
766
|
-
if def_cc is not None:
|
|
767
|
-
return arch.translate_register_name(variable.reg, size=variable.size) in def_cc.ARG_REGS
|
|
768
|
-
return True
|
|
769
|
-
|
|
770
|
-
# VEX
|
|
771
|
-
if arch_name == "AARCH64":
|
|
772
|
-
return 16 <= variable.reg < 80 # x0-x7
|
|
773
|
-
|
|
774
|
-
if arch_name == "AMD64":
|
|
775
|
-
return 24 <= variable.reg < 40 or 64 <= variable.reg < 104 # rcx, rdx # rsi, rdi, r8, r9, r10
|
|
776
|
-
# 224 <= variable.reg < 480) # xmm0-xmm7
|
|
777
|
-
|
|
778
|
-
if is_arm_arch(arch):
|
|
779
|
-
if isinstance(arch, ArchARMHF):
|
|
780
|
-
return 8 <= variable.reg < 24 or 128 <= variable.reg < 160 # r0 - 32 # s0 - s7, or d0 - d4
|
|
781
|
-
return 8 <= variable.reg < 24 # r0-r3
|
|
782
|
-
|
|
783
|
-
if arch_name == "MIPS32":
|
|
784
|
-
return 24 <= variable.reg < 40 # a0-a3
|
|
785
|
-
|
|
786
|
-
if arch_name == "MIPS64":
|
|
787
|
-
return 48 <= variable.reg < 80 or 112 <= variable.reg < 208 # a0-a3 or t4-t7
|
|
788
|
-
|
|
789
|
-
if arch_name == "PPC32":
|
|
790
|
-
return 28 <= variable.reg < 60 # r3-r10
|
|
791
|
-
|
|
792
|
-
if arch_name == "X86":
|
|
793
|
-
return 8 <= variable.reg < 24 or 160 <= variable.reg < 288 # eax, ebx, ecx, edx # xmm0-xmm7
|
|
794
|
-
|
|
795
|
-
l.critical("Unsupported architecture %s.", arch.name)
|
|
796
|
-
return True
|
|
797
|
-
|
|
798
765
|
def _reorder_args(self, args: list[SimRegArg | SimStackArg], cc: SimCC) -> list[SimRegArg | SimStackArg]:
|
|
799
766
|
"""
|
|
800
767
|
Reorder arguments according to the calling convention identified.
|
|
@@ -956,9 +923,10 @@ class CallingConventionAnalysis(Analysis):
|
|
|
956
923
|
if not set(spilled_regs).issubset(set(allowed_spilled_regs)):
|
|
957
924
|
return False, None
|
|
958
925
|
|
|
959
|
-
|
|
960
|
-
if reg in spilled_regs
|
|
961
|
-
|
|
926
|
+
i = next(
|
|
927
|
+
(i for i, reg in enumerate(allowed_spilled_regs) if reg in spilled_regs),
|
|
928
|
+
len(allowed_spilled_regs),
|
|
929
|
+
)
|
|
962
930
|
|
|
963
931
|
return True, i
|
|
964
932
|
|