angr 9.2.87__py3-none-win_amd64.whl → 9.2.89__py3-none-win_amd64.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 (249) 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/lib/angr_native.dll +0 -0
  24. angr/misc/autoimport.py +26 -0
  25. angr/procedures/definitions/__init__.py +32 -3
  26. angr/utils/constants.py +1 -0
  27. angr/utils/graph.py +20 -1
  28. {angr-9.2.87.dist-info → angr-9.2.89.dist-info}/METADATA +7 -6
  29. {angr-9.2.87.dist-info → angr-9.2.89.dist-info}/RECORD +33 -245
  30. angr-9.2.89.dist-info/top_level.txt +1 -0
  31. angr/procedures/definitions/ntdll.py +0 -12
  32. angr-9.2.87.dist-info/top_level.txt +0 -2
  33. tests/__init__.py +0 -0
  34. tests/analyses/__init__.py +0 -0
  35. tests/analyses/cfg/__init__.py +0 -0
  36. tests/analyses/cfg/test_cfg_clflush.py +0 -43
  37. tests/analyses/cfg/test_cfg_get_any_node.py +0 -34
  38. tests/analyses/cfg/test_cfg_manager.py +0 -32
  39. tests/analyses/cfg/test_cfg_model.py +0 -55
  40. tests/analyses/cfg/test_cfg_patching.py +0 -378
  41. tests/analyses/cfg/test_cfg_rust_got_resolution.py +0 -36
  42. tests/analyses/cfg/test_cfg_thumb_firmware.py +0 -50
  43. tests/analyses/cfg/test_cfg_vex_postprocessor.py +0 -27
  44. tests/analyses/cfg/test_cfgemulated.py +0 -634
  45. tests/analyses/cfg/test_cfgfast.py +0 -1123
  46. tests/analyses/cfg/test_cfgfast_soot.py +0 -38
  47. tests/analyses/cfg/test_const_resolver.py +0 -38
  48. tests/analyses/cfg/test_iat_resolver.py +0 -37
  49. tests/analyses/cfg/test_jumptables.py +0 -3008
  50. tests/analyses/cfg/test_noop_blocks.py +0 -54
  51. tests/analyses/cfg_slice_to_sink/__init__.py +0 -0
  52. tests/analyses/cfg_slice_to_sink/test_cfg_slice_to_sink.py +0 -93
  53. tests/analyses/cfg_slice_to_sink/test_graph.py +0 -114
  54. tests/analyses/cfg_slice_to_sink/test_transitions.py +0 -28
  55. tests/analyses/decompiler/__init__.py +0 -0
  56. tests/analyses/decompiler/test_baseptr_save_simplifier.py +0 -80
  57. tests/analyses/decompiler/test_decompiler.py +0 -3336
  58. tests/analyses/decompiler/test_peephole_optimizations.py +0 -48
  59. tests/analyses/decompiler/test_propagator_loops.py +0 -101
  60. tests/analyses/decompiler/test_structurer.py +0 -275
  61. tests/analyses/reaching_definitions/__init__.py +0 -0
  62. tests/analyses/reaching_definitions/test_dep_graph.py +0 -432
  63. tests/analyses/reaching_definitions/test_function_handler.py +0 -131
  64. tests/analyses/reaching_definitions/test_heap_allocator.py +0 -46
  65. tests/analyses/reaching_definitions/test_rd_state.py +0 -78
  66. tests/analyses/reaching_definitions/test_reachingdefinitions.py +0 -463
  67. tests/analyses/reaching_definitions/test_subject.py +0 -76
  68. tests/analyses/test_bindiff.py +0 -52
  69. tests/analyses/test_block_simplifier.py +0 -112
  70. tests/analyses/test_boyscout.py +0 -104
  71. tests/analyses/test_calling_convention_analysis.py +0 -352
  72. tests/analyses/test_callsite_maker.py +0 -60
  73. tests/analyses/test_cdg.py +0 -165
  74. tests/analyses/test_cfb.py +0 -37
  75. tests/analyses/test_class_identifier.py +0 -46
  76. tests/analyses/test_clinic.py +0 -30
  77. tests/analyses/test_codetagging.py +0 -32
  78. tests/analyses/test_constantpropagation.py +0 -88
  79. tests/analyses/test_ddg.py +0 -95
  80. tests/analyses/test_ddg_global_var_dependencies.py +0 -83
  81. tests/analyses/test_ddg_memvar_addresses.py +0 -40
  82. tests/analyses/test_disassembly.py +0 -121
  83. tests/analyses/test_find_objects_static.py +0 -35
  84. tests/analyses/test_flirt.py +0 -49
  85. tests/analyses/test_identifier.py +0 -33
  86. tests/analyses/test_init_finder.py +0 -38
  87. tests/analyses/test_proximitygraph.py +0 -31
  88. tests/analyses/test_reassembler.py +0 -295
  89. tests/analyses/test_regionidentifier.py +0 -27
  90. tests/analyses/test_slicing.py +0 -164
  91. tests/analyses/test_stack_pointer_tracker.py +0 -74
  92. tests/analyses/test_static_hooker.py +0 -28
  93. tests/analyses/test_typehoon.py +0 -55
  94. tests/analyses/test_variablerecovery.py +0 -464
  95. tests/analyses/test_vfg.py +0 -221
  96. tests/analyses/test_vtable.py +0 -31
  97. tests/analyses/test_xrefs.py +0 -77
  98. tests/common.py +0 -128
  99. tests/engines/__init__.py +0 -0
  100. tests/engines/light/__init__.py +0 -0
  101. tests/engines/light/test_data.py +0 -17
  102. tests/engines/pcode/__init__.py +0 -0
  103. tests/engines/pcode/test_emulate.py +0 -607
  104. tests/engines/pcode/test_pcode.py +0 -84
  105. tests/engines/test_actions.py +0 -27
  106. tests/engines/test_hook.py +0 -112
  107. tests/engines/test_java.py +0 -697
  108. tests/engines/test_unicorn.py +0 -518
  109. tests/engines/vex/__init__.py +0 -0
  110. tests/engines/vex/test_lifter.py +0 -124
  111. tests/engines/vex/test_vex.py +0 -574
  112. tests/exploration_techniques/__init__.py +0 -0
  113. tests/exploration_techniques/test_cacher.py +0 -45
  114. tests/exploration_techniques/test_director.py +0 -67
  115. tests/exploration_techniques/test_driller_core.py +0 -48
  116. tests/exploration_techniques/test_loop_seer.py +0 -158
  117. tests/exploration_techniques/test_memory_watcher.py +0 -46
  118. tests/exploration_techniques/test_oppologist.py +0 -65
  119. tests/exploration_techniques/test_spiller.py +0 -82
  120. tests/exploration_techniques/test_stochastic.py +0 -40
  121. tests/exploration_techniques/test_tech_builder.py +0 -61
  122. tests/exploration_techniques/test_tracer.py +0 -856
  123. tests/exploration_techniques/test_unique.py +0 -40
  124. tests/exploration_techniques/test_veritesting.py +0 -120
  125. tests/factory/__init__.py +0 -0
  126. tests/factory/block/__init__.py +0 -0
  127. tests/factory/block/test_block_cache.py +0 -33
  128. tests/factory/block/test_keystone.py +0 -106
  129. tests/factory/test_argc.py +0 -101
  130. tests/factory/test_argc_sym.py +0 -110
  131. tests/factory/test_argv.py +0 -158
  132. tests/factory/test_callable.py +0 -266
  133. tests/factory/test_windows_args.py +0 -36
  134. tests/knowledge_plugins/__init__.py +0 -0
  135. tests/knowledge_plugins/cfg/__init__.py +0 -0
  136. tests/knowledge_plugins/cfg/test_cfg_manager.py +0 -36
  137. tests/knowledge_plugins/functions/__init__.py +0 -0
  138. tests/knowledge_plugins/functions/test_function.py +0 -91
  139. tests/knowledge_plugins/functions/test_function2.py +0 -79
  140. tests/knowledge_plugins/functions/test_function_manager.py +0 -139
  141. tests/knowledge_plugins/functions/test_prototypes.py +0 -53
  142. tests/knowledge_plugins/key_definitions/__init__.py +0 -0
  143. tests/knowledge_plugins/key_definitions/test_atoms.py +0 -24
  144. tests/knowledge_plugins/key_definitions/test_environment.py +0 -126
  145. tests/knowledge_plugins/key_definitions/test_heap_address.py +0 -27
  146. tests/knowledge_plugins/key_definitions/test_live_definitions.py +0 -72
  147. tests/knowledge_plugins/test_dwarf_variables.py +0 -240
  148. tests/knowledge_plugins/test_kb_plugins.py +0 -91
  149. tests/knowledge_plugins/test_kb_plugins_dwarf.py +0 -36
  150. tests/knowledge_plugins/test_patches.py +0 -48
  151. tests/misc/__init__.py +0 -0
  152. tests/misc/test_hookset.py +0 -57
  153. tests/perf/__init__.py +0 -0
  154. tests/perf/perf_cfgemulated.py +0 -19
  155. tests/perf/perf_cfgfast.py +0 -18
  156. tests/perf/perf_concrete_execution.py +0 -41
  157. tests/perf/perf_siminspect_nop.py +0 -36
  158. tests/perf/perf_state_copy.py +0 -33
  159. tests/perf/perf_unicorn_0.py +0 -27
  160. tests/perf/perf_unicorn_1.py +0 -23
  161. tests/procedures/__init__.py +0 -0
  162. tests/procedures/glibc/__init__.py +0 -0
  163. tests/procedures/glibc/test_ctype_locale.py +0 -164
  164. tests/procedures/libc/__init__.py +0 -0
  165. tests/procedures/libc/test_fgets.py +0 -53
  166. tests/procedures/libc/test_scanf.py +0 -205
  167. tests/procedures/libc/test_sprintf.py +0 -44
  168. tests/procedures/libc/test_sscanf.py +0 -63
  169. tests/procedures/libc/test_strcasecmp.py +0 -37
  170. tests/procedures/libc/test_string.py +0 -1102
  171. tests/procedures/libc/test_strtol.py +0 -78
  172. tests/procedures/linux_kernel/__init__.py +0 -0
  173. tests/procedures/linux_kernel/test_lseek.py +0 -174
  174. tests/procedures/posix/__init__.py +0 -0
  175. tests/procedures/posix/test_chroot.py +0 -33
  176. tests/procedures/posix/test_getenv.py +0 -78
  177. tests/procedures/posix/test_pwrite_pread.py +0 -57
  178. tests/procedures/posix/test_sim_time.py +0 -46
  179. tests/procedures/posix/test_unlink.py +0 -46
  180. tests/procedures/test_project_resolve_simproc.py +0 -43
  181. tests/procedures/test_sim_procedure.py +0 -117
  182. tests/procedures/test_stub_procedure_args.py +0 -53
  183. tests/serialization/__init__.py +0 -0
  184. tests/serialization/test_db.py +0 -197
  185. tests/serialization/test_pickle.py +0 -95
  186. tests/serialization/test_serialization.py +0 -132
  187. tests/serialization/test_vault.py +0 -169
  188. tests/sim/__init__.py +0 -3
  189. tests/sim/exec_func/__init__.py +0 -0
  190. tests/sim/exec_func/test_mem_funcs.py +0 -55
  191. tests/sim/exec_func/test_str_funcs.py +0 -93
  192. tests/sim/exec_func/test_syscall_result.py +0 -39
  193. tests/sim/exec_insn/__init__.py +0 -0
  194. tests/sim/exec_insn/test_adc.py +0 -44
  195. tests/sim/exec_insn/test_ops.py +0 -83
  196. tests/sim/exec_insn/test_rcr.py +0 -26
  197. tests/sim/exec_insn/test_rol.py +0 -51
  198. tests/sim/exec_insn/test_signed_div.py +0 -34
  199. tests/sim/exec_insn/test_sqrt.py +0 -56
  200. tests/sim/options/__init__.py +0 -0
  201. tests/sim/options/test_0div.py +0 -54
  202. tests/sim/options/test_symbolic_fd.py +0 -59
  203. tests/sim/options/test_unsupported.py +0 -34
  204. tests/sim/test_accuracy.py +0 -137
  205. tests/sim/test_checkbyte.py +0 -53
  206. tests/sim/test_echo.py +0 -36
  207. tests/sim/test_fauxware.py +0 -202
  208. tests/sim/test_self_modifying_code.py +0 -65
  209. tests/sim/test_simple_api.py +0 -36
  210. tests/sim/test_simulation_manager.py +0 -147
  211. tests/sim/test_stack_alignment.py +0 -65
  212. tests/sim/test_state.py +0 -303
  213. tests/sim/test_state_customization.py +0 -54
  214. tests/sim/test_symbol_hooked_by.py +0 -49
  215. tests/simos/__init__.py +0 -0
  216. tests/simos/windows/__init__.py +0 -0
  217. tests/simos/windows/test_windows_stack_cookie.py +0 -58
  218. tests/state_plugins/__init__.py +0 -0
  219. tests/state_plugins/inspect/__init__.py +0 -0
  220. tests/state_plugins/inspect/test_inspect.py +0 -310
  221. tests/state_plugins/inspect/test_syscall_override.py +0 -90
  222. tests/state_plugins/posix/__init__.py +0 -0
  223. tests/state_plugins/posix/test_file_struct_funcs.py +0 -56
  224. tests/state_plugins/posix/test_files.py +0 -69
  225. tests/state_plugins/posix/test_posix.py +0 -72
  226. tests/state_plugins/solver/__init__.py +0 -0
  227. tests/state_plugins/solver/test_simsolver.py +0 -58
  228. tests/state_plugins/solver/test_symbolic.py +0 -153
  229. tests/state_plugins/solver/test_variable_registration.py +0 -46
  230. tests/state_plugins/test_callstack.py +0 -54
  231. tests/state_plugins/test_gdb_plugin.py +0 -35
  232. tests/state_plugins/test_multi_open_file.py +0 -47
  233. tests/state_plugins/test_symbolization.py +0 -38
  234. tests/storage/__init__.py +0 -0
  235. tests/storage/test_memory.py +0 -960
  236. tests/storage/test_memory_merge.py +0 -114
  237. tests/storage/test_memview.py +0 -205
  238. tests/storage/test_mmap.py +0 -26
  239. tests/storage/test_multivalues.py +0 -44
  240. tests/storage/test_permissions.py +0 -32
  241. tests/storage/test_ptmalloc.py +0 -291
  242. tests/storage/test_relro_perm.py +0 -49
  243. tests/test_calling_conventions.py +0 -86
  244. tests/test_types.py +0 -329
  245. tests/utils/__init__.py +0 -0
  246. tests/utils/test_graph.py +0 -41
  247. {angr-9.2.87.dist-info → angr-9.2.89.dist-info}/LICENSE +0 -0
  248. {angr-9.2.87.dist-info → angr-9.2.89.dist-info}/WHEEL +0 -0
  249. {angr-9.2.87.dist-info → angr-9.2.89.dist-info}/entry_points.txt +0 -0
@@ -1,856 +0,0 @@
1
- #!/usr/bin/env python3
2
- # pylint: disable=missing-class-docstring,no-self-use,line-too-long
3
- __package__ = __package__ or "tests.exploration_techniques" # pylint:disable=redefined-builtin
4
-
5
- import logging
6
- import os
7
- import platform
8
- import sys
9
- import unittest
10
-
11
- import angr
12
-
13
- from ..common import broken, bin_location, do_trace, load_cgc_pov, slow_test, skip_if_not_linux
14
-
15
-
16
- def tracer_cgc(
17
- filename,
18
- test_name,
19
- stdin,
20
- copy_states=False,
21
- follow_unsat=False,
22
- read_strategies=None,
23
- write_strategies=None,
24
- add_options=None,
25
- remove_options=None,
26
- syscall_data=None,
27
- symbolic_stdin=True,
28
- ):
29
- p = angr.Project(filename)
30
- p.simos.syscall_library.update(angr.SIM_LIBRARIES["cgcabi_tracer"])
31
-
32
- trace, magic, crash_mode, crash_addr = do_trace(p, test_name, stdin)
33
- s = p.factory.entry_state(
34
- mode="tracing",
35
- stdin=angr.SimFileStream,
36
- flag_page=magic,
37
- add_options=add_options,
38
- remove_options=remove_options,
39
- )
40
- if read_strategies is not None:
41
- s.memory.read_strategies = read_strategies
42
- if write_strategies is not None:
43
- s.memory.write_strategies = write_strategies
44
- s.preconstrainer.preconstrain_file(stdin, s.posix.stdin, True)
45
-
46
- simgr = p.factory.simulation_manager(s, hierarchy=None, save_unconstrained=crash_mode)
47
- t = angr.exploration_techniques.Tracer(
48
- trace,
49
- crash_addr=crash_addr,
50
- keep_predecessors=1,
51
- copy_states=copy_states,
52
- follow_unsat=follow_unsat,
53
- syscall_data=syscall_data,
54
- )
55
- if add_options is not None and angr.options.UNICORN_HANDLE_CGC_RECEIVE_SYSCALL in add_options:
56
- if symbolic_stdin:
57
- fd_data = {0: (stdin, b"\x01" * len(stdin))}
58
- else:
59
- fd_data = {0: (stdin, b"\x00" * len(stdin))}
60
-
61
- t.set_fd_data(fd_data)
62
-
63
- simgr.use_technique(t)
64
- simgr.use_technique(angr.exploration_techniques.Oppologist())
65
-
66
- return simgr, t
67
-
68
-
69
- def trace_cgc_with_pov_file(
70
- binary: str,
71
- test_name: str,
72
- pov_file: str,
73
- output_initial_bytes: bytes,
74
- copy_states=False,
75
- read_strategies=None,
76
- write_strategies=None,
77
- add_options=None,
78
- remove_options=None,
79
- syscall_data=None,
80
- symbolic_stdin=True,
81
- ):
82
- assert os.path.isfile(pov_file)
83
- pov = load_cgc_pov(pov_file)
84
- trace_result = tracer_cgc(
85
- binary,
86
- test_name,
87
- b"".join(pov.writes),
88
- copy_states,
89
- read_strategies=read_strategies,
90
- write_strategies=write_strategies,
91
- add_options=add_options,
92
- remove_options=remove_options,
93
- syscall_data=syscall_data,
94
- symbolic_stdin=symbolic_stdin,
95
- )
96
- simgr = trace_result[0]
97
- simgr.run()
98
- assert "traced" in simgr.stashes
99
- assert len(simgr.traced) == 1
100
- stdout_dump = simgr.traced[0].posix.dumps(1)
101
- assert stdout_dump.startswith(output_initial_bytes)
102
-
103
-
104
- def tracer_linux(filename, test_name, stdin, add_options=None, remove_options=None):
105
- p = angr.Project(filename)
106
-
107
- trace, _, crash_mode, crash_addr = do_trace(
108
- p,
109
- test_name,
110
- stdin,
111
- ld_linux=p.loader.linux_loader_object.binary,
112
- library_path={os.path.dirname(obj.binary) for obj in p.loader.all_elf_objects},
113
- record_stdout=True,
114
- )
115
- s = p.factory.full_init_state(
116
- mode="tracing",
117
- stdin=angr.SimFileStream,
118
- add_options=add_options,
119
- remove_options=remove_options,
120
- )
121
- s.preconstrainer.preconstrain_file(stdin, s.posix.stdin, True)
122
-
123
- simgr = p.factory.simulation_manager(s, hierarchy=None, save_unconstrained=crash_mode)
124
- t = angr.exploration_techniques.Tracer(trace, crash_addr=crash_addr)
125
- simgr.use_technique(t)
126
- simgr.use_technique(angr.exploration_techniques.Oppologist())
127
-
128
- return simgr, t
129
-
130
-
131
- @unittest.skipIf(sys.platform == "win32", "broken on windows")
132
- class TestTracer(unittest.TestCase):
133
- @unittest.skipIf(platform.system() == "Darwin" and platform.machine() == "arm64", "Broken on apple silicon")
134
- @unittest.skipIf(sys.platform == "win32", "broken on windows")
135
- def test_recursion(self):
136
- blob = bytes.fromhex(
137
- "00aadd114000000000000000200000001d0000000005000000aadd2a1100001d0000000001e8030000aadd21118611b3b3b3b3b3e3b1b"
138
- "1b1adb1b1b1b1b1b1118611981d8611"
139
- )
140
- fname = os.path.join(bin_location, "tests", "cgc", "NRFIN_00075")
141
-
142
- simgr, _ = tracer_cgc(fname, "tracer_recursion", blob)
143
- simgr.run()
144
-
145
- assert simgr.crashed
146
- assert simgr.crashed[0].solver.symbolic(simgr.crashed[0].regs.ip)
147
-
148
- @broken
149
- @slow_test
150
- def test_cache_stall(self):
151
- # test a valid palindrome
152
- b = os.path.join(bin_location, "tests", "cgc", "CROMU_00071")
153
- blob = bytes.fromhex(
154
- "0c0c492a53acacacacacacacacacacacacac000100800a0b690e0aef6503697d660a0059e20afc0a0a332f7d66660a0059e20afc0a0a3"
155
- "32f7fffffff16fb1616162516161616161616166a7dffffff7b0e0a0a6603697d660a0059e21c"
156
- )
157
-
158
- simgr, tracer = tracer_cgc(b, "tracer_cache_stall", blob)
159
- simgr.run()
160
-
161
- crash_path = tracer.predecessors[-1]
162
- crash_state = simgr.crashed[0]
163
-
164
- assert crash_path is not None
165
- assert crash_state is not None
166
-
167
- # load it again
168
- simgr, tracer = tracer_cgc(b, "tracer_cache_stall", blob)
169
- simgr.run()
170
-
171
- crash_path = tracer.predecessors[-1]
172
- crash_state = simgr.one_crashed
173
-
174
- assert crash_path is not None
175
- assert crash_state is not None
176
-
177
- @skip_if_not_linux
178
- def test_manual_recursion(self):
179
- b = os.path.join(bin_location, "tests", "cgc", "CROMU_00071")
180
- with open(os.path.join(bin_location, "tests_data", "crash2731"), "rb") as fh:
181
- blob = fh.read()
182
-
183
- simgr, tracer = tracer_cgc(b, "tracer_manual_recursion", blob)
184
- simgr.run()
185
-
186
- crash_path = tracer.predecessors[-1]
187
- crash_state = simgr.one_crashed
188
-
189
- assert crash_path is not None
190
- assert crash_state is not None
191
-
192
- def test_cgc_receive_unicorn_native_interface(self):
193
- """
194
- Test if unicorn native interface handles CGC receive syscall correctly. Receives with symbolic arguments also
195
- tested.
196
- """
197
-
198
- binary = os.path.join(bin_location, "tests", "cgc", "KPRCA_00038")
199
- pov_file = os.path.join(bin_location, "tests_data", "cgc_povs", "KPRCA_00038_POV_00000.xml")
200
- output_initial_bytes = b""
201
- add_options = {
202
- angr.options.UNICORN_HANDLE_CGC_RECEIVE_SYSCALL,
203
- angr.options.UNICORN_HANDLE_SYMBOLIC_ADDRESSES,
204
- angr.options.UNICORN_HANDLE_SYMBOLIC_CONDITIONS,
205
- angr.options.UNICORN_HANDLE_SYMBOLIC_SYSCALLS,
206
- }
207
- trace_cgc_with_pov_file(
208
- binary,
209
- "tracer_cgc_receive_unicorn_native_interface",
210
- pov_file,
211
- output_initial_bytes,
212
- add_options=add_options,
213
- )
214
-
215
- def test_cgc_receive_unicorn_native_interface_rx_bytes(self):
216
- """
217
- Test rx_bytes is correctly handled by unicorn native interface's CGC receive: update only if non-null
218
- """
219
-
220
- binary = os.path.join(bin_location, "tests", "cgc", "CROMU_00012")
221
- pov_file = os.path.join(bin_location, "tests_data", "cgc_povs", "CROMU_00012_POV_00000.xml")
222
- output_initial_bytes = b""
223
- add_options = {
224
- angr.options.UNICORN_HANDLE_CGC_RECEIVE_SYSCALL,
225
- angr.options.UNICORN_HANDLE_SYMBOLIC_ADDRESSES,
226
- angr.options.UNICORN_HANDLE_SYMBOLIC_CONDITIONS,
227
- }
228
- trace_cgc_with_pov_file(
229
- binary,
230
- "tracer_cgc_receive_unicorn_native_interface_rx_bytes",
231
- pov_file,
232
- output_initial_bytes,
233
- add_options=add_options,
234
- )
235
-
236
- def test_cgc_random_syscall_handling_native_interface(self):
237
- """
238
- Test if random syscall is correctly handled in native interface. Random with symbolic arguments also tested.
239
- """
240
-
241
- binary = os.path.join(bin_location, "tests", "cgc", "KPRCA_00011")
242
- pov_file = os.path.join(bin_location, "tests_data", "cgc_povs", "KPRCA_00011_POV_00000.xml")
243
- output_file = os.path.join(bin_location, "tests_data", "cgc_povs", "KPRCA_00011_stdout.txt")
244
- add_options = {
245
- angr.options.UNICORN_HANDLE_CGC_RECEIVE_SYSCALL,
246
- angr.options.UNICORN_HANDLE_CGC_RANDOM_SYSCALL,
247
- angr.options.UNICORN_HANDLE_SYMBOLIC_ADDRESSES,
248
- angr.options.UNICORN_HANDLE_SYMBOLIC_CONDITIONS,
249
- angr.options.UNICORN_HANDLE_SYMBOLIC_SYSCALLS,
250
- }
251
-
252
- rand_syscall_data = {
253
- "random": [
254
- (65, 1),
255
- (16705, 2),
256
- (16705, 2),
257
- (65, 1),
258
- (16705, 2),
259
- (16705, 2),
260
- (65, 1),
261
- (16705, 2),
262
- (16705, 2),
263
- (65, 1),
264
- (16705, 2),
265
- (16705, 2),
266
- (65, 1),
267
- (16705, 2),
268
- (16705, 2),
269
- (65, 1),
270
- (16705, 2),
271
- (16705, 2),
272
- (65, 1),
273
- (16705, 2),
274
- (16705, 2),
275
- (65, 1),
276
- (16705, 2),
277
- (16705, 2),
278
- (65, 1),
279
- (16705, 2),
280
- (16705, 2),
281
- (65, 1),
282
- (16705, 2),
283
- (16705, 2),
284
- (65, 1),
285
- (16705, 2),
286
- (16705, 2),
287
- (65, 1),
288
- (16705, 2),
289
- (16705, 2),
290
- (65, 1),
291
- (16705, 2),
292
- (16705, 2),
293
- (65, 1),
294
- (16705, 2),
295
- (16705, 2),
296
- (65, 1),
297
- (16705, 2),
298
- (16705, 2),
299
- (65, 1),
300
- (16705, 2),
301
- (16705, 2),
302
- (65, 1),
303
- (16705, 2),
304
- (16705, 2),
305
- (65, 1),
306
- (16705, 2),
307
- (16705, 2),
308
- (65, 1),
309
- (16705, 2),
310
- (16705, 2),
311
- (65, 1),
312
- (16705, 2),
313
- (16705, 2),
314
- (65, 1),
315
- (16705, 2),
316
- (16705, 2),
317
- (65, 1),
318
- (16705, 2),
319
- (16705, 2),
320
- ]
321
- }
322
- with open(output_file, "rb") as fh:
323
- output_bytes = fh.read()
324
-
325
- trace_cgc_with_pov_file(
326
- binary,
327
- "tracer_cgc_receive_unicorn_native_interface_rx_bytes",
328
- pov_file,
329
- output_bytes,
330
- add_options=add_options,
331
- syscall_data=rand_syscall_data,
332
- )
333
-
334
- @unittest.skipIf(platform.system() == "Darwin" and platform.machine() == "arm64", "Broken on apple silicon")
335
- @unittest.skipIf(sys.platform == "win32", "broken on windows")
336
- def test_cgc_se1_palindrome_raw(self):
337
- b = os.path.join(bin_location, "tests", "cgc", "sc1_0b32aa01_01")
338
- # test a valid palindrome
339
-
340
- simgr, _ = tracer_cgc(b, "tracer_cgc_se1_palindrome_raw_nocrash", b"racecar\n")
341
- simgr.run()
342
-
343
- # make sure the heap base is correct and hasn't been altered from the default
344
- assert "traced" in simgr.stashes
345
- assert simgr.traced[0].cgc.allocation_base == 0xB8000000
346
-
347
- # make sure there is no crash state
348
- assert not simgr.crashed
349
-
350
- # make sure angr modeled the correct output
351
- stdout_dump = simgr.traced[0].posix.dumps(1)
352
- assert stdout_dump.startswith(
353
- b"\nWelcome to Palindrome Finder\n\n"
354
- b"\tPlease enter a possible palindrome: "
355
- b"\t\tYes, that's a palindrome!\n\n"
356
- b"\tPlease enter a possible palindrome: "
357
- )
358
- # make sure there were no 'Nope's from non-palindromes
359
- assert b"Nope" not in stdout_dump
360
-
361
- # now test crashing input
362
- simgr, _ = tracer_cgc(b, "tracer_cgc_se1_palindrome_raw_yescrash", b"A" * 129)
363
- simgr.run()
364
-
365
- assert simgr.crashed
366
-
367
- def test_concrete_execution_in_native_interface(self):
368
- """
369
- Test if concrete execution without any symbolic bytes is done correctly when receive syscall is handled in
370
- native interface
371
- """
372
-
373
- binary = os.path.join(bin_location, "tests", "cgc", "KPRCA_00052")
374
- pov_file = os.path.join(bin_location, "tests_data", "cgc_povs", "KPRCA_00052_POV_00000.xml")
375
- output_initial_bytes = (
376
- b"Enter system password: \nWelcome to the CGC Pizzeria order management system.\n1. Input Order\n"
377
- b"2. Update Order\n3. View One Orders\n4. View All Orders\n5. Delete Order\n6. Clear All Orders\n"
378
- b"7. Logout\n"
379
- b"Choice: Enter Pickup Name: Choose what the kind of pizza\n1. Pizza Pie - The classic!\n"
380
- b"2. Pizza Sub - All the fun, on a bun\n3. Pizza Bowl - Our own twist\nChoice: Select Size\n1. Small\n"
381
- b"2. Medium\n3. Large\nChoice: Successfully added a new Pizza Pie!\nSelect an option:\n1. Add Toppings\n"
382
- b"2. Remove Toppings\n3. Add Sauce\n4. Remove Sauce\n5. Finished With Pizza\nChoice: Successfully added "
383
- b"pizza!"
384
- b"\n1. Add another Pizza\n2. Quit\nChoice: 0. Cancel\n==================================================\n"
385
- b" "
386
- b"Item #1. Classic Pizza Pie, Size: SMALL\n Selected Toppings\n\tNone\n Sauce on the side\n\tNone\n"
387
- b"--------------------------------------\n\t\tCalories: 1000\n\t\tCarbs : 222\n\nPizza length... = 1\n"
388
- b"\t\t"
389
- b"Estimated wait time: 36 minute(s)\n==================================================\nChoice: "
390
- b"Removed Item #1\n1. Add another Pizza\n2. Quit\nChoice: Order successfully added!\n1. Input Order\n"
391
- b"2. Update Order\n3. View One Orders\n4. View All Orders\n5. Delete Order\n6. Clear All Orders\n7. "
392
- b"Logout\n"
393
- b"Choice: 1 - pov: Ordered 0 pizza(s)\n==================================================\n"
394
- b"--------------------------------------\n\t\tCalories: 0\n\t\tCarbs : 0\n\n"
395
- )
396
- add_options = {
397
- angr.options.UNICORN_HANDLE_CGC_RECEIVE_SYSCALL,
398
- angr.options.UNICORN_HANDLE_SYMBOLIC_ADDRESSES,
399
- angr.options.UNICORN_HANDLE_SYMBOLIC_CONDITIONS,
400
- }
401
- trace_cgc_with_pov_file(
402
- binary,
403
- "concrete_execution_in_native_interface",
404
- pov_file,
405
- output_initial_bytes,
406
- add_options=add_options,
407
- symbolic_stdin=False,
408
- )
409
-
410
- def test_d_flag_and_write_write_conflict_in_unicorn(self):
411
- """
412
- Check if d flag is handled correctly in unicorn native interface and write-write conflicts do not occur when
413
- re-executing symbolic instructions
414
- """
415
-
416
- binary = os.path.join(bin_location, "tests", "cgc", "CROMU_00008")
417
- pov_file = os.path.join(bin_location, "tests_data", "cgc_povs", "CROMU_00008_POV_00000.xml")
418
- output_initial_bytes = (
419
- b"> You logged in.\n> First name: Last name: User name: Birthdate (mm/dd/yy hh:mm:ss): "
420
- b"Date is: 12/21/1983 5:43:21\nData added, record 0\n"
421
- b"> Enter search express (firstname or fn, lastname or ln, username or un, birthdate or bd,"
422
- b" operators ==, !=, >, <, AND and OR):\n"
423
- )
424
- add_options = {
425
- angr.options.UNICORN_HANDLE_CGC_RECEIVE_SYSCALL,
426
- angr.options.UNICORN_HANDLE_SYMBOLIC_ADDRESSES,
427
- angr.options.UNICORN_HANDLE_SYMBOLIC_CONDITIONS,
428
- }
429
- trace_cgc_with_pov_file(
430
- binary,
431
- "tracer_d_flag_and_write_write_conflict_in_unicorn",
432
- pov_file,
433
- output_initial_bytes,
434
- add_options=add_options,
435
- )
436
-
437
- def test_empty_reexecute_block_remove_in_unicorn_native_interface(self):
438
- """
439
- Test if blocks with no symbolic instructions are removed from re-execution list in unicorn native interface.
440
- Re-execute instruction list of a block can become empty when all of them are removed when performing memory
441
- writes. See handle_write in unicorn native interface.
442
- """
443
-
444
- binary = os.path.join(bin_location, "tests", "cgc", "KPRCA_00052")
445
- pov_file = os.path.join(bin_location, "tests_data", "cgc_povs", "KPRCA_00052_POV_00000.xml")
446
- output_initial_bytes = (
447
- b"Enter system password: \nWelcome to the CGC Pizzeria order management system.\n1. Input Order\n"
448
- b"2. Update Order\n3. View One Orders\n4. View All Orders\n5. Delete Order\n6. Clear All Orders\n"
449
- b"7. Logout\n"
450
- b"Choice: Enter Pickup Name: Choose what the kind of pizza\n1. Pizza Pie - The classic!\n"
451
- b"2. Pizza Sub - All the fun, on a bun\n3. Pizza Bowl - Our own twist\nChoice: Select Size\n1. Small\n"
452
- b"2. Medium\n3. Large\nChoice: Successfully added a new Pizza Pie!\nSelect an option:\n1. Add Toppings\n"
453
- b"2. Remove Toppings\n3. Add Sauce\n4. Remove Sauce\n5. Finished With Pizza\nChoice: Successfully added "
454
- b"pizza!"
455
- b"\n1. Add another Pizza\n2. Quit\nChoice: 0. Cancel\n=================================================="
456
- b"\n "
457
- b"Item #1. Classic Pizza Pie, Size: SMALL\n Selected Toppings\n\tNone\n Sauce on the side\n\tNone\n"
458
- b"--------------------------------------\n\t\tCalories: 1000\n\t\tCarbs : 222\n\nPizza length... = 1"
459
- b"\n\t\t"
460
- b"Estimated wait time: 36 minute(s)\n==================================================\nChoice: "
461
- b"Removed Item #1\n1. Add another Pizza\n2. Quit\nChoice: Order successfully added!\n1. Input Order\n"
462
- b"2. Update Order\n3. View One Orders\n4. View All Orders\n5. Delete Order\n6. Clear All Orders\n7. "
463
- b"Logout\n"
464
- b"Choice: 1 - pov: Ordered 0 pizza(s)\n==================================================\n"
465
- b"--------------------------------------\n\t\tCalories: 0\n\t\tCarbs : 0\n\n"
466
- )
467
- add_options = {
468
- angr.options.UNICORN_HANDLE_CGC_RECEIVE_SYSCALL,
469
- angr.options.UNICORN_HANDLE_SYMBOLIC_ADDRESSES,
470
- angr.options.UNICORN_HANDLE_SYMBOLIC_CONDITIONS,
471
- }
472
- trace_cgc_with_pov_file(
473
- binary,
474
- "tracer_empty_reexecute_block_remove_in_unicorn_native_interface",
475
- pov_file,
476
- output_initial_bytes,
477
- add_options=add_options,
478
- )
479
-
480
- @unittest.skipIf(platform.system() == "Darwin" and platform.machine() == "arm64", "Broken on apple silicon")
481
- @unittest.skipIf(sys.platform == "win32", "broken on windows")
482
- def test_symbolic_sized_receives(self):
483
- b = os.path.join(bin_location, "tests", "cgc", "CROMU_00070")
484
-
485
- simgr, _ = tracer_cgc(b, "tracer_symbolic_sized_receives", b"hello")
486
- simgr.run()
487
-
488
- assert not simgr.crashed
489
- assert "traced" in simgr.stashes
490
-
491
- simgr, _ = tracer_cgc(b, "tracer_symbolic_sized_receives_nulls", b"\0" * 20)
492
- simgr.run()
493
-
494
- assert not simgr.crashed
495
- assert "traced" in simgr.stashes
496
-
497
- def test_allocation_base_continuity(self):
498
- correct_out = (
499
- b"prepare for a challenge\nb7fff000\nb7ffe000\nb7ffd000\nb7ffc000\nb7ffb000\nb7ffa000\nb7ff9000\nb7ff8000\n"
500
- b"b7ff7000\nb7ff6000\nb7ff5000\nb7ff4000\nb7ff3000\nb7ff2000\nb7ff1000\nb7ff0000\nb7fef000\nb7fee000\n"
501
- b"b7fed000\nb7fec000\ndeallocating b7ffa000\na: b7ffb000\nb: b7fff000\nc: b7ff5000\nd: b7feb000\n"
502
- b"e: b7fe8000\n"
503
- b"e: b7fa8000\na: b7ffe000\nb: b7ffd000\nc: b7ff7000\nd: b7ff6000\ne: b7ff3000\ne: b7f68000\nallocate: 3\n"
504
- b"a: b7fef000\n"
505
- )
506
-
507
- b = os.path.join(bin_location, "tests", "i386", "cgc_allocations")
508
-
509
- simgr, _ = tracer_cgc(b, "tracer_allocation_base_continuity", b"")
510
- simgr.run()
511
-
512
- assert simgr.traced[0].posix.dumps(1) == correct_out
513
-
514
- def test_crash_addr_detection(self):
515
- b = os.path.join(bin_location, "tests", "i386", "call_symbolic")
516
-
517
- simgr, _ = tracer_cgc(b, "tracer_crash_addr_detection", b"A" * 700)
518
- simgr.run()
519
-
520
- assert simgr.crashed
521
- assert simgr.crashed[0].solver.symbolic(simgr.crashed[0].regs.ip)
522
-
523
- @skip_if_not_linux
524
- def test_fauxware(self):
525
- b = os.path.join(bin_location, "tests", "x86_64", "fauxware")
526
- simgr, _ = tracer_linux(b, "tracer_fauxware", b"A" * 18, remove_options={angr.options.CPUID_SYMBOLIC})
527
- simgr.run()
528
-
529
- assert "traced" in simgr.stashes
530
-
531
- def test_rollback_on_symbolic_conditional_exit(self):
532
- """
533
- Test if state is correctly rolled back to before start of block in case block cannot be executed in unicorn
534
- engine because exit condition is symbolic
535
- """
536
- binary = os.path.join(bin_location, "tests", "cgc", "CROMU_00043")
537
- pov_file = os.path.join(bin_location, "tests_data", "cgc_povs", "CROMU_00043_POV_00000.xml")
538
- output_initial_bytes = [
539
- b"Network type: Broadcast",
540
- b"Source Address: 0x962B175B",
541
- b"Network type: Endpoint",
542
- b"Source Address: 0x321B00B0",
543
- b"Destination Address: 0xACF70019",
544
- b"Final Statistics:",
545
- b"\tTotal Packets: 6",
546
- b"\tStart Time: 0x5552C470",
547
- b"\tEnd Time: 0x54CAF0B0",
548
- b"\tLargest Packet: 0",
549
- b"\tSmallest Packet: 0",
550
- b"\tNumber of malformed packets: 0",
551
- b"\tNumber of packets shown 6",
552
- b"Option Headers:",
553
- b"This content has not been modified from the original",
554
- b"Capturing Authority: Network Provider",
555
- b"Capture Date: bKQcAXJJEqCSPmrIlRy",
556
- b"Capturing Authority: Employer\n",
557
- ]
558
- trace_cgc_with_pov_file(
559
- binary,
560
- "tracer_rollback_on_symbolic_conditional_exit",
561
- pov_file,
562
- b"\n".join(output_initial_bytes),
563
- )
564
-
565
- def test_floating_point_memory_reads(self):
566
- """
567
- Test float point memory reads in which bytes longer than architecture width are read in a single memory read
568
- hook in unicorn. The other related case is when such reads are split across multiple reads. This is tested in
569
- b01lersctf2020 little engine solver
570
- """
571
- binary = os.path.join(bin_location, "tests", "cgc", "NRFIN_00027")
572
- pov_file = os.path.join(bin_location, "tests_data", "cgc_povs", "NRFIN_00027_POV_00000.xml")
573
- output = b"\x00" * 36
574
- trace_cgc_with_pov_file(
575
- binary,
576
- "tracer_floating_point_memory_reads",
577
- pov_file,
578
- output,
579
- read_strategies=[angr.concretization_strategies.SimConcretizationStrategyAny(exact=True)],
580
- write_strategies=[angr.concretization_strategies.SimConcretizationStrategyAny(exact=True)],
581
- )
582
-
583
- def test_fdwait_fds(self):
584
- """
585
- Test fdwait working with appropriate bit order for read/write fds
586
- """
587
- binary = os.path.join(bin_location, "tests", "cgc", "CROMU_00029")
588
- pov_file = os.path.join(bin_location, "tests_data", "cgc_povs", "CROMU_00029_POV_00000.xml")
589
- output = [
590
- b"For what material would you like to run this simulation?",
591
- b" 1. Air",
592
- b" 2. Aluminum",
593
- b" 3. Copper",
594
- b" 4. Custom\nSelection: ",
595
- ]
596
- trace_cgc_with_pov_file(binary, "tracer_floating_point_memory_reads", pov_file, b"\n".join(output))
597
-
598
- def test_non_zero_offset_subregister_dependency_saving_unicorn_native_interface(self):
599
- """
600
- Test if concrete register dependencies of symbolic instructions are saved correctly in unicorn native interface
601
- for re-executing
602
- """
603
-
604
- binary = os.path.join(bin_location, "tests", "cgc", "KPRCA_00028")
605
- pov_file = os.path.join(bin_location, "tests_data", "cgc_povs", "KPRCA_00028_POV_00000.xml")
606
- output_initial_bytes = b"Welcome to the SLUR REPL. Type an expression to evaluate it.\n> "
607
- add_options = {
608
- angr.options.UNICORN_HANDLE_CGC_RECEIVE_SYSCALL,
609
- angr.options.UNICORN_HANDLE_SYMBOLIC_ADDRESSES,
610
- angr.options.UNICORN_HANDLE_SYMBOLIC_CONDITIONS,
611
- }
612
- trace_cgc_with_pov_file(
613
- binary,
614
- "tracer_non_zero_offset_subregister_dependency_saving_unicorn_native_interface",
615
- pov_file,
616
- output_initial_bytes,
617
- add_options=add_options,
618
- )
619
-
620
- def test_saving_dependencies_of_last_instruction_of_block_in_unicorn_native_interface(self):
621
- """
622
- Test if dependencies of last instruction in a basic block are saved in unicorn native interface
623
- """
624
-
625
- binary = os.path.join(bin_location, "tests", "cgc", "NRFIN_00026")
626
- pov_file = os.path.join(bin_location, "tests_data", "cgc_povs", "NRFIN_00026_POV_00000.xml")
627
- output_initial_bytes = (
628
- b"Starting dissection...\n\n\n====New Packet====\n\n\n===rofl===\n\n\n===rachiometersuprachoroid==="
629
- b"\n301478991"
630
- b"\nString display will be handled in v4.\n1\nString display will be handled in v4.\n0\n1\n"
631
- b"LV type will be handled in v4.\n3582705152\nString display will be handled in v4.\n"
632
- b"LV type will be handled in v4.\n190\n0\n===trolololo===\n"
633
- )
634
- add_options = {
635
- angr.options.UNICORN_HANDLE_CGC_RECEIVE_SYSCALL,
636
- angr.options.UNICORN_HANDLE_SYMBOLIC_ADDRESSES,
637
- angr.options.UNICORN_HANDLE_SYMBOLIC_CONDITIONS,
638
- }
639
- trace_cgc_with_pov_file(
640
- binary,
641
- "tracer_saving_dependencies_of_last_instruction_of_block_in_unicorn_native_interface",
642
- pov_file,
643
- output_initial_bytes,
644
- add_options=add_options,
645
- )
646
-
647
- @slow_test
648
- def test_sseround_register_dependency_unicorn_native_interface(self):
649
- """
650
- Test if value of SSEROUND VEX register is saved correctly when it is a dependency of an instruction that needs
651
- to be re-executed. Takes about 10 minutes.
652
- """
653
-
654
- binary = os.path.join(bin_location, "tests", "cgc", "NRFIN_00021")
655
- pov_file = os.path.join(bin_location, "tests_data", "cgc_povs", "NRFIN_00021_POV_00000.xml")
656
- output_initial_bytes = b""
657
- add_options = {
658
- angr.options.UNICORN_HANDLE_CGC_RECEIVE_SYSCALL,
659
- angr.options.UNICORN_HANDLE_SYMBOLIC_ADDRESSES,
660
- angr.options.UNICORN_HANDLE_SYMBOLIC_CONDITIONS,
661
- }
662
- trace_cgc_with_pov_file(
663
- binary,
664
- "tracer_sseround_register_dependency_unicorn_native_interface",
665
- pov_file,
666
- output_initial_bytes,
667
- add_options=add_options,
668
- )
669
-
670
- def test_concretize_unsupported_vex_irops(self):
671
- """
672
- Test tracing with concretizing unsupported VEX IR Ops
673
- """
674
-
675
- binary = os.path.join(bin_location, "tests", "cgc", "CROMU_00020")
676
- pov_file = os.path.join(bin_location, "tests_data", "cgc_povs", "CROMU_00020_POV_00000.xml")
677
- output = (
678
- b"\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00\x15"
679
- + b"\x00\x00\x00\x00\x00\x00\x00\x15\x00\x00\x00\x00\x00\x00\x00"
680
- )
681
- add_options = {
682
- angr.options.UNSUPPORTED_FORCE_CONCRETIZE,
683
- angr.options.UNICORN_HANDLE_CGC_RECEIVE_SYSCALL,
684
- angr.options.UNICORN_HANDLE_SYMBOLIC_ADDRESSES,
685
- angr.options.UNICORN_HANDLE_SYMBOLIC_CONDITIONS,
686
- }
687
- trace_cgc_with_pov_file(
688
- binary, "tracer_concretize_unsupported_vex_ops", pov_file, output, add_options=add_options
689
- )
690
-
691
- def test_skip_some_symbolic_memory_writes(self):
692
- """
693
- Test symbolic memory write skipping in SimEngineUnicorn during tracing
694
- This test doesn't actually check if instruction was skipped. It checks if tracing is successful
695
- """
696
-
697
- binary = os.path.join(bin_location, "tests", "cgc", "CROMU_00023")
698
- pov_file = os.path.join(bin_location, "tests_data", "cgc_povs", "CROMU_00023_POV_00000.xml")
699
- output_initial_bytes = [
700
- b"",
701
- b"C - Change Diver Info",
702
- b"L - Log a New Dive",
703
- b"D - Download Dive Data",
704
- b"E - Edit Dives",
705
- b"P - Print Dive Logs",
706
- b"R - Remove Dives",
707
- b"S - Diver Statistics",
708
- b"X - Exit Application",
709
- b":",
710
- b"",
711
- b"Dive Log is empty",
712
- b"",
713
- b"C - Change Diver Info",
714
- b"L - Log a New Dive",
715
- b"D - Download Dive Data",
716
- b"E - Edit Dives",
717
- b"P - Print Dive Logs",
718
- b"R - Remove Dives",
719
- b"S - Diver Statistics",
720
- b"X - Exit Application",
721
- b":",
722
- b"",
723
- b"Dive Log is empty",
724
- b"",
725
- b"C - Change Diver Info",
726
- b"L - Log a New Dive",
727
- b"D - Download Dive Data",
728
- b"E - Edit Dives",
729
- b"P - Print Dive Logs",
730
- b"R - Remove Dives",
731
- b"S - Diver Statistics",
732
- b"X - Exit Application",
733
- b":",
734
- (
735
- b"Dive Site: Date: Time: Location (area/city): Max Depth in ft: Avg Depth in ft: "
736
- b"Dive Duration (mins): O2 Percentage: Pressure In (psi): Pressure Out (psi): "
737
- ),
738
- b"C - Change Diver Info",
739
- b"L - Log a New Dive",
740
- b"D - Download Dive Data",
741
- b"E - Edit Dives",
742
- b"P - Print Dive Logs",
743
- b"R - Remove Dives",
744
- b"S - Diver Statistics",
745
- b"X - Exit Application",
746
- b":",
747
- (
748
- b"Dive Site: Date: Time: Location (area/city): Max Depth in ft: Avg Depth in ft: "
749
- b"Dive Duration (mins): O2 Percentage: Pressure In (psi): Pressure Out (psi): "
750
- ),
751
- b"C - Change Diver Info",
752
- b"L - Log a New Dive",
753
- b"D - Download Dive Data",
754
- b"E - Edit Dives",
755
- b"P - Print Dive Logs",
756
- b"R - Remove Dives",
757
- b"S - Diver Statistics",
758
- b"X - Exit Application",
759
- b":",
760
- (
761
- b"First Name: Last Name: Street: City: State: Zip Code: Phone Number: PADI Diver Number: "
762
- b"PADI Cert Date: "
763
- ),
764
- b" Name: ",
765
- ]
766
- trace_cgc_with_pov_file(
767
- binary,
768
- "tracer_skip_some_symbolic_memory_writes",
769
- pov_file,
770
- b"\n".join(output_initial_bytes),
771
- )
772
-
773
- def test_subregister_tainting(self):
774
- """
775
- Tests for subregister tainting: taint only bytes of subregister and not entire register
776
- """
777
- binary = os.path.join(bin_location, "tests", "cgc", "KPRCA_00028")
778
- pov_file = os.path.join(bin_location, "tests_data", "cgc_povs", "KPRCA_00028_POV_00000.xml")
779
- output_initial_bytes = b"Welcome to the SLUR REPL. Type an expression to evaluate it.\n> "
780
- trace_cgc_with_pov_file(binary, "tracer_subregister_tainting", pov_file, output_initial_bytes)
781
-
782
- def test_symbolic_memory_dependencies_liveness(self):
783
- """
784
- Tests for liveness of symbolic memory dependencies when re-executing symbolic instructions in SimEngineUnicorn
785
- NRFIN_00036
786
- """
787
- binary = os.path.join(bin_location, "tests", "cgc", "NRFIN_00036")
788
- pov_file = os.path.join(bin_location, "tests_data", "cgc_povs", "NRFIN_00036_POV_00000.xml")
789
- output_initial_bytes = b"New budget created!\nNew budget created!\nNew budget created!\nNew budget created!\n"
790
- trace_cgc_with_pov_file(
791
- binary,
792
- "tracer_symbolic_memory_dependencies_liveness",
793
- pov_file,
794
- output_initial_bytes,
795
- )
796
-
797
- # CROMU_00008
798
- binary = os.path.join(bin_location, "tests", "cgc", "CROMU_00008")
799
- pov_file = os.path.join(bin_location, "tests_data", "cgc_povs", "CROMU_00008_POV_00000.xml")
800
- output_initial_bytes = (
801
- b"> You logged in.\n> First name: Last name: User name: Birthdate (mm/dd/yy hh:mm:ss): "
802
- b"Date is: 12/21/1983 5:43:21\nData added, record 0\n"
803
- b"> Enter search express (firstname or fn, lastname or ln, username or un, birthdate or bd,"
804
- b" operators ==, !=, >, <, AND and OR):\n"
805
- )
806
- trace_cgc_with_pov_file(
807
- binary,
808
- "tracer_symbolic_memory_dependencies_liveness",
809
- pov_file,
810
- output_initial_bytes,
811
- )
812
-
813
- def test_symbolic_cgc_transmit_handling_in_native_interface(self):
814
- """
815
- Check if CGC transmit syscall with symbolic arguments is handled in native interface when tracing.
816
- """
817
-
818
- binary = os.path.join(bin_location, "tests", "cgc", "CROMU_00008")
819
- pov_file = os.path.join(bin_location, "tests_data", "cgc_povs", "CROMU_00008_POV_00000.xml")
820
- output_initial_bytes = (
821
- b"> You logged in.\n> First name: Last name: User name: Birthdate (mm/dd/yy hh:mm:ss): "
822
- b"Date is: 12/21/1983 5:43:21\nData added, record 0\n"
823
- b"> Enter search express (firstname or fn, lastname or ln, username or un, birthdate or bd,"
824
- b" operators ==, !=, >, <, AND and OR):\n"
825
- )
826
- add_options = {
827
- angr.options.UNICORN_HANDLE_CGC_RECEIVE_SYSCALL,
828
- angr.options.UNICORN_HANDLE_SYMBOLIC_ADDRESSES,
829
- angr.options.UNICORN_HANDLE_SYMBOLIC_CONDITIONS,
830
- angr.options.UNICORN_HANDLE_SYMBOLIC_SYSCALLS,
831
- }
832
- trace_cgc_with_pov_file(
833
- binary,
834
- "tracer_symbolic_cgc_transmit_handling_in_native_interface",
835
- pov_file,
836
- output_initial_bytes,
837
- add_options=add_options,
838
- )
839
-
840
- def test_user_controlled_code_execution(self):
841
- """
842
- Test user controlled code execution where instruction pointer is concrete and code is symbolic
843
- """
844
- binary = os.path.join(bin_location, "tests", "cgc", "NRFIN_00034")
845
- pov_file = os.path.join(bin_location, "tests_data", "cgc_povs", "NRFIN_00034_POV_00000.xml")
846
- output_initial_bytes = b"\x00" * 8
847
- trace_cgc_with_pov_file(binary, "tracer_user_controlled_code_execution", pov_file, output_initial_bytes)
848
-
849
-
850
- if __name__ == "__main__":
851
- logging.getLogger("angr.simos").setLevel("DEBUG")
852
- logging.getLogger("angr.state_plugins.preconstrainer").setLevel("DEBUG")
853
- logging.getLogger("angr.exploration_techniques.tracer").setLevel("DEBUG")
854
- logging.getLogger("angr.exploration_techniques.crash_monitor").setLevel("DEBUG")
855
-
856
- unittest.main()