angr 9.2.165__cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.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 (1409) hide show
  1. angr/__init__.py +366 -0
  2. angr/__main__.py +152 -0
  3. angr/ailment/__init__.py +81 -0
  4. angr/ailment/block.py +81 -0
  5. angr/ailment/block_walker.py +845 -0
  6. angr/ailment/constant.py +3 -0
  7. angr/ailment/converter_common.py +11 -0
  8. angr/ailment/converter_pcode.py +623 -0
  9. angr/ailment/converter_vex.py +798 -0
  10. angr/ailment/expression.py +1655 -0
  11. angr/ailment/manager.py +33 -0
  12. angr/ailment/statement.py +978 -0
  13. angr/ailment/tagged_object.py +61 -0
  14. angr/ailment/utils.py +114 -0
  15. angr/analyses/__init__.py +113 -0
  16. angr/analyses/analysis.py +429 -0
  17. angr/analyses/backward_slice.py +686 -0
  18. angr/analyses/binary_optimizer.py +670 -0
  19. angr/analyses/bindiff.py +1512 -0
  20. angr/analyses/boyscout.py +76 -0
  21. angr/analyses/callee_cleanup_finder.py +74 -0
  22. angr/analyses/calling_convention/__init__.py +6 -0
  23. angr/analyses/calling_convention/calling_convention.py +1096 -0
  24. angr/analyses/calling_convention/fact_collector.py +636 -0
  25. angr/analyses/calling_convention/utils.py +60 -0
  26. angr/analyses/cdg.py +189 -0
  27. angr/analyses/cfg/__init__.py +23 -0
  28. angr/analyses/cfg/cfb.py +428 -0
  29. angr/analyses/cfg/cfg.py +74 -0
  30. angr/analyses/cfg/cfg_arch_options.py +95 -0
  31. angr/analyses/cfg/cfg_base.py +2909 -0
  32. angr/analyses/cfg/cfg_emulated.py +3451 -0
  33. angr/analyses/cfg/cfg_fast.py +5316 -0
  34. angr/analyses/cfg/cfg_fast_soot.py +662 -0
  35. angr/analyses/cfg/cfg_job_base.py +203 -0
  36. angr/analyses/cfg/indirect_jump_resolvers/__init__.py +28 -0
  37. angr/analyses/cfg/indirect_jump_resolvers/amd64_elf_got.py +62 -0
  38. angr/analyses/cfg/indirect_jump_resolvers/amd64_pe_iat.py +51 -0
  39. angr/analyses/cfg/indirect_jump_resolvers/arm_elf_fast.py +159 -0
  40. angr/analyses/cfg/indirect_jump_resolvers/const_resolver.py +339 -0
  41. angr/analyses/cfg/indirect_jump_resolvers/constant_value_manager.py +107 -0
  42. angr/analyses/cfg/indirect_jump_resolvers/default_resolvers.py +76 -0
  43. angr/analyses/cfg/indirect_jump_resolvers/jumptable.py +2367 -0
  44. angr/analyses/cfg/indirect_jump_resolvers/memload_resolver.py +81 -0
  45. angr/analyses/cfg/indirect_jump_resolvers/mips_elf_fast.py +286 -0
  46. angr/analyses/cfg/indirect_jump_resolvers/mips_elf_got.py +148 -0
  47. angr/analyses/cfg/indirect_jump_resolvers/propagator_utils.py +46 -0
  48. angr/analyses/cfg/indirect_jump_resolvers/resolver.py +74 -0
  49. angr/analyses/cfg/indirect_jump_resolvers/syscall_resolver.py +92 -0
  50. angr/analyses/cfg/indirect_jump_resolvers/x86_elf_pic_plt.py +88 -0
  51. angr/analyses/cfg/indirect_jump_resolvers/x86_pe_iat.py +47 -0
  52. angr/analyses/cfg_slice_to_sink/__init__.py +11 -0
  53. angr/analyses/cfg_slice_to_sink/cfg_slice_to_sink.py +117 -0
  54. angr/analyses/cfg_slice_to_sink/graph.py +87 -0
  55. angr/analyses/cfg_slice_to_sink/transitions.py +27 -0
  56. angr/analyses/class_identifier.py +63 -0
  57. angr/analyses/code_tagging.py +123 -0
  58. angr/analyses/codecave.py +77 -0
  59. angr/analyses/complete_calling_conventions.py +461 -0
  60. angr/analyses/congruency_check.py +377 -0
  61. angr/analyses/data_dep/__init__.py +16 -0
  62. angr/analyses/data_dep/data_dependency_analysis.py +595 -0
  63. angr/analyses/data_dep/dep_nodes.py +171 -0
  64. angr/analyses/data_dep/sim_act_location.py +49 -0
  65. angr/analyses/datagraph_meta.py +105 -0
  66. angr/analyses/ddg.py +1670 -0
  67. angr/analyses/decompiler/__init__.py +41 -0
  68. angr/analyses/decompiler/ail_simplifier.py +2085 -0
  69. angr/analyses/decompiler/ailgraph_walker.py +49 -0
  70. angr/analyses/decompiler/block_io_finder.py +302 -0
  71. angr/analyses/decompiler/block_similarity.py +196 -0
  72. angr/analyses/decompiler/block_simplifier.py +376 -0
  73. angr/analyses/decompiler/callsite_maker.py +571 -0
  74. angr/analyses/decompiler/ccall_rewriters/__init__.py +9 -0
  75. angr/analyses/decompiler/ccall_rewriters/amd64_ccalls.py +580 -0
  76. angr/analyses/decompiler/ccall_rewriters/rewriter_base.py +20 -0
  77. angr/analyses/decompiler/ccall_rewriters/x86_ccalls.py +313 -0
  78. angr/analyses/decompiler/clinic.py +3308 -0
  79. angr/analyses/decompiler/condition_processor.py +1281 -0
  80. angr/analyses/decompiler/counters/__init__.py +16 -0
  81. angr/analyses/decompiler/counters/boolean_counter.py +27 -0
  82. angr/analyses/decompiler/counters/call_counter.py +57 -0
  83. angr/analyses/decompiler/counters/expression_counters.py +77 -0
  84. angr/analyses/decompiler/counters/seq_cf_structure_counter.py +63 -0
  85. angr/analyses/decompiler/decompilation_cache.py +46 -0
  86. angr/analyses/decompiler/decompilation_options.py +275 -0
  87. angr/analyses/decompiler/decompiler.py +710 -0
  88. angr/analyses/decompiler/dephication/__init__.py +6 -0
  89. angr/analyses/decompiler/dephication/dephication_base.py +100 -0
  90. angr/analyses/decompiler/dephication/graph_dephication.py +70 -0
  91. angr/analyses/decompiler/dephication/graph_rewriting.py +112 -0
  92. angr/analyses/decompiler/dephication/graph_vvar_mapping.py +363 -0
  93. angr/analyses/decompiler/dephication/rewriting_engine.py +527 -0
  94. angr/analyses/decompiler/dephication/seqnode_dephication.py +156 -0
  95. angr/analyses/decompiler/empty_node_remover.py +212 -0
  96. angr/analyses/decompiler/expression_narrower.py +287 -0
  97. angr/analyses/decompiler/goto_manager.py +112 -0
  98. angr/analyses/decompiler/graph_region.py +426 -0
  99. angr/analyses/decompiler/jump_target_collector.py +37 -0
  100. angr/analyses/decompiler/jumptable_entry_condition_rewriter.py +67 -0
  101. angr/analyses/decompiler/label_collector.py +32 -0
  102. angr/analyses/decompiler/optimization_passes/__init__.py +151 -0
  103. angr/analyses/decompiler/optimization_passes/base_ptr_save_simplifier.py +157 -0
  104. angr/analyses/decompiler/optimization_passes/call_stmt_rewriter.py +46 -0
  105. angr/analyses/decompiler/optimization_passes/code_motion.py +362 -0
  106. angr/analyses/decompiler/optimization_passes/condition_constprop.py +219 -0
  107. angr/analyses/decompiler/optimization_passes/const_derefs.py +266 -0
  108. angr/analyses/decompiler/optimization_passes/const_prop_reverter.py +365 -0
  109. angr/analyses/decompiler/optimization_passes/cross_jump_reverter.py +106 -0
  110. angr/analyses/decompiler/optimization_passes/deadblock_remover.py +82 -0
  111. angr/analyses/decompiler/optimization_passes/determine_load_sizes.py +64 -0
  112. angr/analyses/decompiler/optimization_passes/div_simplifier.py +425 -0
  113. angr/analyses/decompiler/optimization_passes/duplication_reverter/__init__.py +5 -0
  114. angr/analyses/decompiler/optimization_passes/duplication_reverter/ail_merge_graph.py +503 -0
  115. angr/analyses/decompiler/optimization_passes/duplication_reverter/duplication_reverter.py +1218 -0
  116. angr/analyses/decompiler/optimization_passes/duplication_reverter/errors.py +16 -0
  117. angr/analyses/decompiler/optimization_passes/duplication_reverter/similarity.py +126 -0
  118. angr/analyses/decompiler/optimization_passes/duplication_reverter/utils.py +167 -0
  119. angr/analyses/decompiler/optimization_passes/eager_std_string_concatenation.py +165 -0
  120. angr/analyses/decompiler/optimization_passes/engine_base.py +500 -0
  121. angr/analyses/decompiler/optimization_passes/expr_op_swapper.py +135 -0
  122. angr/analyses/decompiler/optimization_passes/flip_boolean_cmp.py +113 -0
  123. angr/analyses/decompiler/optimization_passes/inlined_string_transformation_simplifier.py +615 -0
  124. angr/analyses/decompiler/optimization_passes/ite_expr_converter.py +224 -0
  125. angr/analyses/decompiler/optimization_passes/ite_region_converter.py +335 -0
  126. angr/analyses/decompiler/optimization_passes/lowered_switch_simplifier.py +923 -0
  127. angr/analyses/decompiler/optimization_passes/mod_simplifier.py +99 -0
  128. angr/analyses/decompiler/optimization_passes/optimization_pass.py +703 -0
  129. angr/analyses/decompiler/optimization_passes/register_save_area_simplifier.py +221 -0
  130. angr/analyses/decompiler/optimization_passes/ret_addr_save_simplifier.py +171 -0
  131. angr/analyses/decompiler/optimization_passes/ret_deduplicator.py +222 -0
  132. angr/analyses/decompiler/optimization_passes/return_duplicator_base.py +640 -0
  133. angr/analyses/decompiler/optimization_passes/return_duplicator_high.py +61 -0
  134. angr/analyses/decompiler/optimization_passes/return_duplicator_low.py +237 -0
  135. angr/analyses/decompiler/optimization_passes/stack_canary_simplifier.py +333 -0
  136. angr/analyses/decompiler/optimization_passes/switch_default_case_duplicator.py +149 -0
  137. angr/analyses/decompiler/optimization_passes/switch_reused_entry_rewriter.py +102 -0
  138. angr/analyses/decompiler/optimization_passes/tag_slicer.py +41 -0
  139. angr/analyses/decompiler/optimization_passes/win_stack_canary_simplifier.py +421 -0
  140. angr/analyses/decompiler/optimization_passes/x86_gcc_getpc_simplifier.py +88 -0
  141. angr/analyses/decompiler/peephole_optimizations/__init__.py +129 -0
  142. angr/analyses/decompiler/peephole_optimizations/a_div_const_add_a_mul_n_div_const.py +42 -0
  143. angr/analyses/decompiler/peephole_optimizations/a_mul_const_div_shr_const.py +38 -0
  144. angr/analyses/decompiler/peephole_optimizations/a_mul_const_sub_a.py +34 -0
  145. angr/analyses/decompiler/peephole_optimizations/a_shl_const_sub_a.py +34 -0
  146. angr/analyses/decompiler/peephole_optimizations/a_sub_a_div.py +25 -0
  147. angr/analyses/decompiler/peephole_optimizations/a_sub_a_shr_const_shr_const.py +37 -0
  148. angr/analyses/decompiler/peephole_optimizations/a_sub_a_sub_n.py +23 -0
  149. angr/analyses/decompiler/peephole_optimizations/arm_cmpf.py +236 -0
  150. angr/analyses/decompiler/peephole_optimizations/base.py +157 -0
  151. angr/analyses/decompiler/peephole_optimizations/basepointeroffset_add_n.py +34 -0
  152. angr/analyses/decompiler/peephole_optimizations/basepointeroffset_and_mask.py +36 -0
  153. angr/analyses/decompiler/peephole_optimizations/bitwise_or_to_logical_or.py +34 -0
  154. angr/analyses/decompiler/peephole_optimizations/bool_expr_xor_1.py +27 -0
  155. angr/analyses/decompiler/peephole_optimizations/bswap.py +142 -0
  156. angr/analyses/decompiler/peephole_optimizations/cas_intrinsics.py +115 -0
  157. angr/analyses/decompiler/peephole_optimizations/cmpord_rewriter.py +71 -0
  158. angr/analyses/decompiler/peephole_optimizations/coalesce_adjacent_shrs.py +39 -0
  159. angr/analyses/decompiler/peephole_optimizations/coalesce_same_cascading_ifs.py +28 -0
  160. angr/analyses/decompiler/peephole_optimizations/constant_derefs.py +44 -0
  161. angr/analyses/decompiler/peephole_optimizations/conv_a_sub0_shr_and.py +69 -0
  162. angr/analyses/decompiler/peephole_optimizations/conv_shl_shr.py +52 -0
  163. angr/analyses/decompiler/peephole_optimizations/eager_eval.py +447 -0
  164. angr/analyses/decompiler/peephole_optimizations/extended_byte_and_mask.py +56 -0
  165. angr/analyses/decompiler/peephole_optimizations/inlined_memcpy.py +78 -0
  166. angr/analyses/decompiler/peephole_optimizations/inlined_strcpy.py +217 -0
  167. angr/analyses/decompiler/peephole_optimizations/inlined_strcpy_consolidation.py +106 -0
  168. angr/analyses/decompiler/peephole_optimizations/inlined_wstrcpy.py +170 -0
  169. angr/analyses/decompiler/peephole_optimizations/invert_negated_logical_conjuction_disjunction.py +50 -0
  170. angr/analyses/decompiler/peephole_optimizations/modulo_simplifier.py +89 -0
  171. angr/analyses/decompiler/peephole_optimizations/one_sub_bool.py +33 -0
  172. angr/analyses/decompiler/peephole_optimizations/optimized_div_simplifier.py +356 -0
  173. angr/analyses/decompiler/peephole_optimizations/remove_cascading_conversions.py +45 -0
  174. angr/analyses/decompiler/peephole_optimizations/remove_cxx_destructor_calls.py +32 -0
  175. angr/analyses/decompiler/peephole_optimizations/remove_empty_if_body.py +46 -0
  176. angr/analyses/decompiler/peephole_optimizations/remove_noop_conversions.py +47 -0
  177. angr/analyses/decompiler/peephole_optimizations/remove_redundant_bitmasks.py +125 -0
  178. angr/analyses/decompiler/peephole_optimizations/remove_redundant_conversions.py +273 -0
  179. angr/analyses/decompiler/peephole_optimizations/remove_redundant_ite_branch.py +30 -0
  180. angr/analyses/decompiler/peephole_optimizations/remove_redundant_ite_comparisons.py +54 -0
  181. angr/analyses/decompiler/peephole_optimizations/remove_redundant_nots.py +36 -0
  182. angr/analyses/decompiler/peephole_optimizations/remove_redundant_reinterprets.py +44 -0
  183. angr/analyses/decompiler/peephole_optimizations/remove_redundant_shifts.py +95 -0
  184. angr/analyses/decompiler/peephole_optimizations/remove_redundant_shifts_around_comparators.py +44 -0
  185. angr/analyses/decompiler/peephole_optimizations/rewrite_bit_extractions.py +85 -0
  186. angr/analyses/decompiler/peephole_optimizations/rewrite_conv_mul.py +40 -0
  187. angr/analyses/decompiler/peephole_optimizations/rewrite_cxx_operator_calls.py +90 -0
  188. angr/analyses/decompiler/peephole_optimizations/rewrite_mips_gp_loads.py +49 -0
  189. angr/analyses/decompiler/peephole_optimizations/rol_ror.py +130 -0
  190. angr/analyses/decompiler/peephole_optimizations/sar_to_signed_div.py +143 -0
  191. angr/analyses/decompiler/peephole_optimizations/shl_to_mul.py +25 -0
  192. angr/analyses/decompiler/peephole_optimizations/simplify_pc_relative_loads.py +51 -0
  193. angr/analyses/decompiler/peephole_optimizations/single_bit_cond_to_boolexpr.py +82 -0
  194. angr/analyses/decompiler/peephole_optimizations/single_bit_xor.py +29 -0
  195. angr/analyses/decompiler/peephole_optimizations/tidy_stack_addr.py +131 -0
  196. angr/analyses/decompiler/peephole_optimizations/utils.py +18 -0
  197. angr/analyses/decompiler/presets/__init__.py +20 -0
  198. angr/analyses/decompiler/presets/basic.py +32 -0
  199. angr/analyses/decompiler/presets/fast.py +58 -0
  200. angr/analyses/decompiler/presets/full.py +68 -0
  201. angr/analyses/decompiler/presets/preset.py +37 -0
  202. angr/analyses/decompiler/redundant_label_remover.py +134 -0
  203. angr/analyses/decompiler/region_identifier.py +1239 -0
  204. angr/analyses/decompiler/region_simplifiers/__init__.py +5 -0
  205. angr/analyses/decompiler/region_simplifiers/cascading_cond_transformer.py +95 -0
  206. angr/analyses/decompiler/region_simplifiers/cascading_ifs.py +82 -0
  207. angr/analyses/decompiler/region_simplifiers/expr_folding.py +818 -0
  208. angr/analyses/decompiler/region_simplifiers/goto.py +178 -0
  209. angr/analyses/decompiler/region_simplifiers/if_.py +135 -0
  210. angr/analyses/decompiler/region_simplifiers/ifelse.py +91 -0
  211. angr/analyses/decompiler/region_simplifiers/loop.py +143 -0
  212. angr/analyses/decompiler/region_simplifiers/node_address_finder.py +24 -0
  213. angr/analyses/decompiler/region_simplifiers/region_simplifier.py +246 -0
  214. angr/analyses/decompiler/region_simplifiers/switch_cluster_simplifier.py +654 -0
  215. angr/analyses/decompiler/region_simplifiers/switch_expr_simplifier.py +87 -0
  216. angr/analyses/decompiler/region_walker.py +24 -0
  217. angr/analyses/decompiler/return_maker.py +72 -0
  218. angr/analyses/decompiler/seq_to_blocks.py +20 -0
  219. angr/analyses/decompiler/sequence_walker.py +257 -0
  220. angr/analyses/decompiler/ssailification/__init__.py +4 -0
  221. angr/analyses/decompiler/ssailification/rewriting.py +379 -0
  222. angr/analyses/decompiler/ssailification/rewriting_engine.py +1053 -0
  223. angr/analyses/decompiler/ssailification/rewriting_state.py +61 -0
  224. angr/analyses/decompiler/ssailification/ssailification.py +276 -0
  225. angr/analyses/decompiler/ssailification/traversal.py +124 -0
  226. angr/analyses/decompiler/ssailification/traversal_engine.py +306 -0
  227. angr/analyses/decompiler/ssailification/traversal_state.py +48 -0
  228. angr/analyses/decompiler/stack_item.py +36 -0
  229. angr/analyses/decompiler/structured_codegen/__init__.py +25 -0
  230. angr/analyses/decompiler/structured_codegen/base.py +132 -0
  231. angr/analyses/decompiler/structured_codegen/c.py +4082 -0
  232. angr/analyses/decompiler/structured_codegen/dummy.py +15 -0
  233. angr/analyses/decompiler/structured_codegen/dwarf_import.py +190 -0
  234. angr/analyses/decompiler/structuring/__init__.py +30 -0
  235. angr/analyses/decompiler/structuring/dream.py +1217 -0
  236. angr/analyses/decompiler/structuring/phoenix.py +3090 -0
  237. angr/analyses/decompiler/structuring/recursive_structurer.py +187 -0
  238. angr/analyses/decompiler/structuring/sailr.py +120 -0
  239. angr/analyses/decompiler/structuring/structurer_base.py +1066 -0
  240. angr/analyses/decompiler/structuring/structurer_nodes.py +440 -0
  241. angr/analyses/decompiler/utils.py +1118 -0
  242. angr/analyses/deobfuscator/__init__.py +18 -0
  243. angr/analyses/deobfuscator/api_obf_finder.py +325 -0
  244. angr/analyses/deobfuscator/api_obf_peephole_optimizer.py +51 -0
  245. angr/analyses/deobfuscator/api_obf_type2_finder.py +166 -0
  246. angr/analyses/deobfuscator/irsb_reg_collector.py +54 -0
  247. angr/analyses/deobfuscator/string_obf_finder.py +959 -0
  248. angr/analyses/deobfuscator/string_obf_opt_passes.py +133 -0
  249. angr/analyses/deobfuscator/string_obf_peephole_optimizer.py +47 -0
  250. angr/analyses/disassembly.py +1295 -0
  251. angr/analyses/disassembly_utils.py +101 -0
  252. angr/analyses/dominance_frontier.py +57 -0
  253. angr/analyses/fcp/__init__.py +4 -0
  254. angr/analyses/fcp/fcp.py +427 -0
  255. angr/analyses/find_objects_static.py +205 -0
  256. angr/analyses/flirt/__init__.py +47 -0
  257. angr/analyses/flirt/consts.py +160 -0
  258. angr/analyses/flirt/flirt.py +244 -0
  259. angr/analyses/flirt/flirt_function.py +20 -0
  260. angr/analyses/flirt/flirt_matcher.py +351 -0
  261. angr/analyses/flirt/flirt_module.py +32 -0
  262. angr/analyses/flirt/flirt_node.py +23 -0
  263. angr/analyses/flirt/flirt_sig.py +359 -0
  264. angr/analyses/flirt/flirt_utils.py +31 -0
  265. angr/analyses/forward_analysis/__init__.py +12 -0
  266. angr/analyses/forward_analysis/forward_analysis.py +530 -0
  267. angr/analyses/forward_analysis/job_info.py +64 -0
  268. angr/analyses/forward_analysis/visitors/__init__.py +14 -0
  269. angr/analyses/forward_analysis/visitors/call_graph.py +29 -0
  270. angr/analyses/forward_analysis/visitors/function_graph.py +86 -0
  271. angr/analyses/forward_analysis/visitors/graph.py +242 -0
  272. angr/analyses/forward_analysis/visitors/loop.py +29 -0
  273. angr/analyses/forward_analysis/visitors/single_node_graph.py +38 -0
  274. angr/analyses/identifier/__init__.py +5 -0
  275. angr/analyses/identifier/custom_callable.py +137 -0
  276. angr/analyses/identifier/errors.py +10 -0
  277. angr/analyses/identifier/func.py +60 -0
  278. angr/analyses/identifier/functions/__init__.py +37 -0
  279. angr/analyses/identifier/functions/atoi.py +73 -0
  280. angr/analyses/identifier/functions/based_atoi.py +125 -0
  281. angr/analyses/identifier/functions/fdprintf.py +123 -0
  282. angr/analyses/identifier/functions/free.py +64 -0
  283. angr/analyses/identifier/functions/int2str.py +287 -0
  284. angr/analyses/identifier/functions/malloc.py +111 -0
  285. angr/analyses/identifier/functions/memcmp.py +67 -0
  286. angr/analyses/identifier/functions/memcpy.py +89 -0
  287. angr/analyses/identifier/functions/memset.py +43 -0
  288. angr/analyses/identifier/functions/printf.py +123 -0
  289. angr/analyses/identifier/functions/recv_until.py +312 -0
  290. angr/analyses/identifier/functions/skip_calloc.py +73 -0
  291. angr/analyses/identifier/functions/skip_realloc.py +97 -0
  292. angr/analyses/identifier/functions/skip_recv_n.py +105 -0
  293. angr/analyses/identifier/functions/snprintf.py +112 -0
  294. angr/analyses/identifier/functions/sprintf.py +116 -0
  295. angr/analyses/identifier/functions/strcasecmp.py +33 -0
  296. angr/analyses/identifier/functions/strcmp.py +113 -0
  297. angr/analyses/identifier/functions/strcpy.py +43 -0
  298. angr/analyses/identifier/functions/strlen.py +27 -0
  299. angr/analyses/identifier/functions/strncmp.py +104 -0
  300. angr/analyses/identifier/functions/strncpy.py +65 -0
  301. angr/analyses/identifier/functions/strtol.py +89 -0
  302. angr/analyses/identifier/identify.py +825 -0
  303. angr/analyses/identifier/runner.py +360 -0
  304. angr/analyses/init_finder.py +289 -0
  305. angr/analyses/loop_analysis.py +349 -0
  306. angr/analyses/loopfinder.py +171 -0
  307. angr/analyses/patchfinder.py +137 -0
  308. angr/analyses/pathfinder.py +282 -0
  309. angr/analyses/propagator/__init__.py +5 -0
  310. angr/analyses/propagator/engine_base.py +62 -0
  311. angr/analyses/propagator/engine_vex.py +297 -0
  312. angr/analyses/propagator/propagator.py +361 -0
  313. angr/analyses/propagator/top_checker_mixin.py +218 -0
  314. angr/analyses/propagator/values.py +117 -0
  315. angr/analyses/propagator/vex_vars.py +68 -0
  316. angr/analyses/proximity_graph.py +444 -0
  317. angr/analyses/reaching_definitions/__init__.py +67 -0
  318. angr/analyses/reaching_definitions/call_trace.py +73 -0
  319. angr/analyses/reaching_definitions/dep_graph.py +433 -0
  320. angr/analyses/reaching_definitions/engine_ail.py +1130 -0
  321. angr/analyses/reaching_definitions/engine_vex.py +1127 -0
  322. angr/analyses/reaching_definitions/external_codeloc.py +0 -0
  323. angr/analyses/reaching_definitions/function_handler.py +638 -0
  324. angr/analyses/reaching_definitions/function_handler_library/__init__.py +12 -0
  325. angr/analyses/reaching_definitions/function_handler_library/stdio.py +269 -0
  326. angr/analyses/reaching_definitions/function_handler_library/stdlib.py +195 -0
  327. angr/analyses/reaching_definitions/function_handler_library/string.py +158 -0
  328. angr/analyses/reaching_definitions/function_handler_library/unistd.py +51 -0
  329. angr/analyses/reaching_definitions/heap_allocator.py +70 -0
  330. angr/analyses/reaching_definitions/rd_initializer.py +237 -0
  331. angr/analyses/reaching_definitions/rd_state.py +579 -0
  332. angr/analyses/reaching_definitions/reaching_definitions.py +581 -0
  333. angr/analyses/reaching_definitions/subject.py +65 -0
  334. angr/analyses/reassembler.py +2900 -0
  335. angr/analyses/s_liveness.py +203 -0
  336. angr/analyses/s_propagator.py +542 -0
  337. angr/analyses/s_reaching_definitions/__init__.py +12 -0
  338. angr/analyses/s_reaching_definitions/s_rda_model.py +136 -0
  339. angr/analyses/s_reaching_definitions/s_rda_view.py +316 -0
  340. angr/analyses/s_reaching_definitions/s_reaching_definitions.py +177 -0
  341. angr/analyses/smc.py +161 -0
  342. angr/analyses/soot_class_hierarchy.py +273 -0
  343. angr/analyses/stack_pointer_tracker.py +953 -0
  344. angr/analyses/static_hooker.py +53 -0
  345. angr/analyses/typehoon/__init__.py +5 -0
  346. angr/analyses/typehoon/dfa.py +118 -0
  347. angr/analyses/typehoon/lifter.py +122 -0
  348. angr/analyses/typehoon/simple_solver.py +1666 -0
  349. angr/analyses/typehoon/translator.py +279 -0
  350. angr/analyses/typehoon/typeconsts.py +338 -0
  351. angr/analyses/typehoon/typehoon.py +319 -0
  352. angr/analyses/typehoon/typevars.py +622 -0
  353. angr/analyses/typehoon/variance.py +11 -0
  354. angr/analyses/unpacker/__init__.py +6 -0
  355. angr/analyses/unpacker/obfuscation_detector.py +103 -0
  356. angr/analyses/unpacker/packing_detector.py +138 -0
  357. angr/analyses/variable_recovery/__init__.py +9 -0
  358. angr/analyses/variable_recovery/annotations.py +58 -0
  359. angr/analyses/variable_recovery/engine_ail.py +885 -0
  360. angr/analyses/variable_recovery/engine_base.py +1197 -0
  361. angr/analyses/variable_recovery/engine_vex.py +593 -0
  362. angr/analyses/variable_recovery/irsb_scanner.py +143 -0
  363. angr/analyses/variable_recovery/variable_recovery.py +574 -0
  364. angr/analyses/variable_recovery/variable_recovery_base.py +489 -0
  365. angr/analyses/variable_recovery/variable_recovery_fast.py +661 -0
  366. angr/analyses/veritesting.py +626 -0
  367. angr/analyses/vfg.py +1898 -0
  368. angr/analyses/vsa_ddg.py +420 -0
  369. angr/analyses/vtable.py +92 -0
  370. angr/analyses/xrefs.py +286 -0
  371. angr/angrdb/__init__.py +14 -0
  372. angr/angrdb/db.py +206 -0
  373. angr/angrdb/models.py +184 -0
  374. angr/angrdb/serializers/__init__.py +10 -0
  375. angr/angrdb/serializers/cfg_model.py +41 -0
  376. angr/angrdb/serializers/comments.py +60 -0
  377. angr/angrdb/serializers/funcs.py +61 -0
  378. angr/angrdb/serializers/kb.py +111 -0
  379. angr/angrdb/serializers/labels.py +59 -0
  380. angr/angrdb/serializers/loader.py +165 -0
  381. angr/angrdb/serializers/structured_code.py +125 -0
  382. angr/angrdb/serializers/variables.py +58 -0
  383. angr/angrdb/serializers/xrefs.py +48 -0
  384. angr/annocfg.py +317 -0
  385. angr/blade.py +431 -0
  386. angr/block.py +509 -0
  387. angr/callable.py +168 -0
  388. angr/calling_conventions.py +2580 -0
  389. angr/code_location.py +163 -0
  390. angr/codenode.py +145 -0
  391. angr/concretization_strategies/__init__.py +32 -0
  392. angr/concretization_strategies/any.py +17 -0
  393. angr/concretization_strategies/any_named.py +35 -0
  394. angr/concretization_strategies/base.py +81 -0
  395. angr/concretization_strategies/controlled_data.py +58 -0
  396. angr/concretization_strategies/eval.py +19 -0
  397. angr/concretization_strategies/logging.py +35 -0
  398. angr/concretization_strategies/max.py +25 -0
  399. angr/concretization_strategies/nonzero.py +16 -0
  400. angr/concretization_strategies/nonzero_range.py +22 -0
  401. angr/concretization_strategies/norepeats.py +37 -0
  402. angr/concretization_strategies/norepeats_range.py +37 -0
  403. angr/concretization_strategies/range.py +19 -0
  404. angr/concretization_strategies/signed_add.py +31 -0
  405. angr/concretization_strategies/single.py +15 -0
  406. angr/concretization_strategies/solutions.py +20 -0
  407. angr/concretization_strategies/unlimited_range.py +17 -0
  408. angr/distributed/__init__.py +9 -0
  409. angr/distributed/server.py +197 -0
  410. angr/distributed/worker.py +185 -0
  411. angr/emulator.py +143 -0
  412. angr/engines/__init__.py +67 -0
  413. angr/engines/concrete.py +66 -0
  414. angr/engines/engine.py +29 -0
  415. angr/engines/failure.py +27 -0
  416. angr/engines/hook.py +68 -0
  417. angr/engines/icicle.py +278 -0
  418. angr/engines/light/__init__.py +23 -0
  419. angr/engines/light/data.py +681 -0
  420. angr/engines/light/engine.py +1285 -0
  421. angr/engines/pcode/__init__.py +9 -0
  422. angr/engines/pcode/behavior.py +994 -0
  423. angr/engines/pcode/cc.py +128 -0
  424. angr/engines/pcode/emulate.py +440 -0
  425. angr/engines/pcode/engine.py +242 -0
  426. angr/engines/pcode/lifter.py +1420 -0
  427. angr/engines/procedure.py +70 -0
  428. angr/engines/soot/__init__.py +5 -0
  429. angr/engines/soot/engine.py +410 -0
  430. angr/engines/soot/exceptions.py +17 -0
  431. angr/engines/soot/expressions/__init__.py +87 -0
  432. angr/engines/soot/expressions/arrayref.py +22 -0
  433. angr/engines/soot/expressions/base.py +21 -0
  434. angr/engines/soot/expressions/binop.py +28 -0
  435. angr/engines/soot/expressions/cast.py +22 -0
  436. angr/engines/soot/expressions/condition.py +35 -0
  437. angr/engines/soot/expressions/constants.py +47 -0
  438. angr/engines/soot/expressions/instanceOf.py +15 -0
  439. angr/engines/soot/expressions/instancefieldref.py +8 -0
  440. angr/engines/soot/expressions/invoke.py +114 -0
  441. angr/engines/soot/expressions/length.py +8 -0
  442. angr/engines/soot/expressions/local.py +8 -0
  443. angr/engines/soot/expressions/new.py +16 -0
  444. angr/engines/soot/expressions/newArray.py +54 -0
  445. angr/engines/soot/expressions/newMultiArray.py +86 -0
  446. angr/engines/soot/expressions/paramref.py +8 -0
  447. angr/engines/soot/expressions/phi.py +30 -0
  448. angr/engines/soot/expressions/staticfieldref.py +8 -0
  449. angr/engines/soot/expressions/thisref.py +7 -0
  450. angr/engines/soot/expressions/unsupported.py +7 -0
  451. angr/engines/soot/field_dispatcher.py +46 -0
  452. angr/engines/soot/method_dispatcher.py +46 -0
  453. angr/engines/soot/statements/__init__.py +44 -0
  454. angr/engines/soot/statements/assign.py +30 -0
  455. angr/engines/soot/statements/base.py +79 -0
  456. angr/engines/soot/statements/goto.py +14 -0
  457. angr/engines/soot/statements/identity.py +15 -0
  458. angr/engines/soot/statements/if_.py +19 -0
  459. angr/engines/soot/statements/invoke.py +12 -0
  460. angr/engines/soot/statements/return_.py +20 -0
  461. angr/engines/soot/statements/switch.py +41 -0
  462. angr/engines/soot/statements/throw.py +15 -0
  463. angr/engines/soot/values/__init__.py +38 -0
  464. angr/engines/soot/values/arrayref.py +122 -0
  465. angr/engines/soot/values/base.py +7 -0
  466. angr/engines/soot/values/constants.py +18 -0
  467. angr/engines/soot/values/instancefieldref.py +44 -0
  468. angr/engines/soot/values/local.py +18 -0
  469. angr/engines/soot/values/paramref.py +18 -0
  470. angr/engines/soot/values/staticfieldref.py +38 -0
  471. angr/engines/soot/values/strref.py +38 -0
  472. angr/engines/soot/values/thisref.py +149 -0
  473. angr/engines/successors.py +654 -0
  474. angr/engines/syscall.py +51 -0
  475. angr/engines/unicorn.py +490 -0
  476. angr/engines/vex/__init__.py +20 -0
  477. angr/engines/vex/claripy/__init__.py +5 -0
  478. angr/engines/vex/claripy/ccall.py +2097 -0
  479. angr/engines/vex/claripy/datalayer.py +141 -0
  480. angr/engines/vex/claripy/irop.py +1276 -0
  481. angr/engines/vex/heavy/__init__.py +16 -0
  482. angr/engines/vex/heavy/actions.py +231 -0
  483. angr/engines/vex/heavy/concretizers.py +403 -0
  484. angr/engines/vex/heavy/dirty.py +466 -0
  485. angr/engines/vex/heavy/heavy.py +370 -0
  486. angr/engines/vex/heavy/inspect.py +52 -0
  487. angr/engines/vex/heavy/resilience.py +85 -0
  488. angr/engines/vex/heavy/super_fastpath.py +34 -0
  489. angr/engines/vex/lifter.py +420 -0
  490. angr/engines/vex/light/__init__.py +11 -0
  491. angr/engines/vex/light/light.py +551 -0
  492. angr/engines/vex/light/resilience.py +74 -0
  493. angr/engines/vex/light/slicing.py +52 -0
  494. angr/errors.py +609 -0
  495. angr/exploration_techniques/__init__.py +53 -0
  496. angr/exploration_techniques/base.py +126 -0
  497. angr/exploration_techniques/bucketizer.py +94 -0
  498. angr/exploration_techniques/common.py +56 -0
  499. angr/exploration_techniques/dfs.py +37 -0
  500. angr/exploration_techniques/director.py +520 -0
  501. angr/exploration_techniques/driller_core.py +100 -0
  502. angr/exploration_techniques/explorer.py +152 -0
  503. angr/exploration_techniques/lengthlimiter.py +22 -0
  504. angr/exploration_techniques/local_loop_seer.py +65 -0
  505. angr/exploration_techniques/loop_seer.py +236 -0
  506. angr/exploration_techniques/manual_mergepoint.py +82 -0
  507. angr/exploration_techniques/memory_watcher.py +43 -0
  508. angr/exploration_techniques/oppologist.py +92 -0
  509. angr/exploration_techniques/slicecutor.py +118 -0
  510. angr/exploration_techniques/spiller.py +280 -0
  511. angr/exploration_techniques/spiller_db.py +27 -0
  512. angr/exploration_techniques/stochastic.py +56 -0
  513. angr/exploration_techniques/stub_stasher.py +19 -0
  514. angr/exploration_techniques/suggestions.py +159 -0
  515. angr/exploration_techniques/tech_builder.py +49 -0
  516. angr/exploration_techniques/threading.py +69 -0
  517. angr/exploration_techniques/timeout.py +34 -0
  518. angr/exploration_techniques/tracer.py +1098 -0
  519. angr/exploration_techniques/unique.py +106 -0
  520. angr/exploration_techniques/veritesting.py +37 -0
  521. angr/factory.py +404 -0
  522. angr/flirt/__init__.py +97 -0
  523. angr/flirt/build_sig.py +305 -0
  524. angr/graph_utils.py +0 -0
  525. angr/keyed_region.py +525 -0
  526. angr/knowledge_base.py +143 -0
  527. angr/knowledge_plugins/__init__.py +43 -0
  528. angr/knowledge_plugins/callsite_prototypes.py +53 -0
  529. angr/knowledge_plugins/cfg/__init__.py +18 -0
  530. angr/knowledge_plugins/cfg/cfg_manager.py +95 -0
  531. angr/knowledge_plugins/cfg/cfg_model.py +1045 -0
  532. angr/knowledge_plugins/cfg/cfg_node.py +536 -0
  533. angr/knowledge_plugins/cfg/indirect_jump.py +65 -0
  534. angr/knowledge_plugins/cfg/memory_data.py +156 -0
  535. angr/knowledge_plugins/comments.py +16 -0
  536. angr/knowledge_plugins/custom_strings.py +38 -0
  537. angr/knowledge_plugins/data.py +22 -0
  538. angr/knowledge_plugins/debug_variables.py +216 -0
  539. angr/knowledge_plugins/functions/__init__.py +9 -0
  540. angr/knowledge_plugins/functions/function.py +1780 -0
  541. angr/knowledge_plugins/functions/function_manager.py +588 -0
  542. angr/knowledge_plugins/functions/function_parser.py +299 -0
  543. angr/knowledge_plugins/functions/soot_function.py +128 -0
  544. angr/knowledge_plugins/indirect_jumps.py +35 -0
  545. angr/knowledge_plugins/key_definitions/__init__.py +17 -0
  546. angr/knowledge_plugins/key_definitions/atoms.py +374 -0
  547. angr/knowledge_plugins/key_definitions/constants.py +29 -0
  548. angr/knowledge_plugins/key_definitions/definition.py +214 -0
  549. angr/knowledge_plugins/key_definitions/environment.py +96 -0
  550. angr/knowledge_plugins/key_definitions/heap_address.py +33 -0
  551. angr/knowledge_plugins/key_definitions/key_definition_manager.py +82 -0
  552. angr/knowledge_plugins/key_definitions/live_definitions.py +1010 -0
  553. angr/knowledge_plugins/key_definitions/liveness.py +165 -0
  554. angr/knowledge_plugins/key_definitions/rd_model.py +171 -0
  555. angr/knowledge_plugins/key_definitions/tag.py +78 -0
  556. angr/knowledge_plugins/key_definitions/undefined.py +70 -0
  557. angr/knowledge_plugins/key_definitions/unknown_size.py +86 -0
  558. angr/knowledge_plugins/key_definitions/uses.py +178 -0
  559. angr/knowledge_plugins/labels.py +110 -0
  560. angr/knowledge_plugins/obfuscations.py +37 -0
  561. angr/knowledge_plugins/patches.py +126 -0
  562. angr/knowledge_plugins/plugin.py +24 -0
  563. angr/knowledge_plugins/propagations/__init__.py +10 -0
  564. angr/knowledge_plugins/propagations/prop_value.py +191 -0
  565. angr/knowledge_plugins/propagations/propagation_manager.py +60 -0
  566. angr/knowledge_plugins/propagations/propagation_model.py +80 -0
  567. angr/knowledge_plugins/propagations/states.py +552 -0
  568. angr/knowledge_plugins/structured_code.py +63 -0
  569. angr/knowledge_plugins/types.py +88 -0
  570. angr/knowledge_plugins/variables/__init__.py +8 -0
  571. angr/knowledge_plugins/variables/variable_access.py +113 -0
  572. angr/knowledge_plugins/variables/variable_manager.py +1380 -0
  573. angr/knowledge_plugins/xrefs/__init__.py +12 -0
  574. angr/knowledge_plugins/xrefs/xref.py +150 -0
  575. angr/knowledge_plugins/xrefs/xref_manager.py +127 -0
  576. angr/knowledge_plugins/xrefs/xref_types.py +16 -0
  577. angr/misc/__init__.py +19 -0
  578. angr/misc/ansi.py +47 -0
  579. angr/misc/autoimport.py +90 -0
  580. angr/misc/bug_report.py +117 -0
  581. angr/misc/hookset.py +106 -0
  582. angr/misc/loggers.py +130 -0
  583. angr/misc/picklable_lock.py +46 -0
  584. angr/misc/plugins.py +289 -0
  585. angr/misc/telemetry.py +54 -0
  586. angr/misc/testing.py +24 -0
  587. angr/misc/ux.py +31 -0
  588. angr/procedures/__init__.py +12 -0
  589. angr/procedures/advapi32/__init__.py +0 -0
  590. angr/procedures/cgc/__init__.py +3 -0
  591. angr/procedures/cgc/_terminate.py +11 -0
  592. angr/procedures/cgc/allocate.py +75 -0
  593. angr/procedures/cgc/deallocate.py +67 -0
  594. angr/procedures/cgc/fdwait.py +65 -0
  595. angr/procedures/cgc/random.py +67 -0
  596. angr/procedures/cgc/receive.py +93 -0
  597. angr/procedures/cgc/transmit.py +65 -0
  598. angr/procedures/definitions/__init__.py +779 -0
  599. angr/procedures/definitions/cgc.py +20 -0
  600. angr/procedures/definitions/glibc.py +8372 -0
  601. angr/procedures/definitions/gnulib.py +32 -0
  602. angr/procedures/definitions/libstdcpp.py +21 -0
  603. angr/procedures/definitions/linux_kernel.py +6171 -0
  604. angr/procedures/definitions/linux_loader.py +7 -0
  605. angr/procedures/definitions/msvcr.py +16 -0
  606. angr/procedures/definitions/parse_syscalls_from_local_system.py +50 -0
  607. angr/procedures/definitions/parse_win32json.py +2553 -0
  608. angr/procedures/definitions/types_stl.py +22 -0
  609. angr/procedures/definitions/types_win32.py +34482 -0
  610. angr/procedures/definitions/wdk_api-ms-win-dx-d3dkmt-l1-1-4.py +30 -0
  611. angr/procedures/definitions/wdk_api-ms-win-dx-d3dkmt-l1-1-6.py +26 -0
  612. angr/procedures/definitions/wdk_clfs.py +140 -0
  613. angr/procedures/definitions/wdk_fltmgr.py +556 -0
  614. angr/procedures/definitions/wdk_fwpkclnt.py +30 -0
  615. angr/procedures/definitions/wdk_fwpuclnt.py +316 -0
  616. angr/procedures/definitions/wdk_gdi32.py +366 -0
  617. angr/procedures/definitions/wdk_hal.py +78 -0
  618. angr/procedures/definitions/wdk_ksecdd.py +62 -0
  619. angr/procedures/definitions/wdk_ndis.py +238 -0
  620. angr/procedures/definitions/wdk_ntoskrnl.py +3451 -0
  621. angr/procedures/definitions/wdk_offreg.py +72 -0
  622. angr/procedures/definitions/wdk_pshed.py +36 -0
  623. angr/procedures/definitions/wdk_secur32.py +40 -0
  624. angr/procedures/definitions/wdk_vhfum.py +34 -0
  625. angr/procedures/definitions/win32_aclui.py +30 -0
  626. angr/procedures/definitions/win32_activeds.py +68 -0
  627. angr/procedures/definitions/win32_advapi32.py +1684 -0
  628. angr/procedures/definitions/win32_advpack.py +124 -0
  629. angr/procedures/definitions/win32_amsi.py +38 -0
  630. angr/procedures/definitions/win32_api-ms-win-appmodel-runtime-l1-1-1.py +44 -0
  631. angr/procedures/definitions/win32_api-ms-win-appmodel-runtime-l1-1-3.py +34 -0
  632. angr/procedures/definitions/win32_api-ms-win-appmodel-runtime-l1-1-6.py +26 -0
  633. angr/procedures/definitions/win32_api-ms-win-core-apiquery-l2-1-0.py +26 -0
  634. angr/procedures/definitions/win32_api-ms-win-core-backgroundtask-l1-1-0.py +26 -0
  635. angr/procedures/definitions/win32_api-ms-win-core-comm-l1-1-1.py +26 -0
  636. angr/procedures/definitions/win32_api-ms-win-core-comm-l1-1-2.py +26 -0
  637. angr/procedures/definitions/win32_api-ms-win-core-enclave-l1-1-1.py +30 -0
  638. angr/procedures/definitions/win32_api-ms-win-core-errorhandling-l1-1-3.py +26 -0
  639. angr/procedures/definitions/win32_api-ms-win-core-featurestaging-l1-1-0.py +34 -0
  640. angr/procedures/definitions/win32_api-ms-win-core-featurestaging-l1-1-1.py +26 -0
  641. angr/procedures/definitions/win32_api-ms-win-core-file-fromapp-l1-1-0.py +46 -0
  642. angr/procedures/definitions/win32_api-ms-win-core-handle-l1-1-0.py +26 -0
  643. angr/procedures/definitions/win32_api-ms-win-core-ioring-l1-1-0.py +48 -0
  644. angr/procedures/definitions/win32_api-ms-win-core-marshal-l1-1-0.py +32 -0
  645. angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-3.py +32 -0
  646. angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-4.py +26 -0
  647. angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-5.py +30 -0
  648. angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-6.py +32 -0
  649. angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-7.py +28 -0
  650. angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-8.py +30 -0
  651. angr/procedures/definitions/win32_api-ms-win-core-path-l1-1-0.py +68 -0
  652. angr/procedures/definitions/win32_api-ms-win-core-psm-appnotify-l1-1-0.py +28 -0
  653. angr/procedures/definitions/win32_api-ms-win-core-psm-appnotify-l1-1-1.py +28 -0
  654. angr/procedures/definitions/win32_api-ms-win-core-realtime-l1-1-1.py +30 -0
  655. angr/procedures/definitions/win32_api-ms-win-core-realtime-l1-1-2.py +30 -0
  656. angr/procedures/definitions/win32_api-ms-win-core-slapi-l1-1-0.py +26 -0
  657. angr/procedures/definitions/win32_api-ms-win-core-state-helpers-l1-1-0.py +26 -0
  658. angr/procedures/definitions/win32_api-ms-win-core-synch-l1-2-0.py +30 -0
  659. angr/procedures/definitions/win32_api-ms-win-core-sysinfo-l1-2-0.py +26 -0
  660. angr/procedures/definitions/win32_api-ms-win-core-sysinfo-l1-2-3.py +28 -0
  661. angr/procedures/definitions/win32_api-ms-win-core-sysinfo-l1-2-4.py +28 -0
  662. angr/procedures/definitions/win32_api-ms-win-core-sysinfo-l1-2-6.py +26 -0
  663. angr/procedures/definitions/win32_api-ms-win-core-util-l1-1-1.py +28 -0
  664. angr/procedures/definitions/win32_api-ms-win-core-winrt-error-l1-1-0.py +44 -0
  665. angr/procedures/definitions/win32_api-ms-win-core-winrt-error-l1-1-1.py +38 -0
  666. angr/procedures/definitions/win32_api-ms-win-core-winrt-l1-1-0.py +40 -0
  667. angr/procedures/definitions/win32_api-ms-win-core-winrt-registration-l1-1-0.py +24 -0
  668. angr/procedures/definitions/win32_api-ms-win-core-winrt-robuffer-l1-1-0.py +24 -0
  669. angr/procedures/definitions/win32_api-ms-win-core-winrt-roparameterizediid-l1-1-0.py +28 -0
  670. angr/procedures/definitions/win32_api-ms-win-core-winrt-string-l1-1-0.py +76 -0
  671. angr/procedures/definitions/win32_api-ms-win-core-winrt-string-l1-1-1.py +24 -0
  672. angr/procedures/definitions/win32_api-ms-win-core-wow64-l1-1-1.py +30 -0
  673. angr/procedures/definitions/win32_api-ms-win-devices-query-l1-1-0.py +42 -0
  674. angr/procedures/definitions/win32_api-ms-win-devices-query-l1-1-1.py +34 -0
  675. angr/procedures/definitions/win32_api-ms-win-dx-d3dkmt-l1-1-0.py +26 -0
  676. angr/procedures/definitions/win32_api-ms-win-gaming-deviceinformation-l1-1-0.py +26 -0
  677. angr/procedures/definitions/win32_api-ms-win-gaming-expandedresources-l1-1-0.py +30 -0
  678. angr/procedures/definitions/win32_api-ms-win-gaming-tcui-l1-1-0.py +38 -0
  679. angr/procedures/definitions/win32_api-ms-win-gaming-tcui-l1-1-1.py +28 -0
  680. angr/procedures/definitions/win32_api-ms-win-gaming-tcui-l1-1-2.py +38 -0
  681. angr/procedures/definitions/win32_api-ms-win-gaming-tcui-l1-1-3.py +28 -0
  682. angr/procedures/definitions/win32_api-ms-win-gaming-tcui-l1-1-4.py +40 -0
  683. angr/procedures/definitions/win32_api-ms-win-mm-misc-l1-1-1.py +26 -0
  684. angr/procedures/definitions/win32_api-ms-win-net-isolation-l1-1-0.py +40 -0
  685. angr/procedures/definitions/win32_api-ms-win-security-base-l1-2-2.py +26 -0
  686. angr/procedures/definitions/win32_api-ms-win-security-isolatedcontainer-l1-1-0.py +26 -0
  687. angr/procedures/definitions/win32_api-ms-win-security-isolatedcontainer-l1-1-1.py +26 -0
  688. angr/procedures/definitions/win32_api-ms-win-service-core-l1-1-3.py +26 -0
  689. angr/procedures/definitions/win32_api-ms-win-service-core-l1-1-4.py +26 -0
  690. angr/procedures/definitions/win32_api-ms-win-service-core-l1-1-5.py +28 -0
  691. angr/procedures/definitions/win32_api-ms-win-shcore-scaling-l1-1-0.py +30 -0
  692. angr/procedures/definitions/win32_api-ms-win-shcore-scaling-l1-1-1.py +36 -0
  693. angr/procedures/definitions/win32_api-ms-win-shcore-scaling-l1-1-2.py +26 -0
  694. angr/procedures/definitions/win32_api-ms-win-shcore-stream-winrt-l1-1-0.py +28 -0
  695. angr/procedures/definitions/win32_api-ms-win-wsl-api-l1-1-0.py +38 -0
  696. angr/procedures/definitions/win32_apphelp.py +26 -0
  697. angr/procedures/definitions/win32_authz.py +90 -0
  698. angr/procedures/definitions/win32_avicap32.py +32 -0
  699. angr/procedures/definitions/win32_avifil32.py +144 -0
  700. angr/procedures/definitions/win32_avrt.py +52 -0
  701. angr/procedures/definitions/win32_bcp47mrm.py +28 -0
  702. angr/procedures/definitions/win32_bcrypt.py +130 -0
  703. angr/procedures/definitions/win32_bcryptprimitives.py +28 -0
  704. angr/procedures/definitions/win32_bluetoothapis.py +106 -0
  705. angr/procedures/definitions/win32_bthprops.py +34 -0
  706. angr/procedures/definitions/win32_bthprops_cpl.py +36 -0
  707. angr/procedures/definitions/win32_cabinet.py +68 -0
  708. angr/procedures/definitions/win32_certadm.py +60 -0
  709. angr/procedures/definitions/win32_certpoleng.py +40 -0
  710. angr/procedures/definitions/win32_cfgmgr32.py +502 -0
  711. angr/procedures/definitions/win32_chakra.py +198 -0
  712. angr/procedures/definitions/win32_cldapi.py +96 -0
  713. angr/procedures/definitions/win32_clfsw32.py +142 -0
  714. angr/procedures/definitions/win32_clusapi.py +584 -0
  715. angr/procedures/definitions/win32_comctl32.py +254 -0
  716. angr/procedures/definitions/win32_comdlg32.py +66 -0
  717. angr/procedures/definitions/win32_compstui.py +32 -0
  718. angr/procedures/definitions/win32_computecore.py +132 -0
  719. angr/procedures/definitions/win32_computenetwork.py +110 -0
  720. angr/procedures/definitions/win32_computestorage.py +48 -0
  721. angr/procedures/definitions/win32_comsvcs.py +38 -0
  722. angr/procedures/definitions/win32_coremessaging.py +24 -0
  723. angr/procedures/definitions/win32_credui.py +62 -0
  724. angr/procedures/definitions/win32_crypt32.py +482 -0
  725. angr/procedures/definitions/win32_cryptnet.py +34 -0
  726. angr/procedures/definitions/win32_cryptui.py +44 -0
  727. angr/procedures/definitions/win32_cryptxml.py +62 -0
  728. angr/procedures/definitions/win32_cscapi.py +32 -0
  729. angr/procedures/definitions/win32_d2d1.py +50 -0
  730. angr/procedures/definitions/win32_d3d10.py +78 -0
  731. angr/procedures/definitions/win32_d3d10_1.py +28 -0
  732. angr/procedures/definitions/win32_d3d11.py +30 -0
  733. angr/procedures/definitions/win32_d3d12.py +40 -0
  734. angr/procedures/definitions/win32_d3d9.py +46 -0
  735. angr/procedures/definitions/win32_d3dcompiler_47.py +76 -0
  736. angr/procedures/definitions/win32_d3dcsx.py +42 -0
  737. angr/procedures/definitions/win32_davclnt.py +60 -0
  738. angr/procedures/definitions/win32_dbgeng.py +32 -0
  739. angr/procedures/definitions/win32_dbghelp.py +462 -0
  740. angr/procedures/definitions/win32_dbgmodel.py +26 -0
  741. angr/procedures/definitions/win32_dciman32.py +64 -0
  742. angr/procedures/definitions/win32_dcomp.py +48 -0
  743. angr/procedures/definitions/win32_ddraw.py +38 -0
  744. angr/procedures/definitions/win32_deviceaccess.py +26 -0
  745. angr/procedures/definitions/win32_dflayout.py +26 -0
  746. angr/procedures/definitions/win32_dhcpcsvc.py +54 -0
  747. angr/procedures/definitions/win32_dhcpcsvc6.py +36 -0
  748. angr/procedures/definitions/win32_dhcpsapi.py +416 -0
  749. angr/procedures/definitions/win32_diagnosticdataquery.py +94 -0
  750. angr/procedures/definitions/win32_dinput8.py +26 -0
  751. angr/procedures/definitions/win32_directml.py +28 -0
  752. angr/procedures/definitions/win32_dmprocessxmlfiltered.py +26 -0
  753. angr/procedures/definitions/win32_dnsapi.py +152 -0
  754. angr/procedures/definitions/win32_drt.py +56 -0
  755. angr/procedures/definitions/win32_drtprov.py +42 -0
  756. angr/procedures/definitions/win32_drttransport.py +28 -0
  757. angr/procedures/definitions/win32_dsound.py +44 -0
  758. angr/procedures/definitions/win32_dsparse.py +62 -0
  759. angr/procedures/definitions/win32_dsprop.py +38 -0
  760. angr/procedures/definitions/win32_dssec.py +32 -0
  761. angr/procedures/definitions/win32_dsuiext.py +32 -0
  762. angr/procedures/definitions/win32_dwmapi.py +86 -0
  763. angr/procedures/definitions/win32_dwrite.py +26 -0
  764. angr/procedures/definitions/win32_dxcompiler.py +28 -0
  765. angr/procedures/definitions/win32_dxcore.py +26 -0
  766. angr/procedures/definitions/win32_dxgi.py +36 -0
  767. angr/procedures/definitions/win32_dxva2.py +100 -0
  768. angr/procedures/definitions/win32_eappcfg.py +52 -0
  769. angr/procedures/definitions/win32_eappprxy.py +60 -0
  770. angr/procedures/definitions/win32_efswrt.py +28 -0
  771. angr/procedures/definitions/win32_elscore.py +34 -0
  772. angr/procedures/definitions/win32_esent.py +482 -0
  773. angr/procedures/definitions/win32_evr.py +38 -0
  774. angr/procedures/definitions/win32_faultrep.py +32 -0
  775. angr/procedures/definitions/win32_fhsvcctl.py +38 -0
  776. angr/procedures/definitions/win32_firewallapi.py +30 -0
  777. angr/procedures/definitions/win32_fltlib.py +80 -0
  778. angr/procedures/definitions/win32_fontsub.py +28 -0
  779. angr/procedures/definitions/win32_forceinline.py +30 -0
  780. angr/procedures/definitions/win32_fwpuclnt.py +408 -0
  781. angr/procedures/definitions/win32_fxsutility.py +28 -0
  782. angr/procedures/definitions/win32_gdi32.py +886 -0
  783. angr/procedures/definitions/win32_gdiplus.py +1282 -0
  784. angr/procedures/definitions/win32_glu32.py +128 -0
  785. angr/procedures/definitions/win32_gpedit.py +36 -0
  786. angr/procedures/definitions/win32_hhctrl_ocx.py +28 -0
  787. angr/procedures/definitions/win32_hid.py +114 -0
  788. angr/procedures/definitions/win32_hlink.py +80 -0
  789. angr/procedures/definitions/win32_hrtfapo.py +26 -0
  790. angr/procedures/definitions/win32_httpapi.py +110 -0
  791. angr/procedures/definitions/win32_icm32.py +66 -0
  792. angr/procedures/definitions/win32_icmui.py +28 -0
  793. angr/procedures/definitions/win32_icu.py +2074 -0
  794. angr/procedures/definitions/win32_ieframe.py +82 -0
  795. angr/procedures/definitions/win32_imagehlp.py +76 -0
  796. angr/procedures/definitions/win32_imgutil.py +42 -0
  797. angr/procedures/definitions/win32_imm32.py +188 -0
  798. angr/procedures/definitions/win32_infocardapi.py +58 -0
  799. angr/procedures/definitions/win32_inkobjcore.py +78 -0
  800. angr/procedures/definitions/win32_iphlpapi.py +426 -0
  801. angr/procedures/definitions/win32_iscsidsc.py +182 -0
  802. angr/procedures/definitions/win32_isolatedwindowsenvironmentutils.py +28 -0
  803. angr/procedures/definitions/win32_kernel32.py +3185 -0
  804. angr/procedures/definitions/win32_kernelbase.py +36 -0
  805. angr/procedures/definitions/win32_keycredmgr.py +32 -0
  806. angr/procedures/definitions/win32_ksproxy_ax.py +36 -0
  807. angr/procedures/definitions/win32_ksuser.py +40 -0
  808. angr/procedures/definitions/win32_ktmw32.py +102 -0
  809. angr/procedures/definitions/win32_licenseprotection.py +28 -0
  810. angr/procedures/definitions/win32_loadperf.py +48 -0
  811. angr/procedures/definitions/win32_magnification.py +62 -0
  812. angr/procedures/definitions/win32_mapi32.py +156 -0
  813. angr/procedures/definitions/win32_mdmlocalmanagement.py +30 -0
  814. angr/procedures/definitions/win32_mdmregistration.py +54 -0
  815. angr/procedures/definitions/win32_mf.py +148 -0
  816. angr/procedures/definitions/win32_mfcore.py +28 -0
  817. angr/procedures/definitions/win32_mfplat.py +314 -0
  818. angr/procedures/definitions/win32_mfplay.py +26 -0
  819. angr/procedures/definitions/win32_mfreadwrite.py +34 -0
  820. angr/procedures/definitions/win32_mfsensorgroup.py +44 -0
  821. angr/procedures/definitions/win32_mfsrcsnk.py +28 -0
  822. angr/procedures/definitions/win32_mgmtapi.py +42 -0
  823. angr/procedures/definitions/win32_mi.py +26 -0
  824. angr/procedures/definitions/win32_mmdevapi.py +26 -0
  825. angr/procedures/definitions/win32_mpr.py +118 -0
  826. angr/procedures/definitions/win32_mprapi.py +248 -0
  827. angr/procedures/definitions/win32_mqrt.py +92 -0
  828. angr/procedures/definitions/win32_mrmsupport.py +78 -0
  829. angr/procedures/definitions/win32_msacm32.py +108 -0
  830. angr/procedures/definitions/win32_msajapi.py +1118 -0
  831. angr/procedures/definitions/win32_mscms.py +182 -0
  832. angr/procedures/definitions/win32_mscoree.py +78 -0
  833. angr/procedures/definitions/win32_msctfmonitor.py +30 -0
  834. angr/procedures/definitions/win32_msdelta.py +56 -0
  835. angr/procedures/definitions/win32_msdmo.py +46 -0
  836. angr/procedures/definitions/win32_msdrm.py +192 -0
  837. angr/procedures/definitions/win32_msi.py +552 -0
  838. angr/procedures/definitions/win32_msimg32.py +30 -0
  839. angr/procedures/definitions/win32_mspatcha.py +56 -0
  840. angr/procedures/definitions/win32_mspatchc.py +42 -0
  841. angr/procedures/definitions/win32_msports.py +38 -0
  842. angr/procedures/definitions/win32_msrating.py +62 -0
  843. angr/procedures/definitions/win32_mssign32.py +44 -0
  844. angr/procedures/definitions/win32_mstask.py +28 -0
  845. angr/procedures/definitions/win32_msvfw32.py +110 -0
  846. angr/procedures/definitions/win32_mswsock.py +56 -0
  847. angr/procedures/definitions/win32_mtxdm.py +26 -0
  848. angr/procedures/definitions/win32_ncrypt.py +102 -0
  849. angr/procedures/definitions/win32_ndfapi.py +56 -0
  850. angr/procedures/definitions/win32_netapi32.py +436 -0
  851. angr/procedures/definitions/win32_netsh.py +40 -0
  852. angr/procedures/definitions/win32_netshell.py +28 -0
  853. angr/procedures/definitions/win32_newdev.py +46 -0
  854. angr/procedures/definitions/win32_ninput.py +84 -0
  855. angr/procedures/definitions/win32_normaliz.py +28 -0
  856. angr/procedures/definitions/win32_ntdll.py +171 -0
  857. angr/procedures/definitions/win32_ntdllk.py +26 -0
  858. angr/procedures/definitions/win32_ntdsapi.py +186 -0
  859. angr/procedures/definitions/win32_ntlanman.py +44 -0
  860. angr/procedures/definitions/win32_odbc32.py +392 -0
  861. angr/procedures/definitions/win32_odbcbcp.py +78 -0
  862. angr/procedures/definitions/win32_ole32.py +658 -0
  863. angr/procedures/definitions/win32_oleacc.py +58 -0
  864. angr/procedures/definitions/win32_oleaut32.py +834 -0
  865. angr/procedures/definitions/win32_oledlg.py +70 -0
  866. angr/procedures/definitions/win32_ondemandconnroutehelper.py +34 -0
  867. angr/procedures/definitions/win32_opengl32.py +734 -0
  868. angr/procedures/definitions/win32_opmxbox.py +30 -0
  869. angr/procedures/definitions/win32_p2p.py +240 -0
  870. angr/procedures/definitions/win32_p2pgraph.py +98 -0
  871. angr/procedures/definitions/win32_pdh.py +220 -0
  872. angr/procedures/definitions/win32_peerdist.py +80 -0
  873. angr/procedures/definitions/win32_powrprof.py +192 -0
  874. angr/procedures/definitions/win32_prntvpt.py +46 -0
  875. angr/procedures/definitions/win32_projectedfslib.py +62 -0
  876. angr/procedures/definitions/win32_propsys.py +460 -0
  877. angr/procedures/definitions/win32_psapi.py +78 -0
  878. angr/procedures/definitions/win32_quartz.py +28 -0
  879. angr/procedures/definitions/win32_query.py +32 -0
  880. angr/procedures/definitions/win32_qwave.py +46 -0
  881. angr/procedures/definitions/win32_rasapi32.py +192 -0
  882. angr/procedures/definitions/win32_rasdlg.py +36 -0
  883. angr/procedures/definitions/win32_resutils.py +264 -0
  884. angr/procedures/definitions/win32_rometadata.py +24 -0
  885. angr/procedures/definitions/win32_rpcns4.py +146 -0
  886. angr/procedures/definitions/win32_rpcproxy.py +32 -0
  887. angr/procedures/definitions/win32_rpcrt4.py +918 -0
  888. angr/procedures/definitions/win32_rstrtmgr.py +46 -0
  889. angr/procedures/definitions/win32_rtm.py +176 -0
  890. angr/procedures/definitions/win32_rtutils.py +106 -0
  891. angr/procedures/definitions/win32_rtworkq.py +90 -0
  892. angr/procedures/definitions/win32_sas.py +26 -0
  893. angr/procedures/definitions/win32_scarddlg.py +34 -0
  894. angr/procedures/definitions/win32_schannel.py +42 -0
  895. angr/procedures/definitions/win32_sechost.py +28 -0
  896. angr/procedures/definitions/win32_secur32.py +202 -0
  897. angr/procedures/definitions/win32_sensapi.py +30 -0
  898. angr/procedures/definitions/win32_sensorsutilsv2.py +104 -0
  899. angr/procedures/definitions/win32_setupapi.py +692 -0
  900. angr/procedures/definitions/win32_sfc.py +36 -0
  901. angr/procedures/definitions/win32_shdocvw.py +30 -0
  902. angr/procedures/definitions/win32_shell32.py +512 -0
  903. angr/procedures/definitions/win32_shlwapi.py +744 -0
  904. angr/procedures/definitions/win32_slc.py +88 -0
  905. angr/procedures/definitions/win32_slcext.py +32 -0
  906. angr/procedures/definitions/win32_slwga.py +26 -0
  907. angr/procedures/definitions/win32_snmpapi.py +76 -0
  908. angr/procedures/definitions/win32_spoolss.py +76 -0
  909. angr/procedures/definitions/win32_srclient.py +26 -0
  910. angr/procedures/definitions/win32_srpapi.py +46 -0
  911. angr/procedures/definitions/win32_sspicli.py +38 -0
  912. angr/procedures/definitions/win32_sti.py +26 -0
  913. angr/procedures/definitions/win32_t2embed.py +52 -0
  914. angr/procedures/definitions/win32_tapi32.py +522 -0
  915. angr/procedures/definitions/win32_tbs.py +52 -0
  916. angr/procedures/definitions/win32_tdh.py +78 -0
  917. angr/procedures/definitions/win32_tokenbinding.py +44 -0
  918. angr/procedures/definitions/win32_traffic.py +64 -0
  919. angr/procedures/definitions/win32_txfw32.py +42 -0
  920. angr/procedures/definitions/win32_ualapi.py +32 -0
  921. angr/procedures/definitions/win32_uiautomationcore.py +220 -0
  922. angr/procedures/definitions/win32_urlmon.py +178 -0
  923. angr/procedures/definitions/win32_user32.py +1551 -0
  924. angr/procedures/definitions/win32_userenv.py +112 -0
  925. angr/procedures/definitions/win32_usp10.py +104 -0
  926. angr/procedures/definitions/win32_uxtheme.py +178 -0
  927. angr/procedures/definitions/win32_verifier.py +26 -0
  928. angr/procedures/definitions/win32_version.py +52 -0
  929. angr/procedures/definitions/win32_vertdll.py +38 -0
  930. angr/procedures/definitions/win32_virtdisk.py +82 -0
  931. angr/procedures/definitions/win32_vmdevicehost.py +50 -0
  932. angr/procedures/definitions/win32_vmsavedstatedumpprovider.py +110 -0
  933. angr/procedures/definitions/win32_vssapi.py +26 -0
  934. angr/procedures/definitions/win32_wcmapi.py +34 -0
  935. angr/procedures/definitions/win32_wdsbp.py +38 -0
  936. angr/procedures/definitions/win32_wdsclientapi.py +98 -0
  937. angr/procedures/definitions/win32_wdsmc.py +36 -0
  938. angr/procedures/definitions/win32_wdspxe.py +86 -0
  939. angr/procedures/definitions/win32_wdstptc.py +50 -0
  940. angr/procedures/definitions/win32_webauthn.py +50 -0
  941. angr/procedures/definitions/win32_webservices.py +410 -0
  942. angr/procedures/definitions/win32_websocket.py +50 -0
  943. angr/procedures/definitions/win32_wecapi.py +54 -0
  944. angr/procedures/definitions/win32_wer.py +66 -0
  945. angr/procedures/definitions/win32_wevtapi.py +94 -0
  946. angr/procedures/definitions/win32_winbio.py +132 -0
  947. angr/procedures/definitions/win32_windows_ai_machinelearning.py +26 -0
  948. angr/procedures/definitions/win32_windows_data_pdf.py +24 -0
  949. angr/procedures/definitions/win32_windows_media_mediacontrol.py +40 -0
  950. angr/procedures/definitions/win32_windows_networking.py +26 -0
  951. angr/procedures/definitions/win32_windows_ui_xaml.py +28 -0
  952. angr/procedures/definitions/win32_windowscodecs.py +42 -0
  953. angr/procedures/definitions/win32_winfax.py +136 -0
  954. angr/procedures/definitions/win32_winhttp.py +136 -0
  955. angr/procedures/definitions/win32_winhvemulation.py +32 -0
  956. angr/procedures/definitions/win32_winhvplatform.py +156 -0
  957. angr/procedures/definitions/win32_wininet.py +616 -0
  958. angr/procedures/definitions/win32_winml.py +26 -0
  959. angr/procedures/definitions/win32_winmm.py +376 -0
  960. angr/procedures/definitions/win32_winscard.py +164 -0
  961. angr/procedures/definitions/win32_winspool.py +364 -0
  962. angr/procedures/definitions/win32_winspool_drv.py +368 -0
  963. angr/procedures/definitions/win32_wintrust.py +144 -0
  964. angr/procedures/definitions/win32_winusb.py +92 -0
  965. angr/procedures/definitions/win32_wlanapi.py +144 -0
  966. angr/procedures/definitions/win32_wlanui.py +26 -0
  967. angr/procedures/definitions/win32_wldap32.py +510 -0
  968. angr/procedures/definitions/win32_wldp.py +42 -0
  969. angr/procedures/definitions/win32_wmvcore.py +46 -0
  970. angr/procedures/definitions/win32_wnvapi.py +28 -0
  971. angr/procedures/definitions/win32_wofutil.py +46 -0
  972. angr/procedures/definitions/win32_ws2_32.py +344 -0
  973. angr/procedures/definitions/win32_wscapi.py +36 -0
  974. angr/procedures/definitions/win32_wsclient.py +30 -0
  975. angr/procedures/definitions/win32_wsdapi.py +88 -0
  976. angr/procedures/definitions/win32_wsmsvc.py +90 -0
  977. angr/procedures/definitions/win32_wsnmp32.py +122 -0
  978. angr/procedures/definitions/win32_wtsapi32.py +150 -0
  979. angr/procedures/definitions/win32_xaudio2_8.py +32 -0
  980. angr/procedures/definitions/win32_xinput1_4.py +38 -0
  981. angr/procedures/definitions/win32_xinputuap.py +36 -0
  982. angr/procedures/definitions/win32_xmllite.py +36 -0
  983. angr/procedures/definitions/win32_xolehlp.py +32 -0
  984. angr/procedures/definitions/win32_xpsprint.py +28 -0
  985. angr/procedures/glibc/__ctype_b_loc.py +21 -0
  986. angr/procedures/glibc/__ctype_tolower_loc.py +21 -0
  987. angr/procedures/glibc/__ctype_toupper_loc.py +21 -0
  988. angr/procedures/glibc/__errno_location.py +7 -0
  989. angr/procedures/glibc/__init__.py +3 -0
  990. angr/procedures/glibc/__libc_init.py +37 -0
  991. angr/procedures/glibc/__libc_start_main.py +301 -0
  992. angr/procedures/glibc/dynamic_loading.py +20 -0
  993. angr/procedures/glibc/scanf.py +11 -0
  994. angr/procedures/glibc/sscanf.py +6 -0
  995. angr/procedures/gnulib/__init__.py +3 -0
  996. angr/procedures/gnulib/xalloc_die.py +14 -0
  997. angr/procedures/gnulib/xstrtol_fatal.py +14 -0
  998. angr/procedures/java/__init__.py +42 -0
  999. angr/procedures/java/unconstrained.py +65 -0
  1000. angr/procedures/java_io/__init__.py +0 -0
  1001. angr/procedures/java_io/read.py +12 -0
  1002. angr/procedures/java_io/write.py +17 -0
  1003. angr/procedures/java_jni/__init__.py +482 -0
  1004. angr/procedures/java_jni/array_operations.py +312 -0
  1005. angr/procedures/java_jni/class_and_interface_operations.py +31 -0
  1006. angr/procedures/java_jni/field_access.py +173 -0
  1007. angr/procedures/java_jni/global_and_local_refs.py +57 -0
  1008. angr/procedures/java_jni/method_calls.py +365 -0
  1009. angr/procedures/java_jni/not_implemented.py +26 -0
  1010. angr/procedures/java_jni/object_operations.py +94 -0
  1011. angr/procedures/java_jni/string_operations.py +87 -0
  1012. angr/procedures/java_jni/version_information.py +12 -0
  1013. angr/procedures/java_lang/__init__.py +0 -0
  1014. angr/procedures/java_lang/character.py +30 -0
  1015. angr/procedures/java_lang/double.py +24 -0
  1016. angr/procedures/java_lang/exit.py +13 -0
  1017. angr/procedures/java_lang/getsimplename.py +18 -0
  1018. angr/procedures/java_lang/integer.py +43 -0
  1019. angr/procedures/java_lang/load_library.py +9 -0
  1020. angr/procedures/java_lang/math.py +15 -0
  1021. angr/procedures/java_lang/string.py +78 -0
  1022. angr/procedures/java_lang/stringbuilder.py +44 -0
  1023. angr/procedures/java_lang/system.py +18 -0
  1024. angr/procedures/java_util/__init__.py +0 -0
  1025. angr/procedures/java_util/collection.py +35 -0
  1026. angr/procedures/java_util/iterator.py +46 -0
  1027. angr/procedures/java_util/list.py +99 -0
  1028. angr/procedures/java_util/map.py +131 -0
  1029. angr/procedures/java_util/random.py +14 -0
  1030. angr/procedures/java_util/scanner_nextline.py +23 -0
  1031. angr/procedures/libc/__init__.py +3 -0
  1032. angr/procedures/libc/abort.py +9 -0
  1033. angr/procedures/libc/access.py +13 -0
  1034. angr/procedures/libc/atoi.py +14 -0
  1035. angr/procedures/libc/atol.py +13 -0
  1036. angr/procedures/libc/calloc.py +8 -0
  1037. angr/procedures/libc/closelog.py +10 -0
  1038. angr/procedures/libc/err.py +14 -0
  1039. angr/procedures/libc/error.py +54 -0
  1040. angr/procedures/libc/exit.py +11 -0
  1041. angr/procedures/libc/fclose.py +19 -0
  1042. angr/procedures/libc/feof.py +21 -0
  1043. angr/procedures/libc/fflush.py +16 -0
  1044. angr/procedures/libc/fgetc.py +27 -0
  1045. angr/procedures/libc/fgets.py +68 -0
  1046. angr/procedures/libc/fopen.py +63 -0
  1047. angr/procedures/libc/fprintf.py +25 -0
  1048. angr/procedures/libc/fputc.py +23 -0
  1049. angr/procedures/libc/fputs.py +24 -0
  1050. angr/procedures/libc/fread.py +24 -0
  1051. angr/procedures/libc/free.py +9 -0
  1052. angr/procedures/libc/fscanf.py +20 -0
  1053. angr/procedures/libc/fseek.py +34 -0
  1054. angr/procedures/libc/ftell.py +22 -0
  1055. angr/procedures/libc/fwrite.py +19 -0
  1056. angr/procedures/libc/getchar.py +13 -0
  1057. angr/procedures/libc/getdelim.py +99 -0
  1058. angr/procedures/libc/getegid.py +8 -0
  1059. angr/procedures/libc/geteuid.py +8 -0
  1060. angr/procedures/libc/getgid.py +8 -0
  1061. angr/procedures/libc/gets.py +68 -0
  1062. angr/procedures/libc/getuid.py +8 -0
  1063. angr/procedures/libc/malloc.py +12 -0
  1064. angr/procedures/libc/memcmp.py +69 -0
  1065. angr/procedures/libc/memcpy.py +38 -0
  1066. angr/procedures/libc/memset.py +72 -0
  1067. angr/procedures/libc/openlog.py +10 -0
  1068. angr/procedures/libc/perror.py +13 -0
  1069. angr/procedures/libc/printf.py +34 -0
  1070. angr/procedures/libc/putchar.py +13 -0
  1071. angr/procedures/libc/puts.py +19 -0
  1072. angr/procedures/libc/rand.py +8 -0
  1073. angr/procedures/libc/realloc.py +8 -0
  1074. angr/procedures/libc/rewind.py +12 -0
  1075. angr/procedures/libc/scanf.py +20 -0
  1076. angr/procedures/libc/setbuf.py +9 -0
  1077. angr/procedures/libc/setvbuf.py +7 -0
  1078. angr/procedures/libc/snprintf.py +36 -0
  1079. angr/procedures/libc/sprintf.py +25 -0
  1080. angr/procedures/libc/srand.py +7 -0
  1081. angr/procedures/libc/sscanf.py +13 -0
  1082. angr/procedures/libc/stpcpy.py +18 -0
  1083. angr/procedures/libc/strcat.py +14 -0
  1084. angr/procedures/libc/strchr.py +48 -0
  1085. angr/procedures/libc/strcmp.py +31 -0
  1086. angr/procedures/libc/strcpy.py +13 -0
  1087. angr/procedures/libc/strlen.py +114 -0
  1088. angr/procedures/libc/strncat.py +19 -0
  1089. angr/procedures/libc/strncmp.py +183 -0
  1090. angr/procedures/libc/strncpy.py +22 -0
  1091. angr/procedures/libc/strnlen.py +13 -0
  1092. angr/procedures/libc/strstr.py +101 -0
  1093. angr/procedures/libc/strtol.py +261 -0
  1094. angr/procedures/libc/strtoul.py +9 -0
  1095. angr/procedures/libc/system.py +13 -0
  1096. angr/procedures/libc/time.py +9 -0
  1097. angr/procedures/libc/tmpnam.py +20 -0
  1098. angr/procedures/libc/tolower.py +10 -0
  1099. angr/procedures/libc/toupper.py +10 -0
  1100. angr/procedures/libc/ungetc.py +20 -0
  1101. angr/procedures/libc/vsnprintf.py +17 -0
  1102. angr/procedures/libc/wchar.py +16 -0
  1103. angr/procedures/libstdcpp/__init__.py +0 -0
  1104. angr/procedures/libstdcpp/_unwind_resume.py +11 -0
  1105. angr/procedures/libstdcpp/std____throw_bad_alloc.py +13 -0
  1106. angr/procedures/libstdcpp/std____throw_bad_cast.py +13 -0
  1107. angr/procedures/libstdcpp/std____throw_length_error.py +13 -0
  1108. angr/procedures/libstdcpp/std____throw_logic_error.py +13 -0
  1109. angr/procedures/libstdcpp/std__terminate.py +13 -0
  1110. angr/procedures/linux_kernel/__init__.py +3 -0
  1111. angr/procedures/linux_kernel/access.py +18 -0
  1112. angr/procedures/linux_kernel/arch_prctl.py +34 -0
  1113. angr/procedures/linux_kernel/arm_user_helpers.py +59 -0
  1114. angr/procedures/linux_kernel/brk.py +18 -0
  1115. angr/procedures/linux_kernel/cwd.py +28 -0
  1116. angr/procedures/linux_kernel/fstat.py +138 -0
  1117. angr/procedures/linux_kernel/fstat64.py +170 -0
  1118. angr/procedures/linux_kernel/futex.py +17 -0
  1119. angr/procedures/linux_kernel/getegid.py +17 -0
  1120. angr/procedures/linux_kernel/geteuid.py +17 -0
  1121. angr/procedures/linux_kernel/getgid.py +17 -0
  1122. angr/procedures/linux_kernel/getpid.py +14 -0
  1123. angr/procedures/linux_kernel/getrlimit.py +24 -0
  1124. angr/procedures/linux_kernel/gettid.py +9 -0
  1125. angr/procedures/linux_kernel/getuid.py +17 -0
  1126. angr/procedures/linux_kernel/iovec.py +47 -0
  1127. angr/procedures/linux_kernel/lseek.py +42 -0
  1128. angr/procedures/linux_kernel/mmap.py +16 -0
  1129. angr/procedures/linux_kernel/mprotect.py +42 -0
  1130. angr/procedures/linux_kernel/munmap.py +8 -0
  1131. angr/procedures/linux_kernel/openat.py +26 -0
  1132. angr/procedures/linux_kernel/set_tid_address.py +8 -0
  1133. angr/procedures/linux_kernel/sigaction.py +19 -0
  1134. angr/procedures/linux_kernel/sigprocmask.py +23 -0
  1135. angr/procedures/linux_kernel/stat.py +23 -0
  1136. angr/procedures/linux_kernel/sysinfo.py +59 -0
  1137. angr/procedures/linux_kernel/tgkill.py +10 -0
  1138. angr/procedures/linux_kernel/time.py +34 -0
  1139. angr/procedures/linux_kernel/uid.py +30 -0
  1140. angr/procedures/linux_kernel/uname.py +29 -0
  1141. angr/procedures/linux_kernel/unlink.py +22 -0
  1142. angr/procedures/linux_kernel/vsyscall.py +16 -0
  1143. angr/procedures/linux_loader/__init__.py +3 -0
  1144. angr/procedures/linux_loader/_dl_initial_error_catch_tsd.py +7 -0
  1145. angr/procedures/linux_loader/_dl_rtld_lock.py +15 -0
  1146. angr/procedures/linux_loader/sim_loader.py +54 -0
  1147. angr/procedures/linux_loader/tls.py +40 -0
  1148. angr/procedures/msvcr/__getmainargs.py +16 -0
  1149. angr/procedures/msvcr/__init__.py +4 -0
  1150. angr/procedures/msvcr/_initterm.py +38 -0
  1151. angr/procedures/msvcr/fmode.py +31 -0
  1152. angr/procedures/ntdll/__init__.py +0 -0
  1153. angr/procedures/ntdll/exceptions.py +60 -0
  1154. angr/procedures/posix/__init__.py +3 -0
  1155. angr/procedures/posix/accept.py +29 -0
  1156. angr/procedures/posix/bind.py +13 -0
  1157. angr/procedures/posix/bzero.py +9 -0
  1158. angr/procedures/posix/chroot.py +27 -0
  1159. angr/procedures/posix/close.py +9 -0
  1160. angr/procedures/posix/closedir.py +7 -0
  1161. angr/procedures/posix/dup.py +56 -0
  1162. angr/procedures/posix/fcntl.py +10 -0
  1163. angr/procedures/posix/fdopen.py +76 -0
  1164. angr/procedures/posix/fileno.py +18 -0
  1165. angr/procedures/posix/fork.py +13 -0
  1166. angr/procedures/posix/getenv.py +35 -0
  1167. angr/procedures/posix/gethostbyname.py +43 -0
  1168. angr/procedures/posix/getpass.py +19 -0
  1169. angr/procedures/posix/getsockopt.py +11 -0
  1170. angr/procedures/posix/htonl.py +11 -0
  1171. angr/procedures/posix/htons.py +11 -0
  1172. angr/procedures/posix/inet_ntoa.py +59 -0
  1173. angr/procedures/posix/listen.py +13 -0
  1174. angr/procedures/posix/mmap.py +144 -0
  1175. angr/procedures/posix/open.py +18 -0
  1176. angr/procedures/posix/opendir.py +10 -0
  1177. angr/procedures/posix/poll.py +55 -0
  1178. angr/procedures/posix/pread64.py +46 -0
  1179. angr/procedures/posix/pthread.py +87 -0
  1180. angr/procedures/posix/pwrite64.py +46 -0
  1181. angr/procedures/posix/read.py +13 -0
  1182. angr/procedures/posix/readdir.py +62 -0
  1183. angr/procedures/posix/recv.py +13 -0
  1184. angr/procedures/posix/recvfrom.py +13 -0
  1185. angr/procedures/posix/select.py +48 -0
  1186. angr/procedures/posix/send.py +23 -0
  1187. angr/procedures/posix/setsockopt.py +9 -0
  1188. angr/procedures/posix/sigaction.py +23 -0
  1189. angr/procedures/posix/sim_time.py +48 -0
  1190. angr/procedures/posix/sleep.py +8 -0
  1191. angr/procedures/posix/socket.py +18 -0
  1192. angr/procedures/posix/strcasecmp.py +26 -0
  1193. angr/procedures/posix/strdup.py +18 -0
  1194. angr/procedures/posix/strtok_r.py +64 -0
  1195. angr/procedures/posix/syslog.py +15 -0
  1196. angr/procedures/posix/tz.py +9 -0
  1197. angr/procedures/posix/unlink.py +11 -0
  1198. angr/procedures/posix/usleep.py +8 -0
  1199. angr/procedures/posix/write.py +13 -0
  1200. angr/procedures/procedure_dict.py +50 -0
  1201. angr/procedures/stubs/CallReturn.py +13 -0
  1202. angr/procedures/stubs/NoReturnUnconstrained.py +13 -0
  1203. angr/procedures/stubs/Nop.py +7 -0
  1204. angr/procedures/stubs/PathTerminator.py +9 -0
  1205. angr/procedures/stubs/Redirect.py +18 -0
  1206. angr/procedures/stubs/ReturnChar.py +11 -0
  1207. angr/procedures/stubs/ReturnUnconstrained.py +24 -0
  1208. angr/procedures/stubs/UnresolvableCallTarget.py +9 -0
  1209. angr/procedures/stubs/UnresolvableJumpTarget.py +9 -0
  1210. angr/procedures/stubs/UserHook.py +18 -0
  1211. angr/procedures/stubs/__init__.py +3 -0
  1212. angr/procedures/stubs/b64_decode.py +15 -0
  1213. angr/procedures/stubs/caller.py +14 -0
  1214. angr/procedures/stubs/crazy_scanf.py +20 -0
  1215. angr/procedures/stubs/format_parser.py +669 -0
  1216. angr/procedures/stubs/syscall_stub.py +24 -0
  1217. angr/procedures/testing/__init__.py +3 -0
  1218. angr/procedures/testing/manyargs.py +9 -0
  1219. angr/procedures/testing/retreg.py +8 -0
  1220. angr/procedures/tracer/__init__.py +4 -0
  1221. angr/procedures/tracer/random.py +9 -0
  1222. angr/procedures/tracer/receive.py +23 -0
  1223. angr/procedures/tracer/transmit.py +26 -0
  1224. angr/procedures/uclibc/__init__.py +3 -0
  1225. angr/procedures/uclibc/__uClibc_main.py +10 -0
  1226. angr/procedures/win32/EncodePointer.py +7 -0
  1227. angr/procedures/win32/ExitProcess.py +9 -0
  1228. angr/procedures/win32/GetCommandLine.py +12 -0
  1229. angr/procedures/win32/GetCurrentProcessId.py +7 -0
  1230. angr/procedures/win32/GetCurrentThreadId.py +7 -0
  1231. angr/procedures/win32/GetLastInputInfo.py +40 -0
  1232. angr/procedures/win32/GetModuleHandle.py +29 -0
  1233. angr/procedures/win32/GetProcessAffinityMask.py +37 -0
  1234. angr/procedures/win32/InterlockedExchange.py +15 -0
  1235. angr/procedures/win32/IsProcessorFeaturePresent.py +7 -0
  1236. angr/procedures/win32/VirtualAlloc.py +114 -0
  1237. angr/procedures/win32/VirtualProtect.py +60 -0
  1238. angr/procedures/win32/__init__.py +3 -0
  1239. angr/procedures/win32/critical_section.py +12 -0
  1240. angr/procedures/win32/dynamic_loading.py +104 -0
  1241. angr/procedures/win32/file_handles.py +47 -0
  1242. angr/procedures/win32/gethostbyname.py +12 -0
  1243. angr/procedures/win32/heap.py +45 -0
  1244. angr/procedures/win32/is_bad_ptr.py +26 -0
  1245. angr/procedures/win32/local_storage.py +88 -0
  1246. angr/procedures/win32/mutex.py +11 -0
  1247. angr/procedures/win32/sim_time.py +135 -0
  1248. angr/procedures/win32/system_paths.py +35 -0
  1249. angr/procedures/win32_kernel/ExAllocatePool.py +13 -0
  1250. angr/procedures/win32_kernel/ExFreePoolWithTag.py +8 -0
  1251. angr/procedures/win32_kernel/__fastfail.py +15 -0
  1252. angr/procedures/win32_kernel/__init__.py +3 -0
  1253. angr/procedures/win_user32/__init__.py +0 -0
  1254. angr/procedures/win_user32/chars.py +15 -0
  1255. angr/procedures/win_user32/keyboard.py +14 -0
  1256. angr/procedures/win_user32/messagebox.py +49 -0
  1257. angr/project.py +847 -0
  1258. angr/protos/__init__.py +19 -0
  1259. angr/protos/cfg_pb2.py +31 -0
  1260. angr/protos/function_pb2.py +27 -0
  1261. angr/protos/primitives_pb2.py +52 -0
  1262. angr/protos/variables_pb2.py +44 -0
  1263. angr/protos/xrefs_pb2.py +25 -0
  1264. angr/py.typed +1 -0
  1265. angr/rustylib.abi3.so +0 -0
  1266. angr/serializable.py +66 -0
  1267. angr/sim_manager.py +971 -0
  1268. angr/sim_options.py +438 -0
  1269. angr/sim_procedure.py +606 -0
  1270. angr/sim_state.py +901 -0
  1271. angr/sim_state_options.py +403 -0
  1272. angr/sim_type.py +3702 -0
  1273. angr/sim_variable.py +465 -0
  1274. angr/simos/__init__.py +47 -0
  1275. angr/simos/cgc.py +153 -0
  1276. angr/simos/javavm.py +458 -0
  1277. angr/simos/linux.py +509 -0
  1278. angr/simos/simos.py +444 -0
  1279. angr/simos/snimmuc_nxp.py +149 -0
  1280. angr/simos/userland.py +163 -0
  1281. angr/simos/windows.py +601 -0
  1282. angr/simos/xbox.py +32 -0
  1283. angr/slicer.py +352 -0
  1284. angr/state_hierarchy.py +262 -0
  1285. angr/state_plugins/__init__.py +84 -0
  1286. angr/state_plugins/callstack.py +398 -0
  1287. angr/state_plugins/cgc.py +155 -0
  1288. angr/state_plugins/debug_variables.py +192 -0
  1289. angr/state_plugins/filesystem.py +463 -0
  1290. angr/state_plugins/gdb.py +148 -0
  1291. angr/state_plugins/globals.py +65 -0
  1292. angr/state_plugins/heap/__init__.py +15 -0
  1293. angr/state_plugins/heap/heap_base.py +128 -0
  1294. angr/state_plugins/heap/heap_brk.py +136 -0
  1295. angr/state_plugins/heap/heap_freelist.py +213 -0
  1296. angr/state_plugins/heap/heap_libc.py +46 -0
  1297. angr/state_plugins/heap/heap_ptmalloc.py +620 -0
  1298. angr/state_plugins/heap/utils.py +22 -0
  1299. angr/state_plugins/history.py +564 -0
  1300. angr/state_plugins/inspect.py +375 -0
  1301. angr/state_plugins/javavm_classloader.py +134 -0
  1302. angr/state_plugins/jni_references.py +95 -0
  1303. angr/state_plugins/libc.py +1263 -0
  1304. angr/state_plugins/light_registers.py +168 -0
  1305. angr/state_plugins/log.py +84 -0
  1306. angr/state_plugins/loop_data.py +92 -0
  1307. angr/state_plugins/plugin.py +170 -0
  1308. angr/state_plugins/posix.py +703 -0
  1309. angr/state_plugins/preconstrainer.py +196 -0
  1310. angr/state_plugins/scratch.py +173 -0
  1311. angr/state_plugins/sim_action.py +326 -0
  1312. angr/state_plugins/sim_action_object.py +271 -0
  1313. angr/state_plugins/sim_event.py +59 -0
  1314. angr/state_plugins/solver.py +1127 -0
  1315. angr/state_plugins/symbolizer.py +291 -0
  1316. angr/state_plugins/trace_additions.py +738 -0
  1317. angr/state_plugins/uc_manager.py +94 -0
  1318. angr/state_plugins/unicorn_engine.py +1886 -0
  1319. angr/state_plugins/view.py +340 -0
  1320. angr/storage/__init__.py +15 -0
  1321. angr/storage/file.py +1210 -0
  1322. angr/storage/memory_mixins/__init__.py +317 -0
  1323. angr/storage/memory_mixins/actions_mixin.py +72 -0
  1324. angr/storage/memory_mixins/address_concretization_mixin.py +384 -0
  1325. angr/storage/memory_mixins/bvv_conversion_mixin.py +73 -0
  1326. angr/storage/memory_mixins/clouseau_mixin.py +137 -0
  1327. angr/storage/memory_mixins/conditional_store_mixin.py +25 -0
  1328. angr/storage/memory_mixins/convenient_mappings_mixin.py +256 -0
  1329. angr/storage/memory_mixins/default_filler_mixin.py +144 -0
  1330. angr/storage/memory_mixins/dirty_addrs_mixin.py +11 -0
  1331. angr/storage/memory_mixins/hex_dumper_mixin.py +82 -0
  1332. angr/storage/memory_mixins/javavm_memory_mixin.py +392 -0
  1333. angr/storage/memory_mixins/keyvalue_memory_mixin.py +42 -0
  1334. angr/storage/memory_mixins/label_merger_mixin.py +31 -0
  1335. angr/storage/memory_mixins/memory_mixin.py +174 -0
  1336. angr/storage/memory_mixins/multi_value_merger_mixin.py +79 -0
  1337. angr/storage/memory_mixins/name_resolution_mixin.py +67 -0
  1338. angr/storage/memory_mixins/paged_memory/__init__.py +0 -0
  1339. angr/storage/memory_mixins/paged_memory/page_backer_mixins.py +266 -0
  1340. angr/storage/memory_mixins/paged_memory/paged_memory_mixin.py +743 -0
  1341. angr/storage/memory_mixins/paged_memory/paged_memory_multivalue_mixin.py +65 -0
  1342. angr/storage/memory_mixins/paged_memory/pages/__init__.py +26 -0
  1343. angr/storage/memory_mixins/paged_memory/pages/base.py +31 -0
  1344. angr/storage/memory_mixins/paged_memory/pages/cooperation.py +341 -0
  1345. angr/storage/memory_mixins/paged_memory/pages/history_tracking_mixin.py +92 -0
  1346. angr/storage/memory_mixins/paged_memory/pages/ispo_mixin.py +55 -0
  1347. angr/storage/memory_mixins/paged_memory/pages/list_page.py +338 -0
  1348. angr/storage/memory_mixins/paged_memory/pages/multi_values.py +324 -0
  1349. angr/storage/memory_mixins/paged_memory/pages/mv_list_page.py +419 -0
  1350. angr/storage/memory_mixins/paged_memory/pages/permissions_mixin.py +36 -0
  1351. angr/storage/memory_mixins/paged_memory/pages/refcount_mixin.py +52 -0
  1352. angr/storage/memory_mixins/paged_memory/pages/ultra_page.py +503 -0
  1353. angr/storage/memory_mixins/paged_memory/privileged_mixin.py +36 -0
  1354. angr/storage/memory_mixins/paged_memory/stack_allocation_mixin.py +74 -0
  1355. angr/storage/memory_mixins/regioned_memory/__init__.py +17 -0
  1356. angr/storage/memory_mixins/regioned_memory/abstract_address_descriptor.py +36 -0
  1357. angr/storage/memory_mixins/regioned_memory/abstract_merger_mixin.py +31 -0
  1358. angr/storage/memory_mixins/regioned_memory/region_category_mixin.py +9 -0
  1359. angr/storage/memory_mixins/regioned_memory/region_data.py +246 -0
  1360. angr/storage/memory_mixins/regioned_memory/region_meta_mixin.py +241 -0
  1361. angr/storage/memory_mixins/regioned_memory/regioned_address_concretization_mixin.py +119 -0
  1362. angr/storage/memory_mixins/regioned_memory/regioned_memory_mixin.py +441 -0
  1363. angr/storage/memory_mixins/regioned_memory/static_find_mixin.py +69 -0
  1364. angr/storage/memory_mixins/simple_interface_mixin.py +71 -0
  1365. angr/storage/memory_mixins/simplification_mixin.py +15 -0
  1366. angr/storage/memory_mixins/size_resolution_mixin.py +143 -0
  1367. angr/storage/memory_mixins/slotted_memory.py +140 -0
  1368. angr/storage/memory_mixins/smart_find_mixin.py +161 -0
  1369. angr/storage/memory_mixins/symbolic_merger_mixin.py +16 -0
  1370. angr/storage/memory_mixins/top_merger_mixin.py +25 -0
  1371. angr/storage/memory_mixins/underconstrained_mixin.py +67 -0
  1372. angr/storage/memory_mixins/unwrapper_mixin.py +26 -0
  1373. angr/storage/memory_object.py +195 -0
  1374. angr/tablespecs.py +91 -0
  1375. angr/unicornlib.so +0 -0
  1376. angr/utils/__init__.py +46 -0
  1377. angr/utils/ail.py +70 -0
  1378. angr/utils/algo.py +34 -0
  1379. angr/utils/bits.py +46 -0
  1380. angr/utils/constants.py +9 -0
  1381. angr/utils/cowdict.py +63 -0
  1382. angr/utils/cpp.py +17 -0
  1383. angr/utils/doms.py +149 -0
  1384. angr/utils/dynamic_dictlist.py +89 -0
  1385. angr/utils/endness.py +18 -0
  1386. angr/utils/enums_conv.py +97 -0
  1387. angr/utils/env.py +12 -0
  1388. angr/utils/formatting.py +128 -0
  1389. angr/utils/funcid.py +159 -0
  1390. angr/utils/graph.py +933 -0
  1391. angr/utils/lazy_import.py +13 -0
  1392. angr/utils/library.py +212 -0
  1393. angr/utils/loader.py +55 -0
  1394. angr/utils/mp.py +66 -0
  1395. angr/utils/orderedset.py +74 -0
  1396. angr/utils/ssa/__init__.py +457 -0
  1397. angr/utils/ssa/tmp_uses_collector.py +23 -0
  1398. angr/utils/ssa/vvar_uses_collector.py +37 -0
  1399. angr/utils/tagged_interval_map.py +112 -0
  1400. angr/utils/timing.py +74 -0
  1401. angr/utils/types.py +151 -0
  1402. angr/utils/vex.py +11 -0
  1403. angr/vaults.py +367 -0
  1404. angr-9.2.165.dist-info/METADATA +110 -0
  1405. angr-9.2.165.dist-info/RECORD +1409 -0
  1406. angr-9.2.165.dist-info/WHEEL +6 -0
  1407. angr-9.2.165.dist-info/entry_points.txt +2 -0
  1408. angr-9.2.165.dist-info/licenses/LICENSE +27 -0
  1409. angr-9.2.165.dist-info/top_level.txt +1 -0
angr/sim_type.py ADDED
@@ -0,0 +1,3702 @@
1
+ # pylint:disable=abstract-method,line-too-long,missing-class-docstring,wrong-import-position,too-many-positional-arguments
2
+ from __future__ import annotations
3
+
4
+ import contextlib
5
+ import copy
6
+ import re
7
+ import logging
8
+ from collections import OrderedDict, defaultdict, ChainMap
9
+ from collections.abc import Iterable
10
+ from typing import Literal, Any, cast, overload
11
+
12
+ from archinfo import Endness, Arch
13
+ import claripy
14
+ import cxxheaderparser.simple
15
+ import cxxheaderparser.errors
16
+ import cxxheaderparser.types
17
+ import pycparser
18
+ from pycparser import c_ast
19
+
20
+ from angr.errors import AngrTypeError
21
+ from angr.sim_state import SimState
22
+
23
+ StoreType = int | claripy.ast.BV
24
+
25
+ l = logging.getLogger(name=__name__)
26
+
27
+ # pycparser hack to parse type expressions
28
+ errorlog = logging.getLogger(name=__name__ + ".yacc")
29
+ errorlog.setLevel(logging.ERROR)
30
+
31
+
32
+ class SimType:
33
+ """
34
+ SimType exists to track type information for SimProcedures.
35
+ """
36
+
37
+ _fields: tuple[str, ...] = ()
38
+ _arch: Arch | None
39
+ _size: int | None = None
40
+ _can_refine_int: bool = False
41
+ _base_name: str
42
+ base: bool = True
43
+
44
+ def __init__(self, label=None):
45
+ """
46
+ :param label: the type label.
47
+ """
48
+ self.label = label
49
+ self._arch = None
50
+
51
+ @staticmethod
52
+ def _simtype_eq(self_type: SimType, other: SimType, avoid: dict[str, set[SimType]] | None) -> bool:
53
+ if self_type is other:
54
+ return True
55
+ if avoid is not None and self_type in avoid["self"] and other in avoid["other"]:
56
+ return True
57
+ return self_type.__eq__(other, avoid=avoid) # pylint:disable=unnecessary-dunder-call
58
+
59
+ def __eq__(self, other, avoid=None):
60
+ if type(self) is not type(other):
61
+ return False
62
+
63
+ for attr in self._fields:
64
+ if attr == "size" and self._arch is None and other._arch is None:
65
+ continue
66
+ attr_self = getattr(self, attr)
67
+ attr_other = getattr(other, attr)
68
+ if isinstance(attr_self, SimType):
69
+ if not SimType._simtype_eq(attr_self, attr_other, avoid):
70
+ return False
71
+ elif isinstance(attr_self, (list, tuple)) and isinstance(attr_other, (list, tuple)):
72
+ if len(attr_self) != len(attr_other):
73
+ return False
74
+ for a, b in zip(attr_self, attr_other):
75
+ if isinstance(a, SimType) and isinstance(b, SimType):
76
+ if SimType._simtype_eq(a, b, avoid) is False:
77
+ return False
78
+ else:
79
+ if a != b:
80
+ return False
81
+ else:
82
+ if attr_self != attr_other:
83
+ return False
84
+
85
+ return True
86
+
87
+ def __ne__(self, other):
88
+ # wow many efficient
89
+ return not self == other
90
+
91
+ def __hash__(self):
92
+ # very hashing algorithm many secure wow
93
+ out = hash(type(self))
94
+ for attr in self._fields:
95
+ out ^= hash(getattr(self, attr))
96
+ return out
97
+
98
+ def _refine_dir(self): # pylint: disable=no-self-use
99
+ return []
100
+
101
+ def _refine(self, view, k): # pylint: disable=unused-argument,no-self-use
102
+ raise KeyError(f"{k} is not a valid refinement")
103
+
104
+ @property
105
+ def size(self) -> int | None:
106
+ """
107
+ The size of the type in bits, or None if no size is computable.
108
+ """
109
+ return self._size
110
+
111
+ @property
112
+ def alignment(self):
113
+ """
114
+ The alignment of the type in bytes.
115
+ """
116
+ if self._arch is None:
117
+ raise ValueError("Can't tell my alignment without an arch!")
118
+ if self.size is None:
119
+ l.debug("The size of the type %r is unknown; assuming word size of the arch.", self)
120
+ return self._arch.bytes
121
+ return self.size // self._arch.byte_width
122
+
123
+ def with_arch(self, arch: Arch | None):
124
+ if arch is None:
125
+ return self
126
+ if self._arch is not None and self._arch == arch:
127
+ return self
128
+ return self._with_arch(arch)
129
+
130
+ def _with_arch(self, arch):
131
+ cp = copy.copy(self)
132
+ cp._arch = arch
133
+ return cp
134
+
135
+ def _init_str(self):
136
+ return f"NotImplemented({self.__class__.__name__})"
137
+
138
+ def c_repr(
139
+ self, name=None, full=0, memo=None, indent: int | None = 0, name_parens: bool = True
140
+ ): # pylint: disable=unused-argument
141
+ if name is None:
142
+ return repr(self)
143
+ return f"{str(self) if self.label is None else self.label} {name}"
144
+
145
+ def copy(self):
146
+ raise NotImplementedError
147
+
148
+ def extract(self, state: SimState, addr, concrete: bool = False) -> Any:
149
+ raise NotImplementedError
150
+
151
+ def store(self, state: SimState, addr, value: Any):
152
+ raise NotImplementedError
153
+
154
+ def extract_claripy(self, bits) -> Any:
155
+ """
156
+ Given a bitvector `bits` which was loaded from memory in a big-endian fashion, return a more appropriate or
157
+ structured representation of the data.
158
+
159
+ A type must have an arch associated in order to use this method.
160
+ """
161
+ raise NotImplementedError(f"extract_claripy is not implemented for {self}")
162
+
163
+
164
+ class TypeRef(SimType):
165
+ """
166
+ A TypeRef is a reference to a type with a name. This allows for interactivity in type analysis, by storing a type
167
+ and having the option to update it later and have all references to it automatically update as well.
168
+ """
169
+
170
+ def __init__(self, name, ty):
171
+ super().__init__()
172
+
173
+ self.type = ty
174
+ self._name = name
175
+
176
+ @property
177
+ def type(self):
178
+ return self._type
179
+
180
+ @type.setter
181
+ def type(self, val):
182
+ self._type = val
183
+ self._arch = val._arch
184
+
185
+ @property
186
+ def name(self):
187
+ """
188
+ This is a read-only property because it is desirable to store typerefs in a mapping from name to type, and we
189
+ want the mapping to be in the loop for any updates.
190
+ """
191
+ return self._name
192
+
193
+ def __eq__(self, other, avoid=None):
194
+ return type(other) is TypeRef and self.type == other.type
195
+
196
+ def __hash__(self):
197
+ return hash(self.type)
198
+
199
+ def __repr__(self):
200
+ return self.name
201
+
202
+ @property
203
+ def size(self):
204
+ return self.type.size
205
+
206
+ @property
207
+ def alignment(self):
208
+ return self.type.alignment
209
+
210
+ def with_arch(self, arch):
211
+ self.type = self.type.with_arch(arch)
212
+ return self
213
+
214
+ def c_repr(
215
+ self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
216
+ ): # pylint: disable=unused-argument
217
+ if not full:
218
+ if name is not None:
219
+ return f"{self.name} {name}"
220
+ return self.name
221
+ return self.type.c_repr(name=name, full=full, memo=memo, indent=indent)
222
+
223
+ def copy(self):
224
+ raise NotImplementedError("copy() for TypeRef is ill-defined. What do you want this to do?")
225
+
226
+
227
+ class NamedTypeMixin:
228
+ """
229
+ SimType classes with this mixin in the class hierarchy allows setting custom class names. A typical use case is
230
+ to represent same or similar type classes with different qualified names, such as "std::basic_string" vs
231
+ "std::__cxx11::basic_string". In such cases, .name stores the qualified name, and .unqualified_name() returns the
232
+ unqualified name of the type.
233
+ """
234
+
235
+ def __init__(self, *args, name: str | None = None, **kwargs):
236
+ super().__init__(*args, **kwargs)
237
+ self._name = name
238
+
239
+ @property
240
+ def name(self) -> str:
241
+ if self._name is None:
242
+ self._name = repr(self)
243
+ return self._name
244
+
245
+ @name.setter
246
+ def name(self, v):
247
+ self._name = v
248
+
249
+ def unqualified_name(self, lang: str = "c++") -> str:
250
+ if lang == "c++":
251
+ splitter = "::"
252
+ n = self.name.split(splitter)
253
+ return n[-1]
254
+ raise NotImplementedError(f"Unsupported language {lang}.")
255
+
256
+
257
+ class SimTypeBottom(SimType):
258
+ """
259
+ SimTypeBottom basically represents a type error.
260
+ """
261
+
262
+ _base_name = "bot"
263
+
264
+ def __repr__(self):
265
+ return self.label or "BOT"
266
+
267
+ def c_repr(
268
+ self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
269
+ ): # pylint: disable=unused-argument
270
+ if name is None:
271
+ return "int" if self.label is None else self.label
272
+ return f'{"int" if self.label is None else self.label} {name}'
273
+
274
+ def _init_str(self):
275
+ return "{}({})".format(self.__class__.__name__, (f'label="{self.label}"') if self.label else "")
276
+
277
+ def copy(self):
278
+ return SimTypeBottom(self.label)
279
+
280
+
281
+ class SimTypeTop(SimType):
282
+ """
283
+ SimTypeTop represents any type (mostly used with a pointer for void*).
284
+ """
285
+
286
+ _fields = ("size",)
287
+
288
+ def __init__(self, size: int | None = None, label=None):
289
+ SimType.__init__(self, label)
290
+ self._size = size
291
+
292
+ def __repr__(self):
293
+ return "TOP"
294
+
295
+ def copy(self):
296
+ return SimTypeTop(size=self.size, label=self.label)
297
+
298
+
299
+ class SimTypeReg(SimType):
300
+ """
301
+ SimTypeReg is the base type for all types that are register-sized.
302
+ """
303
+
304
+ _fields = ("size",)
305
+
306
+ def __init__(self, size: int | None, label=None):
307
+ """
308
+ :param label: the type label.
309
+ :param size: the size of the type (e.g. 32bit, 8bit, etc.).
310
+ """
311
+ SimType.__init__(self, label=label)
312
+ self._size = size
313
+
314
+ def __repr__(self):
315
+ return f"reg{self.size}_t"
316
+
317
+ def store(self, state, addr, value: StoreType):
318
+ if self.size is None:
319
+ raise TypeError("Need a size to store")
320
+ store_endness = state.arch.memory_endness
321
+ with contextlib.suppress(AttributeError):
322
+ value = value.ast # type: ignore
323
+ if isinstance(value, claripy.ast.Bits): # pylint:disable=isinstance-second-argument-not-valid-type
324
+ if value.size() != self.size: # type: ignore
325
+ raise ValueError("size of expression is wrong size for type")
326
+ elif isinstance(value, int):
327
+ value = claripy.BVV(value, self.size)
328
+ elif isinstance(value, bytes):
329
+ store_endness = "Iend_BE"
330
+ else:
331
+ raise TypeError(f"unrecognized expression type for SimType {type(self).__name__}")
332
+
333
+ state.memory.store(addr, value, endness=store_endness)
334
+
335
+ def copy(self):
336
+ return self.__class__(self.size, label=self.label)
337
+
338
+
339
+ class SimTypeNum(SimType):
340
+ """
341
+ SimTypeNum is a numeric type of arbitrary length
342
+ """
343
+
344
+ _fields = (*SimType._fields, "signed", "size")
345
+
346
+ def __init__(self, size: int, signed=True, label=None):
347
+ """
348
+ :param size: The size of the integer, in bits
349
+ :param signed: Whether the integer is signed or not
350
+ :param label: A label for the type
351
+ """
352
+ super().__init__(label)
353
+ self._size = size
354
+ self.signed = signed
355
+
356
+ @property
357
+ def size(self) -> int:
358
+ assert self._size is not None
359
+ return self._size
360
+
361
+ def __repr__(self):
362
+ return "{}int{}_t".format("" if self.signed else "u", self.size)
363
+
364
+ @overload
365
+ def extract(self, state, addr, concrete: Literal[False] = ...) -> claripy.ast.BV: ...
366
+
367
+ @overload
368
+ def extract(self, state, addr, concrete: Literal[True]) -> int: ...
369
+
370
+ def extract(self, state, addr, concrete=False):
371
+ out = state.memory.load(addr, self.size // state.arch.byte_width, endness=state.arch.memory_endness)
372
+ if not concrete:
373
+ return out
374
+ n = state.solver.eval(out)
375
+ if self.signed and n >= 1 << (self.size - 1):
376
+ n -= 1 << (self.size)
377
+ return n
378
+
379
+ def store(self, state, addr, value: StoreType):
380
+ store_endness = state.arch.memory_endness
381
+
382
+ if isinstance(value, claripy.ast.Bits): # pylint:disable=isinstance-second-argument-not-valid-type
383
+ if value.size() != self.size: # type: ignore
384
+ raise ValueError("size of expression is wrong size for type")
385
+ elif isinstance(value, int) and self.size is not None:
386
+ value = claripy.BVV(value, self.size)
387
+ elif isinstance(value, bytes):
388
+ store_endness = "Iend_BE"
389
+ else:
390
+ raise TypeError(f"unrecognized expression type for SimType {type(self).__name__}")
391
+
392
+ state.memory.store(addr, value, endness=store_endness)
393
+
394
+ def copy(self):
395
+ return SimTypeNum(self.size, signed=self.signed, label=self.label)
396
+
397
+
398
+ class SimTypeInt(SimTypeReg):
399
+ """
400
+ SimTypeInt is a type that specifies a signed or unsigned C integer.
401
+ """
402
+
403
+ _fields = (*tuple(x for x in SimTypeReg._fields if x != "size"), "signed")
404
+ _base_name = "int"
405
+
406
+ def __init__(self, signed=True, label=None):
407
+ """
408
+ :param signed: True if signed, False if unsigned
409
+ :param label: The type label
410
+ """
411
+ super().__init__(None, label=label)
412
+ self.signed = signed
413
+
414
+ def c_repr(
415
+ self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
416
+ ): # pylint: disable=unused-argument
417
+ out = self._base_name
418
+ if not self.signed:
419
+ out = "unsigned " + out
420
+ if name is None:
421
+ return out
422
+ return f"{out} {name}"
423
+
424
+ def __repr__(self):
425
+ name = self._base_name
426
+ if not self.signed:
427
+ name = "unsigned " + name
428
+
429
+ try:
430
+ return f"{name} ({self.size} bits)"
431
+ except ValueError:
432
+ return name
433
+
434
+ @property
435
+ def size(self):
436
+ if self._arch is None:
437
+ raise ValueError("Can't tell my size without an arch!")
438
+ try:
439
+ return self._arch.sizeof[self._base_name]
440
+ except KeyError as e:
441
+ raise ValueError(f"Arch {self._arch.name} doesn't have its {self._base_name} type defined!") from e
442
+
443
+ @overload
444
+ def extract(self, state, addr, concrete: Literal[False] = ...) -> claripy.ast.BV: ...
445
+
446
+ @overload
447
+ def extract(self, state, addr, concrete: Literal[True]) -> int: ...
448
+
449
+ def extract(self, state, addr, concrete=False):
450
+ out = state.memory.load(addr, self.size // state.arch.byte_width, endness=state.arch.memory_endness)
451
+ if not concrete:
452
+ return out
453
+ n = state.solver.eval(out)
454
+ if self.signed and n >= 1 << (self.size - 1):
455
+ n -= 1 << self.size
456
+ return n
457
+
458
+ def _init_str(self):
459
+ return "{}(signed={}{})".format(
460
+ self.__class__.__name__,
461
+ self.signed,
462
+ (f', label="{self.label}"') if self.label is not None else "",
463
+ )
464
+
465
+ def _refine_dir(self):
466
+ return ["signed", "unsigned"]
467
+
468
+ def _refine(self, view, k):
469
+ if k == "signed":
470
+ ty = copy.copy(self)
471
+ ty.signed = True
472
+ elif k == "unsigned":
473
+ ty = copy.copy(self)
474
+ ty.signed = False
475
+ else:
476
+ raise KeyError(k)
477
+ return view._deeper(ty=ty)
478
+
479
+ def copy(self):
480
+ return self.__class__(signed=self.signed, label=self.label)
481
+
482
+
483
+ class SimTypeShort(SimTypeInt):
484
+ _base_name = "short"
485
+
486
+
487
+ class SimTypeLong(SimTypeInt):
488
+ _base_name = "long"
489
+
490
+
491
+ class SimTypeLongLong(SimTypeInt):
492
+ _base_name = "long long"
493
+
494
+
495
+ class SimTypeFixedSizeInt(SimTypeInt):
496
+ """
497
+ The base class for all fixed-size (i.e., the size stays the same on all platforms) integer types. Do not
498
+ instantiate this class directly.
499
+ """
500
+
501
+ _base_name: str = "int"
502
+ _fixed_size: int = 32
503
+
504
+ def c_repr(
505
+ self,
506
+ name=None,
507
+ full=0,
508
+ memo=None,
509
+ indent: int | None = 0,
510
+ name_parens: bool = True, # pylint:disable=unused-argument
511
+ ):
512
+ out = self._base_name
513
+ if not self.signed:
514
+ out = "u" + out
515
+ if name is None:
516
+ return out
517
+ return f"{out} {name}"
518
+
519
+ def __repr__(self) -> str:
520
+ name = self._base_name
521
+ if not self.signed:
522
+ name = "u" + name
523
+
524
+ try:
525
+ return f"{name} ({self.size} bits)"
526
+ except ValueError:
527
+ return name
528
+
529
+ @property
530
+ def size(self) -> int:
531
+ return self._fixed_size
532
+
533
+
534
+ class SimTypeInt128(SimTypeFixedSizeInt):
535
+ _base_name = "int128_t"
536
+ _fixed_size = 128
537
+
538
+
539
+ class SimTypeInt256(SimTypeFixedSizeInt):
540
+ _base_name = "int256_t"
541
+ _fixed_size = 256
542
+
543
+
544
+ class SimTypeInt512(SimTypeFixedSizeInt):
545
+ _base_name = "int512_t"
546
+ _fixed_size = 512
547
+
548
+
549
+ class SimTypeChar(SimTypeReg):
550
+ """
551
+ SimTypeChar is a type that specifies a character;
552
+ this could be represented by a byte, but this is meant to be interpreted as a character.
553
+ """
554
+
555
+ _base_name = "char"
556
+
557
+ def __init__(self, signed=True, label=None):
558
+ """
559
+ :param label: the type label.
560
+ """
561
+ # FIXME: Now the size of a char is state-dependent.
562
+ super().__init__(8, label=label)
563
+ self.signed = signed
564
+
565
+ def __repr__(self) -> str:
566
+ return "char"
567
+
568
+ def store(self, state, addr, value: StoreType):
569
+ # FIXME: This is a hack.
570
+ self._size = state.arch.byte_width
571
+ try:
572
+ super().store(state, addr, value)
573
+ except TypeError:
574
+ if isinstance(value, bytes) and len(value) == 1:
575
+ value = claripy.BVV(value[0], state.arch.byte_width)
576
+ super().store(state, addr, value)
577
+ else:
578
+ raise
579
+
580
+ @overload
581
+ def extract(self, state, addr, concrete: Literal[False] = ...) -> claripy.ast.BV: ...
582
+
583
+ @overload
584
+ def extract(self, state, addr, concrete: Literal[True]) -> bytes: ...
585
+
586
+ def extract(self, state, addr, concrete: bool = False) -> claripy.ast.BV | bytes:
587
+ # FIXME: This is a hack.
588
+ self._size = state.arch.byte_width
589
+
590
+ out = state.memory.load(addr, 1, endness=state.arch.memory_endness)
591
+ if concrete:
592
+ return bytes(cast(list[int], [state.solver.eval(out)]))
593
+ return out
594
+
595
+ def _init_str(self):
596
+ return "{}({})".format(
597
+ self.__class__.__name__,
598
+ (f'label="{self.label}"') if self.label is not None else "",
599
+ )
600
+
601
+ def copy(self):
602
+ return self.__class__(signed=self.signed, label=self.label)
603
+
604
+
605
+ class SimTypeWideChar(SimTypeReg):
606
+ """
607
+ SimTypeWideChar is a type that specifies a wide character (a UTF-16 character).
608
+ """
609
+
610
+ _base_name = "char"
611
+
612
+ def __init__(self, signed=True, label=None, endness: Endness = Endness.BE):
613
+ """
614
+ :param label: the type label.
615
+ """
616
+ SimTypeReg.__init__(self, 16, label=label)
617
+ self.signed = signed
618
+ self.endness = endness
619
+
620
+ def __repr__(self):
621
+ return "wchar"
622
+
623
+ def store(self, state, addr, value: StoreType):
624
+ try:
625
+ super().store(state, addr, value)
626
+ except TypeError:
627
+ if isinstance(value, bytes) and len(value) == 2:
628
+ inner = (
629
+ ((value[0] << state.arch.byte_width) | value[1])
630
+ if self.endness == Endness.BE
631
+ else ((value[1] << state.arch.byte_width) | value[0])
632
+ )
633
+ value = claripy.BVV(inner, state.arch.byte_width * 2)
634
+ super().store(state, addr, value)
635
+ else:
636
+ raise
637
+
638
+ def extract(self, state, addr, concrete=False) -> Any:
639
+ out = state.memory.load(addr, 2)
640
+ if concrete:
641
+ data = state.solver.eval(out, cast_to=bytes)
642
+ fmt_str = "utf-16be" if self.endness == Endness.BE else "utf-16le"
643
+ try:
644
+ return data.decode(fmt_str)
645
+ except UnicodeDecodeError:
646
+ return data
647
+ return out
648
+
649
+ def _init_str(self):
650
+ return "{}({})".format(
651
+ self.__class__.__name__,
652
+ (f'label="{self.label}"') if self.label is not None else "",
653
+ )
654
+
655
+ def copy(self):
656
+ return self.__class__(signed=self.signed, label=self.label, endness=self.endness)
657
+
658
+
659
+ class SimTypeBool(SimTypeReg):
660
+ _base_name = "bool"
661
+
662
+ def __init__(self, signed=True, label=None):
663
+ """
664
+ :param label: the type label.
665
+ """
666
+ # FIXME: Now the size of a char is state-dependent.
667
+ super().__init__(8, label=label)
668
+ self.signed = signed
669
+
670
+ def __repr__(self):
671
+ return "bool"
672
+
673
+ def store(self, state, addr, value: StoreType | bool):
674
+ if isinstance(value, bool):
675
+ value = int(value)
676
+ return super().store(state, addr, value)
677
+
678
+ @overload
679
+ def extract(self, state, addr, concrete: Literal[False] = ...) -> claripy.ast.Bool: ...
680
+
681
+ @overload
682
+ def extract(self, state, addr, concrete: Literal[True]) -> bool: ...
683
+
684
+ def extract(self, state, addr, concrete=False):
685
+ ver = super().extract(state, addr, concrete)
686
+ if concrete:
687
+ return ver != b"\0"
688
+ return ver != 0
689
+
690
+ def _init_str(self):
691
+ return f"{self.__class__.__name__}()"
692
+
693
+ def copy(self):
694
+ return self.__class__(signed=self.signed, label=self.label)
695
+
696
+
697
+ class SimTypeFd(SimTypeReg):
698
+ """
699
+ SimTypeFd is a type that specifies a file descriptor.
700
+ """
701
+
702
+ _fields = SimTypeReg._fields
703
+
704
+ def __init__(self, label=None):
705
+ """
706
+ :param label: the type label
707
+ """
708
+ # file descriptors are always 32 bits, right?
709
+ # TODO: That's so closed-minded!
710
+ super().__init__(32, label=label)
711
+
712
+ @property
713
+ def size(self):
714
+ return 32
715
+
716
+ def __repr__(self):
717
+ return "fd_t"
718
+
719
+ def copy(self):
720
+ return SimTypeFd(label=self.label)
721
+
722
+ def _init_str(self):
723
+ return "{}({})".format(
724
+ self.__class__.__name__,
725
+ (f'label="{self.label}"') if self.label is not None else "",
726
+ )
727
+
728
+ @overload
729
+ def extract(self, state, addr, concrete: Literal[False] = ...) -> claripy.ast.BV: ...
730
+
731
+ @overload
732
+ def extract(self, state, addr, concrete: Literal[True]) -> int: ...
733
+
734
+ def extract(self, state, addr, concrete=False):
735
+ # TODO: EDG says this looks dangerously closed-minded. Just in case...
736
+ assert self.size % state.arch.byte_width == 0
737
+
738
+ out = state.memory.load(addr, self.size // state.arch.byte_width, endness=state.arch.memory_endness)
739
+ if not concrete:
740
+ return out
741
+ return state.solver.eval(out)
742
+
743
+
744
+ class SimTypePointer(SimTypeReg):
745
+ """
746
+ SimTypePointer is a type that specifies a pointer to some other type.
747
+ """
748
+
749
+ _fields = (*tuple(x for x in SimTypeReg._fields if x != "size"), "pts_to")
750
+
751
+ def __init__(self, pts_to, label=None, offset=0):
752
+ """
753
+ :param label: The type label.
754
+ :param pts_to: The type to which this pointer points.
755
+ """
756
+ super().__init__(None, label=label)
757
+ self.pts_to = pts_to
758
+ self.signed = False
759
+ self.offset = offset
760
+
761
+ def __repr__(self):
762
+ return f"{self.pts_to}*"
763
+
764
+ def c_repr(
765
+ self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
766
+ ): # pylint: disable=unused-argument
767
+ # if pts_to is SimTypeBottom, we return a void*
768
+ if isinstance(self.pts_to, SimTypeBottom):
769
+ out = "void*"
770
+ if name is None:
771
+ return out
772
+ return f"{out} {name}"
773
+ # if it points to an array, we do not need to add a *
774
+ deref_chr = "*" if not isinstance(self.pts_to, SimTypeArray) else ""
775
+ name_with_deref = deref_chr if name is None else f"{deref_chr}{name}"
776
+ return self.pts_to.c_repr(name_with_deref, full, memo, indent)
777
+
778
+ def make(self, pts_to):
779
+ new = type(self)(pts_to)
780
+ new._arch = self._arch
781
+ return new
782
+
783
+ @property
784
+ def size(self):
785
+ if self._arch is None:
786
+ raise ValueError("Can't tell my size without an arch!")
787
+ return self._arch.bits
788
+
789
+ def _with_arch(self, arch):
790
+ out = SimTypePointer(self.pts_to.with_arch(arch), self.label)
791
+ out._arch = arch
792
+ return out
793
+
794
+ def _init_str(self):
795
+ label_str = f', label="{self.label}"' if self.label is not None else ""
796
+ return f"{self.__class__.__name__}({self.pts_to._init_str()}{label_str}, offset={self.offset})"
797
+
798
+ def copy(self):
799
+ return SimTypePointer(self.pts_to, label=self.label, offset=self.offset)
800
+
801
+ @overload
802
+ def extract(self, state, addr, concrete: Literal[False] = ...) -> claripy.ast.BV: ...
803
+
804
+ @overload
805
+ def extract(self, state, addr, concrete: Literal[True]) -> int: ...
806
+
807
+ def extract(self, state, addr, concrete=False):
808
+ # TODO: EDG says this looks dangerously closed-minded. Just in case...
809
+ assert self.size % state.arch.byte_width == 0
810
+
811
+ out = state.memory.load(addr, self.size // state.arch.byte_width, endness=state.arch.memory_endness)
812
+ if not concrete:
813
+ return out
814
+ return state.solver.eval(out)
815
+
816
+
817
+ class SimTypeReference(SimTypeReg):
818
+ """
819
+ SimTypeReference is a type that specifies a reference to some other type.
820
+ """
821
+
822
+ def __init__(self, refs, label=None):
823
+ super().__init__(None, label=label)
824
+ self.refs: SimType = refs
825
+
826
+ def __repr__(self):
827
+ return f"{self.refs}&"
828
+
829
+ def c_repr(
830
+ self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
831
+ ): # pylint: disable=unused-argument
832
+ name = "&" if name is None else f"&{name}"
833
+ return self.refs.c_repr(name, full, memo, indent)
834
+
835
+ def make(self, refs):
836
+ new = type(self)(refs)
837
+ new._arch = self._arch
838
+ return new
839
+
840
+ @property
841
+ def size(self):
842
+ if self._arch is None:
843
+ raise ValueError("Can't tell my size without an arch!")
844
+ return self._arch.bits
845
+
846
+ def _with_arch(self, arch):
847
+ out = SimTypeReference(self.refs.with_arch(arch), label=self.label)
848
+ out._arch = arch
849
+ return out
850
+
851
+ def _init_str(self):
852
+ return "{}({}{})".format(
853
+ self.__class__.__name__,
854
+ self.refs._init_str(),
855
+ (f', label="{self.label}"') if self.label is not None else "",
856
+ )
857
+
858
+ def copy(self):
859
+ return SimTypeReference(self.refs, label=self.label)
860
+
861
+ @overload
862
+ def extract(self, state, addr, concrete: Literal[False] = ...) -> claripy.ast.BV: ...
863
+
864
+ @overload
865
+ def extract(self, state, addr, concrete: Literal[True]) -> int: ...
866
+
867
+ def extract(self, state, addr, concrete=False):
868
+ # TODO: EDG says this looks dangerously closed-minded. Just in case...
869
+ assert self.size % state.arch.byte_width == 0
870
+
871
+ out = state.memory.load(addr, self.size // state.arch.byte_width, endness=state.arch.memory_endness)
872
+ if not concrete:
873
+ return out
874
+ return state.solver.eval(out)
875
+
876
+
877
+ class SimTypeArray(SimType):
878
+ """
879
+ SimTypeArray is a type that specifies a series of data laid out in sequence.
880
+ """
881
+
882
+ _fields = ("elem_type", "length")
883
+
884
+ def __init__(self, elem_type, length=None, label=None):
885
+ """
886
+ :param label: The type label.
887
+ :param elem_type: The type of each element in the array.
888
+ :param length: An expression of the length of the array, if known.
889
+ """
890
+ super().__init__(label=label)
891
+ self.elem_type: SimType = elem_type
892
+ self.length: int | None = length
893
+
894
+ def __repr__(self):
895
+ return "{}[{}]".format(self.elem_type, "" if self.length is None else self.length)
896
+
897
+ def c_repr(
898
+ self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
899
+ ): # pylint: disable=unused-argument
900
+ if name is None:
901
+ return repr(self)
902
+
903
+ name = "{}[{}]".format(name, self.length if self.length is not None else "")
904
+ return self.elem_type.c_repr(name, full, memo, indent)
905
+
906
+ @property
907
+ def size(self):
908
+ if self.length is None:
909
+ return 0
910
+ if self.elem_type.size is None:
911
+ return None
912
+ return self.elem_type.size * self.length
913
+
914
+ @property
915
+ def alignment(self):
916
+ return self.elem_type.alignment
917
+
918
+ def _with_arch(self, arch):
919
+ out = SimTypeArray(self.elem_type.with_arch(arch), self.length, self.label)
920
+ out._arch = arch
921
+ return out
922
+
923
+ def copy(self):
924
+ return SimTypeArray(self.elem_type, length=self.length, label=self.label)
925
+
926
+ _can_refine_int = True
927
+
928
+ def _refine(self, view, k):
929
+ return view._deeper(
930
+ addr=view._addr + k * (self.elem_type.size // view.state.arch.byte_width), ty=self.elem_type
931
+ )
932
+
933
+ @overload
934
+ def extract(self, state, addr, concrete: Literal[False] = ...) -> list[Any]: # associated types...
935
+ ...
936
+
937
+ @overload
938
+ def extract(self, state, addr, concrete: Literal[True] = ...) -> list[Any]: ...
939
+
940
+ def extract(self, state, addr, concrete=False):
941
+ if self.length is None:
942
+ return []
943
+ if self.elem_type.size is None:
944
+ return None
945
+ return [
946
+ self.elem_type.extract(state, addr + i * (self.elem_type.size // state.arch.byte_width), concrete)
947
+ for i in range(self.length)
948
+ ]
949
+
950
+ def store(self, state, addr, value: list[StoreType]):
951
+ if self.elem_type.size is None:
952
+ raise AngrTypeError("Cannot call store on an array of unsized types")
953
+ for i, val in enumerate(value):
954
+ self.elem_type.store(state, addr + i * (self.elem_type.size // state.arch.byte_width), val)
955
+
956
+ def _init_str(self):
957
+ return "{}({}, {}{})".format(
958
+ self.__class__.__name__,
959
+ self.elem_type._init_str(),
960
+ self.length,
961
+ f", {self.label}" if self.label is not None else "",
962
+ )
963
+
964
+
965
+ SimTypeFixedSizeArray = SimTypeArray
966
+
967
+
968
+ class SimTypeString(NamedTypeMixin, SimType):
969
+ """
970
+ SimTypeString is a type that represents a C-style string,
971
+ i.e. a NUL-terminated array of bytes.
972
+ """
973
+
974
+ _fields = (*SimTypeArray._fields, "length")
975
+
976
+ def __init__(self, length: int | None = None, label=None, name: str | None = None):
977
+ """
978
+ :param label: The type label.
979
+ :param length: An expression of the length of the string, if known.
980
+ """
981
+ super().__init__(label=label, name=name)
982
+ self.elem_type = SimTypeChar()
983
+ self.length = length
984
+
985
+ def __repr__(self):
986
+ return "string_t"
987
+
988
+ def c_repr(
989
+ self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
990
+ ): # pylint: disable=unused-argument
991
+ if name is None:
992
+ return repr(self)
993
+
994
+ name = "{}[{}]".format(name, self.length if self.length is not None else "")
995
+ return self.elem_type.c_repr(name, full, memo, indent)
996
+
997
+ @overload
998
+ def extract(self, state, addr, concrete: Literal[False] = ...) -> claripy.ast.BV: ...
999
+
1000
+ @overload
1001
+ def extract(self, state, addr, concrete: Literal[True]) -> bytes: ...
1002
+
1003
+ def extract(self, state: SimState, addr, concrete=False):
1004
+ if self.length is None:
1005
+ out = None
1006
+ last_byte = state.memory.load(addr, size=1)
1007
+ # if we try to extract a symbolic string, it's likely that we are going to be trapped in a very large loop.
1008
+ if state.solver.symbolic(last_byte):
1009
+ raise ValueError(f"Trying to extract a symbolic string at {state.solver.eval(addr):#x}")
1010
+ addr += 1
1011
+ while not (claripy.is_true(last_byte == 0) or state.solver.symbolic(last_byte)):
1012
+ out = last_byte if out is None else out.concat(last_byte)
1013
+ last_byte = state.memory.load(addr, size=1)
1014
+ addr += 1
1015
+ else:
1016
+ out = state.memory.load(addr, size=self.length)
1017
+ if not concrete:
1018
+ return out if out is not None else claripy.BVV(0, 0)
1019
+ return state.solver.eval(out, cast_to=bytes) if out is not None else b""
1020
+
1021
+ _can_refine_int = True
1022
+
1023
+ def _refine(self, view, k):
1024
+ return view._deeper(addr=view._addr + k, ty=SimTypeChar())
1025
+
1026
+ @property
1027
+ def size(self):
1028
+ if self.length is None:
1029
+ return 4096 # :/
1030
+ return (self.length + 1) * 8
1031
+
1032
+ @property
1033
+ def alignment(self):
1034
+ return 1
1035
+
1036
+ def _with_arch(self, arch):
1037
+ return self
1038
+
1039
+ def copy(self):
1040
+ return SimTypeString(length=self.length, label=self.label, name=self.name)
1041
+
1042
+ def _init_str(self):
1043
+ return "{}({}, {}{})".format(
1044
+ self.__class__.__name__,
1045
+ self.elem_type._init_str(),
1046
+ self.length,
1047
+ f", {self.label}" if self.label is not None else "",
1048
+ )
1049
+
1050
+
1051
+ class SimTypeWString(NamedTypeMixin, SimType):
1052
+ """
1053
+ A wide-character null-terminated string, where each character is 2 bytes.
1054
+ """
1055
+
1056
+ _fields = (*SimTypeArray._fields, "length")
1057
+
1058
+ def __init__(self, length: int | None = None, label=None, name: str | None = None):
1059
+ super().__init__(label=label, name=name)
1060
+ self.elem_type = SimTypeNum(16, False)
1061
+ self.length = length
1062
+
1063
+ def __repr__(self):
1064
+ return "wstring_t"
1065
+
1066
+ def c_repr(
1067
+ self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
1068
+ ): # pylint: disable=unused-argument
1069
+ if name is None:
1070
+ return repr(self)
1071
+
1072
+ name = "{}[{}]".format(name, self.length if self.length is not None else "")
1073
+ return self.elem_type.c_repr(name, full, memo, indent)
1074
+
1075
+ def extract(self, state, addr, concrete=False):
1076
+ if self.length is None:
1077
+ out = None
1078
+ last_byte = state.memory.load(addr, 2)
1079
+ # if we try to extract a symbolic string, it's likely that we are going to be trapped in a very large loop.
1080
+ if state.solver.symbolic(last_byte):
1081
+ raise ValueError(f"Trying to extract a symbolic string at {state.solver.eval(addr):#x}")
1082
+ addr += 2
1083
+ while not (claripy.is_true(last_byte == 0) or state.solver.symbolic(last_byte)):
1084
+ out = last_byte if out is None else out.concat(last_byte)
1085
+ last_byte = state.memory.load(addr, 2)
1086
+ addr += 2
1087
+ else:
1088
+ out = state.memory.load(addr, self.length * 2)
1089
+ if out is None:
1090
+ out = claripy.BVV(0, 0)
1091
+ if not concrete:
1092
+ return out
1093
+ return "".join(
1094
+ chr(state.solver.eval(x.reversed if state.arch.memory_endness == "Iend_LE" else x)) for x in out.chop(16)
1095
+ )
1096
+
1097
+ def store(self, state, addr, value):
1098
+ raise NotImplementedError
1099
+
1100
+ _can_refine_int = True
1101
+
1102
+ def _refine(self, view, k):
1103
+ return view._deeper(addr=view._addr + k * 2, ty=SimTypeNum(16, False))
1104
+
1105
+ @property
1106
+ def size(self):
1107
+ if self.length is None:
1108
+ return 4096
1109
+ return (self.length * 2 + 2) * 8
1110
+
1111
+ @property
1112
+ def alignment(self):
1113
+ return 2
1114
+
1115
+ def _with_arch(self, arch):
1116
+ return self
1117
+
1118
+ def copy(self):
1119
+ return SimTypeWString(length=self.length, label=self.label, name=self.name)
1120
+
1121
+ def _init_str(self):
1122
+ return "{}({}, {}{})".format(
1123
+ self.__class__.__name__,
1124
+ self.elem_type._init_str(),
1125
+ self.length,
1126
+ f", {self.label}" if self.label is not None else "",
1127
+ )
1128
+
1129
+
1130
+ class SimTypeFunction(SimType):
1131
+ """
1132
+ SimTypeFunction is a type that specifies an actual function (i.e. not a pointer) with certain types of arguments and
1133
+ a certain return value.
1134
+ """
1135
+
1136
+ _fields = ("args", "returnty")
1137
+ base = False
1138
+
1139
+ def __init__(
1140
+ self,
1141
+ args: Iterable[SimType],
1142
+ returnty: SimType | None,
1143
+ label=None,
1144
+ arg_names: Iterable[str] | None = None,
1145
+ variadic=False,
1146
+ ):
1147
+ """
1148
+ :param label: The type label
1149
+ :param args: A tuple of types representing the arguments to the function
1150
+ :param returnty: The return type of the function, or none for void
1151
+ :param variadic: Whether the function accepts varargs
1152
+ """
1153
+ super().__init__(label=label)
1154
+ self.args: tuple[SimType, ...] = tuple(args)
1155
+ self.returnty: SimType | None = returnty
1156
+ self.arg_names = tuple(arg_names) if arg_names else ()
1157
+ self.variadic = variadic
1158
+
1159
+ def __hash__(self):
1160
+ return hash(type(self)) ^ hash(tuple(self.args)) ^ hash(self.returnty)
1161
+
1162
+ def __repr__(self):
1163
+ argstrs = [str(a) for a in self.args]
1164
+ if self.variadic:
1165
+ argstrs.append("...")
1166
+ return "({}) -> {}".format(", ".join(argstrs), self.returnty)
1167
+
1168
+ def c_repr(self, name=None, full=0, memo=None, indent=0, name_parens: bool = True):
1169
+ formatted_args = [
1170
+ a.c_repr(n, full - 1, memo, indent)
1171
+ for a, n in zip(self.args, self.arg_names if self.arg_names and full else (None,) * len(self.args))
1172
+ ]
1173
+ if self.variadic:
1174
+ formatted_args.append("...")
1175
+ name_str = f"({name or ''})" if name_parens else name or ""
1176
+ proto = f"{name_str}({', '.join(formatted_args)})"
1177
+ return f"void {proto}" if self.returnty is None else self.returnty.c_repr(proto, full, memo, indent)
1178
+
1179
+ @property
1180
+ def size(self):
1181
+ return 4096 # ???????????
1182
+
1183
+ def _with_arch(self, arch):
1184
+ out = SimTypeFunction(
1185
+ [a.with_arch(arch) for a in self.args],
1186
+ self.returnty.with_arch(arch) if self.returnty is not None else None,
1187
+ label=self.label,
1188
+ arg_names=self.arg_names,
1189
+ variadic=self.variadic,
1190
+ )
1191
+ out._arch = arch
1192
+ return out
1193
+
1194
+ def _arg_names_str(self, show_variadic=True):
1195
+ argnames = list(self.arg_names)
1196
+ if self.variadic and show_variadic:
1197
+ argnames.append("...")
1198
+ return ", ".join(f'"{arg_name}"' for arg_name in argnames)
1199
+
1200
+ def _init_str(self):
1201
+ return "{}([{}], {}{}{}{})".format(
1202
+ self.__class__.__name__,
1203
+ ", ".join([arg._init_str() for arg in self.args]),
1204
+ self.returnty._init_str() if self.returnty else "void",
1205
+ (f', label="{self.label}"') if self.label else "",
1206
+ (f", arg_names=[{self._arg_names_str(show_variadic=False)}]") if self.arg_names else "",
1207
+ ", variadic=True" if self.variadic else "",
1208
+ )
1209
+
1210
+ def copy(self):
1211
+ return SimTypeFunction(
1212
+ self.args, self.returnty, label=self.label, arg_names=self.arg_names, variadic=self.variadic
1213
+ )
1214
+
1215
+
1216
+ class SimTypeCppFunction(SimTypeFunction):
1217
+ """
1218
+ SimTypeCppFunction is a type that specifies an actual C++-style function with information about arguments, return
1219
+ value, and more C++-specific properties.
1220
+
1221
+ :ivar ctor: Whether the function is a constructor or not.
1222
+ :ivar dtor: Whether the function is a destructor or not.
1223
+ """
1224
+
1225
+ def __init__(
1226
+ self,
1227
+ args,
1228
+ returnty,
1229
+ label=None,
1230
+ arg_names: Iterable[str] | None = None,
1231
+ ctor: bool = False,
1232
+ dtor: bool = False,
1233
+ convention: str | None = None,
1234
+ ):
1235
+ super().__init__(args, returnty, label=label, arg_names=arg_names, variadic=False)
1236
+ self.ctor = ctor
1237
+ self.dtor = dtor
1238
+ self.convention = convention
1239
+
1240
+ def __repr__(self):
1241
+ argstrs = [str(a) for a in self.args]
1242
+ if self.variadic:
1243
+ argstrs.append("...")
1244
+ return str(self.label) + "({}) -> {}".format(", ".join(argstrs), self.returnty)
1245
+
1246
+ def _init_str(self):
1247
+ return "{}([{}], {}{}{}{})".format(
1248
+ self.__class__.__name__,
1249
+ ", ".join([arg._init_str() for arg in self.args]),
1250
+ self.returnty,
1251
+ (f", label={self.label}") if self.label else "",
1252
+ (f", arg_names=[{self._arg_names_str(show_variadic=False)}]") if self.arg_names else "",
1253
+ ", variadic=True" if self.variadic else "",
1254
+ )
1255
+
1256
+ def _with_arch(self, arch):
1257
+ out = SimTypeCppFunction(
1258
+ [a.with_arch(arch) for a in self.args],
1259
+ self.returnty.with_arch(arch) if self.returnty is not None else None,
1260
+ label=self.label,
1261
+ arg_names=self.arg_names,
1262
+ ctor=self.ctor,
1263
+ dtor=self.dtor,
1264
+ convention=self.convention,
1265
+ )
1266
+ out._arch = arch
1267
+ return out
1268
+
1269
+ def copy(self):
1270
+ return SimTypeCppFunction(
1271
+ self.args,
1272
+ self.returnty,
1273
+ label=self.label,
1274
+ arg_names=self.arg_names,
1275
+ ctor=self.ctor,
1276
+ dtor=self.dtor,
1277
+ convention=self.convention,
1278
+ )
1279
+
1280
+
1281
+ class SimTypeLength(SimTypeLong):
1282
+ """
1283
+ SimTypeLength is a type that specifies the length of some buffer in memory.
1284
+
1285
+ ...I'm not really sure what the original design of this class was going for
1286
+ """
1287
+
1288
+ _fields = (*(x for x in SimTypeReg._fields if x != "size"), "addr", "length") # ?
1289
+
1290
+ def __init__(self, signed=False, addr=None, length=None, label=None):
1291
+ """
1292
+ :param signed: Whether the value is signed or not
1293
+ :param label: The type label.
1294
+ :param addr: The memory address (expression).
1295
+ :param length: The length (expression).
1296
+ """
1297
+ super().__init__(signed=signed, label=label)
1298
+ self.addr = addr
1299
+ self.length = length
1300
+
1301
+ def __repr__(self):
1302
+ return "size_t"
1303
+
1304
+ @property
1305
+ def size(self):
1306
+ if self._arch is None:
1307
+ raise ValueError("I can't tell my size without an arch!")
1308
+ return self._arch.bits
1309
+
1310
+ def _init_str(self):
1311
+ return f"{self.__class__.__name__}(size={self.size})"
1312
+
1313
+ def copy(self):
1314
+ return SimTypeLength(signed=self.signed, addr=self.addr, length=self.length, label=self.label)
1315
+
1316
+
1317
+ class SimTypeFloat(SimTypeReg):
1318
+ """
1319
+ An IEEE754 single-precision floating point number
1320
+ """
1321
+
1322
+ _base_name = "float"
1323
+
1324
+ def __init__(self, size=32):
1325
+ super().__init__(size)
1326
+
1327
+ sort = claripy.FSORT_FLOAT
1328
+ signed = True
1329
+
1330
+ @property
1331
+ def size(self) -> int:
1332
+ return 32
1333
+
1334
+ def extract(self, state, addr, concrete=False):
1335
+ itype = claripy.fpToFP(
1336
+ state.memory.load(addr, self.size // state.arch.byte_width, endness=state.arch.memory_endness), self.sort
1337
+ )
1338
+ if concrete:
1339
+ return state.solver.eval(itype)
1340
+ return itype
1341
+
1342
+ def store(self, state, addr, value: StoreType | claripy.ast.FP):
1343
+ if isinstance(value, (int, float)):
1344
+ value = claripy.FPV(float(value), self.sort)
1345
+ return super().store(state, addr, value) # type: ignore # trust me bro
1346
+
1347
+ def __repr__(self) -> str:
1348
+ return "float"
1349
+
1350
+ def _init_str(self):
1351
+ return f"{self.__class__.__name__}(size={self.size})"
1352
+
1353
+ def copy(self):
1354
+ return SimTypeFloat(self.size)
1355
+
1356
+
1357
+ class SimTypeDouble(SimTypeFloat):
1358
+ """
1359
+ An IEEE754 double-precision floating point number
1360
+ """
1361
+
1362
+ _base_name = "double"
1363
+
1364
+ def __init__(self, align_double=True):
1365
+ self.align_double = align_double
1366
+ super().__init__(64)
1367
+
1368
+ sort = claripy.FSORT_DOUBLE
1369
+
1370
+ @property
1371
+ def size(self) -> int:
1372
+ return 64
1373
+
1374
+ def __repr__(self):
1375
+ return "double"
1376
+
1377
+ @property
1378
+ def alignment(self):
1379
+ return 8 if self.align_double else 4
1380
+
1381
+ def _init_str(self):
1382
+ return f"{self.__class__.__name__}(align_double={self.align_double})"
1383
+
1384
+ def copy(self):
1385
+ return SimTypeDouble(align_double=self.align_double)
1386
+
1387
+
1388
+ class SimStruct(NamedTypeMixin, SimType):
1389
+ _fields = ("name", "fields", "anonymous")
1390
+
1391
+ def __init__(
1392
+ self,
1393
+ fields: dict[str, SimType] | OrderedDict[str, SimType],
1394
+ name=None,
1395
+ pack=False,
1396
+ align=None,
1397
+ anonymous: bool = False,
1398
+ ):
1399
+ super().__init__(None, name="<anon>" if name is None else name)
1400
+
1401
+ self._pack = pack
1402
+ self._align = align
1403
+ self.anonymous = anonymous
1404
+ self.fields: OrderedDict[str, SimType] = OrderedDict(fields)
1405
+
1406
+ # FIXME: Hack for supporting win32 struct definitions
1407
+ if self.name == "_Anonymous_e__Struct":
1408
+ self.anonymous = True
1409
+
1410
+ self._arch_memo = {}
1411
+
1412
+ @property
1413
+ def packed(self):
1414
+ return self._pack
1415
+
1416
+ @property
1417
+ def offsets(self) -> dict[str, int]:
1418
+ if self._arch is None:
1419
+ raise ValueError("Need an arch to calculate offsets")
1420
+
1421
+ offsets = {}
1422
+ offset_so_far = 0
1423
+ for name, ty in self.fields.items():
1424
+ if ty.size is None:
1425
+ l.debug(
1426
+ "Found a bottom field in struct %s. Ignore and increment the offset using the default "
1427
+ "element size.",
1428
+ self.name,
1429
+ )
1430
+ continue
1431
+ if not self._pack:
1432
+ align = ty.alignment
1433
+ if align is NotImplemented:
1434
+ # hack!
1435
+ align = 1
1436
+ if offset_so_far % align != 0:
1437
+ offset_so_far += align - offset_so_far % align
1438
+ offsets[name] = offset_so_far
1439
+ offset_so_far += ty.size // self._arch.byte_width
1440
+ else:
1441
+ offsets[name] = offset_so_far // self._arch.byte_width
1442
+ offset_so_far += ty.size
1443
+
1444
+ return offsets
1445
+
1446
+ def extract(self, state, addr, concrete=False) -> SimStructValue:
1447
+ values = {}
1448
+ for name, offset in self.offsets.items():
1449
+ ty = self.fields[name]
1450
+ v = SimMemView(ty=ty, addr=addr + offset, state=state)
1451
+ if concrete:
1452
+ values[name] = v.concrete
1453
+ else:
1454
+ values[name] = v.resolved
1455
+
1456
+ return SimStructValue(self, values=values)
1457
+
1458
+ def _with_arch(self, arch):
1459
+ if arch.name in self._arch_memo:
1460
+ return self._arch_memo[arch.name]
1461
+
1462
+ out = SimStruct({}, name=self.name, pack=self._pack, align=self._align)
1463
+ out._arch = arch
1464
+ self._arch_memo[arch.name] = out
1465
+
1466
+ out.fields = OrderedDict((k, v.with_arch(arch)) for k, v in self.fields.items())
1467
+
1468
+ # Fixup the offsets to byte aligned addresses for all SimTypeNumOffset types
1469
+ offset_so_far = 0
1470
+ for _, ty in out.fields.items():
1471
+ if isinstance(ty, SimTypeNumOffset):
1472
+ out._pack = True
1473
+ ty.offset = offset_so_far % arch.byte_width
1474
+ offset_so_far += ty.size
1475
+ return out
1476
+
1477
+ def __repr__(self):
1478
+ return f"struct {self.name}"
1479
+
1480
+ def c_repr(
1481
+ self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
1482
+ ): # pylint: disable=unused-argument
1483
+ if not full or (memo is not None and self in memo):
1484
+ return super().c_repr(name, full, memo, indent)
1485
+
1486
+ indented = " " * indent if indent is not None else ""
1487
+ new_indent = indent + 4 if indent is not None else None
1488
+ new_indented = " " * new_indent if new_indent is not None else ""
1489
+ newline = "\n" if indent is not None else " "
1490
+ new_memo = (self,) + (memo if memo is not None else ())
1491
+ members = newline.join(
1492
+ new_indented + v.c_repr(k, full - 1, new_memo, new_indent) + ";" for k, v in self.fields.items()
1493
+ )
1494
+ return f"struct {self.name} {{{newline}{members}{newline}{indented}}}{'' if name is None else ' ' + name}"
1495
+
1496
+ def __hash__(self):
1497
+ return hash((SimStruct, self._name, self._align, self._pack, tuple(self.fields.keys())))
1498
+
1499
+ @property
1500
+ def size(self):
1501
+ if not self.offsets:
1502
+ return 0
1503
+ if self._arch is None:
1504
+ raise ValueError("Need an arch to compute size")
1505
+
1506
+ last_name, last_off = list(self.offsets.items())[-1]
1507
+ last_type = self.fields[last_name]
1508
+ if isinstance(last_type, SimTypeNumOffset):
1509
+ return last_off * self._arch.byte_width + (last_type.size + last_type.offset)
1510
+ if last_type.size is None:
1511
+ raise AngrTypeError("Cannot compute the size of a struct with elements with no size")
1512
+ return last_off * self._arch.byte_width + last_type.size
1513
+
1514
+ @property
1515
+ def alignment(self):
1516
+ if self._align is not None:
1517
+ return self._align
1518
+ if all(val.alignment is NotImplemented for val in self.fields.values()):
1519
+ return NotImplemented
1520
+ return max(val.alignment if val.alignment is not NotImplemented else 1 for val in self.fields.values())
1521
+
1522
+ def _refine_dir(self):
1523
+ return list(self.fields.keys())
1524
+
1525
+ def _refine(self, view, k):
1526
+ offset = self.offsets[k]
1527
+ ty = self.fields[k]
1528
+ return view._deeper(ty=ty, addr=view._addr + offset)
1529
+
1530
+ def store(self, state, addr, value: StoreType):
1531
+ if type(value) is dict:
1532
+ pass
1533
+ elif type(value) is SimStructValue:
1534
+ value = value._values
1535
+ else:
1536
+ raise TypeError(f"Can't store struct of type {type(value)}")
1537
+
1538
+ assert isinstance(value, dict)
1539
+ if len(value) != len(self.fields):
1540
+ raise ValueError(f"Passed bad values for {self}; expected {len(self.offsets)}, got {len(value)}")
1541
+
1542
+ for field, offset in self.offsets.items():
1543
+ ty = self.fields[field]
1544
+ ty.store(state, addr + offset, value[field])
1545
+
1546
+ @staticmethod
1547
+ def _field_str(field_name, field_type):
1548
+ return f'("{field_name}", {field_type._init_str()})'
1549
+
1550
+ def _init_str(self):
1551
+ return '{}(OrderedDict(({},)), name="{}", pack={}, align={})'.format(
1552
+ self.__class__.__name__,
1553
+ ", ".join([self._field_str(f, ty) for f, ty in self.fields.items()]),
1554
+ self._name,
1555
+ self._pack,
1556
+ self._align,
1557
+ )
1558
+
1559
+ def copy(self):
1560
+ return SimStruct(dict(self.fields), name=self.name, pack=self._pack, align=self._align)
1561
+
1562
+ def __eq__(self, other, avoid: dict[str, set[SimType]] | None = None):
1563
+ if not isinstance(other, SimStruct):
1564
+ return False
1565
+ if not (
1566
+ self._pack == other._pack
1567
+ and self._align == other._align
1568
+ and self.label == other.label
1569
+ and self._name == other._name
1570
+ and self._arch == other._arch
1571
+ ):
1572
+ return False
1573
+ # fields comparison that accounts for self references
1574
+ if not self.fields and not other.fields:
1575
+ return True
1576
+ keys_self = list(self.fields)
1577
+ keys_other = list(other.fields)
1578
+ if keys_self != keys_other:
1579
+ return False
1580
+ if avoid is None:
1581
+ avoid = {"self": {self}, "other": {other}}
1582
+ for key in keys_self:
1583
+ field_self = self.fields[key]
1584
+ field_other = other.fields[key]
1585
+ if field_self in avoid["self"] and field_other in avoid["other"]:
1586
+ continue
1587
+ avoid["self"].add(field_self)
1588
+ avoid["other"].add(field_other)
1589
+ if not field_self.__eq__(field_other, avoid=avoid):
1590
+ return False
1591
+ return True
1592
+
1593
+
1594
+ class SimStructValue:
1595
+ """
1596
+ A SimStruct type paired with some real values
1597
+ """
1598
+
1599
+ def __init__(self, struct, values=None):
1600
+ """
1601
+ :param struct: A SimStruct instance describing the type of this struct
1602
+ :param values: A mapping from struct fields to values
1603
+ """
1604
+ self._struct = struct
1605
+ # since the keys are specified, also support specifying the values as just a list
1606
+ if values is not None and hasattr(values, "__iter__") and not hasattr(values, "items"):
1607
+ values = dict(zip(struct.fields.keys(), values))
1608
+ self._values = defaultdict(lambda: None, values or ())
1609
+
1610
+ @property
1611
+ def struct(self):
1612
+ return self._struct
1613
+
1614
+ def __indented_repr__(self, indent=0):
1615
+ fields = []
1616
+ for name in self._struct.fields:
1617
+ value = self._values[name]
1618
+ try:
1619
+ f = value.__indented_repr__ # type: ignore[reportAttributeAccessIssue]
1620
+ s = f(indent=indent + 2)
1621
+ except AttributeError:
1622
+ s = repr(value)
1623
+ fields.append(" " * (indent + 2) + f".{name} = {s}")
1624
+
1625
+ return "{{\n{}\n{}}}".format(",\n".join(fields), " " * indent)
1626
+
1627
+ def __repr__(self):
1628
+ return self.__indented_repr__()
1629
+
1630
+ def __getattr__(self, k):
1631
+ return self[k]
1632
+
1633
+ def __getitem__(self, k):
1634
+ if type(k) is int:
1635
+ k = self._struct.fields[k]
1636
+ if k not in self._values:
1637
+ for f in self._struct.fields:
1638
+ if isinstance(f, NamedTypeMixin) and f.name is None:
1639
+ try:
1640
+ return f[k] # type: ignore # lukas WHAT
1641
+ except KeyError:
1642
+ continue
1643
+ raise KeyError(k)
1644
+
1645
+ return self._values[k]
1646
+
1647
+ def copy(self):
1648
+ return SimStructValue(self._struct, values=defaultdict(lambda: None, self._values))
1649
+
1650
+
1651
+ class SimUnion(NamedTypeMixin, SimType):
1652
+ fields = ("members", "name")
1653
+
1654
+ def __init__(self, members: dict[str, SimType], name=None, label=None):
1655
+ """
1656
+ :param members: The members of the union, as a mapping name -> type
1657
+ :param name: The name of the union
1658
+ """
1659
+ super().__init__(label, name=name if name is not None else "<anon>")
1660
+ self.members = members
1661
+
1662
+ @property
1663
+ def size(self):
1664
+ if self._arch is None:
1665
+ raise ValueError("Can't tell my size without an arch!")
1666
+ member_sizes: list[int] = [ty.size for ty in self.members.values() if not isinstance(ty, SimTypeBottom)]
1667
+ # fall back to word size in case all members are SimTypeBottom
1668
+ return max(member_sizes) if member_sizes else self._arch.bytes
1669
+
1670
+ @property
1671
+ def alignment(self):
1672
+ if all(val.alignment is NotImplemented for val in self.members.values()):
1673
+ return NotImplemented
1674
+ return max(val.alignment if val.alignment is not NotImplemented else 1 for val in self.members.values())
1675
+
1676
+ def _refine_dir(self):
1677
+ return list(self.members.keys())
1678
+
1679
+ def _refine(self, view, k):
1680
+ ty = self.members[k]
1681
+ return view._deeper(ty=ty, addr=view._addr)
1682
+
1683
+ def extract(self, state, addr, concrete=False):
1684
+ values = {}
1685
+ for name, ty in self.members.items():
1686
+ v = SimMemView(ty=ty, addr=addr, state=state)
1687
+ if concrete:
1688
+ values[name] = v.concrete
1689
+ else:
1690
+ values[name] = v.resolved
1691
+
1692
+ return SimUnionValue(self, values=values)
1693
+
1694
+ def __repr__(self):
1695
+ # use the str instead of repr of each member to avoid exceed recursion
1696
+ # depth when representing self-referential unions
1697
+ return "union {} {{\n\t{}\n}}".format(
1698
+ self.name, "\n\t".join(f"{name} {ty!s};" for name, ty in self.members.items())
1699
+ )
1700
+
1701
+ def c_repr(
1702
+ self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
1703
+ ): # pylint: disable=unused-argument
1704
+ if not full or (memo is not None and self in memo):
1705
+ return super().c_repr(name, full, memo, indent)
1706
+
1707
+ indented = " " * indent if indent is not None else ""
1708
+ new_indent = indent + 4 if indent is not None else None
1709
+ new_indented = " " * new_indent if new_indent is not None else ""
1710
+ newline = "\n" if indent is not None else " "
1711
+ new_memo = (self,) + (memo if memo is not None else ())
1712
+ members = newline.join(
1713
+ new_indented + v.c_repr(k, full - 1, new_memo, new_indent) + ";" for k, v in self.members.items()
1714
+ )
1715
+ return f"union {self.name} {{{newline}{members}{newline}{indented}}}{'' if name is None else ' ' + name}"
1716
+
1717
+ def _init_str(self):
1718
+ return '{}({{{}}}, name="{}", label="{}")'.format(
1719
+ self.__class__.__name__,
1720
+ ", ".join([self._field_str(f, ty) for f, ty in self.members.items()]),
1721
+ self._name,
1722
+ self.label,
1723
+ )
1724
+
1725
+ @staticmethod
1726
+ def _field_str(field_name, field_type):
1727
+ return f'"{field_name}": {field_type._init_str()}'
1728
+
1729
+ def __str__(self):
1730
+ return f"union {self.name}"
1731
+
1732
+ def _with_arch(self, arch):
1733
+ out = SimUnion({name: ty.with_arch(arch) for name, ty in self.members.items()}, self.label)
1734
+ out._arch = arch
1735
+ return out
1736
+
1737
+ def copy(self):
1738
+ return SimUnion(dict(self.members), name=self.name, label=self.label)
1739
+
1740
+
1741
+ class SimUnionValue:
1742
+ """
1743
+ A SimStruct type paired with some real values
1744
+ """
1745
+
1746
+ def __init__(self, union, values=None):
1747
+ """
1748
+ :param union: A SimUnion instance describing the type of this union
1749
+ :param values: A mapping from union members to values
1750
+ """
1751
+ self._union = union
1752
+ self._values = defaultdict(lambda: None, values or ())
1753
+
1754
+ def __indented_repr__(self, indent=0):
1755
+ fields = []
1756
+ for name, value in self._values.items():
1757
+ try:
1758
+ f = value.__indented_repr__ # type: ignore[reportAttributeAccessIssue]
1759
+ s = f(indent=indent + 2)
1760
+ except AttributeError:
1761
+ s = repr(value)
1762
+ fields.append(" " * (indent + 2) + f".{name} = {s}")
1763
+
1764
+ return "{{\n{}\n{}}}".format(",\n".join(fields), " " * indent)
1765
+
1766
+ def __repr__(self):
1767
+ return self.__indented_repr__()
1768
+
1769
+ def __getattr__(self, k):
1770
+ return self[k]
1771
+
1772
+ def __getitem__(self, k):
1773
+ if k not in self._values:
1774
+ raise KeyError(k)
1775
+ return self._values[k]
1776
+
1777
+ def copy(self):
1778
+ return SimUnionValue(self._union, values=self._values)
1779
+
1780
+
1781
+ class SimCppClass(SimStruct):
1782
+ def __init__(
1783
+ self,
1784
+ *,
1785
+ unique_name: str | None = None,
1786
+ name: str | None = None,
1787
+ members: dict[str, SimType] | None = None,
1788
+ function_members: dict[str, SimTypeCppFunction] | None = None,
1789
+ vtable_ptrs=None,
1790
+ pack: bool = False,
1791
+ align=None,
1792
+ size: int | None = None,
1793
+ ):
1794
+ super().__init__(members or {}, name=name, pack=pack, align=align)
1795
+ self.unique_name = unique_name
1796
+ # these are actually addresses in the binary
1797
+ self.function_members = function_members
1798
+ # this should also be added to the fields once we know the offsets of the members of this object
1799
+ self.vtable_ptrs = [] if vtable_ptrs is None else vtable_ptrs
1800
+
1801
+ # we can force the size (in bits) of a class because sometimes the class can be opaque and we don't know its
1802
+ # layout
1803
+ self._size = size
1804
+
1805
+ @property
1806
+ def members(self):
1807
+ return self.fields
1808
+
1809
+ @members.setter
1810
+ def members(self, value):
1811
+ self.fields = value
1812
+
1813
+ @property
1814
+ def size(self):
1815
+ if self._size is not None:
1816
+ return self._size
1817
+ return super().size
1818
+
1819
+ def __repr__(self):
1820
+ return f"class {self.name}" if not self.name.startswith("class") else self.name
1821
+
1822
+ def extract(self, state, addr, concrete=False) -> SimCppClassValue:
1823
+ values = {}
1824
+ for name, offset in self.offsets.items():
1825
+ ty = self.fields[name]
1826
+ v = SimMemView(ty=ty, addr=addr + offset, state=state)
1827
+ if concrete:
1828
+ values[name] = v.concrete
1829
+ else:
1830
+ values[name] = v.resolved
1831
+
1832
+ return SimCppClassValue(self, values=values)
1833
+
1834
+ def store(self, state, addr, value: StoreType):
1835
+ if type(value) is dict:
1836
+ pass
1837
+ elif type(value) is SimCppClassValue:
1838
+ value = value._values
1839
+ else:
1840
+ raise TypeError(f"Can't store struct of type {type(value)}")
1841
+
1842
+ assert isinstance(value, dict)
1843
+ if len(value) != len(self.fields):
1844
+ raise ValueError(f"Passed bad values for {self}; expected {len(self.offsets)}, got {len(value)}")
1845
+
1846
+ for field, offset in self.offsets.items():
1847
+ ty = self.fields[field]
1848
+ ty.store(state, addr + offset, value[field])
1849
+
1850
+ def _with_arch(self, arch) -> SimCppClass:
1851
+ if arch.name in self._arch_memo:
1852
+ return self._arch_memo[arch.name]
1853
+
1854
+ out = SimCppClass(
1855
+ unique_name=self.unique_name,
1856
+ name=self.name,
1857
+ members={},
1858
+ function_members={},
1859
+ vtable_ptrs=self.vtable_ptrs,
1860
+ pack=self._pack,
1861
+ align=self._align,
1862
+ size=self._size,
1863
+ )
1864
+ out._arch = arch
1865
+ self._arch_memo[arch.name] = out
1866
+
1867
+ out.members = OrderedDict((k, v.with_arch(arch)) for k, v in self.members.items())
1868
+ out.function_members = (
1869
+ OrderedDict((k, v.with_arch(arch)) for k, v in self.function_members.items())
1870
+ if self.function_members is not None
1871
+ else None
1872
+ )
1873
+
1874
+ # Fixup the offsets to byte aligned addresses for all SimTypeNumOffset types
1875
+ offset_so_far = 0
1876
+ for _, ty in out.members.items():
1877
+ if isinstance(ty, SimTypeNumOffset):
1878
+ out._pack = True
1879
+ ty.offset = offset_so_far % arch.byte_width
1880
+ offset_so_far += ty.size
1881
+ return out
1882
+
1883
+ def copy(self):
1884
+ return SimCppClass(
1885
+ unique_name=self.unique_name,
1886
+ name=self.name,
1887
+ members=dict(self.fields),
1888
+ pack=self._pack,
1889
+ align=self._align,
1890
+ function_members=self.function_members,
1891
+ vtable_ptrs=self.vtable_ptrs,
1892
+ size=self._size,
1893
+ )
1894
+
1895
+
1896
+ class SimCppClassValue(SimStructValue):
1897
+ """
1898
+ A SimCppClass type paired with some real values
1899
+ """
1900
+
1901
+ def __init__(self, class_type: SimCppClass, values):
1902
+ super().__init__(class_type, values)
1903
+ self._class = class_type
1904
+
1905
+ def __indented_repr__(self, indent=0):
1906
+ fields = []
1907
+ for name in self._class.fields:
1908
+ value = self._values[name]
1909
+ try:
1910
+ f = value.__indented_repr__ # type: ignore[reportAttributeAccessIssue]
1911
+ s = f(indent=indent + 2)
1912
+ except AttributeError:
1913
+ s = repr(value)
1914
+ fields.append(" " * (indent + 2) + f".{name} = {s}")
1915
+
1916
+ return "{{\n{}\n{}}}".format(",\n".join(fields), " " * indent)
1917
+
1918
+ def __repr__(self):
1919
+ return self.__indented_repr__()
1920
+
1921
+ def __getattr__(self, k):
1922
+ return self[k]
1923
+
1924
+ def __getitem__(self, k: int | str):
1925
+ if isinstance(k, int):
1926
+ k = list(self._class.fields.keys())[k]
1927
+ if k not in self._values:
1928
+ for f in self._class.fields:
1929
+ if isinstance(f, NamedTypeMixin) and f.name is None:
1930
+ try:
1931
+ return f[k] # type: ignore # lukas WHAT
1932
+ except KeyError:
1933
+ continue
1934
+ return self._values[k]
1935
+
1936
+ return self._values[k]
1937
+
1938
+ def copy(self):
1939
+ return SimCppClassValue(self._class, values=defaultdict(lambda: None, self._values))
1940
+
1941
+
1942
+ class SimTypeNumOffset(SimTypeNum):
1943
+ """
1944
+ like SimTypeNum, but supports an offset of 1 to 7 to a byte aligned address to allow structs with bitfields
1945
+ """
1946
+
1947
+ _fields = (*SimTypeNum._fields, "offset")
1948
+
1949
+ def __init__(self, size, signed=True, label=None, offset=0):
1950
+ super().__init__(size, signed, label)
1951
+ self.offset = offset
1952
+
1953
+ @overload
1954
+ def extract(self, state: SimState, addr, concrete: Literal[False] = ...) -> claripy.ast.BV: ...
1955
+
1956
+ @overload
1957
+ def extract(self, state: SimState, addr, concrete: Literal[True]) -> int: ...
1958
+
1959
+ def extract(self, state: SimState, addr, concrete=False):
1960
+ if state.arch.memory_endness != Endness.LE:
1961
+ raise NotImplementedError("This has only been implemented and tested with Little Endian arches so far")
1962
+ minimum_load_size = self.offset + self.size # because we start from a byte aligned offset _before_ the value
1963
+ # Now round up to the next byte
1964
+ load_size = (minimum_load_size - minimum_load_size % (-state.arch.byte_width)) // state.arch.byte_width
1965
+ out = state.memory.load(addr, size=load_size, endness=state.arch.memory_endness)
1966
+ out = out[self.offset + self.size - 1 : self.offset]
1967
+
1968
+ if not concrete:
1969
+ return out
1970
+ n = state.solver.eval(out)
1971
+ if self.signed and n >= 1 << (self.size - 1):
1972
+ n -= 1 << (self.size)
1973
+ return n
1974
+
1975
+ def store(self, state, addr, value):
1976
+ raise NotImplementedError
1977
+
1978
+ def copy(self):
1979
+ return SimTypeNumOffset(self.size, signed=self.signed, label=self.label, offset=self.offset)
1980
+
1981
+
1982
+ class SimTypeRef(SimType):
1983
+ """
1984
+ SimTypeRef is a to-be-resolved reference to another SimType.
1985
+
1986
+ SimTypeRef is not SimTypeReference.
1987
+ """
1988
+
1989
+ def __init__(self, name, original_type: type[SimStruct]):
1990
+ super().__init__(label=name)
1991
+ self.original_type = original_type
1992
+
1993
+ @property
1994
+ def name(self) -> str | None:
1995
+ return self.label
1996
+
1997
+ def set_size(self, v: int):
1998
+ self._size = v
1999
+
2000
+ def c_repr(
2001
+ self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
2002
+ ) -> str: # pylint: disable=unused-argument
2003
+ prefix = "unknown"
2004
+ if self.original_type is SimStruct:
2005
+ prefix = "struct"
2006
+ if name is None:
2007
+ name = ""
2008
+ return f"{prefix}{name} {self.name}"
2009
+
2010
+ def _init_str(self) -> str:
2011
+ original_type_name = self.original_type.__name__.split(".")[-1]
2012
+ return f'SimTypeRef("{self.name}", {original_type_name})'
2013
+
2014
+
2015
+ ALL_TYPES: dict[str, SimType] = {}
2016
+ BASIC_TYPES: dict[str, SimType] = {
2017
+ "char": SimTypeChar(),
2018
+ "signed char": SimTypeChar(),
2019
+ "unsigned char": SimTypeChar(signed=False),
2020
+ "short": SimTypeShort(True),
2021
+ "signed short": SimTypeShort(True),
2022
+ "unsigned short": SimTypeShort(False),
2023
+ "short int": SimTypeShort(True),
2024
+ "signed short int": SimTypeShort(True),
2025
+ "unsigned short int": SimTypeShort(False),
2026
+ "int": SimTypeInt(True),
2027
+ "signed": SimTypeInt(True),
2028
+ "unsigned": SimTypeInt(False),
2029
+ "signed int": SimTypeInt(True),
2030
+ "unsigned int": SimTypeInt(False),
2031
+ "long": SimTypeLong(True),
2032
+ "signed long": SimTypeLong(True),
2033
+ "long signed": SimTypeLong(True),
2034
+ "unsigned long": SimTypeLong(False),
2035
+ "long int": SimTypeLong(True),
2036
+ "signed long int": SimTypeLong(True),
2037
+ "unsigned long int": SimTypeLong(False),
2038
+ "long unsigned int": SimTypeLong(False),
2039
+ "long long": SimTypeLongLong(True),
2040
+ "signed long long": SimTypeLongLong(True),
2041
+ "unsigned long long": SimTypeLongLong(False),
2042
+ "long long int": SimTypeLongLong(True),
2043
+ "signed long long int": SimTypeLongLong(True),
2044
+ "unsigned long long int": SimTypeLongLong(False),
2045
+ "__int32": SimTypeInt(True),
2046
+ "__int64": SimTypeLongLong(True),
2047
+ "__int128": SimTypeNum(128, True),
2048
+ "unsigned __int128": SimTypeNum(128, False),
2049
+ "__int256": SimTypeNum(256, True),
2050
+ "unsigned __int256": SimTypeNum(256, False),
2051
+ "bool": SimTypeBool(),
2052
+ "_Bool": SimTypeBool(),
2053
+ "float": SimTypeFloat(),
2054
+ "double": SimTypeDouble(),
2055
+ "long double": SimTypeDouble(),
2056
+ "void": SimTypeBottom(label="void"),
2057
+ }
2058
+ ALL_TYPES.update(BASIC_TYPES)
2059
+
2060
+ STDINT_TYPES = {
2061
+ "int8_t": SimTypeNum(8, True),
2062
+ "uint8_t": SimTypeNum(8, False),
2063
+ "byte": SimTypeNum(8, False),
2064
+ "int16_t": SimTypeNum(16, True),
2065
+ "uint16_t": SimTypeNum(16, False),
2066
+ "word": SimTypeNum(16, False),
2067
+ "int32_t": SimTypeNum(32, True),
2068
+ "uint32_t": SimTypeNum(32, False),
2069
+ "dword": SimTypeNum(32, False),
2070
+ "int64_t": SimTypeNum(64, True),
2071
+ "uint64_t": SimTypeNum(64, False),
2072
+ "qword": SimTypeNum(64, False),
2073
+ "ptrdiff_t": SimTypeLong(True),
2074
+ "size_t": SimTypeLength(False),
2075
+ "ssize_t": SimTypeLength(True),
2076
+ "ssize": SimTypeLength(False),
2077
+ "uintptr_t": SimTypeLong(False),
2078
+ "wchar_t": SimTypeShort(True),
2079
+ }
2080
+ ALL_TYPES.update(STDINT_TYPES)
2081
+
2082
+ # Most glibc internal basic types are defined in the following two files:
2083
+ # https://github.com/bminor/glibc/blob/master/bits/typesizes.h
2084
+ # https://github.com/bminor/glibc/blob/master/posix/bits/types.h
2085
+ # Anything that is defined in a different file should probably have a permalink
2086
+
2087
+ GLIBC_INTERNAL_BASIC_TYPES = {
2088
+ "__off_t": ALL_TYPES["long int"],
2089
+ "__off64_t": ALL_TYPES["long long int"],
2090
+ "__pid_t": ALL_TYPES["int"],
2091
+ "__ino_t": ALL_TYPES["unsigned long int"],
2092
+ "__ino64_t": ALL_TYPES["unsigned long long int"],
2093
+ "__mode_t": ALL_TYPES["unsigned int"],
2094
+ "__dev_t": ALL_TYPES["uint64_t"],
2095
+ "__nlink_t": ALL_TYPES["unsigned int"],
2096
+ "__uid_t": ALL_TYPES["unsigned int"],
2097
+ "__gid_t": ALL_TYPES["unsigned int"],
2098
+ "__time_t": ALL_TYPES["long int"],
2099
+ # https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/sysdeps/unix/sysv/linux/x86/bits/siginfo-arch.h#L12
2100
+ "__clock_t": ALL_TYPES["uint32_t"],
2101
+ "__suseconds_t": ALL_TYPES["int64_t"],
2102
+ }
2103
+ ALL_TYPES.update(GLIBC_INTERNAL_BASIC_TYPES)
2104
+
2105
+ GLIBC_EXTERNAL_BASIC_TYPES = {
2106
+ "off_t": ALL_TYPES["__off_t"],
2107
+ "off64_t": ALL_TYPES["__off64_t"],
2108
+ "pid_t": ALL_TYPES["__pid_t"],
2109
+ # https://www.gnu.org/software/libc/manual/html_node/Attribute-Meanings.html
2110
+ # This is "no narrower than unsigned int" but may be wider...
2111
+ # TODO: This should be defined based on the architecture
2112
+ "ino_t": ALL_TYPES["__ino_t"],
2113
+ "ino64_t": ALL_TYPES["__ino64_t"],
2114
+ # https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/bits/sockaddr.h#L28
2115
+ "sa_family_t": ALL_TYPES["unsigned short int"],
2116
+ # https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/inet/netinet/in.h#L123
2117
+ "in_port_t": ALL_TYPES["uint16_t"],
2118
+ # https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/bits/termios.h#L102
2119
+ "tcflag_t": ALL_TYPES["unsigned long int"],
2120
+ # https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/bits/termios.h#L105
2121
+ "cc_t": ALL_TYPES["unsigned char"],
2122
+ # https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/bits/termios.h#L108
2123
+ "speed_t": ALL_TYPES["long int"],
2124
+ "clock_t": ALL_TYPES["__clock_t"],
2125
+ "rlim_t": ALL_TYPES["unsigned long int"],
2126
+ "rlim64_t": ALL_TYPES["uint64_t"],
2127
+ # https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/bits/types/error_t.h#L22
2128
+ "error_t": ALL_TYPES["int"],
2129
+ }
2130
+ ALL_TYPES.update(GLIBC_EXTERNAL_BASIC_TYPES)
2131
+
2132
+ # TODO: switch to stl types declared in types_stl
2133
+ CXX_TYPES = {
2134
+ "string": SimTypeString(),
2135
+ "wstring": SimTypeWString(),
2136
+ "std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>": SimTypeString(),
2137
+ "basic_string": SimTypeString(),
2138
+ "CharT": SimTypeChar(),
2139
+ }
2140
+ ALL_TYPES.update(CXX_TYPES)
2141
+
2142
+
2143
+ # Note about structs with self/next pointers -- they will be defined as memberless
2144
+ # name-only structs the same way they would be in C as a forward declaration
2145
+
2146
+ # This dictionary is defined in two steps to allow structs that are members of other
2147
+ # structs to be defined first
2148
+ GLIBC_INTERNAL_TYPES = {
2149
+ "sigval": SimUnion(
2150
+ {
2151
+ "sival_int": ALL_TYPES["int"],
2152
+ "sival_ptr": SimTypePointer(ALL_TYPES["void"], label="void *"),
2153
+ },
2154
+ name="sigval",
2155
+ ),
2156
+ "__mbstate_t": SimStruct(
2157
+ {
2158
+ "__count": ALL_TYPES["int"],
2159
+ "__value": SimUnion(
2160
+ {
2161
+ "__wch": ALL_TYPES["unsigned int"],
2162
+ "__wchb": SimTypeArray(ALL_TYPES["char"], length=4),
2163
+ }
2164
+ ),
2165
+ },
2166
+ name="__mbstate_t",
2167
+ ),
2168
+ "_IO_codecvt": SimStruct(
2169
+ {
2170
+ "__cd_in": SimStruct({}, name="_IO_iconv_t"),
2171
+ "__cd_out": SimStruct({}, name="_IO_iconv_t"),
2172
+ },
2173
+ name="_IO_codecvt",
2174
+ ),
2175
+ "argp_option": SimStruct(
2176
+ {
2177
+ "name": SimTypePointer(ALL_TYPES["char"], label="char *"),
2178
+ "key": ALL_TYPES["int"],
2179
+ "arg": SimTypePointer(ALL_TYPES["char"], label="char *"),
2180
+ "flags": ALL_TYPES["int"],
2181
+ "doc": SimTypePointer(ALL_TYPES["char"], label="char *"),
2182
+ "group": ALL_TYPES["int"],
2183
+ },
2184
+ name="argp_option",
2185
+ ),
2186
+ "argp_child": SimStruct(
2187
+ {
2188
+ "argp": SimStruct({}, name="argp"),
2189
+ "flags": ALL_TYPES["int"],
2190
+ "header": SimTypePointer(ALL_TYPES["char"], label="char *"),
2191
+ "group": ALL_TYPES["int"],
2192
+ },
2193
+ name="argp_child",
2194
+ ),
2195
+ "argp_parser_t": SimTypeFunction(
2196
+ (
2197
+ ALL_TYPES["int"],
2198
+ SimTypePointer(ALL_TYPES["char"], label="char *"),
2199
+ SimTypePointer(SimStruct({}, name="argp_state")),
2200
+ ),
2201
+ ALL_TYPES["error_t"],
2202
+ arg_names=("__key", "__arg", "__state"),
2203
+ ),
2204
+ }
2205
+
2206
+
2207
+ GLIBC_INTERNAL_TYPES.update(
2208
+ {
2209
+ "_obstack_chunk": SimStruct(
2210
+ {
2211
+ "limit": SimTypePointer(ALL_TYPES["char"], label="char *"),
2212
+ "prev": SimTypePointer(SimStruct({}, name="_obstack_chunk", pack=False, align=None)),
2213
+ "contents": SimTypeArray(ALL_TYPES["char"], length=4, label="char"),
2214
+ },
2215
+ name="_obstack_chunk",
2216
+ ),
2217
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/misc/search.h#L69
2218
+ "_ENTRY": SimStruct(
2219
+ {
2220
+ "key": SimTypePointer(ALL_TYPES["char"], label="char *"),
2221
+ "data": SimTypePointer(ALL_TYPES["void"], label="void *"),
2222
+ },
2223
+ name="_ENTRY",
2224
+ ),
2225
+ # https://man7.org/linux/man-pages/man7/sigevent.7.html
2226
+ "sigevent": SimStruct(
2227
+ {
2228
+ "sigev_notify": ALL_TYPES["int"],
2229
+ "sigev_signo": ALL_TYPES["int"],
2230
+ "sigev_value": GLIBC_INTERNAL_TYPES["sigval"],
2231
+ "sigev_notify_function": SimTypeFunction(
2232
+ (GLIBC_INTERNAL_TYPES["sigval"],),
2233
+ SimTypePointer(ALL_TYPES["void"], label="void *"),
2234
+ ),
2235
+ "sigev_notify_attributes": SimTypePointer(ALL_TYPES["void"], label="void *"),
2236
+ "sigev_notify_thread_id": ALL_TYPES["pid_t"],
2237
+ },
2238
+ name="sigevent",
2239
+ ),
2240
+ "in_addr": SimStruct({"s_addr": ALL_TYPES["uint32_t"]}, name="in_addr"),
2241
+ "_IO_marker": SimStruct(
2242
+ {
2243
+ "_next": SimTypePointer(SimStruct({}, name="_IO_marker"), label="struct _IO_marker *"),
2244
+ "_sbuf": SimTypePointer(SimStruct({}, name="FILE"), label="FILE *"),
2245
+ "_pos": ALL_TYPES["int"],
2246
+ },
2247
+ name="_IO_marker",
2248
+ ),
2249
+ "_IO_iconv_t": SimStruct(
2250
+ {
2251
+ # TODO: Define __gconv structs
2252
+ "step": SimTypePointer(SimStruct({}, name="__gconv_step"), label="struct __gconv_step *"),
2253
+ "step_data": SimStruct({}, name="__gconv_step_data"),
2254
+ },
2255
+ name="_IO_iconv_t",
2256
+ ),
2257
+ "_IO_codecvt": GLIBC_INTERNAL_TYPES["_IO_codecvt"],
2258
+ "_IO_lock_t": SimStruct({}, name="pthread_mutex_t"),
2259
+ "__mbstate_t": GLIBC_INTERNAL_TYPES["__mbstate_t"],
2260
+ "_IO_wide_data": SimStruct(
2261
+ {
2262
+ "_IO_read_ptr": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
2263
+ "_IO_read_end": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
2264
+ "_IO_read_base": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
2265
+ "_IO_write_base": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
2266
+ "_IO_write_ptr": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
2267
+ "_IO_write_end": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
2268
+ "_IO_buf_base": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
2269
+ "_IO_buf_end": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
2270
+ "_IO_save_base": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
2271
+ "_IO_backup_base": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
2272
+ "_IO_save_end": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
2273
+ "_IO_state": GLIBC_INTERNAL_TYPES["__mbstate_t"],
2274
+ "_IO_last_state": GLIBC_INTERNAL_TYPES["__mbstate_t"],
2275
+ "_codecvt": GLIBC_INTERNAL_TYPES["_IO_codecvt"],
2276
+ "_shortbuf": SimTypeArray(ALL_TYPES["wchar_t"], length=1, label="wchar_t[1]"),
2277
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/libio/libioP.h#L293
2278
+ "_wide_vtable": SimStruct({}, name="_IO_jump_t"),
2279
+ },
2280
+ name="_IO_wide_data",
2281
+ ),
2282
+ "argp": SimStruct(
2283
+ {
2284
+ "options": SimTypePointer(GLIBC_INTERNAL_TYPES["argp_option"], label="struct argp_option *"),
2285
+ "parser": GLIBC_INTERNAL_TYPES["argp_parser_t"],
2286
+ "args_doc": SimTypePointer(ALL_TYPES["char"], label="char *"),
2287
+ "doc": SimTypePointer(ALL_TYPES["char"], label="char *"),
2288
+ "children": SimTypePointer(GLIBC_INTERNAL_TYPES["argp_child"], label="struct argp_child *"),
2289
+ "help_filter": SimTypeFunction(
2290
+ (
2291
+ ALL_TYPES["int"],
2292
+ SimTypePointer(ALL_TYPES["char"], label="char *"),
2293
+ SimTypePointer(ALL_TYPES["void"], label="void *"),
2294
+ ),
2295
+ SimTypePointer(ALL_TYPES["char"], label="char *"),
2296
+ arg_names=("__key", "__text", "__input"),
2297
+ ),
2298
+ "argp_domain": SimTypePointer(ALL_TYPES["char"], label="char *"),
2299
+ },
2300
+ name="argp",
2301
+ ),
2302
+ "timeval": SimStruct(
2303
+ {
2304
+ # TODO: This should be architecture dependent
2305
+ "tv_sec": ALL_TYPES["__time_t"],
2306
+ "tv_usec": ALL_TYPES["__suseconds_t"],
2307
+ },
2308
+ name="timeval",
2309
+ ),
2310
+ # https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/time/bits/types/struct_timespec.h#L11
2311
+ "timespec": SimStruct(
2312
+ {
2313
+ # TODO: This should be architecture dependent
2314
+ "tv_sec": ALL_TYPES["__time_t"],
2315
+ "tv_nsec": ALL_TYPES["long int"],
2316
+ # TODO: This should be architecture dependent (byte order)
2317
+ "_pad0": ALL_TYPES["uint32_t"],
2318
+ },
2319
+ name="timeval",
2320
+ ),
2321
+ # https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/bits/utmp.h#L50
2322
+ "exit_status": SimStruct(
2323
+ {
2324
+ "e_termination": ALL_TYPES["short int"],
2325
+ "e_exit": ALL_TYPES["short int"],
2326
+ },
2327
+ name="exit_status",
2328
+ ),
2329
+ }
2330
+ )
2331
+ ALL_TYPES.update(GLIBC_INTERNAL_TYPES)
2332
+
2333
+ GLIBC_TYPES = {
2334
+ # DO NOT use the glibc manual to define these structs! It is not accurate and does
2335
+ # not contain all fields or even the fields in the correct order!. Instead, you
2336
+ # need to use the glibc source and actually find the struct. In most cases,
2337
+ # a link to the struct is provided.
2338
+ # ABI-defined, for x86_64 it can be found here in sec 3.34:
2339
+ # https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-1.0.pdf
2340
+ # TODO: This should be architecture dependent
2341
+ "va_list": SimTypeArray(
2342
+ SimStruct(
2343
+ {
2344
+ "gp_offset": ALL_TYPES["unsigned int"],
2345
+ "fp_offset": ALL_TYPES["unsigned int"],
2346
+ "overflow_arg_area": SimTypePointer(ALL_TYPES["void"], label="void *"),
2347
+ "reg_save_area": SimTypePointer(ALL_TYPES["void"], label="void *"),
2348
+ },
2349
+ name="va_list",
2350
+ ),
2351
+ length=1,
2352
+ label="va_list[1]",
2353
+ ),
2354
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/malloc/malloc.h#L82
2355
+ "mallinfo": SimStruct(
2356
+ {
2357
+ "arena": ALL_TYPES["int"],
2358
+ "ordblks": ALL_TYPES["int"],
2359
+ "smblks": ALL_TYPES["int"],
2360
+ "hblks": ALL_TYPES["int"],
2361
+ "hblkhd": ALL_TYPES["int"],
2362
+ "usmblks": ALL_TYPES["int"],
2363
+ "fsmblks": ALL_TYPES["int"],
2364
+ "uordblks": ALL_TYPES["int"],
2365
+ "fordblks": ALL_TYPES["int"],
2366
+ "keepcost": ALL_TYPES["int"],
2367
+ },
2368
+ name="mallinfo",
2369
+ ),
2370
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/malloc/malloc.h#L99
2371
+ "mallinfo2": SimStruct(
2372
+ {
2373
+ "arena": ALL_TYPES["size_t"],
2374
+ "ordblks": ALL_TYPES["size_t"],
2375
+ "smblks": ALL_TYPES["size_t"],
2376
+ "hblks": ALL_TYPES["size_t"],
2377
+ "hblkhd": ALL_TYPES["size_t"],
2378
+ "usmblks": ALL_TYPES["size_t"],
2379
+ "fsmblks": ALL_TYPES["size_t"],
2380
+ "uordblks": ALL_TYPES["size_t"],
2381
+ "fordblks": ALL_TYPES["size_t"],
2382
+ "keepcost": ALL_TYPES["size_t"],
2383
+ },
2384
+ name="mallinfo2",
2385
+ ),
2386
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/malloc/obstack.h#L153
2387
+ "obstack": SimStruct(
2388
+ {
2389
+ "chunk_size": SimTypeLong(signed=True, label="long"),
2390
+ "chunk": GLIBC_INTERNAL_TYPES["_obstack_chunk"],
2391
+ "object_base": SimTypePointer(ALL_TYPES["char"], label="char *"),
2392
+ "next_free": SimTypePointer(ALL_TYPES["char"], label="char *"),
2393
+ "chunk_limit": SimTypePointer(ALL_TYPES["char"], label="char *"),
2394
+ "temp": SimUnion(
2395
+ {
2396
+ "tempint": ALL_TYPES["ptrdiff_t"],
2397
+ "tempptr": SimTypePointer(ALL_TYPES["void"], label="void *"),
2398
+ }
2399
+ ),
2400
+ "alignment_mask": ALL_TYPES["int"],
2401
+ "chunkfun": SimTypeFunction(
2402
+ (SimTypePointer(ALL_TYPES["void"], label="void *"), ALL_TYPES["long"]),
2403
+ SimTypePointer(ALL_TYPES["_obstack_chunk"], label="struct _obstack_chunk *"),
2404
+ ),
2405
+ "freefun": SimTypeFunction(
2406
+ (
2407
+ SimTypePointer(ALL_TYPES["void"], label="void *"),
2408
+ SimTypePointer(ALL_TYPES["_obstack_chunk"], label="_obstack_chunk *"),
2409
+ ),
2410
+ ALL_TYPES["void"],
2411
+ ),
2412
+ "extra_arg": SimTypePointer(ALL_TYPES["void"], label="void *"),
2413
+ "use_extra_arg": SimTypeNumOffset(1, signed=False, label="unsigned"),
2414
+ "maybe_extra_object": SimTypeNumOffset(1, signed=False, label="unsigned"),
2415
+ "alloc_failed": SimTypeNumOffset(1, signed=False, label="unsigned"),
2416
+ },
2417
+ name="obstack",
2418
+ ),
2419
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/locale/locale.h#L51
2420
+ "lconv": SimStruct(
2421
+ {
2422
+ "decimal_point": SimTypePointer(ALL_TYPES["char"], label="char *"),
2423
+ "thousands_sep": SimTypePointer(ALL_TYPES["char"], label="char *"),
2424
+ "grouping": SimTypePointer(ALL_TYPES["char"], label="char *"),
2425
+ "int_curr_symbol": SimTypePointer(ALL_TYPES["char"], label="char *"),
2426
+ "currency_symbol": SimTypePointer(ALL_TYPES["char"], label="char *"),
2427
+ "mon_decimal_point": SimTypePointer(ALL_TYPES["char"], label="char *"),
2428
+ "mon_thousands_sep": SimTypePointer(ALL_TYPES["char"], label="char *"),
2429
+ "mon_grouping": SimTypePointer(ALL_TYPES["char"], label="char *"),
2430
+ "positive_sign": SimTypePointer(ALL_TYPES["char"], label="char *"),
2431
+ "negative_sign": SimTypePointer(ALL_TYPES["char"], label="char *"),
2432
+ "int_frac_digits": ALL_TYPES["char"],
2433
+ "frac_digits": ALL_TYPES["char"],
2434
+ "p_cs_precedes": ALL_TYPES["char"],
2435
+ "p_sep_by_space": ALL_TYPES["char"],
2436
+ "n_cs_precedes": ALL_TYPES["char"],
2437
+ "n_sep_by_space": ALL_TYPES["char"],
2438
+ "p_sign_posn": ALL_TYPES["char"],
2439
+ "n_sign_posn": ALL_TYPES["char"],
2440
+ "int_p_cs_precedes": ALL_TYPES["char"],
2441
+ "int_p_sep_by_space": ALL_TYPES["char"],
2442
+ "int_n_cs_precedes": ALL_TYPES["char"],
2443
+ "int_n_sep_by_space": ALL_TYPES["char"],
2444
+ "int_p_sign_posn": ALL_TYPES["char"],
2445
+ "int_n_sign_posn": ALL_TYPES["char"],
2446
+ },
2447
+ name="lconv",
2448
+ ),
2449
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/misc/search.h#L97
2450
+ "hsearch_data": SimStruct(
2451
+ {
2452
+ "table": SimTypePointer(ALL_TYPES["_ENTRY"], label="struct _ENTRY *"),
2453
+ "size": ALL_TYPES["unsigned int"],
2454
+ "filled": ALL_TYPES["unsigned int"],
2455
+ },
2456
+ name="hsearch_data",
2457
+ ),
2458
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/libio/bits/types/struct_FILE.h#L49
2459
+ "FILE_t": SimStruct(
2460
+ {
2461
+ "_flags": ALL_TYPES["int"],
2462
+ "_IO_read_ptr": SimTypePointer(ALL_TYPES["char"], label="char *"),
2463
+ "_IO_read_end": SimTypePointer(ALL_TYPES["char"], label="char *"),
2464
+ "_IO_read_base": SimTypePointer(ALL_TYPES["char"], label="char *"),
2465
+ "_IO_write_base": SimTypePointer(ALL_TYPES["char"], label="char *"),
2466
+ "_IO_write_ptr": SimTypePointer(ALL_TYPES["char"], label="char *"),
2467
+ "_IO_write_end": SimTypePointer(ALL_TYPES["char"], label="char *"),
2468
+ "_IO_buf_base": SimTypePointer(ALL_TYPES["char"], label="char *"),
2469
+ "_IO_buf_end": SimTypePointer(ALL_TYPES["char"], label="char *"),
2470
+ "_IO_save_base": SimTypePointer(ALL_TYPES["char"], label="char *"),
2471
+ "_IO_backup_base": SimTypePointer(ALL_TYPES["char"], label="char *"),
2472
+ "_IO_save_end": SimTypePointer(ALL_TYPES["char"], label="char *"),
2473
+ "_markers": SimTypePointer(ALL_TYPES["_IO_marker"]),
2474
+ "_chain": SimTypePointer(SimStruct({}, name="_IO_FILE"), label="struct _IO_FILE *"),
2475
+ "_fileno": ALL_TYPES["int"],
2476
+ "_flags2": ALL_TYPES["int"],
2477
+ "_old_offset": ALL_TYPES["__off_t"],
2478
+ "_cur_column": ALL_TYPES["unsigned short"],
2479
+ "_vtable_offset": ALL_TYPES["signed char"],
2480
+ "_shortbuf": SimTypeArray(ALL_TYPES["char"], length=1, label="char[1]"),
2481
+ "_lock": SimTypePointer(ALL_TYPES["_IO_lock_t"]),
2482
+ "_offset": ALL_TYPES["__off64_t"],
2483
+ "_codecvt": SimTypePointer(ALL_TYPES["_IO_codecvt"], label="struct _IO_codecvt *"),
2484
+ "_wide_data": SimTypePointer(ALL_TYPES["_IO_wide_data"], label="struct _IO_wide_data *"),
2485
+ "_freeres_list": SimTypePointer(SimStruct({}, name="_IO_FILE"), label="struct _IO_FILE *"),
2486
+ "__pad5": ALL_TYPES["size_t"],
2487
+ "_mode": ALL_TYPES["int"],
2488
+ "_unused2": SimTypeArray(
2489
+ ALL_TYPES["char"],
2490
+ length=20,
2491
+ label="char[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)]",
2492
+ ),
2493
+ },
2494
+ name="FILE_t",
2495
+ ),
2496
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/stdio-common/printf.h#L34
2497
+ "printf_info": SimStruct(
2498
+ {
2499
+ "prec": ALL_TYPES["int"],
2500
+ "width": ALL_TYPES["int"],
2501
+ "spec": ALL_TYPES["wchar_t"],
2502
+ "is_long_double": SimTypeNumOffset(1, signed=False, label="unsigned int"),
2503
+ "is_short": SimTypeNumOffset(1, signed=False, label="unsigned int"),
2504
+ "is_long": SimTypeNumOffset(1, signed=False, label="unsigned int"),
2505
+ "alt": SimTypeNumOffset(1, signed=False, label="unsigned int"),
2506
+ "space": SimTypeNumOffset(1, signed=False, label="unsigned int"),
2507
+ "left": SimTypeNumOffset(1, signed=False, label="unsigned int"),
2508
+ "showsign": SimTypeNumOffset(1, signed=False, label="unsigned int"),
2509
+ "group": SimTypeNumOffset(1, signed=False, label="unsigned int"),
2510
+ "extra": SimTypeNumOffset(1, signed=False, label="unsigned int"),
2511
+ "is_char": SimTypeNumOffset(1, signed=False, label="unsigned int"),
2512
+ "wide": SimTypeNumOffset(1, signed=False, label="unsigned int"),
2513
+ "i18n": SimTypeNumOffset(1, signed=False, label="unsigned int"),
2514
+ "is_binary128": SimTypeNumOffset(1, signed=False, label="unsigned int"),
2515
+ "__pad": SimTypeNumOffset(3, signed=False, label="unsigned int"),
2516
+ "user": ALL_TYPES["unsigned short int"],
2517
+ "pad": ALL_TYPES["wchar_t"],
2518
+ },
2519
+ name="printf_info",
2520
+ ),
2521
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/rt/aio.h#L34
2522
+ "aiocb": SimStruct(
2523
+ {
2524
+ "aio_filedes": ALL_TYPES["int"],
2525
+ "aio_lio_opcode": ALL_TYPES["int"],
2526
+ "aio_reqprio": ALL_TYPES["int"],
2527
+ "aio_buf": SimTypePointer(ALL_TYPES["void"], label="void *"),
2528
+ "aio_nbytes": ALL_TYPES["size_t"],
2529
+ "aio_sigevent": ALL_TYPES["sigevent"],
2530
+ "__next_prio": SimTypePointer(SimStruct({}, name="aiocb"), label="struct aiocb *"),
2531
+ "__abs_prio": ALL_TYPES["int"],
2532
+ "__policy": ALL_TYPES["int"],
2533
+ "__error_code": ALL_TYPES["int"],
2534
+ "__return_value": ALL_TYPES["ssize_t"],
2535
+ # TODO: This should be architecture dependent
2536
+ "aio_offset": ALL_TYPES["off_t"],
2537
+ "__glibc_reserved": SimTypeArray(ALL_TYPES["char"], length=32, label="char[32]"),
2538
+ },
2539
+ name="aiocb",
2540
+ ),
2541
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/rt/aio.h#L62
2542
+ "aiocb64": SimStruct(
2543
+ {
2544
+ "aio_filedes": ALL_TYPES["int"],
2545
+ "aio_lio_opcode": ALL_TYPES["int"],
2546
+ "aio_reqprio": ALL_TYPES["int"],
2547
+ "aio_buf": SimTypePointer(ALL_TYPES["void"], label="void *"),
2548
+ "aio_nbytes": ALL_TYPES["size_t"],
2549
+ "aio_sigevent": ALL_TYPES["sigevent"],
2550
+ "__next_prio": SimTypePointer(SimStruct({}, name="aiocb"), label="struct aiocb *"),
2551
+ "__abs_prio": ALL_TYPES["int"],
2552
+ "__policy": ALL_TYPES["int"],
2553
+ "__error_code": ALL_TYPES["int"],
2554
+ "__return_value": ALL_TYPES["ssize_t"],
2555
+ "aio_offset": ALL_TYPES["off64_t"],
2556
+ "__glibc_reserved": SimTypeArray(ALL_TYPES["char"], length=32, label="char[32]"),
2557
+ },
2558
+ name="aiocb64",
2559
+ ),
2560
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/rt/aio.h#L86
2561
+ "aioinit": SimStruct(
2562
+ {
2563
+ "aio_threads": ALL_TYPES["int"],
2564
+ "aio_num": ALL_TYPES["int"],
2565
+ "aio_locks": ALL_TYPES["int"],
2566
+ "aio_debug": ALL_TYPES["int"],
2567
+ "aio_numusers": ALL_TYPES["int"],
2568
+ "aio_idle_time": ALL_TYPES["int"],
2569
+ "aio_reserved": ALL_TYPES["int"],
2570
+ },
2571
+ name="aioinit",
2572
+ ),
2573
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/dirent.h#L23
2574
+ "dirent": SimStruct(
2575
+ {
2576
+ "d_ino": ALL_TYPES["ino_t"],
2577
+ "d_reclen": ALL_TYPES["unsigned short int"],
2578
+ "d_type": ALL_TYPES["unsigned char"],
2579
+ "d_namelen": ALL_TYPES["unsigned char"],
2580
+ "d_name": SimTypeArray(ALL_TYPES["char"], length=1, label="char[1]"),
2581
+ },
2582
+ name="dirent",
2583
+ ),
2584
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/dirent.h#L39
2585
+ "dirent64": SimStruct(
2586
+ {
2587
+ "d_ino": ALL_TYPES["ino64_t"],
2588
+ "d_reclen": ALL_TYPES["unsigned short int"],
2589
+ "d_type": ALL_TYPES["unsigned char"],
2590
+ "d_namelen": ALL_TYPES["unsigned char"],
2591
+ "d_name": SimTypeArray(ALL_TYPES["char"], length=1, label="char[1]"),
2592
+ },
2593
+ name="dirent64",
2594
+ ),
2595
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/stat.h#L31
2596
+ "stat": SimStruct(
2597
+ {
2598
+ "st_mode": ALL_TYPES["__mode_t"],
2599
+ # TODO: This should be architecture dependent
2600
+ "st_ino": ALL_TYPES["__ino_t"],
2601
+ "st_dev": ALL_TYPES["__dev_t"],
2602
+ "st_nlink": ALL_TYPES["__nlink_t"],
2603
+ "st_uid": ALL_TYPES["__uid_t"],
2604
+ "st_gid": ALL_TYPES["__gid_t"],
2605
+ # TODO: This should be architecture dependent
2606
+ "st_size": ALL_TYPES["__off_t"],
2607
+ "st_atime": ALL_TYPES["__time_t"],
2608
+ "st_mtime": ALL_TYPES["__time_t"],
2609
+ "st_ctime": ALL_TYPES["__time_t"],
2610
+ },
2611
+ name="stat",
2612
+ ),
2613
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/stat.h#L86
2614
+ "stat64": SimStruct(
2615
+ {
2616
+ "st_mode": ALL_TYPES["__mode_t"],
2617
+ # TODO: This should be architecture dependent
2618
+ "st_ino": ALL_TYPES["__ino64_t"],
2619
+ "st_dev": ALL_TYPES["__dev_t"],
2620
+ "st_nlink": ALL_TYPES["__nlink_t"],
2621
+ "st_uid": ALL_TYPES["__uid_t"],
2622
+ "st_gid": ALL_TYPES["__gid_t"],
2623
+ # TODO: This should be architecture dependent
2624
+ "st_size": ALL_TYPES["__off64_t"],
2625
+ "st_atime": ALL_TYPES["__time_t"],
2626
+ "st_mtime": ALL_TYPES["__time_t"],
2627
+ "st_ctime": ALL_TYPES["__time_t"],
2628
+ },
2629
+ name="stat64",
2630
+ ),
2631
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/io/utime.h#L36
2632
+ "utimbuf": SimStruct(
2633
+ {
2634
+ # TODO: This should be architecture dependent
2635
+ "actime": ALL_TYPES["__time_t"],
2636
+ "modtime": ALL_TYPES["__time_t"],
2637
+ },
2638
+ name="utimbuf",
2639
+ ),
2640
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/socket.h#L152
2641
+ "sockaddr": SimStruct(
2642
+ {
2643
+ "sin_family": ALL_TYPES["sa_family_t"],
2644
+ "sa_data": SimTypeArray(ALL_TYPES["char"], length=14, label="char[14]"),
2645
+ },
2646
+ name="sockaddr",
2647
+ ),
2648
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/inet/netinet/in.h#L245
2649
+ "sockaddr_in": SimStruct(
2650
+ {
2651
+ "sin_family": ALL_TYPES["sa_family_t"],
2652
+ "sin_port": ALL_TYPES["in_port_t"],
2653
+ "sin_addr": ALL_TYPES["in_addr"],
2654
+ "sin_zero": SimTypeArray(
2655
+ ALL_TYPES["unsigned char"],
2656
+ length=8,
2657
+ label=(
2658
+ "unsigned char[sizeof (struct sockaddr) - __SOCKADDR_COMMON_SIZE - "
2659
+ "sizeof (in_port_t) - sizeof (struct in_addr)]"
2660
+ ),
2661
+ ),
2662
+ },
2663
+ name="sockaddr_in",
2664
+ ),
2665
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/sysdeps/gnu/net/if.h#L33
2666
+ "if_nameindex": SimStruct(
2667
+ {
2668
+ "if_index": ALL_TYPES["unsigned int"],
2669
+ "if_name": SimTypePointer(ALL_TYPES["char"], label="char *"),
2670
+ },
2671
+ name="if_nameindex",
2672
+ ),
2673
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/resolv/netdb.h#L98
2674
+ "hostent": SimStruct(
2675
+ {
2676
+ "h_name": SimTypePointer(ALL_TYPES["char"], label="char *"),
2677
+ "h_aliases": SimTypePointer(SimTypePointer(ALL_TYPES["char"], label="char *"), label="char **"),
2678
+ "h_addrtype": ALL_TYPES["int"],
2679
+ "h_length": ALL_TYPES["int"],
2680
+ "h_addr_list": SimTypePointer(SimTypePointer(ALL_TYPES["char"], label="char *"), label="char **"),
2681
+ },
2682
+ name="hostent",
2683
+ ),
2684
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/resolv/netdb.h#L255
2685
+ "servent": SimStruct(
2686
+ {
2687
+ "s_name": SimTypePointer(ALL_TYPES["char"], label="char *"),
2688
+ "s_aliases": SimTypePointer(SimTypePointer(ALL_TYPES["char"], label="char *"), label="char **"),
2689
+ "s_port": ALL_TYPES["int"],
2690
+ "s_proto": SimTypePointer(ALL_TYPES["char"], label="char *"),
2691
+ },
2692
+ name="servent",
2693
+ ),
2694
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/resolv/netdb.h#L324
2695
+ "protoent": SimStruct(
2696
+ {
2697
+ "p_name": SimTypePointer(ALL_TYPES["char"], label="char *"),
2698
+ "p_aliases": SimTypePointer(SimTypePointer(ALL_TYPES["char"], label="char *"), label="char **"),
2699
+ "p_proto": ALL_TYPES["int"],
2700
+ },
2701
+ name="protoent",
2702
+ ),
2703
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/netdb.h#L26
2704
+ "netent": SimStruct(
2705
+ {
2706
+ "n_name": SimTypePointer(ALL_TYPES["char"], label="char *"),
2707
+ "n_aliases": SimTypePointer(SimTypePointer(ALL_TYPES["char"], label="char *"), label="char **"),
2708
+ "n_addrtype": ALL_TYPES["int"],
2709
+ "n_net": ALL_TYPES["uint32_t"],
2710
+ },
2711
+ name="netent",
2712
+ ),
2713
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/termios.h#L111
2714
+ "termios": SimStruct(
2715
+ {
2716
+ "c_iflag": ALL_TYPES["tcflag_t"],
2717
+ "c_oflag": ALL_TYPES["tcflag_t"],
2718
+ "c_cflag": ALL_TYPES["tcflag_t"],
2719
+ "c_lflag": ALL_TYPES["tcflag_t"],
2720
+ "c_cc": SimTypeArray(ALL_TYPES["cc_t"], length=20, label="cc_t[20]"),
2721
+ "__ispeed": ALL_TYPES["speed_t"],
2722
+ "__ospeed": ALL_TYPES["speed_t"],
2723
+ },
2724
+ name="termios",
2725
+ ),
2726
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/ioctl-types.h#L56
2727
+ "sgttyb": SimStruct(
2728
+ {
2729
+ "sg_ispeed": ALL_TYPES["char"],
2730
+ "sg_ospeed": ALL_TYPES["char"],
2731
+ "sg_erase": ALL_TYPES["char"],
2732
+ "sg_kill": ALL_TYPES["char"],
2733
+ "sg_flags": ALL_TYPES["short int"],
2734
+ },
2735
+ name="sgttyb",
2736
+ ),
2737
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/ioctl-types.h#L70
2738
+ "winsize": SimStruct(
2739
+ {
2740
+ "ws_row": ALL_TYPES["unsigned short int"],
2741
+ "ws_col": ALL_TYPES["unsigned short int"],
2742
+ "ws_xpixel": ALL_TYPES["unsigned short int"],
2743
+ "ws_ypixel": ALL_TYPES["unsigned short int"],
2744
+ },
2745
+ name="winsize",
2746
+ ),
2747
+ # This type is legitimately opaque
2748
+ "random_data": SimStruct({}),
2749
+ # This type is also legitimately opaque
2750
+ "drand48_data": SimStruct({}),
2751
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/posix/sys/times.h#L32
2752
+ "tms": SimStruct(
2753
+ {
2754
+ "tms_utime": ALL_TYPES["clock_t"],
2755
+ "tms_stime": ALL_TYPES["clock_t"],
2756
+ "tms_cutime": ALL_TYPES["clock_t"],
2757
+ "tms_cstime": ALL_TYPES["clock_t"],
2758
+ },
2759
+ name="tms",
2760
+ ),
2761
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/time/sys/time.h#L52
2762
+ "timezone": SimStruct(
2763
+ {
2764
+ "tz_minuteswest": ALL_TYPES["int"],
2765
+ "tz_dsttime": ALL_TYPES["int"],
2766
+ },
2767
+ name="timezone",
2768
+ ),
2769
+ "timeval": ALL_TYPES["timeval"],
2770
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/sysdeps/unix/sysv/linux/bits/timex.h#L26
2771
+ "timex": SimStruct(
2772
+ # TODO: This should be architecture dependent
2773
+ {
2774
+ "modes": ALL_TYPES["unsigned int"],
2775
+ "_pad0": ALL_TYPES["uint32_t"],
2776
+ "offset": ALL_TYPES["long long"],
2777
+ "freq": ALL_TYPES["long long"],
2778
+ "maxerror": ALL_TYPES["long long"],
2779
+ "esterror": ALL_TYPES["long long"],
2780
+ "status": ALL_TYPES["int"],
2781
+ "_pad1": ALL_TYPES["uint32_t"],
2782
+ "constant": ALL_TYPES["long long"],
2783
+ "precision": ALL_TYPES["long long"],
2784
+ "tolerance": ALL_TYPES["long long"],
2785
+ "time": ALL_TYPES["timeval"],
2786
+ "tick": ALL_TYPES["long long"],
2787
+ "ppsfreq": ALL_TYPES["long long"],
2788
+ "jitter": ALL_TYPES["long long"],
2789
+ "shift": ALL_TYPES["int"],
2790
+ "_pad2": ALL_TYPES["uint32_t"],
2791
+ "stabil": ALL_TYPES["long long"],
2792
+ "jitcnt": ALL_TYPES["long long"],
2793
+ "calcnt": ALL_TYPES["long long"],
2794
+ "errcnt": ALL_TYPES["long long"],
2795
+ "stbcnt": ALL_TYPES["long long"],
2796
+ "tai": ALL_TYPES["int"],
2797
+ "_pad3": SimTypeArray(ALL_TYPES["uint32_t"], length=11, label="int :32[11]"),
2798
+ },
2799
+ name="timex",
2800
+ ),
2801
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/time/bits/types/struct_tm.h#L7
2802
+ "tm": SimStruct(
2803
+ {
2804
+ "tm_sec": ALL_TYPES["int"],
2805
+ "tm_min": ALL_TYPES["int"],
2806
+ "tm_hour": ALL_TYPES["int"],
2807
+ "tm_mday": ALL_TYPES["int"],
2808
+ "tm_mon": ALL_TYPES["int"],
2809
+ "tm_year": ALL_TYPES["int"],
2810
+ "tm_wday": ALL_TYPES["int"],
2811
+ "tm_yday": ALL_TYPES["int"],
2812
+ "tm_isdst": ALL_TYPES["int"],
2813
+ "tm_gmtoff": ALL_TYPES["long int"],
2814
+ "tm_zone": SimTypePointer(ALL_TYPES["char"], label="char *"),
2815
+ },
2816
+ name="tm",
2817
+ ),
2818
+ # https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/sysdeps/unix/sysv/linux/sys/timex.h#L30
2819
+ "ntptimeval": SimStruct(
2820
+ {
2821
+ "time": ALL_TYPES["timeval"],
2822
+ "maxerror": ALL_TYPES["long int"],
2823
+ "esterror": ALL_TYPES["long int"],
2824
+ "tai": ALL_TYPES["long int"],
2825
+ "__glibc_reserved1": ALL_TYPES["long int"],
2826
+ "__glibc_reserved2": ALL_TYPES["long int"],
2827
+ "__glibc_reserved3": ALL_TYPES["long int"],
2828
+ "__glibc_reserved4": ALL_TYPES["long int"],
2829
+ },
2830
+ name="ntptimeval",
2831
+ ),
2832
+ # https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/misc/bits/types/struct_iovec.h#L26
2833
+ "iovec": SimStruct(
2834
+ {
2835
+ "iov_base": SimTypePointer(ALL_TYPES["void"], label="void *"),
2836
+ "iov_len": ALL_TYPES["size_t"],
2837
+ }
2838
+ ),
2839
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/time/sys/time.h#L130
2840
+ "itimerval": SimStruct(
2841
+ {
2842
+ "it_interval": ALL_TYPES["timeval"],
2843
+ "it_value": ALL_TYPES["timeval"],
2844
+ },
2845
+ name="itimerval",
2846
+ ),
2847
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/resource/bits/types/struct_rusage.h#L33
2848
+ "rusage": SimStruct(
2849
+ {
2850
+ "ru_utime": ALL_TYPES["timeval"],
2851
+ "ru_stime": ALL_TYPES["timeval"],
2852
+ "ru_maxrss": ALL_TYPES["long int"],
2853
+ "ru_ixrss": ALL_TYPES["long int"],
2854
+ "ru_idrss": ALL_TYPES["long int"],
2855
+ "ru_isrss": ALL_TYPES["long int"],
2856
+ "ru_minflt": ALL_TYPES["long int"],
2857
+ "ru_majflt": ALL_TYPES["long int"],
2858
+ "ru_nswap": ALL_TYPES["long int"],
2859
+ "ru_inblock": ALL_TYPES["long int"],
2860
+ "ru_oublock": ALL_TYPES["long int"],
2861
+ "ru_msgsnd": ALL_TYPES["long int"],
2862
+ "ru_msgrcv": ALL_TYPES["long int"],
2863
+ "ru_nsignals": ALL_TYPES["long int"],
2864
+ "ru_nvcsw": ALL_TYPES["long int"],
2865
+ "ru_nivcsw": ALL_TYPES["long int"],
2866
+ },
2867
+ name="rusage",
2868
+ ),
2869
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/resource/vtimes.c#L28
2870
+ "vtimes": SimStruct(
2871
+ {
2872
+ "vm_utime": ALL_TYPES["int"],
2873
+ "vm_stime": ALL_TYPES["int"],
2874
+ "vm_idsrss": ALL_TYPES["unsigned int"],
2875
+ "vm_ixrss": ALL_TYPES["unsigned int"],
2876
+ "vm_maxrss": ALL_TYPES["int"],
2877
+ "vm_maxflt": ALL_TYPES["int"],
2878
+ "vm_minflt": ALL_TYPES["int"],
2879
+ "vm_nswap": ALL_TYPES["int"],
2880
+ "vm_inblk": ALL_TYPES["int"],
2881
+ "vm_outblk": ALL_TYPES["int"],
2882
+ },
2883
+ name="vtimes",
2884
+ ),
2885
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/sysdeps/unix/sysv/linux/bits/resource.h#L139
2886
+ "rlimit": SimStruct(
2887
+ {
2888
+ "rlim_cur": ALL_TYPES["rlim_t"],
2889
+ "rlim_max": ALL_TYPES["rlim_t"],
2890
+ },
2891
+ name="rlimit",
2892
+ ),
2893
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/sysdeps/unix/sysv/linux/bits/resource.h#L148
2894
+ "rlimit64": SimStruct(
2895
+ {
2896
+ "rlim_cur": ALL_TYPES["rlim64_t"],
2897
+ "rlim_max": ALL_TYPES["rlim64_t"],
2898
+ },
2899
+ name="rlimit64",
2900
+ ),
2901
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/types/struct_sched_param.h#L23
2902
+ "sched_param": SimStruct(
2903
+ {"sched_priority": ALL_TYPES["int"]},
2904
+ name="sched_param",
2905
+ ),
2906
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/signal/bits/types/struct_sigstack.h#L23
2907
+ "sigstack": SimStruct(
2908
+ {
2909
+ "ss_sp": SimTypePointer(ALL_TYPES["void"], label="void *"),
2910
+ "ss_onstack": ALL_TYPES["int"],
2911
+ },
2912
+ name="sigstack",
2913
+ ),
2914
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/posix/bits/getopt_ext.h#L50
2915
+ "option": SimStruct(
2916
+ {
2917
+ "name": SimTypePointer(ALL_TYPES["char"], label="char *"),
2918
+ "has_arg": ALL_TYPES["int"],
2919
+ "flag": SimTypePointer(ALL_TYPES["int"], label="int *"),
2920
+ "val": ALL_TYPES["int"],
2921
+ },
2922
+ name="option",
2923
+ ),
2924
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/argp/argp.h#L273
2925
+ "argp_state": SimStruct(
2926
+ {
2927
+ "root_argp": ALL_TYPES["argp"],
2928
+ "argc": ALL_TYPES["int"],
2929
+ "argv": SimTypePointer(SimTypePointer(ALL_TYPES["char"], label="char *"), label="char **"),
2930
+ "next": ALL_TYPES["int"],
2931
+ "flags": ALL_TYPES["unsigned"],
2932
+ "arg_num": ALL_TYPES["unsigned"],
2933
+ "quoted": ALL_TYPES["int"],
2934
+ "input": SimTypePointer(ALL_TYPES["void"], label="void *"),
2935
+ "child_inputs": SimTypePointer(SimTypePointer(ALL_TYPES["void"], label="void *"), label="void **"),
2936
+ "hook": SimTypePointer(ALL_TYPES["void"], label="void *"),
2937
+ "name": SimTypePointer(ALL_TYPES["char"], label="char *"),
2938
+ "err_stream": SimStruct({}, name="FILE"),
2939
+ "pstate": SimTypePointer(ALL_TYPES["void"], label="void *"),
2940
+ },
2941
+ name="argp_state",
2942
+ ),
2943
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/sysvipc/sys/sem.h#L40
2944
+ "sembuf": SimStruct(
2945
+ {
2946
+ "sem_num": ALL_TYPES["unsigned short int"],
2947
+ "sem_op": ALL_TYPES["short int"],
2948
+ "sem_flg": ALL_TYPES["short int"],
2949
+ },
2950
+ name="sembuf",
2951
+ ),
2952
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/utmp.h#L58
2953
+ "utmp": SimStruct(
2954
+ {
2955
+ "ut_type": ALL_TYPES["short int"],
2956
+ "ut_pid": ALL_TYPES["pid_t"],
2957
+ "ut_line": SimTypeArray(ALL_TYPES["char"], length=32, label="char[32]"),
2958
+ "ut_id": SimTypeArray(ALL_TYPES["char"], length=4, label="char[32]"),
2959
+ "ut_user": SimTypeArray(ALL_TYPES["char"], length=32, label="char[32]"),
2960
+ "ut_host": SimTypeArray(ALL_TYPES["char"], length=256, label="char[32]"),
2961
+ "ut_exit": ALL_TYPES["exit_status"],
2962
+ "ut_session": ALL_TYPES["long int"],
2963
+ "ut_tv": ALL_TYPES["timeval"],
2964
+ "ut_addr_v6": SimTypeArray(ALL_TYPES["int32_t"], length=4, label="int32_t[4]"),
2965
+ "__glibc_reserved": SimTypeArray(ALL_TYPES["char"], length=20, label="char[20]"),
2966
+ },
2967
+ name="utmp",
2968
+ ),
2969
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/sysdeps/gnu/bits/utmpx.h#L55
2970
+ "utmpx": SimStruct(
2971
+ {
2972
+ "ut_type": ALL_TYPES["short int"],
2973
+ "ut_pid": ALL_TYPES["pid_t"],
2974
+ "ut_line": SimTypeArray(ALL_TYPES["char"], length=32, label="char[32]"),
2975
+ "ut_id": SimTypeArray(ALL_TYPES["char"], length=4, label="char[32]"),
2976
+ "ut_user": SimTypeArray(ALL_TYPES["char"], length=32, label="char[32]"),
2977
+ "ut_host": SimTypeArray(ALL_TYPES["char"], length=256, label="char[32]"),
2978
+ "ut_exit": ALL_TYPES["exit_status"],
2979
+ "ut_session": ALL_TYPES["long int"],
2980
+ "ut_tv": ALL_TYPES["timeval"],
2981
+ "ut_addr_v6": SimTypeArray(ALL_TYPES["int32_t"], length=4, label="int32_t[4]"),
2982
+ "__glibc_reserved": SimTypeArray(ALL_TYPES["char"], length=20, label="char[20]"),
2983
+ },
2984
+ name="utmx",
2985
+ ),
2986
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/pwd/pwd.h#L49
2987
+ "passwd": SimStruct(
2988
+ {
2989
+ "pw_name": SimTypePointer(ALL_TYPES["char"], label="char *"),
2990
+ "pw_passwd": SimTypePointer(ALL_TYPES["char"], label="char *"),
2991
+ "pw_uid": ALL_TYPES["__uid_t"],
2992
+ "pw_gid": ALL_TYPES["__gid_t"],
2993
+ "pw_gecos": SimTypePointer(ALL_TYPES["char"], label="char *"),
2994
+ "pw_dir": SimTypePointer(ALL_TYPES["char"], label="char *"),
2995
+ "pw_shell": SimTypePointer(ALL_TYPES["char"], label="char *"),
2996
+ },
2997
+ name="passwd",
2998
+ ),
2999
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/grp/grp.h#L42
3000
+ "group": SimStruct(
3001
+ {
3002
+ "gr_name": SimTypePointer(ALL_TYPES["char"], label="char *"),
3003
+ "gr_passwd": SimTypePointer(ALL_TYPES["char"], label="char *"),
3004
+ "gr_gid": ALL_TYPES["__gid_t"],
3005
+ "gr_mem": SimTypePointer(SimTypePointer(ALL_TYPES["char"], label="char *"), label="char **"),
3006
+ },
3007
+ name="group",
3008
+ ),
3009
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/posix/sys/utsname.h#L48
3010
+ "utsname": SimStruct(
3011
+ {
3012
+ "sysname": SimTypeArray(ALL_TYPES["char"], length=1024, label="char[1024]"),
3013
+ "nodename": SimTypeArray(ALL_TYPES["char"], length=1024, label="char[1024]"),
3014
+ "release": SimTypeArray(ALL_TYPES["char"], length=1024, label="char[1024]"),
3015
+ "version": SimTypeArray(ALL_TYPES["char"], length=1024, label="char[1024]"),
3016
+ "machine": SimTypeArray(ALL_TYPES["char"], length=1024, label="char[1024]"),
3017
+ "domain": SimTypeArray(ALL_TYPES["char"], length=1024, label="char[1024]"),
3018
+ },
3019
+ name="utsname",
3020
+ ),
3021
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/misc/fstab.h#L57
3022
+ "fstab": SimStruct(
3023
+ {
3024
+ "fs_spec": SimTypePointer(ALL_TYPES["char"], label="char *"),
3025
+ "fs_file": SimTypePointer(ALL_TYPES["char"], label="char *"),
3026
+ "fs_vfstype": SimTypePointer(ALL_TYPES["char"], label="char *"),
3027
+ "fs_mntops": SimTypePointer(ALL_TYPES["char"], label="char *"),
3028
+ "fs_type": SimTypePointer(ALL_TYPES["char"], label="char *"),
3029
+ "fs_freq": ALL_TYPES["int"],
3030
+ "fs_passno": ALL_TYPES["int"],
3031
+ },
3032
+ name="fstab",
3033
+ ),
3034
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/misc/mntent.h#L51
3035
+ "mntent": SimStruct(
3036
+ {
3037
+ "mnt_fsname": SimTypePointer(ALL_TYPES["char"], label="char *"),
3038
+ "mnt_dir": SimTypePointer(ALL_TYPES["char"], label="char *"),
3039
+ "mnt_type": SimTypePointer(ALL_TYPES["char"], label="char *"),
3040
+ "mnt_opts": SimTypePointer(ALL_TYPES["char"], label="char *"),
3041
+ "mnt_freq": ALL_TYPES["int"],
3042
+ "mnt_passno": ALL_TYPES["int"],
3043
+ },
3044
+ name="mntent",
3045
+ ),
3046
+ # https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/crypt/crypt.h#L43
3047
+ "crypt_data": SimStruct(
3048
+ {
3049
+ "keysched": SimTypeArray(ALL_TYPES["char"], length=16 * 8, label="char[16 * 8]"),
3050
+ "sb0": SimTypeArray(ALL_TYPES["char"], length=32768, label="char[32768]"),
3051
+ "sb1": SimTypeArray(ALL_TYPES["char"], length=32768, label="char[32768]"),
3052
+ "sb2": SimTypeArray(ALL_TYPES["char"], length=32768, label="char[32768]"),
3053
+ "sb3": SimTypeArray(ALL_TYPES["char"], length=32768, label="char[32768]"),
3054
+ "crypt_3_buf": SimTypeArray(ALL_TYPES["char"], length=14, label="char[14]"),
3055
+ "current_salt": SimTypeArray(ALL_TYPES["char"], length=2, label="char[2]"),
3056
+ "current_saltbits": ALL_TYPES["long int"],
3057
+ "direction": ALL_TYPES["int"],
3058
+ "initialized": ALL_TYPES["int"],
3059
+ },
3060
+ name="crypt_data",
3061
+ ),
3062
+ }
3063
+ ALL_TYPES.update(GLIBC_TYPES)
3064
+
3065
+
3066
+ def _make_scope(predefined_types=None):
3067
+ """
3068
+ Generate CParser scope_stack argument to parse method
3069
+ """
3070
+ all_types = ChainMap(predefined_types or {}, ALL_TYPES)
3071
+ scope = {}
3072
+ for ty in all_types:
3073
+ if ty in BASIC_TYPES:
3074
+ continue
3075
+ if " " in ty:
3076
+ continue
3077
+
3078
+ typ = all_types[ty]
3079
+ if type(typ) is TypeRef:
3080
+ typ = typ.type
3081
+ if isinstance(typ, (SimTypeFunction, SimTypeString, SimTypeWString)):
3082
+ continue
3083
+
3084
+ scope[ty] = True
3085
+ return [scope]
3086
+
3087
+
3088
+ def register_types(types):
3089
+ """
3090
+ Pass in some types and they will be registered to the global type store.
3091
+
3092
+ The argument may be either a mapping from name to SimType, or a plain SimType.
3093
+ The plain SimType must be either a struct or union type with a name present.
3094
+
3095
+ >>> register_types(parse_types("typedef int x; typedef float y;"))
3096
+ >>> register_types(parse_type("struct abcd { int ab; float cd; }"))
3097
+ """
3098
+ if type(types) is SimStruct:
3099
+ if types.name == "<anon>":
3100
+ raise ValueError("Cannot register anonymous struct")
3101
+ ALL_TYPES["struct " + types.name] = types
3102
+ elif type(types) is SimUnion:
3103
+ if types.name == "<anon>":
3104
+ raise ValueError("Cannot register anonymous union")
3105
+ ALL_TYPES["union " + types.name] = types
3106
+ else:
3107
+ ALL_TYPES.update(types)
3108
+
3109
+
3110
+ def do_preprocess(defn, include_path=()):
3111
+ """
3112
+ Run a string through the C preprocessor that ships with pycparser but is weirdly inaccessible?
3113
+ """
3114
+ from pycparser.ply import lex, cpp # pylint:disable=import-outside-toplevel
3115
+
3116
+ lexer = lex.lex(cpp)
3117
+ p = cpp.Preprocessor(lexer)
3118
+ for included in include_path:
3119
+ p.add_path(included)
3120
+ p.parse(defn)
3121
+ return "".join(tok.value for tok in p.parser if tok.type not in p.ignore)
3122
+
3123
+
3124
+ def parse_signature(defn, preprocess=True, predefined_types=None, arch=None):
3125
+ """
3126
+ Parse a single function prototype and return its type
3127
+ """
3128
+ try:
3129
+ parsed = parse_file(
3130
+ defn.strip(" \n\t;") + ";", preprocess=preprocess, predefined_types=predefined_types, arch=arch
3131
+ )
3132
+ return next(iter(parsed[0].values()))
3133
+ except StopIteration as e:
3134
+ raise ValueError("No declarations found") from e
3135
+
3136
+
3137
+ def parse_defns(defn, preprocess=True, predefined_types=None, arch=None):
3138
+ """
3139
+ Parse a series of C definitions, returns a mapping from variable name to variable type object
3140
+ """
3141
+ return parse_file(defn, preprocess=preprocess, predefined_types=predefined_types, arch=arch)[0]
3142
+
3143
+
3144
+ def parse_types(defn, preprocess=True, predefined_types=None, arch=None):
3145
+ """
3146
+ Parse a series of C definitions, returns a mapping from type name to type object
3147
+ """
3148
+ return parse_file(defn, preprocess=preprocess, predefined_types=predefined_types, arch=arch)[1]
3149
+
3150
+
3151
+ _include_re = re.compile(r"^\s*#include")
3152
+
3153
+
3154
+ def parse_file(defn, preprocess=True, predefined_types: dict[Any, SimType] | None = None, arch=None):
3155
+ """
3156
+ Parse a series of C definitions, returns a tuple of two type mappings, one for variable
3157
+ definitions and one for type definitions.
3158
+ """
3159
+ if pycparser is None:
3160
+ raise ImportError("Please install pycparser in order to parse C definitions")
3161
+
3162
+ defn = "\n".join(x for x in defn.split("\n") if _include_re.match(x) is None)
3163
+
3164
+ if preprocess:
3165
+ defn = do_preprocess(defn)
3166
+
3167
+ # pylint: disable=unexpected-keyword-arg
3168
+ node = pycparser.c_parser.CParser().parse(defn, scope_stack=_make_scope(predefined_types))
3169
+ if not isinstance(node, c_ast.FileAST):
3170
+ raise ValueError("Something went horribly wrong using pycparser")
3171
+ out = {}
3172
+ extra_types = {}
3173
+
3174
+ # populate extra_types
3175
+ if predefined_types:
3176
+ extra_types = dict(predefined_types)
3177
+
3178
+ for piece in node.ext:
3179
+ if isinstance(piece, c_ast.FuncDef):
3180
+ out[piece.decl.name] = _decl_to_type(piece.decl.type, extra_types, arch=arch)
3181
+ elif isinstance(piece, c_ast.Decl):
3182
+ ty = _decl_to_type(piece.type, extra_types, arch=arch)
3183
+ if piece.name is not None:
3184
+ out[piece.name] = ty
3185
+
3186
+ # Don't forget to update typedef types
3187
+ if isinstance(ty, (SimStruct, SimUnion)) and ty.name != "<anon>":
3188
+ for _, i in extra_types.items():
3189
+ if isinstance(i, type(ty)) and i.name == ty.name:
3190
+ if isinstance(ty, SimStruct):
3191
+ assert isinstance(i, SimStruct)
3192
+ i.fields = ty.fields
3193
+ else:
3194
+ assert isinstance(i, SimUnion)
3195
+ i.members = ty.members
3196
+
3197
+ elif isinstance(piece, c_ast.Typedef):
3198
+ extra_types[piece.name] = copy.copy(_decl_to_type(piece.type, extra_types, arch=arch))
3199
+ extra_types[piece.name].label = piece.name
3200
+
3201
+ return out, extra_types
3202
+
3203
+
3204
+ _type_parser_singleton = None
3205
+
3206
+
3207
+ def type_parser_singleton() -> pycparser.CParser:
3208
+ global _type_parser_singleton # pylint:disable=global-statement
3209
+ if pycparser is not None and _type_parser_singleton is None:
3210
+ _type_parser_singleton = pycparser.CParser()
3211
+ _type_parser_singleton.cparser = pycparser.ply.yacc.yacc(
3212
+ module=_type_parser_singleton,
3213
+ start="parameter_declaration",
3214
+ debug=False,
3215
+ optimize=False,
3216
+ errorlog=errorlog,
3217
+ )
3218
+ assert _type_parser_singleton is not None
3219
+ return _type_parser_singleton
3220
+
3221
+
3222
+ def parse_type(defn, preprocess=True, predefined_types=None, arch=None): # pylint:disable=unused-argument
3223
+ """
3224
+ Parse a simple type expression into a SimType
3225
+
3226
+ >>> parse_type('int *')
3227
+ """
3228
+ return parse_type_with_name(defn, preprocess=preprocess, predefined_types=predefined_types, arch=arch)[0]
3229
+
3230
+
3231
+ def parse_type_with_name(
3232
+ defn, preprocess=True, predefined_types: dict[Any, SimType] | None = None, arch=None
3233
+ ): # pylint:disable=unused-argument
3234
+ """
3235
+ Parse a simple type expression into a SimType, returning a tuple of the type object and any associated name
3236
+ that might be found in the place a name would go in a type declaration.
3237
+
3238
+ >>> parse_type_with_name('int *foo')
3239
+ """
3240
+ if pycparser is None:
3241
+ raise ImportError("Please install pycparser in order to parse C definitions")
3242
+
3243
+ if preprocess:
3244
+ defn = re.sub(r"/\*.*?\*/", r"", defn)
3245
+
3246
+ # pylint: disable=unexpected-keyword-arg
3247
+ node = type_parser_singleton().parse(text=defn, scope_stack=_make_scope(predefined_types))
3248
+ if not isinstance(node, c_ast.Typename) and not isinstance(node, c_ast.Decl):
3249
+ raise pycparser.c_parser.ParseError("Got an unexpected type out of pycparser")
3250
+
3251
+ decl = node.type
3252
+ extra_types = {} if not predefined_types else dict(predefined_types)
3253
+ return _decl_to_type(decl, extra_types=extra_types, arch=arch), node.name
3254
+
3255
+
3256
+ def _accepts_scope_stack():
3257
+ """
3258
+ pycparser hack to include scope_stack as parameter in CParser parse method
3259
+ """
3260
+
3261
+ def parse(self, text, filename="", debug=False, scope_stack=None):
3262
+ self.clex.filename = filename
3263
+ self.clex.reset_lineno()
3264
+ self._scope_stack = [{}] if scope_stack is None else scope_stack
3265
+ self._last_yielded_token = None
3266
+ return self.cparser.parse(input=text, lexer=self.clex, debug=debug)
3267
+
3268
+ pycparser.CParser.parse = parse
3269
+
3270
+
3271
+ def _decl_to_type(
3272
+ decl, extra_types: dict[str, SimType] | None = None, bitsize=None, arch: Arch | None = None
3273
+ ) -> SimType:
3274
+ if extra_types is None:
3275
+ extra_types = {}
3276
+
3277
+ if isinstance(decl, c_ast.FuncDecl):
3278
+ argtyps = (
3279
+ ()
3280
+ if decl.args is None
3281
+ else [
3282
+ (
3283
+ ...
3284
+ if type(x) is c_ast.EllipsisParam
3285
+ else (
3286
+ SimTypeBottom().with_arch(arch)
3287
+ if type(x) is c_ast.ID
3288
+ else _decl_to_type(x.type, extra_types, arch=arch)
3289
+ )
3290
+ )
3291
+ for x in decl.args.params
3292
+ ]
3293
+ )
3294
+ arg_names = (
3295
+ [arg.name for arg in decl.args.params if type(arg) is not c_ast.EllipsisParam] if decl.args else None
3296
+ )
3297
+ # special handling: func(void) is func()
3298
+ if (
3299
+ len(argtyps) == 1
3300
+ and isinstance(argtyps[0], SimTypeBottom)
3301
+ and arg_names is not None
3302
+ and arg_names[0] is None
3303
+ ):
3304
+ argtyps = ()
3305
+ arg_names = None
3306
+ if argtyps and argtyps[-1] is ...:
3307
+ argtyps.pop()
3308
+ variadic = True
3309
+ else:
3310
+ variadic = False
3311
+ r = SimTypeFunction(
3312
+ cast(list[SimType], argtyps),
3313
+ _decl_to_type(decl.type, extra_types, arch=arch),
3314
+ arg_names=arg_names,
3315
+ variadic=variadic,
3316
+ )
3317
+ r._arch = arch
3318
+ return r
3319
+
3320
+ if isinstance(decl, c_ast.TypeDecl):
3321
+ if decl.declname == "TOP":
3322
+ r = SimTypeTop()
3323
+ r._arch = arch
3324
+ return r
3325
+ return _decl_to_type(decl.type, extra_types, bitsize=bitsize, arch=arch)
3326
+
3327
+ if isinstance(decl, c_ast.PtrDecl):
3328
+ pts_to = _decl_to_type(decl.type, extra_types, arch=arch)
3329
+ r = SimTypePointer(pts_to)
3330
+ r._arch = arch
3331
+ return r
3332
+
3333
+ if isinstance(decl, c_ast.ArrayDecl):
3334
+ elem_type = _decl_to_type(decl.type, extra_types, arch=arch)
3335
+
3336
+ if decl.dim is None:
3337
+ r = SimTypeArray(elem_type)
3338
+ r._arch = arch
3339
+ return r
3340
+ try:
3341
+ size = _parse_const(decl.dim, extra_types=extra_types, arch=arch)
3342
+ except ValueError as e:
3343
+ l.warning("Got error parsing array dimension, defaulting to zero: %s", e)
3344
+ size = 0
3345
+ r = SimTypeFixedSizeArray(elem_type, size)
3346
+ r._arch = arch
3347
+ return r
3348
+
3349
+ if isinstance(decl, c_ast.Struct):
3350
+ if decl.decls is not None:
3351
+ fields = OrderedDict(
3352
+ (field.name, _decl_to_type(field.type, extra_types, bitsize=field.bitsize, arch=arch))
3353
+ for field in decl.decls
3354
+ )
3355
+ else:
3356
+ fields = OrderedDict()
3357
+
3358
+ if decl.name is not None:
3359
+ key = "struct " + decl.name
3360
+ struct = extra_types.get(key)
3361
+ from_global = False
3362
+ if struct is None:
3363
+ struct = ALL_TYPES.get(key)
3364
+ if struct is not None:
3365
+ from_global = True
3366
+ struct = struct.with_arch(arch)
3367
+ if struct is not None and not isinstance(struct, SimStruct):
3368
+ raise AngrTypeError("Provided a non-SimStruct value for a type that must be a struct")
3369
+
3370
+ if struct is None:
3371
+ struct = SimStruct(fields, decl.name)
3372
+ struct._arch = arch
3373
+ elif not struct.fields:
3374
+ struct.fields = fields
3375
+ elif fields and struct.fields != fields:
3376
+ if from_global:
3377
+ struct = SimStruct(fields, decl.name)
3378
+ struct._arch = arch
3379
+ else:
3380
+ raise ValueError("Redefining body of " + key)
3381
+
3382
+ extra_types[key] = struct
3383
+ else:
3384
+ struct = SimStruct(fields)
3385
+ struct._arch = arch
3386
+ return struct
3387
+
3388
+ if isinstance(decl, c_ast.Union):
3389
+ if decl.decls is not None:
3390
+ fields = {field.name: _decl_to_type(field.type, extra_types, arch=arch) for field in decl.decls}
3391
+ else:
3392
+ fields = {}
3393
+
3394
+ if decl.name is not None:
3395
+ key = "union " + decl.name
3396
+ union = extra_types.get(key)
3397
+ from_global = False
3398
+ if union is None and key in ALL_TYPES:
3399
+ union = ALL_TYPES[key]
3400
+ from_global = True
3401
+ if union is not None and not isinstance(union, SimUnion):
3402
+ raise AngrTypeError("Provided a non-SimUnion value for a type that must be a union")
3403
+
3404
+ if union is None:
3405
+ union = SimUnion(fields, decl.name)
3406
+ union._arch = arch
3407
+ elif not union.members:
3408
+ union.members = fields
3409
+ elif fields and union.members != fields:
3410
+ if from_global:
3411
+ union = SimStruct(fields, decl.name)
3412
+ union._arch = arch
3413
+ else:
3414
+ raise ValueError("Redefining body of " + key)
3415
+
3416
+ extra_types[key] = union
3417
+ else:
3418
+ union = SimUnion(fields)
3419
+ union._arch = arch
3420
+ return union
3421
+
3422
+ if isinstance(decl, c_ast.IdentifierType):
3423
+ key = " ".join(decl.names)
3424
+ if bitsize is not None:
3425
+ return SimTypeNumOffset(int(bitsize.value), signed=False)
3426
+ if key in extra_types:
3427
+ return extra_types[key]
3428
+ if key in ALL_TYPES:
3429
+ return ALL_TYPES[key].with_arch(arch)
3430
+ raise TypeError(f"Unknown type '{key}'")
3431
+
3432
+ if isinstance(decl, c_ast.Enum):
3433
+ # See C99 at 6.7.2.2
3434
+ return ALL_TYPES["int"].with_arch(arch)
3435
+
3436
+ raise ValueError("Unknown type!")
3437
+
3438
+
3439
+ def _parse_const(c, arch=None, extra_types=None):
3440
+ if type(c) is c_ast.Constant:
3441
+ return int(c.value, base=0)
3442
+ if type(c) is c_ast.BinaryOp:
3443
+ if c.op == "+":
3444
+ return _parse_const(c.children()[0][1], arch, extra_types) + _parse_const(
3445
+ c.children()[1][1], arch, extra_types
3446
+ )
3447
+ if c.op == "-":
3448
+ return _parse_const(c.children()[0][1], arch, extra_types) - _parse_const(
3449
+ c.children()[1][1], arch, extra_types
3450
+ )
3451
+ if c.op == "*":
3452
+ return _parse_const(c.children()[0][1], arch, extra_types) * _parse_const(
3453
+ c.children()[1][1], arch, extra_types
3454
+ )
3455
+ if c.op == "/":
3456
+ return _parse_const(c.children()[0][1], arch, extra_types) // _parse_const(
3457
+ c.children()[1][1], arch, extra_types
3458
+ )
3459
+ if c.op == "<<":
3460
+ return _parse_const(c.children()[0][1], arch, extra_types) << _parse_const(
3461
+ c.children()[1][1], arch, extra_types
3462
+ )
3463
+ if c.op == ">>":
3464
+ return _parse_const(c.children()[0][1], arch, extra_types) >> _parse_const(
3465
+ c.children()[1][1], arch, extra_types
3466
+ )
3467
+ raise ValueError(f"Binary op {c.op}")
3468
+ if type(c) is c_ast.UnaryOp:
3469
+ if c.op == "sizeof":
3470
+ return _decl_to_type(c.expr.type, extra_types=extra_types, arch=arch).size
3471
+ raise ValueError(f"Unary op {c.op}")
3472
+ if type(c) is c_ast.Cast:
3473
+ return _parse_const(c.expr, arch, extra_types)
3474
+ raise ValueError(c)
3475
+
3476
+
3477
+ CPP_DECL_TYPES = (
3478
+ cxxheaderparser.types.Method
3479
+ | cxxheaderparser.types.Array
3480
+ | cxxheaderparser.types.Pointer
3481
+ | cxxheaderparser.types.MoveReference
3482
+ | cxxheaderparser.types.Reference
3483
+ | cxxheaderparser.types.FunctionType
3484
+ | cxxheaderparser.types.Function
3485
+ | cxxheaderparser.types.Type
3486
+ )
3487
+
3488
+
3489
+ def _cpp_decl_to_type(
3490
+ decl: CPP_DECL_TYPES, extra_types: dict[str, SimType], opaque_classes: bool = True
3491
+ ) -> (
3492
+ SimTypeCppFunction
3493
+ | SimTypeFunction
3494
+ | SimCppClass
3495
+ | SimTypeReference
3496
+ | SimTypePointer
3497
+ | SimTypeArray
3498
+ | SimTypeBottom
3499
+ ):
3500
+ if cxxheaderparser is None:
3501
+ raise ImportError("Please install cxxheaderparser to parse C++ definitions")
3502
+ if isinstance(decl, cxxheaderparser.types.Method):
3503
+ the_func = decl
3504
+ func_name = the_func.name.format()
3505
+ # translate parameters
3506
+ args = []
3507
+ arg_names: list[str] = []
3508
+ for idx, param in enumerate(the_func.parameters):
3509
+ arg_type = param.type
3510
+ args.append(_cpp_decl_to_type(arg_type, extra_types, opaque_classes=opaque_classes))
3511
+ arg_name = param.name if param.name is not None else f"unknown_{idx}"
3512
+ arg_names.append(arg_name)
3513
+
3514
+ args = tuple(args)
3515
+ arg_names_tuple: tuple[str, ...] = tuple(arg_names)
3516
+
3517
+ # note that the constructor and destructor handling in cxxheaderparser is a bit weird and I could not get it to
3518
+ # work, hence the following hack
3519
+ ctor = dtor = False
3520
+ convention = the_func.msvc_convention
3521
+ if len(the_func.name.segments) >= 2:
3522
+ seg1, seg0 = the_func.name.segments[-2:]
3523
+ seg1 = seg1.format()
3524
+ seg0 = seg0.format()
3525
+ if seg0 == seg1:
3526
+ ctor = True
3527
+ if the_func.return_type is not None:
3528
+ convention = the_func.return_type.format() # it's usually just "__thiscall"
3529
+ elif seg0 == "~" + seg1:
3530
+ dtor = True
3531
+ if the_func.return_type is not None:
3532
+ convention = the_func.return_type.format() # it's usually just "__thiscall"
3533
+ # returns
3534
+ if the_func.return_type is None or ctor or dtor:
3535
+ returnty = SimTypeBottom()
3536
+ else:
3537
+ returnty = _cpp_decl_to_type(the_func.return_type, extra_types, opaque_classes=opaque_classes)
3538
+ return SimTypeCppFunction(
3539
+ args,
3540
+ returnty,
3541
+ label=func_name,
3542
+ arg_names=arg_names_tuple,
3543
+ ctor=ctor,
3544
+ dtor=dtor,
3545
+ convention=convention,
3546
+ )
3547
+
3548
+ if isinstance(decl, cxxheaderparser.types.Function):
3549
+ # a function declaration
3550
+ the_func = decl
3551
+ func_name = the_func.name.format()
3552
+ # translate parameters
3553
+ args = []
3554
+ arg_names: list[str] = []
3555
+ for idx, param in enumerate(the_func.parameters):
3556
+ arg_type = param.type
3557
+ args.append(_cpp_decl_to_type(arg_type, extra_types, opaque_classes=opaque_classes))
3558
+ arg_name = param.name if param.name is not None else f"unknown_{idx}"
3559
+ arg_names.append(arg_name)
3560
+
3561
+ args = tuple(args)
3562
+ arg_names_tuple: tuple[str, ...] = tuple(arg_names)
3563
+ # returns
3564
+ if the_func.return_type is None:
3565
+ returnty = SimTypeBottom()
3566
+ else:
3567
+ returnty = _cpp_decl_to_type(the_func.return_type, extra_types, opaque_classes=opaque_classes)
3568
+
3569
+ return SimTypeFunction(args, returnty, label=func_name, arg_names=arg_names_tuple)
3570
+
3571
+ if isinstance(decl, cxxheaderparser.types.Type):
3572
+ # attempt to parse it as one of the existing types
3573
+ lbl = decl.format()
3574
+ lbl = lbl.removeprefix("const ")
3575
+ if lbl in extra_types:
3576
+ t = extra_types[lbl]
3577
+ elif lbl in ALL_TYPES:
3578
+ t = ALL_TYPES[lbl]
3579
+ elif opaque_classes is True:
3580
+ # create a class without knowing the internal members
3581
+ t = SimCppClass(unique_name=lbl, name=lbl, members={}, size=32)
3582
+ else:
3583
+ raise TypeError(f'Unknown type "{lbl}"')
3584
+
3585
+ if isinstance(t, NamedTypeMixin):
3586
+ t = t.copy()
3587
+ t.name = lbl # pylint:disable=attribute-defined-outside-init
3588
+ return t # type:ignore
3589
+
3590
+ if isinstance(decl, cxxheaderparser.types.Array):
3591
+ subt = _cpp_decl_to_type(decl.array_of, extra_types, opaque_classes=opaque_classes)
3592
+ return SimTypeArray(subt, length=decl.size)
3593
+
3594
+ if isinstance(decl, cxxheaderparser.types.MoveReference):
3595
+ subt = _cpp_decl_to_type(decl.moveref_to, extra_types, opaque_classes=opaque_classes)
3596
+ return SimTypeReference(subt) # FIXME: Move reference vs reference
3597
+
3598
+ if isinstance(decl, cxxheaderparser.types.Reference):
3599
+ subt = _cpp_decl_to_type(decl.ref_to, extra_types, opaque_classes=opaque_classes)
3600
+ return SimTypeReference(subt)
3601
+
3602
+ if isinstance(decl, cxxheaderparser.types.Pointer):
3603
+ subt = _cpp_decl_to_type(decl.ptr_to, extra_types, opaque_classes=opaque_classes)
3604
+ return SimTypePointer(subt)
3605
+
3606
+ if isinstance(decl, cxxheaderparser.types.FunctionType):
3607
+ params = tuple(
3608
+ _cpp_decl_to_type(param.type, extra_types, opaque_classes=opaque_classes) for param in decl.parameters
3609
+ )
3610
+ param_names = (
3611
+ tuple(param.name.format() for param in decl.parameters) # type:ignore
3612
+ if all(param.name is not None for param in decl.parameters)
3613
+ else None
3614
+ )
3615
+ returnty = _cpp_decl_to_type(decl.return_type, extra_types, opaque_classes=opaque_classes)
3616
+ return SimTypeCppFunction(params, returnty, arg_names=param_names, convention=decl.msvc_convention)
3617
+
3618
+ raise NotImplementedError
3619
+
3620
+
3621
+ def normalize_cpp_function_name(name: str) -> str:
3622
+ # strip access specifiers
3623
+ prefixes = ["public:", "protected:", "private:"]
3624
+ for pre in prefixes:
3625
+ name = name.removeprefix(pre)
3626
+
3627
+ if name.startswith("operator"):
3628
+ # the return type is missing; give it a default type
3629
+ name = "int " + name
3630
+
3631
+ return name.removesuffix(";")
3632
+
3633
+
3634
+ def parse_cpp_file(cpp_decl, with_param_names: bool = False):
3635
+ #
3636
+ # A series of hacks to make cxxheaderparser happy with whatever C++ function prototypes we feed in
3637
+ #
3638
+
3639
+ if cxxheaderparser is None:
3640
+ raise ImportError("Please install cxxheaderparser to parse C++ definitions")
3641
+
3642
+ # CppHeaderParser does not support specialization
3643
+ s = normalize_cpp_function_name(cpp_decl)
3644
+
3645
+ # CppHeaderParser does not like missing function body
3646
+ s += "\n\n{}"
3647
+
3648
+ try:
3649
+ h = cxxheaderparser.simple.parse_string(s)
3650
+ except cxxheaderparser.errors.CxxParseError:
3651
+ # GCC-mangled (and thus, demangled) function names do not have return types encoded; let's try to prefix s with
3652
+ # "void" and try again
3653
+ s = "void " + s
3654
+ try:
3655
+ h = cxxheaderparser.simple.parse_string(s)
3656
+ except cxxheaderparser.errors.CxxParseError:
3657
+ # if it still fails, we give up
3658
+ return None, None
3659
+
3660
+ if not h.namespace:
3661
+ return None, None
3662
+
3663
+ func_decls: dict[str, SimTypeCppFunction | SimTypeFunction] = {}
3664
+ for the_func in h.namespace.functions + h.namespace.method_impls:
3665
+ # FIXME: We always assume that there is a "this" pointer but it is not the case for static methods.
3666
+ proto = cast(SimTypeCppFunction | SimTypeFunction | None, _cpp_decl_to_type(the_func, {}, opaque_classes=True))
3667
+ if proto is not None:
3668
+ func_name = the_func.name.format()
3669
+ if isinstance(proto, SimTypeCppFunction):
3670
+ proto.args = (
3671
+ SimTypePointer(pts_to=SimTypeBottom(label="void")),
3672
+ *proto.args,
3673
+ ) # pylint:disable=attribute-defined-outside-init
3674
+ proto.arg_names = ("this", *proto.arg_names) # pylint:disable=attribute-defined-outside-init
3675
+ func_decls[func_name] = proto
3676
+
3677
+ return func_decls, {}
3678
+
3679
+
3680
+ if pycparser is not None:
3681
+ _accepts_scope_stack()
3682
+
3683
+ with contextlib.suppress(ImportError):
3684
+ register_types(
3685
+ parse_types(
3686
+ """
3687
+ typedef long time_t;
3688
+
3689
+ struct timespec {
3690
+ time_t tv_sec;
3691
+ long tv_nsec;
3692
+ };
3693
+
3694
+ struct timeval {
3695
+ time_t tv_sec;
3696
+ long tv_usec;
3697
+ };
3698
+ """
3699
+ )
3700
+ )
3701
+
3702
+ from .state_plugins.view import SimMemView