angr 9.2.166__cp310-abi3-manylinux_2_28_x86_64.whl

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

Potentially problematic release.


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

Files changed (1409) hide show
  1. angr/__init__.py +366 -0
  2. angr/__main__.py +152 -0
  3. angr/ailment/__init__.py +81 -0
  4. angr/ailment/block.py +81 -0
  5. angr/ailment/block_walker.py +845 -0
  6. angr/ailment/constant.py +3 -0
  7. angr/ailment/converter_common.py +11 -0
  8. angr/ailment/converter_pcode.py +623 -0
  9. angr/ailment/converter_vex.py +798 -0
  10. angr/ailment/expression.py +1655 -0
  11. angr/ailment/manager.py +33 -0
  12. angr/ailment/statement.py +978 -0
  13. angr/ailment/tagged_object.py +61 -0
  14. angr/ailment/utils.py +114 -0
  15. angr/analyses/__init__.py +113 -0
  16. angr/analyses/analysis.py +429 -0
  17. angr/analyses/backward_slice.py +686 -0
  18. angr/analyses/binary_optimizer.py +670 -0
  19. angr/analyses/bindiff.py +1512 -0
  20. angr/analyses/boyscout.py +76 -0
  21. angr/analyses/callee_cleanup_finder.py +74 -0
  22. angr/analyses/calling_convention/__init__.py +6 -0
  23. angr/analyses/calling_convention/calling_convention.py +1096 -0
  24. angr/analyses/calling_convention/fact_collector.py +636 -0
  25. angr/analyses/calling_convention/utils.py +60 -0
  26. angr/analyses/cdg.py +189 -0
  27. angr/analyses/cfg/__init__.py +23 -0
  28. angr/analyses/cfg/cfb.py +428 -0
  29. angr/analyses/cfg/cfg.py +74 -0
  30. angr/analyses/cfg/cfg_arch_options.py +95 -0
  31. angr/analyses/cfg/cfg_base.py +2909 -0
  32. angr/analyses/cfg/cfg_emulated.py +3451 -0
  33. angr/analyses/cfg/cfg_fast.py +5316 -0
  34. angr/analyses/cfg/cfg_fast_soot.py +662 -0
  35. angr/analyses/cfg/cfg_job_base.py +203 -0
  36. angr/analyses/cfg/indirect_jump_resolvers/__init__.py +28 -0
  37. angr/analyses/cfg/indirect_jump_resolvers/amd64_elf_got.py +62 -0
  38. angr/analyses/cfg/indirect_jump_resolvers/amd64_pe_iat.py +51 -0
  39. angr/analyses/cfg/indirect_jump_resolvers/arm_elf_fast.py +159 -0
  40. angr/analyses/cfg/indirect_jump_resolvers/const_resolver.py +339 -0
  41. angr/analyses/cfg/indirect_jump_resolvers/constant_value_manager.py +107 -0
  42. angr/analyses/cfg/indirect_jump_resolvers/default_resolvers.py +76 -0
  43. angr/analyses/cfg/indirect_jump_resolvers/jumptable.py +2367 -0
  44. angr/analyses/cfg/indirect_jump_resolvers/memload_resolver.py +81 -0
  45. angr/analyses/cfg/indirect_jump_resolvers/mips_elf_fast.py +286 -0
  46. angr/analyses/cfg/indirect_jump_resolvers/mips_elf_got.py +148 -0
  47. angr/analyses/cfg/indirect_jump_resolvers/propagator_utils.py +46 -0
  48. angr/analyses/cfg/indirect_jump_resolvers/resolver.py +74 -0
  49. angr/analyses/cfg/indirect_jump_resolvers/syscall_resolver.py +92 -0
  50. angr/analyses/cfg/indirect_jump_resolvers/x86_elf_pic_plt.py +88 -0
  51. angr/analyses/cfg/indirect_jump_resolvers/x86_pe_iat.py +47 -0
  52. angr/analyses/cfg_slice_to_sink/__init__.py +11 -0
  53. angr/analyses/cfg_slice_to_sink/cfg_slice_to_sink.py +117 -0
  54. angr/analyses/cfg_slice_to_sink/graph.py +87 -0
  55. angr/analyses/cfg_slice_to_sink/transitions.py +27 -0
  56. angr/analyses/class_identifier.py +63 -0
  57. angr/analyses/code_tagging.py +123 -0
  58. angr/analyses/codecave.py +77 -0
  59. angr/analyses/complete_calling_conventions.py +461 -0
  60. angr/analyses/congruency_check.py +377 -0
  61. angr/analyses/data_dep/__init__.py +16 -0
  62. angr/analyses/data_dep/data_dependency_analysis.py +595 -0
  63. angr/analyses/data_dep/dep_nodes.py +171 -0
  64. angr/analyses/data_dep/sim_act_location.py +49 -0
  65. angr/analyses/datagraph_meta.py +105 -0
  66. angr/analyses/ddg.py +1670 -0
  67. angr/analyses/decompiler/__init__.py +41 -0
  68. angr/analyses/decompiler/ail_simplifier.py +2085 -0
  69. angr/analyses/decompiler/ailgraph_walker.py +49 -0
  70. angr/analyses/decompiler/block_io_finder.py +302 -0
  71. angr/analyses/decompiler/block_similarity.py +196 -0
  72. angr/analyses/decompiler/block_simplifier.py +376 -0
  73. angr/analyses/decompiler/callsite_maker.py +571 -0
  74. angr/analyses/decompiler/ccall_rewriters/__init__.py +9 -0
  75. angr/analyses/decompiler/ccall_rewriters/amd64_ccalls.py +580 -0
  76. angr/analyses/decompiler/ccall_rewriters/rewriter_base.py +20 -0
  77. angr/analyses/decompiler/ccall_rewriters/x86_ccalls.py +313 -0
  78. angr/analyses/decompiler/clinic.py +3308 -0
  79. angr/analyses/decompiler/condition_processor.py +1281 -0
  80. angr/analyses/decompiler/counters/__init__.py +16 -0
  81. angr/analyses/decompiler/counters/boolean_counter.py +27 -0
  82. angr/analyses/decompiler/counters/call_counter.py +57 -0
  83. angr/analyses/decompiler/counters/expression_counters.py +77 -0
  84. angr/analyses/decompiler/counters/seq_cf_structure_counter.py +63 -0
  85. angr/analyses/decompiler/decompilation_cache.py +46 -0
  86. angr/analyses/decompiler/decompilation_options.py +275 -0
  87. angr/analyses/decompiler/decompiler.py +710 -0
  88. angr/analyses/decompiler/dephication/__init__.py +6 -0
  89. angr/analyses/decompiler/dephication/dephication_base.py +100 -0
  90. angr/analyses/decompiler/dephication/graph_dephication.py +70 -0
  91. angr/analyses/decompiler/dephication/graph_rewriting.py +112 -0
  92. angr/analyses/decompiler/dephication/graph_vvar_mapping.py +363 -0
  93. angr/analyses/decompiler/dephication/rewriting_engine.py +527 -0
  94. angr/analyses/decompiler/dephication/seqnode_dephication.py +156 -0
  95. angr/analyses/decompiler/empty_node_remover.py +212 -0
  96. angr/analyses/decompiler/expression_narrower.py +287 -0
  97. angr/analyses/decompiler/goto_manager.py +112 -0
  98. angr/analyses/decompiler/graph_region.py +426 -0
  99. angr/analyses/decompiler/jump_target_collector.py +37 -0
  100. angr/analyses/decompiler/jumptable_entry_condition_rewriter.py +67 -0
  101. angr/analyses/decompiler/label_collector.py +32 -0
  102. angr/analyses/decompiler/optimization_passes/__init__.py +151 -0
  103. angr/analyses/decompiler/optimization_passes/base_ptr_save_simplifier.py +157 -0
  104. angr/analyses/decompiler/optimization_passes/call_stmt_rewriter.py +46 -0
  105. angr/analyses/decompiler/optimization_passes/code_motion.py +362 -0
  106. angr/analyses/decompiler/optimization_passes/condition_constprop.py +219 -0
  107. angr/analyses/decompiler/optimization_passes/const_derefs.py +266 -0
  108. angr/analyses/decompiler/optimization_passes/const_prop_reverter.py +365 -0
  109. angr/analyses/decompiler/optimization_passes/cross_jump_reverter.py +106 -0
  110. angr/analyses/decompiler/optimization_passes/deadblock_remover.py +82 -0
  111. angr/analyses/decompiler/optimization_passes/determine_load_sizes.py +64 -0
  112. angr/analyses/decompiler/optimization_passes/div_simplifier.py +425 -0
  113. angr/analyses/decompiler/optimization_passes/duplication_reverter/__init__.py +5 -0
  114. angr/analyses/decompiler/optimization_passes/duplication_reverter/ail_merge_graph.py +503 -0
  115. angr/analyses/decompiler/optimization_passes/duplication_reverter/duplication_reverter.py +1218 -0
  116. angr/analyses/decompiler/optimization_passes/duplication_reverter/errors.py +16 -0
  117. angr/analyses/decompiler/optimization_passes/duplication_reverter/similarity.py +126 -0
  118. angr/analyses/decompiler/optimization_passes/duplication_reverter/utils.py +167 -0
  119. angr/analyses/decompiler/optimization_passes/eager_std_string_concatenation.py +165 -0
  120. angr/analyses/decompiler/optimization_passes/engine_base.py +500 -0
  121. angr/analyses/decompiler/optimization_passes/expr_op_swapper.py +135 -0
  122. angr/analyses/decompiler/optimization_passes/flip_boolean_cmp.py +113 -0
  123. angr/analyses/decompiler/optimization_passes/inlined_string_transformation_simplifier.py +615 -0
  124. angr/analyses/decompiler/optimization_passes/ite_expr_converter.py +224 -0
  125. angr/analyses/decompiler/optimization_passes/ite_region_converter.py +335 -0
  126. angr/analyses/decompiler/optimization_passes/lowered_switch_simplifier.py +923 -0
  127. angr/analyses/decompiler/optimization_passes/mod_simplifier.py +99 -0
  128. angr/analyses/decompiler/optimization_passes/optimization_pass.py +703 -0
  129. angr/analyses/decompiler/optimization_passes/register_save_area_simplifier.py +221 -0
  130. angr/analyses/decompiler/optimization_passes/ret_addr_save_simplifier.py +171 -0
  131. angr/analyses/decompiler/optimization_passes/ret_deduplicator.py +222 -0
  132. angr/analyses/decompiler/optimization_passes/return_duplicator_base.py +640 -0
  133. angr/analyses/decompiler/optimization_passes/return_duplicator_high.py +61 -0
  134. angr/analyses/decompiler/optimization_passes/return_duplicator_low.py +237 -0
  135. angr/analyses/decompiler/optimization_passes/stack_canary_simplifier.py +333 -0
  136. angr/analyses/decompiler/optimization_passes/switch_default_case_duplicator.py +149 -0
  137. angr/analyses/decompiler/optimization_passes/switch_reused_entry_rewriter.py +102 -0
  138. angr/analyses/decompiler/optimization_passes/tag_slicer.py +41 -0
  139. angr/analyses/decompiler/optimization_passes/win_stack_canary_simplifier.py +421 -0
  140. angr/analyses/decompiler/optimization_passes/x86_gcc_getpc_simplifier.py +88 -0
  141. angr/analyses/decompiler/peephole_optimizations/__init__.py +129 -0
  142. angr/analyses/decompiler/peephole_optimizations/a_div_const_add_a_mul_n_div_const.py +42 -0
  143. angr/analyses/decompiler/peephole_optimizations/a_mul_const_div_shr_const.py +38 -0
  144. angr/analyses/decompiler/peephole_optimizations/a_mul_const_sub_a.py +34 -0
  145. angr/analyses/decompiler/peephole_optimizations/a_shl_const_sub_a.py +34 -0
  146. angr/analyses/decompiler/peephole_optimizations/a_sub_a_div.py +25 -0
  147. angr/analyses/decompiler/peephole_optimizations/a_sub_a_shr_const_shr_const.py +37 -0
  148. angr/analyses/decompiler/peephole_optimizations/a_sub_a_sub_n.py +23 -0
  149. angr/analyses/decompiler/peephole_optimizations/arm_cmpf.py +236 -0
  150. angr/analyses/decompiler/peephole_optimizations/base.py +157 -0
  151. angr/analyses/decompiler/peephole_optimizations/basepointeroffset_add_n.py +34 -0
  152. angr/analyses/decompiler/peephole_optimizations/basepointeroffset_and_mask.py +36 -0
  153. angr/analyses/decompiler/peephole_optimizations/bitwise_or_to_logical_or.py +34 -0
  154. angr/analyses/decompiler/peephole_optimizations/bool_expr_xor_1.py +27 -0
  155. angr/analyses/decompiler/peephole_optimizations/bswap.py +142 -0
  156. angr/analyses/decompiler/peephole_optimizations/cas_intrinsics.py +115 -0
  157. angr/analyses/decompiler/peephole_optimizations/cmpord_rewriter.py +71 -0
  158. angr/analyses/decompiler/peephole_optimizations/coalesce_adjacent_shrs.py +39 -0
  159. angr/analyses/decompiler/peephole_optimizations/coalesce_same_cascading_ifs.py +28 -0
  160. angr/analyses/decompiler/peephole_optimizations/constant_derefs.py +44 -0
  161. angr/analyses/decompiler/peephole_optimizations/conv_a_sub0_shr_and.py +69 -0
  162. angr/analyses/decompiler/peephole_optimizations/conv_shl_shr.py +52 -0
  163. angr/analyses/decompiler/peephole_optimizations/eager_eval.py +447 -0
  164. angr/analyses/decompiler/peephole_optimizations/extended_byte_and_mask.py +56 -0
  165. angr/analyses/decompiler/peephole_optimizations/inlined_memcpy.py +78 -0
  166. angr/analyses/decompiler/peephole_optimizations/inlined_strcpy.py +217 -0
  167. angr/analyses/decompiler/peephole_optimizations/inlined_strcpy_consolidation.py +106 -0
  168. angr/analyses/decompiler/peephole_optimizations/inlined_wstrcpy.py +170 -0
  169. angr/analyses/decompiler/peephole_optimizations/invert_negated_logical_conjuction_disjunction.py +50 -0
  170. angr/analyses/decompiler/peephole_optimizations/modulo_simplifier.py +89 -0
  171. angr/analyses/decompiler/peephole_optimizations/one_sub_bool.py +33 -0
  172. angr/analyses/decompiler/peephole_optimizations/optimized_div_simplifier.py +356 -0
  173. angr/analyses/decompiler/peephole_optimizations/remove_cascading_conversions.py +45 -0
  174. angr/analyses/decompiler/peephole_optimizations/remove_cxx_destructor_calls.py +32 -0
  175. angr/analyses/decompiler/peephole_optimizations/remove_empty_if_body.py +46 -0
  176. angr/analyses/decompiler/peephole_optimizations/remove_noop_conversions.py +47 -0
  177. angr/analyses/decompiler/peephole_optimizations/remove_redundant_bitmasks.py +125 -0
  178. angr/analyses/decompiler/peephole_optimizations/remove_redundant_conversions.py +273 -0
  179. angr/analyses/decompiler/peephole_optimizations/remove_redundant_ite_branch.py +30 -0
  180. angr/analyses/decompiler/peephole_optimizations/remove_redundant_ite_comparisons.py +54 -0
  181. angr/analyses/decompiler/peephole_optimizations/remove_redundant_nots.py +36 -0
  182. angr/analyses/decompiler/peephole_optimizations/remove_redundant_reinterprets.py +44 -0
  183. angr/analyses/decompiler/peephole_optimizations/remove_redundant_shifts.py +95 -0
  184. angr/analyses/decompiler/peephole_optimizations/remove_redundant_shifts_around_comparators.py +44 -0
  185. angr/analyses/decompiler/peephole_optimizations/rewrite_bit_extractions.py +85 -0
  186. angr/analyses/decompiler/peephole_optimizations/rewrite_conv_mul.py +40 -0
  187. angr/analyses/decompiler/peephole_optimizations/rewrite_cxx_operator_calls.py +90 -0
  188. angr/analyses/decompiler/peephole_optimizations/rewrite_mips_gp_loads.py +49 -0
  189. angr/analyses/decompiler/peephole_optimizations/rol_ror.py +130 -0
  190. angr/analyses/decompiler/peephole_optimizations/sar_to_signed_div.py +143 -0
  191. angr/analyses/decompiler/peephole_optimizations/shl_to_mul.py +25 -0
  192. angr/analyses/decompiler/peephole_optimizations/simplify_pc_relative_loads.py +51 -0
  193. angr/analyses/decompiler/peephole_optimizations/single_bit_cond_to_boolexpr.py +82 -0
  194. angr/analyses/decompiler/peephole_optimizations/single_bit_xor.py +29 -0
  195. angr/analyses/decompiler/peephole_optimizations/tidy_stack_addr.py +131 -0
  196. angr/analyses/decompiler/peephole_optimizations/utils.py +18 -0
  197. angr/analyses/decompiler/presets/__init__.py +20 -0
  198. angr/analyses/decompiler/presets/basic.py +32 -0
  199. angr/analyses/decompiler/presets/fast.py +58 -0
  200. angr/analyses/decompiler/presets/full.py +68 -0
  201. angr/analyses/decompiler/presets/preset.py +37 -0
  202. angr/analyses/decompiler/redundant_label_remover.py +134 -0
  203. angr/analyses/decompiler/region_identifier.py +1239 -0
  204. angr/analyses/decompiler/region_simplifiers/__init__.py +5 -0
  205. angr/analyses/decompiler/region_simplifiers/cascading_cond_transformer.py +95 -0
  206. angr/analyses/decompiler/region_simplifiers/cascading_ifs.py +82 -0
  207. angr/analyses/decompiler/region_simplifiers/expr_folding.py +818 -0
  208. angr/analyses/decompiler/region_simplifiers/goto.py +178 -0
  209. angr/analyses/decompiler/region_simplifiers/if_.py +135 -0
  210. angr/analyses/decompiler/region_simplifiers/ifelse.py +91 -0
  211. angr/analyses/decompiler/region_simplifiers/loop.py +143 -0
  212. angr/analyses/decompiler/region_simplifiers/node_address_finder.py +24 -0
  213. angr/analyses/decompiler/region_simplifiers/region_simplifier.py +246 -0
  214. angr/analyses/decompiler/region_simplifiers/switch_cluster_simplifier.py +654 -0
  215. angr/analyses/decompiler/region_simplifiers/switch_expr_simplifier.py +87 -0
  216. angr/analyses/decompiler/region_walker.py +24 -0
  217. angr/analyses/decompiler/return_maker.py +72 -0
  218. angr/analyses/decompiler/seq_to_blocks.py +20 -0
  219. angr/analyses/decompiler/sequence_walker.py +257 -0
  220. angr/analyses/decompiler/ssailification/__init__.py +4 -0
  221. angr/analyses/decompiler/ssailification/rewriting.py +379 -0
  222. angr/analyses/decompiler/ssailification/rewriting_engine.py +1053 -0
  223. angr/analyses/decompiler/ssailification/rewriting_state.py +61 -0
  224. angr/analyses/decompiler/ssailification/ssailification.py +276 -0
  225. angr/analyses/decompiler/ssailification/traversal.py +124 -0
  226. angr/analyses/decompiler/ssailification/traversal_engine.py +306 -0
  227. angr/analyses/decompiler/ssailification/traversal_state.py +48 -0
  228. angr/analyses/decompiler/stack_item.py +36 -0
  229. angr/analyses/decompiler/structured_codegen/__init__.py +25 -0
  230. angr/analyses/decompiler/structured_codegen/base.py +132 -0
  231. angr/analyses/decompiler/structured_codegen/c.py +4082 -0
  232. angr/analyses/decompiler/structured_codegen/dummy.py +15 -0
  233. angr/analyses/decompiler/structured_codegen/dwarf_import.py +190 -0
  234. angr/analyses/decompiler/structuring/__init__.py +30 -0
  235. angr/analyses/decompiler/structuring/dream.py +1217 -0
  236. angr/analyses/decompiler/structuring/phoenix.py +3090 -0
  237. angr/analyses/decompiler/structuring/recursive_structurer.py +187 -0
  238. angr/analyses/decompiler/structuring/sailr.py +120 -0
  239. angr/analyses/decompiler/structuring/structurer_base.py +1066 -0
  240. angr/analyses/decompiler/structuring/structurer_nodes.py +440 -0
  241. angr/analyses/decompiler/utils.py +1118 -0
  242. angr/analyses/deobfuscator/__init__.py +18 -0
  243. angr/analyses/deobfuscator/api_obf_finder.py +325 -0
  244. angr/analyses/deobfuscator/api_obf_peephole_optimizer.py +51 -0
  245. angr/analyses/deobfuscator/api_obf_type2_finder.py +166 -0
  246. angr/analyses/deobfuscator/irsb_reg_collector.py +54 -0
  247. angr/analyses/deobfuscator/string_obf_finder.py +959 -0
  248. angr/analyses/deobfuscator/string_obf_opt_passes.py +133 -0
  249. angr/analyses/deobfuscator/string_obf_peephole_optimizer.py +47 -0
  250. angr/analyses/disassembly.py +1295 -0
  251. angr/analyses/disassembly_utils.py +101 -0
  252. angr/analyses/dominance_frontier.py +57 -0
  253. angr/analyses/fcp/__init__.py +4 -0
  254. angr/analyses/fcp/fcp.py +427 -0
  255. angr/analyses/find_objects_static.py +205 -0
  256. angr/analyses/flirt/__init__.py +47 -0
  257. angr/analyses/flirt/consts.py +160 -0
  258. angr/analyses/flirt/flirt.py +244 -0
  259. angr/analyses/flirt/flirt_function.py +20 -0
  260. angr/analyses/flirt/flirt_matcher.py +351 -0
  261. angr/analyses/flirt/flirt_module.py +32 -0
  262. angr/analyses/flirt/flirt_node.py +23 -0
  263. angr/analyses/flirt/flirt_sig.py +359 -0
  264. angr/analyses/flirt/flirt_utils.py +31 -0
  265. angr/analyses/forward_analysis/__init__.py +12 -0
  266. angr/analyses/forward_analysis/forward_analysis.py +530 -0
  267. angr/analyses/forward_analysis/job_info.py +64 -0
  268. angr/analyses/forward_analysis/visitors/__init__.py +14 -0
  269. angr/analyses/forward_analysis/visitors/call_graph.py +29 -0
  270. angr/analyses/forward_analysis/visitors/function_graph.py +86 -0
  271. angr/analyses/forward_analysis/visitors/graph.py +242 -0
  272. angr/analyses/forward_analysis/visitors/loop.py +29 -0
  273. angr/analyses/forward_analysis/visitors/single_node_graph.py +38 -0
  274. angr/analyses/identifier/__init__.py +5 -0
  275. angr/analyses/identifier/custom_callable.py +137 -0
  276. angr/analyses/identifier/errors.py +10 -0
  277. angr/analyses/identifier/func.py +60 -0
  278. angr/analyses/identifier/functions/__init__.py +37 -0
  279. angr/analyses/identifier/functions/atoi.py +73 -0
  280. angr/analyses/identifier/functions/based_atoi.py +125 -0
  281. angr/analyses/identifier/functions/fdprintf.py +123 -0
  282. angr/analyses/identifier/functions/free.py +64 -0
  283. angr/analyses/identifier/functions/int2str.py +287 -0
  284. angr/analyses/identifier/functions/malloc.py +111 -0
  285. angr/analyses/identifier/functions/memcmp.py +67 -0
  286. angr/analyses/identifier/functions/memcpy.py +89 -0
  287. angr/analyses/identifier/functions/memset.py +43 -0
  288. angr/analyses/identifier/functions/printf.py +123 -0
  289. angr/analyses/identifier/functions/recv_until.py +312 -0
  290. angr/analyses/identifier/functions/skip_calloc.py +73 -0
  291. angr/analyses/identifier/functions/skip_realloc.py +97 -0
  292. angr/analyses/identifier/functions/skip_recv_n.py +105 -0
  293. angr/analyses/identifier/functions/snprintf.py +112 -0
  294. angr/analyses/identifier/functions/sprintf.py +116 -0
  295. angr/analyses/identifier/functions/strcasecmp.py +33 -0
  296. angr/analyses/identifier/functions/strcmp.py +113 -0
  297. angr/analyses/identifier/functions/strcpy.py +43 -0
  298. angr/analyses/identifier/functions/strlen.py +27 -0
  299. angr/analyses/identifier/functions/strncmp.py +104 -0
  300. angr/analyses/identifier/functions/strncpy.py +65 -0
  301. angr/analyses/identifier/functions/strtol.py +89 -0
  302. angr/analyses/identifier/identify.py +825 -0
  303. angr/analyses/identifier/runner.py +360 -0
  304. angr/analyses/init_finder.py +289 -0
  305. angr/analyses/loop_analysis.py +349 -0
  306. angr/analyses/loopfinder.py +171 -0
  307. angr/analyses/patchfinder.py +137 -0
  308. angr/analyses/pathfinder.py +282 -0
  309. angr/analyses/propagator/__init__.py +5 -0
  310. angr/analyses/propagator/engine_base.py +62 -0
  311. angr/analyses/propagator/engine_vex.py +297 -0
  312. angr/analyses/propagator/propagator.py +361 -0
  313. angr/analyses/propagator/top_checker_mixin.py +218 -0
  314. angr/analyses/propagator/values.py +117 -0
  315. angr/analyses/propagator/vex_vars.py +68 -0
  316. angr/analyses/proximity_graph.py +444 -0
  317. angr/analyses/reaching_definitions/__init__.py +67 -0
  318. angr/analyses/reaching_definitions/call_trace.py +73 -0
  319. angr/analyses/reaching_definitions/dep_graph.py +433 -0
  320. angr/analyses/reaching_definitions/engine_ail.py +1130 -0
  321. angr/analyses/reaching_definitions/engine_vex.py +1127 -0
  322. angr/analyses/reaching_definitions/external_codeloc.py +0 -0
  323. angr/analyses/reaching_definitions/function_handler.py +638 -0
  324. angr/analyses/reaching_definitions/function_handler_library/__init__.py +12 -0
  325. angr/analyses/reaching_definitions/function_handler_library/stdio.py +269 -0
  326. angr/analyses/reaching_definitions/function_handler_library/stdlib.py +195 -0
  327. angr/analyses/reaching_definitions/function_handler_library/string.py +158 -0
  328. angr/analyses/reaching_definitions/function_handler_library/unistd.py +51 -0
  329. angr/analyses/reaching_definitions/heap_allocator.py +70 -0
  330. angr/analyses/reaching_definitions/rd_initializer.py +237 -0
  331. angr/analyses/reaching_definitions/rd_state.py +579 -0
  332. angr/analyses/reaching_definitions/reaching_definitions.py +581 -0
  333. angr/analyses/reaching_definitions/subject.py +65 -0
  334. angr/analyses/reassembler.py +2900 -0
  335. angr/analyses/s_liveness.py +203 -0
  336. angr/analyses/s_propagator.py +542 -0
  337. angr/analyses/s_reaching_definitions/__init__.py +12 -0
  338. angr/analyses/s_reaching_definitions/s_rda_model.py +136 -0
  339. angr/analyses/s_reaching_definitions/s_rda_view.py +316 -0
  340. angr/analyses/s_reaching_definitions/s_reaching_definitions.py +177 -0
  341. angr/analyses/smc.py +161 -0
  342. angr/analyses/soot_class_hierarchy.py +273 -0
  343. angr/analyses/stack_pointer_tracker.py +953 -0
  344. angr/analyses/static_hooker.py +53 -0
  345. angr/analyses/typehoon/__init__.py +5 -0
  346. angr/analyses/typehoon/dfa.py +118 -0
  347. angr/analyses/typehoon/lifter.py +122 -0
  348. angr/analyses/typehoon/simple_solver.py +1666 -0
  349. angr/analyses/typehoon/translator.py +279 -0
  350. angr/analyses/typehoon/typeconsts.py +338 -0
  351. angr/analyses/typehoon/typehoon.py +319 -0
  352. angr/analyses/typehoon/typevars.py +622 -0
  353. angr/analyses/typehoon/variance.py +11 -0
  354. angr/analyses/unpacker/__init__.py +6 -0
  355. angr/analyses/unpacker/obfuscation_detector.py +103 -0
  356. angr/analyses/unpacker/packing_detector.py +138 -0
  357. angr/analyses/variable_recovery/__init__.py +9 -0
  358. angr/analyses/variable_recovery/annotations.py +58 -0
  359. angr/analyses/variable_recovery/engine_ail.py +885 -0
  360. angr/analyses/variable_recovery/engine_base.py +1197 -0
  361. angr/analyses/variable_recovery/engine_vex.py +593 -0
  362. angr/analyses/variable_recovery/irsb_scanner.py +143 -0
  363. angr/analyses/variable_recovery/variable_recovery.py +574 -0
  364. angr/analyses/variable_recovery/variable_recovery_base.py +489 -0
  365. angr/analyses/variable_recovery/variable_recovery_fast.py +661 -0
  366. angr/analyses/veritesting.py +626 -0
  367. angr/analyses/vfg.py +1898 -0
  368. angr/analyses/vsa_ddg.py +420 -0
  369. angr/analyses/vtable.py +92 -0
  370. angr/analyses/xrefs.py +286 -0
  371. angr/angrdb/__init__.py +14 -0
  372. angr/angrdb/db.py +206 -0
  373. angr/angrdb/models.py +184 -0
  374. angr/angrdb/serializers/__init__.py +10 -0
  375. angr/angrdb/serializers/cfg_model.py +41 -0
  376. angr/angrdb/serializers/comments.py +60 -0
  377. angr/angrdb/serializers/funcs.py +61 -0
  378. angr/angrdb/serializers/kb.py +111 -0
  379. angr/angrdb/serializers/labels.py +59 -0
  380. angr/angrdb/serializers/loader.py +165 -0
  381. angr/angrdb/serializers/structured_code.py +125 -0
  382. angr/angrdb/serializers/variables.py +58 -0
  383. angr/angrdb/serializers/xrefs.py +48 -0
  384. angr/annocfg.py +317 -0
  385. angr/blade.py +431 -0
  386. angr/block.py +509 -0
  387. angr/callable.py +168 -0
  388. angr/calling_conventions.py +2580 -0
  389. angr/code_location.py +163 -0
  390. angr/codenode.py +145 -0
  391. angr/concretization_strategies/__init__.py +32 -0
  392. angr/concretization_strategies/any.py +17 -0
  393. angr/concretization_strategies/any_named.py +35 -0
  394. angr/concretization_strategies/base.py +81 -0
  395. angr/concretization_strategies/controlled_data.py +58 -0
  396. angr/concretization_strategies/eval.py +19 -0
  397. angr/concretization_strategies/logging.py +35 -0
  398. angr/concretization_strategies/max.py +25 -0
  399. angr/concretization_strategies/nonzero.py +16 -0
  400. angr/concretization_strategies/nonzero_range.py +22 -0
  401. angr/concretization_strategies/norepeats.py +37 -0
  402. angr/concretization_strategies/norepeats_range.py +37 -0
  403. angr/concretization_strategies/range.py +19 -0
  404. angr/concretization_strategies/signed_add.py +31 -0
  405. angr/concretization_strategies/single.py +15 -0
  406. angr/concretization_strategies/solutions.py +20 -0
  407. angr/concretization_strategies/unlimited_range.py +17 -0
  408. angr/distributed/__init__.py +9 -0
  409. angr/distributed/server.py +197 -0
  410. angr/distributed/worker.py +185 -0
  411. angr/emulator.py +143 -0
  412. angr/engines/__init__.py +67 -0
  413. angr/engines/concrete.py +66 -0
  414. angr/engines/engine.py +29 -0
  415. angr/engines/failure.py +27 -0
  416. angr/engines/hook.py +68 -0
  417. angr/engines/icicle.py +278 -0
  418. angr/engines/light/__init__.py +23 -0
  419. angr/engines/light/data.py +681 -0
  420. angr/engines/light/engine.py +1285 -0
  421. angr/engines/pcode/__init__.py +9 -0
  422. angr/engines/pcode/behavior.py +994 -0
  423. angr/engines/pcode/cc.py +128 -0
  424. angr/engines/pcode/emulate.py +440 -0
  425. angr/engines/pcode/engine.py +242 -0
  426. angr/engines/pcode/lifter.py +1420 -0
  427. angr/engines/procedure.py +70 -0
  428. angr/engines/soot/__init__.py +5 -0
  429. angr/engines/soot/engine.py +410 -0
  430. angr/engines/soot/exceptions.py +17 -0
  431. angr/engines/soot/expressions/__init__.py +87 -0
  432. angr/engines/soot/expressions/arrayref.py +22 -0
  433. angr/engines/soot/expressions/base.py +21 -0
  434. angr/engines/soot/expressions/binop.py +28 -0
  435. angr/engines/soot/expressions/cast.py +22 -0
  436. angr/engines/soot/expressions/condition.py +35 -0
  437. angr/engines/soot/expressions/constants.py +47 -0
  438. angr/engines/soot/expressions/instanceOf.py +15 -0
  439. angr/engines/soot/expressions/instancefieldref.py +8 -0
  440. angr/engines/soot/expressions/invoke.py +114 -0
  441. angr/engines/soot/expressions/length.py +8 -0
  442. angr/engines/soot/expressions/local.py +8 -0
  443. angr/engines/soot/expressions/new.py +16 -0
  444. angr/engines/soot/expressions/newArray.py +54 -0
  445. angr/engines/soot/expressions/newMultiArray.py +86 -0
  446. angr/engines/soot/expressions/paramref.py +8 -0
  447. angr/engines/soot/expressions/phi.py +30 -0
  448. angr/engines/soot/expressions/staticfieldref.py +8 -0
  449. angr/engines/soot/expressions/thisref.py +7 -0
  450. angr/engines/soot/expressions/unsupported.py +7 -0
  451. angr/engines/soot/field_dispatcher.py +46 -0
  452. angr/engines/soot/method_dispatcher.py +46 -0
  453. angr/engines/soot/statements/__init__.py +44 -0
  454. angr/engines/soot/statements/assign.py +30 -0
  455. angr/engines/soot/statements/base.py +79 -0
  456. angr/engines/soot/statements/goto.py +14 -0
  457. angr/engines/soot/statements/identity.py +15 -0
  458. angr/engines/soot/statements/if_.py +19 -0
  459. angr/engines/soot/statements/invoke.py +12 -0
  460. angr/engines/soot/statements/return_.py +20 -0
  461. angr/engines/soot/statements/switch.py +41 -0
  462. angr/engines/soot/statements/throw.py +15 -0
  463. angr/engines/soot/values/__init__.py +38 -0
  464. angr/engines/soot/values/arrayref.py +122 -0
  465. angr/engines/soot/values/base.py +7 -0
  466. angr/engines/soot/values/constants.py +18 -0
  467. angr/engines/soot/values/instancefieldref.py +44 -0
  468. angr/engines/soot/values/local.py +18 -0
  469. angr/engines/soot/values/paramref.py +18 -0
  470. angr/engines/soot/values/staticfieldref.py +38 -0
  471. angr/engines/soot/values/strref.py +38 -0
  472. angr/engines/soot/values/thisref.py +149 -0
  473. angr/engines/successors.py +654 -0
  474. angr/engines/syscall.py +51 -0
  475. angr/engines/unicorn.py +490 -0
  476. angr/engines/vex/__init__.py +20 -0
  477. angr/engines/vex/claripy/__init__.py +5 -0
  478. angr/engines/vex/claripy/ccall.py +2097 -0
  479. angr/engines/vex/claripy/datalayer.py +141 -0
  480. angr/engines/vex/claripy/irop.py +1276 -0
  481. angr/engines/vex/heavy/__init__.py +16 -0
  482. angr/engines/vex/heavy/actions.py +231 -0
  483. angr/engines/vex/heavy/concretizers.py +403 -0
  484. angr/engines/vex/heavy/dirty.py +466 -0
  485. angr/engines/vex/heavy/heavy.py +370 -0
  486. angr/engines/vex/heavy/inspect.py +52 -0
  487. angr/engines/vex/heavy/resilience.py +85 -0
  488. angr/engines/vex/heavy/super_fastpath.py +34 -0
  489. angr/engines/vex/lifter.py +420 -0
  490. angr/engines/vex/light/__init__.py +11 -0
  491. angr/engines/vex/light/light.py +551 -0
  492. angr/engines/vex/light/resilience.py +74 -0
  493. angr/engines/vex/light/slicing.py +52 -0
  494. angr/errors.py +609 -0
  495. angr/exploration_techniques/__init__.py +53 -0
  496. angr/exploration_techniques/base.py +126 -0
  497. angr/exploration_techniques/bucketizer.py +94 -0
  498. angr/exploration_techniques/common.py +56 -0
  499. angr/exploration_techniques/dfs.py +37 -0
  500. angr/exploration_techniques/director.py +520 -0
  501. angr/exploration_techniques/driller_core.py +100 -0
  502. angr/exploration_techniques/explorer.py +152 -0
  503. angr/exploration_techniques/lengthlimiter.py +22 -0
  504. angr/exploration_techniques/local_loop_seer.py +65 -0
  505. angr/exploration_techniques/loop_seer.py +236 -0
  506. angr/exploration_techniques/manual_mergepoint.py +82 -0
  507. angr/exploration_techniques/memory_watcher.py +43 -0
  508. angr/exploration_techniques/oppologist.py +92 -0
  509. angr/exploration_techniques/slicecutor.py +118 -0
  510. angr/exploration_techniques/spiller.py +280 -0
  511. angr/exploration_techniques/spiller_db.py +27 -0
  512. angr/exploration_techniques/stochastic.py +56 -0
  513. angr/exploration_techniques/stub_stasher.py +19 -0
  514. angr/exploration_techniques/suggestions.py +159 -0
  515. angr/exploration_techniques/tech_builder.py +49 -0
  516. angr/exploration_techniques/threading.py +69 -0
  517. angr/exploration_techniques/timeout.py +34 -0
  518. angr/exploration_techniques/tracer.py +1098 -0
  519. angr/exploration_techniques/unique.py +106 -0
  520. angr/exploration_techniques/veritesting.py +37 -0
  521. angr/factory.py +404 -0
  522. angr/flirt/__init__.py +97 -0
  523. angr/flirt/build_sig.py +305 -0
  524. angr/graph_utils.py +0 -0
  525. angr/keyed_region.py +525 -0
  526. angr/knowledge_base.py +143 -0
  527. angr/knowledge_plugins/__init__.py +43 -0
  528. angr/knowledge_plugins/callsite_prototypes.py +53 -0
  529. angr/knowledge_plugins/cfg/__init__.py +18 -0
  530. angr/knowledge_plugins/cfg/cfg_manager.py +95 -0
  531. angr/knowledge_plugins/cfg/cfg_model.py +1045 -0
  532. angr/knowledge_plugins/cfg/cfg_node.py +536 -0
  533. angr/knowledge_plugins/cfg/indirect_jump.py +65 -0
  534. angr/knowledge_plugins/cfg/memory_data.py +156 -0
  535. angr/knowledge_plugins/comments.py +16 -0
  536. angr/knowledge_plugins/custom_strings.py +38 -0
  537. angr/knowledge_plugins/data.py +22 -0
  538. angr/knowledge_plugins/debug_variables.py +216 -0
  539. angr/knowledge_plugins/functions/__init__.py +9 -0
  540. angr/knowledge_plugins/functions/function.py +1780 -0
  541. angr/knowledge_plugins/functions/function_manager.py +588 -0
  542. angr/knowledge_plugins/functions/function_parser.py +299 -0
  543. angr/knowledge_plugins/functions/soot_function.py +128 -0
  544. angr/knowledge_plugins/indirect_jumps.py +35 -0
  545. angr/knowledge_plugins/key_definitions/__init__.py +17 -0
  546. angr/knowledge_plugins/key_definitions/atoms.py +374 -0
  547. angr/knowledge_plugins/key_definitions/constants.py +29 -0
  548. angr/knowledge_plugins/key_definitions/definition.py +214 -0
  549. angr/knowledge_plugins/key_definitions/environment.py +96 -0
  550. angr/knowledge_plugins/key_definitions/heap_address.py +33 -0
  551. angr/knowledge_plugins/key_definitions/key_definition_manager.py +82 -0
  552. angr/knowledge_plugins/key_definitions/live_definitions.py +1010 -0
  553. angr/knowledge_plugins/key_definitions/liveness.py +165 -0
  554. angr/knowledge_plugins/key_definitions/rd_model.py +171 -0
  555. angr/knowledge_plugins/key_definitions/tag.py +78 -0
  556. angr/knowledge_plugins/key_definitions/undefined.py +70 -0
  557. angr/knowledge_plugins/key_definitions/unknown_size.py +86 -0
  558. angr/knowledge_plugins/key_definitions/uses.py +178 -0
  559. angr/knowledge_plugins/labels.py +110 -0
  560. angr/knowledge_plugins/obfuscations.py +37 -0
  561. angr/knowledge_plugins/patches.py +126 -0
  562. angr/knowledge_plugins/plugin.py +24 -0
  563. angr/knowledge_plugins/propagations/__init__.py +10 -0
  564. angr/knowledge_plugins/propagations/prop_value.py +191 -0
  565. angr/knowledge_plugins/propagations/propagation_manager.py +60 -0
  566. angr/knowledge_plugins/propagations/propagation_model.py +80 -0
  567. angr/knowledge_plugins/propagations/states.py +552 -0
  568. angr/knowledge_plugins/structured_code.py +63 -0
  569. angr/knowledge_plugins/types.py +88 -0
  570. angr/knowledge_plugins/variables/__init__.py +8 -0
  571. angr/knowledge_plugins/variables/variable_access.py +113 -0
  572. angr/knowledge_plugins/variables/variable_manager.py +1380 -0
  573. angr/knowledge_plugins/xrefs/__init__.py +12 -0
  574. angr/knowledge_plugins/xrefs/xref.py +150 -0
  575. angr/knowledge_plugins/xrefs/xref_manager.py +127 -0
  576. angr/knowledge_plugins/xrefs/xref_types.py +16 -0
  577. angr/misc/__init__.py +19 -0
  578. angr/misc/ansi.py +47 -0
  579. angr/misc/autoimport.py +90 -0
  580. angr/misc/bug_report.py +117 -0
  581. angr/misc/hookset.py +106 -0
  582. angr/misc/loggers.py +130 -0
  583. angr/misc/picklable_lock.py +46 -0
  584. angr/misc/plugins.py +289 -0
  585. angr/misc/telemetry.py +54 -0
  586. angr/misc/testing.py +24 -0
  587. angr/misc/ux.py +31 -0
  588. angr/procedures/__init__.py +12 -0
  589. angr/procedures/advapi32/__init__.py +0 -0
  590. angr/procedures/cgc/__init__.py +3 -0
  591. angr/procedures/cgc/_terminate.py +11 -0
  592. angr/procedures/cgc/allocate.py +75 -0
  593. angr/procedures/cgc/deallocate.py +67 -0
  594. angr/procedures/cgc/fdwait.py +65 -0
  595. angr/procedures/cgc/random.py +67 -0
  596. angr/procedures/cgc/receive.py +93 -0
  597. angr/procedures/cgc/transmit.py +65 -0
  598. angr/procedures/definitions/__init__.py +779 -0
  599. angr/procedures/definitions/cgc.py +20 -0
  600. angr/procedures/definitions/glibc.py +8372 -0
  601. angr/procedures/definitions/gnulib.py +32 -0
  602. angr/procedures/definitions/libstdcpp.py +21 -0
  603. angr/procedures/definitions/linux_kernel.py +6171 -0
  604. angr/procedures/definitions/linux_loader.py +7 -0
  605. angr/procedures/definitions/msvcr.py +16 -0
  606. angr/procedures/definitions/parse_syscalls_from_local_system.py +50 -0
  607. angr/procedures/definitions/parse_win32json.py +2553 -0
  608. angr/procedures/definitions/types_stl.py +22 -0
  609. angr/procedures/definitions/types_win32.py +34482 -0
  610. angr/procedures/definitions/wdk_api-ms-win-dx-d3dkmt-l1-1-4.py +30 -0
  611. angr/procedures/definitions/wdk_api-ms-win-dx-d3dkmt-l1-1-6.py +26 -0
  612. angr/procedures/definitions/wdk_clfs.py +140 -0
  613. angr/procedures/definitions/wdk_fltmgr.py +556 -0
  614. angr/procedures/definitions/wdk_fwpkclnt.py +30 -0
  615. angr/procedures/definitions/wdk_fwpuclnt.py +316 -0
  616. angr/procedures/definitions/wdk_gdi32.py +366 -0
  617. angr/procedures/definitions/wdk_hal.py +78 -0
  618. angr/procedures/definitions/wdk_ksecdd.py +62 -0
  619. angr/procedures/definitions/wdk_ndis.py +238 -0
  620. angr/procedures/definitions/wdk_ntoskrnl.py +3451 -0
  621. angr/procedures/definitions/wdk_offreg.py +72 -0
  622. angr/procedures/definitions/wdk_pshed.py +36 -0
  623. angr/procedures/definitions/wdk_secur32.py +40 -0
  624. angr/procedures/definitions/wdk_vhfum.py +34 -0
  625. angr/procedures/definitions/win32_aclui.py +30 -0
  626. angr/procedures/definitions/win32_activeds.py +68 -0
  627. angr/procedures/definitions/win32_advapi32.py +1684 -0
  628. angr/procedures/definitions/win32_advpack.py +124 -0
  629. angr/procedures/definitions/win32_amsi.py +38 -0
  630. angr/procedures/definitions/win32_api-ms-win-appmodel-runtime-l1-1-1.py +44 -0
  631. angr/procedures/definitions/win32_api-ms-win-appmodel-runtime-l1-1-3.py +34 -0
  632. angr/procedures/definitions/win32_api-ms-win-appmodel-runtime-l1-1-6.py +26 -0
  633. angr/procedures/definitions/win32_api-ms-win-core-apiquery-l2-1-0.py +26 -0
  634. angr/procedures/definitions/win32_api-ms-win-core-backgroundtask-l1-1-0.py +26 -0
  635. angr/procedures/definitions/win32_api-ms-win-core-comm-l1-1-1.py +26 -0
  636. angr/procedures/definitions/win32_api-ms-win-core-comm-l1-1-2.py +26 -0
  637. angr/procedures/definitions/win32_api-ms-win-core-enclave-l1-1-1.py +30 -0
  638. angr/procedures/definitions/win32_api-ms-win-core-errorhandling-l1-1-3.py +26 -0
  639. angr/procedures/definitions/win32_api-ms-win-core-featurestaging-l1-1-0.py +34 -0
  640. angr/procedures/definitions/win32_api-ms-win-core-featurestaging-l1-1-1.py +26 -0
  641. angr/procedures/definitions/win32_api-ms-win-core-file-fromapp-l1-1-0.py +46 -0
  642. angr/procedures/definitions/win32_api-ms-win-core-handle-l1-1-0.py +26 -0
  643. angr/procedures/definitions/win32_api-ms-win-core-ioring-l1-1-0.py +48 -0
  644. angr/procedures/definitions/win32_api-ms-win-core-marshal-l1-1-0.py +32 -0
  645. angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-3.py +32 -0
  646. angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-4.py +26 -0
  647. angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-5.py +30 -0
  648. angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-6.py +32 -0
  649. angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-7.py +28 -0
  650. angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-8.py +30 -0
  651. angr/procedures/definitions/win32_api-ms-win-core-path-l1-1-0.py +68 -0
  652. angr/procedures/definitions/win32_api-ms-win-core-psm-appnotify-l1-1-0.py +28 -0
  653. angr/procedures/definitions/win32_api-ms-win-core-psm-appnotify-l1-1-1.py +28 -0
  654. angr/procedures/definitions/win32_api-ms-win-core-realtime-l1-1-1.py +30 -0
  655. angr/procedures/definitions/win32_api-ms-win-core-realtime-l1-1-2.py +30 -0
  656. angr/procedures/definitions/win32_api-ms-win-core-slapi-l1-1-0.py +26 -0
  657. angr/procedures/definitions/win32_api-ms-win-core-state-helpers-l1-1-0.py +26 -0
  658. angr/procedures/definitions/win32_api-ms-win-core-synch-l1-2-0.py +30 -0
  659. angr/procedures/definitions/win32_api-ms-win-core-sysinfo-l1-2-0.py +26 -0
  660. angr/procedures/definitions/win32_api-ms-win-core-sysinfo-l1-2-3.py +28 -0
  661. angr/procedures/definitions/win32_api-ms-win-core-sysinfo-l1-2-4.py +28 -0
  662. angr/procedures/definitions/win32_api-ms-win-core-sysinfo-l1-2-6.py +26 -0
  663. angr/procedures/definitions/win32_api-ms-win-core-util-l1-1-1.py +28 -0
  664. angr/procedures/definitions/win32_api-ms-win-core-winrt-error-l1-1-0.py +44 -0
  665. angr/procedures/definitions/win32_api-ms-win-core-winrt-error-l1-1-1.py +38 -0
  666. angr/procedures/definitions/win32_api-ms-win-core-winrt-l1-1-0.py +40 -0
  667. angr/procedures/definitions/win32_api-ms-win-core-winrt-registration-l1-1-0.py +24 -0
  668. angr/procedures/definitions/win32_api-ms-win-core-winrt-robuffer-l1-1-0.py +24 -0
  669. angr/procedures/definitions/win32_api-ms-win-core-winrt-roparameterizediid-l1-1-0.py +28 -0
  670. angr/procedures/definitions/win32_api-ms-win-core-winrt-string-l1-1-0.py +76 -0
  671. angr/procedures/definitions/win32_api-ms-win-core-winrt-string-l1-1-1.py +24 -0
  672. angr/procedures/definitions/win32_api-ms-win-core-wow64-l1-1-1.py +30 -0
  673. angr/procedures/definitions/win32_api-ms-win-devices-query-l1-1-0.py +42 -0
  674. angr/procedures/definitions/win32_api-ms-win-devices-query-l1-1-1.py +34 -0
  675. angr/procedures/definitions/win32_api-ms-win-dx-d3dkmt-l1-1-0.py +26 -0
  676. angr/procedures/definitions/win32_api-ms-win-gaming-deviceinformation-l1-1-0.py +26 -0
  677. angr/procedures/definitions/win32_api-ms-win-gaming-expandedresources-l1-1-0.py +30 -0
  678. angr/procedures/definitions/win32_api-ms-win-gaming-tcui-l1-1-0.py +38 -0
  679. angr/procedures/definitions/win32_api-ms-win-gaming-tcui-l1-1-1.py +28 -0
  680. angr/procedures/definitions/win32_api-ms-win-gaming-tcui-l1-1-2.py +38 -0
  681. angr/procedures/definitions/win32_api-ms-win-gaming-tcui-l1-1-3.py +28 -0
  682. angr/procedures/definitions/win32_api-ms-win-gaming-tcui-l1-1-4.py +40 -0
  683. angr/procedures/definitions/win32_api-ms-win-mm-misc-l1-1-1.py +26 -0
  684. angr/procedures/definitions/win32_api-ms-win-net-isolation-l1-1-0.py +40 -0
  685. angr/procedures/definitions/win32_api-ms-win-security-base-l1-2-2.py +26 -0
  686. angr/procedures/definitions/win32_api-ms-win-security-isolatedcontainer-l1-1-0.py +26 -0
  687. angr/procedures/definitions/win32_api-ms-win-security-isolatedcontainer-l1-1-1.py +26 -0
  688. angr/procedures/definitions/win32_api-ms-win-service-core-l1-1-3.py +26 -0
  689. angr/procedures/definitions/win32_api-ms-win-service-core-l1-1-4.py +26 -0
  690. angr/procedures/definitions/win32_api-ms-win-service-core-l1-1-5.py +28 -0
  691. angr/procedures/definitions/win32_api-ms-win-shcore-scaling-l1-1-0.py +30 -0
  692. angr/procedures/definitions/win32_api-ms-win-shcore-scaling-l1-1-1.py +36 -0
  693. angr/procedures/definitions/win32_api-ms-win-shcore-scaling-l1-1-2.py +26 -0
  694. angr/procedures/definitions/win32_api-ms-win-shcore-stream-winrt-l1-1-0.py +28 -0
  695. angr/procedures/definitions/win32_api-ms-win-wsl-api-l1-1-0.py +38 -0
  696. angr/procedures/definitions/win32_apphelp.py +26 -0
  697. angr/procedures/definitions/win32_authz.py +90 -0
  698. angr/procedures/definitions/win32_avicap32.py +32 -0
  699. angr/procedures/definitions/win32_avifil32.py +144 -0
  700. angr/procedures/definitions/win32_avrt.py +52 -0
  701. angr/procedures/definitions/win32_bcp47mrm.py +28 -0
  702. angr/procedures/definitions/win32_bcrypt.py +130 -0
  703. angr/procedures/definitions/win32_bcryptprimitives.py +28 -0
  704. angr/procedures/definitions/win32_bluetoothapis.py +106 -0
  705. angr/procedures/definitions/win32_bthprops.py +34 -0
  706. angr/procedures/definitions/win32_bthprops_cpl.py +36 -0
  707. angr/procedures/definitions/win32_cabinet.py +68 -0
  708. angr/procedures/definitions/win32_certadm.py +60 -0
  709. angr/procedures/definitions/win32_certpoleng.py +40 -0
  710. angr/procedures/definitions/win32_cfgmgr32.py +502 -0
  711. angr/procedures/definitions/win32_chakra.py +198 -0
  712. angr/procedures/definitions/win32_cldapi.py +96 -0
  713. angr/procedures/definitions/win32_clfsw32.py +142 -0
  714. angr/procedures/definitions/win32_clusapi.py +584 -0
  715. angr/procedures/definitions/win32_comctl32.py +254 -0
  716. angr/procedures/definitions/win32_comdlg32.py +66 -0
  717. angr/procedures/definitions/win32_compstui.py +32 -0
  718. angr/procedures/definitions/win32_computecore.py +132 -0
  719. angr/procedures/definitions/win32_computenetwork.py +110 -0
  720. angr/procedures/definitions/win32_computestorage.py +48 -0
  721. angr/procedures/definitions/win32_comsvcs.py +38 -0
  722. angr/procedures/definitions/win32_coremessaging.py +24 -0
  723. angr/procedures/definitions/win32_credui.py +62 -0
  724. angr/procedures/definitions/win32_crypt32.py +482 -0
  725. angr/procedures/definitions/win32_cryptnet.py +34 -0
  726. angr/procedures/definitions/win32_cryptui.py +44 -0
  727. angr/procedures/definitions/win32_cryptxml.py +62 -0
  728. angr/procedures/definitions/win32_cscapi.py +32 -0
  729. angr/procedures/definitions/win32_d2d1.py +50 -0
  730. angr/procedures/definitions/win32_d3d10.py +78 -0
  731. angr/procedures/definitions/win32_d3d10_1.py +28 -0
  732. angr/procedures/definitions/win32_d3d11.py +30 -0
  733. angr/procedures/definitions/win32_d3d12.py +40 -0
  734. angr/procedures/definitions/win32_d3d9.py +46 -0
  735. angr/procedures/definitions/win32_d3dcompiler_47.py +76 -0
  736. angr/procedures/definitions/win32_d3dcsx.py +42 -0
  737. angr/procedures/definitions/win32_davclnt.py +60 -0
  738. angr/procedures/definitions/win32_dbgeng.py +32 -0
  739. angr/procedures/definitions/win32_dbghelp.py +462 -0
  740. angr/procedures/definitions/win32_dbgmodel.py +26 -0
  741. angr/procedures/definitions/win32_dciman32.py +64 -0
  742. angr/procedures/definitions/win32_dcomp.py +48 -0
  743. angr/procedures/definitions/win32_ddraw.py +38 -0
  744. angr/procedures/definitions/win32_deviceaccess.py +26 -0
  745. angr/procedures/definitions/win32_dflayout.py +26 -0
  746. angr/procedures/definitions/win32_dhcpcsvc.py +54 -0
  747. angr/procedures/definitions/win32_dhcpcsvc6.py +36 -0
  748. angr/procedures/definitions/win32_dhcpsapi.py +416 -0
  749. angr/procedures/definitions/win32_diagnosticdataquery.py +94 -0
  750. angr/procedures/definitions/win32_dinput8.py +26 -0
  751. angr/procedures/definitions/win32_directml.py +28 -0
  752. angr/procedures/definitions/win32_dmprocessxmlfiltered.py +26 -0
  753. angr/procedures/definitions/win32_dnsapi.py +152 -0
  754. angr/procedures/definitions/win32_drt.py +56 -0
  755. angr/procedures/definitions/win32_drtprov.py +42 -0
  756. angr/procedures/definitions/win32_drttransport.py +28 -0
  757. angr/procedures/definitions/win32_dsound.py +44 -0
  758. angr/procedures/definitions/win32_dsparse.py +62 -0
  759. angr/procedures/definitions/win32_dsprop.py +38 -0
  760. angr/procedures/definitions/win32_dssec.py +32 -0
  761. angr/procedures/definitions/win32_dsuiext.py +32 -0
  762. angr/procedures/definitions/win32_dwmapi.py +86 -0
  763. angr/procedures/definitions/win32_dwrite.py +26 -0
  764. angr/procedures/definitions/win32_dxcompiler.py +28 -0
  765. angr/procedures/definitions/win32_dxcore.py +26 -0
  766. angr/procedures/definitions/win32_dxgi.py +36 -0
  767. angr/procedures/definitions/win32_dxva2.py +100 -0
  768. angr/procedures/definitions/win32_eappcfg.py +52 -0
  769. angr/procedures/definitions/win32_eappprxy.py +60 -0
  770. angr/procedures/definitions/win32_efswrt.py +28 -0
  771. angr/procedures/definitions/win32_elscore.py +34 -0
  772. angr/procedures/definitions/win32_esent.py +482 -0
  773. angr/procedures/definitions/win32_evr.py +38 -0
  774. angr/procedures/definitions/win32_faultrep.py +32 -0
  775. angr/procedures/definitions/win32_fhsvcctl.py +38 -0
  776. angr/procedures/definitions/win32_firewallapi.py +30 -0
  777. angr/procedures/definitions/win32_fltlib.py +80 -0
  778. angr/procedures/definitions/win32_fontsub.py +28 -0
  779. angr/procedures/definitions/win32_forceinline.py +30 -0
  780. angr/procedures/definitions/win32_fwpuclnt.py +408 -0
  781. angr/procedures/definitions/win32_fxsutility.py +28 -0
  782. angr/procedures/definitions/win32_gdi32.py +886 -0
  783. angr/procedures/definitions/win32_gdiplus.py +1282 -0
  784. angr/procedures/definitions/win32_glu32.py +128 -0
  785. angr/procedures/definitions/win32_gpedit.py +36 -0
  786. angr/procedures/definitions/win32_hhctrl_ocx.py +28 -0
  787. angr/procedures/definitions/win32_hid.py +114 -0
  788. angr/procedures/definitions/win32_hlink.py +80 -0
  789. angr/procedures/definitions/win32_hrtfapo.py +26 -0
  790. angr/procedures/definitions/win32_httpapi.py +110 -0
  791. angr/procedures/definitions/win32_icm32.py +66 -0
  792. angr/procedures/definitions/win32_icmui.py +28 -0
  793. angr/procedures/definitions/win32_icu.py +2074 -0
  794. angr/procedures/definitions/win32_ieframe.py +82 -0
  795. angr/procedures/definitions/win32_imagehlp.py +76 -0
  796. angr/procedures/definitions/win32_imgutil.py +42 -0
  797. angr/procedures/definitions/win32_imm32.py +188 -0
  798. angr/procedures/definitions/win32_infocardapi.py +58 -0
  799. angr/procedures/definitions/win32_inkobjcore.py +78 -0
  800. angr/procedures/definitions/win32_iphlpapi.py +426 -0
  801. angr/procedures/definitions/win32_iscsidsc.py +182 -0
  802. angr/procedures/definitions/win32_isolatedwindowsenvironmentutils.py +28 -0
  803. angr/procedures/definitions/win32_kernel32.py +3185 -0
  804. angr/procedures/definitions/win32_kernelbase.py +36 -0
  805. angr/procedures/definitions/win32_keycredmgr.py +32 -0
  806. angr/procedures/definitions/win32_ksproxy_ax.py +36 -0
  807. angr/procedures/definitions/win32_ksuser.py +40 -0
  808. angr/procedures/definitions/win32_ktmw32.py +102 -0
  809. angr/procedures/definitions/win32_licenseprotection.py +28 -0
  810. angr/procedures/definitions/win32_loadperf.py +48 -0
  811. angr/procedures/definitions/win32_magnification.py +62 -0
  812. angr/procedures/definitions/win32_mapi32.py +156 -0
  813. angr/procedures/definitions/win32_mdmlocalmanagement.py +30 -0
  814. angr/procedures/definitions/win32_mdmregistration.py +54 -0
  815. angr/procedures/definitions/win32_mf.py +148 -0
  816. angr/procedures/definitions/win32_mfcore.py +28 -0
  817. angr/procedures/definitions/win32_mfplat.py +314 -0
  818. angr/procedures/definitions/win32_mfplay.py +26 -0
  819. angr/procedures/definitions/win32_mfreadwrite.py +34 -0
  820. angr/procedures/definitions/win32_mfsensorgroup.py +44 -0
  821. angr/procedures/definitions/win32_mfsrcsnk.py +28 -0
  822. angr/procedures/definitions/win32_mgmtapi.py +42 -0
  823. angr/procedures/definitions/win32_mi.py +26 -0
  824. angr/procedures/definitions/win32_mmdevapi.py +26 -0
  825. angr/procedures/definitions/win32_mpr.py +118 -0
  826. angr/procedures/definitions/win32_mprapi.py +248 -0
  827. angr/procedures/definitions/win32_mqrt.py +92 -0
  828. angr/procedures/definitions/win32_mrmsupport.py +78 -0
  829. angr/procedures/definitions/win32_msacm32.py +108 -0
  830. angr/procedures/definitions/win32_msajapi.py +1118 -0
  831. angr/procedures/definitions/win32_mscms.py +182 -0
  832. angr/procedures/definitions/win32_mscoree.py +78 -0
  833. angr/procedures/definitions/win32_msctfmonitor.py +30 -0
  834. angr/procedures/definitions/win32_msdelta.py +56 -0
  835. angr/procedures/definitions/win32_msdmo.py +46 -0
  836. angr/procedures/definitions/win32_msdrm.py +192 -0
  837. angr/procedures/definitions/win32_msi.py +552 -0
  838. angr/procedures/definitions/win32_msimg32.py +30 -0
  839. angr/procedures/definitions/win32_mspatcha.py +56 -0
  840. angr/procedures/definitions/win32_mspatchc.py +42 -0
  841. angr/procedures/definitions/win32_msports.py +38 -0
  842. angr/procedures/definitions/win32_msrating.py +62 -0
  843. angr/procedures/definitions/win32_mssign32.py +44 -0
  844. angr/procedures/definitions/win32_mstask.py +28 -0
  845. angr/procedures/definitions/win32_msvfw32.py +110 -0
  846. angr/procedures/definitions/win32_mswsock.py +56 -0
  847. angr/procedures/definitions/win32_mtxdm.py +26 -0
  848. angr/procedures/definitions/win32_ncrypt.py +102 -0
  849. angr/procedures/definitions/win32_ndfapi.py +56 -0
  850. angr/procedures/definitions/win32_netapi32.py +436 -0
  851. angr/procedures/definitions/win32_netsh.py +40 -0
  852. angr/procedures/definitions/win32_netshell.py +28 -0
  853. angr/procedures/definitions/win32_newdev.py +46 -0
  854. angr/procedures/definitions/win32_ninput.py +84 -0
  855. angr/procedures/definitions/win32_normaliz.py +28 -0
  856. angr/procedures/definitions/win32_ntdll.py +171 -0
  857. angr/procedures/definitions/win32_ntdllk.py +26 -0
  858. angr/procedures/definitions/win32_ntdsapi.py +186 -0
  859. angr/procedures/definitions/win32_ntlanman.py +44 -0
  860. angr/procedures/definitions/win32_odbc32.py +392 -0
  861. angr/procedures/definitions/win32_odbcbcp.py +78 -0
  862. angr/procedures/definitions/win32_ole32.py +658 -0
  863. angr/procedures/definitions/win32_oleacc.py +58 -0
  864. angr/procedures/definitions/win32_oleaut32.py +834 -0
  865. angr/procedures/definitions/win32_oledlg.py +70 -0
  866. angr/procedures/definitions/win32_ondemandconnroutehelper.py +34 -0
  867. angr/procedures/definitions/win32_opengl32.py +734 -0
  868. angr/procedures/definitions/win32_opmxbox.py +30 -0
  869. angr/procedures/definitions/win32_p2p.py +240 -0
  870. angr/procedures/definitions/win32_p2pgraph.py +98 -0
  871. angr/procedures/definitions/win32_pdh.py +220 -0
  872. angr/procedures/definitions/win32_peerdist.py +80 -0
  873. angr/procedures/definitions/win32_powrprof.py +192 -0
  874. angr/procedures/definitions/win32_prntvpt.py +46 -0
  875. angr/procedures/definitions/win32_projectedfslib.py +62 -0
  876. angr/procedures/definitions/win32_propsys.py +460 -0
  877. angr/procedures/definitions/win32_psapi.py +78 -0
  878. angr/procedures/definitions/win32_quartz.py +28 -0
  879. angr/procedures/definitions/win32_query.py +32 -0
  880. angr/procedures/definitions/win32_qwave.py +46 -0
  881. angr/procedures/definitions/win32_rasapi32.py +192 -0
  882. angr/procedures/definitions/win32_rasdlg.py +36 -0
  883. angr/procedures/definitions/win32_resutils.py +264 -0
  884. angr/procedures/definitions/win32_rometadata.py +24 -0
  885. angr/procedures/definitions/win32_rpcns4.py +146 -0
  886. angr/procedures/definitions/win32_rpcproxy.py +32 -0
  887. angr/procedures/definitions/win32_rpcrt4.py +918 -0
  888. angr/procedures/definitions/win32_rstrtmgr.py +46 -0
  889. angr/procedures/definitions/win32_rtm.py +176 -0
  890. angr/procedures/definitions/win32_rtutils.py +106 -0
  891. angr/procedures/definitions/win32_rtworkq.py +90 -0
  892. angr/procedures/definitions/win32_sas.py +26 -0
  893. angr/procedures/definitions/win32_scarddlg.py +34 -0
  894. angr/procedures/definitions/win32_schannel.py +42 -0
  895. angr/procedures/definitions/win32_sechost.py +28 -0
  896. angr/procedures/definitions/win32_secur32.py +202 -0
  897. angr/procedures/definitions/win32_sensapi.py +30 -0
  898. angr/procedures/definitions/win32_sensorsutilsv2.py +104 -0
  899. angr/procedures/definitions/win32_setupapi.py +692 -0
  900. angr/procedures/definitions/win32_sfc.py +36 -0
  901. angr/procedures/definitions/win32_shdocvw.py +30 -0
  902. angr/procedures/definitions/win32_shell32.py +512 -0
  903. angr/procedures/definitions/win32_shlwapi.py +744 -0
  904. angr/procedures/definitions/win32_slc.py +88 -0
  905. angr/procedures/definitions/win32_slcext.py +32 -0
  906. angr/procedures/definitions/win32_slwga.py +26 -0
  907. angr/procedures/definitions/win32_snmpapi.py +76 -0
  908. angr/procedures/definitions/win32_spoolss.py +76 -0
  909. angr/procedures/definitions/win32_srclient.py +26 -0
  910. angr/procedures/definitions/win32_srpapi.py +46 -0
  911. angr/procedures/definitions/win32_sspicli.py +38 -0
  912. angr/procedures/definitions/win32_sti.py +26 -0
  913. angr/procedures/definitions/win32_t2embed.py +52 -0
  914. angr/procedures/definitions/win32_tapi32.py +522 -0
  915. angr/procedures/definitions/win32_tbs.py +52 -0
  916. angr/procedures/definitions/win32_tdh.py +78 -0
  917. angr/procedures/definitions/win32_tokenbinding.py +44 -0
  918. angr/procedures/definitions/win32_traffic.py +64 -0
  919. angr/procedures/definitions/win32_txfw32.py +42 -0
  920. angr/procedures/definitions/win32_ualapi.py +32 -0
  921. angr/procedures/definitions/win32_uiautomationcore.py +220 -0
  922. angr/procedures/definitions/win32_urlmon.py +178 -0
  923. angr/procedures/definitions/win32_user32.py +1551 -0
  924. angr/procedures/definitions/win32_userenv.py +112 -0
  925. angr/procedures/definitions/win32_usp10.py +104 -0
  926. angr/procedures/definitions/win32_uxtheme.py +178 -0
  927. angr/procedures/definitions/win32_verifier.py +26 -0
  928. angr/procedures/definitions/win32_version.py +52 -0
  929. angr/procedures/definitions/win32_vertdll.py +38 -0
  930. angr/procedures/definitions/win32_virtdisk.py +82 -0
  931. angr/procedures/definitions/win32_vmdevicehost.py +50 -0
  932. angr/procedures/definitions/win32_vmsavedstatedumpprovider.py +110 -0
  933. angr/procedures/definitions/win32_vssapi.py +26 -0
  934. angr/procedures/definitions/win32_wcmapi.py +34 -0
  935. angr/procedures/definitions/win32_wdsbp.py +38 -0
  936. angr/procedures/definitions/win32_wdsclientapi.py +98 -0
  937. angr/procedures/definitions/win32_wdsmc.py +36 -0
  938. angr/procedures/definitions/win32_wdspxe.py +86 -0
  939. angr/procedures/definitions/win32_wdstptc.py +50 -0
  940. angr/procedures/definitions/win32_webauthn.py +50 -0
  941. angr/procedures/definitions/win32_webservices.py +410 -0
  942. angr/procedures/definitions/win32_websocket.py +50 -0
  943. angr/procedures/definitions/win32_wecapi.py +54 -0
  944. angr/procedures/definitions/win32_wer.py +66 -0
  945. angr/procedures/definitions/win32_wevtapi.py +94 -0
  946. angr/procedures/definitions/win32_winbio.py +132 -0
  947. angr/procedures/definitions/win32_windows_ai_machinelearning.py +26 -0
  948. angr/procedures/definitions/win32_windows_data_pdf.py +24 -0
  949. angr/procedures/definitions/win32_windows_media_mediacontrol.py +40 -0
  950. angr/procedures/definitions/win32_windows_networking.py +26 -0
  951. angr/procedures/definitions/win32_windows_ui_xaml.py +28 -0
  952. angr/procedures/definitions/win32_windowscodecs.py +42 -0
  953. angr/procedures/definitions/win32_winfax.py +136 -0
  954. angr/procedures/definitions/win32_winhttp.py +136 -0
  955. angr/procedures/definitions/win32_winhvemulation.py +32 -0
  956. angr/procedures/definitions/win32_winhvplatform.py +156 -0
  957. angr/procedures/definitions/win32_wininet.py +616 -0
  958. angr/procedures/definitions/win32_winml.py +26 -0
  959. angr/procedures/definitions/win32_winmm.py +376 -0
  960. angr/procedures/definitions/win32_winscard.py +164 -0
  961. angr/procedures/definitions/win32_winspool.py +364 -0
  962. angr/procedures/definitions/win32_winspool_drv.py +368 -0
  963. angr/procedures/definitions/win32_wintrust.py +144 -0
  964. angr/procedures/definitions/win32_winusb.py +92 -0
  965. angr/procedures/definitions/win32_wlanapi.py +144 -0
  966. angr/procedures/definitions/win32_wlanui.py +26 -0
  967. angr/procedures/definitions/win32_wldap32.py +510 -0
  968. angr/procedures/definitions/win32_wldp.py +42 -0
  969. angr/procedures/definitions/win32_wmvcore.py +46 -0
  970. angr/procedures/definitions/win32_wnvapi.py +28 -0
  971. angr/procedures/definitions/win32_wofutil.py +46 -0
  972. angr/procedures/definitions/win32_ws2_32.py +344 -0
  973. angr/procedures/definitions/win32_wscapi.py +36 -0
  974. angr/procedures/definitions/win32_wsclient.py +30 -0
  975. angr/procedures/definitions/win32_wsdapi.py +88 -0
  976. angr/procedures/definitions/win32_wsmsvc.py +90 -0
  977. angr/procedures/definitions/win32_wsnmp32.py +122 -0
  978. angr/procedures/definitions/win32_wtsapi32.py +150 -0
  979. angr/procedures/definitions/win32_xaudio2_8.py +32 -0
  980. angr/procedures/definitions/win32_xinput1_4.py +38 -0
  981. angr/procedures/definitions/win32_xinputuap.py +36 -0
  982. angr/procedures/definitions/win32_xmllite.py +36 -0
  983. angr/procedures/definitions/win32_xolehlp.py +32 -0
  984. angr/procedures/definitions/win32_xpsprint.py +28 -0
  985. angr/procedures/glibc/__ctype_b_loc.py +21 -0
  986. angr/procedures/glibc/__ctype_tolower_loc.py +21 -0
  987. angr/procedures/glibc/__ctype_toupper_loc.py +21 -0
  988. angr/procedures/glibc/__errno_location.py +7 -0
  989. angr/procedures/glibc/__init__.py +3 -0
  990. angr/procedures/glibc/__libc_init.py +37 -0
  991. angr/procedures/glibc/__libc_start_main.py +301 -0
  992. angr/procedures/glibc/dynamic_loading.py +20 -0
  993. angr/procedures/glibc/scanf.py +11 -0
  994. angr/procedures/glibc/sscanf.py +6 -0
  995. angr/procedures/gnulib/__init__.py +3 -0
  996. angr/procedures/gnulib/xalloc_die.py +14 -0
  997. angr/procedures/gnulib/xstrtol_fatal.py +14 -0
  998. angr/procedures/java/__init__.py +42 -0
  999. angr/procedures/java/unconstrained.py +65 -0
  1000. angr/procedures/java_io/__init__.py +0 -0
  1001. angr/procedures/java_io/read.py +12 -0
  1002. angr/procedures/java_io/write.py +17 -0
  1003. angr/procedures/java_jni/__init__.py +482 -0
  1004. angr/procedures/java_jni/array_operations.py +312 -0
  1005. angr/procedures/java_jni/class_and_interface_operations.py +31 -0
  1006. angr/procedures/java_jni/field_access.py +173 -0
  1007. angr/procedures/java_jni/global_and_local_refs.py +57 -0
  1008. angr/procedures/java_jni/method_calls.py +365 -0
  1009. angr/procedures/java_jni/not_implemented.py +26 -0
  1010. angr/procedures/java_jni/object_operations.py +94 -0
  1011. angr/procedures/java_jni/string_operations.py +87 -0
  1012. angr/procedures/java_jni/version_information.py +12 -0
  1013. angr/procedures/java_lang/__init__.py +0 -0
  1014. angr/procedures/java_lang/character.py +30 -0
  1015. angr/procedures/java_lang/double.py +24 -0
  1016. angr/procedures/java_lang/exit.py +13 -0
  1017. angr/procedures/java_lang/getsimplename.py +18 -0
  1018. angr/procedures/java_lang/integer.py +43 -0
  1019. angr/procedures/java_lang/load_library.py +9 -0
  1020. angr/procedures/java_lang/math.py +15 -0
  1021. angr/procedures/java_lang/string.py +78 -0
  1022. angr/procedures/java_lang/stringbuilder.py +44 -0
  1023. angr/procedures/java_lang/system.py +18 -0
  1024. angr/procedures/java_util/__init__.py +0 -0
  1025. angr/procedures/java_util/collection.py +35 -0
  1026. angr/procedures/java_util/iterator.py +46 -0
  1027. angr/procedures/java_util/list.py +99 -0
  1028. angr/procedures/java_util/map.py +131 -0
  1029. angr/procedures/java_util/random.py +14 -0
  1030. angr/procedures/java_util/scanner_nextline.py +23 -0
  1031. angr/procedures/libc/__init__.py +3 -0
  1032. angr/procedures/libc/abort.py +9 -0
  1033. angr/procedures/libc/access.py +13 -0
  1034. angr/procedures/libc/atoi.py +14 -0
  1035. angr/procedures/libc/atol.py +13 -0
  1036. angr/procedures/libc/calloc.py +8 -0
  1037. angr/procedures/libc/closelog.py +10 -0
  1038. angr/procedures/libc/err.py +14 -0
  1039. angr/procedures/libc/error.py +54 -0
  1040. angr/procedures/libc/exit.py +11 -0
  1041. angr/procedures/libc/fclose.py +19 -0
  1042. angr/procedures/libc/feof.py +21 -0
  1043. angr/procedures/libc/fflush.py +16 -0
  1044. angr/procedures/libc/fgetc.py +27 -0
  1045. angr/procedures/libc/fgets.py +68 -0
  1046. angr/procedures/libc/fopen.py +63 -0
  1047. angr/procedures/libc/fprintf.py +25 -0
  1048. angr/procedures/libc/fputc.py +23 -0
  1049. angr/procedures/libc/fputs.py +24 -0
  1050. angr/procedures/libc/fread.py +24 -0
  1051. angr/procedures/libc/free.py +9 -0
  1052. angr/procedures/libc/fscanf.py +20 -0
  1053. angr/procedures/libc/fseek.py +34 -0
  1054. angr/procedures/libc/ftell.py +22 -0
  1055. angr/procedures/libc/fwrite.py +19 -0
  1056. angr/procedures/libc/getchar.py +13 -0
  1057. angr/procedures/libc/getdelim.py +99 -0
  1058. angr/procedures/libc/getegid.py +8 -0
  1059. angr/procedures/libc/geteuid.py +8 -0
  1060. angr/procedures/libc/getgid.py +8 -0
  1061. angr/procedures/libc/gets.py +68 -0
  1062. angr/procedures/libc/getuid.py +8 -0
  1063. angr/procedures/libc/malloc.py +12 -0
  1064. angr/procedures/libc/memcmp.py +69 -0
  1065. angr/procedures/libc/memcpy.py +38 -0
  1066. angr/procedures/libc/memset.py +72 -0
  1067. angr/procedures/libc/openlog.py +10 -0
  1068. angr/procedures/libc/perror.py +13 -0
  1069. angr/procedures/libc/printf.py +34 -0
  1070. angr/procedures/libc/putchar.py +13 -0
  1071. angr/procedures/libc/puts.py +19 -0
  1072. angr/procedures/libc/rand.py +8 -0
  1073. angr/procedures/libc/realloc.py +8 -0
  1074. angr/procedures/libc/rewind.py +12 -0
  1075. angr/procedures/libc/scanf.py +20 -0
  1076. angr/procedures/libc/setbuf.py +9 -0
  1077. angr/procedures/libc/setvbuf.py +7 -0
  1078. angr/procedures/libc/snprintf.py +36 -0
  1079. angr/procedures/libc/sprintf.py +25 -0
  1080. angr/procedures/libc/srand.py +7 -0
  1081. angr/procedures/libc/sscanf.py +13 -0
  1082. angr/procedures/libc/stpcpy.py +18 -0
  1083. angr/procedures/libc/strcat.py +14 -0
  1084. angr/procedures/libc/strchr.py +48 -0
  1085. angr/procedures/libc/strcmp.py +31 -0
  1086. angr/procedures/libc/strcpy.py +13 -0
  1087. angr/procedures/libc/strlen.py +114 -0
  1088. angr/procedures/libc/strncat.py +19 -0
  1089. angr/procedures/libc/strncmp.py +183 -0
  1090. angr/procedures/libc/strncpy.py +22 -0
  1091. angr/procedures/libc/strnlen.py +13 -0
  1092. angr/procedures/libc/strstr.py +101 -0
  1093. angr/procedures/libc/strtol.py +261 -0
  1094. angr/procedures/libc/strtoul.py +9 -0
  1095. angr/procedures/libc/system.py +13 -0
  1096. angr/procedures/libc/time.py +9 -0
  1097. angr/procedures/libc/tmpnam.py +20 -0
  1098. angr/procedures/libc/tolower.py +10 -0
  1099. angr/procedures/libc/toupper.py +10 -0
  1100. angr/procedures/libc/ungetc.py +20 -0
  1101. angr/procedures/libc/vsnprintf.py +17 -0
  1102. angr/procedures/libc/wchar.py +16 -0
  1103. angr/procedures/libstdcpp/__init__.py +0 -0
  1104. angr/procedures/libstdcpp/_unwind_resume.py +11 -0
  1105. angr/procedures/libstdcpp/std____throw_bad_alloc.py +13 -0
  1106. angr/procedures/libstdcpp/std____throw_bad_cast.py +13 -0
  1107. angr/procedures/libstdcpp/std____throw_length_error.py +13 -0
  1108. angr/procedures/libstdcpp/std____throw_logic_error.py +13 -0
  1109. angr/procedures/libstdcpp/std__terminate.py +13 -0
  1110. angr/procedures/linux_kernel/__init__.py +3 -0
  1111. angr/procedures/linux_kernel/access.py +18 -0
  1112. angr/procedures/linux_kernel/arch_prctl.py +34 -0
  1113. angr/procedures/linux_kernel/arm_user_helpers.py +59 -0
  1114. angr/procedures/linux_kernel/brk.py +18 -0
  1115. angr/procedures/linux_kernel/cwd.py +28 -0
  1116. angr/procedures/linux_kernel/fstat.py +138 -0
  1117. angr/procedures/linux_kernel/fstat64.py +170 -0
  1118. angr/procedures/linux_kernel/futex.py +17 -0
  1119. angr/procedures/linux_kernel/getegid.py +17 -0
  1120. angr/procedures/linux_kernel/geteuid.py +17 -0
  1121. angr/procedures/linux_kernel/getgid.py +17 -0
  1122. angr/procedures/linux_kernel/getpid.py +14 -0
  1123. angr/procedures/linux_kernel/getrlimit.py +24 -0
  1124. angr/procedures/linux_kernel/gettid.py +9 -0
  1125. angr/procedures/linux_kernel/getuid.py +17 -0
  1126. angr/procedures/linux_kernel/iovec.py +47 -0
  1127. angr/procedures/linux_kernel/lseek.py +42 -0
  1128. angr/procedures/linux_kernel/mmap.py +16 -0
  1129. angr/procedures/linux_kernel/mprotect.py +42 -0
  1130. angr/procedures/linux_kernel/munmap.py +8 -0
  1131. angr/procedures/linux_kernel/openat.py +26 -0
  1132. angr/procedures/linux_kernel/set_tid_address.py +8 -0
  1133. angr/procedures/linux_kernel/sigaction.py +19 -0
  1134. angr/procedures/linux_kernel/sigprocmask.py +23 -0
  1135. angr/procedures/linux_kernel/stat.py +23 -0
  1136. angr/procedures/linux_kernel/sysinfo.py +59 -0
  1137. angr/procedures/linux_kernel/tgkill.py +10 -0
  1138. angr/procedures/linux_kernel/time.py +34 -0
  1139. angr/procedures/linux_kernel/uid.py +30 -0
  1140. angr/procedures/linux_kernel/uname.py +29 -0
  1141. angr/procedures/linux_kernel/unlink.py +22 -0
  1142. angr/procedures/linux_kernel/vsyscall.py +16 -0
  1143. angr/procedures/linux_loader/__init__.py +3 -0
  1144. angr/procedures/linux_loader/_dl_initial_error_catch_tsd.py +7 -0
  1145. angr/procedures/linux_loader/_dl_rtld_lock.py +15 -0
  1146. angr/procedures/linux_loader/sim_loader.py +54 -0
  1147. angr/procedures/linux_loader/tls.py +40 -0
  1148. angr/procedures/msvcr/__getmainargs.py +16 -0
  1149. angr/procedures/msvcr/__init__.py +4 -0
  1150. angr/procedures/msvcr/_initterm.py +38 -0
  1151. angr/procedures/msvcr/fmode.py +31 -0
  1152. angr/procedures/ntdll/__init__.py +0 -0
  1153. angr/procedures/ntdll/exceptions.py +60 -0
  1154. angr/procedures/posix/__init__.py +3 -0
  1155. angr/procedures/posix/accept.py +29 -0
  1156. angr/procedures/posix/bind.py +13 -0
  1157. angr/procedures/posix/bzero.py +9 -0
  1158. angr/procedures/posix/chroot.py +27 -0
  1159. angr/procedures/posix/close.py +9 -0
  1160. angr/procedures/posix/closedir.py +7 -0
  1161. angr/procedures/posix/dup.py +56 -0
  1162. angr/procedures/posix/fcntl.py +10 -0
  1163. angr/procedures/posix/fdopen.py +76 -0
  1164. angr/procedures/posix/fileno.py +18 -0
  1165. angr/procedures/posix/fork.py +13 -0
  1166. angr/procedures/posix/getenv.py +35 -0
  1167. angr/procedures/posix/gethostbyname.py +43 -0
  1168. angr/procedures/posix/getpass.py +19 -0
  1169. angr/procedures/posix/getsockopt.py +11 -0
  1170. angr/procedures/posix/htonl.py +11 -0
  1171. angr/procedures/posix/htons.py +11 -0
  1172. angr/procedures/posix/inet_ntoa.py +59 -0
  1173. angr/procedures/posix/listen.py +13 -0
  1174. angr/procedures/posix/mmap.py +144 -0
  1175. angr/procedures/posix/open.py +18 -0
  1176. angr/procedures/posix/opendir.py +10 -0
  1177. angr/procedures/posix/poll.py +55 -0
  1178. angr/procedures/posix/pread64.py +46 -0
  1179. angr/procedures/posix/pthread.py +87 -0
  1180. angr/procedures/posix/pwrite64.py +46 -0
  1181. angr/procedures/posix/read.py +13 -0
  1182. angr/procedures/posix/readdir.py +62 -0
  1183. angr/procedures/posix/recv.py +13 -0
  1184. angr/procedures/posix/recvfrom.py +13 -0
  1185. angr/procedures/posix/select.py +48 -0
  1186. angr/procedures/posix/send.py +23 -0
  1187. angr/procedures/posix/setsockopt.py +9 -0
  1188. angr/procedures/posix/sigaction.py +23 -0
  1189. angr/procedures/posix/sim_time.py +48 -0
  1190. angr/procedures/posix/sleep.py +8 -0
  1191. angr/procedures/posix/socket.py +18 -0
  1192. angr/procedures/posix/strcasecmp.py +26 -0
  1193. angr/procedures/posix/strdup.py +18 -0
  1194. angr/procedures/posix/strtok_r.py +64 -0
  1195. angr/procedures/posix/syslog.py +15 -0
  1196. angr/procedures/posix/tz.py +9 -0
  1197. angr/procedures/posix/unlink.py +11 -0
  1198. angr/procedures/posix/usleep.py +8 -0
  1199. angr/procedures/posix/write.py +13 -0
  1200. angr/procedures/procedure_dict.py +50 -0
  1201. angr/procedures/stubs/CallReturn.py +13 -0
  1202. angr/procedures/stubs/NoReturnUnconstrained.py +13 -0
  1203. angr/procedures/stubs/Nop.py +7 -0
  1204. angr/procedures/stubs/PathTerminator.py +9 -0
  1205. angr/procedures/stubs/Redirect.py +18 -0
  1206. angr/procedures/stubs/ReturnChar.py +11 -0
  1207. angr/procedures/stubs/ReturnUnconstrained.py +24 -0
  1208. angr/procedures/stubs/UnresolvableCallTarget.py +9 -0
  1209. angr/procedures/stubs/UnresolvableJumpTarget.py +9 -0
  1210. angr/procedures/stubs/UserHook.py +18 -0
  1211. angr/procedures/stubs/__init__.py +3 -0
  1212. angr/procedures/stubs/b64_decode.py +15 -0
  1213. angr/procedures/stubs/caller.py +14 -0
  1214. angr/procedures/stubs/crazy_scanf.py +20 -0
  1215. angr/procedures/stubs/format_parser.py +669 -0
  1216. angr/procedures/stubs/syscall_stub.py +24 -0
  1217. angr/procedures/testing/__init__.py +3 -0
  1218. angr/procedures/testing/manyargs.py +9 -0
  1219. angr/procedures/testing/retreg.py +8 -0
  1220. angr/procedures/tracer/__init__.py +4 -0
  1221. angr/procedures/tracer/random.py +9 -0
  1222. angr/procedures/tracer/receive.py +23 -0
  1223. angr/procedures/tracer/transmit.py +26 -0
  1224. angr/procedures/uclibc/__init__.py +3 -0
  1225. angr/procedures/uclibc/__uClibc_main.py +10 -0
  1226. angr/procedures/win32/EncodePointer.py +7 -0
  1227. angr/procedures/win32/ExitProcess.py +9 -0
  1228. angr/procedures/win32/GetCommandLine.py +12 -0
  1229. angr/procedures/win32/GetCurrentProcessId.py +7 -0
  1230. angr/procedures/win32/GetCurrentThreadId.py +7 -0
  1231. angr/procedures/win32/GetLastInputInfo.py +40 -0
  1232. angr/procedures/win32/GetModuleHandle.py +29 -0
  1233. angr/procedures/win32/GetProcessAffinityMask.py +37 -0
  1234. angr/procedures/win32/InterlockedExchange.py +15 -0
  1235. angr/procedures/win32/IsProcessorFeaturePresent.py +7 -0
  1236. angr/procedures/win32/VirtualAlloc.py +114 -0
  1237. angr/procedures/win32/VirtualProtect.py +60 -0
  1238. angr/procedures/win32/__init__.py +3 -0
  1239. angr/procedures/win32/critical_section.py +12 -0
  1240. angr/procedures/win32/dynamic_loading.py +104 -0
  1241. angr/procedures/win32/file_handles.py +47 -0
  1242. angr/procedures/win32/gethostbyname.py +12 -0
  1243. angr/procedures/win32/heap.py +45 -0
  1244. angr/procedures/win32/is_bad_ptr.py +26 -0
  1245. angr/procedures/win32/local_storage.py +88 -0
  1246. angr/procedures/win32/mutex.py +11 -0
  1247. angr/procedures/win32/sim_time.py +135 -0
  1248. angr/procedures/win32/system_paths.py +35 -0
  1249. angr/procedures/win32_kernel/ExAllocatePool.py +13 -0
  1250. angr/procedures/win32_kernel/ExFreePoolWithTag.py +8 -0
  1251. angr/procedures/win32_kernel/__fastfail.py +15 -0
  1252. angr/procedures/win32_kernel/__init__.py +3 -0
  1253. angr/procedures/win_user32/__init__.py +0 -0
  1254. angr/procedures/win_user32/chars.py +15 -0
  1255. angr/procedures/win_user32/keyboard.py +14 -0
  1256. angr/procedures/win_user32/messagebox.py +49 -0
  1257. angr/project.py +847 -0
  1258. angr/protos/__init__.py +19 -0
  1259. angr/protos/cfg_pb2.py +31 -0
  1260. angr/protos/function_pb2.py +27 -0
  1261. angr/protos/primitives_pb2.py +52 -0
  1262. angr/protos/variables_pb2.py +44 -0
  1263. angr/protos/xrefs_pb2.py +25 -0
  1264. angr/py.typed +1 -0
  1265. angr/rustylib.abi3.so +0 -0
  1266. angr/serializable.py +66 -0
  1267. angr/sim_manager.py +971 -0
  1268. angr/sim_options.py +438 -0
  1269. angr/sim_procedure.py +606 -0
  1270. angr/sim_state.py +901 -0
  1271. angr/sim_state_options.py +403 -0
  1272. angr/sim_type.py +3702 -0
  1273. angr/sim_variable.py +465 -0
  1274. angr/simos/__init__.py +47 -0
  1275. angr/simos/cgc.py +153 -0
  1276. angr/simos/javavm.py +458 -0
  1277. angr/simos/linux.py +509 -0
  1278. angr/simos/simos.py +444 -0
  1279. angr/simos/snimmuc_nxp.py +149 -0
  1280. angr/simos/userland.py +163 -0
  1281. angr/simos/windows.py +601 -0
  1282. angr/simos/xbox.py +32 -0
  1283. angr/slicer.py +352 -0
  1284. angr/state_hierarchy.py +262 -0
  1285. angr/state_plugins/__init__.py +84 -0
  1286. angr/state_plugins/callstack.py +398 -0
  1287. angr/state_plugins/cgc.py +155 -0
  1288. angr/state_plugins/debug_variables.py +192 -0
  1289. angr/state_plugins/filesystem.py +463 -0
  1290. angr/state_plugins/gdb.py +148 -0
  1291. angr/state_plugins/globals.py +65 -0
  1292. angr/state_plugins/heap/__init__.py +15 -0
  1293. angr/state_plugins/heap/heap_base.py +128 -0
  1294. angr/state_plugins/heap/heap_brk.py +136 -0
  1295. angr/state_plugins/heap/heap_freelist.py +213 -0
  1296. angr/state_plugins/heap/heap_libc.py +46 -0
  1297. angr/state_plugins/heap/heap_ptmalloc.py +620 -0
  1298. angr/state_plugins/heap/utils.py +22 -0
  1299. angr/state_plugins/history.py +564 -0
  1300. angr/state_plugins/inspect.py +375 -0
  1301. angr/state_plugins/javavm_classloader.py +134 -0
  1302. angr/state_plugins/jni_references.py +95 -0
  1303. angr/state_plugins/libc.py +1263 -0
  1304. angr/state_plugins/light_registers.py +168 -0
  1305. angr/state_plugins/log.py +84 -0
  1306. angr/state_plugins/loop_data.py +92 -0
  1307. angr/state_plugins/plugin.py +170 -0
  1308. angr/state_plugins/posix.py +703 -0
  1309. angr/state_plugins/preconstrainer.py +196 -0
  1310. angr/state_plugins/scratch.py +173 -0
  1311. angr/state_plugins/sim_action.py +326 -0
  1312. angr/state_plugins/sim_action_object.py +271 -0
  1313. angr/state_plugins/sim_event.py +59 -0
  1314. angr/state_plugins/solver.py +1127 -0
  1315. angr/state_plugins/symbolizer.py +291 -0
  1316. angr/state_plugins/trace_additions.py +738 -0
  1317. angr/state_plugins/uc_manager.py +94 -0
  1318. angr/state_plugins/unicorn_engine.py +1886 -0
  1319. angr/state_plugins/view.py +340 -0
  1320. angr/storage/__init__.py +15 -0
  1321. angr/storage/file.py +1210 -0
  1322. angr/storage/memory_mixins/__init__.py +317 -0
  1323. angr/storage/memory_mixins/actions_mixin.py +72 -0
  1324. angr/storage/memory_mixins/address_concretization_mixin.py +384 -0
  1325. angr/storage/memory_mixins/bvv_conversion_mixin.py +73 -0
  1326. angr/storage/memory_mixins/clouseau_mixin.py +137 -0
  1327. angr/storage/memory_mixins/conditional_store_mixin.py +25 -0
  1328. angr/storage/memory_mixins/convenient_mappings_mixin.py +256 -0
  1329. angr/storage/memory_mixins/default_filler_mixin.py +144 -0
  1330. angr/storage/memory_mixins/dirty_addrs_mixin.py +11 -0
  1331. angr/storage/memory_mixins/hex_dumper_mixin.py +82 -0
  1332. angr/storage/memory_mixins/javavm_memory_mixin.py +392 -0
  1333. angr/storage/memory_mixins/keyvalue_memory_mixin.py +42 -0
  1334. angr/storage/memory_mixins/label_merger_mixin.py +31 -0
  1335. angr/storage/memory_mixins/memory_mixin.py +174 -0
  1336. angr/storage/memory_mixins/multi_value_merger_mixin.py +79 -0
  1337. angr/storage/memory_mixins/name_resolution_mixin.py +67 -0
  1338. angr/storage/memory_mixins/paged_memory/__init__.py +0 -0
  1339. angr/storage/memory_mixins/paged_memory/page_backer_mixins.py +266 -0
  1340. angr/storage/memory_mixins/paged_memory/paged_memory_mixin.py +743 -0
  1341. angr/storage/memory_mixins/paged_memory/paged_memory_multivalue_mixin.py +65 -0
  1342. angr/storage/memory_mixins/paged_memory/pages/__init__.py +26 -0
  1343. angr/storage/memory_mixins/paged_memory/pages/base.py +31 -0
  1344. angr/storage/memory_mixins/paged_memory/pages/cooperation.py +341 -0
  1345. angr/storage/memory_mixins/paged_memory/pages/history_tracking_mixin.py +92 -0
  1346. angr/storage/memory_mixins/paged_memory/pages/ispo_mixin.py +55 -0
  1347. angr/storage/memory_mixins/paged_memory/pages/list_page.py +338 -0
  1348. angr/storage/memory_mixins/paged_memory/pages/multi_values.py +324 -0
  1349. angr/storage/memory_mixins/paged_memory/pages/mv_list_page.py +419 -0
  1350. angr/storage/memory_mixins/paged_memory/pages/permissions_mixin.py +36 -0
  1351. angr/storage/memory_mixins/paged_memory/pages/refcount_mixin.py +52 -0
  1352. angr/storage/memory_mixins/paged_memory/pages/ultra_page.py +503 -0
  1353. angr/storage/memory_mixins/paged_memory/privileged_mixin.py +36 -0
  1354. angr/storage/memory_mixins/paged_memory/stack_allocation_mixin.py +74 -0
  1355. angr/storage/memory_mixins/regioned_memory/__init__.py +17 -0
  1356. angr/storage/memory_mixins/regioned_memory/abstract_address_descriptor.py +36 -0
  1357. angr/storage/memory_mixins/regioned_memory/abstract_merger_mixin.py +31 -0
  1358. angr/storage/memory_mixins/regioned_memory/region_category_mixin.py +9 -0
  1359. angr/storage/memory_mixins/regioned_memory/region_data.py +246 -0
  1360. angr/storage/memory_mixins/regioned_memory/region_meta_mixin.py +241 -0
  1361. angr/storage/memory_mixins/regioned_memory/regioned_address_concretization_mixin.py +119 -0
  1362. angr/storage/memory_mixins/regioned_memory/regioned_memory_mixin.py +441 -0
  1363. angr/storage/memory_mixins/regioned_memory/static_find_mixin.py +69 -0
  1364. angr/storage/memory_mixins/simple_interface_mixin.py +71 -0
  1365. angr/storage/memory_mixins/simplification_mixin.py +15 -0
  1366. angr/storage/memory_mixins/size_resolution_mixin.py +143 -0
  1367. angr/storage/memory_mixins/slotted_memory.py +140 -0
  1368. angr/storage/memory_mixins/smart_find_mixin.py +161 -0
  1369. angr/storage/memory_mixins/symbolic_merger_mixin.py +16 -0
  1370. angr/storage/memory_mixins/top_merger_mixin.py +25 -0
  1371. angr/storage/memory_mixins/underconstrained_mixin.py +67 -0
  1372. angr/storage/memory_mixins/unwrapper_mixin.py +26 -0
  1373. angr/storage/memory_object.py +195 -0
  1374. angr/tablespecs.py +91 -0
  1375. angr/unicornlib.so +0 -0
  1376. angr/utils/__init__.py +46 -0
  1377. angr/utils/ail.py +70 -0
  1378. angr/utils/algo.py +34 -0
  1379. angr/utils/bits.py +46 -0
  1380. angr/utils/constants.py +9 -0
  1381. angr/utils/cowdict.py +63 -0
  1382. angr/utils/cpp.py +17 -0
  1383. angr/utils/doms.py +149 -0
  1384. angr/utils/dynamic_dictlist.py +89 -0
  1385. angr/utils/endness.py +18 -0
  1386. angr/utils/enums_conv.py +97 -0
  1387. angr/utils/env.py +12 -0
  1388. angr/utils/formatting.py +128 -0
  1389. angr/utils/funcid.py +159 -0
  1390. angr/utils/graph.py +933 -0
  1391. angr/utils/lazy_import.py +13 -0
  1392. angr/utils/library.py +212 -0
  1393. angr/utils/loader.py +55 -0
  1394. angr/utils/mp.py +66 -0
  1395. angr/utils/orderedset.py +74 -0
  1396. angr/utils/ssa/__init__.py +457 -0
  1397. angr/utils/ssa/tmp_uses_collector.py +23 -0
  1398. angr/utils/ssa/vvar_uses_collector.py +37 -0
  1399. angr/utils/tagged_interval_map.py +112 -0
  1400. angr/utils/timing.py +74 -0
  1401. angr/utils/types.py +151 -0
  1402. angr/utils/vex.py +11 -0
  1403. angr/vaults.py +367 -0
  1404. angr-9.2.166.dist-info/METADATA +110 -0
  1405. angr-9.2.166.dist-info/RECORD +1409 -0
  1406. angr-9.2.166.dist-info/WHEEL +5 -0
  1407. angr-9.2.166.dist-info/entry_points.txt +2 -0
  1408. angr-9.2.166.dist-info/licenses/LICENSE +27 -0
  1409. angr-9.2.166.dist-info/top_level.txt +1 -0
@@ -0,0 +1,2367 @@
1
+ # pylint:disable=wrong-import-position,wrong-import-order
2
+ from __future__ import annotations
3
+ import enum
4
+ from typing import TYPE_CHECKING, Literal, cast
5
+ from collections.abc import Sequence
6
+ from collections import defaultdict, OrderedDict
7
+ import logging
8
+ import functools
9
+ import contextlib
10
+
11
+ import pyvex
12
+ import claripy
13
+ from archinfo.arch_arm import is_arm_arch
14
+ from claripy.annotation import UninitializedAnnotation
15
+
16
+ from angr import sim_options as o
17
+ from angr import BP, BP_BEFORE, BP_AFTER
18
+ from angr.misc.ux import once
19
+ from angr.concretization_strategies import SimConcretizationStrategyAny
20
+ from angr.knowledge_plugins.cfg import IndirectJump, IndirectJumpType
21
+ from angr.engines.vex.claripy import ccall
22
+ from angr.engines.light import SimEngineNostmtVEX, SpOffset, RegisterOffset
23
+ from angr.errors import AngrError, SimError
24
+ from angr.blade import Blade
25
+ from angr.annocfg import AnnotatedCFG
26
+ from angr.exploration_techniques.slicecutor import Slicecutor
27
+ from angr.exploration_techniques.local_loop_seer import LocalLoopSeer
28
+ from angr.exploration_techniques.explorer import Explorer
29
+ from angr.utils.constants import DEFAULT_STATEMENT
30
+ from angr.analyses.propagator.top_checker_mixin import ClaripyDataVEXEngineMixin
31
+ from angr.engines.vex.claripy.datalayer import value
32
+ from .resolver import IndirectJumpResolver
33
+ from .constant_value_manager import ConstantValueManager
34
+
35
+ try:
36
+ from angr.engines import pcode
37
+ except ImportError:
38
+ pcode = None
39
+
40
+ if TYPE_CHECKING:
41
+ from angr.knowledge_plugins import Function
42
+
43
+ l = logging.getLogger(name=__name__)
44
+
45
+
46
+ class NotAJumpTableNotification(AngrError):
47
+ """
48
+ Exception raised to indicate this is not (or does not appear to be) a jump table.
49
+ """
50
+
51
+
52
+ class UninitReadMeta:
53
+ """
54
+ Uninitialized read remapping details.
55
+ """
56
+
57
+ uninit_read_base = 0xC000000
58
+
59
+
60
+ class AddressTransformationTypes(int, enum.Enum):
61
+ """
62
+ Address transformation operations.
63
+ """
64
+
65
+ Assignment = 0
66
+ SignedExtension = 1
67
+ UnsignedExtension = 2
68
+ Truncation = 3
69
+ Or1 = 4
70
+ ShiftLeft = 5
71
+ ShiftRight = 6
72
+ Add = 7
73
+ Load = 8
74
+
75
+
76
+ class AddressTransformation:
77
+ """
78
+ Describe and record an address transformation operation.
79
+ """
80
+
81
+ def __init__(self, op: AddressTransformationTypes, operands: list, first_load: bool = False):
82
+ self.op = op
83
+ self.operands = operands
84
+ self.first_load = first_load
85
+
86
+ def __repr__(self):
87
+ return f"<Transformation: {self.op} {self.operands}>"
88
+
89
+
90
+ class AddressOperand:
91
+ """
92
+ The class for the singleton class AddressSingleton. It represents the address being transformed before using as an
93
+ indirect jump target.
94
+ """
95
+
96
+ def __repr__(self):
97
+ return "ADDR"
98
+
99
+
100
+ AddressSingleton = AddressOperand()
101
+
102
+
103
+ class Tmp:
104
+ """
105
+ For modeling Tmp variables.
106
+ """
107
+
108
+ def __init__(self, tmp_idx):
109
+ self.tmp_idx = tmp_idx
110
+
111
+
112
+ class JumpTargetBaseAddr:
113
+ """
114
+ Model for jump targets and their data origin.
115
+ """
116
+
117
+ def __init__(
118
+ self, stmt_loc, stmt: pyvex.stmt.IRStmt, tmp: int, base_addr: int | None = None, tmp_1: int | None = None
119
+ ):
120
+ self.stmt_loc = stmt_loc
121
+ self.stmt = stmt
122
+ self.tmp = tmp
123
+ self.tmp_1 = tmp_1
124
+ self.base_addr = base_addr
125
+
126
+ assert base_addr is not None or tmp_1 is not None
127
+
128
+ @property
129
+ def base_addr_available(self):
130
+ return self.base_addr is not None
131
+
132
+
133
+ #
134
+ # Jump table pre-check
135
+ #
136
+
137
+ _x86_ct = ccall.data["X86"]["CondTypes"]
138
+ _amd64_ct = ccall.data["AMD64"]["CondTypes"]
139
+ EXPECTED_COND_TYPES = {
140
+ "X86": {
141
+ _x86_ct["CondB"],
142
+ _x86_ct["CondNB"],
143
+ _x86_ct["CondBE"],
144
+ _x86_ct["CondNBE"],
145
+ _x86_ct["CondL"],
146
+ _x86_ct["CondNL"],
147
+ _x86_ct["CondLE"],
148
+ _x86_ct["CondNLE"],
149
+ },
150
+ "AMD64": {
151
+ _amd64_ct["CondB"],
152
+ _amd64_ct["CondNB"],
153
+ _amd64_ct["CondBE"],
154
+ _amd64_ct["CondNBE"],
155
+ _amd64_ct["CondL"],
156
+ _amd64_ct["CondNL"],
157
+ _amd64_ct["CondLE"],
158
+ _amd64_ct["CondNLE"],
159
+ },
160
+ "ARM": {
161
+ ccall.ARMCondHS,
162
+ ccall.ARMCondLO,
163
+ ccall.ARMCondHI,
164
+ ccall.ARMCondLS,
165
+ ccall.ARMCondGE,
166
+ ccall.ARMCondLT,
167
+ ccall.ARMCondGT,
168
+ ccall.ARMCondLE,
169
+ },
170
+ "AARCH64": {
171
+ ccall.ARM64CondCS,
172
+ ccall.ARM64CondCC,
173
+ ccall.ARM64CondHI,
174
+ ccall.ARM64CondLS,
175
+ ccall.ARM64CondGE,
176
+ ccall.ARM64CondLT,
177
+ ccall.ARM64CondGT,
178
+ ccall.ARM64CondLE,
179
+ },
180
+ }
181
+
182
+
183
+ class JumpTableProcessorState:
184
+ """
185
+ The state used in JumpTableProcessor.
186
+ """
187
+
188
+ __slots__ = (
189
+ "_registers",
190
+ "_stack",
191
+ "_tmpvar_source",
192
+ "arch",
193
+ "is_jumptable",
194
+ "regs_to_initialize",
195
+ "stmts_to_instrument",
196
+ )
197
+
198
+ def __init__(self, arch):
199
+ self.arch = arch
200
+
201
+ self._registers = {}
202
+ self._stack = {}
203
+ self._tmpvar_source = {} # a mapping from temporary variables to their origins
204
+
205
+ self.is_jumptable: bool | None = None # is the current slice representing a jump table?
206
+ self.stmts_to_instrument = [] # Store/Put statements that we should instrument
207
+ self.regs_to_initialize = [] # registers that we should initialize
208
+
209
+
210
+ class RegOffsetAnnotation(claripy.Annotation):
211
+ """
212
+ Register Offset annotation.
213
+ """
214
+
215
+ __slots__ = ("reg_offset",)
216
+
217
+ def __init__(self, reg_offset: RegisterOffset):
218
+ self.reg_offset = reg_offset
219
+
220
+ @property
221
+ def relocatable(self):
222
+ return False
223
+
224
+ @property
225
+ def eliminatable(self):
226
+ return False
227
+
228
+
229
+ binop_handler = SimEngineNostmtVEX[JumpTableProcessorState, claripy.ast.BV, JumpTableProcessorState].binop_handler
230
+
231
+
232
+ class JumpTableProcessor(
233
+ SimEngineNostmtVEX[JumpTableProcessorState, claripy.ast.BV, JumpTableProcessorState],
234
+ ClaripyDataVEXEngineMixin[JumpTableProcessorState, claripy.ast.BV, JumpTableProcessorState, None],
235
+ ): # pylint:disable=abstract-method
236
+ """
237
+ Implements a simple and stupid data dependency tracking for stack and register variables.
238
+
239
+ Also determines which statements to instrument during static execution of the slice later. For example, the
240
+ following example is not uncommon in non-optimized binaries::
241
+
242
+ mov [rbp+var_54], 1
243
+ loc_4051a6:
244
+ cmp [rbp+var_54], 6
245
+ ja loc_405412 (default)
246
+ loc_4051b0:
247
+ mov eax, [rbp+var_54]
248
+ mov rax, qword [rax*8+0x223a01]
249
+ jmp rax
250
+
251
+ We want to instrument the first instruction and replace the constant 1 with a symbolic variable, otherwise we will
252
+ not be able to recover all jump targets later in block 0x4051b0.
253
+ """
254
+
255
+ def __init__(self, project, indirect_jump_node_pred_addrs: set[int], bp_sp_diff=0x100):
256
+ super().__init__(project)
257
+ self._bp_sp_diff = bp_sp_diff # bp - sp
258
+ self._tsrc: set[Literal["const"] | tuple[int, int]] = (
259
+ set()
260
+ ) # a scratch variable to store source information for values
261
+ self._indirect_jump_node_pred_addrs = indirect_jump_node_pred_addrs
262
+
263
+ self._SPOFFSET_BASE = claripy.BVS("SpOffset", self.project.arch.bits, explicit_name=True)
264
+ self._REGOFFSET_BASE: dict[int, claripy.ast.BV] = {}
265
+
266
+ def _process_block_end(self, stmt_result, whitelist):
267
+ return self.state
268
+
269
+ @staticmethod
270
+ def _is_spoffset(expr) -> bool:
271
+ return "SpOffset" in expr.variables
272
+
273
+ def _get_spoffset_expr(self, sp_offset: SpOffset) -> claripy.ast.BV:
274
+ return self._SPOFFSET_BASE.annotate(RegOffsetAnnotation(sp_offset))
275
+
276
+ @staticmethod
277
+ def _extract_spoffset_from_expr(expr: claripy.ast.Base) -> RegisterOffset | None:
278
+ if expr.op == "BVS":
279
+ for anno in expr.annotations:
280
+ if isinstance(anno, RegOffsetAnnotation):
281
+ return anno.reg_offset
282
+ elif expr.op == "__add__":
283
+ if len(expr.args) == 1:
284
+ return JumpTableProcessor._extract_spoffset_from_expr(cast(claripy.ast.BV, expr.args[0]))
285
+ if len(expr.args) == 2 and cast(claripy.ast.BV, expr.args[1]).op == "BVV":
286
+ sp_offset = JumpTableProcessor._extract_spoffset_from_expr(cast(claripy.ast.BV, expr.args[0]))
287
+ if sp_offset is not None:
288
+ delta = cast(claripy.ast.BV, expr.args[1]).concrete_value
289
+ sp_offset += delta
290
+ return sp_offset
291
+ elif expr.op == "__and__" and len(expr.args) == 2 and cast(claripy.ast.BV, expr.args[1]).op == "BVV":
292
+ # ignore all masking on SpOffsets
293
+ return JumpTableProcessor._extract_spoffset_from_expr(cast(claripy.ast.BV, expr.args[0]))
294
+ return None
295
+
296
+ @staticmethod
297
+ def _is_registeroffset(expr) -> bool:
298
+ return "RegisterOffset" in expr.variables
299
+
300
+ def _get_regoffset_expr(self, reg_offset: RegisterOffset, bits: int) -> claripy.ast.BV:
301
+ if bits not in self._REGOFFSET_BASE:
302
+ self._REGOFFSET_BASE[bits] = claripy.BVS("RegisterOffset", bits, explicit_name=True)
303
+ return self._REGOFFSET_BASE[bits].annotate(RegOffsetAnnotation(reg_offset))
304
+
305
+ @staticmethod
306
+ def _extract_regoffset_from_expr(expr: claripy.ast.Base) -> RegisterOffset | None:
307
+ if expr.op == "BVS":
308
+ for anno in expr.annotations:
309
+ if isinstance(anno, RegOffsetAnnotation):
310
+ return anno.reg_offset
311
+ elif expr.op == "__add__":
312
+ if len(expr.args) == 1:
313
+ return JumpTableProcessor._extract_regoffset_from_expr(cast(claripy.ast.BV, expr.args[0]))
314
+ if len(expr.args) == 2 and cast(claripy.ast.BV, expr.args[1]).op == "BVV":
315
+ reg_offset = JumpTableProcessor._extract_regoffset_from_expr(cast(claripy.ast.BV, expr.args[0]))
316
+ if reg_offset is not None:
317
+ delta = cast(claripy.ast.BV, expr.args[1]).concrete_value
318
+ reg_offset += delta
319
+ return reg_offset
320
+ elif expr.op == "__and__" and len(expr.args) == 2 and cast(claripy.ast.BV, expr.args[1]).op == "BVV":
321
+ # ignore all masking on SpOffsets
322
+ return JumpTableProcessor._extract_spoffset_from_expr(cast(claripy.ast.BV, expr.args[0]))
323
+ return None
324
+
325
+ def _handle_stmt_WrTmp(self, stmt):
326
+ self._tsrc = set()
327
+
328
+ self.tmps[stmt.tmp] = self._expr(stmt.data)
329
+ if self._tsrc:
330
+ self.state._tmpvar_source[stmt.tmp] = self._tsrc
331
+
332
+ def _handle_stmt_Put(self, stmt):
333
+ self._tsrc = set()
334
+ offset = stmt.offset
335
+ data = self._expr(stmt.data)
336
+ r = (self._tsrc, data) if self._tsrc is not None else ((self.block.addr, self.stmt_idx), data)
337
+ self.state._registers[offset] = r
338
+
339
+ def _handle_stmt_Store(self, stmt):
340
+ self._tsrc = set()
341
+ addr = self._expr(stmt.addr)
342
+ data = self._expr(stmt.data)
343
+
344
+ if addr is None:
345
+ return
346
+
347
+ if isinstance(addr, SpOffset):
348
+ self.state._stack[addr.offset] = ((self.block.addr, self.stmt_idx), data)
349
+
350
+ def _handle_expr_RdTmp(self, expr):
351
+ try:
352
+ v = self.tmps[expr.tmp]
353
+ except KeyError:
354
+ v = self._top(expr.result_size(self.tyenv))
355
+ if expr.tmp in self.state._tmpvar_source:
356
+ self._tsrc |= set(self.state._tmpvar_source[expr.tmp])
357
+ return v
358
+
359
+ def _handle_expr_Get(self, expr):
360
+ if expr.offset == self.arch.bp_offset:
361
+ v = self._get_spoffset_expr(SpOffset(self.arch.bits, self._bp_sp_diff))
362
+ elif expr.offset == self.arch.sp_offset:
363
+ v = self._get_spoffset_expr(SpOffset(self.arch.bits, 0))
364
+ else:
365
+ if expr.offset in self.state._registers:
366
+ self._tsrc |= set(self.state._registers[expr.offset][0])
367
+ v = self.state._registers[expr.offset][1]
368
+ else:
369
+ # the register does not exist
370
+ # we initialize it here
371
+ v = RegisterOffset(expr.result_size(self.tyenv), expr.offset, 0)
372
+ v = self._get_regoffset_expr(v, expr.result_size(self.tyenv))
373
+ src = (self.block.addr, self.stmt_idx)
374
+ self._tsrc.add(src)
375
+ self.state._registers[expr.offset] = ([src], v)
376
+
377
+ # make sure the size matches
378
+ # note that this is sometimes incorrect. for example, we do not differentiate between reads at ah and al...
379
+ # but it should be good enough for now (without switching state._registers to a real SimMemory, which will
380
+ # surely slow down stuff quite a bit)
381
+ if v is not None:
382
+ bits = expr.result_size(self.tyenv)
383
+ if v.size() > bits:
384
+ v = v[bits - 1 : 0]
385
+ elif v.size() < bits:
386
+ v = claripy.ZeroExt(bits - v.size(), v)
387
+ return v
388
+
389
+ def _handle_function(self, expr): # pylint:disable=unused-argument,no-self-use
390
+ return None # This analysis is not interprocedural
391
+
392
+ def _handle_expr_Load(self, expr):
393
+ addr = self._expr(expr.addr)
394
+ size = expr.result_size(self.tyenv) // 8
395
+ return self._do_load(addr, size)
396
+
397
+ def _handle_stmt_LoadG(self, stmt: pyvex.stmt.LoadG):
398
+ self._tsrc = set()
399
+
400
+ guard = self._expr(stmt.guard) != 0
401
+ iftrue = self._do_load(self._expr(stmt.addr), stmt.addr.result_size(self.tyenv) // 8)
402
+ iffalse = self._expr(stmt.alt)
403
+ result = claripy.If(guard, iftrue, iffalse)
404
+ self.tmps[stmt.dst] = result
405
+ if self._tsrc:
406
+ self.state._tmpvar_source[stmt.dst] = self._tsrc
407
+
408
+ def _handle_expr_Const(self, expr):
409
+ v = value(expr.con.type, expr.con.value)
410
+ self._tsrc.add("const")
411
+ if not isinstance(v, claripy.ast.BV):
412
+ return self._top(expr.result_size(self.tyenv))
413
+ return v
414
+
415
+ @binop_handler
416
+ def _handle_binop_And(self, expr):
417
+ arg0 = self._expr(expr.args[0])
418
+ if (
419
+ isinstance(arg0, claripy.ast.BV)
420
+ and self._is_registeroffset(arg0)
421
+ and isinstance(expr.args[1], pyvex.IRExpr.Const)
422
+ ):
423
+ mask_value = expr.args[1].con.value
424
+ if mask_value in {1, 3, 7, 15, 31, 63, 127, 255}:
425
+ # 1cbbf108f44c8f4babde546d26425ca5340dccf878d306b90eb0fbec2f83ab51:0x40bd1b
426
+ self.state.is_jumptable = True
427
+ return arg0 & mask_value
428
+ return self._top(expr.result_size(self.tyenv))
429
+
430
+ @binop_handler
431
+ def _handle_binop_CmpLE(self, expr):
432
+ return self._handle_Comparison(*expr.args)
433
+
434
+ @binop_handler
435
+ def _handle_binop_CmpGE(self, expr):
436
+ return self._handle_Comparison(*expr.args)
437
+
438
+ @binop_handler
439
+ def _handle_binop_CmpLT(self, expr):
440
+ return self._handle_Comparison(*expr.args)
441
+
442
+ @binop_handler
443
+ def _handle_binop_CmpGT(self, expr):
444
+ return self._handle_Comparison(*expr.args)
445
+
446
+ def _handle_expr_CCall(self, expr):
447
+ if isinstance(expr.args[0], pyvex.IRExpr.Const):
448
+ cond_type_enum = expr.args[0].con.value
449
+
450
+ if self.arch.name in {"X86", "AMD64", "AARCH64"}:
451
+ if cond_type_enum in EXPECTED_COND_TYPES[self.arch.name]:
452
+ self._handle_Comparison(expr.args[2], expr.args[3])
453
+ elif is_arm_arch(self.arch):
454
+ if cond_type_enum in EXPECTED_COND_TYPES["ARM"]:
455
+ self._handle_Comparison(expr.args[2], expr.args[3])
456
+ else:
457
+ # other architectures
458
+ l.warning("Please fill in EXPECTED_COND_TYPES for %s.", self.arch.name)
459
+ self._handle_Comparison(expr.args[2], expr.args[3])
460
+
461
+ return self._top(expr.result_size(self.tyenv))
462
+
463
+ def _handle_expr_VECRET(self, expr):
464
+ return self._top(expr.result_size(self.tyenv))
465
+
466
+ def _handle_expr_GSPTR(self, expr):
467
+ return self._top(expr.result_size(self.tyenv))
468
+
469
+ def _handle_expr_GetI(self, expr):
470
+ return self._top(expr.result_size(self.tyenv))
471
+
472
+ def _handle_expr_ITE(self, expr):
473
+ return self._top(expr.result_size(self.tyenv))
474
+
475
+ def _handle_Comparison(self, arg0: pyvex.expr.IRExpr, arg1: pyvex.expr.IRExpr) -> claripy.ast.BV:
476
+ if self.block.addr not in self._indirect_jump_node_pred_addrs:
477
+ return self._top(1)
478
+
479
+ # found the comparison
480
+ arg0_src, arg1_src = None, None
481
+
482
+ if isinstance(arg0, pyvex.IRExpr.RdTmp):
483
+ if arg0.tmp in self.state._tmpvar_source:
484
+ arg0_src = self.state._tmpvar_source[arg0.tmp]
485
+ arg0_src = None if not arg0_src or len(arg0_src) > 1 else next(iter(arg0_src))
486
+ elif isinstance(arg0, pyvex.IRExpr.Const):
487
+ arg0_src = "const"
488
+ if isinstance(arg1, pyvex.IRExpr.RdTmp):
489
+ if arg1.tmp in self.state._tmpvar_source:
490
+ arg1_src = self.state._tmpvar_source[arg1.tmp]
491
+ arg1_src = None if not arg1_src or len(arg1_src) > 1 else next(iter(arg1_src))
492
+ elif isinstance(arg1, pyvex.IRExpr.Const):
493
+ arg1_src = "const"
494
+
495
+ if arg0_src == "const" and arg1_src == "const":
496
+ # comparison of two consts... there is nothing we can do
497
+ self.state.is_jumptable = True
498
+ return self._top(1)
499
+ if arg0_src not in {"const", None} and arg1_src not in {"const", None}:
500
+ # this is probably not a jump table
501
+ return self._top(1)
502
+ if arg1_src == "const":
503
+ # make sure arg0_src is const
504
+ arg0_src, arg1_src = arg1_src, arg0_src
505
+
506
+ self.state.is_jumptable = True
507
+
508
+ if arg0_src != "const":
509
+ # we failed during dependency tracking so arg0_src couldn't be determined
510
+ # but we will still try to resolve it as a jump table as a fall back
511
+ return self._top(1)
512
+
513
+ if isinstance(arg1_src, tuple):
514
+ arg1_src_stmt = self.project.factory.block(arg1_src[0], cross_insn_opt=True).vex.statements[arg1_src[1]]
515
+ if isinstance(arg1_src_stmt, pyvex.IRStmt.Store):
516
+ # Storing a constant/variable in memory
517
+ # We will need to overwrite it when executing the slice to guarantee the full recovery of jump table
518
+ # targets.
519
+ #
520
+ # Here is an example:
521
+ # mov [rbp+var_54], 1
522
+ # loc_4051a6:
523
+ # cmp [rbp+var_54], 6
524
+ # ja loc_405412 (default)
525
+ #
526
+ # Instead of writing 1 to [rbp+var_54], we want to write a symbolic variable there instead. Otherwise
527
+ # we will only recover the second jump target instead of all 7 targets.
528
+ self.state.stmts_to_instrument.append(("mem_write", *arg1_src))
529
+ elif isinstance(arg1_src_stmt, pyvex.IRStmt.WrTmp) and isinstance(arg1_src_stmt.data, pyvex.IRExpr.Load):
530
+ # Loading a constant/variable from memory (and later the value is stored in a register)
531
+ # Same as above, we will need to overwrite it when executing the slice to guarantee the full recovery
532
+ # of jump table targets.
533
+ #
534
+ # Here is an example:
535
+ # mov eax, [0x625a3c]
536
+ # cmp eax, 0x4
537
+ # ja 0x40899d (default)
538
+ # loc_408899:
539
+ # mov eax, eax
540
+ # mov rax, qword [rax*8+0x220741]
541
+ # jmp rax
542
+ #
543
+ self.state.stmts_to_instrument.append(("mem_read", *arg1_src))
544
+ elif isinstance(arg1_src_stmt, pyvex.IRStmt.Put):
545
+ # Storing a constant/variable in register
546
+ # Same as above...
547
+ #
548
+ # Here is an example:
549
+ # movzx eax, byte ptr [rax+12h]
550
+ # movzx eax, al
551
+ # cmp eax, 0xe
552
+ # ja 0x405b9f (default)
553
+ # loc_405b34:
554
+ # mov eax, eax
555
+ # mov rax, qword [rax*8+0x2231ae]
556
+ #
557
+ self.state.stmts_to_instrument.append(("reg_write", *arg1_src))
558
+
559
+ return self._top(1)
560
+
561
+ def _do_load(self, addr: claripy.ast.BV, size: int) -> claripy.ast.BV:
562
+ src = (self.block.addr, self.stmt_idx)
563
+ self._tsrc = {src}
564
+
565
+ if self._is_spoffset(addr):
566
+ spoffset = self._extract_spoffset_from_expr(addr)
567
+ if spoffset is not None and spoffset.offset in self.state._stack:
568
+ self._tsrc = {self.state._stack[spoffset.offset][0]}
569
+ return self.state._stack[spoffset.offset][1]
570
+ elif self._is_registeroffset(addr):
571
+ # Load data from a register, but this register hasn't been initialized at this point
572
+ # We will need to initialize this register during slice execution later
573
+
574
+ # Try to get where this register is first accessed
575
+ reg_offset = self._extract_regoffset_from_expr(addr)
576
+ if reg_offset is not None and reg_offset.reg in self.state._registers:
577
+ try:
578
+ source = next(iter(src for src in self.state._registers[reg_offset.reg][0] if src != "const"))
579
+ assert isinstance(source, tuple)
580
+ self.state.regs_to_initialize.append((*source, reg_offset.reg, reg_offset.bits))
581
+ except StopIteration:
582
+ # we don't need to initialize this register
583
+ # it might be caused by an incorrect analysis result
584
+ # e.g. PN-337140.bin 11e918 r0 comes from r4, r4 comes from r0@11e8c0, and r0@11e8c0 comes from
585
+ # function call sub_375c04. Since we do not analyze sub_375c04, we treat r0@11e918 as a constant 0.
586
+ pass
587
+
588
+ return self._top(size)
589
+
590
+
591
+ #
592
+ # State hooks
593
+ #
594
+
595
+
596
+ class StoreHook:
597
+ """
598
+ Hook for memory stores.
599
+ """
600
+
601
+ @staticmethod
602
+ def hook(state):
603
+ write_length = state.inspect.mem_write_length
604
+ if write_length is None:
605
+ write_length = len(state.inspect.mem_write_expr)
606
+ else:
607
+ write_length = write_length * state.arch.byte_width
608
+ state.inspect.mem_write_expr = claripy.BVS("instrumented_store", write_length)
609
+
610
+
611
+ class LoadHook:
612
+ """
613
+ Hook for memory loads.
614
+ """
615
+
616
+ def __init__(self):
617
+ self._var = None
618
+
619
+ def hook_before(self, state):
620
+ addr = state.inspect.mem_read_address
621
+ size = state.solver.eval(state.inspect.mem_read_length)
622
+ self._var = claripy.BVS("instrumented_load", size * 8)
623
+ state.memory.store(addr, self._var, endness=state.arch.memory_endness)
624
+
625
+ def hook_after(self, state):
626
+ state.inspect.mem_read_expr = self._var
627
+
628
+
629
+ class PutHook:
630
+ """
631
+ Hook for register writes.
632
+ """
633
+
634
+ @staticmethod
635
+ def hook(state):
636
+ state.inspect.reg_write_expr = claripy.BVS(
637
+ "instrumented_put", state.solver.eval(state.inspect.reg_write_length) * 8
638
+ )
639
+
640
+
641
+ class RegisterInitializerHook:
642
+ """
643
+ Hook for register init.
644
+ """
645
+
646
+ def __init__(self, reg_offset, reg_bits, initial_value):
647
+ self.reg_offset = reg_offset
648
+ self.reg_bits = reg_bits
649
+ self.value = initial_value
650
+
651
+ def hook(self, state):
652
+ state.registers.store(self.reg_offset, claripy.BVV(self.value, self.reg_bits))
653
+
654
+
655
+ class BSSHook:
656
+ """
657
+ Hook for BSS read/write.
658
+ """
659
+
660
+ def __init__(self, project, bss_regions):
661
+ self.project = project
662
+ self._bss_regions = bss_regions
663
+ self._written_addrs = set()
664
+
665
+ def bss_memory_read_hook(self, state):
666
+ if not self._bss_regions:
667
+ return
668
+
669
+ read_addr = state.inspect.mem_read_address
670
+ read_length = state.inspect.mem_read_length
671
+
672
+ if not isinstance(read_addr, int) and read_addr.symbolic:
673
+ # don't touch it
674
+ return
675
+
676
+ concrete_read_addr = state.solver.eval(read_addr)
677
+ concrete_read_length = state.solver.eval(read_length)
678
+
679
+ for start, size in self._bss_regions:
680
+ if start <= concrete_read_addr < start + size:
681
+ # this is a read from the .bss section
682
+ break
683
+ else:
684
+ return
685
+
686
+ if concrete_read_addr not in self._written_addrs:
687
+ # it was never written to before. we overwrite it with unconstrained bytes
688
+ for i in range(0, concrete_read_length, self.project.arch.bytes):
689
+ state.memory.store(
690
+ concrete_read_addr + i,
691
+ state.solver.Unconstrained("unconstrained", self.project.arch.bits),
692
+ endness=self.project.arch.memory_endness,
693
+ )
694
+
695
+ # job done :-)
696
+
697
+ def bss_memory_write_hook(self, state):
698
+ if not self._bss_regions:
699
+ return
700
+
701
+ write_addr = state.inspect.mem_write_address
702
+
703
+ if not isinstance(write_addr, int) and write_addr.symbolic:
704
+ return
705
+
706
+ concrete_write_addr = state.solver.eval(write_addr)
707
+ concrete_write_length = (
708
+ state.solver.eval(state.inspect.mem_write_length)
709
+ if state.inspect.mem_write_length is not None
710
+ else len(state.inspect.mem_write_expr) // state.arch.byte_width
711
+ )
712
+
713
+ for start, size in self._bss_regions:
714
+ if start <= concrete_write_addr < start + size:
715
+ # hit a BSS section
716
+ break
717
+ else:
718
+ return
719
+
720
+ if concrete_write_length > 1024:
721
+ l.warning("Writing more 1024 bytes to the BSS region, only considering the first 1024 bytes.")
722
+ concrete_write_length = 1024
723
+
724
+ for i in range(concrete_write_addr, concrete_write_length):
725
+ self._written_addrs.add(i)
726
+
727
+
728
+ class MIPSGPHook:
729
+ """
730
+ Hooks all reads from and writes into the gp register for MIPS32 binaries.
731
+ """
732
+
733
+ def __init__(self, gp_offset: int, gp: int):
734
+ self.gp_offset = gp_offset
735
+ self.gp = gp
736
+
737
+ def gp_register_read_hook(self, state):
738
+ read_offset = state.inspect.reg_read_offset
739
+ read_length = state.inspect.reg_read_length
740
+ if state.solver.eval(read_offset) == self.gp_offset and read_length == 4:
741
+ state.inspect.reg_read_expr = claripy.BVV(self.gp, size=32)
742
+
743
+ def gp_register_write_hook(self, state):
744
+ write_offset = state.inspect.reg_write_offset
745
+ write_length = state.inspect.reg_write_length
746
+ if state.solver.eval(write_offset) == self.gp_offset and write_length == 4:
747
+ state.inspect.reg_write_expr = claripy.BVV(self.gp, size=32)
748
+
749
+
750
+ #
751
+ # Main class
752
+ #
753
+
754
+
755
+ class JumpTableResolver(IndirectJumpResolver):
756
+ """
757
+ A generic jump table resolver.
758
+
759
+ This is a fast jump table resolution. For performance concerns, we made the following assumptions:
760
+ - The final jump target comes from the memory.
761
+ - The final jump target must be directly read out of the memory, without any further modification or altering.
762
+
763
+ Progressively larger program slices will be analyzed to determine jump table location and size. If the size of the
764
+ table cannot be determined, a *guess* will be made based on how many entries in the table *appear* valid.
765
+ """
766
+
767
+ def __init__(self, project, resolve_calls: bool = True):
768
+ super().__init__(project, timeless=False)
769
+
770
+ self.resolve_calls = resolve_calls
771
+
772
+ self._bss_regions = None
773
+ # the maximum number of resolved targets. Will be initialized from CFG.
774
+ self._max_targets = 0
775
+
776
+ # cached memory read addresses that are used to initialize uninitialized registers
777
+ # should be cleared before every symbolic execution run on the slice
778
+ self._cached_memread_addrs = {}
779
+
780
+ self._find_bss_region()
781
+
782
+ def filter(self, cfg, addr, func_addr, block, jumpkind):
783
+ if pcode is not None and isinstance(block.vex, pcode.lifter.IRSB):
784
+ if once("pcode__indirect_jump_resolver"):
785
+ l.warning("JumpTableResolver does not support P-Code IR yet; CFG may be incomplete.")
786
+ return False
787
+
788
+ if jumpkind == "Ijk_Boring":
789
+ return True
790
+ return bool(self.resolve_calls and jumpkind == "Ijk_Call")
791
+
792
+ def resolve(self, cfg, addr, func_addr, block, jumpkind, func_graph_complete: bool = True, **kwargs):
793
+ """
794
+ Resolves jump tables.
795
+
796
+ :param cfg: A CFG instance.
797
+ :param int addr: IRSB address.
798
+ :param int func_addr: The function address.
799
+ :param pyvex.IRSB block: The IRSB.
800
+ :return: A bool indicating whether the indirect jump is resolved successfully, and a list of resolved targets
801
+ :rtype: tuple
802
+ """
803
+
804
+ if not cfg.kb.functions.contains_addr(func_addr):
805
+ # fix for angr issue #3768
806
+ # the function must exist in the KB
807
+ return False, None
808
+
809
+ func: Function = cfg.kb.functions[func_addr]
810
+ self._max_targets = cfg._indirect_jump_target_limit
811
+
812
+ # this is an indirect call if (1) the instruction is a call, or (2) the instruction is a tail jump (we detect
813
+ # sp moving up to approximate)
814
+ potential_call_table = jumpkind == "Ijk_Call" or self._sp_moved_up(block) or len(func.block_addrs_set) <= 5
815
+ # we only perform full-function propagation for jump tables or call tables in really small functions
816
+ if not potential_call_table or len(func.block_addrs_set) <= 5:
817
+ cv_manager = ConstantValueManager(self.project, cfg.kb, func, addr)
818
+ else:
819
+ cv_manager = None
820
+
821
+ for slice_steps in range(1, 5):
822
+ # Perform a backward slicing from the jump target
823
+ # Important: Do not go across function call boundaries
824
+ b = Blade(
825
+ cfg.graph,
826
+ addr,
827
+ -1,
828
+ cfg=cfg,
829
+ project=self.project,
830
+ ignore_sp=False,
831
+ ignore_bp=False,
832
+ max_level=slice_steps,
833
+ base_state=self.base_state,
834
+ stop_at_calls=True,
835
+ cross_insn_opt=True,
836
+ )
837
+
838
+ l.debug("Try resolving %#x with a %d-level backward slice...", addr, slice_steps)
839
+ r, targets = self._resolve(
840
+ cfg, addr, func, b, cv_manager, potential_call_table=False, func_graph_complete=func_graph_complete
841
+ )
842
+ if r:
843
+ return r, targets
844
+
845
+ if potential_call_table:
846
+ b = Blade(
847
+ cfg.graph,
848
+ addr,
849
+ -1,
850
+ cfg=cfg,
851
+ project=self.project,
852
+ ignore_sp=False,
853
+ ignore_bp=False,
854
+ max_level=1,
855
+ base_state=self.base_state,
856
+ stop_at_calls=True,
857
+ cross_insn_opt=True,
858
+ )
859
+ return self._resolve(
860
+ cfg, addr, func, b, cv_manager, potential_call_table=True, func_graph_complete=func_graph_complete
861
+ )
862
+
863
+ return False, None
864
+
865
+ #
866
+ # Private methods
867
+ #
868
+
869
+ def _resolve(
870
+ self,
871
+ cfg,
872
+ addr: int,
873
+ func: Function,
874
+ b: Blade,
875
+ cv_manager: ConstantValueManager | None,
876
+ potential_call_table: bool = False,
877
+ func_graph_complete: bool = True,
878
+ ) -> tuple[bool, Sequence[int] | None]:
879
+ """
880
+ Internal method for resolving jump tables.
881
+
882
+ :param cfg: A CFG instance.
883
+ :param addr: Address of the block where the indirect jump is.
884
+ :param func: The Function instance.
885
+ :param b: The generated backward slice.
886
+ :return: A bool indicating whether the indirect jump is resolved successfully, and a list of
887
+ resolved targets.
888
+ """
889
+
890
+ project = self.project # short-hand
891
+ func_addr = func.addr
892
+ is_arm = is_arm_arch(self.project.arch)
893
+
894
+ stmt_loc = (addr, DEFAULT_STATEMENT)
895
+ if stmt_loc not in b.slice:
896
+ return False, None
897
+
898
+ (
899
+ load_stmt_loc,
900
+ load_stmt,
901
+ load_size,
902
+ stmts_to_remove,
903
+ stmts_adding_base_addr,
904
+ transformations,
905
+ ) = self._find_load_statement(b, stmt_loc)
906
+ ite_stmt, ite_stmt_loc = None, None
907
+
908
+ if load_stmt_loc is None:
909
+ # the load statement is not found
910
+ # maybe it's a typical ARM-style jump table like the following:
911
+ # SUB R3, R5, #34
912
+ # CMP R3, #28
913
+ # ADDLS PC, PC, R3,LSL#2
914
+ if is_arm:
915
+ ite_stmt, ite_stmt_loc, stmts_to_remove = self._find_load_pc_ite_statement(b, stmt_loc)
916
+ if ite_stmt is None:
917
+ l.debug("Could not find load statement in this slice")
918
+ return False, None
919
+
920
+ # more sanity checks
921
+
922
+ # for a typical jump table, the current block has only one predecessor, and the predecessor to the current
923
+ # block has two successors (not including itself)
924
+ # for a typical vtable call (or jump if at the end of a function), the block as two predecessors that form a
925
+ # diamond shape
926
+ curr_node = func.get_node(addr)
927
+ if curr_node is None or curr_node not in func.graph:
928
+ l.debug("Could not find the node %#x in the function transition graph", addr)
929
+ return False, None
930
+ preds = list(func.graph.predecessors(curr_node))
931
+ pred_endaddrs = {pred.addr + pred.size for pred in preds} # handle non-normalized CFGs
932
+ if func_graph_complete and not is_arm and not potential_call_table:
933
+ # on ARM you can do a single-block jump table...
934
+ if len(pred_endaddrs) == 1:
935
+ pred_succs = [succ for succ in func.graph.successors(preds[0]) if succ.addr != preds[0].addr]
936
+ if len(pred_succs) != 2:
937
+ l.debug("Expect two successors to the single predecessor, found %d.", len(pred_succs))
938
+ return False, None
939
+ elif len(pred_endaddrs) == 2 and len(preds) == 2:
940
+ pred_succs = set(
941
+ [succ for succ in func.graph.successors(preds[0]) if succ.addr != preds[0].addr]
942
+ + [succ for succ in func.graph.successors(preds[1]) if succ.addr != preds[1].addr]
943
+ )
944
+ is_diamond = False
945
+ if len(pred_succs) == 2:
946
+ non_node_succ = next(iter(pred_succ for pred_succ in pred_succs if pred_succ is not curr_node))
947
+ while func.graph.out_degree[non_node_succ] == 1:
948
+ non_node_succ = next(iter(func.graph.successors(non_node_succ)))
949
+ if non_node_succ == curr_node:
950
+ is_diamond = True
951
+ break
952
+ if not is_diamond:
953
+ l.debug("Expect a diamond shape.")
954
+ return False, None
955
+ else:
956
+ l.debug("The predecessor-successor shape does not look like a jump table or a vtable jump/call.")
957
+ return False, None
958
+
959
+ try:
960
+ jump_target = self._try_resolve_single_constant_loads(load_stmt, cfg, addr)
961
+ except NotAJumpTableNotification:
962
+ return False, None
963
+ if jump_target is not None:
964
+ if self._is_target_valid(cfg, jump_target):
965
+ ij = cfg.indirect_jumps.get(addr, None)
966
+ if ij is not None:
967
+ ij.jumptable = False
968
+ ij.resolved_targets = {jump_target}
969
+ return True, [jump_target]
970
+ l.debug("Found single constant load, but it does not appear to be a valid target")
971
+ return False, None
972
+
973
+ # Well, we have a real jump table to resolve!
974
+
975
+ # skip all statements after the load statement
976
+ # We want to leave the final loaded value as symbolic, so we can
977
+ # get the full range of possibilities
978
+ b.slice.remove_nodes_from(stmts_to_remove)
979
+
980
+ stmts_to_instrument, regs_to_initialize = [], []
981
+ try:
982
+ stmts_to_instrument, regs_to_initialize = self._jumptable_precheck(b, {pred.addr for pred in preds})
983
+ l.debug(
984
+ "jumptable_precheck provides stmts_to_instrument = %s, regs_to_initialize = %s",
985
+ stmts_to_instrument,
986
+ regs_to_initialize,
987
+ )
988
+ except NotAJumpTableNotification:
989
+ if not potential_call_table and not is_arm:
990
+ l.debug("Indirect jump at %#x does not look like a jump table. Skip.", addr)
991
+ return False, None
992
+
993
+ # Debugging output
994
+ if l.level == logging.DEBUG:
995
+ self._dbg_repr_slice(b)
996
+
997
+ # Get all sources
998
+ sources = [n_ for n_ in b.slice.nodes() if b.slice.in_degree(n_) == 0]
999
+
1000
+ # Create the annotated CFG
1001
+ annotatedcfg = AnnotatedCFG(project, None, detect_loops=False)
1002
+ annotatedcfg.from_digraph(b.slice)
1003
+
1004
+ # pylint: disable=too-many-nested-blocks
1005
+ for block_addr, _ in sources:
1006
+ # Use slicecutor to execute each one, and get the address
1007
+ # We simply give up if any exception occurs on the way
1008
+ start_state = self._initial_state(block_addr, cfg, func_addr)
1009
+
1010
+ # instrument specified store/put/load statements
1011
+ self._instrument_statements(start_state, stmts_to_instrument, regs_to_initialize)
1012
+
1013
+ self._cached_memread_addrs.clear()
1014
+ init_registers_on_demand_bp = BP(when=BP_BEFORE, enabled=True, action=self._init_registers_on_demand)
1015
+ start_state.inspect.add_breakpoint("mem_read", init_registers_on_demand_bp)
1016
+
1017
+ # constant value manager
1018
+ if cv_manager is not None:
1019
+ constant_value_reg_read_bp = BP(when=BP_AFTER, enabled=True, action=cv_manager.reg_read_callback)
1020
+ start_state.inspect.add_breakpoint("reg_read", constant_value_reg_read_bp)
1021
+
1022
+ # use Any as the concretization strategy
1023
+ start_state.memory.read_strategies = [SimConcretizationStrategyAny()]
1024
+ start_state.memory.write_strategies = [SimConcretizationStrategyAny()]
1025
+
1026
+ # Create the slicecutor
1027
+ simgr = self.project.factory.simulation_manager(start_state, resilience=True)
1028
+ slicecutor = Slicecutor(annotatedcfg, force_taking_exit=True)
1029
+ simgr.use_technique(slicecutor)
1030
+ simgr.use_technique(LocalLoopSeer(bound=1))
1031
+ if load_stmt is not None:
1032
+ assert load_stmt_loc is not None
1033
+ explorer = Explorer(find=load_stmt_loc[0])
1034
+ elif ite_stmt is not None:
1035
+ assert ite_stmt_loc is not None
1036
+ explorer = Explorer(find=ite_stmt_loc[0])
1037
+ else:
1038
+ raise TypeError("Unsupported type of jump table.")
1039
+ simgr.use_technique(explorer)
1040
+
1041
+ # Run it!
1042
+ try:
1043
+ simgr.run()
1044
+ except KeyError as ex:
1045
+ # This is because the program slice is incomplete.
1046
+ # Blade will support more IRExprs and IRStmts in the future
1047
+ l.debug("KeyError occurred due to incomplete program slice.", exc_info=ex)
1048
+ continue
1049
+
1050
+ # Get the jumping targets
1051
+ for r in simgr.found:
1052
+ if load_stmt is not None:
1053
+ ret = self._try_resolve_targets_load(
1054
+ r,
1055
+ addr,
1056
+ cfg,
1057
+ annotatedcfg,
1058
+ load_stmt,
1059
+ load_size,
1060
+ stmts_adding_base_addr,
1061
+ transformations,
1062
+ potential_call_table,
1063
+ )
1064
+ if ret is None:
1065
+ # Try the next state
1066
+ continue
1067
+ jump_table, jumptable_addr, entry_size, jumptable_size, all_targets, sort = ret
1068
+ if sort == "jumptable":
1069
+ ij_type = IndirectJumpType.Jumptable_AddressLoadedFromMemory
1070
+ elif sort == "vtable":
1071
+ ij_type = IndirectJumpType.Vtable
1072
+ else:
1073
+ ij_type = IndirectJumpType.Unknown
1074
+ elif ite_stmt is not None:
1075
+ ret = self._try_resolve_targets_ite(r, addr, cfg, annotatedcfg, ite_stmt)
1076
+ if ret is None:
1077
+ # Try the next state
1078
+ continue
1079
+ jumptable_addr = None
1080
+ jump_table, jumptable_size, entry_size = ret
1081
+ all_targets = jump_table
1082
+ ij_type = IndirectJumpType.Jumptable_AddressComputed
1083
+ else:
1084
+ raise TypeError("Unsupported type of jump table.")
1085
+
1086
+ assert ret is not None
1087
+
1088
+ # finally, we filter jump targets according to the alignment of the architecture
1089
+ if is_arm_arch(self.project.arch):
1090
+ alignment = 4 if addr % 2 == 0 else 2
1091
+ else:
1092
+ alignment = self.project.arch.instruction_alignment
1093
+ if alignment != 1:
1094
+ if is_arm_arch(self.project.arch) and addr % 2 == 1:
1095
+ # Special logic for handling THUMB addresses
1096
+ all_targets = [t_ for t_ in all_targets if (t_ - 1) % alignment == 0]
1097
+ else:
1098
+ all_targets = [t_ for t_ in all_targets if t_ % alignment == 0]
1099
+
1100
+ l.info(
1101
+ "Jump table at %#x has %d targets: %s",
1102
+ addr,
1103
+ len(all_targets),
1104
+ ", ".join([hex(a) for a in all_targets]),
1105
+ )
1106
+
1107
+ # write to the IndirectJump object in CFG
1108
+ ij: IndirectJump = cfg.indirect_jumps.get(addr, None)
1109
+ if ij is not None:
1110
+ if len(all_targets) > 1:
1111
+ # It can be considered a jump table only if there are more than one jump target
1112
+ if ij_type in {
1113
+ IndirectJumpType.Jumptable_AddressComputed,
1114
+ IndirectJumpType.Jumptable_AddressLoadedFromMemory,
1115
+ }:
1116
+ ij.jumptable = True
1117
+ else:
1118
+ ij.jumptable = False
1119
+ ij.jumptable_addr = jumptable_addr
1120
+ ij.jumptable_size = jumptable_size
1121
+ ij.jumptable_entry_size = entry_size
1122
+ ij.resolved_targets = set(jump_table)
1123
+ ij.jumptable_entries = jump_table
1124
+ ij.type = ij_type
1125
+ else:
1126
+ ij.jumptable = False
1127
+ ij.resolved_targets = set(jump_table)
1128
+
1129
+ return True, all_targets
1130
+
1131
+ l.info("Could not resolve indirect jump %#x in function %#x.", addr, func_addr)
1132
+ return False, None
1133
+
1134
+ def _find_load_statement(self, b, stmt_loc: tuple[int, int]) -> tuple[
1135
+ tuple[int, int] | None,
1136
+ pyvex.stmt.IRStmt | None,
1137
+ int | None,
1138
+ list[tuple[int, int]],
1139
+ list[JumpTargetBaseAddr],
1140
+ OrderedDict[tuple[int, int], AddressTransformation],
1141
+ ]:
1142
+ """
1143
+ Find the location of the final Load statement that loads indirect jump targets from the jump table.
1144
+ """
1145
+
1146
+ # pylint:disable=no-else-continue
1147
+
1148
+ # shorthand
1149
+ project = self.project
1150
+
1151
+ # initialization
1152
+ load_stmt_loc, load_stmt, load_size = None, None, None
1153
+ stmts_to_remove = [stmt_loc]
1154
+ stmts_adding_base_addr: list[JumpTargetBaseAddr] = []
1155
+ # All temporary variables that hold indirect addresses loaded out of the memory
1156
+ # Obviously, load_stmt.tmp must be here
1157
+ # if there are additional data transferring statements between the Load statement and the base-address-adding
1158
+ # statement, all_addr_holders will have more than one temporary variables
1159
+ #
1160
+ # Here is an example:
1161
+ #
1162
+ # IRSB 0x4c64c4
1163
+ # + 06 | t12 = LDle:I32(t7)
1164
+ # + 07 | t11 = 32Sto64(t12)
1165
+ # + 10 | t2 = Add64(0x0000000000571df0,t11)
1166
+ #
1167
+ # all_addr_holders will be {(0x4c64c4, 11): (AddressTransferringTypes.SignedExtension, 32, 64,),
1168
+ # (0x4c64c4, 12); (AddressTransferringTypes.Assignment,),
1169
+ # }
1170
+ transformations: dict[tuple[int, int], AddressTransformation] = OrderedDict()
1171
+
1172
+ initial_block_addr = stmt_loc[0]
1173
+ all_load_stmts = sorted(self._all_qualified_load_stmts_in_slice(b, stmt_loc[0]))
1174
+
1175
+ while True:
1176
+ preds = list(b.slice.predecessors(stmt_loc))
1177
+ if len(preds) != 1:
1178
+ break
1179
+ block_addr, stmt_idx = stmt_loc = preds[0]
1180
+ block = project.factory.block(block_addr, cross_insn_opt=True, backup_state=self.base_state).vex
1181
+ if stmt_idx == DEFAULT_STATEMENT:
1182
+ # it's the default exit. continue
1183
+ continue
1184
+ stmt = block.statements[stmt_idx]
1185
+ if isinstance(stmt, (pyvex.IRStmt.WrTmp, pyvex.IRStmt.Put)):
1186
+ if isinstance(stmt.data, (pyvex.IRExpr.Get, pyvex.IRExpr.RdTmp)):
1187
+ # data transferring
1188
+ stmts_to_remove.append(stmt_loc)
1189
+ if isinstance(stmt, pyvex.IRStmt.WrTmp):
1190
+ transformations[(stmt_loc[0], stmt.tmp)] = AddressTransformation(
1191
+ AddressTransformationTypes.Assignment, [stmt.tmp, AddressSingleton]
1192
+ )
1193
+ continue
1194
+ if isinstance(stmt.data, pyvex.IRExpr.ITE):
1195
+ # data transferring
1196
+ # t16 = if (t43) ILGop_Ident32(LDle(t29)) else 0x0000c844
1197
+ # > t44 = ITE(t43,t16,0x0000c844)
1198
+ stmts_to_remove.append(stmt_loc)
1199
+ if isinstance(stmt, pyvex.IRStmt.WrTmp):
1200
+ transformations[(stmt_loc[0], stmt.tmp)] = AddressTransformation(
1201
+ AddressTransformationTypes.Assignment, [stmt.tmp, AddressSingleton]
1202
+ )
1203
+ continue
1204
+ if isinstance(stmt.data, pyvex.IRExpr.Unop):
1205
+ if stmt.data.op == "Iop_32Sto64":
1206
+ # data transferring with conversion
1207
+ # t11 = 32Sto64(t12)
1208
+ stmts_to_remove.append(stmt_loc)
1209
+ if isinstance(stmt, pyvex.IRStmt.WrTmp):
1210
+ transformations[(stmt_loc[0], stmt.tmp)] = AddressTransformation(
1211
+ AddressTransformationTypes.SignedExtension, [32, 64, AddressSingleton]
1212
+ )
1213
+ continue
1214
+ if stmt.data.op == "Iop_64to32":
1215
+ # data transferring with conversion
1216
+ # t24 = 64to32(t21)
1217
+ stmts_to_remove.append(stmt_loc)
1218
+ if isinstance(stmt, pyvex.IRStmt.WrTmp):
1219
+ transformations[(stmt_loc[0], stmt.tmp)] = AddressTransformation(
1220
+ AddressTransformationTypes.Truncation, [64, 32, AddressSingleton]
1221
+ )
1222
+ continue
1223
+ if stmt.data.op == "Iop_32Uto64":
1224
+ # data transferring with conversion
1225
+ # t21 = 32Uto64(t22)
1226
+ stmts_to_remove.append(stmt_loc)
1227
+ if isinstance(stmt, pyvex.IRStmt.WrTmp):
1228
+ transformations[(stmt_loc[0], stmt.tmp)] = AddressTransformation(
1229
+ AddressTransformationTypes.UnsignedExtension, [32, 64, AddressSingleton]
1230
+ )
1231
+ continue
1232
+ if stmt.data.op == "Iop_16Uto32":
1233
+ # data transferring with conversion
1234
+ stmts_to_remove.append(stmt_loc)
1235
+ if isinstance(stmt, pyvex.IRStmt.WrTmp):
1236
+ transformations[(stmt_loc[0], stmt.tmp)] = AddressTransformation(
1237
+ AddressTransformationTypes.UnsignedExtension, [16, 32, AddressSingleton]
1238
+ )
1239
+ continue
1240
+ if stmt.data.op == "Iop_8Uto32":
1241
+ # data transferring with conversion
1242
+ stmts_to_remove.append(stmt_loc)
1243
+ if isinstance(stmt, pyvex.IRStmt.WrTmp):
1244
+ transformations[(stmt_loc[0], stmt.tmp)] = AddressTransformation(
1245
+ AddressTransformationTypes.UnsignedExtension, [8, 32, AddressSingleton]
1246
+ )
1247
+ continue
1248
+ if stmt.data.op == "Iop_8Uto64":
1249
+ stmts_to_remove.append(stmt_loc)
1250
+ if isinstance(stmt, pyvex.IRStmt.WrTmp):
1251
+ transformations[(stmt_loc[0], stmt.tmp)] = AddressTransformation(
1252
+ AddressTransformationTypes.UnsignedExtension, [8, 64, AddressSingleton]
1253
+ )
1254
+ continue
1255
+ elif isinstance(stmt.data, pyvex.IRExpr.Binop):
1256
+ if stmt.data.op.startswith("Iop_Add"):
1257
+ # GitHub issue #1289, an S390X binary
1258
+ # jump_label = &jump_table + *(jump_table[index])
1259
+ # IRSB 0x4007c0
1260
+ # 00 | ------ IMark(0x4007c0, 4, 0) ------
1261
+ # + 01 | t0 = GET:I32(212)
1262
+ # + 02 | t1 = Add32(t0,0xffffffff)
1263
+ # 03 | PUT(352) = 0x0000000000000003
1264
+ # 04 | t13 = 32Sto64(t0)
1265
+ # 05 | t6 = t13
1266
+ # 06 | PUT(360) = t6
1267
+ # 07 | PUT(368) = 0xffffffffffffffff
1268
+ # 08 | PUT(376) = 0x0000000000000000
1269
+ # 09 | PUT(212) = t1
1270
+ # 10 | PUT(ia) = 0x00000000004007c4
1271
+ # 11 | ------ IMark(0x4007c4, 6, 0) ------
1272
+ # + 12 | t14 = 32Uto64(t1)
1273
+ # + 13 | t8 = t14
1274
+ # + 14 | t16 = CmpLE64U(t8,0x000000000000000b)
1275
+ # + 15 | t15 = 1Uto32(t16)
1276
+ # + 16 | t10 = t15
1277
+ # + 17 | t11 = CmpNE32(t10,0x00000000)
1278
+ # + 18 | if (t11) { PUT(offset=336) = 0x4007d4; Ijk_Boring }
1279
+ # Next: 0x4007ca
1280
+ #
1281
+ # IRSB 0x4007d4
1282
+ # 00 | ------ IMark(0x4007d4, 6, 0) ------
1283
+ # + 01 | t8 = GET:I64(r2)
1284
+ # + 02 | t7 = Shr64(t8,0x3d)
1285
+ # + 03 | t9 = Shl64(t8,0x03)
1286
+ # + 04 | t6 = Or64(t9,t7)
1287
+ # + 05 | t11 = And64(t6,0x00000007fffffff8)
1288
+ # 06 | ------ IMark(0x4007da, 6, 0) ------
1289
+ # 07 | PUT(r1) = 0x0000000000400a50
1290
+ # 08 | PUT(ia) = 0x00000000004007e0
1291
+ # 09 | ------ IMark(0x4007e0, 6, 0) ------
1292
+ # + 10 | t12 = Add64(0x0000000000400a50,t11)
1293
+ # + 11 | t16 = LDbe:I64(t12)
1294
+ # 12 | PUT(r2) = t16
1295
+ # 13 | ------ IMark(0x4007e6, 4, 0) ------
1296
+ # + 14 | t17 = Add64(0x0000000000400a50,t16)
1297
+ # + Next: t17
1298
+ #
1299
+ # Special case: a base address is added to the loaded offset before jumping to it.
1300
+ if isinstance(stmt.data.args[0], pyvex.IRExpr.Const) and isinstance(
1301
+ stmt.data.args[1], pyvex.IRExpr.RdTmp
1302
+ ):
1303
+ assert isinstance(stmt, pyvex.stmt.WrTmp)
1304
+ transformations[(stmt_loc[0], stmt.tmp)] = AddressTransformation(
1305
+ AddressTransformationTypes.Add, [stmt.data.args[0].con.value, AddressSingleton]
1306
+ )
1307
+ # we no longer update stmts_adding_base_addr in this case because it's replaced by
1308
+ # transformations
1309
+ stmts_to_remove.append(stmt_loc)
1310
+ elif isinstance(stmt.data.args[0], pyvex.IRExpr.RdTmp) and isinstance(
1311
+ stmt.data.args[1], pyvex.IRExpr.Const
1312
+ ):
1313
+ assert isinstance(stmt, pyvex.stmt.WrTmp)
1314
+ transformations[(stmt_loc[0], stmt.tmp)] = AddressTransformation(
1315
+ AddressTransformationTypes.Add, [AddressSingleton, stmt.data.args[1].con.value]
1316
+ )
1317
+ # we no longer update stmts_adding_base_addr in this case because it's replaced by
1318
+ # transformations
1319
+ stmts_to_remove.append(stmt_loc)
1320
+ elif isinstance(stmt.data.args[0], pyvex.IRExpr.RdTmp) and isinstance(
1321
+ stmt.data.args[1], pyvex.IRExpr.RdTmp
1322
+ ):
1323
+ # one of the tmps must be holding a concrete value at this point. we will know this when
1324
+ # we perform constant propagation before running JumpTableResolver. this can act as an
1325
+ # indicator that we need to run constant propagation for this function.
1326
+ # for now, we don't support it :)
1327
+ # FIXME: Run constant propagation for the function when necessary. we can also remove
1328
+ # stmts_adding_base_addr and the surrounding logic then.
1329
+ # transformations[(stmt_loc[0], stmt.tmp)] = AddressTransformation(
1330
+ # AddressTransferringTypes.Add,
1331
+ # [Tmp(stmt.data.args[0].tmp), Tmp(stmt.data.args[1].tmp)],
1332
+ # )
1333
+ stmts_adding_base_addr.append(
1334
+ JumpTargetBaseAddr(stmt_loc, stmt, stmt.data.args[0].tmp, tmp_1=stmt.data.args[1].tmp)
1335
+ )
1336
+ stmts_to_remove.append(stmt_loc)
1337
+ else:
1338
+ # not supported
1339
+ pass
1340
+ continue
1341
+ if stmt.data.op.startswith("Iop_Or"):
1342
+ # this is sometimes used in VEX statements in THUMB mode code to adjust the address to an odd
1343
+ # number
1344
+ # e.g.
1345
+ # IRSB 0x4b63
1346
+ # 00 | ------ IMark(0x4b62, 4, 1) ------
1347
+ # 01 | PUT(itstate) = 0x00000000
1348
+ # + 02 | t11 = GET:I32(r2)
1349
+ # + 03 | t10 = Shl32(t11,0x01)
1350
+ # + 04 | t9 = Add32(0x00004b66,t10)
1351
+ # + 05 | t8 = LDle:I16(t9)
1352
+ # + 06 | t7 = 16Uto32(t8)
1353
+ # + 07 | t14 = Shl32(t7,0x01)
1354
+ # + 08 | t13 = Add32(0x00004b66,t14)
1355
+ # + 09 | t12 = Or32(t13,0x00000001)
1356
+ # + Next: t12
1357
+ if (
1358
+ isinstance(stmt.data.args[0], pyvex.IRExpr.RdTmp)
1359
+ and isinstance(stmt.data.args[1], pyvex.IRExpr.Const)
1360
+ and stmt.data.args[1].con.value == 1
1361
+ ):
1362
+ assert isinstance(stmt, pyvex.stmt.WrTmp)
1363
+ # great. here it is
1364
+ stmts_to_remove.append(stmt_loc)
1365
+ transformations[(stmt_loc[0], stmt.tmp)] = AddressTransformation(
1366
+ AddressTransformationTypes.Or1, [AddressSingleton]
1367
+ )
1368
+ continue
1369
+ elif stmt.data.op.startswith("Iop_Shl"):
1370
+ # this is sometimes used when dealing with TBx instructions in ARM code.
1371
+ # e.g.
1372
+ # IRSB 0x4b63
1373
+ # 00 | ------ IMark(0x4b62, 4, 1) ------
1374
+ # 01 | PUT(itstate) = 0x00000000
1375
+ # + 02 | t11 = GET:I32(r2)
1376
+ # + 03 | t10 = Shl32(t11,0x01)
1377
+ # + 04 | t9 = Add32(0x00004b66,t10)
1378
+ # + 05 | t8 = LDle:I16(t9)
1379
+ # + 06 | t7 = 16Uto32(t8)
1380
+ # + 07 | t14 = Shl32(t7,0x01)
1381
+ # + 08 | t13 = Add32(0x00004b66,t14)
1382
+ # + 09 | t12 = Or32(t13,0x00000001)
1383
+ # + Next: t12
1384
+ if isinstance(stmt.data.args[0], pyvex.IRExpr.RdTmp) and isinstance(
1385
+ stmt.data.args[1], pyvex.IRExpr.Const
1386
+ ):
1387
+ assert isinstance(stmt, pyvex.stmt.WrTmp)
1388
+ # found it
1389
+ stmts_to_remove.append(stmt_loc)
1390
+ transformations[(stmt_loc[0], stmt.tmp)] = AddressTransformation(
1391
+ AddressTransformationTypes.ShiftLeft, [AddressSingleton, stmt.data.args[1].con.value]
1392
+ )
1393
+ continue
1394
+ # AArch64
1395
+ #
1396
+ # LDRB W0, [X20,W26,UXTW]
1397
+ # ADR X1, loc_11F85C
1398
+ # ADD X0, X1, W0,SXTB#2
1399
+ # BR X0
1400
+ #
1401
+ # IRSB 0x51f84c
1402
+ # + 00 | ------ IMark(0x51f84c, 4, 0) ------
1403
+ # + 01 | t8 = GET:I64(x26)
1404
+ # + 02 | t7 = 64to32(t8)
1405
+ # + 03 | t6 = 32Uto64(t7)
1406
+ # + 04 | t9 = GET:I64(x20)
1407
+ # + 05 | t5 = Add64(t9,t6)
1408
+ # + 06 | t11 = LDle:I8(t5)
1409
+ # + 07 | t10 = 8Uto64(t11)
1410
+ # + 08 | ------ IMark(0x51f850, 4, 0) ------
1411
+ # 09 | PUT(x1) = 0x000000000051f85c
1412
+ # + 10 | ------ IMark(0x51f854, 4, 0) ------
1413
+ # + 11 | t14 = Shl64(t10,0x38)
1414
+ # + 12 | t13 = Sar64(t14,0x38)
1415
+ # + 13 | t12 = Shl64(t13,0x02)
1416
+ # + 14 | t4 = Add64(0x000000000051f85c,t12)
1417
+ # 15 | PUT(x0) = t4
1418
+ # + 16 | ------ IMark(0x51f858, 4, 0) ------
1419
+ # + Next: t4
1420
+ elif (
1421
+ stmt.data.op.startswith("Iop_Sar")
1422
+ and isinstance(stmt.data.args[0], pyvex.IRExpr.RdTmp)
1423
+ and isinstance(stmt.data.args[1], pyvex.IRExpr.Const)
1424
+ ):
1425
+ assert isinstance(stmt, pyvex.stmt.WrTmp)
1426
+ # found it
1427
+ stmts_to_remove.append(stmt_loc)
1428
+ transformations[(stmt_loc[0], stmt.tmp)] = AddressTransformation(
1429
+ AddressTransformationTypes.ShiftRight, [AddressSingleton, stmt.data.args[1].con.value]
1430
+ )
1431
+ continue
1432
+ elif isinstance(stmt.data, pyvex.IRExpr.Load):
1433
+ assert isinstance(stmt, pyvex.stmt.WrTmp)
1434
+ # Got it!
1435
+ load_stmt, load_stmt_loc, load_size = (
1436
+ stmt,
1437
+ stmt_loc,
1438
+ block.tyenv.sizeof(stmt.tmp) // self.project.arch.byte_width,
1439
+ )
1440
+ stmts_to_remove.append(stmt_loc)
1441
+ is_first_load_stmt = (
1442
+ True if not all_load_stmts else (stmt_loc == (initial_block_addr, all_load_stmts[0]))
1443
+ )
1444
+ transformations[(stmt_loc[0], stmt.tmp)] = AddressTransformation(
1445
+ AddressTransformationTypes.Load, [AddressSingleton, load_size], first_load=is_first_load_stmt
1446
+ )
1447
+ if not is_first_load_stmt:
1448
+ # This is not the first load statement in the block. more to go
1449
+ continue
1450
+ elif isinstance(stmt, pyvex.IRStmt.LoadG):
1451
+ # Got it!
1452
+ #
1453
+ # this is how an ARM jump table is translated to VEX
1454
+ # > t16 = if (t43) ILGop_Ident32(LDle(t29)) else 0x0000c844
1455
+ load_stmt, load_stmt_loc, load_size = (
1456
+ stmt,
1457
+ stmt_loc,
1458
+ block.tyenv.sizeof(stmt.dst) // self.project.arch.byte_width,
1459
+ )
1460
+ stmts_to_remove.append(stmt_loc)
1461
+ elif isinstance(stmt, pyvex.IRStmt.IMark):
1462
+ continue
1463
+
1464
+ break
1465
+
1466
+ return load_stmt_loc, load_stmt, load_size, stmts_to_remove, stmts_adding_base_addr, transformations
1467
+
1468
+ def _find_load_pc_ite_statement(self, b: Blade, stmt_loc: tuple[int, int]):
1469
+ """
1470
+ Find the location of the final ITE statement that loads indirect jump targets into a tmp.
1471
+
1472
+ The slice looks like the following:
1473
+
1474
+ IRSB 0x41d0fc
1475
+ 00 | ------ IMark(0x41d0fc, 4, 0) ------
1476
+ + 01 | t0 = GET:I32(r5)
1477
+ + 02 | t2 = Sub32(t0,0x00000022)
1478
+ 03 | PUT(r3) = t2
1479
+ 04 | ------ IMark(0x41d100, 4, 0) ------
1480
+ 05 | PUT(cc_op) = 0x00000002
1481
+ 06 | PUT(cc_dep1) = t2
1482
+ 07 | PUT(cc_dep2) = 0x0000001c
1483
+ 08 | PUT(cc_ndep) = 0x00000000
1484
+ 09 | ------ IMark(0x41d104, 4, 0) ------
1485
+ + 10 | t25 = CmpLE32U(t2,0x0000001c)
1486
+ 11 | t24 = 1Uto32(t25)
1487
+ + 12 | t8 = Shl32(t2,0x02)
1488
+ + 13 | t10 = Add32(0x0041d10c,t8)
1489
+ + 14 | t26 = ITE(t25,t10,0x0041d104) <---- this is the statement that we are looking for. Note that
1490
+ 0x0041d104 *must* be ignored since it is a side effect generated
1491
+ by the VEX ARM lifter
1492
+ 15 | PUT(pc) = t26
1493
+ 16 | t21 = Xor32(t24,0x00000001)
1494
+ 17 | t27 = 32to1(t21)
1495
+ 18 | if (t27) { PUT(offset=68) = 0x41d108; Ijk_Boring }
1496
+ + Next: t26
1497
+
1498
+ :param b: The Blade instance, which comes with the slice.
1499
+ :param stmt_loc: The location of the final statement.
1500
+ :return:
1501
+ """
1502
+
1503
+ project = self.project
1504
+ ite_stmt, ite_stmt_loc = None, None
1505
+ stmts_to_remove = [stmt_loc]
1506
+
1507
+ while True:
1508
+ preds = list(b.slice.predecessors(stmt_loc))
1509
+ if len(preds) != 1:
1510
+ break
1511
+ block_addr, stmt_idx = stmt_loc = preds[0]
1512
+ stmts_to_remove.append(stmt_loc)
1513
+ block = project.factory.block(block_addr, cross_insn_opt=True).vex
1514
+ if stmt_idx == DEFAULT_STATEMENT:
1515
+ # we should not reach the default exit (which belongs to a predecessor block)
1516
+ break
1517
+ if not isinstance(block.next, pyvex.IRExpr.RdTmp):
1518
+ # next must be an RdTmp
1519
+ break
1520
+ stmt = block.statements[stmt_idx]
1521
+ if (
1522
+ isinstance(stmt, pyvex.IRStmt.WrTmp)
1523
+ and stmt.tmp == block.next.tmp
1524
+ and isinstance(stmt.data, pyvex.IRExpr.ITE)
1525
+ ):
1526
+ # yes!
1527
+ ite_stmt, ite_stmt_loc = stmt, stmt_loc
1528
+ break
1529
+
1530
+ return ite_stmt, ite_stmt_loc, stmts_to_remove
1531
+
1532
+ def _jumptable_precheck(self, b, indirect_jump_node_pred_addrs):
1533
+ """
1534
+ Perform a pre-check on the slice to determine whether it is a jump table or not. Please refer to the docstring
1535
+ of JumpTableProcessor for how precheck and statement instrumentation works. A NotAJumpTableNotification
1536
+ exception will be raised if the slice fails this precheck.
1537
+
1538
+ :param b: The statement slice generated by Blade.
1539
+ :return: A list of statements to instrument, and a list of registers to initialize.
1540
+ :rtype: tuple of lists
1541
+ """
1542
+
1543
+ # pylint:disable=no-else-continue
1544
+
1545
+ engine = JumpTableProcessor(self.project, indirect_jump_node_pred_addrs)
1546
+
1547
+ sources = [n for n in b.slice.nodes() if b.slice.in_degree(n) == 0]
1548
+
1549
+ annotatedcfg = AnnotatedCFG(self.project, None, detect_loops=False)
1550
+ annotatedcfg.from_digraph(b.slice)
1551
+
1552
+ for src in sources:
1553
+ state = JumpTableProcessorState(self.project.arch)
1554
+ traced = {src[0]}
1555
+ while src is not None:
1556
+ state._tmpvar_source.clear()
1557
+ block_addr, _ = src
1558
+
1559
+ block = self.project.factory.block(block_addr, cross_insn_opt=True, backup_state=self.base_state)
1560
+ stmt_whitelist = annotatedcfg.get_whitelisted_statements(block_addr)
1561
+ assert isinstance(stmt_whitelist, list)
1562
+ try:
1563
+ engine.process(state, block=block, whitelist=stmt_whitelist)
1564
+ except (claripy.ClaripyError, SimError, AngrError):
1565
+ # anything can happen
1566
+ break
1567
+
1568
+ if state.is_jumptable:
1569
+ return state.stmts_to_instrument, state.regs_to_initialize
1570
+ if state.is_jumptable is False:
1571
+ raise NotAJumpTableNotification
1572
+
1573
+ # find the next block
1574
+ src = None
1575
+ for idx in reversed(stmt_whitelist):
1576
+ loc = (block_addr, idx)
1577
+ successors = list(b.slice.successors(loc))
1578
+ if len(successors) == 1:
1579
+ block_addr_ = successors[0][0]
1580
+ if block_addr_ not in traced:
1581
+ src = successors[0]
1582
+ traced.add(block_addr_)
1583
+ break
1584
+
1585
+ raise NotAJumpTableNotification
1586
+
1587
+ @staticmethod
1588
+ def _try_resolve_single_constant_loads(load_stmt, cfg, addr):
1589
+ """
1590
+ Resolve cases where only a single constant load is required to resolve the indirect jump. Strictly speaking, it
1591
+ is not a jump table, but we resolve it here anyway.
1592
+
1593
+ :param load_stmt: The pyvex.IRStmt.Load statement that loads an address.
1594
+ :param cfg: The CFG instance.
1595
+ :param int addr: Address of the jump table block.
1596
+ :return: A jump target, or None if it cannot be resolved.
1597
+ :rtype: int or None
1598
+ """
1599
+
1600
+ # If we're just reading a constant, don't bother with the rest of this mess!
1601
+ if isinstance(load_stmt, pyvex.IRStmt.WrTmp):
1602
+ assert isinstance(load_stmt.data, pyvex.IRExpr.Load)
1603
+ if isinstance(load_stmt.data.addr, pyvex.IRExpr.Const):
1604
+ # It's directly loading from a constant address
1605
+ # e.g.,
1606
+ # ldr r0, =main+1
1607
+ # blx r0
1608
+ # It's not a jump table, but we resolve it anyway
1609
+ jump_target_addr = load_stmt.data.addr.con.value
1610
+ jump_target = cfg._fast_memory_load_pointer(jump_target_addr)
1611
+ if jump_target is None:
1612
+ l.info(
1613
+ "Constant indirect jump %#x points outside of loaded memory to %#08x", addr, jump_target_addr
1614
+ )
1615
+ raise NotAJumpTableNotification
1616
+
1617
+ l.info("Resolved constant indirect jump from %#08x to %#08x", addr, jump_target_addr)
1618
+ return jump_target
1619
+
1620
+ elif isinstance(load_stmt, pyvex.IRStmt.LoadG) and isinstance(load_stmt.addr, pyvex.IRExpr.Const):
1621
+ # It's directly loading from a constant address
1622
+ # e.g.,
1623
+ # 4352c SUB R1, R11, #0x1000
1624
+ # 43530 LDRHI R3, =loc_45450
1625
+ # ...
1626
+ # 43540 MOV PC, R3
1627
+ #
1628
+ # It's not a jump table, but we resolve it anyway
1629
+ # Note that this block has two branches: One goes to 45450, the other one goes to whatever the original
1630
+ # value of R3 is. Some intensive data-flow analysis is required in this case.
1631
+ jump_target_addr = load_stmt.addr.con.value
1632
+ jump_target = cfg._fast_memory_load_pointer(jump_target_addr)
1633
+ l.info("Resolved constant indirect jump from %#08x to %#08x", addr, jump_target_addr)
1634
+ return jump_target
1635
+
1636
+ return None
1637
+
1638
+ def _try_resolve_targets_load(
1639
+ self,
1640
+ r,
1641
+ addr,
1642
+ cfg,
1643
+ annotatedcfg,
1644
+ load_stmt,
1645
+ load_size,
1646
+ stmts_adding_base_addr,
1647
+ transformations: dict[tuple[int, int], AddressTransformation],
1648
+ potential_call_table: bool = False,
1649
+ ):
1650
+ """
1651
+ Try loading all jump targets from a jump table or a vtable.
1652
+ """
1653
+
1654
+ # shorthand
1655
+ project = self.project
1656
+
1657
+ try:
1658
+ whitelist = annotatedcfg.get_whitelisted_statements(r.addr)
1659
+ last_stmt = annotatedcfg.get_last_statement_index(r.addr)
1660
+ succ = project.factory.successors(r, whitelist=whitelist, last_stmt=last_stmt)
1661
+ except (AngrError, SimError):
1662
+ # oops there are errors
1663
+ l.debug("Cannot get jump successor states from a path that has reached the target. Skip it.")
1664
+ return None
1665
+
1666
+ all_states = succ.flat_successors + succ.unconstrained_successors
1667
+ if not all_states:
1668
+ l.debug("Slicecutor failed to execute the program slice. No output state is available.")
1669
+ return None
1670
+
1671
+ state = all_states[0] # Just take the first state
1672
+ self._cached_memread_addrs.clear() # clear the cache to save some memory (and avoid confusion when debugging)
1673
+
1674
+ # Parse the memory load statement and get the memory address of where the jump table is stored
1675
+ jumptable_addr = self._parse_load_statement(load_stmt, state)
1676
+ if jumptable_addr is None:
1677
+ return None
1678
+
1679
+ # sanity check and necessary pre-processing
1680
+ jump_base_addr = None
1681
+ if stmts_adding_base_addr:
1682
+ if len(stmts_adding_base_addr) == 1:
1683
+ jump_base_addr = stmts_adding_base_addr[0]
1684
+ if jump_base_addr.base_addr_available:
1685
+ addr_holders = {(jump_base_addr.stmt_loc[0], jump_base_addr.tmp)}
1686
+ else:
1687
+ addr_holders = {
1688
+ (jump_base_addr.stmt_loc[0], jump_base_addr.tmp),
1689
+ (jump_base_addr.stmt_loc[0], jump_base_addr.tmp_1),
1690
+ }
1691
+ if len(set(transformations.keys()).intersection(addr_holders)) != 1:
1692
+ # for some reason it's trying to add a base address onto a different temporary variable that we
1693
+ # are not aware of. skip.
1694
+ return None
1695
+
1696
+ if not jump_base_addr.base_addr_available:
1697
+ # we need to decide which tmp is the address holder and which tmp holds the base address
1698
+ addr_holder = next(iter(set(transformations.keys()).intersection(addr_holders)))
1699
+ if jump_base_addr.tmp_1 == addr_holder[1]:
1700
+ # swap the two tmps
1701
+ jump_base_addr.tmp, jump_base_addr.tmp_1 = jump_base_addr.tmp_1, jump_base_addr.tmp
1702
+ # Load the concrete base address
1703
+ with contextlib.suppress(SimError):
1704
+ # silently eat the claripy exception
1705
+ jump_base_addr.base_addr = state.solver.eval(state.scratch.temps[jump_base_addr.tmp_1])
1706
+ else:
1707
+ # We do not support the cases where the base address involves more than one addition.
1708
+ # One such case exists in libc-2.27.so shipped with Ubuntu x86 where esi is used as the address of the
1709
+ # data region.
1710
+ #
1711
+ # .text:00047316 mov eax, esi
1712
+ # .text:00047318 mov esi, [ebp+data_region_ptr]
1713
+ # .text:0004731E movsx eax, al
1714
+ # .text:00047321 movzx eax, byte ptr [esi+eax-603A0h]
1715
+ # .text:00047329 mov eax, ds:(jpt_47337 - 1D8000h)[esi+eax*4] ; switch 32 cases
1716
+ # .text:00047330 lea eax, (loc_47033 - 1D8000h)[esi+eax] ; jumptable 00047337 cases 0-13,27-31
1717
+ # .text:00047337 jmp eax ; switch
1718
+ #
1719
+ # the proper solution requires angr to correctly determine that esi is the beginning address of the data
1720
+ # region (in this case, 0x1d8000). we give up in such cases until we can reasonably perform a
1721
+ # full-function data propagation before performing jump table recovery.
1722
+ l.debug("Multiple statements adding bases, not supported yet") # FIXME: Just check the addresses?
1723
+
1724
+ if jumptable_addr.has_annotation_type(claripy.RegionAnnotation):
1725
+ return None
1726
+
1727
+ all_targets = []
1728
+ jump_table = []
1729
+
1730
+ if jumptable_addr.op == "BVV":
1731
+ stride = 0
1732
+ else:
1733
+ try:
1734
+ jumptable_si = claripy.backends.vsa.simplify(jumptable_addr)
1735
+ si_annotation = jumptable_si.get_annotation(claripy.annotation.StridedIntervalAnnotation)
1736
+ stride = si_annotation.stride if si_annotation is not None else 0
1737
+ except claripy.ClaripyError:
1738
+ return None
1739
+
1740
+ # we may resolve a vtable (in C, e.g., the IO_JUMPS_FUNC in libc), but the stride of this load is usually 1
1741
+ # while the read statement reads a word size at a time.
1742
+ # we use this to differentiate between traditional jump tables (where each entry is some blocks that belong to
1743
+ # the current function) and vtables (where each entry is a function).
1744
+ if stride < load_size:
1745
+ stride = load_size
1746
+ total_cases = jumptable_addr.cardinality // load_size
1747
+ sort = "vtable" # it's probably a vtable!
1748
+ else:
1749
+ total_cases = jumptable_addr.cardinality
1750
+ sort = "jumptable"
1751
+
1752
+ assert self._max_targets is not None
1753
+ if total_cases > self._max_targets:
1754
+ if (
1755
+ potential_call_table
1756
+ and sort == "jumptable"
1757
+ and stride * 8 == state.arch.bits
1758
+ and jumptable_addr.op == "__add__"
1759
+ ):
1760
+ # Undetermined table size. Take a guess based on target plausibility.
1761
+ table_base_addr = None
1762
+ for arg in jumptable_addr.args:
1763
+ assert isinstance(arg, (claripy.ast.BV, claripy.ast.FP, claripy.ast.Bool))
1764
+ if arg.concrete:
1765
+ table_base_addr = state.solver.eval(arg)
1766
+ break
1767
+
1768
+ if table_base_addr is not None:
1769
+ addr = table_base_addr
1770
+ # FIXME: May want to support NULL targets for handlers that are not filled in / placeholders
1771
+ # FIXME: Try negative offsets too? (this would be unusual)
1772
+ l.debug("Inspecting table at %#x for plausible targets...", addr)
1773
+ for i in range(self._max_targets):
1774
+ target = cfg._fast_memory_load_pointer(addr, size=load_size)
1775
+ if target is None or not self._is_jumptarget_legal(target):
1776
+ break
1777
+ l.debug("- %#x[%d] -> %#x", table_base_addr, i, target)
1778
+ jump_table.append(target)
1779
+ addr += stride
1780
+ num_targets = len(jump_table)
1781
+ if num_targets == 0:
1782
+ l.debug("Didn't find any plausible targets in suspected jump table %#x", table_base_addr)
1783
+ elif num_targets == self._max_targets:
1784
+ l.debug(
1785
+ "Reached maximum number of targets (%d) while scanning jump table %#x. It might not be "
1786
+ "a jump table, or the limit might be too low.",
1787
+ num_targets,
1788
+ table_base_addr,
1789
+ )
1790
+ else:
1791
+ l.debug("Table at %#x has %d plausible targets", table_base_addr, num_targets)
1792
+ return jump_table, table_base_addr, load_size, num_targets * load_size, jump_table, sort
1793
+
1794
+ # We resolved too many targets for this indirect jump. Something might have gone wrong.
1795
+ l.debug(
1796
+ "%d targets are resolved for the indirect jump at %#x. It may not be a jump table. Try the "
1797
+ "next source, if there is any.",
1798
+ total_cases,
1799
+ addr,
1800
+ )
1801
+ return None
1802
+
1803
+ # Or alternatively, we can ask user, which is meh...
1804
+ #
1805
+ # jump_base_addr = int(raw_input("please give me the jump base addr: "), 16)
1806
+ # total_cases = int(raw_input("please give me the total cases: "))
1807
+ # jump_target = state.solver.SI(bits=64, lower_bound=jump_base_addr, upper_bound=jump_base_addr +
1808
+ # (total_cases - 1) * 8, stride=8)
1809
+
1810
+ min_jumptable_addr = state.solver.min(jumptable_addr)
1811
+ max_jumptable_addr = state.solver.max(jumptable_addr)
1812
+
1813
+ # Both the min jump target and the max jump target should be within a mapped memory region
1814
+ # i.e., we shouldn't be jumping to the stack or somewhere unmapped
1815
+ if not (
1816
+ (
1817
+ project.loader.find_segment_containing(min_jumptable_addr)
1818
+ and project.loader.find_segment_containing(max_jumptable_addr)
1819
+ )
1820
+ or (
1821
+ project.loader.find_section_containing(min_jumptable_addr)
1822
+ and project.loader.find_section_containing(max_jumptable_addr)
1823
+ )
1824
+ ):
1825
+ l.debug(
1826
+ "Jump table %#x might have jump targets outside mapped memory regions. "
1827
+ "Continue to resolve it from the next data source.",
1828
+ addr,
1829
+ )
1830
+ return None
1831
+
1832
+ # Load the jump table from memory
1833
+ should_skip = False
1834
+ for idx, a in enumerate(range(min_jumptable_addr, max_jumptable_addr + 1, stride)):
1835
+ if idx % 100 == 0 and idx != 0:
1836
+ l.debug("%d targets have been resolved for the indirect jump at %#x...", idx, addr)
1837
+ if idx >= total_cases:
1838
+ break
1839
+ target = cfg._fast_memory_load_pointer(a, size=load_size)
1840
+ if target is None:
1841
+ l.debug("Cannot load pointer from address %#x. Skip.", a)
1842
+ should_skip = True
1843
+ break
1844
+ all_targets.append(target)
1845
+ if should_skip:
1846
+ return None
1847
+
1848
+ # Adjust entries inside the jump table
1849
+ mask = (2**self.project.arch.bits) - 1
1850
+ transformation_list = list(reversed([v for v in transformations.values() if not v.first_load]))
1851
+ if transformation_list:
1852
+
1853
+ def handle_signed_ext(a):
1854
+ return (a | 0xFFFFFFFF00000000) if a >= 0x80000000 else a
1855
+
1856
+ def handle_unsigned_ext(a):
1857
+ return a
1858
+
1859
+ def handle_trunc_64_32(a):
1860
+ return a & 0xFFFFFFFF
1861
+
1862
+ def handle_or1(a):
1863
+ return a | 1
1864
+
1865
+ def handle_lshift(num_bits, a):
1866
+ return a << num_bits
1867
+
1868
+ def handle_rshift(num_bits, a):
1869
+ return a >> num_bits
1870
+
1871
+ def handle_add(con, a):
1872
+ return (a + con) & mask
1873
+
1874
+ def handle_load(size, a):
1875
+ return cfg._fast_memory_load_pointer(a, size=size)
1876
+
1877
+ invert_conversion_ops = []
1878
+ for tran in transformation_list:
1879
+ tran_op, args = tran.op, tran.operands
1880
+ if tran_op is AddressTransformationTypes.SignedExtension:
1881
+ if args == [32, 64, AddressSingleton]:
1882
+ lam = handle_signed_ext
1883
+ else:
1884
+ raise NotImplementedError("Unsupported signed extension operation.")
1885
+ elif tran_op is AddressTransformationTypes.UnsignedExtension:
1886
+ lam = handle_unsigned_ext
1887
+ elif tran_op is AddressTransformationTypes.Truncation:
1888
+ if args == [64, 32, AddressSingleton]:
1889
+ lam = handle_trunc_64_32
1890
+ else:
1891
+ raise NotImplementedError("Unsupported truncation operation.")
1892
+ elif tran_op is AddressTransformationTypes.Or1:
1893
+ lam = handle_or1
1894
+ elif tran_op is AddressTransformationTypes.ShiftLeft:
1895
+ lam = functools.partial(
1896
+ handle_lshift, next(iter(arg for arg in args if arg is not AddressSingleton))
1897
+ )
1898
+ elif tran_op is AddressTransformationTypes.ShiftRight:
1899
+ lam = functools.partial(
1900
+ handle_rshift, next(iter(arg for arg in args if arg is not AddressSingleton))
1901
+ )
1902
+ elif tran_op is AddressTransformationTypes.Add:
1903
+ add_arg = next(iter(arg for arg in args if arg is not AddressSingleton))
1904
+ if not isinstance(add_arg, int):
1905
+ # unsupported cases (Tmp, for example). abort
1906
+ return None
1907
+ lam = functools.partial(handle_add, add_arg)
1908
+ elif tran_op is AddressTransformationTypes.Load:
1909
+ lam = functools.partial(handle_load, args[1])
1910
+ elif tran_op is AddressTransformationTypes.Assignment:
1911
+ continue
1912
+ else:
1913
+ raise NotImplementedError("Unsupported transformation operation.")
1914
+ invert_conversion_ops.append(lam)
1915
+ all_targets_copy = all_targets
1916
+ all_targets = []
1917
+ for target_ in all_targets_copy:
1918
+ for lam in invert_conversion_ops:
1919
+ target_ = lam(target_)
1920
+ if target_ is None:
1921
+ # transformation failed. abort
1922
+ return None
1923
+ all_targets.append(target_)
1924
+ if None in all_targets:
1925
+ return None
1926
+ if len(stmts_adding_base_addr) == 1:
1927
+ stmt_adding_base_addr = stmts_adding_base_addr[0]
1928
+ base_addr = stmt_adding_base_addr.base_addr
1929
+ all_targets = [(target + base_addr) & mask for target in all_targets]
1930
+
1931
+ # special case for ARM: if the source block is in THUMB mode, all jump targets should be in THUMB mode, too
1932
+ if is_arm_arch(self.project.arch) and (addr & 1) == 1:
1933
+ all_targets = [target | 1 for target in all_targets]
1934
+
1935
+ if len(all_targets) == 0:
1936
+ l.debug("Could not recover jump table")
1937
+ return None
1938
+
1939
+ # Finally... all targets are ready
1940
+ illegal_target_found = False
1941
+ for target in all_targets:
1942
+ # if the total number of targets is suspicious (it usually implies a failure in applying the
1943
+ # constraints), check if all jump targets are legal
1944
+ if len(all_targets) in {1, 0x100, 0x10000} and not self._is_jumptarget_legal(target):
1945
+ l.info(
1946
+ "Jump target %#x is probably illegal. Try to resolve indirect jump at %#x from the next source.",
1947
+ target,
1948
+ addr,
1949
+ )
1950
+ illegal_target_found = True
1951
+ break
1952
+ jump_table.append(target)
1953
+ if illegal_target_found:
1954
+ return None
1955
+
1956
+ return jump_table, min_jumptable_addr, load_size, total_cases * load_size, all_targets, sort
1957
+
1958
+ def _try_resolve_targets_ite(
1959
+ self, r, addr, cfg, annotatedcfg, ite_stmt: pyvex.IRStmt.WrTmp
1960
+ ): # pylint:disable=unused-argument
1961
+ """
1962
+ Try loading all jump targets from parsing an ITE block.
1963
+ """
1964
+ project = self.project
1965
+
1966
+ try:
1967
+ whitelist = annotatedcfg.get_whitelisted_statements(r.addr)
1968
+ last_stmt = annotatedcfg.get_last_statement_index(r.addr)
1969
+ succ = project.factory.successors(r, whitelist=whitelist, last_stmt=last_stmt)
1970
+ except (AngrError, SimError):
1971
+ # oops there are errors
1972
+ l.warning("Cannot get jump successor states from a path that has reached the target. Skip it.")
1973
+ return None
1974
+
1975
+ all_states = succ.flat_successors + succ.unconstrained_successors
1976
+ if not all_states:
1977
+ l.warning("Slicecutor failed to execute the program slice. No output state is available.")
1978
+ return None
1979
+
1980
+ state = all_states[0] # Just take the first state
1981
+ temps = state.scratch.temps
1982
+ if not isinstance(ite_stmt.data, pyvex.IRExpr.ITE):
1983
+ return None
1984
+ # load the default
1985
+ if not isinstance(ite_stmt.data.iffalse, pyvex.IRExpr.Const):
1986
+ return None
1987
+ # ite_stmt.data.iffalse.con.value is garbage introduced by the VEX ARM lifter and should be ignored
1988
+ if not isinstance(ite_stmt.data.iftrue, pyvex.IRExpr.RdTmp):
1989
+ return None
1990
+ if not isinstance(ite_stmt.data.cond, pyvex.IRExpr.RdTmp):
1991
+ return None
1992
+ cond = temps[ite_stmt.data.cond.tmp]
1993
+ # apply the constraint
1994
+ state.add_constraints(cond == 1)
1995
+ # load the target
1996
+ target_expr = temps[ite_stmt.data.iftrue.tmp]
1997
+ try:
1998
+ jump_table = state.solver.eval_upto(target_expr, self._max_targets + 1)
1999
+ except SimError:
2000
+ return None
2001
+ entry_size = len(target_expr) // self.project.arch.byte_width
2002
+
2003
+ if len(jump_table) == self._max_targets + 1:
2004
+ # so many targets! failed
2005
+ return None
2006
+
2007
+ return jump_table, len(jump_table), entry_size
2008
+
2009
+ @staticmethod
2010
+ def _instrument_statements(state, stmts_to_instrument, regs_to_initialize):
2011
+ """
2012
+ Hook statements as specified in stmts_to_instrument and overwrite values loaded in those statements.
2013
+
2014
+ :param SimState state: The program state to insert hooks to.
2015
+ :param list stmts_to_instrument: A list of statements to instrument.
2016
+ :param list regs_to_initialize: A list of registers to initialize.
2017
+ :return: None
2018
+ """
2019
+
2020
+ for sort, block_addr, stmt_idx in stmts_to_instrument:
2021
+ l.debug("Add a %s hook to overwrite memory/register values at %#x:%d.", sort, block_addr, stmt_idx)
2022
+ if sort == "mem_write":
2023
+ bp = BP(
2024
+ when=BP_BEFORE,
2025
+ enabled=True,
2026
+ action=StoreHook.hook,
2027
+ condition=lambda _s, a=block_addr, idx=stmt_idx: _s.scratch.bbl_addr == a
2028
+ and _s.scratch.stmt_idx == idx,
2029
+ )
2030
+ state.inspect.add_breakpoint("mem_write", bp)
2031
+ elif sort == "mem_read":
2032
+ hook = LoadHook()
2033
+ bp0 = BP(
2034
+ when=BP_BEFORE,
2035
+ enabled=True,
2036
+ action=hook.hook_before,
2037
+ condition=lambda _s, a=block_addr, idx=stmt_idx: _s.scratch.bbl_addr == a
2038
+ and _s.scratch.stmt_idx == idx,
2039
+ )
2040
+ state.inspect.add_breakpoint("mem_read", bp0)
2041
+ bp1 = BP(
2042
+ when=BP_AFTER,
2043
+ enabled=True,
2044
+ action=hook.hook_after,
2045
+ condition=lambda _s, a=block_addr, idx=stmt_idx: _s.scratch.bbl_addr == a
2046
+ and _s.scratch.stmt_idx == idx,
2047
+ )
2048
+ state.inspect.add_breakpoint("mem_read", bp1)
2049
+ elif sort == "reg_write":
2050
+ bp = BP(
2051
+ when=BP_BEFORE,
2052
+ enabled=True,
2053
+ action=PutHook.hook,
2054
+ condition=lambda _s, a=block_addr, idx=stmt_idx: _s.scratch.bbl_addr == a
2055
+ and _s.scratch.stmt_idx == idx,
2056
+ )
2057
+ state.inspect.add_breakpoint("reg_write", bp)
2058
+ else:
2059
+ raise NotImplementedError(f"Unsupported sort {sort} in stmts_to_instrument.")
2060
+
2061
+ reg_val = 0x13370000
2062
+
2063
+ def bp_condition(block_addr, stmt_idx, _s):
2064
+ return _s.scratch.bbl_addr == block_addr and _s.inspect.statement == stmt_idx
2065
+
2066
+ for block_addr, stmt_idx, reg_offset, reg_bits in regs_to_initialize:
2067
+ l.debug(
2068
+ "Add a hook to initialize register %s at %x:%d.",
2069
+ state.arch.translate_register_name(reg_offset, size=reg_bits),
2070
+ block_addr,
2071
+ stmt_idx,
2072
+ )
2073
+ bp = BP(
2074
+ when=BP_BEFORE,
2075
+ enabled=True,
2076
+ action=RegisterInitializerHook(reg_offset, reg_bits, reg_val).hook,
2077
+ condition=functools.partial(bp_condition, block_addr, stmt_idx),
2078
+ )
2079
+ state.inspect.add_breakpoint("statement", bp)
2080
+ reg_val += 16
2081
+
2082
+ def _find_bss_region(self):
2083
+ self._bss_regions = []
2084
+
2085
+ # TODO: support other sections other than '.bss'.
2086
+ # TODO: this is very hackish. fix it after the chaos.
2087
+ for section in self.project.loader.main_object.sections:
2088
+ if section.name == ".bss":
2089
+ self._bss_regions.append((section.vaddr, section.memsize))
2090
+ break
2091
+
2092
+ def _init_registers_on_demand(self, state):
2093
+ # for uninitialized read using a register as the source address, we replace them in memory on demand
2094
+ read_addr = state.inspect.mem_read_address
2095
+ cond = state.inspect.mem_read_condition
2096
+
2097
+ if not isinstance(read_addr, int) and read_addr.has_annotation_type(UninitializedAnnotation) and cond is None:
2098
+ # if this AST has been initialized before, just use the cached addr
2099
+ cached_addr = self._cached_memread_addrs.get(read_addr, None)
2100
+ if cached_addr is not None:
2101
+ state.inspect.mem_read_address = cached_addr
2102
+ return
2103
+
2104
+ read_length = state.inspect.mem_read_length
2105
+ if not isinstance(read_length, int):
2106
+ read_length = read_length.args[3] # max
2107
+ if read_length > 16:
2108
+ return
2109
+ new_read_addr = claripy.BVV(UninitReadMeta.uninit_read_base, state.arch.bits)
2110
+ UninitReadMeta.uninit_read_base += read_length
2111
+
2112
+ # replace the expression in registers
2113
+ state.registers.replace_all(read_addr, new_read_addr)
2114
+
2115
+ # extra caution: if this read_addr AST comes up again in the future, we want to replace it with the same
2116
+ # address again.
2117
+ self._cached_memread_addrs[read_addr] = new_read_addr
2118
+
2119
+ state.inspect.mem_read_address = new_read_addr
2120
+
2121
+ # job done :-)
2122
+
2123
+ def _dbg_repr_slice(self, blade, in_slice_stmts_only=False):
2124
+ stmts = defaultdict(set)
2125
+
2126
+ for addr, stmt_idx in sorted(blade.slice.nodes()):
2127
+ stmts[addr].add(stmt_idx)
2128
+
2129
+ for addr in sorted(stmts.keys()):
2130
+ stmt_ids = stmts[addr]
2131
+ irsb = self.project.factory.block(addr, cross_insn_opt=True, backup_state=self.base_state).vex
2132
+
2133
+ print(" ####")
2134
+ print(f" #### Block {addr:#x}")
2135
+ print(" ####")
2136
+
2137
+ for i, stmt in enumerate(irsb.statements):
2138
+ stmt_taken = i in stmt_ids
2139
+ display = stmt_taken if in_slice_stmts_only else True
2140
+ if display:
2141
+ s = (
2142
+ f"{'+' if stmt_taken else ' '} {addr:x}:{i:02d} | "
2143
+ f"{stmt.pp_str(arch=self.project.arch, tyenv=irsb.tyenv)} "
2144
+ )
2145
+ if stmt_taken:
2146
+ s += f"IN: {blade.slice.in_degree((addr, i))}"
2147
+ print(s)
2148
+
2149
+ # the default exit
2150
+ default_exit_taken = DEFAULT_STATEMENT in stmt_ids
2151
+ s = "{} {:x}:default | PUT({}) = {}; {}".format(
2152
+ "+" if default_exit_taken else " ", addr, irsb.offsIP, irsb.next, irsb.jumpkind
2153
+ )
2154
+ print(s)
2155
+
2156
+ def _initial_state(self, block_addr, cfg, func_addr: int):
2157
+ add_options = {
2158
+ o.DO_RET_EMULATION,
2159
+ o.TRUE_RET_EMULATION_GUARD,
2160
+ o.AVOID_MULTIVALUED_READS,
2161
+ # Keep IP symbolic to avoid unnecessary concretization
2162
+ o.KEEP_IP_SYMBOLIC,
2163
+ o.NO_IP_CONCRETIZATION,
2164
+ # be quiet!!!!!!
2165
+ o.SYMBOL_FILL_UNCONSTRAINED_REGISTERS,
2166
+ o.SYMBOL_FILL_UNCONSTRAINED_MEMORY,
2167
+ }
2168
+ state = self.project.factory.blank_state(
2169
+ addr=block_addr,
2170
+ mode="static",
2171
+ add_options=add_options,
2172
+ remove_options={
2173
+ o.CGC_ZERO_FILL_UNCONSTRAINED_MEMORY,
2174
+ o.UNINITIALIZED_ACCESS_AWARENESS,
2175
+ }
2176
+ | o.refs,
2177
+ )
2178
+ state.regs._sp = 0x7FFF_FFF0
2179
+
2180
+ # any read from an uninitialized segment should be unconstrained
2181
+ if self._bss_regions:
2182
+ bss_hook = BSSHook(self.project, self._bss_regions)
2183
+ bss_memory_write_bp = BP(when=BP_AFTER, enabled=True, action=bss_hook.bss_memory_write_hook)
2184
+ state.inspect.add_breakpoint("mem_write", bss_memory_write_bp)
2185
+ bss_memory_read_bp = BP(when=BP_BEFORE, enabled=True, action=bss_hook.bss_memory_read_hook)
2186
+ state.inspect.add_breakpoint("mem_read", bss_memory_read_bp)
2187
+
2188
+ if self.project.arch.name == "MIPS32":
2189
+ try:
2190
+ func = cfg.kb.functions.get_by_addr(func_addr)
2191
+ if func.info and "gp" in func.info:
2192
+ state.regs._gp = func.info["gp"]
2193
+ except KeyError:
2194
+ pass
2195
+
2196
+ # instrument all reads from gp and all writes to gp
2197
+ gp = None
2198
+ try:
2199
+ func = cfg.kb.functions.get_by_addr(func_addr)
2200
+ if func.info and "gp" in func.info:
2201
+ gp = func.info["gp"]
2202
+ except KeyError:
2203
+ pass
2204
+ if gp is not None:
2205
+ mips_gp_hook = MIPSGPHook(self.project.arch.registers["gp"][0], gp)
2206
+ mips_gp_read_bp = BP(when=BP_AFTER, enabled=True, action=mips_gp_hook.gp_register_read_hook)
2207
+ mips_gp_write_bp = BP(when=BP_AFTER, enabled=True, action=mips_gp_hook.gp_register_write_hook)
2208
+ state.inspect.add_breakpoint("reg_read", mips_gp_read_bp)
2209
+ state.inspect.add_breakpoint("reg_write", mips_gp_write_bp)
2210
+
2211
+ # FIXME:
2212
+ # this is a hack: for certain architectures, we do not initialize the base pointer, since the jump table on
2213
+ # those architectures may use the bp register to store value
2214
+ if self.project.arch.name not in {"S390X"}:
2215
+ state.regs.bp = state.arch.initial_sp + 0x2000
2216
+
2217
+ return state
2218
+
2219
+ @staticmethod
2220
+ def _parse_load_statement(load_stmt, state):
2221
+ """
2222
+ Parse a memory load VEX statement and get the jump target addresses.
2223
+
2224
+ :param load_stmt: The VEX statement for loading the jump target addresses.
2225
+ :param state: The SimState instance (in static mode).
2226
+ :return: An abstract value (or a concrete value) representing the jump target addresses. Return None
2227
+ if we fail to parse the statement.
2228
+ """
2229
+
2230
+ # The jump table address is stored in a tmp. In this case, we find the jump-target loading tmp.
2231
+ load_addr_tmp = None
2232
+
2233
+ if isinstance(load_stmt, pyvex.IRStmt.WrTmp):
2234
+ assert isinstance(load_stmt.data, pyvex.IRExpr.Load)
2235
+ if isinstance(load_stmt.data.addr, pyvex.IRExpr.RdTmp):
2236
+ load_addr_tmp = load_stmt.data.addr.tmp
2237
+ elif isinstance(load_stmt.data.addr, pyvex.IRExpr.Const):
2238
+ # It's directly loading from a constant address
2239
+ # e.g.,
2240
+ # ldr r0, =main+1
2241
+ # blx r0
2242
+ # It's not a jump table, but we resolve it anyway
2243
+ jump_target_addr = load_stmt.data.addr.con.value
2244
+ return claripy.BVV(jump_target_addr, state.arch.bits)
2245
+ elif isinstance(load_stmt, pyvex.IRStmt.LoadG):
2246
+ if isinstance(load_stmt.addr, pyvex.IRExpr.RdTmp):
2247
+ load_addr_tmp = load_stmt.addr.tmp
2248
+ elif isinstance(load_stmt.addr, pyvex.IRExpr.Const):
2249
+ # It's directly loading from a constant address
2250
+ # e.g.,
2251
+ # 4352c SUB R1, R11, #0x1000
2252
+ # 43530 LDRHI R3, =loc_45450
2253
+ # ...
2254
+ # 43540 MOV PC, R3
2255
+ #
2256
+ # It's not a jump table, but we resolve it anyway
2257
+ # Note that this block has two branches: One goes to 45450, the other one goes to whatever the original
2258
+ # value of R3 is. Some intensive data-flow analysis is required in this case.
2259
+ jump_target_addr = load_stmt.addr.con.value
2260
+ return claripy.BVV(jump_target_addr, state.arch.bits)
2261
+ else:
2262
+ raise TypeError(f"Unsupported address loading statement type {type(load_stmt)}.")
2263
+
2264
+ if state.scratch.temps[load_addr_tmp] is None:
2265
+ # the tmp variable is not there... umm...
2266
+ return None
2267
+
2268
+ jump_addr = state.scratch.temps[load_addr_tmp]
2269
+
2270
+ if isinstance(load_stmt, pyvex.IRStmt.LoadG) and not isinstance(load_stmt.guard, pyvex.IRExpr.Const):
2271
+ # LoadG comes with a guard. We should apply this guard to the load expression
2272
+ assert isinstance(load_stmt.guard, pyvex.expr.RdTmp)
2273
+ guard_tmp = load_stmt.guard.tmp
2274
+ guard = state.scratch.temps[guard_tmp] != 0
2275
+ try:
2276
+ jump_addr = state.memory._apply_condition_to_symbolic_addr(jump_addr, guard)
2277
+ except Exception: # pylint: disable=broad-except
2278
+ l.exception("Error computing jump table address!")
2279
+ return None
2280
+ return jump_addr
2281
+
2282
+ def _sp_moved_up(self, block) -> bool:
2283
+ """
2284
+ Examine if the stack pointer moves up (if any values are popped out of the stack) within a single block.
2285
+ """
2286
+
2287
+ spt = self.project.analyses.StackPointerTracker(
2288
+ None, {self.project.arch.sp_offset}, block=block, track_memory=False
2289
+ )
2290
+ offset_after = spt.offset_after(block.addr, self.project.arch.sp_offset)
2291
+ return offset_after is not None and offset_after > 0
2292
+
2293
+ def _is_jumptarget_legal(self, target):
2294
+ try:
2295
+ vex_block = self.project.factory.block(target, cross_insn_opt=True).vex_nostmt
2296
+ except (AngrError, SimError):
2297
+ return False
2298
+ if vex_block.jumpkind == "Ijk_NoDecode":
2299
+ return False
2300
+ return vex_block.size != 0
2301
+
2302
+ def _is_address_mapped(self, addr: int) -> bool:
2303
+ return (
2304
+ self.project.loader.find_segment_containing(addr) is not None
2305
+ or self.project.loader.find_section_containing(addr) is not None
2306
+ )
2307
+
2308
+ def _all_qualified_load_stmts_in_slice(self, b: Blade, addr: int) -> list[int]:
2309
+ """
2310
+ Recognize all qualified load statements in a slice. A qualified load statements refers to those that are
2311
+ loading jump targets (or jump offsets) from a jump table, or loading jump table offsets from a jump-table
2312
+ offset table.
2313
+
2314
+ :param b: The Blade object.
2315
+ :param addr: Address of the last block.
2316
+ :return: A list of qualified load statement IDs.
2317
+ """
2318
+
2319
+ stmt_ids = []
2320
+ for block_addr, stmt_id in b.slice.nodes:
2321
+ if block_addr == addr and stmt_id != DEFAULT_STATEMENT:
2322
+ stmt_ids.append(stmt_id)
2323
+
2324
+ if not stmt_ids:
2325
+ return []
2326
+ stmt_ids = sorted(stmt_ids)
2327
+ qualified_load_stmt_ids = []
2328
+ load_stmt_ids = []
2329
+ block = self.project.factory.block(addr, cross_insn_opt=True, backup_state=self.base_state).vex
2330
+ tmp_values = {}
2331
+ mask = (2**self.project.arch.bits) - 1
2332
+ for stmt_id in stmt_ids:
2333
+ stmt = block.statements[stmt_id]
2334
+ if isinstance(stmt, pyvex.IRStmt.WrTmp):
2335
+ if isinstance(stmt.data, pyvex.IRExpr.Const):
2336
+ tmp_values[stmt.tmp] = stmt.data.con.value
2337
+ elif isinstance(stmt.data, pyvex.IRExpr.Binop) and stmt.data.op.startswith("Iop_Add"):
2338
+ op0 = None
2339
+ if isinstance(stmt.data.args[0], pyvex.IRExpr.RdTmp):
2340
+ op0 = tmp_values.get(stmt.data.args[0].tmp, None)
2341
+ elif isinstance(stmt.data.args[0], pyvex.IRExpr.Const):
2342
+ op0 = stmt.data.args[0].con.value
2343
+ op1 = None
2344
+ if isinstance(stmt.data.args[1], pyvex.IRExpr.RdTmp):
2345
+ op1 = tmp_values.get(stmt.data.args[1].tmp, None)
2346
+ elif isinstance(stmt.data.args[1], pyvex.IRExpr.Const):
2347
+ op1 = stmt.data.args[1].con.value
2348
+ if isinstance(op1, int) and not isinstance(op0, int):
2349
+ op0, op1 = op1, op0
2350
+ if isinstance(op0, int):
2351
+ if op1 is None:
2352
+ tmp_values[stmt.tmp] = ("+", op0, op1)
2353
+ elif isinstance(op1, int):
2354
+ tmp_values[stmt.tmp] = (op0 + op1) & mask
2355
+ elif isinstance(op1, tuple) and op1[0] == "+":
2356
+ tmp_values[stmt.tmp] = ("+", (op0 + op1[1]) & mask, op1[2])
2357
+ elif isinstance(stmt.data, pyvex.IRExpr.Load) and isinstance(stmt.data.addr, pyvex.IRExpr.RdTmp):
2358
+ # is this load statement loading from a static address + an offset?
2359
+ v = tmp_values.get(stmt.data.addr.tmp, None)
2360
+ if isinstance(v, tuple) and v[0] == "+" and v[2] is None and self._is_address_mapped(v[1]):
2361
+ qualified_load_stmt_ids.append(stmt_id)
2362
+ load_stmt_ids.append(stmt_id)
2363
+ if qualified_load_stmt_ids and len(qualified_load_stmt_ids) <= 2:
2364
+ return qualified_load_stmt_ids
2365
+ if load_stmt_ids:
2366
+ return [load_stmt_ids[-1]]
2367
+ return []