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.
- angr/__init__.py +153 -0
- angr/__main__.py +59 -0
- angr/analyses/__init__.py +46 -0
- angr/analyses/analysis.py +359 -0
- angr/analyses/backward_slice.py +691 -0
- angr/analyses/binary_optimizer.py +683 -0
- angr/analyses/bindiff.py +1251 -0
- angr/analyses/boyscout.py +77 -0
- angr/analyses/callee_cleanup_finder.py +75 -0
- angr/analyses/calling_convention.py +956 -0
- angr/analyses/cdg.py +197 -0
- angr/analyses/cfg/__init__.py +11 -0
- angr/analyses/cfg/cfb.py +436 -0
- angr/analyses/cfg/cfg.py +73 -0
- angr/analyses/cfg/cfg_arch_options.py +82 -0
- angr/analyses/cfg/cfg_base.py +2917 -0
- angr/analyses/cfg/cfg_emulated.py +3570 -0
- angr/analyses/cfg/cfg_fast.py +5053 -0
- angr/analyses/cfg/cfg_fast_soot.py +669 -0
- angr/analyses/cfg/cfg_job_base.py +204 -0
- angr/analyses/cfg/indirect_jump_resolvers/__init__.py +8 -0
- angr/analyses/cfg/indirect_jump_resolvers/amd64_elf_got.py +63 -0
- angr/analyses/cfg/indirect_jump_resolvers/amd64_pe_iat.py +52 -0
- angr/analyses/cfg/indirect_jump_resolvers/arm_elf_fast.py +151 -0
- angr/analyses/cfg/indirect_jump_resolvers/const_resolver.py +141 -0
- angr/analyses/cfg/indirect_jump_resolvers/default_resolvers.py +68 -0
- angr/analyses/cfg/indirect_jump_resolvers/jumptable.py +2368 -0
- angr/analyses/cfg/indirect_jump_resolvers/mips_elf_fast.py +517 -0
- angr/analyses/cfg/indirect_jump_resolvers/propagator_utils.py +26 -0
- angr/analyses/cfg/indirect_jump_resolvers/resolver.py +74 -0
- angr/analyses/cfg/indirect_jump_resolvers/x86_elf_pic_plt.py +93 -0
- angr/analyses/cfg/indirect_jump_resolvers/x86_pe_iat.py +51 -0
- angr/analyses/cfg_slice_to_sink/__init__.py +2 -0
- angr/analyses/cfg_slice_to_sink/cfg_slice_to_sink.py +117 -0
- angr/analyses/cfg_slice_to_sink/graph.py +84 -0
- angr/analyses/cfg_slice_to_sink/transitions.py +25 -0
- angr/analyses/class_identifier.py +62 -0
- angr/analyses/code_tagging.py +123 -0
- angr/analyses/complete_calling_conventions.py +424 -0
- angr/analyses/congruency_check.py +384 -0
- angr/analyses/data_dep/__init__.py +2 -0
- angr/analyses/data_dep/data_dependency_analysis.py +605 -0
- angr/analyses/data_dep/dep_nodes.py +170 -0
- angr/analyses/data_dep/sim_act_location.py +46 -0
- angr/analyses/datagraph_meta.py +105 -0
- angr/analyses/ddg.py +1695 -0
- angr/analyses/decompiler/__init__.py +13 -0
- angr/analyses/decompiler/ail_simplifier.py +1408 -0
- angr/analyses/decompiler/ailgraph_walker.py +48 -0
- angr/analyses/decompiler/block_io_finder.py +293 -0
- angr/analyses/decompiler/block_similarity.py +188 -0
- angr/analyses/decompiler/block_simplifier.py +434 -0
- angr/analyses/decompiler/call_counter.py +43 -0
- angr/analyses/decompiler/callsite_maker.py +403 -0
- angr/analyses/decompiler/ccall_rewriters/__init__.py +6 -0
- angr/analyses/decompiler/ccall_rewriters/amd64_ccalls.py +489 -0
- angr/analyses/decompiler/ccall_rewriters/rewriter_base.py +19 -0
- angr/analyses/decompiler/clinic.py +2166 -0
- angr/analyses/decompiler/condition_processor.py +1184 -0
- angr/analyses/decompiler/decompilation_cache.py +38 -0
- angr/analyses/decompiler/decompilation_options.py +274 -0
- angr/analyses/decompiler/decompiler.py +544 -0
- angr/analyses/decompiler/empty_node_remover.py +211 -0
- angr/analyses/decompiler/expression_counters.py +76 -0
- angr/analyses/decompiler/expression_narrower.py +92 -0
- angr/analyses/decompiler/goto_manager.py +73 -0
- angr/analyses/decompiler/graph_region.py +413 -0
- angr/analyses/decompiler/jump_target_collector.py +36 -0
- angr/analyses/decompiler/jumptable_entry_condition_rewriter.py +66 -0
- angr/analyses/decompiler/optimization_passes/__init__.py +108 -0
- angr/analyses/decompiler/optimization_passes/base_ptr_save_simplifier.py +144 -0
- angr/analyses/decompiler/optimization_passes/code_motion.py +360 -0
- angr/analyses/decompiler/optimization_passes/const_derefs.py +265 -0
- angr/analyses/decompiler/optimization_passes/cross_jump_reverter.py +108 -0
- angr/analyses/decompiler/optimization_passes/deadblock_remover.py +73 -0
- angr/analyses/decompiler/optimization_passes/div_simplifier.py +391 -0
- angr/analyses/decompiler/optimization_passes/engine_base.py +303 -0
- angr/analyses/decompiler/optimization_passes/expr_op_swapper.py +136 -0
- angr/analyses/decompiler/optimization_passes/flip_boolean_cmp.py +91 -0
- angr/analyses/decompiler/optimization_passes/inlined_string_transformation_simplifier.py +386 -0
- angr/analyses/decompiler/optimization_passes/ite_expr_converter.py +226 -0
- angr/analyses/decompiler/optimization_passes/ite_region_converter.py +189 -0
- angr/analyses/decompiler/optimization_passes/lowered_switch_simplifier.py +757 -0
- angr/analyses/decompiler/optimization_passes/mod_simplifier.py +86 -0
- angr/analyses/decompiler/optimization_passes/multi_simplifier.py +227 -0
- angr/analyses/decompiler/optimization_passes/optimization_pass.py +397 -0
- angr/analyses/decompiler/optimization_passes/register_save_area_simplifier.py +198 -0
- angr/analyses/decompiler/optimization_passes/ret_addr_save_simplifier.py +172 -0
- angr/analyses/decompiler/optimization_passes/ret_deduplicator.py +219 -0
- angr/analyses/decompiler/optimization_passes/return_duplicator_base.py +448 -0
- angr/analyses/decompiler/optimization_passes/return_duplicator_high.py +57 -0
- angr/analyses/decompiler/optimization_passes/return_duplicator_low.py +121 -0
- angr/analyses/decompiler/optimization_passes/spilled_register_finder.py +18 -0
- angr/analyses/decompiler/optimization_passes/stack_canary_simplifier.py +293 -0
- angr/analyses/decompiler/optimization_passes/switch_default_case_duplicator.py +110 -0
- angr/analyses/decompiler/optimization_passes/win_stack_canary_simplifier.py +281 -0
- angr/analyses/decompiler/optimization_passes/x86_gcc_getpc_simplifier.py +87 -0
- angr/analyses/decompiler/peephole_optimizations/__init__.py +69 -0
- angr/analyses/decompiler/peephole_optimizations/a_div_const_add_a_mul_n_div_const.py +38 -0
- angr/analyses/decompiler/peephole_optimizations/a_mul_const_div_shr_const.py +38 -0
- angr/analyses/decompiler/peephole_optimizations/a_shl_const_sub_a.py +31 -0
- angr/analyses/decompiler/peephole_optimizations/a_sub_a_div.py +25 -0
- angr/analyses/decompiler/peephole_optimizations/a_sub_a_div_const_mul_const.py +56 -0
- angr/analyses/decompiler/peephole_optimizations/a_sub_a_sub_n.py +19 -0
- angr/analyses/decompiler/peephole_optimizations/arm_cmpf.py +235 -0
- angr/analyses/decompiler/peephole_optimizations/base.py +120 -0
- angr/analyses/decompiler/peephole_optimizations/basepointeroffset_add_n.py +33 -0
- angr/analyses/decompiler/peephole_optimizations/basepointeroffset_and_mask.py +35 -0
- angr/analyses/decompiler/peephole_optimizations/bitwise_or_to_logical_or.py +34 -0
- angr/analyses/decompiler/peephole_optimizations/bool_expr_xor_1.py +27 -0
- angr/analyses/decompiler/peephole_optimizations/bswap.py +131 -0
- angr/analyses/decompiler/peephole_optimizations/cmpord_rewriter.py +72 -0
- angr/analyses/decompiler/peephole_optimizations/coalesce_same_cascading_ifs.py +27 -0
- angr/analyses/decompiler/peephole_optimizations/const_mull_a_shift.py +91 -0
- angr/analyses/decompiler/peephole_optimizations/constant_derefs.py +43 -0
- angr/analyses/decompiler/peephole_optimizations/conv_a_sub0_shr_and.py +70 -0
- angr/analyses/decompiler/peephole_optimizations/conv_shl_shr.py +51 -0
- angr/analyses/decompiler/peephole_optimizations/eager_eval.py +225 -0
- angr/analyses/decompiler/peephole_optimizations/extended_byte_and_mask.py +55 -0
- angr/analyses/decompiler/peephole_optimizations/inlined_strcpy.py +146 -0
- angr/analyses/decompiler/peephole_optimizations/inlined_strcpy_consolidation.py +102 -0
- angr/analyses/decompiler/peephole_optimizations/inlined_wstrcpy.py +159 -0
- angr/analyses/decompiler/peephole_optimizations/invert_negated_logical_conjuction_disjunction.py +50 -0
- angr/analyses/decompiler/peephole_optimizations/one_sub_bool.py +33 -0
- angr/analyses/decompiler/peephole_optimizations/remove_cascading_conversions.py +19 -0
- angr/analyses/decompiler/peephole_optimizations/remove_empty_if_body.py +45 -0
- angr/analyses/decompiler/peephole_optimizations/remove_noop_conversions.py +26 -0
- angr/analyses/decompiler/peephole_optimizations/remove_redundant_bitmasks.py +48 -0
- angr/analyses/decompiler/peephole_optimizations/remove_redundant_conversions.py +160 -0
- angr/analyses/decompiler/peephole_optimizations/remove_redundant_ite_branch.py +29 -0
- angr/analyses/decompiler/peephole_optimizations/remove_redundant_ite_comparisons.py +54 -0
- angr/analyses/decompiler/peephole_optimizations/remove_redundant_nots.py +17 -0
- angr/analyses/decompiler/peephole_optimizations/remove_redundant_reinterprets.py +43 -0
- angr/analyses/decompiler/peephole_optimizations/remove_redundant_shifts.py +44 -0
- angr/analyses/decompiler/peephole_optimizations/remove_redundant_shifts_around_comparators.py +40 -0
- angr/analyses/decompiler/peephole_optimizations/rewrite_bit_extractions.py +85 -0
- angr/analyses/decompiler/peephole_optimizations/rewrite_mips_gp_loads.py +47 -0
- angr/analyses/decompiler/peephole_optimizations/rol_ror.py +77 -0
- angr/analyses/decompiler/peephole_optimizations/sar_to_signed_div.py +105 -0
- angr/analyses/decompiler/peephole_optimizations/simplify_pc_relative_loads.py +37 -0
- angr/analyses/decompiler/peephole_optimizations/single_bit_cond_to_boolexpr.py +52 -0
- angr/analyses/decompiler/peephole_optimizations/single_bit_xor.py +26 -0
- angr/analyses/decompiler/peephole_optimizations/tidy_stack_addr.py +133 -0
- angr/analyses/decompiler/redundant_label_remover.py +116 -0
- angr/analyses/decompiler/region_identifier.py +1098 -0
- angr/analyses/decompiler/region_simplifiers/__init__.py +1 -0
- angr/analyses/decompiler/region_simplifiers/cascading_cond_transformer.py +93 -0
- angr/analyses/decompiler/region_simplifiers/cascading_ifs.py +81 -0
- angr/analyses/decompiler/region_simplifiers/expr_folding.py +606 -0
- angr/analyses/decompiler/region_simplifiers/goto.py +177 -0
- angr/analyses/decompiler/region_simplifiers/if_.py +142 -0
- angr/analyses/decompiler/region_simplifiers/ifelse.py +90 -0
- angr/analyses/decompiler/region_simplifiers/loop.py +135 -0
- angr/analyses/decompiler/region_simplifiers/node_address_finder.py +23 -0
- angr/analyses/decompiler/region_simplifiers/region_simplifier.py +211 -0
- angr/analyses/decompiler/region_simplifiers/switch_cluster_simplifier.py +644 -0
- angr/analyses/decompiler/region_simplifiers/switch_expr_simplifier.py +83 -0
- angr/analyses/decompiler/region_walker.py +23 -0
- angr/analyses/decompiler/return_maker.py +70 -0
- angr/analyses/decompiler/seq_to_blocks.py +19 -0
- angr/analyses/decompiler/sequence_walker.py +235 -0
- angr/analyses/decompiler/structured_codegen/__init__.py +10 -0
- angr/analyses/decompiler/structured_codegen/base.py +132 -0
- angr/analyses/decompiler/structured_codegen/c.py +3811 -0
- angr/analyses/decompiler/structured_codegen/dummy.py +14 -0
- angr/analyses/decompiler/structured_codegen/dwarf_import.py +186 -0
- angr/analyses/decompiler/structuring/__init__.py +15 -0
- angr/analyses/decompiler/structuring/dream.py +1225 -0
- angr/analyses/decompiler/structuring/phoenix.py +2546 -0
- angr/analyses/decompiler/structuring/recursive_structurer.py +186 -0
- angr/analyses/decompiler/structuring/structurer_base.py +954 -0
- angr/analyses/decompiler/structuring/structurer_nodes.py +414 -0
- angr/analyses/decompiler/utils.py +787 -0
- angr/analyses/disassembly.py +1302 -0
- angr/analyses/disassembly_utils.py +104 -0
- angr/analyses/dominance_frontier.py +39 -0
- angr/analyses/find_objects_static.py +203 -0
- angr/analyses/flirt.py +185 -0
- angr/analyses/forward_analysis/__init__.py +2 -0
- angr/analyses/forward_analysis/forward_analysis.py +527 -0
- angr/analyses/forward_analysis/job_info.py +64 -0
- angr/analyses/forward_analysis/visitors/__init__.py +4 -0
- angr/analyses/forward_analysis/visitors/call_graph.py +28 -0
- angr/analyses/forward_analysis/visitors/function_graph.py +85 -0
- angr/analyses/forward_analysis/visitors/graph.py +250 -0
- angr/analyses/forward_analysis/visitors/loop.py +28 -0
- angr/analyses/forward_analysis/visitors/single_node_graph.py +38 -0
- angr/analyses/identifier/__init__.py +1 -0
- angr/analyses/identifier/custom_callable.py +138 -0
- angr/analyses/identifier/errors.py +9 -0
- angr/analyses/identifier/func.py +57 -0
- angr/analyses/identifier/functions/__init__.py +36 -0
- angr/analyses/identifier/functions/atoi.py +75 -0
- angr/analyses/identifier/functions/based_atoi.py +128 -0
- angr/analyses/identifier/functions/fdprintf.py +122 -0
- angr/analyses/identifier/functions/free.py +64 -0
- angr/analyses/identifier/functions/int2str.py +302 -0
- angr/analyses/identifier/functions/malloc.py +113 -0
- angr/analyses/identifier/functions/memcmp.py +69 -0
- angr/analyses/identifier/functions/memcpy.py +89 -0
- angr/analyses/identifier/functions/memset.py +43 -0
- angr/analyses/identifier/functions/printf.py +122 -0
- angr/analyses/identifier/functions/recv_until.py +315 -0
- angr/analyses/identifier/functions/skip_calloc.py +72 -0
- angr/analyses/identifier/functions/skip_realloc.py +99 -0
- angr/analyses/identifier/functions/skip_recv_n.py +107 -0
- angr/analyses/identifier/functions/snprintf.py +114 -0
- angr/analyses/identifier/functions/sprintf.py +115 -0
- angr/analyses/identifier/functions/strcasecmp.py +32 -0
- angr/analyses/identifier/functions/strcmp.py +112 -0
- angr/analyses/identifier/functions/strcpy.py +43 -0
- angr/analyses/identifier/functions/strlen.py +26 -0
- angr/analyses/identifier/functions/strncmp.py +103 -0
- angr/analyses/identifier/functions/strncpy.py +65 -0
- angr/analyses/identifier/functions/strtol.py +91 -0
- angr/analyses/identifier/identify.py +848 -0
- angr/analyses/identifier/runner.py +359 -0
- angr/analyses/init_finder.py +264 -0
- angr/analyses/loop_analysis.py +353 -0
- angr/analyses/loopfinder.py +174 -0
- angr/analyses/propagator/__init__.py +1 -0
- angr/analyses/propagator/engine_ail.py +1560 -0
- angr/analyses/propagator/engine_base.py +53 -0
- angr/analyses/propagator/engine_vex.py +328 -0
- angr/analyses/propagator/outdated_definition_walker.py +158 -0
- angr/analyses/propagator/propagator.py +422 -0
- angr/analyses/propagator/tmpvar_finder.py +17 -0
- angr/analyses/propagator/top_checker_mixin.py +14 -0
- angr/analyses/propagator/values.py +116 -0
- angr/analyses/propagator/vex_vars.py +67 -0
- angr/analyses/proximity_graph.py +452 -0
- angr/analyses/reaching_definitions/__init__.py +65 -0
- angr/analyses/reaching_definitions/call_trace.py +72 -0
- angr/analyses/reaching_definitions/dep_graph.py +392 -0
- angr/analyses/reaching_definitions/engine_ail.py +1172 -0
- angr/analyses/reaching_definitions/engine_vex.py +1102 -0
- angr/analyses/reaching_definitions/external_codeloc.py +0 -0
- angr/analyses/reaching_definitions/function_handler.py +603 -0
- angr/analyses/reaching_definitions/heap_allocator.py +69 -0
- angr/analyses/reaching_definitions/rd_initializer.py +235 -0
- angr/analyses/reaching_definitions/rd_state.py +613 -0
- angr/analyses/reaching_definitions/reaching_definitions.py +594 -0
- angr/analyses/reaching_definitions/subject.py +64 -0
- angr/analyses/reassembler.py +2970 -0
- angr/analyses/soot_class_hierarchy.py +283 -0
- angr/analyses/stack_pointer_tracker.py +832 -0
- angr/analyses/static_hooker.py +51 -0
- angr/analyses/typehoon/__init__.py +1 -0
- angr/analyses/typehoon/dfa.py +108 -0
- angr/analyses/typehoon/lifter.py +91 -0
- angr/analyses/typehoon/simple_solver.py +1258 -0
- angr/analyses/typehoon/translator.py +242 -0
- angr/analyses/typehoon/typeconsts.py +294 -0
- angr/analyses/typehoon/typehoon.py +239 -0
- angr/analyses/typehoon/typevars.py +565 -0
- angr/analyses/typehoon/variance.py +10 -0
- angr/analyses/variable_recovery/__init__.py +2 -0
- angr/analyses/variable_recovery/annotations.py +57 -0
- angr/analyses/variable_recovery/engine_ail.py +746 -0
- angr/analyses/variable_recovery/engine_base.py +962 -0
- angr/analyses/variable_recovery/engine_vex.py +580 -0
- angr/analyses/variable_recovery/irsb_scanner.py +131 -0
- angr/analyses/variable_recovery/variable_recovery.py +552 -0
- angr/analyses/variable_recovery/variable_recovery_base.py +452 -0
- angr/analyses/variable_recovery/variable_recovery_fast.py +589 -0
- angr/analyses/veritesting.py +635 -0
- angr/analyses/vfg.py +1945 -0
- angr/analyses/vsa_ddg.py +423 -0
- angr/analyses/vtable.py +92 -0
- angr/analyses/xrefs.py +263 -0
- angr/angrdb/__init__.py +9 -0
- angr/angrdb/db.py +208 -0
- angr/angrdb/models.py +183 -0
- angr/angrdb/serializers/__init__.py +2 -0
- angr/angrdb/serializers/cfg_model.py +41 -0
- angr/angrdb/serializers/comments.py +59 -0
- angr/angrdb/serializers/funcs.py +60 -0
- angr/angrdb/serializers/kb.py +110 -0
- angr/angrdb/serializers/labels.py +58 -0
- angr/angrdb/serializers/loader.py +81 -0
- angr/angrdb/serializers/structured_code.py +128 -0
- angr/angrdb/serializers/variables.py +58 -0
- angr/angrdb/serializers/xrefs.py +48 -0
- angr/annocfg.py +320 -0
- angr/blade.py +430 -0
- angr/block.py +506 -0
- angr/callable.py +162 -0
- angr/calling_conventions.py +2383 -0
- angr/code_location.py +168 -0
- angr/codenode.py +140 -0
- angr/concretization_strategies/__init__.py +97 -0
- angr/concretization_strategies/any.py +15 -0
- angr/concretization_strategies/any_named.py +32 -0
- angr/concretization_strategies/controlled_data.py +54 -0
- angr/concretization_strategies/eval.py +18 -0
- angr/concretization_strategies/logging.py +32 -0
- angr/concretization_strategies/max.py +24 -0
- angr/concretization_strategies/nonzero.py +14 -0
- angr/concretization_strategies/nonzero_range.py +20 -0
- angr/concretization_strategies/norepeats.py +35 -0
- angr/concretization_strategies/norepeats_range.py +35 -0
- angr/concretization_strategies/range.py +17 -0
- angr/concretization_strategies/signed_add.py +24 -0
- angr/concretization_strategies/single.py +12 -0
- angr/concretization_strategies/solutions.py +18 -0
- angr/concretization_strategies/unlimited_range.py +15 -0
- angr/distributed/__init__.py +3 -0
- angr/distributed/server.py +198 -0
- angr/distributed/worker.py +183 -0
- angr/engines/__init__.py +41 -0
- angr/engines/concrete.py +178 -0
- angr/engines/engine.py +212 -0
- angr/engines/failure.py +27 -0
- angr/engines/hook.py +67 -0
- angr/engines/light/__init__.py +2 -0
- angr/engines/light/data.py +715 -0
- angr/engines/light/engine.py +1441 -0
- angr/engines/pcode/__init__.py +2 -0
- angr/engines/pcode/behavior.py +995 -0
- angr/engines/pcode/cc.py +123 -0
- angr/engines/pcode/emulate.py +446 -0
- angr/engines/pcode/engine.py +256 -0
- angr/engines/pcode/lifter.py +1423 -0
- angr/engines/procedure.py +71 -0
- angr/engines/soot/__init__.py +1 -0
- angr/engines/soot/engine.py +415 -0
- angr/engines/soot/exceptions.py +14 -0
- angr/engines/soot/expressions/__init__.py +56 -0
- angr/engines/soot/expressions/arrayref.py +21 -0
- angr/engines/soot/expressions/base.py +22 -0
- angr/engines/soot/expressions/binop.py +27 -0
- angr/engines/soot/expressions/cast.py +21 -0
- angr/engines/soot/expressions/condition.py +34 -0
- angr/engines/soot/expressions/constants.py +45 -0
- angr/engines/soot/expressions/instanceOf.py +11 -0
- angr/engines/soot/expressions/instancefieldref.py +7 -0
- angr/engines/soot/expressions/invoke.py +117 -0
- angr/engines/soot/expressions/length.py +7 -0
- angr/engines/soot/expressions/local.py +7 -0
- angr/engines/soot/expressions/new.py +15 -0
- angr/engines/soot/expressions/newArray.py +51 -0
- angr/engines/soot/expressions/newMultiArray.py +84 -0
- angr/engines/soot/expressions/paramref.py +7 -0
- angr/engines/soot/expressions/phi.py +29 -0
- angr/engines/soot/expressions/staticfieldref.py +7 -0
- angr/engines/soot/expressions/thisref.py +6 -0
- angr/engines/soot/expressions/unsupported.py +6 -0
- angr/engines/soot/field_dispatcher.py +49 -0
- angr/engines/soot/method_dispatcher.py +49 -0
- angr/engines/soot/statements/__init__.py +30 -0
- angr/engines/soot/statements/assign.py +29 -0
- angr/engines/soot/statements/base.py +80 -0
- angr/engines/soot/statements/goto.py +11 -0
- angr/engines/soot/statements/identity.py +14 -0
- angr/engines/soot/statements/if_.py +16 -0
- angr/engines/soot/statements/invoke.py +11 -0
- angr/engines/soot/statements/return_.py +19 -0
- angr/engines/soot/statements/switch.py +38 -0
- angr/engines/soot/statements/throw.py +12 -0
- angr/engines/soot/values/__init__.py +24 -0
- angr/engines/soot/values/arrayref.py +124 -0
- angr/engines/soot/values/base.py +4 -0
- angr/engines/soot/values/constants.py +17 -0
- angr/engines/soot/values/instancefieldref.py +42 -0
- angr/engines/soot/values/local.py +17 -0
- angr/engines/soot/values/paramref.py +17 -0
- angr/engines/soot/values/staticfieldref.py +37 -0
- angr/engines/soot/values/strref.py +37 -0
- angr/engines/soot/values/thisref.py +148 -0
- angr/engines/successors.py +540 -0
- angr/engines/syscall.py +53 -0
- angr/engines/unicorn.py +483 -0
- angr/engines/vex/__init__.py +4 -0
- angr/engines/vex/claripy/__init__.py +1 -0
- angr/engines/vex/claripy/ccall.py +2097 -0
- angr/engines/vex/claripy/datalayer.py +149 -0
- angr/engines/vex/claripy/irop.py +1279 -0
- angr/engines/vex/heavy/__init__.py +5 -0
- angr/engines/vex/heavy/actions.py +237 -0
- angr/engines/vex/heavy/concretizers.py +394 -0
- angr/engines/vex/heavy/dirty.py +467 -0
- angr/engines/vex/heavy/heavy.py +379 -0
- angr/engines/vex/heavy/inspect.py +51 -0
- angr/engines/vex/heavy/resilience.py +85 -0
- angr/engines/vex/heavy/super_fastpath.py +34 -0
- angr/engines/vex/lifter.py +424 -0
- angr/engines/vex/light/__init__.py +3 -0
- angr/engines/vex/light/light.py +555 -0
- angr/engines/vex/light/resilience.py +73 -0
- angr/engines/vex/light/slicing.py +51 -0
- angr/errors.py +604 -0
- angr/exploration_techniques/__init__.py +176 -0
- angr/exploration_techniques/bucketizer.py +96 -0
- angr/exploration_techniques/common.py +56 -0
- angr/exploration_techniques/dfs.py +34 -0
- angr/exploration_techniques/director.py +523 -0
- angr/exploration_techniques/driller_core.py +102 -0
- angr/exploration_techniques/explorer.py +146 -0
- angr/exploration_techniques/lengthlimiter.py +20 -0
- angr/exploration_techniques/local_loop_seer.py +64 -0
- angr/exploration_techniques/loop_seer.py +239 -0
- angr/exploration_techniques/manual_mergepoint.py +80 -0
- angr/exploration_techniques/memory_watcher.py +40 -0
- angr/exploration_techniques/oppologist.py +93 -0
- angr/exploration_techniques/slicecutor.py +115 -0
- angr/exploration_techniques/spiller.py +282 -0
- angr/exploration_techniques/spiller_db.py +27 -0
- angr/exploration_techniques/stochastic.py +57 -0
- angr/exploration_techniques/suggestions.py +156 -0
- angr/exploration_techniques/symbion.py +78 -0
- angr/exploration_techniques/tech_builder.py +47 -0
- angr/exploration_techniques/threading.py +77 -0
- angr/exploration_techniques/timeout.py +31 -0
- angr/exploration_techniques/tracer.py +1101 -0
- angr/exploration_techniques/unique.py +104 -0
- angr/exploration_techniques/veritesting.py +36 -0
- angr/factory.py +385 -0
- angr/flirt/__init__.py +126 -0
- angr/flirt/build_sig.py +316 -0
- angr/graph_utils.py +0 -0
- angr/keyed_region.py +532 -0
- angr/knowledge_base/__init__.py +1 -0
- angr/knowledge_base/knowledge_base.py +145 -0
- angr/knowledge_plugins/__init__.py +18 -0
- angr/knowledge_plugins/callsite_prototypes.py +52 -0
- angr/knowledge_plugins/cfg/__init__.py +16 -0
- angr/knowledge_plugins/cfg/cfg_manager.py +94 -0
- angr/knowledge_plugins/cfg/cfg_model.py +1057 -0
- angr/knowledge_plugins/cfg/cfg_node.py +541 -0
- angr/knowledge_plugins/cfg/indirect_jump.py +67 -0
- angr/knowledge_plugins/cfg/memory_data.py +156 -0
- angr/knowledge_plugins/comments.py +15 -0
- angr/knowledge_plugins/custom_strings.py +37 -0
- angr/knowledge_plugins/data.py +21 -0
- angr/knowledge_plugins/debug_variables.py +221 -0
- angr/knowledge_plugins/functions/__init__.py +2 -0
- angr/knowledge_plugins/functions/function.py +1694 -0
- angr/knowledge_plugins/functions/function_manager.py +501 -0
- angr/knowledge_plugins/functions/function_parser.py +295 -0
- angr/knowledge_plugins/functions/soot_function.py +131 -0
- angr/knowledge_plugins/indirect_jumps.py +34 -0
- angr/knowledge_plugins/key_definitions/__init__.py +16 -0
- angr/knowledge_plugins/key_definitions/atoms.py +314 -0
- angr/knowledge_plugins/key_definitions/constants.py +23 -0
- angr/knowledge_plugins/key_definitions/definition.py +217 -0
- angr/knowledge_plugins/key_definitions/environment.py +92 -0
- angr/knowledge_plugins/key_definitions/heap_address.py +32 -0
- angr/knowledge_plugins/key_definitions/key_definition_manager.py +81 -0
- angr/knowledge_plugins/key_definitions/live_definitions.py +1074 -0
- angr/knowledge_plugins/key_definitions/liveness.py +170 -0
- angr/knowledge_plugins/key_definitions/rd_model.py +176 -0
- angr/knowledge_plugins/key_definitions/tag.py +77 -0
- angr/knowledge_plugins/key_definitions/undefined.py +67 -0
- angr/knowledge_plugins/key_definitions/unknown_size.py +83 -0
- angr/knowledge_plugins/key_definitions/uses.py +180 -0
- angr/knowledge_plugins/labels.py +109 -0
- angr/knowledge_plugins/patches.py +125 -0
- angr/knowledge_plugins/plugin.py +23 -0
- angr/knowledge_plugins/propagations/__init__.py +2 -0
- angr/knowledge_plugins/propagations/prop_value.py +193 -0
- angr/knowledge_plugins/propagations/propagation_manager.py +60 -0
- angr/knowledge_plugins/propagations/propagation_model.py +74 -0
- angr/knowledge_plugins/propagations/states.py +1064 -0
- angr/knowledge_plugins/structured_code/__init__.py +1 -0
- angr/knowledge_plugins/structured_code/manager.py +59 -0
- angr/knowledge_plugins/sync/__init__.py +1 -0
- angr/knowledge_plugins/sync/sync_controller.py +329 -0
- angr/knowledge_plugins/types.py +87 -0
- angr/knowledge_plugins/variables/__init__.py +1 -0
- angr/knowledge_plugins/variables/variable_access.py +114 -0
- angr/knowledge_plugins/variables/variable_manager.py +1191 -0
- angr/knowledge_plugins/xrefs/__init__.py +3 -0
- angr/knowledge_plugins/xrefs/xref.py +157 -0
- angr/knowledge_plugins/xrefs/xref_manager.py +122 -0
- angr/knowledge_plugins/xrefs/xref_types.py +13 -0
- angr/lib/angr_native.so +0 -0
- angr/misc/__init__.py +8 -0
- angr/misc/ansi.py +46 -0
- angr/misc/autoimport.py +89 -0
- angr/misc/bug_report.py +125 -0
- angr/misc/hookset.py +106 -0
- angr/misc/import_hooks.py +63 -0
- angr/misc/loggers.py +130 -0
- angr/misc/picklable_lock.py +45 -0
- angr/misc/plugins.py +291 -0
- angr/misc/range.py +21 -0
- angr/misc/testing.py +23 -0
- angr/misc/ux.py +31 -0
- angr/misc/weakpatch.py +58 -0
- angr/procedures/__init__.py +2 -0
- angr/procedures/advapi32/__init__.py +0 -0
- angr/procedures/cgc/__init__.py +3 -0
- angr/procedures/cgc/_terminate.py +10 -0
- angr/procedures/cgc/allocate.py +76 -0
- angr/procedures/cgc/deallocate.py +59 -0
- angr/procedures/cgc/fdwait.py +62 -0
- angr/procedures/cgc/random.py +60 -0
- angr/procedures/cgc/receive.py +91 -0
- angr/procedures/cgc/transmit.py +63 -0
- angr/procedures/definitions/__init__.py +784 -0
- angr/procedures/definitions/cgc.py +19 -0
- angr/procedures/definitions/glibc.py +8384 -0
- angr/procedures/definitions/gnulib.py +35 -0
- angr/procedures/definitions/libstdcpp.py +20 -0
- angr/procedures/definitions/linux_kernel.py +6167 -0
- angr/procedures/definitions/linux_loader.py +6 -0
- angr/procedures/definitions/msvcr.py +15 -0
- angr/procedures/definitions/parse_syscalls_from_local_system.py +49 -0
- angr/procedures/definitions/parse_win32json.py +2556 -0
- angr/procedures/definitions/types_win32.py +34481 -0
- angr/procedures/definitions/wdk_api-ms-win-dx-d3dkmt-l1-1-4.py +44 -0
- angr/procedures/definitions/wdk_api-ms-win-dx-d3dkmt-l1-1-6.py +40 -0
- angr/procedures/definitions/wdk_clfs.py +154 -0
- angr/procedures/definitions/wdk_fltmgr.py +570 -0
- angr/procedures/definitions/wdk_fwpkclnt.py +44 -0
- angr/procedures/definitions/wdk_fwpuclnt.py +330 -0
- angr/procedures/definitions/wdk_gdi32.py +380 -0
- angr/procedures/definitions/wdk_hal.py +92 -0
- angr/procedures/definitions/wdk_ksecdd.py +76 -0
- angr/procedures/definitions/wdk_ndis.py +252 -0
- angr/procedures/definitions/wdk_ntoskrnl.py +3463 -0
- angr/procedures/definitions/wdk_offreg.py +86 -0
- angr/procedures/definitions/wdk_pshed.py +50 -0
- angr/procedures/definitions/wdk_secur32.py +54 -0
- angr/procedures/definitions/wdk_vhfum.py +48 -0
- angr/procedures/definitions/win32_aclui.py +44 -0
- angr/procedures/definitions/win32_activeds.py +82 -0
- angr/procedures/definitions/win32_advapi32.py +1698 -0
- angr/procedures/definitions/win32_advpack.py +138 -0
- angr/procedures/definitions/win32_amsi.py +52 -0
- angr/procedures/definitions/win32_api-ms-win-appmodel-runtime-l1-1-1.py +58 -0
- angr/procedures/definitions/win32_api-ms-win-appmodel-runtime-l1-1-3.py +48 -0
- angr/procedures/definitions/win32_api-ms-win-appmodel-runtime-l1-1-6.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-core-apiquery-l2-1-0.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-core-backgroundtask-l1-1-0.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-core-comm-l1-1-1.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-core-comm-l1-1-2.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-core-enclave-l1-1-1.py +44 -0
- angr/procedures/definitions/win32_api-ms-win-core-errorhandling-l1-1-3.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-core-featurestaging-l1-1-0.py +48 -0
- angr/procedures/definitions/win32_api-ms-win-core-featurestaging-l1-1-1.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-core-file-fromapp-l1-1-0.py +60 -0
- angr/procedures/definitions/win32_api-ms-win-core-handle-l1-1-0.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-core-ioring-l1-1-0.py +62 -0
- angr/procedures/definitions/win32_api-ms-win-core-marshal-l1-1-0.py +46 -0
- angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-3.py +46 -0
- angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-4.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-5.py +44 -0
- angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-6.py +46 -0
- angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-7.py +42 -0
- angr/procedures/definitions/win32_api-ms-win-core-memory-l1-1-8.py +44 -0
- angr/procedures/definitions/win32_api-ms-win-core-path-l1-1-0.py +82 -0
- angr/procedures/definitions/win32_api-ms-win-core-psm-appnotify-l1-1-0.py +42 -0
- angr/procedures/definitions/win32_api-ms-win-core-psm-appnotify-l1-1-1.py +42 -0
- angr/procedures/definitions/win32_api-ms-win-core-realtime-l1-1-1.py +44 -0
- angr/procedures/definitions/win32_api-ms-win-core-realtime-l1-1-2.py +44 -0
- angr/procedures/definitions/win32_api-ms-win-core-slapi-l1-1-0.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-core-state-helpers-l1-1-0.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-core-synch-l1-2-0.py +44 -0
- angr/procedures/definitions/win32_api-ms-win-core-sysinfo-l1-2-0.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-core-sysinfo-l1-2-3.py +42 -0
- angr/procedures/definitions/win32_api-ms-win-core-sysinfo-l1-2-4.py +42 -0
- angr/procedures/definitions/win32_api-ms-win-core-sysinfo-l1-2-6.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-core-util-l1-1-1.py +42 -0
- angr/procedures/definitions/win32_api-ms-win-core-winrt-error-l1-1-0.py +43 -0
- angr/procedures/definitions/win32_api-ms-win-core-winrt-error-l1-1-1.py +37 -0
- angr/procedures/definitions/win32_api-ms-win-core-winrt-l1-1-0.py +39 -0
- angr/procedures/definitions/win32_api-ms-win-core-winrt-registration-l1-1-0.py +23 -0
- angr/procedures/definitions/win32_api-ms-win-core-winrt-robuffer-l1-1-0.py +23 -0
- angr/procedures/definitions/win32_api-ms-win-core-winrt-roparameterizediid-l1-1-0.py +27 -0
- angr/procedures/definitions/win32_api-ms-win-core-winrt-string-l1-1-0.py +75 -0
- angr/procedures/definitions/win32_api-ms-win-core-winrt-string-l1-1-1.py +23 -0
- angr/procedures/definitions/win32_api-ms-win-core-wow64-l1-1-1.py +44 -0
- angr/procedures/definitions/win32_api-ms-win-devices-query-l1-1-0.py +56 -0
- angr/procedures/definitions/win32_api-ms-win-devices-query-l1-1-1.py +48 -0
- angr/procedures/definitions/win32_api-ms-win-dx-d3dkmt-l1-1-0.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-gaming-deviceinformation-l1-1-0.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-gaming-expandedresources-l1-1-0.py +44 -0
- angr/procedures/definitions/win32_api-ms-win-gaming-tcui-l1-1-0.py +52 -0
- angr/procedures/definitions/win32_api-ms-win-gaming-tcui-l1-1-1.py +42 -0
- angr/procedures/definitions/win32_api-ms-win-gaming-tcui-l1-1-2.py +52 -0
- angr/procedures/definitions/win32_api-ms-win-gaming-tcui-l1-1-3.py +42 -0
- angr/procedures/definitions/win32_api-ms-win-gaming-tcui-l1-1-4.py +54 -0
- angr/procedures/definitions/win32_api-ms-win-mm-misc-l1-1-1.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-net-isolation-l1-1-0.py +54 -0
- angr/procedures/definitions/win32_api-ms-win-security-base-l1-2-2.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-security-isolatedcontainer-l1-1-0.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-security-isolatedcontainer-l1-1-1.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-service-core-l1-1-3.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-service-core-l1-1-4.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-service-core-l1-1-5.py +42 -0
- angr/procedures/definitions/win32_api-ms-win-shcore-scaling-l1-1-0.py +44 -0
- angr/procedures/definitions/win32_api-ms-win-shcore-scaling-l1-1-1.py +50 -0
- angr/procedures/definitions/win32_api-ms-win-shcore-scaling-l1-1-2.py +40 -0
- angr/procedures/definitions/win32_api-ms-win-shcore-stream-winrt-l1-1-0.py +27 -0
- angr/procedures/definitions/win32_api-ms-win-wsl-api-l1-1-0.py +52 -0
- angr/procedures/definitions/win32_apphelp.py +40 -0
- angr/procedures/definitions/win32_authz.py +104 -0
- angr/procedures/definitions/win32_avicap32.py +46 -0
- angr/procedures/definitions/win32_avifil32.py +158 -0
- angr/procedures/definitions/win32_avrt.py +66 -0
- angr/procedures/definitions/win32_bcp47mrm.py +42 -0
- angr/procedures/definitions/win32_bcrypt.py +144 -0
- angr/procedures/definitions/win32_bcryptprimitives.py +42 -0
- angr/procedures/definitions/win32_bluetoothapis.py +120 -0
- angr/procedures/definitions/win32_bthprops.py +33 -0
- angr/procedures/definitions/win32_bthprops_cpl.py +50 -0
- angr/procedures/definitions/win32_cabinet.py +82 -0
- angr/procedures/definitions/win32_certadm.py +74 -0
- angr/procedures/definitions/win32_certpoleng.py +54 -0
- angr/procedures/definitions/win32_cfgmgr32.py +516 -0
- angr/procedures/definitions/win32_chakra.py +212 -0
- angr/procedures/definitions/win32_cldapi.py +110 -0
- angr/procedures/definitions/win32_clfsw32.py +156 -0
- angr/procedures/definitions/win32_clusapi.py +598 -0
- angr/procedures/definitions/win32_comctl32.py +268 -0
- angr/procedures/definitions/win32_comdlg32.py +80 -0
- angr/procedures/definitions/win32_compstui.py +46 -0
- angr/procedures/definitions/win32_computecore.py +146 -0
- angr/procedures/definitions/win32_computenetwork.py +124 -0
- angr/procedures/definitions/win32_computestorage.py +62 -0
- angr/procedures/definitions/win32_comsvcs.py +52 -0
- angr/procedures/definitions/win32_coremessaging.py +23 -0
- angr/procedures/definitions/win32_credui.py +76 -0
- angr/procedures/definitions/win32_crypt32.py +496 -0
- angr/procedures/definitions/win32_cryptnet.py +48 -0
- angr/procedures/definitions/win32_cryptui.py +58 -0
- angr/procedures/definitions/win32_cryptxml.py +76 -0
- angr/procedures/definitions/win32_cscapi.py +46 -0
- angr/procedures/definitions/win32_d2d1.py +64 -0
- angr/procedures/definitions/win32_d3d10.py +92 -0
- angr/procedures/definitions/win32_d3d10_1.py +42 -0
- angr/procedures/definitions/win32_d3d11.py +44 -0
- angr/procedures/definitions/win32_d3d12.py +54 -0
- angr/procedures/definitions/win32_d3d9.py +60 -0
- angr/procedures/definitions/win32_d3dcompiler_47.py +90 -0
- angr/procedures/definitions/win32_d3dcsx.py +56 -0
- angr/procedures/definitions/win32_davclnt.py +74 -0
- angr/procedures/definitions/win32_dbgeng.py +46 -0
- angr/procedures/definitions/win32_dbghelp.py +476 -0
- angr/procedures/definitions/win32_dbgmodel.py +40 -0
- angr/procedures/definitions/win32_dciman32.py +78 -0
- angr/procedures/definitions/win32_dcomp.py +62 -0
- angr/procedures/definitions/win32_ddraw.py +52 -0
- angr/procedures/definitions/win32_deviceaccess.py +40 -0
- angr/procedures/definitions/win32_dflayout.py +40 -0
- angr/procedures/definitions/win32_dhcpcsvc.py +68 -0
- angr/procedures/definitions/win32_dhcpcsvc6.py +50 -0
- angr/procedures/definitions/win32_dhcpsapi.py +430 -0
- angr/procedures/definitions/win32_diagnosticdataquery.py +108 -0
- angr/procedures/definitions/win32_dinput8.py +40 -0
- angr/procedures/definitions/win32_directml.py +42 -0
- angr/procedures/definitions/win32_dmprocessxmlfiltered.py +40 -0
- angr/procedures/definitions/win32_dnsapi.py +166 -0
- angr/procedures/definitions/win32_drt.py +70 -0
- angr/procedures/definitions/win32_drtprov.py +56 -0
- angr/procedures/definitions/win32_drttransport.py +42 -0
- angr/procedures/definitions/win32_dsound.py +58 -0
- angr/procedures/definitions/win32_dsparse.py +76 -0
- angr/procedures/definitions/win32_dsprop.py +52 -0
- angr/procedures/definitions/win32_dssec.py +46 -0
- angr/procedures/definitions/win32_dsuiext.py +46 -0
- angr/procedures/definitions/win32_dwmapi.py +100 -0
- angr/procedures/definitions/win32_dwrite.py +40 -0
- angr/procedures/definitions/win32_dxcompiler.py +42 -0
- angr/procedures/definitions/win32_dxcore.py +40 -0
- angr/procedures/definitions/win32_dxgi.py +50 -0
- angr/procedures/definitions/win32_dxva2.py +114 -0
- angr/procedures/definitions/win32_eappcfg.py +66 -0
- angr/procedures/definitions/win32_eappprxy.py +74 -0
- angr/procedures/definitions/win32_efswrt.py +42 -0
- angr/procedures/definitions/win32_elscore.py +48 -0
- angr/procedures/definitions/win32_esent.py +496 -0
- angr/procedures/definitions/win32_evr.py +52 -0
- angr/procedures/definitions/win32_faultrep.py +46 -0
- angr/procedures/definitions/win32_fhsvcctl.py +52 -0
- angr/procedures/definitions/win32_firewallapi.py +44 -0
- angr/procedures/definitions/win32_fltlib.py +94 -0
- angr/procedures/definitions/win32_fontsub.py +42 -0
- angr/procedures/definitions/win32_forceinline.py +44 -0
- angr/procedures/definitions/win32_fwpuclnt.py +422 -0
- angr/procedures/definitions/win32_fxsutility.py +42 -0
- angr/procedures/definitions/win32_gdi32.py +900 -0
- angr/procedures/definitions/win32_gdiplus.py +1296 -0
- angr/procedures/definitions/win32_glu32.py +142 -0
- angr/procedures/definitions/win32_gpedit.py +50 -0
- angr/procedures/definitions/win32_hhctrl_ocx.py +42 -0
- angr/procedures/definitions/win32_hid.py +128 -0
- angr/procedures/definitions/win32_hlink.py +94 -0
- angr/procedures/definitions/win32_hrtfapo.py +40 -0
- angr/procedures/definitions/win32_httpapi.py +124 -0
- angr/procedures/definitions/win32_icm32.py +80 -0
- angr/procedures/definitions/win32_icmui.py +42 -0
- angr/procedures/definitions/win32_icu.py +2088 -0
- angr/procedures/definitions/win32_ieframe.py +96 -0
- angr/procedures/definitions/win32_imagehlp.py +90 -0
- angr/procedures/definitions/win32_imgutil.py +56 -0
- angr/procedures/definitions/win32_imm32.py +202 -0
- angr/procedures/definitions/win32_infocardapi.py +72 -0
- angr/procedures/definitions/win32_inkobjcore.py +92 -0
- angr/procedures/definitions/win32_iphlpapi.py +440 -0
- angr/procedures/definitions/win32_iscsidsc.py +196 -0
- angr/procedures/definitions/win32_isolatedwindowsenvironmentutils.py +42 -0
- angr/procedures/definitions/win32_kernel32.py +3199 -0
- angr/procedures/definitions/win32_kernelbase.py +50 -0
- angr/procedures/definitions/win32_keycredmgr.py +46 -0
- angr/procedures/definitions/win32_ksproxy_ax.py +50 -0
- angr/procedures/definitions/win32_ksuser.py +54 -0
- angr/procedures/definitions/win32_ktmw32.py +116 -0
- angr/procedures/definitions/win32_licenseprotection.py +42 -0
- angr/procedures/definitions/win32_loadperf.py +62 -0
- angr/procedures/definitions/win32_magnification.py +76 -0
- angr/procedures/definitions/win32_mapi32.py +170 -0
- angr/procedures/definitions/win32_mdmlocalmanagement.py +44 -0
- angr/procedures/definitions/win32_mdmregistration.py +68 -0
- angr/procedures/definitions/win32_mf.py +162 -0
- angr/procedures/definitions/win32_mfcore.py +42 -0
- angr/procedures/definitions/win32_mfplat.py +328 -0
- angr/procedures/definitions/win32_mfplay.py +40 -0
- angr/procedures/definitions/win32_mfreadwrite.py +48 -0
- angr/procedures/definitions/win32_mfsensorgroup.py +58 -0
- angr/procedures/definitions/win32_mfsrcsnk.py +42 -0
- angr/procedures/definitions/win32_mgmtapi.py +56 -0
- angr/procedures/definitions/win32_mi.py +40 -0
- angr/procedures/definitions/win32_mmdevapi.py +40 -0
- angr/procedures/definitions/win32_mpr.py +132 -0
- angr/procedures/definitions/win32_mprapi.py +262 -0
- angr/procedures/definitions/win32_mqrt.py +106 -0
- angr/procedures/definitions/win32_mrmsupport.py +92 -0
- angr/procedures/definitions/win32_msacm32.py +122 -0
- angr/procedures/definitions/win32_msajapi.py +1132 -0
- angr/procedures/definitions/win32_mscms.py +196 -0
- angr/procedures/definitions/win32_mscoree.py +92 -0
- angr/procedures/definitions/win32_msctfmonitor.py +44 -0
- angr/procedures/definitions/win32_msdelta.py +70 -0
- angr/procedures/definitions/win32_msdmo.py +60 -0
- angr/procedures/definitions/win32_msdrm.py +206 -0
- angr/procedures/definitions/win32_msi.py +566 -0
- angr/procedures/definitions/win32_msimg32.py +44 -0
- angr/procedures/definitions/win32_mspatcha.py +70 -0
- angr/procedures/definitions/win32_mspatchc.py +56 -0
- angr/procedures/definitions/win32_msports.py +52 -0
- angr/procedures/definitions/win32_msrating.py +76 -0
- angr/procedures/definitions/win32_mssign32.py +58 -0
- angr/procedures/definitions/win32_mstask.py +42 -0
- angr/procedures/definitions/win32_msvfw32.py +124 -0
- angr/procedures/definitions/win32_mswsock.py +70 -0
- angr/procedures/definitions/win32_mtxdm.py +40 -0
- angr/procedures/definitions/win32_ncrypt.py +116 -0
- angr/procedures/definitions/win32_ndfapi.py +70 -0
- angr/procedures/definitions/win32_netapi32.py +450 -0
- angr/procedures/definitions/win32_netsh.py +54 -0
- angr/procedures/definitions/win32_netshell.py +42 -0
- angr/procedures/definitions/win32_newdev.py +60 -0
- angr/procedures/definitions/win32_ninput.py +98 -0
- angr/procedures/definitions/win32_normaliz.py +42 -0
- angr/procedures/definitions/win32_ntdll.py +185 -0
- angr/procedures/definitions/win32_ntdllk.py +40 -0
- angr/procedures/definitions/win32_ntdsapi.py +200 -0
- angr/procedures/definitions/win32_ntlanman.py +58 -0
- angr/procedures/definitions/win32_odbc32.py +406 -0
- angr/procedures/definitions/win32_odbcbcp.py +92 -0
- angr/procedures/definitions/win32_ole32.py +672 -0
- angr/procedures/definitions/win32_oleacc.py +72 -0
- angr/procedures/definitions/win32_oleaut32.py +848 -0
- angr/procedures/definitions/win32_oledlg.py +84 -0
- angr/procedures/definitions/win32_ondemandconnroutehelper.py +48 -0
- angr/procedures/definitions/win32_opengl32.py +748 -0
- angr/procedures/definitions/win32_opmxbox.py +44 -0
- angr/procedures/definitions/win32_p2p.py +254 -0
- angr/procedures/definitions/win32_p2pgraph.py +112 -0
- angr/procedures/definitions/win32_pdh.py +234 -0
- angr/procedures/definitions/win32_peerdist.py +94 -0
- angr/procedures/definitions/win32_powrprof.py +206 -0
- angr/procedures/definitions/win32_prntvpt.py +60 -0
- angr/procedures/definitions/win32_projectedfslib.py +76 -0
- angr/procedures/definitions/win32_propsys.py +474 -0
- angr/procedures/definitions/win32_psapi.py +92 -0
- angr/procedures/definitions/win32_quartz.py +42 -0
- angr/procedures/definitions/win32_query.py +46 -0
- angr/procedures/definitions/win32_qwave.py +60 -0
- angr/procedures/definitions/win32_rasapi32.py +206 -0
- angr/procedures/definitions/win32_rasdlg.py +50 -0
- angr/procedures/definitions/win32_resutils.py +278 -0
- angr/procedures/definitions/win32_rometadata.py +23 -0
- angr/procedures/definitions/win32_rpcns4.py +160 -0
- angr/procedures/definitions/win32_rpcproxy.py +46 -0
- angr/procedures/definitions/win32_rpcrt4.py +932 -0
- angr/procedures/definitions/win32_rstrtmgr.py +60 -0
- angr/procedures/definitions/win32_rtm.py +190 -0
- angr/procedures/definitions/win32_rtutils.py +120 -0
- angr/procedures/definitions/win32_rtworkq.py +104 -0
- angr/procedures/definitions/win32_sas.py +40 -0
- angr/procedures/definitions/win32_scarddlg.py +48 -0
- angr/procedures/definitions/win32_schannel.py +56 -0
- angr/procedures/definitions/win32_sechost.py +42 -0
- angr/procedures/definitions/win32_secur32.py +216 -0
- angr/procedures/definitions/win32_sensapi.py +44 -0
- angr/procedures/definitions/win32_sensorsutilsv2.py +118 -0
- angr/procedures/definitions/win32_setupapi.py +706 -0
- angr/procedures/definitions/win32_sfc.py +50 -0
- angr/procedures/definitions/win32_shdocvw.py +44 -0
- angr/procedures/definitions/win32_shell32.py +526 -0
- angr/procedures/definitions/win32_shlwapi.py +758 -0
- angr/procedures/definitions/win32_slc.py +102 -0
- angr/procedures/definitions/win32_slcext.py +46 -0
- angr/procedures/definitions/win32_slwga.py +40 -0
- angr/procedures/definitions/win32_snmpapi.py +90 -0
- angr/procedures/definitions/win32_spoolss.py +90 -0
- angr/procedures/definitions/win32_srclient.py +40 -0
- angr/procedures/definitions/win32_srpapi.py +60 -0
- angr/procedures/definitions/win32_sspicli.py +52 -0
- angr/procedures/definitions/win32_sti.py +40 -0
- angr/procedures/definitions/win32_t2embed.py +66 -0
- angr/procedures/definitions/win32_tapi32.py +536 -0
- angr/procedures/definitions/win32_tbs.py +66 -0
- angr/procedures/definitions/win32_tdh.py +92 -0
- angr/procedures/definitions/win32_tokenbinding.py +58 -0
- angr/procedures/definitions/win32_traffic.py +78 -0
- angr/procedures/definitions/win32_txfw32.py +56 -0
- angr/procedures/definitions/win32_ualapi.py +46 -0
- angr/procedures/definitions/win32_uiautomationcore.py +234 -0
- angr/procedures/definitions/win32_urlmon.py +192 -0
- angr/procedures/definitions/win32_user32.py +1565 -0
- angr/procedures/definitions/win32_userenv.py +126 -0
- angr/procedures/definitions/win32_usp10.py +118 -0
- angr/procedures/definitions/win32_uxtheme.py +192 -0
- angr/procedures/definitions/win32_verifier.py +40 -0
- angr/procedures/definitions/win32_version.py +66 -0
- angr/procedures/definitions/win32_vertdll.py +52 -0
- angr/procedures/definitions/win32_virtdisk.py +96 -0
- angr/procedures/definitions/win32_vmdevicehost.py +64 -0
- angr/procedures/definitions/win32_vmsavedstatedumpprovider.py +124 -0
- angr/procedures/definitions/win32_vssapi.py +40 -0
- angr/procedures/definitions/win32_wcmapi.py +48 -0
- angr/procedures/definitions/win32_wdsbp.py +52 -0
- angr/procedures/definitions/win32_wdsclientapi.py +112 -0
- angr/procedures/definitions/win32_wdsmc.py +50 -0
- angr/procedures/definitions/win32_wdspxe.py +100 -0
- angr/procedures/definitions/win32_wdstptc.py +64 -0
- angr/procedures/definitions/win32_webauthn.py +64 -0
- angr/procedures/definitions/win32_webservices.py +424 -0
- angr/procedures/definitions/win32_websocket.py +64 -0
- angr/procedures/definitions/win32_wecapi.py +68 -0
- angr/procedures/definitions/win32_wer.py +80 -0
- angr/procedures/definitions/win32_wevtapi.py +108 -0
- angr/procedures/definitions/win32_winbio.py +146 -0
- angr/procedures/definitions/win32_windows_ai_machinelearning.py +40 -0
- angr/procedures/definitions/win32_windows_data_pdf.py +23 -0
- angr/procedures/definitions/win32_windows_media_mediacontrol.py +54 -0
- angr/procedures/definitions/win32_windows_networking.py +40 -0
- angr/procedures/definitions/win32_windows_ui_xaml.py +42 -0
- angr/procedures/definitions/win32_windowscodecs.py +56 -0
- angr/procedures/definitions/win32_winfax.py +150 -0
- angr/procedures/definitions/win32_winhttp.py +150 -0
- angr/procedures/definitions/win32_winhvemulation.py +46 -0
- angr/procedures/definitions/win32_winhvplatform.py +170 -0
- angr/procedures/definitions/win32_wininet.py +630 -0
- angr/procedures/definitions/win32_winml.py +40 -0
- angr/procedures/definitions/win32_winmm.py +390 -0
- angr/procedures/definitions/win32_winscard.py +178 -0
- angr/procedures/definitions/win32_winspool.py +363 -0
- angr/procedures/definitions/win32_winspool_drv.py +382 -0
- angr/procedures/definitions/win32_wintrust.py +158 -0
- angr/procedures/definitions/win32_winusb.py +106 -0
- angr/procedures/definitions/win32_wlanapi.py +158 -0
- angr/procedures/definitions/win32_wlanui.py +40 -0
- angr/procedures/definitions/win32_wldap32.py +524 -0
- angr/procedures/definitions/win32_wldp.py +56 -0
- angr/procedures/definitions/win32_wmvcore.py +60 -0
- angr/procedures/definitions/win32_wnvapi.py +42 -0
- angr/procedures/definitions/win32_wofutil.py +60 -0
- angr/procedures/definitions/win32_ws2_32.py +358 -0
- angr/procedures/definitions/win32_wscapi.py +50 -0
- angr/procedures/definitions/win32_wsclient.py +44 -0
- angr/procedures/definitions/win32_wsdapi.py +102 -0
- angr/procedures/definitions/win32_wsmsvc.py +104 -0
- angr/procedures/definitions/win32_wsnmp32.py +136 -0
- angr/procedures/definitions/win32_wtsapi32.py +164 -0
- angr/procedures/definitions/win32_xaudio2_8.py +46 -0
- angr/procedures/definitions/win32_xinput1_4.py +52 -0
- angr/procedures/definitions/win32_xinputuap.py +35 -0
- angr/procedures/definitions/win32_xmllite.py +50 -0
- angr/procedures/definitions/win32_xolehlp.py +46 -0
- angr/procedures/definitions/win32_xpsprint.py +42 -0
- angr/procedures/glibc/__ctype_b_loc.py +22 -0
- angr/procedures/glibc/__ctype_tolower_loc.py +22 -0
- angr/procedures/glibc/__ctype_toupper_loc.py +22 -0
- angr/procedures/glibc/__errno_location.py +6 -0
- angr/procedures/glibc/__init__.py +3 -0
- angr/procedures/glibc/__libc_init.py +36 -0
- angr/procedures/glibc/__libc_start_main.py +294 -0
- angr/procedures/glibc/dynamic_loading.py +19 -0
- angr/procedures/glibc/scanf.py +10 -0
- angr/procedures/glibc/sscanf.py +5 -0
- angr/procedures/gnulib/__init__.py +3 -0
- angr/procedures/gnulib/xalloc_die.py +13 -0
- angr/procedures/gnulib/xstrtol_fatal.py +13 -0
- angr/procedures/java/__init__.py +38 -0
- angr/procedures/java/unconstrained.py +64 -0
- angr/procedures/java_io/__init__.py +0 -0
- angr/procedures/java_io/read.py +11 -0
- angr/procedures/java_io/write.py +16 -0
- angr/procedures/java_jni/__init__.py +475 -0
- angr/procedures/java_jni/array_operations.py +309 -0
- angr/procedures/java_jni/class_and_interface_operations.py +31 -0
- angr/procedures/java_jni/field_access.py +176 -0
- angr/procedures/java_jni/global_and_local_refs.py +56 -0
- angr/procedures/java_jni/method_calls.py +364 -0
- angr/procedures/java_jni/not_implemented.py +25 -0
- angr/procedures/java_jni/object_operations.py +95 -0
- angr/procedures/java_jni/string_operations.py +86 -0
- angr/procedures/java_jni/version_information.py +11 -0
- angr/procedures/java_lang/__init__.py +0 -0
- angr/procedures/java_lang/character.py +31 -0
- angr/procedures/java_lang/double.py +24 -0
- angr/procedures/java_lang/exit.py +12 -0
- angr/procedures/java_lang/getsimplename.py +15 -0
- angr/procedures/java_lang/integer.py +42 -0
- angr/procedures/java_lang/load_library.py +8 -0
- angr/procedures/java_lang/math.py +14 -0
- angr/procedures/java_lang/string.py +78 -0
- angr/procedures/java_lang/stringbuilder.py +43 -0
- angr/procedures/java_lang/system.py +17 -0
- angr/procedures/java_util/__init__.py +0 -0
- angr/procedures/java_util/collection.py +34 -0
- angr/procedures/java_util/iterator.py +45 -0
- angr/procedures/java_util/list.py +98 -0
- angr/procedures/java_util/map.py +132 -0
- angr/procedures/java_util/random.py +11 -0
- angr/procedures/java_util/scanner_nextline.py +22 -0
- angr/procedures/libc/__init__.py +3 -0
- angr/procedures/libc/abort.py +8 -0
- angr/procedures/libc/access.py +10 -0
- angr/procedures/libc/atoi.py +14 -0
- angr/procedures/libc/atol.py +12 -0
- angr/procedures/libc/calloc.py +7 -0
- angr/procedures/libc/closelog.py +9 -0
- angr/procedures/libc/err.py +13 -0
- angr/procedures/libc/error.py +55 -0
- angr/procedures/libc/exit.py +10 -0
- angr/procedures/libc/fclose.py +20 -0
- angr/procedures/libc/feof.py +19 -0
- angr/procedures/libc/fflush.py +15 -0
- angr/procedures/libc/fgetc.py +24 -0
- angr/procedures/libc/fgets.py +68 -0
- angr/procedures/libc/fopen.py +64 -0
- angr/procedures/libc/fprintf.py +24 -0
- angr/procedures/libc/fputc.py +22 -0
- angr/procedures/libc/fputs.py +23 -0
- angr/procedures/libc/fread.py +22 -0
- angr/procedures/libc/free.py +8 -0
- angr/procedures/libc/fscanf.py +20 -0
- angr/procedures/libc/fseek.py +32 -0
- angr/procedures/libc/ftell.py +21 -0
- angr/procedures/libc/fwrite.py +18 -0
- angr/procedures/libc/getchar.py +13 -0
- angr/procedures/libc/getdelim.py +96 -0
- angr/procedures/libc/getegid.py +7 -0
- angr/procedures/libc/geteuid.py +7 -0
- angr/procedures/libc/getgid.py +7 -0
- angr/procedures/libc/gets.py +66 -0
- angr/procedures/libc/getuid.py +7 -0
- angr/procedures/libc/malloc.py +11 -0
- angr/procedures/libc/memcmp.py +69 -0
- angr/procedures/libc/memcpy.py +37 -0
- angr/procedures/libc/memset.py +69 -0
- angr/procedures/libc/openlog.py +9 -0
- angr/procedures/libc/perror.py +12 -0
- angr/procedures/libc/printf.py +33 -0
- angr/procedures/libc/putchar.py +12 -0
- angr/procedures/libc/puts.py +16 -0
- angr/procedures/libc/rand.py +7 -0
- angr/procedures/libc/realloc.py +7 -0
- angr/procedures/libc/rewind.py +11 -0
- angr/procedures/libc/scanf.py +20 -0
- angr/procedures/libc/setbuf.py +8 -0
- angr/procedures/libc/setvbuf.py +6 -0
- angr/procedures/libc/snprintf.py +33 -0
- angr/procedures/libc/sprintf.py +22 -0
- angr/procedures/libc/srand.py +6 -0
- angr/procedures/libc/sscanf.py +13 -0
- angr/procedures/libc/stpcpy.py +18 -0
- angr/procedures/libc/strcat.py +13 -0
- angr/procedures/libc/strchr.py +44 -0
- angr/procedures/libc/strcmp.py +28 -0
- angr/procedures/libc/strcpy.py +13 -0
- angr/procedures/libc/strlen.py +99 -0
- angr/procedures/libc/strncat.py +18 -0
- angr/procedures/libc/strncmp.py +180 -0
- angr/procedures/libc/strncpy.py +18 -0
- angr/procedures/libc/strnlen.py +13 -0
- angr/procedures/libc/strstr.py +94 -0
- angr/procedures/libc/strtol.py +263 -0
- angr/procedures/libc/strtoul.py +9 -0
- angr/procedures/libc/system.py +12 -0
- angr/procedures/libc/time.py +9 -0
- angr/procedures/libc/tmpnam.py +19 -0
- angr/procedures/libc/tolower.py +7 -0
- angr/procedures/libc/toupper.py +7 -0
- angr/procedures/libc/ungetc.py +19 -0
- angr/procedures/libc/vsnprintf.py +16 -0
- angr/procedures/libc/wchar.py +15 -0
- angr/procedures/libstdcpp/__init__.py +0 -0
- angr/procedures/libstdcpp/_unwind_resume.py +10 -0
- angr/procedures/libstdcpp/std____throw_bad_alloc.py +12 -0
- angr/procedures/libstdcpp/std____throw_bad_cast.py +12 -0
- angr/procedures/libstdcpp/std____throw_length_error.py +12 -0
- angr/procedures/libstdcpp/std____throw_logic_error.py +12 -0
- angr/procedures/libstdcpp/std__terminate.py +12 -0
- angr/procedures/linux_kernel/__init__.py +3 -0
- angr/procedures/linux_kernel/access.py +17 -0
- angr/procedures/linux_kernel/arch_prctl.py +33 -0
- angr/procedures/linux_kernel/arm_user_helpers.py +58 -0
- angr/procedures/linux_kernel/brk.py +17 -0
- angr/procedures/linux_kernel/cwd.py +27 -0
- angr/procedures/linux_kernel/fstat.py +137 -0
- angr/procedures/linux_kernel/fstat64.py +169 -0
- angr/procedures/linux_kernel/futex.py +17 -0
- angr/procedures/linux_kernel/getegid.py +16 -0
- angr/procedures/linux_kernel/geteuid.py +16 -0
- angr/procedures/linux_kernel/getgid.py +16 -0
- angr/procedures/linux_kernel/getpid.py +13 -0
- angr/procedures/linux_kernel/getrlimit.py +24 -0
- angr/procedures/linux_kernel/gettid.py +8 -0
- angr/procedures/linux_kernel/getuid.py +16 -0
- angr/procedures/linux_kernel/iovec.py +43 -0
- angr/procedures/linux_kernel/lseek.py +39 -0
- angr/procedures/linux_kernel/mmap.py +15 -0
- angr/procedures/linux_kernel/mprotect.py +41 -0
- angr/procedures/linux_kernel/munmap.py +7 -0
- angr/procedures/linux_kernel/openat.py +28 -0
- angr/procedures/linux_kernel/set_tid_address.py +7 -0
- angr/procedures/linux_kernel/sigaction.py +16 -0
- angr/procedures/linux_kernel/sigprocmask.py +20 -0
- angr/procedures/linux_kernel/stat.py +22 -0
- angr/procedures/linux_kernel/sysinfo.py +58 -0
- angr/procedures/linux_kernel/tgkill.py +7 -0
- angr/procedures/linux_kernel/time.py +30 -0
- angr/procedures/linux_kernel/uid.py +29 -0
- angr/procedures/linux_kernel/uname.py +28 -0
- angr/procedures/linux_kernel/unlink.py +22 -0
- angr/procedures/linux_kernel/vsyscall.py +15 -0
- angr/procedures/linux_loader/__init__.py +3 -0
- angr/procedures/linux_loader/_dl_initial_error_catch_tsd.py +6 -0
- angr/procedures/linux_loader/_dl_rtld_lock.py +14 -0
- angr/procedures/linux_loader/sim_loader.py +53 -0
- angr/procedures/linux_loader/tls.py +40 -0
- angr/procedures/msvcr/__getmainargs.py +15 -0
- angr/procedures/msvcr/__init__.py +4 -0
- angr/procedures/msvcr/_initterm.py +37 -0
- angr/procedures/msvcr/fmode.py +28 -0
- angr/procedures/ntdll/__init__.py +0 -0
- angr/procedures/ntdll/exceptions.py +57 -0
- angr/procedures/posix/__init__.py +3 -0
- angr/procedures/posix/accept.py +29 -0
- angr/procedures/posix/bind.py +12 -0
- angr/procedures/posix/bzero.py +6 -0
- angr/procedures/posix/chroot.py +26 -0
- angr/procedures/posix/close.py +9 -0
- angr/procedures/posix/closedir.py +6 -0
- angr/procedures/posix/dup.py +55 -0
- angr/procedures/posix/fcntl.py +9 -0
- angr/procedures/posix/fdopen.py +77 -0
- angr/procedures/posix/fileno.py +17 -0
- angr/procedures/posix/fork.py +10 -0
- angr/procedures/posix/getenv.py +34 -0
- angr/procedures/posix/gethostbyname.py +42 -0
- angr/procedures/posix/getpass.py +18 -0
- angr/procedures/posix/getsockopt.py +10 -0
- angr/procedures/posix/htonl.py +11 -0
- angr/procedures/posix/htons.py +11 -0
- angr/procedures/posix/inet_ntoa.py +61 -0
- angr/procedures/posix/listen.py +12 -0
- angr/procedures/posix/mmap.py +140 -0
- angr/procedures/posix/open.py +17 -0
- angr/procedures/posix/opendir.py +9 -0
- angr/procedures/posix/poll.py +54 -0
- angr/procedures/posix/pread64.py +45 -0
- angr/procedures/posix/pthread.py +87 -0
- angr/procedures/posix/pwrite64.py +45 -0
- angr/procedures/posix/read.py +12 -0
- angr/procedures/posix/readdir.py +59 -0
- angr/procedures/posix/recv.py +12 -0
- angr/procedures/posix/recvfrom.py +12 -0
- angr/procedures/posix/select.py +46 -0
- angr/procedures/posix/send.py +22 -0
- angr/procedures/posix/setsockopt.py +8 -0
- angr/procedures/posix/sigaction.py +20 -0
- angr/procedures/posix/sim_time.py +45 -0
- angr/procedures/posix/sleep.py +7 -0
- angr/procedures/posix/socket.py +18 -0
- angr/procedures/posix/strcasecmp.py +23 -0
- angr/procedures/posix/strdup.py +17 -0
- angr/procedures/posix/strtok_r.py +65 -0
- angr/procedures/posix/syslog.py +15 -0
- angr/procedures/posix/tz.py +8 -0
- angr/procedures/posix/unlink.py +10 -0
- angr/procedures/posix/usleep.py +7 -0
- angr/procedures/posix/write.py +12 -0
- angr/procedures/procedure_dict.py +48 -0
- angr/procedures/stubs/CallReturn.py +12 -0
- angr/procedures/stubs/NoReturnUnconstrained.py +12 -0
- angr/procedures/stubs/Nop.py +6 -0
- angr/procedures/stubs/PathTerminator.py +8 -0
- angr/procedures/stubs/Redirect.py +15 -0
- angr/procedures/stubs/ReturnChar.py +10 -0
- angr/procedures/stubs/ReturnUnconstrained.py +24 -0
- angr/procedures/stubs/UnresolvableCallTarget.py +8 -0
- angr/procedures/stubs/UnresolvableJumpTarget.py +8 -0
- angr/procedures/stubs/UserHook.py +15 -0
- angr/procedures/stubs/__init__.py +3 -0
- angr/procedures/stubs/b64_decode.py +12 -0
- angr/procedures/stubs/caller.py +13 -0
- angr/procedures/stubs/crazy_scanf.py +17 -0
- angr/procedures/stubs/format_parser.py +677 -0
- angr/procedures/stubs/syscall_stub.py +26 -0
- angr/procedures/testing/__init__.py +3 -0
- angr/procedures/testing/manyargs.py +8 -0
- angr/procedures/testing/retreg.py +8 -0
- angr/procedures/tracer/__init__.py +4 -0
- angr/procedures/tracer/random.py +8 -0
- angr/procedures/tracer/receive.py +21 -0
- angr/procedures/tracer/transmit.py +24 -0
- angr/procedures/uclibc/__init__.py +3 -0
- angr/procedures/uclibc/__uClibc_main.py +9 -0
- angr/procedures/win32/EncodePointer.py +6 -0
- angr/procedures/win32/ExitProcess.py +8 -0
- angr/procedures/win32/GetCommandLine.py +11 -0
- angr/procedures/win32/GetCurrentProcessId.py +6 -0
- angr/procedures/win32/GetCurrentThreadId.py +6 -0
- angr/procedures/win32/GetLastInputInfo.py +37 -0
- angr/procedures/win32/GetModuleHandle.py +30 -0
- angr/procedures/win32/GetProcessAffinityMask.py +34 -0
- angr/procedures/win32/InterlockedExchange.py +14 -0
- angr/procedures/win32/IsProcessorFeaturePresent.py +6 -0
- angr/procedures/win32/VirtualAlloc.py +113 -0
- angr/procedures/win32/VirtualProtect.py +59 -0
- angr/procedures/win32/__init__.py +3 -0
- angr/procedures/win32/critical_section.py +11 -0
- angr/procedures/win32/dynamic_loading.py +103 -0
- angr/procedures/win32/file_handles.py +47 -0
- angr/procedures/win32/gethostbyname.py +10 -0
- angr/procedures/win32/heap.py +42 -0
- angr/procedures/win32/is_bad_ptr.py +25 -0
- angr/procedures/win32/local_storage.py +85 -0
- angr/procedures/win32/mutex.py +10 -0
- angr/procedures/win32/sim_time.py +135 -0
- angr/procedures/win32/system_paths.py +34 -0
- angr/procedures/win32_kernel/ExAllocatePool.py +12 -0
- angr/procedures/win32_kernel/ExFreePoolWithTag.py +7 -0
- angr/procedures/win32_kernel/__init__.py +3 -0
- angr/procedures/win_user32/__init__.py +0 -0
- angr/procedures/win_user32/chars.py +12 -0
- angr/procedures/win_user32/keyboard.py +13 -0
- angr/procedures/win_user32/messagebox.py +49 -0
- angr/project.py +834 -0
- angr/protos/__init__.py +13 -0
- angr/protos/cfg_pb2.py +31 -0
- angr/protos/function_pb2.py +37 -0
- angr/protos/primitives_pb2.py +124 -0
- angr/protos/variables_pb2.py +126 -0
- angr/protos/xrefs_pb2.py +34 -0
- angr/py.typed +1 -0
- angr/serializable.py +63 -0
- angr/service.py +35 -0
- angr/sim_manager.py +971 -0
- angr/sim_options.py +444 -0
- angr/sim_procedure.py +606 -0
- angr/sim_state.py +1003 -0
- angr/sim_state_options.py +409 -0
- angr/sim_type.py +3372 -0
- angr/sim_variable.py +562 -0
- angr/simos/__init__.py +31 -0
- angr/simos/cgc.py +152 -0
- angr/simos/javavm.py +471 -0
- angr/simos/linux.py +519 -0
- angr/simos/simos.py +450 -0
- angr/simos/snimmuc_nxp.py +152 -0
- angr/simos/userland.py +163 -0
- angr/simos/windows.py +562 -0
- angr/slicer.py +353 -0
- angr/state_hierarchy.py +262 -0
- angr/state_plugins/__init__.py +29 -0
- angr/state_plugins/callstack.py +404 -0
- angr/state_plugins/cgc.py +153 -0
- angr/state_plugins/concrete.py +297 -0
- angr/state_plugins/debug_variables.py +194 -0
- angr/state_plugins/filesystem.py +469 -0
- angr/state_plugins/gdb.py +146 -0
- angr/state_plugins/globals.py +62 -0
- angr/state_plugins/heap/__init__.py +5 -0
- angr/state_plugins/heap/heap_base.py +126 -0
- angr/state_plugins/heap/heap_brk.py +134 -0
- angr/state_plugins/heap/heap_freelist.py +210 -0
- angr/state_plugins/heap/heap_libc.py +45 -0
- angr/state_plugins/heap/heap_ptmalloc.py +646 -0
- angr/state_plugins/heap/utils.py +21 -0
- angr/state_plugins/history.py +548 -0
- angr/state_plugins/inspect.py +376 -0
- angr/state_plugins/javavm_classloader.py +133 -0
- angr/state_plugins/jni_references.py +93 -0
- angr/state_plugins/libc.py +1263 -0
- angr/state_plugins/light_registers.py +170 -0
- angr/state_plugins/log.py +85 -0
- angr/state_plugins/loop_data.py +92 -0
- angr/state_plugins/plugin.py +155 -0
- angr/state_plugins/posix.py +709 -0
- angr/state_plugins/preconstrainer.py +195 -0
- angr/state_plugins/scratch.py +175 -0
- angr/state_plugins/sim_action.py +334 -0
- angr/state_plugins/sim_action_object.py +148 -0
- angr/state_plugins/sim_event.py +58 -0
- angr/state_plugins/solver.py +1129 -0
- angr/state_plugins/symbolizer.py +292 -0
- angr/state_plugins/trace_additions.py +752 -0
- angr/state_plugins/uc_manager.py +85 -0
- angr/state_plugins/unicorn_engine.py +1899 -0
- angr/state_plugins/view.py +341 -0
- angr/storage/__init__.py +9 -0
- angr/storage/file.py +1219 -0
- angr/storage/memory_mixins/__init__.py +393 -0
- angr/storage/memory_mixins/__init__.pyi +49 -0
- angr/storage/memory_mixins/actions_mixin.py +69 -0
- angr/storage/memory_mixins/address_concretization_mixin.py +388 -0
- angr/storage/memory_mixins/bvv_conversion_mixin.py +74 -0
- angr/storage/memory_mixins/clouseau_mixin.py +131 -0
- angr/storage/memory_mixins/conditional_store_mixin.py +24 -0
- angr/storage/memory_mixins/convenient_mappings_mixin.py +257 -0
- angr/storage/memory_mixins/default_filler_mixin.py +146 -0
- angr/storage/memory_mixins/dirty_addrs_mixin.py +9 -0
- angr/storage/memory_mixins/hex_dumper_mixin.py +85 -0
- angr/storage/memory_mixins/javavm_memory/__init__.py +1 -0
- angr/storage/memory_mixins/javavm_memory/javavm_memory_mixin.py +394 -0
- angr/storage/memory_mixins/keyvalue_memory/__init__.py +1 -0
- angr/storage/memory_mixins/keyvalue_memory/keyvalue_memory_mixin.py +36 -0
- angr/storage/memory_mixins/label_merger_mixin.py +31 -0
- angr/storage/memory_mixins/multi_value_merger_mixin.py +68 -0
- angr/storage/memory_mixins/name_resolution_mixin.py +70 -0
- angr/storage/memory_mixins/paged_memory/__init__.py +0 -0
- angr/storage/memory_mixins/paged_memory/page_backer_mixins.py +266 -0
- angr/storage/memory_mixins/paged_memory/paged_memory_mixin.py +750 -0
- angr/storage/memory_mixins/paged_memory/paged_memory_multivalue_mixin.py +63 -0
- angr/storage/memory_mixins/paged_memory/pages/__init__.py +33 -0
- angr/storage/memory_mixins/paged_memory/pages/cooperation.py +330 -0
- angr/storage/memory_mixins/paged_memory/pages/history_tracking_mixin.py +87 -0
- angr/storage/memory_mixins/paged_memory/pages/ispo_mixin.py +53 -0
- angr/storage/memory_mixins/paged_memory/pages/list_page.py +346 -0
- angr/storage/memory_mixins/paged_memory/pages/multi_values.py +290 -0
- angr/storage/memory_mixins/paged_memory/pages/mv_list_page.py +434 -0
- angr/storage/memory_mixins/paged_memory/pages/permissions_mixin.py +33 -0
- angr/storage/memory_mixins/paged_memory/pages/refcount_mixin.py +51 -0
- angr/storage/memory_mixins/paged_memory/pages/ultra_page.py +468 -0
- angr/storage/memory_mixins/paged_memory/privileged_mixin.py +36 -0
- angr/storage/memory_mixins/paged_memory/stack_allocation_mixin.py +73 -0
- angr/storage/memory_mixins/regioned_memory/__init__.py +6 -0
- angr/storage/memory_mixins/regioned_memory/abstract_address_descriptor.py +35 -0
- angr/storage/memory_mixins/regioned_memory/abstract_merger_mixin.py +43 -0
- angr/storage/memory_mixins/regioned_memory/region_category_mixin.py +7 -0
- angr/storage/memory_mixins/regioned_memory/region_data.py +245 -0
- angr/storage/memory_mixins/regioned_memory/region_meta_mixin.py +125 -0
- angr/storage/memory_mixins/regioned_memory/regioned_address_concretization_mixin.py +118 -0
- angr/storage/memory_mixins/regioned_memory/regioned_memory_mixin.py +462 -0
- angr/storage/memory_mixins/regioned_memory/static_find_mixin.py +70 -0
- angr/storage/memory_mixins/simple_interface_mixin.py +73 -0
- angr/storage/memory_mixins/simplification_mixin.py +13 -0
- angr/storage/memory_mixins/size_resolution_mixin.py +140 -0
- angr/storage/memory_mixins/slotted_memory.py +140 -0
- angr/storage/memory_mixins/smart_find_mixin.py +159 -0
- angr/storage/memory_mixins/symbolic_merger_mixin.py +12 -0
- angr/storage/memory_mixins/top_merger_mixin.py +24 -0
- angr/storage/memory_mixins/underconstrained_mixin.py +67 -0
- angr/storage/memory_mixins/unwrapper_mixin.py +26 -0
- angr/storage/memory_object.py +194 -0
- angr/storage/pcap.py +65 -0
- angr/tablespecs.py +90 -0
- angr/utils/__init__.py +33 -0
- angr/utils/algo.py +33 -0
- angr/utils/constants.py +7 -0
- angr/utils/cowdict.py +64 -0
- angr/utils/dynamic_dictlist.py +92 -0
- angr/utils/enums_conv.py +80 -0
- angr/utils/env.py +11 -0
- angr/utils/formatting.py +124 -0
- angr/utils/funcid.py +133 -0
- angr/utils/graph.py +822 -0
- angr/utils/lazy_import.py +12 -0
- angr/utils/library.py +214 -0
- angr/utils/loader.py +55 -0
- angr/utils/mp.py +64 -0
- angr/utils/segment_list.py +558 -0
- angr/utils/timing.py +45 -0
- angr/utils/typing.py +17 -0
- angr/vaults.py +370 -0
- angr-9.2.103.dist-info/LICENSE +24 -0
- angr-9.2.103.dist-info/METADATA +119 -0
- angr-9.2.103.dist-info/RECORD +1300 -0
- angr-9.2.103.dist-info/WHEEL +5 -0
- angr-9.2.103.dist-info/entry_points.txt +2 -0
- angr-9.2.103.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,2383 @@
|
|
|
1
|
+
# pylint:disable=line-too-long,missing-class-docstring,no-self-use
|
|
2
|
+
import logging
|
|
3
|
+
from typing import Optional, Union
|
|
4
|
+
from collections import defaultdict
|
|
5
|
+
|
|
6
|
+
import claripy
|
|
7
|
+
import archinfo
|
|
8
|
+
from archinfo import RegisterName
|
|
9
|
+
from unique_log_filter import UniqueLogFilter
|
|
10
|
+
|
|
11
|
+
from .errors import AngrTypeError
|
|
12
|
+
from .sim_type import (
|
|
13
|
+
SimType,
|
|
14
|
+
SimTypeChar,
|
|
15
|
+
SimTypePointer,
|
|
16
|
+
SimTypeFixedSizeArray,
|
|
17
|
+
SimTypeArray,
|
|
18
|
+
SimTypeString,
|
|
19
|
+
SimTypeFunction,
|
|
20
|
+
SimTypeFloat,
|
|
21
|
+
SimTypeDouble,
|
|
22
|
+
SimTypeReg,
|
|
23
|
+
SimStruct,
|
|
24
|
+
SimStructValue,
|
|
25
|
+
SimTypeInt,
|
|
26
|
+
SimTypeNum,
|
|
27
|
+
SimUnion,
|
|
28
|
+
SimTypeBottom,
|
|
29
|
+
parse_signature,
|
|
30
|
+
SimTypeReference,
|
|
31
|
+
)
|
|
32
|
+
from .state_plugins.sim_action_object import SimActionObject
|
|
33
|
+
from .engines.soot.engine import SootMixin
|
|
34
|
+
|
|
35
|
+
l = logging.getLogger(name=__name__)
|
|
36
|
+
l.addFilter(UniqueLogFilter())
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class PointerWrapper:
|
|
40
|
+
def __init__(self, value, buffer=False):
|
|
41
|
+
self.value = value
|
|
42
|
+
self.buffer = buffer
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class AllocHelper:
|
|
46
|
+
def __init__(self, ptrsize):
|
|
47
|
+
self.base = claripy.BVS("alloc_base", ptrsize)
|
|
48
|
+
self.ptr = self.base
|
|
49
|
+
self.stores = {}
|
|
50
|
+
|
|
51
|
+
def alloc(self, size):
|
|
52
|
+
out = self.ptr
|
|
53
|
+
self.ptr += size
|
|
54
|
+
return out
|
|
55
|
+
|
|
56
|
+
def dump(self, val, state, loc=None):
|
|
57
|
+
if loc is None:
|
|
58
|
+
loc = self.stack_loc(val, state.arch)
|
|
59
|
+
self.stores[self.ptr.cache_key] = (val, loc)
|
|
60
|
+
return self.alloc(self.calc_size(val, state.arch))
|
|
61
|
+
|
|
62
|
+
def translate(self, val, base):
|
|
63
|
+
if type(val) is SimStructValue:
|
|
64
|
+
return SimStructValue(
|
|
65
|
+
val.struct, {field: self.translate(subval, base) for field, subval in val._values.items()}
|
|
66
|
+
)
|
|
67
|
+
if isinstance(val, claripy.Bits):
|
|
68
|
+
return val.replace(self.base, base)
|
|
69
|
+
if type(val) is list:
|
|
70
|
+
return [self.translate(subval, base) for subval in val]
|
|
71
|
+
raise TypeError(type(val))
|
|
72
|
+
|
|
73
|
+
def apply(self, state, base):
|
|
74
|
+
for ptr, (val, loc) in self.stores.items():
|
|
75
|
+
translated_val = self.translate(val, base)
|
|
76
|
+
translated_ptr = self.translate(ptr.ast, base)
|
|
77
|
+
loc.set_value(state, translated_val, stack_base=translated_ptr)
|
|
78
|
+
|
|
79
|
+
def size(self):
|
|
80
|
+
val = self.translate(self.ptr, claripy.BVV(0, len(self.ptr)))
|
|
81
|
+
assert val.op == "BVV"
|
|
82
|
+
return abs(val.args[0])
|
|
83
|
+
|
|
84
|
+
@classmethod
|
|
85
|
+
def calc_size(cls, val, arch):
|
|
86
|
+
if type(val) is SimStructValue:
|
|
87
|
+
return val.struct.size // arch.byte_width
|
|
88
|
+
if isinstance(val, claripy.Bits):
|
|
89
|
+
return len(val) // arch.byte_width
|
|
90
|
+
if type(val) is list:
|
|
91
|
+
# TODO real strides
|
|
92
|
+
if len(val) == 0:
|
|
93
|
+
return 0
|
|
94
|
+
return cls.calc_size(val[0], arch) * len(val)
|
|
95
|
+
raise TypeError(type(val))
|
|
96
|
+
|
|
97
|
+
@classmethod
|
|
98
|
+
def stack_loc(cls, val, arch, offset=0):
|
|
99
|
+
if isinstance(val, claripy.Bits):
|
|
100
|
+
return SimStackArg(offset, len(val) // arch.byte_width)
|
|
101
|
+
if type(val) is list:
|
|
102
|
+
# TODO real strides
|
|
103
|
+
if len(val) == 0:
|
|
104
|
+
return SimArrayArg([])
|
|
105
|
+
stride = cls.calc_size(val[0], arch)
|
|
106
|
+
return SimArrayArg([cls.stack_loc(subval, arch, offset + i * stride) for i, subval in enumerate(val)])
|
|
107
|
+
if type(val) is SimStructValue:
|
|
108
|
+
return SimStructArg(
|
|
109
|
+
val.struct,
|
|
110
|
+
{
|
|
111
|
+
field: cls.stack_loc(subval, arch, offset + val.struct.offsets[field])
|
|
112
|
+
for field, subval in val._values.items()
|
|
113
|
+
},
|
|
114
|
+
)
|
|
115
|
+
raise TypeError(type(val))
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def refine_locs_with_struct_type(
|
|
119
|
+
arch: archinfo.Arch, locs: list, arg_type: SimType, offset: int = 0, treat_bot_as_int=True
|
|
120
|
+
):
|
|
121
|
+
# CONTRACT FOR USING THIS METHOD: locs must be a list of locs which are all wordsize
|
|
122
|
+
# ADDITIONAL NUANCE: this will not respect the need for big-endian integers to be stored at the end of words.
|
|
123
|
+
# that's why this is named with_struct_type, because it will blindly trust the offsets given to it.
|
|
124
|
+
|
|
125
|
+
if treat_bot_as_int and isinstance(arg_type, SimTypeBottom):
|
|
126
|
+
arg_type = SimTypeInt(label=arg_type.label).with_arch(arch)
|
|
127
|
+
|
|
128
|
+
if isinstance(arg_type, (SimTypeReg, SimTypeNum, SimTypeFloat)):
|
|
129
|
+
seen_bytes = 0
|
|
130
|
+
pieces = []
|
|
131
|
+
while seen_bytes < arg_type.size // arch.byte_width:
|
|
132
|
+
start_offset = offset + seen_bytes
|
|
133
|
+
chunk = start_offset // arch.bytes
|
|
134
|
+
chunk_offset = start_offset % arch.bytes
|
|
135
|
+
chunk_remaining = arch.bytes - chunk_offset
|
|
136
|
+
type_remaining = arg_type.size // arch.byte_width - seen_bytes
|
|
137
|
+
use_bytes = min(chunk_remaining, type_remaining)
|
|
138
|
+
pieces.append(locs[chunk].refine(size=use_bytes, offset=chunk_offset))
|
|
139
|
+
seen_bytes += use_bytes
|
|
140
|
+
|
|
141
|
+
if len(pieces) == 1:
|
|
142
|
+
piece = pieces[0]
|
|
143
|
+
else:
|
|
144
|
+
piece = SimComboArg(pieces)
|
|
145
|
+
if isinstance(arg_type, SimTypeFloat):
|
|
146
|
+
piece.is_fp = True
|
|
147
|
+
return piece
|
|
148
|
+
if isinstance(arg_type, SimTypeFixedSizeArray):
|
|
149
|
+
# TODO explicit stride
|
|
150
|
+
locs = [
|
|
151
|
+
refine_locs_with_struct_type(
|
|
152
|
+
arch, locs, arg_type.elem_type, offset=offset + i * arg_type.elem_type.size // arch.byte_width
|
|
153
|
+
)
|
|
154
|
+
for i in range(arg_type.length)
|
|
155
|
+
]
|
|
156
|
+
return SimArrayArg(locs)
|
|
157
|
+
if isinstance(arg_type, SimStruct):
|
|
158
|
+
locs = {
|
|
159
|
+
field: refine_locs_with_struct_type(arch, locs, field_ty, offset=offset + arg_type.offsets[field])
|
|
160
|
+
for field, field_ty in arg_type.fields.items()
|
|
161
|
+
}
|
|
162
|
+
return SimStructArg(arg_type, locs)
|
|
163
|
+
if isinstance(arg_type, SimUnion):
|
|
164
|
+
# Treat a SimUnion as functionality equivalent to its longest member
|
|
165
|
+
for member in arg_type.members.values():
|
|
166
|
+
if member.size == arg_type.size:
|
|
167
|
+
return refine_locs_with_struct_type(arch, locs, member, offset)
|
|
168
|
+
|
|
169
|
+
raise TypeError("I don't know how to lay out a %s" % arg_type)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
class SerializableIterator:
|
|
173
|
+
def __iter__(self):
|
|
174
|
+
return self
|
|
175
|
+
|
|
176
|
+
def __next__(self):
|
|
177
|
+
raise NotImplementedError
|
|
178
|
+
|
|
179
|
+
def getstate(self):
|
|
180
|
+
raise NotImplementedError
|
|
181
|
+
|
|
182
|
+
def setstate(self, state):
|
|
183
|
+
raise NotImplementedError
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
class SerializableListIterator(SerializableIterator):
|
|
187
|
+
def __init__(self, lst):
|
|
188
|
+
self._lst = lst
|
|
189
|
+
self._index = 0
|
|
190
|
+
|
|
191
|
+
def __next__(self):
|
|
192
|
+
if self._index >= len(self._lst):
|
|
193
|
+
raise StopIteration
|
|
194
|
+
result = self._lst[self._index]
|
|
195
|
+
self._index += 1
|
|
196
|
+
return result
|
|
197
|
+
|
|
198
|
+
def getstate(self):
|
|
199
|
+
return self._index
|
|
200
|
+
|
|
201
|
+
def setstate(self, state):
|
|
202
|
+
self._index = state
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
class SerializableCounter(SerializableIterator):
|
|
206
|
+
def __init__(self, start, stride, mapping=lambda x: x):
|
|
207
|
+
self._next = start
|
|
208
|
+
self._stride = stride
|
|
209
|
+
self._mapping = mapping
|
|
210
|
+
|
|
211
|
+
def __next__(self):
|
|
212
|
+
result = self._mapping(self._next)
|
|
213
|
+
self._next += self._stride
|
|
214
|
+
return result
|
|
215
|
+
|
|
216
|
+
def getstate(self):
|
|
217
|
+
return self._next
|
|
218
|
+
|
|
219
|
+
def setstate(self, state):
|
|
220
|
+
self._next = state
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
class SimFunctionArgument:
|
|
224
|
+
"""
|
|
225
|
+
Represent a generic function argument.
|
|
226
|
+
|
|
227
|
+
:ivar int size: The size of the argument, in number of bytes.
|
|
228
|
+
:ivar bool is_fp: Whether loads from this location should return a floating point bitvector
|
|
229
|
+
"""
|
|
230
|
+
|
|
231
|
+
def __init__(self, size, is_fp=False):
|
|
232
|
+
self.size = size
|
|
233
|
+
self.is_fp = is_fp
|
|
234
|
+
|
|
235
|
+
def __ne__(self, other):
|
|
236
|
+
return not self == other
|
|
237
|
+
|
|
238
|
+
def __hash__(self):
|
|
239
|
+
return hash(("function_argument", self.size))
|
|
240
|
+
|
|
241
|
+
def check_value_set(self, value, arch):
|
|
242
|
+
if not isinstance(value, claripy.ast.Base) and self.size is None:
|
|
243
|
+
raise TypeError("Only claripy objects may be stored through SimFunctionArgument when size is not provided")
|
|
244
|
+
if self.size is not None and isinstance(value, claripy.ast.Base) and self.size * arch.byte_width < value.length:
|
|
245
|
+
raise TypeError("%s doesn't fit in an argument of size %d" % (value, self.size))
|
|
246
|
+
if isinstance(value, int):
|
|
247
|
+
value = claripy.BVV(value, self.size * arch.byte_width)
|
|
248
|
+
if isinstance(value, float):
|
|
249
|
+
if self.size not in (4, 8):
|
|
250
|
+
raise ValueError("What do I do with a float %d bytes long" % self.size)
|
|
251
|
+
value = claripy.FPV(value, claripy.FSORT_FLOAT if self.size == 4 else claripy.FSORT_DOUBLE)
|
|
252
|
+
return value.raw_to_bv()
|
|
253
|
+
|
|
254
|
+
def check_value_get(self, value):
|
|
255
|
+
if self.is_fp:
|
|
256
|
+
return value.raw_to_fp()
|
|
257
|
+
return value
|
|
258
|
+
|
|
259
|
+
def set_value(self, state, value, **kwargs):
|
|
260
|
+
raise NotImplementedError
|
|
261
|
+
|
|
262
|
+
def get_value(self, state, **kwargs):
|
|
263
|
+
raise NotImplementedError
|
|
264
|
+
|
|
265
|
+
def refine(self, size, arch=None, offset=None, is_fp=None):
|
|
266
|
+
raise NotImplementedError
|
|
267
|
+
|
|
268
|
+
def get_footprint(self) -> list[Union["SimRegArg", "SimStackArg"]]:
|
|
269
|
+
"""
|
|
270
|
+
Return a list of SimRegArg and SimStackArgs that are the base components used for this location
|
|
271
|
+
"""
|
|
272
|
+
raise NotImplementedError
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
class SimRegArg(SimFunctionArgument):
|
|
276
|
+
"""
|
|
277
|
+
Represents a function argument that has been passed in a register.
|
|
278
|
+
|
|
279
|
+
:ivar string reg_name: The name of the represented register.
|
|
280
|
+
:ivar int size: The size of the data to store, in number of bytes.
|
|
281
|
+
:ivar reg_offset: The offset into the register to start storing data.
|
|
282
|
+
:ivar clear_entire_reg: Whether a store to this register should zero the unused parts of the register.
|
|
283
|
+
:ivar bool is_fp: Whether loads from this location should return a floating point bitvector
|
|
284
|
+
"""
|
|
285
|
+
|
|
286
|
+
def __init__(self, reg_name: RegisterName, size: int, reg_offset=0, is_fp=False, clear_entire_reg=False):
|
|
287
|
+
super().__init__(size, is_fp)
|
|
288
|
+
self.reg_name = reg_name
|
|
289
|
+
self.reg_offset = reg_offset
|
|
290
|
+
self.clear_entire_reg = clear_entire_reg
|
|
291
|
+
|
|
292
|
+
def get_footprint(self):
|
|
293
|
+
yield self
|
|
294
|
+
|
|
295
|
+
def __repr__(self):
|
|
296
|
+
return "<%s>" % self.reg_name
|
|
297
|
+
|
|
298
|
+
def __eq__(self, other):
|
|
299
|
+
return type(other) is SimRegArg and self.reg_name == other.reg_name and self.reg_offset == other.reg_offset
|
|
300
|
+
|
|
301
|
+
def __hash__(self):
|
|
302
|
+
return hash((self.size, self.reg_name, self.reg_offset))
|
|
303
|
+
|
|
304
|
+
def check_offset(self, arch):
|
|
305
|
+
return arch.registers[self.reg_name][0] + self.reg_offset
|
|
306
|
+
|
|
307
|
+
def set_value(self, state, value, **kwargs): # pylint: disable=unused-argument,arguments-differ
|
|
308
|
+
value = self.check_value_set(value, state.arch)
|
|
309
|
+
offset = self.check_offset(state.arch)
|
|
310
|
+
if self.clear_entire_reg:
|
|
311
|
+
state.registers.store(self.reg_name, 0)
|
|
312
|
+
state.registers.store(offset, value, size=self.size)
|
|
313
|
+
|
|
314
|
+
def get_value(self, state, **kwargs): # pylint: disable=unused-argument,arguments-differ
|
|
315
|
+
offset = self.check_offset(state.arch)
|
|
316
|
+
return self.check_value_get(state.registers.load(offset, size=self.size))
|
|
317
|
+
|
|
318
|
+
def refine(self, size, arch=None, offset=None, is_fp=None):
|
|
319
|
+
passed_offset_none = offset is None
|
|
320
|
+
if offset is None:
|
|
321
|
+
if arch is None:
|
|
322
|
+
raise ValueError("Need to specify either offset or arch in order to refine a register argument")
|
|
323
|
+
if arch.register_endness == "Iend_LE":
|
|
324
|
+
offset = 0
|
|
325
|
+
else:
|
|
326
|
+
offset = self.size - size
|
|
327
|
+
if is_fp is None:
|
|
328
|
+
is_fp = self.is_fp
|
|
329
|
+
return SimRegArg(self.reg_name, size, self.reg_offset + offset, is_fp, clear_entire_reg=passed_offset_none)
|
|
330
|
+
|
|
331
|
+
def sse_extend(self):
|
|
332
|
+
return SimRegArg(self.reg_name, self.size, self.reg_offset + self.size, is_fp=self.is_fp)
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
class SimStackArg(SimFunctionArgument):
|
|
336
|
+
"""
|
|
337
|
+
Represents a function argument that has been passed on the stack.
|
|
338
|
+
|
|
339
|
+
:var int stack_offset: The position of the argument relative to the stack pointer after the function prelude.
|
|
340
|
+
:ivar int size: The size of the argument, in number of bytes.
|
|
341
|
+
:ivar bool is_fp: Whether loads from this location should return a floating point bitvector
|
|
342
|
+
"""
|
|
343
|
+
|
|
344
|
+
def __init__(self, stack_offset, size, is_fp=False):
|
|
345
|
+
SimFunctionArgument.__init__(self, size, is_fp)
|
|
346
|
+
self.stack_offset = stack_offset
|
|
347
|
+
|
|
348
|
+
def get_footprint(self):
|
|
349
|
+
yield self
|
|
350
|
+
|
|
351
|
+
def __repr__(self):
|
|
352
|
+
return "[%#x]" % self.stack_offset
|
|
353
|
+
|
|
354
|
+
def __eq__(self, other):
|
|
355
|
+
return type(other) is SimStackArg and self.stack_offset == other.stack_offset
|
|
356
|
+
|
|
357
|
+
def __hash__(self):
|
|
358
|
+
return hash((self.size, self.stack_offset))
|
|
359
|
+
|
|
360
|
+
def set_value(self, state, value, stack_base=None, **kwargs): # pylint: disable=arguments-differ
|
|
361
|
+
value = self.check_value_set(value, state.arch)
|
|
362
|
+
if stack_base is None:
|
|
363
|
+
stack_base = state.regs.sp
|
|
364
|
+
state.memory.store(stack_base + self.stack_offset, value, endness=state.arch.memory_endness)
|
|
365
|
+
|
|
366
|
+
def get_value(self, state, stack_base=None, **kwargs): # pylint: disable=arguments-differ
|
|
367
|
+
if stack_base is None:
|
|
368
|
+
stack_base = state.regs.sp
|
|
369
|
+
value = state.memory.load(stack_base + self.stack_offset, endness=state.arch.memory_endness, size=self.size)
|
|
370
|
+
return self.check_value_get(value)
|
|
371
|
+
|
|
372
|
+
def refine(self, size, arch=None, offset=None, is_fp=None):
|
|
373
|
+
if offset is None:
|
|
374
|
+
if arch is None:
|
|
375
|
+
raise ValueError("Need to specify either offset or arch in order to refine a stack argument")
|
|
376
|
+
if arch.register_endness == "Iend_LE":
|
|
377
|
+
offset = 0
|
|
378
|
+
else:
|
|
379
|
+
offset = self.size - size
|
|
380
|
+
if is_fp is None:
|
|
381
|
+
is_fp = self.is_fp
|
|
382
|
+
return SimStackArg(self.stack_offset + offset, size, is_fp)
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
class SimComboArg(SimFunctionArgument):
|
|
386
|
+
"""
|
|
387
|
+
An argument which spans multiple storage locations. Locations should be given least-significant first.
|
|
388
|
+
"""
|
|
389
|
+
|
|
390
|
+
def __init__(self, locations, is_fp=False):
|
|
391
|
+
super().__init__(sum(x.size for x in locations), is_fp=is_fp)
|
|
392
|
+
self.locations = locations
|
|
393
|
+
|
|
394
|
+
def get_footprint(self):
|
|
395
|
+
for x in self.locations:
|
|
396
|
+
yield from x.get_footprint()
|
|
397
|
+
|
|
398
|
+
def __repr__(self):
|
|
399
|
+
return "SimComboArg(%s)" % repr(self.locations)
|
|
400
|
+
|
|
401
|
+
def __eq__(self, other):
|
|
402
|
+
return type(other) is SimComboArg and all(a == b for a, b in zip(self.locations, other.locations))
|
|
403
|
+
|
|
404
|
+
def set_value(self, state, value, **kwargs): # pylint:disable=arguments-differ
|
|
405
|
+
value = self.check_value_set(value, state.arch)
|
|
406
|
+
cur = 0
|
|
407
|
+
for loc in self.locations:
|
|
408
|
+
size_bits = loc.size * state.arch.byte_width
|
|
409
|
+
loc.set_value(state, value[cur + size_bits - 1 : cur], **kwargs)
|
|
410
|
+
cur += size_bits
|
|
411
|
+
|
|
412
|
+
def get_value(self, state, **kwargs): # pylint:disable=arguments-differ
|
|
413
|
+
vals = []
|
|
414
|
+
for loc in reversed(self.locations):
|
|
415
|
+
vals.append(loc.get_value(state, **kwargs))
|
|
416
|
+
return self.check_value_get(state.solver.Concat(*vals))
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
class SimStructArg(SimFunctionArgument):
|
|
420
|
+
"""
|
|
421
|
+
An argument which de/serializes a struct from a list of storage locations
|
|
422
|
+
|
|
423
|
+
:ivar struct: The simtype describing the structure
|
|
424
|
+
:ivar locs: The storage locations to use
|
|
425
|
+
"""
|
|
426
|
+
|
|
427
|
+
def __init__(self, struct: SimStruct, locs: dict[str, SimFunctionArgument]):
|
|
428
|
+
super().__init__(sum(loc.size for loc in locs.values()))
|
|
429
|
+
self.struct = struct
|
|
430
|
+
self.locs = locs
|
|
431
|
+
|
|
432
|
+
def get_footprint(self):
|
|
433
|
+
for x in self.locs.values():
|
|
434
|
+
yield from x.get_footprint()
|
|
435
|
+
|
|
436
|
+
def get_value(self, state, **kwargs):
|
|
437
|
+
return SimStructValue(
|
|
438
|
+
self.struct, {field: getter.get_value(state, **kwargs) for field, getter in self.locs.items()}
|
|
439
|
+
)
|
|
440
|
+
|
|
441
|
+
def set_value(self, state, value, **kwargs):
|
|
442
|
+
for field, setter in self.locs.items():
|
|
443
|
+
setter.set_value(state, value[field], **kwargs)
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
class SimArrayArg(SimFunctionArgument):
|
|
447
|
+
def __init__(self, locs):
|
|
448
|
+
super().__init__(sum(loc.size for loc in locs))
|
|
449
|
+
self.locs = locs
|
|
450
|
+
|
|
451
|
+
def get_footprint(self):
|
|
452
|
+
for x in self.locs:
|
|
453
|
+
yield from x.get_footprint()
|
|
454
|
+
|
|
455
|
+
def get_value(self, state, **kwargs):
|
|
456
|
+
return [getter.get_value(state, **kwargs) for getter in self.locs]
|
|
457
|
+
|
|
458
|
+
def set_value(self, state, value, **kwargs):
|
|
459
|
+
if len(value) != len(self.locs):
|
|
460
|
+
raise TypeError("Expected %d elements, got %d" % (len(self.locs), len(value)))
|
|
461
|
+
for subvalue, setter in zip(value, self.locs):
|
|
462
|
+
setter.set_value(state, subvalue, **kwargs)
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
class SimReferenceArgument(SimFunctionArgument):
|
|
466
|
+
"""
|
|
467
|
+
A function argument which is passed by reference.
|
|
468
|
+
|
|
469
|
+
:ivar ptr_loc: The location the reference's pointer is stored
|
|
470
|
+
:ivar main_loc: A SimStackArgument describing how to load the argument's value as if it were stored at offset
|
|
471
|
+
zero on the stack. It will be passed ``stack_base=ptr_loc.get_value(state)``
|
|
472
|
+
"""
|
|
473
|
+
|
|
474
|
+
def __init__(self, ptr_loc, main_loc):
|
|
475
|
+
super().__init__(ptr_loc.size) # ???
|
|
476
|
+
self.ptr_loc = ptr_loc
|
|
477
|
+
self.main_loc = main_loc
|
|
478
|
+
|
|
479
|
+
def get_footprint(self):
|
|
480
|
+
yield from self.ptr_loc.get_footprint()
|
|
481
|
+
|
|
482
|
+
def get_value(self, state, **kwargs):
|
|
483
|
+
ptr_val = self.ptr_loc.get_value(state, **kwargs)
|
|
484
|
+
return self.main_loc.get_value(state, stack_base=ptr_val, **kwargs)
|
|
485
|
+
|
|
486
|
+
def set_value(self, state, value, **kwargs):
|
|
487
|
+
ptr_val = self.ptr_loc.get_value(state, **kwargs)
|
|
488
|
+
self.main_loc.set_value(state, value, stack_base=ptr_val, **kwargs)
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
class ArgSession:
|
|
492
|
+
"""
|
|
493
|
+
A class to keep track of the state accumulated in laying parameters out into memory
|
|
494
|
+
"""
|
|
495
|
+
|
|
496
|
+
__slots__ = (
|
|
497
|
+
"cc",
|
|
498
|
+
"fp_iter",
|
|
499
|
+
"int_iter",
|
|
500
|
+
"both_iter",
|
|
501
|
+
)
|
|
502
|
+
|
|
503
|
+
def __init__(self, cc):
|
|
504
|
+
self.cc = cc
|
|
505
|
+
self.fp_iter = cc.fp_args
|
|
506
|
+
self.int_iter = cc.int_args
|
|
507
|
+
self.both_iter = cc.memory_args
|
|
508
|
+
|
|
509
|
+
def getstate(self):
|
|
510
|
+
return (self.fp_iter.getstate(), self.int_iter.getstate(), self.both_iter.getstate())
|
|
511
|
+
|
|
512
|
+
def setstate(self, state):
|
|
513
|
+
fp, int_, both = state
|
|
514
|
+
self.fp_iter.setstate(fp)
|
|
515
|
+
self.int_iter.setstate(int_)
|
|
516
|
+
self.both_iter.setstate(both)
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
class UsercallArgSession:
|
|
520
|
+
"""
|
|
521
|
+
An argsession for use with SimCCUsercall
|
|
522
|
+
"""
|
|
523
|
+
|
|
524
|
+
__slots__ = (
|
|
525
|
+
"cc",
|
|
526
|
+
"real_args",
|
|
527
|
+
)
|
|
528
|
+
|
|
529
|
+
def __init__(self, cc):
|
|
530
|
+
self.cc = cc
|
|
531
|
+
self.real_args = SerializableListIterator(self.cc.arg_locs)
|
|
532
|
+
|
|
533
|
+
def getstate(self):
|
|
534
|
+
return self.real_args.getstate()
|
|
535
|
+
|
|
536
|
+
def setstate(self, state):
|
|
537
|
+
self.real_args.setstate(state)
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
class SimCC:
|
|
541
|
+
"""
|
|
542
|
+
A calling convention allows you to extract from a state the data passed from function to
|
|
543
|
+
function by calls and returns. Most of the methods provided by SimCC that operate on a state
|
|
544
|
+
assume that the program is just after a call but just before stack frame allocation, though
|
|
545
|
+
this may be overridden with the `stack_base` parameter to each individual method.
|
|
546
|
+
|
|
547
|
+
This is the base class for all calling conventions.
|
|
548
|
+
"""
|
|
549
|
+
|
|
550
|
+
def __init__(self, arch: archinfo.Arch):
|
|
551
|
+
"""
|
|
552
|
+
:param arch: The Archinfo arch for this CC
|
|
553
|
+
"""
|
|
554
|
+
self.arch = arch
|
|
555
|
+
|
|
556
|
+
#
|
|
557
|
+
# Here are all the things a subclass needs to specify!
|
|
558
|
+
#
|
|
559
|
+
|
|
560
|
+
ARG_REGS: list[str] = [] # A list of all the registers used for integral args, in order (names or offsets)
|
|
561
|
+
FP_ARG_REGS: list[str] = [] # A list of all the registers used for floating point args, in order
|
|
562
|
+
STACKARG_SP_BUFF = 0 # The amount of stack space reserved between the saved return address
|
|
563
|
+
# (if applicable) and the arguments. Probably zero.
|
|
564
|
+
STACKARG_SP_DIFF = 0 # The amount of stack space reserved for the return address
|
|
565
|
+
CALLER_SAVED_REGS: list[str] = [] # Caller-saved registers
|
|
566
|
+
RETURN_ADDR: SimFunctionArgument = None # The location where the return address is stored, as a SimFunctionArgument
|
|
567
|
+
RETURN_VAL: SimFunctionArgument = None # The location where the return value is stored, as a SimFunctionArgument
|
|
568
|
+
OVERFLOW_RETURN_VAL: SimFunctionArgument | None = (
|
|
569
|
+
None # The second half of the location where a double-length return value is stored
|
|
570
|
+
)
|
|
571
|
+
FP_RETURN_VAL: SimFunctionArgument | None = (
|
|
572
|
+
None # The location where floating-point argument return values are stored
|
|
573
|
+
)
|
|
574
|
+
ARCH = None # The archinfo.Arch class that this CC must be used for, if relevant
|
|
575
|
+
CALLEE_CLEANUP = False # Whether the callee has to deallocate the stack space for the arguments
|
|
576
|
+
|
|
577
|
+
STACK_ALIGNMENT = 1 # the alignment requirement of the stack pointer at function start BEFORE call
|
|
578
|
+
|
|
579
|
+
#
|
|
580
|
+
# Here are several things you MAY want to override to change your cc's convention
|
|
581
|
+
#
|
|
582
|
+
|
|
583
|
+
@property
|
|
584
|
+
def int_args(self):
|
|
585
|
+
"""
|
|
586
|
+
Iterate through all the possible arg positions that can only be used to store integer or pointer values.
|
|
587
|
+
|
|
588
|
+
Returns an iterator of SimFunctionArguments
|
|
589
|
+
"""
|
|
590
|
+
if self.ARG_REGS is None:
|
|
591
|
+
raise NotImplementedError()
|
|
592
|
+
return SerializableListIterator([SimRegArg(reg, self.arch.bytes) for reg in self.ARG_REGS])
|
|
593
|
+
|
|
594
|
+
@property
|
|
595
|
+
def memory_args(self):
|
|
596
|
+
"""
|
|
597
|
+
Iterate through all the possible arg positions that can be used to store any kind of argument.
|
|
598
|
+
|
|
599
|
+
Returns an iterator of SimFunctionArguments
|
|
600
|
+
"""
|
|
601
|
+
start = self.STACKARG_SP_BUFF + self.STACKARG_SP_DIFF
|
|
602
|
+
return SerializableCounter(start, self.arch.bytes, lambda offset: SimStackArg(offset, self.arch.bytes))
|
|
603
|
+
|
|
604
|
+
@property
|
|
605
|
+
def fp_args(self):
|
|
606
|
+
"""
|
|
607
|
+
Iterate through all the possible arg positions that can only be used to store floating point values.
|
|
608
|
+
|
|
609
|
+
Returns an iterator of SimFunctionArguments
|
|
610
|
+
"""
|
|
611
|
+
if self.FP_ARG_REGS is None:
|
|
612
|
+
raise NotImplementedError()
|
|
613
|
+
return SerializableListIterator([SimRegArg(reg, self.arch.bytes) for reg in self.FP_ARG_REGS])
|
|
614
|
+
|
|
615
|
+
def is_fp_arg(self, arg):
|
|
616
|
+
"""
|
|
617
|
+
This should take a SimFunctionArgument instance and return whether or not that argument is a floating-point
|
|
618
|
+
argument.
|
|
619
|
+
|
|
620
|
+
Returns True for MUST be a floating point arg,
|
|
621
|
+
False for MUST NOT be a floating point arg,
|
|
622
|
+
None for when it can be either.
|
|
623
|
+
"""
|
|
624
|
+
if arg in self.int_args:
|
|
625
|
+
return False
|
|
626
|
+
if arg in self.fp_args or arg == self.FP_RETURN_VAL:
|
|
627
|
+
return True
|
|
628
|
+
return None
|
|
629
|
+
|
|
630
|
+
ArgSession = ArgSession # import this from global scope so SimCC subclasses can subclass it if they like
|
|
631
|
+
|
|
632
|
+
def arg_session(self, ret_ty: SimType | None):
|
|
633
|
+
"""
|
|
634
|
+
Return an arg session.
|
|
635
|
+
|
|
636
|
+
A session provides the control interface necessary to describe how integral and floating-point arguments are
|
|
637
|
+
laid out into memory. The default behavior is that there are a finite list of int-only and fp-only argument
|
|
638
|
+
slots, and an infinite number of generic slots, and when an argument of a given type is requested, the most
|
|
639
|
+
slot available is used. If you need different behavior, subclass ArgSession.
|
|
640
|
+
|
|
641
|
+
You need to provide the return type of the function in order to kick off an arg layout session.
|
|
642
|
+
"""
|
|
643
|
+
session = self.ArgSession(self)
|
|
644
|
+
if self.return_in_implicit_outparam(ret_ty):
|
|
645
|
+
self.next_arg(session, SimTypePointer(SimTypeBottom()))
|
|
646
|
+
return session
|
|
647
|
+
|
|
648
|
+
def return_in_implicit_outparam(self, ty):
|
|
649
|
+
return False
|
|
650
|
+
|
|
651
|
+
def stack_space(self, args):
|
|
652
|
+
"""
|
|
653
|
+
:param args: A list of SimFunctionArguments
|
|
654
|
+
|
|
655
|
+
:returns: The number of bytes that should be allocated on the stack to store all these args,
|
|
656
|
+
NOT INCLUDING the return address.
|
|
657
|
+
"""
|
|
658
|
+
out = self.STACKARG_SP_DIFF
|
|
659
|
+
for arg in args:
|
|
660
|
+
if isinstance(arg, SimStackArg):
|
|
661
|
+
out = max(out, arg.stack_offset + self.arch.bytes)
|
|
662
|
+
|
|
663
|
+
out += self.STACKARG_SP_BUFF
|
|
664
|
+
return out
|
|
665
|
+
|
|
666
|
+
def return_val(self, ty, perspective_returned=False):
|
|
667
|
+
"""
|
|
668
|
+
The location the return value is stored, based on its type.
|
|
669
|
+
"""
|
|
670
|
+
if ty._arch is None:
|
|
671
|
+
ty = ty.with_arch(self.arch)
|
|
672
|
+
if isinstance(ty, (SimStruct, SimUnion, SimTypeFixedSizeArray)):
|
|
673
|
+
raise AngrTypeError(
|
|
674
|
+
f"{self} doesn't know how to return aggregate types. Consider overriding return_val to "
|
|
675
|
+
"implement its ABI logic"
|
|
676
|
+
)
|
|
677
|
+
if self.return_in_implicit_outparam(ty):
|
|
678
|
+
if perspective_returned:
|
|
679
|
+
ptr_loc = self.RETURN_VAL
|
|
680
|
+
else:
|
|
681
|
+
ptr_loc = self.next_arg(self.ArgSession(self), SimTypePointer(SimTypeBottom()))
|
|
682
|
+
return SimReferenceArgument(
|
|
683
|
+
ptr_loc, SimStackArg(0, ty.size // self.arch.byte_width, is_fp=isinstance(ty, SimTypeFloat))
|
|
684
|
+
)
|
|
685
|
+
|
|
686
|
+
if isinstance(ty, SimTypeFloat) and self.FP_RETURN_VAL is not None:
|
|
687
|
+
return self.FP_RETURN_VAL.refine(size=ty.size // self.arch.byte_width, arch=self.arch, is_fp=True)
|
|
688
|
+
|
|
689
|
+
if self.RETURN_VAL is None or isinstance(ty, SimTypeBottom):
|
|
690
|
+
return None
|
|
691
|
+
if ty.size > self.RETURN_VAL.size * self.arch.byte_width:
|
|
692
|
+
return SimComboArg([self.RETURN_VAL, self.OVERFLOW_RETURN_VAL])
|
|
693
|
+
return self.RETURN_VAL.refine(size=ty.size // self.arch.byte_width, arch=self.arch, is_fp=False)
|
|
694
|
+
|
|
695
|
+
@property
|
|
696
|
+
def return_addr(self):
|
|
697
|
+
"""
|
|
698
|
+
The location the return address is stored.
|
|
699
|
+
"""
|
|
700
|
+
return self.RETURN_ADDR
|
|
701
|
+
|
|
702
|
+
def next_arg(self, session: ArgSession, arg_type: SimType):
|
|
703
|
+
if isinstance(arg_type, (SimTypeArray, SimTypeFixedSizeArray)): # hack
|
|
704
|
+
arg_type = SimTypePointer(arg_type.elem_type).with_arch(self.arch)
|
|
705
|
+
if isinstance(arg_type, (SimStruct, SimUnion, SimTypeFixedSizeArray)):
|
|
706
|
+
raise TypeError(
|
|
707
|
+
f"{self} doesn't know how to store aggregate type {type(arg_type)}. Consider overriding next_arg to "
|
|
708
|
+
"implement its ABI logic"
|
|
709
|
+
)
|
|
710
|
+
if isinstance(arg_type, SimTypeBottom):
|
|
711
|
+
# This is usually caused by failures or mistakes during type inference
|
|
712
|
+
l.warning("Function argument type cannot be BOT. Treating it as a 32-bit int.")
|
|
713
|
+
arg_type = SimTypeInt().with_arch(self.arch)
|
|
714
|
+
is_fp = isinstance(arg_type, SimTypeFloat)
|
|
715
|
+
size = arg_type.size // self.arch.byte_width
|
|
716
|
+
try:
|
|
717
|
+
if is_fp:
|
|
718
|
+
arg = next(session.fp_iter)
|
|
719
|
+
else:
|
|
720
|
+
arg = next(session.int_iter)
|
|
721
|
+
except StopIteration:
|
|
722
|
+
try:
|
|
723
|
+
arg = next(session.both_iter)
|
|
724
|
+
except StopIteration:
|
|
725
|
+
raise TypeError("Accessed too many arguments - exhausted all positions?")
|
|
726
|
+
|
|
727
|
+
if size > arg.size:
|
|
728
|
+
if isinstance(arg, SimStackArg):
|
|
729
|
+
arg_size = arg.size
|
|
730
|
+
locations = [arg]
|
|
731
|
+
while arg_size < size:
|
|
732
|
+
next_arg = next(session.both_iter)
|
|
733
|
+
arg_size += next_arg.size
|
|
734
|
+
locations.append(next_arg)
|
|
735
|
+
return SimComboArg(locations, is_fp=is_fp)
|
|
736
|
+
raise ValueError(
|
|
737
|
+
f"{self} doesn't know how to store large types. Consider overriding"
|
|
738
|
+
" next_arg to implement its ABI logic"
|
|
739
|
+
)
|
|
740
|
+
return arg.refine(size, is_fp=is_fp, arch=self.arch)
|
|
741
|
+
|
|
742
|
+
#
|
|
743
|
+
# Useful functions!
|
|
744
|
+
#
|
|
745
|
+
|
|
746
|
+
@staticmethod
|
|
747
|
+
def is_fp_value(val):
|
|
748
|
+
return (
|
|
749
|
+
isinstance(val, (float, claripy.ast.FP))
|
|
750
|
+
or (isinstance(val, claripy.ast.Base) and val.op.startswith("fp"))
|
|
751
|
+
or (isinstance(val, claripy.ast.Base) and val.op == "Reverse" and val.args[0].op.startswith("fp"))
|
|
752
|
+
)
|
|
753
|
+
|
|
754
|
+
@staticmethod
|
|
755
|
+
def guess_prototype(args, prototype=None):
|
|
756
|
+
"""
|
|
757
|
+
Come up with a plausible SimTypeFunction for the given args (as would be passed to e.g. setup_callsite).
|
|
758
|
+
|
|
759
|
+
You can pass a variadic function prototype in the `base_type` parameter and all its arguments will be used,
|
|
760
|
+
only guessing types for the variadic arguments.
|
|
761
|
+
"""
|
|
762
|
+
if type(prototype) is str:
|
|
763
|
+
prototype = parse_signature(prototype)
|
|
764
|
+
elif prototype is None:
|
|
765
|
+
l.warning("Guessing call prototype. Please specify prototype.")
|
|
766
|
+
|
|
767
|
+
charp = SimTypePointer(SimTypeChar())
|
|
768
|
+
result = prototype if prototype is not None else SimTypeFunction([], charp)
|
|
769
|
+
for arg in args[len(result.args) :]:
|
|
770
|
+
if type(arg) in (int, bytes, PointerWrapper):
|
|
771
|
+
result.args.append(charp)
|
|
772
|
+
elif type(arg) is float:
|
|
773
|
+
result.args.append(SimTypeDouble())
|
|
774
|
+
elif isinstance(arg, claripy.ast.BV):
|
|
775
|
+
result.args.append(SimTypeNum(len(arg), False))
|
|
776
|
+
elif isinstance(arg, claripy.ast.FP):
|
|
777
|
+
if arg.sort == claripy.FSORT_FLOAT:
|
|
778
|
+
result.args.append(SimTypeFloat())
|
|
779
|
+
elif arg.sort == claripy.FSORT_DOUBLE:
|
|
780
|
+
result.args.append(SimTypeDouble())
|
|
781
|
+
else:
|
|
782
|
+
raise TypeError("WHAT kind of floating point is this")
|
|
783
|
+
else:
|
|
784
|
+
raise TypeError("Cannot guess FFI type for %s" % type(arg))
|
|
785
|
+
|
|
786
|
+
return result
|
|
787
|
+
|
|
788
|
+
def arg_locs(self, prototype) -> list[SimFunctionArgument]:
|
|
789
|
+
if prototype._arch is None:
|
|
790
|
+
prototype = prototype.with_arch(self.arch)
|
|
791
|
+
session = self.arg_session(prototype.returnty)
|
|
792
|
+
return [self.next_arg(session, arg_ty) for arg_ty in prototype.args]
|
|
793
|
+
|
|
794
|
+
def get_args(self, state, prototype, stack_base=None):
|
|
795
|
+
arg_locs = self.arg_locs(prototype)
|
|
796
|
+
return [loc.get_value(state, stack_base=stack_base) for loc in arg_locs]
|
|
797
|
+
|
|
798
|
+
def set_return_val(self, state, val, ty, stack_base=None, perspective_returned=False):
|
|
799
|
+
loc = self.return_val(ty, perspective_returned=perspective_returned)
|
|
800
|
+
loc.set_value(state, val, stack_base=stack_base)
|
|
801
|
+
|
|
802
|
+
def setup_callsite(self, state, ret_addr, args, prototype, stack_base=None, alloc_base=None, grow_like_stack=True):
|
|
803
|
+
"""
|
|
804
|
+
This function performs the actions of the caller getting ready to jump into a function.
|
|
805
|
+
|
|
806
|
+
:param state: The SimState to operate on
|
|
807
|
+
:param ret_addr: The address to return to when the called function finishes
|
|
808
|
+
:param args: The list of arguments that that the called function will see
|
|
809
|
+
:param prototype: The signature of the call you're making. Should include variadic args concretely.
|
|
810
|
+
:param stack_base: An optional pointer to use as the top of the stack, circa the function entry point
|
|
811
|
+
:param alloc_base: An optional pointer to use as the place to put excess argument data
|
|
812
|
+
:param grow_like_stack: When allocating data at alloc_base, whether to allocate at decreasing addresses
|
|
813
|
+
|
|
814
|
+
The idea here is that you can provide almost any kind of python type in `args` and it'll be translated to a
|
|
815
|
+
binary format to be placed into simulated memory. Lists (representing arrays) must be entirely elements of the
|
|
816
|
+
same type and size, while tuples (representing structs) can be elements of any type and size.
|
|
817
|
+
If you'd like there to be a pointer to a given value, wrap the value in a `PointerWrapper`.
|
|
818
|
+
|
|
819
|
+
If stack_base is not provided, the current stack pointer will be used, and it will be updated.
|
|
820
|
+
If alloc_base is not provided, the stack base will be used and grow_like_stack will implicitly be True.
|
|
821
|
+
|
|
822
|
+
grow_like_stack controls the behavior of allocating data at alloc_base. When data from args needs to be wrapped
|
|
823
|
+
in a pointer, the pointer needs to point somewhere, so that data is dumped into memory at alloc_base. If you
|
|
824
|
+
set alloc_base to point to somewhere other than the stack, set grow_like_stack to False so that sequential
|
|
825
|
+
allocations happen at increasing addresses.
|
|
826
|
+
"""
|
|
827
|
+
|
|
828
|
+
# STEP 0: clerical work
|
|
829
|
+
|
|
830
|
+
allocator = AllocHelper(self.arch.bits)
|
|
831
|
+
if type(prototype) is str:
|
|
832
|
+
prototype = parse_signature(prototype, arch=self.arch)
|
|
833
|
+
elif prototype._arch is None:
|
|
834
|
+
prototype = prototype.with_arch(self.arch)
|
|
835
|
+
|
|
836
|
+
#
|
|
837
|
+
# STEP 1: convert all values into serialized form
|
|
838
|
+
# this entails creating the vals list of simple values to store and also populating the allocator's
|
|
839
|
+
# understanding of what aux data needs to be stored
|
|
840
|
+
# This is also where we compute arg locations (arg_locs)
|
|
841
|
+
#
|
|
842
|
+
|
|
843
|
+
vals = [self._standardize_value(arg, ty, state, allocator.dump) for arg, ty in zip(args, prototype.args)]
|
|
844
|
+
arg_locs = self.arg_locs(prototype)
|
|
845
|
+
|
|
846
|
+
# step 1.5, gotta handle the SimReferenceArguments correctly
|
|
847
|
+
for i, (loc, val) in enumerate(zip(arg_locs, vals)):
|
|
848
|
+
if not isinstance(loc, SimReferenceArgument):
|
|
849
|
+
continue
|
|
850
|
+
dumped = allocator.dump(val, state, loc=val.main_loc)
|
|
851
|
+
vals[i] = dumped
|
|
852
|
+
arg_locs[i] = val.ptr_loc
|
|
853
|
+
|
|
854
|
+
# step 1.75 allocate implicit outparam stuff
|
|
855
|
+
if self.return_in_implicit_outparam(prototype.returnty):
|
|
856
|
+
loc = self.return_val(prototype.returnty)
|
|
857
|
+
assert isinstance(loc, SimReferenceArgument)
|
|
858
|
+
# hack: because the allocator gives us a pointer that needs to be translated, we need to shove it into
|
|
859
|
+
# the args list so it'll be translated and stored once everything is laid out
|
|
860
|
+
vals.append(allocator.alloc(loc.main_loc.size))
|
|
861
|
+
arg_locs.append(loc.ptr_loc)
|
|
862
|
+
|
|
863
|
+
#
|
|
864
|
+
# STEP 2: decide on memory storage locations
|
|
865
|
+
# implement the contract for stack_base/alloc_base/grow_like_stack
|
|
866
|
+
# after this, stack_base should be the final stack pointer, alloc_base should be the final aux storage location,
|
|
867
|
+
# and the stack pointer should be updated
|
|
868
|
+
#
|
|
869
|
+
|
|
870
|
+
if stack_base is None:
|
|
871
|
+
if alloc_base is None:
|
|
872
|
+
alloc_size = allocator.size()
|
|
873
|
+
state.regs.sp -= alloc_size
|
|
874
|
+
alloc_base = state.regs.sp
|
|
875
|
+
grow_like_stack = False
|
|
876
|
+
|
|
877
|
+
state.regs.sp -= self.stack_space(arg_locs)
|
|
878
|
+
|
|
879
|
+
# handle alignment
|
|
880
|
+
alignment = (state.regs.sp + self.STACKARG_SP_DIFF) % self.STACK_ALIGNMENT
|
|
881
|
+
state.regs.sp -= alignment
|
|
882
|
+
|
|
883
|
+
else:
|
|
884
|
+
state.regs.sp = stack_base
|
|
885
|
+
|
|
886
|
+
if alloc_base is None:
|
|
887
|
+
alloc_base = stack_base + self.stack_space(arg_locs)
|
|
888
|
+
grow_like_stack = False
|
|
889
|
+
|
|
890
|
+
if grow_like_stack:
|
|
891
|
+
alloc_base -= allocator.size()
|
|
892
|
+
if type(alloc_base) is int:
|
|
893
|
+
alloc_base = claripy.BVV(alloc_base, state.arch.bits)
|
|
894
|
+
|
|
895
|
+
for i, val in enumerate(vals):
|
|
896
|
+
vals[i] = allocator.translate(val, alloc_base)
|
|
897
|
+
|
|
898
|
+
#
|
|
899
|
+
# STEP 3: store everything!
|
|
900
|
+
#
|
|
901
|
+
|
|
902
|
+
allocator.apply(state, alloc_base)
|
|
903
|
+
|
|
904
|
+
for loc, val in zip(arg_locs, vals):
|
|
905
|
+
loc.set_value(state, val, stack_base=stack_base)
|
|
906
|
+
self.return_addr.set_value(state, ret_addr, stack_base=stack_base)
|
|
907
|
+
|
|
908
|
+
def teardown_callsite(self, state, return_val=None, prototype=None, force_callee_cleanup=False):
|
|
909
|
+
"""
|
|
910
|
+
This function performs the actions of the callee as it's getting ready to return.
|
|
911
|
+
It returns the address to return to.
|
|
912
|
+
|
|
913
|
+
:param state: The state to mutate
|
|
914
|
+
:param return_val: The value to return
|
|
915
|
+
:param prototype: The prototype of the given function
|
|
916
|
+
:param force_callee_cleanup: If we should clean up the stack allocation for the arguments even if it's not
|
|
917
|
+
the callee's job to do so
|
|
918
|
+
|
|
919
|
+
TODO: support the stack_base parameter from setup_callsite...? Does that make sense in this context?
|
|
920
|
+
Maybe it could make sense by saying that you pass it in as something like the "saved base pointer" value?
|
|
921
|
+
"""
|
|
922
|
+
if return_val is not None and not isinstance(prototype.returnty, SimTypeBottom):
|
|
923
|
+
self.set_return_val(state, return_val, prototype.returnty)
|
|
924
|
+
# ummmmmmmm hack
|
|
925
|
+
loc = self.return_val(prototype.returnty)
|
|
926
|
+
if isinstance(loc, SimReferenceArgument):
|
|
927
|
+
self.RETURN_VAL.set_value(state, loc.ptr_loc.get_value(state))
|
|
928
|
+
|
|
929
|
+
ret_addr = self.return_addr.get_value(state)
|
|
930
|
+
|
|
931
|
+
if state.arch.sp_offset is not None:
|
|
932
|
+
if force_callee_cleanup or self.CALLEE_CLEANUP:
|
|
933
|
+
session = self.arg_session(prototype.returnty)
|
|
934
|
+
if self.return_in_implicit_outparam(prototype.returnty):
|
|
935
|
+
extra = [self.return_val(prototype.returnty).ptr_loc]
|
|
936
|
+
else:
|
|
937
|
+
extra = []
|
|
938
|
+
state.regs.sp += self.stack_space(extra + [self.next_arg(session, x) for x in prototype.args])
|
|
939
|
+
else:
|
|
940
|
+
state.regs.sp += self.STACKARG_SP_DIFF
|
|
941
|
+
|
|
942
|
+
return ret_addr
|
|
943
|
+
|
|
944
|
+
#
|
|
945
|
+
# Helper functions
|
|
946
|
+
#
|
|
947
|
+
|
|
948
|
+
@staticmethod
|
|
949
|
+
def _standardize_value(arg, ty, state, alloc):
|
|
950
|
+
if isinstance(arg, SimActionObject):
|
|
951
|
+
return SimCC._standardize_value(arg.ast, ty, state, alloc)
|
|
952
|
+
elif isinstance(arg, PointerWrapper):
|
|
953
|
+
if not isinstance(ty, (SimTypePointer, SimTypeReference)):
|
|
954
|
+
raise TypeError("Type mismatch: expected %s, got pointer-wrapper" % ty)
|
|
955
|
+
|
|
956
|
+
if arg.buffer:
|
|
957
|
+
if isinstance(arg.value, claripy.Bits):
|
|
958
|
+
real_value = arg.value.chop(state.arch.byte_width)
|
|
959
|
+
elif type(arg.value) in (bytes, str):
|
|
960
|
+
real_value = claripy.BVV(arg.value).chop(8)
|
|
961
|
+
else:
|
|
962
|
+
raise TypeError("PointerWrapper(buffer=True) can only be used with a bitvector or a bytestring")
|
|
963
|
+
else:
|
|
964
|
+
child_type = SimTypeArray(ty.pts_to) if type(arg.value) in (str, bytes, list) else ty.pts_to
|
|
965
|
+
try:
|
|
966
|
+
real_value = SimCC._standardize_value(arg.value, child_type, state, alloc)
|
|
967
|
+
except TypeError as e: # this is a dangerous catch...
|
|
968
|
+
raise TypeError(
|
|
969
|
+
f"Failed to store pointer-wrapped data ({e.args[0]}). "
|
|
970
|
+
"Do you want a PointerWrapper(buffer=True)?"
|
|
971
|
+
) from None
|
|
972
|
+
return alloc(real_value, state)
|
|
973
|
+
|
|
974
|
+
elif isinstance(arg, (str, bytes)):
|
|
975
|
+
# sanitize the argument and request standardization again with SimTypeArray
|
|
976
|
+
if type(arg) is str:
|
|
977
|
+
arg = arg.encode()
|
|
978
|
+
arg += b"\0"
|
|
979
|
+
if isinstance(ty, SimTypePointer) and isinstance(ty.pts_to, SimTypeChar):
|
|
980
|
+
pass
|
|
981
|
+
elif isinstance(ty, SimTypeFixedSizeArray) and isinstance(ty.elem_type, SimTypeChar):
|
|
982
|
+
if len(arg) > ty.length:
|
|
983
|
+
raise TypeError(f"String {repr(arg)} is too long for {ty}")
|
|
984
|
+
arg = arg.ljust(ty.length, b"\0")
|
|
985
|
+
elif isinstance(ty, SimTypeArray) and isinstance(ty.elem_type, SimTypeChar):
|
|
986
|
+
if ty.length is not None:
|
|
987
|
+
if len(arg) > ty.length:
|
|
988
|
+
raise TypeError(f"String {repr(arg)} is too long for {ty}")
|
|
989
|
+
arg = arg.ljust(ty.length, b"\0")
|
|
990
|
+
elif isinstance(ty, SimTypeString):
|
|
991
|
+
if len(arg) > ty.length + 1:
|
|
992
|
+
raise TypeError(f"String {repr(arg)} is too long for {ty}")
|
|
993
|
+
arg = arg.ljust(ty.length + 1, b"\0")
|
|
994
|
+
else:
|
|
995
|
+
raise TypeError("Type mismatch: Expected %s, got char*" % ty)
|
|
996
|
+
val = SimCC._standardize_value(list(arg), SimTypeArray(SimTypeChar(), len(arg)), state, alloc)
|
|
997
|
+
return val
|
|
998
|
+
|
|
999
|
+
elif isinstance(arg, list):
|
|
1000
|
+
if isinstance(ty, (SimTypePointer, SimTypeReference)):
|
|
1001
|
+
ref = True
|
|
1002
|
+
subty = ty.pts_to
|
|
1003
|
+
elif isinstance(ty, SimTypeArray):
|
|
1004
|
+
ref = True
|
|
1005
|
+
subty = ty.elem_type
|
|
1006
|
+
if ty.length is not None:
|
|
1007
|
+
if len(arg) != ty.length:
|
|
1008
|
+
raise TypeError(f"Array {repr(arg)} is the wrong length for {ty}")
|
|
1009
|
+
else:
|
|
1010
|
+
raise TypeError("Type mismatch: Expected %s, got char*" % ty)
|
|
1011
|
+
|
|
1012
|
+
val = [SimCC._standardize_value(sarg, subty, state, alloc) for sarg in arg]
|
|
1013
|
+
if ref:
|
|
1014
|
+
val = alloc(val, state)
|
|
1015
|
+
return val
|
|
1016
|
+
|
|
1017
|
+
elif isinstance(arg, (tuple, dict, SimStructValue)):
|
|
1018
|
+
if not isinstance(ty, SimStruct):
|
|
1019
|
+
raise TypeError(f"Type mismatch: Expected {ty}, got {type(arg)} (i.e. struct)")
|
|
1020
|
+
if type(arg) is not SimStructValue:
|
|
1021
|
+
if len(arg) != len(ty.fields):
|
|
1022
|
+
raise TypeError("Wrong number of fields in struct, expected %d got %d" % (len(ty.fields), len(arg)))
|
|
1023
|
+
arg = SimStructValue(ty, arg)
|
|
1024
|
+
return SimStructValue(
|
|
1025
|
+
ty, [SimCC._standardize_value(arg[field], ty.fields[field], state, alloc) for field in ty.fields]
|
|
1026
|
+
)
|
|
1027
|
+
|
|
1028
|
+
elif isinstance(arg, int):
|
|
1029
|
+
if isinstance(ty, SimTypeFloat):
|
|
1030
|
+
return SimCC._standardize_value(float(arg), ty, state, alloc)
|
|
1031
|
+
|
|
1032
|
+
val = state.solver.BVV(arg, ty.size)
|
|
1033
|
+
return val
|
|
1034
|
+
|
|
1035
|
+
elif isinstance(arg, float):
|
|
1036
|
+
if isinstance(ty, SimTypeDouble):
|
|
1037
|
+
sort = claripy.FSORT_DOUBLE
|
|
1038
|
+
elif isinstance(ty, SimTypeFloat):
|
|
1039
|
+
sort = claripy.FSORT_FLOAT
|
|
1040
|
+
else:
|
|
1041
|
+
raise TypeError("Type mismatch: expected %s, got float" % ty)
|
|
1042
|
+
|
|
1043
|
+
return claripy.FPV(arg, sort)
|
|
1044
|
+
|
|
1045
|
+
elif isinstance(arg, claripy.ast.FP):
|
|
1046
|
+
if isinstance(ty, SimTypeFloat):
|
|
1047
|
+
if len(arg) != ty.size:
|
|
1048
|
+
raise TypeError(f"Type mismatch: expected {ty}, got {arg.sort}")
|
|
1049
|
+
return arg
|
|
1050
|
+
if isinstance(ty, (SimTypeReg, SimTypeNum)):
|
|
1051
|
+
return arg.val_to_bv(ty.size, ty.signed)
|
|
1052
|
+
raise TypeError(f"Type mismatch: expected {ty}, got {arg.sort}")
|
|
1053
|
+
|
|
1054
|
+
elif isinstance(arg, claripy.ast.BV):
|
|
1055
|
+
if isinstance(ty, (SimTypeReg, SimTypeNum)):
|
|
1056
|
+
if len(arg) != ty.size:
|
|
1057
|
+
raise TypeError("Type mismatch: expected %s, got %d bits" % (ty, len(arg)))
|
|
1058
|
+
return arg
|
|
1059
|
+
if isinstance(ty, (SimTypeFloat)):
|
|
1060
|
+
raise TypeError(
|
|
1061
|
+
"It's unclear how to coerce a bitvector to %s. "
|
|
1062
|
+
"Do you want .raw_to_fp or .val_to_fp, and signed or unsigned?"
|
|
1063
|
+
)
|
|
1064
|
+
raise TypeError("Type mismatch: expected %s, got bitvector" % ty)
|
|
1065
|
+
|
|
1066
|
+
else:
|
|
1067
|
+
raise TypeError("I don't know how to serialize %s." % repr(arg))
|
|
1068
|
+
|
|
1069
|
+
def __repr__(self):
|
|
1070
|
+
return f"<{self.__class__.__name__}>"
|
|
1071
|
+
|
|
1072
|
+
def __eq__(self, other):
|
|
1073
|
+
return isinstance(other, self.__class__)
|
|
1074
|
+
|
|
1075
|
+
@classmethod
|
|
1076
|
+
def _match(cls, arch, args: list, sp_delta):
|
|
1077
|
+
if cls.ARCH is not None and not isinstance(
|
|
1078
|
+
arch, cls.ARCH
|
|
1079
|
+
): # pylint:disable=isinstance-second-argument-not-valid-type
|
|
1080
|
+
return False
|
|
1081
|
+
if sp_delta != cls.STACKARG_SP_DIFF:
|
|
1082
|
+
return False
|
|
1083
|
+
|
|
1084
|
+
sample_inst = cls(arch)
|
|
1085
|
+
all_fp_args = list(sample_inst.fp_args)
|
|
1086
|
+
all_int_args = list(sample_inst.int_args)
|
|
1087
|
+
both_iter = sample_inst.memory_args
|
|
1088
|
+
some_both_args = [next(both_iter) for _ in range(len(args))]
|
|
1089
|
+
|
|
1090
|
+
new_args = []
|
|
1091
|
+
for arg in args:
|
|
1092
|
+
if arg not in all_fp_args and arg not in all_int_args and arg not in some_both_args:
|
|
1093
|
+
if isinstance(arg, SimRegArg) and arg.reg_name in sample_inst.CALLER_SAVED_REGS:
|
|
1094
|
+
continue
|
|
1095
|
+
return False
|
|
1096
|
+
new_args.append(arg)
|
|
1097
|
+
|
|
1098
|
+
# update args (e.g., drop caller-saved register arguments)
|
|
1099
|
+
args.clear()
|
|
1100
|
+
args.extend(new_args)
|
|
1101
|
+
|
|
1102
|
+
return True
|
|
1103
|
+
|
|
1104
|
+
@staticmethod
|
|
1105
|
+
def find_cc(
|
|
1106
|
+
arch: "archinfo.Arch", args: list[SimFunctionArgument], sp_delta: int, platform: str = "Linux"
|
|
1107
|
+
) -> Optional["SimCC"]:
|
|
1108
|
+
"""
|
|
1109
|
+
Pinpoint the best-fit calling convention and return the corresponding SimCC instance, or None if no fit is
|
|
1110
|
+
found.
|
|
1111
|
+
|
|
1112
|
+
:param arch: An ArchX instance. Can be obtained from archinfo.
|
|
1113
|
+
:param args: A list of arguments. It may be updated by the first matched calling convention to
|
|
1114
|
+
remove non-argument arguments.
|
|
1115
|
+
:param sp_delta: The change of stack pointer before and after the call is made.
|
|
1116
|
+
:return: A calling convention instance, or None if none of the SimCC subclasses seems to fit the
|
|
1117
|
+
arguments provided.
|
|
1118
|
+
"""
|
|
1119
|
+
if arch.name not in CC:
|
|
1120
|
+
return None
|
|
1121
|
+
if platform not in CC[arch.name]:
|
|
1122
|
+
# fallback to default
|
|
1123
|
+
platform = "default"
|
|
1124
|
+
possible_cc_classes = CC[arch.name][platform]
|
|
1125
|
+
for cc_cls in possible_cc_classes:
|
|
1126
|
+
if cc_cls._match(arch, args, sp_delta):
|
|
1127
|
+
return cc_cls(arch)
|
|
1128
|
+
return None
|
|
1129
|
+
|
|
1130
|
+
def get_arg_info(self, state, prototype):
|
|
1131
|
+
"""
|
|
1132
|
+
This is just a simple wrapper that collects the information from various locations
|
|
1133
|
+
prototype is as passed to self.arg_locs and self.get_args
|
|
1134
|
+
:param angr.SimState state: The state to evaluate and extract the values from
|
|
1135
|
+
:return: A list of tuples, where the nth tuple is (type, name, location, value) of the nth argument
|
|
1136
|
+
"""
|
|
1137
|
+
|
|
1138
|
+
argument_locations = self.arg_locs(prototype)
|
|
1139
|
+
argument_values = self.get_args(state, prototype)
|
|
1140
|
+
|
|
1141
|
+
argument_types = prototype.args
|
|
1142
|
+
argument_names = prototype.arg_names if prototype.arg_names else ["unknown"] * len(prototype.args)
|
|
1143
|
+
return list(zip(argument_types, argument_names, argument_locations, argument_values))
|
|
1144
|
+
|
|
1145
|
+
|
|
1146
|
+
class SimLyingRegArg(SimRegArg):
|
|
1147
|
+
"""
|
|
1148
|
+
A register that LIES about the types it holds
|
|
1149
|
+
"""
|
|
1150
|
+
|
|
1151
|
+
def __init__(self, name, size=8):
|
|
1152
|
+
super().__init__(name, 8)
|
|
1153
|
+
self._real_size = size
|
|
1154
|
+
|
|
1155
|
+
def get_value(self, state, **kwargs): # pylint:disable=arguments-differ
|
|
1156
|
+
# val = super(SimLyingRegArg, self).get_value(state, **kwargs)
|
|
1157
|
+
val = state.registers.load(self.reg_name).raw_to_fp()
|
|
1158
|
+
if self._real_size == 4:
|
|
1159
|
+
val = claripy.fpToFP(claripy.fp.RM.RM_NearestTiesEven, val.raw_to_fp(), claripy.FSORT_FLOAT)
|
|
1160
|
+
return val
|
|
1161
|
+
|
|
1162
|
+
def set_value(self, state, value, **kwargs): # pylint:disable=arguments-differ,unused-argument
|
|
1163
|
+
value = self.check_value_set(value, state.arch)
|
|
1164
|
+
if self._real_size == 4:
|
|
1165
|
+
value = claripy.fpToFP(claripy.fp.RM.RM_NearestTiesEven, value.raw_to_fp(), claripy.FSORT_DOUBLE)
|
|
1166
|
+
state.registers.store(self.reg_name, value)
|
|
1167
|
+
# super(SimLyingRegArg, self).set_value(state, value, endness=endness, **kwargs)
|
|
1168
|
+
|
|
1169
|
+
def refine(self, size, arch=None, offset=None, is_fp=None):
|
|
1170
|
+
return SimLyingRegArg(self.reg_name, size)
|
|
1171
|
+
|
|
1172
|
+
|
|
1173
|
+
class SimCCUsercall(SimCC):
|
|
1174
|
+
def __init__(self, arch, args, ret_loc):
|
|
1175
|
+
super().__init__(arch)
|
|
1176
|
+
self.args = args
|
|
1177
|
+
self.ret_loc = ret_loc
|
|
1178
|
+
|
|
1179
|
+
ArgSession = UsercallArgSession
|
|
1180
|
+
|
|
1181
|
+
def next_arg(self, session, arg_type):
|
|
1182
|
+
return next(session.real_args)
|
|
1183
|
+
|
|
1184
|
+
def return_val(self, ty, **kwargs):
|
|
1185
|
+
return self.ret_loc
|
|
1186
|
+
|
|
1187
|
+
|
|
1188
|
+
class SimCCCdecl(SimCC):
|
|
1189
|
+
ARG_REGS = [] # All arguments are passed in stack
|
|
1190
|
+
FP_ARG_REGS = []
|
|
1191
|
+
STACKARG_SP_DIFF = 4 # Return address is pushed on to stack by call
|
|
1192
|
+
CALLER_SAVED_REGS = ["eax", "ecx", "edx"]
|
|
1193
|
+
RETURN_VAL = SimRegArg("eax", 4)
|
|
1194
|
+
OVERFLOW_RETURN_VAL = SimRegArg("edx", 4)
|
|
1195
|
+
FP_RETURN_VAL = SimLyingRegArg("st0")
|
|
1196
|
+
RETURN_ADDR = SimStackArg(0, 4)
|
|
1197
|
+
ARCH = archinfo.ArchX86
|
|
1198
|
+
|
|
1199
|
+
def next_arg(self, session, arg_type):
|
|
1200
|
+
if isinstance(arg_type, (SimTypeArray, SimTypeFixedSizeArray)): # hack
|
|
1201
|
+
arg_type = SimTypePointer(arg_type.elem_type).with_arch(self.arch)
|
|
1202
|
+
locs_size = 0
|
|
1203
|
+
byte_size = arg_type.size // self.arch.byte_width
|
|
1204
|
+
locs = []
|
|
1205
|
+
while locs_size < byte_size:
|
|
1206
|
+
locs.append(next(session.both_iter))
|
|
1207
|
+
locs_size += locs[-1].size
|
|
1208
|
+
|
|
1209
|
+
return refine_locs_with_struct_type(self.arch, locs, arg_type)
|
|
1210
|
+
|
|
1211
|
+
STRUCT_RETURN_THRESHOLD = 32
|
|
1212
|
+
|
|
1213
|
+
def return_val(self, ty, perspective_returned=False):
|
|
1214
|
+
if ty._arch is None:
|
|
1215
|
+
ty = ty.with_arch(self.arch)
|
|
1216
|
+
if not isinstance(ty, SimStruct):
|
|
1217
|
+
return super().return_val(ty, perspective_returned)
|
|
1218
|
+
|
|
1219
|
+
if ty.size > self.STRUCT_RETURN_THRESHOLD:
|
|
1220
|
+
# TODO this code is duplicated a ton of places. how should it be a function?
|
|
1221
|
+
byte_size = ty.size // self.arch.byte_width
|
|
1222
|
+
referenced_locs = [SimStackArg(offset, self.arch.bytes) for offset in range(0, byte_size, self.arch.bytes)]
|
|
1223
|
+
referenced_loc = refine_locs_with_struct_type(self.arch, referenced_locs, ty)
|
|
1224
|
+
if perspective_returned:
|
|
1225
|
+
ptr_loc = self.RETURN_VAL
|
|
1226
|
+
else:
|
|
1227
|
+
ptr_loc = SimStackArg(0, 4)
|
|
1228
|
+
reference_loc = SimReferenceArgument(ptr_loc, referenced_loc)
|
|
1229
|
+
return reference_loc
|
|
1230
|
+
|
|
1231
|
+
return refine_locs_with_struct_type(self.arch, [self.RETURN_VAL, self.OVERFLOW_RETURN_VAL], ty)
|
|
1232
|
+
|
|
1233
|
+
def return_in_implicit_outparam(self, ty):
|
|
1234
|
+
if isinstance(ty, SimTypeBottom):
|
|
1235
|
+
return False
|
|
1236
|
+
return isinstance(ty, SimStruct) and ty.size > self.STRUCT_RETURN_THRESHOLD
|
|
1237
|
+
|
|
1238
|
+
|
|
1239
|
+
class SimCCMicrosoftCdecl(SimCCCdecl):
|
|
1240
|
+
STRUCT_RETURN_THRESHOLD = 64
|
|
1241
|
+
|
|
1242
|
+
|
|
1243
|
+
class SimCCStdcall(SimCCMicrosoftCdecl):
|
|
1244
|
+
CALLEE_CLEANUP = True
|
|
1245
|
+
|
|
1246
|
+
|
|
1247
|
+
class SimCCMicrosoftFastcall(SimCC):
|
|
1248
|
+
ARG_REGS = ["ecx", "edx"] # Remaining arguments are passed in stack
|
|
1249
|
+
STACKARG_SP_DIFF = 4 # Return address is pushed on to stack by call
|
|
1250
|
+
RETURN_VAL = SimRegArg("eax", 4)
|
|
1251
|
+
RETURN_ADDR = SimStackArg(0, 4)
|
|
1252
|
+
ARCH = archinfo.ArchX86
|
|
1253
|
+
|
|
1254
|
+
|
|
1255
|
+
class MicrosoftAMD64ArgSession:
|
|
1256
|
+
def __init__(self, cc):
|
|
1257
|
+
self.cc = cc
|
|
1258
|
+
self.int_iter = cc.int_args
|
|
1259
|
+
self.fp_iter = cc.fp_args
|
|
1260
|
+
self.both_iter = cc.memory_args
|
|
1261
|
+
|
|
1262
|
+
|
|
1263
|
+
class SimCCMicrosoftAMD64(SimCC):
|
|
1264
|
+
ARG_REGS = ["rcx", "rdx", "r8", "r9"]
|
|
1265
|
+
FP_ARG_REGS = ["xmm0", "xmm1", "xmm2", "xmm3"]
|
|
1266
|
+
STACKARG_SP_DIFF = 8 # Return address is pushed on to stack by call
|
|
1267
|
+
STACKARG_SP_BUFF = 32 # 32 bytes of shadow stack space
|
|
1268
|
+
RETURN_VAL = SimRegArg("rax", 8)
|
|
1269
|
+
OVERFLOW_RETURN_VAL = SimRegArg("rdx", 8)
|
|
1270
|
+
FP_RETURN_VAL = SimRegArg("xmm0", 32)
|
|
1271
|
+
RETURN_ADDR = SimStackArg(0, 8)
|
|
1272
|
+
ARCH = archinfo.ArchAMD64
|
|
1273
|
+
STACK_ALIGNMENT = 16
|
|
1274
|
+
|
|
1275
|
+
ArgSession = MicrosoftAMD64ArgSession
|
|
1276
|
+
|
|
1277
|
+
def next_arg(self, session, arg_type):
|
|
1278
|
+
if isinstance(arg_type, (SimTypeArray, SimTypeFixedSizeArray)): # hack
|
|
1279
|
+
arg_type = SimTypePointer(arg_type.elem_type).with_arch(self.arch)
|
|
1280
|
+
try:
|
|
1281
|
+
int_loc = next(session.int_iter)
|
|
1282
|
+
fp_loc = next(session.fp_iter)
|
|
1283
|
+
except StopIteration:
|
|
1284
|
+
int_loc = fp_loc = next(session.both_iter)
|
|
1285
|
+
|
|
1286
|
+
byte_size = arg_type.size // self.arch.byte_width
|
|
1287
|
+
|
|
1288
|
+
if isinstance(arg_type, SimTypeFloat):
|
|
1289
|
+
return fp_loc.refine(size=byte_size, is_fp=True, arch=self.arch)
|
|
1290
|
+
|
|
1291
|
+
if byte_size <= int_loc.size:
|
|
1292
|
+
return int_loc.refine(size=byte_size, is_fp=False, arch=self.arch)
|
|
1293
|
+
|
|
1294
|
+
referenced_locs = [SimStackArg(offset, self.arch.bytes) for offset in range(0, byte_size, self.arch.bytes)]
|
|
1295
|
+
referenced_loc = refine_locs_with_struct_type(self.arch, referenced_locs, arg_type)
|
|
1296
|
+
reference_loc = SimReferenceArgument(int_loc, referenced_loc)
|
|
1297
|
+
return reference_loc
|
|
1298
|
+
|
|
1299
|
+
def return_in_implicit_outparam(self, ty):
|
|
1300
|
+
if isinstance(ty, SimTypeBottom):
|
|
1301
|
+
return False
|
|
1302
|
+
return not isinstance(ty, SimTypeFloat) and ty.size > 64
|
|
1303
|
+
|
|
1304
|
+
|
|
1305
|
+
class SimCCSyscall(SimCC):
|
|
1306
|
+
"""
|
|
1307
|
+
The base class of all syscall CCs.
|
|
1308
|
+
"""
|
|
1309
|
+
|
|
1310
|
+
ERROR_REG: SimRegArg = None
|
|
1311
|
+
SYSCALL_ERRNO_START = None
|
|
1312
|
+
|
|
1313
|
+
@staticmethod
|
|
1314
|
+
def syscall_num(state) -> int:
|
|
1315
|
+
raise NotImplementedError()
|
|
1316
|
+
|
|
1317
|
+
def linux_syscall_update_error_reg(self, state, expr):
|
|
1318
|
+
# special handling for Linux syscalls: on some architectures (mips/a3, powerpc/cr0_0) a bool indicating success
|
|
1319
|
+
# or failure of a system call is used as an error flag (0 for success, 1 for error). we have to set this
|
|
1320
|
+
if state.project is None or state.project.simos is None or state.project.simos.name != "Linux":
|
|
1321
|
+
return expr
|
|
1322
|
+
if type(expr) is int:
|
|
1323
|
+
expr = claripy.BVV(expr, state.arch.bits)
|
|
1324
|
+
try:
|
|
1325
|
+
expr = expr.ast
|
|
1326
|
+
except AttributeError:
|
|
1327
|
+
pass
|
|
1328
|
+
nbits = self.ERROR_REG.size * state.arch.byte_width
|
|
1329
|
+
error_cond = claripy.UGE(expr, self.SYSCALL_ERRNO_START)
|
|
1330
|
+
if state.solver.is_false(error_cond):
|
|
1331
|
+
# guaranteed no error
|
|
1332
|
+
error_reg_val = claripy.BVV(0, nbits)
|
|
1333
|
+
elif state.solver.is_true(error_cond):
|
|
1334
|
+
# guaranteed error
|
|
1335
|
+
error_reg_val = claripy.BVV(-1, nbits)
|
|
1336
|
+
expr = -expr
|
|
1337
|
+
else:
|
|
1338
|
+
# both are satisfied, handle gracefully
|
|
1339
|
+
error_reg_val = claripy.If(error_cond, claripy.BVV(-1, nbits), 0)
|
|
1340
|
+
expr = claripy.If(error_cond, -expr, expr)
|
|
1341
|
+
|
|
1342
|
+
self.ERROR_REG.set_value(state, error_reg_val)
|
|
1343
|
+
return expr
|
|
1344
|
+
|
|
1345
|
+
def set_return_val(self, state, val, ty, **kwargs): # pylint:disable=arguments-differ
|
|
1346
|
+
if self.ERROR_REG is not None:
|
|
1347
|
+
val = self.linux_syscall_update_error_reg(state, val)
|
|
1348
|
+
super().set_return_val(state, val, ty, **kwargs)
|
|
1349
|
+
|
|
1350
|
+
|
|
1351
|
+
class SimCCX86LinuxSyscall(SimCCSyscall):
|
|
1352
|
+
ARG_REGS = ["ebx", "ecx", "edx", "esi", "edi", "ebp"]
|
|
1353
|
+
FP_ARG_REGS = []
|
|
1354
|
+
RETURN_VAL = SimRegArg("eax", 4)
|
|
1355
|
+
RETURN_ADDR = SimRegArg("ip_at_syscall", 4)
|
|
1356
|
+
ARCH = archinfo.ArchX86
|
|
1357
|
+
|
|
1358
|
+
@classmethod
|
|
1359
|
+
def _match(cls, arch, args, sp_delta): # pylint: disable=unused-argument
|
|
1360
|
+
# never appears anywhere except syscalls
|
|
1361
|
+
return False
|
|
1362
|
+
|
|
1363
|
+
@staticmethod
|
|
1364
|
+
def syscall_num(state):
|
|
1365
|
+
return state.regs.eax
|
|
1366
|
+
|
|
1367
|
+
|
|
1368
|
+
class SimCCX86WindowsSyscall(SimCCSyscall):
|
|
1369
|
+
# TODO: Make sure the information is correct
|
|
1370
|
+
ARG_REGS = []
|
|
1371
|
+
FP_ARG_REGS = []
|
|
1372
|
+
RETURN_VAL = SimRegArg("eax", 4)
|
|
1373
|
+
RETURN_ADDR = SimRegArg("ip_at_syscall", 4)
|
|
1374
|
+
ARCH = archinfo.ArchX86
|
|
1375
|
+
|
|
1376
|
+
@classmethod
|
|
1377
|
+
def _match(cls, arch, args, sp_delta): # pylint: disable=unused-argument
|
|
1378
|
+
# never appears anywhere except syscalls
|
|
1379
|
+
return False
|
|
1380
|
+
|
|
1381
|
+
@staticmethod
|
|
1382
|
+
def syscall_num(state):
|
|
1383
|
+
return state.regs.eax
|
|
1384
|
+
|
|
1385
|
+
|
|
1386
|
+
class SimCCSystemVAMD64(SimCC):
|
|
1387
|
+
ARG_REGS = ["rdi", "rsi", "rdx", "rcx", "r8", "r9"]
|
|
1388
|
+
FP_ARG_REGS = ["xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"]
|
|
1389
|
+
STACKARG_SP_DIFF = 8 # Return address is pushed on to stack by call
|
|
1390
|
+
CALLER_SAVED_REGS = [
|
|
1391
|
+
"rdi",
|
|
1392
|
+
"rsi",
|
|
1393
|
+
"rdx",
|
|
1394
|
+
"rcx",
|
|
1395
|
+
"r8",
|
|
1396
|
+
"r9",
|
|
1397
|
+
"r10",
|
|
1398
|
+
"r11",
|
|
1399
|
+
"rax",
|
|
1400
|
+
]
|
|
1401
|
+
RETURN_ADDR = SimStackArg(0, 8)
|
|
1402
|
+
RETURN_VAL = SimRegArg("rax", 8)
|
|
1403
|
+
OVERFLOW_RETURN_VAL = SimRegArg("rdx", 8)
|
|
1404
|
+
FP_RETURN_VAL = SimRegArg("xmm0", 128)
|
|
1405
|
+
OVERFLOW_FP_RETURN_VAL = SimRegArg("xmm1", 128)
|
|
1406
|
+
ARCH = archinfo.ArchAMD64
|
|
1407
|
+
STACK_ALIGNMENT = 16
|
|
1408
|
+
|
|
1409
|
+
@classmethod
|
|
1410
|
+
def _match(cls, arch, args, sp_delta):
|
|
1411
|
+
if cls.ARCH is not None and not isinstance(arch, cls.ARCH):
|
|
1412
|
+
return False
|
|
1413
|
+
# if sp_delta != cls.STACKARG_SP_DIFF:
|
|
1414
|
+
# return False
|
|
1415
|
+
|
|
1416
|
+
sample_inst = cls(arch)
|
|
1417
|
+
all_fp_args = list(sample_inst.fp_args)
|
|
1418
|
+
all_int_args = list(sample_inst.int_args)
|
|
1419
|
+
both_iter = sample_inst.memory_args
|
|
1420
|
+
some_both_args = [next(both_iter) for _ in range(len(args))]
|
|
1421
|
+
|
|
1422
|
+
for arg in args:
|
|
1423
|
+
ex_arg = arg
|
|
1424
|
+
# attempt to coerce the argument into a form that might show up in these lists
|
|
1425
|
+
if type(ex_arg) is SimRegArg:
|
|
1426
|
+
if ex_arg.reg_name not in arch.registers:
|
|
1427
|
+
# danger!
|
|
1428
|
+
# if the register name is a digit-only string, we use it as an offset
|
|
1429
|
+
try:
|
|
1430
|
+
regfile_offset = int(ex_arg.reg_name)
|
|
1431
|
+
except ValueError:
|
|
1432
|
+
return False
|
|
1433
|
+
else:
|
|
1434
|
+
regfile_offset = arch.registers[ex_arg.reg_name][0]
|
|
1435
|
+
while regfile_offset not in arch.register_names:
|
|
1436
|
+
regfile_offset -= 1
|
|
1437
|
+
ex_arg.reg_name = arch.register_names[regfile_offset]
|
|
1438
|
+
ex_arg.reg_offset = 0
|
|
1439
|
+
|
|
1440
|
+
if ex_arg not in all_fp_args and ex_arg not in all_int_args and ex_arg not in some_both_args:
|
|
1441
|
+
if isinstance(arg, SimStackArg) and arg.stack_offset == 0:
|
|
1442
|
+
continue # ignore return address?
|
|
1443
|
+
return False
|
|
1444
|
+
|
|
1445
|
+
return True
|
|
1446
|
+
|
|
1447
|
+
# https://raw.githubusercontent.com/wiki/hjl-tools/x86-psABI/x86-64-psABI-1.0.pdf
|
|
1448
|
+
# section 3.2.3
|
|
1449
|
+
def next_arg(self, session, arg_type):
|
|
1450
|
+
if isinstance(arg_type, (SimTypeArray, SimTypeFixedSizeArray)): # hack
|
|
1451
|
+
arg_type = SimTypePointer(arg_type.elem_type).with_arch(self.arch)
|
|
1452
|
+
state = session.getstate()
|
|
1453
|
+
classification = self._classify(arg_type)
|
|
1454
|
+
try:
|
|
1455
|
+
mapped_classes = []
|
|
1456
|
+
for cls in classification:
|
|
1457
|
+
if cls == "SSEUP":
|
|
1458
|
+
mapped_classes.append(mapped_classes[-1].sse_extend(self.arch.bytes))
|
|
1459
|
+
elif cls == "NO_CLASS":
|
|
1460
|
+
raise NotImplementedError("Bug. Report to @rhelmot")
|
|
1461
|
+
elif cls == "MEMORY":
|
|
1462
|
+
mapped_classes.append(next(session.both_iter))
|
|
1463
|
+
elif cls == "INTEGER":
|
|
1464
|
+
mapped_classes.append(next(session.int_iter))
|
|
1465
|
+
elif cls == "SSE":
|
|
1466
|
+
mapped_classes.append(next(session.fp_iter))
|
|
1467
|
+
else:
|
|
1468
|
+
raise NotImplementedError("Bug. Report to @rhelmot")
|
|
1469
|
+
except StopIteration:
|
|
1470
|
+
session.setstate(state)
|
|
1471
|
+
mapped_classes = [next(session.both_iter) for _ in classification]
|
|
1472
|
+
|
|
1473
|
+
return refine_locs_with_struct_type(self.arch, mapped_classes, arg_type)
|
|
1474
|
+
|
|
1475
|
+
def return_val(self, ty: SimType | None, perspective_returned=False):
|
|
1476
|
+
if ty is None:
|
|
1477
|
+
return None
|
|
1478
|
+
if ty._arch is None:
|
|
1479
|
+
ty = ty.with_arch(self.arch)
|
|
1480
|
+
classification = self._classify(ty)
|
|
1481
|
+
if any(cls == "MEMORY" for cls in classification):
|
|
1482
|
+
assert all(cls == "MEMORY" for cls in classification)
|
|
1483
|
+
byte_size = ty.size // self.arch.byte_width
|
|
1484
|
+
referenced_locs = [SimStackArg(offset, self.arch.bytes) for offset in range(0, byte_size, self.arch.bytes)]
|
|
1485
|
+
referenced_loc = refine_locs_with_struct_type(self.arch, referenced_locs, ty)
|
|
1486
|
+
if perspective_returned:
|
|
1487
|
+
ptr_loc = self.RETURN_VAL
|
|
1488
|
+
else:
|
|
1489
|
+
ptr_loc = SimRegArg("rdi", 8)
|
|
1490
|
+
reference_loc = SimReferenceArgument(ptr_loc, referenced_loc)
|
|
1491
|
+
return reference_loc
|
|
1492
|
+
else:
|
|
1493
|
+
mapped_classes = []
|
|
1494
|
+
int_iter = iter([self.RETURN_VAL, self.OVERFLOW_RETURN_VAL])
|
|
1495
|
+
fp_iter = iter([self.FP_RETURN_VAL, self.OVERFLOW_FP_RETURN_VAL])
|
|
1496
|
+
for cls in classification:
|
|
1497
|
+
if cls == "SSEUP":
|
|
1498
|
+
mapped_classes.append(mapped_classes[-1].sse_extend(self.arch.bytes))
|
|
1499
|
+
elif cls == "NO_CLASS":
|
|
1500
|
+
raise NotImplementedError("Bug. Report to @rhelmot")
|
|
1501
|
+
elif cls == "INTEGER":
|
|
1502
|
+
mapped_classes.append(next(int_iter))
|
|
1503
|
+
elif cls == "SSE":
|
|
1504
|
+
mapped_classes.append(next(fp_iter))
|
|
1505
|
+
else:
|
|
1506
|
+
raise NotImplementedError("Bug. Report to @rhelmot")
|
|
1507
|
+
|
|
1508
|
+
return refine_locs_with_struct_type(self.arch, mapped_classes, ty)
|
|
1509
|
+
|
|
1510
|
+
def return_in_implicit_outparam(self, ty):
|
|
1511
|
+
if isinstance(ty, SimTypeBottom):
|
|
1512
|
+
return False
|
|
1513
|
+
# :P
|
|
1514
|
+
return isinstance(self.return_val(ty), SimReferenceArgument)
|
|
1515
|
+
|
|
1516
|
+
def _classify(self, ty, chunksize=None):
|
|
1517
|
+
if chunksize is None:
|
|
1518
|
+
chunksize = self.arch.bytes
|
|
1519
|
+
# treat BOT as INTEGER
|
|
1520
|
+
if isinstance(ty, SimTypeBottom):
|
|
1521
|
+
nchunks = 1
|
|
1522
|
+
else:
|
|
1523
|
+
nchunks = (ty.size // self.arch.byte_width + chunksize - 1) // chunksize
|
|
1524
|
+
if isinstance(ty, (SimTypeInt, SimTypeChar, SimTypePointer, SimTypeNum, SimTypeBottom, SimTypeReference)):
|
|
1525
|
+
return ["INTEGER"] * nchunks
|
|
1526
|
+
elif isinstance(ty, (SimTypeFloat,)):
|
|
1527
|
+
return ["SSE"] + ["SSEUP"] * (nchunks - 1)
|
|
1528
|
+
elif isinstance(ty, (SimStruct, SimTypeFixedSizeArray, SimUnion)):
|
|
1529
|
+
if ty.size > 512:
|
|
1530
|
+
return ["MEMORY"] * nchunks
|
|
1531
|
+
flattened = self._flatten(ty)
|
|
1532
|
+
if flattened is None:
|
|
1533
|
+
return ["MEMORY"] * nchunks
|
|
1534
|
+
result = ["NO_CLASS"] * nchunks
|
|
1535
|
+
for offset, subty_list in flattened.items():
|
|
1536
|
+
for subty in subty_list:
|
|
1537
|
+
# is the smaller chunk size necessary? Genuinely unsure
|
|
1538
|
+
subresult = self._classify(subty, chunksize=1)
|
|
1539
|
+
idx_start = offset // chunksize
|
|
1540
|
+
idx_end = (offset + (subty.size // self.arch.byte_width) - 1) // chunksize
|
|
1541
|
+
for i, idx in enumerate(range(idx_start, idx_end + 1)):
|
|
1542
|
+
subclass = subresult[i * chunksize]
|
|
1543
|
+
result[idx] = self._combine_classes(result[idx], subclass)
|
|
1544
|
+
if any(subresult == "MEMORY" for subresult in result):
|
|
1545
|
+
return ["MEMORY"] * nchunks
|
|
1546
|
+
if nchunks > 2 and (result[0] != "SSE" or any(subresult != "SSEUP" for subresult in result[1:])):
|
|
1547
|
+
return ["MEMORY"] * nchunks
|
|
1548
|
+
for i in range(1, nchunks):
|
|
1549
|
+
if result[i] == "SSEUP" and result[i - 1] not in ("SSE", "SSEUP"):
|
|
1550
|
+
result[i] = "SSE"
|
|
1551
|
+
return result
|
|
1552
|
+
else:
|
|
1553
|
+
raise NotImplementedError("Ummmmm... not sure what goes here. report bug to @rhelmot")
|
|
1554
|
+
|
|
1555
|
+
def _flatten(self, ty) -> dict[int, list[SimType]] | None:
|
|
1556
|
+
result: dict[int, list[SimType]] = defaultdict(list)
|
|
1557
|
+
if isinstance(ty, SimStruct):
|
|
1558
|
+
if ty.packed:
|
|
1559
|
+
return None
|
|
1560
|
+
for field, subty in ty.fields.items():
|
|
1561
|
+
offset = ty.offsets[field]
|
|
1562
|
+
subresult = self._flatten(subty)
|
|
1563
|
+
if subresult is None:
|
|
1564
|
+
return None
|
|
1565
|
+
for suboffset, subsubty_list in subresult.items():
|
|
1566
|
+
result[offset + suboffset] += subsubty_list
|
|
1567
|
+
elif isinstance(ty, SimTypeFixedSizeArray):
|
|
1568
|
+
subresult = self._flatten(ty.elem_type)
|
|
1569
|
+
if subresult is None:
|
|
1570
|
+
return None
|
|
1571
|
+
for suboffset, subsubty_list in subresult.items():
|
|
1572
|
+
for idx in range(ty.length):
|
|
1573
|
+
# TODO I think we need an explicit stride field on array types
|
|
1574
|
+
result[idx * ty.elem_type.size // self.arch.byte_width + suboffset] += subsubty_list
|
|
1575
|
+
elif isinstance(ty, SimUnion):
|
|
1576
|
+
for field, subty in ty.members.items():
|
|
1577
|
+
subresult = self._flatten(subty)
|
|
1578
|
+
if subresult is None:
|
|
1579
|
+
return None
|
|
1580
|
+
for suboffset, subsubty_list in subresult.items():
|
|
1581
|
+
result[suboffset] += subsubty_list
|
|
1582
|
+
else:
|
|
1583
|
+
result[0].append(ty)
|
|
1584
|
+
return result
|
|
1585
|
+
|
|
1586
|
+
def _combine_classes(self, cls1, cls2):
|
|
1587
|
+
if cls1 == cls2:
|
|
1588
|
+
return cls1
|
|
1589
|
+
if cls1 == "NO_CLASS":
|
|
1590
|
+
return cls2
|
|
1591
|
+
if cls2 == "NO_CLASS":
|
|
1592
|
+
return cls1
|
|
1593
|
+
if cls1 == "MEMORY" or cls2 == "MEMORY":
|
|
1594
|
+
return "MEMORY"
|
|
1595
|
+
if cls1 == "INTEGER" or cls2 == "INTEGER":
|
|
1596
|
+
return "INTEGER"
|
|
1597
|
+
return "SSE"
|
|
1598
|
+
|
|
1599
|
+
|
|
1600
|
+
class SimCCAMD64LinuxSyscall(SimCCSyscall):
|
|
1601
|
+
ARG_REGS = ["rdi", "rsi", "rdx", "r10", "r8", "r9"]
|
|
1602
|
+
RETURN_VAL = SimRegArg("rax", 8)
|
|
1603
|
+
RETURN_ADDR = SimRegArg("ip_at_syscall", 8)
|
|
1604
|
+
ARCH = archinfo.ArchAMD64
|
|
1605
|
+
CALLER_SAVED_REGS = ["rax", "rcx", "r11"]
|
|
1606
|
+
|
|
1607
|
+
@staticmethod
|
|
1608
|
+
def _match(arch, args, sp_delta): # pylint: disable=unused-argument
|
|
1609
|
+
# doesn't appear anywhere but syscalls
|
|
1610
|
+
return False
|
|
1611
|
+
|
|
1612
|
+
@staticmethod
|
|
1613
|
+
def syscall_num(state):
|
|
1614
|
+
return state.regs.rax
|
|
1615
|
+
|
|
1616
|
+
|
|
1617
|
+
class SimCCAMD64WindowsSyscall(SimCCSyscall):
|
|
1618
|
+
# TODO: Make sure the information is correct
|
|
1619
|
+
ARG_REGS = []
|
|
1620
|
+
FP_ARG_REGS = []
|
|
1621
|
+
RETURN_VAL = SimRegArg("rax", 8)
|
|
1622
|
+
RETURN_ADDR = SimRegArg("ip_at_syscall", 8)
|
|
1623
|
+
ARCH = archinfo.ArchAMD64
|
|
1624
|
+
|
|
1625
|
+
@classmethod
|
|
1626
|
+
def _match(cls, arch, args, sp_delta): # pylint: disable=unused-argument
|
|
1627
|
+
# never appears anywhere except syscalls
|
|
1628
|
+
return False
|
|
1629
|
+
|
|
1630
|
+
@staticmethod
|
|
1631
|
+
def syscall_num(state):
|
|
1632
|
+
return state.regs.rax
|
|
1633
|
+
|
|
1634
|
+
|
|
1635
|
+
class SimCCARM(SimCC):
|
|
1636
|
+
ARG_REGS = ["r0", "r1", "r2", "r3"]
|
|
1637
|
+
FP_ARG_REGS = [] # regular arg regs are used as fp arg regs
|
|
1638
|
+
CALLER_SAVED_REGS = []
|
|
1639
|
+
RETURN_ADDR = SimRegArg("lr", 4)
|
|
1640
|
+
RETURN_VAL = SimRegArg("r0", 4)
|
|
1641
|
+
OVERFLOW_RETURN_VAL = SimRegArg("r1", 4)
|
|
1642
|
+
ARCH = archinfo.ArchARM
|
|
1643
|
+
|
|
1644
|
+
# https://github.com/ARM-software/abi-aa/blob/60a8eb8c55e999d74dac5e368fc9d7e36e38dda4/aapcs32/aapcs32.rst#parameter-passing
|
|
1645
|
+
def next_arg(self, session, arg_type):
|
|
1646
|
+
if isinstance(arg_type, (SimTypeArray, SimTypeFixedSizeArray)): # hack
|
|
1647
|
+
arg_type = SimTypePointer(arg_type.elem_type).with_arch(self.arch)
|
|
1648
|
+
state = session.getstate()
|
|
1649
|
+
classification = self._classify(arg_type)
|
|
1650
|
+
try:
|
|
1651
|
+
mapped_classes = []
|
|
1652
|
+
for cls in classification:
|
|
1653
|
+
if cls == "DOUBLEP":
|
|
1654
|
+
if session.getstate()[1] % 2 == 1: # doubles must start on an even register
|
|
1655
|
+
next(session.int_iter)
|
|
1656
|
+
|
|
1657
|
+
if session.getstate()[1] == len(self.ARG_REGS) - 2:
|
|
1658
|
+
mapped_classes.append(next(session.int_iter))
|
|
1659
|
+
mapped_classes.append(next(session.both_iter))
|
|
1660
|
+
else:
|
|
1661
|
+
try:
|
|
1662
|
+
mapped_classes.append(next(session.int_iter))
|
|
1663
|
+
mapped_classes.append(next(session.int_iter))
|
|
1664
|
+
except StopIteration:
|
|
1665
|
+
mapped_classes.append(next(session.both_iter))
|
|
1666
|
+
mapped_classes.append(next(session.both_iter))
|
|
1667
|
+
elif cls == "NO_CLASS":
|
|
1668
|
+
raise NotImplementedError("Bug. Report to @rhelmot")
|
|
1669
|
+
elif cls == "MEMORY":
|
|
1670
|
+
mapped_classes.append(next(session.both_iter))
|
|
1671
|
+
elif cls == "INTEGER":
|
|
1672
|
+
try:
|
|
1673
|
+
mapped_classes.append(next(session.int_iter))
|
|
1674
|
+
except StopIteration:
|
|
1675
|
+
mapped_classes.append(next(session.both_iter))
|
|
1676
|
+
elif cls == "SINGLEP":
|
|
1677
|
+
try:
|
|
1678
|
+
mapped_classes.append(next(session.int_iter))
|
|
1679
|
+
except StopIteration:
|
|
1680
|
+
mapped_classes.append(next(session.both_iter))
|
|
1681
|
+
else:
|
|
1682
|
+
raise NotImplementedError("Bug. Report to @rhelmot")
|
|
1683
|
+
except StopIteration:
|
|
1684
|
+
session.setstate(state)
|
|
1685
|
+
mapped_classes = [next(session.both_iter) for _ in classification]
|
|
1686
|
+
|
|
1687
|
+
return refine_locs_with_struct_type(self.arch, mapped_classes, arg_type)
|
|
1688
|
+
|
|
1689
|
+
def _classify(self, ty, chunksize=None):
|
|
1690
|
+
if chunksize is None:
|
|
1691
|
+
chunksize = self.arch.bytes
|
|
1692
|
+
# treat BOT as INTEGER
|
|
1693
|
+
if isinstance(ty, SimTypeBottom):
|
|
1694
|
+
nchunks = 1
|
|
1695
|
+
else:
|
|
1696
|
+
nchunks = (ty.size // self.arch.byte_width + chunksize - 1) // chunksize
|
|
1697
|
+
if isinstance(ty, (SimTypeInt, SimTypeChar, SimTypePointer, SimTypeNum, SimTypeBottom, SimTypeReference)):
|
|
1698
|
+
return ["INTEGER"] * nchunks
|
|
1699
|
+
elif isinstance(ty, (SimTypeFloat,)):
|
|
1700
|
+
if ty.size == 64:
|
|
1701
|
+
return ["DOUBLEP"]
|
|
1702
|
+
elif ty.size == 32:
|
|
1703
|
+
return ["SINGLEP"]
|
|
1704
|
+
return ["NO_CLASS"]
|
|
1705
|
+
elif isinstance(ty, (SimStruct, SimTypeFixedSizeArray, SimUnion)):
|
|
1706
|
+
flattened = self._flatten(ty)
|
|
1707
|
+
if flattened is None:
|
|
1708
|
+
return ["MEMORY"] * nchunks
|
|
1709
|
+
result = ["NO_CLASS"] * nchunks
|
|
1710
|
+
for offset, subty_list in flattened.items():
|
|
1711
|
+
for subty in subty_list:
|
|
1712
|
+
# is the smaller chunk size necessary? Genuinely unsure
|
|
1713
|
+
subresult = self._classify(subty, chunksize=1)
|
|
1714
|
+
idx_start = offset // chunksize
|
|
1715
|
+
idx_end = (offset + (subty.size // self.arch.byte_width) - 1) // chunksize
|
|
1716
|
+
for i, idx in enumerate(range(idx_start, idx_end + 1)):
|
|
1717
|
+
subclass = subresult[i * chunksize]
|
|
1718
|
+
result[idx] = self._combine_classes(result[idx], subclass)
|
|
1719
|
+
return result
|
|
1720
|
+
else:
|
|
1721
|
+
raise NotImplementedError("Ummmmm... not sure what goes here. report bug to @rhelmot")
|
|
1722
|
+
|
|
1723
|
+
def _combine_classes(self, cls1, cls2):
|
|
1724
|
+
if cls1 == cls2:
|
|
1725
|
+
return cls1
|
|
1726
|
+
if cls1 == "NO_CLASS":
|
|
1727
|
+
return cls2
|
|
1728
|
+
if cls2 == "NO_CLASS":
|
|
1729
|
+
return cls1
|
|
1730
|
+
if cls1 == "MEMORY" or cls2 == "MEMORY":
|
|
1731
|
+
return "MEMORY"
|
|
1732
|
+
if cls1 == "INTEGER" or cls2 == "INTEGER":
|
|
1733
|
+
return "INTEGER"
|
|
1734
|
+
return "SSE"
|
|
1735
|
+
|
|
1736
|
+
def _flatten(self, ty) -> dict[int, list[SimType]] | None:
|
|
1737
|
+
result: dict[int, list[SimType]] = defaultdict(list)
|
|
1738
|
+
if isinstance(ty, SimStruct):
|
|
1739
|
+
if ty.packed:
|
|
1740
|
+
return None
|
|
1741
|
+
for field, subty in ty.fields.items():
|
|
1742
|
+
offset = ty.offsets[field]
|
|
1743
|
+
subresult = self._flatten(subty)
|
|
1744
|
+
if subresult is None:
|
|
1745
|
+
return None
|
|
1746
|
+
for suboffset, subsubty_list in subresult.items():
|
|
1747
|
+
result[offset + suboffset] += subsubty_list
|
|
1748
|
+
elif isinstance(ty, SimTypeFixedSizeArray):
|
|
1749
|
+
subresult = self._flatten(ty.elem_type)
|
|
1750
|
+
if subresult is None:
|
|
1751
|
+
return None
|
|
1752
|
+
for suboffset, subsubty_list in subresult.items():
|
|
1753
|
+
for idx in range(ty.length):
|
|
1754
|
+
# TODO I think we need an explicit stride field on array types
|
|
1755
|
+
result[idx * ty.elem_type.size // self.arch.byte_width + suboffset] += subsubty_list
|
|
1756
|
+
elif isinstance(ty, SimUnion):
|
|
1757
|
+
for field, subty in ty.members.items():
|
|
1758
|
+
subresult = self._flatten(subty)
|
|
1759
|
+
if subresult is None:
|
|
1760
|
+
return None
|
|
1761
|
+
for suboffset, subsubty_list in subresult.items():
|
|
1762
|
+
result[suboffset] += subsubty_list
|
|
1763
|
+
else:
|
|
1764
|
+
result[0].append(ty)
|
|
1765
|
+
return result
|
|
1766
|
+
|
|
1767
|
+
|
|
1768
|
+
class SimCCARMHF(SimCCARM):
|
|
1769
|
+
ARG_REGS = ["r0", "r1", "r2", "r3"]
|
|
1770
|
+
FP_ARG_REGS = [f"s{i}" for i in range(16)] # regular arg regs are used as fp arg regs
|
|
1771
|
+
FP_RETURN_VAL = SimRegArg("s0", 32)
|
|
1772
|
+
CALLER_SAVED_REGS = []
|
|
1773
|
+
RETURN_ADDR = SimRegArg("lr", 4)
|
|
1774
|
+
RETURN_VAL = SimRegArg("r0", 4) # TODO Return val can also include reg r1
|
|
1775
|
+
ARCH = archinfo.ArchARMHF
|
|
1776
|
+
|
|
1777
|
+
|
|
1778
|
+
class SimCCARMLinuxSyscall(SimCCSyscall):
|
|
1779
|
+
# TODO: Make sure all the information is correct
|
|
1780
|
+
ARG_REGS = ["r0", "r1", "r2", "r3"]
|
|
1781
|
+
FP_ARG_REGS = [] # TODO: ???
|
|
1782
|
+
RETURN_ADDR = SimRegArg("ip_at_syscall", 4)
|
|
1783
|
+
RETURN_VAL = SimRegArg("r0", 4)
|
|
1784
|
+
ARCH = archinfo.ArchARM
|
|
1785
|
+
|
|
1786
|
+
@classmethod
|
|
1787
|
+
def _match(cls, arch, args, sp_delta): # pylint: disable=unused-argument
|
|
1788
|
+
# never appears anywhere except syscalls
|
|
1789
|
+
return False
|
|
1790
|
+
|
|
1791
|
+
@staticmethod
|
|
1792
|
+
def syscall_num(state):
|
|
1793
|
+
if ((state.regs.ip_at_syscall & 1) == 1).is_true():
|
|
1794
|
+
insn = state.mem[state.regs.ip_at_syscall - 3].short.resolved
|
|
1795
|
+
is_svc = ((insn & 0xFF00) == 0xDF00).is_true()
|
|
1796
|
+
svc_num = insn & 0xFF
|
|
1797
|
+
else:
|
|
1798
|
+
insn = state.mem[state.regs.ip_at_syscall - 4].dword.resolved
|
|
1799
|
+
is_svc = ((insn & 0x0F000000) == 0x0F000000).is_true()
|
|
1800
|
+
svc_num = insn & 0xFFFFFF
|
|
1801
|
+
if not is_svc:
|
|
1802
|
+
l.error("ARM syscall number being queried at an address which is not an SVC")
|
|
1803
|
+
return claripy.BVV(0, 32)
|
|
1804
|
+
|
|
1805
|
+
if len(svc_num) == 32 and (svc_num > 0x900000).is_true() and (svc_num < 0x90FFFF).is_true():
|
|
1806
|
+
return svc_num - 0x900000
|
|
1807
|
+
else:
|
|
1808
|
+
return state.regs.r7
|
|
1809
|
+
|
|
1810
|
+
|
|
1811
|
+
class SimCCAArch64(SimCC):
|
|
1812
|
+
ARG_REGS = ["x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7"]
|
|
1813
|
+
FP_ARG_REGS = [] # TODO: ???
|
|
1814
|
+
RETURN_ADDR = SimRegArg("lr", 8)
|
|
1815
|
+
RETURN_VAL = SimRegArg("x0", 8)
|
|
1816
|
+
ARCH = archinfo.ArchAArch64
|
|
1817
|
+
|
|
1818
|
+
|
|
1819
|
+
class SimCCAArch64LinuxSyscall(SimCCSyscall):
|
|
1820
|
+
# TODO: Make sure all the information is correct
|
|
1821
|
+
ARG_REGS = ["x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7"]
|
|
1822
|
+
FP_ARG_REGS = [] # TODO: ???
|
|
1823
|
+
RETURN_VAL = SimRegArg("x0", 8)
|
|
1824
|
+
RETURN_ADDR = SimRegArg("ip_at_syscall", 8)
|
|
1825
|
+
ARCH = archinfo.ArchAArch64
|
|
1826
|
+
|
|
1827
|
+
@classmethod
|
|
1828
|
+
def _match(cls, arch, args, sp_delta): # pylint: disable=unused-argument
|
|
1829
|
+
# never appears anywhere except syscalls
|
|
1830
|
+
return False
|
|
1831
|
+
|
|
1832
|
+
@staticmethod
|
|
1833
|
+
def syscall_num(state):
|
|
1834
|
+
return state.regs.x8
|
|
1835
|
+
|
|
1836
|
+
|
|
1837
|
+
class SimCCRISCV64LinuxSyscall(SimCCSyscall):
|
|
1838
|
+
# TODO: Make sure all the information is correct
|
|
1839
|
+
ARG_REGS = ["a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7"]
|
|
1840
|
+
FP_ARG_REGS = [] # TODO: ???
|
|
1841
|
+
RETURN_VAL = SimRegArg("a0", 8)
|
|
1842
|
+
RETURN_ADDR = SimRegArg("ip_at_syscall", 4)
|
|
1843
|
+
ARCH = archinfo.ArchRISCV64
|
|
1844
|
+
|
|
1845
|
+
@classmethod
|
|
1846
|
+
def _match(cls, arch, args, sp_delta): # pylint: disable=unused-argument
|
|
1847
|
+
# never appears anywhere except syscalls
|
|
1848
|
+
return False
|
|
1849
|
+
|
|
1850
|
+
@staticmethod
|
|
1851
|
+
def syscall_num(state):
|
|
1852
|
+
return state.regs.a0
|
|
1853
|
+
|
|
1854
|
+
|
|
1855
|
+
class SimCCO32(SimCC):
|
|
1856
|
+
ARG_REGS = ["a0", "a1", "a2", "a3"]
|
|
1857
|
+
FP_ARG_REGS = [
|
|
1858
|
+
"f12",
|
|
1859
|
+
"f13",
|
|
1860
|
+
"f14",
|
|
1861
|
+
"f15",
|
|
1862
|
+
] # Note double precision args are split between f12-f13, f14-f15 and single precision only use f12 and f14
|
|
1863
|
+
STACKARG_SP_BUFF = 16
|
|
1864
|
+
CALLER_SAVED_REGS = ["t9", "gp"]
|
|
1865
|
+
RETURN_ADDR = SimRegArg("ra", 4)
|
|
1866
|
+
RETURN_VAL = SimRegArg("v0", 4)
|
|
1867
|
+
OVERFLOW_RETURN_VAL = SimRegArg("v1", 4)
|
|
1868
|
+
ARCH = archinfo.ArchMIPS32
|
|
1869
|
+
|
|
1870
|
+
# http://math-atlas.sourceforge.net/devel/assembly/mipsabi32.pdf Section 3-17
|
|
1871
|
+
def next_arg(self, session, arg_type):
|
|
1872
|
+
if isinstance(arg_type, (SimTypeArray, SimTypeFixedSizeArray)): # hack
|
|
1873
|
+
arg_type = SimTypePointer(arg_type.elem_type).with_arch(self.arch)
|
|
1874
|
+
state = session.getstate()
|
|
1875
|
+
classification = self._classify(arg_type)
|
|
1876
|
+
try:
|
|
1877
|
+
mapped_classes = []
|
|
1878
|
+
can_use_fp = True
|
|
1879
|
+
for idx, cls in enumerate(classification):
|
|
1880
|
+
if cls == "DOUBLEP":
|
|
1881
|
+
mapped_classes.append(next(session.fp_iter))
|
|
1882
|
+
mapped_classes.append(next(session.fp_iter))
|
|
1883
|
+
if isinstance(arg_type, SimStruct) and idx < 2 and can_use_fp:
|
|
1884
|
+
next(session.fp_iter) # consume next two fp regs since it's double precision
|
|
1885
|
+
next(session.fp_iter)
|
|
1886
|
+
elif cls == "NO_CLASS":
|
|
1887
|
+
raise NotImplementedError("Bug. Report to @rhelmot")
|
|
1888
|
+
elif cls == "MEMORY":
|
|
1889
|
+
mapped_classes.append(next(session.both_iter))
|
|
1890
|
+
can_use_fp = False
|
|
1891
|
+
elif cls == "INTEGER":
|
|
1892
|
+
mapped_classes.append(next(session.int_iter))
|
|
1893
|
+
can_use_fp = False
|
|
1894
|
+
elif cls == "SINGLEP":
|
|
1895
|
+
if isinstance(arg_type, SimStruct):
|
|
1896
|
+
if idx < 2 and can_use_fp:
|
|
1897
|
+
mapped_classes.append(next(session.fp_iter))
|
|
1898
|
+
next(session.int_iter) # Need to take up the arg slot
|
|
1899
|
+
else:
|
|
1900
|
+
mapped_classes.append(next(session.both_iter))
|
|
1901
|
+
else:
|
|
1902
|
+
mapped_classes.append(next(session.fp_iter))
|
|
1903
|
+
next(session.fp_iter) # consume f13 or f15 since it's single precision
|
|
1904
|
+
|
|
1905
|
+
else:
|
|
1906
|
+
raise NotImplementedError("Bug. Report to @rhelmot")
|
|
1907
|
+
except StopIteration:
|
|
1908
|
+
session.setstate(state)
|
|
1909
|
+
mapped_classes = [next(session.both_iter) for _ in classification]
|
|
1910
|
+
|
|
1911
|
+
return refine_locs_with_struct_type(self.arch, mapped_classes, arg_type)
|
|
1912
|
+
|
|
1913
|
+
def _classify(self, ty, chunksize=None):
|
|
1914
|
+
if chunksize is None:
|
|
1915
|
+
chunksize = self.arch.bytes
|
|
1916
|
+
# treat BOT as INTEGER
|
|
1917
|
+
if isinstance(ty, SimTypeBottom):
|
|
1918
|
+
nchunks = 1
|
|
1919
|
+
else:
|
|
1920
|
+
nchunks = (ty.size // self.arch.byte_width + chunksize - 1) // chunksize
|
|
1921
|
+
if isinstance(ty, (SimTypeInt, SimTypeChar, SimTypePointer, SimTypeNum, SimTypeBottom, SimTypeReference)):
|
|
1922
|
+
return ["INTEGER"] * nchunks
|
|
1923
|
+
elif isinstance(ty, (SimTypeFloat,)):
|
|
1924
|
+
if ty.size == 64:
|
|
1925
|
+
return ["DOUBLEP"]
|
|
1926
|
+
elif ty.size == 32:
|
|
1927
|
+
return ["SINGLEP"]
|
|
1928
|
+
return ["NO_CLASS"]
|
|
1929
|
+
elif isinstance(ty, (SimStruct, SimTypeFixedSizeArray, SimUnion)):
|
|
1930
|
+
flattened = self._flatten(ty)
|
|
1931
|
+
if flattened is None:
|
|
1932
|
+
return ["MEMORY"] * nchunks
|
|
1933
|
+
result = ["NO_CLASS"] * nchunks
|
|
1934
|
+
for offset, subty_list in flattened.items():
|
|
1935
|
+
for subty in subty_list:
|
|
1936
|
+
# is the smaller chunk size necessary? Genuinely unsure
|
|
1937
|
+
subresult = self._classify(subty, chunksize=1)
|
|
1938
|
+
idx_start = offset // chunksize
|
|
1939
|
+
idx_end = (offset + (subty.size // self.arch.byte_width) - 1) // chunksize
|
|
1940
|
+
for i, idx in enumerate(range(idx_start, idx_end + 1)):
|
|
1941
|
+
subclass = subresult[i * chunksize]
|
|
1942
|
+
result[idx] = self._combine_classes(result[idx], subclass)
|
|
1943
|
+
return result
|
|
1944
|
+
else:
|
|
1945
|
+
raise NotImplementedError("Ummmmm... not sure what goes here. report bug to @rhelmot")
|
|
1946
|
+
|
|
1947
|
+
def _combine_classes(self, cls1, cls2):
|
|
1948
|
+
if cls1 == cls2:
|
|
1949
|
+
return cls1
|
|
1950
|
+
if cls1 == "NO_CLASS":
|
|
1951
|
+
return cls2
|
|
1952
|
+
if cls2 == "NO_CLASS":
|
|
1953
|
+
return cls1
|
|
1954
|
+
if cls1 == "MEMORY" or cls2 == "MEMORY":
|
|
1955
|
+
return "MEMORY"
|
|
1956
|
+
if cls1 == "INTEGER" or cls2 == "INTEGER":
|
|
1957
|
+
return "INTEGER"
|
|
1958
|
+
return "SSE"
|
|
1959
|
+
|
|
1960
|
+
def _flatten(self, ty) -> dict[int, list[SimType]] | None:
|
|
1961
|
+
result: dict[int, list[SimType]] = defaultdict(list)
|
|
1962
|
+
if isinstance(ty, SimStruct):
|
|
1963
|
+
if ty.packed:
|
|
1964
|
+
return None
|
|
1965
|
+
for field, subty in ty.fields.items():
|
|
1966
|
+
offset = ty.offsets[field]
|
|
1967
|
+
subresult = self._flatten(subty)
|
|
1968
|
+
if subresult is None:
|
|
1969
|
+
return None
|
|
1970
|
+
for suboffset, subsubty_list in subresult.items():
|
|
1971
|
+
result[offset + suboffset] += subsubty_list
|
|
1972
|
+
elif isinstance(ty, SimTypeFixedSizeArray):
|
|
1973
|
+
subresult = self._flatten(ty.elem_type)
|
|
1974
|
+
if subresult is None:
|
|
1975
|
+
return None
|
|
1976
|
+
for suboffset, subsubty_list in subresult.items():
|
|
1977
|
+
for idx in range(ty.length):
|
|
1978
|
+
# TODO I think we need an explicit stride field on array types
|
|
1979
|
+
result[idx * ty.elem_type.size // self.arch.byte_width + suboffset] += subsubty_list
|
|
1980
|
+
elif isinstance(ty, SimUnion):
|
|
1981
|
+
for field, subty in ty.members.items():
|
|
1982
|
+
subresult = self._flatten(subty)
|
|
1983
|
+
if subresult is None:
|
|
1984
|
+
return None
|
|
1985
|
+
for suboffset, subsubty_list in subresult.items():
|
|
1986
|
+
result[suboffset] += subsubty_list
|
|
1987
|
+
else:
|
|
1988
|
+
result[0].append(ty)
|
|
1989
|
+
return result
|
|
1990
|
+
|
|
1991
|
+
|
|
1992
|
+
class SimCCO32LinuxSyscall(SimCCSyscall):
|
|
1993
|
+
# TODO: Make sure all the information is correct
|
|
1994
|
+
ARG_REGS = ["a0", "a1", "a2", "a3"]
|
|
1995
|
+
FP_ARG_REGS = [] # TODO: ???
|
|
1996
|
+
RETURN_VAL = SimRegArg("v0", 4)
|
|
1997
|
+
RETURN_ADDR = SimRegArg("ip_at_syscall", 4)
|
|
1998
|
+
ARCH = archinfo.ArchMIPS32
|
|
1999
|
+
|
|
2000
|
+
ERROR_REG = SimRegArg("a3", 4)
|
|
2001
|
+
SYSCALL_ERRNO_START = -1133
|
|
2002
|
+
|
|
2003
|
+
@classmethod
|
|
2004
|
+
def _match(cls, arch, args, sp_delta): # pylint: disable=unused-argument
|
|
2005
|
+
# never appears anywhere except syscalls
|
|
2006
|
+
return False
|
|
2007
|
+
|
|
2008
|
+
@staticmethod
|
|
2009
|
+
def syscall_num(state):
|
|
2010
|
+
return state.regs.v0
|
|
2011
|
+
|
|
2012
|
+
|
|
2013
|
+
class SimCCN64(SimCC): # TODO: add n32
|
|
2014
|
+
ARG_REGS = ["a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7"]
|
|
2015
|
+
CALLER_SAVED_REGS = ["t9", "gp"]
|
|
2016
|
+
FP_ARG_REGS = [] # TODO: ???
|
|
2017
|
+
STACKARG_SP_BUFF = 32
|
|
2018
|
+
RETURN_ADDR = SimRegArg("ra", 8)
|
|
2019
|
+
RETURN_VAL = SimRegArg("v0", 8)
|
|
2020
|
+
ARCH = archinfo.ArchMIPS64
|
|
2021
|
+
|
|
2022
|
+
|
|
2023
|
+
SimCCO64 = SimCCN64 # compatibility
|
|
2024
|
+
|
|
2025
|
+
|
|
2026
|
+
class SimCCN64LinuxSyscall(SimCCSyscall):
|
|
2027
|
+
ARG_REGS = ["a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7"]
|
|
2028
|
+
FP_ARG_REGS = [] # TODO: ???
|
|
2029
|
+
RETURN_VAL = SimRegArg("v0", 8)
|
|
2030
|
+
RETURN_ADDR = SimRegArg("ip_at_syscall", 8)
|
|
2031
|
+
ARCH = archinfo.ArchMIPS64
|
|
2032
|
+
|
|
2033
|
+
ERROR_REG = SimRegArg("a3", 8)
|
|
2034
|
+
SYSCALL_ERRNO_START = -1133
|
|
2035
|
+
|
|
2036
|
+
@classmethod
|
|
2037
|
+
def _match(cls, arch, args, sp_delta): # pylint: disable=unused-argument
|
|
2038
|
+
# never appears anywhere except syscalls
|
|
2039
|
+
return False
|
|
2040
|
+
|
|
2041
|
+
@staticmethod
|
|
2042
|
+
def syscall_num(state):
|
|
2043
|
+
return state.regs.v0
|
|
2044
|
+
|
|
2045
|
+
|
|
2046
|
+
class SimCCPowerPC(SimCC):
|
|
2047
|
+
ARG_REGS = ["r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10"]
|
|
2048
|
+
FP_ARG_REGS = [] # TODO: ???
|
|
2049
|
+
STACKARG_SP_BUFF = 8
|
|
2050
|
+
RETURN_ADDR = SimRegArg("lr", 4)
|
|
2051
|
+
RETURN_VAL = SimRegArg("r3", 4)
|
|
2052
|
+
ARCH = archinfo.ArchPPC32
|
|
2053
|
+
|
|
2054
|
+
|
|
2055
|
+
class SimCCPowerPCLinuxSyscall(SimCCSyscall):
|
|
2056
|
+
# TODO: Make sure all the information is correct
|
|
2057
|
+
ARG_REGS = ["r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10"]
|
|
2058
|
+
FP_ARG_REGS = []
|
|
2059
|
+
RETURN_VAL = SimRegArg("r3", 4)
|
|
2060
|
+
RETURN_ADDR = SimRegArg("ip_at_syscall", 4)
|
|
2061
|
+
ARCH = archinfo.ArchPPC32
|
|
2062
|
+
|
|
2063
|
+
ERROR_REG = SimRegArg("cr0_0", 1)
|
|
2064
|
+
SYSCALL_ERRNO_START = -515
|
|
2065
|
+
|
|
2066
|
+
@classmethod
|
|
2067
|
+
def _match(cls, arch, args, sp_delta): # pylint: disable=unused-argument
|
|
2068
|
+
# never appears anywhere except syscalls
|
|
2069
|
+
return False
|
|
2070
|
+
|
|
2071
|
+
@staticmethod
|
|
2072
|
+
def syscall_num(state):
|
|
2073
|
+
return state.regs.r0
|
|
2074
|
+
|
|
2075
|
+
|
|
2076
|
+
class SimCCPowerPC64(SimCC):
|
|
2077
|
+
ARG_REGS = ["r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10"]
|
|
2078
|
+
FP_ARG_REGS = [] # TODO: ???
|
|
2079
|
+
STACKARG_SP_BUFF = 0x70
|
|
2080
|
+
RETURN_ADDR = SimRegArg("lr", 8)
|
|
2081
|
+
RETURN_VAL = SimRegArg("r3", 8)
|
|
2082
|
+
ARCH = archinfo.ArchPPC64
|
|
2083
|
+
|
|
2084
|
+
|
|
2085
|
+
class SimCCPowerPC64LinuxSyscall(SimCCSyscall):
|
|
2086
|
+
# TODO: Make sure all the information is correct
|
|
2087
|
+
ARG_REGS = ["r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10"]
|
|
2088
|
+
FP_ARG_REGS = []
|
|
2089
|
+
RETURN_VAL = SimRegArg("r3", 8)
|
|
2090
|
+
RETURN_ADDR = SimRegArg("ip_at_syscall", 8)
|
|
2091
|
+
ARCH = archinfo.ArchPPC64
|
|
2092
|
+
|
|
2093
|
+
ERROR_REG = SimRegArg("cr0_0", 1)
|
|
2094
|
+
SYSCALL_ERRNO_START = -515
|
|
2095
|
+
|
|
2096
|
+
@classmethod
|
|
2097
|
+
def _match(cls, arch, args, sp_delta): # pylint: disable=unused-argument
|
|
2098
|
+
# never appears anywhere except syscalls
|
|
2099
|
+
return False
|
|
2100
|
+
|
|
2101
|
+
@staticmethod
|
|
2102
|
+
def syscall_num(state):
|
|
2103
|
+
return state.regs.r0
|
|
2104
|
+
|
|
2105
|
+
|
|
2106
|
+
class SimCCSoot(SimCC):
|
|
2107
|
+
ARCH = archinfo.ArchSoot
|
|
2108
|
+
ARG_REGS = []
|
|
2109
|
+
|
|
2110
|
+
def setup_callsite(self, state, ret_addr, args, prototype, stack_base=None, alloc_base=None, grow_like_stack=True):
|
|
2111
|
+
SootMixin.setup_callsite(state, args, ret_addr)
|
|
2112
|
+
|
|
2113
|
+
@staticmethod
|
|
2114
|
+
def guess_prototype(args, prototype=None):
|
|
2115
|
+
# uhhhhhhhhhhhhhhhh
|
|
2116
|
+
return None
|
|
2117
|
+
|
|
2118
|
+
|
|
2119
|
+
class SimCCUnknown(SimCC):
|
|
2120
|
+
"""
|
|
2121
|
+
Represent an unknown calling convention.
|
|
2122
|
+
"""
|
|
2123
|
+
|
|
2124
|
+
@staticmethod
|
|
2125
|
+
def _match(arch, args, sp_delta): # pylint: disable=unused-argument
|
|
2126
|
+
# It always returns True
|
|
2127
|
+
return True
|
|
2128
|
+
|
|
2129
|
+
def __repr__(self):
|
|
2130
|
+
return f"<SimCCUnknown - {self.arch.name}>"
|
|
2131
|
+
|
|
2132
|
+
|
|
2133
|
+
class SimCCS390X(SimCC):
|
|
2134
|
+
ARG_REGS = ["r2", "r3", "r4", "r5", "r6"]
|
|
2135
|
+
FP_ARG_REGS = ["f0", "f2", "f4", "f6"]
|
|
2136
|
+
STACKARG_SP_BUFF = 0xA0
|
|
2137
|
+
RETURN_ADDR = SimRegArg("r14", 8)
|
|
2138
|
+
RETURN_VAL = SimRegArg("r2", 8)
|
|
2139
|
+
ARCH = archinfo.ArchS390X
|
|
2140
|
+
|
|
2141
|
+
|
|
2142
|
+
class SimCCS390XLinuxSyscall(SimCCSyscall):
|
|
2143
|
+
ARG_REGS = ["r2", "r3", "r4", "r5", "r6", "r7"]
|
|
2144
|
+
FP_ARG_REGS = []
|
|
2145
|
+
RETURN_VAL = SimRegArg("r2", 8)
|
|
2146
|
+
RETURN_ADDR = SimRegArg("ip_at_syscall", 8)
|
|
2147
|
+
ARCH = archinfo.ArchS390X
|
|
2148
|
+
|
|
2149
|
+
@classmethod
|
|
2150
|
+
def _match(cls, arch, args, sp_delta): # pylint: disable=unused-argument
|
|
2151
|
+
# never appears anywhere except syscalls
|
|
2152
|
+
return False
|
|
2153
|
+
|
|
2154
|
+
@staticmethod
|
|
2155
|
+
def syscall_num(state):
|
|
2156
|
+
return state.regs.r1
|
|
2157
|
+
|
|
2158
|
+
|
|
2159
|
+
CC: dict[str, dict[str, list[type[SimCC]]]] = {
|
|
2160
|
+
"AMD64": {
|
|
2161
|
+
"default": [SimCCSystemVAMD64],
|
|
2162
|
+
"Linux": [SimCCSystemVAMD64],
|
|
2163
|
+
"Win32": [SimCCMicrosoftAMD64],
|
|
2164
|
+
},
|
|
2165
|
+
"X86": {
|
|
2166
|
+
"default": [SimCCCdecl],
|
|
2167
|
+
"Linux": [SimCCCdecl],
|
|
2168
|
+
"CGC": [SimCCCdecl],
|
|
2169
|
+
"Win32": [SimCCMicrosoftCdecl, SimCCMicrosoftFastcall],
|
|
2170
|
+
},
|
|
2171
|
+
"ARMEL": {
|
|
2172
|
+
"default": [SimCCARM],
|
|
2173
|
+
"Linux": [SimCCARM],
|
|
2174
|
+
},
|
|
2175
|
+
"ARMHF": {
|
|
2176
|
+
"default": [SimCCARMHF, SimCCARM],
|
|
2177
|
+
"Linux": [SimCCARMHF, SimCCARM],
|
|
2178
|
+
},
|
|
2179
|
+
"ARMCortexM": {
|
|
2180
|
+
"default": [SimCCARMHF, SimCCARM],
|
|
2181
|
+
"Linux": [SimCCARMHF, SimCCARM],
|
|
2182
|
+
},
|
|
2183
|
+
"MIPS32": {
|
|
2184
|
+
"default": [SimCCO32],
|
|
2185
|
+
"Linux": [SimCCO32],
|
|
2186
|
+
},
|
|
2187
|
+
"MIPS64": {
|
|
2188
|
+
"default": [SimCCN64],
|
|
2189
|
+
"Linux": [SimCCN64],
|
|
2190
|
+
},
|
|
2191
|
+
"PPC32": {
|
|
2192
|
+
"default": [SimCCPowerPC],
|
|
2193
|
+
"Linux": [SimCCPowerPC],
|
|
2194
|
+
},
|
|
2195
|
+
"PPC64": {
|
|
2196
|
+
"default": [SimCCPowerPC64],
|
|
2197
|
+
"Linux": [SimCCPowerPC64],
|
|
2198
|
+
},
|
|
2199
|
+
"AARCH64": {
|
|
2200
|
+
"default": [SimCCAArch64],
|
|
2201
|
+
"Linux": [SimCCAArch64],
|
|
2202
|
+
},
|
|
2203
|
+
"S390X": {
|
|
2204
|
+
"default": [SimCCS390X],
|
|
2205
|
+
"Linux": [SimCCS390X],
|
|
2206
|
+
},
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
|
|
2210
|
+
DEFAULT_CC: dict[str, dict[str, type[SimCC]]] = {
|
|
2211
|
+
"AMD64": {"Linux": SimCCSystemVAMD64, "Win32": SimCCMicrosoftAMD64},
|
|
2212
|
+
"X86": {"Linux": SimCCCdecl, "CGC": SimCCCdecl, "Win32": SimCCMicrosoftCdecl},
|
|
2213
|
+
"ARMEL": {"Linux": SimCCARM},
|
|
2214
|
+
"ARMHF": {"Linux": SimCCARMHF},
|
|
2215
|
+
"ARMCortexM": {"Linux": SimCCARM},
|
|
2216
|
+
"MIPS32": {"Linux": SimCCO32},
|
|
2217
|
+
"MIPS64": {"Linux": SimCCN64},
|
|
2218
|
+
"PPC32": {"Linux": SimCCPowerPC},
|
|
2219
|
+
"PPC64": {"Linux": SimCCPowerPC64},
|
|
2220
|
+
"AARCH64": {"Linux": SimCCAArch64},
|
|
2221
|
+
"Soot": {"Linux": SimCCSoot},
|
|
2222
|
+
"AVR8": {"Linux": SimCCUnknown},
|
|
2223
|
+
"MSP": {"Linux": SimCCUnknown},
|
|
2224
|
+
"S390X": {"Linux": SimCCS390X},
|
|
2225
|
+
}
|
|
2226
|
+
|
|
2227
|
+
|
|
2228
|
+
def register_default_cc(arch: str, cc: type[SimCC], platform: str = "Linux"):
|
|
2229
|
+
DEFAULT_CC[arch] = {platform: cc}
|
|
2230
|
+
if arch not in CC:
|
|
2231
|
+
CC[arch] = {}
|
|
2232
|
+
if platform not in CC[arch]:
|
|
2233
|
+
CC[arch][platform] = [cc]
|
|
2234
|
+
if platform != "default":
|
|
2235
|
+
CC[arch]["default"] = [cc]
|
|
2236
|
+
else:
|
|
2237
|
+
if cc not in CC[arch][platform]:
|
|
2238
|
+
CC[arch][platform].append(cc)
|
|
2239
|
+
|
|
2240
|
+
|
|
2241
|
+
ARCH_NAME_ALIASES = {
|
|
2242
|
+
"X86": ["x8632"],
|
|
2243
|
+
"AMD64": ["x86-64", "x86_64", "x8664"],
|
|
2244
|
+
"ARMEL": [],
|
|
2245
|
+
"ARMHF": [],
|
|
2246
|
+
"ARMCortexM": [],
|
|
2247
|
+
"AARCH64": ["arm64"],
|
|
2248
|
+
"MIPS32": [],
|
|
2249
|
+
"MIPS64": [],
|
|
2250
|
+
"PPC32": ["powerpc32"],
|
|
2251
|
+
"PPC64": ["powerpc64"],
|
|
2252
|
+
"Soot": [],
|
|
2253
|
+
"AVR8": [],
|
|
2254
|
+
"MSP": [],
|
|
2255
|
+
"S390X": [],
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2258
|
+
ALIAS_TO_ARCH_NAME = {}
|
|
2259
|
+
for k, vs in ARCH_NAME_ALIASES.items():
|
|
2260
|
+
for v in vs:
|
|
2261
|
+
ALIAS_TO_ARCH_NAME[v] = k
|
|
2262
|
+
|
|
2263
|
+
|
|
2264
|
+
def default_cc( # pylint:disable=unused-argument
|
|
2265
|
+
arch: str,
|
|
2266
|
+
platform: str | None = "Linux",
|
|
2267
|
+
language: str | None = None,
|
|
2268
|
+
syscall: bool = False,
|
|
2269
|
+
**kwargs,
|
|
2270
|
+
) -> type[SimCC] | None:
|
|
2271
|
+
"""
|
|
2272
|
+
Return the default calling convention for a given architecture, platform, and language combination.
|
|
2273
|
+
|
|
2274
|
+
:param arch: The architecture name.
|
|
2275
|
+
:param platform: The platform name (e.g., "Linux" or "Win32").
|
|
2276
|
+
:param language: The programming language name (e.g., "go").
|
|
2277
|
+
:param syscall: Return syscall convention (True), or normal calling convention (False, default).
|
|
2278
|
+
:return: A default calling convention class if we can find one for the architecture, platform, and
|
|
2279
|
+
language combination, or None if nothing fits.
|
|
2280
|
+
"""
|
|
2281
|
+
|
|
2282
|
+
if platform is None:
|
|
2283
|
+
platform = "Linux"
|
|
2284
|
+
|
|
2285
|
+
default = kwargs.get("default", ...)
|
|
2286
|
+
cc_map = SYSCALL_CC if syscall else DEFAULT_CC
|
|
2287
|
+
|
|
2288
|
+
if arch in cc_map:
|
|
2289
|
+
if platform not in cc_map[arch]:
|
|
2290
|
+
if default is not ...:
|
|
2291
|
+
return default
|
|
2292
|
+
if "Linux" in cc_map[arch]:
|
|
2293
|
+
return cc_map[arch]["Linux"]
|
|
2294
|
+
return cc_map[arch][platform]
|
|
2295
|
+
|
|
2296
|
+
alias = unify_arch_name(arch)
|
|
2297
|
+
if alias not in cc_map or platform not in cc_map[alias]:
|
|
2298
|
+
if default is not ...:
|
|
2299
|
+
return default
|
|
2300
|
+
return cc_map[alias][platform]
|
|
2301
|
+
|
|
2302
|
+
|
|
2303
|
+
def unify_arch_name(arch: str) -> str:
|
|
2304
|
+
"""
|
|
2305
|
+
Return the unified architecture name.
|
|
2306
|
+
|
|
2307
|
+
:param arch: The architecture name.
|
|
2308
|
+
:return: A unified architecture name.
|
|
2309
|
+
"""
|
|
2310
|
+
|
|
2311
|
+
if ":" in arch:
|
|
2312
|
+
# Sleigh architecture names
|
|
2313
|
+
chunks = arch.lower().split(":")
|
|
2314
|
+
if len(chunks) >= 3:
|
|
2315
|
+
arch_base, endianness, bits = chunks[:3] # pylint:disable=unused-variable
|
|
2316
|
+
arch = f"{arch_base}{bits}"
|
|
2317
|
+
|
|
2318
|
+
return ALIAS_TO_ARCH_NAME.get(arch, arch)
|
|
2319
|
+
|
|
2320
|
+
|
|
2321
|
+
SYSCALL_CC: dict[str, dict[str, type[SimCCSyscall]]] = {
|
|
2322
|
+
"X86": {
|
|
2323
|
+
"default": SimCCX86LinuxSyscall,
|
|
2324
|
+
"Linux": SimCCX86LinuxSyscall,
|
|
2325
|
+
"Win32": SimCCX86WindowsSyscall,
|
|
2326
|
+
"CGC": SimCCX86LinuxSyscall,
|
|
2327
|
+
},
|
|
2328
|
+
"AMD64": {
|
|
2329
|
+
"default": SimCCAMD64LinuxSyscall,
|
|
2330
|
+
"Linux": SimCCAMD64LinuxSyscall,
|
|
2331
|
+
"Win32": SimCCAMD64WindowsSyscall,
|
|
2332
|
+
},
|
|
2333
|
+
"ARMEL": {
|
|
2334
|
+
"default": SimCCARMLinuxSyscall,
|
|
2335
|
+
"Linux": SimCCARMLinuxSyscall,
|
|
2336
|
+
},
|
|
2337
|
+
"ARMCortexM": {
|
|
2338
|
+
# FIXME: TODO: This is wrong. Fill in with a real CC when we support CM syscalls
|
|
2339
|
+
"default": SimCCARMLinuxSyscall,
|
|
2340
|
+
},
|
|
2341
|
+
"ARMHF": {
|
|
2342
|
+
"default": SimCCARMLinuxSyscall,
|
|
2343
|
+
"Linux": SimCCARMLinuxSyscall,
|
|
2344
|
+
},
|
|
2345
|
+
"AARCH64": {
|
|
2346
|
+
"default": SimCCAArch64LinuxSyscall,
|
|
2347
|
+
"Linux": SimCCAArch64LinuxSyscall,
|
|
2348
|
+
},
|
|
2349
|
+
"MIPS32": {
|
|
2350
|
+
"default": SimCCO32LinuxSyscall,
|
|
2351
|
+
"Linux": SimCCO32LinuxSyscall,
|
|
2352
|
+
},
|
|
2353
|
+
"MIPS64": {
|
|
2354
|
+
"default": SimCCN64LinuxSyscall,
|
|
2355
|
+
"Linux": SimCCN64LinuxSyscall,
|
|
2356
|
+
},
|
|
2357
|
+
"PPC32": {
|
|
2358
|
+
"default": SimCCPowerPCLinuxSyscall,
|
|
2359
|
+
"Linux": SimCCPowerPCLinuxSyscall,
|
|
2360
|
+
},
|
|
2361
|
+
"PPC64": {
|
|
2362
|
+
"default": SimCCPowerPC64LinuxSyscall,
|
|
2363
|
+
"Linux": SimCCPowerPC64LinuxSyscall,
|
|
2364
|
+
},
|
|
2365
|
+
"S390X": {
|
|
2366
|
+
"default": SimCCS390XLinuxSyscall,
|
|
2367
|
+
"Linux": SimCCS390XLinuxSyscall,
|
|
2368
|
+
},
|
|
2369
|
+
"RISCV64": {
|
|
2370
|
+
"default": SimCCRISCV64LinuxSyscall,
|
|
2371
|
+
"Linux": SimCCRISCV64LinuxSyscall,
|
|
2372
|
+
},
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2375
|
+
|
|
2376
|
+
def register_syscall_cc(arch, os, cc):
|
|
2377
|
+
if arch not in SYSCALL_CC:
|
|
2378
|
+
SYSCALL_CC[arch] = {}
|
|
2379
|
+
SYSCALL_CC[arch][os] = cc
|
|
2380
|
+
|
|
2381
|
+
|
|
2382
|
+
SyscallCC = SYSCALL_CC
|
|
2383
|
+
DefaultCC = DEFAULT_CC
|