angr 9.2.115__py3-none-macosx_11_0_arm64.whl → 9.2.117__py3-none-macosx_11_0_arm64.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 (162) hide show
  1. angr/__init__.py +1 -1
  2. angr/__main__.py +1 -1
  3. angr/analyses/cfg/cfg_emulated.py +4 -4
  4. angr/analyses/cfg/indirect_jump_resolvers/jumptable.py +7 -7
  5. angr/analyses/cfg/indirect_jump_resolvers/mips_elf_fast.py +3 -2
  6. angr/analyses/decompiler/optimization_passes/stack_canary_simplifier.py +5 -1
  7. angr/analyses/decompiler/structured_codegen/c.py +10 -13
  8. angr/analyses/decompiler/structuring/dream.py +3 -4
  9. angr/analyses/decompiler/structuring/phoenix.py +4 -5
  10. angr/analyses/decompiler/structuring/structurer_base.py +2 -3
  11. angr/analyses/decompiler/structuring/structurer_nodes.py +3 -3
  12. angr/analyses/identifier/functions/free.py +3 -1
  13. angr/analyses/identifier/identify.py +13 -15
  14. angr/analyses/identifier/runner.py +2 -2
  15. angr/analyses/reaching_definitions/dep_graph.py +62 -5
  16. angr/analyses/reaching_definitions/function_handler_library/__init__.py +11 -0
  17. angr/analyses/reaching_definitions/function_handler_library/stdio.py +15 -13
  18. angr/analyses/reaching_definitions/function_handler_library/stdlib.py +17 -11
  19. angr/analyses/reaching_definitions/function_handler_library/string.py +1 -1
  20. angr/analyses/reaching_definitions/function_handler_library/unistd.py +2 -2
  21. angr/analyses/reaching_definitions/rd_state.py +26 -29
  22. angr/analyses/variable_recovery/engine_vex.py +0 -9
  23. angr/analyses/vfg.py +4 -4
  24. angr/calling_conventions.py +4 -2
  25. angr/concretization_strategies/any_named.py +3 -1
  26. angr/concretization_strategies/controlled_data.py +4 -2
  27. angr/concretization_strategies/signed_add.py +3 -1
  28. angr/engines/concrete.py +3 -1
  29. angr/engines/pcode/behavior.py +2 -0
  30. angr/engines/pcode/cc.py +2 -0
  31. angr/engines/pcode/emulate.py +4 -4
  32. angr/engines/pcode/engine.py +3 -7
  33. angr/engines/soot/engine.py +7 -6
  34. angr/engines/soot/expressions/constants.py +6 -5
  35. angr/engines/soot/expressions/newArray.py +3 -1
  36. angr/engines/soot/expressions/newMultiArray.py +3 -1
  37. angr/engines/soot/statements/goto.py +3 -1
  38. angr/engines/soot/statements/if_.py +3 -1
  39. angr/engines/soot/statements/switch.py +3 -1
  40. angr/engines/soot/statements/throw.py +4 -2
  41. angr/engines/soot/values/arrayref.py +5 -5
  42. angr/engines/unicorn.py +8 -7
  43. angr/engines/vex/heavy/concretizers.py +6 -6
  44. angr/engines/vex/heavy/dirty.py +20 -22
  45. angr/engines/vex/heavy/heavy.py +4 -8
  46. angr/exploration_techniques/director.py +1 -1
  47. angr/exploration_techniques/driller_core.py +3 -1
  48. angr/exploration_techniques/tracer.py +2 -1
  49. angr/knowledge_plugins/key_definitions/live_definitions.py +12 -13
  50. angr/lib/angr_native.dylib +0 -0
  51. angr/procedures/cgc/allocate.py +8 -10
  52. angr/procedures/cgc/deallocate.py +10 -3
  53. angr/procedures/cgc/fdwait.py +15 -13
  54. angr/procedures/cgc/random.py +11 -5
  55. angr/procedures/cgc/receive.py +5 -3
  56. angr/procedures/cgc/transmit.py +5 -4
  57. angr/procedures/glibc/__libc_start_main.py +5 -4
  58. angr/procedures/java_jni/__init__.py +4 -4
  59. angr/procedures/java_jni/array_operations.py +3 -1
  60. angr/procedures/java_lang/string.py +1 -1
  61. angr/procedures/java_util/random.py +3 -1
  62. angr/procedures/libc/access.py +4 -2
  63. angr/procedures/libc/feof.py +4 -3
  64. angr/procedures/libc/fgetc.py +3 -1
  65. angr/procedures/libc/fgets.py +5 -5
  66. angr/procedures/libc/fopen.py +5 -4
  67. angr/procedures/libc/fread.py +4 -3
  68. angr/procedures/libc/fseek.py +4 -3
  69. angr/procedures/libc/getdelim.py +7 -4
  70. angr/procedures/libc/gets.py +4 -2
  71. angr/procedures/libc/memcmp.py +18 -15
  72. angr/procedures/libc/memset.py +9 -7
  73. angr/procedures/libc/puts.py +3 -1
  74. angr/procedures/libc/snprintf.py +4 -2
  75. angr/procedures/libc/sprintf.py +3 -1
  76. angr/procedures/libc/strchr.py +6 -3
  77. angr/procedures/libc/strcmp.py +5 -3
  78. angr/procedures/libc/strlen.py +3 -3
  79. angr/procedures/libc/strncmp.py +28 -28
  80. angr/procedures/libc/strncpy.py +5 -2
  81. angr/procedures/libc/strstr.py +10 -7
  82. angr/procedures/libc/strtol.py +32 -34
  83. angr/procedures/libc/tolower.py +3 -1
  84. angr/procedures/libc/toupper.py +3 -1
  85. angr/procedures/linux_kernel/fstat.py +13 -13
  86. angr/procedures/linux_kernel/fstat64.py +15 -15
  87. angr/procedures/linux_kernel/lseek.py +5 -3
  88. angr/procedures/linux_kernel/sigaction.py +4 -2
  89. angr/procedures/linux_kernel/sigprocmask.py +5 -3
  90. angr/procedures/linux_kernel/tgkill.py +3 -1
  91. angr/procedures/linux_kernel/time.py +7 -4
  92. angr/procedures/msvcr/fmode.py +3 -1
  93. angr/procedures/ntdll/exceptions.py +3 -1
  94. angr/procedures/posix/bzero.py +3 -1
  95. angr/procedures/posix/fdopen.py +6 -4
  96. angr/procedures/posix/fork.py +6 -4
  97. angr/procedures/posix/mmap.py +6 -3
  98. angr/procedures/posix/poll.py +6 -5
  99. angr/procedures/posix/readdir.py +10 -7
  100. angr/procedures/posix/select.py +4 -2
  101. angr/procedures/posix/send.py +4 -3
  102. angr/procedures/posix/sigaction.py +4 -2
  103. angr/procedures/posix/sim_time.py +3 -1
  104. angr/procedures/posix/strcasecmp.py +3 -1
  105. angr/procedures/posix/strtok_r.py +10 -7
  106. angr/procedures/stubs/Redirect.py +3 -1
  107. angr/procedures/stubs/ReturnChar.py +3 -3
  108. angr/procedures/stubs/UserHook.py +3 -1
  109. angr/procedures/stubs/b64_decode.py +3 -1
  110. angr/procedures/stubs/crazy_scanf.py +6 -4
  111. angr/procedures/stubs/format_parser.py +13 -15
  112. angr/procedures/tracer/receive.py +3 -1
  113. angr/procedures/tracer/transmit.py +3 -1
  114. angr/procedures/win32/GetLastInputInfo.py +4 -2
  115. angr/procedures/win32/GetProcessAffinityMask.py +4 -2
  116. angr/procedures/win32/gethostbyname.py +3 -1
  117. angr/procedures/win32/heap.py +3 -1
  118. angr/procedures/win32/local_storage.py +4 -2
  119. angr/procedures/win32/sim_time.py +7 -4
  120. angr/procedures/win_user32/chars.py +4 -2
  121. angr/procedures/win_user32/messagebox.py +3 -1
  122. angr/sim_procedure.py +7 -7
  123. angr/sim_state.py +10 -7
  124. angr/sim_type.py +3 -3
  125. angr/simos/cgc.py +2 -2
  126. angr/simos/simos.py +5 -4
  127. angr/simos/windows.py +5 -5
  128. angr/state_plugins/heap/heap_brk.py +5 -3
  129. angr/state_plugins/heap/heap_ptmalloc.py +5 -4
  130. angr/state_plugins/history.py +7 -5
  131. angr/state_plugins/light_registers.py +2 -2
  132. angr/state_plugins/plugin.py +2 -2
  133. angr/state_plugins/posix.py +28 -26
  134. angr/state_plugins/preconstrainer.py +2 -1
  135. angr/state_plugins/solver.py +11 -27
  136. angr/state_plugins/trace_additions.py +9 -13
  137. angr/state_plugins/uc_manager.py +4 -2
  138. angr/state_plugins/unicorn_engine.py +1 -1
  139. angr/state_plugins/view.py +1 -1
  140. angr/storage/file.py +21 -26
  141. angr/storage/memory_mixins/actions_mixin.py +4 -2
  142. angr/storage/memory_mixins/address_concretization_mixin.py +3 -3
  143. angr/storage/memory_mixins/default_filler_mixin.py +6 -4
  144. angr/storage/memory_mixins/javavm_memory/javavm_memory_mixin.py +7 -5
  145. angr/storage/memory_mixins/paged_memory/paged_memory_mixin.py +1 -1
  146. angr/storage/memory_mixins/paged_memory/pages/cooperation.py +2 -1
  147. angr/storage/memory_mixins/regioned_memory/abstract_merger_mixin.py +1 -1
  148. angr/storage/memory_mixins/regioned_memory/region_data.py +3 -1
  149. angr/storage/memory_mixins/regioned_memory/region_meta_mixin.py +1 -1
  150. angr/storage/memory_mixins/regioned_memory/regioned_memory_mixin.py +5 -4
  151. angr/storage/memory_mixins/simple_interface_mixin.py +2 -2
  152. angr/storage/memory_mixins/size_resolution_mixin.py +3 -1
  153. angr/storage/memory_mixins/slotted_memory.py +1 -1
  154. angr/storage/memory_mixins/smart_find_mixin.py +2 -2
  155. angr/storage/memory_mixins/symbolic_merger_mixin.py +5 -3
  156. angr/tablespecs.py +3 -3
  157. {angr-9.2.115.dist-info → angr-9.2.117.dist-info}/METADATA +7 -7
  158. {angr-9.2.115.dist-info → angr-9.2.117.dist-info}/RECORD +162 -162
  159. {angr-9.2.115.dist-info → angr-9.2.117.dist-info}/WHEEL +1 -1
  160. {angr-9.2.115.dist-info → angr-9.2.117.dist-info}/LICENSE +0 -0
  161. {angr-9.2.115.dist-info → angr-9.2.117.dist-info}/entry_points.txt +0 -0
  162. {angr-9.2.115.dist-info → angr-9.2.117.dist-info}/top_level.txt +0 -0
@@ -1,3 +1,5 @@
1
+ import claripy
2
+
1
3
  import angr
2
4
 
3
5
 
@@ -9,7 +11,7 @@ class MessageBoxA(angr.SimProcedure):
9
11
  else:
10
12
  caption = "Error"
11
13
 
12
- result = self.state.solver.If(
14
+ result = claripy.If(
13
15
  uType & 0xF == 0, 1, self.state.solver.BVS("messagebox_button", 32, key=("api", "messagebox", "button"))
14
16
  )
15
17
  self.state.history.add_event("message_box", text=text, caption=caption, result=result)
angr/sim_procedure.py CHANGED
@@ -412,7 +412,7 @@ class SimProcedure:
412
412
  :param sim_kwargs: Any additional keyword args will be passed as sim_kwargs to the
413
413
  procedure construtor
414
414
  """
415
- e_args = [self.state.solver.BVV(a, self.state.arch.bits) if isinstance(a, int) else a for a in arguments]
415
+ e_args = [claripy.BVV(a, self.state.arch.bits) if isinstance(a, int) else a for a in arguments]
416
416
  p = procedure(project=self.project, **kwargs)
417
417
  return p.execute(self.state, None, arguments=e_args)
418
418
 
@@ -476,7 +476,7 @@ class SimProcedure:
476
476
  self._prepare_ret_state()
477
477
 
478
478
  self._exit_action(self.state, ret_addr)
479
- self.successors.add_successor(self.state, ret_addr, self.state.solver.true, "Ijk_Ret")
479
+ self.successors.add_successor(self.state, ret_addr, claripy.true, "Ijk_Ret")
480
480
 
481
481
  def call(self, addr, args, continue_at, cc=None, prototype=None, jumpkind="Ijk_Call"):
482
482
  """
@@ -519,7 +519,7 @@ class SimProcedure:
519
519
  call_state.regs.t9 = addr
520
520
 
521
521
  self._exit_action(call_state, addr)
522
- self.successors.add_successor(call_state, addr, call_state.solver.true, jumpkind)
522
+ self.successors.add_successor(call_state, addr, claripy.true, jumpkind)
523
523
  if jumpkind != "Ijk_Call":
524
524
  call_state.callstack.call(
525
525
  self.state.addr, addr, retn_target=ret_addr, stack_pointer=call_state.regs.sp.concrete_value
@@ -530,7 +530,7 @@ class SimProcedure:
530
530
  ret_state = self.state.copy()
531
531
  cc.setup_callsite(ret_state, ret_addr, args, prototype)
532
532
  ret_state.callstack.top.procedure_data = simcallstack_entry
533
- guard = ret_state.solver.true if o.TRUE_RET_EMULATION_GUARD in ret_state.options else ret_state.solver.false
533
+ guard = claripy.true if o.TRUE_RET_EMULATION_GUARD in ret_state.options else claripy.false
534
534
  self.successors.add_successor(ret_state, ret_addr, guard, "Ijk_FakeRet")
535
535
 
536
536
  def jump(self, addr, jumpkind="Ijk_Boring"):
@@ -539,7 +539,7 @@ class SimProcedure:
539
539
  """
540
540
  self.inhibit_autoret = True
541
541
  self._exit_action(self.state, addr)
542
- self.successors.add_successor(self.state, addr, self.state.solver.true, jumpkind)
542
+ self.successors.add_successor(self.state, addr, claripy.true, jumpkind)
543
543
 
544
544
  def exit(self, exit_code):
545
545
  """
@@ -550,9 +550,9 @@ class SimProcedure:
550
550
  self.state.options.discard(o.AUTO_REFS)
551
551
 
552
552
  if isinstance(exit_code, int):
553
- exit_code = self.state.solver.BVV(exit_code, self.state.arch.bits)
553
+ exit_code = claripy.BVV(exit_code, self.state.arch.bits)
554
554
  self.state.history.add_event("terminate", exit_code=exit_code)
555
- self.successors.add_successor(self.state, self.state.regs.ip, self.state.solver.true, "Ijk_Exit")
555
+ self.successors.add_successor(self.state, self.state.regs.ip, claripy.true, "Ijk_Exit")
556
556
 
557
557
  @staticmethod
558
558
  def _exit_action(state, addr):
angr/sim_state.py CHANGED
@@ -538,7 +538,7 @@ class SimState(PluginHub):
538
538
  # We take the argument, extract a list of constrained SIs out of it (if we could, of course), and
539
539
  # then replace each original SI the intersection of original SI and the constrained one.
540
540
 
541
- _, converted = self.solver.constraint_to_si(arg)
541
+ _, converted = claripy.constraint_to_si(arg)
542
542
 
543
543
  for original_expr, constrained_si in converted:
544
544
  if not original_expr.variables:
@@ -684,11 +684,14 @@ class SimState(PluginHub):
684
684
 
685
685
  if merge_conditions is None:
686
686
  # TODO: maybe make the length of this smaller? Maybe: math.ceil(math.log(len(others)+1, 2))
687
- merge_flag = self.solver.BVS("state_merge_%d" % next(merge_counter), 16)
687
+ merge_flag = claripy.BVS("state_merge_%d" % next(merge_counter), 16)
688
688
  merge_values = range(len(others) + 1)
689
689
  merge_conditions = [merge_flag == b for b in merge_values]
690
690
  else:
691
- merge_conditions = [(self.solver.true if len(mc) == 0 else self.solver.And(*mc)) for mc in merge_conditions]
691
+ merge_conditions = [
692
+ (claripy.true if len(mc) == 0 else claripy.And(*[c.to_claripy() for c in mc]))
693
+ for mc in merge_conditions
694
+ ]
692
695
 
693
696
  if len({o.arch.name for o in others}) != 1:
694
697
  raise SimMergeError("Unable to merge due to different architectures.")
@@ -738,7 +741,7 @@ class SimState(PluginHub):
738
741
  l.debug("Merging occurred in %s", p)
739
742
  merging_occurred = True
740
743
 
741
- merged.add_constraints(merged.solver.Or(*merge_conditions))
744
+ merged.add_constraints(claripy.Or(*merge_conditions))
742
745
  return merged, merge_conditions, merging_occurred
743
746
 
744
747
  def widen(self, *others):
@@ -956,7 +959,7 @@ class SimState(PluginHub):
956
959
  def ctx(c):
957
960
  old_condition = self._global_condition
958
961
  try:
959
- new_condition = c if old_condition is None else self.solver.And(old_condition, c)
962
+ new_condition = c if old_condition is None else claripy.And(old_condition, c)
960
963
  self._global_condition = new_condition
961
964
  yield
962
965
  finally:
@@ -970,7 +973,7 @@ class SimState(PluginHub):
970
973
  elif c is None:
971
974
  return self._global_condition
972
975
  else:
973
- return self.solver.And(self._global_condition, c)
976
+ return claripy.And(self._global_condition, c)
974
977
 
975
978
  def _adjust_condition_list(self, conditions):
976
979
  if self._global_condition is None:
@@ -978,7 +981,7 @@ class SimState(PluginHub):
978
981
  elif len(conditions) == 0:
979
982
  return conditions.__class__((self._global_condition,))
980
983
  else:
981
- return conditions.__class__((self._adjust_condition(self.solver.And(*conditions)),))
984
+ return conditions.__class__((self._adjust_condition(claripy.And(*conditions)),))
982
985
 
983
986
 
984
987
  default_state_plugin_preset = PluginPreset()
angr/sim_type.py CHANGED
@@ -335,7 +335,7 @@ class SimTypeReg(SimType):
335
335
  if value.size() != self.size:
336
336
  raise ValueError("size of expression is wrong size for type")
337
337
  elif isinstance(value, int):
338
- value = state.solver.BVV(value, self.size)
338
+ value = claripy.BVV(value, self.size)
339
339
  elif isinstance(value, bytes):
340
340
  store_endness = "Iend_BE"
341
341
  else:
@@ -527,7 +527,7 @@ class SimTypeChar(SimTypeReg):
527
527
  super().store(state, addr, value)
528
528
  except TypeError:
529
529
  if isinstance(value, bytes) and len(value) == 1:
530
- value = state.solver.BVV(value[0], state.arch.byte_width)
530
+ value = claripy.BVV(value[0], state.arch.byte_width)
531
531
  super().store(state, addr, value)
532
532
  else:
533
533
  raise
@@ -580,7 +580,7 @@ class SimTypeWideChar(SimTypeReg):
580
580
  super().store(state, addr, value)
581
581
  except TypeError:
582
582
  if isinstance(value, bytes) and len(value) == 2:
583
- value = state.solver.BVV(value[0], state.arch.byte_width)
583
+ value = claripy.BVV(value[0], state.arch.byte_width)
584
584
  super().store(state, addr, value)
585
585
  else:
586
586
  raise
angr/simos/cgc.py CHANGED
@@ -51,7 +51,7 @@ class SimCGC(SimUserland):
51
51
  if flag_page is None:
52
52
  flag_page = [s.solver.BVS("cgc-flag-byte-%d" % i, 8, key=("flag", i), eternal=True) for i in range(0x1000)]
53
53
  elif type(flag_page) is bytes:
54
- flag_page = [s.solver.BVV(c, 8) for c in flag_page]
54
+ flag_page = [claripy.BVV(c, 8) for c in flag_page]
55
55
  elif type(flag_page) is list:
56
56
  pass
57
57
  else:
@@ -93,7 +93,7 @@ class SimCGC(SimUserland):
93
93
  for size in writes_backer:
94
94
  if size == 0:
95
95
  continue
96
- str_to_write = state.solver.BVS("file_write", size * 8)
96
+ str_to_write = claripy.BVS("file_write", size * 8)
97
97
  a = SimActionData(
98
98
  state, "file_1_0", "write", addr=claripy.BVV(pos, state.arch.bits), data=str_to_write, size=size
99
99
  )
angr/simos/simos.py CHANGED
@@ -1,11 +1,10 @@
1
1
  import logging
2
2
  import struct
3
3
 
4
- import angr # for types
5
-
6
- import claripy
7
4
  from archinfo import ArchMIPS32, ArchS390X
5
+ import claripy
8
6
 
7
+ import angr
9
8
  from ..errors import (
10
9
  AngrCallableError,
11
10
  AngrCallableMultistateError,
@@ -179,7 +178,7 @@ class SimOS:
179
178
  for reg in state.arch.default_symbolic_registers:
180
179
  state.registers.store(
181
180
  reg,
182
- state.solver.BVS(
181
+ claripy.BVS(
183
182
  initial_prefix + "_" + reg, state.arch.bits, explicit_name=True, key=("reg", reg), eternal=True
184
183
  ),
185
184
  )
@@ -437,6 +436,8 @@ class SimOS:
437
436
 
438
437
 
439
438
  class GlobalDescriptorTable:
439
+ """GlobalDescriptorTable object to store the GDT table and the segment registers values"""
440
+
440
441
  def __init__(self, addr, limit, table, gdt_sel, cs_sel, ds_sel, es_sel, ss_sel, fs_sel, gs_sel):
441
442
  self.addr = addr
442
443
  self.limit = limit
angr/simos/windows.py CHANGED
@@ -170,7 +170,7 @@ class SimWindows(SimOS):
170
170
  state.mem[state.regs.sp].dword = return_addr
171
171
 
172
172
  # first argument appears to be PEB
173
- tib_addr = state.regs.fs.concat(state.solver.BVV(0, 16))
173
+ tib_addr = state.regs.fs.concat(claripy.BVV(0, 16))
174
174
  peb_addr = state.mem[tib_addr + 0x30].dword.resolved
175
175
  state.mem[state.regs.sp + 4].dword = peb_addr
176
176
 
@@ -377,7 +377,7 @@ class SimWindows(SimOS):
377
377
 
378
378
  # first check that we actually have an exception handler
379
379
  # we check is_true since if it's symbolic this is exploitable maybe?
380
- tib_addr = exc_state.regs._fs.concat(exc_state.solver.BVV(0, 16))
380
+ tib_addr = exc_state.regs._fs.concat(claripy.BVV(0, 16))
381
381
  if exc_state.solver.is_true(exc_state.mem[tib_addr].long.resolved == -1):
382
382
  _l.debug("... no handlers registered")
383
383
  exception.args = ("Unhandled exception: %r" % exception,)
@@ -419,7 +419,7 @@ class SimWindows(SimOS):
419
419
 
420
420
  # let's go let's go!
421
421
  # we want to use a true guard here. if it's not true, then it's already been added in windup.
422
- successors.add_successor(exc_state, self._exception_handler, exc_state.solver.true, "Ijk_Exception")
422
+ successors.add_successor(exc_state, self._exception_handler, claripy.true, "Ijk_Exception")
423
423
  successors.processed = True
424
424
 
425
425
  # these two methods load and store register state from a struct CONTEXT
@@ -433,8 +433,8 @@ class SimWindows(SimOS):
433
433
  state.mem[addr + 0].uint32_t = 0x07 # contextflags = control | integer | segments
434
434
  # dr0 - dr7 are at 0x4-0x18
435
435
  # fp state is at 0x1c: 8 ulongs plus a char[80] gives it size 0x70
436
- state.mem[addr + 0x8C].uint32_t = state.regs.gs.concat(state.solver.BVV(0, 16))
437
- state.mem[addr + 0x90].uint32_t = state.regs.fs.concat(state.solver.BVV(0, 16))
436
+ state.mem[addr + 0x8C].uint32_t = state.regs.gs.concat(claripy.BVV(0, 16))
437
+ state.mem[addr + 0x90].uint32_t = state.regs.fs.concat(claripy.BVV(0, 16))
438
438
  state.mem[addr + 0x94].uint32_t = 0 # es
439
439
  state.mem[addr + 0x98].uint32_t = 0 # ds
440
440
  state.mem[addr + 0x9C].uint32_t = state.regs.edi
@@ -1,9 +1,11 @@
1
+ import logging
2
+
3
+ import claripy
4
+
1
5
  from angr.errors import SimSolverError
2
6
  from ..plugin import SimStatePlugin
3
7
  from . import SimHeapBase
4
8
 
5
- import logging
6
-
7
9
  l = logging.getLogger(__name__)
8
10
 
9
11
 
@@ -92,7 +94,7 @@ class SimHeapBrk(SimHeapBase):
92
94
  final_size = plugin.max_variable_size
93
95
 
94
96
  addr = self.state.heap.allocate(final_size)
95
- v = self.state.solver.BVV(0, final_size * 8)
97
+ v = claripy.BVV(0, final_size * 8)
96
98
  self.state.memory.store(addr, v)
97
99
  return addr
98
100
 
@@ -1,12 +1,13 @@
1
+ import logging
2
+
3
+ import claripy
4
+
1
5
  from ..plugin import SimStatePlugin
2
6
  from .heap_freelist import SimHeapFreelist, Chunk
3
7
  from .utils import concretize
4
-
5
8
  from ...errors import SimHeapError, SimMergeError, SimSolverError
6
9
 
7
10
 
8
- import logging
9
-
10
11
  l = logging.getLogger("angr.state_plugins.heap.heap_ptmalloc")
11
12
  sml = logging.getLogger("angr.state_plugins.symbolic_memory")
12
13
 
@@ -526,7 +527,7 @@ class SimHeapPTMalloc(SimHeapFreelist):
526
527
  if addr == 0:
527
528
  return 0
528
529
  if size != 0:
529
- z = self.state.solver.BVV(0, size * 8)
530
+ z = claripy.BVV(0, size * 8)
530
531
  self.state.memory.store(addr, z)
531
532
  return addr
532
533
 
@@ -140,17 +140,19 @@ class SimStateHistory(SimStatePlugin):
140
140
  self.parent = common_ancestor if common_ancestor is not None else self.parent
141
141
 
142
142
  # rebuild recent constraints
143
- recent_constraints = [h.constraints_since(common_ancestor) for h in itertools.chain([self], others)]
143
+ recent_constraints = [
144
+ [c.ast for c in h.constraints_since(common_ancestor)] for h in itertools.chain([self], others)
145
+ ]
144
146
  if sim_options.SIMPLIFY_MERGED_CONSTRAINTS in self.state.options:
145
- combined_constraint = self.state.solver.Or(
147
+ combined_constraint = claripy.Or(
146
148
  *[
147
- self.state.solver.simplify(self.state.solver.And(*history_constraints))
149
+ self.state.solver.simplify(claripy.And(*history_constraints))
148
150
  for history_constraints in recent_constraints
149
151
  ]
150
152
  )
151
153
  else:
152
- combined_constraint = self.state.solver.Or(
153
- *[self.state.solver.And(*history_constraints) for history_constraints in recent_constraints]
154
+ combined_constraint = claripy.Or(
155
+ *[claripy.And(*history_constraints) for history_constraints in recent_constraints]
154
156
  )
155
157
  self.recent_events = [
156
158
  e.recent_events for e in itertools.chain([self], others) if not isinstance(e, SimActionConstraint)
@@ -118,7 +118,7 @@ class SimLightRegisters(SimStatePlugin):
118
118
  raise SimFastMemoryError("Invalid register store value") from None
119
119
 
120
120
  if type(value) is int:
121
- value = self.state.solver.BVV(value, xsize)
121
+ value = claripy.BVV(value, xsize)
122
122
 
123
123
  if endness is not None and endness != self.state.arch.register_endness:
124
124
  # ???????
@@ -142,7 +142,7 @@ class SimLightRegisters(SimStatePlugin):
142
142
  def _fill(self, name, size):
143
143
  size_bits = size * self.state.arch.byte_width
144
144
  if options.ZERO_FILL_UNCONSTRAINED_REGISTERS in self.state.options:
145
- value = self.state.solver.BVV(0, size_bits)
145
+ value = claripy.BVV(0, size_bits)
146
146
  else:
147
147
  if options.SYMBOL_FILL_UNCONSTRAINED_REGISTERS not in self.state.options:
148
148
  if once("mem_fill_warning"):
@@ -98,8 +98,8 @@ class SimStatePlugin:
98
98
  ``state.solver.union(values)``.
99
99
  TODO: fish please make this less bullshit
100
100
 
101
- There is a utility ``state.solver.ite_cases`` which will help with constructing arbitrarily large merged ASTs.
102
- Use it like ``self.bar = self.state.solver.ite_cases(zip(conditions[1:], [o.bar for o in others]), self.bar)``
101
+ There is a utility ``claripy.ite_cases`` which will help with constructing arbitrarily large merged ASTs.
102
+ Use it like ``self.bar = claripy.ite_cases(zip(conditions[1:], [o.bar for o in others]), self.bar)``
103
103
 
104
104
  :param others: the other state plugins to merge with
105
105
  :param merge_conditions: a symbolic condition for each of the plugins
@@ -1,5 +1,7 @@
1
1
  import logging
2
2
 
3
+ import claripy
4
+
3
5
  from .plugin import SimStatePlugin
4
6
  from .filesystem import SimMount, Stat
5
7
  from ..storage.file import SimFile, SimPacketsStream, Flags, SimFileDescriptor, SimFileDescriptorDuplex
@@ -239,11 +241,11 @@ class SimSystemPosix(SimStatePlugin):
239
241
  def set_brk(self, new_brk):
240
242
  # arch word size is not available at init for some reason, fix that here
241
243
  if isinstance(self.brk, int):
242
- self.brk = self.state.solver.BVV(self.brk, self.state.arch.bits)
244
+ self.brk = claripy.BVV(self.brk, self.state.arch.bits)
243
245
 
244
246
  if new_brk.symbolic:
245
247
  l.warning("Program is requesting a symbolic brk! This cannot be emulated cleanly!")
246
- self.brk = self.state.solver.If(new_brk < self.brk, self.brk, new_brk)
248
+ self.brk = claripy.If(new_brk < self.brk, self.brk, new_brk)
247
249
 
248
250
  else:
249
251
  conc_start = self.state.solver.eval(self.brk)
@@ -342,7 +344,7 @@ class SimSystemPosix(SimStatePlugin):
342
344
  if not create_file:
343
345
  if options.ALL_FILES_EXIST not in self.state.options:
344
346
  if options.ANY_FILE_MIGHT_EXIST in self.state.options:
345
- file_exists = self.state.solver.BoolS("file_exists_%s" % ident, explicit_name=True)
347
+ file_exists = claripy.BoolS("file_exists_%s" % ident, explicit_name=True)
346
348
  else:
347
349
  return -1
348
350
  else:
@@ -369,8 +371,8 @@ class SimSystemPosix(SimStatePlugin):
369
371
  if self.state.solver.is_true(simfd.file_exists):
370
372
  return fd
371
373
  else:
372
- m1 = self.state.solver.BVV(-1, self.state.arch.sizeof["int"])
373
- return self.state.solver.If(simfd.file_exists, fd, m1)
374
+ m1 = claripy.BVV(-1, self.state.arch.sizeof["int"])
375
+ return claripy.If(simfd.file_exists, fd, m1)
374
376
 
375
377
  def open_socket(self, ident):
376
378
  fd = self._pick_fd()
@@ -513,8 +515,8 @@ class SimSystemPosix(SimStatePlugin):
513
515
  else:
514
516
  if options.ALL_FILES_EXIST not in self.state.options:
515
517
  if options.ANY_FILE_MIGHT_EXIST in self.state.options:
516
- m1 = self.state.solver.BVV(-1, self.state.arch.bits)
517
- result = self.state.solver.If(self.state.solver.BoolS("file_exists"), 0, m1)
518
+ m1 = claripy.BVV(-1, self.state.arch.bits)
519
+ result = claripy.If(claripy.BoolS("file_exists"), 0, m1)
518
520
  else:
519
521
  result = -1
520
522
  else:
@@ -536,7 +538,7 @@ class SimSystemPosix(SimStatePlugin):
536
538
  mode = (
537
539
  self.state.solver.BVS("st_mode", 32, key=("api", "fstat", "st_mode"))
538
540
  if fd > 2
539
- else self.state.solver.BVV(0, 32)
541
+ else claripy.BVV(0, 32)
540
542
  )
541
543
  size = self.state.solver.BVS("st_size", 64, key=("api", "fstat", "st_size")) # st_size
542
544
  ino = 0
@@ -544,22 +546,22 @@ class SimSystemPosix(SimStatePlugin):
544
546
  # return this weird bogus zero value to keep code paths in libc simple :\
545
547
  return (
546
548
  Stat(
547
- self.state.solver.BVV(0, 64), # st_dev
548
- self.state.solver.BVV(ino, 64), # st_ino
549
- self.state.solver.BVV(0, 64), # st_nlink
549
+ claripy.BVV(0, 64), # st_dev
550
+ claripy.BVV(ino, 64), # st_ino
551
+ claripy.BVV(0, 64), # st_nlink
550
552
  mode, # st_mode
551
- self.state.solver.BVV(0, 32), # st_uid (lol root)
552
- self.state.solver.BVV(0, 32), # st_gid
553
- self.state.solver.BVV(0, 64), # st_rdev
553
+ claripy.BVV(0, 32), # st_uid (lol root)
554
+ claripy.BVV(0, 32), # st_gid
555
+ claripy.BVV(0, 64), # st_rdev
554
556
  size, # st_size
555
- self.state.solver.BVV(0x400, 64), # st_blksize
556
- self.state.solver.BVV(0, 64), # st_blocks
557
- self.state.solver.BVV(0, 64), # st_atime
558
- self.state.solver.BVV(0, 64), # st_atimensec
559
- self.state.solver.BVV(0, 64), # st_mtime
560
- self.state.solver.BVV(0, 64), # st_mtimensec
561
- self.state.solver.BVV(0, 64), # st_ctime
562
- self.state.solver.BVV(0, 64), # st_ctimensec
557
+ claripy.BVV(0x400, 64), # st_blksize
558
+ claripy.BVV(0, 64), # st_blocks
559
+ claripy.BVV(0, 64), # st_atime
560
+ claripy.BVV(0, 64), # st_atimensec
561
+ claripy.BVV(0, 64), # st_mtime
562
+ claripy.BVV(0, 64), # st_mtimensec
563
+ claripy.BVV(0, 64), # st_ctime
564
+ claripy.BVV(0, 64), # st_ctimensec
563
565
  ),
564
566
  result,
565
567
  )
@@ -594,15 +596,15 @@ class SimSystemPosix(SimStatePlugin):
594
596
  :param valid_ptr: is set if the new_mask was not NULL
595
597
  """
596
598
  oldmask = self.sigmask(sigsetsize)
597
- self._sigmask = self.state.solver.If(
599
+ self._sigmask = claripy.If(
598
600
  valid_ptr,
599
- self.state.solver.If(
601
+ claripy.If(
600
602
  how == self.SIG_BLOCK,
601
603
  oldmask | new_mask,
602
- self.state.solver.If(
604
+ claripy.If(
603
605
  how == self.SIG_UNBLOCK,
604
606
  oldmask & (~new_mask),
605
- self.state.solver.If(how == self.SIG_SETMASK, new_mask, oldmask),
607
+ claripy.If(how == self.SIG_SETMASK, new_mask, oldmask),
606
608
  ),
607
609
  ),
608
610
  oldmask,
@@ -1,4 +1,5 @@
1
1
  import logging
2
+
2
3
  import claripy
3
4
 
4
5
  from .plugin import SimStatePlugin
@@ -52,7 +53,7 @@ class SimStatePreconstrainer(SimStatePlugin):
52
53
  :param variable: The BVS to preconstrain.
53
54
  """
54
55
  if not isinstance(value, claripy.ast.Base):
55
- value = self.state.solver.BVV(value, len(variable))
56
+ value = claripy.BVV(value, len(variable))
56
57
  elif value.op != "BVV":
57
58
  raise ValueError("Passed a value to preconstrain that was not a BVV or a string")
58
59
 
@@ -4,11 +4,12 @@ import logging
4
4
  import os
5
5
  from typing import TypeVar, overload
6
6
 
7
- from angr import sim_options as o
8
- from angr.errors import SimValueError, SimUnsatError, SimSolverModeError, SimSolverOptionError
9
7
  import claripy
10
8
  from claripy import backend_manager
11
9
 
10
+ from angr import sim_options as o
11
+ from angr.errors import SimValueError, SimUnsatError, SimSolverModeError, SimSolverOptionError
12
+ from angr.sim_state import SimState
12
13
  from .plugin import SimStatePlugin
13
14
  from .sim_action_object import ast_stripping_decorator, SimActionObject
14
15
 
@@ -234,13 +235,16 @@ class SimSolver(SimStatePlugin):
234
235
  [(('mem', 0x1000), <BV64 mem_1000_4_64>), (('mem', 0x1008), <BV64 mem_1008_5_64>)]
235
236
 
236
237
  >>> list(s.solver.get_variables('file'))
237
- [(('file', 1, 0), <BV8 file_1_0_6_8>), (('file', 1, 1), <BV8 file_1_1_7_8>), (('file', 2, 0), <BV8 file_2_0_8_8>)]
238
+ [(('file', 1, 0), <BV8 file_1_0_6_8>), (('file', 1, 1), <BV8 file_1_1_7_8>),
239
+ (('file', 2, 0), <BV8 file_2_0_8_8>)]
238
240
 
239
241
  >>> list(s.solver.get_variables('file', 2))
240
242
  [(('file', 2, 0), <BV8 file_2_0_8_8>)]
241
243
 
242
244
  >>> list(s.solver.get_variables())
243
- [(('mem', 0x1000), <BV64 mem_1000_4_64>), (('mem', 0x1008), <BV64 mem_1008_5_64>), (('file', 1, 0), <BV8 file_1_0_6_8>), (('file', 1, 1), <BV8 file_1_1_7_8>), (('file', 2, 0), <BV8 file_2_0_8_8>)]
245
+ [(('mem', 0x1000), <BV64 mem_1000_4_64>), (('mem', 0x1008), <BV64 mem_1008_5_64>),
246
+ (('file', 1, 0), <BV8 file_1_0_6_8>), (('file', 1, 1), <BV8 file_1_1_7_8>),
247
+ (('file', 2, 0), <BV8 file_2_0_8_8>)]
244
248
  """
245
249
  for k, v in self.eternal_tracked_variables.items():
246
250
  if len(k) >= len(keys) and all(x == y for x, y in zip(keys, k)):
@@ -464,24 +468,6 @@ class SimSolver(SimStatePlugin):
464
468
  self.all_variables.append(r)
465
469
  return r
466
470
 
467
- #
468
- # Operation passthroughs to claripy
469
- #
470
-
471
- def __getattr__(self, a):
472
- f = getattr(claripy._all_operations, a)
473
- if hasattr(f, "__call__"):
474
- ff = error_converter(ast_stripping_decorator(f))
475
- if _timing_enabled:
476
- ff = functools.partial(timed_function(ff), the_solver=self)
477
- ff.__doc__ = f.__doc__
478
- return ff
479
- else:
480
- return f
481
-
482
- def __dir__(self):
483
- return sorted(set(dir(super()) + dir(claripy._all_operations) + dir(self.__class__)))
484
-
485
471
  #
486
472
  # Branching stuff
487
473
  #
@@ -508,7 +494,7 @@ class SimSolver(SimStatePlugin):
508
494
 
509
495
  @error_converter
510
496
  def widen(self, others):
511
- c = self.state.solver.BVS("random_widen_condition", 32)
497
+ c = claripy.BVS("random_widen_condition", 32)
512
498
  merge_conditions = [[c == i] for i in range(len(others) + 1)]
513
499
  merging_occurred = self.merge(others, merge_conditions)
514
500
  return merging_occurred
@@ -538,7 +524,7 @@ class SimSolver(SimStatePlugin):
538
524
  l.critical("PLEASE REPORT THIS MESSAGE, AND WHAT YOU WERE DOING, TO YAN")
539
525
  return self.state._global_condition
540
526
  else:
541
- return self.Or(self.Not(self.state._global_condition), c)
527
+ return claripy.Or(claripy.Not(self.state._global_condition), c)
542
528
 
543
529
  def _adjust_constraint_list(self, constraints):
544
530
  if self.state._global_condition is None:
@@ -546,7 +532,7 @@ class SimSolver(SimStatePlugin):
546
532
  if len(constraints) == 0:
547
533
  return constraints.__class__((self.state._global_condition,))
548
534
  else:
549
- return constraints.__class__((self._adjust_constraint(self.And(*constraints)),))
535
+ return constraints.__class__((self._adjust_constraint(claripy.And(*constraints)),))
550
536
 
551
537
  @timed_function
552
538
  @ast_stripping_decorator
@@ -1108,8 +1094,6 @@ class SimSolver(SimStatePlugin):
1108
1094
  return e.variables
1109
1095
 
1110
1096
 
1111
- from angr.sim_state import SimState
1112
-
1113
1097
  SimState.register_default("solver", SimSolver)
1114
1098
 
1115
1099
  from .inspect import BP_AFTER
@@ -196,7 +196,7 @@ def end_info_hook(state):
196
196
  if pending_info.get_type() == "StrToInt":
197
197
  # mark the input
198
198
  input_val = state.mem[pending_info.input_val].string.resolved
199
- result = state.solver.BVV(state.solver.eval(state.regs.eax, cast_to=bytes))
199
+ result = claripy.BVV(state.solver.eval(state.regs.eax, cast_to=bytes))
200
200
  real_len = chall_resp_plugin.get_real_len(
201
201
  input_val, pending_info.input_base, result, pending_info.allows_negative
202
202
  )
@@ -207,7 +207,7 @@ def end_info_hook(state):
207
207
  return
208
208
 
209
209
  # result constraint
210
- new_var = state.solver.BVS(pending_info.get_type() + "_" + str(pending_info.input_base) + "_result", 32)
210
+ new_var = claripy.BVS(pending_info.get_type() + "_" + str(pending_info.input_base) + "_result", 32)
211
211
  constraint = new_var == result
212
212
  chall_resp_plugin.replacement_pairs.append((new_var, state.regs.eax))
213
213
  state.regs.eax = new_var
@@ -215,7 +215,7 @@ def end_info_hook(state):
215
215
  # finish marking the input
216
216
  input_val = state.memory.load(pending_info.input_val, real_len)
217
217
  l.debug("string len was %d, value was %d", real_len, state.solver.eval(result))
218
- input_bvs = state.solver.BVS(
218
+ input_bvs = claripy.BVS(
219
219
  pending_info.get_type() + "_" + str(pending_info.input_base) + "_input", input_val.size()
220
220
  )
221
221
  chall_resp_plugin.str_to_int_pairs.append((input_bvs, new_var))
@@ -224,23 +224,19 @@ def end_info_hook(state):
224
224
  chall_resp_plugin.replacement_pairs.append((input_bvs, input_val))
225
225
  elif pending_info.get_type() == "IntToStr":
226
226
  # result constraint
227
- result = state.solver.BVV(
228
- state.solver.eval(state.mem[pending_info.str_dst_addr].string.resolved, cast_to=bytes)
229
- )
227
+ result = claripy.BVV(state.solver.eval(state.mem[pending_info.str_dst_addr].string.resolved, cast_to=bytes))
230
228
  if result is None or result.size() == 0:
231
229
  l.warning("zero len string")
232
230
  chall_resp_plugin.pop_from_backup()
233
231
  return
234
- new_var = state.solver.BVS(
235
- pending_info.get_type() + "_" + str(pending_info.input_base) + "_result", result.size()
236
- )
232
+ new_var = claripy.BVS(pending_info.get_type() + "_" + str(pending_info.input_base) + "_result", result.size())
237
233
  chall_resp_plugin.replacement_pairs.append((new_var, state.mem[pending_info.str_dst_addr].string.resolved))
238
234
  state.memory.store(pending_info.str_dst_addr, new_var)
239
235
  constraint = new_var == result
240
236
 
241
237
  # mark the input
242
238
  input_val = pending_info.input_val
243
- input_bvs = state.solver.BVS(pending_info.get_type() + "_" + str(pending_info.input_base) + "_input", 32)
239
+ input_bvs = claripy.BVS(pending_info.get_type() + "_" + str(pending_info.input_base) + "_input", 32)
244
240
  chall_resp_plugin.int_to_str_pairs.append((input_bvs, new_var))
245
241
  chall_resp_plugin.replacement_pairs.append((input_bvs, input_val))
246
242
  # here we need the constraint that the input was equal to the StrToInt_input
@@ -298,8 +294,8 @@ def syscall_hook(state):
298
294
  num_bytes = state.solver.eval(state.regs.ecx)
299
295
  buf = state.solver.eval(state.regs.ebx)
300
296
  if num_bytes != 0:
301
- rand_bytes = state.solver.BVS("random", num_bytes * 8)
302
- concrete_val = state.solver.BVV("A" * num_bytes)
297
+ rand_bytes = claripy.BVS("random", num_bytes * 8)
298
+ concrete_val = claripy.BVV("A" * num_bytes)
303
299
  state.solver._solver.add_replacement(rand_bytes, concrete_val, invalidate_cache=False)
304
300
  state.memory.store(buf, rand_bytes)
305
301
 
@@ -509,7 +505,7 @@ class ChallRespInfo(angr.state_plugins.SimStatePlugin):
509
505
  solns = solns[0]
510
506
 
511
507
  # now make the real stdin
512
- stdin = state.solver.eval(state.solver.BVV(solns[0], pos * 8), cast_to=bytes)
508
+ stdin = state.solver.eval(claripy.BVV(solns[0], pos * 8), cast_to=bytes)
513
509
 
514
510
  stdin_replacements = []
515
511
  for soln, (_, int_var) in zip(solns[1:], chall_resp_plugin.str_to_int_pairs):