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.knowledge_plugins.functions" # pylint:disable=redefined-builtin
4
-
5
- import os
6
- import unittest
7
-
8
- import angr
9
- import angr.calling_conventions
10
- from angr.sim_type import SimTypePointer
11
-
12
- from ...common import bin_location
13
-
14
-
15
- test_location = os.path.join(bin_location, "tests")
16
-
17
-
18
- class TestPrototypes(unittest.TestCase):
19
- def test_function_prototype(self):
20
- proj = angr.Project(os.path.join(test_location, "x86_64", "all"), auto_load_libs=False)
21
-
22
- func = angr.knowledge_plugins.Function(proj.kb.functions, 0x100000, name="strcmp")
23
- func.prototype = angr.SIM_LIBRARIES["libc.so.6"].prototypes[func.name]
24
- func.calling_convention = angr.calling_conventions.default_cc(proj.arch.name, platform="Linux")(proj.arch)
25
-
26
- def test_find_prototype(self):
27
- proj = angr.Project(os.path.join(test_location, "x86_64", "all"), auto_load_libs=False)
28
-
29
- cfg = proj.analyses.CFG()
30
-
31
- func = cfg.kb.functions.function(name="strcmp", plt=False)
32
- func.calling_convention = angr.calling_conventions.default_cc(proj.arch.name, platform="Linux")(proj.arch)
33
-
34
- func.find_declaration()
35
-
36
- arg_locs = func.calling_convention.arg_locs(func.prototype)
37
-
38
- assert len(arg_locs) == 2
39
- assert arg_locs[0].reg_name == "rdi"
40
- assert arg_locs[1].reg_name == "rsi"
41
-
42
- def test_cpp_void_pointer(self):
43
- proj = angr.Project(os.path.join(test_location, "x86_64", "void_pointer"), auto_load_libs=False)
44
-
45
- cfg = proj.analyses.CFG()
46
- proj.analyses.CompleteCallingConventions(recover_variables=True, analyze_callsites=True)
47
-
48
- func = cfg.kb.functions.function(name="_ZdlPvm", plt=True)
49
- assert isinstance(func.prototype.args[0], SimTypePointer)
50
-
51
-
52
- if __name__ == "__main__":
53
- unittest.main()
File without changes
@@ -1,24 +0,0 @@
1
- #!/usr/bin/env python3
2
- # pylint: disable=missing-class-docstring
3
- from unittest import main, TestCase
4
-
5
- from archinfo import ArchMIPS32
6
-
7
- from angr.calling_conventions import SimRegArg
8
- from angr.knowledge_plugins.key_definitions.atoms import Atom, Register
9
-
10
-
11
- class TestAtoms(TestCase):
12
- def test_from_argument_instanciate_a_Register_when_given_a_SimRegArg(self):
13
- argument = SimRegArg("r0", 4)
14
- arch = ArchMIPS32()
15
-
16
- result = Atom.from_argument(argument, arch)
17
-
18
- self.assertTrue(isinstance(result, Register))
19
- self.assertEqual(result.reg_offset, arch.registers["r0"][0])
20
- self.assertEqual(result.size, 4)
21
-
22
-
23
- if __name__ == "__main__":
24
- main()
@@ -1,126 +0,0 @@
1
- #!/usr/bin/env python3
2
- from unittest import main, TestCase
3
-
4
- import claripy
5
-
6
- from angr.knowledge_plugins.key_definitions.environment import Environment
7
- from angr.knowledge_plugins.key_definitions.undefined import UNDEFINED
8
-
9
-
10
- class TestEnvironment(TestCase):
11
- def setUp(self):
12
- self.pointer_length = 8
13
- self.pointer = 0x7FFFFFFFF00 - 0xFF
14
-
15
- def test_get_returns_the_pointer_associated_with_an_existing_environment_variable(self):
16
- name = "variable_name"
17
- data = {claripy.BVV(self.pointer, self.pointer_length)}
18
- environment = Environment(environment={name: data})
19
-
20
- variable_names = {name}
21
-
22
- result_values, _ = environment.get(variable_names)
23
- self.assertEqual(result_values, data)
24
-
25
- def test_get_returns_a_dataset_with_UNDEFINED_when_the_environment_variable_is_not_set(self):
26
- environment = Environment(environment={})
27
-
28
- name = "variable_name"
29
- variable_names = {name}
30
-
31
- result_values, _ = environment.get(variable_names)
32
- self.assertEqual(result_values, {UNDEFINED})
33
-
34
- def test_get_returns_values_associated_with_all_possible_given_names(self):
35
- environment_data = {
36
- "variable_name": {claripy.BVV(self.pointer, self.pointer_length)},
37
- UNDEFINED: {UNDEFINED},
38
- }
39
- environment = Environment(environment=environment_data)
40
-
41
- variable_names = {"variable_name", UNDEFINED}
42
- expected_result = {claripy.BVV(self.pointer, self.pointer_length), UNDEFINED}
43
-
44
- result_values, _ = environment.get(variable_names)
45
- self.assertEqual(result_values, expected_result)
46
-
47
- def test_get_fails_when_called_with_wrong_type_of_name(self):
48
- environment = Environment(environment={})
49
- variable_names = {claripy.BVV(0x42, 8 * 8)}
50
-
51
- self.assertRaises(TypeError, environment.get, variable_names)
52
-
53
- def test_get_result_tells_if_environment_knows_about_all_the_variables(self):
54
- name = "variable_name"
55
- data = {claripy.BVV(self.pointer, self.pointer_length)}
56
- environment = Environment(environment={name: data})
57
-
58
- name = "variable_name"
59
- variable_names = {name}
60
-
61
- _, has_unknown = environment.get(variable_names)
62
- self.assertFalse(has_unknown)
63
-
64
- def test_get_result_tells_if_environment_does_not_know_about_one_of_the_variable(self):
65
- name = "variable_name"
66
- data = {claripy.BVV(b"value\x00", 6 * 8)}
67
- environment = Environment(environment={name: data})
68
-
69
- name = "variable_name"
70
- variable_names = {name, "unknown_name"}
71
-
72
- _, has_unknown = environment.get(variable_names)
73
- self.assertTrue(has_unknown)
74
-
75
- def test_set_sets_associates_data_to_a_given_variable_name(self):
76
- environment = Environment(environment={})
77
-
78
- data = {claripy.BVV(b"value\x00", 6 * 8)}
79
- environment.set("variable_name", data)
80
-
81
- # Testing internal attribute which is not ideal, but I'am trying to not rely on any other behavior
82
- # (e.g. without using `get`).
83
- self.assertDictEqual(environment._environment, {"variable_name": data})
84
-
85
- def test_set_sets_can_associate_data_to_UNDEFINED(self):
86
- environment = Environment(environment={})
87
-
88
- data = {claripy.BVV(b"value\x00", 6 * 8)}
89
- environment.set(UNDEFINED, data)
90
-
91
- # Testing internal attribute which is not ideal, but I'am trying to not rely on any other behavior
92
- # (e.g. without using `get`).
93
- self.assertDictEqual(environment._environment, {UNDEFINED: data})
94
-
95
- def test_set_fails_when_wvariable_name_is_of_wrong_type(self):
96
- environment = Environment(environment={})
97
-
98
- data = {claripy.BVV(b"value\x00", 6 * 8)}
99
-
100
- self.assertRaises(TypeError, environment.set, 0x42, data)
101
-
102
- def test_merge_fails_when_merging_with_a_non_Environment_instance(self):
103
- environment = Environment(environment={"variable_name": {claripy.BVV(b"value1\x00", 7 * 8)}})
104
- other_environment = 0x42
105
-
106
- self.assertRaises(TypeError, environment.merge, other_environment)
107
-
108
- def test_merge_two_environments_merge_data_associated_with_each_variable(self):
109
- first = "variable_name"
110
- second = "other_variable_name"
111
- environment = Environment(environment={first: {claripy.BVV(b"value1\x00", 7 * 8)}})
112
- other_environment = Environment(environment={first: {claripy.BVV(b"value2\x00", 7 * 8)}, second: {UNDEFINED}})
113
-
114
- expected_environment = Environment(
115
- environment={
116
- first: {claripy.BVV(b"value1\x00", 7 * 8), claripy.BVV(b"value2\x00", 7 * 8)},
117
- second: {UNDEFINED},
118
- }
119
- )
120
-
121
- env, _ = environment.merge(other_environment)
122
- self.assertEqual(env, expected_environment)
123
-
124
-
125
- if __name__ == "__main__":
126
- main()
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env python3
2
- from unittest import main, TestCase
3
-
4
- from angr.knowledge_plugins.key_definitions.heap_address import HeapAddress
5
-
6
-
7
- class TestHeapAddress(TestCase):
8
- def test_expose_its_value_as_a_property(self):
9
- address = HeapAddress(0x42)
10
- self.assertEqual(address.value, 0x42)
11
-
12
- def test_add_fails_if_value_added_is_not_int(self):
13
- address = HeapAddress(0x0)
14
- self.assertRaises(TypeError, address + 0x8)
15
-
16
- def test_add_increase_the_heap_address_value_by_the_right_amount(self):
17
- address = HeapAddress(0x0)
18
- new_address = address + 0x8
19
- self.assertEqual(new_address.value, 0x8)
20
-
21
- def test_add_is_commutative(self):
22
- address = HeapAddress(0x0)
23
- self.assertEqual(address + 0x8, 0x8 + address)
24
-
25
-
26
- if __name__ == "__main__":
27
- main()
@@ -1,72 +0,0 @@
1
- #!/usr/bin/env python3
2
- from unittest import main, TestCase
3
-
4
- import archinfo
5
-
6
- from angr.storage.memory_mixins.paged_memory.pages.multi_values import MultiValues
7
- from angr.knowledge_plugins.key_definitions.atoms import Register, SpOffset
8
- from angr.knowledge_plugins.key_definitions.live_definitions import LiveDefinitions
9
-
10
-
11
- class TestLiveDefinitions(TestCase):
12
- def setUp(self):
13
- self.arch = archinfo.arch_arm.ArchARM()
14
-
15
- sp_offset = self.arch.registers["sp"][0]
16
- self.sp_register = Register(sp_offset, self.arch.bytes)
17
-
18
- def test_get_sp_retrieves_the_value_of_sp_register(self):
19
- live_definitions = LiveDefinitions(self.arch)
20
-
21
- offset = SpOffset(self.arch.bits, 0)
22
- address = live_definitions.stack_address(offset.offset)
23
- sp_value = MultiValues(offset_to_values={0: {address}})
24
-
25
- live_definitions.kill_and_add_definition(self.sp_register, None, sp_value)
26
-
27
- retrieved_sp_value = live_definitions.get_sp()
28
-
29
- self.assertEqual(retrieved_sp_value, live_definitions.stack_offset_to_stack_addr(offset.offset))
30
-
31
- def test_get_sp_fails_if_there_are_different_definitions_for_sp_with_different_values(self):
32
- # To get multiple definitions of SP cohabiting, we need to create a `LiveDefinitions` via `.merge`:
33
- # Let's create the "base" `LiveDefinitions`, holding *DIFFERENT* values.
34
- live_definitions = LiveDefinitions(self.arch)
35
-
36
- offset = SpOffset(self.arch.bits, 0)
37
- address = live_definitions.stack_address(offset.offset)
38
- sp_value = MultiValues(offset_to_values={0: {address}})
39
- other_offset = SpOffset(self.arch.bits, 20)
40
- other_address = live_definitions.stack_address(other_offset.offset)
41
- other_sp_value = MultiValues(offset_to_values={0: {other_address}})
42
-
43
- live_definitions.kill_and_add_definition(self.sp_register, 0x0, sp_value)
44
- other_live_definitions = LiveDefinitions(self.arch)
45
- other_live_definitions.kill_and_add_definition(self.sp_register, 0x1, other_sp_value)
46
- # Then merge them.
47
- live_definitions_with_multiple_sps, _ = live_definitions.merge(other_live_definitions)
48
-
49
- self.assertRaises(AssertionError, live_definitions_with_multiple_sps.get_sp)
50
-
51
- def test_get_sp_retrieves_the_value_of_sp_register_even_if_it_has_several_definitions(self):
52
- # To get multiple definitions of SP cohabiting, we need to create a `LiveDefinitions` via `.merge`:
53
- # Let's create the "base" `LiveDefinitions`, holding *THE SAME* values.
54
- live_definitions = LiveDefinitions(self.arch)
55
-
56
- offset = SpOffset(self.arch.bits, 0)
57
- address = live_definitions.stack_address(offset.offset)
58
- sp_value = MultiValues(offset_to_values={0: {address}})
59
-
60
- live_definitions.kill_and_add_definition(self.sp_register, 0x1, sp_value)
61
- other_live_definitions = LiveDefinitions(self.arch)
62
- other_live_definitions.kill_and_add_definition(self.sp_register, 0x2, sp_value)
63
- # Then merge them.
64
- live_definitions_with_multiple_sps, _ = live_definitions.merge(other_live_definitions)
65
-
66
- retrieved_sp_value = live_definitions_with_multiple_sps.get_sp()
67
-
68
- self.assertEqual(retrieved_sp_value, live_definitions.stack_offset_to_stack_addr(offset.offset))
69
-
70
-
71
- if __name__ == "__main__":
72
- main()
@@ -1,240 +0,0 @@
1
- #!/usr/bin/env python3
2
- __package__ = __package__ or "tests.knowledge_plugins" # pylint:disable=redefined-builtin
3
-
4
- import math
5
- import os
6
- from unittest import TestCase, main
7
-
8
- import angr
9
-
10
- from ..common import bin_location
11
-
12
-
13
- test_location = os.path.join(bin_location, "tests")
14
-
15
-
16
- class TestDwarfVariables(TestCase):
17
- """
18
- Test dwarf variables import and resolution of these variables
19
- """
20
-
21
- def setUp(self):
22
- self.p = angr.Project(os.path.join(test_location, "x86_64", "various_variables"), load_debug_info=True)
23
- self.p.kb.dvars.load_from_dwarf()
24
- simgr = self.p.factory.simgr()
25
- main_addr = self.p.loader.find_symbol("main").rebased_addr
26
- simgr.explore(find=main_addr)
27
- self.s = simgr.found[0]
28
- self.addr2line = self.p.loader.main_object.addr_to_line
29
-
30
- # tests for global variables
31
-
32
- def test_resolve_a(self):
33
- a = self.s.dvars["a"]
34
- computed_result = []
35
- for i in range(9):
36
- computed_result.append(a.array(i).mem.concrete)
37
- expected_result = [1, 2, 3, 4, 5, 6, 7, 8, 9]
38
- self.assertEqual(computed_result, expected_result, 'global variable "a" array values is computed wrong')
39
-
40
- def test_resolve_pointer(self):
41
- pointer = self.s.dvars["pointer"]
42
- computed_result = pointer.deref.mem.concrete
43
- expected_result = 0
44
- self.assertEqual(
45
- computed_result, expected_result, 'global variable "pointer" dereferences value is computed wrong'
46
- )
47
-
48
- def test_resolve_pointer2(self):
49
- pointer2 = self.s.dvars["pointer2"]
50
- computed_result = pointer2.deref.mem.concrete
51
- expected_result = 1
52
- self.assertEqual(
53
- computed_result, expected_result, 'global variable "pointer2" dereferences value is computed wrong'
54
- )
55
-
56
- def test_resolve_global_var(self):
57
- global_var = self.s.dvars["global_var"]
58
- computed_result = global_var.mem.concrete
59
- expected_result = 7
60
- self.assertEqual(computed_result, expected_result, 'global variable "global_var" value is computed wrong')
61
-
62
- def test_resolve_extern_var(self):
63
- extern_var = self.s.dvars["extern_var"]
64
- computed_result = extern_var.mem.concrete
65
- expected_result = 42
66
- self.assertEqual(computed_result, expected_result, 'global variable "extern_var" value is computed wrong')
67
-
68
- def test_resolve_global_struct(self):
69
- global_struct = self.s.dvars["global_struct"]
70
-
71
- computed_struct_array = []
72
- a = global_struct.member("struct_array")
73
- for i in range(3):
74
- computed_struct_array.append(a.array(i).mem.concrete)
75
-
76
- computed_result = [
77
- global_struct.member("struct_fun").mem.concrete,
78
- global_struct.member("struct_int").mem.concrete,
79
- global_struct.member("struct_ll").mem.concrete,
80
- global_struct.member("struct_char").mem.concrete,
81
- global_struct.member("struct_strref").string.concrete,
82
- global_struct.member("struct_pointer").mem.concrete,
83
- computed_struct_array,
84
- # struct_float is tested below,
85
- # struct_double is tested below,
86
- global_struct.member("struct_my_type").mem.concrete,
87
- ]
88
-
89
- expected_result = [
90
- self.p.loader.find_symbol("variable_scopes").rebased_addr,
91
- 42,
92
- 256,
93
- b"a",
94
- b"hello",
95
- self.s.dvars["dummy"].addr,
96
- [9, 8, 7],
97
- # 1.141,
98
- # 1.141,
99
- 16,
100
- ]
101
-
102
- self.assertEqual(
103
- computed_result, expected_result, 'global variable "global_struct" members value is computed wrong'
104
- )
105
-
106
- struct_float = global_struct.member("struct_float").mem.concrete
107
- struct_double = global_struct.member("struct_double").mem.concrete
108
- self.assertTrue(
109
- math.isclose(struct_float, 1.141, rel_tol=1e-7) and math.isclose(struct_double, 1.141, rel_tol=1e-7)
110
- )
111
-
112
- # tests for local variables
113
-
114
- def test_sum_in_global(self):
115
- simgr = self.p.factory.simgr()
116
- addr = self.p.loader.find_symbol("sum_in_global").rebased_addr
117
- simgr.explore(find=addr)
118
- simgr.move(from_stash="found", to_stash="active")
119
- simgr.step()
120
- simgr.step()
121
- s = simgr.active[0]
122
- result = []
123
- for _ in range(9):
124
- result.append(s.dvars["global_var"].mem.concrete)
125
- simgr.step()
126
- s = simgr.active[0]
127
- ref = [7, 8, 10, 13, 17, 22, 28, 35, 43]
128
- self.assertEqual(result, ref)
129
-
130
- def test_sum_in_local(self):
131
- simgr = self.p.factory.simgr()
132
- addr = self.p.loader.find_symbol("sum_in_local").rebased_addr
133
- simgr.explore(find=addr)
134
- simgr.move(from_stash="found", to_stash="active")
135
- simgr.step()
136
- s = simgr.active[0]
137
- local_var = s.dvars["local_var"].mem.concrete
138
- ref = 0
139
- self.assertEqual(local_var, ref)
140
-
141
- def test_variable_scopes(self):
142
- simgr = self.p.factory.simgr()
143
- filename = "/home/lukas/Software/angr-dev/binaries/tests_src/various_variables.c"
144
- lines_strings = [
145
- (78, b"He"),
146
- (80, b"llo "),
147
- # (84, b"Wor"), # FIXME fails
148
- (88, b"ld!\n"),
149
- ]
150
- for line, expected_string in lines_strings:
151
- addr = {addr for addr in self.addr2line if (filename, line) in self.addr2line[addr]}.pop()
152
- simgr.explore(find=addr)
153
- s = simgr.found[0]
154
- computed_string = s.dvars["string"].string.concrete
155
- self.assertEqual(expected_string, computed_string)
156
- simgr.move(from_stash="found", to_stash="active")
157
-
158
- def test_sum_in_static(self):
159
- simgr = self.p.factory.simgr()
160
- filename = "/home/lukas/Software/angr-dev/binaries/tests_src/various_variables.c"
161
- line = 47
162
- addr = {addr for addr in self.addr2line if (filename, line) in self.addr2line[addr]}.pop()
163
- simgr.explore(find=addr)
164
- s = simgr.found[0]
165
- computed_value = s.dvars["static_var"].mem.concrete
166
- self.assertEqual(computed_value, 0)
167
-
168
- def test_local_in_loop(self):
169
- simgr = self.p.factory.simgr()
170
- filename = "/home/lukas/Software/angr-dev/binaries/tests_src/various_variables.c"
171
- line = 55
172
- addr = {addr for addr in self.addr2line if (filename, line) in self.addr2line[addr]}.pop()
173
- simgr.explore(find=addr)
174
- s = simgr.found[0]
175
- computed_value = s.dvars["local_in_loop"].mem.concrete
176
- self.assertEqual(computed_value, 9)
177
-
178
- def test_local_in_if(self):
179
- simgr = self.p.factory.simgr()
180
- filename = "/home/lukas/Software/angr-dev/binaries/tests_src/various_variables.c"
181
- line = 68
182
- addr = {addr for addr in self.addr2line if (filename, line) in self.addr2line[addr]}.pop()
183
- simgr.explore(find=addr)
184
- s = simgr.found[0]
185
- computed_value = s.dvars["local_in_if"].mem.concrete
186
- self.assertEqual(computed_value, 52)
187
-
188
- def test_resolve_local_struct(self):
189
- simgr = self.p.factory.simgr()
190
- filename = "/home/lukas/Software/angr-dev/binaries/tests_src/various_variables.c"
191
- line = 144
192
- addr = {addr for addr in self.addr2line if (filename, line) in self.addr2line[addr]}.pop()
193
- simgr.explore(find=addr)
194
- s = simgr.found[0]
195
- local_struct = s.dvars["local_struct"]
196
-
197
- computed_struct_array = []
198
- a = local_struct.member("struct_array")
199
- for i in range(3):
200
- computed_struct_array.append(a.array(i).mem.concrete)
201
-
202
- computed_result = [
203
- local_struct.member("struct_fun").mem.concrete,
204
- local_struct.member("struct_int").mem.concrete,
205
- local_struct.member("struct_ll").mem.concrete,
206
- local_struct.member("struct_char").mem.concrete,
207
- local_struct.member("struct_strref").string.concrete,
208
- local_struct.member("struct_pointer").mem.concrete,
209
- computed_struct_array,
210
- # struct_float is tested below,
211
- # struct_double is tested below,
212
- local_struct.member("struct_my_type").mem.concrete,
213
- ]
214
-
215
- expected_result = [
216
- self.p.loader.find_symbol("variable_scopes").rebased_addr,
217
- 42,
218
- 256,
219
- b"a",
220
- b"hello",
221
- s.dvars["local_pointer"].mem.concrete,
222
- [9, 8, 7],
223
- # 1.141,
224
- # 1.141,
225
- 16,
226
- ]
227
-
228
- self.assertEqual(
229
- computed_result, expected_result, 'local variable "local_struct" members value is computed wrong'
230
- )
231
-
232
- struct_float = local_struct.member("struct_float").mem.concrete
233
- struct_double = local_struct.member("struct_double").mem.concrete
234
- self.assertTrue(
235
- math.isclose(struct_float, 1.141, rel_tol=1e-7) and math.isclose(struct_double, 1.141, rel_tol=1e-7)
236
- )
237
-
238
-
239
- if __name__ == "__main__":
240
- main()
@@ -1,91 +0,0 @@
1
- #!/usr/bin/env python3
2
- # pylint: disable=missing-class-docstring,no-self-use,line-too-long
3
- __package__ = __package__ or "tests.knowledge_plugins" # pylint:disable=redefined-builtin
4
-
5
- import os
6
- import unittest
7
-
8
- import networkx
9
-
10
- import angr
11
-
12
- from ..common import bin_location
13
-
14
-
15
- test_location = os.path.join(bin_location, "tests")
16
-
17
-
18
- class TestKbPlugins(unittest.TestCase):
19
- def test_kb_plugins(self):
20
- p = angr.Project(os.path.join(test_location, "x86_64", "fauxware"), auto_load_libs=False)
21
-
22
- assert isinstance(p.kb.data, angr.knowledge_plugins.Data)
23
- assert isinstance(p.kb.functions, angr.knowledge_plugins.FunctionManager)
24
- assert isinstance(p.kb.variables, angr.knowledge_plugins.VariableManager)
25
- assert isinstance(p.kb.labels, angr.knowledge_plugins.Labels)
26
- assert isinstance(p.kb.comments, angr.knowledge_plugins.Comments)
27
-
28
- assert isinstance(p.kb.callgraph, networkx.Graph)
29
- assert isinstance(p.kb.resolved_indirect_jumps, dict)
30
- assert isinstance(p.kb.unresolved_indirect_jumps, set)
31
-
32
- assert dir(p.kb) is not None
33
- for plugin in [
34
- "data",
35
- "functions",
36
- "variables",
37
- "labels",
38
- "comments",
39
- "callgraph",
40
- "resolved_indirect_jumps",
41
- "unresolved_indirect_jumps",
42
- ]:
43
- assert plugin in dir(p.kb)
44
-
45
- def test_kb_plugins_typed(self):
46
- p = angr.Project(os.path.join(test_location, "x86_64", "fauxware"), auto_load_libs=False)
47
-
48
- for plugin in [
49
- angr.knowledge_plugins.Data,
50
- angr.knowledge_plugins.FunctionManager,
51
- angr.knowledge_plugins.VariableManager,
52
- angr.knowledge_plugins.Labels,
53
- angr.knowledge_plugins.Comments,
54
- ]:
55
- assert p.kb.get_knowledge(plugin) is None
56
-
57
- for plugin in [
58
- angr.knowledge_plugins.Data,
59
- angr.knowledge_plugins.FunctionManager,
60
- angr.knowledge_plugins.VariableManager,
61
- angr.knowledge_plugins.Labels,
62
- angr.knowledge_plugins.Comments,
63
- ]:
64
- assert isinstance(p.kb.request_knowledge(plugin), plugin)
65
-
66
- # The default plugins should have been instantiated by `request_knowledge`, and should now be available
67
- for plugin in [
68
- angr.knowledge_plugins.Data,
69
- angr.knowledge_plugins.FunctionManager,
70
- angr.knowledge_plugins.VariableManager,
71
- angr.knowledge_plugins.Labels,
72
- angr.knowledge_plugins.Comments,
73
- ]:
74
- assert isinstance(p.kb.request_knowledge(plugin), plugin)
75
-
76
- # Check that explicitly creating and registering new kind of plugin also works
77
- class TestPlugin(angr.knowledge_plugins.KnowledgeBasePlugin):
78
- def __init__(self, kb=None):
79
- self._kb = kb
80
-
81
- # Assert that unknown plugins return None when using "get_knowledge"
82
- assert p.kb.get_knowledge(TestPlugin) is None
83
-
84
- t = TestPlugin(p.kb)
85
- p.kb.register_plugin("test_plugin", t)
86
-
87
- assert p.kb.get_knowledge(TestPlugin) == t
88
-
89
-
90
- if __name__ == "__main__":
91
- unittest.main()
@@ -1,36 +0,0 @@
1
- #!/usr/bin/env python3
2
- # pylint: disable=missing-class-docstring,no-self-use,line-too-long
3
- __package__ = __package__ or "tests.knowledge_plugins" # pylint:disable=redefined-builtin
4
-
5
- import os
6
- import unittest
7
-
8
- import angr
9
-
10
- from ..common import bin_location
11
-
12
-
13
- test_location = os.path.join(bin_location, "tests")
14
-
15
-
16
- class TestKbPluginsDwarf(unittest.TestCase):
17
- def test_kb_plugins_dwarf(self):
18
- p = angr.Project(
19
- os.path.join(test_location, "x86_64", "state_merge_0"),
20
- load_options={
21
- "load_debug_info": True,
22
- "auto_load_libs": False,
23
- },
24
- )
25
- assert isinstance(p.kb.variables, angr.knowledge_plugins.VariableManager)
26
- p.kb.variables.load_from_dwarf()
27
-
28
- ret = p.kb.variables.global_manager.get_global_variables(6295620)
29
- assert len(ret) == 1
30
-
31
- v = ret.pop()
32
- assert v.name == "buf"
33
-
34
-
35
- if __name__ == "__main__":
36
- unittest.main()