angr 9.2.87__py3-none-manylinux2014_x86_64.whl → 9.2.89__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 (248) hide show
  1. angr/__init__.py +4 -1
  2. angr/analyses/decompiler/clinic.py +16 -0
  3. angr/analyses/decompiler/decompiler.py +3 -0
  4. angr/analyses/decompiler/optimization_passes/__init__.py +5 -0
  5. angr/analyses/decompiler/optimization_passes/cross_jump_reverter.py +108 -0
  6. angr/analyses/decompiler/optimization_passes/optimization_pass.py +17 -4
  7. angr/analyses/decompiler/optimization_passes/return_duplicator.py +4 -32
  8. angr/analyses/decompiler/structured_codegen/c.py +12 -2
  9. angr/analyses/decompiler/utils.py +13 -0
  10. angr/analyses/typehoon/dfa.py +108 -0
  11. angr/analyses/typehoon/lifter.py +34 -2
  12. angr/analyses/typehoon/simple_solver.py +1043 -503
  13. angr/analyses/typehoon/translator.py +13 -4
  14. angr/analyses/typehoon/typeconsts.py +117 -36
  15. angr/analyses/typehoon/typehoon.py +31 -11
  16. angr/analyses/typehoon/typevars.py +88 -21
  17. angr/analyses/typehoon/variance.py +10 -0
  18. angr/analyses/variable_recovery/engine_ail.py +28 -9
  19. angr/analyses/variable_recovery/engine_base.py +50 -43
  20. angr/analyses/variable_recovery/variable_recovery_base.py +16 -3
  21. angr/analyses/variable_recovery/variable_recovery_fast.py +14 -5
  22. angr/exploration_techniques/tracer.py +2 -0
  23. angr/misc/autoimport.py +26 -0
  24. angr/procedures/definitions/__init__.py +32 -3
  25. angr/utils/constants.py +1 -0
  26. angr/utils/graph.py +20 -1
  27. {angr-9.2.87.dist-info → angr-9.2.89.dist-info}/METADATA +7 -6
  28. {angr-9.2.87.dist-info → angr-9.2.89.dist-info}/RECORD +32 -244
  29. angr-9.2.89.dist-info/top_level.txt +1 -0
  30. angr/procedures/definitions/ntdll.py +0 -12
  31. angr-9.2.87.dist-info/top_level.txt +0 -2
  32. tests/__init__.py +0 -0
  33. tests/analyses/__init__.py +0 -0
  34. tests/analyses/cfg/__init__.py +0 -0
  35. tests/analyses/cfg/test_cfg_clflush.py +0 -43
  36. tests/analyses/cfg/test_cfg_get_any_node.py +0 -34
  37. tests/analyses/cfg/test_cfg_manager.py +0 -32
  38. tests/analyses/cfg/test_cfg_model.py +0 -55
  39. tests/analyses/cfg/test_cfg_patching.py +0 -378
  40. tests/analyses/cfg/test_cfg_rust_got_resolution.py +0 -36
  41. tests/analyses/cfg/test_cfg_thumb_firmware.py +0 -50
  42. tests/analyses/cfg/test_cfg_vex_postprocessor.py +0 -27
  43. tests/analyses/cfg/test_cfgemulated.py +0 -634
  44. tests/analyses/cfg/test_cfgfast.py +0 -1123
  45. tests/analyses/cfg/test_cfgfast_soot.py +0 -38
  46. tests/analyses/cfg/test_const_resolver.py +0 -38
  47. tests/analyses/cfg/test_iat_resolver.py +0 -37
  48. tests/analyses/cfg/test_jumptables.py +0 -3008
  49. tests/analyses/cfg/test_noop_blocks.py +0 -54
  50. tests/analyses/cfg_slice_to_sink/__init__.py +0 -0
  51. tests/analyses/cfg_slice_to_sink/test_cfg_slice_to_sink.py +0 -93
  52. tests/analyses/cfg_slice_to_sink/test_graph.py +0 -114
  53. tests/analyses/cfg_slice_to_sink/test_transitions.py +0 -28
  54. tests/analyses/decompiler/__init__.py +0 -0
  55. tests/analyses/decompiler/test_baseptr_save_simplifier.py +0 -80
  56. tests/analyses/decompiler/test_decompiler.py +0 -3336
  57. tests/analyses/decompiler/test_peephole_optimizations.py +0 -48
  58. tests/analyses/decompiler/test_propagator_loops.py +0 -101
  59. tests/analyses/decompiler/test_structurer.py +0 -275
  60. tests/analyses/reaching_definitions/__init__.py +0 -0
  61. tests/analyses/reaching_definitions/test_dep_graph.py +0 -432
  62. tests/analyses/reaching_definitions/test_function_handler.py +0 -131
  63. tests/analyses/reaching_definitions/test_heap_allocator.py +0 -46
  64. tests/analyses/reaching_definitions/test_rd_state.py +0 -78
  65. tests/analyses/reaching_definitions/test_reachingdefinitions.py +0 -463
  66. tests/analyses/reaching_definitions/test_subject.py +0 -76
  67. tests/analyses/test_bindiff.py +0 -52
  68. tests/analyses/test_block_simplifier.py +0 -112
  69. tests/analyses/test_boyscout.py +0 -104
  70. tests/analyses/test_calling_convention_analysis.py +0 -352
  71. tests/analyses/test_callsite_maker.py +0 -60
  72. tests/analyses/test_cdg.py +0 -165
  73. tests/analyses/test_cfb.py +0 -37
  74. tests/analyses/test_class_identifier.py +0 -46
  75. tests/analyses/test_clinic.py +0 -30
  76. tests/analyses/test_codetagging.py +0 -32
  77. tests/analyses/test_constantpropagation.py +0 -88
  78. tests/analyses/test_ddg.py +0 -95
  79. tests/analyses/test_ddg_global_var_dependencies.py +0 -83
  80. tests/analyses/test_ddg_memvar_addresses.py +0 -40
  81. tests/analyses/test_disassembly.py +0 -121
  82. tests/analyses/test_find_objects_static.py +0 -35
  83. tests/analyses/test_flirt.py +0 -49
  84. tests/analyses/test_identifier.py +0 -33
  85. tests/analyses/test_init_finder.py +0 -38
  86. tests/analyses/test_proximitygraph.py +0 -31
  87. tests/analyses/test_reassembler.py +0 -295
  88. tests/analyses/test_regionidentifier.py +0 -27
  89. tests/analyses/test_slicing.py +0 -164
  90. tests/analyses/test_stack_pointer_tracker.py +0 -74
  91. tests/analyses/test_static_hooker.py +0 -28
  92. tests/analyses/test_typehoon.py +0 -55
  93. tests/analyses/test_variablerecovery.py +0 -464
  94. tests/analyses/test_vfg.py +0 -221
  95. tests/analyses/test_vtable.py +0 -31
  96. tests/analyses/test_xrefs.py +0 -77
  97. tests/common.py +0 -128
  98. tests/engines/__init__.py +0 -0
  99. tests/engines/light/__init__.py +0 -0
  100. tests/engines/light/test_data.py +0 -17
  101. tests/engines/pcode/__init__.py +0 -0
  102. tests/engines/pcode/test_emulate.py +0 -607
  103. tests/engines/pcode/test_pcode.py +0 -84
  104. tests/engines/test_actions.py +0 -27
  105. tests/engines/test_hook.py +0 -112
  106. tests/engines/test_java.py +0 -697
  107. tests/engines/test_unicorn.py +0 -518
  108. tests/engines/vex/__init__.py +0 -0
  109. tests/engines/vex/test_lifter.py +0 -124
  110. tests/engines/vex/test_vex.py +0 -574
  111. tests/exploration_techniques/__init__.py +0 -0
  112. tests/exploration_techniques/test_cacher.py +0 -45
  113. tests/exploration_techniques/test_director.py +0 -67
  114. tests/exploration_techniques/test_driller_core.py +0 -48
  115. tests/exploration_techniques/test_loop_seer.py +0 -158
  116. tests/exploration_techniques/test_memory_watcher.py +0 -46
  117. tests/exploration_techniques/test_oppologist.py +0 -65
  118. tests/exploration_techniques/test_spiller.py +0 -82
  119. tests/exploration_techniques/test_stochastic.py +0 -40
  120. tests/exploration_techniques/test_tech_builder.py +0 -61
  121. tests/exploration_techniques/test_tracer.py +0 -856
  122. tests/exploration_techniques/test_unique.py +0 -40
  123. tests/exploration_techniques/test_veritesting.py +0 -120
  124. tests/factory/__init__.py +0 -0
  125. tests/factory/block/__init__.py +0 -0
  126. tests/factory/block/test_block_cache.py +0 -33
  127. tests/factory/block/test_keystone.py +0 -106
  128. tests/factory/test_argc.py +0 -101
  129. tests/factory/test_argc_sym.py +0 -110
  130. tests/factory/test_argv.py +0 -158
  131. tests/factory/test_callable.py +0 -266
  132. tests/factory/test_windows_args.py +0 -36
  133. tests/knowledge_plugins/__init__.py +0 -0
  134. tests/knowledge_plugins/cfg/__init__.py +0 -0
  135. tests/knowledge_plugins/cfg/test_cfg_manager.py +0 -36
  136. tests/knowledge_plugins/functions/__init__.py +0 -0
  137. tests/knowledge_plugins/functions/test_function.py +0 -91
  138. tests/knowledge_plugins/functions/test_function2.py +0 -79
  139. tests/knowledge_plugins/functions/test_function_manager.py +0 -139
  140. tests/knowledge_plugins/functions/test_prototypes.py +0 -53
  141. tests/knowledge_plugins/key_definitions/__init__.py +0 -0
  142. tests/knowledge_plugins/key_definitions/test_atoms.py +0 -24
  143. tests/knowledge_plugins/key_definitions/test_environment.py +0 -126
  144. tests/knowledge_plugins/key_definitions/test_heap_address.py +0 -27
  145. tests/knowledge_plugins/key_definitions/test_live_definitions.py +0 -72
  146. tests/knowledge_plugins/test_dwarf_variables.py +0 -240
  147. tests/knowledge_plugins/test_kb_plugins.py +0 -91
  148. tests/knowledge_plugins/test_kb_plugins_dwarf.py +0 -36
  149. tests/knowledge_plugins/test_patches.py +0 -48
  150. tests/misc/__init__.py +0 -0
  151. tests/misc/test_hookset.py +0 -57
  152. tests/perf/__init__.py +0 -0
  153. tests/perf/perf_cfgemulated.py +0 -19
  154. tests/perf/perf_cfgfast.py +0 -18
  155. tests/perf/perf_concrete_execution.py +0 -41
  156. tests/perf/perf_siminspect_nop.py +0 -36
  157. tests/perf/perf_state_copy.py +0 -33
  158. tests/perf/perf_unicorn_0.py +0 -27
  159. tests/perf/perf_unicorn_1.py +0 -23
  160. tests/procedures/__init__.py +0 -0
  161. tests/procedures/glibc/__init__.py +0 -0
  162. tests/procedures/glibc/test_ctype_locale.py +0 -164
  163. tests/procedures/libc/__init__.py +0 -0
  164. tests/procedures/libc/test_fgets.py +0 -53
  165. tests/procedures/libc/test_scanf.py +0 -205
  166. tests/procedures/libc/test_sprintf.py +0 -44
  167. tests/procedures/libc/test_sscanf.py +0 -63
  168. tests/procedures/libc/test_strcasecmp.py +0 -37
  169. tests/procedures/libc/test_string.py +0 -1102
  170. tests/procedures/libc/test_strtol.py +0 -78
  171. tests/procedures/linux_kernel/__init__.py +0 -0
  172. tests/procedures/linux_kernel/test_lseek.py +0 -174
  173. tests/procedures/posix/__init__.py +0 -0
  174. tests/procedures/posix/test_chroot.py +0 -33
  175. tests/procedures/posix/test_getenv.py +0 -78
  176. tests/procedures/posix/test_pwrite_pread.py +0 -57
  177. tests/procedures/posix/test_sim_time.py +0 -46
  178. tests/procedures/posix/test_unlink.py +0 -46
  179. tests/procedures/test_project_resolve_simproc.py +0 -43
  180. tests/procedures/test_sim_procedure.py +0 -117
  181. tests/procedures/test_stub_procedure_args.py +0 -53
  182. tests/serialization/__init__.py +0 -0
  183. tests/serialization/test_db.py +0 -197
  184. tests/serialization/test_pickle.py +0 -95
  185. tests/serialization/test_serialization.py +0 -132
  186. tests/serialization/test_vault.py +0 -169
  187. tests/sim/__init__.py +0 -3
  188. tests/sim/exec_func/__init__.py +0 -0
  189. tests/sim/exec_func/test_mem_funcs.py +0 -55
  190. tests/sim/exec_func/test_str_funcs.py +0 -93
  191. tests/sim/exec_func/test_syscall_result.py +0 -39
  192. tests/sim/exec_insn/__init__.py +0 -0
  193. tests/sim/exec_insn/test_adc.py +0 -44
  194. tests/sim/exec_insn/test_ops.py +0 -83
  195. tests/sim/exec_insn/test_rcr.py +0 -26
  196. tests/sim/exec_insn/test_rol.py +0 -51
  197. tests/sim/exec_insn/test_signed_div.py +0 -34
  198. tests/sim/exec_insn/test_sqrt.py +0 -56
  199. tests/sim/options/__init__.py +0 -0
  200. tests/sim/options/test_0div.py +0 -54
  201. tests/sim/options/test_symbolic_fd.py +0 -59
  202. tests/sim/options/test_unsupported.py +0 -34
  203. tests/sim/test_accuracy.py +0 -137
  204. tests/sim/test_checkbyte.py +0 -53
  205. tests/sim/test_echo.py +0 -36
  206. tests/sim/test_fauxware.py +0 -202
  207. tests/sim/test_self_modifying_code.py +0 -65
  208. tests/sim/test_simple_api.py +0 -36
  209. tests/sim/test_simulation_manager.py +0 -147
  210. tests/sim/test_stack_alignment.py +0 -65
  211. tests/sim/test_state.py +0 -303
  212. tests/sim/test_state_customization.py +0 -54
  213. tests/sim/test_symbol_hooked_by.py +0 -49
  214. tests/simos/__init__.py +0 -0
  215. tests/simos/windows/__init__.py +0 -0
  216. tests/simos/windows/test_windows_stack_cookie.py +0 -58
  217. tests/state_plugins/__init__.py +0 -0
  218. tests/state_plugins/inspect/__init__.py +0 -0
  219. tests/state_plugins/inspect/test_inspect.py +0 -310
  220. tests/state_plugins/inspect/test_syscall_override.py +0 -90
  221. tests/state_plugins/posix/__init__.py +0 -0
  222. tests/state_plugins/posix/test_file_struct_funcs.py +0 -56
  223. tests/state_plugins/posix/test_files.py +0 -69
  224. tests/state_plugins/posix/test_posix.py +0 -72
  225. tests/state_plugins/solver/__init__.py +0 -0
  226. tests/state_plugins/solver/test_simsolver.py +0 -58
  227. tests/state_plugins/solver/test_symbolic.py +0 -153
  228. tests/state_plugins/solver/test_variable_registration.py +0 -46
  229. tests/state_plugins/test_callstack.py +0 -54
  230. tests/state_plugins/test_gdb_plugin.py +0 -35
  231. tests/state_plugins/test_multi_open_file.py +0 -47
  232. tests/state_plugins/test_symbolization.py +0 -38
  233. tests/storage/__init__.py +0 -0
  234. tests/storage/test_memory.py +0 -960
  235. tests/storage/test_memory_merge.py +0 -114
  236. tests/storage/test_memview.py +0 -205
  237. tests/storage/test_mmap.py +0 -26
  238. tests/storage/test_multivalues.py +0 -44
  239. tests/storage/test_permissions.py +0 -32
  240. tests/storage/test_ptmalloc.py +0 -291
  241. tests/storage/test_relro_perm.py +0 -49
  242. tests/test_calling_conventions.py +0 -86
  243. tests/test_types.py +0 -329
  244. tests/utils/__init__.py +0 -0
  245. tests/utils/test_graph.py +0 -41
  246. {angr-9.2.87.dist-info → angr-9.2.89.dist-info}/LICENSE +0 -0
  247. {angr-9.2.87.dist-info → angr-9.2.89.dist-info}/WHEEL +0 -0
  248. {angr-9.2.87.dist-info → angr-9.2.89.dist-info}/entry_points.txt +0 -0
@@ -1,65 +0,0 @@
1
- #!/usr/bin/env python3
2
- # pylint: disable=missing-class-docstring,no-self-use,line-too-long
3
- __package__ = __package__ or "tests.sim" # pylint:disable=redefined-builtin
4
-
5
- import logging
6
- import os
7
- import unittest
8
-
9
- from archinfo import all_arches, ArchAMD64, ArchSoot
10
-
11
- from angr.calling_conventions import DEFAULT_CC, default_cc, SimCCUnknown
12
- from angr import SimState, sim_options as o, Project
13
-
14
- from ..common import bin_location
15
-
16
-
17
- test_location = os.path.join(bin_location, "tests")
18
-
19
- log = logging.getLogger(__name__)
20
-
21
-
22
- class TestStackAlignment(unittest.TestCase):
23
- def test_alignment(self):
24
- for arch in all_arches:
25
- if arch.name in DEFAULT_CC and default_cc(arch.name, platform="Linux") is not SimCCUnknown:
26
- # There is nothing to test for soot about stack alignment
27
- if isinstance(arch, ArchSoot):
28
- continue
29
- log.info("Testing stack alignment for %s", arch.name)
30
- st = SimState(arch=arch)
31
- cc = default_cc(arch.name, platform="Linux")(arch=arch)
32
-
33
- st.regs.sp = -1
34
-
35
- # setup callsite with one argument (0x1337), "returning" to 0
36
- cc.setup_callsite(st, 0, [0x1337], "void foo(int x)")
37
-
38
- # ensure stack alignment is correct
39
- assert st.solver.is_true((st.regs.sp + cc.STACKARG_SP_DIFF) % cc.STACK_ALIGNMENT == 0), (
40
- "non-zero stack alignment after setup_callsite for %s" % cc
41
- )
42
-
43
- def test_sys_v_abi_compliance(self):
44
- arch = ArchAMD64()
45
- st = SimState(arch=arch)
46
- cc = default_cc(arch.name, platform="Linux")(arch=arch)
47
-
48
- st.regs.sp = -1
49
-
50
- # setup callsite with one argument (0x1337), "returning" to 0
51
- cc.setup_callsite(st, 0, [0x1337], "void foo(int x)")
52
-
53
- # (rsp+8) must be aligned to 16 as required by System V ABI.
54
- # ref: https://raw.githubusercontent.com/wiki/hjl-tools/x86-psABI/x86-64-psABI-1.0.pdf , page 18t
55
- assert st.solver.is_true((st.regs.rsp + 8) % 16 == 0), "System V ABI calling convention violated!"
56
-
57
- def test_initial_allocation(self):
58
- # not strictly about alignment but it's about stack initialization so whatever
59
- p = Project(os.path.join(test_location, "x86_64", "true"), auto_load_libs=False)
60
- s = p.factory.entry_state(add_options={o.STRICT_PAGE_ACCESS})
61
- s.memory.load(s.regs.sp - 0x10000, size=4)
62
-
63
-
64
- if __name__ == "__main__":
65
- unittest.main()
tests/sim/test_state.py DELETED
@@ -1,303 +0,0 @@
1
- #!/usr/bin/env python3
2
- __package__ = __package__ or "tests.sim" # pylint:disable=redefined-builtin
3
-
4
- import pickle
5
- import gc
6
- import os
7
- import unittest
8
-
9
- import claripy
10
- import cle
11
-
12
- import angr
13
- from angr import SimState
14
-
15
- from ..common import bin_location
16
-
17
-
18
- test_location = os.path.join(bin_location, "tests")
19
-
20
-
21
- class TestState(unittest.TestCase):
22
- def test_state(self):
23
- s = SimState(arch="AMD64")
24
- s.registers.store("sp", 0x7FFFFFFFFFF0000)
25
- assert s.solver.eval(s.registers.load("sp")) == 0x7FFFFFFFFFF0000
26
-
27
- s.stack_push(s.solver.BVV(b"ABCDEFGH"))
28
- assert s.solver.eval(s.registers.load("sp")) == 0x7FFFFFFFFFEFFF8
29
- s.stack_push(s.solver.BVV(b"IJKLMNOP"))
30
- assert s.solver.eval(s.registers.load("sp")) == 0x7FFFFFFFFFEFFF0
31
-
32
- a = s.stack_pop()
33
- assert s.solver.eval(s.registers.load("sp")) == 0x7FFFFFFFFFEFFF8
34
- assert s.solver.eval(a, cast_to=bytes) == b"IJKLMNOP"
35
-
36
- b = s.stack_pop()
37
- assert s.solver.eval(s.registers.load("sp")) == 0x7FFFFFFFFFF0000
38
- assert s.solver.eval(b, cast_to=bytes) == b"ABCDEFGH"
39
-
40
- def test_state_merge(self):
41
- a = SimState(arch="AMD64", mode="symbolic")
42
- a.memory.store(1, a.solver.BVV(42, 8))
43
-
44
- b = a.copy()
45
- c = b.copy()
46
- a.memory.store(2, a.memory.load(1, 1) + 1)
47
- b.memory.store(2, b.memory.load(1, 1) * 2)
48
- c.memory.store(2, c.memory.load(1, 1) / 2)
49
-
50
- # make sure the byte at 1 is right
51
- assert a.solver.eval(a.memory.load(1, 1)) == 42
52
- assert b.solver.eval(b.memory.load(1, 1)) == 42
53
- assert c.solver.eval(c.memory.load(1, 1)) == 42
54
-
55
- # make sure the byte at 2 is right
56
- assert a.solver.eval(a.memory.load(2, 1)) == 43
57
- assert b.solver.eval(b.memory.load(2, 1)) == 84
58
- assert c.solver.eval(c.memory.load(2, 1)) == 21
59
-
60
- # the byte at 2 should be unique for all before the merge
61
- assert a.solver.unique(a.memory.load(2, 1))
62
- assert b.solver.unique(b.memory.load(2, 1))
63
- assert c.solver.unique(c.memory.load(2, 1))
64
-
65
- # logging.getLogger('angr.state_plugins.symbolic_memory').setLevel(logging.DEBUG)
66
- m, merge_conditions, merging_occurred = a.merge(b, c)
67
- # logging.getLogger('angr.state_plugins.symbolic_memory').setLevel(logging.WARNING)
68
-
69
- assert merging_occurred
70
- # assert sorted(m.solver.eval_upto(merge_flag, 10)) == [ 0,1,2 ]
71
- assert len(merge_conditions) == 3
72
-
73
- # the byte at 2 should now *not* be unique for a
74
- assert not m.solver.unique(m.memory.load(2, 1))
75
- assert a.solver.unique(a.memory.load(2, 1))
76
- assert b.solver.unique(b.memory.load(2, 1))
77
- assert c.solver.unique(c.memory.load(2, 1))
78
-
79
- # the byte at 2 should have the three values
80
- self.assertSequenceEqual(sorted(m.solver.eval_upto(m.memory.load(2, 1), 10)), (21, 43, 84))
81
-
82
- # we should be able to select them by adding constraints
83
- a_a = m.copy()
84
- a_a.add_constraints(merge_conditions[0])
85
- assert a_a.solver.unique(a_a.memory.load(2, 1))
86
- assert a_a.solver.eval(a_a.memory.load(2, 1)) == 43
87
-
88
- a_b = m.copy()
89
- a_b.add_constraints(merge_conditions[1])
90
- assert a_b.solver.unique(a_b.memory.load(2, 1))
91
- assert a_b.solver.eval(a_b.memory.load(2, 1)) == 84
92
-
93
- a_c = m.copy()
94
- a_c.add_constraints(merge_conditions[2])
95
- assert a_c.solver.unique(a_c.memory.load(2, 1))
96
- assert a_c.solver.eval(a_c.memory.load(2, 1)) == 21
97
-
98
- # test different sets of plugins
99
- a = SimState(arch="AMD64", mode="symbolic")
100
- assert a.has_plugin("memory")
101
- assert a.has_plugin("registers")
102
- assert not a.has_plugin("libc")
103
-
104
- b = a.copy()
105
- a.get_plugin("libc")
106
- assert a.has_plugin("libc")
107
- assert not b.has_plugin("libc")
108
- c = a.copy().merge(b.copy())[0]
109
- d = b.copy().merge(a.copy())[0]
110
- assert c.has_plugin("libc")
111
- assert d.has_plugin("libc")
112
-
113
- # test merging posix with different open files (illegal!)
114
- a = SimState(arch="AMD64", mode="symbolic")
115
- b = a.copy()
116
- a.posix.open(b"/tmp/idk", 1)
117
- self.assertRaises(angr.errors.SimMergeError, lambda: a.copy().merge(b.copy()))
118
-
119
- def test_state_merge_static(self):
120
- # With abstract memory
121
- # Aligned memory merging
122
- a = SimState(arch="AMD64", mode="static")
123
-
124
- addr = a.solver.ValueSet(32, "global", 0, 8)
125
- a.memory.store(addr, a.solver.BVV(42, 32))
126
- # Clear a_locs, so further writes will not try to merge with value 42
127
- a.memory._regions["global"]._alocs = {}
128
-
129
- b = a.copy()
130
- c = a.copy()
131
- a.memory.store(addr, a.solver.BVV(50, 32), endness="Iend_LE")
132
- b.memory.store(addr, a.solver.BVV(60, 32), endness="Iend_LE")
133
- c.memory.store(addr, a.solver.BVV(70, 32), endness="Iend_LE")
134
-
135
- merged, _, _ = a.merge(b, c)
136
- actual = claripy.backends.vsa.convert(merged.memory.load(addr, 4, endness="Iend_LE"))
137
- expected = claripy.backends.vsa.convert(a.solver.SI(bits=32, stride=10, lower_bound=50, upper_bound=70))
138
- assert actual.identical(expected)
139
-
140
- def test_state_merge_3way(self):
141
- a = SimState(arch="AMD64", mode="symbolic")
142
- b = a.copy()
143
- c = a.copy()
144
- conds = [a.solver.BoolS("cond_0"), a.solver.BoolS("cond_1")]
145
- a.add_constraints(conds[0])
146
- b.add_constraints(a.solver.Not(conds[0]), conds[1])
147
- c.add_constraints(a.solver.Not(conds[0]), a.solver.Not(conds[1]))
148
-
149
- a.memory.store(0x400000, a.solver.BVV(8, 32))
150
- b.memory.store(0x400000, b.solver.BVV(9, 32))
151
- c.memory.store(0x400000, c.solver.BVV(10, 32))
152
-
153
- m, _, _ = a.merge(b)
154
- m, _, _ = m.merge(c)
155
-
156
- assert m.satisfiable(extra_constraints=(m.memory.load(0x400000, 4) == 8,))
157
- assert m.satisfiable(extra_constraints=(m.memory.load(0x400000, 4) == 9,))
158
- assert m.satisfiable(extra_constraints=(m.memory.load(0x400000, 4) == 10,))
159
-
160
- def test_state_merge_optimal_nostrongrefstate(self):
161
- # We do not specify the state option EFFICIENT_STATE_MERGING, and as a result, state histories do not store
162
- # strong # references to states. This will result in less efficient state merging since SimStateHistory will be
163
- # the only # state plugin that knows the common ancestor of all instances to merge. But it should still succeed.
164
-
165
- binary_path = os.path.join(test_location, "x86_64", "state_merge_0")
166
- p = angr.Project(binary_path, auto_load_libs=False)
167
- sm = p.factory.simulation_manager()
168
-
169
- sm.explore(find=0x400616, num_find=3)
170
-
171
- var_addr = 0x601044
172
-
173
- sm.merge(stash="found")
174
- s = sm.one_found
175
- culprit = s.mem[var_addr].dword.resolved
176
-
177
- for i in range(8, 11):
178
- assert i, s.solver.satisfiable(extra_constraints=(culprit == i,))
179
-
180
- assert not s.solver.satisfiable(extra_constraints=(culprit == 12,))
181
-
182
- def test_state_merge_optimal(self):
183
- # Unlike the above test case, EFFICIENT_STATE_MERGING is enabled here
184
-
185
- binary_path = os.path.join(test_location, "x86_64", "state_merge_0")
186
- p = angr.Project(binary_path, auto_load_libs=False)
187
- state = p.factory.blank_state(add_options={angr.sim_options.EFFICIENT_STATE_MERGING})
188
- sm = p.factory.simulation_manager(state)
189
-
190
- sm.explore(find=0x400616, num_find=3)
191
-
192
- var_addr = 0x601044
193
-
194
- sm.merge(stash="found")
195
- s = sm.one_found
196
- culprit = s.mem[var_addr].dword.resolved
197
-
198
- for i in range(8, 11):
199
- assert i, s.solver.satisfiable(extra_constraints=(culprit == i,))
200
-
201
- assert not s.solver.satisfiable(extra_constraints=(culprit == 12,))
202
-
203
- def test_state_pickle(self):
204
- s = SimState(arch="AMD64")
205
- s.memory.store(100, s.solver.BVV(0x4141414241414241424300, 88), endness="Iend_BE")
206
- s.regs.rax = 100
207
-
208
- sp = pickle.dumps(s)
209
- del s
210
- gc.collect()
211
- s = pickle.loads(sp)
212
- assert s.solver.eval(s.memory.load(100, 10), cast_to=bytes) == b"AAABAABABC"
213
-
214
- def test_global_condition(self):
215
- s = SimState(arch="AMD64")
216
-
217
- s.regs.rax = 10
218
- old_rax = s.regs.rax
219
- with s.with_condition(False):
220
- assert not s.solver.satisfiable()
221
- s.regs.rax = 20
222
- assert s._global_condition is None
223
- assert old_rax is s.regs.rax
224
-
225
- with s.with_condition(True):
226
- s.regs.rax = 20
227
- assert s._global_condition is None
228
- assert old_rax is not s.regs.rax
229
- assert s.solver.BVV(20, s.arch.bits) is s.regs.rax
230
-
231
- with s.with_condition(s.regs.rbx != 0):
232
- s.regs.rax = 25
233
- assert s._global_condition is None
234
- assert s.solver.BVV(25, s.arch.bits) is not s.regs.rax
235
-
236
- with s.with_condition(s.regs.rbx != 1):
237
- s.regs.rax = 30
238
- assert s._global_condition is None
239
- assert s.solver.BVV(30, s.arch.bits) is not s.regs.rax
240
-
241
- with s.with_condition(s.regs.rbx == 0):
242
- assert s.solver.eval_upto(s.regs.rbx, 10) == [0]
243
- assert s.solver.eval_upto(s.regs.rax, 10) == [30]
244
- with s.with_condition(s.regs.rbx == 1):
245
- assert s.solver.eval_upto(s.regs.rbx, 10) == [1]
246
- assert s.solver.eval_upto(s.regs.rax, 10) == [25]
247
-
248
- def test_successors_catch_arbitrary_interrupts(self):
249
- # int 0xd2 should fail on x86/amd64 since it's an unsupported interrupt
250
- block_bytes = b"\xcd\xd2"
251
-
252
- proj = angr.load_shellcode(block_bytes, "amd64")
253
- proj.loader._tls = cle.backends.tls.ELFThreadManager(proj.loader, proj.arch)
254
- proj.simos = angr.simos.SimLinux(proj)
255
- proj.simos.configure_project()
256
- state = proj.factory.blank_state(addr=0)
257
- simgr = proj.factory.simgr(state)
258
-
259
- simgr.step()
260
-
261
- assert (
262
- len(simgr.errored) == 0
263
- ), "The state should not go to the errored stash. Is AngrSyscallError handled in SimSuccessors?"
264
- assert len(simgr.unsat) == 1
265
-
266
- def test_bypass_errored_irstmt(self):
267
- # fild [esp+4] will fail when ftop is unspecified
268
- # BYPASS_ERRORED_IRSTMT will suppress it
269
-
270
- block_bytes = b"\xdb\x44\x24\x04"
271
-
272
- proj = angr.load_shellcode(block_bytes, "x86")
273
- state = proj.factory.blank_state(
274
- addr=0,
275
- mode="fastpath",
276
- cle_memory_backer=proj.loader.memory,
277
- add_options={angr.sim_options.FAST_REGISTERS},
278
- remove_options={angr.sim_options.BYPASS_ERRORED_IRSTMT},
279
- )
280
-
281
- # destroy esp
282
- state.regs._esp = state.solver.BVS("unknown_rsp", 32)
283
- state.regs._ftop = state.solver.BVS("unknown_ftop", 32)
284
-
285
- # there should be one errored state if we step the state further without BYPASS_ERRORED_IRSTMT
286
- simgr = proj.factory.simgr(state)
287
- simgr.step()
288
- assert len(simgr.errored) == 1
289
- assert (
290
- str(simgr.errored[0].error) == "address not supported"
291
- ), "Does SimFastMemory support reading from a symbolic address?"
292
-
293
- # try it with BYPASS_ERRORED_IRSTMT
294
- state.options.add(angr.sim_options.BYPASS_ERRORED_IRSTMT)
295
- simgr = proj.factory.simgr(state)
296
- simgr.step()
297
-
298
- assert len(simgr.errored) == 0
299
- assert len(simgr.active) == 1
300
-
301
-
302
- if __name__ == "__main__":
303
- unittest.main()
@@ -1,54 +0,0 @@
1
- #!/usr/bin/env python3
2
- # pylint: disable=missing-class-docstring,no-self-use,line-too-long
3
- __package__ = __package__ or "tests.sim" # pylint:disable=redefined-builtin
4
-
5
- import glob
6
- import os
7
- import unittest
8
-
9
- import angr
10
-
11
- from ..common import bin_location
12
-
13
-
14
- test_location = os.path.join(bin_location, "tests")
15
-
16
-
17
- class TestStateCustomization(unittest.TestCase):
18
- def test_stack_end(self):
19
- for fn in glob.glob(os.path.join(test_location, "*", "fauxware")):
20
- p = angr.Project(fn, auto_load_libs=False)
21
-
22
- # normal state
23
- s = p.factory.full_init_state()
24
- offset = s.solver.eval(p.arch.initial_sp - s.regs.sp)
25
-
26
- # different stack ends
27
- for n in [0x1337000, 0xBAAAAA00, 0x100, 0xFFFFFF00, 0x13371337000, 0xBAAAAAAA0000, 0xFFFFFFFFFFFFFF00]:
28
- if n.bit_length() > p.arch.bits:
29
- continue
30
- s = p.factory.full_init_state(stack_end=n)
31
- assert s.solver.eval_one(s.regs.sp + offset == n)
32
-
33
- def test_execstack(self):
34
- bin_path = os.path.join(test_location, "x86_64", "fauxware")
35
- proj = angr.Project(bin_path, auto_load_libs=False)
36
- # manually mark the stack as executable
37
- proj.loader.main_object.execstack = True
38
- s = proj.factory.blank_state()
39
- assert s.memory._stack_perms == 7
40
-
41
- def test_brk(self):
42
- for fn in glob.glob(os.path.join(test_location, "*", "fauxware")):
43
- p = angr.Project(fn, auto_load_libs=False)
44
-
45
- # different stack ends
46
- for n in [0x1337000, 0xBAAAAA00, 0x100, 0xFFFFFF00, 0x13371337000, 0xBAAAAAAA0000, 0xFFFFFFFFFFFFFF00]:
47
- if n.bit_length() > p.arch.bits:
48
- continue
49
- s = p.factory.full_init_state(brk=n)
50
- assert s.solver.eval_one(s.posix.brk == n)
51
-
52
-
53
- if __name__ == "__main__":
54
- unittest.main()
@@ -1,49 +0,0 @@
1
- #!/usr/bin/env python3
2
- # pylint:disable=missing-class-docstring,no-self-use,arguments-differ,unused-argument
3
- __package__ = __package__ or "tests.sim" # pylint:disable=redefined-builtin
4
-
5
- import os
6
- import unittest
7
-
8
- import angr
9
-
10
- from ..common import bin_location
11
-
12
-
13
- test_location = os.path.join(bin_location, "tests")
14
-
15
-
16
- class TestSymbolHookedBy(unittest.TestCase):
17
- def test_hook_symbol(self):
18
- """
19
- Test the hook_symbol (and related functions) useing the inet_ntoa simprocedure for functionality
20
- """
21
- bin_path = os.path.join(test_location, "x86_64", "inet_ntoa")
22
- proj = angr.Project(bin_path, auto_load_libs=False, use_sim_procedures=True)
23
-
24
- assert proj.is_symbol_hooked("inet_ntoa")
25
- assert not proj.is_symbol_hooked("not_expected_to_exist")
26
-
27
- original_hook = proj.symbol_hooked_by("inet_ntoa")
28
-
29
- assert isinstance(original_hook, angr.SIM_PROCEDURES["posix"]["inet_ntoa"])
30
-
31
- # No intention to call this, just checking hooking
32
- class FakeInetNtoa(angr.SimProcedure):
33
- def run(self, in_addr):
34
- return None
35
-
36
- fake_inet_ntoa = FakeInetNtoa()
37
-
38
- # test not allowing replacement
39
- proj.hook_symbol("inet_ntoa", fake_inet_ntoa, replace=False)
40
- assert proj.symbol_hooked_by("inet_ntoa") == original_hook
41
-
42
- # test allowing replacement
43
- proj.hook_symbol("inet_ntoa", fake_inet_ntoa, replace=True)
44
- assert proj.symbol_hooked_by("inet_ntoa") != original_hook
45
- assert proj.symbol_hooked_by("inet_ntoa") == fake_inet_ntoa
46
-
47
-
48
- if __name__ == "__main__":
49
- unittest.main()
tests/simos/__init__.py DELETED
File without changes
File without changes
@@ -1,58 +0,0 @@
1
- #!/usr/bin/env python3
2
- __package__ = __package__ or "tests.simos.windows" # pylint:disable=redefined-builtin
3
-
4
- import os
5
- import struct
6
- import unittest
7
-
8
- import angr
9
- import angr.simos.windows
10
-
11
- from ...common import bin_location
12
-
13
-
14
- test_location = os.path.join(bin_location, "tests")
15
-
16
-
17
- def compare_none(state, test_value):
18
- test_value = test_value.concrete
19
- correct_value = angr.simos.windows.VS_SECURITY_COOKIES[state.arch.name].default
20
- assert test_value == correct_value
21
-
22
-
23
- def compare_random(state, test_value):
24
- test_value = test_value.concrete
25
- incorrect_value = angr.simos.windows.VS_SECURITY_COOKIES[state.arch.name].default
26
- assert test_value != incorrect_value
27
-
28
-
29
- def compare_static(state, test_value):
30
- test_value = test_value.concrete
31
- correct_value = struct.unpack(">I", b"cook")[0]
32
- assert test_value == correct_value
33
-
34
-
35
- def compare_symbolic(state, test_value):
36
- assert test_value.resolved.symbolic
37
-
38
-
39
- def check_value(project, init_type, comparison):
40
- main_object = project.loader.main_object
41
- state = project.factory.blank_state(security_cookie_init=init_type)
42
- value = getattr(state.mem[main_object.load_config["SecurityCookie"]], f"uint{state.arch.bits}_t")
43
- comparison(state, value)
44
-
45
-
46
- class TestWindowsStackCookie(unittest.TestCase):
47
- def test_security_cookie_init(self):
48
- project = angr.Project(os.path.join(test_location, "i386", "test_arrays.exe"), auto_load_libs=False)
49
- check_value(project, angr.simos.windows.SecurityCookieInit.NONE, compare_none)
50
- check_value(project, angr.simos.windows.SecurityCookieInit.RANDOM, compare_random)
51
- check_value(project, angr.simos.windows.SecurityCookieInit.STATIC, compare_static)
52
- check_value(project, angr.simos.windows.SecurityCookieInit.SYMBOLIC, compare_symbolic)
53
-
54
- self.assertRaises(TypeError, project.factory.blank_state, security_cookie_init=1)
55
-
56
-
57
- if __name__ == "__main__":
58
- unittest.main()
File without changes
File without changes