angr 9.2.156__cp310-cp310-manylinux2014_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of angr might be problematic. Click here for more details.

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