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,574 +0,0 @@
1
- #!/usr/bin/env python3
2
- # pylint: disable=missing-class-docstring,no-self-use,line-too-long
3
-
4
- import logging
5
- import unittest
6
-
7
- import pyvex
8
- import claripy
9
-
10
- from angr import SimState, load_shellcode
11
- from angr.engines import HeavyVEXMixin
12
- import angr.engines.vex.claripy.ccall as s_ccall
13
-
14
- l = logging.getLogger(__name__)
15
-
16
-
17
- class TestVex(unittest.TestCase):
18
- def test_ccall(self):
19
- s = SimState(arch="AMD64")
20
-
21
- l.debug("Testing amd64_actions_ADD")
22
- l.debug("(8-bit) 1 + 1...")
23
- arg_l = s.solver.BVV(1, 8)
24
- arg_r = s.solver.BVV(1, 8)
25
- cf, pf, af, zf, sf, of = s_ccall.pc_actions_ADD(s, 8, arg_l, arg_r, 0, platform="AMD64")
26
- assert s.solver.is_true(cf == 0)
27
- assert s.solver.is_true(pf == 0)
28
- assert s.solver.is_true(af == 0)
29
- assert s.solver.is_true(zf == 0)
30
- assert s.solver.is_true(sf == 0)
31
- assert s.solver.is_true(of == 0)
32
-
33
- l.debug("(32-bit) (-1) + (-2)...")
34
- arg_l = s.solver.BVV(-1, 32)
35
- arg_r = s.solver.BVV(-1, 32)
36
- cf, pf, af, zf, sf, of = s_ccall.pc_actions_ADD(s, 32, arg_l, arg_r, 0, platform="AMD64")
37
- assert s.solver.is_true(cf == 1)
38
- assert s.solver.is_true(pf == 0)
39
- assert s.solver.is_true(af == 1)
40
- assert s.solver.is_true(zf == 0)
41
- assert s.solver.is_true(sf == 1)
42
- assert s.solver.is_true(of == 0)
43
-
44
- l.debug("Testing pc_actions_SUB")
45
- l.debug(
46
- "(8-bit) 1 - 1...",
47
- )
48
- arg_l = s.solver.BVV(1, 8)
49
- arg_r = s.solver.BVV(1, 8)
50
- cf, pf, af, zf, sf, of = s_ccall.pc_actions_SUB(s, 8, arg_l, arg_r, 0, platform="AMD64")
51
- assert s.solver.is_true(cf == 0)
52
- assert s.solver.is_true(pf == 1)
53
- assert s.solver.is_true(af == 0)
54
- assert s.solver.is_true(zf == 1)
55
- assert s.solver.is_true(sf == 0)
56
- assert s.solver.is_true(of == 0)
57
-
58
- l.debug("(32-bit) (-1) - (-2)...")
59
- arg_l = s.solver.BVV(-1, 32)
60
- arg_r = s.solver.BVV(-2, 32)
61
- cf, pf, af, zf, sf, of = s_ccall.pc_actions_SUB(s, 32, arg_l, arg_r, 0, platform="AMD64")
62
- assert s.solver.is_true(cf == 0)
63
- assert s.solver.is_true(pf == 0)
64
- assert s.solver.is_true(af == 0)
65
- assert s.solver.is_true(zf == 0)
66
- assert s.solver.is_true(sf == 0)
67
- assert s.solver.is_true(of == 0)
68
-
69
- l.debug("Testing pc_actions_ROL")
70
- l.debug("(8-bit) ROL 1 1...")
71
- result = s.solver.BVV(2, 8) # the result of rol(1, 1)
72
- oldflags = s.solver.BVV(0, 8)
73
- cf, pf, af, zf, sf, of = s_ccall.pc_actions_ROL(s, 8, result, None, oldflags, platform="AMD64")
74
- assert s.solver.is_true(cf == 0)
75
- assert s.solver.is_true(pf == 0)
76
- assert s.solver.is_true(af == 0)
77
- assert s.solver.is_true(zf == 0)
78
- assert s.solver.is_true(sf == 0)
79
- assert s.solver.is_true(of == 0)
80
-
81
- l.debug("(32-bit) ROL (-1) (-2)... (shift out of range)")
82
- result = s.solver.BVV(-1, 32) # the result of rol(-1, 0xfe)
83
- oldflags = s.solver.BVV(0, 32)
84
- cf, pf, af, zf, sf, of = s_ccall.pc_actions_ROL(s, 32, result, None, oldflags, platform="AMD64")
85
- assert s.solver.is_true(cf == 1)
86
- assert s.solver.is_true(pf == 0)
87
- assert s.solver.is_true(af == 0)
88
- assert s.solver.is_true(zf == 0)
89
- assert s.solver.is_true(sf == 0)
90
- assert s.solver.is_true(of == 0)
91
-
92
- l.debug("Testing pc_actions_ROR")
93
- l.debug("(32-bit) ROR 2 1...")
94
- result = s.solver.BVV(1, 32) # the result of ror(2, 1)
95
- oldflags = s.solver.BVV(0, 8)
96
- cf, pf, af, zf, sf, of = s_ccall.pc_actions_ROR(s, 32, result, None, oldflags, platform="AMD64")
97
- assert s.solver.is_true(cf == 0)
98
- assert s.solver.is_true(pf == 0)
99
- assert s.solver.is_true(af == 0)
100
- assert s.solver.is_true(zf == 0)
101
- assert s.solver.is_true(sf == 0)
102
- assert s.solver.is_true(of == 0)
103
-
104
- l.debug("Testing pc_actions_ROR")
105
- l.debug("(32-bit) ROR 1 1...")
106
- result = s.solver.BVV(0x80000000, 32) # the result of ror(1, 1)
107
- oldflags = s.solver.BVV(0, 8)
108
- cf, pf, af, zf, sf, of = s_ccall.pc_actions_ROR(s, 32, result, None, oldflags, platform="AMD64")
109
- assert s.solver.is_true(cf == 1)
110
- assert s.solver.is_true(pf == 0)
111
- assert s.solver.is_true(af == 0)
112
- assert s.solver.is_true(zf == 0)
113
- assert s.solver.is_true(sf == 0)
114
- assert s.solver.is_true(of == 1)
115
-
116
- l.debug("Testing pc_actions_ROR")
117
- l.debug("(32-bit) ROR -1 1...")
118
- result = s.solver.BVV(-1, 32) # the result of ror(0xffffffff, 1)
119
- oldflags = s.solver.BVV(0, 32)
120
- cf, pf, af, zf, sf, of = s_ccall.pc_actions_ROR(s, 32, result, None, oldflags, platform="AMD64")
121
- assert s.solver.is_true(cf == 1)
122
- assert s.solver.is_true(pf == 0)
123
- assert s.solver.is_true(af == 0)
124
- assert s.solver.is_true(zf == 0)
125
- assert s.solver.is_true(sf == 0)
126
- assert s.solver.is_true(of == 0)
127
-
128
- l.debug("(32-bit) ROR (-1) (-2)... (shift out of range)")
129
- result = s.solver.BVV(-1, 32) # the result of ror(0xffffffff, 0xfe)
130
- oldflags = s.solver.BVV(0, 32)
131
- cf, pf, af, zf, sf, of = s_ccall.pc_actions_ROR(s, 32, result, None, oldflags, platform="AMD64")
132
- assert s.solver.is_true(cf == 1)
133
- assert s.solver.is_true(pf == 0)
134
- assert s.solver.is_true(af == 0)
135
- assert s.solver.is_true(zf == 0)
136
- assert s.solver.is_true(sf == 0)
137
- assert s.solver.is_true(of == 0)
138
-
139
- l.debug("Testing pc_actions_SHR")
140
- l.debug("(64-bit) SHR 0xffffffffffffffff 1")
141
- result = s.solver.BVV(0x7FFFFFFFFFFFFFFF, 64)
142
- subshifted_result = s.solver.BVV(0xFFFFFFFFFFFFFFFF, 64)
143
- cf, pf, af, zf, sf, of = s_ccall.pc_actions_SHR(s, 64, result, subshifted_result, None, platform="AMD64")
144
- assert s.solver.is_true(cf == 1)
145
- assert s.solver.is_true(pf == 1)
146
- assert s.solver.is_true(af == 0)
147
- assert s.solver.is_true(zf == 0)
148
- assert s.solver.is_true(sf == 0)
149
- assert s.solver.is_true(of == 1)
150
-
151
- l.debug("Testing amd64_actions_ADCX")
152
-
153
- l.debug("(ADCX, 32-bit) 0xffffffff + 1...")
154
- arg_l = s.solver.BVV(0xFFFFFFFF, 32)
155
- arg_r = s.solver.BVV(1, 32)
156
- cf, pf, af, zf, sf, of = s_ccall.pc_actions_ADCX(
157
- s, 32, arg_l, arg_r, s.solver.BVV(0, 32), True, platform="AMD64"
158
- )
159
- assert s.solver.is_true(cf == 1)
160
- assert s.solver.is_true(of == 0)
161
-
162
- l.debug("(ADOX, 32-bit) 0xffffffff + 1...")
163
- arg_l = s.solver.BVV(0xFFFFFFFF, 32)
164
- arg_r = s.solver.BVV(1, 32)
165
- cf, pf, af, zf, sf, of = s_ccall.pc_actions_ADCX(
166
- s, 32, arg_l, arg_r, s.solver.BVV(0, 32), False, platform="AMD64"
167
- )
168
- assert s.solver.is_true(cf == 0)
169
- assert s.solver.is_true(of == 1)
170
-
171
- l.debug("(ADCX, 64-bit) 0xffffffffffffffff + 1...")
172
- arg_l = s.solver.BVV(0xFFFFFFFFFFFFFFFF, 64)
173
- arg_r = s.solver.BVV(1, 64)
174
- cf, pf, af, zf, sf, of = s_ccall.pc_actions_ADCX(
175
- s, 64, arg_l, arg_r, s.solver.BVV(0, 64), True, platform="AMD64"
176
- )
177
- assert s.solver.is_true(cf == 1)
178
- assert s.solver.is_true(of == 0)
179
-
180
- l.debug("(ADOX, 64-bit) 0xffffffffffffffff + 1...")
181
- arg_l = s.solver.BVV(0xFFFFFFFFFFFFFFFF, 64)
182
- arg_r = s.solver.BVV(1, 64)
183
- cf, pf, af, zf, sf, of = s_ccall.pc_actions_ADCX(
184
- s, 64, arg_l, arg_r, s.solver.BVV(0, 64), False, platform="AMD64"
185
- )
186
- assert s.solver.is_true(cf == 0)
187
- assert s.solver.is_true(of == 1)
188
-
189
- def test_aarch64_32bit_ccalls(self):
190
- # GitHub issue #1238
191
- s = SimState(arch="AArch64")
192
-
193
- x = s.solver.BVS("x", 32)
194
- # A normal operation
195
- flag_z = s_ccall.arm64g_calculate_flag_z(s, s_ccall.ARM64G_CC_OP_ADD32, x, s.solver.BVV(1, 32), 0)
196
- assert s.satisfiable(extra_constraints=(flag_z == 0,))
197
- assert s.satisfiable(extra_constraints=(flag_z == 1,))
198
- # What VEX does
199
- flag_z = s_ccall.arm64g_calculate_flag_z(
200
- s, s_ccall.ARM64G_CC_OP_ADD32, x.zero_extend(32), s.solver.BVV(1, 64), 0
201
- )
202
- assert s.satisfiable(extra_constraints=(flag_z == 0,))
203
- assert s.satisfiable(extra_constraints=(flag_z == 1,))
204
-
205
- def test_some_vector_ops(self):
206
- engine = HeavyVEXMixin(None)
207
- s = SimState(arch="AMD64")
208
-
209
- def translate(state, op, args): # pylint:disable=unused-argument
210
- return engine._perform_vex_expr_Op(op, args)
211
-
212
- a = s.solver.BVV(0xFFFF0000000100020003000400050006, 128)
213
- b = s.solver.BVV(0x00020002000200020002000200020002, 128)
214
-
215
- calc_result = translate(s, "Iop_Sub16x8", (a, b))
216
- correct_result = s.solver.BVV(0xFFFDFFFEFFFF00000001000200030004, 128)
217
- assert s.solver.is_true(calc_result == correct_result)
218
-
219
- calc_result = translate(s, "Iop_CmpEQ16x8", (a, b))
220
- correct_result = s.solver.BVV(0x000000000000FFFF0000000000000000, 128)
221
- assert s.solver.is_true(calc_result == correct_result)
222
-
223
- calc_result = translate(s, "Iop_CmpEQ8x16", (a, b))
224
- correct_result = s.solver.BVV(0x0000FF00FF00FFFFFF00FF00FF00FF00, 128)
225
- assert s.solver.is_true(calc_result == correct_result)
226
-
227
- calc_result = translate(s, "Iop_CmpGT16Sx8", (a, b))
228
- correct_result = s.solver.BVV(0x0000000000000000FFFFFFFFFFFFFFFF, 128)
229
- assert s.solver.is_true(calc_result == correct_result)
230
-
231
- calc_result = translate(s, "Iop_CmpGT16Ux8", (a, b))
232
- correct_result = s.solver.BVV(0xFFFF000000000000FFFFFFFFFFFFFFFF, 128)
233
- assert s.solver.is_true(calc_result == correct_result)
234
-
235
- calc_result = translate(s, "Iop_InterleaveLO16x8", (a, b))
236
- correct_result = s.solver.BVV(0x00030002000400020005000200060002, 128)
237
- assert s.solver.is_true(calc_result == correct_result)
238
-
239
- calc_result = translate(s, "Iop_InterleaveLO8x16", (a, b))
240
- correct_result = s.solver.BVV(0x00000302000004020000050200000602, 128)
241
- assert s.solver.is_true(calc_result == correct_result)
242
-
243
- calc_result = translate(s, "Iop_Min8Ux16", (a, b))
244
- correct_result = s.solver.BVV(0x00020000000100020002000200020002, 128)
245
- assert s.solver.is_true(calc_result == correct_result)
246
-
247
- calc_result = translate(s, "Iop_Min8Sx16", (a, b))
248
- correct_result = s.solver.BVV(0xFFFF0000000100020002000200020002, 128)
249
- assert s.solver.is_true(calc_result == correct_result)
250
-
251
- calc_result = translate(s, "Iop_QNarrowBin16Sto8Ux16", (a, b))
252
- correct_result = s.solver.BVV(0x00000102030405060202020202020202, 128)
253
- assert s.solver.is_true(calc_result == correct_result)
254
-
255
- c = s.solver.BVV(0xFF008877, 32)
256
- d = s.solver.BVV(0x11111111, 32)
257
-
258
- calc_result = translate(s, "Iop_HAdd8Sx4", (c, d))
259
- correct_result = s.solver.BVV(0x0808CC44, 32)
260
- assert s.solver.is_true(calc_result == correct_result)
261
-
262
- calc_result = translate(s, "Iop_QAdd8Sx4", (c, d))
263
- correct_result = s.solver.BVV(0x1011997F, 32)
264
- assert s.solver.is_true(calc_result == correct_result)
265
-
266
- calc_result = translate(s, "Iop_QAdd8Ux4", (c, d))
267
- correct_result = s.solver.BVV(0xFF119988, 32)
268
- assert s.solver.is_true(calc_result == correct_result)
269
-
270
- calc_result = translate(s, "Iop_QSub8Sx4", (c, d))
271
- correct_result = s.solver.BVV(0xEEEF8066, 32)
272
- assert s.solver.is_true(calc_result == correct_result)
273
-
274
- calc_result = translate(s, "Iop_QSub8Ux4", (c, d))
275
- correct_result = s.solver.BVV(0xEE007766, 32)
276
- assert s.solver.is_true(calc_result == correct_result)
277
-
278
- e = s.solver.BVV(0xFF00887766554433, 64)
279
- f = s.solver.BVV(0x0202000200020002, 64)
280
-
281
- calc_result = translate(s, "Iop_QNarrowBin16Sto8Ux8", (e, f))
282
- correct_result = s.solver.BVV(0x0000FFFFFF020202, 64)
283
- assert s.solver.is_true(calc_result == correct_result)
284
-
285
- gg = claripy.BVV(0x111111112222222233333333FFFFFFFF, 128)
286
- h = claripy.BVV(0x1111111100000000FFFFFFFFFFFFFFFF, 128)
287
-
288
- calc_result = translate(s, "Iop_CmpEQ32Fx4", (gg, h))
289
- correct_result = claripy.BVV(0xFFFFFFFF000000000000000000000000, 128)
290
- assert s.solver.is_true(calc_result == correct_result)
291
-
292
- calc_result = translate(s, "Iop_Clz32x4", (gg,))
293
- correct_result = claripy.BVV(0x00000003000000020000000200000000, 128)
294
- assert s.solver.is_true(calc_result == correct_result)
295
-
296
- i = claripy.BVV(0x1001000000001000, 64)
297
- j = claripy.BVV(0x100000000000F000, 64)
298
-
299
- calc_result = translate(s, "Iop_Mull16Sx4", (i, j))
300
- correct_result = claripy.BVV(0x10010000000000000000000FF000000, 128)
301
- assert s.solver.is_true(calc_result == correct_result)
302
-
303
- calc_result = translate(s, "Iop_Mull16Ux4", (i, j))
304
- correct_result = claripy.BVV(0x100100000000000000000000F000000, 128)
305
- assert s.solver.is_true(calc_result == correct_result)
306
-
307
- k = claripy.BVV(0xE7, 8)
308
- ll = claripy.BVV(0x1234, 16)
309
- m = claripy.BVV(0x12345678, 32)
310
-
311
- calc_result = translate(s, "Iop_Dup8x8", (k,))
312
- correct_result = claripy.BVV(0xE7E7E7E7E7E7E7E7, 64)
313
- assert s.solver.is_true(calc_result == correct_result)
314
-
315
- calc_result = translate(s, "Iop_Dup8x16", (k,))
316
- correct_result = claripy.BVV(0xE7E7E7E7E7E7E7E7E7E7E7E7E7E7E7E7, 128)
317
- assert s.solver.is_true(calc_result == correct_result)
318
-
319
- calc_result = translate(s, "Iop_Dup16x4", (ll,))
320
- correct_result = claripy.BVV(0x1234123412341234, 64)
321
- assert s.solver.is_true(calc_result == correct_result)
322
-
323
- calc_result = translate(s, "Iop_Dup16x8", (ll,))
324
- correct_result = claripy.BVV(0x12341234123412341234123412341234, 128)
325
- assert s.solver.is_true(calc_result == correct_result)
326
-
327
- calc_result = translate(s, "Iop_Dup32x2", (m,))
328
- correct_result = claripy.BVV(0x1234567812345678, 64)
329
- assert s.solver.is_true(calc_result == correct_result)
330
-
331
- calc_result = translate(s, "Iop_Dup32x4", (m,))
332
- correct_result = claripy.BVV(0x12345678123456781234567812345678, 128)
333
- assert s.solver.is_true(calc_result == correct_result)
334
-
335
- n = claripy.BVV(0x0123456789ABCDEF, 64)
336
- o = claripy.BVV(0xAF, 8)
337
- p = claripy.BVV(0xDFEC, 16)
338
- q = claripy.BVV(0xBFCFDFEF, 32)
339
- r = claripy.BVV(0x0102030405060708, 64)
340
- ss = claripy.BVS("index", 8)
341
-
342
- # According to the source code of LibVex, the index is a U8 constant
343
- calc_result = translate(s, "Iop_GetElem8x8", (n, claripy.BVV(0, 8)))
344
- correct_result = claripy.BVV(0xEF, 8)
345
- assert s.solver.is_true(calc_result == correct_result)
346
-
347
- calc_result = translate(s, "Iop_GetElem8x8", (n, claripy.BVV(1, 8)))
348
- correct_result = claripy.BVV(0xCD, 8)
349
- assert s.solver.is_true(calc_result == correct_result)
350
-
351
- calc_result = translate(s, "Iop_GetElem8x8", (n, claripy.BVV(6, 8)))
352
- correct_result = claripy.BVV(0x23, 8)
353
- assert s.solver.is_true(calc_result == correct_result)
354
-
355
- calc_result = translate(s, "Iop_GetElem8x8", (n, claripy.BVV(7, 8)))
356
- correct_result = claripy.BVV(0x01, 8)
357
- assert s.solver.is_true(calc_result == correct_result)
358
-
359
- calc_result = translate(s, "Iop_GetElem16x4", (n, claripy.BVV(0, 8)))
360
- correct_result = claripy.BVV(0xCDEF, 16)
361
- assert s.solver.is_true(calc_result == correct_result)
362
-
363
- calc_result = translate(s, "Iop_GetElem16x4", (n, claripy.BVV(3, 8)))
364
- correct_result = claripy.BVV(0x0123, 16)
365
- assert s.solver.is_true(calc_result == correct_result)
366
-
367
- calc_result = translate(s, "Iop_GetElem32x2", (n, claripy.BVV(0, 8)))
368
- correct_result = claripy.BVV(0x89ABCDEF, 32)
369
- assert s.solver.is_true(calc_result == correct_result)
370
-
371
- calc_result = translate(s, "Iop_GetElem32x2", (n, claripy.BVV(1, 8)))
372
- correct_result = claripy.BVV(0x01234567, 32)
373
- assert s.solver.is_true(calc_result == correct_result)
374
-
375
- calc_result = translate(s, "Iop_SetElem8x8", (n, claripy.BVV(0, 8), o))
376
- correct_result = claripy.BVV(0x0123456789ABCDAF, 64)
377
- assert s.solver.is_true(calc_result == correct_result)
378
-
379
- calc_result = translate(s, "Iop_SetElem8x8", (n, claripy.BVV(1, 8), o))
380
- correct_result = claripy.BVV(0x0123456789ABAFEF, 64)
381
- assert s.solver.is_true(calc_result == correct_result)
382
-
383
- calc_result = translate(s, "Iop_SetElem8x8", (n, claripy.BVV(6, 8), o))
384
- correct_result = claripy.BVV(0x01AF456789ABCDEF, 64)
385
- assert s.solver.is_true(calc_result == correct_result)
386
-
387
- calc_result = translate(s, "Iop_SetElem8x8", (n, claripy.BVV(7, 8), o))
388
- correct_result = claripy.BVV(0xAF23456789ABCDEF, 64)
389
- assert s.solver.is_true(calc_result == correct_result)
390
-
391
- calc_result = translate(s, "Iop_SetElem16x4", (n, claripy.BVV(0, 8), p))
392
- correct_result = claripy.BVV(0x0123456789ABDFEC, 64)
393
- assert s.solver.is_true(calc_result == correct_result)
394
-
395
- calc_result = translate(s, "Iop_SetElem16x4", (n, claripy.BVV(3, 8), p))
396
- correct_result = claripy.BVV(0xDFEC456789ABCDEF, 64)
397
- assert s.solver.is_true(calc_result == correct_result)
398
-
399
- calc_result = translate(s, "Iop_SetElem32x2", (n, claripy.BVV(0, 8), q))
400
- correct_result = claripy.BVV(0x01234567BFCFDFEF, 64)
401
- assert s.solver.is_true(calc_result == correct_result)
402
-
403
- calc_result = translate(s, "Iop_SetElem32x2", (n, claripy.BVV(1, 8), q))
404
- correct_result = claripy.BVV(0xBFCFDFEF89ABCDEF, 64)
405
- assert s.solver.is_true(calc_result == correct_result)
406
-
407
- # Symbolic indexes
408
- calc_result = translate(ss, "Iop_GetElem8x8", (r, ss))
409
- correct_result = claripy.If(
410
- ss == 7,
411
- claripy.BVV(0x01, 8),
412
- claripy.If(
413
- ss == 6,
414
- claripy.BVV(0x02, 8),
415
- claripy.If(
416
- ss == 5,
417
- claripy.BVV(0x03, 8),
418
- claripy.If(
419
- ss == 4,
420
- claripy.BVV(0x04, 8),
421
- claripy.If(
422
- ss == 3,
423
- claripy.BVV(0x05, 8),
424
- claripy.If(
425
- ss == 2,
426
- claripy.BVV(0x06, 8),
427
- claripy.If(ss == 1, claripy.BVV(0x07, 8), claripy.BVV(0x08, 8)),
428
- ),
429
- ),
430
- ),
431
- ),
432
- ),
433
- )
434
- assert s.solver.is_true(calc_result == correct_result)
435
-
436
- calc_result = translate(s, "Iop_GetElem16x4", (r, ss))
437
- correct_result = claripy.If(
438
- ss == 3,
439
- claripy.BVV(0x0102, 16),
440
- claripy.If(
441
- ss == 2,
442
- claripy.BVV(0x0304, 16),
443
- claripy.If(ss == 1, claripy.BVV(0x0506, 16), claripy.BVV(0x0708, 16)),
444
- ),
445
- )
446
- assert s.solver.is_true(calc_result == correct_result)
447
-
448
- calc_result = translate(s, "Iop_GetElem32x2", (r, ss))
449
- correct_result = claripy.If(ss == 1, claripy.BVV(0x01020304, 32), claripy.BVV(0x05060708, 32))
450
- assert s.solver.is_true(calc_result == correct_result)
451
-
452
- r_slices = r.chop(8)
453
- calc_result = translate(s, "Iop_SetElem8x8", (r, ss, o))
454
- correct_result = claripy.Concat(
455
- claripy.If(ss == 7, o, r_slices[0]),
456
- claripy.If(ss == 6, o, r_slices[1]),
457
- claripy.If(ss == 5, o, r_slices[2]),
458
- claripy.If(ss == 4, o, r_slices[3]),
459
- claripy.If(ss == 3, o, r_slices[4]),
460
- claripy.If(ss == 2, o, r_slices[5]),
461
- claripy.If(ss == 1, o, r_slices[6]),
462
- claripy.If(ss == 0, o, r_slices[7]),
463
- )
464
- assert s.solver.is_true(calc_result == correct_result)
465
-
466
- r_slices = r.chop(16)
467
- calc_result = translate(s, "Iop_SetElem16x4", (r, ss, p))
468
- correct_result = claripy.Concat(
469
- claripy.If(ss == 3, p, r_slices[0]),
470
- claripy.If(ss == 2, p, r_slices[1]),
471
- claripy.If(ss == 1, p, r_slices[2]),
472
- claripy.If(ss == 0, p, r_slices[3]),
473
- )
474
- assert s.solver.is_true(calc_result == correct_result)
475
-
476
- r_slices = r.chop(32)
477
- calc_result = translate(s, "Iop_SetElem32x2", (r, ss, q))
478
- correct_result = claripy.Concat(
479
- claripy.If(ss == 1, q, r_slices[0]),
480
- claripy.If(ss == 0, q, r_slices[1]),
481
- )
482
- assert s.solver.is_true(calc_result == correct_result)
483
-
484
- def test_store_simplification(self):
485
- state = SimState(arch="X86")
486
- state.regs.esp = state.solver.BVS("stack_pointer", 32)
487
- state.regs.ebp = state.solver.BVS("base_pointer", 32)
488
- state.regs.eax = state.solver.BVS("base_eax", 32)
489
-
490
- irsb = pyvex.IRSB(b"PT]\xc2\x10\x00", 0x4000, state.arch)
491
- sim_successors = HeavyVEXMixin(None).process(state.copy(), irsb=irsb)
492
- exit_state = sim_successors.all_successors[0]
493
-
494
- assert claripy.backends.z3.is_true(exit_state.regs.ebp == state.regs.esp - 4)
495
-
496
- def test_loadg_no_constraint_creation(self):
497
- state = SimState(arch="armel", mode="symbolic")
498
- engine = HeavyVEXMixin(None)
499
-
500
- stmt = pyvex.IRStmt.LoadG(
501
- "Iend_LE",
502
- "ILGop_16Uto32",
503
- 0, # dst
504
- pyvex.IRExpr.Const(pyvex.const.U32(0x2000)), # addr (src)
505
- pyvex.IRExpr.Const(pyvex.const.U32(0x1337)), # alt
506
- pyvex.IRExpr.RdTmp(1), # guard
507
- )
508
- tyenv = pyvex.IRTypeEnv(state.arch)
509
- tyenv.types = ["Ity_I32", "Ity_I32"]
510
- state.scratch.set_tyenv(tyenv)
511
- state.scratch.temps[1] = state.solver.BVS("tmp_1", 32)
512
- engine.state = state
513
- engine._handle_vex_stmt(stmt)
514
-
515
- # LOADG should not create new constraints - it is a simple conditional memory read. The conditions should only
516
- # be used inside the value AST to guard the memory read.
517
- assert not state.solver.constraints
518
- assert state.scratch.temps[0] is not None
519
- assert state.scratch.temps[0].variables.issuperset(state.scratch.temps[1].variables)
520
- assert state.scratch.temps[0].op == "If"
521
-
522
- def test_amd64_ud012_behaviors(self):
523
- # Test if VEX's lifter behaves as what CFGFast expects
524
- #
525
- # Note: if such behaviors change in the future, you also need to fix the ud{0,1,2} handling logic in
526
- # CFGFast._generate_cfgnode().
527
-
528
- # according to VEX, ud0 is not part of the block
529
- a = load_shellcode(b"\x90\x90\x0f\xff", "amd64")
530
- block_0 = a.factory.block(0)
531
- assert block_0.size == 2
532
-
533
- # according to VEX, ud1 is not part of the block
534
- a = load_shellcode(b"\x90\x90\x0f\xb9", "amd64")
535
- block_1 = a.factory.block(0)
536
- assert block_1.size == 2
537
-
538
- # according to VEX, ud2 under AMD64 *is* part of the block
539
- a = load_shellcode(b"\x90\x90\x0f\x0b", "amd64")
540
- block_2 = a.factory.block(0)
541
- assert block_2.size == 4
542
-
543
- def test_x86_ud2_behaviors(self):
544
- # Test if VEX's lifter behaves as what CFGFast expects
545
- #
546
- # Note: if such behaviors change in the future, you also need to fix the ud2 handling logic in
547
- # CFGFast._generate_cfgnode().
548
-
549
- # according to VEX, ud2 on x86 is not part of the block
550
- a = load_shellcode(b"\x90\x90\x0f\x0b", "x86")
551
- block_0 = a.factory.block(0)
552
- assert block_0.size == 2
553
-
554
- def test_blsr(self):
555
- p = load_shellcode(bytes.fromhex("c4e2f8f3cf0f95c00fb6c0c3"), arch="amd64")
556
- # compiled form of !!(x & (x - 1))
557
- # 2c0: c4 e2 f8 f3 cf blsr %rdi,%rax
558
-
559
- # 2c5: 0f 95 c0 setne %al
560
- # 2c8: 0f b6 c0 movzbl %al,%eax
561
- # 2cb: c3 retq
562
- x = claripy.BVS("x", 64)
563
- s = p.factory.call_state(0, x)
564
- sm = p.factory.simulation_manager(s)
565
- sm.run()
566
-
567
- target_func = claripy.If((x & (x - 1)) == 0, claripy.BVV(0, 64), 1)
568
- solver = claripy.Solver()
569
- solver.add(sm.one_deadended.regs.rax != target_func)
570
- assert not solver.satisfiable()
571
-
572
-
573
- if __name__ == "__main__":
574
- unittest.main()
File without changes
@@ -1,45 +0,0 @@
1
- #!/usr/bin/env python3
2
- __package__ = __package__ or "tests.exploration_techniques" # pylint:disable=redefined-builtin
3
-
4
- import tempfile
5
- import os
6
- import logging
7
- import unittest
8
-
9
- import angr
10
-
11
- from ..common import bin_location, broken
12
-
13
-
14
- test_location = os.path.join(bin_location, "tests")
15
- l = logging.getLogger("angr_tests.managers")
16
-
17
-
18
- # pylint: disable=missing-class-docstring
19
- # pylint: disable=no-self-use
20
- class TestCacher(unittest.TestCase):
21
- @broken
22
- def test_cacher(self):
23
- p = angr.Project(os.path.join(test_location, "x86_64", "fauxware"), load_options={"auto_load_libs": False})
24
-
25
- tmp_dir = tempfile.mkdtemp(prefix="test_cacher_container")
26
- container = os.path.join(tmp_dir, "%s.cache" % os.path.basename(p.filename))
27
-
28
- pg = p.factory.simulation_manager()
29
- pg.use_technique(angr.exploration_techniques.Cacher(when=0x4006EE, container=container))
30
- pg.run()
31
-
32
- pg2 = p.factory.simulation_manager()
33
- pg2.use_technique(angr.exploration_techniques.Cacher(container=container))
34
- assert pg2.active[0].addr == 0x4006ED
35
-
36
- pg2.run()
37
-
38
- assert len(pg2.deadended) == len(pg.deadended)
39
- assert pg2.deadended[0].addr in [s.addr for s in pg.deadended]
40
- assert pg2.deadended[1].addr in [s.addr for s in pg.deadended]
41
- assert pg2.deadended[2].addr in [s.addr for s in pg.deadended]
42
-
43
-
44
- if __name__ == "__main__":
45
- unittest.main()
@@ -1,67 +0,0 @@
1
- #!/usr/bin/env python3
2
- # pylint: disable=missing-class-docstring,disable=no-self-use
3
- __package__ = __package__ or "tests.exploration_techniques" # pylint:disable=redefined-builtin
4
-
5
- import os
6
- import logging
7
- import unittest
8
-
9
- import angr
10
- from angr.sim_type import SimTypePointer, SimTypeChar
11
-
12
- from ..common import bin_location
13
-
14
-
15
- test_location = os.path.join(bin_location, "tests")
16
-
17
-
18
- class TestDirector(unittest.TestCase):
19
- def test_execute_address_brancher(self):
20
- p = angr.Project(os.path.join(test_location, "x86_64", "brancher"), load_options={"auto_load_libs": False})
21
-
22
- pg = p.factory.simulation_manager()
23
-
24
- # initialize the exploration technique
25
- dm = angr.exploration_techniques.Director(num_fallback_states=1)
26
- goal = angr.exploration_techniques.ExecuteAddressGoal(0x400594)
27
- dm.add_goal(goal)
28
- pg.use_technique(dm)
29
-
30
- pg.explore(find=(0x4005B4,))
31
-
32
- assert len(pg.deprioritized) > 0
33
-
34
- def test_call_function_brancher(self):
35
- class NonLocal:
36
- the_state = None
37
- the_goal = None
38
-
39
- def goal_reached_callback(goal, p, pg): # pylint:disable=unused-argument
40
- NonLocal.the_state = p
41
- NonLocal.the_goal = goal
42
-
43
- p = angr.Project(os.path.join(test_location, "x86_64", "brancher"), load_options={"auto_load_libs": False})
44
-
45
- pg = p.factory.simulation_manager()
46
-
47
- # initialize the exploration technique
48
- dm = angr.exploration_techniques.Director(
49
- cfg_keep_states=True, goal_satisfied_callback=goal_reached_callback, num_fallback_states=1
50
- )
51
- _ = p.analyses.CFG()
52
- puts_func = p.kb.functions.function(name="puts")
53
- goal = angr.exploration_techniques.CallFunctionGoal(puts_func, [(SimTypePointer(SimTypeChar()), ">=20")])
54
- dm.add_goal(goal)
55
- pg.use_technique(dm)
56
-
57
- pg.explore(find=(0x40059E,))
58
-
59
- assert len(pg.deprioritized) > 0
60
- assert len(pg.found) > 0
61
- assert NonLocal.the_state is not None
62
- assert NonLocal.the_goal is goal
63
-
64
-
65
- if __name__ == "__main__":
66
- logging.getLogger("angr.exploration_techniques.director").setLevel(logging.DEBUG)
67
- unittest.main()