angr 9.2.103__py3-none-manylinux2014_aarch64.whl

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

Potentially problematic release.


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

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