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
tests/test_types.py DELETED
@@ -1,329 +0,0 @@
1
- #!/usr/bin/env python3
2
- # pylint: disable=missing-class-docstring,no-self-use,line-too-long
3
-
4
- import unittest
5
- from typing import Dict
6
-
7
- import archinfo
8
-
9
- import angr
10
- from angr.sim_type import (
11
- SimTypeFunction,
12
- SimTypeInt,
13
- SimTypePointer,
14
- SimTypeChar,
15
- SimStruct,
16
- SimTypeFloat,
17
- SimUnion,
18
- SimTypeDouble,
19
- SimTypeLongLong,
20
- SimTypeLong,
21
- SimTypeNum,
22
- SimTypeReference,
23
- SimTypeBottom,
24
- SimTypeString,
25
- )
26
- from angr.utils.library import convert_cproto_to_py, convert_cppproto_to_py
27
-
28
-
29
- class TestTypes(unittest.TestCase):
30
- def test_cproto_conversion(self):
31
- # A normal function declaration
32
- cproto_0 = "int main(int argc, char** argv);"
33
- pyproto_name, pyproto, the_str = convert_cproto_to_py(cproto_0)
34
-
35
- assert pyproto_name == "main"
36
- assert isinstance(pyproto, SimTypeFunction)
37
- assert isinstance(pyproto.args[0], SimTypeInt)
38
- assert isinstance(pyproto.args[1], SimTypePointer)
39
- assert isinstance(pyproto.args[1].pts_to.pts_to, SimTypeChar)
40
- assert isinstance(pyproto.returnty, SimTypeInt)
41
-
42
- # Directly comparing the strings... how bad can I be?
43
- assert the_str == (
44
- '# int main(int argc, char** argv);\n"main": SimTypeFunction([SimTypeInt(signed=True), SimTypePointer('
45
- 'SimTypePointer(SimTypeChar(), offset=0), offset=0)], SimTypeInt(signed=True), arg_names=["argc", "argv"]),'
46
- )
47
-
48
- # A bad function declaration
49
- cproto_1 = "int bad(xxxxxxx);"
50
- pyproto_name, pyproto, the_str = convert_cproto_to_py(cproto_1) # pylint:disable=unused-variable
51
-
52
- assert pyproto_name == "bad"
53
- assert pyproto is not None
54
-
55
- # A even worse function declaration
56
- # Special thanks to @schieb, see GitHub PR #958
57
- cproto_2 = "__attribute__ ((something)) void foo(void);"
58
- pyproto_name, pyproto, the_str = convert_cproto_to_py(cproto_2) # pylint:disable=unused-variable
59
-
60
- assert pyproto_name == "foo"
61
-
62
- def test_cppproto_conversion(self):
63
- # a demangled class constructor prototype, without parameter names
64
- proto_0 = (
65
- "std::basic_ifstream<char, std::char_traits<char>>::{ctor}(std::__cxx11::basic_string<char, "
66
- "std::char_traits<char>, std::allocator<char>> const&, std::_Ios_Openmode)"
67
- )
68
- name, proto, _ = convert_cppproto_to_py(proto_0, with_param_names=False)
69
- assert proto.ctor is True
70
- assert name == "std::basic_ifstream::__ctor__"
71
- assert len(proto.args) == 3
72
- assert isinstance(proto.args[0], SimTypePointer) # this
73
- assert isinstance(proto.args[1], SimTypeReference)
74
- assert isinstance(proto.args[1].refs, SimTypeString)
75
- assert proto.args[1].refs.name == "std::__cxx11::basic_string"
76
- assert proto.args[1].refs.unqualified_name(lang="c++") == "basic_string"
77
-
78
- proto_1 = "void std::basic_string<CharT,Traits,Allocator>::push_back(CharT ch)"
79
- name, proto, _ = convert_cppproto_to_py(proto_1, with_param_names=True)
80
- assert name == "std::basic_string::push_back"
81
- assert isinstance(proto.returnty, SimTypeBottom)
82
- assert isinstance(proto.args[0], SimTypePointer) # this
83
- assert isinstance(proto.args[1], SimTypeChar)
84
-
85
- proto_2 = "void std::basic_string<CharT,Traits,Allocator>::swap(basic_string& other)"
86
- name, proto, _ = convert_cppproto_to_py(proto_2, with_param_names=True)
87
- assert name == "std::basic_string::swap"
88
- assert isinstance(proto.returnty, SimTypeBottom)
89
- assert isinstance(proto.args[0], SimTypePointer) # this
90
- assert isinstance(proto.args[1], SimTypeReference)
91
- assert isinstance(proto.args[1].refs, SimTypeString)
92
-
93
- proto_3 = "std::ios_base::{base dtor}()"
94
- name, proto, _ = convert_cppproto_to_py(proto_3, with_param_names=True)
95
- assert name == "std::ios_base::__base_dtor__"
96
- assert proto.dtor is True
97
- assert isinstance(proto.returnty, SimTypeBottom)
98
-
99
- proto_4 = "std::ios_base::{base dtor}()"
100
- name, proto, _ = convert_cppproto_to_py(proto_4, with_param_names=True)
101
- assert name == "std::ios_base::__base_dtor__"
102
-
103
- proto_5 = "void foo(int & bar);"
104
- name, proto, _ = convert_cppproto_to_py(proto_5, with_param_names=True)
105
- assert name == "foo"
106
- # note that there is no "this" pointer
107
- assert isinstance(proto.args[0], SimTypeReference)
108
- assert isinstance(proto.args[0].refs, SimTypeInt)
109
- assert isinstance(proto.returnty, SimTypeBottom)
110
-
111
- def test_struct_deduplication(self):
112
- angr.types.register_types(angr.types.parse_type("struct ahdr { int a ;}"))
113
- angr.types.register_types(angr.types.parse_type("struct bhdr { int b ;}"))
114
- angr.types.register_types(angr.types.parse_type("struct chdr { int c ;}"))
115
- dhdr = angr.types.parse_type("struct dhdr { struct ahdr a; struct bhdr b; struct chdr c;}")
116
- assert dhdr.fields["a"].fields
117
-
118
- def test_parse_type(self):
119
- int_ptr = angr.types.parse_type("int *")
120
- assert isinstance(int_ptr, SimTypePointer)
121
- assert isinstance(int_ptr.pts_to, SimTypeInt)
122
-
123
- char_ptr = angr.types.parse_type("char *c")
124
- assert isinstance(char_ptr, SimTypePointer)
125
- assert isinstance(char_ptr.pts_to, SimTypeChar)
126
-
127
- struct_parse_type = angr.types.parse_type("struct parse_type { char c; float f; }")
128
- assert isinstance(struct_parse_type, SimStruct)
129
- assert struct_parse_type.name == "parse_type"
130
- assert len(struct_parse_type.fields) == 2
131
- assert isinstance(struct_parse_type.fields["c"], SimTypeChar)
132
- assert isinstance(struct_parse_type.fields["f"], SimTypeFloat)
133
-
134
- union_dcba = angr.types.parse_type("union dcba { double d; long long int lli; }")
135
- assert isinstance(union_dcba, SimUnion)
136
- assert union_dcba.name == "dcba"
137
- assert len(union_dcba.members) == 2
138
- assert isinstance(union_dcba.members["d"], SimTypeDouble)
139
- assert isinstance(union_dcba.members["lli"], SimTypeLongLong)
140
-
141
- struct_llist = angr.types.parse_type("struct llist { int data; struct llist * next; }")
142
- assert isinstance(struct_llist, SimStruct)
143
- assert struct_llist.name == "llist"
144
- assert len(struct_llist.fields) == 2
145
- assert isinstance(struct_llist.fields["data"], SimTypeInt)
146
- assert isinstance(struct_llist.fields["next"], SimTypePointer)
147
- assert isinstance(struct_llist.fields["next"].pts_to, SimStruct)
148
- assert struct_llist.fields["next"].pts_to.name == "llist"
149
-
150
- func_ptr = angr.types.parse_type("double (*) (int, float)")
151
- assert isinstance(func_ptr, SimTypePointer)
152
- assert isinstance(func_ptr.pts_to, SimTypeFunction)
153
- assert isinstance(func_ptr.pts_to.returnty, SimTypeDouble)
154
- assert len(func_ptr.pts_to.args) == 2
155
- assert isinstance(func_ptr.pts_to.args[0], SimTypeInt)
156
- assert isinstance(func_ptr.pts_to.args[1], SimTypeFloat)
157
-
158
- def test_parse_type_no_basic_types(self):
159
- time_t = angr.types.parse_type("time_t")
160
- assert isinstance(time_t, SimTypeLong)
161
-
162
- byte = angr.types.parse_type("byte")
163
- assert isinstance(byte, SimTypeNum)
164
- assert byte.size == 8
165
- assert not byte.signed
166
-
167
- def test_self_referential_struct_or_union(self):
168
- struct_llist = angr.types.parse_type("struct llist { int data; struct llist *next; }")
169
- next_struct_llist = struct_llist.fields["next"].pts_to
170
- assert len(next_struct_llist.fields) == 2
171
- assert isinstance(next_struct_llist.fields["data"], SimTypeInt)
172
- assert isinstance(next_struct_llist.fields["next"], SimTypePointer)
173
-
174
- union_heap = angr.types.parse_type("union heap { int data; union heap *forward; }")
175
- forward_union_heap = union_heap.members["forward"].pts_to
176
- assert len(forward_union_heap.members) == 2
177
- assert isinstance(forward_union_heap.members["data"], SimTypeInt)
178
- assert isinstance(forward_union_heap.members["forward"], SimTypePointer)
179
-
180
- def test_union_struct_referencing_each_other(self):
181
- angr.types.register_types(angr.types.parse_type("struct a"))
182
- angr.types.register_types(angr.types.parse_type("struct b"))
183
- a = angr.types.parse_type("struct a { struct b *b_ptr; }")
184
- b = angr.types.parse_type("struct b { struct a *a_ptr; }")
185
-
186
- assert len(a.fields) == 1
187
- assert isinstance(a.fields["b_ptr"], SimTypePointer)
188
- assert isinstance(a.fields["b_ptr"].pts_to, SimStruct)
189
- assert a.fields["b_ptr"].pts_to.name == "b"
190
-
191
- assert len(b.fields) == 1
192
- assert isinstance(b.fields["a_ptr"], SimTypePointer)
193
- assert isinstance(b.fields["a_ptr"].pts_to, SimStruct)
194
- assert b.fields["a_ptr"].pts_to.name == "a"
195
-
196
- angr.types.register_types(angr.types.parse_type("union a"))
197
- angr.types.register_types(angr.types.parse_type("union b"))
198
- a = angr.types.parse_type("union a { union b *b_ptr; }")
199
- b = angr.types.parse_type("union b { union a *a_ptr; }")
200
-
201
- assert len(a.members) == 1
202
- assert isinstance(a.members["b_ptr"], SimTypePointer)
203
- assert isinstance(a.members["b_ptr"].pts_to, SimUnion)
204
- assert a.members["b_ptr"].pts_to.name == "b"
205
-
206
- assert len(b.members) == 1
207
- assert isinstance(b.members["a_ptr"], SimTypePointer)
208
- assert isinstance(b.members["a_ptr"].pts_to, SimUnion)
209
- assert b.members["a_ptr"].pts_to.name == "a"
210
-
211
- def test_top_type(self):
212
- angr.types.register_types({"undefined": angr.types.SimTypeTop()})
213
- fdef: Dict[str, SimTypeFunction] = angr.types.parse_defns("undefined f(undefined param_1, int param_2);")
214
- sig = fdef["f"]
215
- assert sig.args == [angr.types.SimTypeTop(), angr.types.SimTypeInt()]
216
-
217
- def test_arg_names(self):
218
- angr.types.register_types({"undefined": angr.types.SimTypeTop()})
219
- fdef: Dict[str, SimTypeFunction] = angr.types.parse_defns("int f(int param_1, int param_2);")
220
- sig = fdef["f"]
221
- assert sig.arg_names == ["param_1", "param_2"]
222
-
223
- # Check that arg_names survive a with_arch call
224
- nsig = sig.with_arch(archinfo.ArchAMD64())
225
- assert (
226
- sig.arg_names == nsig.arg_names
227
- ), "Function type generated with .with_arch() doesn't have identical arg_names"
228
-
229
- # If for some reason only some of the parameters are named,
230
- # the list can only be partially not None, but has to match the positions
231
- fdef: Dict[str, SimTypeFunction] = angr.types.parse_defns("int f(int param1, int);")
232
- sig = fdef["f"]
233
- assert sig.arg_names == ["param1", None]
234
-
235
- fdef: Dict[str, SimTypeFunction] = angr.types.parse_defns("int f();")
236
- sig = fdef["f"]
237
- assert sig.arg_names == ()
238
-
239
- def test_varargs(self):
240
- fdef = angr.types.parse_defns("int printf(const char *fmt, ...);")
241
- sig = fdef["printf"]
242
-
243
- assert sig.variadic
244
- assert "..." in repr(sig)
245
- assert len(sig.args) == 1
246
- assert len(sig.arg_names) == 1
247
- assert "..." not in sig._init_str()
248
-
249
- def test_forward_declaration_typedef_struct(self):
250
- _, extra_types = angr.types.parse_file("typedef struct _A A; struct _A {int a;int b;};")
251
-
252
- assert extra_types["A"].fields is not None
253
- assert isinstance(extra_types["A"].fields["a"], SimTypeInt)
254
- assert isinstance(extra_types["A"].fields["b"], SimTypeInt)
255
-
256
- assert extra_types["struct _A"].fields is not None
257
- assert isinstance(extra_types["struct _A"].fields["a"], SimTypeInt)
258
- assert isinstance(extra_types["struct _A"].fields["b"], SimTypeInt)
259
-
260
- def test_forward_declaration_typedef_union(self):
261
- _, extra_types = angr.types.parse_file("typedef union _A A; union _A {int a;int b;};")
262
-
263
- assert extra_types["A"].members is not None
264
- assert isinstance(extra_types["A"].members["a"], SimTypeInt)
265
- assert isinstance(extra_types["A"].members["b"], SimTypeInt)
266
-
267
- assert extra_types["union _A"].members is not None
268
- assert isinstance(extra_types["union _A"].members["a"], SimTypeInt)
269
- assert isinstance(extra_types["union _A"].members["b"], SimTypeInt)
270
-
271
- def test_bitfield_struct(self):
272
- code = """
273
- struct bitfield_struct {
274
- uint64_t qword;
275
- uint64_t a : 36,
276
- b : 8,
277
- c : 7,
278
- d : 12,
279
- e : 1;
280
- char* name;
281
- }"""
282
- ty = angr.types.parse_type(code)
283
- ty = ty.with_arch(archinfo.ArchAArch64())
284
- assert [(t.size, t.offset) for t in list(ty.fields.values())[1:-1]] == [
285
- (36, 0),
286
- (8, 4),
287
- (7, 4),
288
- (12, 3),
289
- (1, 7),
290
- ]
291
-
292
-
293
- class TestSimTypeFunction(unittest.TestCase):
294
- def test_c_repr(self):
295
- proto = "int (main)(int argc, char **argv)"
296
- _, pyproto, _ = convert_cproto_to_py(proto + ";")
297
- assert pyproto.c_repr(name="main", full=True) == proto
298
-
299
- def test_c_repr_noargs(self):
300
- proto = "int (main)()"
301
- _, pyproto, _ = convert_cproto_to_py(proto + ";")
302
- assert pyproto.c_repr(name="main") == proto
303
-
304
- def test_c_repr_noname(self):
305
- _, pyproto, _ = convert_cproto_to_py("int (main)(int argc, char **argv);")
306
- assert pyproto.c_repr(full=True) == "int ()(int argc, char **argv)"
307
-
308
- def test_c_repr_notfull(self):
309
- _, pyproto, _ = convert_cproto_to_py("int (main)(int argc, char **argv);")
310
- assert pyproto.c_repr(name="main", full=False) == "int (main)(int, char **)"
311
-
312
- def test_c_repr_void(self):
313
- proto = "void (main)(int argc, char **argv)"
314
- _, pyproto, _ = convert_cproto_to_py(proto + ";")
315
- assert pyproto.c_repr(name="main", full=True) == proto
316
-
317
- def test_c_repr_variadic(self):
318
- proto = "int (main)(int x, ...)"
319
- _, pyproto, _ = convert_cproto_to_py(proto + ";")
320
- assert pyproto.c_repr(name="main", full=True) == proto
321
-
322
- def test_c_repr_variadic_only(self):
323
- _, pyproto, _ = convert_cproto_to_py("int (main)(void);") # XXX: pycparser does not support full variadic yet
324
- pyproto.variadic = True
325
- assert pyproto.c_repr(name="main", full=True) == "int (main)(...)"
326
-
327
-
328
- if __name__ == "__main__":
329
- unittest.main()
tests/utils/__init__.py DELETED
File without changes
tests/utils/test_graph.py DELETED
@@ -1,41 +0,0 @@
1
- #!/usr/bin/env python3
2
- # pylint: disable=missing-class-docstring,disable=no-self-use
3
- import unittest
4
- import networkx as nx
5
- from angr.utils.graph import Dominators, TemporaryNode
6
-
7
-
8
- class TestGraph(unittest.TestCase):
9
- def test_dominators(self):
10
- G = nx.DiGraph()
11
- G.add_edge("1", "2")
12
- G.add_edge("1", "3")
13
- G.add_edge("2", "5")
14
- G.add_edge("2", "7")
15
- G.add_edge("3", "4")
16
- G.add_edge("4", "5")
17
- G.add_edge("4", "6")
18
- G.add_edge("4", "7")
19
- G.add_edge("5", "8")
20
- G.add_edge("7", "8")
21
- G.add_edge("8", "6")
22
- d = Dominators(G, "1")
23
- start_node = TemporaryNode("start_node")
24
- end_node = TemporaryNode("end_node")
25
- idom_succ = {
26
- start_node: {"1": {}},
27
- "1": {"2": {}, "3": {}, "5": {}, "6": {}, "7": {}, "8": {}},
28
- "2": {},
29
- "3": {"4": {}},
30
- "4": {},
31
- "5": {},
32
- "6": {end_node: {}},
33
- "7": {},
34
- "8": {},
35
- end_node: {},
36
- }
37
- assert d.dom.succ == idom_succ
38
-
39
-
40
- if __name__ == "__main__":
41
- unittest.main()
File without changes
File without changes