angr 9.2.135__py3-none-manylinux2014_x86_64.whl → 9.2.137__py3-none-manylinux2014_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.

Files changed (198) hide show
  1. angr/__init__.py +1 -1
  2. angr/analyses/__init__.py +3 -7
  3. angr/analyses/analysis.py +4 -0
  4. angr/analyses/backward_slice.py +1 -2
  5. angr/analyses/binary_optimizer.py +3 -4
  6. angr/analyses/bindiff.py +4 -6
  7. angr/analyses/boyscout.py +1 -3
  8. angr/analyses/callee_cleanup_finder.py +4 -4
  9. angr/analyses/calling_convention/calling_convention.py +6 -4
  10. angr/analyses/calling_convention/fact_collector.py +10 -3
  11. angr/analyses/cdg.py +1 -2
  12. angr/analyses/cfg/cfb.py +1 -3
  13. angr/analyses/cfg/cfg.py +2 -2
  14. angr/analyses/cfg/cfg_base.py +40 -68
  15. angr/analyses/cfg/cfg_emulated.py +1 -104
  16. angr/analyses/cfg/cfg_fast.py +90 -27
  17. angr/analyses/cfg/cfg_fast_soot.py +1 -1
  18. angr/analyses/cfg/indirect_jump_resolvers/__init__.py +2 -0
  19. angr/analyses/cfg/indirect_jump_resolvers/const_resolver.py +46 -10
  20. angr/analyses/cfg/indirect_jump_resolvers/default_resolvers.py +5 -1
  21. angr/analyses/cfg/indirect_jump_resolvers/jumptable.py +65 -14
  22. angr/analyses/cfg/indirect_jump_resolvers/memload_resolver.py +81 -0
  23. angr/analyses/cfg/indirect_jump_resolvers/propagator_utils.py +24 -5
  24. angr/analyses/cfg/indirect_jump_resolvers/x86_pe_iat.py +2 -5
  25. angr/analyses/class_identifier.py +1 -2
  26. angr/analyses/complete_calling_conventions.py +3 -0
  27. angr/analyses/congruency_check.py +2 -3
  28. angr/analyses/data_dep/data_dependency_analysis.py +2 -2
  29. angr/analyses/ddg.py +1 -4
  30. angr/analyses/decompiler/ail_simplifier.py +15 -5
  31. angr/analyses/decompiler/block_simplifier.py +2 -2
  32. angr/analyses/decompiler/ccall_rewriters/__init__.py +2 -0
  33. angr/analyses/decompiler/ccall_rewriters/amd64_ccalls.py +1 -1
  34. angr/analyses/decompiler/ccall_rewriters/x86_ccalls.py +69 -0
  35. angr/analyses/decompiler/clinic.py +119 -72
  36. angr/analyses/decompiler/condition_processor.py +2 -0
  37. angr/analyses/decompiler/decompiler.py +1 -0
  38. angr/analyses/decompiler/dephication/dephication_base.py +2 -0
  39. angr/analyses/decompiler/dephication/rewriting_engine.py +8 -6
  40. angr/analyses/decompiler/dephication/seqnode_dephication.py +10 -1
  41. angr/analyses/decompiler/optimization_passes/duplication_reverter/ail_merge_graph.py +2 -2
  42. angr/analyses/decompiler/optimization_passes/duplication_reverter/duplication_reverter.py +2 -2
  43. angr/analyses/decompiler/optimization_passes/ite_region_converter.py +1 -1
  44. angr/analyses/decompiler/optimization_passes/lowered_switch_simplifier.py +1 -1
  45. angr/analyses/decompiler/optimization_passes/return_duplicator_base.py +1 -2
  46. angr/analyses/decompiler/optimization_passes/stack_canary_simplifier.py +1 -1
  47. angr/analyses/decompiler/sequence_walker.py +6 -2
  48. angr/analyses/decompiler/ssailification/rewriting.py +11 -1
  49. angr/analyses/decompiler/ssailification/rewriting_engine.py +56 -19
  50. angr/analyses/decompiler/ssailification/ssailification.py +13 -3
  51. angr/analyses/decompiler/ssailification/traversal.py +28 -2
  52. angr/analyses/decompiler/ssailification/traversal_state.py +6 -1
  53. angr/analyses/decompiler/structured_codegen/c.py +44 -21
  54. angr/analyses/decompiler/structuring/phoenix.py +118 -15
  55. angr/analyses/decompiler/utils.py +113 -8
  56. angr/analyses/disassembly.py +5 -5
  57. angr/analyses/fcp/__init__.py +4 -0
  58. angr/analyses/fcp/fcp.py +429 -0
  59. angr/analyses/identifier/identify.py +1 -3
  60. angr/analyses/loopfinder.py +4 -3
  61. angr/analyses/patchfinder.py +1 -1
  62. angr/analyses/propagator/engine_base.py +4 -3
  63. angr/analyses/propagator/propagator.py +14 -53
  64. angr/analyses/reaching_definitions/function_handler.py +1 -1
  65. angr/analyses/reassembler.py +1 -2
  66. angr/analyses/s_liveness.py +5 -1
  67. angr/analyses/s_propagator.py +26 -7
  68. angr/analyses/s_reaching_definitions/s_rda_model.py +2 -1
  69. angr/analyses/s_reaching_definitions/s_rda_view.py +20 -1
  70. angr/analyses/s_reaching_definitions/s_reaching_definitions.py +11 -1
  71. angr/analyses/soot_class_hierarchy.py +1 -2
  72. angr/analyses/stack_pointer_tracker.py +29 -3
  73. angr/analyses/static_hooker.py +1 -2
  74. angr/analyses/typehoon/simple_solver.py +2 -2
  75. angr/analyses/variable_recovery/engine_ail.py +19 -7
  76. angr/analyses/variable_recovery/engine_base.py +16 -14
  77. angr/analyses/variable_recovery/engine_vex.py +2 -2
  78. angr/analyses/variable_recovery/variable_recovery_fast.py +23 -3
  79. angr/analyses/veritesting.py +4 -7
  80. angr/analyses/vfg.py +1 -1
  81. angr/analyses/vsa_ddg.py +1 -2
  82. angr/block.py +62 -22
  83. angr/callable.py +1 -3
  84. angr/calling_conventions.py +3 -3
  85. angr/codenode.py +5 -1
  86. angr/concretization_strategies/__init__.py +1 -83
  87. angr/concretization_strategies/any.py +2 -1
  88. angr/concretization_strategies/any_named.py +1 -1
  89. angr/concretization_strategies/base.py +81 -0
  90. angr/concretization_strategies/controlled_data.py +2 -1
  91. angr/concretization_strategies/eval.py +2 -1
  92. angr/concretization_strategies/logging.py +3 -1
  93. angr/concretization_strategies/max.py +2 -1
  94. angr/concretization_strategies/nonzero.py +2 -1
  95. angr/concretization_strategies/nonzero_range.py +2 -1
  96. angr/concretization_strategies/norepeats.py +2 -1
  97. angr/concretization_strategies/norepeats_range.py +2 -1
  98. angr/concretization_strategies/range.py +2 -1
  99. angr/concretization_strategies/signed_add.py +2 -1
  100. angr/concretization_strategies/single.py +2 -1
  101. angr/concretization_strategies/solutions.py +2 -1
  102. angr/concretization_strategies/unlimited_range.py +2 -1
  103. angr/engines/__init__.py +8 -5
  104. angr/engines/engine.py +3 -5
  105. angr/engines/failure.py +4 -5
  106. angr/engines/pcode/emulate.py +1 -1
  107. angr/engines/pcode/lifter.py +31 -18
  108. angr/engines/procedure.py +5 -7
  109. angr/engines/soot/expressions/__init__.py +20 -23
  110. angr/engines/soot/expressions/base.py +4 -4
  111. angr/engines/soot/expressions/invoke.py +1 -2
  112. angr/engines/soot/statements/__init__.py +10 -12
  113. angr/engines/soot/values/__init__.py +10 -12
  114. angr/engines/soot/values/arrayref.py +3 -3
  115. angr/engines/soot/values/instancefieldref.py +3 -2
  116. angr/engines/successors.py +18 -12
  117. angr/engines/syscall.py +4 -6
  118. angr/engines/unicorn.py +3 -2
  119. angr/engines/vex/claripy/ccall.py +8 -10
  120. angr/engines/vex/claripy/datalayer.py +4 -5
  121. angr/engines/vex/lifter.py +9 -6
  122. angr/exploration_techniques/__init__.py +0 -2
  123. angr/exploration_techniques/spiller.py +1 -3
  124. angr/exploration_techniques/stochastic.py +2 -3
  125. angr/factory.py +3 -9
  126. angr/flirt/build_sig.py +8 -15
  127. angr/knowledge_plugins/cfg/cfg_model.py +20 -17
  128. angr/knowledge_plugins/functions/function.py +70 -79
  129. angr/knowledge_plugins/functions/function_manager.py +8 -7
  130. angr/knowledge_plugins/functions/function_parser.py +1 -1
  131. angr/knowledge_plugins/functions/soot_function.py +21 -24
  132. angr/knowledge_plugins/propagations/propagation_model.py +4 -5
  133. angr/knowledge_plugins/propagations/states.py +0 -511
  134. angr/knowledge_plugins/variables/variable_manager.py +16 -10
  135. angr/procedures/libc/memcpy.py +4 -4
  136. angr/procedures/procedure_dict.py +3 -2
  137. angr/protos/__init__.py +2 -5
  138. angr/protos/cfg_pb2.py +21 -18
  139. angr/protos/function_pb2.py +17 -14
  140. angr/protos/primitives_pb2.py +44 -39
  141. angr/protos/variables_pb2.py +36 -31
  142. angr/protos/xrefs_pb2.py +15 -12
  143. angr/sim_procedure.py +15 -16
  144. angr/sim_variable.py +13 -1
  145. angr/simos/__init__.py +2 -0
  146. angr/simos/javavm.py +4 -6
  147. angr/simos/xbox.py +32 -0
  148. angr/state_plugins/__init__.py +0 -2
  149. angr/state_plugins/callstack.py +4 -4
  150. angr/state_plugins/cgc.py +3 -2
  151. angr/state_plugins/gdb.py +6 -5
  152. angr/state_plugins/globals.py +1 -2
  153. angr/state_plugins/heap/heap_brk.py +1 -2
  154. angr/state_plugins/history.py +10 -12
  155. angr/state_plugins/inspect.py +3 -5
  156. angr/state_plugins/libc.py +2 -2
  157. angr/state_plugins/log.py +8 -10
  158. angr/state_plugins/loop_data.py +1 -2
  159. angr/state_plugins/posix.py +7 -7
  160. angr/state_plugins/preconstrainer.py +2 -3
  161. angr/state_plugins/scratch.py +5 -8
  162. angr/state_plugins/sim_action.py +3 -3
  163. angr/state_plugins/solver.py +8 -3
  164. angr/state_plugins/symbolizer.py +5 -4
  165. angr/state_plugins/uc_manager.py +3 -3
  166. angr/state_plugins/unicorn_engine.py +5 -1
  167. angr/state_plugins/view.py +3 -5
  168. angr/storage/file.py +3 -5
  169. angr/storage/memory_mixins/address_concretization_mixin.py +2 -2
  170. angr/storage/memory_mixins/bvv_conversion_mixin.py +3 -3
  171. angr/storage/memory_mixins/clouseau_mixin.py +1 -3
  172. angr/storage/memory_mixins/name_resolution_mixin.py +1 -3
  173. angr/storage/memory_mixins/paged_memory/paged_memory_mixin.py +13 -15
  174. angr/storage/memory_mixins/paged_memory/pages/__init__.py +1 -22
  175. angr/storage/memory_mixins/paged_memory/pages/base.py +31 -0
  176. angr/storage/memory_mixins/paged_memory/pages/list_page.py +1 -1
  177. angr/storage/memory_mixins/paged_memory/pages/mv_list_page.py +1 -1
  178. angr/storage/memory_mixins/paged_memory/pages/ultra_page.py +2 -4
  179. angr/storage/memory_mixins/paged_memory/privileged_mixin.py +3 -4
  180. angr/storage/memory_mixins/regioned_memory/abstract_merger_mixin.py +4 -2
  181. angr/storage/memory_mixins/smart_find_mixin.py +1 -1
  182. angr/storage/memory_mixins/underconstrained_mixin.py +1 -1
  183. angr/storage/memory_mixins/unwrapper_mixin.py +1 -3
  184. angr/utils/enums_conv.py +28 -12
  185. angr/utils/segment_list.py +25 -22
  186. angr/utils/timing.py +18 -1
  187. angr/vaults.py +5 -6
  188. {angr-9.2.135.dist-info → angr-9.2.137.dist-info}/METADATA +7 -7
  189. {angr-9.2.135.dist-info → angr-9.2.137.dist-info}/RECORD +193 -191
  190. {angr-9.2.135.dist-info → angr-9.2.137.dist-info}/WHEEL +1 -1
  191. angr/analyses/propagator/outdated_definition_walker.py +0 -159
  192. angr/analyses/propagator/tmpvar_finder.py +0 -18
  193. angr/engines/concrete.py +0 -180
  194. angr/exploration_techniques/symbion.py +0 -80
  195. angr/state_plugins/concrete.py +0 -295
  196. {angr-9.2.135.dist-info → angr-9.2.137.dist-info}/LICENSE +0 -0
  197. {angr-9.2.135.dist-info → angr-9.2.137.dist-info}/entry_points.txt +0 -0
  198. {angr-9.2.135.dist-info → angr-9.2.137.dist-info}/top_level.txt +0 -0
angr/engines/failure.py CHANGED
@@ -1,9 +1,11 @@
1
1
  from __future__ import annotations
2
- from .engine import SuccessorsMixin
3
- from .procedure import ProcedureMixin
4
2
 
5
3
  import logging
6
4
 
5
+ from angr.errors import AngrExitError
6
+ from .engine import SuccessorsMixin
7
+ from .procedure import ProcedureMixin
8
+
7
9
  l = logging.getLogger(name=__name__)
8
10
 
9
11
 
@@ -23,6 +25,3 @@ class SimEngineFailure(SuccessorsMixin, ProcedureMixin):
23
25
  return self.process_procedure(state, successors, terminator, **kwargs)
24
26
 
25
27
  return super().process_successors(successors, **kwargs)
26
-
27
-
28
- from angr.errors import AngrExitError
@@ -92,7 +92,7 @@ class PcodeEmulatorMixin(SimEngineBase):
92
92
  self.state,
93
93
  fallthru_addr,
94
94
  self.state.scratch.guard,
95
- "Ijk_Boring",
95
+ irsb.jumpkind,
96
96
  exit_stmt_idx=DEFAULT_STATEMENT,
97
97
  exit_ins_addr=self.state.scratch.ins_addr,
98
98
  )
@@ -7,7 +7,7 @@
7
7
  from __future__ import annotations
8
8
 
9
9
  import logging
10
- from typing import Optional
10
+ from typing import Any, TYPE_CHECKING
11
11
  from collections.abc import Iterable, Sequence
12
12
 
13
13
  import archinfo
@@ -35,6 +35,12 @@ except ImportError:
35
35
  pypcode = None
36
36
 
37
37
 
38
+ if TYPE_CHECKING:
39
+ # this is to make pyright happy; otherwise it believes pypcode is None
40
+ import pypcode
41
+ from pypcode import PcodeOp, Context
42
+
43
+
38
44
  l = logging.getLogger(__name__)
39
45
 
40
46
  IRSB_MAX_SIZE = 400
@@ -130,8 +136,8 @@ class IRSB:
130
136
 
131
137
  _direct_next: bool | None
132
138
  _exit_statements: Sequence[tuple[int, int, ExitStatement]]
133
- _instruction_addresses: Sequence[int] | None
134
- _ops: Sequence[pypcode.PcodeOp] # FIXME: Merge into _statements
139
+ _instruction_addresses: list[int] | None
140
+ _ops: list[PcodeOp] # FIXME: Merge into _statements
135
141
  _size: int | None
136
142
  _statements: Iterable # Note: currently unused
137
143
  _disassembly: PcodeDisassemblerBlock | None
@@ -140,7 +146,7 @@ class IRSB:
140
146
  behaviors: BehaviorFactory | None
141
147
  data_refs: Sequence # Note: currently unused
142
148
  const_vals: Sequence # Note: currently unused
143
- default_exit_target: Optional # Note: currently used
149
+ default_exit_target: Any # Note: currently used
144
150
  jumpkind: str | None
145
151
  next: int | None
146
152
 
@@ -199,7 +205,7 @@ class IRSB:
199
205
  self._direct_next = None
200
206
  self._exit_statements = []
201
207
  self._instruction_addresses = None
202
- self._ops = []
208
+ self._ops: list[PcodeOp] = []
203
209
  self._size = None
204
210
  self._statements = []
205
211
  self.addr = mem_addr
@@ -248,7 +254,7 @@ class IRSB:
248
254
 
249
255
  @property
250
256
  def has_statements(self) -> bool:
251
- return self.statements is not None and self.statements
257
+ return bool(self.statements is not None and self.statements)
252
258
 
253
259
  @property
254
260
  def exit_statements(self) -> Sequence[tuple[int, int, ExitStatement]]:
@@ -320,7 +326,7 @@ class IRSB:
320
326
  return len(self.statements)
321
327
 
322
328
  @property
323
- def offsIP(self) -> int:
329
+ def offsIP(self) -> int | None:
324
330
  return self.arch.ip_offset
325
331
 
326
332
  @property
@@ -459,10 +465,10 @@ class IRSB:
459
465
  jumpkind: str | None = None,
460
466
  direct_next: bool | None = None,
461
467
  size: int | None = None,
462
- ops: Sequence[pypcode.PcodeOp] | None = None,
463
- instruction_addresses: Iterable[int] | None = None,
468
+ ops: list[PcodeOp] | None = None,
469
+ instruction_addresses: list[int] | None = None,
464
470
  exit_statements: Sequence[tuple[int, int, ExitStatement]] | None = None,
465
- default_exit_target: Optional | None = None,
471
+ default_exit_target: Any = None,
466
472
  ) -> None:
467
473
  # pylint: disable=unused-argument
468
474
  self._statements = statements if statements is not None else []
@@ -490,7 +496,7 @@ class IRSB:
490
496
  )
491
497
 
492
498
  @property
493
- def statements(self) -> Iterable:
499
+ def statements(self) -> list:
494
500
  # FIXME: For compatibility, may want to implement Ist_IMark and
495
501
  # pyvex.IRStmt.Exit to ease analyses.
496
502
  l.debug("Returning empty statements list!")
@@ -807,7 +813,7 @@ class PcodeBasicBlockLifter:
807
813
  Lifts basic blocks to P-code
808
814
  """
809
815
 
810
- context: pypcode.Context
816
+ context: Context
811
817
  behaviors: BehaviorFactory
812
818
 
813
819
  def __init__(self, arch: archinfo.Arch):
@@ -1032,7 +1038,7 @@ class PcodeLifterEngineMixin(SimEngineBase):
1032
1038
  self,
1033
1039
  addr: int | None = None,
1034
1040
  state: SimState | None = None,
1035
- clemory: cle.Clemory | None = None,
1041
+ clemory: cle.Clemory | cle.ClemoryReadOnlyView | None = None,
1036
1042
  insn_bytes: bytes | None = None,
1037
1043
  arch: archinfo.Arch | None = None,
1038
1044
  size: int | None = None,
@@ -1047,7 +1053,7 @@ class PcodeLifterEngineMixin(SimEngineBase):
1047
1053
  load_from_ro_regions: bool = False,
1048
1054
  cross_insn_opt: bool | None = None,
1049
1055
  const_prop: bool | None = None,
1050
- ):
1056
+ ) -> IRSB:
1051
1057
  """
1052
1058
  Temporary compatibility interface for integration with block code.
1053
1059
  """
@@ -1075,7 +1081,7 @@ class PcodeLifterEngineMixin(SimEngineBase):
1075
1081
  self,
1076
1082
  addr: int | None = None,
1077
1083
  state: SimState | None = None,
1078
- clemory: cle.Clemory | None = None,
1084
+ clemory: cle.Clemory | cle.ClemoryReadOnlyView | None = None,
1079
1085
  insn_bytes: bytes | None = None,
1080
1086
  arch: archinfo.Arch | None = None,
1081
1087
  size: int | None = None,
@@ -1090,7 +1096,7 @@ class PcodeLifterEngineMixin(SimEngineBase):
1090
1096
  load_from_ro_regions: bool = False,
1091
1097
  cross_insn_opt: bool | None = None,
1092
1098
  const_prop: bool | None = None,
1093
- ):
1099
+ ) -> IRSB:
1094
1100
  """
1095
1101
  Lift an IRSB.
1096
1102
 
@@ -1137,6 +1143,7 @@ class PcodeLifterEngineMixin(SimEngineBase):
1137
1143
 
1138
1144
  # phase 1: parameter defaults
1139
1145
  if addr is None:
1146
+ assert state is not None
1140
1147
  addr = state.solver.eval(state._ip)
1141
1148
  if size is not None:
1142
1149
  size = min(size, IRSB_MAX_SIZE)
@@ -1158,6 +1165,7 @@ class PcodeLifterEngineMixin(SimEngineBase):
1158
1165
  " disabled."
1159
1166
  )
1160
1167
  opt_level = 0
1168
+ assert state is not None
1161
1169
  if state and o.OPTIMIZE_IR in state.options:
1162
1170
  state.options.remove(o.OPTIMIZE_IR)
1163
1171
  if skip_stmts is not True:
@@ -1278,13 +1286,18 @@ class PcodeLifterEngineMixin(SimEngineBase):
1278
1286
  )
1279
1287
  return irsb
1280
1288
 
1289
+ raise SimEngineError("Unreachable code reached")
1281
1290
  # phase x: error handling
1282
1291
  except PyVEXError as e:
1283
1292
  l.debug("Translation error at %#x", addr)
1284
1293
  raise SimTranslationError("Unable to translate bytecode") from e
1285
1294
 
1286
1295
  def _load_bytes(
1287
- self, addr: int, max_size: int, state: SimState | None = None, clemory: cle.Clemory | None = None
1296
+ self,
1297
+ addr: int,
1298
+ max_size: int,
1299
+ state: SimState | None = None,
1300
+ clemory: cle.Clemory | cle.ClemoryReadOnlyView | None = None,
1288
1301
  ) -> tuple[bytes, int, int]:
1289
1302
  if clemory is None and state is None:
1290
1303
  raise SimEngineError("state and clemory cannot both be None in _load_bytes().")
@@ -1306,7 +1319,7 @@ class PcodeLifterEngineMixin(SimEngineBase):
1306
1319
 
1307
1320
  # Load from the clemory if we can
1308
1321
  if not load_from_state or not state:
1309
- if isinstance(clemory, cle.Clemory):
1322
+ if isinstance(clemory, (cle.Clemory, cle.ClemoryReadOnlyView)):
1310
1323
  try:
1311
1324
  start, backer = next(clemory.backers(addr))
1312
1325
  except StopIteration:
angr/engines/procedure.py CHANGED
@@ -1,10 +1,13 @@
1
1
  from __future__ import annotations
2
2
  import logging
3
3
 
4
- l = logging.getLogger(name=__name__)
5
-
4
+ from angr import sim_options as o
5
+ from angr import errors
6
+ from angr.state_plugins.inspect import BP_BEFORE, BP_AFTER
6
7
  from .engine import SuccessorsMixin
7
8
 
9
+
10
+ l = logging.getLogger(name=__name__)
8
11
  # pylint: disable=arguments-differ
9
12
 
10
13
 
@@ -65,8 +68,3 @@ class ProcedureEngine(ProcedureMixin, SuccessorsMixin):
65
68
  if procedure is None:
66
69
  raise errors.SimEngineError("Must provide the procedure explicitly to use ProcedureEngine")
67
70
  self.process_procedure(self.state, successors, procedure, **kwargs)
68
-
69
-
70
- from angr import sim_options as o
71
- from angr import errors
72
- from angr.state_plugins.inspect import BP_BEFORE, BP_AFTER
@@ -2,29 +2,6 @@ from __future__ import annotations
2
2
 
3
3
  import logging
4
4
 
5
- l = logging.getLogger("angr.engines.soot.expressions")
6
-
7
-
8
- def translate_expr(expr, state):
9
- expr_name = expr.__class__.__name__.split(".")[-1]
10
- if expr_name.startswith("Soot"):
11
- expr_name = expr_name[4:]
12
- if expr_name.endswith("Expr"):
13
- expr_name = expr_name[:-4]
14
- expr_cls_name = "SimSootExpr_" + expr_name
15
-
16
- g = globals()
17
- if expr_cls_name in g:
18
- expr_cls = g[expr_cls_name]
19
- else:
20
- l.warning("Unsupported Soot expression %s.", expr_cls_name)
21
- expr_cls = SimSootExpr_Unsupported
22
-
23
- expr = expr_cls(expr, state)
24
- expr.process()
25
- return expr
26
-
27
-
28
5
  from .arrayref import SimSootExpr_ArrayRef
29
6
  from .binop import SimSootExpr_Binop
30
7
  from .cast import SimSootExpr_Cast
@@ -57,6 +34,26 @@ from .paramref import SimSootExpr_ParamRef
57
34
  from .unsupported import SimSootExpr_Unsupported
58
35
  from .instanceOf import SimSootExpr_InstanceOf
59
36
 
37
+ l = logging.getLogger("angr.engines.soot.expressions")
38
+
39
+
40
+ def translate_expr(expr, state):
41
+ expr_name = expr.__class__.__name__.split(".")[-1]
42
+ expr_name = expr_name.removeprefix("Soot")
43
+ expr_name = expr_name.removesuffix("Expr")
44
+ expr_cls_name = "SimSootExpr_" + expr_name
45
+
46
+ g = globals()
47
+ if expr_cls_name in g:
48
+ expr_cls = g[expr_cls_name]
49
+ else:
50
+ l.warning("Unsupported Soot expression %s.", expr_cls_name)
51
+ expr_cls = SimSootExpr_Unsupported
52
+
53
+ expr = expr_cls(expr, state)
54
+ expr.process()
55
+ return expr
56
+
60
57
 
61
58
  __all__ = (
62
59
  "SimSootExpr_ArrayRef",
@@ -1,6 +1,6 @@
1
1
  from __future__ import annotations
2
- from . import translate_expr
3
- from angr.engines.soot.values import translate_value
2
+
3
+ import angr
4
4
 
5
5
 
6
6
  class SimSootExpr:
@@ -15,7 +15,7 @@ class SimSootExpr:
15
15
  raise NotImplementedError
16
16
 
17
17
  def _translate_expr(self, expr):
18
- return translate_expr(expr, self.state)
18
+ return angr.engines.soot.expressions.translate_expr(expr, self.state)
19
19
 
20
20
  def _translate_value(self, value):
21
- return translate_value(value, self.state)
21
+ return angr.engines.soot.values.translate_value(value, self.state)
@@ -1,7 +1,6 @@
1
1
  from __future__ import annotations
2
2
  from archinfo.arch_soot import SootArgument, SootMethodDescriptor
3
3
 
4
- from . import translate_expr
5
4
  from angr.engines.soot.method_dispatcher import resolve_method
6
5
  from angr.engines.soot.exceptions import SootMethodNotLoadedException
7
6
  from .base import SimSootExpr
@@ -56,7 +55,7 @@ class SimSootExpr_VirtualInvoke(InvokeBase):
56
55
 
57
56
  def _resolve_invoke_target(self, expr, state):
58
57
  # get the type of the base object
59
- base = translate_expr(self.expr.base, self.state).expr
58
+ base = self._translate_expr(self.expr.base).expr
60
59
  # if the base is not set, for example if we process an invocation of an
61
60
  # unloaded library function
62
61
  # => fallback: use the statically retrieved type
@@ -2,13 +2,21 @@ from __future__ import annotations
2
2
 
3
3
  import logging
4
4
 
5
+ from .assign import SimSootStmt_Assign
6
+ from .return_ import SimSootStmt_Return, SimSootStmt_ReturnVoid
7
+ from .identity import SimSootStmt_Identity
8
+ from .goto import SimSootStmt_Goto
9
+ from .invoke import SimSootStmt_Invoke
10
+ from .if_ import SimSootStmt_If
11
+ from .switch import SimSootStmt_TableSwitch, SimSootStmt_LookupSwitch
12
+ from .throw import SimSootStmt_Throw
13
+
5
14
  l = logging.getLogger("angr.engines.soot.statements")
6
15
 
7
16
 
8
17
  def translate_stmt(stmt, state):
9
18
  stmt_name = stmt.__class__.__name__.split(".")[-1]
10
- if stmt_name.endswith("Stmt"):
11
- stmt_name = stmt_name[:-4]
19
+ stmt_name = stmt_name.removesuffix("Stmt")
12
20
 
13
21
  stmt_cls_name = f"SimSootStmt_{stmt_name}"
14
22
  if stmt_cls_name in globals():
@@ -21,16 +29,6 @@ def translate_stmt(stmt, state):
21
29
  return None
22
30
 
23
31
 
24
- from .assign import SimSootStmt_Assign
25
- from .return_ import SimSootStmt_Return, SimSootStmt_ReturnVoid
26
- from .identity import SimSootStmt_Identity
27
- from .goto import SimSootStmt_Goto
28
- from .invoke import SimSootStmt_Invoke
29
- from .if_ import SimSootStmt_If
30
- from .switch import SimSootStmt_TableSwitch, SimSootStmt_LookupSwitch
31
- from .throw import SimSootStmt_Throw
32
-
33
-
34
32
  __all__ = (
35
33
  "SimSootStmt_Assign",
36
34
  "SimSootStmt_Goto",
@@ -1,10 +1,18 @@
1
1
  from __future__ import annotations
2
2
 
3
+ from .local import SimSootValue_Local
4
+ from .paramref import SimSootValue_ParamRef
5
+ from .arrayref import SimSootValue_ArrayRef, SimSootValue_ArrayBaseRef
6
+ from .thisref import SimSootValue_ThisRef
7
+ from .staticfieldref import SimSootValue_StaticFieldRef
8
+ from .instancefieldref import SimSootValue_InstanceFieldRef
9
+ from .constants import SimSootValue_IntConstant
10
+ from .strref import SimSootValue_StringRef
11
+
3
12
 
4
13
  def translate_value(value, state):
5
14
  value_name = value.__class__.__name__
6
- if value_name.startswith("Soot"):
7
- value_name = value_name[4:]
15
+ value_name = value_name.removeprefix("Soot")
8
16
  value_cls_name = "SimSootValue_" + value_name
9
17
 
10
18
  g = globals()
@@ -16,16 +24,6 @@ def translate_value(value, state):
16
24
  return value_cls.from_sootvalue(value, state)
17
25
 
18
26
 
19
- from .local import SimSootValue_Local
20
- from .paramref import SimSootValue_ParamRef
21
- from .arrayref import SimSootValue_ArrayRef, SimSootValue_ArrayBaseRef
22
- from .thisref import SimSootValue_ThisRef
23
- from .staticfieldref import SimSootValue_StaticFieldRef
24
- from .instancefieldref import SimSootValue_InstanceFieldRef
25
- from .constants import SimSootValue_IntConstant
26
- from .strref import SimSootValue_StringRef
27
-
28
-
29
27
  __all__ = (
30
28
  "SimSootValue_ArrayBaseRef",
31
29
  "SimSootValue_ArrayRef",
@@ -3,7 +3,7 @@ import logging
3
3
 
4
4
  import claripy
5
5
 
6
- from . import translate_value
6
+ import angr
7
7
  from angr.errors import SimEngineError
8
8
  from .base import SimSootValue
9
9
  from .constants import SimSootValue_IntConstant
@@ -60,7 +60,7 @@ class SimSootValue_ArrayRef(SimSootValue):
60
60
 
61
61
  @classmethod
62
62
  def from_sootvalue(cls, soot_value, state):
63
- base_local = translate_value(soot_value.base, state)
63
+ base_local = angr.engines.soot.values.translate_value(soot_value.base, state)
64
64
  base = state.memory.load(base_local)
65
65
  idx = cls.translate_array_index(soot_value.index, state)
66
66
  cls.check_array_bounds(idx, base, state)
@@ -68,7 +68,7 @@ class SimSootValue_ArrayRef(SimSootValue):
68
68
 
69
69
  @staticmethod
70
70
  def translate_array_index(idx, state):
71
- idx_value = translate_value(idx, state)
71
+ idx_value = angr.engines.soot.values.translate_value(idx, state)
72
72
  if isinstance(idx_value, SimSootValue_IntConstant):
73
73
  # idx is a constant
74
74
  return idx_value.value
@@ -1,5 +1,6 @@
1
1
  from __future__ import annotations
2
- from . import translate_value
2
+
3
+ import angr
3
4
  from .base import SimSootValue
4
5
  from angr.engines.soot.field_dispatcher import resolve_field
5
6
 
@@ -25,7 +26,7 @@ class SimSootValue_InstanceFieldRef(SimSootValue):
25
26
  field_name, field_class_name = soot_value.field
26
27
  field_type = soot_value.type
27
28
  # get heap allocation id from base object
28
- fixed_base = translate_value(soot_value.base, state)
29
+ fixed_base = angr.engines.soot.values.translate_value(soot_value.base, state)
29
30
  field_ref_base = state.memory.load(fixed_base)
30
31
  obj_alloc_id = field_ref_base.heap_alloc_id
31
32
  # return field reference
@@ -6,6 +6,13 @@ import claripy
6
6
 
7
7
  from archinfo.arch_soot import ArchSoot, SootAddressDescriptor
8
8
 
9
+ from angr import sim_options as o
10
+ from angr.errors import SimSolverModeError, AngrUnsupportedSyscallError, AngrSyscallError, SimValueError, SimUnsatError
11
+ from angr.storage import DUMMY_SYMBOLIC_READ_VALUE
12
+ from angr.state_plugins.inspect import BP_BEFORE, BP_AFTER
13
+ from angr.state_plugins.callstack import CallStack
14
+ from angr.state_plugins.sim_action_object import _raw_ast
15
+
9
16
 
10
17
  if TYPE_CHECKING:
11
18
  from angr import SimState
@@ -262,11 +269,11 @@ class SimSuccessors:
262
269
  # categorize the state
263
270
  if o.APPROXIMATE_GUARDS in state.options and state.solver.is_false(state.scratch.guard, exact=False):
264
271
  if o.VALIDATE_APPROXIMATIONS in state.options and state.satisfiable():
265
- raise Exception("WTF")
272
+ raise AssertionError("WTF")
266
273
  self.unsat_successors.append(state)
267
274
  elif o.APPROXIMATE_SATISFIABILITY in state.options and not state.solver.satisfiable(exact=False):
268
275
  if o.VALIDATE_APPROXIMATIONS in state.options and state.solver.satisfiable():
269
- raise Exception("WTF")
276
+ raise AssertionError("WTF")
270
277
  self.unsat_successors.append(state)
271
278
  elif (not state.scratch.guard.symbolic and state.solver.is_false(state.scratch.guard)) or (
272
279
  o.LAZY_SOLVES not in state.options and not state.satisfiable()
@@ -288,10 +295,15 @@ class SimSuccessors:
288
295
  # syscall
289
296
  self.successors.append(state)
290
297
 
291
- # Misuse the ip_at_syscall register to save the return address for this syscall
292
- # state.ip *might be* changed to be the real address of syscall SimProcedures by syscall handling code in
293
- # angr
294
- state.regs.ip_at_syscall = state.ip
298
+ if "ip_at_syscall" in state.arch.registers:
299
+ # Misuse the ip_at_syscall register to save the return address for this syscall
300
+ # state.ip *might be* changed to be the real address
301
+ # of syscall SimProcedures by syscall handling code in angr
302
+ state.regs.ip_at_syscall = state.ip
303
+ else:
304
+ # The architecture doesn't have an ip_at_syscall register.
305
+ # Nothing to do but hope vigorously.
306
+ l.warning(f"Handling syscall on arch {state.arch.name:s} without ip_at_syscall register")
295
307
 
296
308
  try:
297
309
  symbolic_syscall_num, concrete_syscall_nums = self._resolve_syscall(state)
@@ -533,10 +545,4 @@ class SimSuccessors:
533
545
 
534
546
 
535
547
  # pylint: disable=wrong-import-position
536
- from angr.state_plugins.inspect import BP_BEFORE, BP_AFTER
537
- from angr.errors import SimSolverModeError, AngrUnsupportedSyscallError, AngrSyscallError, SimValueError, SimUnsatError
538
548
  from angr.calling_conventions import SYSCALL_CC
539
- from angr.state_plugins.sim_action_object import _raw_ast
540
- from angr.state_plugins.callstack import CallStack
541
- from angr.storage import DUMMY_SYMBOLIC_READ_VALUE
542
- from angr import sim_options as o
angr/engines/syscall.py CHANGED
@@ -1,12 +1,13 @@
1
1
  from __future__ import annotations
2
- import angr
3
2
  import logging
4
3
 
5
- l = logging.getLogger(name=__name__)
6
-
4
+ import angr
5
+ from angr.errors import AngrUnsupportedSyscallError
7
6
  from .engine import SuccessorsMixin
8
7
  from .procedure import ProcedureMixin
9
8
 
9
+ l = logging.getLogger(name=__name__)
10
+
10
11
 
11
12
  # pylint:disable=abstract-method,arguments-differ
12
13
  class SimEngineSyscall(SuccessorsMixin, ProcedureMixin):
@@ -48,6 +49,3 @@ class SimEngineSyscall(SuccessorsMixin, ProcedureMixin):
48
49
  sys_procedure = angr.SIM_PROCEDURES["stubs"]["syscall"](cc=cc)
49
50
 
50
51
  return self.process_procedure(state, successors, sys_procedure, **kwargs)
51
-
52
-
53
- from angr.errors import AngrUnsupportedSyscallError
angr/engines/unicorn.py CHANGED
@@ -6,6 +6,7 @@ import logging
6
6
  import archinfo
7
7
  import claripy
8
8
 
9
+ import angr
9
10
  from angr.errors import SimIRSBError, SimIRSBNoDecodeError, SimValueError
10
11
  from .engine import SuccessorsMixin
11
12
  from .vex.heavy.heavy import VEXEarlyExit
@@ -30,8 +31,8 @@ class SimEngineUnicorn(SuccessorsMixin):
30
31
  - extra_stop_points: A collection of addresses at which execution should halt
31
32
  """
32
33
 
33
- def __init__(self, *args, **kwargs):
34
- super().__init__(*args, **kwargs)
34
+ def __init__(self, project: angr.Project):
35
+ super().__init__(project)
35
36
  # Cache of details of basic blocks containing statements that need to re-executed
36
37
  self._block_details_cache = {}
37
38
  # Addresses of basic blocks which native interface will not execute
@@ -3,8 +3,11 @@ import logging
3
3
 
4
4
  import claripy
5
5
  from archinfo.arch_arm import is_arm_arch
6
- from angr.state_plugins.sim_action_object import _raw_ast, SimActionObject
6
+
7
7
  from angr import errors
8
+ from angr.errors import SimError, SimCCallError
9
+ from angr.sim_options import USE_SIMPLIFIED_CCALLS
10
+ from angr.state_plugins.sim_action_object import _raw_ast, SimActionObject
8
11
 
9
12
  l = logging.getLogger(name=__name__)
10
13
 
@@ -2020,11 +2023,10 @@ def _get_flags(state) -> claripy.ast.bv.BV:
2020
2023
  except CCallMultivaluedException as e:
2021
2024
  cases, to_replace = e.args
2022
2025
  args = [cc_op, cc_dep1, cc_dep2, cc_ndep]
2023
- for i, arg in enumerate(args):
2024
- if arg is to_replace:
2025
- break
2026
- else:
2027
- raise errors.UnsupportedCCallError("Trying to concretize a value which is not an argument")
2026
+ try:
2027
+ i = args.index(to_replace)
2028
+ except ValueError as ve:
2029
+ raise errors.UnsupportedCCallError("Trying to concretize a value which is not an argument") from ve
2028
2030
  return claripy.ite_cases([(case, func(state, *args[:i], value_, *args[i + 1 :])) for case, value_ in cases], 0)
2029
2031
 
2030
2032
 
@@ -2064,7 +2066,3 @@ def _get_nbits(cc_str):
2064
2066
  elif cc_str.endswith("64"):
2065
2067
  nbits = 64
2066
2068
  return nbits
2067
-
2068
-
2069
- from angr.errors import SimError, SimCCallError
2070
- from angr.sim_options import USE_SIMPLIFIED_CCALLS
@@ -130,11 +130,10 @@ class ClaripyDataMixin(VEXMixin):
130
130
  except ccall.CCallMultivaluedException as e:
131
131
  cases, to_replace = e.args
132
132
  # pylint: disable=undefined-loop-variable
133
- for i, arg in enumerate(args):
134
- if arg is to_replace:
135
- break
136
- else:
137
- raise errors.UnsupportedCCallError("Trying to concretize a value which is not an argument")
133
+ try:
134
+ i = args.index(to_replace)
135
+ except ValueError as ve:
136
+ raise errors.UnsupportedCCallError("Trying to concretize a value which is not an argument") from ve
138
137
  evaluated_cases = [(case, func(self.state, *args[:i], value_, *args[i + 1 :])) for case, value_ in cases]
139
138
  try:
140
139
  return claripy.ite_cases(evaluated_cases, value(ty, 0))
@@ -57,7 +57,7 @@ class VEXLifter(SimEngineBase):
57
57
  self.selfmodifying_code = False
58
58
 
59
59
  # block cache
60
- self._block_cache = None
60
+ self._block_cache: LRUCache = None
61
61
  self._block_cache_hits = 0
62
62
  self._block_cache_misses = 0
63
63
 
@@ -78,8 +78,8 @@ class VEXLifter(SimEngineBase):
78
78
  self,
79
79
  addr=None,
80
80
  state=None,
81
- clemory=None,
82
- insn_bytes=None,
81
+ clemory: cle.Clemory | cle.ClemoryReadOnlyView | None = None,
82
+ insn_bytes: bytes | None = None,
83
83
  offset=None,
84
84
  arch=None,
85
85
  size=None,
@@ -94,7 +94,7 @@ class VEXLifter(SimEngineBase):
94
94
  cross_insn_opt=None,
95
95
  load_from_ro_regions=False,
96
96
  const_prop=False,
97
- ):
97
+ ) -> pyvex.IRSB:
98
98
  """
99
99
  Lift an IRSB.
100
100
 
@@ -245,6 +245,7 @@ class VEXLifter(SimEngineBase):
245
245
  raise SimEngineError(f"No bytes in memory for block starting at {addr:#x}.")
246
246
 
247
247
  # phase 5: call into pyvex
248
+ buff: bytes | claripy.ast.BV
248
249
  l.debug("Creating IRSB of %s at %#x", arch, addr)
249
250
  try:
250
251
  for subphase in range(2):
@@ -287,7 +288,9 @@ class VEXLifter(SimEngineBase):
287
288
  l.debug("Using bytes: %r", pyvex.ffi.buffer(buff, size))
288
289
  raise SimTranslationError("Unable to translate bytecode") from e
289
290
 
290
- def _load_bytes(self, addr, max_size, state=None, clemory=None):
291
+ def _load_bytes(
292
+ self, addr, max_size, state=None, clemory: cle.Clemory | cle.ClemoryReadOnlyView | None = None
293
+ ) -> tuple[bytes, int, int]:
291
294
  if clemory is None and state is None:
292
295
  raise SimEngineError("state and clemory cannot both be None in _load_bytes().")
293
296
 
@@ -308,7 +311,7 @@ class VEXLifter(SimEngineBase):
308
311
 
309
312
  # Load from the clemory if we can
310
313
  if not load_from_state or not state:
311
- if isinstance(clemory, cle.Clemory):
314
+ if isinstance(clemory, (cle.Clemory, cle.ClemoryReadOnlyView)):
312
315
  try:
313
316
  start, backer = next(clemory.backers(addr))
314
317
  except StopIteration: