angr 9.2.103__py3-none-manylinux2014_aarch64.whl

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

Potentially problematic release.


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

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