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,1899 @@
1
+ import binascii
2
+ import copy
3
+ import ctypes
4
+ import itertools
5
+ import logging
6
+ import os
7
+ import sys
8
+ import threading
9
+ import time
10
+
11
+ import cffi # lmao
12
+
13
+ import archinfo
14
+ import claripy
15
+ import pyvex
16
+ from angr.engines.vex.claripy import ccall
17
+ from angr.sim_state import SimState
18
+
19
+ from .. import sim_options as options
20
+ from ..engines.vex.claripy.irop import operations as irop_ops
21
+ from ..errors import SimMemoryError, SimSegfaultError, SimUnicornError, SimUnicornUnsupport, SimValueError
22
+ from ..misc.testing import is_testing
23
+ from .plugin import SimStatePlugin
24
+
25
+ l = logging.getLogger(name=__name__)
26
+ ffi = cffi.FFI()
27
+
28
+ try:
29
+ import unicorn
30
+ except ImportError:
31
+ l.warning("Unicorn is not installed. Support disabled.")
32
+ unicorn = None
33
+
34
+
35
+ class MEM_PATCH(ctypes.Structure):
36
+ """
37
+ struct mem_update_t
38
+ """
39
+
40
+
41
+ MEM_PATCH._fields_ = [("address", ctypes.c_uint64), ("length", ctypes.c_uint64), ("next", ctypes.POINTER(MEM_PATCH))]
42
+
43
+
44
+ class TRANSMIT_RECORD(ctypes.Structure):
45
+ """
46
+ struct transmit_record_t
47
+ """
48
+
49
+ _fields_ = [("fd", ctypes.c_uint32), ("data", ctypes.c_void_p), ("count", ctypes.c_uint32)]
50
+
51
+
52
+ class TaintEntityEnum:
53
+ """
54
+ taint_entity_enum_t
55
+ """
56
+
57
+ TAINT_ENTITY_REG = 0
58
+ TAINT_ENTITY_TMP = 1
59
+ TAINT_ENTITY_MEM = 2
60
+ TAINT_ENTITY_NONE = 3
61
+
62
+
63
+ class MemoryValue(ctypes.Structure):
64
+ """
65
+ struct memory_value_t
66
+ """
67
+
68
+ _MAX_MEM_ACCESS_SIZE = 8
69
+
70
+ _fields_ = [
71
+ ("address", ctypes.c_uint64),
72
+ ("value", ctypes.c_uint8),
73
+ ("is_value_set", ctypes.c_bool),
74
+ ("is_value_symbolic", ctypes.c_bool),
75
+ ]
76
+
77
+
78
+ class RegisterValue(ctypes.Structure):
79
+ """
80
+ struct register_value_t
81
+ """
82
+
83
+ _MAX_REGISTER_BYTE_SIZE = 32
84
+
85
+ _fields_ = [
86
+ ("offset", ctypes.c_uint64),
87
+ ("value", ctypes.c_uint8 * _MAX_REGISTER_BYTE_SIZE),
88
+ ("size", ctypes.c_int64),
89
+ ]
90
+
91
+
92
+ class VEXStmtDetails(ctypes.Structure):
93
+ """
94
+ struct sym_vex_stmt_details_t
95
+ """
96
+
97
+ _fields_ = [
98
+ ("stmt_idx", ctypes.c_int64),
99
+ ("has_memory_dep", ctypes.c_bool),
100
+ ("memory_values", ctypes.POINTER(MemoryValue)),
101
+ ("memory_values_count", ctypes.c_uint64),
102
+ ]
103
+
104
+
105
+ class BlockDetails(ctypes.Structure):
106
+ """
107
+ struct sym_block_details_ret_t
108
+ """
109
+
110
+ _fields_ = [
111
+ ("block_addr", ctypes.c_uint64),
112
+ ("block_size", ctypes.c_uint64),
113
+ ("block_trace_ind", ctypes.c_int64),
114
+ ("has_symbolic_exit", ctypes.c_bool),
115
+ ("symbolic_vex_stmts", ctypes.POINTER(VEXStmtDetails)),
116
+ ("symbolic_vex_stmts_count", ctypes.c_uint64),
117
+ ("register_values", ctypes.POINTER(RegisterValue)),
118
+ ("register_values_count", ctypes.c_uint64),
119
+ ]
120
+
121
+
122
+ class STOP:
123
+ """
124
+ enum stop_t
125
+ """
126
+
127
+ STOP_NORMAL = 0
128
+ STOP_STOPPOINT = 1
129
+ STOP_ERROR = 2
130
+ STOP_SYSCALL = 3
131
+ STOP_EXECNONE = 4
132
+ STOP_ZEROPAGE = 5
133
+ STOP_NOSTART = 6
134
+ STOP_SEGFAULT = 7
135
+ STOP_ZERO_DIV = 8
136
+ STOP_NODECODE = 9
137
+ STOP_HLT = 10
138
+ STOP_VEX_LIFT_FAILED = 11
139
+ STOP_SYMBOLIC_PC = 12
140
+ STOP_SYMBOLIC_READ_ADDR = 13
141
+ STOP_SYMBOLIC_READ_SYMBOLIC_TRACKING_DISABLED = 14
142
+ STOP_SYMBOLIC_WRITE_ADDR = 15
143
+ STOP_SYMBOLIC_BLOCK_EXIT_CONDITION = 16
144
+ STOP_SYMBOLIC_BLOCK_EXIT_TARGET = 17
145
+ STOP_UNSUPPORTED_STMT_PUTI = 18
146
+ STOP_UNSUPPORTED_STMT_STOREG = 19
147
+ STOP_UNSUPPORTED_STMT_LOADG = 20
148
+ STOP_UNSUPPORTED_STMT_CAS = 21
149
+ STOP_UNSUPPORTED_STMT_LLSC = 22
150
+ STOP_UNSUPPORTED_STMT_DIRTY = 23
151
+ STOP_UNSUPPORTED_EXPR_GETI = 24
152
+ STOP_UNSUPPORTED_STMT_UNKNOWN = 25
153
+ STOP_UNSUPPORTED_EXPR_UNKNOWN = 26
154
+ STOP_UNKNOWN_MEMORY_WRITE_SIZE = 27
155
+ STOP_SYSCALL_ARM = 28
156
+ STOP_X86_CPUID = 29
157
+
158
+ stop_message = {}
159
+ stop_message[STOP_NORMAL] = "Reached maximum steps"
160
+ stop_message[STOP_STOPPOINT] = "Hit a stop point"
161
+ stop_message[STOP_ERROR] = "Something wrong"
162
+ stop_message[STOP_SYSCALL] = "Unable to handle syscall"
163
+ stop_message[STOP_EXECNONE] = "Fetching empty page"
164
+ stop_message[STOP_ZEROPAGE] = "Accessing zero page"
165
+ stop_message[STOP_NOSTART] = "Failed to start"
166
+ stop_message[STOP_SEGFAULT] = "Permissions or mapping error"
167
+ stop_message[STOP_ZERO_DIV] = "Divide by zero"
168
+ stop_message[STOP_NODECODE] = "Instruction decoding error"
169
+ stop_message[STOP_HLT] = "hlt instruction encountered"
170
+ stop_message[STOP_VEX_LIFT_FAILED] = "Failed to lift block to VEX"
171
+ stop_message[STOP_SYMBOLIC_PC] = "Instruction pointer became symbolic"
172
+ stop_message[STOP_SYMBOLIC_READ_ADDR] = "Attempted to read from symbolic address"
173
+ stop_message[STOP_SYMBOLIC_READ_SYMBOLIC_TRACKING_DISABLED] = (
174
+ "Attempted to read symbolic data from memory but symbolic tracking is disabled"
175
+ )
176
+ stop_message[STOP_SYMBOLIC_WRITE_ADDR] = "Attempted to write to symbolic address"
177
+ stop_message[STOP_SYMBOLIC_BLOCK_EXIT_CONDITION] = "Guard condition of block's exit statement is symbolic"
178
+ stop_message[STOP_SYMBOLIC_BLOCK_EXIT_TARGET] = "Target of default exit of block is symbolic"
179
+ stop_message[STOP_UNSUPPORTED_STMT_PUTI] = "Symbolic taint propagation for PutI statement not yet supported"
180
+ stop_message[STOP_UNSUPPORTED_STMT_STOREG] = "Symbolic taint propagation for StoreG statement not yet supported"
181
+ stop_message[STOP_UNSUPPORTED_STMT_LOADG] = "Symbolic taint propagation for LoadG statement not yet supported"
182
+ stop_message[STOP_UNSUPPORTED_STMT_CAS] = "Symbolic taint propagation for CAS statement not yet supported"
183
+ stop_message[STOP_UNSUPPORTED_STMT_LLSC] = "Symbolic taint propagation for LLSC statement not yet supported"
184
+ stop_message[STOP_UNSUPPORTED_STMT_DIRTY] = "Symbolic taint propagation for Dirty statement not yet supported"
185
+ stop_message[STOP_UNSUPPORTED_EXPR_GETI] = "Symbolic taint propagation for GetI expression not yet supported"
186
+ stop_message[STOP_UNSUPPORTED_STMT_UNKNOWN] = "Canoo propagate symbolic taint for unsupported VEX statement type"
187
+ stop_message[STOP_UNSUPPORTED_EXPR_UNKNOWN] = "Cannot propagate symbolic taint for unsupported VEX expression"
188
+ stop_message[STOP_UNKNOWN_MEMORY_WRITE_SIZE] = "Unicorn failed to determine size of memory write"
189
+ stop_message[STOP_SYSCALL_ARM] = "ARM syscalls are currently not supported by SimEngineUnicorn"
190
+ stop_message[STOP_X86_CPUID] = "Block executes cpuid which should be handled in VEX engine"
191
+
192
+ symbolic_stop_reasons = {
193
+ STOP_SYMBOLIC_PC,
194
+ STOP_SYMBOLIC_READ_ADDR,
195
+ STOP_SYMBOLIC_READ_SYMBOLIC_TRACKING_DISABLED,
196
+ STOP_SYMBOLIC_WRITE_ADDR,
197
+ STOP_SYMBOLIC_BLOCK_EXIT_CONDITION,
198
+ STOP_SYMBOLIC_BLOCK_EXIT_TARGET,
199
+ STOP_SYSCALL_ARM,
200
+ STOP_X86_CPUID,
201
+ }
202
+
203
+ unsupported_reasons = {
204
+ STOP_UNSUPPORTED_STMT_PUTI,
205
+ STOP_UNSUPPORTED_STMT_STOREG,
206
+ STOP_UNSUPPORTED_STMT_LOADG,
207
+ STOP_UNSUPPORTED_STMT_CAS,
208
+ STOP_UNSUPPORTED_STMT_LLSC,
209
+ STOP_UNSUPPORTED_STMT_DIRTY,
210
+ STOP_UNSUPPORTED_STMT_UNKNOWN,
211
+ STOP_UNSUPPORTED_EXPR_UNKNOWN,
212
+ STOP_VEX_LIFT_FAILED,
213
+ }
214
+
215
+ @staticmethod
216
+ def name_stop(num):
217
+ for item in dir(STOP):
218
+ if item.startswith("STOP_") and getattr(STOP, item) == num:
219
+ return item
220
+ raise ValueError(num)
221
+
222
+ @staticmethod
223
+ def get_stop_msg(stop_reason):
224
+ if stop_reason in STOP.stop_message:
225
+ return STOP.stop_message[stop_reason]
226
+
227
+ return "Unknown stop reason"
228
+
229
+
230
+ class StopDetails(ctypes.Structure):
231
+ """
232
+ struct stop_details_t
233
+ """
234
+
235
+ _fields_ = [
236
+ ("stop_reason", ctypes.c_int),
237
+ ("block_addr", ctypes.c_uint64),
238
+ ("block_size", ctypes.c_uint64),
239
+ ]
240
+
241
+
242
+ class SimOSEnum:
243
+ """
244
+ enum simos_t
245
+ """
246
+
247
+ SIMOS_CGC = 0
248
+ SIMOS_LINUX = 1
249
+ SIMOS_OTHER = 2
250
+
251
+
252
+ #
253
+ # Memory mapping errors - only used internally
254
+ #
255
+
256
+
257
+ class MemoryMappingError(Exception): # pylint: disable=missing-class-docstring
258
+ pass
259
+
260
+
261
+ class AccessingZeroPageError(MemoryMappingError): # pylint: disable=missing-class-docstring
262
+ pass
263
+
264
+
265
+ class FetchingZeroPageError(MemoryMappingError): # pylint: disable=missing-class-docstring
266
+ pass
267
+
268
+
269
+ class SegfaultError(MemoryMappingError): # pylint: disable=missing-class-docstring
270
+ pass
271
+
272
+
273
+ class MixedPermissonsError(MemoryMappingError): # pylint: disable=missing-class-docstring
274
+ pass
275
+
276
+
277
+ #
278
+ # This annotation is added to constraints that Unicorn generates in aggressive concretization mode
279
+ #
280
+
281
+
282
+ class AggressiveConcretizationAnnotation(claripy.SimplificationAvoidanceAnnotation):
283
+ # pylint: disable=missing-class-docstring
284
+ def __init__(self, addr):
285
+ claripy.SimplificationAvoidanceAnnotation.__init__(self)
286
+ self.unicorn_start_addr = addr
287
+
288
+
289
+ #
290
+ # Because Unicorn leaks like crazy, we use one Uc object per thread...
291
+ #
292
+
293
+ _unicounter = itertools.count()
294
+
295
+
296
+ class Uniwrapper(unicorn.Uc if unicorn is not None else object):
297
+ # pylint: disable=non-parent-init-called,missing-class-docstring
298
+ def __init__(self, arch, cache_key, thumb=False):
299
+ l.debug("Creating unicorn state!")
300
+ self.arch = arch
301
+ self.cache_key = cache_key
302
+ self.wrapped_mapped = set()
303
+ self.wrapped_hooks = set()
304
+ self.id = None
305
+ if thumb:
306
+ uc_mode = arch.uc_mode_thumb
307
+ else:
308
+ uc_mode = arch.uc_mode
309
+ unicorn.Uc.__init__(self, arch.uc_arch, uc_mode)
310
+
311
+ def hook_add(self, htype, callback, user_data=None, begin=1, end=0, arg1=0):
312
+ h = unicorn.Uc.hook_add(self, htype, callback, user_data=user_data, begin=begin, end=end, arg1=arg1)
313
+ # l.debug("Hook: %s,%s -> %s", htype, callback.__name__, h)
314
+ self.wrapped_hooks.add(h)
315
+ return h
316
+
317
+ def hook_del(self, h):
318
+ # l.debug("Clearing hook %s", h)
319
+ unicorn.Uc.hook_del(self, h)
320
+ self.wrapped_hooks.discard(h)
321
+ return h
322
+
323
+ def mem_map(self, addr, size, perms=7):
324
+ # l.debug("Mapping %d bytes at %#x", size, addr)
325
+ m = unicorn.Uc.mem_map(self, addr, size, perms=perms)
326
+ self.wrapped_mapped.add((addr, size))
327
+ return m
328
+
329
+ def mem_map_ptr(self, addr, size, perms, ptr):
330
+ m = unicorn.Uc.mem_map_ptr(self, addr, size, perms, ptr)
331
+ self.wrapped_mapped.add((addr, size))
332
+ return m
333
+
334
+ def mem_unmap(self, addr, size):
335
+ # l.debug("Unmapping %d bytes at %#x", size, addr)
336
+ m = unicorn.Uc.mem_unmap(self, addr, size)
337
+ self.wrapped_mapped.discard((addr, size))
338
+ return m
339
+
340
+ def mem_reset(self):
341
+ # l.debug("Resetting memory.")
342
+ for addr, size in self.wrapped_mapped:
343
+ # l.debug("Unmapping %d bytes at %#x", size, addr)
344
+ unicorn.Uc.mem_unmap(self, addr, size)
345
+ self.wrapped_mapped.clear()
346
+
347
+ def hook_reset(self):
348
+ # l.debug("Resetting hooks.")
349
+ for h in self.wrapped_hooks:
350
+ # l.debug("Clearing hook %s", h)
351
+ unicorn.Uc.hook_del(self, h)
352
+ self.wrapped_hooks.clear()
353
+
354
+ def reset(self):
355
+ self.mem_reset()
356
+ # self.hook_reset()
357
+ # l.debug("Reset complete.")
358
+
359
+
360
+ _unicorn_tls = threading.local()
361
+ _unicorn_tls.uc = None
362
+
363
+
364
+ class _VexCacheInfo(ctypes.Structure):
365
+ """
366
+ VexCacheInfo struct from vex
367
+ """
368
+
369
+ _fields_ = [
370
+ ("num_levels", ctypes.c_uint),
371
+ ("num_caches", ctypes.c_uint),
372
+ ("caches", ctypes.c_void_p),
373
+ ("icaches_maintain_coherence", ctypes.c_bool),
374
+ ]
375
+
376
+
377
+ class _VexArchInfo(ctypes.Structure):
378
+ """
379
+ VexArchInfo struct from vex
380
+ """
381
+
382
+ _fields_ = [
383
+ ("hwcaps", ctypes.c_uint),
384
+ ("endness", ctypes.c_int),
385
+ ("hwcache_info", _VexCacheInfo),
386
+ ("ppc_icache_line_szB", ctypes.c_int),
387
+ ("ppc_dcbz_szB", ctypes.c_uint),
388
+ ("ppc_dcbzl_szB", ctypes.c_uint),
389
+ ("arm64_dMinLine_lg2_szB", ctypes.c_uint),
390
+ ("arm64_iMinLine_lg2_szB", ctypes.c_uint),
391
+ ("x86_cr0", ctypes.c_uint),
392
+ ]
393
+
394
+
395
+ def _locate_lib(module: str, library: str) -> str:
396
+ """
397
+ Attempt to find a native library without using pkg_resources, and only fall back to pkg_resources upon failures.
398
+ This is because "import pkg_resources" is slow.
399
+
400
+ :return: The full path of the native library.
401
+ """
402
+ base_dir = os.path.join(os.path.dirname(__file__), "..")
403
+ attempt = os.path.join(base_dir, library)
404
+ if os.path.isfile(attempt):
405
+ return attempt
406
+
407
+ import pkg_resources # pylint:disable=import-outside-toplevel
408
+
409
+ return pkg_resources.resource_filename(module, os.path.join(library))
410
+
411
+
412
+ def _load_native():
413
+ if sys.platform == "darwin":
414
+ libfile = "angr_native.dylib"
415
+ elif sys.platform in {"win32", "cygwin"}:
416
+ libfile = "angr_native.dll"
417
+ else:
418
+ libfile = "angr_native.so"
419
+
420
+ try:
421
+ angr_path = _locate_lib("angr", os.path.join("lib", libfile))
422
+ h = ctypes.CDLL(angr_path)
423
+
424
+ VexArch = ctypes.c_int
425
+ uc_err = ctypes.c_int
426
+ state_t = ctypes.c_void_p
427
+ stop_t = ctypes.c_int
428
+ uc_engine_t = ctypes.c_void_p
429
+
430
+ def _setup_prototype(handle, func, restype, *argtypes):
431
+ realname = "simunicorn_" + func
432
+ _setup_prototype_explicit(handle, realname, restype, *argtypes)
433
+ setattr(handle, func, getattr(handle, realname))
434
+
435
+ def _setup_prototype_explicit(handle, func, restype, *argtypes):
436
+ getattr(handle, func).restype = restype
437
+ getattr(handle, func).argtypes = argtypes
438
+
439
+ # _setup_prototype_explicit(h, 'logSetLogLevel', None, ctypes.c_uint64)
440
+ _setup_prototype(
441
+ h,
442
+ "alloc",
443
+ state_t,
444
+ uc_engine_t,
445
+ ctypes.c_uint64,
446
+ ctypes.c_uint64,
447
+ ctypes.c_bool,
448
+ ctypes.c_bool,
449
+ ctypes.c_bool,
450
+ )
451
+ _setup_prototype(h, "dealloc", None, state_t)
452
+ _setup_prototype(h, "hook", None, state_t)
453
+ _setup_prototype(h, "unhook", None, state_t)
454
+ _setup_prototype(h, "start", uc_err, state_t, ctypes.c_uint64, ctypes.c_uint64)
455
+ _setup_prototype(h, "stop", None, state_t, stop_t)
456
+ _setup_prototype(h, "sync", ctypes.POINTER(MEM_PATCH), state_t)
457
+ _setup_prototype(h, "bbl_addrs", ctypes.POINTER(ctypes.c_uint64), state_t)
458
+ _setup_prototype(h, "stack_pointers", ctypes.POINTER(ctypes.c_uint64), state_t)
459
+ _setup_prototype(h, "bbl_addr_count", ctypes.c_uint64, state_t)
460
+ _setup_prototype(h, "syscall_count", ctypes.c_uint64, state_t)
461
+ _setup_prototype(h, "step", ctypes.c_uint64, state_t)
462
+ _setup_prototype(h, "activate_page", None, state_t, ctypes.c_uint64, ctypes.c_void_p, ctypes.c_void_p)
463
+ _setup_prototype(h, "set_last_block_details", None, state_t, ctypes.c_uint64, ctypes.c_int64, ctypes.c_int64)
464
+ _setup_prototype(h, "set_stops", None, state_t, ctypes.c_uint64, ctypes.POINTER(ctypes.c_uint64))
465
+ _setup_prototype(
466
+ h, "cache_page", ctypes.c_bool, state_t, ctypes.c_uint64, ctypes.c_uint64, ctypes.c_char_p, ctypes.c_uint64
467
+ )
468
+ _setup_prototype(h, "uncache_pages_touching_region", None, state_t, ctypes.c_uint64, ctypes.c_uint64)
469
+ _setup_prototype(h, "clear_page_cache", None, state_t)
470
+ _setup_prototype(h, "enable_symbolic_reg_tracking", None, state_t, VexArch, _VexArchInfo)
471
+ _setup_prototype(h, "disable_symbolic_reg_tracking", None, state_t)
472
+ _setup_prototype(h, "symbolic_register_data", None, state_t, ctypes.c_uint64, ctypes.POINTER(ctypes.c_uint64))
473
+ _setup_prototype(h, "get_symbolic_registers", ctypes.c_uint64, state_t, ctypes.POINTER(ctypes.c_uint64))
474
+ _setup_prototype(h, "is_interrupt_handled", ctypes.c_bool, state_t)
475
+ _setup_prototype(
476
+ h,
477
+ "set_cgc_syscall_details",
478
+ None,
479
+ state_t,
480
+ ctypes.c_uint32,
481
+ ctypes.c_uint64,
482
+ ctypes.c_uint32,
483
+ ctypes.c_uint64,
484
+ ctypes.c_uint64,
485
+ ctypes.c_uint32,
486
+ ctypes.c_uint64,
487
+ )
488
+ _setup_prototype(h, "process_transmit", ctypes.POINTER(TRANSMIT_RECORD), state_t, ctypes.c_uint32)
489
+ _setup_prototype(h, "set_tracking", None, state_t, ctypes.c_bool, ctypes.c_bool)
490
+ _setup_prototype(h, "executed_pages", ctypes.c_uint64, state_t)
491
+ _setup_prototype(h, "in_cache", ctypes.c_bool, state_t, ctypes.c_uint64)
492
+ _setup_prototype(h, "set_map_callback", None, state_t, unicorn.unicorn.UC_HOOK_MEM_INVALID_CB)
493
+ _setup_prototype(
494
+ h,
495
+ "set_vex_to_unicorn_reg_mappings",
496
+ None,
497
+ state_t,
498
+ ctypes.POINTER(ctypes.c_uint64),
499
+ ctypes.POINTER(ctypes.c_uint64),
500
+ ctypes.POINTER(ctypes.c_uint64),
501
+ ctypes.c_uint64,
502
+ )
503
+ _setup_prototype(h, "set_artificial_registers", None, state_t, ctypes.POINTER(ctypes.c_uint64), ctypes.c_uint64)
504
+ _setup_prototype(h, "get_count_of_blocks_with_symbolic_vex_stmts", ctypes.c_uint64, state_t)
505
+ _setup_prototype(
506
+ h, "get_details_of_blocks_with_symbolic_vex_stmts", None, state_t, ctypes.POINTER(BlockDetails)
507
+ )
508
+ _setup_prototype(h, "get_stop_details", StopDetails, state_t)
509
+ _setup_prototype(h, "set_register_blacklist", None, state_t, ctypes.POINTER(ctypes.c_uint64), ctypes.c_uint64)
510
+ _setup_prototype(
511
+ h,
512
+ "set_cpu_flags_details",
513
+ None,
514
+ state_t,
515
+ ctypes.POINTER(ctypes.c_uint64),
516
+ ctypes.POINTER(ctypes.c_uint64),
517
+ ctypes.POINTER(ctypes.c_uint64),
518
+ ctypes.c_uint64,
519
+ )
520
+ _setup_prototype(
521
+ h,
522
+ "set_fd_bytes",
523
+ state_t,
524
+ ctypes.c_uint64,
525
+ ctypes.c_void_p,
526
+ ctypes.c_void_p,
527
+ ctypes.c_uint64,
528
+ ctypes.c_uint64,
529
+ )
530
+ _setup_prototype(
531
+ h,
532
+ "set_random_syscall_data",
533
+ None,
534
+ state_t,
535
+ ctypes.POINTER(ctypes.c_uint64),
536
+ ctypes.POINTER(ctypes.c_uint64),
537
+ ctypes.c_uint64,
538
+ )
539
+ _setup_prototype(
540
+ h,
541
+ "set_vex_cc_reg_data",
542
+ None,
543
+ state_t,
544
+ ctypes.POINTER(ctypes.c_uint64),
545
+ ctypes.POINTER(ctypes.c_uint64),
546
+ ctypes.c_uint64,
547
+ )
548
+ _setup_prototype(h, "get_count_of_writes_to_reexecute", ctypes.c_uint64, state_t)
549
+ _setup_prototype(
550
+ h,
551
+ "get_concrete_writes_to_reexecute",
552
+ None,
553
+ state_t,
554
+ ctypes.POINTER(ctypes.c_uint64),
555
+ ctypes.POINTER(ctypes.c_uint8),
556
+ )
557
+ _setup_prototype(
558
+ h,
559
+ "set_fp_regs_fp_ops_vex_codes",
560
+ None,
561
+ state_t,
562
+ ctypes.c_uint64,
563
+ ctypes.c_uint64,
564
+ ctypes.POINTER(ctypes.c_uint64),
565
+ ctypes.c_uint32,
566
+ )
567
+
568
+ l.info("native plugin is enabled")
569
+
570
+ return h
571
+ except (OSError, AttributeError) as e:
572
+ l.warning('failed loading "%s", unicorn support disabled (%s)', libfile, e)
573
+ raise ImportError("Unable to import native SimUnicorn support") from e
574
+
575
+
576
+ try:
577
+ _UC_NATIVE = _load_native()
578
+ # _UC_NATIVE.logSetLogLevel(2)
579
+ except ImportError:
580
+ _UC_NATIVE = None
581
+
582
+
583
+ class Unicorn(SimStatePlugin):
584
+ """
585
+ setup the unicorn engine for a state
586
+ """
587
+
588
+ UC_CONFIG = {} # config cache for each arch
589
+
590
+ def __init__(
591
+ self,
592
+ syscall_hooks=None,
593
+ cache_key=None,
594
+ unicount=None,
595
+ symbolic_var_counts=None,
596
+ symbolic_inst_counts=None,
597
+ concretized_asts=None,
598
+ always_concretize=None,
599
+ never_concretize=None,
600
+ concretize_at=None,
601
+ concretization_threshold_memory=None,
602
+ concretization_threshold_registers=None,
603
+ concretization_threshold_instruction=None,
604
+ cooldown_symbolic_stop=2,
605
+ cooldown_unsupported_stop=2,
606
+ cooldown_nonunicorn_blocks=100,
607
+ cooldown_stop_point=1,
608
+ max_steps=1000000,
609
+ ):
610
+ """
611
+ Initializes the Unicorn plugin for angr. This plugin handles communication with
612
+ UnicornEngine.
613
+ """
614
+
615
+ SimStatePlugin.__init__(self)
616
+
617
+ self._syscall_pc = None
618
+ self.jumpkind = "Ijk_Boring"
619
+ self.error = None
620
+ self.errno = 0
621
+ self.trap_ip = None
622
+
623
+ self.cache_key = hash(self) if cache_key is None else cache_key
624
+
625
+ # cooldowns to avoid thrashing in and out of unicorn
626
+ # the countdown vars are the CURRENT counter that is counting down
627
+ # when they hit zero execution will start
628
+ # the cooldown vars are the settings for what the countdown should start at
629
+ # the val is copied from cooldown to countdown on check fail
630
+ self.cooldown_nonunicorn_blocks = cooldown_nonunicorn_blocks
631
+ self.cooldown_symbolic_stop = cooldown_symbolic_stop
632
+ self.cooldown_unsupported_stop = cooldown_unsupported_stop
633
+ self.cooldown_stop_point = cooldown_stop_point
634
+ self.countdown_nonunicorn_blocks = 0
635
+ self.countdown_symbolic_stop = 0
636
+ self.countdown_unsupported_stop = 0
637
+ self.countdown_stop_point = 0
638
+
639
+ # the default step limit
640
+ self.max_steps = max_steps
641
+
642
+ self.steps = 0
643
+ self._mapped = 0
644
+ self._uncache_regions = []
645
+ self._symbolic_offsets = None
646
+ self.gdt = None
647
+
648
+ # following variables are used in python level hook
649
+ # we cannot see native hooks from python
650
+ self.syscall_hooks = {} if syscall_hooks is None else syscall_hooks
651
+
652
+ # native state in libsimunicorn
653
+ self._uc_state = None
654
+ self.stop_reason = None
655
+ self.stop_details = None
656
+ self.stop_message = None
657
+
658
+ # this is the counter for the unicorn count
659
+ self._unicount = next(_unicounter) if unicount is None else unicount
660
+
661
+ #
662
+ # Selective concretization stuff
663
+ #
664
+
665
+ # this is the number of times specific symbolic variables have kicked us out of unicorn
666
+ self.symbolic_var_counts = {} if symbolic_var_counts is None else symbolic_var_counts
667
+
668
+ # this is the number of times we've been kept out of unicorn at given instructions
669
+ self.symbolic_inst_counts = {} if symbolic_inst_counts is None else symbolic_inst_counts
670
+
671
+ # these are threshold for the number of times that we tolerate being kept out of unicorn
672
+ # before we start concretizing
673
+ self.concretization_threshold_memory = concretization_threshold_memory
674
+ self.concretization_threshold_registers = concretization_threshold_registers
675
+ self.concretization_threshold_instruction = concretization_threshold_instruction
676
+
677
+ # these are sets of names of variables that should either always or never
678
+ # be concretized
679
+ self.always_concretize = set() if always_concretize is None else always_concretize
680
+ self.never_concretize = set() if never_concretize is None else never_concretize
681
+ self.concretize_at = set() if concretize_at is None else concretize_at
682
+
683
+ # this is a record of the ASTs for which we've added concretization constraints
684
+ self._concretized_asts = set() if concretized_asts is None else concretized_asts
685
+
686
+ # the address to use for concrete transmits
687
+ self.cgc_transmit_addr = None
688
+
689
+ # the address for CGC receive
690
+ self.cgc_receive_addr = None
691
+
692
+ # the address for CGC random
693
+ self.cgc_random_addr = None
694
+
695
+ self.time = None
696
+
697
+ self._bullshit_cb = ctypes.cast(
698
+ unicorn.unicorn.UC_HOOK_MEM_INVALID_CB(self._hook_mem_unmapped), unicorn.unicorn.UC_HOOK_MEM_INVALID_CB
699
+ )
700
+
701
+ @SimStatePlugin.memo
702
+ def copy(self, _memo):
703
+ u = Unicorn(
704
+ syscall_hooks=dict(self.syscall_hooks),
705
+ cache_key=self.cache_key,
706
+ # unicount=self._unicount,
707
+ symbolic_var_counts=dict(self.symbolic_var_counts),
708
+ symbolic_inst_counts=dict(self.symbolic_inst_counts),
709
+ concretized_asts=set(self._concretized_asts),
710
+ always_concretize=set(self.always_concretize),
711
+ never_concretize=set(self.never_concretize),
712
+ concretize_at=set(self.concretize_at),
713
+ concretization_threshold_memory=self.concretization_threshold_memory,
714
+ concretization_threshold_registers=self.concretization_threshold_registers,
715
+ concretization_threshold_instruction=self.concretization_threshold_instruction,
716
+ cooldown_nonunicorn_blocks=self.cooldown_nonunicorn_blocks,
717
+ cooldown_symbolic_stop=self.cooldown_symbolic_stop,
718
+ cooldown_unsupported_stop=self.cooldown_unsupported_stop,
719
+ max_steps=self.max_steps,
720
+ )
721
+ u.countdown_nonunicorn_blocks = self.countdown_nonunicorn_blocks
722
+ u.countdown_symbolic_stop = self.countdown_symbolic_stop
723
+ u.countdown_unsupported_stop = self.countdown_unsupported_stop
724
+ u.countdown_stop_point = self.countdown_stop_point
725
+ u.cgc_receive_addr = self.cgc_receive_addr
726
+ u.cgc_random_addr = self.cgc_random_addr
727
+ u.cgc_transmit_addr = self.cgc_transmit_addr
728
+ u._uncache_regions = list(self._uncache_regions)
729
+ u.gdt = self.gdt
730
+ return u
731
+
732
+ def merge(self, others, merge_conditions, common_ancestor=None): # pylint: disable=unused-argument
733
+ self.cooldown_nonunicorn_blocks = max(
734
+ self.cooldown_nonunicorn_blocks, max(o.cooldown_nonunicorn_blocks for o in others)
735
+ )
736
+ self.cooldown_symbolic_stop = max(self.cooldown_symbolic_stop, max(o.cooldown_symbolic_stop for o in others))
737
+ self.cooldown_unsupported_stop = max(
738
+ self.cooldown_unsupported_stop, max(o.cooldown_unsupported_stop for o in others)
739
+ )
740
+ self.countdown_nonunicorn_blocks = max(
741
+ self.countdown_nonunicorn_blocks, max(o.countdown_nonunicorn_blocks for o in others)
742
+ )
743
+ self.countdown_symbolic_stop = max(self.countdown_symbolic_stop, max(o.countdown_symbolic_stop for o in others))
744
+ self.countdown_unsupported_stop = max(
745
+ self.countdown_unsupported_stop, max(o.countdown_unsupported_stop for o in others)
746
+ )
747
+ self.countdown_stop_point = max(self.countdown_stop_point, max(o.countdown_stop_point for o in others))
748
+
749
+ # get a fresh unicount, just in case
750
+ self._unicount = next(_unicounter)
751
+
752
+ # keep these guys, since merging them sounds like a pain
753
+ # self.symbolic_var_counts
754
+ # self.symbolic_inst_counts
755
+
756
+ # these are threshold for the number of times that we tolerate being kept out of unicorn
757
+ # before we start concretizing
758
+ def merge_nullable_min(*args):
759
+ nonnull = [a for a in args if a is not None]
760
+ if not nonnull:
761
+ return None
762
+ return min(nonnull)
763
+
764
+ self.concretization_threshold_memory = merge_nullable_min(
765
+ self.concretization_threshold_memory, *(o.concretization_threshold_memory for o in others)
766
+ )
767
+ self.concretization_threshold_registers = merge_nullable_min(
768
+ self.concretization_threshold_registers, *(o.concretization_threshold_registers for o in others)
769
+ )
770
+ self.concretization_threshold_instruction = merge_nullable_min(
771
+ self.concretization_threshold_instruction, *(o.concretization_threshold_instruction for o in others)
772
+ )
773
+
774
+ # these are sets of names of variables that should either always or never
775
+ # be concretized
776
+ self.always_concretize.union(*[o.always_concretize for o in others])
777
+ self.never_concretize.union(*[o.never_concretize for o in others])
778
+ self.concretize_at.union(*[o.concretize_at for o in others])
779
+
780
+ # intersect these so that we know to add future constraints properly
781
+ self._concretized_asts.intersection(*[o._concretized_asts for o in others])
782
+
783
+ # I guess always lie to the static analysis?
784
+ return False
785
+
786
+ def widen(self, others): # pylint: disable=unused-argument
787
+ l.warning("Can't widen the unicorn plugin!")
788
+
789
+ def __getstate__(self):
790
+ d = dict(self.__dict__)
791
+ del d["_bullshit_cb"]
792
+ del d["_uc_state"]
793
+ del d["cache_key"]
794
+ del d["_unicount"]
795
+ return d
796
+
797
+ def __setstate__(self, s):
798
+ self.__dict__.update(s)
799
+ self._bullshit_cb = ctypes.cast(
800
+ unicorn.unicorn.UC_HOOK_MEM_INVALID_CB(self._hook_mem_unmapped), unicorn.unicorn.UC_HOOK_MEM_INVALID_CB
801
+ )
802
+ self._unicount = next(_unicounter)
803
+ self._uc_state = None
804
+ self.cache_key = hash(self)
805
+ _unicorn_tls.uc = None
806
+
807
+ def set_state(self, state):
808
+ SimStatePlugin.set_state(self, state)
809
+ if self._is_mips32:
810
+ self._unicount = next(_unicounter)
811
+
812
+ @property
813
+ def _reuse_unicorn(self):
814
+ return not self._is_mips32
815
+
816
+ @property
817
+ def uc(self):
818
+ new_id = next(_unicounter)
819
+ is_thumb = self.state.arch.qemu_name == "arm" and self.state.arch.is_thumb(self.state.addr)
820
+ if (
821
+ not hasattr(_unicorn_tls, "uc")
822
+ or _unicorn_tls.uc is None
823
+ or _unicorn_tls.uc.arch != self.state.arch
824
+ or _unicorn_tls.uc.cache_key != self.cache_key
825
+ ):
826
+ _unicorn_tls.uc = Uniwrapper(self.state.arch, self.cache_key, thumb=is_thumb)
827
+ elif _unicorn_tls.uc.id != self._unicount:
828
+ if not self._reuse_unicorn:
829
+ _unicorn_tls.uc = Uniwrapper(self.state.arch, self.cache_key, thumb=is_thumb)
830
+ else:
831
+ # l.debug("Reusing unicorn state!")
832
+ _unicorn_tls.uc.reset()
833
+ else:
834
+ # l.debug("Reusing unicorn state!")
835
+ pass
836
+
837
+ _unicorn_tls.uc.id = new_id
838
+ self._unicount = new_id
839
+ return _unicorn_tls.uc
840
+
841
+ @staticmethod
842
+ def delete_uc():
843
+ _unicorn_tls.uc = None
844
+
845
+ @property
846
+ def _uc_regs(self):
847
+ return self.state.arch.uc_regs
848
+
849
+ @property
850
+ def _uc_prefix(self):
851
+ return self.state.arch.uc_prefix
852
+
853
+ @property
854
+ def _uc_const(self):
855
+ return self.state.arch.uc_const
856
+
857
+ def _setup_unicorn(self):
858
+ if self.state.arch.uc_mode is None:
859
+ raise SimUnicornUnsupport("unsupported architecture %r" % self.state.arch)
860
+
861
+ def set_last_block_details(self, details):
862
+ _UC_NATIVE.set_last_block_details(self._uc_state, details["addr"], details["curr_count"], details["tot_count"])
863
+
864
+ def set_stops(self, stop_points):
865
+ _UC_NATIVE.set_stops(
866
+ self._uc_state,
867
+ ctypes.c_uint64(len(stop_points)),
868
+ (ctypes.c_uint64 * len(stop_points))(*(ctypes.c_uint64(sp) for sp in stop_points)),
869
+ )
870
+
871
+ def set_tracking(self, track_bbls, track_stack):
872
+ _UC_NATIVE.set_tracking(self._uc_state, track_bbls, track_stack)
873
+
874
+ def hook(self):
875
+ # l.debug('adding native hooks')
876
+ _UC_NATIVE.hook(self._uc_state) # prefer to use native hooks
877
+
878
+ self.uc.hook_add(unicorn.UC_HOOK_MEM_UNMAPPED, self._hook_mem_unmapped, None, 1)
879
+
880
+ arch = self.state.arch.qemu_name
881
+ if arch == "x86_64":
882
+ self.uc.hook_add(unicorn.UC_HOOK_INTR, self._hook_intr_x86, None, 1, 0)
883
+ self.uc.hook_add(
884
+ unicorn.UC_HOOK_INSN, self._hook_syscall_x86_64, None, arg1=self._uc_const.UC_X86_INS_SYSCALL
885
+ )
886
+ elif arch == "i386":
887
+ self.uc.hook_add(unicorn.UC_HOOK_INTR, self._hook_intr_x86, None, 1, 0)
888
+ elif arch == "mips":
889
+ self.uc.hook_add(unicorn.UC_HOOK_INTR, self._hook_intr_mips, None, 1, 0)
890
+ elif arch == "mipsel":
891
+ self.uc.hook_add(unicorn.UC_HOOK_INTR, self._hook_intr_mips, None, 1, 0)
892
+ elif arch == "arm":
893
+ # EDG says: Unicorn's ARM support has no concept of interrupts.
894
+ # This is because interrupts are not a part of the ARM ISA per se, and interrupt controllers
895
+ # are left to the vendor to provide.
896
+ # TODO: This is not true for CortexM. Revisit when Tobi's NVIC implementation gets upstreamed.
897
+ pass
898
+ else:
899
+ raise SimUnicornUnsupport
900
+
901
+ def _hook_intr_mips(self, uc, intno, user_data):
902
+ self.trap_ip = self.uc.reg_read(unicorn.mips_const.UC_MIPS_REG_PC)
903
+
904
+ if intno == 17: # EXCP_SYSCALL
905
+ sysno = uc.reg_read(self._uc_regs["v0"])
906
+ pc = uc.reg_read(self._uc_regs["pc"])
907
+ l.debug("hit sys_%d at %#x", sysno, pc)
908
+ self._syscall_pc = pc
909
+ self._handle_syscall(uc, user_data)
910
+ else:
911
+ l.warning("unhandled interrupt %d", intno)
912
+ _UC_NATIVE.stop(self._uc_state, STOP.STOP_ERROR)
913
+
914
+ def _hook_intr_x86(self, uc, intno, user_data):
915
+ if _UC_NATIVE.is_interrupt_handled(self._uc_state):
916
+ return
917
+
918
+ if self.state.arch.bits == 32:
919
+ self.trap_ip = self.uc.reg_read(unicorn.x86_const.UC_X86_REG_EIP)
920
+ else:
921
+ self.trap_ip = self.uc.reg_read(unicorn.x86_const.UC_X86_REG_RIP)
922
+
923
+ # https://wiki.osdev.org/Exceptions
924
+ if intno == 0:
925
+ # divide by zero
926
+ _UC_NATIVE.stop(self._uc_state, STOP.STOP_ZERO_DIV)
927
+ elif intno == 0x80:
928
+ if self.state.arch.bits == 32:
929
+ self._hook_syscall_i386(uc, user_data)
930
+ else:
931
+ self._hook_syscall_x86_64(uc, user_data)
932
+ else:
933
+ l.warning("unhandled interrupt %d", intno)
934
+ _UC_NATIVE.stop(self._uc_state, STOP.STOP_ERROR)
935
+
936
+ def _hook_syscall_x86_64(self, uc, user_data):
937
+ sysno = uc.reg_read(self._uc_regs["rax"])
938
+ pc = uc.reg_read(self._uc_regs["rip"])
939
+ l.debug("hit sys_%d at %#x", sysno, pc)
940
+ self._syscall_pc = pc + 2 # skip syscall instruction
941
+ self._handle_syscall(uc, user_data)
942
+
943
+ def _hook_syscall_i386(self, uc, user_data):
944
+ sysno = uc.reg_read(self._uc_regs["eax"])
945
+ pc = uc.reg_read(self._uc_regs["eip"])
946
+ l.debug("hit sys_%d at %#x", sysno, pc)
947
+ self._syscall_pc = pc
948
+ if not self._quick_syscall(sysno):
949
+ self._handle_syscall(uc, user_data)
950
+
951
+ def _quick_syscall(self, sysno):
952
+ if sysno in self.syscall_hooks:
953
+ self.syscall_hooks[sysno](self.state)
954
+ return True
955
+ else:
956
+ return False
957
+
958
+ def _handle_syscall(self, uc, user_data): # pylint:disable=unused-argument
959
+ # unicorn does not support syscall, we should giveup emulation
960
+ # and send back to SimProcedure. (ignore is always False)
961
+ l.info("stop emulation")
962
+ self.jumpkind = "Ijk_Sys_syscall"
963
+ _UC_NATIVE.stop(self._uc_state, STOP.STOP_SYSCALL)
964
+
965
+ def _concretize(self, d):
966
+ cd = self.state.solver.eval_to_ast(d, 1)[0]
967
+ if hash(d) not in self._concretized_asts:
968
+ constraint = (d == cd).annotate(AggressiveConcretizationAnnotation(self.state.regs.ip))
969
+ self.state.add_constraints(constraint)
970
+ self._concretized_asts.add(hash(d))
971
+ return cd
972
+
973
+ def _symbolic_passthrough(self, d):
974
+ if not d.symbolic:
975
+ return d
976
+ elif options.UNICORN_AGGRESSIVE_CONCRETIZATION in self.state.options:
977
+ return self._concretize(d)
978
+ elif len(d.variables & self.never_concretize) > 0:
979
+ return d
980
+ elif d.variables.issubset(self.always_concretize):
981
+ return self._concretize(d)
982
+ elif self.state.solver.eval(self.state.ip) in self.concretize_at:
983
+ return self._concretize(d)
984
+ else:
985
+ return d
986
+
987
+ def _report_symbolic_blocker(self, d, from_where):
988
+ if options.UNICORN_THRESHOLD_CONCRETIZATION in self.state.options:
989
+ if self.concretization_threshold_instruction is not None:
990
+ addr = self.state.solver.eval(self.state.ip)
991
+ count = self.symbolic_inst_counts.get(addr, 0)
992
+ l.debug("... inst count for %s: %d", addr, count)
993
+ self.symbolic_inst_counts[addr] = count + 1
994
+ if count >= self.concretization_threshold_instruction:
995
+ self.concretize_at.add(addr)
996
+
997
+ threshold = (
998
+ self.concretization_threshold_memory if from_where == "mem" else self.concretization_threshold_registers
999
+ )
1000
+ if threshold is None:
1001
+ return
1002
+
1003
+ for v in d.variables:
1004
+ old_count = self.symbolic_var_counts.get(v, 0)
1005
+ l.debug("... %s: %d", v, old_count)
1006
+ self.symbolic_var_counts[v] = old_count + 1
1007
+ if old_count >= threshold:
1008
+ self.always_concretize.add(v)
1009
+
1010
+ def _process_value(self, d, from_where):
1011
+ """
1012
+ Pre-process an AST for insertion into unicorn.
1013
+
1014
+ :param d: the AST
1015
+ :param from_where: the ID of the memory region it comes from ('mem' or 'reg')
1016
+ :returns: the value to be inserted into Unicorn, or None
1017
+ """
1018
+ if len(d.annotations):
1019
+ l.debug("Blocking annotated AST.")
1020
+ return None
1021
+ elif not d.symbolic:
1022
+ return d
1023
+ else:
1024
+ l.debug("Processing AST with variables %s.", d.variables)
1025
+
1026
+ dd = self._symbolic_passthrough(d)
1027
+
1028
+ if not dd.symbolic:
1029
+ if d.symbolic:
1030
+ l.debug("... concretized")
1031
+ return dd
1032
+ elif from_where == "reg" and options.UNICORN_SYM_REGS_SUPPORT in self.state.options:
1033
+ l.debug("... allowing symbolic register")
1034
+ return dd
1035
+ else:
1036
+ l.debug("... denied")
1037
+ return None
1038
+
1039
+ def _hook_mem_unmapped(self, uc, access, address, size, value, user_data): # pylint:disable=unused-argument
1040
+ """
1041
+ This callback is called when unicorn needs to access data that's not yet present in memory.
1042
+ """
1043
+ start = address & ~0xFFF
1044
+ needed_pages = 2 if address - start + size > 0x1000 else 1
1045
+
1046
+ attempt_pages = 10
1047
+ for pageno in range(attempt_pages):
1048
+ page_addr = (start + pageno * 0x1000) & ((1 << self.state.arch.bits) - 1)
1049
+ if page_addr == 0:
1050
+ if pageno >= needed_pages:
1051
+ break
1052
+ if options.UNICORN_ZEROPAGE_GUARD in self.state.options:
1053
+ self.error = "accessing zero page (%#x)" % access
1054
+ l.warning(self.error)
1055
+
1056
+ _UC_NATIVE.stop(self._uc_state, STOP.STOP_ZEROPAGE)
1057
+ return False
1058
+
1059
+ l.info("mmap [%#x, %#x] because %d", page_addr, page_addr + 0xFFF, access)
1060
+ try:
1061
+ self._map_one_page(uc, page_addr)
1062
+ except SegfaultError:
1063
+ # this is the unicorn segfault error. idk why this would show up
1064
+ _UC_NATIVE.stop(self._uc_state, STOP.STOP_SEGFAULT)
1065
+ return False
1066
+ except SimSegfaultError:
1067
+ _UC_NATIVE.stop(self._uc_state, STOP.STOP_SEGFAULT)
1068
+ return False
1069
+ except unicorn.UcError as e:
1070
+ if e.errno != 11:
1071
+ self.error = str(e)
1072
+ _UC_NATIVE.stop(self._uc_state, STOP.STOP_ERROR)
1073
+ return False
1074
+ l.info("...already mapped :)")
1075
+ break
1076
+ except SimMemoryError as e:
1077
+ if pageno >= needed_pages:
1078
+ l.info("...never mind")
1079
+ break
1080
+
1081
+ self.error = str(e)
1082
+ _UC_NATIVE.stop(self._uc_state, STOP.STOP_ERROR)
1083
+ return False
1084
+
1085
+ return True
1086
+
1087
+ def _map_one_page(self, _uc, addr):
1088
+ # allow any SimMemory errors to propagate upward. they will be caught immediately above
1089
+ perm = self.state.memory.permissions(addr)
1090
+
1091
+ if perm.op != "BVV":
1092
+ perm = 7
1093
+ elif options.ENABLE_NX not in self.state.options:
1094
+ perm = perm.args[0] | 4
1095
+ else:
1096
+ perm = perm.args[0]
1097
+
1098
+ # this should return two memoryviews
1099
+ # if they are writable they are direct references to the state backing store and can be mapped directly
1100
+ data, bitmap = self.state.memory.concrete_load(addr, 0x1000, with_bitmap=True, writing=(perm & 2) != 0)
1101
+
1102
+ if not bitmap:
1103
+ raise SimMemoryError("No bytes available in memory? when would this happen...")
1104
+
1105
+ if bitmap.readonly:
1106
+ # old-style mapping, do it via copy
1107
+ self.uc.mem_map(addr, 0x1000, perm)
1108
+ # huge hack. why doesn't ctypes let you pass memoryview as void*?
1109
+ unicorn.unicorn._uc.uc_mem_write(
1110
+ self.uc._uch,
1111
+ addr,
1112
+ ctypes.cast(int(ffi.cast("uint64_t", ffi.from_buffer(data))), ctypes.c_void_p),
1113
+ len(data),
1114
+ )
1115
+ # self.uc.mem_write(addr, data)
1116
+ self._mapped += 1
1117
+ _UC_NATIVE.activate_page(self._uc_state, addr, int(ffi.cast("uint64_t", ffi.from_buffer(bitmap))), None)
1118
+ else:
1119
+ # new-style mapping, do it directly
1120
+ self.uc.mem_map_ptr(addr, 0x1000, perm, int(ffi.cast("uint64_t", ffi.from_buffer(data))))
1121
+ self._mapped += 1
1122
+ _UC_NATIVE.activate_page(
1123
+ self._uc_state,
1124
+ addr,
1125
+ int(ffi.cast("uint64_t", ffi.from_buffer(bitmap))),
1126
+ int(ffi.cast("unsigned long", ffi.from_buffer(data))),
1127
+ )
1128
+
1129
+ def _get_details_of_blocks_with_symbolic_vex_stmts(self):
1130
+ def _get_reg_values(register_values):
1131
+ for register_value in register_values:
1132
+ # Convert the register value in bytes to number of appropriate size and endianness
1133
+ reg_name = self.state.arch.register_size_names[(register_value.offset, register_value.size)]
1134
+ if self.state.arch.register_endness == archinfo.Endness.LE:
1135
+ reg_value = int.from_bytes(register_value.value, "little")
1136
+ else:
1137
+ reg_value = int.from_bytes(register_value.value, "big")
1138
+
1139
+ reg_value = reg_value & (pow(2, register_value.size * 8) - 1)
1140
+ yield (reg_name, reg_value)
1141
+
1142
+ def _get_memory_values(memory_values):
1143
+ for memory_value in memory_values:
1144
+ yield {
1145
+ "address": memory_value.address,
1146
+ "value": bytes([memory_value.value]),
1147
+ "symbolic": memory_value.is_value_symbolic,
1148
+ }
1149
+
1150
+ def _get_vex_stmt_details(symbolic_stmts):
1151
+ for instr in symbolic_stmts:
1152
+ instr_entry = {"stmt_idx": instr.stmt_idx, "mem_dep": []}
1153
+ if instr.has_memory_dep:
1154
+ instr_entry["mem_dep"] = _get_memory_values(instr.memory_values[: instr.memory_values_count])
1155
+
1156
+ yield instr_entry
1157
+
1158
+ block_count = _UC_NATIVE.get_count_of_blocks_with_symbolic_vex_stmts(self._uc_state)
1159
+ if block_count == 0:
1160
+ return
1161
+
1162
+ block_details_list = (BlockDetails * block_count)()
1163
+ _UC_NATIVE.get_details_of_blocks_with_symbolic_vex_stmts(self._uc_state, block_details_list)
1164
+ for block_det in block_details_list:
1165
+ entry = {
1166
+ "block_addr": block_det.block_addr,
1167
+ "block_size": block_det.block_size,
1168
+ "block_hist_ind": block_det.block_trace_ind,
1169
+ "has_symbolic_exit": block_det.has_symbolic_exit,
1170
+ }
1171
+ entry["registers"] = _get_reg_values(block_det.register_values[: block_det.register_values_count])
1172
+ entry["stmts"] = _get_vex_stmt_details(block_det.symbolic_vex_stmts[: block_det.symbolic_vex_stmts_count])
1173
+ yield entry
1174
+
1175
+ def uncache_region(self, addr, length):
1176
+ self._uncache_regions.append((addr, length))
1177
+
1178
+ def clear_page_cache(self):
1179
+ self._uncache_regions = [] # this is no longer needed, everything has been uncached
1180
+ _UC_NATIVE.clear_page_cache()
1181
+
1182
+ @property
1183
+ def _is_mips32(self):
1184
+ """
1185
+ There seems to be weird issues with unicorn-engine support on MIPS32 code (see commit 01126bf7). As a result,
1186
+ we test if the current architecture is MIPS32 in several places, and if so, we perform some extra steps, like
1187
+ re-creating the thread-local UC object.
1188
+
1189
+ :return: True if the current architecture is MIPS32, False otherwise.
1190
+ :rtype: bool
1191
+ """
1192
+ return self.state.arch.name == "MIPS32"
1193
+
1194
+ def setup(self, syscall_data=None, fd_bytes=None):
1195
+ if self._is_mips32 and options.COPY_STATES not in self.state.options:
1196
+ # we always re-create the thread-local UC object for MIPS32 even if COPY_STATES is disabled in state
1197
+ # options. this is to avoid some weird bugs in unicorn (e.g., it reports stepping 1 step while in reality it
1198
+ # did not step at all).
1199
+ self.delete_uc()
1200
+ self._setup_unicorn()
1201
+ try:
1202
+ self.set_regs()
1203
+ except SimValueError:
1204
+ # reset the state and re-raise
1205
+ self.uc.reset()
1206
+ raise
1207
+
1208
+ if self.state.os_name == "CGC":
1209
+ simos_val = SimOSEnum.SIMOS_CGC
1210
+ elif self.state.os_name == "Linux":
1211
+ simos_val = SimOSEnum.SIMOS_LINUX
1212
+ else:
1213
+ simos_val = SimOSEnum.SIMOS_OTHER
1214
+
1215
+ # tricky: using unicorn handle from unicorn.Uc object
1216
+ handle_symb_addrs = options.UNICORN_HANDLE_SYMBOLIC_ADDRESSES in self.state.options
1217
+ handle_symb_conds = options.UNICORN_HANDLE_SYMBOLIC_CONDITIONS in self.state.options
1218
+ handle_symbolic_syscalls = options.UNICORN_HANDLE_SYMBOLIC_SYSCALLS in self.state.options
1219
+ self._uc_state = _UC_NATIVE.alloc(
1220
+ self.uc._uch, self.cache_key, simos_val, handle_symb_addrs, handle_symb_conds, handle_symbolic_syscalls
1221
+ )
1222
+
1223
+ if (
1224
+ options.UNICORN_SYM_REGS_SUPPORT in self.state.options
1225
+ and options.UNICORN_AGGRESSIVE_CONCRETIZATION not in self.state.options
1226
+ ):
1227
+ vex_archinfo = copy.deepcopy(self.state.arch.vex_archinfo)
1228
+ vex_archinfo["hwcache_info"]["caches"] = 0
1229
+ vex_archinfo["hwcache_info"] = _VexCacheInfo(**vex_archinfo["hwcache_info"])
1230
+ _UC_NATIVE.enable_symbolic_reg_tracking(
1231
+ self._uc_state,
1232
+ getattr(pyvex.pvc, self.state.arch.vex_arch),
1233
+ _VexArchInfo(**vex_archinfo),
1234
+ )
1235
+
1236
+ if self._symbolic_offsets:
1237
+ l.debug("Symbolic offsets: %s", self._symbolic_offsets)
1238
+ tmp_sym_regs_off = (ctypes.c_uint64(offset) for offset in self._symbolic_offsets)
1239
+ sym_regs_array = (ctypes.c_uint64 * len(self._symbolic_offsets))(*tmp_sym_regs_off)
1240
+ _UC_NATIVE.symbolic_register_data(self._uc_state, len(self._symbolic_offsets), sym_regs_array)
1241
+ else:
1242
+ _UC_NATIVE.symbolic_register_data(self._uc_state, 0, None)
1243
+
1244
+ # set (cgc, for now) transmit and receive syscall handler
1245
+ if self.state.has_plugin("cgc"):
1246
+ cgc_transmit_addr = 0
1247
+ cgc_receive_addr = 0
1248
+ cgc_random_addr = 0
1249
+ if options.UNICORN_HANDLE_CGC_TRANSMIT_SYSCALL in self.state.options:
1250
+ if self.cgc_transmit_addr is None:
1251
+ l.error("You haven't set the address for concrete transmits!!!!!!!!!!!")
1252
+ else:
1253
+ cgc_transmit_addr = self.cgc_transmit_addr
1254
+
1255
+ if options.UNICORN_HANDLE_CGC_RECEIVE_SYSCALL in self.state.options:
1256
+ if self.cgc_receive_addr is None:
1257
+ l.error("You haven't set the address for receive syscall!!!!!!!!!!!!!!")
1258
+ else:
1259
+ cgc_receive_addr = self.cgc_receive_addr
1260
+
1261
+ if options.UNICORN_HANDLE_CGC_RANDOM_SYSCALL in self.state.options and syscall_data is not None:
1262
+ if self.cgc_random_addr is None:
1263
+ l.error("You haven't set the address for random syscall!!!!!!!!!!!!!!")
1264
+ elif "random" not in syscall_data or not syscall_data["random"]:
1265
+ l.error("No syscall data specified for replaying random syscall!!!!!!!!!!!!!!")
1266
+ else:
1267
+ cgc_random_addr = self.cgc_random_addr
1268
+ values = (ctypes.c_uint64(item[0]) for item in syscall_data["random"])
1269
+ sizes = (ctypes.c_uint64(item[1]) for item in syscall_data["random"])
1270
+ values_array = (ctypes.c_uint64 * len(syscall_data["random"]))(*values)
1271
+ sizes_array = (ctypes.c_uint64 * len(syscall_data["random"]))(*sizes)
1272
+ _UC_NATIVE.set_random_syscall_data(
1273
+ self._uc_state, values_array, sizes_array, len(syscall_data["random"])
1274
+ )
1275
+
1276
+ _UC_NATIVE.set_cgc_syscall_details(
1277
+ self._uc_state,
1278
+ 2,
1279
+ cgc_transmit_addr,
1280
+ 3,
1281
+ cgc_receive_addr,
1282
+ self.state.cgc.max_receive_size,
1283
+ 7,
1284
+ cgc_random_addr,
1285
+ )
1286
+
1287
+ # set memory map callback so we can call it explicitly
1288
+ _UC_NATIVE.set_map_callback(self._uc_state, self._bullshit_cb)
1289
+
1290
+ # activate gdt page, which was written/mapped during set_regs
1291
+ if self.gdt is not None:
1292
+ _UC_NATIVE.activate_page(self._uc_state, self.gdt.addr, bytes(0x1000), None)
1293
+
1294
+ # Pass all concrete fd bytes to native interface so that it can handle relevant syscalls
1295
+ if fd_bytes is not None:
1296
+ for fd_num, fd_data in fd_bytes.items():
1297
+ # fd_data is a tuple whose first element is fd data and second is taints for each fd byte
1298
+ fd_bytes_p = int(ffi.cast("uint64_t", ffi.from_buffer(memoryview(fd_data[0]))))
1299
+ fd_taint_p = int(ffi.cast("uint64_t", ffi.from_buffer(memoryview(fd_data[1]))))
1300
+ read_pos = self.state.solver.eval(self.state.posix.fd.get(fd_num).read_pos)
1301
+ _UC_NATIVE.set_fd_bytes(self._uc_state, fd_num, fd_bytes_p, fd_taint_p, len(fd_data[0]), read_pos)
1302
+ else:
1303
+ l.info("Input fds concrete data not specified. Handling some syscalls in native interface could fail.")
1304
+
1305
+ # Initialize list of artificial VEX registers
1306
+ artificial_regs_list = (ctypes.c_uint64(offset) for offset in self.state.arch.artificial_registers_offsets)
1307
+ artifical_regs_count = len(self.state.arch.artificial_registers_offsets)
1308
+ artificial_regs_array = (ctypes.c_uint64 * artifical_regs_count)(*artificial_regs_list)
1309
+ _UC_NATIVE.set_artificial_registers(self._uc_state, artificial_regs_array, artifical_regs_count)
1310
+
1311
+ # Initialize VEX register offset to unicorn register ID mappings and VEX register offset to name map
1312
+ vex_reg_offsets = []
1313
+ unicorn_reg_ids = []
1314
+ reg_sizes = []
1315
+ for vex_reg_offset, (unicorn_reg_id, reg_size) in self.state.arch.vex_to_unicorn_map.items():
1316
+ vex_reg_offsets.append(ctypes.c_uint64(vex_reg_offset))
1317
+ unicorn_reg_ids.append(ctypes.c_uint64(unicorn_reg_id))
1318
+ reg_sizes.append(ctypes.c_uint64(reg_size))
1319
+
1320
+ vex_reg_offsets_array = (ctypes.c_uint64 * len(vex_reg_offsets))(*vex_reg_offsets)
1321
+ unicorn_reg_ids_array = (ctypes.c_uint64 * len(unicorn_reg_ids))(*unicorn_reg_ids)
1322
+ reg_sizes_array = (ctypes.c_uint64 * len(reg_sizes))(*reg_sizes)
1323
+ _UC_NATIVE.set_vex_to_unicorn_reg_mappings(
1324
+ self._uc_state, vex_reg_offsets_array, unicorn_reg_ids_array, reg_sizes_array, len(vex_reg_offsets)
1325
+ )
1326
+
1327
+ # VEX to unicorn mappings for VEX flag registers
1328
+ if self.state.arch.cpu_flag_register_offsets_and_bitmasks_map:
1329
+ flag_vex_offsets = []
1330
+ flag_bitmasks = []
1331
+ flag_uc_regs = []
1332
+ for flag_offset, (uc_reg, bitmask) in self.state.arch.cpu_flag_register_offsets_and_bitmasks_map.items():
1333
+ flag_vex_offsets.append(ctypes.c_uint64(flag_offset))
1334
+ flag_bitmasks.append(ctypes.c_uint64(bitmask))
1335
+ flag_uc_regs.append(ctypes.c_uint64(uc_reg))
1336
+
1337
+ flag_vex_offsets_array = (ctypes.c_uint64 * len(flag_vex_offsets))(*flag_vex_offsets)
1338
+ flag_bitmasks_array = (ctypes.c_uint64 * len(flag_bitmasks))(*flag_bitmasks)
1339
+ flag_uc_regs_array = (ctypes.c_uint64 * len(flag_uc_regs))(*flag_uc_regs)
1340
+ _UC_NATIVE.set_cpu_flags_details(
1341
+ self._uc_state, flag_vex_offsets_array, flag_uc_regs_array, flag_bitmasks_array, len(flag_vex_offsets)
1342
+ )
1343
+ elif self.state.arch.name.startswith("ARM"):
1344
+ l.warning("Flag registers for %s not set in native unicorn interface.", self.state.arch.name)
1345
+
1346
+ # Initialize list of blacklisted registers
1347
+ blacklist_regs_offsets = (ctypes.c_uint64(offset) for offset in self.state.arch.reg_blacklist_offsets)
1348
+ blacklist_regs_count = len(self.state.arch.reg_blacklist_offsets)
1349
+ if blacklist_regs_count > 0:
1350
+ blacklist_regs_array = (ctypes.c_uint64 * blacklist_regs_count)(*blacklist_regs_offsets)
1351
+ _UC_NATIVE.set_register_blacklist(self._uc_state, blacklist_regs_array, blacklist_regs_count)
1352
+
1353
+ # Initialize VEX CC registers data
1354
+ if len(self.state.arch.vex_cc_regs) > 0:
1355
+ cc_regs_offsets = []
1356
+ cc_regs_sizes = []
1357
+ for cc_reg in self.state.arch.vex_cc_regs:
1358
+ cc_regs_offsets.append(ctypes.c_uint64(cc_reg.vex_offset))
1359
+ cc_regs_sizes.append(ctypes.c_uint64(cc_reg.size))
1360
+
1361
+ cc_regs_offsets_array = (ctypes.c_uint64 * len(cc_regs_offsets))(*cc_regs_offsets)
1362
+ cc_regs_sizes_array = (ctypes.c_uint64 * len(cc_regs_offsets))(*cc_regs_sizes)
1363
+ _UC_NATIVE.set_vex_cc_reg_data(
1364
+ self._uc_state, cc_regs_offsets_array, cc_regs_sizes_array, len(cc_regs_offsets)
1365
+ )
1366
+
1367
+ # Set floating point operations VEX codes
1368
+ if options.UNSUPPORTED_FORCE_CONCRETIZE in self.state.options:
1369
+ fp_op_codes = [ctypes.c_uint64(pyvex.irop_enums_to_ints[op.name]) for op in irop_ops.values() if op._float]
1370
+ fp_op_codes_array = (ctypes.c_uint64 * len(fp_op_codes))(*fp_op_codes)
1371
+ fp_reg_start_offset, fp_regs_size = self.state.arch.registers["fpu_regs"]
1372
+ _UC_NATIVE.set_fp_regs_fp_ops_vex_codes(
1373
+ self._uc_state, fp_reg_start_offset, fp_regs_size, fp_op_codes_array, len(fp_op_codes)
1374
+ )
1375
+
1376
+ def start(self, step=None):
1377
+ self.jumpkind = "Ijk_Boring"
1378
+ self.countdown_nonunicorn_blocks = self.cooldown_nonunicorn_blocks
1379
+
1380
+ for addr, length in self._uncache_regions:
1381
+ l.debug("Un-caching writable page region @ %#x of length %x", addr, length)
1382
+ _UC_NATIVE.uncache_pages_touching_region(self._uc_state, addr, length)
1383
+ self._uncache_regions = []
1384
+
1385
+ addr = self.state.solver.eval(self.state.ip)
1386
+ l.info("started emulation at %#x (%d steps)", addr, self.max_steps if step is None else step)
1387
+ self.time = time.time()
1388
+ self.errno = _UC_NATIVE.start(self._uc_state, addr, self.max_steps if step is None else step)
1389
+ self.time = time.time() - self.time
1390
+
1391
+ def get_recent_bbl_addrs(self):
1392
+ steps = _UC_NATIVE.step(self._uc_state)
1393
+ bbl_addrs = _UC_NATIVE.bbl_addrs(self._uc_state)
1394
+ return bbl_addrs[:steps]
1395
+
1396
+ def get_stop_details(self):
1397
+ return _UC_NATIVE.get_stop_details(self._uc_state)
1398
+
1399
+ def finish(self, succ_state):
1400
+ # do the superficial synchronization
1401
+ # If succ_state is not None, synchronize it instead of self.state. Needed when handling symbolic exits in native
1402
+ # interface.
1403
+ self.get_regs(succ_state)
1404
+ if succ_state:
1405
+ state = succ_state
1406
+ unicorn_obj = succ_state.unicorn
1407
+ unicorn_obj.time = self.time
1408
+ unicorn_obj.jumpkind = self.jumpkind
1409
+ unicorn_obj._syscall_pc = self._syscall_pc
1410
+ else:
1411
+ unicorn_obj = self
1412
+ state = self.state
1413
+
1414
+ unicorn_obj.steps = _UC_NATIVE.step(self._uc_state)
1415
+ unicorn_obj.stop_details = _UC_NATIVE.get_stop_details(self._uc_state)
1416
+ unicorn_obj.stop_reason = unicorn_obj.stop_details.stop_reason
1417
+ unicorn_obj.stop_message = STOP.get_stop_msg(unicorn_obj.stop_reason)
1418
+ if unicorn_obj.stop_reason in (
1419
+ STOP.symbolic_stop_reasons | STOP.unsupported_reasons
1420
+ ) or unicorn_obj.stop_reason in {STOP.STOP_UNKNOWN_MEMORY_WRITE_SIZE, STOP.STOP_VEX_LIFT_FAILED}:
1421
+ stop_block_addr = unicorn_obj.stop_details.block_addr
1422
+ stop_block_size = unicorn_obj.stop_details.block_size
1423
+ unicorn_obj.stop_message += f". Block 0x{stop_block_addr:02x}(size: {stop_block_size})."
1424
+
1425
+ # figure out why we stopped
1426
+ if unicorn_obj.stop_reason == STOP.STOP_NOSTART and unicorn_obj.steps > 0:
1427
+ # unicorn just does quits without warning if it sees hlt. detect that.
1428
+ if (state.memory.load(state.ip, 1) == 0xF4).is_true():
1429
+ unicorn_obj.stop_reason = STOP.STOP_HLT
1430
+ else:
1431
+ raise SimUnicornError("Got STOP_NOSTART but steps > 0. This indicates a serious unicorn bug.")
1432
+
1433
+ addr = state.solver.eval(state.ip)
1434
+ l.info(
1435
+ "finished emulation at %#x after %d steps: %s",
1436
+ addr,
1437
+ unicorn_obj.steps,
1438
+ STOP.name_stop(unicorn_obj.stop_reason),
1439
+ )
1440
+
1441
+ # should this be in destroy?
1442
+ _UC_NATIVE.disable_symbolic_reg_tracking(self._uc_state)
1443
+
1444
+ # synchronize memory contents - head is a linked list of memory updates
1445
+ head = _UC_NATIVE.sync(self._uc_state)
1446
+ p_update = head
1447
+ while bool(p_update):
1448
+ update = p_update.contents
1449
+ address, length = update.address, update.length
1450
+ if (
1451
+ unicorn_obj.gdt is not None
1452
+ and unicorn_obj.gdt.addr <= address < unicorn_obj.gdt.addr + unicorn_obj.gdt.limit
1453
+ ):
1454
+ l.warning("Emulation touched fake GDT at %#x, discarding changes", unicorn_obj.gdt.addr)
1455
+ else:
1456
+ s = bytes(self.uc.mem_read(address, int(length)))
1457
+ l.debug("...changed memory: [%#x, %#x] = %s", address, address + length, binascii.hexlify(s))
1458
+ state.memory.store(address, s)
1459
+
1460
+ p_update = update.next
1461
+
1462
+ # process the concrete transmits
1463
+ i = 0
1464
+ stdout = state.posix.get_fd(1)
1465
+ stderr = state.posix.get_fd(2)
1466
+
1467
+ while True:
1468
+ record = _UC_NATIVE.process_transmit(self._uc_state, i)
1469
+ if not bool(record):
1470
+ break
1471
+
1472
+ string = ctypes.string_at(record.contents.data, record.contents.count)
1473
+ if record.contents.fd == 1:
1474
+ stdout.write_data(string)
1475
+ elif record.contents.fd == 2:
1476
+ stderr.write_data(string)
1477
+ i += 1
1478
+
1479
+ # Re-execute concrete writes
1480
+ count_of_writes_to_reexecute = _UC_NATIVE.get_count_of_writes_to_reexecute(self._uc_state)
1481
+ if count_of_writes_to_reexecute > 0:
1482
+ write_addrs = (ctypes.c_uint64 * count_of_writes_to_reexecute)()
1483
+ write_values = (ctypes.c_uint8 * count_of_writes_to_reexecute)()
1484
+ _UC_NATIVE.get_concrete_writes_to_reexecute(self._uc_state, write_addrs, write_values)
1485
+ for address, value in zip(write_addrs, write_values):
1486
+ state.memory.store(address, value, 1)
1487
+
1488
+ if unicorn_obj.stop_reason in {STOP.STOP_NORMAL, STOP.STOP_SYSCALL}:
1489
+ unicorn_obj.countdown_nonunicorn_blocks = 0
1490
+ elif unicorn_obj.stop_reason == STOP.STOP_STOPPOINT:
1491
+ unicorn_obj.countdown_nonunicorn_blocks = 0
1492
+ unicorn_obj.countdown_stop_point = unicorn_obj.cooldown_stop_point
1493
+ elif unicorn_obj.stop_reason in STOP.symbolic_stop_reasons:
1494
+ unicorn_obj.countdown_nonunicorn_blocks = 0
1495
+ unicorn_obj.countdown_symbolic_stop = unicorn_obj.cooldown_symbolic_stop
1496
+ elif unicorn_obj.stop_reason in STOP.unsupported_reasons:
1497
+ unicorn_obj.countdown_nonunicorn_blocks = 0
1498
+ unicorn_obj.countdown_unsupported_stop = unicorn_obj.cooldown_unsupported_stop
1499
+ elif unicorn_obj.stop_reason == STOP.STOP_UNKNOWN_MEMORY_WRITE_SIZE:
1500
+ # Skip one block in case of unknown memory write size
1501
+ unicorn_obj.countdown_nonunicorn_blocks = 0
1502
+ unicorn_obj.countdown_unsupported_stop = 2
1503
+ else:
1504
+ unicorn_obj.countdown_nonunicorn_blocks = unicorn_obj.cooldown_nonunicorn_blocks
1505
+
1506
+ # TODO: make this tunable
1507
+ if not is_testing and unicorn_obj.time != 0 and unicorn_obj.steps / unicorn_obj.time < 10:
1508
+ l.info(
1509
+ "Unicorn stepped %d block%s in %fsec (%f blocks/sec), enabling cooldown",
1510
+ unicorn_obj.steps,
1511
+ "" if unicorn_obj.steps == 1 else "s",
1512
+ unicorn_obj.time,
1513
+ unicorn_obj.steps / unicorn_obj.time,
1514
+ )
1515
+ unicorn_obj.countdown_nonunicorn_blocks = unicorn_obj.cooldown_nonunicorn_blocks
1516
+ else:
1517
+ l.info(
1518
+ "Unicorn stepped %d block%s in %f sec (%f blocks/sec)",
1519
+ unicorn_obj.steps,
1520
+ "" if unicorn_obj.steps == 1 else "s",
1521
+ unicorn_obj.time,
1522
+ unicorn_obj.steps / unicorn_obj.time if unicorn_obj.time != 0 else float("nan"),
1523
+ )
1524
+
1525
+ # get the address list out of the state
1526
+ if options.UNICORN_TRACK_BBL_ADDRS in state.options:
1527
+ bbl_addrs = _UC_NATIVE.bbl_addrs(self._uc_state)
1528
+ # bbl_addr_count = _UC_NATIVE.bbl_addr_count(self._uc_state)
1529
+ # why is bbl_addr_count unused?
1530
+ if unicorn_obj.steps:
1531
+ state.history.recent_bbl_addrs = bbl_addrs[: unicorn_obj.steps]
1532
+ # get the stack pointers
1533
+ if options.UNICORN_TRACK_STACK_POINTERS in state.options:
1534
+ stack_pointers = _UC_NATIVE.stack_pointers(self._uc_state)
1535
+ state.scratch.stack_pointer_list = stack_pointers[: unicorn_obj.steps]
1536
+ # syscall counts
1537
+ state.history.recent_syscall_count = _UC_NATIVE.syscall_count(self._uc_state)
1538
+ # executed page set
1539
+ state.scratch.executed_pages_set = set()
1540
+ while True:
1541
+ page = _UC_NATIVE.executed_pages(self._uc_state)
1542
+ if page == 2**64 - 1:
1543
+ break
1544
+ state.scratch.executed_pages_set.add(page)
1545
+
1546
+ def destroy(self, succ_state):
1547
+ # l.debug("Unhooking.")
1548
+ _UC_NATIVE.unhook(self._uc_state)
1549
+ self.uc.hook_reset()
1550
+
1551
+ # l.debug('deallocting native state %#x', self._uc_state)
1552
+ _UC_NATIVE.dealloc(self._uc_state)
1553
+ self._uc_state = None
1554
+
1555
+ # there's something we're not properly resetting for syscalls, so
1556
+ # we'll clear the state when they happen
1557
+ if self.stop_reason not in {STOP.STOP_NORMAL, STOP.STOP_STOPPOINT}:
1558
+ # If succ_state is not None, reset its unicorn object too
1559
+ if succ_state:
1560
+ succ_state.unicorn.delete_uc()
1561
+
1562
+ self.delete_uc()
1563
+
1564
+ # l.debug("Resetting the unicorn state.")
1565
+ self.uc.reset()
1566
+
1567
+ def set_regs(self):
1568
+ """setting unicorn registers"""
1569
+ uc = self.uc
1570
+
1571
+ self._symbolic_offsets = set()
1572
+
1573
+ if self.state.arch.qemu_name == "x86_64":
1574
+ fs = self.state.solver.eval(self.state.regs.fs)
1575
+ gs = self.state.solver.eval(self.state.regs.gs)
1576
+ self.write_msr(fs, 0xC0000100)
1577
+ self.write_msr(gs, 0xC0000101)
1578
+ elif self.state.arch.qemu_name == "i386":
1579
+ fs = self.state.solver.eval(self.state.regs.fs) << 16
1580
+ gs = self.state.solver.eval(self.state.regs.gs) << 16
1581
+ self.setup_gdt(fs, gs)
1582
+ elif self.state.arch.qemu_name == "mips":
1583
+ # ulr
1584
+ ulr = self.state.regs._ulr
1585
+ uc.reg_write(self._uc_const.UC_MIPS_REG_CP0_USERLOCAL, self.state.solver.eval(ulr))
1586
+
1587
+ self.setup_flags()
1588
+ for r, c in self._uc_regs.items():
1589
+ if r in self.state.arch.reg_blacklist:
1590
+ continue
1591
+ v = self._process_value(getattr(self.state.regs, r), "reg")
1592
+ if v is None:
1593
+ raise SimValueError("setting a symbolic register")
1594
+ # l.debug('setting $%s = %#x', r, self.state.solver.eval(v))
1595
+ uc.reg_write(c, self.state.solver.eval(v))
1596
+
1597
+ start, size = self.state.arch.registers[r]
1598
+ if v.symbolic:
1599
+ symbolic_reg_offsets = set(range(start, start + size))
1600
+ # Process subregisters in decreasing order of their size so that smaller subregisters' taint status
1601
+ # isn't clobbered by larger subregisters
1602
+ subregs = sorted(
1603
+ self.state.arch.get_register_by_name(r).subregisters, key=lambda x: x[-1], reverse=True
1604
+ )
1605
+ for subreg in subregs:
1606
+ if not getattr(self.state.regs, subreg[0]).symbolic:
1607
+ for subreg_offset in range(start + subreg[1], start + subreg[1] + subreg[2]):
1608
+ symbolic_reg_offsets.discard(subreg_offset)
1609
+
1610
+ self._symbolic_offsets.update(symbolic_reg_offsets)
1611
+
1612
+ # TODO: Support ARM hardfloat synchronization
1613
+
1614
+ if self.state.arch.name in {"X86", "AMD64"}:
1615
+ # sync the fp clerical data
1616
+ c3210 = self.state.solver.eval(self.state.regs.fc3210)
1617
+ top = self.state.solver.eval(self.state.regs.ftop[2:0])
1618
+ rm = self.state.solver.eval(self.state.regs.fpround[1:0])
1619
+ control = 0x037F | (rm << 10)
1620
+ status = (top << 11) | c3210
1621
+ uc.reg_write(unicorn.x86_const.UC_X86_REG_FPCW, control)
1622
+ uc.reg_write(unicorn.x86_const.UC_X86_REG_FPSW, status)
1623
+
1624
+ for rn in ("fc3210", "ftop", "fpround"):
1625
+ start, size = self.state.arch.registers[rn]
1626
+ self._symbolic_offsets.difference_update(range(start, start + size))
1627
+
1628
+ # we gotta convert the 64-bit doubles values to 80-bit extended precision!
1629
+ uc_offset = unicorn.x86_const.UC_X86_REG_FP0
1630
+ vex_offset = self.state.arch.registers["fpu_regs"][0]
1631
+ vex_tag_offset = self.state.arch.registers["fpu_tags"][0]
1632
+ tag_word = 0
1633
+ for _ in range(8):
1634
+ tag = self.state.solver.eval(self.state.registers.load(vex_tag_offset, size=1))
1635
+ tag_word <<= 2
1636
+ if tag == 0:
1637
+ tag_word |= 3 # unicorn doesn't care about any value other than 3 for setting
1638
+ else:
1639
+ val = self._process_value(self.state.registers.load(vex_offset, size=8), "reg")
1640
+ if val is None:
1641
+ raise SimValueError("setting a symbolic fp register")
1642
+ if val.symbolic:
1643
+ self._symbolic_offsets.difference_update(
1644
+ b for b, vb in enumerate(val.chop(8), start) if vb.symbolic
1645
+ )
1646
+ val = self.state.solver.eval(val)
1647
+
1648
+ sign = bool(val & 0x8000000000000000)
1649
+ exponent = (val & 0x7FF0000000000000) >> 52
1650
+ mantissa = val & 0x000FFFFFFFFFFFFF
1651
+ if exponent not in {0, 0x7FF}: # normal value
1652
+ exponent = exponent - 1023 + 16383
1653
+ mantissa <<= 11
1654
+ mantissa |= 0x8000000000000000 # set integer part bit, implicit to double
1655
+ elif exponent == 0: # zero or subnormal value
1656
+ mantissa = 0
1657
+ elif exponent == 0x7FF: # nan or infinity
1658
+ exponent = 0x7FFF
1659
+ if mantissa != 0:
1660
+ mantissa = 0x8000000000000000
1661
+ else:
1662
+ mantissa = 0xFFFFFFFFFFFFFFFF
1663
+
1664
+ if sign:
1665
+ exponent |= 0x8000
1666
+
1667
+ uc.reg_write(uc_offset, (exponent, mantissa))
1668
+
1669
+ uc_offset += 1
1670
+ vex_offset += 8
1671
+ vex_tag_offset += 1
1672
+
1673
+ uc.reg_write(unicorn.x86_const.UC_X86_REG_FPTAG, tag_word)
1674
+
1675
+ def setup_flags(self):
1676
+ uc = self.uc
1677
+
1678
+ # Save any symbolic VEX CC registers
1679
+ saved_cc_regs = {}
1680
+ for reg in self.state.arch.vex_cc_regs:
1681
+ reg_val = getattr(self.state.regs, reg.name)
1682
+ if reg_val.symbolic:
1683
+ saved_cc_regs[reg.name] = reg_val
1684
+ setattr(self.state.regs, reg.name, self.state.solver.eval(reg_val))
1685
+
1686
+ if saved_cc_regs:
1687
+ vex_offset = self.state.arch.registers["cc_op"][0]
1688
+ self._symbolic_offsets.update(range(vex_offset, vex_offset + self.state.arch.bytes * 4))
1689
+
1690
+ if self.state.arch.qemu_name in ["i386", "x86_64"]:
1691
+ flags = self._process_value(self.state.regs.eflags, "reg")
1692
+ if flags is None:
1693
+ raise SimValueError("symbolic eflags")
1694
+
1695
+ uc.reg_write(self._uc_const.UC_X86_REG_EFLAGS, self.state.solver.eval(flags))
1696
+
1697
+ elif self.state.arch.qemu_name == "arm":
1698
+ flags = self._process_value(self.state.regs.flags, "reg")
1699
+ if flags is None:
1700
+ raise SimValueError("symbolic cpsr")
1701
+
1702
+ uc.reg_write(self._uc_const.UC_ARM_REG_CPSR, self.state.solver.eval(flags))
1703
+
1704
+ # Restore saved symbolic VEX CC registers
1705
+ for reg_name, saved_reg_val in saved_cc_regs.items():
1706
+ setattr(self.state.regs, reg_name, saved_reg_val)
1707
+
1708
+ def setup_gdt(self, fs, gs):
1709
+ gdt = self.state.project.simos.generate_gdt(fs, gs)
1710
+ uc = self.uc
1711
+
1712
+ uc.mem_map(gdt.addr, gdt.limit)
1713
+ uc.mem_write(gdt.addr + 8, gdt.table)
1714
+ uc.reg_write(self._uc_const.UC_X86_REG_GDTR, (0, gdt.addr, gdt.limit, 0x0))
1715
+
1716
+ uc.reg_write(self._uc_const.UC_X86_REG_CS, gdt.cs)
1717
+ uc.reg_write(self._uc_const.UC_X86_REG_DS, gdt.ds)
1718
+ uc.reg_write(self._uc_const.UC_X86_REG_ES, gdt.es)
1719
+ uc.reg_write(self._uc_const.UC_X86_REG_SS, gdt.ss)
1720
+ uc.reg_write(self._uc_const.UC_X86_REG_FS, gdt.fs)
1721
+ uc.reg_write(self._uc_const.UC_X86_REG_GS, gdt.gs)
1722
+ # if programs want to access this memory....... let them
1723
+ # uc.mem_unmap(GDT_ADDR, GDT_LIMIT)
1724
+
1725
+ self.gdt = gdt
1726
+
1727
+ # do NOT call either of these functions in a callback, lmao
1728
+ def read_msr(self, msr=0xC0000100):
1729
+ setup_code = b"\x0f\x32"
1730
+ BASE = 0x100B000000
1731
+
1732
+ uc = self.uc
1733
+ uc.mem_map(BASE, 0x1000)
1734
+ uc.mem_write(BASE, setup_code)
1735
+ uc.reg_write(self._uc_const.UC_X86_REG_RCX, msr)
1736
+ uc.emu_start(BASE, BASE + len(setup_code))
1737
+ uc.mem_unmap(BASE, 0x1000)
1738
+
1739
+ a = uc.reg_read(self._uc_const.UC_X86_REG_RAX)
1740
+ d = uc.reg_read(self._uc_const.UC_X86_REG_RDX)
1741
+ return (d << 32) + a
1742
+
1743
+ def write_msr(self, val, msr=0xC0000100):
1744
+ setup_code = b"\x0f\x30"
1745
+ BASE = 0x100B000000
1746
+
1747
+ uc = self.uc
1748
+ uc.mem_map(BASE, 0x1000)
1749
+ uc.mem_write(BASE, setup_code)
1750
+ uc.reg_write(self._uc_const.UC_X86_REG_RCX, msr)
1751
+ uc.reg_write(self._uc_const.UC_X86_REG_RAX, val & 0xFFFFFFFF)
1752
+ uc.reg_write(self._uc_const.UC_X86_REG_RDX, val >> 32)
1753
+ uc.emu_start(BASE, BASE + len(setup_code))
1754
+ uc.mem_unmap(BASE, 0x1000)
1755
+
1756
+ def get_regs(self, succ_state):
1757
+ """
1758
+ loading registers from unicorn. If succ_state is not None, update it instead of self.state. Needed when
1759
+ handling symbolic exits in native interface
1760
+ """
1761
+
1762
+ if succ_state:
1763
+ state = succ_state
1764
+ else:
1765
+ state = self.state
1766
+
1767
+ # first, get the ignore list (in case of symbolic registers)
1768
+ saved_registers = []
1769
+ if options.UNICORN_SYM_REGS_SUPPORT in state.options:
1770
+ highest_reg_offset, reg_size = max(state.arch.registers.values())
1771
+ symbolic_list = (ctypes.c_uint64 * (highest_reg_offset + reg_size))()
1772
+ num_regs = _UC_NATIVE.get_symbolic_registers(self._uc_state, symbolic_list)
1773
+
1774
+ # If any VEX cc_dep registers are symbolic, mark VEX cc_op register as symbolic so that it would be saved
1775
+ # and restored for future use if needed
1776
+ symbolic_list = symbolic_list[:num_regs]
1777
+ for reg in state.arch.vex_cc_regs[1:]:
1778
+ if reg.vex_offset in symbolic_list:
1779
+ cc_op_reg = state.arch.vex_cc_regs[0]
1780
+ if cc_op_reg.vex_offset not in symbolic_list:
1781
+ symbolic_list.extend(range(cc_op_reg.vex_offset, cc_op_reg.vex_offset + cc_op_reg.size))
1782
+ break
1783
+
1784
+ # we take the approach of saving off the symbolic regs and then writing them back
1785
+
1786
+ cur_group = None
1787
+ last = None
1788
+ for i in sorted(symbolic_list):
1789
+ if cur_group is None:
1790
+ cur_group = i
1791
+ elif i != last + 1 or cur_group // state.arch.bytes != i // state.arch.bytes:
1792
+ l.debug("Restoring symbolic register %d", cur_group)
1793
+ saved_registers.append((cur_group, state.registers.load(cur_group, last - cur_group + 1)))
1794
+ cur_group = i
1795
+ last = i
1796
+ if cur_group is not None:
1797
+ l.debug("Restoring symbolic register %d", cur_group)
1798
+ saved_registers.append((cur_group, state.registers.load(cur_group, last - cur_group + 1)))
1799
+
1800
+ # now we sync registers out of unicorn
1801
+ for r, c in self._uc_regs.items():
1802
+ if r in state.arch.reg_blacklist:
1803
+ continue
1804
+ v = self.uc.reg_read(c)
1805
+ # l.debug('getting $%s = %#x', r, v)
1806
+ setattr(state.regs, r, v)
1807
+
1808
+ # some architecture-specific register fixups
1809
+ if state.arch.name in {"X86", "AMD64"}:
1810
+ # update the eflags
1811
+ state.regs.eflags = state.solver.BVV(self.uc.reg_read(self._uc_const.UC_X86_REG_EFLAGS), state.arch.bits)
1812
+
1813
+ # sync the fp clerical data
1814
+ status = self.uc.reg_read(unicorn.x86_const.UC_X86_REG_FPSW)
1815
+ c3210 = status & 0x4700
1816
+ top = (status & 0x3800) >> 11
1817
+ control = self.uc.reg_read(unicorn.x86_const.UC_X86_REG_FPCW)
1818
+ rm = (control & 0x0C00) >> 10
1819
+ state.regs.fpround = rm
1820
+ state.regs.fc3210 = c3210
1821
+ state.regs.ftop = top
1822
+
1823
+ # sync the stx registers
1824
+ # we gotta round the 80-bit extended precision values to 64-bit doubles!
1825
+ uc_offset = unicorn.x86_const.UC_X86_REG_FP0
1826
+ vex_offset = state.arch.registers["fpu_regs"][0]
1827
+ vex_tag_offset = state.arch.registers["fpu_tags"][0] + 7
1828
+ tag_word = self.uc.reg_read(unicorn.x86_const.UC_X86_REG_FPTAG)
1829
+
1830
+ for _ in range(8):
1831
+ if tag_word & 3 == 3:
1832
+ state.registers.store(vex_tag_offset, 0, size=1)
1833
+ else:
1834
+ state.registers.store(vex_tag_offset, 1, size=1)
1835
+
1836
+ mantissa, exponent = self.uc.reg_read(uc_offset)
1837
+ sign = bool(exponent & 0x8000)
1838
+ exponent = exponent & 0x7FFF
1839
+ if exponent not in {0, 0x7FFF}: # normal value
1840
+ exponent = exponent - 16383 + 1023
1841
+ if exponent <= 0: # underflow to zero
1842
+ exponent = 0
1843
+ mantissa = 0
1844
+ elif exponent >= 0x7FF: # overflow to infinity
1845
+ exponent = 0x7FF
1846
+ mantissa = 0
1847
+ elif exponent == 0: # zero or subnormal value
1848
+ mantissa = 0
1849
+ elif exponent == 0x7FFF: # nan or infinity
1850
+ exponent = 0x7FF
1851
+ if mantissa != 0:
1852
+ mantissa = 0xFFFF
1853
+
1854
+ val = 0x8000000000000000 if sign else 0
1855
+ val |= exponent << 52
1856
+ val |= (mantissa >> 11) & 0xFFFFFFFFFFFFF
1857
+ # the mantissa calculation is to convert from the 64-bit mantissa to 52-bit
1858
+ # additionally, extended precision keeps around an high bit that we don't care about
1859
+ # so 11-shift, not 12
1860
+
1861
+ state.registers.store(vex_offset, val, size=8)
1862
+
1863
+ uc_offset += 1
1864
+ vex_offset += 8
1865
+ tag_word >>= 2
1866
+ vex_tag_offset -= 1
1867
+
1868
+ # TODO: ARM hardfloat
1869
+
1870
+ # now, we restore the symbolic registers
1871
+ if options.UNICORN_SYM_REGS_SUPPORT in state.options:
1872
+ for o, r in saved_registers:
1873
+ state.registers.store(o, r)
1874
+
1875
+ def _check_registers(self, report=True):
1876
+ """check if this state might be used in unicorn (has no concrete register)"""
1877
+ for r in self.state.arch.uc_regs.keys():
1878
+ v = getattr(self.state.regs, r)
1879
+ processed_v = self._process_value(v, "reg")
1880
+ if processed_v is None or processed_v.symbolic:
1881
+ # l.info('detected symbolic register %s', r)
1882
+ if report:
1883
+ self._report_symbolic_blocker(v, "reg")
1884
+ return False
1885
+
1886
+ if self.state.arch.vex_conditional_helpers:
1887
+ flags = ccall._get_flags(self.state)
1888
+ processed_flags = self._process_value(flags, "reg")
1889
+ if processed_flags is None or processed_flags.symbolic:
1890
+ # l.info("detected symbolic rflags/eflags")
1891
+ if report:
1892
+ self._report_symbolic_blocker(flags, "reg")
1893
+ return False
1894
+
1895
+ # l.debug('passed quick check')
1896
+ return True
1897
+
1898
+
1899
+ SimState.register_default("unicorn", Unicorn)