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,53 +0,0 @@
1
- #!/usr/bin/env python3
2
- # pylint: disable=missing-class-docstring,no-self-use,line-too-long
3
- __package__ = __package__ or "tests.procedures" # pylint:disable=redefined-builtin
4
-
5
- import os
6
- import unittest
7
-
8
- import archinfo
9
-
10
- import angr
11
- from angr.procedures.definitions.user32 import lib
12
- from angr.sim_type import SimTypeFunction, SimTypeInt, SimTypePointer, SimTypeChar
13
- from angr.engines.successors import SimSuccessors
14
- from angr.calling_conventions import SimCCStdcall, SimStackArg
15
-
16
- from ..common import bin_location
17
-
18
-
19
- test_location = os.path.join(bin_location, "tests")
20
-
21
-
22
- class TestStubProcedureArgs(unittest.TestCase):
23
- def test_stub_procedure_args(self):
24
- # stub procedures should have the right number of arguments
25
-
26
- lib.set_prototype(
27
- "____a_random_stdcall_function__",
28
- SimTypeFunction(
29
- [SimTypeInt(signed=True), SimTypeInt(signed=True), SimTypeInt(signed=False)],
30
- SimTypePointer(SimTypeChar(), offset=0),
31
- arg_names=["_random_arg_0", "_random_arg_1", "_random_arg_2"],
32
- ),
33
- )
34
- stub = lib.get_stub("____a_random_stdcall_function__", archinfo.ArchX86())
35
- stub.cc = SimCCStdcall(archinfo.ArchX86())
36
- lib._apply_metadata(stub, archinfo.ArchX86())
37
- assert len(stub.prototype.args) == 3
38
- assert all(isinstance(arg, SimStackArg) for arg in stub.cc.arg_locs(stub.prototype))
39
-
40
- proj = angr.Project(os.path.join(test_location, "i386", "all"), auto_load_libs=False)
41
- state = proj.factory.blank_state()
42
-
43
- initial_sp = state.regs.sp
44
- stub.state = state
45
- stub.successors = SimSuccessors(0, state)
46
- stub.ret(0)
47
-
48
- succ = stub.successors.all_successors[0]
49
- assert state.solver.eval_one(succ.regs.sp - initial_sp) == 0x10
50
-
51
-
52
- if __name__ == "__main__":
53
- unittest.main()
File without changes
@@ -1,197 +0,0 @@
1
- #!/usr/bin/env python3
2
- # pylint: disable=missing-class-docstring,disable=no-self-use
3
- __package__ = __package__ or "tests.serialization" # pylint:disable=redefined-builtin
4
-
5
- import os
6
- import tempfile
7
- import shutil
8
- import unittest
9
-
10
- import angr
11
- from angr.angrdb import AngrDB
12
-
13
- from ..common import bin_location
14
-
15
-
16
- test_location = os.path.join(bin_location, "tests")
17
-
18
-
19
- class TestDb(unittest.TestCase):
20
- def test_angrdb_fauxware(self):
21
- bin_path = os.path.join(test_location, "x86_64", "fauxware")
22
-
23
- proj = angr.Project(bin_path, auto_load_libs=False)
24
- cfg: angr.analyses.CFGFast = proj.analyses.CFGFast(data_references=True, cross_references=True, normalize=True)
25
- proj.kb.comments[proj.entry] = "Entry point"
26
-
27
- dtemp = tempfile.mkdtemp()
28
- db_file = os.path.join(dtemp, "fauxware.adb")
29
-
30
- db = AngrDB(proj)
31
- db.dump(db_file)
32
-
33
- db1 = AngrDB()
34
- new_proj = db1.load(db_file)
35
-
36
- assert len(new_proj.kb.cfgs["CFGFast"].nodes()) == len(cfg.model.nodes())
37
- assert len(new_proj.kb.functions) == len(proj.kb.functions)
38
-
39
- # compare each function
40
- for func in proj.kb.functions.values():
41
- new_func = new_proj.kb.functions[func.addr]
42
-
43
- assert func.addr == new_func.addr
44
- assert func.normalized == new_func.normalized
45
-
46
- assert len(func.transition_graph.nodes()) == len(new_func.transition_graph.nodes())
47
- assert set(map(lambda x: x.addr, func.transition_graph.nodes())) == set(
48
- map(lambda x: x.addr, new_func.transition_graph.nodes())
49
- )
50
- assert len(func.transition_graph.edges()) == len(new_func.transition_graph.edges())
51
-
52
- # compare call graph
53
- callgraph_nodes_old = set(proj.kb.callgraph.nodes)
54
- callgraph_nodes_new = set(new_proj.kb.callgraph.nodes)
55
- callgraph_edges_old = set(proj.kb.callgraph.edges)
56
- callgraph_edges_new = set(new_proj.kb.callgraph.edges)
57
-
58
- assert callgraph_nodes_old == callgraph_nodes_new
59
- assert callgraph_edges_old == callgraph_edges_new
60
-
61
- # compare CFG
62
- new_cfg = new_proj.kb.cfgs["CFGFast"]
63
- for node in cfg.model.nodes():
64
- new_node = new_cfg.get_any_node(node.addr)
65
-
66
- assert new_node.addr == node.addr
67
- assert new_node.size == node.size
68
-
69
- # compare memory data
70
- for addr, memory_data in cfg.model.memory_data.items():
71
- new_memory_data = new_cfg.memory_data[addr]
72
-
73
- assert memory_data.addr == new_memory_data.addr
74
- assert memory_data.size == new_memory_data.size
75
- assert memory_data.reference_size == new_memory_data.reference_size
76
- assert memory_data.sort == new_memory_data.sort
77
- assert memory_data.content == new_memory_data.content
78
-
79
- assert cfg.model.insn_addr_to_memory_data.keys() == new_cfg.insn_addr_to_memory_data.keys()
80
-
81
- # comments
82
- for addr, comment in proj.kb.comments.items():
83
- new_comment = new_proj.kb.comments.get(addr, None)
84
-
85
- assert comment == new_comment
86
-
87
- def test_angrdb_open_multiple_times(self):
88
- bin_path = os.path.join(test_location, "x86_64", "fauxware")
89
-
90
- proj = angr.Project(bin_path, auto_load_libs=False)
91
- _: angr.analyses.CFGFast = proj.analyses.CFGFast(data_references=True, cross_references=True, normalize=True)
92
- proj.kb.comments[proj.entry] = "Entry point"
93
-
94
- dtemp = tempfile.mkdtemp()
95
- db_file = os.path.join(dtemp, "fauxware.adb")
96
-
97
- db = AngrDB(proj)
98
- db.dump(db_file)
99
-
100
- # attempt 0
101
- db0 = AngrDB()
102
- proj0 = db0.load(db_file)
103
-
104
- # attempt 1
105
- db1 = AngrDB()
106
- proj1 = db1.load(db_file)
107
-
108
- # attempt 2
109
- db2 = AngrDB()
110
- proj2 = db2.load(db_file)
111
-
112
- # attempt 3
113
- db3 = AngrDB()
114
- proj3 = db3.load(db_file)
115
-
116
- # compare functions
117
- for func in proj.kb.functions.values():
118
- for p in [proj0, proj1, proj2, proj3]:
119
- new_func = p.kb.functions[func.addr]
120
-
121
- assert func.addr == new_func.addr
122
- assert func.normalized == new_func.normalized
123
-
124
- assert len(func.transition_graph.nodes()) == len(new_func.transition_graph.nodes())
125
- assert set(map(lambda x: x.addr, func.transition_graph.nodes())) == set(
126
- map(lambda x: x.addr, new_func.transition_graph.nodes())
127
- )
128
- assert len(func.transition_graph.edges()) == len(new_func.transition_graph.edges())
129
-
130
- def test_angrdb_save_multiple_times(self):
131
- bin_path = os.path.join(test_location, "x86_64", "fauxware")
132
-
133
- proj = angr.Project(bin_path, auto_load_libs=False)
134
- _: angr.analyses.CFGFast = proj.analyses.CFGFast(data_references=True, cross_references=True, normalize=True)
135
- proj.kb.comments[proj.entry] = "Entry point"
136
-
137
- dtemp = tempfile.mkdtemp()
138
- db_file = os.path.join(dtemp, "fauxware.adb")
139
-
140
- # attempt 0
141
- db = AngrDB(proj)
142
- db.dump(db_file)
143
-
144
- # attempt 1
145
- proj0 = AngrDB().load(db_file)
146
- assert proj0.kb.comments[proj.entry] == "Entry point"
147
- proj0.kb.comments[proj.entry] = "Comment 0"
148
- AngrDB(proj0).dump(db_file)
149
-
150
- # attempt 2
151
- proj1 = AngrDB().load(db_file)
152
- assert proj1.kb.comments[proj.entry] == "Comment 0"
153
- proj1.kb.comments[proj.entry] = "Comment 1"
154
- AngrDB(proj1).dump(db_file)
155
-
156
- # attempt 3
157
- proj1 = AngrDB().load(db_file)
158
- assert proj1.kb.comments[proj.entry] == "Comment 1"
159
- proj1.kb.comments[proj.entry] = "Comment 22222222222222222222222"
160
- AngrDB(proj1).dump(db_file)
161
-
162
- # attempt 4
163
- proj1 = AngrDB().load(db_file)
164
- assert proj1.kb.comments[proj.entry] == "Comment 22222222222222222222222"
165
-
166
- def test_angrdb_save_without_binary_existence(self):
167
- bin_path = os.path.join(test_location, "x86_64", "fauxware")
168
-
169
- with tempfile.TemporaryDirectory() as td:
170
- db_file = os.path.join(td, "proj.adb")
171
-
172
- with tempfile.TemporaryDirectory() as td0:
173
- tmp_path = os.path.join(td0, os.path.basename(bin_path))
174
- shutil.copy(bin_path, tmp_path)
175
- proj = angr.Project(tmp_path, auto_load_libs=False)
176
-
177
- AngrDB(proj).dump(db_file)
178
-
179
- del proj
180
- os.remove(tmp_path)
181
-
182
- # now that the binary file no longer exists, we should be able to open the angr DB and save it without
183
- # raising exceptions.
184
-
185
- proj = AngrDB().load(db_file)
186
- os.remove(db_file)
187
-
188
- db_file_new = os.path.join(td, "proj_new.adb")
189
- AngrDB(proj).dump(db_file_new)
190
-
191
- # we should be able to load it back!
192
- proj_new = AngrDB().load(db_file_new)
193
- assert os.path.basename(proj_new.loader.main_object.binary) == "fauxware"
194
-
195
-
196
- if __name__ == "__main__":
197
- unittest.main()
@@ -1,95 +0,0 @@
1
- #!/usr/bin/env python3
2
- __package__ = __package__ or "tests.serialization" # pylint:disable=redefined-builtin
3
-
4
- from contextlib import suppress
5
- import gc
6
- import os
7
- import pickle
8
- import shutil
9
- import unittest
10
-
11
- from claripy import BVS
12
-
13
- import angr
14
- from angr.storage import SimFile
15
-
16
- from ..common import bin_location
17
-
18
-
19
- test_location = os.path.join(bin_location, "tests")
20
-
21
-
22
- class TestPickle(unittest.TestCase):
23
- @classmethod
24
- def tearDown(self):
25
- shutil.rmtree("pickletest", ignore_errors=True)
26
- shutil.rmtree("pickletest2", ignore_errors=True)
27
- with suppress(FileNotFoundError):
28
- os.remove("pickletest_good")
29
- with suppress(FileNotFoundError):
30
- os.remove("pickletest_bad")
31
-
32
- def _load_pickles(self):
33
- # This is the working case
34
- f = open("pickletest_good", "rb")
35
- f.close()
36
-
37
- # This will not work
38
- f = open("pickletest_bad", "rb")
39
- f.close()
40
-
41
- def _make_pickles(self):
42
- p = angr.Project(os.path.join(test_location, "i386", "fauxware"))
43
-
44
- fs = {
45
- "/dev/stdin": SimFile("/dev/stdin"),
46
- "/dev/stdout": SimFile("/dev/stdout"),
47
- "/dev/stderr": SimFile("/dev/stderr"),
48
- }
49
-
50
- MEM_SIZE = 1024
51
- mem_bvv = {}
52
- for f in fs:
53
- mem = BVS(f, MEM_SIZE * 8)
54
- mem_bvv[f] = mem
55
-
56
- f = open("pickletest_good", "wb")
57
- pickle.dump(mem_bvv, f, -1)
58
- f.close()
59
-
60
- # If you do not have a state you cannot write
61
- _ = p.factory.entry_state(fs=fs)
62
- for f in fs:
63
- mem = mem_bvv[f]
64
- fs[f].write(0, mem, MEM_SIZE)
65
-
66
- f = open("pickletest_bad", "wb")
67
- pickle.dump(mem_bvv, f, -1)
68
- f.close()
69
-
70
- def test_pickling(self):
71
- self._make_pickles()
72
- self._load_pickles()
73
- gc.collect()
74
- self._load_pickles()
75
-
76
- def test_project_pickling(self):
77
- # AnalysesHub should not be pickled together with the project itself
78
- p = angr.Project(os.path.join(test_location, "i386", "fauxware"))
79
-
80
- # make a copy of the active_preset so that we do not touch the global preset object. this is only for writing
81
- # this test case.
82
- p.analyses._active_preset = pickle.loads(pickle.dumps(p.analyses._active_preset, -1))
83
- assert len(p.analyses._active_preset._default_plugins) > 0
84
- p.analyses._active_preset = p.analyses._active_preset
85
- p.analyses._active_preset._default_plugins = {}
86
- assert len(p.analyses._active_preset._default_plugins) == 0
87
-
88
- s = pickle.dumps(p, -1)
89
-
90
- p1 = pickle.loads(s)
91
- assert len(p1.analyses._active_preset._default_plugins) > 0
92
-
93
-
94
- if __name__ == "__main__":
95
- unittest.main()
@@ -1,132 +0,0 @@
1
- #!/usr/bin/env python3
2
- # pylint: disable=missing-class-docstring,no-self-use,line-too-long
3
- __package__ = __package__ or "tests.serialization" # pylint:disable=redefined-builtin
4
-
5
- import gc
6
- import os
7
- import pickle
8
- import shutil
9
- import tempfile
10
- import unittest
11
-
12
- import angr
13
-
14
- from ..common import bin_location
15
-
16
- test_location = os.path.join(bin_location, "tests")
17
-
18
- internaltest_files = [
19
- "argc_decide",
20
- "argc_symbol",
21
- "argv_test",
22
- "counter",
23
- "fauxware",
24
- "fauxware.idb",
25
- "manysum",
26
- "pw",
27
- "strlen",
28
- "test_arrays",
29
- "test_division",
30
- "test_loops",
31
- ]
32
- internaltest_arch = ["i386", "armel"]
33
-
34
-
35
- def internaltest_vfg(p, cfg):
36
- vfg = p.analyses.VFG(cfg=cfg)
37
- v = angr.vaults.VaultDict()
38
- state = v.dumps(vfg)
39
- vfg2 = v.loads(state)
40
- assert vfg.final_states == vfg2.final_states
41
- assert set(vfg.graph.nodes()) == set(vfg2.graph.nodes())
42
-
43
-
44
- def internaltest_cfg(p):
45
- state = tempfile.TemporaryFile()
46
-
47
- cfg = p.analyses.CFGEmulated()
48
- pickle.dump(cfg, state, -1)
49
-
50
- state.seek(0)
51
- cfg2 = pickle.load(state)
52
- assert set(cfg.model.nodes()) == set(cfg2.model.nodes())
53
- assert cfg.unresolvables == cfg2.unresolvables
54
- assert set(cfg.deadends) == set(cfg2.deadends)
55
-
56
- return cfg
57
-
58
-
59
- def internaltest_cfgfast(p):
60
- state = tempfile.TemporaryFile()
61
-
62
- cfg = p.analyses.CFGFast()
63
-
64
- # generate capstone blocks
65
- main_function = cfg.functions.function(name="main")
66
- for b in main_function.blocks:
67
- _ = b.capstone
68
-
69
- pickle.dump(cfg, state, -1)
70
-
71
- state.seek(0)
72
- cfg2 = pickle.load(state)
73
- assert set(cfg.model.nodes()) == set(cfg2.model.nodes())
74
-
75
-
76
- def internaltest_project(fpath):
77
- tpath = tempfile.mktemp()
78
- shutil.copy(fpath, tpath)
79
-
80
- p = angr.Project(tpath, auto_load_libs=False)
81
- state = pickle.dumps(p, -1)
82
- loaded_p = pickle.loads(state)
83
- assert p is not loaded_p
84
- assert p.arch == loaded_p.arch
85
- assert p.filename == loaded_p.filename
86
- assert p.entry == loaded_p.entry
87
-
88
- simgr = loaded_p.factory.simulation_manager()
89
- simgr.run(n=10)
90
- assert len(simgr.errored) == 0
91
-
92
-
93
- class TestSerialization(unittest.TestCase):
94
- def test_analyses(self):
95
- p = angr.Project(os.path.join(test_location, "i386", "fauxware"), load_options={"auto_load_libs": False})
96
- cfg = p.analyses.CFG()
97
- cfb = p.analyses.CFB(kb=cfg.kb)
98
- vrf = p.analyses.VariableRecoveryFast(p.kb.functions["main"])
99
-
100
- assert len(p.kb.functions) > 0
101
- assert len(pickle.loads(pickle.dumps(p.kb, -1)).functions) > 0
102
-
103
- state = pickle.dumps((p, cfg, cfb, vrf), -1)
104
- del p
105
- del cfg
106
- del cfb
107
- del vrf
108
-
109
- gc.collect()
110
-
111
- p, cfg, cfb, vrf = pickle.loads(state)
112
- assert p.kb is not None
113
- assert p.kb.functions is not None
114
- assert cfg.kb is not None
115
- assert len(p.kb.functions) > 0
116
-
117
- def test_serialization(self):
118
- for d in internaltest_arch:
119
- for f in internaltest_files:
120
- fpath = os.path.join(test_location, d, f)
121
- if os.path.isfile(fpath) and os.access(fpath, os.X_OK):
122
- internaltest_project(fpath)
123
-
124
- p = angr.Project(os.path.join(test_location, "i386", "fauxware"), load_options={"auto_load_libs": False})
125
- internaltest_cfgfast(p)
126
-
127
- cfg = internaltest_cfg(p)
128
- internaltest_vfg(p, cfg)
129
-
130
-
131
- if __name__ == "__main__":
132
- unittest.main()
@@ -1,169 +0,0 @@
1
- #!/usr/bin/env python3
2
- __package__ = __package__ or "tests.serialization" # pylint:disable=redefined-builtin
3
-
4
- import os
5
- import unittest
6
-
7
- import claripy
8
- import angr
9
-
10
- from ..common import bin_location
11
-
12
-
13
- class A:
14
- n = 0
15
-
16
-
17
- class TestVault(unittest.TestCase):
18
- def _do_vault_identity(self, v_factory):
19
- v = v_factory()
20
- v.uuid_dedup.add(A)
21
- assert len(v.keys()) == 0
22
-
23
- a = A()
24
- b = A()
25
- b.n = 1
26
- c = A()
27
- c.n = 2
28
-
29
- aid = v.store(a)
30
- assert len(v.keys()) == 1, "Current keys: %s" % v.keys()
31
- bid = v.store(b)
32
- assert len(v.keys()) == 2
33
- cid = v.store(c)
34
- assert len(v.keys()) == 3
35
-
36
- aa = v.load(aid)
37
- bb = v.load(bid)
38
- cc = v.load(cid)
39
-
40
- assert aa is a
41
- assert bb is b
42
- assert cc is c
43
-
44
- bb.n = 1337
45
- del bb
46
- del b
47
- import gc
48
-
49
- gc.collect()
50
- bbb = v.load(bid)
51
- assert bbb.n == 1
52
-
53
- def _do_vault_noidentity(self, v_factory):
54
- v = v_factory()
55
- assert len(v.keys()) == 0
56
-
57
- a = A()
58
- b = A()
59
- b.n = 1
60
- c = A()
61
- c.n = 2
62
-
63
- aid = v.store(a)
64
- assert len(v.keys()) == 1, "Current keys: %s" % v.keys()
65
- bid = v.store(b)
66
- assert len(v.keys()) == 2
67
- cid = v.store(c)
68
- assert len(v.keys()) == 3
69
-
70
- aa = v.load(aid)
71
- bb = v.load(bid)
72
- cc = v.load(cid)
73
-
74
- assert aa is not a
75
- assert bb is not b
76
- assert cc is not c
77
-
78
- v.store(aa)
79
- assert len(v.keys()) == 4
80
- v.store(bb)
81
- assert len(v.keys()) == 5
82
- v.store(cc)
83
- assert len(v.keys()) == 6
84
-
85
- def _do_ast_vault(self, v_factory):
86
- v = v_factory()
87
- x = claripy.BVS("x", 32)
88
- y = claripy.BVS("y", 32)
89
- z = x + y
90
-
91
- v.store(x)
92
- assert len(v.keys()) == 1
93
- zid = v.store(z)
94
- assert len(v.keys()) == 3
95
- zz = v.load(zid)
96
- assert z is zz
97
-
98
- zs = v.dumps(z)
99
- zzz = v.loads(zs)
100
- assert zzz is z
101
-
102
- def test_vault_noidentity_VaultDir(self):
103
- self._do_vault_noidentity(angr.vaults.VaultDir)
104
-
105
- def test_vault_noidentity_VaultShelf(self):
106
- self._do_vault_noidentity(angr.vaults.VaultShelf)
107
-
108
- def test_vault_noidentity_VaultDict(self):
109
- self._do_vault_noidentity(angr.vaults.VaultDict)
110
-
111
- def test_vault_noidentity_VaultDirShelf(self):
112
- self._do_vault_noidentity(angr.vaults.VaultDirShelf)
113
-
114
- def test_vault_identity_VaultDir(self):
115
- self._do_vault_identity(angr.vaults.VaultDir)
116
-
117
- def test_vault_identity_VaultShelf(self):
118
- self._do_vault_identity(angr.vaults.VaultShelf)
119
-
120
- def test_vault_identity_VaultDict(self):
121
- self._do_vault_identity(angr.vaults.VaultDict)
122
-
123
- @unittest.expectedFailure
124
- def test_vault_identity_VaultDirShelf(self):
125
- # VaultDirShelf does not guarantee identity equivalence due to the absence of caching
126
- self._do_vault_identity(angr.vaults.VaultDirShelf)
127
-
128
- def test_ast_vault_do_ast_vault_VaultDir(self):
129
- self._do_ast_vault(angr.vaults.VaultDir)
130
-
131
- def test_ast_vault_do_ast_vault_VaultShelf(self):
132
- self._do_ast_vault(angr.vaults.VaultShelf)
133
-
134
- def test_ast_vault_do_ast_vault_VaultDict(self):
135
- self._do_ast_vault(angr.vaults.VaultDict)
136
-
137
- @unittest.expectedFailure
138
- def test_ast_vault_VaultDirShelf(self):
139
- # VaultDirShelf does not guarantee identity equivalence due to the absence of caching
140
- self._do_ast_vault(angr.vaults.VaultDirShelf)
141
-
142
- def test_project(self):
143
- v = angr.vaults.VaultDir()
144
- p = angr.Project(os.path.join(bin_location, "tests", "x86_64", "fauxware"), auto_load_libs=False)
145
- ps = v.store(p)
146
- pp = v.load(ps)
147
- assert p is pp
148
- assert sum(1 for k in v.keys() if k.startswith("Project")) == 1
149
-
150
- pstring = v.dumps(p)
151
- assert sum(1 for k in v.keys() if k.startswith("Project")) == 1
152
- pp2 = v.loads(pstring)
153
- assert sum(1 for k in v.keys() if k.startswith("Project")) == 1
154
- assert p is pp
155
-
156
- p._asdf = "fdsa"
157
- del pp2
158
- del pp
159
- del p
160
- import gc
161
-
162
- gc.collect()
163
-
164
- v.load(ps)
165
- assert sum(1 for k in v.keys() if k.startswith("Project")) == 1
166
-
167
-
168
- if __name__ == "__main__":
169
- unittest.main()
tests/sim/__init__.py DELETED
@@ -1,3 +0,0 @@
1
- """
2
- Tests related to execution.
3
- """
File without changes