angr 9.2.158__cp310-abi3-win_amd64.whl

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

Potentially problematic release.


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

Files changed (1393) hide show
  1. angr/__init__.py +363 -0
  2. angr/__main__.py +152 -0
  3. angr/analyses/__init__.py +113 -0
  4. angr/analyses/analysis.py +407 -0
  5. angr/analyses/backward_slice.py +686 -0
  6. angr/analyses/binary_optimizer.py +670 -0
  7. angr/analyses/bindiff.py +1512 -0
  8. angr/analyses/boyscout.py +76 -0
  9. angr/analyses/callee_cleanup_finder.py +74 -0
  10. angr/analyses/calling_convention/__init__.py +6 -0
  11. angr/analyses/calling_convention/calling_convention.py +1092 -0
  12. angr/analyses/calling_convention/fact_collector.py +636 -0
  13. angr/analyses/calling_convention/utils.py +60 -0
  14. angr/analyses/cdg.py +189 -0
  15. angr/analyses/cfg/__init__.py +23 -0
  16. angr/analyses/cfg/cfb.py +428 -0
  17. angr/analyses/cfg/cfg.py +74 -0
  18. angr/analyses/cfg/cfg_arch_options.py +95 -0
  19. angr/analyses/cfg/cfg_base.py +2902 -0
  20. angr/analyses/cfg/cfg_emulated.py +3447 -0
  21. angr/analyses/cfg/cfg_fast.py +5278 -0
  22. angr/analyses/cfg/cfg_fast_soot.py +662 -0
  23. angr/analyses/cfg/cfg_job_base.py +203 -0
  24. angr/analyses/cfg/indirect_jump_resolvers/__init__.py +28 -0
  25. angr/analyses/cfg/indirect_jump_resolvers/amd64_elf_got.py +62 -0
  26. angr/analyses/cfg/indirect_jump_resolvers/amd64_pe_iat.py +51 -0
  27. angr/analyses/cfg/indirect_jump_resolvers/arm_elf_fast.py +149 -0
  28. angr/analyses/cfg/indirect_jump_resolvers/const_resolver.py +186 -0
  29. angr/analyses/cfg/indirect_jump_resolvers/constant_value_manager.py +107 -0
  30. angr/analyses/cfg/indirect_jump_resolvers/default_resolvers.py +76 -0
  31. angr/analyses/cfg/indirect_jump_resolvers/jumptable.py +2367 -0
  32. angr/analyses/cfg/indirect_jump_resolvers/memload_resolver.py +81 -0
  33. angr/analyses/cfg/indirect_jump_resolvers/mips_elf_fast.py +286 -0
  34. angr/analyses/cfg/indirect_jump_resolvers/mips_elf_got.py +148 -0
  35. angr/analyses/cfg/indirect_jump_resolvers/propagator_utils.py +46 -0
  36. angr/analyses/cfg/indirect_jump_resolvers/resolver.py +74 -0
  37. angr/analyses/cfg/indirect_jump_resolvers/syscall_resolver.py +92 -0
  38. angr/analyses/cfg/indirect_jump_resolvers/x86_elf_pic_plt.py +88 -0
  39. angr/analyses/cfg/indirect_jump_resolvers/x86_pe_iat.py +47 -0
  40. angr/analyses/cfg_slice_to_sink/__init__.py +11 -0
  41. angr/analyses/cfg_slice_to_sink/cfg_slice_to_sink.py +117 -0
  42. angr/analyses/cfg_slice_to_sink/graph.py +87 -0
  43. angr/analyses/cfg_slice_to_sink/transitions.py +27 -0
  44. angr/analyses/class_identifier.py +63 -0
  45. angr/analyses/code_tagging.py +123 -0
  46. angr/analyses/codecave.py +77 -0
  47. angr/analyses/complete_calling_conventions.py +461 -0
  48. angr/analyses/congruency_check.py +377 -0
  49. angr/analyses/data_dep/__init__.py +16 -0
  50. angr/analyses/data_dep/data_dependency_analysis.py +595 -0
  51. angr/analyses/data_dep/dep_nodes.py +171 -0
  52. angr/analyses/data_dep/sim_act_location.py +49 -0
  53. angr/analyses/datagraph_meta.py +105 -0
  54. angr/analyses/ddg.py +1670 -0
  55. angr/analyses/decompiler/__init__.py +41 -0
  56. angr/analyses/decompiler/ail_simplifier.py +1972 -0
  57. angr/analyses/decompiler/ailgraph_walker.py +49 -0
  58. angr/analyses/decompiler/block_io_finder.py +302 -0
  59. angr/analyses/decompiler/block_similarity.py +196 -0
  60. angr/analyses/decompiler/block_simplifier.py +371 -0
  61. angr/analyses/decompiler/callsite_maker.py +555 -0
  62. angr/analyses/decompiler/ccall_rewriters/__init__.py +9 -0
  63. angr/analyses/decompiler/ccall_rewriters/amd64_ccalls.py +580 -0
  64. angr/analyses/decompiler/ccall_rewriters/rewriter_base.py +20 -0
  65. angr/analyses/decompiler/ccall_rewriters/x86_ccalls.py +313 -0
  66. angr/analyses/decompiler/clinic.py +3304 -0
  67. angr/analyses/decompiler/condition_processor.py +1256 -0
  68. angr/analyses/decompiler/counters/__init__.py +16 -0
  69. angr/analyses/decompiler/counters/boolean_counter.py +27 -0
  70. angr/analyses/decompiler/counters/call_counter.py +47 -0
  71. angr/analyses/decompiler/counters/expression_counters.py +77 -0
  72. angr/analyses/decompiler/counters/seq_cf_structure_counter.py +63 -0
  73. angr/analyses/decompiler/decompilation_cache.py +46 -0
  74. angr/analyses/decompiler/decompilation_options.py +275 -0
  75. angr/analyses/decompiler/decompiler.py +703 -0
  76. angr/analyses/decompiler/dephication/__init__.py +6 -0
  77. angr/analyses/decompiler/dephication/dephication_base.py +89 -0
  78. angr/analyses/decompiler/dephication/graph_dephication.py +63 -0
  79. angr/analyses/decompiler/dephication/graph_rewriting.py +116 -0
  80. angr/analyses/decompiler/dephication/graph_vvar_mapping.py +326 -0
  81. angr/analyses/decompiler/dephication/rewriting_engine.py +504 -0
  82. angr/analyses/decompiler/dephication/seqnode_dephication.py +134 -0
  83. angr/analyses/decompiler/empty_node_remover.py +212 -0
  84. angr/analyses/decompiler/expression_narrower.py +287 -0
  85. angr/analyses/decompiler/goto_manager.py +112 -0
  86. angr/analyses/decompiler/graph_region.py +398 -0
  87. angr/analyses/decompiler/jump_target_collector.py +37 -0
  88. angr/analyses/decompiler/jumptable_entry_condition_rewriter.py +67 -0
  89. angr/analyses/decompiler/label_collector.py +32 -0
  90. angr/analyses/decompiler/optimization_passes/__init__.py +151 -0
  91. angr/analyses/decompiler/optimization_passes/base_ptr_save_simplifier.py +157 -0
  92. angr/analyses/decompiler/optimization_passes/call_stmt_rewriter.py +46 -0
  93. angr/analyses/decompiler/optimization_passes/code_motion.py +362 -0
  94. angr/analyses/decompiler/optimization_passes/condition_constprop.py +219 -0
  95. angr/analyses/decompiler/optimization_passes/const_derefs.py +266 -0
  96. angr/analyses/decompiler/optimization_passes/const_prop_reverter.py +365 -0
  97. angr/analyses/decompiler/optimization_passes/cross_jump_reverter.py +106 -0
  98. angr/analyses/decompiler/optimization_passes/deadblock_remover.py +82 -0
  99. angr/analyses/decompiler/optimization_passes/determine_load_sizes.py +64 -0
  100. angr/analyses/decompiler/optimization_passes/div_simplifier.py +425 -0
  101. angr/analyses/decompiler/optimization_passes/duplication_reverter/__init__.py +5 -0
  102. angr/analyses/decompiler/optimization_passes/duplication_reverter/ail_merge_graph.py +503 -0
  103. angr/analyses/decompiler/optimization_passes/duplication_reverter/duplication_reverter.py +1218 -0
  104. angr/analyses/decompiler/optimization_passes/duplication_reverter/errors.py +16 -0
  105. angr/analyses/decompiler/optimization_passes/duplication_reverter/similarity.py +126 -0
  106. angr/analyses/decompiler/optimization_passes/duplication_reverter/utils.py +167 -0
  107. angr/analyses/decompiler/optimization_passes/eager_std_string_concatenation.py +165 -0
  108. angr/analyses/decompiler/optimization_passes/engine_base.py +500 -0
  109. angr/analyses/decompiler/optimization_passes/expr_op_swapper.py +135 -0
  110. angr/analyses/decompiler/optimization_passes/flip_boolean_cmp.py +113 -0
  111. angr/analyses/decompiler/optimization_passes/inlined_string_transformation_simplifier.py +615 -0
  112. angr/analyses/decompiler/optimization_passes/ite_expr_converter.py +224 -0
  113. angr/analyses/decompiler/optimization_passes/ite_region_converter.py +335 -0
  114. angr/analyses/decompiler/optimization_passes/lowered_switch_simplifier.py +922 -0
  115. angr/analyses/decompiler/optimization_passes/mod_simplifier.py +99 -0
  116. angr/analyses/decompiler/optimization_passes/optimization_pass.py +659 -0
  117. angr/analyses/decompiler/optimization_passes/register_save_area_simplifier.py +221 -0
  118. angr/analyses/decompiler/optimization_passes/ret_addr_save_simplifier.py +171 -0
  119. angr/analyses/decompiler/optimization_passes/ret_deduplicator.py +222 -0
  120. angr/analyses/decompiler/optimization_passes/return_duplicator_base.py +640 -0
  121. angr/analyses/decompiler/optimization_passes/return_duplicator_high.py +61 -0
  122. angr/analyses/decompiler/optimization_passes/return_duplicator_low.py +235 -0
  123. angr/analyses/decompiler/optimization_passes/stack_canary_simplifier.py +333 -0
  124. angr/analyses/decompiler/optimization_passes/switch_default_case_duplicator.py +149 -0
  125. angr/analyses/decompiler/optimization_passes/switch_reused_entry_rewriter.py +102 -0
  126. angr/analyses/decompiler/optimization_passes/tag_slicer.py +41 -0
  127. angr/analyses/decompiler/optimization_passes/win_stack_canary_simplifier.py +421 -0
  128. angr/analyses/decompiler/optimization_passes/x86_gcc_getpc_simplifier.py +88 -0
  129. angr/analyses/decompiler/peephole_optimizations/__init__.py +127 -0
  130. angr/analyses/decompiler/peephole_optimizations/a_div_const_add_a_mul_n_div_const.py +42 -0
  131. angr/analyses/decompiler/peephole_optimizations/a_mul_const_div_shr_const.py +38 -0
  132. angr/analyses/decompiler/peephole_optimizations/a_mul_const_sub_a.py +34 -0
  133. angr/analyses/decompiler/peephole_optimizations/a_shl_const_sub_a.py +34 -0
  134. angr/analyses/decompiler/peephole_optimizations/a_sub_a_div.py +25 -0
  135. angr/analyses/decompiler/peephole_optimizations/a_sub_a_div_const_mul_const.py +57 -0
  136. angr/analyses/decompiler/peephole_optimizations/a_sub_a_shr_const_shr_const.py +37 -0
  137. angr/analyses/decompiler/peephole_optimizations/a_sub_a_sub_n.py +23 -0
  138. angr/analyses/decompiler/peephole_optimizations/arm_cmpf.py +236 -0
  139. angr/analyses/decompiler/peephole_optimizations/base.py +157 -0
  140. angr/analyses/decompiler/peephole_optimizations/basepointeroffset_add_n.py +34 -0
  141. angr/analyses/decompiler/peephole_optimizations/basepointeroffset_and_mask.py +36 -0
  142. angr/analyses/decompiler/peephole_optimizations/bitwise_or_to_logical_or.py +34 -0
  143. angr/analyses/decompiler/peephole_optimizations/bool_expr_xor_1.py +27 -0
  144. angr/analyses/decompiler/peephole_optimizations/bswap.py +142 -0
  145. angr/analyses/decompiler/peephole_optimizations/cas_intrinsics.py +115 -0
  146. angr/analyses/decompiler/peephole_optimizations/cmpord_rewriter.py +71 -0
  147. angr/analyses/decompiler/peephole_optimizations/coalesce_adjacent_shrs.py +39 -0
  148. angr/analyses/decompiler/peephole_optimizations/coalesce_same_cascading_ifs.py +28 -0
  149. angr/analyses/decompiler/peephole_optimizations/const_mull_a_shift.py +242 -0
  150. angr/analyses/decompiler/peephole_optimizations/constant_derefs.py +44 -0
  151. angr/analyses/decompiler/peephole_optimizations/conv_a_sub0_shr_and.py +69 -0
  152. angr/analyses/decompiler/peephole_optimizations/conv_shl_shr.py +52 -0
  153. angr/analyses/decompiler/peephole_optimizations/eager_eval.py +394 -0
  154. angr/analyses/decompiler/peephole_optimizations/extended_byte_and_mask.py +56 -0
  155. angr/analyses/decompiler/peephole_optimizations/inlined_strcpy.py +160 -0
  156. angr/analyses/decompiler/peephole_optimizations/inlined_strcpy_consolidation.py +109 -0
  157. angr/analyses/decompiler/peephole_optimizations/inlined_wstrcpy.py +170 -0
  158. angr/analyses/decompiler/peephole_optimizations/invert_negated_logical_conjuction_disjunction.py +50 -0
  159. angr/analyses/decompiler/peephole_optimizations/one_sub_bool.py +33 -0
  160. angr/analyses/decompiler/peephole_optimizations/remove_cascading_conversions.py +45 -0
  161. angr/analyses/decompiler/peephole_optimizations/remove_cxx_destructor_calls.py +32 -0
  162. angr/analyses/decompiler/peephole_optimizations/remove_empty_if_body.py +46 -0
  163. angr/analyses/decompiler/peephole_optimizations/remove_noop_conversions.py +47 -0
  164. angr/analyses/decompiler/peephole_optimizations/remove_redundant_bitmasks.py +116 -0
  165. angr/analyses/decompiler/peephole_optimizations/remove_redundant_conversions.py +273 -0
  166. angr/analyses/decompiler/peephole_optimizations/remove_redundant_ite_branch.py +30 -0
  167. angr/analyses/decompiler/peephole_optimizations/remove_redundant_ite_comparisons.py +54 -0
  168. angr/analyses/decompiler/peephole_optimizations/remove_redundant_nots.py +36 -0
  169. angr/analyses/decompiler/peephole_optimizations/remove_redundant_reinterprets.py +44 -0
  170. angr/analyses/decompiler/peephole_optimizations/remove_redundant_shifts.py +95 -0
  171. angr/analyses/decompiler/peephole_optimizations/remove_redundant_shifts_around_comparators.py +44 -0
  172. angr/analyses/decompiler/peephole_optimizations/rewrite_bit_extractions.py +85 -0
  173. angr/analyses/decompiler/peephole_optimizations/rewrite_conv_mul.py +40 -0
  174. angr/analyses/decompiler/peephole_optimizations/rewrite_cxx_operator_calls.py +90 -0
  175. angr/analyses/decompiler/peephole_optimizations/rewrite_mips_gp_loads.py +49 -0
  176. angr/analyses/decompiler/peephole_optimizations/rol_ror.py +130 -0
  177. angr/analyses/decompiler/peephole_optimizations/sar_to_signed_div.py +143 -0
  178. angr/analyses/decompiler/peephole_optimizations/shl_to_mul.py +25 -0
  179. angr/analyses/decompiler/peephole_optimizations/simplify_pc_relative_loads.py +51 -0
  180. angr/analyses/decompiler/peephole_optimizations/single_bit_cond_to_boolexpr.py +82 -0
  181. angr/analyses/decompiler/peephole_optimizations/single_bit_xor.py +29 -0
  182. angr/analyses/decompiler/peephole_optimizations/tidy_stack_addr.py +131 -0
  183. angr/analyses/decompiler/peephole_optimizations/utils.py +18 -0
  184. angr/analyses/decompiler/presets/__init__.py +20 -0
  185. angr/analyses/decompiler/presets/basic.py +32 -0
  186. angr/analyses/decompiler/presets/fast.py +58 -0
  187. angr/analyses/decompiler/presets/full.py +68 -0
  188. angr/analyses/decompiler/presets/preset.py +37 -0
  189. angr/analyses/decompiler/redundant_label_remover.py +134 -0
  190. angr/analyses/decompiler/region_identifier.py +1218 -0
  191. angr/analyses/decompiler/region_simplifiers/__init__.py +5 -0
  192. angr/analyses/decompiler/region_simplifiers/cascading_cond_transformer.py +95 -0
  193. angr/analyses/decompiler/region_simplifiers/cascading_ifs.py +82 -0
  194. angr/analyses/decompiler/region_simplifiers/expr_folding.py +789 -0
  195. angr/analyses/decompiler/region_simplifiers/goto.py +178 -0
  196. angr/analyses/decompiler/region_simplifiers/if_.py +135 -0
  197. angr/analyses/decompiler/region_simplifiers/ifelse.py +91 -0
  198. angr/analyses/decompiler/region_simplifiers/loop.py +143 -0
  199. angr/analyses/decompiler/region_simplifiers/node_address_finder.py +24 -0
  200. angr/analyses/decompiler/region_simplifiers/region_simplifier.py +234 -0
  201. angr/analyses/decompiler/region_simplifiers/switch_cluster_simplifier.py +654 -0
  202. angr/analyses/decompiler/region_simplifiers/switch_expr_simplifier.py +87 -0
  203. angr/analyses/decompiler/region_walker.py +24 -0
  204. angr/analyses/decompiler/return_maker.py +72 -0
  205. angr/analyses/decompiler/seq_to_blocks.py +20 -0
  206. angr/analyses/decompiler/sequence_walker.py +257 -0
  207. angr/analyses/decompiler/ssailification/__init__.py +4 -0
  208. angr/analyses/decompiler/ssailification/rewriting.py +379 -0
  209. angr/analyses/decompiler/ssailification/rewriting_engine.py +1053 -0
  210. angr/analyses/decompiler/ssailification/rewriting_state.py +61 -0
  211. angr/analyses/decompiler/ssailification/ssailification.py +276 -0
  212. angr/analyses/decompiler/ssailification/traversal.py +124 -0
  213. angr/analyses/decompiler/ssailification/traversal_engine.py +297 -0
  214. angr/analyses/decompiler/ssailification/traversal_state.py +48 -0
  215. angr/analyses/decompiler/stack_item.py +36 -0
  216. angr/analyses/decompiler/structured_codegen/__init__.py +25 -0
  217. angr/analyses/decompiler/structured_codegen/base.py +132 -0
  218. angr/analyses/decompiler/structured_codegen/c.py +4082 -0
  219. angr/analyses/decompiler/structured_codegen/dummy.py +15 -0
  220. angr/analyses/decompiler/structured_codegen/dwarf_import.py +190 -0
  221. angr/analyses/decompiler/structuring/__init__.py +30 -0
  222. angr/analyses/decompiler/structuring/dream.py +1217 -0
  223. angr/analyses/decompiler/structuring/phoenix.py +2999 -0
  224. angr/analyses/decompiler/structuring/recursive_structurer.py +187 -0
  225. angr/analyses/decompiler/structuring/sailr.py +112 -0
  226. angr/analyses/decompiler/structuring/structurer_base.py +1067 -0
  227. angr/analyses/decompiler/structuring/structurer_nodes.py +438 -0
  228. angr/analyses/decompiler/utils.py +1106 -0
  229. angr/analyses/deobfuscator/__init__.py +18 -0
  230. angr/analyses/deobfuscator/api_obf_finder.py +325 -0
  231. angr/analyses/deobfuscator/api_obf_peephole_optimizer.py +51 -0
  232. angr/analyses/deobfuscator/api_obf_type2_finder.py +166 -0
  233. angr/analyses/deobfuscator/irsb_reg_collector.py +54 -0
  234. angr/analyses/deobfuscator/string_obf_finder.py +861 -0
  235. angr/analyses/deobfuscator/string_obf_opt_passes.py +133 -0
  236. angr/analyses/deobfuscator/string_obf_peephole_optimizer.py +47 -0
  237. angr/analyses/disassembly.py +1295 -0
  238. angr/analyses/disassembly_utils.py +101 -0
  239. angr/analyses/dominance_frontier.py +57 -0
  240. angr/analyses/fcp/__init__.py +4 -0
  241. angr/analyses/fcp/fcp.py +426 -0
  242. angr/analyses/find_objects_static.py +205 -0
  243. angr/analyses/flirt/__init__.py +47 -0
  244. angr/analyses/flirt/consts.py +160 -0
  245. angr/analyses/flirt/flirt.py +244 -0
  246. angr/analyses/flirt/flirt_function.py +20 -0
  247. angr/analyses/flirt/flirt_matcher.py +351 -0
  248. angr/analyses/flirt/flirt_module.py +32 -0
  249. angr/analyses/flirt/flirt_node.py +23 -0
  250. angr/analyses/flirt/flirt_sig.py +356 -0
  251. angr/analyses/flirt/flirt_utils.py +31 -0
  252. angr/analyses/forward_analysis/__init__.py +12 -0
  253. angr/analyses/forward_analysis/forward_analysis.py +530 -0
  254. angr/analyses/forward_analysis/job_info.py +64 -0
  255. angr/analyses/forward_analysis/visitors/__init__.py +14 -0
  256. angr/analyses/forward_analysis/visitors/call_graph.py +29 -0
  257. angr/analyses/forward_analysis/visitors/function_graph.py +86 -0
  258. angr/analyses/forward_analysis/visitors/graph.py +242 -0
  259. angr/analyses/forward_analysis/visitors/loop.py +29 -0
  260. angr/analyses/forward_analysis/visitors/single_node_graph.py +38 -0
  261. angr/analyses/identifier/__init__.py +5 -0
  262. angr/analyses/identifier/custom_callable.py +137 -0
  263. angr/analyses/identifier/errors.py +10 -0
  264. angr/analyses/identifier/func.py +60 -0
  265. angr/analyses/identifier/functions/__init__.py +37 -0
  266. angr/analyses/identifier/functions/atoi.py +73 -0
  267. angr/analyses/identifier/functions/based_atoi.py +125 -0
  268. angr/analyses/identifier/functions/fdprintf.py +123 -0
  269. angr/analyses/identifier/functions/free.py +64 -0
  270. angr/analyses/identifier/functions/int2str.py +287 -0
  271. angr/analyses/identifier/functions/malloc.py +111 -0
  272. angr/analyses/identifier/functions/memcmp.py +67 -0
  273. angr/analyses/identifier/functions/memcpy.py +89 -0
  274. angr/analyses/identifier/functions/memset.py +43 -0
  275. angr/analyses/identifier/functions/printf.py +123 -0
  276. angr/analyses/identifier/functions/recv_until.py +312 -0
  277. angr/analyses/identifier/functions/skip_calloc.py +73 -0
  278. angr/analyses/identifier/functions/skip_realloc.py +97 -0
  279. angr/analyses/identifier/functions/skip_recv_n.py +105 -0
  280. angr/analyses/identifier/functions/snprintf.py +112 -0
  281. angr/analyses/identifier/functions/sprintf.py +116 -0
  282. angr/analyses/identifier/functions/strcasecmp.py +33 -0
  283. angr/analyses/identifier/functions/strcmp.py +113 -0
  284. angr/analyses/identifier/functions/strcpy.py +43 -0
  285. angr/analyses/identifier/functions/strlen.py +27 -0
  286. angr/analyses/identifier/functions/strncmp.py +104 -0
  287. angr/analyses/identifier/functions/strncpy.py +65 -0
  288. angr/analyses/identifier/functions/strtol.py +89 -0
  289. angr/analyses/identifier/identify.py +825 -0
  290. angr/analyses/identifier/runner.py +360 -0
  291. angr/analyses/init_finder.py +289 -0
  292. angr/analyses/loop_analysis.py +349 -0
  293. angr/analyses/loopfinder.py +171 -0
  294. angr/analyses/patchfinder.py +137 -0
  295. angr/analyses/pathfinder.py +282 -0
  296. angr/analyses/propagator/__init__.py +5 -0
  297. angr/analyses/propagator/engine_base.py +62 -0
  298. angr/analyses/propagator/engine_vex.py +297 -0
  299. angr/analyses/propagator/propagator.py +361 -0
  300. angr/analyses/propagator/top_checker_mixin.py +218 -0
  301. angr/analyses/propagator/values.py +117 -0
  302. angr/analyses/propagator/vex_vars.py +68 -0
  303. angr/analyses/proximity_graph.py +444 -0
  304. angr/analyses/reaching_definitions/__init__.py +67 -0
  305. angr/analyses/reaching_definitions/call_trace.py +73 -0
  306. angr/analyses/reaching_definitions/dep_graph.py +433 -0
  307. angr/analyses/reaching_definitions/engine_ail.py +1130 -0
  308. angr/analyses/reaching_definitions/engine_vex.py +1127 -0
  309. angr/analyses/reaching_definitions/external_codeloc.py +0 -0
  310. angr/analyses/reaching_definitions/function_handler.py +637 -0
  311. angr/analyses/reaching_definitions/function_handler_library/__init__.py +12 -0
  312. angr/analyses/reaching_definitions/function_handler_library/stdio.py +268 -0
  313. angr/analyses/reaching_definitions/function_handler_library/stdlib.py +189 -0
  314. angr/analyses/reaching_definitions/function_handler_library/string.py +147 -0
  315. angr/analyses/reaching_definitions/function_handler_library/unistd.py +44 -0
  316. angr/analyses/reaching_definitions/heap_allocator.py +70 -0
  317. angr/analyses/reaching_definitions/rd_initializer.py +237 -0
  318. angr/analyses/reaching_definitions/rd_state.py +579 -0
  319. angr/analyses/reaching_definitions/reaching_definitions.py +581 -0
  320. angr/analyses/reaching_definitions/subject.py +65 -0
  321. angr/analyses/reassembler.py +2900 -0
  322. angr/analyses/s_liveness.py +203 -0
  323. angr/analyses/s_propagator.py +542 -0
  324. angr/analyses/s_reaching_definitions/__init__.py +12 -0
  325. angr/analyses/s_reaching_definitions/s_rda_model.py +135 -0
  326. angr/analyses/s_reaching_definitions/s_rda_view.py +315 -0
  327. angr/analyses/s_reaching_definitions/s_reaching_definitions.py +174 -0
  328. angr/analyses/smc.py +161 -0
  329. angr/analyses/soot_class_hierarchy.py +273 -0
  330. angr/analyses/stack_pointer_tracker.py +953 -0
  331. angr/analyses/static_hooker.py +53 -0
  332. angr/analyses/typehoon/__init__.py +5 -0
  333. angr/analyses/typehoon/dfa.py +118 -0
  334. angr/analyses/typehoon/lifter.py +122 -0
  335. angr/analyses/typehoon/simple_solver.py +1464 -0
  336. angr/analyses/typehoon/translator.py +279 -0
  337. angr/analyses/typehoon/typeconsts.py +336 -0
  338. angr/analyses/typehoon/typehoon.py +311 -0
  339. angr/analyses/typehoon/typevars.py +622 -0
  340. angr/analyses/typehoon/variance.py +11 -0
  341. angr/analyses/unpacker/__init__.py +6 -0
  342. angr/analyses/unpacker/obfuscation_detector.py +103 -0
  343. angr/analyses/unpacker/packing_detector.py +138 -0
  344. angr/analyses/variable_recovery/__init__.py +9 -0
  345. angr/analyses/variable_recovery/annotations.py +58 -0
  346. angr/analyses/variable_recovery/engine_ail.py +897 -0
  347. angr/analyses/variable_recovery/engine_base.py +1185 -0
  348. angr/analyses/variable_recovery/engine_vex.py +593 -0
  349. angr/analyses/variable_recovery/irsb_scanner.py +143 -0
  350. angr/analyses/variable_recovery/variable_recovery.py +574 -0
  351. angr/analyses/variable_recovery/variable_recovery_base.py +461 -0
  352. angr/analyses/variable_recovery/variable_recovery_fast.py +652 -0
  353. angr/analyses/veritesting.py +626 -0
  354. angr/analyses/vfg.py +1898 -0
  355. angr/analyses/vsa_ddg.py +420 -0
  356. angr/analyses/vtable.py +92 -0
  357. angr/analyses/xrefs.py +286 -0
  358. angr/angrdb/__init__.py +14 -0
  359. angr/angrdb/db.py +206 -0
  360. angr/angrdb/models.py +184 -0
  361. angr/angrdb/serializers/__init__.py +10 -0
  362. angr/angrdb/serializers/cfg_model.py +41 -0
  363. angr/angrdb/serializers/comments.py +60 -0
  364. angr/angrdb/serializers/funcs.py +61 -0
  365. angr/angrdb/serializers/kb.py +111 -0
  366. angr/angrdb/serializers/labels.py +59 -0
  367. angr/angrdb/serializers/loader.py +165 -0
  368. angr/angrdb/serializers/structured_code.py +125 -0
  369. angr/angrdb/serializers/variables.py +58 -0
  370. angr/angrdb/serializers/xrefs.py +48 -0
  371. angr/annocfg.py +317 -0
  372. angr/blade.py +426 -0
  373. angr/block.py +509 -0
  374. angr/callable.py +168 -0
  375. angr/calling_conventions.py +2580 -0
  376. angr/code_location.py +163 -0
  377. angr/codenode.py +145 -0
  378. angr/concretization_strategies/__init__.py +32 -0
  379. angr/concretization_strategies/any.py +17 -0
  380. angr/concretization_strategies/any_named.py +35 -0
  381. angr/concretization_strategies/base.py +81 -0
  382. angr/concretization_strategies/controlled_data.py +58 -0
  383. angr/concretization_strategies/eval.py +19 -0
  384. angr/concretization_strategies/logging.py +35 -0
  385. angr/concretization_strategies/max.py +25 -0
  386. angr/concretization_strategies/nonzero.py +16 -0
  387. angr/concretization_strategies/nonzero_range.py +22 -0
  388. angr/concretization_strategies/norepeats.py +37 -0
  389. angr/concretization_strategies/norepeats_range.py +37 -0
  390. angr/concretization_strategies/range.py +19 -0
  391. angr/concretization_strategies/signed_add.py +31 -0
  392. angr/concretization_strategies/single.py +15 -0
  393. angr/concretization_strategies/solutions.py +20 -0
  394. angr/concretization_strategies/unlimited_range.py +17 -0
  395. angr/distributed/__init__.py +9 -0
  396. angr/distributed/server.py +197 -0
  397. angr/distributed/worker.py +185 -0
  398. angr/engines/__init__.py +67 -0
  399. angr/engines/engine.py +29 -0
  400. angr/engines/failure.py +27 -0
  401. angr/engines/hook.py +68 -0
  402. angr/engines/icicle.py +229 -0
  403. angr/engines/light/__init__.py +23 -0
  404. angr/engines/light/data.py +681 -0
  405. angr/engines/light/engine.py +1285 -0
  406. angr/engines/pcode/__init__.py +9 -0
  407. angr/engines/pcode/behavior.py +994 -0
  408. angr/engines/pcode/cc.py +128 -0
  409. angr/engines/pcode/emulate.py +440 -0
  410. angr/engines/pcode/engine.py +242 -0
  411. angr/engines/pcode/lifter.py +1420 -0
  412. angr/engines/procedure.py +70 -0
  413. angr/engines/soot/__init__.py +5 -0
  414. angr/engines/soot/engine.py +410 -0
  415. angr/engines/soot/exceptions.py +17 -0
  416. angr/engines/soot/expressions/__init__.py +87 -0
  417. angr/engines/soot/expressions/arrayref.py +22 -0
  418. angr/engines/soot/expressions/base.py +21 -0
  419. angr/engines/soot/expressions/binop.py +28 -0
  420. angr/engines/soot/expressions/cast.py +22 -0
  421. angr/engines/soot/expressions/condition.py +35 -0
  422. angr/engines/soot/expressions/constants.py +47 -0
  423. angr/engines/soot/expressions/instanceOf.py +15 -0
  424. angr/engines/soot/expressions/instancefieldref.py +8 -0
  425. angr/engines/soot/expressions/invoke.py +114 -0
  426. angr/engines/soot/expressions/length.py +8 -0
  427. angr/engines/soot/expressions/local.py +8 -0
  428. angr/engines/soot/expressions/new.py +16 -0
  429. angr/engines/soot/expressions/newArray.py +54 -0
  430. angr/engines/soot/expressions/newMultiArray.py +86 -0
  431. angr/engines/soot/expressions/paramref.py +8 -0
  432. angr/engines/soot/expressions/phi.py +30 -0
  433. angr/engines/soot/expressions/staticfieldref.py +8 -0
  434. angr/engines/soot/expressions/thisref.py +7 -0
  435. angr/engines/soot/expressions/unsupported.py +7 -0
  436. angr/engines/soot/field_dispatcher.py +46 -0
  437. angr/engines/soot/method_dispatcher.py +46 -0
  438. angr/engines/soot/statements/__init__.py +44 -0
  439. angr/engines/soot/statements/assign.py +30 -0
  440. angr/engines/soot/statements/base.py +79 -0
  441. angr/engines/soot/statements/goto.py +14 -0
  442. angr/engines/soot/statements/identity.py +15 -0
  443. angr/engines/soot/statements/if_.py +19 -0
  444. angr/engines/soot/statements/invoke.py +12 -0
  445. angr/engines/soot/statements/return_.py +20 -0
  446. angr/engines/soot/statements/switch.py +41 -0
  447. angr/engines/soot/statements/throw.py +15 -0
  448. angr/engines/soot/values/__init__.py +38 -0
  449. angr/engines/soot/values/arrayref.py +122 -0
  450. angr/engines/soot/values/base.py +7 -0
  451. angr/engines/soot/values/constants.py +18 -0
  452. angr/engines/soot/values/instancefieldref.py +44 -0
  453. angr/engines/soot/values/local.py +18 -0
  454. angr/engines/soot/values/paramref.py +18 -0
  455. angr/engines/soot/values/staticfieldref.py +38 -0
  456. angr/engines/soot/values/strref.py +38 -0
  457. angr/engines/soot/values/thisref.py +149 -0
  458. angr/engines/successors.py +654 -0
  459. angr/engines/syscall.py +51 -0
  460. angr/engines/unicorn.py +490 -0
  461. angr/engines/vex/__init__.py +20 -0
  462. angr/engines/vex/claripy/__init__.py +5 -0
  463. angr/engines/vex/claripy/ccall.py +2097 -0
  464. angr/engines/vex/claripy/datalayer.py +141 -0
  465. angr/engines/vex/claripy/irop.py +1276 -0
  466. angr/engines/vex/heavy/__init__.py +16 -0
  467. angr/engines/vex/heavy/actions.py +231 -0
  468. angr/engines/vex/heavy/concretizers.py +403 -0
  469. angr/engines/vex/heavy/dirty.py +466 -0
  470. angr/engines/vex/heavy/heavy.py +370 -0
  471. angr/engines/vex/heavy/inspect.py +52 -0
  472. angr/engines/vex/heavy/resilience.py +85 -0
  473. angr/engines/vex/heavy/super_fastpath.py +34 -0
  474. angr/engines/vex/lifter.py +420 -0
  475. angr/engines/vex/light/__init__.py +11 -0
  476. angr/engines/vex/light/light.py +551 -0
  477. angr/engines/vex/light/resilience.py +74 -0
  478. angr/engines/vex/light/slicing.py +52 -0
  479. angr/errors.py +609 -0
  480. angr/exploration_techniques/__init__.py +53 -0
  481. angr/exploration_techniques/base.py +126 -0
  482. angr/exploration_techniques/bucketizer.py +94 -0
  483. angr/exploration_techniques/common.py +56 -0
  484. angr/exploration_techniques/dfs.py +37 -0
  485. angr/exploration_techniques/director.py +520 -0
  486. angr/exploration_techniques/driller_core.py +100 -0
  487. angr/exploration_techniques/explorer.py +152 -0
  488. angr/exploration_techniques/lengthlimiter.py +22 -0
  489. angr/exploration_techniques/local_loop_seer.py +65 -0
  490. angr/exploration_techniques/loop_seer.py +236 -0
  491. angr/exploration_techniques/manual_mergepoint.py +82 -0
  492. angr/exploration_techniques/memory_watcher.py +43 -0
  493. angr/exploration_techniques/oppologist.py +92 -0
  494. angr/exploration_techniques/slicecutor.py +118 -0
  495. angr/exploration_techniques/spiller.py +280 -0
  496. angr/exploration_techniques/spiller_db.py +27 -0
  497. angr/exploration_techniques/stochastic.py +56 -0
  498. angr/exploration_techniques/stub_stasher.py +19 -0
  499. angr/exploration_techniques/suggestions.py +159 -0
  500. angr/exploration_techniques/tech_builder.py +49 -0
  501. angr/exploration_techniques/threading.py +69 -0
  502. angr/exploration_techniques/timeout.py +34 -0
  503. angr/exploration_techniques/tracer.py +1098 -0
  504. angr/exploration_techniques/unique.py +106 -0
  505. angr/exploration_techniques/veritesting.py +37 -0
  506. angr/factory.py +404 -0
  507. angr/flirt/__init__.py +97 -0
  508. angr/flirt/build_sig.py +305 -0
  509. angr/graph_utils.py +0 -0
  510. angr/keyed_region.py +525 -0
  511. angr/knowledge_base.py +143 -0
  512. angr/knowledge_plugins/__init__.py +43 -0
  513. angr/knowledge_plugins/callsite_prototypes.py +53 -0
  514. angr/knowledge_plugins/cfg/__init__.py +18 -0
  515. angr/knowledge_plugins/cfg/cfg_manager.py +95 -0
  516. angr/knowledge_plugins/cfg/cfg_model.py +1045 -0
  517. angr/knowledge_plugins/cfg/cfg_node.py +536 -0
  518. angr/knowledge_plugins/cfg/indirect_jump.py +65 -0
  519. angr/knowledge_plugins/cfg/memory_data.py +156 -0
  520. angr/knowledge_plugins/comments.py +16 -0
  521. angr/knowledge_plugins/custom_strings.py +38 -0
  522. angr/knowledge_plugins/data.py +22 -0
  523. angr/knowledge_plugins/debug_variables.py +216 -0
  524. angr/knowledge_plugins/functions/__init__.py +9 -0
  525. angr/knowledge_plugins/functions/function.py +1780 -0
  526. angr/knowledge_plugins/functions/function_manager.py +589 -0
  527. angr/knowledge_plugins/functions/function_parser.py +299 -0
  528. angr/knowledge_plugins/functions/soot_function.py +128 -0
  529. angr/knowledge_plugins/indirect_jumps.py +35 -0
  530. angr/knowledge_plugins/key_definitions/__init__.py +17 -0
  531. angr/knowledge_plugins/key_definitions/atoms.py +374 -0
  532. angr/knowledge_plugins/key_definitions/constants.py +29 -0
  533. angr/knowledge_plugins/key_definitions/definition.py +214 -0
  534. angr/knowledge_plugins/key_definitions/environment.py +96 -0
  535. angr/knowledge_plugins/key_definitions/heap_address.py +33 -0
  536. angr/knowledge_plugins/key_definitions/key_definition_manager.py +82 -0
  537. angr/knowledge_plugins/key_definitions/live_definitions.py +1010 -0
  538. angr/knowledge_plugins/key_definitions/liveness.py +165 -0
  539. angr/knowledge_plugins/key_definitions/rd_model.py +171 -0
  540. angr/knowledge_plugins/key_definitions/tag.py +78 -0
  541. angr/knowledge_plugins/key_definitions/undefined.py +70 -0
  542. angr/knowledge_plugins/key_definitions/unknown_size.py +86 -0
  543. angr/knowledge_plugins/key_definitions/uses.py +178 -0
  544. angr/knowledge_plugins/labels.py +110 -0
  545. angr/knowledge_plugins/obfuscations.py +37 -0
  546. angr/knowledge_plugins/patches.py +126 -0
  547. angr/knowledge_plugins/plugin.py +24 -0
  548. angr/knowledge_plugins/propagations/__init__.py +10 -0
  549. angr/knowledge_plugins/propagations/prop_value.py +191 -0
  550. angr/knowledge_plugins/propagations/propagation_manager.py +60 -0
  551. angr/knowledge_plugins/propagations/propagation_model.py +73 -0
  552. angr/knowledge_plugins/propagations/states.py +552 -0
  553. angr/knowledge_plugins/structured_code.py +63 -0
  554. angr/knowledge_plugins/types.py +88 -0
  555. angr/knowledge_plugins/variables/__init__.py +8 -0
  556. angr/knowledge_plugins/variables/variable_access.py +113 -0
  557. angr/knowledge_plugins/variables/variable_manager.py +1380 -0
  558. angr/knowledge_plugins/xrefs/__init__.py +12 -0
  559. angr/knowledge_plugins/xrefs/xref.py +150 -0
  560. angr/knowledge_plugins/xrefs/xref_manager.py +127 -0
  561. angr/knowledge_plugins/xrefs/xref_types.py +16 -0
  562. angr/lib/angr_native.dll +0 -0
  563. angr/misc/__init__.py +19 -0
  564. angr/misc/ansi.py +47 -0
  565. angr/misc/autoimport.py +90 -0
  566. angr/misc/bug_report.py +117 -0
  567. angr/misc/hookset.py +106 -0
  568. angr/misc/loggers.py +130 -0
  569. angr/misc/picklable_lock.py +46 -0
  570. angr/misc/plugins.py +289 -0
  571. angr/misc/telemetry.py +54 -0
  572. angr/misc/testing.py +24 -0
  573. angr/misc/ux.py +31 -0
  574. angr/procedures/__init__.py +12 -0
  575. angr/procedures/advapi32/__init__.py +0 -0
  576. angr/procedures/cgc/__init__.py +3 -0
  577. angr/procedures/cgc/_terminate.py +11 -0
  578. angr/procedures/cgc/allocate.py +75 -0
  579. angr/procedures/cgc/deallocate.py +67 -0
  580. angr/procedures/cgc/fdwait.py +65 -0
  581. angr/procedures/cgc/random.py +67 -0
  582. angr/procedures/cgc/receive.py +93 -0
  583. angr/procedures/cgc/transmit.py +65 -0
  584. angr/procedures/definitions/__init__.py +779 -0
  585. angr/procedures/definitions/cgc.py +20 -0
  586. angr/procedures/definitions/glibc.py +8372 -0
  587. angr/procedures/definitions/gnulib.py +32 -0
  588. angr/procedures/definitions/libstdcpp.py +21 -0
  589. angr/procedures/definitions/linux_kernel.py +6171 -0
  590. angr/procedures/definitions/linux_loader.py +7 -0
  591. angr/procedures/definitions/msvcr.py +16 -0
  592. angr/procedures/definitions/parse_syscalls_from_local_system.py +50 -0
  593. angr/procedures/definitions/parse_win32json.py +2553 -0
  594. angr/procedures/definitions/types_stl.py +22 -0
  595. angr/procedures/definitions/types_win32.py +34482 -0
  596. angr/procedures/definitions/wdk_api-ms-win-dx-d3dkmt-l1-1-4.py +30 -0
  597. angr/procedures/definitions/wdk_api-ms-win-dx-d3dkmt-l1-1-6.py +26 -0
  598. angr/procedures/definitions/wdk_clfs.py +140 -0
  599. angr/procedures/definitions/wdk_fltmgr.py +556 -0
  600. angr/procedures/definitions/wdk_fwpkclnt.py +30 -0
  601. angr/procedures/definitions/wdk_fwpuclnt.py +316 -0
  602. angr/procedures/definitions/wdk_gdi32.py +366 -0
  603. angr/procedures/definitions/wdk_hal.py +78 -0
  604. angr/procedures/definitions/wdk_ksecdd.py +62 -0
  605. angr/procedures/definitions/wdk_ndis.py +238 -0
  606. angr/procedures/definitions/wdk_ntoskrnl.py +3451 -0
  607. angr/procedures/definitions/wdk_offreg.py +72 -0
  608. angr/procedures/definitions/wdk_pshed.py +36 -0
  609. angr/procedures/definitions/wdk_secur32.py +40 -0
  610. angr/procedures/definitions/wdk_vhfum.py +34 -0
  611. angr/procedures/definitions/win32_aclui.py +30 -0
  612. angr/procedures/definitions/win32_activeds.py +68 -0
  613. angr/procedures/definitions/win32_advapi32.py +1684 -0
  614. angr/procedures/definitions/win32_advpack.py +124 -0
  615. angr/procedures/definitions/win32_amsi.py +38 -0
  616. angr/procedures/definitions/win32_api-ms-win-appmodel-runtime-l1-1-1.py +44 -0
  617. angr/procedures/definitions/win32_api-ms-win-appmodel-runtime-l1-1-3.py +34 -0
  618. angr/procedures/definitions/win32_api-ms-win-appmodel-runtime-l1-1-6.py +26 -0
  619. angr/procedures/definitions/win32_api-ms-win-core-apiquery-l2-1-0.py +26 -0
  620. angr/procedures/definitions/win32_api-ms-win-core-backgroundtask-l1-1-0.py +26 -0
  621. angr/procedures/definitions/win32_api-ms-win-core-comm-l1-1-1.py +26 -0
  622. angr/procedures/definitions/win32_api-ms-win-core-comm-l1-1-2.py +26 -0
  623. angr/procedures/definitions/win32_api-ms-win-core-enclave-l1-1-1.py +30 -0
  624. angr/procedures/definitions/win32_api-ms-win-core-errorhandling-l1-1-3.py +26 -0
  625. angr/procedures/definitions/win32_api-ms-win-core-featurestaging-l1-1-0.py +34 -0
  626. angr/procedures/definitions/win32_api-ms-win-core-featurestaging-l1-1-1.py +26 -0
  627. angr/procedures/definitions/win32_api-ms-win-core-file-fromapp-l1-1-0.py +46 -0
  628. angr/procedures/definitions/win32_api-ms-win-core-handle-l1-1-0.py +26 -0
  629. angr/procedures/definitions/win32_api-ms-win-core-ioring-l1-1-0.py +48 -0
  630. angr/procedures/definitions/win32_api-ms-win-core-marshal-l1-1-0.py +32 -0
  631. angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-3.py +32 -0
  632. angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-4.py +26 -0
  633. angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-5.py +30 -0
  634. angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-6.py +32 -0
  635. angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-7.py +28 -0
  636. angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-8.py +30 -0
  637. angr/procedures/definitions/win32_api-ms-win-core-path-l1-1-0.py +68 -0
  638. angr/procedures/definitions/win32_api-ms-win-core-psm-appnotify-l1-1-0.py +28 -0
  639. angr/procedures/definitions/win32_api-ms-win-core-psm-appnotify-l1-1-1.py +28 -0
  640. angr/procedures/definitions/win32_api-ms-win-core-realtime-l1-1-1.py +30 -0
  641. angr/procedures/definitions/win32_api-ms-win-core-realtime-l1-1-2.py +30 -0
  642. angr/procedures/definitions/win32_api-ms-win-core-slapi-l1-1-0.py +26 -0
  643. angr/procedures/definitions/win32_api-ms-win-core-state-helpers-l1-1-0.py +26 -0
  644. angr/procedures/definitions/win32_api-ms-win-core-synch-l1-2-0.py +30 -0
  645. angr/procedures/definitions/win32_api-ms-win-core-sysinfo-l1-2-0.py +26 -0
  646. angr/procedures/definitions/win32_api-ms-win-core-sysinfo-l1-2-3.py +28 -0
  647. angr/procedures/definitions/win32_api-ms-win-core-sysinfo-l1-2-4.py +28 -0
  648. angr/procedures/definitions/win32_api-ms-win-core-sysinfo-l1-2-6.py +26 -0
  649. angr/procedures/definitions/win32_api-ms-win-core-util-l1-1-1.py +28 -0
  650. angr/procedures/definitions/win32_api-ms-win-core-winrt-error-l1-1-0.py +44 -0
  651. angr/procedures/definitions/win32_api-ms-win-core-winrt-error-l1-1-1.py +38 -0
  652. angr/procedures/definitions/win32_api-ms-win-core-winrt-l1-1-0.py +40 -0
  653. angr/procedures/definitions/win32_api-ms-win-core-winrt-registration-l1-1-0.py +24 -0
  654. angr/procedures/definitions/win32_api-ms-win-core-winrt-robuffer-l1-1-0.py +24 -0
  655. angr/procedures/definitions/win32_api-ms-win-core-winrt-roparameterizediid-l1-1-0.py +28 -0
  656. angr/procedures/definitions/win32_api-ms-win-core-winrt-string-l1-1-0.py +76 -0
  657. angr/procedures/definitions/win32_api-ms-win-core-winrt-string-l1-1-1.py +24 -0
  658. angr/procedures/definitions/win32_api-ms-win-core-wow64-l1-1-1.py +30 -0
  659. angr/procedures/definitions/win32_api-ms-win-devices-query-l1-1-0.py +42 -0
  660. angr/procedures/definitions/win32_api-ms-win-devices-query-l1-1-1.py +34 -0
  661. angr/procedures/definitions/win32_api-ms-win-dx-d3dkmt-l1-1-0.py +26 -0
  662. angr/procedures/definitions/win32_api-ms-win-gaming-deviceinformation-l1-1-0.py +26 -0
  663. angr/procedures/definitions/win32_api-ms-win-gaming-expandedresources-l1-1-0.py +30 -0
  664. angr/procedures/definitions/win32_api-ms-win-gaming-tcui-l1-1-0.py +38 -0
  665. angr/procedures/definitions/win32_api-ms-win-gaming-tcui-l1-1-1.py +28 -0
  666. angr/procedures/definitions/win32_api-ms-win-gaming-tcui-l1-1-2.py +38 -0
  667. angr/procedures/definitions/win32_api-ms-win-gaming-tcui-l1-1-3.py +28 -0
  668. angr/procedures/definitions/win32_api-ms-win-gaming-tcui-l1-1-4.py +40 -0
  669. angr/procedures/definitions/win32_api-ms-win-mm-misc-l1-1-1.py +26 -0
  670. angr/procedures/definitions/win32_api-ms-win-net-isolation-l1-1-0.py +40 -0
  671. angr/procedures/definitions/win32_api-ms-win-security-base-l1-2-2.py +26 -0
  672. angr/procedures/definitions/win32_api-ms-win-security-isolatedcontainer-l1-1-0.py +26 -0
  673. angr/procedures/definitions/win32_api-ms-win-security-isolatedcontainer-l1-1-1.py +26 -0
  674. angr/procedures/definitions/win32_api-ms-win-service-core-l1-1-3.py +26 -0
  675. angr/procedures/definitions/win32_api-ms-win-service-core-l1-1-4.py +26 -0
  676. angr/procedures/definitions/win32_api-ms-win-service-core-l1-1-5.py +28 -0
  677. angr/procedures/definitions/win32_api-ms-win-shcore-scaling-l1-1-0.py +30 -0
  678. angr/procedures/definitions/win32_api-ms-win-shcore-scaling-l1-1-1.py +36 -0
  679. angr/procedures/definitions/win32_api-ms-win-shcore-scaling-l1-1-2.py +26 -0
  680. angr/procedures/definitions/win32_api-ms-win-shcore-stream-winrt-l1-1-0.py +28 -0
  681. angr/procedures/definitions/win32_api-ms-win-wsl-api-l1-1-0.py +38 -0
  682. angr/procedures/definitions/win32_apphelp.py +26 -0
  683. angr/procedures/definitions/win32_authz.py +90 -0
  684. angr/procedures/definitions/win32_avicap32.py +32 -0
  685. angr/procedures/definitions/win32_avifil32.py +144 -0
  686. angr/procedures/definitions/win32_avrt.py +52 -0
  687. angr/procedures/definitions/win32_bcp47mrm.py +28 -0
  688. angr/procedures/definitions/win32_bcrypt.py +130 -0
  689. angr/procedures/definitions/win32_bcryptprimitives.py +28 -0
  690. angr/procedures/definitions/win32_bluetoothapis.py +106 -0
  691. angr/procedures/definitions/win32_bthprops.py +34 -0
  692. angr/procedures/definitions/win32_bthprops_cpl.py +36 -0
  693. angr/procedures/definitions/win32_cabinet.py +68 -0
  694. angr/procedures/definitions/win32_certadm.py +60 -0
  695. angr/procedures/definitions/win32_certpoleng.py +40 -0
  696. angr/procedures/definitions/win32_cfgmgr32.py +502 -0
  697. angr/procedures/definitions/win32_chakra.py +198 -0
  698. angr/procedures/definitions/win32_cldapi.py +96 -0
  699. angr/procedures/definitions/win32_clfsw32.py +142 -0
  700. angr/procedures/definitions/win32_clusapi.py +584 -0
  701. angr/procedures/definitions/win32_comctl32.py +254 -0
  702. angr/procedures/definitions/win32_comdlg32.py +66 -0
  703. angr/procedures/definitions/win32_compstui.py +32 -0
  704. angr/procedures/definitions/win32_computecore.py +132 -0
  705. angr/procedures/definitions/win32_computenetwork.py +110 -0
  706. angr/procedures/definitions/win32_computestorage.py +48 -0
  707. angr/procedures/definitions/win32_comsvcs.py +38 -0
  708. angr/procedures/definitions/win32_coremessaging.py +24 -0
  709. angr/procedures/definitions/win32_credui.py +62 -0
  710. angr/procedures/definitions/win32_crypt32.py +482 -0
  711. angr/procedures/definitions/win32_cryptnet.py +34 -0
  712. angr/procedures/definitions/win32_cryptui.py +44 -0
  713. angr/procedures/definitions/win32_cryptxml.py +62 -0
  714. angr/procedures/definitions/win32_cscapi.py +32 -0
  715. angr/procedures/definitions/win32_d2d1.py +50 -0
  716. angr/procedures/definitions/win32_d3d10.py +78 -0
  717. angr/procedures/definitions/win32_d3d10_1.py +28 -0
  718. angr/procedures/definitions/win32_d3d11.py +30 -0
  719. angr/procedures/definitions/win32_d3d12.py +40 -0
  720. angr/procedures/definitions/win32_d3d9.py +46 -0
  721. angr/procedures/definitions/win32_d3dcompiler_47.py +76 -0
  722. angr/procedures/definitions/win32_d3dcsx.py +42 -0
  723. angr/procedures/definitions/win32_davclnt.py +60 -0
  724. angr/procedures/definitions/win32_dbgeng.py +32 -0
  725. angr/procedures/definitions/win32_dbghelp.py +462 -0
  726. angr/procedures/definitions/win32_dbgmodel.py +26 -0
  727. angr/procedures/definitions/win32_dciman32.py +64 -0
  728. angr/procedures/definitions/win32_dcomp.py +48 -0
  729. angr/procedures/definitions/win32_ddraw.py +38 -0
  730. angr/procedures/definitions/win32_deviceaccess.py +26 -0
  731. angr/procedures/definitions/win32_dflayout.py +26 -0
  732. angr/procedures/definitions/win32_dhcpcsvc.py +54 -0
  733. angr/procedures/definitions/win32_dhcpcsvc6.py +36 -0
  734. angr/procedures/definitions/win32_dhcpsapi.py +416 -0
  735. angr/procedures/definitions/win32_diagnosticdataquery.py +94 -0
  736. angr/procedures/definitions/win32_dinput8.py +26 -0
  737. angr/procedures/definitions/win32_directml.py +28 -0
  738. angr/procedures/definitions/win32_dmprocessxmlfiltered.py +26 -0
  739. angr/procedures/definitions/win32_dnsapi.py +152 -0
  740. angr/procedures/definitions/win32_drt.py +56 -0
  741. angr/procedures/definitions/win32_drtprov.py +42 -0
  742. angr/procedures/definitions/win32_drttransport.py +28 -0
  743. angr/procedures/definitions/win32_dsound.py +44 -0
  744. angr/procedures/definitions/win32_dsparse.py +62 -0
  745. angr/procedures/definitions/win32_dsprop.py +38 -0
  746. angr/procedures/definitions/win32_dssec.py +32 -0
  747. angr/procedures/definitions/win32_dsuiext.py +32 -0
  748. angr/procedures/definitions/win32_dwmapi.py +86 -0
  749. angr/procedures/definitions/win32_dwrite.py +26 -0
  750. angr/procedures/definitions/win32_dxcompiler.py +28 -0
  751. angr/procedures/definitions/win32_dxcore.py +26 -0
  752. angr/procedures/definitions/win32_dxgi.py +36 -0
  753. angr/procedures/definitions/win32_dxva2.py +100 -0
  754. angr/procedures/definitions/win32_eappcfg.py +52 -0
  755. angr/procedures/definitions/win32_eappprxy.py +60 -0
  756. angr/procedures/definitions/win32_efswrt.py +28 -0
  757. angr/procedures/definitions/win32_elscore.py +34 -0
  758. angr/procedures/definitions/win32_esent.py +482 -0
  759. angr/procedures/definitions/win32_evr.py +38 -0
  760. angr/procedures/definitions/win32_faultrep.py +32 -0
  761. angr/procedures/definitions/win32_fhsvcctl.py +38 -0
  762. angr/procedures/definitions/win32_firewallapi.py +30 -0
  763. angr/procedures/definitions/win32_fltlib.py +80 -0
  764. angr/procedures/definitions/win32_fontsub.py +28 -0
  765. angr/procedures/definitions/win32_forceinline.py +30 -0
  766. angr/procedures/definitions/win32_fwpuclnt.py +408 -0
  767. angr/procedures/definitions/win32_fxsutility.py +28 -0
  768. angr/procedures/definitions/win32_gdi32.py +886 -0
  769. angr/procedures/definitions/win32_gdiplus.py +1282 -0
  770. angr/procedures/definitions/win32_glu32.py +128 -0
  771. angr/procedures/definitions/win32_gpedit.py +36 -0
  772. angr/procedures/definitions/win32_hhctrl_ocx.py +28 -0
  773. angr/procedures/definitions/win32_hid.py +114 -0
  774. angr/procedures/definitions/win32_hlink.py +80 -0
  775. angr/procedures/definitions/win32_hrtfapo.py +26 -0
  776. angr/procedures/definitions/win32_httpapi.py +110 -0
  777. angr/procedures/definitions/win32_icm32.py +66 -0
  778. angr/procedures/definitions/win32_icmui.py +28 -0
  779. angr/procedures/definitions/win32_icu.py +2074 -0
  780. angr/procedures/definitions/win32_ieframe.py +82 -0
  781. angr/procedures/definitions/win32_imagehlp.py +76 -0
  782. angr/procedures/definitions/win32_imgutil.py +42 -0
  783. angr/procedures/definitions/win32_imm32.py +188 -0
  784. angr/procedures/definitions/win32_infocardapi.py +58 -0
  785. angr/procedures/definitions/win32_inkobjcore.py +78 -0
  786. angr/procedures/definitions/win32_iphlpapi.py +426 -0
  787. angr/procedures/definitions/win32_iscsidsc.py +182 -0
  788. angr/procedures/definitions/win32_isolatedwindowsenvironmentutils.py +28 -0
  789. angr/procedures/definitions/win32_kernel32.py +3185 -0
  790. angr/procedures/definitions/win32_kernelbase.py +36 -0
  791. angr/procedures/definitions/win32_keycredmgr.py +32 -0
  792. angr/procedures/definitions/win32_ksproxy_ax.py +36 -0
  793. angr/procedures/definitions/win32_ksuser.py +40 -0
  794. angr/procedures/definitions/win32_ktmw32.py +102 -0
  795. angr/procedures/definitions/win32_licenseprotection.py +28 -0
  796. angr/procedures/definitions/win32_loadperf.py +48 -0
  797. angr/procedures/definitions/win32_magnification.py +62 -0
  798. angr/procedures/definitions/win32_mapi32.py +156 -0
  799. angr/procedures/definitions/win32_mdmlocalmanagement.py +30 -0
  800. angr/procedures/definitions/win32_mdmregistration.py +54 -0
  801. angr/procedures/definitions/win32_mf.py +148 -0
  802. angr/procedures/definitions/win32_mfcore.py +28 -0
  803. angr/procedures/definitions/win32_mfplat.py +314 -0
  804. angr/procedures/definitions/win32_mfplay.py +26 -0
  805. angr/procedures/definitions/win32_mfreadwrite.py +34 -0
  806. angr/procedures/definitions/win32_mfsensorgroup.py +44 -0
  807. angr/procedures/definitions/win32_mfsrcsnk.py +28 -0
  808. angr/procedures/definitions/win32_mgmtapi.py +42 -0
  809. angr/procedures/definitions/win32_mi.py +26 -0
  810. angr/procedures/definitions/win32_mmdevapi.py +26 -0
  811. angr/procedures/definitions/win32_mpr.py +118 -0
  812. angr/procedures/definitions/win32_mprapi.py +248 -0
  813. angr/procedures/definitions/win32_mqrt.py +92 -0
  814. angr/procedures/definitions/win32_mrmsupport.py +78 -0
  815. angr/procedures/definitions/win32_msacm32.py +108 -0
  816. angr/procedures/definitions/win32_msajapi.py +1118 -0
  817. angr/procedures/definitions/win32_mscms.py +182 -0
  818. angr/procedures/definitions/win32_mscoree.py +78 -0
  819. angr/procedures/definitions/win32_msctfmonitor.py +30 -0
  820. angr/procedures/definitions/win32_msdelta.py +56 -0
  821. angr/procedures/definitions/win32_msdmo.py +46 -0
  822. angr/procedures/definitions/win32_msdrm.py +192 -0
  823. angr/procedures/definitions/win32_msi.py +552 -0
  824. angr/procedures/definitions/win32_msimg32.py +30 -0
  825. angr/procedures/definitions/win32_mspatcha.py +56 -0
  826. angr/procedures/definitions/win32_mspatchc.py +42 -0
  827. angr/procedures/definitions/win32_msports.py +38 -0
  828. angr/procedures/definitions/win32_msrating.py +62 -0
  829. angr/procedures/definitions/win32_mssign32.py +44 -0
  830. angr/procedures/definitions/win32_mstask.py +28 -0
  831. angr/procedures/definitions/win32_msvfw32.py +110 -0
  832. angr/procedures/definitions/win32_mswsock.py +56 -0
  833. angr/procedures/definitions/win32_mtxdm.py +26 -0
  834. angr/procedures/definitions/win32_ncrypt.py +102 -0
  835. angr/procedures/definitions/win32_ndfapi.py +56 -0
  836. angr/procedures/definitions/win32_netapi32.py +436 -0
  837. angr/procedures/definitions/win32_netsh.py +40 -0
  838. angr/procedures/definitions/win32_netshell.py +28 -0
  839. angr/procedures/definitions/win32_newdev.py +46 -0
  840. angr/procedures/definitions/win32_ninput.py +84 -0
  841. angr/procedures/definitions/win32_normaliz.py +28 -0
  842. angr/procedures/definitions/win32_ntdll.py +171 -0
  843. angr/procedures/definitions/win32_ntdllk.py +26 -0
  844. angr/procedures/definitions/win32_ntdsapi.py +186 -0
  845. angr/procedures/definitions/win32_ntlanman.py +44 -0
  846. angr/procedures/definitions/win32_odbc32.py +392 -0
  847. angr/procedures/definitions/win32_odbcbcp.py +78 -0
  848. angr/procedures/definitions/win32_ole32.py +658 -0
  849. angr/procedures/definitions/win32_oleacc.py +58 -0
  850. angr/procedures/definitions/win32_oleaut32.py +834 -0
  851. angr/procedures/definitions/win32_oledlg.py +70 -0
  852. angr/procedures/definitions/win32_ondemandconnroutehelper.py +34 -0
  853. angr/procedures/definitions/win32_opengl32.py +734 -0
  854. angr/procedures/definitions/win32_opmxbox.py +30 -0
  855. angr/procedures/definitions/win32_p2p.py +240 -0
  856. angr/procedures/definitions/win32_p2pgraph.py +98 -0
  857. angr/procedures/definitions/win32_pdh.py +220 -0
  858. angr/procedures/definitions/win32_peerdist.py +80 -0
  859. angr/procedures/definitions/win32_powrprof.py +192 -0
  860. angr/procedures/definitions/win32_prntvpt.py +46 -0
  861. angr/procedures/definitions/win32_projectedfslib.py +62 -0
  862. angr/procedures/definitions/win32_propsys.py +460 -0
  863. angr/procedures/definitions/win32_psapi.py +78 -0
  864. angr/procedures/definitions/win32_quartz.py +28 -0
  865. angr/procedures/definitions/win32_query.py +32 -0
  866. angr/procedures/definitions/win32_qwave.py +46 -0
  867. angr/procedures/definitions/win32_rasapi32.py +192 -0
  868. angr/procedures/definitions/win32_rasdlg.py +36 -0
  869. angr/procedures/definitions/win32_resutils.py +264 -0
  870. angr/procedures/definitions/win32_rometadata.py +24 -0
  871. angr/procedures/definitions/win32_rpcns4.py +146 -0
  872. angr/procedures/definitions/win32_rpcproxy.py +32 -0
  873. angr/procedures/definitions/win32_rpcrt4.py +918 -0
  874. angr/procedures/definitions/win32_rstrtmgr.py +46 -0
  875. angr/procedures/definitions/win32_rtm.py +176 -0
  876. angr/procedures/definitions/win32_rtutils.py +106 -0
  877. angr/procedures/definitions/win32_rtworkq.py +90 -0
  878. angr/procedures/definitions/win32_sas.py +26 -0
  879. angr/procedures/definitions/win32_scarddlg.py +34 -0
  880. angr/procedures/definitions/win32_schannel.py +42 -0
  881. angr/procedures/definitions/win32_sechost.py +28 -0
  882. angr/procedures/definitions/win32_secur32.py +202 -0
  883. angr/procedures/definitions/win32_sensapi.py +30 -0
  884. angr/procedures/definitions/win32_sensorsutilsv2.py +104 -0
  885. angr/procedures/definitions/win32_setupapi.py +692 -0
  886. angr/procedures/definitions/win32_sfc.py +36 -0
  887. angr/procedures/definitions/win32_shdocvw.py +30 -0
  888. angr/procedures/definitions/win32_shell32.py +512 -0
  889. angr/procedures/definitions/win32_shlwapi.py +744 -0
  890. angr/procedures/definitions/win32_slc.py +88 -0
  891. angr/procedures/definitions/win32_slcext.py +32 -0
  892. angr/procedures/definitions/win32_slwga.py +26 -0
  893. angr/procedures/definitions/win32_snmpapi.py +76 -0
  894. angr/procedures/definitions/win32_spoolss.py +76 -0
  895. angr/procedures/definitions/win32_srclient.py +26 -0
  896. angr/procedures/definitions/win32_srpapi.py +46 -0
  897. angr/procedures/definitions/win32_sspicli.py +38 -0
  898. angr/procedures/definitions/win32_sti.py +26 -0
  899. angr/procedures/definitions/win32_t2embed.py +52 -0
  900. angr/procedures/definitions/win32_tapi32.py +522 -0
  901. angr/procedures/definitions/win32_tbs.py +52 -0
  902. angr/procedures/definitions/win32_tdh.py +78 -0
  903. angr/procedures/definitions/win32_tokenbinding.py +44 -0
  904. angr/procedures/definitions/win32_traffic.py +64 -0
  905. angr/procedures/definitions/win32_txfw32.py +42 -0
  906. angr/procedures/definitions/win32_ualapi.py +32 -0
  907. angr/procedures/definitions/win32_uiautomationcore.py +220 -0
  908. angr/procedures/definitions/win32_urlmon.py +178 -0
  909. angr/procedures/definitions/win32_user32.py +1551 -0
  910. angr/procedures/definitions/win32_userenv.py +112 -0
  911. angr/procedures/definitions/win32_usp10.py +104 -0
  912. angr/procedures/definitions/win32_uxtheme.py +178 -0
  913. angr/procedures/definitions/win32_verifier.py +26 -0
  914. angr/procedures/definitions/win32_version.py +52 -0
  915. angr/procedures/definitions/win32_vertdll.py +38 -0
  916. angr/procedures/definitions/win32_virtdisk.py +82 -0
  917. angr/procedures/definitions/win32_vmdevicehost.py +50 -0
  918. angr/procedures/definitions/win32_vmsavedstatedumpprovider.py +110 -0
  919. angr/procedures/definitions/win32_vssapi.py +26 -0
  920. angr/procedures/definitions/win32_wcmapi.py +34 -0
  921. angr/procedures/definitions/win32_wdsbp.py +38 -0
  922. angr/procedures/definitions/win32_wdsclientapi.py +98 -0
  923. angr/procedures/definitions/win32_wdsmc.py +36 -0
  924. angr/procedures/definitions/win32_wdspxe.py +86 -0
  925. angr/procedures/definitions/win32_wdstptc.py +50 -0
  926. angr/procedures/definitions/win32_webauthn.py +50 -0
  927. angr/procedures/definitions/win32_webservices.py +410 -0
  928. angr/procedures/definitions/win32_websocket.py +50 -0
  929. angr/procedures/definitions/win32_wecapi.py +54 -0
  930. angr/procedures/definitions/win32_wer.py +66 -0
  931. angr/procedures/definitions/win32_wevtapi.py +94 -0
  932. angr/procedures/definitions/win32_winbio.py +132 -0
  933. angr/procedures/definitions/win32_windows_ai_machinelearning.py +26 -0
  934. angr/procedures/definitions/win32_windows_data_pdf.py +24 -0
  935. angr/procedures/definitions/win32_windows_media_mediacontrol.py +40 -0
  936. angr/procedures/definitions/win32_windows_networking.py +26 -0
  937. angr/procedures/definitions/win32_windows_ui_xaml.py +28 -0
  938. angr/procedures/definitions/win32_windowscodecs.py +42 -0
  939. angr/procedures/definitions/win32_winfax.py +136 -0
  940. angr/procedures/definitions/win32_winhttp.py +136 -0
  941. angr/procedures/definitions/win32_winhvemulation.py +32 -0
  942. angr/procedures/definitions/win32_winhvplatform.py +156 -0
  943. angr/procedures/definitions/win32_wininet.py +616 -0
  944. angr/procedures/definitions/win32_winml.py +26 -0
  945. angr/procedures/definitions/win32_winmm.py +376 -0
  946. angr/procedures/definitions/win32_winscard.py +164 -0
  947. angr/procedures/definitions/win32_winspool.py +364 -0
  948. angr/procedures/definitions/win32_winspool_drv.py +368 -0
  949. angr/procedures/definitions/win32_wintrust.py +144 -0
  950. angr/procedures/definitions/win32_winusb.py +92 -0
  951. angr/procedures/definitions/win32_wlanapi.py +144 -0
  952. angr/procedures/definitions/win32_wlanui.py +26 -0
  953. angr/procedures/definitions/win32_wldap32.py +510 -0
  954. angr/procedures/definitions/win32_wldp.py +42 -0
  955. angr/procedures/definitions/win32_wmvcore.py +46 -0
  956. angr/procedures/definitions/win32_wnvapi.py +28 -0
  957. angr/procedures/definitions/win32_wofutil.py +46 -0
  958. angr/procedures/definitions/win32_ws2_32.py +344 -0
  959. angr/procedures/definitions/win32_wscapi.py +36 -0
  960. angr/procedures/definitions/win32_wsclient.py +30 -0
  961. angr/procedures/definitions/win32_wsdapi.py +88 -0
  962. angr/procedures/definitions/win32_wsmsvc.py +90 -0
  963. angr/procedures/definitions/win32_wsnmp32.py +122 -0
  964. angr/procedures/definitions/win32_wtsapi32.py +150 -0
  965. angr/procedures/definitions/win32_xaudio2_8.py +32 -0
  966. angr/procedures/definitions/win32_xinput1_4.py +38 -0
  967. angr/procedures/definitions/win32_xinputuap.py +36 -0
  968. angr/procedures/definitions/win32_xmllite.py +36 -0
  969. angr/procedures/definitions/win32_xolehlp.py +32 -0
  970. angr/procedures/definitions/win32_xpsprint.py +28 -0
  971. angr/procedures/glibc/__ctype_b_loc.py +21 -0
  972. angr/procedures/glibc/__ctype_tolower_loc.py +21 -0
  973. angr/procedures/glibc/__ctype_toupper_loc.py +21 -0
  974. angr/procedures/glibc/__errno_location.py +7 -0
  975. angr/procedures/glibc/__init__.py +3 -0
  976. angr/procedures/glibc/__libc_init.py +37 -0
  977. angr/procedures/glibc/__libc_start_main.py +301 -0
  978. angr/procedures/glibc/dynamic_loading.py +20 -0
  979. angr/procedures/glibc/scanf.py +11 -0
  980. angr/procedures/glibc/sscanf.py +6 -0
  981. angr/procedures/gnulib/__init__.py +3 -0
  982. angr/procedures/gnulib/xalloc_die.py +14 -0
  983. angr/procedures/gnulib/xstrtol_fatal.py +14 -0
  984. angr/procedures/java/__init__.py +42 -0
  985. angr/procedures/java/unconstrained.py +65 -0
  986. angr/procedures/java_io/__init__.py +0 -0
  987. angr/procedures/java_io/read.py +12 -0
  988. angr/procedures/java_io/write.py +17 -0
  989. angr/procedures/java_jni/__init__.py +482 -0
  990. angr/procedures/java_jni/array_operations.py +312 -0
  991. angr/procedures/java_jni/class_and_interface_operations.py +31 -0
  992. angr/procedures/java_jni/field_access.py +173 -0
  993. angr/procedures/java_jni/global_and_local_refs.py +57 -0
  994. angr/procedures/java_jni/method_calls.py +365 -0
  995. angr/procedures/java_jni/not_implemented.py +26 -0
  996. angr/procedures/java_jni/object_operations.py +94 -0
  997. angr/procedures/java_jni/string_operations.py +87 -0
  998. angr/procedures/java_jni/version_information.py +12 -0
  999. angr/procedures/java_lang/__init__.py +0 -0
  1000. angr/procedures/java_lang/character.py +30 -0
  1001. angr/procedures/java_lang/double.py +24 -0
  1002. angr/procedures/java_lang/exit.py +13 -0
  1003. angr/procedures/java_lang/getsimplename.py +18 -0
  1004. angr/procedures/java_lang/integer.py +43 -0
  1005. angr/procedures/java_lang/load_library.py +9 -0
  1006. angr/procedures/java_lang/math.py +15 -0
  1007. angr/procedures/java_lang/string.py +78 -0
  1008. angr/procedures/java_lang/stringbuilder.py +44 -0
  1009. angr/procedures/java_lang/system.py +18 -0
  1010. angr/procedures/java_util/__init__.py +0 -0
  1011. angr/procedures/java_util/collection.py +35 -0
  1012. angr/procedures/java_util/iterator.py +46 -0
  1013. angr/procedures/java_util/list.py +99 -0
  1014. angr/procedures/java_util/map.py +131 -0
  1015. angr/procedures/java_util/random.py +14 -0
  1016. angr/procedures/java_util/scanner_nextline.py +23 -0
  1017. angr/procedures/libc/__init__.py +3 -0
  1018. angr/procedures/libc/abort.py +9 -0
  1019. angr/procedures/libc/access.py +13 -0
  1020. angr/procedures/libc/atoi.py +14 -0
  1021. angr/procedures/libc/atol.py +13 -0
  1022. angr/procedures/libc/calloc.py +8 -0
  1023. angr/procedures/libc/closelog.py +10 -0
  1024. angr/procedures/libc/err.py +14 -0
  1025. angr/procedures/libc/error.py +54 -0
  1026. angr/procedures/libc/exit.py +11 -0
  1027. angr/procedures/libc/fclose.py +19 -0
  1028. angr/procedures/libc/feof.py +21 -0
  1029. angr/procedures/libc/fflush.py +16 -0
  1030. angr/procedures/libc/fgetc.py +27 -0
  1031. angr/procedures/libc/fgets.py +68 -0
  1032. angr/procedures/libc/fopen.py +63 -0
  1033. angr/procedures/libc/fprintf.py +25 -0
  1034. angr/procedures/libc/fputc.py +23 -0
  1035. angr/procedures/libc/fputs.py +24 -0
  1036. angr/procedures/libc/fread.py +24 -0
  1037. angr/procedures/libc/free.py +9 -0
  1038. angr/procedures/libc/fscanf.py +20 -0
  1039. angr/procedures/libc/fseek.py +34 -0
  1040. angr/procedures/libc/ftell.py +22 -0
  1041. angr/procedures/libc/fwrite.py +19 -0
  1042. angr/procedures/libc/getchar.py +13 -0
  1043. angr/procedures/libc/getdelim.py +99 -0
  1044. angr/procedures/libc/getegid.py +8 -0
  1045. angr/procedures/libc/geteuid.py +8 -0
  1046. angr/procedures/libc/getgid.py +8 -0
  1047. angr/procedures/libc/gets.py +68 -0
  1048. angr/procedures/libc/getuid.py +8 -0
  1049. angr/procedures/libc/malloc.py +12 -0
  1050. angr/procedures/libc/memcmp.py +69 -0
  1051. angr/procedures/libc/memcpy.py +38 -0
  1052. angr/procedures/libc/memset.py +72 -0
  1053. angr/procedures/libc/openlog.py +10 -0
  1054. angr/procedures/libc/perror.py +13 -0
  1055. angr/procedures/libc/printf.py +34 -0
  1056. angr/procedures/libc/putchar.py +13 -0
  1057. angr/procedures/libc/puts.py +19 -0
  1058. angr/procedures/libc/rand.py +8 -0
  1059. angr/procedures/libc/realloc.py +8 -0
  1060. angr/procedures/libc/rewind.py +12 -0
  1061. angr/procedures/libc/scanf.py +20 -0
  1062. angr/procedures/libc/setbuf.py +9 -0
  1063. angr/procedures/libc/setvbuf.py +7 -0
  1064. angr/procedures/libc/snprintf.py +36 -0
  1065. angr/procedures/libc/sprintf.py +25 -0
  1066. angr/procedures/libc/srand.py +7 -0
  1067. angr/procedures/libc/sscanf.py +13 -0
  1068. angr/procedures/libc/stpcpy.py +18 -0
  1069. angr/procedures/libc/strcat.py +14 -0
  1070. angr/procedures/libc/strchr.py +48 -0
  1071. angr/procedures/libc/strcmp.py +31 -0
  1072. angr/procedures/libc/strcpy.py +13 -0
  1073. angr/procedures/libc/strlen.py +114 -0
  1074. angr/procedures/libc/strncat.py +19 -0
  1075. angr/procedures/libc/strncmp.py +183 -0
  1076. angr/procedures/libc/strncpy.py +22 -0
  1077. angr/procedures/libc/strnlen.py +13 -0
  1078. angr/procedures/libc/strstr.py +101 -0
  1079. angr/procedures/libc/strtol.py +261 -0
  1080. angr/procedures/libc/strtoul.py +9 -0
  1081. angr/procedures/libc/system.py +13 -0
  1082. angr/procedures/libc/time.py +9 -0
  1083. angr/procedures/libc/tmpnam.py +20 -0
  1084. angr/procedures/libc/tolower.py +10 -0
  1085. angr/procedures/libc/toupper.py +10 -0
  1086. angr/procedures/libc/ungetc.py +20 -0
  1087. angr/procedures/libc/vsnprintf.py +17 -0
  1088. angr/procedures/libc/wchar.py +16 -0
  1089. angr/procedures/libstdcpp/__init__.py +0 -0
  1090. angr/procedures/libstdcpp/_unwind_resume.py +11 -0
  1091. angr/procedures/libstdcpp/std____throw_bad_alloc.py +13 -0
  1092. angr/procedures/libstdcpp/std____throw_bad_cast.py +13 -0
  1093. angr/procedures/libstdcpp/std____throw_length_error.py +13 -0
  1094. angr/procedures/libstdcpp/std____throw_logic_error.py +13 -0
  1095. angr/procedures/libstdcpp/std__terminate.py +13 -0
  1096. angr/procedures/linux_kernel/__init__.py +3 -0
  1097. angr/procedures/linux_kernel/access.py +18 -0
  1098. angr/procedures/linux_kernel/arch_prctl.py +34 -0
  1099. angr/procedures/linux_kernel/arm_user_helpers.py +59 -0
  1100. angr/procedures/linux_kernel/brk.py +18 -0
  1101. angr/procedures/linux_kernel/cwd.py +28 -0
  1102. angr/procedures/linux_kernel/fstat.py +138 -0
  1103. angr/procedures/linux_kernel/fstat64.py +170 -0
  1104. angr/procedures/linux_kernel/futex.py +17 -0
  1105. angr/procedures/linux_kernel/getegid.py +17 -0
  1106. angr/procedures/linux_kernel/geteuid.py +17 -0
  1107. angr/procedures/linux_kernel/getgid.py +17 -0
  1108. angr/procedures/linux_kernel/getpid.py +14 -0
  1109. angr/procedures/linux_kernel/getrlimit.py +24 -0
  1110. angr/procedures/linux_kernel/gettid.py +9 -0
  1111. angr/procedures/linux_kernel/getuid.py +17 -0
  1112. angr/procedures/linux_kernel/iovec.py +47 -0
  1113. angr/procedures/linux_kernel/lseek.py +42 -0
  1114. angr/procedures/linux_kernel/mmap.py +16 -0
  1115. angr/procedures/linux_kernel/mprotect.py +42 -0
  1116. angr/procedures/linux_kernel/munmap.py +8 -0
  1117. angr/procedures/linux_kernel/openat.py +26 -0
  1118. angr/procedures/linux_kernel/set_tid_address.py +8 -0
  1119. angr/procedures/linux_kernel/sigaction.py +19 -0
  1120. angr/procedures/linux_kernel/sigprocmask.py +23 -0
  1121. angr/procedures/linux_kernel/stat.py +23 -0
  1122. angr/procedures/linux_kernel/sysinfo.py +59 -0
  1123. angr/procedures/linux_kernel/tgkill.py +10 -0
  1124. angr/procedures/linux_kernel/time.py +34 -0
  1125. angr/procedures/linux_kernel/uid.py +30 -0
  1126. angr/procedures/linux_kernel/uname.py +29 -0
  1127. angr/procedures/linux_kernel/unlink.py +22 -0
  1128. angr/procedures/linux_kernel/vsyscall.py +16 -0
  1129. angr/procedures/linux_loader/__init__.py +3 -0
  1130. angr/procedures/linux_loader/_dl_initial_error_catch_tsd.py +7 -0
  1131. angr/procedures/linux_loader/_dl_rtld_lock.py +15 -0
  1132. angr/procedures/linux_loader/sim_loader.py +54 -0
  1133. angr/procedures/linux_loader/tls.py +40 -0
  1134. angr/procedures/msvcr/__getmainargs.py +16 -0
  1135. angr/procedures/msvcr/__init__.py +4 -0
  1136. angr/procedures/msvcr/_initterm.py +38 -0
  1137. angr/procedures/msvcr/fmode.py +31 -0
  1138. angr/procedures/ntdll/__init__.py +0 -0
  1139. angr/procedures/ntdll/exceptions.py +60 -0
  1140. angr/procedures/posix/__init__.py +3 -0
  1141. angr/procedures/posix/accept.py +29 -0
  1142. angr/procedures/posix/bind.py +13 -0
  1143. angr/procedures/posix/bzero.py +9 -0
  1144. angr/procedures/posix/chroot.py +27 -0
  1145. angr/procedures/posix/close.py +9 -0
  1146. angr/procedures/posix/closedir.py +7 -0
  1147. angr/procedures/posix/dup.py +56 -0
  1148. angr/procedures/posix/fcntl.py +10 -0
  1149. angr/procedures/posix/fdopen.py +76 -0
  1150. angr/procedures/posix/fileno.py +18 -0
  1151. angr/procedures/posix/fork.py +13 -0
  1152. angr/procedures/posix/getenv.py +35 -0
  1153. angr/procedures/posix/gethostbyname.py +43 -0
  1154. angr/procedures/posix/getpass.py +19 -0
  1155. angr/procedures/posix/getsockopt.py +11 -0
  1156. angr/procedures/posix/htonl.py +11 -0
  1157. angr/procedures/posix/htons.py +11 -0
  1158. angr/procedures/posix/inet_ntoa.py +59 -0
  1159. angr/procedures/posix/listen.py +13 -0
  1160. angr/procedures/posix/mmap.py +144 -0
  1161. angr/procedures/posix/open.py +18 -0
  1162. angr/procedures/posix/opendir.py +10 -0
  1163. angr/procedures/posix/poll.py +55 -0
  1164. angr/procedures/posix/pread64.py +46 -0
  1165. angr/procedures/posix/pthread.py +87 -0
  1166. angr/procedures/posix/pwrite64.py +46 -0
  1167. angr/procedures/posix/read.py +13 -0
  1168. angr/procedures/posix/readdir.py +62 -0
  1169. angr/procedures/posix/recv.py +13 -0
  1170. angr/procedures/posix/recvfrom.py +13 -0
  1171. angr/procedures/posix/select.py +48 -0
  1172. angr/procedures/posix/send.py +23 -0
  1173. angr/procedures/posix/setsockopt.py +9 -0
  1174. angr/procedures/posix/sigaction.py +23 -0
  1175. angr/procedures/posix/sim_time.py +48 -0
  1176. angr/procedures/posix/sleep.py +8 -0
  1177. angr/procedures/posix/socket.py +18 -0
  1178. angr/procedures/posix/strcasecmp.py +26 -0
  1179. angr/procedures/posix/strdup.py +18 -0
  1180. angr/procedures/posix/strtok_r.py +64 -0
  1181. angr/procedures/posix/syslog.py +15 -0
  1182. angr/procedures/posix/tz.py +9 -0
  1183. angr/procedures/posix/unlink.py +11 -0
  1184. angr/procedures/posix/usleep.py +8 -0
  1185. angr/procedures/posix/write.py +13 -0
  1186. angr/procedures/procedure_dict.py +50 -0
  1187. angr/procedures/stubs/CallReturn.py +13 -0
  1188. angr/procedures/stubs/NoReturnUnconstrained.py +13 -0
  1189. angr/procedures/stubs/Nop.py +7 -0
  1190. angr/procedures/stubs/PathTerminator.py +9 -0
  1191. angr/procedures/stubs/Redirect.py +18 -0
  1192. angr/procedures/stubs/ReturnChar.py +11 -0
  1193. angr/procedures/stubs/ReturnUnconstrained.py +24 -0
  1194. angr/procedures/stubs/UnresolvableCallTarget.py +9 -0
  1195. angr/procedures/stubs/UnresolvableJumpTarget.py +9 -0
  1196. angr/procedures/stubs/UserHook.py +18 -0
  1197. angr/procedures/stubs/__init__.py +3 -0
  1198. angr/procedures/stubs/b64_decode.py +15 -0
  1199. angr/procedures/stubs/caller.py +14 -0
  1200. angr/procedures/stubs/crazy_scanf.py +20 -0
  1201. angr/procedures/stubs/format_parser.py +669 -0
  1202. angr/procedures/stubs/syscall_stub.py +24 -0
  1203. angr/procedures/testing/__init__.py +3 -0
  1204. angr/procedures/testing/manyargs.py +9 -0
  1205. angr/procedures/testing/retreg.py +8 -0
  1206. angr/procedures/tracer/__init__.py +4 -0
  1207. angr/procedures/tracer/random.py +9 -0
  1208. angr/procedures/tracer/receive.py +23 -0
  1209. angr/procedures/tracer/transmit.py +26 -0
  1210. angr/procedures/uclibc/__init__.py +3 -0
  1211. angr/procedures/uclibc/__uClibc_main.py +10 -0
  1212. angr/procedures/win32/EncodePointer.py +7 -0
  1213. angr/procedures/win32/ExitProcess.py +9 -0
  1214. angr/procedures/win32/GetCommandLine.py +12 -0
  1215. angr/procedures/win32/GetCurrentProcessId.py +7 -0
  1216. angr/procedures/win32/GetCurrentThreadId.py +7 -0
  1217. angr/procedures/win32/GetLastInputInfo.py +40 -0
  1218. angr/procedures/win32/GetModuleHandle.py +29 -0
  1219. angr/procedures/win32/GetProcessAffinityMask.py +37 -0
  1220. angr/procedures/win32/InterlockedExchange.py +15 -0
  1221. angr/procedures/win32/IsProcessorFeaturePresent.py +7 -0
  1222. angr/procedures/win32/VirtualAlloc.py +114 -0
  1223. angr/procedures/win32/VirtualProtect.py +60 -0
  1224. angr/procedures/win32/__init__.py +3 -0
  1225. angr/procedures/win32/critical_section.py +12 -0
  1226. angr/procedures/win32/dynamic_loading.py +104 -0
  1227. angr/procedures/win32/file_handles.py +47 -0
  1228. angr/procedures/win32/gethostbyname.py +12 -0
  1229. angr/procedures/win32/heap.py +45 -0
  1230. angr/procedures/win32/is_bad_ptr.py +26 -0
  1231. angr/procedures/win32/local_storage.py +88 -0
  1232. angr/procedures/win32/mutex.py +11 -0
  1233. angr/procedures/win32/sim_time.py +135 -0
  1234. angr/procedures/win32/system_paths.py +35 -0
  1235. angr/procedures/win32_kernel/ExAllocatePool.py +13 -0
  1236. angr/procedures/win32_kernel/ExFreePoolWithTag.py +8 -0
  1237. angr/procedures/win32_kernel/__fastfail.py +15 -0
  1238. angr/procedures/win32_kernel/__init__.py +3 -0
  1239. angr/procedures/win_user32/__init__.py +0 -0
  1240. angr/procedures/win_user32/chars.py +15 -0
  1241. angr/procedures/win_user32/keyboard.py +14 -0
  1242. angr/procedures/win_user32/messagebox.py +49 -0
  1243. angr/project.py +837 -0
  1244. angr/protos/__init__.py +19 -0
  1245. angr/protos/cfg_pb2.py +31 -0
  1246. angr/protos/function_pb2.py +27 -0
  1247. angr/protos/primitives_pb2.py +52 -0
  1248. angr/protos/variables_pb2.py +44 -0
  1249. angr/protos/xrefs_pb2.py +25 -0
  1250. angr/py.typed +1 -0
  1251. angr/rustylib.pyd +0 -0
  1252. angr/serializable.py +66 -0
  1253. angr/sim_manager.py +971 -0
  1254. angr/sim_options.py +438 -0
  1255. angr/sim_procedure.py +606 -0
  1256. angr/sim_state.py +901 -0
  1257. angr/sim_state_options.py +403 -0
  1258. angr/sim_type.py +3679 -0
  1259. angr/sim_variable.py +465 -0
  1260. angr/simos/__init__.py +47 -0
  1261. angr/simos/cgc.py +153 -0
  1262. angr/simos/javavm.py +458 -0
  1263. angr/simos/linux.py +509 -0
  1264. angr/simos/simos.py +444 -0
  1265. angr/simos/snimmuc_nxp.py +149 -0
  1266. angr/simos/userland.py +163 -0
  1267. angr/simos/windows.py +601 -0
  1268. angr/simos/xbox.py +32 -0
  1269. angr/slicer.py +352 -0
  1270. angr/state_hierarchy.py +262 -0
  1271. angr/state_plugins/__init__.py +84 -0
  1272. angr/state_plugins/callstack.py +398 -0
  1273. angr/state_plugins/cgc.py +155 -0
  1274. angr/state_plugins/debug_variables.py +192 -0
  1275. angr/state_plugins/filesystem.py +463 -0
  1276. angr/state_plugins/gdb.py +148 -0
  1277. angr/state_plugins/globals.py +65 -0
  1278. angr/state_plugins/heap/__init__.py +15 -0
  1279. angr/state_plugins/heap/heap_base.py +128 -0
  1280. angr/state_plugins/heap/heap_brk.py +136 -0
  1281. angr/state_plugins/heap/heap_freelist.py +213 -0
  1282. angr/state_plugins/heap/heap_libc.py +46 -0
  1283. angr/state_plugins/heap/heap_ptmalloc.py +620 -0
  1284. angr/state_plugins/heap/utils.py +22 -0
  1285. angr/state_plugins/history.py +548 -0
  1286. angr/state_plugins/inspect.py +375 -0
  1287. angr/state_plugins/javavm_classloader.py +134 -0
  1288. angr/state_plugins/jni_references.py +95 -0
  1289. angr/state_plugins/libc.py +1263 -0
  1290. angr/state_plugins/light_registers.py +168 -0
  1291. angr/state_plugins/log.py +84 -0
  1292. angr/state_plugins/loop_data.py +92 -0
  1293. angr/state_plugins/plugin.py +170 -0
  1294. angr/state_plugins/posix.py +703 -0
  1295. angr/state_plugins/preconstrainer.py +196 -0
  1296. angr/state_plugins/scratch.py +173 -0
  1297. angr/state_plugins/sim_action.py +326 -0
  1298. angr/state_plugins/sim_action_object.py +271 -0
  1299. angr/state_plugins/sim_event.py +59 -0
  1300. angr/state_plugins/solver.py +1127 -0
  1301. angr/state_plugins/symbolizer.py +291 -0
  1302. angr/state_plugins/trace_additions.py +738 -0
  1303. angr/state_plugins/uc_manager.py +94 -0
  1304. angr/state_plugins/unicorn_engine.py +1886 -0
  1305. angr/state_plugins/view.py +340 -0
  1306. angr/storage/__init__.py +15 -0
  1307. angr/storage/file.py +1210 -0
  1308. angr/storage/memory_mixins/__init__.py +317 -0
  1309. angr/storage/memory_mixins/actions_mixin.py +72 -0
  1310. angr/storage/memory_mixins/address_concretization_mixin.py +384 -0
  1311. angr/storage/memory_mixins/bvv_conversion_mixin.py +73 -0
  1312. angr/storage/memory_mixins/clouseau_mixin.py +137 -0
  1313. angr/storage/memory_mixins/conditional_store_mixin.py +25 -0
  1314. angr/storage/memory_mixins/convenient_mappings_mixin.py +256 -0
  1315. angr/storage/memory_mixins/default_filler_mixin.py +144 -0
  1316. angr/storage/memory_mixins/dirty_addrs_mixin.py +11 -0
  1317. angr/storage/memory_mixins/hex_dumper_mixin.py +82 -0
  1318. angr/storage/memory_mixins/javavm_memory_mixin.py +392 -0
  1319. angr/storage/memory_mixins/keyvalue_memory_mixin.py +42 -0
  1320. angr/storage/memory_mixins/label_merger_mixin.py +31 -0
  1321. angr/storage/memory_mixins/memory_mixin.py +174 -0
  1322. angr/storage/memory_mixins/multi_value_merger_mixin.py +79 -0
  1323. angr/storage/memory_mixins/name_resolution_mixin.py +67 -0
  1324. angr/storage/memory_mixins/paged_memory/__init__.py +0 -0
  1325. angr/storage/memory_mixins/paged_memory/page_backer_mixins.py +266 -0
  1326. angr/storage/memory_mixins/paged_memory/paged_memory_mixin.py +743 -0
  1327. angr/storage/memory_mixins/paged_memory/paged_memory_multivalue_mixin.py +65 -0
  1328. angr/storage/memory_mixins/paged_memory/pages/__init__.py +26 -0
  1329. angr/storage/memory_mixins/paged_memory/pages/base.py +31 -0
  1330. angr/storage/memory_mixins/paged_memory/pages/cooperation.py +341 -0
  1331. angr/storage/memory_mixins/paged_memory/pages/history_tracking_mixin.py +92 -0
  1332. angr/storage/memory_mixins/paged_memory/pages/ispo_mixin.py +55 -0
  1333. angr/storage/memory_mixins/paged_memory/pages/list_page.py +338 -0
  1334. angr/storage/memory_mixins/paged_memory/pages/multi_values.py +324 -0
  1335. angr/storage/memory_mixins/paged_memory/pages/mv_list_page.py +419 -0
  1336. angr/storage/memory_mixins/paged_memory/pages/permissions_mixin.py +36 -0
  1337. angr/storage/memory_mixins/paged_memory/pages/refcount_mixin.py +52 -0
  1338. angr/storage/memory_mixins/paged_memory/pages/ultra_page.py +503 -0
  1339. angr/storage/memory_mixins/paged_memory/privileged_mixin.py +36 -0
  1340. angr/storage/memory_mixins/paged_memory/stack_allocation_mixin.py +74 -0
  1341. angr/storage/memory_mixins/regioned_memory/__init__.py +17 -0
  1342. angr/storage/memory_mixins/regioned_memory/abstract_address_descriptor.py +36 -0
  1343. angr/storage/memory_mixins/regioned_memory/abstract_merger_mixin.py +31 -0
  1344. angr/storage/memory_mixins/regioned_memory/region_category_mixin.py +9 -0
  1345. angr/storage/memory_mixins/regioned_memory/region_data.py +246 -0
  1346. angr/storage/memory_mixins/regioned_memory/region_meta_mixin.py +241 -0
  1347. angr/storage/memory_mixins/regioned_memory/regioned_address_concretization_mixin.py +119 -0
  1348. angr/storage/memory_mixins/regioned_memory/regioned_memory_mixin.py +441 -0
  1349. angr/storage/memory_mixins/regioned_memory/static_find_mixin.py +69 -0
  1350. angr/storage/memory_mixins/simple_interface_mixin.py +71 -0
  1351. angr/storage/memory_mixins/simplification_mixin.py +15 -0
  1352. angr/storage/memory_mixins/size_resolution_mixin.py +143 -0
  1353. angr/storage/memory_mixins/slotted_memory.py +140 -0
  1354. angr/storage/memory_mixins/smart_find_mixin.py +161 -0
  1355. angr/storage/memory_mixins/symbolic_merger_mixin.py +16 -0
  1356. angr/storage/memory_mixins/top_merger_mixin.py +25 -0
  1357. angr/storage/memory_mixins/underconstrained_mixin.py +67 -0
  1358. angr/storage/memory_mixins/unwrapper_mixin.py +26 -0
  1359. angr/storage/memory_object.py +195 -0
  1360. angr/tablespecs.py +91 -0
  1361. angr/utils/__init__.py +46 -0
  1362. angr/utils/ail.py +70 -0
  1363. angr/utils/algo.py +34 -0
  1364. angr/utils/bits.py +46 -0
  1365. angr/utils/constants.py +9 -0
  1366. angr/utils/cowdict.py +63 -0
  1367. angr/utils/cpp.py +17 -0
  1368. angr/utils/doms.py +149 -0
  1369. angr/utils/dynamic_dictlist.py +89 -0
  1370. angr/utils/endness.py +18 -0
  1371. angr/utils/enums_conv.py +97 -0
  1372. angr/utils/env.py +12 -0
  1373. angr/utils/formatting.py +128 -0
  1374. angr/utils/funcid.py +159 -0
  1375. angr/utils/graph.py +898 -0
  1376. angr/utils/lazy_import.py +13 -0
  1377. angr/utils/library.py +211 -0
  1378. angr/utils/loader.py +55 -0
  1379. angr/utils/mp.py +66 -0
  1380. angr/utils/orderedset.py +74 -0
  1381. angr/utils/ssa/__init__.py +395 -0
  1382. angr/utils/ssa/tmp_uses_collector.py +23 -0
  1383. angr/utils/ssa/vvar_uses_collector.py +37 -0
  1384. angr/utils/tagged_interval_map.py +112 -0
  1385. angr/utils/timing.py +74 -0
  1386. angr/utils/types.py +151 -0
  1387. angr/vaults.py +367 -0
  1388. angr-9.2.158.dist-info/METADATA +111 -0
  1389. angr-9.2.158.dist-info/RECORD +1393 -0
  1390. angr-9.2.158.dist-info/WHEEL +5 -0
  1391. angr-9.2.158.dist-info/entry_points.txt +2 -0
  1392. angr-9.2.158.dist-info/licenses/LICENSE +27 -0
  1393. angr-9.2.158.dist-info/top_level.txt +1 -0
@@ -0,0 +1,3447 @@
1
+ from __future__ import annotations
2
+ from typing import TYPE_CHECKING
3
+ import itertools
4
+ import logging
5
+ import sys
6
+ from collections import defaultdict
7
+ from functools import reduce
8
+ import contextlib
9
+
10
+ import angr
11
+ import claripy
12
+ import networkx
13
+ import pyvex
14
+ from archinfo import ArchARM
15
+
16
+ from angr.analyses import ForwardAnalysis
17
+ from angr.utils.graph import GraphUtils
18
+ from angr.analyses import AnalysesHub
19
+ from angr import BP, BP_BEFORE, BP_AFTER, SIM_PROCEDURES, procedures
20
+ from angr import options as o
21
+ from angr.codenode import BlockNode
22
+ from angr.engines.procedure import ProcedureEngine
23
+ from angr.exploration_techniques.loop_seer import LoopSeer
24
+ from angr.exploration_techniques.slicecutor import Slicecutor
25
+ from angr.exploration_techniques.explorer import Explorer
26
+ from angr.exploration_techniques.lengthlimiter import LengthLimiter
27
+ from angr.errors import (
28
+ AngrCFGError,
29
+ AngrError,
30
+ AngrSkipJobNotice,
31
+ SimError,
32
+ SimValueError,
33
+ SimSolverModeError,
34
+ SimFastPathError,
35
+ SimIRSBError,
36
+ AngrExitError,
37
+ SimEmptyCallStackError,
38
+ )
39
+ from angr.sim_state import SimState
40
+ from angr.state_plugins.callstack import CallStack
41
+ from angr.state_plugins.sim_action import SimActionData
42
+ from angr.knowledge_plugins.cfg import CFGENode, IndirectJump
43
+ from angr.utils.constants import DEFAULT_STATEMENT
44
+ from angr.analyses.cdg import CDG
45
+ from angr.analyses.ddg import DDG
46
+ from angr.analyses.backward_slice import BackwardSlice
47
+ from angr.analyses.loopfinder import LoopFinder, Loop
48
+ from .cfg_base import CFGBase
49
+ from .cfg_job_base import BlockID, CFGJobBase
50
+
51
+ if TYPE_CHECKING:
52
+ from angr.knowledge_plugins.cfg import CFGNode
53
+
54
+
55
+ l = logging.getLogger(name=__name__)
56
+
57
+
58
+ class CFGJob(CFGJobBase):
59
+ """
60
+ The job class that CFGEmulated uses.
61
+ """
62
+
63
+ def __init__(self, *args, **kwargs):
64
+ super().__init__(*args, **kwargs)
65
+
66
+ #
67
+ # local variables used during analysis
68
+ #
69
+
70
+ if self.jumpkind is None:
71
+ # load jumpkind from path.state.scratch
72
+ self.jumpkind = "Ijk_Boring" if self.state.history.jumpkind is None else self.state.history.jumpkind
73
+
74
+ self.call_stack_suffix = None
75
+ self.current_function = None
76
+
77
+ self.cfg_node = None
78
+ self.sim_successors = None
79
+ self.exception_info = None
80
+ self.successor_status = None
81
+
82
+ self.extra_info = None
83
+
84
+ @property
85
+ def block_id(self):
86
+ if self._block_id is None:
87
+ # generate a new block ID
88
+ self._block_id = CFGEmulated._generate_block_id(
89
+ self.call_stack.stack_suffix(self._context_sensitivity_level), self.addr, self.is_syscall
90
+ )
91
+ return self._block_id
92
+
93
+ @property
94
+ def is_syscall(self):
95
+ return self.jumpkind is not None and self.jumpkind.startswith("Ijk_Sys")
96
+
97
+ def __hash__(self):
98
+ return hash(self.block_id)
99
+
100
+
101
+ class PendingJob:
102
+ """
103
+ A PendingJob is whatever will be put into our pending_exit list. A pending exit is an entry that created by the
104
+ returning of a call or syscall. It is "pending" since we cannot immediately figure out whether this entry will
105
+ be executed or not. If the corresponding call/syscall intentionally doesn't return, then the pending exit will be
106
+ removed. If the corresponding call/syscall returns, then the pending exit will be removed as well (since a real
107
+ entry is created from the returning and will be analyzed later). If the corresponding call/syscall might
108
+ return, but for some reason (for example, an unsupported instruction is met during the analysis) our analysis
109
+ does not return properly, then the pending exit will be picked up and put into remaining_jobs list.
110
+ """
111
+
112
+ def __init__(
113
+ self, caller_func_addr, returning_source, state, src_block_id, src_exit_stmt_idx, src_exit_ins_addr, call_stack
114
+ ):
115
+ """
116
+ :param returning_source: Address of the callee function. It might be None if address of the callee is not
117
+ resolvable.
118
+ :param state: The state after returning from the callee function. Of course there is no way to get
119
+ a precise state without emulating the execution of the callee, but at least we can
120
+ properly adjust the stack and registers to imitate the real returned state.
121
+ :param call_stack: A callstack.
122
+ """
123
+
124
+ self.caller_func_addr = caller_func_addr
125
+ self.returning_source = returning_source
126
+ self.state = state
127
+ self.src_block_id = src_block_id
128
+ self.src_exit_stmt_idx = src_exit_stmt_idx
129
+ self.src_exit_ins_addr = src_exit_ins_addr
130
+ self.call_stack = call_stack
131
+
132
+ def __repr__(self):
133
+ return "<PendingJob to {}, from function {}>".format(
134
+ self.state.ip, hex(self.returning_source) if self.returning_source is not None else "Unknown"
135
+ )
136
+
137
+ def __hash__(self):
138
+ return hash(
139
+ (
140
+ self.caller_func_addr,
141
+ self.returning_source,
142
+ self.src_block_id,
143
+ self.src_exit_stmt_idx,
144
+ self.src_exit_ins_addr,
145
+ )
146
+ )
147
+
148
+ def __eq__(self, other):
149
+ if not isinstance(other, PendingJob):
150
+ return False
151
+ return (
152
+ self.caller_func_addr == other.caller_func_addr
153
+ and self.returning_source == other.returning_source
154
+ and self.src_block_id == other.src_block_id
155
+ and self.src_exit_stmt_idx == other.src_exit_stmt_idx
156
+ and self.src_exit_ins_addr == other.src_exit_ins_addr
157
+ )
158
+
159
+
160
+ class CFGEmulated(ForwardAnalysis, CFGBase): # pylint: disable=abstract-method
161
+ """
162
+ This class represents a control-flow graph.
163
+ """
164
+
165
+ tag = "CFGEmulated"
166
+
167
+ def __init__(
168
+ self,
169
+ context_sensitivity_level=1,
170
+ start=None,
171
+ avoid_runs=None,
172
+ enable_function_hints=False,
173
+ call_depth=None,
174
+ call_tracing_filter=None,
175
+ initial_state=None,
176
+ starts=None,
177
+ keep_state=False,
178
+ indirect_jump_target_limit=100000,
179
+ resolve_indirect_jumps=True,
180
+ enable_advanced_backward_slicing=False,
181
+ enable_symbolic_back_traversal=False,
182
+ indirect_jump_resolvers=None,
183
+ additional_edges=None,
184
+ no_construct=False,
185
+ normalize=False,
186
+ max_iterations=1,
187
+ address_whitelist=None,
188
+ base_graph=None,
189
+ iropt_level=None,
190
+ max_steps=None,
191
+ state_add_options=None,
192
+ state_remove_options=None,
193
+ model=None,
194
+ ):
195
+ """
196
+ All parameters are optional.
197
+
198
+ :param context_sensitivity_level: The level of context-sensitivity of this CFG (see documentation for
199
+ further details). It ranges from 0 to infinity. Default 1.
200
+ :param avoid_runs: A list of runs to avoid.
201
+ :param enable_function_hints: Whether to use function hints (constants that might be used as exit
202
+ targets) or not.
203
+ :param call_depth: How deep in the call stack to trace.
204
+ :param call_tracing_filter: Filter to apply on a given path and jumpkind to determine if it
205
+ should be skipped when call_depth is reached.
206
+ :param initial_state: An initial state to use to begin analysis.
207
+ :param iterable starts: A collection of starting points to begin analysis. It can contain
208
+ the following three different types of entries: an address specified
209
+ as an integer, a 2-tuple that includes an integer address and a
210
+ jumpkind, or a SimState instance. Unsupported entries in starts will
211
+ lead to an AngrCFGError being raised.
212
+ :param keep_state: Whether to keep the SimStates for each CFGNode.
213
+ :param resolve_indirect_jumps: Whether to enable the indirect jump resolvers for resolving indirect
214
+ jumps
215
+ :param enable_advanced_backward_slicing: Whether to enable an intensive technique for resolving indirect
216
+ jumps
217
+ :param enable_symbolic_back_traversal: Whether to enable an intensive technique for resolving indirect
218
+ jumps
219
+ :param list indirect_jump_resolvers: A custom list of indirect jump resolvers. If this list is None or
220
+ empty,
221
+ default indirect jump resolvers specific to this architecture and
222
+ binary types will be loaded.
223
+ :param additional_edges: A dict mapping addresses of basic blocks to addresses of
224
+ successors to manually include and analyze forward from.
225
+ :param bool no_construct: Skip the construction procedure. Only used in unit-testing.
226
+ :param bool normalize: If the CFG as well as all Function graphs should be normalized or
227
+ not.
228
+ :param int max_iterations: The maximum number of iterations that each basic block should be
229
+ "executed". 1 by default. Larger numbers of iterations are usually
230
+ required for complex analyses like loop analysis.
231
+ :param iterable address_whitelist: A list of allowed addresses. Any basic blocks outside of this
232
+ collection of addresses will be ignored.
233
+ :param networkx.DiGraph base_graph: A basic control flow graph to follow. Each node inside this graph
234
+ must have the following properties: `addr` and `size`. CFG recovery
235
+ will strictly follow nodes and edges shown in the graph, and discard
236
+ any control flow that does not follow an existing edge in the base
237
+ graph. For example, you can pass in a Function local transition
238
+ graph as the base graph, and CFGEmulated will traverse nodes and
239
+ edges and extract useful information.
240
+ :param int iropt_level: The optimization level of VEX IR (0, 1, 2). The default level will
241
+ be used if `iropt_level` is None.
242
+ :param int max_steps: The maximum number of basic blocks to recover forthe longest path
243
+ from each start before pausing the recovery procedure.
244
+ :param state_add_options: State options that will be added to the initial state.
245
+ :param state_remove_options: State options that will be removed from the initial state.
246
+ """
247
+ ForwardAnalysis.__init__(self, order_jobs=base_graph is not None)
248
+ CFGBase.__init__(
249
+ self,
250
+ "emulated",
251
+ context_sensitivity_level,
252
+ normalize=normalize,
253
+ resolve_indirect_jumps=resolve_indirect_jumps,
254
+ indirect_jump_resolvers=indirect_jump_resolvers,
255
+ indirect_jump_target_limit=indirect_jump_target_limit,
256
+ model=model,
257
+ )
258
+
259
+ if start is not None:
260
+ l.warning("`start` is deprecated. Please consider using `starts` instead in your code.")
261
+ self._starts = (start,)
262
+ else:
263
+ if isinstance(starts, (list, set)):
264
+ self._starts = tuple(starts)
265
+ elif isinstance(starts, tuple) or starts is None:
266
+ self._starts = starts
267
+ else:
268
+ raise AngrCFGError("Unsupported type of the `starts` argument.")
269
+
270
+ if enable_advanced_backward_slicing or enable_symbolic_back_traversal:
271
+ l.warning("`advanced backward slicing` and `symbolic back traversal` are deprecated.")
272
+ l.warning(
273
+ "Please use `resolve_indirect_jumps` to resolve indirect jumps using different resolvers instead."
274
+ )
275
+
276
+ self._iropt_level = iropt_level
277
+ self._avoid_runs = avoid_runs
278
+ self._enable_function_hints = enable_function_hints
279
+ self._call_depth = call_depth
280
+ self._call_tracing_filter = call_tracing_filter
281
+ self._initial_state = initial_state
282
+ self._keep_state = keep_state
283
+ self._advanced_backward_slicing = enable_advanced_backward_slicing
284
+ self._enable_symbolic_back_traversal = enable_symbolic_back_traversal
285
+ self._additional_edges = additional_edges if additional_edges else {}
286
+ self._max_steps = max_steps
287
+ self._state_add_options = state_add_options if state_add_options is not None else set()
288
+ self._state_remove_options = state_remove_options if state_remove_options is not None else set()
289
+ self._state_add_options.update([o.SYMBOL_FILL_UNCONSTRAINED_MEMORY, o.SYMBOL_FILL_UNCONSTRAINED_REGISTERS])
290
+
291
+ # add the track_memory_option if the enable function hint flag is set
292
+ if self._enable_function_hints and o.TRACK_MEMORY_ACTIONS not in self._state_add_options:
293
+ self._state_add_options.add(o.TRACK_MEMORY_ACTIONS)
294
+
295
+ # more initialization
296
+
297
+ self._symbolic_function_initial_state = {}
298
+ self._function_input_states = None
299
+ self._unresolvable_runs = set()
300
+
301
+ # Stores the index for each CFGNode in this CFG after a quasi-topological sort (currently a DFS)
302
+ # TODO: remove it since it's no longer used
303
+ self._quasi_topological_order = {}
304
+ # A copy of all entry points in this CFG. Integers
305
+ self._entry_points = []
306
+
307
+ self._max_iterations = max_iterations
308
+ self._address_whitelist = set(address_whitelist) if address_whitelist is not None else None
309
+ self._base_graph = base_graph
310
+ self._node_addr_visiting_order = []
311
+
312
+ if self._base_graph:
313
+ sorted_nodes = GraphUtils.quasi_topological_sort_nodes(self._base_graph)
314
+ self._node_addr_visiting_order = [n.addr for n in sorted_nodes]
315
+
316
+ self._sanitize_parameters()
317
+
318
+ self._executable_address_ranges = []
319
+ self._executable_address_ranges = self._executable_memory_regions()
320
+
321
+ # These save input states of functions. It will be discarded after the CFG is constructed
322
+ self._function_input_states = {}
323
+ self._loop_back_edges = []
324
+ self._overlapped_loop_headers = []
325
+ self._pending_function_hints = set()
326
+ # A dict to log edges and the jumpkind between each basic block
327
+ self._edge_map = defaultdict(list)
328
+
329
+ self._model._iropt_level = self._iropt_level
330
+
331
+ self._start_keys = [] # a list of block IDs of all starts
332
+
333
+ # For each call, we are always getting two exits: an Ijk_Call that
334
+ # stands for the real call exit, and an Ijk_Ret that is a simulated exit
335
+ # for the retn address. There are certain cases that the control flow
336
+ # never returns to the next instruction of a callsite due to
337
+ # imprecision of the concrete execution. So we save those simulated
338
+ # exits here to increase our code coverage. Of course the real retn from
339
+ # that call always precedes those "fake" retns.
340
+ self._pending_jobs = defaultdict(list) # Dict[BlockID, List[PendingJob]]
341
+
342
+ # Counting how many times a basic block is traced into
343
+ self._traced_addrs = defaultdict(lambda: defaultdict(int))
344
+
345
+ # A dict that collects essential parameters to properly reconstruct initial state for a block
346
+ self._block_artifacts = {}
347
+ self._analyzed_addrs = set()
348
+ self._non_returning_functions = set()
349
+
350
+ self._pending_edges = defaultdict(list)
351
+
352
+ if not no_construct:
353
+ self._initialize_cfg()
354
+ self._analyze()
355
+
356
+ #
357
+ # Public methods
358
+ #
359
+
360
+ def copy(self) -> CFGEmulated:
361
+ """
362
+ Make a copy of the CFG.
363
+
364
+ :return: A copy of the CFG instance.
365
+ """
366
+ new_cfg = CFGEmulated.__new__(CFGEmulated)
367
+ super().make_copy(new_cfg)
368
+
369
+ new_cfg._indirect_jump_target_limit = self._indirect_jump_target_limit
370
+ new_cfg.named_errors = defaultdict(list, self.named_errors)
371
+ new_cfg.errors = list(self.errors)
372
+ new_cfg._fail_fast = self._fail_fast
373
+ new_cfg._max_steps = self._max_steps
374
+ new_cfg.project = self.project
375
+
376
+ # Intelligently (or stupidly... you tell me) fill it up
377
+ new_cfg._edge_map = self._edge_map.copy()
378
+ new_cfg._loop_back_edges = self._loop_back_edges[::]
379
+ new_cfg._executable_address_ranges = self._executable_address_ranges[::]
380
+ new_cfg._unresolvable_runs = self._unresolvable_runs.copy()
381
+ new_cfg._overlapped_loop_headers = self._overlapped_loop_headers[::]
382
+ new_cfg._thumb_addrs = self._thumb_addrs.copy()
383
+ new_cfg._keep_state = self._keep_state
384
+
385
+ return new_cfg
386
+
387
+ def resume(self, starts=None, max_steps=None):
388
+ """
389
+ Resume a paused or terminated control flow graph recovery.
390
+
391
+ :param iterable starts: A collection of new starts to resume from. If `starts` is None, we will resume CFG
392
+ recovery from where it was paused before.
393
+ :param int max_steps: The maximum number of blocks on the longest path starting from each start before pausing
394
+ the recovery.
395
+ :return: None
396
+ """
397
+
398
+ self._should_abort = False
399
+
400
+ self._starts = starts
401
+ self._max_steps = max_steps
402
+
403
+ if self._starts is None:
404
+ self._starts = []
405
+
406
+ if self._starts:
407
+ self._sanitize_starts()
408
+
409
+ self._analyze()
410
+
411
+ def remove_cycles(self):
412
+ """
413
+ Forces graph to become acyclic, removes all loop back edges and edges between overlapped loop headers and their
414
+ successors.
415
+ """
416
+ # loop detection
417
+ # only detect loops after potential graph normalization
418
+ if not self._loop_back_edges:
419
+ l.debug("Detecting loops...")
420
+ self._detect_loops()
421
+
422
+ l.debug("Removing cycles...")
423
+ l.debug("There are %d loop back edges.", len(self._loop_back_edges))
424
+ l.debug("And there are %d overlapping loop headers.", len(self._overlapped_loop_headers))
425
+ # First break all detected loops
426
+ for b1, b2 in self._loop_back_edges:
427
+ if self._graph.has_edge(b1, b2):
428
+ l.debug("Removing loop back edge %s -> %s", b1, b2)
429
+ self._graph.remove_edge(b1, b2)
430
+ # Then remove all outedges from overlapped loop headers
431
+ for b in self._overlapped_loop_headers:
432
+ successors = self._graph.successors(b)
433
+ for succ in successors:
434
+ self._graph.remove_edge(b, succ)
435
+ l.debug("Removing partial loop header edge %s -> %s", b, succ)
436
+
437
+ def downsize(self):
438
+ """
439
+ Remove saved states from all CFGNodes to reduce memory usage.
440
+
441
+ :return: None
442
+ """
443
+
444
+ for cfg_node in self._nodes.values():
445
+ cfg_node.downsize()
446
+
447
+ def unroll_loops(self, max_loop_unrolling_times):
448
+ """
449
+ Unroll loops for each function. The resulting CFG may still contain loops due to recursion, function calls, etc.
450
+
451
+ :param int max_loop_unrolling_times: The maximum iterations of unrolling.
452
+ :return: None
453
+ """
454
+
455
+ if not isinstance(max_loop_unrolling_times, int) or max_loop_unrolling_times < 0:
456
+ raise AngrCFGError(
457
+ "Max loop unrolling times must be set to an integer greater than or equal to 0 if "
458
+ + "loop unrolling is enabled."
459
+ )
460
+
461
+ def _unroll(graph: networkx.DiGraph, loop: Loop):
462
+ """
463
+ The loop callback method where loops are unrolled.
464
+
465
+ :param graph: The control flow graph.
466
+ :param loop: The loop instance.
467
+ :return: None
468
+ """
469
+
470
+ for back_edge in loop.continue_edges:
471
+ loop_body_addrs = {n.addr for n in loop.body_nodes}
472
+ src_blocknode: BlockNode = back_edge[0]
473
+ dst_blocknode: BlockNode = back_edge[1]
474
+
475
+ for src in self.model.get_all_nodes(src_blocknode.addr):
476
+ for dst in graph.successors(src):
477
+ if dst.addr != dst_blocknode.addr:
478
+ continue
479
+
480
+ # Duplicate the dst node
481
+ new_dst = dst.copy()
482
+ new_dst.looping_times = dst.looping_times + 1
483
+ if (
484
+ new_dst not in graph
485
+ and
486
+ # If the new_dst is already in the graph, we don't want to keep unrolling
487
+ # the this loop anymore since it may *create* a new loop. Of course we
488
+ # will lose some edges in this way, but in general it is acceptable.
489
+ new_dst.looping_times <= max_loop_unrolling_times
490
+ ):
491
+ # Log all successors of the dst node
492
+ dst_successors = graph.successors(dst)
493
+ # Add new_dst to the graph
494
+ edge_data = graph.get_edge_data(src, dst)
495
+ graph.add_edge(src, new_dst, **edge_data)
496
+ for ds in dst_successors:
497
+ if ds.looping_times == 0 and ds.addr not in loop_body_addrs:
498
+ edge_data = graph.get_edge_data(dst, ds)
499
+ graph.add_edge(new_dst, ds, **edge_data)
500
+
501
+ graph.remove_edge(src, dst)
502
+
503
+ self._detect_loops(loop_callback=_unroll)
504
+
505
+ def force_unroll_loops(self, max_loop_unrolling_times):
506
+ """
507
+ Unroll loops globally. The resulting CFG does not contain any loop, but this method is slow on large graphs.
508
+
509
+ :param int max_loop_unrolling_times: The maximum iterations of unrolling.
510
+ :return: None
511
+ """
512
+
513
+ assert self._starts is not None
514
+
515
+ if not isinstance(max_loop_unrolling_times, int) or max_loop_unrolling_times < 0:
516
+ raise AngrCFGError(
517
+ "Max loop unrolling times must be set to an integer greater than or equal to 0 if "
518
+ + "loop unrolling is enabled."
519
+ )
520
+
521
+ # Traverse the CFG and try to find the beginning of loops
522
+ loop_backedges = []
523
+
524
+ start = self._starts[0]
525
+ if isinstance(start, tuple):
526
+ start, _ = start # pylint: disable=unpacking-non-sequence
527
+ start_node = self.model.get_any_node(start)
528
+ if start_node is None:
529
+ raise AngrCFGError("Cannot find start node when trying to unroll loops. The CFG might be empty.")
530
+
531
+ graph_copy = networkx.DiGraph(self.graph)
532
+
533
+ while True:
534
+ cycles_iter = networkx.simple_cycles(graph_copy)
535
+ try:
536
+ cycle = next(cycles_iter)
537
+ except StopIteration:
538
+ break
539
+
540
+ loop_backedge = (None, None)
541
+
542
+ for n in networkx.dfs_preorder_nodes(graph_copy, source=start_node):
543
+ if n in cycle:
544
+ idx = cycle.index(n)
545
+ loop_backedge = (cycle[-1], cycle[idx]) if idx == 0 else (cycle[idx - 1], cycle[idx])
546
+ break
547
+
548
+ if loop_backedge not in loop_backedges:
549
+ loop_backedges.append(loop_backedge)
550
+
551
+ # Create a common end node for all nodes whose out_degree is 0
552
+ end_nodes = [n for n in graph_copy.nodes() if graph_copy.out_degree(n) == 0]
553
+ new_end_node = "end_node"
554
+
555
+ if not end_nodes:
556
+ # We gotta randomly break a loop
557
+ cycles = sorted(networkx.simple_cycles(graph_copy), key=len)
558
+ first_cycle = cycles[0]
559
+ if len(first_cycle) == 1:
560
+ graph_copy.remove_edge(first_cycle[0], first_cycle[0])
561
+ else:
562
+ graph_copy.remove_edge(first_cycle[0], first_cycle[1])
563
+ end_nodes = [n for n in graph_copy.nodes() if graph_copy.out_degree(n) == 0]
564
+
565
+ for en in end_nodes:
566
+ graph_copy.add_edge(en, new_end_node)
567
+
568
+ # postdoms = self.immediate_postdominators(new_end_node, target_graph=graph_copy)
569
+ # reverse_postdoms = defaultdict(list)
570
+ # for k, v in postdoms.items():
571
+ # reverse_postdoms[v].append(k)
572
+
573
+ # Find all loop bodies
574
+ # for src, dst in loop_backedges:
575
+ # nodes_in_loop = { src, dst }
576
+
577
+ # while True:
578
+ # new_nodes = set()
579
+
580
+ # for n in nodes_in_loop:
581
+ # if n in reverse_postdoms:
582
+ # for node in reverse_postdoms[n]:
583
+ # if node not in nodes_in_loop:
584
+ # new_nodes.add(node)
585
+
586
+ # if not new_nodes:
587
+ # break
588
+
589
+ # nodes_in_loop |= new_nodes
590
+
591
+ # Unroll the loop body
592
+ # TODO: Finish the implementation
593
+
594
+ graph_copy.remove_node(new_end_node)
595
+ src, dst = loop_backedge
596
+ assert src is not None and dst is not None
597
+ if graph_copy.has_edge(src, dst): # It might have been removed before
598
+ # Duplicate the dst node
599
+ new_dst = dst.copy()
600
+ new_dst.looping_times = dst.looping_times + 1
601
+ if (
602
+ new_dst not in graph_copy
603
+ and
604
+ # If the new_dst is already in the graph, we don't want to keep unrolling
605
+ # the this loop anymore since it may *create* a new loop. Of course we
606
+ # will lose some edges in this way, but in general it is acceptable.
607
+ new_dst.looping_times <= max_loop_unrolling_times
608
+ ):
609
+ # Log all successors of the dst node
610
+ dst_successors = list(graph_copy.successors(dst))
611
+ # Add new_dst to the graph
612
+ edge_data = graph_copy.get_edge_data(src, dst)
613
+ graph_copy.add_edge(src, new_dst, **edge_data)
614
+ for ds in dst_successors:
615
+ if ds.looping_times == 0 and ds not in cycle:
616
+ edge_data = graph_copy.get_edge_data(dst, ds)
617
+ graph_copy.add_edge(new_dst, ds, **edge_data)
618
+ # Remove the original edge
619
+ graph_copy.remove_edge(src, dst)
620
+
621
+ # Update loop backedges
622
+ self._loop_back_edges = loop_backedges
623
+
624
+ self.model.graph = graph_copy
625
+
626
+ def immediate_dominators(self, start, target_graph=None):
627
+ """
628
+ Get all immediate dominators of sub graph from given node upwards.
629
+
630
+ :param str start: id of the node to navigate forwards from.
631
+ :param networkx.classes.digraph.DiGraph target_graph: graph to analyse, default is self.graph.
632
+
633
+ :return: each node of graph as index values, with element as respective node's immediate dominator.
634
+ :rtype: dict
635
+ """
636
+ return self._immediate_dominators(start, target_graph=target_graph, reverse_graph=False)
637
+
638
+ def immediate_postdominators(self, end, target_graph=None):
639
+ """
640
+ Get all immediate postdominators of sub graph from given node upwards.
641
+
642
+ :param str start: id of the node to navigate forwards from.
643
+ :param networkx.classes.digraph.DiGraph target_graph: graph to analyse, default is self.graph.
644
+
645
+ :return: each node of graph as index values, with element as respective node's immediate dominator.
646
+ :rtype: dict
647
+ """
648
+ return self._immediate_dominators(end, target_graph=target_graph, reverse_graph=True)
649
+
650
+ def remove_fakerets(self):
651
+ """
652
+ Get rid of fake returns (i.e., Ijk_FakeRet edges) from this CFG
653
+
654
+ :return: None
655
+ """
656
+ fakeret_edges = [
657
+ (src, dst) for src, dst, data in self.graph.edges(data=True) if data["jumpkind"] == "Ijk_FakeRet"
658
+ ]
659
+ self.graph.remove_edges_from(fakeret_edges)
660
+
661
+ def get_topological_order(self, cfg_node):
662
+ """
663
+ Get the topological order of a CFG Node.
664
+
665
+ :param cfg_node: A CFGNode instance.
666
+ :return: An integer representing its order, or None if the CFGNode does not exist in the graph.
667
+ """
668
+
669
+ if not self._quasi_topological_order:
670
+ self._quasi_topological_sort()
671
+
672
+ return self._quasi_topological_order.get(cfg_node, None)
673
+
674
+ def get_subgraph(self, starting_node, block_addresses):
675
+ """
676
+ Get a sub-graph out of a bunch of basic block addresses.
677
+
678
+ :param CFGNode starting_node: The beginning of the subgraph
679
+ :param iterable block_addresses: A collection of block addresses that should be included in the subgraph if
680
+ there is a path between `starting_node` and a CFGNode with the specified
681
+ address, and all nodes on the path should also be included in the subgraph.
682
+ :return: A new CFG that only contain the specific subgraph.
683
+ :rtype: CFGEmulated
684
+ """
685
+
686
+ graph = networkx.DiGraph()
687
+
688
+ if starting_node not in self.graph:
689
+ raise AngrCFGError(
690
+ f'get_subgraph(): the specified "starting_node" {starting_node} does not exist in the current CFG.'
691
+ )
692
+
693
+ addr_set = set(block_addresses)
694
+
695
+ graph.add_node(starting_node)
696
+ queue = [starting_node]
697
+
698
+ while queue:
699
+ node = queue.pop()
700
+ for _, dst, data in self.graph.out_edges([node], data=True):
701
+ if dst not in graph and dst.addr in addr_set:
702
+ graph.add_edge(node, dst, **data)
703
+ queue.append(dst)
704
+
705
+ cfg = self.copy()
706
+ cfg._graph = graph
707
+ cfg._starts = (starting_node.addr,)
708
+
709
+ return cfg
710
+
711
+ def get_function_subgraph(self, start, max_call_depth=None):
712
+ """
713
+ Get a sub-graph of a certain function.
714
+
715
+ :param start: The function start. Currently it should be an integer.
716
+ :param max_call_depth: Call depth limit. None indicates no limit.
717
+ :return: A CFG instance which is a sub-graph of self.graph
718
+ """
719
+
720
+ # FIXME: syscalls are not supported
721
+ # FIXME: start should also take a CFGNode instance
722
+
723
+ start_node = self.model.get_any_node(start)
724
+ assert start_node is not None
725
+
726
+ node_wrapper = (start_node, 0)
727
+ stack: list[tuple[CFGNode, int]] = [node_wrapper]
728
+ traversed_nodes = {start_node}
729
+ subgraph_nodes = {start_node}
730
+
731
+ while stack:
732
+ nw = stack.pop()
733
+ n, call_depth = nw[0], nw[1]
734
+
735
+ # Get successors
736
+ edges = self.graph.out_edges(n, data=True)
737
+
738
+ for _, dst, data in edges:
739
+ assert dst is not None
740
+ if dst not in traversed_nodes:
741
+ # We see a new node!
742
+ traversed_nodes.add(dst)
743
+
744
+ if data["jumpkind"] == "Ijk_Call":
745
+ if max_call_depth is None or (max_call_depth is not None and call_depth < max_call_depth):
746
+ subgraph_nodes.add(dst)
747
+ new_nw = (dst, call_depth + 1)
748
+ stack.append(new_nw)
749
+ elif data["jumpkind"] == "Ijk_Ret":
750
+ if call_depth > 0:
751
+ subgraph_nodes.add(dst)
752
+ new_nw = (dst, call_depth - 1)
753
+ stack.append(new_nw)
754
+ else:
755
+ subgraph_nodes.add(dst)
756
+ new_nw = (dst, call_depth)
757
+ stack.append(new_nw)
758
+
759
+ # subgraph = networkx.subgraph(self.graph, subgraph_nodes)
760
+ subgraph = self.graph.subgraph(subgraph_nodes).copy()
761
+
762
+ # Make it a CFG instance
763
+ subcfg = self.copy()
764
+ subcfg._graph = subgraph
765
+ subcfg._starts = (start,)
766
+
767
+ return subcfg
768
+
769
+ @property
770
+ def context_sensitivity_level(self):
771
+ return self._context_sensitivity_level
772
+
773
+ #
774
+ # Serialization
775
+ #
776
+
777
+ def __setstate__(self, s):
778
+ self.project: angr.Project = s["project"]
779
+ self.indirect_jumps: dict[int, IndirectJump] = s["indirect_jumps"]
780
+ self._loop_back_edges = s["_loop_back_edges"]
781
+ self._thumb_addrs = s["_thumb_addrs"]
782
+ self._unresolvable_runs = s["_unresolvable_runs"]
783
+ self._executable_address_ranges = s["_executable_address_ranges"]
784
+ self._iropt_level = s["_iropt_level"]
785
+ self._model = s["_model"]
786
+
787
+ def __getstate__(self):
788
+ return {
789
+ "project": self.project,
790
+ "indirect_jumps": self.indirect_jumps,
791
+ "_loop_back_edges": self._loop_back_edges,
792
+ "_nodes_by_addr": self._nodes_by_addr,
793
+ "_thumb_addrs": self._thumb_addrs,
794
+ "_unresolvable_runs": self._unresolvable_runs,
795
+ "_executable_address_ranges": self._executable_address_ranges,
796
+ "_iropt_level": self._iropt_level,
797
+ "_model": self._model,
798
+ }
799
+
800
+ #
801
+ # Properties
802
+ #
803
+
804
+ @property
805
+ def graph(self):
806
+ return self._model.graph
807
+
808
+ @property
809
+ def unresolvables(self):
810
+ """
811
+ Get those SimRuns that have non-resolvable exits.
812
+
813
+ :return: A set of SimRuns
814
+ :rtype: set
815
+ """
816
+ return self._unresolvable_runs
817
+
818
+ @property
819
+ def deadends(self):
820
+ """
821
+ Get all CFGNodes that has an out-degree of 0
822
+
823
+ :return: A list of CFGNode instances
824
+ :rtype: list
825
+ """
826
+ if self.graph is None:
827
+ raise AngrCFGError("CFG hasn't been generated yet.")
828
+
829
+ return [i for i in self.graph if self.graph.out_degree(i) == 0]
830
+
831
+ #
832
+ # Private methods
833
+ #
834
+
835
+ # Initialization related methods
836
+
837
+ def _sanitize_parameters(self):
838
+ """
839
+ Perform a sanity check on parameters passed in to CFG.__init__().
840
+ An AngrCFGError is raised if any parameter fails the sanity check.
841
+
842
+ :return: None
843
+ """
844
+
845
+ # Check additional_edges
846
+ if isinstance(self._additional_edges, (list, set, tuple)):
847
+ new_dict = defaultdict(list)
848
+ for s, d in self._additional_edges:
849
+ new_dict[s].append(d)
850
+ self._additional_edges = new_dict
851
+
852
+ elif isinstance(self._additional_edges, dict):
853
+ pass
854
+
855
+ else:
856
+ raise AngrCFGError("Additional edges can only be a list, set, tuple, or a dict.")
857
+
858
+ # Check _advanced_backward_slicing
859
+ if self._advanced_backward_slicing and self._enable_symbolic_back_traversal:
860
+ raise AngrCFGError("Advanced backward slicing and symbolic back traversal cannot both be enabled.")
861
+
862
+ if self._advanced_backward_slicing and not self._keep_state:
863
+ raise AngrCFGError("Keep state must be enabled if advanced backward slicing is enabled.")
864
+
865
+ # Sanitize avoid_runs
866
+ self._avoid_runs = [] if self._avoid_runs is None else self._avoid_runs
867
+ if not isinstance(self._avoid_runs, (list, set)):
868
+ raise AngrCFGError('"avoid_runs" must either be None, or a list or a set.')
869
+
870
+ self._sanitize_starts()
871
+
872
+ def _sanitize_starts(self):
873
+ # Sanitize starts
874
+ # Convert self._starts to a list of SimState instances or tuples of (ip, jumpkind)
875
+ if self._starts is None:
876
+ self._starts = ((self.project.entry, None),)
877
+
878
+ else:
879
+ new_starts = []
880
+ for item in self._starts:
881
+ if isinstance(item, tuple):
882
+ if len(item) != 2:
883
+ raise AngrCFGError(f'Unsupported item in "starts": {item!s}')
884
+
885
+ new_starts.append(item)
886
+ elif isinstance(item, int):
887
+ new_starts.append((item, None))
888
+
889
+ elif isinstance(item, SimState):
890
+ new_starts.append(item)
891
+
892
+ else:
893
+ raise AngrCFGError(f'Unsupported item type in "starts": {type(item)}')
894
+
895
+ self._starts = new_starts
896
+
897
+ if not self._starts:
898
+ raise AngrCFGError("At least one start must be provided")
899
+
900
+ # CFG construction
901
+ # The main loop and sub-methods
902
+
903
+ def _job_key(self, job):
904
+ """
905
+ Get the key for a specific CFG job. The key is a context-sensitive block ID.
906
+
907
+ :param CFGJob job: The CFGJob instance.
908
+ :return: The block ID of the specific CFG job.
909
+ :rtype: BlockID
910
+ """
911
+
912
+ return job.block_id
913
+
914
+ def _job_sorting_key(self, job):
915
+ """
916
+ Get the sorting key of a CFGJob instance.
917
+
918
+ :param CFGJob job: the CFGJob object.
919
+ :return: An integer that determines the order of this job in the queue.
920
+ :rtype: int
921
+ """
922
+
923
+ if self._base_graph is None:
924
+ # we don't do sorting if there is no base_graph
925
+ return 0
926
+
927
+ MAX_JOBS = 1000000
928
+
929
+ if job.addr not in self._node_addr_visiting_order:
930
+ return MAX_JOBS
931
+
932
+ return self._node_addr_visiting_order.index(job.addr)
933
+
934
+ def _pre_analysis(self):
935
+ """
936
+ Initialization work. Executed prior to the analysis.
937
+
938
+ :return: None
939
+ """
940
+
941
+ # Fill up self._starts
942
+ for item in self._starts:
943
+ callstack = None
944
+ if isinstance(item, tuple):
945
+ # (addr, jumpkind)
946
+ ip = item[0]
947
+ state = self._create_initial_state(item[0], item[1])
948
+
949
+ elif isinstance(item, SimState):
950
+ # SimState
951
+ state = item.copy() # pylint: disable=no-member
952
+ ip = state.solver.eval_one(state.ip)
953
+ self._reset_state_mode(state, "fastpath")
954
+
955
+ else:
956
+ raise AngrCFGError(f"Unsupported CFG start type: {type(item)!s}.")
957
+
958
+ self._symbolic_function_initial_state[ip] = state
959
+ path_wrapper = CFGJob(ip, state, self._context_sensitivity_level, None, None, call_stack=callstack)
960
+ key = path_wrapper.block_id
961
+ if key not in self._start_keys:
962
+ self._start_keys.append(key)
963
+
964
+ self._insert_job(path_wrapper)
965
+ self._register_analysis_job(path_wrapper.func_addr, path_wrapper)
966
+
967
+ def _intra_analysis(self):
968
+ """
969
+ During the analysis. We process function hints here.
970
+
971
+ :return: None
972
+ """
973
+
974
+ if self._pending_function_hints:
975
+ self._process_hints(self._analyzed_addrs)
976
+
977
+ def _job_queue_empty(self):
978
+ """
979
+ A callback method called when the job queue is empty.
980
+
981
+ :return: None
982
+ """
983
+
984
+ self._iteratively_clean_pending_exits()
985
+
986
+ while self._pending_jobs:
987
+ # We don't have any exits remaining. Let's pop out a pending exit
988
+ pending_job = self._get_one_pending_job()
989
+ if pending_job is None:
990
+ continue
991
+
992
+ self._insert_job(pending_job)
993
+ self._register_analysis_job(pending_job.func_addr, pending_job)
994
+ break
995
+
996
+ def _create_initial_state(self, ip, jumpkind):
997
+ """
998
+ Obtain a SimState object for a specific address
999
+
1000
+ Fastpath means the CFG generation will work in an IDA-like way, in which it will not try to execute every
1001
+ single statement in the emulator, but will just do the decoding job. This is much faster than the old way.
1002
+
1003
+ :param int ip: The instruction pointer
1004
+ :param str jumpkind: The jumpkind upon executing the block
1005
+ :return: The newly-generated state
1006
+ :rtype: SimState
1007
+ """
1008
+
1009
+ jumpkind = "Ijk_Boring" if jumpkind is None else jumpkind
1010
+
1011
+ if self._initial_state is None:
1012
+ state = self.project.factory.blank_state(
1013
+ addr=ip,
1014
+ mode="fastpath",
1015
+ add_options=self._state_add_options,
1016
+ remove_options=self._state_remove_options,
1017
+ )
1018
+ self._initial_state = state
1019
+ else:
1020
+ # FIXME: self._initial_state is deprecated. This branch will be removed soon
1021
+ state = self._initial_state.copy()
1022
+ state.history.jumpkind = jumpkind
1023
+ self._reset_state_mode(state, "fastpath")
1024
+ state._ip = claripy.BVV(ip, self.project.arch.bits)
1025
+
1026
+ if jumpkind is not None:
1027
+ state.history.jumpkind = jumpkind
1028
+
1029
+ # THIS IS A HACK FOR MIPS
1030
+ if ip is not None and self.project.arch.name in ("MIPS32", "MIPS64"):
1031
+ # We assume this is a function start
1032
+ state.regs.t9 = ip
1033
+ # TODO there was at one point special logic for the ppc64 table of contents but it seems to have bitrotted
1034
+
1035
+ return state
1036
+
1037
+ def _get_one_pending_job(self):
1038
+ """
1039
+ Retrieve a pending job.
1040
+
1041
+ :return: A CFGJob instance or None
1042
+ """
1043
+
1044
+ pending_job_key = next(iter(self._pending_jobs.keys()))
1045
+ pending_job = self._pending_jobs[pending_job_key].pop()
1046
+ if len(self._pending_jobs[pending_job_key]) == 0:
1047
+ del self._pending_jobs[pending_job_key]
1048
+
1049
+ pending_job_state = pending_job.state
1050
+ pending_job_call_stack = pending_job.call_stack
1051
+ pending_job_src_block_id = pending_job.src_block_id
1052
+ pending_job_src_exit_stmt_idx = pending_job.src_exit_stmt_idx
1053
+
1054
+ self._deregister_analysis_job(pending_job.caller_func_addr, pending_job)
1055
+
1056
+ # Let's check whether this address has been traced before.
1057
+ if pending_job_key in self._nodes:
1058
+ node = self._nodes[pending_job_key]
1059
+ if node in self.graph:
1060
+ pending_exit_addr = self._block_id_addr(pending_job_key)
1061
+ # That block has been traced before. Let's forget about it
1062
+ l.debug("Target 0x%08x has been traced before. Trying the next one...", pending_exit_addr)
1063
+
1064
+ # However, we should still create the FakeRet edge
1065
+ self._graph_add_edge(
1066
+ pending_job_src_block_id,
1067
+ pending_job_key,
1068
+ jumpkind="Ijk_FakeRet",
1069
+ stmt_idx=pending_job_src_exit_stmt_idx,
1070
+ ins_addr=pending_job.src_exit_ins_addr,
1071
+ )
1072
+
1073
+ return None
1074
+
1075
+ pending_job_state.history.jumpkind = "Ijk_FakeRet"
1076
+
1077
+ job = CFGJob(
1078
+ pending_job_state.addr,
1079
+ pending_job_state,
1080
+ self._context_sensitivity_level,
1081
+ src_block_id=pending_job_src_block_id,
1082
+ src_exit_stmt_idx=pending_job_src_exit_stmt_idx,
1083
+ src_ins_addr=pending_job.src_exit_ins_addr,
1084
+ call_stack=pending_job_call_stack,
1085
+ )
1086
+ l.debug("Tracing a missing return exit %s", self._block_id_repr(pending_job_key))
1087
+
1088
+ return job
1089
+
1090
+ def _process_hints(self, analyzed_addrs):
1091
+ """
1092
+ Process function hints in the binary.
1093
+
1094
+ :return: None
1095
+ """
1096
+
1097
+ # Function hints!
1098
+ # Now let's see how many new functions we can get here...
1099
+ while self._pending_function_hints:
1100
+ f = self._pending_function_hints.pop()
1101
+ if f not in analyzed_addrs:
1102
+ new_state = self.project.factory.entry_state(mode="fastpath")
1103
+ new_state.ip = claripy.BVV(f, self.project.arch.bits)
1104
+
1105
+ # TOOD: Specially for MIPS
1106
+ if new_state.arch.name in ("MIPS32", "MIPS64"):
1107
+ # Properly set t9
1108
+ new_state.registers.store("t9", f)
1109
+
1110
+ new_path_wrapper = CFGJob(f, new_state, self._context_sensitivity_level)
1111
+ self._insert_job(new_path_wrapper)
1112
+ self._register_analysis_job(f, new_path_wrapper)
1113
+ l.debug("Picking a function 0x%x from pending function hints.", f)
1114
+ self.kb.functions.function(new_path_wrapper.func_addr, create=True)
1115
+ break
1116
+
1117
+ def _post_analysis(self):
1118
+ """
1119
+ Post-CFG-construction.
1120
+
1121
+ :return: None
1122
+ """
1123
+
1124
+ self._make_completed_functions()
1125
+ new_changes = self._iteratively_analyze_function_features()
1126
+ functions_do_not_return = new_changes["functions_do_not_return"]
1127
+ self._update_function_callsites(functions_do_not_return)
1128
+
1129
+ # Create all pending edges
1130
+ for _, edges in self._pending_edges.items():
1131
+ for src_node, dst_node, data in edges:
1132
+ self._graph_add_edge(src_node, dst_node, **data)
1133
+
1134
+ # Remove those edges that will never be taken!
1135
+ self._remove_non_return_edges()
1136
+
1137
+ CFGBase._post_analysis(self)
1138
+
1139
+ # Job handling
1140
+
1141
+ def _pre_job_handling(self, job): # pylint:disable=arguments-differ
1142
+ """
1143
+ Before processing a CFGJob.
1144
+ Right now each block is traced at most once. If it is traced more than once, we will mark it as "should_skip"
1145
+ before tracing it.
1146
+ An AngrForwardAnalysisSkipJob exception is raised in order to skip analyzing the job.
1147
+
1148
+ :param CFGJob job: The CFG job object.
1149
+ :param dict _locals: A bunch of local variables that will be kept around when handling this job and its
1150
+ corresponding successors.
1151
+ :return: None
1152
+ """
1153
+
1154
+ # Extract initial info the CFGJob
1155
+ job.call_stack_suffix = job.get_call_stack_suffix()
1156
+ job.current_function = self.kb.functions.function(
1157
+ job.func_addr, create=True, syscall=job.jumpkind.startswith("Ijk_Sys")
1158
+ )
1159
+ src_block_id = job.src_block_id
1160
+ src_exit_stmt_idx = job.src_exit_stmt_idx
1161
+ src_ins_addr = job.src_ins_addr
1162
+ addr = job.addr
1163
+
1164
+ # Log this address
1165
+ if l.level == logging.DEBUG:
1166
+ self._analyzed_addrs.add(addr)
1167
+
1168
+ if addr == job.func_addr:
1169
+ # Store the input state of this function
1170
+ self._function_input_states[job.func_addr] = job.state
1171
+
1172
+ # deregister this job
1173
+ self._deregister_analysis_job(job.func_addr, job)
1174
+
1175
+ # Generate a unique key for this job
1176
+ block_id = job.block_id
1177
+
1178
+ # Should we skip tracing this block?
1179
+ should_skip = False
1180
+ if self._traced_addrs[job.call_stack_suffix][addr] >= self._max_iterations or (
1181
+ self._is_call_jumpkind(job.jumpkind)
1182
+ and self._call_depth is not None
1183
+ and len(job.call_stack) > self._call_depth
1184
+ and (self._call_tracing_filter is None or self._call_tracing_filter(job.state, job.jumpkind))
1185
+ ):
1186
+ should_skip = True
1187
+
1188
+ # SimInspect breakpoints support
1189
+ job.state._inspect("cfg_handle_job", BP_BEFORE)
1190
+
1191
+ # Get a SimSuccessors out of current job
1192
+ sim_successors, exception_info, _ = self._get_simsuccessors(addr, job, current_function_addr=job.func_addr)
1193
+
1194
+ # determine the depth of this basic block
1195
+ if self._max_steps is None:
1196
+ # it's unnecessary to track depth when we are not limiting max_steps
1197
+ depth = None
1198
+ else:
1199
+ if src_block_id is None:
1200
+ # oh this is the very first basic block on this path
1201
+ depth = 0
1202
+ else:
1203
+ src_cfgnode = self._nodes[src_block_id]
1204
+ depth = src_cfgnode.depth + 1
1205
+ # the depth will not be updated later on even if this block has a greater depth on another path.
1206
+ # consequently, the `max_steps` limit is not very precise - I didn't see a need to make it precise
1207
+ # though.
1208
+
1209
+ if block_id not in self._nodes:
1210
+ # Create the CFGNode object
1211
+ cfg_node = self._create_cfgnode(
1212
+ sim_successors, job.call_stack, job.func_addr, block_id=block_id, depth=depth
1213
+ )
1214
+
1215
+ self._model.add_node(block_id, cfg_node)
1216
+
1217
+ else:
1218
+ # each block_id should only correspond to one CFGNode
1219
+ # use the existing CFGNode object
1220
+ # note that since we reuse existing CFGNodes, we may miss the following cases:
1221
+ #
1222
+ # mov eax, label_0 mov ebx, label_1
1223
+ # jmp xxx jmp xxx
1224
+ # | |
1225
+ # | |
1226
+ # *----------------------*
1227
+ # |
1228
+ # call eax
1229
+ #
1230
+ # Since the basic block "call eax" will only be traced once, either label_0 or label_1 will be missed in
1231
+ # this case. Indirect jump resolution might be able to get it, but that's another story. Ideally,
1232
+ # "call eax" should be traced twice with *different* sim_successors keys, which requires block ID being flow
1233
+ # sensitive, but it is way too expensive.
1234
+
1235
+ cfg_node = self._nodes[block_id]
1236
+
1237
+ # Increment tracing count for this block
1238
+ self._traced_addrs[job.call_stack_suffix][addr] += 1
1239
+
1240
+ if self._keep_state:
1241
+ # TODO: if we are reusing an existing CFGNode, we will be overwriting the original input state here. we
1242
+ # TODO: should save them all, which, unfortunately, requires some redesigning :-(
1243
+ cfg_node.input_state = sim_successors.initial_state
1244
+
1245
+ # See if this job cancels another FakeRet
1246
+ # This should be done regardless of whether this job should be skipped or not, otherwise edges will go missing
1247
+ # in the CFG or function transition graphs.
1248
+ if job.jumpkind == "Ijk_FakeRet" or (job.jumpkind == "Ijk_Ret" and block_id in self._pending_jobs):
1249
+ # The fake ret is confirmed (since we are returning from the function it calls). Create an edge for it
1250
+ # in the graph.
1251
+
1252
+ the_jobs = []
1253
+ if block_id in self._pending_jobs:
1254
+ the_jobs: PendingJob = self._pending_jobs.pop(block_id)
1255
+ for the_job in the_jobs:
1256
+ self._deregister_analysis_job(the_job.caller_func_addr, the_job)
1257
+ else:
1258
+ the_jobs = [job]
1259
+
1260
+ for the_job in the_jobs:
1261
+ self._graph_add_edge(
1262
+ the_job.src_block_id,
1263
+ block_id,
1264
+ jumpkind="Ijk_FakeRet",
1265
+ stmt_idx=the_job.src_exit_stmt_idx,
1266
+ ins_addr=src_ins_addr,
1267
+ )
1268
+ self._update_function_transition_graph(
1269
+ the_job.src_block_id,
1270
+ block_id,
1271
+ jumpkind="Ijk_FakeRet",
1272
+ ins_addr=src_ins_addr,
1273
+ stmt_idx=the_job.src_exit_stmt_idx,
1274
+ confirmed=True,
1275
+ )
1276
+
1277
+ if sim_successors is None or should_skip:
1278
+ # We cannot retrieve the block, or we should skip the analysis of this node
1279
+ # But we create the edge anyway. If the sim_successors does not exist, it will be an edge from the previous
1280
+ # node to a PathTerminator
1281
+ self._graph_add_edge(
1282
+ src_block_id, block_id, jumpkind=job.jumpkind, stmt_idx=src_exit_stmt_idx, ins_addr=src_ins_addr
1283
+ )
1284
+ self._update_function_transition_graph(
1285
+ src_block_id, block_id, jumpkind=job.jumpkind, ins_addr=src_ins_addr, stmt_idx=src_exit_stmt_idx
1286
+ )
1287
+
1288
+ # We are good. Raise the exception and leave
1289
+ raise AngrSkipJobNotice
1290
+
1291
+ self._update_thumb_addrs(sim_successors, job.state)
1292
+
1293
+ # We store the function hints first. Function hints will be checked at the end of the analysis to avoid
1294
+ # any duplication with existing jumping targets
1295
+ if self._enable_function_hints and sim_successors.sort == "IRSB" and sim_successors.all_successors:
1296
+ function_hints = self._search_for_function_hints(sim_successors.all_successors[0])
1297
+ for f in function_hints:
1298
+ self._pending_function_hints.add(f)
1299
+
1300
+ self._graph_add_edge(
1301
+ src_block_id, block_id, jumpkind=job.jumpkind, stmt_idx=src_exit_stmt_idx, ins_addr=src_ins_addr
1302
+ )
1303
+ self._update_function_transition_graph(
1304
+ src_block_id, block_id, jumpkind=job.jumpkind, ins_addr=src_ins_addr, stmt_idx=src_exit_stmt_idx
1305
+ )
1306
+
1307
+ if block_id in self._pending_edges:
1308
+ # there are some edges waiting to be created. do it here.
1309
+ for src_key, dst_key, data in self._pending_edges[block_id]:
1310
+ self._graph_add_edge(src_key, dst_key, **data)
1311
+ del self._pending_edges[block_id]
1312
+
1313
+ block_info = {
1314
+ reg: sim_successors.initial_state.registers.load(reg) for reg in self.project.arch.persistent_regs
1315
+ }
1316
+ self._block_artifacts[addr] = block_info
1317
+
1318
+ job.cfg_node = cfg_node
1319
+ job.sim_successors = sim_successors
1320
+ job.exception_info = exception_info
1321
+
1322
+ # For debugging purposes!
1323
+ job.successor_status = {}
1324
+
1325
+ def _get_successors(self, job):
1326
+ """
1327
+ Get a collection of successors out of the current job.
1328
+
1329
+ :param CFGJob job: The CFGJob instance.
1330
+ :return: A collection of successors.
1331
+ :rtype: list
1332
+ """
1333
+
1334
+ addr = job.addr
1335
+ sim_successors = job.sim_successors
1336
+ cfg_node = job.cfg_node
1337
+ input_state = job.state
1338
+ func_addr = job.func_addr
1339
+
1340
+ # check step limit
1341
+ if self._max_steps is not None:
1342
+ depth = cfg_node.depth
1343
+ if depth >= self._max_steps:
1344
+ return []
1345
+
1346
+ successors = []
1347
+ is_indirect_jump = sim_successors.sort == "IRSB" and self._is_indirect_jump(cfg_node, sim_successors)
1348
+ indirect_jump_resolved_by_resolvers = False
1349
+
1350
+ if is_indirect_jump and self._resolve_indirect_jumps:
1351
+ # Try to resolve indirect jumps
1352
+ irsb = input_state.block(cross_insn_opt=False).vex
1353
+
1354
+ resolved, resolved_targets, ij = self._indirect_jump_encountered(
1355
+ addr, cfg_node, irsb, func_addr, stmt_idx=DEFAULT_STATEMENT
1356
+ )
1357
+ if resolved:
1358
+ successors = self._convert_indirect_jump_targets_to_states(job, resolved_targets)
1359
+ if ij:
1360
+ self._indirect_jump_resolved(ij, ij.addr, None, resolved_targets)
1361
+ else:
1362
+ # Try to resolve this indirect jump using heavier approaches
1363
+ resolved_targets = self._process_one_indirect_jump(ij, func_graph_complete=False)
1364
+ successors = self._convert_indirect_jump_targets_to_states(job, resolved_targets)
1365
+
1366
+ if successors:
1367
+ indirect_jump_resolved_by_resolvers = True
1368
+ else:
1369
+ # It's unresolved. Add it to the wait list (but apparently we don't have any better way to resolve it
1370
+ # right now).
1371
+ self._indirect_jumps_to_resolve.add(ij)
1372
+
1373
+ if not successors:
1374
+ # Get all successors of this block
1375
+ successors = (
1376
+ (sim_successors.flat_successors + sim_successors.unsat_successors)
1377
+ if addr not in self._avoid_runs
1378
+ else []
1379
+ )
1380
+
1381
+ # Post-process successors
1382
+ successors, job.extra_info = self._post_process_successors(input_state, sim_successors, successors)
1383
+
1384
+ all_successors = successors + sim_successors.unconstrained_successors
1385
+
1386
+ # make sure FakeRets are at the last
1387
+ all_successors = [suc for suc in all_successors if suc.history.jumpkind != "Ijk_FakeRet"] + [
1388
+ suc for suc in all_successors if suc.history.jumpkind == "Ijk_FakeRet"
1389
+ ]
1390
+
1391
+ if self._keep_state:
1392
+ cfg_node.final_states = all_successors[::]
1393
+
1394
+ if is_indirect_jump and not indirect_jump_resolved_by_resolvers:
1395
+ # For indirect jumps, filter successors that do not make sense
1396
+ successors = self._filter_insane_successors(successors)
1397
+
1398
+ successors = self._try_resolving_indirect_jumps(
1399
+ sim_successors, cfg_node, func_addr, successors, job.exception_info, self._block_artifacts
1400
+ )
1401
+ # Remove all successors whose IP is symbolic
1402
+ successors = [s for s in successors if not s.ip.symbolic]
1403
+
1404
+ # Add additional edges supplied by the user
1405
+ successors = self._add_additional_edges(input_state, sim_successors, cfg_node, successors)
1406
+
1407
+ # if base graph is used, add successors implied from the graph
1408
+ if self._base_graph:
1409
+ basegraph_successor_addrs = set()
1410
+ for src_, dst_ in self._base_graph.edges():
1411
+ if src_.addr == addr:
1412
+ basegraph_successor_addrs.add(dst_.addr)
1413
+ successor_addrs = {s.solver.eval(s.ip) for s in successors}
1414
+ extra_successor_addrs = basegraph_successor_addrs - successor_addrs
1415
+
1416
+ if all_successors: # make sure we have a base state to use
1417
+ base_state = all_successors[0] # TODO: for calls, we want to use the fake_ret state
1418
+
1419
+ for s_addr in extra_successor_addrs:
1420
+ # an extra target
1421
+ successor_state = base_state.copy()
1422
+ successor_state.ip = s_addr
1423
+ successors.append(successor_state)
1424
+ else:
1425
+ if extra_successor_addrs:
1426
+ l.error("CFGEmulated terminates at %#x although base graph provided more exits.", addr)
1427
+
1428
+ if not successors:
1429
+ # There is no way out :-(
1430
+ # Log it first
1431
+ self._push_unresolvable_run(addr)
1432
+
1433
+ if sim_successors.sort == "SimProcedure" and isinstance(
1434
+ sim_successors.artifacts["procedure"], SIM_PROCEDURES["stubs"]["PathTerminator"]
1435
+ ):
1436
+ # If there is no valid exit in this branch and it's not
1437
+ # intentional (e.g. caused by a SimProcedure that does not
1438
+ # do_return) , we should make it return to its call-site. However,
1439
+ # we don't want to use its state anymore as it might be corrupted.
1440
+ # Just create an edge in the graph.
1441
+ return_target = job.call_stack.current_return_target
1442
+ if return_target is not None:
1443
+ new_call_stack = job.call_stack_copy()
1444
+ return_target_key = self._generate_block_id(
1445
+ new_call_stack.stack_suffix(self.context_sensitivity_level), return_target, False
1446
+ ) # You can never return to a syscall
1447
+
1448
+ if not cfg_node.instruction_addrs:
1449
+ ret_ins_addr = None
1450
+ else:
1451
+ if self.project.arch.branch_delay_slot:
1452
+ if len(cfg_node.instruction_addrs) > 1:
1453
+ ret_ins_addr = cfg_node.instruction_addrs[-2]
1454
+ else:
1455
+ l.error("At %s: expecting more than one instruction. Only got one.", cfg_node)
1456
+ ret_ins_addr = None
1457
+ else:
1458
+ ret_ins_addr = cfg_node.instruction_addrs[-1]
1459
+
1460
+ # Things might be a bit difficult here. _graph_add_edge() requires both nodes to exist, but here
1461
+ # the return target node may not exist yet. If that's the case, we will put it into a "delayed edge
1462
+ # list", and add this edge later when the return target CFGNode is created.
1463
+ if return_target_key in self._nodes:
1464
+ self._graph_add_edge(
1465
+ job.block_id,
1466
+ return_target_key,
1467
+ jumpkind="Ijk_Ret",
1468
+ stmt_id=DEFAULT_STATEMENT,
1469
+ ins_addr=ret_ins_addr,
1470
+ )
1471
+ else:
1472
+ self._pending_edges[return_target_key].append(
1473
+ (
1474
+ job.block_id,
1475
+ return_target_key,
1476
+ {
1477
+ "jumpkind": "Ijk_Ret",
1478
+ "stmt_id": DEFAULT_STATEMENT,
1479
+ "ins_addr": ret_ins_addr,
1480
+ },
1481
+ )
1482
+ )
1483
+
1484
+ else:
1485
+ # There are no successors, but we still want to update the function graph
1486
+ artifacts = job.sim_successors.artifacts
1487
+ if "irsb" in artifacts and "insn_addrs" in artifacts and artifacts["insn_addrs"]:
1488
+ the_irsb = artifacts["irsb"]
1489
+ insn_addrs = artifacts["insn_addrs"]
1490
+ self._handle_job_without_successors(job, the_irsb, insn_addrs)
1491
+
1492
+ # TODO: replace it with a DDG-based function IO analysis
1493
+ # handle all actions
1494
+ if successors:
1495
+ self._handle_actions(
1496
+ successors[0],
1497
+ sim_successors,
1498
+ job.current_function,
1499
+ job.current_stack_pointer,
1500
+ set(),
1501
+ )
1502
+
1503
+ return successors
1504
+
1505
+ def _post_job_handling(self, job: CFGJob, _new_jobs, successors: list[SimState]): # type: ignore[override]
1506
+ """
1507
+
1508
+ :param CFGJob job:
1509
+ :param successors:
1510
+ :return:
1511
+ """
1512
+
1513
+ # Finally, post-process CFG Node and log the return target
1514
+ if job.extra_info and job.extra_info["is_call_jump"] and job.extra_info["return_target"] is not None:
1515
+ job.cfg_node.return_target = job.extra_info["return_target"]
1516
+
1517
+ # Debugging output if needed
1518
+ if l.level == logging.DEBUG:
1519
+ # Only in DEBUG mode do we process and output all those shit
1520
+ self._post_handle_job_debug(job, successors)
1521
+
1522
+ # SimInspect breakpoints support
1523
+ job.state._inspect("cfg_handle_job", BP_AFTER)
1524
+
1525
+ def _post_process_successors(self, input_state, sim_successors, successors):
1526
+ """
1527
+ Filter the list of successors
1528
+
1529
+ :param SimState input_state: Input state.
1530
+ :param SimSuccessors sim_successors: The SimSuccessors instance.
1531
+ :param list successors: A list of successors generated after processing the current block.
1532
+ :return: A list of successors.
1533
+ :rtype: list
1534
+ """
1535
+
1536
+ if sim_successors.sort == "IRSB" and input_state.thumb:
1537
+ successors = self._arm_thumb_filter_jump_successors(
1538
+ sim_successors.artifacts["irsb"],
1539
+ successors,
1540
+ lambda state: state.scratch.ins_addr,
1541
+ lambda state: state.scratch.exit_stmt_idx,
1542
+ lambda state: state.history.jumpkind,
1543
+ )
1544
+
1545
+ # If there is a call exit, we shouldn't put the default exit (which
1546
+ # is artificial) into the CFG. The exits will be Ijk_Call and
1547
+ # Ijk_FakeRet, and Ijk_Call always goes first
1548
+ extra_info = {
1549
+ "is_call_jump": False,
1550
+ "call_target": None,
1551
+ "return_target": None,
1552
+ "last_call_exit_target": None,
1553
+ "skip_fakeret": False,
1554
+ }
1555
+
1556
+ # Post-process jumpkind before touching all_successors
1557
+ for (
1558
+ suc
1559
+ ) in sim_successors.all_successors: # we process all successors here to include potential unsat successors
1560
+ suc_jumpkind = suc.history.jumpkind
1561
+ if self._is_call_jumpkind(suc_jumpkind):
1562
+ extra_info["is_call_jump"] = True
1563
+ break
1564
+
1565
+ return successors, extra_info
1566
+
1567
+ def _post_handle_job_debug(self, job: CFGJob, successors: list[SimState]) -> None:
1568
+ """
1569
+ Post job handling: print debugging information regarding the current job.
1570
+
1571
+ :param CFGJob job: The current CFGJob instance.
1572
+ :param list successors: All successors of the analysis job.
1573
+ :return: None
1574
+ """
1575
+
1576
+ sim_successors = job.sim_successors
1577
+ call_stack_suffix = job.call_stack_suffix
1578
+ extra_info = job.extra_info
1579
+ successor_status = job.successor_status
1580
+
1581
+ func = self.project.loader.find_symbol(job.func_addr)
1582
+ obj = self.project.loader.find_object_containing(job.addr)
1583
+ function_name = func.name if func is not None else None
1584
+ module_name = obj.provides if obj is not None else None
1585
+
1586
+ node = self.model.get_node(job.block_id)
1587
+ depth_str = f"(D:{node.depth})" if node.depth is not None else ""
1588
+
1589
+ l.debug(
1590
+ "%s [%#x%s | %s]",
1591
+ sim_successors.description,
1592
+ sim_successors.addr,
1593
+ depth_str,
1594
+ "->".join([hex(i) for i in call_stack_suffix if i is not None]),
1595
+ )
1596
+ l.debug("(Function %s of binary %s)", function_name, module_name)
1597
+ l.debug("| Call jump: %s", extra_info["is_call_jump"] if extra_info is not None else "unknown")
1598
+
1599
+ for suc in successors:
1600
+ jumpkind = suc.history.jumpkind
1601
+ exit_type_str = "Simulated Ret" if jumpkind == "Ijk_FakeRet" else "-"
1602
+ try:
1603
+ l.debug(
1604
+ "| target: %#x %s [%s] %s",
1605
+ suc.solver.eval_one(suc.ip),
1606
+ successor_status[suc],
1607
+ exit_type_str,
1608
+ jumpkind,
1609
+ )
1610
+ except (SimValueError, SimSolverModeError):
1611
+ l.debug("| target cannot be concretized. %s [%s] %s", successor_status[suc], exit_type_str, jumpkind)
1612
+ l.debug("%d exits remaining, %d exits pending.", len(self._job_info_queue), len(self._pending_jobs))
1613
+ l.debug("%d unique basic blocks are analyzed so far.", len(self._analyzed_addrs))
1614
+
1615
+ def _iteratively_clean_pending_exits(self):
1616
+ """
1617
+ Iteratively update the completed functions set, analyze whether each function returns or not, and remove
1618
+ pending exits if the callee function does not return. We do this iteratively so that we come to a fixed point
1619
+ in the end. In most cases, the number of outer iteration equals to the maximum levels of wrapped functions
1620
+ whose "returningness" is determined by the very last function it calls.
1621
+
1622
+ :return: None
1623
+ """
1624
+
1625
+ while True:
1626
+ # did we finish analyzing any function?
1627
+ # fill in self._completed_functions
1628
+ self._make_completed_functions()
1629
+
1630
+ if self._pending_jobs:
1631
+ # There are no more remaining jobs, but only pending jobs left. Each pending job corresponds to
1632
+ # a previous job that does not return properly.
1633
+ # Now it's a good time to analyze each function (that we have so far) and determine if it is a)
1634
+ # returning, b) not returning, or c) unknown. For those functions that are definitely not returning,
1635
+ # remove the corresponding pending exits from `pending_jobs` array. Perform this procedure iteratively
1636
+ # until no new not-returning functions appear. Then we pick a pending exit based on the following
1637
+ # priorities:
1638
+ # - Job pended by a returning function
1639
+ # - Job pended by an unknown function
1640
+
1641
+ new_changes = self._iteratively_analyze_function_features()
1642
+ functions_do_not_return = new_changes["functions_do_not_return"]
1643
+
1644
+ self._update_function_callsites(functions_do_not_return)
1645
+
1646
+ if not self._clean_pending_exits():
1647
+ # no more pending exits are removed. we are good to go!
1648
+ break
1649
+ else:
1650
+ break
1651
+
1652
+ def _clean_pending_exits(self):
1653
+ """
1654
+ Remove those pending exits if:
1655
+ a) they are the return exits of non-returning SimProcedures
1656
+ b) they are the return exits of non-returning syscalls
1657
+ c) they are the return exits of non-returning functions
1658
+
1659
+ :return: True if any pending exits are removed, False otherwise
1660
+ :rtype: bool
1661
+ """
1662
+
1663
+ pending_exits_to_remove = []
1664
+
1665
+ for block_id, jobs in self._pending_jobs.items():
1666
+ for pe in jobs:
1667
+ if pe.returning_source is None:
1668
+ # The original call failed. This pending exit must be followed.
1669
+ continue
1670
+
1671
+ func = self.kb.functions.function(pe.returning_source)
1672
+ if func is None:
1673
+ # Why does it happen?
1674
+ l.warning(
1675
+ "An expected function at %s is not found. Please report it to Fish.",
1676
+ hex(pe.returning_source) if pe.returning_source is not None else "None",
1677
+ )
1678
+ continue
1679
+
1680
+ if func.returning is False:
1681
+ # Oops, it's not returning
1682
+ # Remove this pending exit
1683
+ pending_exits_to_remove.append(block_id)
1684
+
1685
+ # We want to mark that call as not returning in the current function
1686
+ current_function_addr = self._block_id_current_func_addr(block_id)
1687
+ if current_function_addr is not None:
1688
+ current_function = self.kb.functions.function(current_function_addr)
1689
+ if current_function is not None:
1690
+ call_site_addr = self._block_id_addr(pe.src_block_id)
1691
+ current_function._call_sites[call_site_addr] = (func.addr, None)
1692
+ else:
1693
+ l.warning(
1694
+ "An expected function at %#x is not found. Please report it to Fish.",
1695
+ current_function_addr,
1696
+ )
1697
+
1698
+ for block_id in pending_exits_to_remove:
1699
+ l.debug(
1700
+ "Removing all pending exits to %#x since the target function does not return",
1701
+ self._block_id_addr(block_id),
1702
+ )
1703
+
1704
+ for to_remove in self._pending_jobs[block_id]:
1705
+ self._deregister_analysis_job(to_remove.caller_func_addr, to_remove)
1706
+
1707
+ del self._pending_jobs[block_id]
1708
+
1709
+ return bool(pending_exits_to_remove)
1710
+
1711
+ # Successor handling
1712
+
1713
+ def _pre_handle_successor_state(self, extra_info, jumpkind, target_addr):
1714
+ """
1715
+
1716
+ :return: None
1717
+ """
1718
+
1719
+ # Fill up extra_info
1720
+ if extra_info["is_call_jump"] and self._is_call_jumpkind(jumpkind):
1721
+ extra_info["call_target"] = target_addr
1722
+
1723
+ if extra_info["is_call_jump"] and jumpkind == "Ijk_FakeRet":
1724
+ extra_info["return_target"] = target_addr
1725
+
1726
+ if jumpkind == "Ijk_Call":
1727
+ extra_info["last_call_exit_target"] = target_addr
1728
+
1729
+ def _handle_successor(self, job, successor: SimState, successors):
1730
+ """
1731
+ Returns a new CFGJob instance for further analysis, or None if there is no immediate state to perform the
1732
+ analysis on.
1733
+
1734
+ :param CFGJob job: The current job.
1735
+ """
1736
+
1737
+ state: SimState = successor
1738
+ all_successor_states = successors
1739
+ addr = job.addr
1740
+
1741
+ # The PathWrapper instance to return
1742
+ pw = None
1743
+
1744
+ job.successor_status[state] = ""
1745
+
1746
+ new_state = state.copy()
1747
+ suc_jumpkind = state.history.jumpkind
1748
+ suc_exit_stmt_idx = state.scratch.exit_stmt_idx
1749
+ suc_exit_ins_addr = state.scratch.exit_ins_addr
1750
+
1751
+ if suc_jumpkind in {
1752
+ "Ijk_EmWarn",
1753
+ "Ijk_NoDecode",
1754
+ "Ijk_MapFail",
1755
+ "Ijk_NoRedir",
1756
+ "Ijk_SigTRAP",
1757
+ "Ijk_SigSEGV",
1758
+ "Ijk_ClientReq",
1759
+ }:
1760
+ # Ignore SimExits that are of these jumpkinds
1761
+ job.successor_status[state] = "Skipped"
1762
+ return []
1763
+
1764
+ call_target = job.extra_info["call_target"]
1765
+ if suc_jumpkind == "Ijk_FakeRet" and call_target is not None and self.project.is_hooked(call_target):
1766
+ # if the call points to a SimProcedure that doesn't return, we don't follow the fakeret anymore
1767
+ sim_proc = self.project._sim_procedures[call_target]
1768
+ if sim_proc.NO_RET:
1769
+ return []
1770
+
1771
+ # Get target address
1772
+ try:
1773
+ target_addr = state.solver.eval_one(state.ip)
1774
+ except (SimValueError, SimSolverModeError):
1775
+ # It cannot be concretized currently. Maybe we can handle it later, maybe it just cannot be concretized
1776
+ target_addr = None
1777
+ if suc_jumpkind == "Ijk_Ret":
1778
+ target_addr = job.call_stack.current_return_target
1779
+ if target_addr is not None:
1780
+ new_state.ip = claripy.BVV(target_addr, new_state.arch.bits)
1781
+
1782
+ if target_addr is None:
1783
+ # Unlucky...
1784
+ return []
1785
+
1786
+ if state.thumb:
1787
+ # Make sure addresses are always odd. It is important to encode this information in the address for the
1788
+ # time being.
1789
+ target_addr |= 1
1790
+
1791
+ # see if the target successor is in our whitelist
1792
+ if self._address_whitelist is not None and target_addr not in self._address_whitelist:
1793
+ l.debug("Successor %#x is not in the address whitelist. Skip.", target_addr)
1794
+ return []
1795
+
1796
+ # see if this edge is in the base graph
1797
+ if self._base_graph is not None:
1798
+ # TODO: make it more efficient. the current implementation is half-assed and extremely slow
1799
+ for src_, dst_ in self._base_graph.edges():
1800
+ if src_.addr == addr and dst_.addr == target_addr:
1801
+ break
1802
+ else:
1803
+ # not found
1804
+ l.debug("Edge (%#x -> %#x) is not found in the base graph. Skip.", addr, target_addr)
1805
+ return []
1806
+
1807
+ # Fix target_addr for syscalls
1808
+ if suc_jumpkind.startswith("Ijk_Sys"):
1809
+ syscall_proc = self.project.simos.syscall(new_state)
1810
+ if syscall_proc is not None:
1811
+ target_addr = syscall_proc.addr
1812
+
1813
+ self._pre_handle_successor_state(job.extra_info, suc_jumpkind, target_addr)
1814
+
1815
+ if suc_jumpkind == "Ijk_FakeRet":
1816
+ if target_addr == job.extra_info["last_call_exit_target"]:
1817
+ l.debug("... skipping a fake return exit that has the same target with its call exit.")
1818
+ job.successor_status[state] = "Skipped"
1819
+ return []
1820
+
1821
+ if job.extra_info["skip_fakeret"]:
1822
+ l.debug("... skipping a fake return exit since the function it's calling doesn't return")
1823
+ job.successor_status[state] = "Skipped - non-returning function 0x{:x}".format(
1824
+ job.extra_info["call_target"]
1825
+ )
1826
+ return []
1827
+
1828
+ # TODO: Make it optional
1829
+ if suc_jumpkind == "Ijk_Ret" and self._call_depth is not None and len(job.call_stack) <= 1:
1830
+ # We cannot continue anymore since this is the end of the function where we started tracing
1831
+ l.debug("... reaching the end of the starting function, skip.")
1832
+ job.successor_status[state] = "Skipped - reaching the end of the starting function"
1833
+ return []
1834
+
1835
+ # Create the new call stack of target block
1836
+ new_call_stack = self._create_new_call_stack(addr, all_successor_states, job, target_addr, suc_jumpkind)
1837
+ # Create the callstack suffix
1838
+ new_call_stack_suffix = new_call_stack.stack_suffix(self._context_sensitivity_level)
1839
+ # Tuple that will be used to index this exit
1840
+ new_tpl = self._generate_block_id(new_call_stack_suffix, target_addr, suc_jumpkind.startswith("Ijk_Sys"))
1841
+
1842
+ # We might have changed the mode for this basic block
1843
+ # before. Make sure it is still running in 'fastpath' mode
1844
+ self._reset_state_mode(new_state, "fastpath")
1845
+
1846
+ pw = CFGJob(
1847
+ target_addr,
1848
+ new_state,
1849
+ self._context_sensitivity_level,
1850
+ src_block_id=job.block_id,
1851
+ src_exit_stmt_idx=suc_exit_stmt_idx,
1852
+ src_ins_addr=suc_exit_ins_addr,
1853
+ call_stack=new_call_stack,
1854
+ jumpkind=suc_jumpkind,
1855
+ )
1856
+ # Special case: If the binary has symbols and the target address is a function, but for some reason (e.g.,
1857
+ # a tail-call optimization) the CallStack's function address is still the old function address, we will have to
1858
+ # overwrite it here.
1859
+ if not self._is_call_jumpkind(pw.jumpkind):
1860
+ target_symbol = self.project.loader.find_symbol(target_addr)
1861
+ if target_symbol and target_symbol.is_function:
1862
+ # Force update the function address
1863
+ pw.func_addr = target_addr
1864
+
1865
+ # Generate new exits
1866
+ if suc_jumpkind == "Ijk_Ret":
1867
+ # This is the real return exit
1868
+ job.successor_status[state] = "Appended"
1869
+
1870
+ elif suc_jumpkind == "Ijk_FakeRet":
1871
+ # This is the default "fake" retn that generated at each
1872
+ # call. Save them first, but don't process them right
1873
+ # away
1874
+ # st = self.project._simos.prepare_call_state(new_state, initial_state=saved_state)
1875
+ st = new_state
1876
+ self._reset_state_mode(st, "fastpath")
1877
+
1878
+ pw = None # clear the job
1879
+ pe = PendingJob(
1880
+ job.func_addr,
1881
+ job.extra_info["call_target"],
1882
+ st,
1883
+ job.block_id,
1884
+ suc_exit_stmt_idx,
1885
+ suc_exit_ins_addr,
1886
+ new_call_stack,
1887
+ )
1888
+ self._pending_jobs[new_tpl].append(pe)
1889
+ self._register_analysis_job(pe.caller_func_addr, pe)
1890
+ job.successor_status[state] = "Pended"
1891
+
1892
+ elif self._traced_addrs[new_call_stack_suffix][target_addr] >= 1 and suc_jumpkind == "Ijk_Ret":
1893
+ # This is a corner case for the f****** ARM instruction
1894
+ # like
1895
+ # BLEQ <address>
1896
+ # If we have analyzed the boring exit before returning from that called address, we will lose the link
1897
+ # between the last block of the function being called and the basic block it returns to. We cannot
1898
+ # reanalyze the basic block as we are not flow-sensitive, but we can still record the connection and make
1899
+ # for it afterwards.
1900
+ pass
1901
+
1902
+ else:
1903
+ job.successor_status[state] = "Appended"
1904
+
1905
+ if job.extra_info["is_call_jump"] and job.extra_info["call_target"] in self._non_returning_functions:
1906
+ job.extra_info["skip_fakeret"] = True
1907
+
1908
+ if not pw:
1909
+ return []
1910
+
1911
+ # register the job
1912
+ self._register_analysis_job(pw.func_addr, pw)
1913
+
1914
+ return [pw]
1915
+
1916
+ def _handle_job_without_successors(self, job, irsb, insn_addrs):
1917
+ """
1918
+ A block without successors should still be handled so it can be added to the function graph correctly.
1919
+
1920
+ :param CFGJob job: The current job that do not have any successor.
1921
+ :param IRSB irsb: The related IRSB.
1922
+ :param insn_addrs: A list of instruction addresses of this IRSB.
1923
+ :return: None
1924
+ """
1925
+
1926
+ # it's not an empty block
1927
+
1928
+ # handle all conditional exits
1929
+ ins_addr = job.addr
1930
+ for stmt_idx, stmt in enumerate(irsb.statements):
1931
+ if type(stmt) is pyvex.IRStmt.IMark:
1932
+ ins_addr = stmt.addr + stmt.delta
1933
+ elif type(stmt) is pyvex.IRStmt.Exit:
1934
+ successor_jumpkind = stmt.jk
1935
+ self._update_function_transition_graph(
1936
+ job.block_id,
1937
+ None,
1938
+ jumpkind=successor_jumpkind,
1939
+ ins_addr=ins_addr,
1940
+ stmt_idx=stmt_idx,
1941
+ )
1942
+
1943
+ # handle the default exit
1944
+ successor_jumpkind = irsb.jumpkind
1945
+ successor_last_ins_addr = insn_addrs[-1]
1946
+ self._update_function_transition_graph(
1947
+ job.block_id,
1948
+ None,
1949
+ jumpkind=successor_jumpkind,
1950
+ ins_addr=successor_last_ins_addr,
1951
+ stmt_idx=DEFAULT_STATEMENT,
1952
+ )
1953
+
1954
+ # SimAction handling
1955
+
1956
+ def _handle_actions(self, state, current_run, func, sp_addr, accessed_registers):
1957
+ """
1958
+ For a given state and current location of of execution, will update a function by adding the offsets of
1959
+ appropriate actions to the stack variable or argument registers for the fnc.
1960
+
1961
+ :param SimState state: upcoming state.
1962
+ :param SimSuccessors current_run: possible result states.
1963
+ :param knowledge.Function func: current function.
1964
+ :param int sp_addr: stack pointer address.
1965
+ :param set accessed_registers: set of before accessed registers.
1966
+ """
1967
+ se = state.solver
1968
+
1969
+ if func is not None and sp_addr is not None:
1970
+ # Fix the stack pointer (for example, skip the return address on the stack)
1971
+ new_sp_addr = sp_addr + self.project.arch.call_sp_fix
1972
+
1973
+ actions = [a for a in state.history.recent_actions if a.bbl_addr == current_run.addr]
1974
+
1975
+ for a in actions:
1976
+ if a.type == "mem" and a.action == "read":
1977
+ try:
1978
+ addr = se.eval_one(a.addr.ast, default=0)
1979
+ except (claripy.ClaripyError, SimSolverModeError):
1980
+ continue
1981
+ if (self.project.arch.call_pushes_ret and addr >= new_sp_addr) or (
1982
+ not self.project.arch.call_pushes_ret and addr >= new_sp_addr
1983
+ ):
1984
+ # TODO: What if a variable locates higher than the stack is modified as well? We probably want
1985
+ # TODO: to make sure the accessing address falls in the range of stack
1986
+ offset = addr - new_sp_addr
1987
+ func._add_argument_stack_variable(offset)
1988
+ elif a.type == "reg":
1989
+ offset = a.offset
1990
+ if a.action == "read" and offset not in accessed_registers:
1991
+ func._add_argument_register(offset)
1992
+ elif a.action == "write":
1993
+ accessed_registers.add(offset)
1994
+ else:
1995
+ l.error(
1996
+ "handle_actions: Function not found, or stack pointer is None. It might indicates unbalanced stack."
1997
+ )
1998
+
1999
+ # Private utils - DiGraph construction and manipulation
2000
+
2001
+ def _graph_get_node(self, node_key, terminator_for_nonexistent_node=False):
2002
+ """
2003
+
2004
+ :param node_key:
2005
+ :return:
2006
+ """
2007
+
2008
+ if node_key not in self._nodes:
2009
+ if not terminator_for_nonexistent_node:
2010
+ return None
2011
+ # Generate a PathTerminator node
2012
+ addr = self._block_id_addr(node_key)
2013
+ func_addr = self._block_id_current_func_addr(node_key)
2014
+ if func_addr is None:
2015
+ # We'll have to use the current block address instead
2016
+ # TODO: Is it really OK?
2017
+ func_addr = self._block_id_addr(node_key)
2018
+
2019
+ is_thumb = isinstance(self.project.arch, ArchARM) and addr % 2 == 1
2020
+
2021
+ pt = CFGENode(
2022
+ self._block_id_addr(node_key),
2023
+ None,
2024
+ self.model,
2025
+ input_state=None,
2026
+ simprocedure_name="PathTerminator",
2027
+ function_address=func_addr,
2028
+ callstack_key=self._block_id_callstack_key(node_key),
2029
+ thumb=is_thumb,
2030
+ )
2031
+ if self._keep_state:
2032
+ # We don't have an input state available for it (otherwise we won't have to create a
2033
+ # PathTerminator). This is just a trick to make get_any_irsb() happy.
2034
+ pt.input_state = self.project.factory.entry_state()
2035
+ pt.input_state.ip = pt.addr
2036
+ self._model.add_node(node_key, pt)
2037
+
2038
+ if is_thumb:
2039
+ self._thumb_addrs.add(addr)
2040
+ self._thumb_addrs.add(addr - 1)
2041
+
2042
+ l.debug("Block ID %s does not exist. Create a PathTerminator instead.", self._block_id_repr(node_key))
2043
+
2044
+ return self._nodes[node_key]
2045
+
2046
+ def _graph_add_edge(self, src_node_key, dst_node_key, **kwargs):
2047
+ """
2048
+
2049
+ :param src_node_key:
2050
+ :param dst_node_key:
2051
+ :param jumpkind:
2052
+ :param exit_stmt_idx:
2053
+ :return:
2054
+ """
2055
+
2056
+ dst_node = self._graph_get_node(dst_node_key, terminator_for_nonexistent_node=True)
2057
+
2058
+ if src_node_key is None:
2059
+ self.graph.add_node(dst_node)
2060
+
2061
+ else:
2062
+ src_node = self._graph_get_node(src_node_key, terminator_for_nonexistent_node=True)
2063
+ self.graph.add_edge(src_node, dst_node, **kwargs)
2064
+
2065
+ def _update_function_transition_graph(
2066
+ self, src_node_key, dst_node_key, jumpkind="Ijk_Boring", ins_addr=None, stmt_idx=None, confirmed=None
2067
+ ):
2068
+ """
2069
+ Update transition graphs of functions in function manager based on information passed in.
2070
+
2071
+ :param src_node_key: Node key of the source CFGNode. Might be None.
2072
+ :param dst_node: Node key of the destination CFGNode. Might be None.
2073
+ :param str jumpkind: Jump kind of this transition.
2074
+ :param int ret_addr: The theoretical return address for calls.
2075
+ :param int or None ins_addr: Address of the instruction where this transition is made.
2076
+ :param int or None stmt_idx: ID of the statement where this transition is made.
2077
+ :param bool or None confirmed: Whether this call transition has been confirmed or not.
2078
+ :return: None
2079
+ """
2080
+
2081
+ if dst_node_key is not None:
2082
+ dst_node = self._graph_get_node(dst_node_key, terminator_for_nonexistent_node=True)
2083
+ dst_node_addr = dst_node.addr
2084
+ dst_codenode = dst_node.to_codenode()
2085
+ dst_node_func_addr = dst_node.function_address
2086
+ else:
2087
+ dst_node = None
2088
+ dst_node_addr = None
2089
+ dst_codenode = None
2090
+ dst_node_func_addr = None
2091
+
2092
+ if src_node_key is None:
2093
+ if dst_node is None:
2094
+ raise ValueError("Either src_node_key or dst_node_key must be specified.")
2095
+ self.kb.functions.function(dst_node.function_address, create=True)._register_node(True, dst_codenode)
2096
+ return
2097
+
2098
+ src_node = self._graph_get_node(src_node_key, terminator_for_nonexistent_node=True)
2099
+
2100
+ # Update the transition graph of current function
2101
+ if jumpkind == "Ijk_Call":
2102
+ ret_addr = src_node.return_target
2103
+ ret_node = (
2104
+ self.kb.functions.function(src_node.function_address, create=True)._get_block(ret_addr).codenode
2105
+ if ret_addr
2106
+ else None
2107
+ )
2108
+
2109
+ self.kb.functions._add_call_to(
2110
+ function_addr=src_node.function_address,
2111
+ from_node=src_node.to_codenode(),
2112
+ to_addr=dst_node_addr,
2113
+ retn_node=ret_node,
2114
+ syscall=False,
2115
+ ins_addr=ins_addr,
2116
+ stmt_idx=stmt_idx,
2117
+ )
2118
+
2119
+ if jumpkind.startswith("Ijk_Sys"):
2120
+ self.kb.functions._add_call_to(
2121
+ function_addr=src_node.function_address,
2122
+ from_node=src_node.to_codenode(),
2123
+ to_addr=dst_node_addr,
2124
+ retn_node=src_node.to_codenode(), # For syscalls, they are returning to the address of themselves
2125
+ syscall=True,
2126
+ ins_addr=ins_addr,
2127
+ stmt_idx=stmt_idx,
2128
+ )
2129
+
2130
+ elif jumpkind == "Ijk_Ret":
2131
+ # Create a return site for current function
2132
+ self.kb.functions._add_return_from(
2133
+ function_addr=src_node.function_address,
2134
+ from_node=src_node.to_codenode(),
2135
+ to_node=dst_codenode,
2136
+ )
2137
+
2138
+ if dst_node is not None:
2139
+ # Create a returning edge in the caller function
2140
+ self.kb.functions._add_return_from_call(
2141
+ function_addr=dst_node_func_addr,
2142
+ src_function_addr=src_node.function_address,
2143
+ to_node=dst_codenode,
2144
+ )
2145
+
2146
+ elif jumpkind == "Ijk_FakeRet":
2147
+ self.kb.functions._add_fakeret_to(
2148
+ function_addr=src_node.function_address,
2149
+ from_node=src_node.to_codenode(),
2150
+ to_node=dst_codenode,
2151
+ confirmed=confirmed,
2152
+ )
2153
+
2154
+ elif jumpkind in ("Ijk_Boring", "Ijk_InvalICache"):
2155
+ src_obj = self.project.loader.find_object_containing(src_node.addr)
2156
+ dest_obj = self.project.loader.find_object_containing(dst_node.addr) if dst_node is not None else None
2157
+
2158
+ # if true: Jump/branch within the same object. Might be an outside jump.
2159
+ # if false: Jump/branch between different objects. Must be an outside jump.
2160
+ to_outside = src_node.function_address != dst_node_func_addr if src_obj is dest_obj else True
2161
+
2162
+ if not to_outside:
2163
+ self.kb.functions._add_transition_to(
2164
+ function_addr=src_node.function_address,
2165
+ from_node=src_node.to_codenode(),
2166
+ to_node=dst_codenode,
2167
+ ins_addr=ins_addr,
2168
+ stmt_idx=stmt_idx,
2169
+ )
2170
+
2171
+ else:
2172
+ self.kb.functions._add_outside_transition_to(
2173
+ function_addr=src_node.function_address,
2174
+ from_node=src_node.to_codenode(),
2175
+ to_node=dst_codenode,
2176
+ to_function_addr=dst_node_func_addr,
2177
+ ins_addr=ins_addr,
2178
+ stmt_idx=stmt_idx,
2179
+ )
2180
+
2181
+ def _update_function_callsites(self, noreturns):
2182
+ """
2183
+ Update the callsites of functions (remove return targets) that are calling functions that are just deemed not
2184
+ returning.
2185
+
2186
+ :param iterable func_addrs: A collection of functions for newly-recovered non-returning functions.
2187
+ :return: None
2188
+ """
2189
+
2190
+ for callee_func in noreturns:
2191
+ # consult the callgraph to find callers of each function
2192
+ if callee_func.addr not in self.functions.callgraph:
2193
+ continue
2194
+ caller_addrs = self.functions.callgraph.predecessors(callee_func.addr)
2195
+ for caller_addr in caller_addrs:
2196
+ caller = self.functions[caller_addr]
2197
+ if callee_func not in caller.transition_graph:
2198
+ continue
2199
+ callsites = caller.transition_graph.predecessors(callee_func)
2200
+ for callsite in callsites:
2201
+ caller._add_call_site(callsite.addr, callee_func.addr, None)
2202
+
2203
+ def _add_additional_edges(self, input_state, sim_successors, cfg_node, successors):
2204
+ """
2205
+
2206
+ :return:
2207
+ """
2208
+
2209
+ # If we have additional edges for this block, add them in
2210
+ addr = cfg_node.addr
2211
+
2212
+ if addr in self._additional_edges:
2213
+ dests = self._additional_edges[addr]
2214
+ for dst in dests:
2215
+ if sim_successors.sort == "IRSB":
2216
+ base_state = sim_successors.all_successors[0].copy()
2217
+ else:
2218
+ # If true, we try to use the first successor.
2219
+ # If false, the SimProcedure doesn't have any successor (e.g. it's a PathTerminator)
2220
+ # We'll use its input state instead
2221
+ base_state = successors[0].copy() if successors else input_state
2222
+ base_state.ip = dst
2223
+ # TODO: Allow for sp adjustments
2224
+ successors.append(base_state)
2225
+ l.debug("Additional jump target %#x for block %s is appended.", dst, sim_successors.description)
2226
+
2227
+ return successors
2228
+
2229
+ def _filter_insane_successors(self, successors):
2230
+ """
2231
+ Throw away all successors whose target doesn't make sense
2232
+
2233
+ This method is called after we resolve an indirect jump using an unreliable method (like, not through one of
2234
+ the indirect jump resolvers, but through either pure concrete execution or backward slicing) to filter out the
2235
+ obviously incorrect successors.
2236
+
2237
+ :param list successors: A collection of successors.
2238
+ :return: A filtered list of successors
2239
+ :rtype: list
2240
+ """
2241
+
2242
+ old_successors = successors[::]
2243
+ successors = []
2244
+ for i, suc in enumerate(old_successors):
2245
+ if suc.solver.symbolic(suc.ip):
2246
+ # It's symbolic. Take it, and hopefully we can resolve it later
2247
+ successors.append(suc)
2248
+
2249
+ else:
2250
+ ip_int = suc.solver.eval_one(suc.ip)
2251
+
2252
+ if (
2253
+ self._is_address_executable(ip_int)
2254
+ or self.project.is_hooked(ip_int)
2255
+ or self.project.simos.is_syscall_addr(ip_int)
2256
+ ):
2257
+ successors.append(suc)
2258
+ else:
2259
+ l.debug(
2260
+ "An obviously incorrect successor %d/%d (%#x) is ditched", i + 1, len(old_successors), ip_int
2261
+ )
2262
+
2263
+ return successors
2264
+
2265
+ def _remove_non_return_edges(self):
2266
+ """
2267
+ Remove those return_from_call edges that actually do not return due to
2268
+ calling some not-returning functions.
2269
+ :return: None
2270
+ """
2271
+ for func in self.kb.functions.values():
2272
+ graph = func.transition_graph
2273
+ all_return_edges = [(u, v) for (u, v, data) in graph.edges(data=True) if data["type"] == "return"]
2274
+ for return_from_call_edge in all_return_edges:
2275
+ callsite_block_addr, return_to_addr = return_from_call_edge
2276
+ call_func_addr = func.get_call_target(callsite_block_addr)
2277
+ if call_func_addr is None:
2278
+ continue
2279
+
2280
+ call_func = self.kb.functions.function(call_func_addr)
2281
+ if call_func is None:
2282
+ # Weird...
2283
+ continue
2284
+
2285
+ if call_func.returning is False:
2286
+ # Remove that edge!
2287
+ graph.remove_edge(call_func_addr, return_to_addr)
2288
+ # Remove the edge in CFG
2289
+ nodes = self.model.get_all_nodes(callsite_block_addr)
2290
+ for n in nodes:
2291
+ successors = self.model.get_successors_and_jumpkind(n, excluding_fakeret=False)
2292
+ for successor, jumpkind in successors:
2293
+ if jumpkind == "Ijk_FakeRet" and successor.addr == return_to_addr:
2294
+ self.remove_edge(n, successor)
2295
+
2296
+ # Remove all dangling nodes
2297
+ # wcc = list(networkx.weakly_connected_components(graph))
2298
+ # for nodes in wcc:
2299
+ # if func.startpoint not in nodes:
2300
+ # graph.remove_nodes_from(nodes)
2301
+
2302
+ # Private methods - resolving indirect jumps
2303
+
2304
+ @staticmethod
2305
+ def _convert_indirect_jump_targets_to_states(job, indirect_jump_targets):
2306
+ """
2307
+ Convert each concrete indirect jump target into a SimState. If there are non-zero successors and the original
2308
+ jumpkind is a call, we also generate a fake-ret successor.
2309
+
2310
+ :param job: The CFGJob instance.
2311
+ :param indirect_jump_targets: A collection of concrete jump targets resolved from a indirect jump.
2312
+ :return: A list of SimStates.
2313
+ :rtype: list
2314
+ """
2315
+
2316
+ first_successor = job.sim_successors.all_successors[0]
2317
+ successors = []
2318
+ for t in indirect_jump_targets:
2319
+ # Insert new successors
2320
+ a = first_successor.copy()
2321
+ a.ip = t
2322
+ successors.append(a)
2323
+ # special case: if the indirect jump is in fact an indirect call, we should create a FakeRet successor
2324
+ if successors and first_successor.history.jumpkind == "Ijk_Call":
2325
+ a = first_successor.copy()
2326
+ a.ip = job.cfg_node.addr + job.cfg_node.size
2327
+ a.history.jumpkind = "Ijk_FakeRet"
2328
+ successors.append(a)
2329
+ return successors
2330
+
2331
+ def _try_resolving_indirect_jumps(self, sim_successors, cfg_node, func_addr, successors, exception_info, artifacts):
2332
+ """
2333
+ Resolve indirect jumps specified by sim_successors.addr.
2334
+
2335
+ :param SimSuccessors sim_successors: The SimSuccessors instance.
2336
+ :param CFGNode cfg_node: The CFGNode instance.
2337
+ :param int func_addr: Current function address.
2338
+ :param list successors: A list of successors.
2339
+ :param tuple exception_info: The sys.exc_info() of the exception or None if none occurred.
2340
+ :param artifacts: A container of collected information.
2341
+ :return: Resolved successors
2342
+ :rtype: list
2343
+ """
2344
+
2345
+ # Try to resolve indirect jumps with advanced backward slicing (if enabled)
2346
+ if sim_successors.sort == "IRSB" and self._is_indirect_jump(cfg_node, sim_successors):
2347
+ l.debug("IRSB %#x has an indirect jump as its default exit", cfg_node.addr)
2348
+
2349
+ # We need input states to perform backward slicing
2350
+ if self._advanced_backward_slicing and self._keep_state:
2351
+ # Optimization: make sure we only try to resolve an indirect jump if any of the following criteria holds
2352
+ # - It's a jump (Ijk_Boring), and its target is either fully symbolic, or its resolved target is within
2353
+ # the current binary
2354
+ # - It's a call (Ijk_Call), and its target is fully symbolic
2355
+ # TODO: This is very hackish, please refactor this part of code later
2356
+ should_resolve = True
2357
+ legit_successors = [
2358
+ suc for suc in successors if suc.history.jumpkind in ("Ijk_Boring", "Ijk_InvalICache", "Ijk_Call")
2359
+ ]
2360
+ if legit_successors:
2361
+ legit_successor = legit_successors[0]
2362
+ if legit_successor.ip.symbolic:
2363
+ if legit_successor.history.jumpkind != "Ijk_Call":
2364
+ should_resolve = False
2365
+ else:
2366
+ if legit_successor.history.jumpkind == "Ijk_Call":
2367
+ should_resolve = False
2368
+ else:
2369
+ concrete_target = legit_successor.solver.eval(legit_successor.ip)
2370
+ if (
2371
+ self.project.loader.find_object_containing(concrete_target)
2372
+ is not self.project.loader.main_object
2373
+ ):
2374
+ should_resolve = False
2375
+
2376
+ else:
2377
+ # No interesting successors... skip
2378
+ should_resolve = False
2379
+
2380
+ # TODO: Handle those successors
2381
+ if not should_resolve:
2382
+ l.debug("This might not be an indirect jump that has multiple targets. Skipped.")
2383
+ self.kb.unresolved_indirect_jumps.add(cfg_node.addr)
2384
+
2385
+ else:
2386
+ more_successors = self._backward_slice_indirect(cfg_node, sim_successors, func_addr)
2387
+
2388
+ if more_successors:
2389
+ # Remove the symbolic successor
2390
+ # TODO: Now we are removing all symbolic successors. Is it possible
2391
+ # TODO: that there is more than one symbolic successor?
2392
+ all_successors = [suc for suc in successors if not suc.solver.symbolic(suc.ip)]
2393
+ # Insert new successors
2394
+ # We insert new successors in the beginning of all_successors list so that we don't break the
2395
+ # assumption that Ijk_FakeRet is always the last element in the list
2396
+ for suc_addr in more_successors:
2397
+ a = sim_successors.all_successors[0].copy()
2398
+ a.ip = suc_addr
2399
+ all_successors.insert(0, a)
2400
+
2401
+ l.debug("The indirect jump is successfully resolved.")
2402
+ self.kb.indirect_jumps.update_resolved_addrs(cfg_node.addr, more_successors)
2403
+
2404
+ else:
2405
+ l.debug("Failed to resolve the indirect jump.")
2406
+ self.kb.unresolved_indirect_jumps.add(cfg_node.addr)
2407
+
2408
+ else:
2409
+ if not successors:
2410
+ l.debug("Cannot resolve the indirect jump without advanced backward slicing enabled: %s", cfg_node)
2411
+
2412
+ # Try to find more successors if we failed to resolve the indirect jump before
2413
+ if exception_info is None and (cfg_node.is_simprocedure or self._is_indirect_jump(cfg_node, sim_successors)):
2414
+ has_call_jumps = any(suc_state.history.jumpkind == "Ijk_Call" for suc_state in successors)
2415
+ if has_call_jumps:
2416
+ concrete_successors = [
2417
+ suc_state
2418
+ for suc_state in successors
2419
+ if suc_state.history.jumpkind != "Ijk_FakeRet" and not suc_state.solver.symbolic(suc_state.ip)
2420
+ ]
2421
+ else:
2422
+ concrete_successors = [
2423
+ suc_state for suc_state in successors if not suc_state.solver.symbolic(suc_state.ip)
2424
+ ]
2425
+ symbolic_successors = [suc_state for suc_state in successors if suc_state.solver.symbolic(suc_state.ip)]
2426
+
2427
+ resolved = not symbolic_successors
2428
+ if symbolic_successors:
2429
+ for suc in symbolic_successors:
2430
+ if o.SYMBOLIC in suc.options:
2431
+ targets = suc.solver.eval_upto(suc.ip, 32)
2432
+ if len(targets) < 32:
2433
+ all_successors = []
2434
+ resolved = True
2435
+ for t in targets:
2436
+ new_ex = suc.copy()
2437
+ new_ex.ip = claripy.BVV(t, suc.ip.size())
2438
+ all_successors.append(new_ex)
2439
+ else:
2440
+ break
2441
+
2442
+ if not resolved and (
2443
+ (symbolic_successors and not concrete_successors)
2444
+ or (not cfg_node.is_simprocedure and self._is_indirect_jump(cfg_node, sim_successors))
2445
+ ):
2446
+ l.debug("%s has an indirect jump. See what we can do about it.", cfg_node)
2447
+
2448
+ if sim_successors.sort == "SimProcedure" and sim_successors.artifacts["adds_exits"]:
2449
+ # Skip those SimProcedures that don't create new SimExits
2450
+ l.debug(
2451
+ "We got a SimProcedure %s in fastpath mode that creates new exits.", sim_successors.description
2452
+ )
2453
+ if self._enable_symbolic_back_traversal:
2454
+ successors = self._symbolically_back_traverse(sim_successors, artifacts, cfg_node)
2455
+ # mark jump as resolved if we got successors
2456
+ if successors:
2457
+ succ_addrs = [s.addr for s in successors]
2458
+ self.kb.indirect_jumps.update_resolved_addrs(cfg_node.addr, succ_addrs)
2459
+ else:
2460
+ self.kb.unresolved_indirect_jumps.add(cfg_node.addr)
2461
+ l.debug("Got %d concrete exits in symbolic mode.", len(successors))
2462
+ else:
2463
+ self.kb.unresolved_indirect_jumps.add(cfg_node.addr)
2464
+ # keep fake_rets
2465
+ successors = [s for s in successors if s.history.jumpkind == "Ijk_FakeRet"]
2466
+
2467
+ elif sim_successors.sort == "IRSB" and any(ex.history.jumpkind != "Ijk_Ret" for ex in successors):
2468
+ # We cannot properly handle Return as that requires us start execution from the caller...
2469
+ l.debug("Try traversal backwards in symbolic mode on %s.", cfg_node)
2470
+ if self._enable_symbolic_back_traversal:
2471
+ successors = self._symbolically_back_traverse(sim_successors, artifacts, cfg_node)
2472
+
2473
+ # Remove successors whose IP doesn't make sense
2474
+ successors = [
2475
+ suc for suc in successors if self._is_address_executable(suc.solver.eval_one(suc.ip))
2476
+ ]
2477
+
2478
+ # mark jump as resolved if we got successors
2479
+ if successors:
2480
+ succ_addrs = [s.addr for s in successors]
2481
+ self.kb.indirect_jumps.update_resolved_addrs(cfg_node.addr, succ_addrs)
2482
+ else:
2483
+ self.kb.unresolved_indirect_jumps.add(cfg_node.addr)
2484
+ l.debug("Got %d concrete exits in symbolic mode", len(successors))
2485
+ else:
2486
+ self.kb.unresolved_indirect_jumps.add(cfg_node.addr)
2487
+ successors = []
2488
+
2489
+ elif successors and all(ex.history.jumpkind == "Ijk_Ret" for ex in successors):
2490
+ l.debug("All exits are returns (Ijk_Ret). It will be handled by pending exits.")
2491
+
2492
+ else:
2493
+ l.debug("Cannot resolve this indirect jump: %s", cfg_node)
2494
+ self.kb.unresolved_indirect_jumps.add(cfg_node.addr)
2495
+
2496
+ return successors
2497
+
2498
+ def _backward_slice_indirect(self, cfgnode, sim_successors, current_function_addr):
2499
+ """
2500
+ Try to resolve an indirect jump by slicing backwards
2501
+ """
2502
+ # TODO: make this a real indirect jump resolver under the new paradigm
2503
+
2504
+ irsb = sim_successors.artifacts["irsb"] # shorthand
2505
+
2506
+ l.debug("Resolving indirect jump at IRSB %s", irsb)
2507
+
2508
+ # Let's slice backwards from the end of this exit
2509
+ next_tmp = irsb.next.tmp
2510
+ stmt_id = next(
2511
+ i for i, s in enumerate(irsb.statements) if isinstance(s, pyvex.IRStmt.WrTmp) and s.tmp == next_tmp
2512
+ )
2513
+
2514
+ cdg = self.project.analyses[CDG].prep(fail_fast=self._fail_fast)(cfg=self)
2515
+ ddg = self.project.analyses[DDG].prep(fail_fast=self._fail_fast)(
2516
+ cfg=self, start=current_function_addr, call_depth=0
2517
+ )
2518
+
2519
+ bc = self.project.analyses[BackwardSlice].prep(fail_fast=self._fail_fast)(
2520
+ self, cdg, ddg, targets=[(cfgnode, stmt_id)], same_function=True
2521
+ )
2522
+ taint_graph = bc.taint_graph
2523
+ # Find the correct taint
2524
+ next_nodes = [cl for cl in taint_graph.nodes() if cl.block_addr == sim_successors.addr]
2525
+
2526
+ if not next_nodes:
2527
+ l.error("The target exit is not included in the slice. Something is wrong")
2528
+ return []
2529
+
2530
+ next_node = next_nodes[0]
2531
+
2532
+ # Get the weakly-connected subgraph that contains `next_node`
2533
+ all_subgraphs = (
2534
+ networkx.induced_subgraph(taint_graph, nodes) for nodes in networkx.weakly_connected_components(taint_graph)
2535
+ )
2536
+ starts = set()
2537
+ for subgraph in all_subgraphs:
2538
+ if next_node in subgraph:
2539
+ # Make sure there is no symbolic read...
2540
+ # FIXME: This is an over-approximation. We should try to limit the starts more
2541
+ nodes = [n for n in subgraph.nodes() if subgraph.in_degree(n) == 0]
2542
+ for n in nodes:
2543
+ starts.add(n.block_addr)
2544
+
2545
+ # Execute the slice
2546
+ successing_addresses = set()
2547
+ annotated_cfg = bc.annotated_cfg()
2548
+ for start in starts:
2549
+ l.debug("Start symbolic execution at 0x%x on program slice.", start)
2550
+ # Get the state from our CFG
2551
+ node = self.model.get_any_node(start)
2552
+ if node is None:
2553
+ # Well, we have to live with an empty state
2554
+ base_state = self.project.factory.blank_state(addr=start)
2555
+ else:
2556
+ base_state = node.input_state.copy()
2557
+ base_state.set_mode("symbolic")
2558
+ base_state.ip = start
2559
+
2560
+ # Clear all initial taints (register values, memory values, etc.)
2561
+ initial_nodes = [n for n in bc.taint_graph.nodes() if bc.taint_graph.in_degree(n) == 0]
2562
+ for cl in initial_nodes:
2563
+ # Iterate in all actions of this node, and pick corresponding actions
2564
+ cfg_nodes = self.model.get_all_nodes(cl.block_addr)
2565
+ for n in cfg_nodes:
2566
+ if not n.final_states:
2567
+ continue
2568
+ actions = [
2569
+ ac
2570
+ for ac in n.final_states[0].history.recent_actions
2571
+ # Normally it's enough to only use the first final state
2572
+ if ac.bbl_addr == cl.block_addr and ac.stmt_idx == cl.stmt_idx
2573
+ ]
2574
+ for ac in actions:
2575
+ if not hasattr(ac, "action"):
2576
+ continue
2577
+ if ac.action == "read":
2578
+ if ac.type == "mem":
2579
+ unconstrained_value = base_state.solver.Unconstrained(
2580
+ "unconstrained", ac.size.ast * 8
2581
+ )
2582
+ base_state.memory.store(
2583
+ ac.addr, unconstrained_value, endness=self.project.arch.memory_endness
2584
+ )
2585
+ elif ac.type == "reg":
2586
+ unconstrained_value = base_state.solver.Unconstrained(
2587
+ "unconstrained", ac.size.ast * 8
2588
+ )
2589
+ base_state.registers.store(
2590
+ ac.offset, unconstrained_value, endness=self.project.arch.register_endness
2591
+ )
2592
+
2593
+ # Clear the constraints!
2594
+ base_state.release_plugin("solver")
2595
+
2596
+ # For speed concerns, we are limiting the timeout for z3 solver to 5 seconds
2597
+ base_state.solver._solver.timeout = 5000
2598
+
2599
+ sc = self.project.factory.simulation_manager(base_state)
2600
+ sc.use_technique(Slicecutor(annotated_cfg))
2601
+ sc.use_technique(LoopSeer(bound=1))
2602
+ sc.run()
2603
+
2604
+ if sc.cut or sc.deadended:
2605
+ all_deadended_states = sc.cut + sc.deadended
2606
+ for s in all_deadended_states:
2607
+ if s.addr == sim_successors.addr:
2608
+ # We want to get its successors
2609
+ succs = s.step()
2610
+ for succ in succs.flat_successors:
2611
+ successing_addresses.add(succ.addr)
2612
+
2613
+ else:
2614
+ l.debug("Cannot determine the exit. You need some better ways to recover the exits :-(")
2615
+
2616
+ l.debug("Resolution is done, and we have %d new successors.", len(successing_addresses))
2617
+
2618
+ return list(successing_addresses)
2619
+
2620
+ def _symbolically_back_traverse(self, current_block, block_artifacts, cfg_node):
2621
+ """
2622
+ Symbolically executes from ancestor nodes (2-5 times removed) finding paths of execution through the given
2623
+ CFGNode.
2624
+
2625
+ :param SimSuccessors current_block: SimSuccessor with address to attempt to navigate to.
2626
+ :param dict block_artifacts: Container of IRSB data - specifically used for known persistent register values.
2627
+ :param CFGNode cfg_node: Current node interested around.
2628
+ :returns: Double-checked concrete successors.
2629
+ :rtype: List
2630
+ """
2631
+
2632
+ class RegisterProtector:
2633
+ """
2634
+ A class that prevent specific registers from being overwritten.
2635
+ """
2636
+
2637
+ def __init__(self, reg_offset, info_collection):
2638
+ """
2639
+ Class to overwrite registers.
2640
+
2641
+ :param int reg_offset: Register offset to overwrite from.
2642
+ :param dict info_collection: New register offsets to use (in container).
2643
+ """
2644
+ self._reg_offset = reg_offset
2645
+ self._info_collection = info_collection
2646
+
2647
+ def write_persistent_register(self, state_):
2648
+ """
2649
+ Writes over given registers from self._info_collection (taken from block_artifacts)
2650
+
2651
+ :param SimSuccessors state_: state to update registers for
2652
+ """
2653
+ if state_.inspect.address is None:
2654
+ l.error("state.inspect.address is None. It will be fixed by Yan later.")
2655
+ return
2656
+
2657
+ if state_.registers.load(self._reg_offset).symbolic:
2658
+ current_run = state_.inspect.address
2659
+ if current_run in self._info_collection and not state_.solver.symbolic(
2660
+ self._info_collection[current_run][self._reg_offset]
2661
+ ):
2662
+ l.debug(
2663
+ "Overwriting %s with %s",
2664
+ state_.registers.load(self._reg_offset),
2665
+ self._info_collection[current_run][self._reg_offset],
2666
+ )
2667
+ state_.registers.store(self._reg_offset, self._info_collection[current_run][self._reg_offset])
2668
+
2669
+ l.debug("Start back traversal from %s", current_block)
2670
+
2671
+ # Create a partial CFG first
2672
+ temp_cfg = networkx.DiGraph(self.graph)
2673
+ # Reverse it
2674
+ temp_cfg.reverse(copy=False)
2675
+
2676
+ path_length = 0
2677
+ concrete_exits = []
2678
+ if cfg_node not in temp_cfg.nodes():
2679
+ # TODO: Figure out why this is happening
2680
+ return concrete_exits
2681
+
2682
+ keep_running = True
2683
+ while not concrete_exits and path_length < 5 and keep_running:
2684
+ path_length += 1
2685
+ queue = [cfg_node]
2686
+ avoid = set()
2687
+ for _ in range(path_length):
2688
+ new_queue = []
2689
+ for n in queue:
2690
+ successors = list(temp_cfg.successors(n))
2691
+ for suc in successors:
2692
+ jk = temp_cfg.get_edge_data(n, suc)["jumpkind"]
2693
+ if jk != "Ijk_Ret":
2694
+ # We don't want to trace into libraries
2695
+ predecessors = list(temp_cfg.predecessors(suc))
2696
+ avoid |= {p.addr for p in predecessors if p is not n}
2697
+ new_queue.append(suc)
2698
+ queue = new_queue
2699
+
2700
+ if path_length <= 1:
2701
+ continue
2702
+
2703
+ for n in queue:
2704
+ # Start symbolic exploration from each block
2705
+ state = self.project.factory.blank_state(
2706
+ addr=n.addr,
2707
+ mode="symbolic",
2708
+ add_options={
2709
+ o.DO_RET_EMULATION,
2710
+ o.CONSERVATIVE_READ_STRATEGY,
2711
+ }
2712
+ | o.resilience,
2713
+ )
2714
+ # Avoid concretization of any symbolic read address that is over a certain limit
2715
+ # TODO: test case is needed for this option
2716
+
2717
+ # Set initial values of persistent regs
2718
+ if n.addr in block_artifacts:
2719
+ for reg in state.arch.persistent_regs:
2720
+ state.registers.store(reg, block_artifacts[n.addr][reg])
2721
+ for reg in state.arch.persistent_regs:
2722
+ reg_protector = RegisterProtector(reg, block_artifacts)
2723
+ state.inspect.add_breakpoint(
2724
+ "reg_write",
2725
+ BP(
2726
+ BP_AFTER,
2727
+ reg_write_offset=state.arch.registers[reg][0],
2728
+ action=reg_protector.write_persistent_register,
2729
+ ),
2730
+ )
2731
+ simgr = self.project.factory.simulation_manager(state)
2732
+ simgr.use_technique(LoopSeer(bound=10))
2733
+ simgr.use_technique(Explorer(find=current_block.addr, avoid=avoid))
2734
+ simgr.use_technique(LengthLimiter(path_length))
2735
+ simgr.run()
2736
+
2737
+ if simgr.found:
2738
+ simgr = self.project.factory.simulation_manager(simgr.one_found, save_unsat=True)
2739
+ simgr.step()
2740
+ if simgr.active or simgr.unsat:
2741
+ keep_running = False
2742
+ concrete_exits.extend(simgr.active)
2743
+ concrete_exits.extend(simgr.unsat)
2744
+ if keep_running:
2745
+ l.debug("Step back for one more run...")
2746
+
2747
+ # Make sure these successors are actually concrete
2748
+ # We just use the ip, persistent registers, and jumpkind to initialize the original unsat state
2749
+ # TODO: It works for jumptables, but not for calls. We should also handle changes in sp
2750
+ new_concrete_successors = []
2751
+ for c in concrete_exits:
2752
+ unsat_state = current_block.unsat_successors[0].copy()
2753
+ unsat_state.history.jumpkind = c.history.jumpkind
2754
+ for reg in [*unsat_state.arch.persistent_regs, "ip"]:
2755
+ unsat_state.registers.store(reg, c.registers.load(reg))
2756
+ new_concrete_successors.append(unsat_state)
2757
+
2758
+ return new_concrete_successors
2759
+
2760
+ def _get_symbolic_function_initial_state(self, function_addr, fastpath_mode_state=None):
2761
+ """
2762
+ Symbolically execute the first basic block of the specified function,
2763
+ then returns it. We prepares the state using the already existing
2764
+ state in fastpath mode (if available).
2765
+ :param function_addr: The function address
2766
+ :return: A symbolic state if succeeded, None otherwise
2767
+ """
2768
+ if function_addr is None:
2769
+ return None
2770
+
2771
+ if function_addr in self._symbolic_function_initial_state:
2772
+ return self._symbolic_function_initial_state[function_addr]
2773
+
2774
+ if fastpath_mode_state is not None:
2775
+ fastpath_state = fastpath_mode_state
2776
+ else:
2777
+ if function_addr in self._function_input_states:
2778
+ fastpath_state = self._function_input_states[function_addr]
2779
+ else:
2780
+ raise AngrCFGError("The impossible happened. Please report to Fish.")
2781
+
2782
+ symbolic_initial_state = self.project.factory.entry_state(mode="symbolic")
2783
+ if fastpath_state is not None:
2784
+ symbolic_initial_state = self.project.simos.prepare_call_state(
2785
+ fastpath_state, initial_state=symbolic_initial_state
2786
+ )
2787
+
2788
+ # Find number of instructions of start block
2789
+ func = self.project.kb.functions.get(function_addr)
2790
+ start_block = func._get_block(function_addr)
2791
+ num_instr = start_block.instructions - 1
2792
+
2793
+ symbolic_initial_state.ip = function_addr
2794
+ path = self.project.factory.path(symbolic_initial_state)
2795
+ try:
2796
+ sim_successors = self.project.factory.successors(path.state, num_inst=num_instr)
2797
+ except (SimError, AngrError):
2798
+ return None
2799
+
2800
+ # We execute all but the last instruction in this basic block, so we have a cleaner
2801
+ # state
2802
+ # Start execution!
2803
+ exits = sim_successors.flat_successors + sim_successors.unsat_successors
2804
+
2805
+ if exits:
2806
+ final_st = None
2807
+ for ex in exits:
2808
+ if ex.satisfiable():
2809
+ final_st = ex
2810
+ break
2811
+ else:
2812
+ final_st = None
2813
+
2814
+ self._symbolic_function_initial_state[function_addr] = final_st
2815
+
2816
+ return final_st
2817
+
2818
+ # Private methods - function hints
2819
+
2820
+ def _search_for_function_hints(self, successor_state):
2821
+ """
2822
+ Scan for constants that might be used as exit targets later, and add them into pending_exits.
2823
+
2824
+ :param SimState successor_state: A successing state.
2825
+ :return: A list of discovered code addresses.
2826
+ :rtype: list
2827
+ """
2828
+
2829
+ function_hints = []
2830
+
2831
+ for action in successor_state.history.recent_actions:
2832
+ if action.type == "reg" and action.offset == self.project.arch.ip_offset:
2833
+ # Skip all accesses to IP registers
2834
+ continue
2835
+ if action.type == "exit":
2836
+ # only consider read/write actions
2837
+ continue
2838
+
2839
+ # Enumerate actions
2840
+ if isinstance(action, SimActionData):
2841
+ data = action.data
2842
+ if data is not None:
2843
+ # TODO: Check if there is a proper way to tell whether this const falls in the range of code
2844
+ # TODO: segments
2845
+ # Now let's live with this big hack...
2846
+ try:
2847
+ const = successor_state.solver.eval_one(data.ast)
2848
+ except Exception: # pylint:disable=broad-exception-caught
2849
+ continue
2850
+
2851
+ if self._is_address_executable(const):
2852
+ if self._pending_function_hints is not None and const in self._pending_function_hints:
2853
+ continue
2854
+
2855
+ # target = const
2856
+ # tpl = (None, None, target)
2857
+ # st = self.project._simos.prepare_call_state(self.project.initial_state(mode='fastpath'),
2858
+ # initial_state=saved_state)
2859
+ # st = self.project.initial_state(mode='fastpath')
2860
+ # exits[tpl] = (st, None, None)
2861
+
2862
+ function_hints.append(const)
2863
+
2864
+ l.debug(
2865
+ "Got %d possible exits, including: %s", len(function_hints), ", ".join([f"0x{f:x}" for f in function_hints])
2866
+ )
2867
+
2868
+ return function_hints
2869
+
2870
+ # Private methods - creation of stuff (SimSuccessors, CFGNode, call-stack, etc.)
2871
+
2872
+ def _get_simsuccessors(self, addr, job, current_function_addr=None):
2873
+ """
2874
+ Create the SimSuccessors instance for a block.
2875
+
2876
+ :param int addr: Address of the block.
2877
+ :param CFGJob job: The CFG job instance with an input state inside.
2878
+ :param int current_function_addr: Address of the current function.
2879
+ :return: A SimSuccessors instance
2880
+ :rtype: SimSuccessors
2881
+ """
2882
+
2883
+ exception_info = None
2884
+ state = job.state
2885
+ saved_state = job.state # We don't have to make a copy here
2886
+
2887
+ # respect the basic block size from base graph
2888
+ block_size = None
2889
+ if self._base_graph is not None:
2890
+ for n in self._base_graph.nodes():
2891
+ if n.addr == addr:
2892
+ block_size = n.size
2893
+ break
2894
+
2895
+ try:
2896
+ sim_successors = None
2897
+
2898
+ if not self._keep_state:
2899
+ if self.project.is_hooked(addr):
2900
+ old_proc = self.project._sim_procedures[addr]
2901
+ is_continuation = old_proc.is_continuation
2902
+ elif self.project.simos.is_syscall_addr(addr):
2903
+ old_proc = self.project.simos.syscall_from_addr(addr)
2904
+ is_continuation = False # syscalls don't support continuation
2905
+ else:
2906
+ old_proc = None
2907
+ is_continuation = None
2908
+
2909
+ if old_proc is not None and not is_continuation and not old_proc.ADDS_EXITS and not old_proc.NO_RET:
2910
+ # DON'T CREATE USELESS SIMPROCEDURES if we don't care about the accuracy of states
2911
+ # When generating CFG, a SimProcedure will not be created as it is but be created as a
2912
+ # ReturnUnconstrained stub if it satisfies the following conditions:
2913
+ # - It doesn't add any new exits.
2914
+ # - It returns as normal.
2915
+ # In this way, we can speed up the CFG generation by quite a lot as we avoid simulating
2916
+ # those functions like read() and puts(), which has no impact on the overall control flow at all.
2917
+ #
2918
+ # Special notes about SimProcedure continuation: Any SimProcedure instance that is a continuation
2919
+ # will add new exits, otherwise the original SimProcedure wouldn't have been executed anyway. Hence
2920
+ # it's reasonable for us to always simulate a SimProcedure with continuation.
2921
+
2922
+ old_name = None
2923
+
2924
+ if old_proc.is_syscall:
2925
+ new_stub = SIM_PROCEDURES["stubs"]["syscall"]
2926
+ ret_to = state.regs.ip_at_syscall
2927
+ else:
2928
+ # normal SimProcedures
2929
+ new_stub = SIM_PROCEDURES["stubs"]["ReturnUnconstrained"]
2930
+ ret_to = None
2931
+
2932
+ old_name = old_proc.display_name
2933
+
2934
+ # instantiate the stub
2935
+ new_stub_inst = new_stub(display_name=old_name)
2936
+
2937
+ sim_successors = self.project.factory.procedure_engine.process(
2938
+ state,
2939
+ procedure=new_stub_inst,
2940
+ force_addr=addr,
2941
+ ret_to=ret_to,
2942
+ )
2943
+
2944
+ if sim_successors is None:
2945
+ jumpkind = state.history.jumpkind
2946
+ jumpkind = "Ijk_Boring" if jumpkind is None else jumpkind
2947
+ sim_successors = self.project.factory.successors(
2948
+ state, jumpkind=jumpkind, size=block_size, opt_level=self._iropt_level
2949
+ )
2950
+
2951
+ except (SimFastPathError, SimSolverModeError) as ex:
2952
+ if saved_state.mode == "fastpath":
2953
+ # Got a SimFastPathError or SimSolverModeError in FastPath mode.
2954
+ # We wanna switch to symbolic mode for current IRSB.
2955
+ l.debug("Switch to symbolic mode for address %#x", addr)
2956
+ # Make a copy of the current 'fastpath' state
2957
+
2958
+ l.debug("Symbolic jumps at basic block %#x.", addr)
2959
+
2960
+ new_state = None
2961
+ if addr != current_function_addr:
2962
+ new_state = self._get_symbolic_function_initial_state(current_function_addr)
2963
+
2964
+ if new_state is None:
2965
+ new_state = state.copy()
2966
+ new_state.set_mode("symbolic")
2967
+ new_state.options.add(o.DO_RET_EMULATION)
2968
+ # Remove bad constraints
2969
+ # FIXME: This is so hackish...
2970
+ preserved_constraints = [
2971
+ c for c in new_state.solver.constraints if c.op != "BoolV" or c.args[0] is not False
2972
+ ]
2973
+ new_solver = new_state.solver._solver.blank_copy()
2974
+ new_solver.add(preserved_constraints)
2975
+ new_state.solver._stored_solver = new_solver
2976
+
2977
+ # Swap them
2978
+ saved_state, job.state = job.state, new_state
2979
+ sim_successors, exception_info, _ = self._get_simsuccessors(addr, job)
2980
+
2981
+ else:
2982
+ exception_info = sys.exc_info()
2983
+ # Got a SimSolverModeError in symbolic mode. We are screwed.
2984
+ # Skip this IRSB
2985
+ l.debug("Caught a SimIRSBError %s. Don't panic, this is usually expected.", ex)
2986
+ inst = SIM_PROCEDURES["stubs"]["PathTerminator"]()
2987
+ sim_successors = ProcedureEngine(self.project).process(state, procedure=inst)
2988
+
2989
+ except SimIRSBError:
2990
+ exception_info = sys.exc_info()
2991
+ # It's a tragedy that we came across some instructions that VEX
2992
+ # does not support. I'll create a terminating stub there
2993
+ l.debug("Caught a SimIRSBError during CFG recovery. Creating a PathTerminator.", exc_info=True)
2994
+ inst = SIM_PROCEDURES["stubs"]["PathTerminator"]()
2995
+ sim_successors = ProcedureEngine(self.project).process(state, procedure=inst)
2996
+
2997
+ except claripy.ClaripyError:
2998
+ exception_info = sys.exc_info()
2999
+ l.debug("Caught a ClaripyError during CFG recovery. Don't panic, this is usually expected.", exc_info=True)
3000
+ # Generate a PathTerminator to terminate the current path
3001
+ inst = SIM_PROCEDURES["stubs"]["PathTerminator"]()
3002
+ sim_successors = ProcedureEngine(self.project).process(state, procedure=inst)
3003
+
3004
+ except SimError:
3005
+ exception_info = sys.exc_info()
3006
+ l.debug("Caught a SimError during CFG recovery. Don't panic, this is usually expected.", exc_info=True)
3007
+ # Generate a PathTerminator to terminate the current path
3008
+ inst = SIM_PROCEDURES["stubs"]["PathTerminator"]()
3009
+ sim_successors = ProcedureEngine(self.project).process(state, procedure=inst)
3010
+
3011
+ except AngrExitError:
3012
+ exception_info = sys.exc_info()
3013
+ l.debug("Caught a AngrExitError during CFG recovery. Don't panic, this is usually expected.", exc_info=True)
3014
+ # Generate a PathTerminator to terminate the current path
3015
+ inst = SIM_PROCEDURES["stubs"]["PathTerminator"]()
3016
+ sim_successors = ProcedureEngine(self.project).process(state, procedure=inst)
3017
+
3018
+ except AngrError:
3019
+ exception_info = sys.exc_info()
3020
+ section = self.project.loader.main_object.find_section_containing(addr)
3021
+ sec_name = "No section" if section is None else section.name
3022
+ # AngrError shouldn't really happen though
3023
+ l.debug("Caught an AngrError during CFG recovery at %#x (%s)", addr, sec_name, exc_info=True)
3024
+ # We might be on a wrong branch, and is likely to encounter the
3025
+ # "No bytes in memory xxx" exception
3026
+ # Just ignore it
3027
+ sim_successors = None
3028
+
3029
+ return sim_successors, exception_info, saved_state
3030
+
3031
+ def _create_new_call_stack(self, addr, all_jobs, job, exit_target, jumpkind):
3032
+ """
3033
+ Creates a new call stack, and according to the jumpkind performs appropriate actions.
3034
+
3035
+ :param int addr: Address to create at.
3036
+ :param Simsuccessors all_jobs: Jobs to get stack pointer from or return address.
3037
+ :param CFGJob job: CFGJob to copy current call stack from.
3038
+ :param int exit_target: Address of exit target.
3039
+ :param str jumpkind: The type of jump performed.
3040
+ :returns: New call stack for target block.
3041
+ :rtype: CallStack
3042
+ """
3043
+
3044
+ if self._is_call_jumpkind(jumpkind):
3045
+ new_call_stack = job.call_stack_copy()
3046
+ # Notice that in ARM, there are some freaking instructions
3047
+ # like
3048
+ # BLEQ <address>
3049
+ # It should give us three exits: Ijk_Call, Ijk_Boring, and
3050
+ # Ijk_Ret. The last exit is simulated.
3051
+ # Notice: We assume the last exit is the simulated one
3052
+ if len(all_jobs) > 1 and all_jobs[-1].history.jumpkind == "Ijk_FakeRet":
3053
+ se = all_jobs[-1].solver
3054
+ retn_target_addr = se.eval_one(all_jobs[-1].ip, default=0)
3055
+ sp = se.eval_one(all_jobs[-1].regs.sp, default=0)
3056
+
3057
+ new_call_stack = new_call_stack.call(addr, exit_target, retn_target=retn_target_addr, stack_pointer=sp)
3058
+
3059
+ elif jumpkind.startswith("Ijk_Sys") and len(all_jobs) == 1:
3060
+ # This is a syscall. It returns to the same address as itself (with a different jumpkind)
3061
+ retn_target_addr = exit_target
3062
+ se = all_jobs[0].solver
3063
+ sp = se.eval_one(all_jobs[0].regs.sp, default=0)
3064
+ new_call_stack = new_call_stack.call(addr, exit_target, retn_target=retn_target_addr, stack_pointer=sp)
3065
+
3066
+ else:
3067
+ # We don't have a fake return exit available, which means
3068
+ # this call doesn't return.
3069
+ new_call_stack = CallStack()
3070
+ se = all_jobs[-1].solver
3071
+ sp = se.eval_one(all_jobs[-1].regs.sp, default=0)
3072
+
3073
+ new_call_stack = new_call_stack.call(addr, exit_target, retn_target=None, stack_pointer=sp)
3074
+
3075
+ elif jumpkind == "Ijk_Ret":
3076
+ # Normal return
3077
+ new_call_stack = job.call_stack_copy()
3078
+ with contextlib.suppress(SimEmptyCallStackError):
3079
+ new_call_stack = new_call_stack.ret(exit_target)
3080
+
3081
+ se = all_jobs[-1].solver
3082
+ sp = se.eval_one(all_jobs[-1].regs.sp, default=0)
3083
+ old_sp = job.current_stack_pointer
3084
+
3085
+ # Calculate the delta of stack pointer
3086
+ if sp is not None and old_sp is not None:
3087
+ delta = sp - old_sp
3088
+ func_addr = job.func_addr
3089
+
3090
+ if self.kb.functions.function(func_addr) is None:
3091
+ # Create the function if it doesn't exist
3092
+ # FIXME: But hell, why doesn't it exist in the first place?
3093
+ l.error(
3094
+ "Function 0x%x doesn't exist in function manager although it should be there."
3095
+ "Look into this issue later.",
3096
+ func_addr,
3097
+ )
3098
+ self.kb.functions.function(func_addr, create=True)
3099
+
3100
+ # Set sp_delta of the function
3101
+ self.kb.functions.function(func_addr, create=True).sp_delta = delta
3102
+
3103
+ elif jumpkind == "Ijk_FakeRet":
3104
+ # The fake return...
3105
+ new_call_stack = job.call_stack
3106
+
3107
+ else:
3108
+ # although the jumpkind is not Ijk_Call, it may still jump to a new function... let's see
3109
+ if self.project.is_hooked(exit_target):
3110
+ hooker = self.project.hooked_by(exit_target)
3111
+ if hooker is not procedures.stubs.UserHook.UserHook:
3112
+ # if it's not a UserHook, it must be a function
3113
+ # Update the function address of the most recent call stack frame
3114
+ new_call_stack = job.call_stack_copy()
3115
+ new_call_stack.current_function_address = exit_target
3116
+
3117
+ else:
3118
+ # TODO: We need a way to mark if a user hook is a function or not
3119
+ # TODO: We can add a map in Project to store this information
3120
+ # For now we are just assuming they are not functions, which is mostly the case
3121
+ new_call_stack = job.call_stack
3122
+
3123
+ else:
3124
+ # Normal control flow transition
3125
+ new_call_stack = job.call_stack
3126
+
3127
+ return new_call_stack
3128
+
3129
+ def _create_cfgnode(self, sim_successors, call_stack, func_addr, block_id=None, depth=None, exception_info=None):
3130
+ """
3131
+ Create a context-sensitive CFGNode instance for a specific block.
3132
+
3133
+ :param SimSuccessors sim_successors: The SimSuccessors object.
3134
+ :param CallStack call_stack_suffix: The call stack.
3135
+ :param int func_addr: Address of the current function.
3136
+ :param BlockID block_id: The block ID of this CFGNode.
3137
+ :param int or None depth: Depth of this CFGNode.
3138
+ :return: A CFGNode instance.
3139
+ :rtype: CFGNode
3140
+ """
3141
+
3142
+ sa = sim_successors.artifacts # shorthand
3143
+
3144
+ # Determine if this is a SimProcedure, and further, if this is a syscall
3145
+ syscall = None
3146
+ is_syscall = False
3147
+ if sim_successors.sort == "SimProcedure":
3148
+ is_simprocedure = True
3149
+ if sa["is_syscall"] is True:
3150
+ is_syscall = True
3151
+ syscall = sim_successors.artifacts["procedure"]
3152
+ else:
3153
+ is_simprocedure = False
3154
+
3155
+ if is_simprocedure:
3156
+ simproc_name = sa["name"].split(".")[-1]
3157
+ if simproc_name == "ReturnUnconstrained" and "resolves" in sa and sa["resolves"] is not None:
3158
+ simproc_name = sa["resolves"]
3159
+
3160
+ no_ret = False
3161
+ if syscall is not None and sa["no_ret"]:
3162
+ no_ret = True
3163
+
3164
+ cfg_node = CFGENode(
3165
+ sim_successors.addr,
3166
+ None,
3167
+ self.model,
3168
+ callstack_key=call_stack.stack_suffix(self.context_sensitivity_level),
3169
+ input_state=None,
3170
+ simprocedure_name=simproc_name,
3171
+ syscall_name=syscall,
3172
+ no_ret=no_ret,
3173
+ is_syscall=is_syscall,
3174
+ function_address=sim_successors.addr,
3175
+ block_id=block_id,
3176
+ depth=depth,
3177
+ creation_failure_info=exception_info,
3178
+ thumb=(isinstance(self.project.arch, ArchARM) and sim_successors.addr & 1),
3179
+ )
3180
+
3181
+ else:
3182
+ cfg_node = CFGENode(
3183
+ sim_successors.addr,
3184
+ sa["irsb_size"],
3185
+ self.model,
3186
+ callstack_key=call_stack.stack_suffix(self.context_sensitivity_level),
3187
+ input_state=None,
3188
+ is_syscall=is_syscall,
3189
+ function_address=func_addr,
3190
+ block_id=block_id,
3191
+ depth=depth,
3192
+ irsb=sim_successors.artifacts["irsb"],
3193
+ creation_failure_info=exception_info,
3194
+ thumb=(isinstance(self.project.arch, ArchARM) and sim_successors.addr & 1),
3195
+ )
3196
+
3197
+ return cfg_node
3198
+
3199
+ # Private methods - loops and graph normalization
3200
+
3201
+ def _detect_loops(self, loop_callback=None):
3202
+ """
3203
+ Loop detection.
3204
+
3205
+ :param func loop_callback: A callback function for each detected loop backedge.
3206
+ :return: None
3207
+ """
3208
+
3209
+ loop_finder = self.project.analyses[LoopFinder].prep(kb=self.kb, fail_fast=self._fail_fast)(normalize=False)
3210
+
3211
+ if loop_callback is not None:
3212
+ graph_copy = networkx.DiGraph(self._graph)
3213
+
3214
+ loop: angr.analyses.loopfinder.Loop
3215
+ for loop in loop_finder.loops:
3216
+ loop_callback(graph_copy, loop)
3217
+
3218
+ self.model.graph = graph_copy
3219
+
3220
+ # Update loop backedges and graph
3221
+ self._loop_back_edges = list(itertools.chain.from_iterable(loop.continue_edges for loop in loop_finder.loops))
3222
+
3223
+ # Private methods - dominators and post-dominators
3224
+
3225
+ def _immediate_dominators(self, node, target_graph=None, reverse_graph=False):
3226
+ """
3227
+ Get all immediate dominators of sub graph from given node upwards.
3228
+
3229
+ :param str node: id of the node to navigate forwards from.
3230
+ :param networkx.classes.digraph.DiGraph target_graph: graph to analyse, default is self.graph.
3231
+ :param bool reverse_graph: Whether the target graph should be reversed before analysation.
3232
+
3233
+ :return: each node of graph as index values, with element as respective node's immediate dominator.
3234
+ :rtype: dict
3235
+ """
3236
+ if target_graph is None:
3237
+ target_graph = self.graph
3238
+
3239
+ if node not in target_graph:
3240
+ raise AngrCFGError(f"Target node {node} is not in graph.")
3241
+
3242
+ graph = networkx.DiGraph(target_graph)
3243
+ if reverse_graph:
3244
+ # Reverse the graph without deepcopy
3245
+ for n in target_graph.nodes():
3246
+ graph.add_node(n)
3247
+ for src, dst in target_graph.edges():
3248
+ graph.add_edge(dst, src)
3249
+
3250
+ idom = {node: node}
3251
+
3252
+ order = list(networkx.dfs_postorder_nodes(graph, node))
3253
+ dfn = {u: i for i, u in enumerate(order)}
3254
+ order.pop()
3255
+ order.reverse()
3256
+
3257
+ def intersect(u_, v_):
3258
+ """
3259
+ Finds the highest (in postorder valuing) point of intersection above two node arguments.
3260
+
3261
+ :param str u_: nx node id.
3262
+ :param str v_: nx node id.
3263
+ :return: intersection of paths.
3264
+ :rtype: str
3265
+ """
3266
+ while u_ != v_:
3267
+ while dfn[u_] < dfn[v_]:
3268
+ u_ = idom[u_]
3269
+ while dfn[u_] > dfn[v_]:
3270
+ v_ = idom[v_]
3271
+ return u_
3272
+
3273
+ changed = True
3274
+ while changed:
3275
+ changed = False
3276
+ for u in order:
3277
+ new_idom = reduce(intersect, (v for v in graph.pred[u] if v in idom))
3278
+ if u not in idom or idom[u] != new_idom:
3279
+ idom[u] = new_idom
3280
+ changed = True
3281
+
3282
+ return idom
3283
+
3284
+ #
3285
+ # Static private utility methods
3286
+ #
3287
+
3288
+ @staticmethod
3289
+ def _is_indirect_jump(_, sim_successors):
3290
+ """
3291
+ Determine if this SimIRSB has an indirect jump as its exit
3292
+ """
3293
+
3294
+ if sim_successors.artifacts["irsb_direct_next"]:
3295
+ # It's a direct jump
3296
+ return False
3297
+
3298
+ default_jumpkind = sim_successors.artifacts["irsb_default_jumpkind"]
3299
+
3300
+ # If false, it's something else, like a ret of a syscall... we don't care about it
3301
+ return not (default_jumpkind not in ("Ijk_Call", "Ijk_Boring", "Ijk_InvalICache"))
3302
+
3303
+ @staticmethod
3304
+ def _generate_block_id(call_stack_suffix, block_addr, is_syscall):
3305
+ if not is_syscall:
3306
+ return BlockID.new(block_addr, call_stack_suffix, "normal")
3307
+ return BlockID.new(block_addr, call_stack_suffix, "syscall")
3308
+
3309
+ @staticmethod
3310
+ def _block_id_repr(block_id):
3311
+ return repr(block_id)
3312
+
3313
+ @staticmethod
3314
+ def _block_id_callstack_key(block_id):
3315
+ return block_id.callsite_tuples
3316
+
3317
+ @staticmethod
3318
+ def _block_id_addr(block_id):
3319
+ return block_id.addr
3320
+
3321
+ @staticmethod
3322
+ def _block_id_current_func_addr(block_id):
3323
+ """
3324
+ If we don't have any information about the caller, we have no way to get the address of the current function.
3325
+
3326
+ :param BlockID block_id: The block ID.
3327
+ :return: The function address if there is one, or None if it's not possible to get.
3328
+ :rtype: int or None
3329
+ """
3330
+
3331
+ if block_id.callsite_tuples:
3332
+ return block_id.callsite_tuples[-1]
3333
+ return None
3334
+
3335
+ #
3336
+ # Other private utility methods
3337
+ #
3338
+
3339
+ @staticmethod
3340
+ def _is_call_jumpkind(jumpkind):
3341
+ return bool(jumpkind == "Ijk_Call" or jumpkind.startswith("Ijk_Sys_"))
3342
+
3343
+ def _push_unresolvable_run(self, block_address):
3344
+ """
3345
+ Adds this block to the list of unresolvable runs.
3346
+
3347
+ :param dict block_address: container of IRSB data from run.
3348
+ """
3349
+ self._unresolvable_runs.add(block_address)
3350
+
3351
+ def _is_address_executable(self, address):
3352
+ """
3353
+ Check if the specific address is in one of the executable ranges.
3354
+
3355
+ :param int address: The address
3356
+ :return: True if it's in an executable range, False otherwise
3357
+ """
3358
+
3359
+ return any(r[0] <= address < r[1] for r in self._executable_address_ranges)
3360
+
3361
+ def _update_thumb_addrs(self, simsuccessors, state):
3362
+ """
3363
+
3364
+ :return:
3365
+ """
3366
+
3367
+ # For ARM THUMB mode
3368
+ if simsuccessors.sort == "IRSB" and state.thumb:
3369
+ insn_addrs = simsuccessors.artifacts["insn_addrs"]
3370
+ self._thumb_addrs.update(insn_addrs)
3371
+ self._thumb_addrs.update(x + 1 for x in insn_addrs) # pylint:disable=bad-builtin
3372
+
3373
+ def _get_callsites(self, function_address):
3374
+ """
3375
+ Get where a specific function is called.
3376
+ :param function_address: Address of the target function
3377
+ :return: A list of CFGNodes whose exits include a call/jump to the given function
3378
+ """
3379
+
3380
+ all_predecessors = []
3381
+
3382
+ nodes = self.model.get_all_nodes(function_address)
3383
+ for n in nodes:
3384
+ predecessors = list(self.model.get_predecessors(n))
3385
+ all_predecessors.extend(predecessors)
3386
+
3387
+ return all_predecessors
3388
+
3389
+ def _get_nx_paths(self, begin, end):
3390
+ """
3391
+ Get the possible (networkx) simple paths between two nodes or addresses
3392
+ corresponding to nodes.
3393
+ Input: addresses or node instances
3394
+ Return: a list of lists of nodes representing paths.
3395
+ """
3396
+ if isinstance(begin, int) and isinstance(end, int):
3397
+ n_begin = self.model.get_any_node(begin)
3398
+ n_end = self.model.get_any_node(end)
3399
+
3400
+ elif isinstance(begin, CFGENode) and isinstance(end, CFGENode):
3401
+ n_begin = begin
3402
+ n_end = end
3403
+ else:
3404
+ raise AngrCFGError("from and to should be of the same type")
3405
+
3406
+ self.remove_fakerets()
3407
+ return networkx.all_shortest_paths(self.graph, n_begin, n_end)
3408
+
3409
+ def _quasi_topological_sort(self):
3410
+ """
3411
+ Perform a quasi-topological sort on an already constructed CFG graph (a networkx DiGraph)
3412
+
3413
+ :return: None
3414
+ """
3415
+
3416
+ # Clear the existing sorting result
3417
+ self._quasi_topological_order = {}
3418
+
3419
+ ctr = self._graph.number_of_nodes()
3420
+
3421
+ for ep in self._entry_points:
3422
+ # FIXME: This is not always correct. We'd better store CFGNodes in self._entry_points
3423
+ ep_node = self.model.get_any_node(ep)
3424
+
3425
+ if not ep_node:
3426
+ continue
3427
+
3428
+ for n in networkx.dfs_postorder_nodes(self._graph, source=ep_node):
3429
+ if n not in self._quasi_topological_order:
3430
+ self._quasi_topological_order[n] = ctr
3431
+ ctr -= 1
3432
+
3433
+ def _reset_state_mode(self, state, mode):
3434
+ """
3435
+ Reset the state mode to the given mode, and apply the custom state options specified with this analysis.
3436
+
3437
+ :param state: The state to work with.
3438
+ :param str mode: The state mode.
3439
+ :return: None
3440
+ """
3441
+
3442
+ state.set_mode(mode)
3443
+ state.options |= self._state_add_options
3444
+ state.options = state.options.difference(self._state_remove_options)
3445
+
3446
+
3447
+ AnalysesHub.register_default("CFGEmulated", CFGEmulated)