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,518 +0,0 @@
1
- #!/usr/bin/env python3
2
- # pylint: disable=missing-class-docstring,no-self-use,line-too-long
3
- __package__ = __package__ or "tests.engines" # pylint:disable=redefined-builtin
4
-
5
- import gc
6
- import os
7
- import pickle
8
- import platform
9
- import re
10
- import sys
11
- import unittest
12
-
13
- import angr
14
- from angr import options as so
15
-
16
- from ..common import bin_location, broken, slow_test
17
-
18
- test_location = os.path.join(bin_location, "tests")
19
-
20
-
21
- def _remove_addr_from_trace_item(trace_item_str):
22
- m = re.match(r"(<\S+ \S+) from 0x[0-9a-f]+(:[\s\S]+)", trace_item_str)
23
- if m is None:
24
- return None
25
- return m.group(1) + m.group(2)
26
-
27
-
28
- def _compare_trace(trace, expected):
29
- assert len(trace) == len(expected)
30
-
31
- for trace_item, expected_str in zip(trace, expected):
32
- trace_item_str = str(trace_item)
33
- if trace_item_str.startswith("<SimProcedure"):
34
- # we do not care if addresses of SimProcedures match, since they are not allocated in a deterministic way
35
- trace_item_str = _remove_addr_from_trace_item(trace_item_str)
36
- expected_str = _remove_addr_from_trace_item(expected_str)
37
-
38
- assert trace_item_str == expected_str
39
-
40
-
41
- @unittest.skipIf(sys.platform == "win32", "broken on windows")
42
- @unittest.skipIf(platform.system() == "Darwin" and platform.machine() == "arm64", "broken on apple silicon")
43
- class TestUnicorn(unittest.TestCase):
44
- def test_stops(self):
45
- p = angr.Project(os.path.join(test_location, "i386", "uc_stop"), auto_load_libs=False)
46
-
47
- # test STOP_NORMAL, STOP_STOPPOINT
48
- s_normal = p.factory.entry_state(args=["a"], add_options=so.unicorn)
49
- s_normal.unicorn.max_steps = 100
50
- pg_normal = p.factory.simulation_manager(s_normal).run()
51
- p_normal = pg_normal.one_deadended
52
- _compare_trace(
53
- p_normal.history.descriptions,
54
- [
55
- "<Unicorn (STOP_STOPPOINT after 4 steps) from 0x8048340: 1 sat>",
56
- "<SimProcedure __libc_start_main from 0x8119990: 1 sat>",
57
- "<Unicorn (STOP_STOPPOINT after 14 steps) from 0x8048650: 1 sat>",
58
- "<SimProcedure __libc_start_main from 0x8400044: 1 sat>",
59
- "<Unicorn (STOP_NORMAL after 100 steps) from 0x80485b5: 1 sat>",
60
- "<Unicorn (STOP_STOPPOINT after 12 steps) from 0x804846f: 1 sat>",
61
- "<SimProcedure __libc_start_main from 0x8400048: 1 sat>",
62
- ],
63
- )
64
-
65
- s_normal_angr = p.factory.entry_state(args=["a"])
66
- pg_normal_angr = p.factory.simulation_manager(s_normal_angr).run()
67
- p_normal_angr = pg_normal_angr.one_deadended
68
- assert p_normal_angr.history.bbl_addrs.hardcopy == p_normal.history.bbl_addrs.hardcopy
69
-
70
- # test STOP_STOPPOINT on an address that is not a basic block start
71
- s_stoppoints = p.factory.call_state(
72
- p.loader.find_symbol("main").rebased_addr, 1, angr.PointerWrapper([]), add_options=so.unicorn
73
- )
74
-
75
- # this address is right before/after the bb for the stop_normal() function ends
76
- # we should not stop there, since that code is never hit
77
- stop_fake = [0x0804847C, 0x08048454]
78
-
79
- # this is an address inside main that is not the beginning of a basic block. we should stop here
80
- stop_in_bb = 0x08048638
81
- stop_bb = 0x08048633 # basic block of the above address
82
- pg_stoppoints = p.factory.simulation_manager(s_stoppoints).run(n=1, extra_stop_points=stop_fake + [stop_in_bb])
83
- assert len(pg_stoppoints.active) == 1
84
- p_stoppoints = pg_stoppoints.one_active
85
- assert p_stoppoints.addr == stop_bb
86
- _compare_trace(
87
- p_stoppoints.history.descriptions,
88
- ["<Unicorn (STOP_STOPPOINT after 111 steps) from 0x80485b5: 1 sat>"],
89
- )
90
-
91
- # test STOP_SYMBOLIC_READ_SYMBOLIC_TRACKING_DISABLED
92
- s_symbolic_read_tracking_disabled = p.factory.entry_state(
93
- args=["a", "a"],
94
- add_options=so.unicorn,
95
- remove_options={so.UNICORN_SYM_REGS_SUPPORT},
96
- )
97
- pg_symbolic_read_tracking_disabled = p.factory.simulation_manager(s_symbolic_read_tracking_disabled).run()
98
- p_symbolic_read_tracking_disabled = pg_symbolic_read_tracking_disabled.one_deadended
99
- _compare_trace(
100
- p_symbolic_read_tracking_disabled.history.descriptions,
101
- [
102
- "<Unicorn (STOP_STOPPOINT after 4 steps) from 0x8048340: 1 sat>",
103
- "<SimProcedure __libc_start_main from 0x8119990: 1 sat>",
104
- "<Unicorn (STOP_STOPPOINT after 14 steps) from 0x8048650: 1 sat>",
105
- "<SimProcedure __libc_start_main from 0x8400044: 1 sat>",
106
- "<Unicorn (STOP_SYMBOLIC_READ_SYMBOLIC_TRACKING_DISABLED after 7 steps) from 0x80485b5: 1 sat>",
107
- "<IRSB from 0x804848a: 1 sat 3 unsat>",
108
- "<Unicorn (STOP_STOPPOINT after 3 steps) from 0x80484bb: 1 sat>",
109
- "<SimProcedure __libc_start_main from 0x8400048: 1 sat>",
110
- ],
111
- )
112
-
113
- s_symbolic_read_tracking_disabled_angr = p.factory.entry_state(args=["a", "a"])
114
- pg_symbolic_read_tracking_disabled_angr = p.factory.simulation_manager(
115
- s_symbolic_read_tracking_disabled_angr
116
- ).run()
117
- p_symbolic_read_tracking_disabled_angr = pg_symbolic_read_tracking_disabled_angr.one_deadended
118
- assert (
119
- p_symbolic_read_tracking_disabled_angr.history.bbl_addrs.hardcopy
120
- == p_symbolic_read_tracking_disabled.history.bbl_addrs.hardcopy
121
- )
122
-
123
- # test STOP_SEGFAULT
124
- s_segfault = p.factory.entry_state(
125
- args=["a", "a", "a", "a", "a", "a", "a"],
126
- add_options=so.unicorn | {so.STRICT_PAGE_ACCESS, so.ENABLE_NX},
127
- )
128
- pg_segfault = p.factory.simulation_manager(s_segfault).run()
129
- p_segfault = pg_segfault.errored[0].state
130
- # TODO: fix the permissions segfault to commit if it's a MEM_FETCH
131
- # this will extend the last simunicorn one more block
132
- _compare_trace(
133
- p_segfault.history.descriptions,
134
- [
135
- "<Unicorn (STOP_STOPPOINT after 4 steps) from 0x8048340: 1 sat>",
136
- "<SimProcedure __libc_start_main from 0x8119990: 1 sat>",
137
- "<Unicorn (STOP_STOPPOINT after 14 steps) from 0x8048650: 1 sat>",
138
- "<SimProcedure __libc_start_main from 0x8400044: 1 sat>",
139
- "<Unicorn (STOP_SEGFAULT after 7 steps) from 0x80485b5: 1 sat>",
140
- "<IRSB from 0x8048508: 1 sat>",
141
- ],
142
- )
143
-
144
- s_segfault_angr = p.factory.entry_state(
145
- args=["a", "a", "a", "a", "a", "a", "a"],
146
- add_options={so.STRICT_PAGE_ACCESS, so.ENABLE_NX},
147
- )
148
- pg_segfault_angr = p.factory.simulation_manager(s_segfault_angr).run()
149
- p_segfault_angr = pg_segfault_angr.errored[0].state
150
- assert p_segfault_angr.history.bbl_addrs.hardcopy == p_segfault.history.bbl_addrs.hardcopy
151
- assert pg_segfault_angr.errored[0].error.addr == pg_segfault.errored[0].error.addr
152
-
153
- # test STOP_SYMBOLIC_BLOCK_EXIT
154
- s_symbolic_exit = p.factory.entry_state(args=["a"] * 10, add_options=so.unicorn)
155
- pg_symbolic_exit = p.factory.simulation_manager(s_symbolic_exit).run()
156
- p_symbolic_exit = pg_symbolic_exit.one_deadended
157
- _compare_trace(
158
- p_symbolic_exit.history.descriptions,
159
- [
160
- "<Unicorn (STOP_STOPPOINT after 4 steps) from 0x8048340: 1 sat>",
161
- "<SimProcedure __libc_start_main from 0x8119990: 1 sat>",
162
- "<Unicorn (STOP_STOPPOINT after 14 steps) from 0x8048650: 1 sat>",
163
- "<SimProcedure __libc_start_main from 0x8400044: 1 sat>",
164
- "<Unicorn (STOP_SYMBOLIC_BLOCK_EXIT_CONDITION after 7 steps) from 0x80485b5: 1 sat>",
165
- "<IRSB from 0x804855d: 2 sat 1 unsat>",
166
- "<Unicorn (STOP_STOPPOINT after 4 steps) from 0x8048587: 1 sat>",
167
- "<SimProcedure __libc_start_main from 0x8400048: 1 sat>",
168
- ],
169
- )
170
-
171
- s_symbolic_exit_angr = p.factory.entry_state(args=["a"] * 10)
172
- pg_symbolic_exit_angr = p.factory.simulation_manager(s_symbolic_exit_angr).run()
173
- p_symbolic_exit_angr = pg_symbolic_exit_angr.one_deadended
174
- assert p_symbolic_exit_angr.history.bbl_addrs.hardcopy == p_symbolic_exit.history.bbl_addrs.hardcopy
175
-
176
- @staticmethod
177
- def _run_longinit(arch):
178
- p = angr.Project(os.path.join(test_location, arch, "longinit"), auto_load_libs=False)
179
- s_unicorn = p.factory.entry_state(add_options=so.unicorn, remove_options={so.SHORT_READS})
180
- pg = p.factory.simulation_manager(s_unicorn, save_unconstrained=True, save_unsat=True)
181
- pg.explore()
182
- s = pg.deadended[0]
183
- (first, _), (second, _) = s.posix.stdin.content
184
- s.add_constraints(first == s.solver.BVV(b"A" * 9))
185
- s.add_constraints(second == s.solver.BVV(b"B" * 9))
186
- assert s.posix.dumps(1) == b"You entered AAAAAAAAA and BBBBBBBBB!\n"
187
-
188
- def test_longinit_i386(self):
189
- self._run_longinit("i386")
190
-
191
- def test_longinit_x86_64(self):
192
- self._run_longinit("x86_64")
193
-
194
- @broken
195
- def test_fauxware_arm(self):
196
- p = angr.Project(os.path.join(test_location, "armel", "fauxware"), auto_load_libs=False)
197
- s_unicorn = p.factory.entry_state(add_options=so.unicorn) # unicorn
198
- pg = p.factory.simulation_manager(s_unicorn)
199
- pg.explore()
200
- assert all("Unicorn" in "".join(p.history.descriptions.hardcopy) for p in pg.deadended)
201
- assert sorted(pg.mp_deadended.posix.dumps(1).mp_items) == sorted(
202
- (
203
- b"Username: \nPassword: \nWelcome to the admin console, trusted user!\n",
204
- b"Username: \nPassword: \nGo away!",
205
- b"Username: \nPassword: \nWelcome to the admin console, trusted user!\n",
206
- )
207
- )
208
-
209
- def test_fauxware(self):
210
- p = angr.Project(os.path.join(test_location, "i386", "fauxware"), auto_load_libs=False)
211
- s_unicorn = p.factory.entry_state(add_options=so.unicorn) # unicorn
212
- pg = p.factory.simulation_manager(s_unicorn)
213
- pg.explore()
214
-
215
- assert all("Unicorn" in "".join(p.history.descriptions.hardcopy) for p in pg.deadended)
216
- assert sorted(pg.mp_deadended.posix.dumps(1).mp_items) == sorted(
217
- (
218
- b"Username: \nPassword: \nWelcome to the admin console, trusted user!\n",
219
- b"Username: \nPassword: \nGo away!",
220
- b"Username: \nPassword: \nWelcome to the admin console, trusted user!\n",
221
- )
222
- )
223
-
224
- def test_fauxware_aggressive(self):
225
- p = angr.Project(os.path.join(test_location, "i386", "fauxware"), auto_load_libs=False)
226
- s_unicorn = p.factory.entry_state(
227
- add_options=so.unicorn | {so.UNICORN_AGGRESSIVE_CONCRETIZATION},
228
- remove_options={so.LAZY_SOLVES},
229
- ) # unicorn
230
- s_unicorn.unicorn.cooldown_symbolic_stop = 2
231
- s_unicorn.unicorn.cooldown_unsupported_stop = 2
232
- s_unicorn.unicorn.cooldown_nonunicorn_blocks = 0
233
-
234
- pg = p.factory.simulation_manager(s_unicorn)
235
- pg.explore()
236
-
237
- assert len(pg.deadended) == 1
238
-
239
- def test_partial_reads(self):
240
- """
241
- This test case if unicorn engine correctly handles case when symbolic taint is introduced by the second partial
242
- read performed by unicorn. Unicorn triggers memory read hook twice when reading value greater than 8 bytes on
243
- x86-64.
244
- """
245
-
246
- p = angr.Project(
247
- os.path.join(test_location, "x86_64", "test_partial_reads_handling_in_unicorn"),
248
- auto_load_libs=False,
249
- )
250
- # Do not treat as uninitialized memory as symbolic. Prevents introducing undesired symbolic taint
251
- init_state = p.factory.full_init_state(add_options=so.unicorn | {so.ZERO_FILL_UNCONSTRAINED_MEMORY})
252
- global_var_val = [
253
- init_state.solver.BVV(0x41414141, 32),
254
- init_state.solver.BVV(0x42424242, 32),
255
- init_state.solver.BVS("symb_val_0", 32),
256
- init_state.solver.BVS("symb_val_1", 32),
257
- ]
258
- global_var_symb = p.loader.find_symbol("global_var")
259
- # Store every byte separately so that entire variable is not treated as symbolic
260
- for count, val in enumerate(global_var_val):
261
- init_state.memory.store(
262
- global_var_symb.rebased_addr + count * 4, val, endness=init_state.arch.memory_endness
263
- )
264
-
265
- pg = p.factory.simulation_manager(init_state)
266
- pg.run()
267
- assert len(pg.deadended) == 1
268
-
269
- @staticmethod
270
- def _run_similarity(binpath, depth, prehook=None):
271
- b = angr.Project(os.path.join(test_location, binpath), auto_load_libs=False)
272
- cc = b.analyses.CongruencyCheck(throw=True)
273
- cc.set_state_options(
274
- left_add_options=so.unicorn,
275
- left_remove_options={
276
- so.LAZY_SOLVES,
277
- so.TRACK_MEMORY_MAPPING,
278
- so.COMPOSITE_SOLVER,
279
- },
280
- right_add_options={so.ZERO_FILL_UNCONSTRAINED_REGISTERS},
281
- right_remove_options={
282
- so.LAZY_SOLVES,
283
- so.TRACK_MEMORY_MAPPING,
284
- so.COMPOSITE_SOLVER,
285
- },
286
- )
287
- if prehook:
288
- cc.simgr = prehook(cc.simgr)
289
- cc.run(depth=depth)
290
-
291
- @slow_test
292
- def test_similarity_fauxware(self):
293
- def cooldown(pg):
294
- # gotta skip the initializers because of cpuid and RDTSC
295
- pg.one_left.unicorn.countdown_nonunicorn_blocks = 39
296
- return pg
297
-
298
- self._run_similarity(os.path.join("i386", "fauxware"), 1000, prehook=cooldown)
299
-
300
- def test_fp(self):
301
- with open(os.path.join(bin_location, "tests_src", "manyfloatsum.c"), encoding="utf-8") as fp:
302
- type_cache = angr.sim_type.parse_defns(fp.read())
303
- p = angr.Project(os.path.join(test_location, "i386", "manyfloatsum"), auto_load_libs=False)
304
-
305
- for function in (
306
- "sum_floats",
307
- "sum_combo",
308
- "sum_segregated",
309
- "sum_doubles",
310
- "sum_combo_doubles",
311
- "sum_segregated_doubles",
312
- ):
313
- args = list(range(len(type_cache[function].args)))
314
- answer = float(sum(args))
315
- addr = p.loader.find_symbol(function).rebased_addr
316
- my_callable = p.factory.callable(addr, prototype=type_cache[function])
317
- my_callable.set_base_state(p.factory.blank_state(add_options=so.unicorn))
318
- result = my_callable(*args)
319
- assert not result.symbolic
320
- result_concrete = result.args[0]
321
- assert answer == result_concrete
322
-
323
- def test_unicorn_pickle(self):
324
- p = angr.Project(os.path.join(test_location, "i386", "fauxware"), auto_load_libs=False)
325
-
326
- def _uni_state():
327
- # try pickling out paths that went through unicorn
328
- s_unicorn = p.factory.entry_state(add_options=so.unicorn)
329
- s_unicorn.unicorn.countdown_nonunicorn_blocks = 0
330
- s_unicorn.unicorn.countdown_symbolic_stop = 0
331
- s_unicorn.unicorn.cooldown_nonunicorn_blocks = 0
332
- s_unicorn.unicorn.cooldown_symbolic_stop = 2
333
- return s_unicorn
334
-
335
- pg = p.factory.simulation_manager(_uni_state())
336
- pg.one_active.options.update(so.unicorn)
337
- pg.run(until=lambda lpg: "Unicorn" in lpg.one_active.history.recent_description)
338
- assert len(pg.active) > 0
339
-
340
- pgp = pickle.dumps(pg, -1)
341
- del pg
342
- gc.collect()
343
- pg2 = pickle.loads(pgp)
344
- pg2.explore()
345
-
346
- assert sorted(pg2.mp_deadended.posix.dumps(1).mp_items) == sorted(
347
- (
348
- b"Username: \nPassword: \nWelcome to the admin console, trusted user!\n",
349
- b"Username: \nPassword: \nGo away!",
350
- b"Username: \nPassword: \nWelcome to the admin console, trusted user!\n",
351
- )
352
- )
353
-
354
- # test the pickling of SimUnicorn itself
355
- p = angr.Project(os.path.join(test_location, "i386", "fauxware"), auto_load_libs=False)
356
- pg = p.factory.simulation_manager(_uni_state())
357
- pg.run(n=2)
358
- assert p.factory.successors(pg.one_active).sort == "Unicorn"
359
-
360
- pgp = pickle.dumps(pg, -1)
361
- del pg
362
- gc.collect()
363
- pg2 = pickle.loads(pgp)
364
- pg2.explore()
365
-
366
- assert sorted(pg2.mp_deadended.posix.dumps(1).mp_items) == sorted(
367
- (
368
- b"Username: \nPassword: \nWelcome to the admin console, trusted user!\n",
369
- b"Username: \nPassword: \nGo away!",
370
- b"Username: \nPassword: \nWelcome to the admin console, trusted user!\n",
371
- )
372
- )
373
-
374
- def test_concrete_transmits(self):
375
- p = angr.Project(os.path.join(test_location, "cgc", "PIZZA_00001"), auto_load_libs=False)
376
- inp = bytes.fromhex("320a310a0100000005000000330a330a340a")
377
-
378
- s_unicorn = p.factory.entry_state(
379
- add_options=so.unicorn | {so.CGC_NO_SYMBOLIC_RECEIVE_LENGTH},
380
- stdin=inp,
381
- flag_page=b"\0" * 4096,
382
- )
383
- pg_unicorn = p.factory.simulation_manager(s_unicorn)
384
- pg_unicorn.run(n=10)
385
-
386
- assert pg_unicorn.one_active.posix.dumps(1) == (
387
- b"1) Add number to the array\n"
388
- b"2) Add random number to the array\n"
389
- b"3) Sum numbers\n"
390
- b"4) Exit\n"
391
- b"Randomness added\n"
392
- b"1) Add number to the array\n"
393
- b"2) Add random number to the array\n"
394
- b"3) Sum numbers\n"
395
- b"4) Exit\n"
396
- b" Index: \n"
397
- b"1) Add number to the array\n"
398
- b"2) Add random number to the array\n"
399
- b"3) Sum numbers\n"
400
- b"4) Exit\n"
401
- )
402
-
403
- def test_inspect(self):
404
- p = angr.Project(os.path.join(test_location, "i386", "uc_stop"), auto_load_libs=False)
405
-
406
- def main_state(argc, add_options=None):
407
- add_options = add_options or so.unicorn
408
- main_addr = p.loader.find_symbol("main").rebased_addr
409
- return p.factory.call_state(main_addr, argc, angr.PointerWrapper([]), add_options=add_options)
410
-
411
- # test breaking on specific addresses
412
- s_break_addr = main_state(1)
413
- addr0 = 0x08048479 # at the beginning of a basic block, at end of stop_normal function
414
- addr1 = 0x080485D0 # this is at the beginning of main, in the middle of a basic block
415
- addr2 = 0x08048461 # another non-bb address, at the start of stop_normal
416
- addr3 = 0x0804847C # address of a block that should not get hit (stop_symbolc function)
417
- addr4 = 0x08048632 # another address that shouldn't get hit, near end of main
418
- hits = {addr0: 0, addr1: 0, addr2: 0, addr3: 0, addr4: 0}
419
-
420
- def create_addr_action(addr):
421
- def action(_state):
422
- hits[addr] += 1
423
-
424
- return action
425
-
426
- for addr in [addr0, addr1, addr2]:
427
- s_break_addr.inspect.b("instruction", instruction=addr, action=create_addr_action(addr))
428
-
429
- pg_instruction = p.factory.simulation_manager(s_break_addr)
430
- pg_instruction.run()
431
- assert hits[addr0] == 1
432
- assert hits[addr1] == 1
433
- assert hits[addr2] == 1
434
- assert hits[addr3] == 0
435
- assert hits[addr4] == 0
436
-
437
- # test breaking on every instruction
438
- def collect_trace(options):
439
- s_break_every = main_state(1, add_options=options)
440
- trace = []
441
-
442
- def action_every(state):
443
- trace.append(state.addr)
444
-
445
- s_break_every.inspect.b("instruction", action=action_every)
446
- pg_break_every = p.factory.simulation_manager(s_break_every)
447
- pg_break_every.run()
448
-
449
- assert collect_trace(so.unicorn) == collect_trace(set())
450
-
451
- def test_explore(self):
452
- p = angr.Project(os.path.join(test_location, "i386", "uc_stop"), auto_load_libs=False)
453
-
454
- def main_state(argc, add_options=None):
455
- add_options = add_options or so.unicorn
456
- main_addr = p.loader.find_symbol("main").rebased_addr
457
- return p.factory.call_state(main_addr, argc, angr.PointerWrapper([]), add_options=add_options)
458
-
459
- addr = 0x08048479
460
- s_explore = main_state(1)
461
- pg_explore_find = p.factory.simulation_manager(s_explore)
462
- pg_explore_find.explore(find=addr)
463
- assert len(pg_explore_find.found) == 1
464
- assert pg_explore_find.found[0].addr == addr
465
-
466
- pg_explore_avoid = p.factory.simulation_manager(s_explore)
467
- pg_explore_avoid.explore(avoid=addr)
468
- assert len(pg_explore_avoid.avoid) == 1
469
- assert pg_explore_avoid.avoid[0].addr == addr
470
-
471
- def test_single_step(self):
472
- p = angr.Project(os.path.join(test_location, "i386", "uc_stop"), auto_load_libs=False)
473
-
474
- def main_state(argc, add_options=None):
475
- add_options = add_options or so.unicorn
476
- main_addr = p.loader.find_symbol("main").rebased_addr
477
- return p.factory.call_state(main_addr, argc, angr.PointerWrapper([]), add_options=add_options)
478
-
479
- s_main = main_state(1)
480
-
481
- step1 = s_main.block().instruction_addrs[1]
482
- successors1 = s_main.step(num_inst=1).successors
483
- assert len(successors1) == 1
484
- assert successors1[0].addr == step1
485
-
486
- step5 = s_main.block().instruction_addrs[5]
487
- successors2 = successors1[0].step(num_inst=4).successors
488
- assert len(successors2) == 1
489
- assert successors2[0].addr == step5
490
-
491
- def test_symbolic_flags_preserved_on_stop(self):
492
- """
493
- Test if symbolic flags are preserved when unicorn engine stops. This is needed for cases where compare is
494
- performed in one block and conditional jump in another.
495
- """
496
-
497
- p = angr.Project(os.path.join(test_location, "x86_64", "test_symbolic_flags_in_unicorn"))
498
- init_state = p.factory.full_init_state(add_options=angr.options.unicorn)
499
- simgr = p.factory.simgr(init_state)
500
- simgr.run()
501
- result = None
502
- for final_state in simgr.deadended:
503
- if b"Congrats" in final_state.posix.dumps(1):
504
- result = final_state.posix.dumps(0)
505
- break
506
-
507
- assert result == b"FLAG{l00ps_4r3_t00_34sy_r1gh7??}"
508
-
509
-
510
- if __name__ == "__main__":
511
- import logging
512
-
513
- logging.getLogger("angr.state_plugins.unicorn_engine").setLevel("DEBUG")
514
- logging.getLogger("angr.engines.unicorn_engine").setLevel("INFO")
515
- logging.getLogger("angr.factory").setLevel("DEBUG")
516
- logging.getLogger("angr.project").setLevel("DEBUG")
517
-
518
- unittest.main()
File without changes
@@ -1,124 +0,0 @@
1
- #!/usr/bin/env python3
2
- # pylint: disable=missing-class-docstring,no-self-use,line-too-long
3
-
4
- import binascii
5
- import unittest
6
-
7
- import pyvex
8
- import archinfo
9
- import angr
10
-
11
-
12
- class TestLifter(unittest.TestCase):
13
- def test_strict_block_ends_cbz(self):
14
- # ldr r3, [sp, #4]
15
- # cbz r3, #0x8149
16
- # mov.w r2, #0x10000000
17
- # ldr r3, [pc, #0x38]
18
- # str r2, [r3]
19
- # add sp, #8
20
- # pop {r4, r5, r6, pc}
21
-
22
- p = angr.load_shellcode(b"\x01\x9b\x1b\xb1O\xf0\x80R\x0eK\x1a`\x02\xb0p\xbd", "arm")
23
- assert p.factory.block(1, strict_block_end=False).instructions == 7
24
- assert p.factory.block(1, strict_block_end=True).instructions == 2
25
- p.factory.default_engine.default_strict_block_end = False
26
- assert p.factory.block(1).instructions == 7
27
- p.factory.default_engine.default_strict_block_end = True
28
- assert p.factory.block(1).instructions == 2
29
-
30
- def test_strict_block_ends_with_size_x86(self):
31
- # cmovnz cx, dx
32
- # pop eax
33
- # jecxz short loc_4010D7 ; the first block should end here
34
- # sub edi, 2
35
- # loop loc_4010c9
36
- # nop
37
- # nop
38
-
39
- b = b"\x66\x0f\x45\xca\x58\xe3\x07\x83\xef\x02\xe2\xf4\x90\x90"
40
- p = angr.load_shellcode(b, "x86", load_address=0x4010C9)
41
-
42
- # jecxz
43
- assert p.factory.block(0x4010C9, size=len(b), strict_block_end=False).instructions == 7
44
- assert p.factory.block(0x4010C9, strict_block_end=True).instructions == 3
45
- assert p.factory.block(0x4010C9, size=len(b), strict_block_end=True).instructions == 3
46
-
47
- # loop
48
- assert p.factory.block(0x4010D0, strict_block_end=False).instructions == 4
49
- assert p.factory.block(0x4010D0, strict_block_end=True).instructions == 2
50
- assert p.factory.block(0x4010D0, size=7, strict_block_end=True).instructions == 2
51
-
52
- def test_strict_block_ends_with_size_amd64(self):
53
- # cmovnz cx, dx
54
- # pop rax
55
- # jrcxz short loc_4010D7 ; the first block should end here
56
- # sub edi, 2
57
- # loop loc_4010c9
58
- # nop
59
- # nop
60
-
61
- b = b"\x66\x0f\x45\xca\x58\xe3\x07\x83\xef\x02\xe2\xf4\x90\x90"
62
- p = angr.load_shellcode(b, "amd64", load_address=0x4010C9)
63
-
64
- # jrcxz
65
- assert p.factory.block(0x4010C9, size=len(b), strict_block_end=False).instructions == 7
66
- assert p.factory.block(0x4010C9, strict_block_end=True).instructions == 3
67
- assert p.factory.block(0x4010C9, size=len(b), strict_block_end=True).instructions == 3
68
-
69
- # loop
70
- assert p.factory.block(0x4010D0, strict_block_end=False).instructions == 4
71
- assert p.factory.block(0x4010D0, strict_block_end=True).instructions == 2
72
- assert p.factory.block(0x4010D0, size=7, strict_block_end=True).instructions == 2
73
-
74
- def test_no_cross_insn_boundary_opt_amd64(self):
75
- # 0x4020f8: sub rsp, 8
76
- # 0x4020fc: mov rax, qword ptr [rip + 0x221ef5]
77
- # 0x402103: test rax, rax
78
- # 0x402106: je 0x40210d
79
-
80
- b = binascii.unhexlify("4883ec08488b05f51e22004885c07405")
81
- p = angr.load_shellcode(b, "amd64", load_address=0x4020F8)
82
-
83
- # No optimization
84
- block = p.factory.block(0x4020F8, size=len(b), opt_level=0)
85
- assert len(block.vex.statements) == 32
86
- # Full level-1 optimization
87
- block = p.factory.block(0x4020F8, size=len(b), opt_level=1, cross_insn_opt=True)
88
- assert len(block.vex.statements) == 20
89
- # Level-1 optimization within each instruction
90
- block = p.factory.block(0x4020F8, size=len(b), opt_level=1, cross_insn_opt=False)
91
- stmts = block.vex.statements
92
- assert len(stmts) == 22
93
- # 09 | ------ IMark(0x402103, 3, 0) ------
94
- assert isinstance(stmts[9], pyvex.IRStmt.IMark)
95
- assert stmts[9].addr == 0x402103
96
- # 10 | t6 = GET:I64(rax)
97
- assert isinstance(stmts[10], pyvex.IRStmt.WrTmp)
98
- assert isinstance(stmts[10].data, pyvex.IRExpr.Get)
99
- assert stmts[10].data.offset == archinfo.arch_from_id("amd64").registers["rax"][0]
100
- # 11 | PUT(cc_op) = 0x0000000000000014
101
- assert isinstance(stmts[11], pyvex.IRStmt.Put)
102
- assert stmts[11].offset == archinfo.arch_from_id("amd64").registers["cc_op"][0]
103
- assert isinstance(stmts[11].data, pyvex.IRExpr.Const)
104
- assert stmts[11].data.con.value == 0x14
105
- # 12 | PUT(cc_dep1) = t6
106
- assert isinstance(stmts[12], pyvex.IRStmt.Put)
107
- assert stmts[12].offset == archinfo.arch_from_id("amd64").registers["cc_dep1"][0]
108
- # 13 | PUT(cc_dep2) = 0x0000000000000000
109
- assert isinstance(stmts[13], pyvex.IRStmt.Put)
110
- assert stmts[13].offset == archinfo.arch_from_id("amd64").registers["cc_dep2"][0]
111
- assert isinstance(stmts[13].data, pyvex.IRExpr.Const)
112
- assert stmts[13].data.con.value == 0
113
- # 14 | PUT(rip) = 0x0000000000402106
114
- assert isinstance(stmts[14], pyvex.IRStmt.Put)
115
- assert stmts[14].offset == archinfo.arch_from_id("amd64").registers["rip"][0]
116
- assert isinstance(stmts[14].data, pyvex.IRExpr.Const)
117
- assert stmts[14].data.con.value == 0x402106
118
- # 15 | ------ IMark(0x402106, 2, 0) ------
119
- assert isinstance(stmts[15], pyvex.IRStmt.IMark)
120
- assert stmts[15].addr == 0x402106
121
-
122
-
123
- if __name__ == "__main__":
124
- unittest.main()