angr 9.2.192__cp311-cp311-macosx_10_12_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- angr/__init__.py +366 -0
- angr/__main__.py +182 -0
- angr/ail_callable.py +79 -0
- angr/ailment/__init__.py +83 -0
- angr/ailment/block.py +88 -0
- angr/ailment/block_walker.py +856 -0
- angr/ailment/constant.py +3 -0
- angr/ailment/converter_common.py +11 -0
- angr/ailment/converter_pcode.py +648 -0
- angr/ailment/converter_vex.py +829 -0
- angr/ailment/expression.py +1655 -0
- angr/ailment/manager.py +34 -0
- angr/ailment/statement.py +973 -0
- angr/ailment/tagged_object.py +58 -0
- angr/ailment/utils.py +114 -0
- angr/analyses/__init__.py +117 -0
- angr/analyses/analysis.py +429 -0
- angr/analyses/backward_slice.py +686 -0
- angr/analyses/binary_optimizer.py +670 -0
- angr/analyses/bindiff.py +1512 -0
- angr/analyses/boyscout.py +76 -0
- angr/analyses/callee_cleanup_finder.py +74 -0
- angr/analyses/calling_convention/__init__.py +6 -0
- angr/analyses/calling_convention/calling_convention.py +1113 -0
- angr/analyses/calling_convention/fact_collector.py +647 -0
- angr/analyses/calling_convention/utils.py +60 -0
- angr/analyses/cdg.py +189 -0
- angr/analyses/cfg/__init__.py +23 -0
- angr/analyses/cfg/cfb.py +451 -0
- angr/analyses/cfg/cfg.py +74 -0
- angr/analyses/cfg/cfg_arch_options.py +95 -0
- angr/analyses/cfg/cfg_base.py +2954 -0
- angr/analyses/cfg/cfg_emulated.py +3451 -0
- angr/analyses/cfg/cfg_fast.py +5431 -0
- angr/analyses/cfg/cfg_fast_soot.py +662 -0
- angr/analyses/cfg/cfg_job_base.py +203 -0
- angr/analyses/cfg/indirect_jump_resolvers/__init__.py +30 -0
- angr/analyses/cfg/indirect_jump_resolvers/aarch64_macho_got.py +77 -0
- angr/analyses/cfg/indirect_jump_resolvers/amd64_elf_got.py +62 -0
- angr/analyses/cfg/indirect_jump_resolvers/amd64_pe_iat.py +51 -0
- angr/analyses/cfg/indirect_jump_resolvers/arm_elf_fast.py +159 -0
- angr/analyses/cfg/indirect_jump_resolvers/const_resolver.py +339 -0
- angr/analyses/cfg/indirect_jump_resolvers/constant_value_manager.py +107 -0
- angr/analyses/cfg/indirect_jump_resolvers/default_resolvers.py +82 -0
- angr/analyses/cfg/indirect_jump_resolvers/jumptable.py +2490 -0
- angr/analyses/cfg/indirect_jump_resolvers/memload_resolver.py +81 -0
- angr/analyses/cfg/indirect_jump_resolvers/mips_elf_fast.py +286 -0
- angr/analyses/cfg/indirect_jump_resolvers/mips_elf_got.py +148 -0
- angr/analyses/cfg/indirect_jump_resolvers/propagator_utils.py +46 -0
- angr/analyses/cfg/indirect_jump_resolvers/resolver.py +74 -0
- angr/analyses/cfg/indirect_jump_resolvers/syscall_resolver.py +92 -0
- angr/analyses/cfg/indirect_jump_resolvers/x86_elf_pic_plt.py +88 -0
- angr/analyses/cfg/indirect_jump_resolvers/x86_pe_iat.py +47 -0
- angr/analyses/cfg_slice_to_sink/__init__.py +11 -0
- angr/analyses/cfg_slice_to_sink/cfg_slice_to_sink.py +117 -0
- angr/analyses/cfg_slice_to_sink/graph.py +87 -0
- angr/analyses/cfg_slice_to_sink/transitions.py +27 -0
- angr/analyses/class_identifier.py +63 -0
- angr/analyses/code_tagging.py +123 -0
- angr/analyses/codecave.py +77 -0
- angr/analyses/complete_calling_conventions.py +475 -0
- angr/analyses/congruency_check.py +377 -0
- angr/analyses/data_dep/__init__.py +16 -0
- angr/analyses/data_dep/data_dependency_analysis.py +595 -0
- angr/analyses/data_dep/dep_nodes.py +171 -0
- angr/analyses/data_dep/sim_act_location.py +49 -0
- angr/analyses/datagraph_meta.py +105 -0
- angr/analyses/ddg.py +1670 -0
- angr/analyses/decompiler/__init__.py +41 -0
- angr/analyses/decompiler/ail_simplifier.py +2246 -0
- angr/analyses/decompiler/ailgraph_walker.py +49 -0
- angr/analyses/decompiler/block_io_finder.py +302 -0
- angr/analyses/decompiler/block_similarity.py +199 -0
- angr/analyses/decompiler/block_simplifier.py +397 -0
- angr/analyses/decompiler/callsite_maker.py +579 -0
- angr/analyses/decompiler/ccall_rewriters/__init__.py +9 -0
- angr/analyses/decompiler/ccall_rewriters/amd64_ccalls.py +618 -0
- angr/analyses/decompiler/ccall_rewriters/rewriter_base.py +24 -0
- angr/analyses/decompiler/ccall_rewriters/x86_ccalls.py +354 -0
- angr/analyses/decompiler/clinic.py +3662 -0
- angr/analyses/decompiler/condition_processor.py +1323 -0
- angr/analyses/decompiler/counters/__init__.py +16 -0
- angr/analyses/decompiler/counters/boolean_counter.py +27 -0
- angr/analyses/decompiler/counters/call_counter.py +77 -0
- angr/analyses/decompiler/counters/expression_counters.py +77 -0
- angr/analyses/decompiler/counters/seq_cf_structure_counter.py +63 -0
- angr/analyses/decompiler/decompilation_cache.py +54 -0
- angr/analyses/decompiler/decompilation_options.py +317 -0
- angr/analyses/decompiler/decompiler.py +796 -0
- angr/analyses/decompiler/dephication/__init__.py +6 -0
- angr/analyses/decompiler/dephication/dephication_base.py +100 -0
- angr/analyses/decompiler/dephication/graph_dephication.py +70 -0
- angr/analyses/decompiler/dephication/graph_rewriting.py +112 -0
- angr/analyses/decompiler/dephication/graph_vvar_mapping.py +357 -0
- angr/analyses/decompiler/dephication/rewriting_engine.py +528 -0
- angr/analyses/decompiler/dephication/seqnode_dephication.py +156 -0
- angr/analyses/decompiler/dirty_rewriters/__init__.py +7 -0
- angr/analyses/decompiler/dirty_rewriters/amd64_dirty.py +74 -0
- angr/analyses/decompiler/dirty_rewriters/rewriter_base.py +27 -0
- angr/analyses/decompiler/empty_node_remover.py +212 -0
- angr/analyses/decompiler/expression_narrower.py +290 -0
- angr/analyses/decompiler/goto_manager.py +112 -0
- angr/analyses/decompiler/graph_region.py +441 -0
- angr/analyses/decompiler/jump_target_collector.py +37 -0
- angr/analyses/decompiler/jumptable_entry_condition_rewriter.py +67 -0
- angr/analyses/decompiler/label_collector.py +32 -0
- angr/analyses/decompiler/node_replacer.py +42 -0
- angr/analyses/decompiler/notes/__init__.py +9 -0
- angr/analyses/decompiler/notes/decompilation_note.py +48 -0
- angr/analyses/decompiler/notes/deobfuscated_strings.py +56 -0
- angr/analyses/decompiler/optimization_passes/__init__.py +164 -0
- angr/analyses/decompiler/optimization_passes/base_ptr_save_simplifier.py +157 -0
- angr/analyses/decompiler/optimization_passes/call_stmt_rewriter.py +46 -0
- angr/analyses/decompiler/optimization_passes/code_motion.py +362 -0
- angr/analyses/decompiler/optimization_passes/condition_constprop.py +211 -0
- angr/analyses/decompiler/optimization_passes/const_derefs.py +127 -0
- angr/analyses/decompiler/optimization_passes/const_prop_reverter.py +365 -0
- angr/analyses/decompiler/optimization_passes/cross_jump_reverter.py +106 -0
- angr/analyses/decompiler/optimization_passes/deadblock_remover.py +82 -0
- angr/analyses/decompiler/optimization_passes/determine_load_sizes.py +64 -0
- angr/analyses/decompiler/optimization_passes/div_simplifier.py +425 -0
- angr/analyses/decompiler/optimization_passes/duplication_reverter/__init__.py +5 -0
- angr/analyses/decompiler/optimization_passes/duplication_reverter/ail_merge_graph.py +503 -0
- angr/analyses/decompiler/optimization_passes/duplication_reverter/duplication_reverter.py +1221 -0
- angr/analyses/decompiler/optimization_passes/duplication_reverter/errors.py +16 -0
- angr/analyses/decompiler/optimization_passes/duplication_reverter/similarity.py +126 -0
- angr/analyses/decompiler/optimization_passes/duplication_reverter/utils.py +167 -0
- angr/analyses/decompiler/optimization_passes/eager_std_string_concatenation.py +236 -0
- angr/analyses/decompiler/optimization_passes/eager_std_string_eval.py +186 -0
- angr/analyses/decompiler/optimization_passes/engine_base.py +502 -0
- angr/analyses/decompiler/optimization_passes/expr_op_swapper.py +138 -0
- angr/analyses/decompiler/optimization_passes/flip_boolean_cmp.py +113 -0
- angr/analyses/decompiler/optimization_passes/inlined_string_transformation_simplifier.py +618 -0
- angr/analyses/decompiler/optimization_passes/inlined_strlen_simplifier.py +274 -0
- angr/analyses/decompiler/optimization_passes/ite_expr_converter.py +224 -0
- angr/analyses/decompiler/optimization_passes/ite_region_converter.py +337 -0
- angr/analyses/decompiler/optimization_passes/lowered_switch_simplifier.py +939 -0
- angr/analyses/decompiler/optimization_passes/mod_simplifier.py +99 -0
- angr/analyses/decompiler/optimization_passes/optimization_pass.py +710 -0
- angr/analyses/decompiler/optimization_passes/peephole_simplifier.py +75 -0
- angr/analyses/decompiler/optimization_passes/register_save_area_simplifier.py +263 -0
- angr/analyses/decompiler/optimization_passes/register_save_area_simplifier_adv.py +198 -0
- angr/analyses/decompiler/optimization_passes/ret_addr_save_simplifier.py +171 -0
- angr/analyses/decompiler/optimization_passes/ret_deduplicator.py +222 -0
- angr/analyses/decompiler/optimization_passes/return_duplicator_base.py +632 -0
- angr/analyses/decompiler/optimization_passes/return_duplicator_high.py +61 -0
- angr/analyses/decompiler/optimization_passes/return_duplicator_low.py +166 -0
- angr/analyses/decompiler/optimization_passes/stack_canary_simplifier.py +333 -0
- angr/analyses/decompiler/optimization_passes/static_vvar_rewriter.py +336 -0
- angr/analyses/decompiler/optimization_passes/switch_default_case_duplicator.py +166 -0
- angr/analyses/decompiler/optimization_passes/switch_reused_entry_rewriter.py +102 -0
- angr/analyses/decompiler/optimization_passes/tag_slicer.py +41 -0
- angr/analyses/decompiler/optimization_passes/win_stack_canary_simplifier.py +477 -0
- angr/analyses/decompiler/optimization_passes/x86_gcc_getpc_simplifier.py +88 -0
- angr/analyses/decompiler/peephole_optimizations/__init__.py +136 -0
- angr/analyses/decompiler/peephole_optimizations/a_div_const_add_a_mul_n_div_const.py +42 -0
- angr/analyses/decompiler/peephole_optimizations/a_mul_const_div_shr_const.py +38 -0
- angr/analyses/decompiler/peephole_optimizations/a_mul_const_sub_a.py +34 -0
- angr/analyses/decompiler/peephole_optimizations/a_shl_const_sub_a.py +34 -0
- angr/analyses/decompiler/peephole_optimizations/a_sub_a_div.py +25 -0
- angr/analyses/decompiler/peephole_optimizations/a_sub_a_shr_const_shr_const.py +37 -0
- angr/analyses/decompiler/peephole_optimizations/a_sub_a_sub_n.py +23 -0
- angr/analyses/decompiler/peephole_optimizations/arm_cmpf.py +236 -0
- angr/analyses/decompiler/peephole_optimizations/base.py +157 -0
- angr/analyses/decompiler/peephole_optimizations/basepointeroffset_add_n.py +34 -0
- angr/analyses/decompiler/peephole_optimizations/basepointeroffset_and_mask.py +36 -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 +142 -0
- angr/analyses/decompiler/peephole_optimizations/cas_intrinsics.py +182 -0
- angr/analyses/decompiler/peephole_optimizations/cmpord_rewriter.py +71 -0
- angr/analyses/decompiler/peephole_optimizations/coalesce_adjacent_shrs.py +39 -0
- angr/analyses/decompiler/peephole_optimizations/coalesce_same_cascading_ifs.py +28 -0
- angr/analyses/decompiler/peephole_optimizations/constant_derefs.py +44 -0
- angr/analyses/decompiler/peephole_optimizations/conv_a_sub0_shr_and.py +69 -0
- angr/analyses/decompiler/peephole_optimizations/conv_shl_shr.py +52 -0
- angr/analyses/decompiler/peephole_optimizations/eager_eval.py +436 -0
- angr/analyses/decompiler/peephole_optimizations/extended_byte_and_mask.py +56 -0
- angr/analyses/decompiler/peephole_optimizations/inlined_memcpy.py +78 -0
- angr/analyses/decompiler/peephole_optimizations/inlined_memset.py +262 -0
- angr/analyses/decompiler/peephole_optimizations/inlined_strcpy.py +217 -0
- angr/analyses/decompiler/peephole_optimizations/inlined_strcpy_consolidation.py +106 -0
- angr/analyses/decompiler/peephole_optimizations/inlined_wcscpy.py +256 -0
- angr/analyses/decompiler/peephole_optimizations/inlined_wcscpy_consolidation.py +296 -0
- angr/analyses/decompiler/peephole_optimizations/invert_negated_logical_conjuction_disjunction.py +50 -0
- angr/analyses/decompiler/peephole_optimizations/modulo_simplifier.py +89 -0
- angr/analyses/decompiler/peephole_optimizations/one_sub_bool.py +33 -0
- angr/analyses/decompiler/peephole_optimizations/optimized_div_simplifier.py +356 -0
- angr/analyses/decompiler/peephole_optimizations/remove_cascading_conversions.py +45 -0
- angr/analyses/decompiler/peephole_optimizations/remove_cxx_destructor_calls.py +32 -0
- angr/analyses/decompiler/peephole_optimizations/remove_empty_if_body.py +46 -0
- angr/analyses/decompiler/peephole_optimizations/remove_noop_conversions.py +47 -0
- angr/analyses/decompiler/peephole_optimizations/remove_redundant_bitmasks.py +125 -0
- angr/analyses/decompiler/peephole_optimizations/remove_redundant_conversions.py +273 -0
- angr/analyses/decompiler/peephole_optimizations/remove_redundant_derefs.py +21 -0
- angr/analyses/decompiler/peephole_optimizations/remove_redundant_ite_branch.py +30 -0
- angr/analyses/decompiler/peephole_optimizations/remove_redundant_ite_comparisons.py +54 -0
- angr/analyses/decompiler/peephole_optimizations/remove_redundant_nots.py +36 -0
- angr/analyses/decompiler/peephole_optimizations/remove_redundant_reinterprets.py +44 -0
- angr/analyses/decompiler/peephole_optimizations/remove_redundant_shifts.py +95 -0
- angr/analyses/decompiler/peephole_optimizations/remove_redundant_shifts_around_comparators.py +115 -0
- angr/analyses/decompiler/peephole_optimizations/rewrite_bit_extractions.py +85 -0
- angr/analyses/decompiler/peephole_optimizations/rewrite_conv_mul.py +40 -0
- angr/analyses/decompiler/peephole_optimizations/rewrite_cxx_operator_calls.py +90 -0
- angr/analyses/decompiler/peephole_optimizations/rewrite_mips_gp_loads.py +49 -0
- angr/analyses/decompiler/peephole_optimizations/rol_ror.py +130 -0
- angr/analyses/decompiler/peephole_optimizations/sar_to_signed_div.py +143 -0
- angr/analyses/decompiler/peephole_optimizations/shl_to_mul.py +25 -0
- angr/analyses/decompiler/peephole_optimizations/simplify_pc_relative_loads.py +51 -0
- angr/analyses/decompiler/peephole_optimizations/single_bit_cond_to_boolexpr.py +28 -0
- angr/analyses/decompiler/peephole_optimizations/single_bit_xor.py +29 -0
- angr/analyses/decompiler/peephole_optimizations/tidy_stack_addr.py +131 -0
- angr/analyses/decompiler/peephole_optimizations/utils.py +18 -0
- angr/analyses/decompiler/presets/__init__.py +22 -0
- angr/analyses/decompiler/presets/basic.py +36 -0
- angr/analyses/decompiler/presets/fast.py +66 -0
- angr/analyses/decompiler/presets/full.py +76 -0
- angr/analyses/decompiler/presets/malware.py +70 -0
- angr/analyses/decompiler/presets/preset.py +37 -0
- angr/analyses/decompiler/redundant_label_remover.py +141 -0
- angr/analyses/decompiler/region_identifier.py +1319 -0
- angr/analyses/decompiler/region_simplifiers/__init__.py +5 -0
- angr/analyses/decompiler/region_simplifiers/cascading_cond_transformer.py +95 -0
- angr/analyses/decompiler/region_simplifiers/cascading_ifs.py +82 -0
- angr/analyses/decompiler/region_simplifiers/expr_folding.py +838 -0
- angr/analyses/decompiler/region_simplifiers/goto.py +178 -0
- angr/analyses/decompiler/region_simplifiers/if_.py +135 -0
- angr/analyses/decompiler/region_simplifiers/ifelse.py +91 -0
- angr/analyses/decompiler/region_simplifiers/loop.py +143 -0
- angr/analyses/decompiler/region_simplifiers/node_address_finder.py +24 -0
- angr/analyses/decompiler/region_simplifiers/region_simplifier.py +270 -0
- angr/analyses/decompiler/region_simplifiers/switch_cluster_simplifier.py +654 -0
- angr/analyses/decompiler/region_simplifiers/switch_expr_simplifier.py +87 -0
- angr/analyses/decompiler/region_walker.py +24 -0
- angr/analyses/decompiler/return_maker.py +72 -0
- angr/analyses/decompiler/semantic_naming/__init__.py +37 -0
- angr/analyses/decompiler/semantic_naming/array_index_naming.py +196 -0
- angr/analyses/decompiler/semantic_naming/boolean_naming.py +264 -0
- angr/analyses/decompiler/semantic_naming/call_result_naming.py +220 -0
- angr/analyses/decompiler/semantic_naming/naming_base.py +166 -0
- angr/analyses/decompiler/semantic_naming/orchestrator.py +107 -0
- angr/analyses/decompiler/semantic_naming/pointer_naming.py +334 -0
- angr/analyses/decompiler/semantic_naming/region_loop_counter_naming.py +246 -0
- angr/analyses/decompiler/semantic_naming/size_naming.py +137 -0
- angr/analyses/decompiler/seq_to_blocks.py +20 -0
- angr/analyses/decompiler/sequence_walker.py +261 -0
- angr/analyses/decompiler/ssailification/__init__.py +4 -0
- angr/analyses/decompiler/ssailification/rewriting.py +451 -0
- angr/analyses/decompiler/ssailification/rewriting_engine.py +1091 -0
- angr/analyses/decompiler/ssailification/rewriting_state.py +61 -0
- angr/analyses/decompiler/ssailification/ssailification.py +283 -0
- angr/analyses/decompiler/ssailification/traversal.py +127 -0
- angr/analyses/decompiler/ssailification/traversal_engine.py +323 -0
- angr/analyses/decompiler/ssailification/traversal_state.py +48 -0
- angr/analyses/decompiler/stack_item.py +36 -0
- angr/analyses/decompiler/structured_codegen/__init__.py +25 -0
- angr/analyses/decompiler/structured_codegen/base.py +193 -0
- angr/analyses/decompiler/structured_codegen/c.py +4257 -0
- angr/analyses/decompiler/structured_codegen/dummy.py +15 -0
- angr/analyses/decompiler/structured_codegen/dwarf_import.py +190 -0
- angr/analyses/decompiler/structuring/__init__.py +30 -0
- angr/analyses/decompiler/structuring/dream.py +1217 -0
- angr/analyses/decompiler/structuring/phoenix.py +3636 -0
- angr/analyses/decompiler/structuring/recursive_structurer.py +187 -0
- angr/analyses/decompiler/structuring/sailr.py +120 -0
- angr/analyses/decompiler/structuring/structurer_base.py +1140 -0
- angr/analyses/decompiler/structuring/structurer_nodes.py +442 -0
- angr/analyses/decompiler/utils.py +1224 -0
- angr/analyses/deobfuscator/__init__.py +23 -0
- angr/analyses/deobfuscator/api_obf_finder.py +333 -0
- angr/analyses/deobfuscator/api_obf_peephole_optimizer.py +80 -0
- angr/analyses/deobfuscator/api_obf_type2_finder.py +166 -0
- angr/analyses/deobfuscator/data_transformation_embedder.py +633 -0
- angr/analyses/deobfuscator/hash_lookup_api_deobfuscator.py +156 -0
- angr/analyses/deobfuscator/irsb_reg_collector.py +54 -0
- angr/analyses/deobfuscator/scope_ops_analyzer.py +68 -0
- angr/analyses/deobfuscator/string_obf_finder.py +983 -0
- angr/analyses/deobfuscator/string_obf_opt_passes.py +136 -0
- angr/analyses/deobfuscator/string_obf_peephole_optimizer.py +47 -0
- angr/analyses/disassembly.py +1351 -0
- angr/analyses/disassembly_utils.py +101 -0
- angr/analyses/dominance_frontier.py +57 -0
- angr/analyses/fcp/__init__.py +4 -0
- angr/analyses/fcp/fcp.py +427 -0
- angr/analyses/find_objects_static.py +205 -0
- angr/analyses/flirt/__init__.py +47 -0
- angr/analyses/flirt/consts.py +160 -0
- angr/analyses/flirt/flirt.py +249 -0
- angr/analyses/flirt/flirt_function.py +20 -0
- angr/analyses/flirt/flirt_matcher.py +352 -0
- angr/analyses/flirt/flirt_module.py +32 -0
- angr/analyses/flirt/flirt_node.py +23 -0
- angr/analyses/flirt/flirt_sig.py +359 -0
- angr/analyses/flirt/flirt_utils.py +31 -0
- angr/analyses/forward_analysis/__init__.py +12 -0
- angr/analyses/forward_analysis/forward_analysis.py +619 -0
- angr/analyses/forward_analysis/job_info.py +64 -0
- angr/analyses/forward_analysis/visitors/__init__.py +14 -0
- angr/analyses/forward_analysis/visitors/call_graph.py +29 -0
- angr/analyses/forward_analysis/visitors/function_graph.py +86 -0
- angr/analyses/forward_analysis/visitors/graph.py +242 -0
- angr/analyses/forward_analysis/visitors/loop.py +29 -0
- angr/analyses/forward_analysis/visitors/single_node_graph.py +38 -0
- angr/analyses/identifier/__init__.py +5 -0
- angr/analyses/identifier/custom_callable.py +137 -0
- angr/analyses/identifier/errors.py +10 -0
- angr/analyses/identifier/func.py +60 -0
- angr/analyses/identifier/functions/__init__.py +37 -0
- angr/analyses/identifier/functions/atoi.py +73 -0
- angr/analyses/identifier/functions/based_atoi.py +125 -0
- angr/analyses/identifier/functions/fdprintf.py +123 -0
- angr/analyses/identifier/functions/free.py +64 -0
- angr/analyses/identifier/functions/int2str.py +287 -0
- angr/analyses/identifier/functions/malloc.py +111 -0
- angr/analyses/identifier/functions/memcmp.py +67 -0
- angr/analyses/identifier/functions/memcpy.py +89 -0
- angr/analyses/identifier/functions/memset.py +43 -0
- angr/analyses/identifier/functions/printf.py +123 -0
- angr/analyses/identifier/functions/recv_until.py +312 -0
- angr/analyses/identifier/functions/skip_calloc.py +73 -0
- angr/analyses/identifier/functions/skip_realloc.py +97 -0
- angr/analyses/identifier/functions/skip_recv_n.py +105 -0
- angr/analyses/identifier/functions/snprintf.py +112 -0
- angr/analyses/identifier/functions/sprintf.py +116 -0
- angr/analyses/identifier/functions/strcasecmp.py +33 -0
- angr/analyses/identifier/functions/strcmp.py +113 -0
- angr/analyses/identifier/functions/strcpy.py +43 -0
- angr/analyses/identifier/functions/strlen.py +27 -0
- angr/analyses/identifier/functions/strncmp.py +104 -0
- angr/analyses/identifier/functions/strncpy.py +65 -0
- angr/analyses/identifier/functions/strtol.py +89 -0
- angr/analyses/identifier/identify.py +825 -0
- angr/analyses/identifier/runner.py +360 -0
- angr/analyses/init_finder.py +289 -0
- angr/analyses/loop_analysis/__init__.py +4 -0
- angr/analyses/loop_analysis/loop_analysis.py +464 -0
- angr/analyses/loop_analysis.py +349 -0
- angr/analyses/loop_unroller/__init__.py +4 -0
- angr/analyses/loop_unroller/loop_unroller.py +222 -0
- angr/analyses/loopfinder.py +171 -0
- angr/analyses/outliner/__init__.py +7 -0
- angr/analyses/outliner/outliner.py +402 -0
- angr/analyses/patchfinder.py +137 -0
- angr/analyses/pathfinder.py +282 -0
- angr/analyses/propagator/__init__.py +5 -0
- angr/analyses/propagator/engine_base.py +62 -0
- angr/analyses/propagator/engine_vex.py +297 -0
- angr/analyses/propagator/propagator.py +361 -0
- angr/analyses/propagator/top_checker_mixin.py +218 -0
- angr/analyses/propagator/values.py +117 -0
- angr/analyses/propagator/vex_vars.py +68 -0
- angr/analyses/proximity_graph.py +444 -0
- angr/analyses/purity/__init__.py +15 -0
- angr/analyses/purity/analysis.py +78 -0
- angr/analyses/purity/engine.py +593 -0
- angr/analyses/reaching_definitions/__init__.py +67 -0
- angr/analyses/reaching_definitions/call_trace.py +73 -0
- angr/analyses/reaching_definitions/dep_graph.py +433 -0
- angr/analyses/reaching_definitions/engine_ail.py +1128 -0
- angr/analyses/reaching_definitions/engine_vex.py +1128 -0
- angr/analyses/reaching_definitions/external_codeloc.py +0 -0
- angr/analyses/reaching_definitions/function_handler.py +639 -0
- angr/analyses/reaching_definitions/function_handler_library/__init__.py +12 -0
- angr/analyses/reaching_definitions/function_handler_library/stdio.py +269 -0
- angr/analyses/reaching_definitions/function_handler_library/stdlib.py +195 -0
- angr/analyses/reaching_definitions/function_handler_library/string.py +158 -0
- angr/analyses/reaching_definitions/function_handler_library/unistd.py +51 -0
- angr/analyses/reaching_definitions/heap_allocator.py +70 -0
- angr/analyses/reaching_definitions/rd_initializer.py +237 -0
- angr/analyses/reaching_definitions/rd_state.py +579 -0
- angr/analyses/reaching_definitions/reaching_definitions.py +581 -0
- angr/analyses/reaching_definitions/subject.py +65 -0
- angr/analyses/reassembler.py +2900 -0
- angr/analyses/s_liveness.py +254 -0
- angr/analyses/s_propagator.py +575 -0
- angr/analyses/s_reaching_definitions/__init__.py +12 -0
- angr/analyses/s_reaching_definitions/s_rda_model.py +145 -0
- angr/analyses/s_reaching_definitions/s_rda_view.py +344 -0
- angr/analyses/s_reaching_definitions/s_reaching_definitions.py +230 -0
- angr/analyses/smc.py +160 -0
- angr/analyses/soot_class_hierarchy.py +273 -0
- angr/analyses/stack_pointer_tracker.py +954 -0
- angr/analyses/static_hooker.py +53 -0
- angr/analyses/typehoon/__init__.py +5 -0
- angr/analyses/typehoon/dfa.py +118 -0
- angr/analyses/typehoon/lifter.py +133 -0
- angr/analyses/typehoon/simple_solver.py +2009 -0
- angr/analyses/typehoon/translator.py +283 -0
- angr/analyses/typehoon/typeconsts.py +439 -0
- angr/analyses/typehoon/typehoon.py +338 -0
- angr/analyses/typehoon/typevars.py +633 -0
- angr/analyses/typehoon/variance.py +11 -0
- angr/analyses/unpacker/__init__.py +6 -0
- angr/analyses/unpacker/obfuscation_detector.py +103 -0
- angr/analyses/unpacker/packing_detector.py +138 -0
- angr/analyses/variable_recovery/__init__.py +9 -0
- angr/analyses/variable_recovery/annotations.py +58 -0
- angr/analyses/variable_recovery/engine_ail.py +978 -0
- angr/analyses/variable_recovery/engine_base.py +1256 -0
- angr/analyses/variable_recovery/engine_vex.py +594 -0
- angr/analyses/variable_recovery/irsb_scanner.py +143 -0
- angr/analyses/variable_recovery/variable_recovery.py +574 -0
- angr/analyses/variable_recovery/variable_recovery_base.py +489 -0
- angr/analyses/variable_recovery/variable_recovery_fast.py +669 -0
- angr/analyses/veritesting.py +626 -0
- angr/analyses/vfg.py +1898 -0
- angr/analyses/vsa_ddg.py +420 -0
- angr/analyses/vtable.py +92 -0
- angr/analyses/xrefs.py +286 -0
- angr/angrdb/__init__.py +14 -0
- angr/angrdb/db.py +215 -0
- angr/angrdb/models.py +184 -0
- angr/angrdb/serializers/__init__.py +10 -0
- angr/angrdb/serializers/cfg_model.py +41 -0
- angr/angrdb/serializers/comments.py +60 -0
- angr/angrdb/serializers/funcs.py +61 -0
- angr/angrdb/serializers/kb.py +111 -0
- angr/angrdb/serializers/labels.py +59 -0
- angr/angrdb/serializers/loader.py +165 -0
- angr/angrdb/serializers/structured_code.py +167 -0
- angr/angrdb/serializers/variables.py +58 -0
- angr/angrdb/serializers/xrefs.py +48 -0
- angr/annocfg.py +317 -0
- angr/blade.py +431 -0
- angr/block.py +509 -0
- angr/callable.py +176 -0
- angr/calling_conventions.py +2613 -0
- angr/code_location.py +249 -0
- angr/codenode.py +145 -0
- angr/concretization_strategies/__init__.py +32 -0
- angr/concretization_strategies/any.py +17 -0
- angr/concretization_strategies/any_named.py +35 -0
- angr/concretization_strategies/base.py +81 -0
- angr/concretization_strategies/controlled_data.py +58 -0
- angr/concretization_strategies/eval.py +19 -0
- angr/concretization_strategies/logging.py +35 -0
- angr/concretization_strategies/max.py +25 -0
- angr/concretization_strategies/nonzero.py +16 -0
- angr/concretization_strategies/nonzero_range.py +22 -0
- angr/concretization_strategies/norepeats.py +37 -0
- angr/concretization_strategies/norepeats_range.py +37 -0
- angr/concretization_strategies/range.py +19 -0
- angr/concretization_strategies/signed_add.py +31 -0
- angr/concretization_strategies/single.py +15 -0
- angr/concretization_strategies/solutions.py +20 -0
- angr/concretization_strategies/unlimited_range.py +17 -0
- angr/distributed/__init__.py +9 -0
- angr/distributed/server.py +197 -0
- angr/distributed/worker.py +185 -0
- angr/emulator.py +144 -0
- angr/engines/__init__.py +69 -0
- angr/engines/ail/__init__.py +16 -0
- angr/engines/ail/callstack.py +58 -0
- angr/engines/ail/engine_light.py +903 -0
- angr/engines/ail/engine_successors.py +24 -0
- angr/engines/ail/setup.py +57 -0
- angr/engines/concrete.py +66 -0
- angr/engines/engine.py +29 -0
- angr/engines/failure.py +27 -0
- angr/engines/hook.py +93 -0
- angr/engines/icicle.py +294 -0
- angr/engines/light/__init__.py +23 -0
- angr/engines/light/data.py +681 -0
- angr/engines/light/engine.py +1297 -0
- angr/engines/pcode/__init__.py +9 -0
- angr/engines/pcode/behavior.py +998 -0
- angr/engines/pcode/cc.py +148 -0
- angr/engines/pcode/emulate.py +440 -0
- angr/engines/pcode/engine.py +242 -0
- angr/engines/pcode/lifter.py +1428 -0
- angr/engines/procedure.py +70 -0
- angr/engines/soot/__init__.py +5 -0
- angr/engines/soot/engine.py +410 -0
- angr/engines/soot/exceptions.py +17 -0
- angr/engines/soot/expressions/__init__.py +87 -0
- angr/engines/soot/expressions/arrayref.py +22 -0
- angr/engines/soot/expressions/base.py +21 -0
- angr/engines/soot/expressions/binop.py +28 -0
- angr/engines/soot/expressions/cast.py +22 -0
- angr/engines/soot/expressions/condition.py +35 -0
- angr/engines/soot/expressions/constants.py +47 -0
- angr/engines/soot/expressions/instanceOf.py +15 -0
- angr/engines/soot/expressions/instancefieldref.py +8 -0
- angr/engines/soot/expressions/invoke.py +114 -0
- angr/engines/soot/expressions/length.py +8 -0
- angr/engines/soot/expressions/local.py +8 -0
- angr/engines/soot/expressions/new.py +16 -0
- angr/engines/soot/expressions/newArray.py +54 -0
- angr/engines/soot/expressions/newMultiArray.py +86 -0
- angr/engines/soot/expressions/paramref.py +8 -0
- angr/engines/soot/expressions/phi.py +30 -0
- angr/engines/soot/expressions/staticfieldref.py +8 -0
- angr/engines/soot/expressions/thisref.py +7 -0
- angr/engines/soot/expressions/unsupported.py +7 -0
- angr/engines/soot/field_dispatcher.py +46 -0
- angr/engines/soot/method_dispatcher.py +46 -0
- angr/engines/soot/statements/__init__.py +44 -0
- angr/engines/soot/statements/assign.py +30 -0
- angr/engines/soot/statements/base.py +79 -0
- angr/engines/soot/statements/goto.py +14 -0
- angr/engines/soot/statements/identity.py +15 -0
- angr/engines/soot/statements/if_.py +19 -0
- angr/engines/soot/statements/invoke.py +12 -0
- angr/engines/soot/statements/return_.py +20 -0
- angr/engines/soot/statements/switch.py +41 -0
- angr/engines/soot/statements/throw.py +15 -0
- angr/engines/soot/values/__init__.py +38 -0
- angr/engines/soot/values/arrayref.py +122 -0
- angr/engines/soot/values/base.py +7 -0
- angr/engines/soot/values/constants.py +18 -0
- angr/engines/soot/values/instancefieldref.py +44 -0
- angr/engines/soot/values/local.py +18 -0
- angr/engines/soot/values/paramref.py +18 -0
- angr/engines/soot/values/staticfieldref.py +38 -0
- angr/engines/soot/values/strref.py +38 -0
- angr/engines/soot/values/thisref.py +149 -0
- angr/engines/successors.py +608 -0
- angr/engines/syscall.py +51 -0
- angr/engines/unicorn.py +490 -0
- angr/engines/vex/__init__.py +20 -0
- angr/engines/vex/claripy/__init__.py +5 -0
- angr/engines/vex/claripy/ccall.py +2097 -0
- angr/engines/vex/claripy/datalayer.py +141 -0
- angr/engines/vex/claripy/irop.py +1276 -0
- angr/engines/vex/heavy/__init__.py +16 -0
- angr/engines/vex/heavy/actions.py +231 -0
- angr/engines/vex/heavy/concretizers.py +403 -0
- angr/engines/vex/heavy/dirty.py +466 -0
- angr/engines/vex/heavy/heavy.py +370 -0
- angr/engines/vex/heavy/inspect.py +52 -0
- angr/engines/vex/heavy/resilience.py +85 -0
- angr/engines/vex/heavy/super_fastpath.py +34 -0
- angr/engines/vex/lifter.py +420 -0
- angr/engines/vex/light/__init__.py +11 -0
- angr/engines/vex/light/light.py +551 -0
- angr/engines/vex/light/resilience.py +74 -0
- angr/engines/vex/light/slicing.py +52 -0
- angr/errors.py +611 -0
- angr/exploration_techniques/__init__.py +53 -0
- angr/exploration_techniques/base.py +126 -0
- angr/exploration_techniques/bucketizer.py +94 -0
- angr/exploration_techniques/common.py +56 -0
- angr/exploration_techniques/dfs.py +37 -0
- angr/exploration_techniques/director.py +520 -0
- angr/exploration_techniques/driller_core.py +100 -0
- angr/exploration_techniques/explorer.py +152 -0
- angr/exploration_techniques/lengthlimiter.py +22 -0
- angr/exploration_techniques/local_loop_seer.py +65 -0
- angr/exploration_techniques/loop_seer.py +236 -0
- angr/exploration_techniques/manual_mergepoint.py +82 -0
- angr/exploration_techniques/memory_watcher.py +43 -0
- angr/exploration_techniques/oppologist.py +92 -0
- angr/exploration_techniques/slicecutor.py +118 -0
- angr/exploration_techniques/spiller.py +280 -0
- angr/exploration_techniques/spiller_db.py +27 -0
- angr/exploration_techniques/stochastic.py +56 -0
- angr/exploration_techniques/stub_stasher.py +19 -0
- angr/exploration_techniques/suggestions.py +159 -0
- angr/exploration_techniques/tech_builder.py +49 -0
- angr/exploration_techniques/threading.py +69 -0
- angr/exploration_techniques/timeout.py +34 -0
- angr/exploration_techniques/tracer.py +1098 -0
- angr/exploration_techniques/unique.py +106 -0
- angr/exploration_techniques/veritesting.py +37 -0
- angr/factory.py +413 -0
- angr/flirt/__init__.py +124 -0
- angr/flirt/build_sig.py +305 -0
- angr/graph_utils.py +0 -0
- angr/keyed_region.py +525 -0
- angr/knowledge_base.py +146 -0
- angr/knowledge_plugins/__init__.py +43 -0
- angr/knowledge_plugins/callsite_prototypes.py +95 -0
- angr/knowledge_plugins/cfg/__init__.py +18 -0
- angr/knowledge_plugins/cfg/cfg_manager.py +95 -0
- angr/knowledge_plugins/cfg/cfg_model.py +1043 -0
- angr/knowledge_plugins/cfg/cfg_node.py +536 -0
- angr/knowledge_plugins/cfg/indirect_jump.py +131 -0
- angr/knowledge_plugins/cfg/memory_data.py +156 -0
- angr/knowledge_plugins/comments.py +16 -0
- angr/knowledge_plugins/custom_strings.py +38 -0
- angr/knowledge_plugins/data.py +22 -0
- angr/knowledge_plugins/debug_variables.py +216 -0
- angr/knowledge_plugins/functions/__init__.py +9 -0
- angr/knowledge_plugins/functions/function.py +1830 -0
- angr/knowledge_plugins/functions/function_manager.py +621 -0
- angr/knowledge_plugins/functions/function_parser.py +360 -0
- angr/knowledge_plugins/functions/soot_function.py +128 -0
- angr/knowledge_plugins/indirect_jumps.py +35 -0
- angr/knowledge_plugins/key_definitions/__init__.py +17 -0
- angr/knowledge_plugins/key_definitions/atoms.py +374 -0
- angr/knowledge_plugins/key_definitions/constants.py +29 -0
- angr/knowledge_plugins/key_definitions/definition.py +216 -0
- angr/knowledge_plugins/key_definitions/environment.py +96 -0
- angr/knowledge_plugins/key_definitions/heap_address.py +33 -0
- angr/knowledge_plugins/key_definitions/key_definition_manager.py +82 -0
- angr/knowledge_plugins/key_definitions/live_definitions.py +1020 -0
- angr/knowledge_plugins/key_definitions/liveness.py +165 -0
- angr/knowledge_plugins/key_definitions/rd_model.py +171 -0
- angr/knowledge_plugins/key_definitions/tag.py +78 -0
- angr/knowledge_plugins/key_definitions/undefined.py +70 -0
- angr/knowledge_plugins/key_definitions/unknown_size.py +86 -0
- angr/knowledge_plugins/key_definitions/uses.py +178 -0
- angr/knowledge_plugins/labels.py +110 -0
- angr/knowledge_plugins/obfuscations.py +40 -0
- angr/knowledge_plugins/patches.py +126 -0
- angr/knowledge_plugins/plugin.py +24 -0
- angr/knowledge_plugins/propagations/__init__.py +10 -0
- angr/knowledge_plugins/propagations/prop_value.py +191 -0
- angr/knowledge_plugins/propagations/propagation_manager.py +60 -0
- angr/knowledge_plugins/propagations/propagation_model.py +80 -0
- angr/knowledge_plugins/propagations/states.py +552 -0
- angr/knowledge_plugins/structured_code.py +63 -0
- angr/knowledge_plugins/types.py +95 -0
- angr/knowledge_plugins/variables/__init__.py +8 -0
- angr/knowledge_plugins/variables/variable_access.py +113 -0
- angr/knowledge_plugins/variables/variable_manager.py +1375 -0
- angr/knowledge_plugins/xrefs/__init__.py +12 -0
- angr/knowledge_plugins/xrefs/xref.py +150 -0
- angr/knowledge_plugins/xrefs/xref_manager.py +127 -0
- angr/knowledge_plugins/xrefs/xref_types.py +16 -0
- angr/misc/__init__.py +19 -0
- angr/misc/ansi.py +47 -0
- angr/misc/autoimport.py +90 -0
- angr/misc/bug_report.py +126 -0
- angr/misc/hookset.py +106 -0
- angr/misc/loggers.py +130 -0
- angr/misc/picklable_lock.py +46 -0
- angr/misc/plugins.py +289 -0
- angr/misc/telemetry.py +54 -0
- angr/misc/testing.py +24 -0
- angr/misc/ux.py +31 -0
- angr/procedures/__init__.py +12 -0
- angr/procedures/advapi32/__init__.py +0 -0
- angr/procedures/cgc/__init__.py +3 -0
- angr/procedures/cgc/_terminate.py +11 -0
- angr/procedures/cgc/allocate.py +75 -0
- angr/procedures/cgc/deallocate.py +67 -0
- angr/procedures/cgc/fdwait.py +65 -0
- angr/procedures/cgc/random.py +67 -0
- angr/procedures/cgc/receive.py +93 -0
- angr/procedures/cgc/transmit.py +65 -0
- angr/procedures/definitions/__init__.py +1043 -0
- angr/procedures/definitions/cgc.py +23 -0
- angr/procedures/definitions/common/glibc.json +3516 -0
- angr/procedures/definitions/gnulib.py +41 -0
- angr/procedures/definitions/libstdcpp.py +25 -0
- angr/procedures/definitions/linux_kernel.py +8382 -0
- angr/procedures/definitions/linux_loader.py +7 -0
- angr/procedures/definitions/macho_libsystem.py +18 -0
- angr/procedures/definitions/msvcr.py +25 -0
- angr/procedures/definitions/parse_glibc.py +77 -0
- angr/procedures/definitions/parse_syscalls_from_local_system.py +54 -0
- angr/procedures/definitions/parse_win32json.py +2540 -0
- angr/procedures/definitions/types_stl.py +22 -0
- angr/procedures/definitions/wdk/api-ms-win-dx-d3dkmt-l1-1-4.json +24 -0
- angr/procedures/definitions/wdk/api-ms-win-dx-d3dkmt-l1-1-6.json +18 -0
- angr/procedures/definitions/wdk/clfs.json +189 -0
- angr/procedures/definitions/wdk/fltmgr.json +813 -0
- angr/procedures/definitions/wdk/fwpkclnt.json +24 -0
- angr/procedures/definitions/wdk/fwpuclnt.json +453 -0
- angr/procedures/definitions/wdk/gdi32.json +528 -0
- angr/procedures/definitions/wdk/hal.json +96 -0
- angr/procedures/definitions/wdk/ksecdd.json +72 -0
- angr/procedures/definitions/wdk/ndis.json +336 -0
- angr/procedures/definitions/wdk/ntoskrnl.json +5158 -0
- angr/procedures/definitions/wdk/offreg.json +87 -0
- angr/procedures/definitions/wdk/pshed.json +33 -0
- angr/procedures/definitions/wdk/secur32.json +39 -0
- angr/procedures/definitions/wdk/vhfum.json +30 -0
- angr/procedures/definitions/win32/_types_win32.json +34480 -0
- angr/procedures/definitions/win32/aclui.json +24 -0
- angr/procedures/definitions/win32/activeds.json +81 -0
- angr/procedures/definitions/win32/advapi32.json +2505 -0
- angr/procedures/definitions/win32/advpack.json +165 -0
- angr/procedures/definitions/win32/amsi.json +36 -0
- angr/procedures/definitions/win32/api-ms-win-appmodel-runtime-l1-1-1.json +45 -0
- angr/procedures/definitions/win32/api-ms-win-appmodel-runtime-l1-1-3.json +30 -0
- angr/procedures/definitions/win32/api-ms-win-appmodel-runtime-l1-1-6.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-core-apiquery-l2-1-0.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-core-backgroundtask-l1-1-0.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-core-comm-l1-1-1.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-core-comm-l1-1-2.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-core-enclave-l1-1-1.json +24 -0
- angr/procedures/definitions/win32/api-ms-win-core-errorhandling-l1-1-3.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-core-featurestaging-l1-1-0.json +30 -0
- angr/procedures/definitions/win32/api-ms-win-core-featurestaging-l1-1-1.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-core-file-fromapp-l1-1-0.json +48 -0
- angr/procedures/definitions/win32/api-ms-win-core-handle-l1-1-0.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-core-ioring-l1-1-0.json +51 -0
- angr/procedures/definitions/win32/api-ms-win-core-marshal-l1-1-0.json +27 -0
- angr/procedures/definitions/win32/api-ms-win-core-memory-l1-1-3.json +27 -0
- angr/procedures/definitions/win32/api-ms-win-core-memory-l1-1-4.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-core-memory-l1-1-5.json +24 -0
- angr/procedures/definitions/win32/api-ms-win-core-memory-l1-1-6.json +27 -0
- angr/procedures/definitions/win32/api-ms-win-core-memory-l1-1-7.json +21 -0
- angr/procedures/definitions/win32/api-ms-win-core-memory-l1-1-8.json +24 -0
- angr/procedures/definitions/win32/api-ms-win-core-path-l1-1-0.json +81 -0
- angr/procedures/definitions/win32/api-ms-win-core-psm-appnotify-l1-1-0.json +21 -0
- angr/procedures/definitions/win32/api-ms-win-core-psm-appnotify-l1-1-1.json +21 -0
- angr/procedures/definitions/win32/api-ms-win-core-realtime-l1-1-1.json +24 -0
- angr/procedures/definitions/win32/api-ms-win-core-realtime-l1-1-2.json +24 -0
- angr/procedures/definitions/win32/api-ms-win-core-slapi-l1-1-0.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-core-state-helpers-l1-1-0.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-core-synch-l1-2-0.json +24 -0
- angr/procedures/definitions/win32/api-ms-win-core-sysinfo-l1-2-0.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-core-sysinfo-l1-2-3.json +21 -0
- angr/procedures/definitions/win32/api-ms-win-core-sysinfo-l1-2-4.json +21 -0
- angr/procedures/definitions/win32/api-ms-win-core-sysinfo-l1-2-6.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-core-util-l1-1-1.json +21 -0
- angr/procedures/definitions/win32/api-ms-win-core-wow64-l1-1-1.json +24 -0
- angr/procedures/definitions/win32/api-ms-win-devices-query-l1-1-0.json +42 -0
- angr/procedures/definitions/win32/api-ms-win-devices-query-l1-1-1.json +30 -0
- angr/procedures/definitions/win32/api-ms-win-dx-d3dkmt-l1-1-0.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-gaming-deviceinformation-l1-1-0.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-gaming-expandedresources-l1-1-0.json +24 -0
- angr/procedures/definitions/win32/api-ms-win-gaming-tcui-l1-1-0.json +36 -0
- angr/procedures/definitions/win32/api-ms-win-gaming-tcui-l1-1-1.json +21 -0
- angr/procedures/definitions/win32/api-ms-win-gaming-tcui-l1-1-2.json +36 -0
- angr/procedures/definitions/win32/api-ms-win-gaming-tcui-l1-1-3.json +21 -0
- angr/procedures/definitions/win32/api-ms-win-gaming-tcui-l1-1-4.json +39 -0
- angr/procedures/definitions/win32/api-ms-win-mm-misc-l1-1-1.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-net-isolation-l1-1-0.json +39 -0
- angr/procedures/definitions/win32/api-ms-win-security-base-l1-2-2.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-security-isolatedcontainer-l1-1-0.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-security-isolatedcontainer-l1-1-1.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-service-core-l1-1-3.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-service-core-l1-1-4.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-service-core-l1-1-5.json +21 -0
- angr/procedures/definitions/win32/api-ms-win-shcore-scaling-l1-1-0.json +24 -0
- angr/procedures/definitions/win32/api-ms-win-shcore-scaling-l1-1-1.json +33 -0
- angr/procedures/definitions/win32/api-ms-win-shcore-scaling-l1-1-2.json +18 -0
- angr/procedures/definitions/win32/api-ms-win-wsl-api-l1-1-0.json +36 -0
- angr/procedures/definitions/win32/apphelp.json +18 -0
- angr/procedures/definitions/win32/authz.json +114 -0
- angr/procedures/definitions/win32/avicap32.json +27 -0
- angr/procedures/definitions/win32/avifil32.json +195 -0
- angr/procedures/definitions/win32/avrt.json +57 -0
- angr/procedures/definitions/win32/bcp47mrm.json +21 -0
- angr/procedures/definitions/win32/bcrypt.json +174 -0
- angr/procedures/definitions/win32/bcryptprimitives.json +21 -0
- angr/procedures/definitions/win32/bluetoothapis.json +138 -0
- angr/procedures/definitions/win32/bthprops_cpl.json +33 -0
- angr/procedures/definitions/win32/cabinet.json +81 -0
- angr/procedures/definitions/win32/certadm.json +69 -0
- angr/procedures/definitions/win32/certpoleng.json +39 -0
- angr/procedures/definitions/win32/cfgmgr32.json +732 -0
- angr/procedures/definitions/win32/chakra.json +270 -0
- angr/procedures/definitions/win32/cldapi.json +123 -0
- angr/procedures/definitions/win32/clfsw32.json +192 -0
- angr/procedures/definitions/win32/clusapi.json +855 -0
- angr/procedures/definitions/win32/comctl32.json +360 -0
- angr/procedures/definitions/win32/comdlg32.json +78 -0
- angr/procedures/definitions/win32/compstui.json +27 -0
- angr/procedures/definitions/win32/computecore.json +177 -0
- angr/procedures/definitions/win32/computenetwork.json +144 -0
- angr/procedures/definitions/win32/computestorage.json +51 -0
- angr/procedures/definitions/win32/comsvcs.json +36 -0
- angr/procedures/definitions/win32/credui.json +72 -0
- angr/procedures/definitions/win32/crypt32.json +702 -0
- angr/procedures/definitions/win32/cryptnet.json +30 -0
- angr/procedures/definitions/win32/cryptui.json +45 -0
- angr/procedures/definitions/win32/cryptxml.json +72 -0
- angr/procedures/definitions/win32/cscapi.json +27 -0
- angr/procedures/definitions/win32/d2d1.json +54 -0
- angr/procedures/definitions/win32/d3d10.json +96 -0
- angr/procedures/definitions/win32/d3d10_1.json +21 -0
- angr/procedures/definitions/win32/d3d11.json +24 -0
- angr/procedures/definitions/win32/d3d12.json +39 -0
- angr/procedures/definitions/win32/d3d9.json +48 -0
- angr/procedures/definitions/win32/d3dcompiler_47.json +93 -0
- angr/procedures/definitions/win32/d3dcsx.json +42 -0
- angr/procedures/definitions/win32/davclnt.json +69 -0
- angr/procedures/definitions/win32/dbgeng.json +27 -0
- angr/procedures/definitions/win32/dbghelp.json +663 -0
- angr/procedures/definitions/win32/dbgmodel.json +18 -0
- angr/procedures/definitions/win32/dciman32.json +75 -0
- angr/procedures/definitions/win32/dcomp.json +51 -0
- angr/procedures/definitions/win32/ddraw.json +36 -0
- angr/procedures/definitions/win32/deviceaccess.json +18 -0
- angr/procedures/definitions/win32/dflayout.json +18 -0
- angr/procedures/definitions/win32/dhcpcsvc.json +60 -0
- angr/procedures/definitions/win32/dhcpcsvc6.json +33 -0
- angr/procedures/definitions/win32/dhcpsapi.json +603 -0
- angr/procedures/definitions/win32/diagnosticdataquery.json +120 -0
- angr/procedures/definitions/win32/dinput8.json +18 -0
- angr/procedures/definitions/win32/directml.json +21 -0
- angr/procedures/definitions/win32/dmprocessxmlfiltered.json +18 -0
- angr/procedures/definitions/win32/dnsapi.json +207 -0
- angr/procedures/definitions/win32/drt.json +63 -0
- angr/procedures/definitions/win32/drtprov.json +42 -0
- angr/procedures/definitions/win32/drttransport.json +21 -0
- angr/procedures/definitions/win32/dsound.json +45 -0
- angr/procedures/definitions/win32/dsparse.json +72 -0
- angr/procedures/definitions/win32/dsprop.json +36 -0
- angr/procedures/definitions/win32/dssec.json +27 -0
- angr/procedures/definitions/win32/dsuiext.json +27 -0
- angr/procedures/definitions/win32/dwmapi.json +108 -0
- angr/procedures/definitions/win32/dwrite.json +18 -0
- angr/procedures/definitions/win32/dxcompiler.json +21 -0
- angr/procedures/definitions/win32/dxcore.json +18 -0
- angr/procedures/definitions/win32/dxgi.json +33 -0
- angr/procedures/definitions/win32/dxva2.json +129 -0
- angr/procedures/definitions/win32/eappcfg.json +57 -0
- angr/procedures/definitions/win32/eappprxy.json +69 -0
- angr/procedures/definitions/win32/efswrt.json +21 -0
- angr/procedures/definitions/win32/elscore.json +30 -0
- angr/procedures/definitions/win32/esent.json +702 -0
- angr/procedures/definitions/win32/evr.json +36 -0
- angr/procedures/definitions/win32/faultrep.json +27 -0
- angr/procedures/definitions/win32/fhsvcctl.json +36 -0
- angr/procedures/definitions/win32/firewallapi.json +24 -0
- angr/procedures/definitions/win32/fltlib.json +99 -0
- angr/procedures/definitions/win32/fontsub.json +21 -0
- angr/procedures/definitions/win32/forceinline.json +24 -0
- angr/procedures/definitions/win32/fwpuclnt.json +591 -0
- angr/procedures/definitions/win32/fxsutility.json +21 -0
- angr/procedures/definitions/win32/gdi32.json +1308 -0
- angr/procedures/definitions/win32/gdiplus.json +1902 -0
- angr/procedures/definitions/win32/glu32.json +171 -0
- angr/procedures/definitions/win32/gpedit.json +33 -0
- angr/procedures/definitions/win32/hhctrl_ocx.json +21 -0
- angr/procedures/definitions/win32/hid.json +150 -0
- angr/procedures/definitions/win32/hlink.json +99 -0
- angr/procedures/definitions/win32/hrtfapo.json +18 -0
- angr/procedures/definitions/win32/httpapi.json +144 -0
- angr/procedures/definitions/win32/icm32.json +78 -0
- angr/procedures/definitions/win32/icmui.json +21 -0
- angr/procedures/definitions/win32/icu.json +3090 -0
- angr/procedures/definitions/win32/ieframe.json +102 -0
- angr/procedures/definitions/win32/imagehlp.json +84 -0
- angr/procedures/definitions/win32/imgutil.json +42 -0
- angr/procedures/definitions/win32/imm32.json +261 -0
- angr/procedures/definitions/win32/infocardapi.json +66 -0
- angr/procedures/definitions/win32/inkobjcore.json +96 -0
- angr/procedures/definitions/win32/iphlpapi.json +618 -0
- angr/procedures/definitions/win32/iscsidsc.json +252 -0
- angr/procedures/definitions/win32/isolatedwindowsenvironmentutils.json +21 -0
- angr/procedures/definitions/win32/kernel32.json +4566 -0
- angr/procedures/definitions/win32/kernelbase.json +33 -0
- angr/procedures/definitions/win32/keycredmgr.json +27 -0
- angr/procedures/definitions/win32/ksproxy_ax.json +33 -0
- angr/procedures/definitions/win32/ksuser.json +39 -0
- angr/procedures/definitions/win32/ktmw32.json +132 -0
- angr/procedures/definitions/win32/licenseprotection.json +21 -0
- angr/procedures/definitions/win32/loadperf.json +51 -0
- angr/procedures/definitions/win32/magnification.json +72 -0
- angr/procedures/definitions/win32/mapi32.json +213 -0
- angr/procedures/definitions/win32/mdmlocalmanagement.json +24 -0
- angr/procedures/definitions/win32/mdmregistration.json +60 -0
- angr/procedures/definitions/win32/mf.json +201 -0
- angr/procedures/definitions/win32/mfcore.json +21 -0
- angr/procedures/definitions/win32/mfplat.json +450 -0
- angr/procedures/definitions/win32/mfplay.json +18 -0
- angr/procedures/definitions/win32/mfreadwrite.json +30 -0
- angr/procedures/definitions/win32/mfsensorgroup.json +45 -0
- angr/procedures/definitions/win32/mfsrcsnk.json +21 -0
- angr/procedures/definitions/win32/mgmtapi.json +42 -0
- angr/procedures/definitions/win32/mi.json +18 -0
- angr/procedures/definitions/win32/mmdevapi.json +18 -0
- angr/procedures/definitions/win32/mpr.json +156 -0
- angr/procedures/definitions/win32/mprapi.json +351 -0
- angr/procedures/definitions/win32/mqrt.json +117 -0
- angr/procedures/definitions/win32/mrmsupport.json +96 -0
- angr/procedures/definitions/win32/msacm32.json +141 -0
- angr/procedures/definitions/win32/msajapi.json +1656 -0
- angr/procedures/definitions/win32/mscms.json +252 -0
- angr/procedures/definitions/win32/mscoree.json +96 -0
- angr/procedures/definitions/win32/msctfmonitor.json +24 -0
- angr/procedures/definitions/win32/msdelta.json +63 -0
- angr/procedures/definitions/win32/msdmo.json +48 -0
- angr/procedures/definitions/win32/msdrm.json +267 -0
- angr/procedures/definitions/win32/msi.json +807 -0
- angr/procedures/definitions/win32/msimg32.json +24 -0
- angr/procedures/definitions/win32/mspatcha.json +63 -0
- angr/procedures/definitions/win32/mspatchc.json +42 -0
- angr/procedures/definitions/win32/msports.json +36 -0
- angr/procedures/definitions/win32/msrating.json +72 -0
- angr/procedures/definitions/win32/mssign32.json +45 -0
- angr/procedures/definitions/win32/mstask.json +21 -0
- angr/procedures/definitions/win32/msvfw32.json +144 -0
- angr/procedures/definitions/win32/mswsock.json +63 -0
- angr/procedures/definitions/win32/mtxdm.json +18 -0
- angr/procedures/definitions/win32/ncrypt.json +132 -0
- angr/procedures/definitions/win32/ndfapi.json +63 -0
- angr/procedures/definitions/win32/netapi32.json +633 -0
- angr/procedures/definitions/win32/netsh.json +39 -0
- angr/procedures/definitions/win32/netshell.json +21 -0
- angr/procedures/definitions/win32/newdev.json +48 -0
- angr/procedures/definitions/win32/ninput.json +105 -0
- angr/procedures/definitions/win32/normaliz.json +21 -0
- angr/procedures/definitions/win32/ntdll.json +234 -0
- angr/procedures/definitions/win32/ntdllk.json +18 -0
- angr/procedures/definitions/win32/ntdsapi.json +258 -0
- angr/procedures/definitions/win32/ntlanman.json +45 -0
- angr/procedures/definitions/win32/odbc32.json +477 -0
- angr/procedures/definitions/win32/odbcbcp.json +96 -0
- angr/procedures/definitions/win32/ole32.json +966 -0
- angr/procedures/definitions/win32/oleacc.json +66 -0
- angr/procedures/definitions/win32/oleaut32.json +1230 -0
- angr/procedures/definitions/win32/oledlg.json +84 -0
- angr/procedures/definitions/win32/ondemandconnroutehelper.json +30 -0
- angr/procedures/definitions/win32/opengl32.json +1080 -0
- angr/procedures/definitions/win32/opmxbox.json +24 -0
- angr/procedures/definitions/win32/p2p.json +339 -0
- angr/procedures/definitions/win32/p2pgraph.json +126 -0
- angr/procedures/definitions/win32/pdh.json +309 -0
- angr/procedures/definitions/win32/peerdist.json +99 -0
- angr/procedures/definitions/win32/powrprof.json +267 -0
- angr/procedures/definitions/win32/prntvpt.json +48 -0
- angr/procedures/definitions/win32/projectedfslib.json +72 -0
- angr/procedures/definitions/win32/propsys.json +669 -0
- angr/procedures/definitions/win32/psapi.json +96 -0
- angr/procedures/definitions/win32/quartz.json +21 -0
- angr/procedures/definitions/win32/query.json +27 -0
- angr/procedures/definitions/win32/qwave.json +48 -0
- angr/procedures/definitions/win32/rasapi32.json +267 -0
- angr/procedures/definitions/win32/rasdlg.json +33 -0
- angr/procedures/definitions/win32/resutils.json +375 -0
- angr/procedures/definitions/win32/rpcns4.json +198 -0
- angr/procedures/definitions/win32/rpcproxy.json +27 -0
- angr/procedures/definitions/win32/rpcrt4.json +1356 -0
- angr/procedures/definitions/win32/rstrtmgr.json +48 -0
- angr/procedures/definitions/win32/rtm.json +243 -0
- angr/procedures/definitions/win32/rtutils.json +138 -0
- angr/procedures/definitions/win32/rtworkq.json +114 -0
- angr/procedures/definitions/win32/sas.json +18 -0
- angr/procedures/definitions/win32/scarddlg.json +30 -0
- angr/procedures/definitions/win32/schannel.json +42 -0
- angr/procedures/definitions/win32/sechost.json +21 -0
- angr/procedures/definitions/win32/secur32.json +282 -0
- angr/procedures/definitions/win32/sensapi.json +24 -0
- angr/procedures/definitions/win32/sensorsutilsv2.json +135 -0
- angr/procedures/definitions/win32/setupapi.json +1017 -0
- angr/procedures/definitions/win32/sfc.json +33 -0
- angr/procedures/definitions/win32/shdocvw.json +24 -0
- angr/procedures/definitions/win32/shell32.json +747 -0
- angr/procedures/definitions/win32/shlwapi.json +1095 -0
- angr/procedures/definitions/win32/slc.json +111 -0
- angr/procedures/definitions/win32/slcext.json +27 -0
- angr/procedures/definitions/win32/slwga.json +18 -0
- angr/procedures/definitions/win32/snmpapi.json +93 -0
- angr/procedures/definitions/win32/spoolss.json +93 -0
- angr/procedures/definitions/win32/srclient.json +18 -0
- angr/procedures/definitions/win32/srpapi.json +48 -0
- angr/procedures/definitions/win32/sspicli.json +36 -0
- angr/procedures/definitions/win32/sti.json +18 -0
- angr/procedures/definitions/win32/t2embed.json +57 -0
- angr/procedures/definitions/win32/tapi32.json +762 -0
- angr/procedures/definitions/win32/tbs.json +57 -0
- angr/procedures/definitions/win32/tdh.json +96 -0
- angr/procedures/definitions/win32/tokenbinding.json +45 -0
- angr/procedures/definitions/win32/traffic.json +75 -0
- angr/procedures/definitions/win32/txfw32.json +42 -0
- angr/procedures/definitions/win32/ualapi.json +27 -0
- angr/procedures/definitions/win32/uiautomationcore.json +309 -0
- angr/procedures/definitions/win32/urlmon.json +246 -0
- angr/procedures/definitions/win32/user32.json +2298 -0
- angr/procedures/definitions/win32/userenv.json +147 -0
- angr/procedures/definitions/win32/usp10.json +135 -0
- angr/procedures/definitions/win32/uxtheme.json +246 -0
- angr/procedures/definitions/win32/verifier.json +18 -0
- angr/procedures/definitions/win32/version.json +57 -0
- angr/procedures/definitions/win32/vertdll.json +36 -0
- angr/procedures/definitions/win32/virtdisk.json +102 -0
- angr/procedures/definitions/win32/vmdevicehost.json +54 -0
- angr/procedures/definitions/win32/vmsavedstatedumpprovider.json +144 -0
- angr/procedures/definitions/win32/vssapi.json +18 -0
- angr/procedures/definitions/win32/wcmapi.json +30 -0
- angr/procedures/definitions/win32/wdsbp.json +36 -0
- angr/procedures/definitions/win32/wdsclientapi.json +126 -0
- angr/procedures/definitions/win32/wdsmc.json +33 -0
- angr/procedures/definitions/win32/wdspxe.json +108 -0
- angr/procedures/definitions/win32/wdstptc.json +54 -0
- angr/procedures/definitions/win32/webauthn.json +54 -0
- angr/procedures/definitions/win32/webservices.json +594 -0
- angr/procedures/definitions/win32/websocket.json +54 -0
- angr/procedures/definitions/win32/wecapi.json +60 -0
- angr/procedures/definitions/win32/wer.json +78 -0
- angr/procedures/definitions/win32/wevtapi.json +120 -0
- angr/procedures/definitions/win32/winbio.json +177 -0
- angr/procedures/definitions/win32/windows_ai_machinelearning.json +18 -0
- angr/procedures/definitions/win32/windows_media_mediacontrol.json +39 -0
- angr/procedures/definitions/win32/windows_networking.json +18 -0
- angr/procedures/definitions/win32/windows_ui_xaml.json +21 -0
- angr/procedures/definitions/win32/windowscodecs.json +42 -0
- angr/procedures/definitions/win32/winfax.json +183 -0
- angr/procedures/definitions/win32/winhttp.json +183 -0
- angr/procedures/definitions/win32/winhvemulation.json +27 -0
- angr/procedures/definitions/win32/winhvplatform.json +213 -0
- angr/procedures/definitions/win32/wininet.json +903 -0
- angr/procedures/definitions/win32/winml.json +18 -0
- angr/procedures/definitions/win32/winmm.json +543 -0
- angr/procedures/definitions/win32/winscard.json +225 -0
- angr/procedures/definitions/win32/winspool_drv.json +531 -0
- angr/procedures/definitions/win32/wintrust.json +195 -0
- angr/procedures/definitions/win32/winusb.json +117 -0
- angr/procedures/definitions/win32/wlanapi.json +195 -0
- angr/procedures/definitions/win32/wlanui.json +18 -0
- angr/procedures/definitions/win32/wldap32.json +744 -0
- angr/procedures/definitions/win32/wldp.json +42 -0
- angr/procedures/definitions/win32/wmvcore.json +48 -0
- angr/procedures/definitions/win32/wnvapi.json +21 -0
- angr/procedures/definitions/win32/wofutil.json +48 -0
- angr/procedures/definitions/win32/ws2_32.json +495 -0
- angr/procedures/definitions/win32/wscapi.json +33 -0
- angr/procedures/definitions/win32/wsclient.json +24 -0
- angr/procedures/definitions/win32/wsdapi.json +111 -0
- angr/procedures/definitions/win32/wsmsvc.json +114 -0
- angr/procedures/definitions/win32/wsnmp32.json +162 -0
- angr/procedures/definitions/win32/wtsapi32.json +204 -0
- angr/procedures/definitions/win32/xaudio2_8.json +27 -0
- angr/procedures/definitions/win32/xinput1_4.json +36 -0
- angr/procedures/definitions/win32/xmllite.json +33 -0
- angr/procedures/definitions/win32/xolehlp.json +27 -0
- angr/procedures/definitions/win32/xpsprint.json +21 -0
- angr/procedures/glibc/__ctype_b_loc.py +21 -0
- angr/procedures/glibc/__ctype_tolower_loc.py +21 -0
- angr/procedures/glibc/__ctype_toupper_loc.py +21 -0
- angr/procedures/glibc/__errno_location.py +7 -0
- angr/procedures/glibc/__init__.py +3 -0
- angr/procedures/glibc/__libc_init.py +37 -0
- angr/procedures/glibc/__libc_start_main.py +301 -0
- angr/procedures/glibc/dynamic_loading.py +20 -0
- angr/procedures/glibc/scanf.py +19 -0
- angr/procedures/glibc/sscanf.py +10 -0
- angr/procedures/gnulib/__init__.py +3 -0
- angr/procedures/gnulib/xalloc_die.py +14 -0
- angr/procedures/gnulib/xstrtol_fatal.py +14 -0
- angr/procedures/java/__init__.py +42 -0
- angr/procedures/java/unconstrained.py +65 -0
- angr/procedures/java_io/__init__.py +0 -0
- angr/procedures/java_io/read.py +12 -0
- angr/procedures/java_io/write.py +17 -0
- angr/procedures/java_jni/__init__.py +482 -0
- angr/procedures/java_jni/array_operations.py +312 -0
- angr/procedures/java_jni/class_and_interface_operations.py +31 -0
- angr/procedures/java_jni/field_access.py +173 -0
- angr/procedures/java_jni/global_and_local_refs.py +57 -0
- angr/procedures/java_jni/method_calls.py +365 -0
- angr/procedures/java_jni/not_implemented.py +26 -0
- angr/procedures/java_jni/object_operations.py +94 -0
- angr/procedures/java_jni/string_operations.py +87 -0
- angr/procedures/java_jni/version_information.py +12 -0
- angr/procedures/java_lang/__init__.py +0 -0
- angr/procedures/java_lang/character.py +30 -0
- angr/procedures/java_lang/double.py +24 -0
- angr/procedures/java_lang/exit.py +13 -0
- angr/procedures/java_lang/getsimplename.py +18 -0
- angr/procedures/java_lang/integer.py +43 -0
- angr/procedures/java_lang/load_library.py +9 -0
- angr/procedures/java_lang/math.py +15 -0
- angr/procedures/java_lang/string.py +78 -0
- angr/procedures/java_lang/stringbuilder.py +44 -0
- angr/procedures/java_lang/system.py +18 -0
- angr/procedures/java_util/__init__.py +0 -0
- angr/procedures/java_util/collection.py +35 -0
- angr/procedures/java_util/iterator.py +46 -0
- angr/procedures/java_util/list.py +99 -0
- angr/procedures/java_util/map.py +131 -0
- angr/procedures/java_util/random.py +14 -0
- angr/procedures/java_util/scanner_nextline.py +23 -0
- angr/procedures/libc/__init__.py +3 -0
- angr/procedures/libc/abort.py +9 -0
- angr/procedures/libc/access.py +13 -0
- angr/procedures/libc/atoi.py +14 -0
- angr/procedures/libc/atol.py +13 -0
- angr/procedures/libc/calloc.py +8 -0
- angr/procedures/libc/closelog.py +10 -0
- angr/procedures/libc/err.py +14 -0
- angr/procedures/libc/error.py +54 -0
- angr/procedures/libc/exit.py +11 -0
- angr/procedures/libc/fclose.py +19 -0
- angr/procedures/libc/feof.py +21 -0
- angr/procedures/libc/fflush.py +16 -0
- angr/procedures/libc/fgetc.py +27 -0
- angr/procedures/libc/fgets.py +69 -0
- angr/procedures/libc/fopen.py +63 -0
- angr/procedures/libc/fprintf.py +25 -0
- angr/procedures/libc/fputc.py +23 -0
- angr/procedures/libc/fputs.py +24 -0
- angr/procedures/libc/fread.py +24 -0
- angr/procedures/libc/free.py +9 -0
- angr/procedures/libc/fscanf.py +20 -0
- angr/procedures/libc/fseek.py +34 -0
- angr/procedures/libc/ftell.py +22 -0
- angr/procedures/libc/fwrite.py +19 -0
- angr/procedures/libc/getchar.py +13 -0
- angr/procedures/libc/getdelim.py +99 -0
- angr/procedures/libc/getegid.py +8 -0
- angr/procedures/libc/geteuid.py +8 -0
- angr/procedures/libc/getgid.py +8 -0
- angr/procedures/libc/gets.py +68 -0
- angr/procedures/libc/getuid.py +8 -0
- angr/procedures/libc/malloc.py +12 -0
- angr/procedures/libc/memcmp.py +69 -0
- angr/procedures/libc/memcpy.py +45 -0
- angr/procedures/libc/memset.py +72 -0
- angr/procedures/libc/openlog.py +10 -0
- angr/procedures/libc/perror.py +13 -0
- angr/procedures/libc/printf.py +34 -0
- angr/procedures/libc/putchar.py +13 -0
- angr/procedures/libc/puts.py +19 -0
- angr/procedures/libc/rand.py +8 -0
- angr/procedures/libc/realloc.py +8 -0
- angr/procedures/libc/rewind.py +12 -0
- angr/procedures/libc/scanf.py +20 -0
- angr/procedures/libc/setbuf.py +9 -0
- angr/procedures/libc/setvbuf.py +7 -0
- angr/procedures/libc/snprintf.py +36 -0
- angr/procedures/libc/sprintf.py +25 -0
- angr/procedures/libc/srand.py +7 -0
- angr/procedures/libc/sscanf.py +13 -0
- angr/procedures/libc/stpcpy.py +18 -0
- angr/procedures/libc/strcat.py +14 -0
- angr/procedures/libc/strchr.py +48 -0
- angr/procedures/libc/strcmp.py +31 -0
- angr/procedures/libc/strcpy.py +13 -0
- angr/procedures/libc/strlen.py +114 -0
- angr/procedures/libc/strncat.py +19 -0
- angr/procedures/libc/strncmp.py +183 -0
- angr/procedures/libc/strncpy.py +22 -0
- angr/procedures/libc/strnlen.py +13 -0
- angr/procedures/libc/strstr.py +101 -0
- angr/procedures/libc/strtol.py +261 -0
- angr/procedures/libc/strtoul.py +9 -0
- angr/procedures/libc/system.py +13 -0
- angr/procedures/libc/time.py +9 -0
- angr/procedures/libc/tmpnam.py +20 -0
- angr/procedures/libc/tolower.py +10 -0
- angr/procedures/libc/toupper.py +10 -0
- angr/procedures/libc/ungetc.py +20 -0
- angr/procedures/libc/vsnprintf.py +17 -0
- angr/procedures/libc/wchar.py +16 -0
- angr/procedures/libstdcpp/__init__.py +0 -0
- angr/procedures/libstdcpp/_unwind_resume.py +11 -0
- angr/procedures/libstdcpp/std____throw_bad_alloc.py +13 -0
- angr/procedures/libstdcpp/std____throw_bad_cast.py +13 -0
- angr/procedures/libstdcpp/std____throw_length_error.py +13 -0
- angr/procedures/libstdcpp/std____throw_logic_error.py +13 -0
- angr/procedures/libstdcpp/std__terminate.py +13 -0
- angr/procedures/linux_kernel/__init__.py +3 -0
- angr/procedures/linux_kernel/access.py +18 -0
- angr/procedures/linux_kernel/arch_prctl.py +34 -0
- angr/procedures/linux_kernel/arm_user_helpers.py +59 -0
- angr/procedures/linux_kernel/brk.py +18 -0
- angr/procedures/linux_kernel/cwd.py +28 -0
- angr/procedures/linux_kernel/fstat.py +138 -0
- angr/procedures/linux_kernel/fstat64.py +170 -0
- angr/procedures/linux_kernel/futex.py +17 -0
- angr/procedures/linux_kernel/getegid.py +17 -0
- angr/procedures/linux_kernel/geteuid.py +17 -0
- angr/procedures/linux_kernel/getgid.py +17 -0
- angr/procedures/linux_kernel/getpid.py +14 -0
- angr/procedures/linux_kernel/getrlimit.py +24 -0
- angr/procedures/linux_kernel/gettid.py +9 -0
- angr/procedures/linux_kernel/getuid.py +17 -0
- angr/procedures/linux_kernel/iovec.py +47 -0
- angr/procedures/linux_kernel/lseek.py +42 -0
- angr/procedures/linux_kernel/mmap.py +16 -0
- angr/procedures/linux_kernel/mprotect.py +42 -0
- angr/procedures/linux_kernel/munmap.py +8 -0
- angr/procedures/linux_kernel/openat.py +26 -0
- angr/procedures/linux_kernel/set_tid_address.py +8 -0
- angr/procedures/linux_kernel/sigaction.py +19 -0
- angr/procedures/linux_kernel/sigprocmask.py +23 -0
- angr/procedures/linux_kernel/stat.py +23 -0
- angr/procedures/linux_kernel/sysinfo.py +59 -0
- angr/procedures/linux_kernel/tgkill.py +10 -0
- angr/procedures/linux_kernel/time.py +34 -0
- angr/procedures/linux_kernel/uid.py +30 -0
- angr/procedures/linux_kernel/uname.py +29 -0
- angr/procedures/linux_kernel/unlink.py +22 -0
- angr/procedures/linux_kernel/vsyscall.py +16 -0
- angr/procedures/linux_loader/__init__.py +3 -0
- angr/procedures/linux_loader/_dl_initial_error_catch_tsd.py +7 -0
- angr/procedures/linux_loader/_dl_rtld_lock.py +15 -0
- angr/procedures/linux_loader/sim_loader.py +54 -0
- angr/procedures/linux_loader/tls.py +40 -0
- angr/procedures/msvcr/__getmainargs.py +16 -0
- angr/procedures/msvcr/__init__.py +4 -0
- angr/procedures/msvcr/_initterm.py +38 -0
- angr/procedures/msvcr/fmode.py +31 -0
- angr/procedures/ntdll/__init__.py +0 -0
- angr/procedures/ntdll/exceptions.py +60 -0
- angr/procedures/posix/__init__.py +3 -0
- angr/procedures/posix/accept.py +29 -0
- angr/procedures/posix/bind.py +13 -0
- angr/procedures/posix/bzero.py +9 -0
- angr/procedures/posix/chroot.py +27 -0
- angr/procedures/posix/close.py +9 -0
- angr/procedures/posix/closedir.py +7 -0
- angr/procedures/posix/dup.py +56 -0
- angr/procedures/posix/fcntl.py +10 -0
- angr/procedures/posix/fdopen.py +76 -0
- angr/procedures/posix/fileno.py +18 -0
- angr/procedures/posix/fork.py +13 -0
- angr/procedures/posix/getenv.py +35 -0
- angr/procedures/posix/gethostbyname.py +43 -0
- angr/procedures/posix/getpass.py +19 -0
- angr/procedures/posix/getsockopt.py +11 -0
- angr/procedures/posix/htonl.py +11 -0
- angr/procedures/posix/htons.py +11 -0
- angr/procedures/posix/inet_ntoa.py +59 -0
- angr/procedures/posix/listen.py +13 -0
- angr/procedures/posix/mmap.py +144 -0
- angr/procedures/posix/open.py +18 -0
- angr/procedures/posix/opendir.py +10 -0
- angr/procedures/posix/poll.py +55 -0
- angr/procedures/posix/pread64.py +46 -0
- angr/procedures/posix/pthread.py +87 -0
- angr/procedures/posix/pwrite64.py +46 -0
- angr/procedures/posix/read.py +13 -0
- angr/procedures/posix/readdir.py +62 -0
- angr/procedures/posix/recv.py +13 -0
- angr/procedures/posix/recvfrom.py +13 -0
- angr/procedures/posix/select.py +48 -0
- angr/procedures/posix/send.py +23 -0
- angr/procedures/posix/setsockopt.py +9 -0
- angr/procedures/posix/sigaction.py +23 -0
- angr/procedures/posix/sim_time.py +48 -0
- angr/procedures/posix/sleep.py +8 -0
- angr/procedures/posix/socket.py +18 -0
- angr/procedures/posix/strcasecmp.py +26 -0
- angr/procedures/posix/strdup.py +18 -0
- angr/procedures/posix/strtok_r.py +64 -0
- angr/procedures/posix/syslog.py +15 -0
- angr/procedures/posix/tz.py +9 -0
- angr/procedures/posix/unlink.py +11 -0
- angr/procedures/posix/usleep.py +8 -0
- angr/procedures/posix/write.py +13 -0
- angr/procedures/procedure_dict.py +50 -0
- angr/procedures/stubs/CallReturn.py +13 -0
- angr/procedures/stubs/NoReturnUnconstrained.py +13 -0
- angr/procedures/stubs/Nop.py +7 -0
- angr/procedures/stubs/PathTerminator.py +9 -0
- angr/procedures/stubs/Redirect.py +18 -0
- angr/procedures/stubs/ReturnChar.py +11 -0
- angr/procedures/stubs/ReturnUnconstrained.py +24 -0
- angr/procedures/stubs/UnresolvableCallTarget.py +9 -0
- angr/procedures/stubs/UnresolvableJumpTarget.py +9 -0
- angr/procedures/stubs/UserHook.py +18 -0
- angr/procedures/stubs/__init__.py +3 -0
- angr/procedures/stubs/b64_decode.py +15 -0
- angr/procedures/stubs/caller.py +14 -0
- angr/procedures/stubs/crazy_scanf.py +20 -0
- angr/procedures/stubs/format_parser.py +669 -0
- angr/procedures/stubs/syscall_stub.py +24 -0
- angr/procedures/testing/__init__.py +3 -0
- angr/procedures/testing/manyargs.py +9 -0
- angr/procedures/testing/retreg.py +8 -0
- angr/procedures/tracer/__init__.py +4 -0
- angr/procedures/tracer/random.py +9 -0
- angr/procedures/tracer/receive.py +23 -0
- angr/procedures/tracer/transmit.py +26 -0
- angr/procedures/uclibc/__init__.py +3 -0
- angr/procedures/uclibc/__uClibc_main.py +10 -0
- angr/procedures/win32/EncodePointer.py +7 -0
- angr/procedures/win32/ExitProcess.py +9 -0
- angr/procedures/win32/GetCommandLine.py +12 -0
- angr/procedures/win32/GetCurrentProcessId.py +7 -0
- angr/procedures/win32/GetCurrentThreadId.py +7 -0
- angr/procedures/win32/GetLastInputInfo.py +40 -0
- angr/procedures/win32/GetModuleHandle.py +29 -0
- angr/procedures/win32/GetProcessAffinityMask.py +37 -0
- angr/procedures/win32/InterlockedExchange.py +15 -0
- angr/procedures/win32/IsProcessorFeaturePresent.py +7 -0
- angr/procedures/win32/VirtualAlloc.py +114 -0
- angr/procedures/win32/VirtualProtect.py +60 -0
- angr/procedures/win32/__init__.py +3 -0
- angr/procedures/win32/critical_section.py +12 -0
- angr/procedures/win32/dynamic_loading.py +104 -0
- angr/procedures/win32/file_handles.py +47 -0
- angr/procedures/win32/gethostbyname.py +12 -0
- angr/procedures/win32/heap.py +45 -0
- angr/procedures/win32/is_bad_ptr.py +26 -0
- angr/procedures/win32/local_storage.py +88 -0
- angr/procedures/win32/mutex.py +11 -0
- angr/procedures/win32/sim_time.py +135 -0
- angr/procedures/win32/system_paths.py +35 -0
- angr/procedures/win32_kernel/ExAllocatePool.py +13 -0
- angr/procedures/win32_kernel/ExFreePoolWithTag.py +8 -0
- angr/procedures/win32_kernel/__fastfail.py +15 -0
- angr/procedures/win32_kernel/__init__.py +3 -0
- angr/procedures/win_user32/__init__.py +0 -0
- angr/procedures/win_user32/chars.py +15 -0
- angr/procedures/win_user32/keyboard.py +14 -0
- angr/procedures/win_user32/messagebox.py +49 -0
- angr/project.py +860 -0
- angr/protos/__init__.py +19 -0
- angr/protos/cfg_pb2.py +42 -0
- angr/protos/function_pb2.py +38 -0
- angr/protos/primitives_pb2.py +59 -0
- angr/protos/variables_pb2.py +55 -0
- angr/protos/xrefs_pb2.py +36 -0
- angr/py.typed +1 -0
- angr/rustylib.cpython-311-darwin.so +0 -0
- angr/serializable.py +66 -0
- angr/sim_manager.py +971 -0
- angr/sim_options.py +436 -0
- angr/sim_procedure.py +626 -0
- angr/sim_state.py +926 -0
- angr/sim_state_options.py +403 -0
- angr/sim_type.py +4026 -0
- angr/sim_variable.py +470 -0
- angr/simos/__init__.py +47 -0
- angr/simos/cgc.py +153 -0
- angr/simos/javavm.py +458 -0
- angr/simos/linux.py +509 -0
- angr/simos/simos.py +444 -0
- angr/simos/snimmuc_nxp.py +149 -0
- angr/simos/userland.py +163 -0
- angr/simos/windows.py +615 -0
- angr/simos/xbox.py +32 -0
- angr/slicer.py +352 -0
- angr/state_hierarchy.py +262 -0
- angr/state_plugins/__init__.py +84 -0
- angr/state_plugins/callstack.py +478 -0
- angr/state_plugins/cgc.py +155 -0
- angr/state_plugins/debug_variables.py +192 -0
- angr/state_plugins/filesystem.py +463 -0
- angr/state_plugins/gdb.py +148 -0
- angr/state_plugins/globals.py +65 -0
- angr/state_plugins/heap/__init__.py +15 -0
- angr/state_plugins/heap/heap_base.py +128 -0
- angr/state_plugins/heap/heap_brk.py +136 -0
- angr/state_plugins/heap/heap_freelist.py +213 -0
- angr/state_plugins/heap/heap_libc.py +46 -0
- angr/state_plugins/heap/heap_ptmalloc.py +620 -0
- angr/state_plugins/heap/utils.py +22 -0
- angr/state_plugins/history.py +564 -0
- angr/state_plugins/inspect.py +375 -0
- angr/state_plugins/javavm_classloader.py +134 -0
- angr/state_plugins/jni_references.py +95 -0
- angr/state_plugins/libc.py +1263 -0
- angr/state_plugins/light_registers.py +168 -0
- angr/state_plugins/log.py +84 -0
- angr/state_plugins/loop_data.py +92 -0
- angr/state_plugins/plugin.py +176 -0
- angr/state_plugins/posix.py +703 -0
- angr/state_plugins/preconstrainer.py +196 -0
- angr/state_plugins/scratch.py +173 -0
- angr/state_plugins/sim_action.py +326 -0
- angr/state_plugins/sim_action_object.py +271 -0
- angr/state_plugins/sim_event.py +59 -0
- angr/state_plugins/solver.py +1128 -0
- angr/state_plugins/symbolizer.py +291 -0
- angr/state_plugins/trace_additions.py +738 -0
- angr/state_plugins/uc_manager.py +94 -0
- angr/state_plugins/unicorn_engine.py +1920 -0
- angr/state_plugins/view.py +340 -0
- angr/storage/__init__.py +15 -0
- angr/storage/file.py +1210 -0
- angr/storage/memory_mixins/__init__.py +317 -0
- angr/storage/memory_mixins/actions_mixin.py +72 -0
- angr/storage/memory_mixins/address_concretization_mixin.py +384 -0
- angr/storage/memory_mixins/bvv_conversion_mixin.py +73 -0
- angr/storage/memory_mixins/clouseau_mixin.py +137 -0
- angr/storage/memory_mixins/conditional_store_mixin.py +25 -0
- angr/storage/memory_mixins/convenient_mappings_mixin.py +256 -0
- angr/storage/memory_mixins/default_filler_mixin.py +144 -0
- angr/storage/memory_mixins/dirty_addrs_mixin.py +11 -0
- angr/storage/memory_mixins/hex_dumper_mixin.py +82 -0
- angr/storage/memory_mixins/javavm_memory_mixin.py +392 -0
- angr/storage/memory_mixins/keyvalue_memory_mixin.py +43 -0
- angr/storage/memory_mixins/label_merger_mixin.py +31 -0
- angr/storage/memory_mixins/memory_mixin.py +175 -0
- angr/storage/memory_mixins/multi_value_merger_mixin.py +79 -0
- angr/storage/memory_mixins/name_resolution_mixin.py +67 -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 +743 -0
- angr/storage/memory_mixins/paged_memory/paged_memory_multivalue_mixin.py +65 -0
- angr/storage/memory_mixins/paged_memory/pages/__init__.py +26 -0
- angr/storage/memory_mixins/paged_memory/pages/base.py +31 -0
- angr/storage/memory_mixins/paged_memory/pages/cooperation.py +341 -0
- angr/storage/memory_mixins/paged_memory/pages/history_tracking_mixin.py +92 -0
- angr/storage/memory_mixins/paged_memory/pages/ispo_mixin.py +55 -0
- angr/storage/memory_mixins/paged_memory/pages/list_page.py +338 -0
- angr/storage/memory_mixins/paged_memory/pages/multi_values.py +324 -0
- angr/storage/memory_mixins/paged_memory/pages/mv_list_page.py +419 -0
- angr/storage/memory_mixins/paged_memory/pages/permissions_mixin.py +36 -0
- angr/storage/memory_mixins/paged_memory/pages/refcount_mixin.py +52 -0
- angr/storage/memory_mixins/paged_memory/pages/ultra_page.py +529 -0
- angr/storage/memory_mixins/paged_memory/privileged_mixin.py +36 -0
- angr/storage/memory_mixins/paged_memory/stack_allocation_mixin.py +74 -0
- angr/storage/memory_mixins/regioned_memory/__init__.py +17 -0
- angr/storage/memory_mixins/regioned_memory/abstract_address_descriptor.py +36 -0
- angr/storage/memory_mixins/regioned_memory/abstract_merger_mixin.py +31 -0
- angr/storage/memory_mixins/regioned_memory/region_category_mixin.py +9 -0
- angr/storage/memory_mixins/regioned_memory/region_data.py +246 -0
- angr/storage/memory_mixins/regioned_memory/region_meta_mixin.py +241 -0
- angr/storage/memory_mixins/regioned_memory/regioned_address_concretization_mixin.py +119 -0
- angr/storage/memory_mixins/regioned_memory/regioned_memory_mixin.py +442 -0
- angr/storage/memory_mixins/regioned_memory/static_find_mixin.py +69 -0
- angr/storage/memory_mixins/simple_interface_mixin.py +71 -0
- angr/storage/memory_mixins/simplification_mixin.py +15 -0
- angr/storage/memory_mixins/size_resolution_mixin.py +143 -0
- angr/storage/memory_mixins/slotted_memory.py +140 -0
- angr/storage/memory_mixins/smart_find_mixin.py +161 -0
- angr/storage/memory_mixins/symbolic_merger_mixin.py +16 -0
- angr/storage/memory_mixins/top_merger_mixin.py +25 -0
- angr/storage/memory_mixins/underconstrained_mixin.py +67 -0
- angr/storage/memory_mixins/unwrapper_mixin.py +26 -0
- angr/storage/memory_object.py +195 -0
- angr/tablespecs.py +91 -0
- angr/unicornlib.dylib +0 -0
- angr/utils/__init__.py +46 -0
- angr/utils/ail.py +176 -0
- angr/utils/algo.py +34 -0
- angr/utils/balancer.py +776 -0
- angr/utils/bits.py +46 -0
- angr/utils/constants.py +9 -0
- angr/utils/cowdict.py +63 -0
- angr/utils/cpp.py +17 -0
- angr/utils/doms.py +150 -0
- angr/utils/dynamic_dictlist.py +89 -0
- angr/utils/endness.py +18 -0
- angr/utils/enums_conv.py +97 -0
- angr/utils/env.py +12 -0
- angr/utils/formatting.py +128 -0
- angr/utils/funcid.py +244 -0
- angr/utils/graph.py +981 -0
- angr/utils/lazy_import.py +13 -0
- angr/utils/library.py +236 -0
- angr/utils/loader.py +55 -0
- angr/utils/mp.py +66 -0
- angr/utils/orderedset.py +74 -0
- angr/utils/ssa/__init__.py +455 -0
- angr/utils/ssa/tmp_uses_collector.py +23 -0
- angr/utils/ssa/vvar_uses_collector.py +36 -0
- angr/utils/strings.py +20 -0
- angr/utils/tagged_interval_map.py +112 -0
- angr/utils/timing.py +74 -0
- angr/utils/types.py +193 -0
- angr/utils/vex.py +11 -0
- angr/vaults.py +367 -0
- angr-9.2.192.dist-info/METADATA +112 -0
- angr-9.2.192.dist-info/RECORD +1442 -0
- angr-9.2.192.dist-info/WHEEL +6 -0
- angr-9.2.192.dist-info/entry_points.txt +2 -0
- angr-9.2.192.dist-info/licenses/LICENSE +27 -0
- angr-9.2.192.dist-info/top_level.txt +1 -0
angr/sim_type.py
ADDED
|
@@ -0,0 +1,4026 @@
|
|
|
1
|
+
# pylint:disable=abstract-method,line-too-long,missing-class-docstring,wrong-import-position,too-many-positional-arguments
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import contextlib
|
|
5
|
+
import copy
|
|
6
|
+
import re
|
|
7
|
+
import logging
|
|
8
|
+
from typing import Literal, Any, cast, overload
|
|
9
|
+
from collections import OrderedDict, defaultdict, ChainMap
|
|
10
|
+
from collections.abc import Iterable
|
|
11
|
+
from collections.abc import MutableMapping
|
|
12
|
+
|
|
13
|
+
from archinfo import Endness, Arch
|
|
14
|
+
import claripy
|
|
15
|
+
import cxxheaderparser.simple
|
|
16
|
+
import cxxheaderparser.errors
|
|
17
|
+
import cxxheaderparser.types
|
|
18
|
+
import pycparser
|
|
19
|
+
from pycparser import c_ast
|
|
20
|
+
|
|
21
|
+
from angr.errors import AngrTypeError
|
|
22
|
+
from angr.sim_state import SimState
|
|
23
|
+
|
|
24
|
+
StoreType = int | claripy.ast.BV
|
|
25
|
+
|
|
26
|
+
l = logging.getLogger(name=__name__)
|
|
27
|
+
|
|
28
|
+
# pycparser hack to parse type expressions
|
|
29
|
+
errorlog = logging.getLogger(name=__name__ + ".yacc")
|
|
30
|
+
errorlog.setLevel(logging.ERROR)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class SimType:
|
|
34
|
+
"""
|
|
35
|
+
SimType exists to track type information for SimProcedures.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
_fields: tuple[str, ...] = ()
|
|
39
|
+
_args: tuple[str, ...] = ("label",)
|
|
40
|
+
_arch: Arch | None
|
|
41
|
+
_size: int | None = None
|
|
42
|
+
_can_refine_int: bool = False
|
|
43
|
+
_base_name: str
|
|
44
|
+
_ident: str = "simtype"
|
|
45
|
+
base: bool = True
|
|
46
|
+
|
|
47
|
+
def __init__(self, label=None):
|
|
48
|
+
"""
|
|
49
|
+
:param label: the type label.
|
|
50
|
+
"""
|
|
51
|
+
self.label = label
|
|
52
|
+
self._arch = None
|
|
53
|
+
|
|
54
|
+
@staticmethod
|
|
55
|
+
def _simtype_eq(self_type: SimType, other: SimType, avoid: dict[str, set[SimType]] | None) -> bool:
|
|
56
|
+
if self_type is other:
|
|
57
|
+
return True
|
|
58
|
+
if avoid is not None and self_type in avoid["self"] and other in avoid["other"]:
|
|
59
|
+
return True
|
|
60
|
+
return self_type.__eq__(other, avoid=avoid) # pylint:disable=unnecessary-dunder-call
|
|
61
|
+
|
|
62
|
+
def __eq__(self, other, avoid=None):
|
|
63
|
+
if type(self) is not type(other):
|
|
64
|
+
return False
|
|
65
|
+
|
|
66
|
+
for attr in self._fields:
|
|
67
|
+
if attr == "size" and self._arch is None and other._arch is None:
|
|
68
|
+
continue
|
|
69
|
+
attr_self = getattr(self, attr)
|
|
70
|
+
attr_other = getattr(other, attr)
|
|
71
|
+
if isinstance(attr_self, SimType):
|
|
72
|
+
if not SimType._simtype_eq(attr_self, attr_other, avoid):
|
|
73
|
+
return False
|
|
74
|
+
elif isinstance(attr_self, (list, tuple)) and isinstance(attr_other, (list, tuple)):
|
|
75
|
+
if len(attr_self) != len(attr_other):
|
|
76
|
+
return False
|
|
77
|
+
for a, b in zip(attr_self, attr_other):
|
|
78
|
+
if isinstance(a, SimType) and isinstance(b, SimType):
|
|
79
|
+
if SimType._simtype_eq(a, b, avoid) is False:
|
|
80
|
+
return False
|
|
81
|
+
else:
|
|
82
|
+
if a != b:
|
|
83
|
+
return False
|
|
84
|
+
else:
|
|
85
|
+
if attr_self != attr_other:
|
|
86
|
+
return False
|
|
87
|
+
|
|
88
|
+
return True
|
|
89
|
+
|
|
90
|
+
def __ne__(self, other):
|
|
91
|
+
# wow many efficient
|
|
92
|
+
return not self == other
|
|
93
|
+
|
|
94
|
+
def __hash__(self):
|
|
95
|
+
# very hashing algorithm many secure wow
|
|
96
|
+
out = hash(type(self))
|
|
97
|
+
for attr in self._fields:
|
|
98
|
+
out ^= hash(getattr(self, attr))
|
|
99
|
+
return out
|
|
100
|
+
|
|
101
|
+
def _refine_dir(self): # pylint: disable=no-self-use
|
|
102
|
+
return []
|
|
103
|
+
|
|
104
|
+
def _refine(self, view, k): # pylint: disable=unused-argument,no-self-use
|
|
105
|
+
raise KeyError(f"{k} is not a valid refinement")
|
|
106
|
+
|
|
107
|
+
@property
|
|
108
|
+
def size(self) -> int | None:
|
|
109
|
+
"""
|
|
110
|
+
The size of the type in bits, or None if no size is computable.
|
|
111
|
+
"""
|
|
112
|
+
return self._size
|
|
113
|
+
|
|
114
|
+
@property
|
|
115
|
+
def alignment(self):
|
|
116
|
+
"""
|
|
117
|
+
The alignment of the type in bytes.
|
|
118
|
+
"""
|
|
119
|
+
if self._arch is None:
|
|
120
|
+
raise ValueError("Can't tell my alignment without an arch!")
|
|
121
|
+
if self.size is None:
|
|
122
|
+
l.debug("The size of the type %r is unknown; assuming word size of the arch.", self)
|
|
123
|
+
return self._arch.bytes
|
|
124
|
+
return self.size // self._arch.byte_width
|
|
125
|
+
|
|
126
|
+
def with_arch(self, arch: Arch | None):
|
|
127
|
+
if arch is None:
|
|
128
|
+
return self
|
|
129
|
+
if self._arch is not None and self._arch == arch:
|
|
130
|
+
return self
|
|
131
|
+
return self._with_arch(arch)
|
|
132
|
+
|
|
133
|
+
def _with_arch(self, arch):
|
|
134
|
+
cp = copy.copy(self)
|
|
135
|
+
cp._arch = arch
|
|
136
|
+
return cp
|
|
137
|
+
|
|
138
|
+
def _init_str(self):
|
|
139
|
+
return f"NotImplemented({self.__class__.__name__})"
|
|
140
|
+
|
|
141
|
+
def c_repr(
|
|
142
|
+
self, name=None, full=0, memo=None, indent: int | None = 0, name_parens: bool = True
|
|
143
|
+
): # pylint: disable=unused-argument
|
|
144
|
+
if name is None:
|
|
145
|
+
return repr(self)
|
|
146
|
+
return f"{str(self) if self.label is None else self.label} {name}"
|
|
147
|
+
|
|
148
|
+
def copy(self):
|
|
149
|
+
raise NotImplementedError
|
|
150
|
+
|
|
151
|
+
def extract(self, state: SimState, addr, concrete: bool = False) -> Any:
|
|
152
|
+
raise NotImplementedError
|
|
153
|
+
|
|
154
|
+
def store(self, state: SimState, addr, value: Any):
|
|
155
|
+
raise NotImplementedError
|
|
156
|
+
|
|
157
|
+
def extract_claripy(self, bits) -> Any:
|
|
158
|
+
"""
|
|
159
|
+
Given a bitvector `bits` which was loaded from memory in a big-endian fashion, return a more appropriate or
|
|
160
|
+
structured representation of the data.
|
|
161
|
+
|
|
162
|
+
A type must have an arch associated in order to use this method.
|
|
163
|
+
"""
|
|
164
|
+
raise NotImplementedError(f"extract_claripy is not implemented for {self}")
|
|
165
|
+
|
|
166
|
+
def to_json(self, fields: Iterable[str] | None = None, memo: dict[str, SimTypeRef] | None = None) -> dict[str, Any]:
|
|
167
|
+
"""
|
|
168
|
+
Serialize the type class to a JSON-compatible dictionary.
|
|
169
|
+
"""
|
|
170
|
+
|
|
171
|
+
if memo is None:
|
|
172
|
+
memo = {}
|
|
173
|
+
|
|
174
|
+
nullable_fields = {"label"}
|
|
175
|
+
if fields is None:
|
|
176
|
+
fields = self._args
|
|
177
|
+
|
|
178
|
+
d: dict[str, Any] = {"_t": self._ident}
|
|
179
|
+
for field in fields:
|
|
180
|
+
value = getattr(self, field)
|
|
181
|
+
if isinstance(value, SimType):
|
|
182
|
+
d[field] = value.to_json(memo=memo)
|
|
183
|
+
elif isinstance(value, (list, tuple)):
|
|
184
|
+
d[field] = [v.to_json(memo=memo) if isinstance(v, SimType) else v for v in value]
|
|
185
|
+
elif isinstance(value, dict):
|
|
186
|
+
d[field] = {k: v.to_json(memo=memo) if isinstance(v, SimType) else v for k, v in value.items()}
|
|
187
|
+
else:
|
|
188
|
+
if field in nullable_fields and value is None:
|
|
189
|
+
continue
|
|
190
|
+
d[field] = value
|
|
191
|
+
return d
|
|
192
|
+
|
|
193
|
+
@staticmethod
|
|
194
|
+
def from_json(d: dict[str, Any]):
|
|
195
|
+
"""
|
|
196
|
+
Deserialize a type class from a JSON-compatible dictionary.
|
|
197
|
+
"""
|
|
198
|
+
|
|
199
|
+
assert "_t" in d
|
|
200
|
+
cls = IDENT_TO_CLS.get(d["_t"], None) # pylint: disable=redefined-outer-name
|
|
201
|
+
assert cls is not None, f"Unknown SimType class identifier {d['_t']}"
|
|
202
|
+
if getattr(cls, "from_json", SimType.from_json) is not SimType.from_json:
|
|
203
|
+
return cls.from_json(d)
|
|
204
|
+
|
|
205
|
+
kwargs = {}
|
|
206
|
+
for field in cls._args:
|
|
207
|
+
if field not in d:
|
|
208
|
+
continue
|
|
209
|
+
value = d[field]
|
|
210
|
+
if isinstance(value, dict):
|
|
211
|
+
if "_t" in value:
|
|
212
|
+
value = SimType.from_json(value)
|
|
213
|
+
else:
|
|
214
|
+
new_value = {}
|
|
215
|
+
for k, v in value.items():
|
|
216
|
+
if isinstance(v, dict) and "_t" in v:
|
|
217
|
+
new_value[k] = SimType.from_json(v)
|
|
218
|
+
else:
|
|
219
|
+
new_value[k] = v
|
|
220
|
+
value = new_value
|
|
221
|
+
elif isinstance(value, list):
|
|
222
|
+
new_value = []
|
|
223
|
+
for v in value:
|
|
224
|
+
if isinstance(v, dict) and "_t" in v:
|
|
225
|
+
new_value.append(SimType.from_json(v))
|
|
226
|
+
else:
|
|
227
|
+
new_value.append(v)
|
|
228
|
+
value = new_value
|
|
229
|
+
kwargs[field] = value
|
|
230
|
+
return cls(**kwargs)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
class TypeRef(SimType):
|
|
234
|
+
"""
|
|
235
|
+
A TypeRef is a reference to a type with a name. This allows for interactivity in type analysis, by storing a type
|
|
236
|
+
and having the option to update it later and have all references to it automatically update as well.
|
|
237
|
+
"""
|
|
238
|
+
|
|
239
|
+
_args = ("name", "ty")
|
|
240
|
+
_ident = "tref"
|
|
241
|
+
|
|
242
|
+
def __init__(self, name, ty):
|
|
243
|
+
super().__init__()
|
|
244
|
+
|
|
245
|
+
self.type = ty
|
|
246
|
+
self._name = name
|
|
247
|
+
|
|
248
|
+
@property
|
|
249
|
+
def type(self):
|
|
250
|
+
return self._type
|
|
251
|
+
|
|
252
|
+
@property
|
|
253
|
+
def ty(self):
|
|
254
|
+
return self.type
|
|
255
|
+
|
|
256
|
+
@type.setter
|
|
257
|
+
def type(self, val):
|
|
258
|
+
self._type = val
|
|
259
|
+
self._arch = val._arch
|
|
260
|
+
|
|
261
|
+
@property
|
|
262
|
+
def name(self):
|
|
263
|
+
"""
|
|
264
|
+
This is a read-only property because it is desirable to store typerefs in a mapping from name to type, and we
|
|
265
|
+
want the mapping to be in the loop for any updates.
|
|
266
|
+
"""
|
|
267
|
+
return self._name
|
|
268
|
+
|
|
269
|
+
def __eq__(self, other, avoid=None):
|
|
270
|
+
return type(other) is TypeRef and self.type == other.type
|
|
271
|
+
|
|
272
|
+
def __hash__(self):
|
|
273
|
+
return hash(self.type)
|
|
274
|
+
|
|
275
|
+
def __repr__(self):
|
|
276
|
+
return self.name
|
|
277
|
+
|
|
278
|
+
@property
|
|
279
|
+
def size(self):
|
|
280
|
+
return self.type.size
|
|
281
|
+
|
|
282
|
+
@property
|
|
283
|
+
def alignment(self):
|
|
284
|
+
return self.type.alignment
|
|
285
|
+
|
|
286
|
+
def with_arch(self, arch):
|
|
287
|
+
self.type = self.type.with_arch(arch)
|
|
288
|
+
self._arch = arch
|
|
289
|
+
return self
|
|
290
|
+
|
|
291
|
+
def c_repr(
|
|
292
|
+
self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
|
|
293
|
+
): # pylint: disable=unused-argument
|
|
294
|
+
if not full:
|
|
295
|
+
if name is not None:
|
|
296
|
+
return f"{self.name} {name}"
|
|
297
|
+
return self.name
|
|
298
|
+
return self.type.c_repr(name=name, full=full, memo=memo, indent=indent)
|
|
299
|
+
|
|
300
|
+
def copy(self):
|
|
301
|
+
raise NotImplementedError("copy() for TypeRef is ill-defined. What do you want this to do?")
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
class NamedTypeMixin:
|
|
305
|
+
"""
|
|
306
|
+
SimType classes with this mixin in the class hierarchy allows setting custom class names. A typical use case is
|
|
307
|
+
to represent same or similar type classes with different qualified names, such as "std::basic_string" vs
|
|
308
|
+
"std::__cxx11::basic_string". In such cases, .name stores the qualified name, and .unqualified_name() returns the
|
|
309
|
+
unqualified name of the type.
|
|
310
|
+
"""
|
|
311
|
+
|
|
312
|
+
def __init__(self, *args, name: str | None = None, **kwargs):
|
|
313
|
+
super().__init__(*args, **kwargs)
|
|
314
|
+
self._name = name
|
|
315
|
+
|
|
316
|
+
@property
|
|
317
|
+
def name(self) -> str:
|
|
318
|
+
if self._name is None:
|
|
319
|
+
self._name = repr(self)
|
|
320
|
+
return self._name
|
|
321
|
+
|
|
322
|
+
@name.setter
|
|
323
|
+
def name(self, v):
|
|
324
|
+
self._name = v
|
|
325
|
+
|
|
326
|
+
def unqualified_name(self, lang: str = "c++") -> str:
|
|
327
|
+
if lang == "c++":
|
|
328
|
+
splitter = "::"
|
|
329
|
+
n = self.name.split(splitter)
|
|
330
|
+
return n[-1]
|
|
331
|
+
raise NotImplementedError(f"Unsupported language {lang}.")
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
class SimTypeBottom(SimType):
|
|
335
|
+
"""
|
|
336
|
+
SimTypeBottom basically represents a type error.
|
|
337
|
+
"""
|
|
338
|
+
|
|
339
|
+
_base_name = "bot"
|
|
340
|
+
_ident = "bot"
|
|
341
|
+
|
|
342
|
+
def __repr__(self):
|
|
343
|
+
return self.label or "BOT"
|
|
344
|
+
|
|
345
|
+
def c_repr(
|
|
346
|
+
self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
|
|
347
|
+
): # pylint: disable=unused-argument
|
|
348
|
+
if name is None:
|
|
349
|
+
return "int" if self.label is None else self.label
|
|
350
|
+
return f'{"int" if self.label is None else self.label} {name}'
|
|
351
|
+
|
|
352
|
+
def _init_str(self):
|
|
353
|
+
return "{}({})".format(self.__class__.__name__, (f'label="{self.label}"') if self.label else "")
|
|
354
|
+
|
|
355
|
+
def copy(self):
|
|
356
|
+
return SimTypeBottom(self.label)
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
class SimTypeTop(SimType):
|
|
360
|
+
"""
|
|
361
|
+
SimTypeTop represents any type (mostly used with a pointer for void*).
|
|
362
|
+
"""
|
|
363
|
+
|
|
364
|
+
_fields = ("size",)
|
|
365
|
+
_args = ("size", "label")
|
|
366
|
+
_ident = "top"
|
|
367
|
+
|
|
368
|
+
def __init__(self, size: int | None = None, label=None):
|
|
369
|
+
SimType.__init__(self, label)
|
|
370
|
+
self._size = size
|
|
371
|
+
|
|
372
|
+
def __repr__(self):
|
|
373
|
+
return "TOP"
|
|
374
|
+
|
|
375
|
+
def copy(self):
|
|
376
|
+
return SimTypeTop(size=self.size, label=self.label)
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
class SimTypeReg(SimType):
|
|
380
|
+
"""
|
|
381
|
+
SimTypeReg is the base type for all types that are register-sized.
|
|
382
|
+
"""
|
|
383
|
+
|
|
384
|
+
_fields = ("size",)
|
|
385
|
+
_args = ("size", "label")
|
|
386
|
+
_ident = "reg"
|
|
387
|
+
|
|
388
|
+
def __init__(self, size: int | None, label=None):
|
|
389
|
+
"""
|
|
390
|
+
:param label: the type label.
|
|
391
|
+
:param size: the size of the type (e.g. 32bit, 8bit, etc.).
|
|
392
|
+
"""
|
|
393
|
+
SimType.__init__(self, label=label)
|
|
394
|
+
self._size = size
|
|
395
|
+
|
|
396
|
+
def __repr__(self):
|
|
397
|
+
return f"reg{self.size}_t"
|
|
398
|
+
|
|
399
|
+
def store(self, state, addr, value: StoreType):
|
|
400
|
+
if self.size is None:
|
|
401
|
+
raise TypeError("Need a size to store")
|
|
402
|
+
store_endness = state.arch.memory_endness
|
|
403
|
+
with contextlib.suppress(AttributeError):
|
|
404
|
+
value = value.ast # type: ignore
|
|
405
|
+
if isinstance(value, claripy.ast.Bits): # pylint:disable=isinstance-second-argument-not-valid-type
|
|
406
|
+
if value.size() != self.size: # type: ignore
|
|
407
|
+
raise ValueError("size of expression is wrong size for type")
|
|
408
|
+
elif isinstance(value, int):
|
|
409
|
+
value = claripy.BVV(value, self.size)
|
|
410
|
+
elif isinstance(value, bytes):
|
|
411
|
+
store_endness = "Iend_BE"
|
|
412
|
+
else:
|
|
413
|
+
raise TypeError(f"unrecognized expression type for SimType {type(self).__name__}")
|
|
414
|
+
|
|
415
|
+
state.memory.store(addr, value, endness=store_endness)
|
|
416
|
+
|
|
417
|
+
def copy(self):
|
|
418
|
+
return self.__class__(self.size, label=self.label)
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
class SimTypeNum(SimType):
|
|
422
|
+
"""
|
|
423
|
+
SimTypeNum is a numeric type of arbitrary length
|
|
424
|
+
"""
|
|
425
|
+
|
|
426
|
+
_fields = (*SimType._fields, "signed", "size")
|
|
427
|
+
_args = ("size", "signed", "label")
|
|
428
|
+
_ident = "num"
|
|
429
|
+
|
|
430
|
+
def __init__(self, size: int, signed=True, label=None):
|
|
431
|
+
"""
|
|
432
|
+
:param size: The size of the integer, in bits
|
|
433
|
+
:param signed: Whether the integer is signed or not
|
|
434
|
+
:param label: A label for the type
|
|
435
|
+
"""
|
|
436
|
+
super().__init__(label)
|
|
437
|
+
self._size = size
|
|
438
|
+
self.signed = signed
|
|
439
|
+
|
|
440
|
+
@property
|
|
441
|
+
def size(self) -> int:
|
|
442
|
+
assert self._size is not None
|
|
443
|
+
return self._size
|
|
444
|
+
|
|
445
|
+
def __repr__(self):
|
|
446
|
+
return "{}int{}_t".format("" if self.signed else "u", self.size)
|
|
447
|
+
|
|
448
|
+
@overload
|
|
449
|
+
def extract(self, state, addr, concrete: Literal[False] = ...) -> claripy.ast.BV: ...
|
|
450
|
+
|
|
451
|
+
@overload
|
|
452
|
+
def extract(self, state, addr, concrete: Literal[True]) -> int: ...
|
|
453
|
+
|
|
454
|
+
def extract(self, state, addr, concrete=False):
|
|
455
|
+
out = state.memory.load(addr, self.size // state.arch.byte_width, endness=state.arch.memory_endness)
|
|
456
|
+
if not concrete:
|
|
457
|
+
return out
|
|
458
|
+
n = state.solver.eval(out)
|
|
459
|
+
if self.signed and n >= 1 << (self.size - 1):
|
|
460
|
+
n -= 1 << (self.size)
|
|
461
|
+
return n
|
|
462
|
+
|
|
463
|
+
def store(self, state, addr, value: StoreType):
|
|
464
|
+
store_endness = state.arch.memory_endness
|
|
465
|
+
|
|
466
|
+
if isinstance(value, claripy.ast.Bits): # pylint:disable=isinstance-second-argument-not-valid-type
|
|
467
|
+
if value.size() != self.size: # type: ignore
|
|
468
|
+
raise ValueError("size of expression is wrong size for type")
|
|
469
|
+
elif isinstance(value, int) and self.size is not None:
|
|
470
|
+
value = claripy.BVV(value, self.size)
|
|
471
|
+
elif isinstance(value, bytes):
|
|
472
|
+
store_endness = "Iend_BE"
|
|
473
|
+
else:
|
|
474
|
+
raise TypeError(f"unrecognized expression type for SimType {type(self).__name__}")
|
|
475
|
+
|
|
476
|
+
state.memory.store(addr, value, endness=store_endness)
|
|
477
|
+
|
|
478
|
+
def copy(self):
|
|
479
|
+
return SimTypeNum(self.size, signed=self.signed, label=self.label)
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
class SimTypeInt(SimTypeReg):
|
|
483
|
+
"""
|
|
484
|
+
SimTypeInt is a type that specifies a signed or unsigned C integer.
|
|
485
|
+
"""
|
|
486
|
+
|
|
487
|
+
_fields = (*tuple(x for x in SimTypeReg._fields if x != "size"), "signed")
|
|
488
|
+
_args = ("signed", "label")
|
|
489
|
+
_base_name = "int"
|
|
490
|
+
_ident = "int"
|
|
491
|
+
|
|
492
|
+
def __init__(self, signed=True, label=None):
|
|
493
|
+
"""
|
|
494
|
+
:param signed: True if signed, False if unsigned
|
|
495
|
+
:param label: The type label
|
|
496
|
+
"""
|
|
497
|
+
super().__init__(None, label=label)
|
|
498
|
+
self.signed = signed
|
|
499
|
+
|
|
500
|
+
def to_json(self, fields: Iterable[str] | None = None, memo: dict[str, SimTypeRef] | None = None) -> dict[str, Any]:
|
|
501
|
+
if memo is None:
|
|
502
|
+
memo = {}
|
|
503
|
+
d = super().to_json(fields=fields, memo=memo)
|
|
504
|
+
if "signed" in d and d["signed"] is True:
|
|
505
|
+
del d["signed"]
|
|
506
|
+
return d
|
|
507
|
+
|
|
508
|
+
def c_repr(
|
|
509
|
+
self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
|
|
510
|
+
): # pylint: disable=unused-argument
|
|
511
|
+
out = self._base_name
|
|
512
|
+
if not self.signed:
|
|
513
|
+
out = "unsigned " + out
|
|
514
|
+
if name is None:
|
|
515
|
+
return out
|
|
516
|
+
return f"{out} {name}"
|
|
517
|
+
|
|
518
|
+
def __repr__(self):
|
|
519
|
+
name = self._base_name
|
|
520
|
+
if not self.signed:
|
|
521
|
+
name = "unsigned " + name
|
|
522
|
+
|
|
523
|
+
try:
|
|
524
|
+
return f"{name} ({self.size} bits)"
|
|
525
|
+
except ValueError:
|
|
526
|
+
return name
|
|
527
|
+
|
|
528
|
+
@property
|
|
529
|
+
def size(self):
|
|
530
|
+
if self._arch is None:
|
|
531
|
+
raise ValueError("Can't tell my size without an arch!")
|
|
532
|
+
try:
|
|
533
|
+
return self._arch.sizeof[self._base_name]
|
|
534
|
+
except KeyError as e:
|
|
535
|
+
raise ValueError(f"Arch {self._arch.name} doesn't have its {self._base_name} type defined!") from e
|
|
536
|
+
|
|
537
|
+
@overload
|
|
538
|
+
def extract(self, state, addr, concrete: Literal[False] = ...) -> claripy.ast.BV: ...
|
|
539
|
+
|
|
540
|
+
@overload
|
|
541
|
+
def extract(self, state, addr, concrete: Literal[True]) -> int: ...
|
|
542
|
+
|
|
543
|
+
def extract(self, state, addr, concrete=False):
|
|
544
|
+
out = state.memory.load(addr, self.size // state.arch.byte_width, endness=state.arch.memory_endness)
|
|
545
|
+
if not concrete:
|
|
546
|
+
return out
|
|
547
|
+
n = state.solver.eval(out)
|
|
548
|
+
if self.signed and n >= 1 << (self.size - 1):
|
|
549
|
+
n -= 1 << self.size
|
|
550
|
+
return n
|
|
551
|
+
|
|
552
|
+
def _init_str(self):
|
|
553
|
+
return "{}(signed={}{})".format(
|
|
554
|
+
self.__class__.__name__,
|
|
555
|
+
self.signed,
|
|
556
|
+
(f', label="{self.label}"') if self.label is not None else "",
|
|
557
|
+
)
|
|
558
|
+
|
|
559
|
+
def _refine_dir(self):
|
|
560
|
+
return ["signed", "unsigned"]
|
|
561
|
+
|
|
562
|
+
def _refine(self, view, k):
|
|
563
|
+
if k == "signed":
|
|
564
|
+
ty = copy.copy(self)
|
|
565
|
+
ty.signed = True
|
|
566
|
+
elif k == "unsigned":
|
|
567
|
+
ty = copy.copy(self)
|
|
568
|
+
ty.signed = False
|
|
569
|
+
else:
|
|
570
|
+
raise KeyError(k)
|
|
571
|
+
return view._deeper(ty=ty)
|
|
572
|
+
|
|
573
|
+
def copy(self):
|
|
574
|
+
return self.__class__(signed=self.signed, label=self.label)
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
class SimTypeShort(SimTypeInt):
|
|
578
|
+
_base_name = "short"
|
|
579
|
+
_ident = "short"
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
class SimTypeLong(SimTypeInt):
|
|
583
|
+
_base_name = "long"
|
|
584
|
+
_ident = "long"
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
class SimTypeLongLong(SimTypeInt):
|
|
588
|
+
_base_name = "long long"
|
|
589
|
+
_ident = "llong"
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
class SimTypeFixedSizeInt(SimTypeInt):
|
|
593
|
+
"""
|
|
594
|
+
The base class for all fixed-size (i.e., the size stays the same on all platforms) integer types. Do not
|
|
595
|
+
instantiate this class directly.
|
|
596
|
+
"""
|
|
597
|
+
|
|
598
|
+
_args = ("signed", "label")
|
|
599
|
+
_base_name: str = "int"
|
|
600
|
+
_ident = "intfixedsize"
|
|
601
|
+
_fixed_size: int = 32
|
|
602
|
+
|
|
603
|
+
def c_repr(
|
|
604
|
+
self,
|
|
605
|
+
name=None,
|
|
606
|
+
full=0,
|
|
607
|
+
memo=None,
|
|
608
|
+
indent: int | None = 0,
|
|
609
|
+
name_parens: bool = True, # pylint:disable=unused-argument
|
|
610
|
+
):
|
|
611
|
+
out = self._base_name
|
|
612
|
+
if not self.signed:
|
|
613
|
+
out = "u" + out
|
|
614
|
+
if name is None:
|
|
615
|
+
return out
|
|
616
|
+
return f"{out} {name}"
|
|
617
|
+
|
|
618
|
+
def __repr__(self) -> str:
|
|
619
|
+
name = self._base_name
|
|
620
|
+
if not self.signed:
|
|
621
|
+
name = "u" + name
|
|
622
|
+
|
|
623
|
+
try:
|
|
624
|
+
return f"{name} ({self.size} bits)"
|
|
625
|
+
except ValueError:
|
|
626
|
+
return name
|
|
627
|
+
|
|
628
|
+
@property
|
|
629
|
+
def size(self) -> int:
|
|
630
|
+
return self._fixed_size
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
class SimTypeInt128(SimTypeFixedSizeInt):
|
|
634
|
+
_base_name = "int128_t"
|
|
635
|
+
_ident = "int128"
|
|
636
|
+
_fixed_size = 128
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
class SimTypeInt256(SimTypeFixedSizeInt):
|
|
640
|
+
_base_name = "int256_t"
|
|
641
|
+
_ident = "int256"
|
|
642
|
+
_fixed_size = 256
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
class SimTypeInt512(SimTypeFixedSizeInt):
|
|
646
|
+
_base_name = "int512_t"
|
|
647
|
+
_ident = "int512"
|
|
648
|
+
_fixed_size = 512
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
class SimTypeChar(SimTypeReg):
|
|
652
|
+
"""
|
|
653
|
+
SimTypeChar is a type that specifies a character;
|
|
654
|
+
this could be represented by a byte, but this is meant to be interpreted as a character.
|
|
655
|
+
"""
|
|
656
|
+
|
|
657
|
+
_base_name = "char"
|
|
658
|
+
_args = ("signed", "label")
|
|
659
|
+
_ident = "char"
|
|
660
|
+
|
|
661
|
+
def __init__(self, signed=True, label=None):
|
|
662
|
+
"""
|
|
663
|
+
:param label: the type label.
|
|
664
|
+
"""
|
|
665
|
+
# FIXME: Now the size of a char is state-dependent.
|
|
666
|
+
super().__init__(8, label=label)
|
|
667
|
+
self.signed = signed
|
|
668
|
+
|
|
669
|
+
def __repr__(self) -> str:
|
|
670
|
+
return "char"
|
|
671
|
+
|
|
672
|
+
def store(self, state, addr, value: StoreType):
|
|
673
|
+
# FIXME: This is a hack.
|
|
674
|
+
self._size = state.arch.byte_width
|
|
675
|
+
try:
|
|
676
|
+
super().store(state, addr, value)
|
|
677
|
+
except TypeError:
|
|
678
|
+
if isinstance(value, bytes) and len(value) == 1:
|
|
679
|
+
value = claripy.BVV(value[0], state.arch.byte_width)
|
|
680
|
+
super().store(state, addr, value)
|
|
681
|
+
else:
|
|
682
|
+
raise
|
|
683
|
+
|
|
684
|
+
@overload
|
|
685
|
+
def extract(self, state, addr, concrete: Literal[False] = ...) -> claripy.ast.BV: ...
|
|
686
|
+
|
|
687
|
+
@overload
|
|
688
|
+
def extract(self, state, addr, concrete: Literal[True]) -> bytes: ...
|
|
689
|
+
|
|
690
|
+
def extract(self, state, addr, concrete: bool = False) -> claripy.ast.BV | bytes:
|
|
691
|
+
# FIXME: This is a hack.
|
|
692
|
+
self._size = state.arch.byte_width
|
|
693
|
+
|
|
694
|
+
out = state.memory.load(addr, 1, endness=state.arch.memory_endness)
|
|
695
|
+
if concrete:
|
|
696
|
+
return bytes(cast(list[int], [state.solver.eval(out)]))
|
|
697
|
+
return out
|
|
698
|
+
|
|
699
|
+
def _init_str(self):
|
|
700
|
+
return "{}({})".format(
|
|
701
|
+
self.__class__.__name__,
|
|
702
|
+
(f'label="{self.label}"') if self.label is not None else "",
|
|
703
|
+
)
|
|
704
|
+
|
|
705
|
+
def copy(self):
|
|
706
|
+
return self.__class__(signed=self.signed, label=self.label)
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
class SimTypeWideChar(SimTypeReg):
|
|
710
|
+
"""
|
|
711
|
+
SimTypeWideChar is a type that specifies a wide character (a UTF-16 character).
|
|
712
|
+
"""
|
|
713
|
+
|
|
714
|
+
_args = ("signed", "label", "endness")
|
|
715
|
+
_base_name = "char"
|
|
716
|
+
_ident = "wchar"
|
|
717
|
+
|
|
718
|
+
def __init__(self, signed=True, label=None, endness: Endness = Endness.BE):
|
|
719
|
+
"""
|
|
720
|
+
:param label: the type label.
|
|
721
|
+
"""
|
|
722
|
+
SimTypeReg.__init__(self, 16, label=label)
|
|
723
|
+
self.signed = signed
|
|
724
|
+
self.endness = endness
|
|
725
|
+
|
|
726
|
+
def __repr__(self):
|
|
727
|
+
return "wchar"
|
|
728
|
+
|
|
729
|
+
def store(self, state, addr, value: StoreType):
|
|
730
|
+
try:
|
|
731
|
+
super().store(state, addr, value)
|
|
732
|
+
except TypeError:
|
|
733
|
+
if isinstance(value, bytes) and len(value) == 2:
|
|
734
|
+
inner = (
|
|
735
|
+
((value[0] << state.arch.byte_width) | value[1])
|
|
736
|
+
if self.endness == Endness.BE
|
|
737
|
+
else ((value[1] << state.arch.byte_width) | value[0])
|
|
738
|
+
)
|
|
739
|
+
value = claripy.BVV(inner, state.arch.byte_width * 2)
|
|
740
|
+
super().store(state, addr, value)
|
|
741
|
+
else:
|
|
742
|
+
raise
|
|
743
|
+
|
|
744
|
+
def extract(self, state, addr, concrete=False) -> Any:
|
|
745
|
+
out = state.memory.load(addr, 2)
|
|
746
|
+
if concrete:
|
|
747
|
+
data = state.solver.eval(out, cast_to=bytes)
|
|
748
|
+
fmt_str = "utf-16be" if self.endness == Endness.BE else "utf-16le"
|
|
749
|
+
try:
|
|
750
|
+
return data.decode(fmt_str)
|
|
751
|
+
except UnicodeDecodeError:
|
|
752
|
+
return data
|
|
753
|
+
return out
|
|
754
|
+
|
|
755
|
+
def _init_str(self):
|
|
756
|
+
return "{}({})".format(
|
|
757
|
+
self.__class__.__name__,
|
|
758
|
+
(f'label="{self.label}"') if self.label is not None else "",
|
|
759
|
+
)
|
|
760
|
+
|
|
761
|
+
def copy(self):
|
|
762
|
+
return self.__class__(signed=self.signed, label=self.label, endness=self.endness)
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
class SimTypeBool(SimTypeReg):
|
|
766
|
+
_args = ("signed", "label")
|
|
767
|
+
_base_name = "bool"
|
|
768
|
+
_ident = "bool"
|
|
769
|
+
|
|
770
|
+
def __init__(self, signed=True, label=None):
|
|
771
|
+
"""
|
|
772
|
+
:param label: the type label.
|
|
773
|
+
"""
|
|
774
|
+
# FIXME: Now the size of a char is state-dependent.
|
|
775
|
+
super().__init__(8, label=label)
|
|
776
|
+
self.signed = signed
|
|
777
|
+
|
|
778
|
+
def __repr__(self):
|
|
779
|
+
return "bool"
|
|
780
|
+
|
|
781
|
+
def store(self, state, addr, value: StoreType | bool):
|
|
782
|
+
if isinstance(value, bool):
|
|
783
|
+
value = int(value)
|
|
784
|
+
return super().store(state, addr, value)
|
|
785
|
+
|
|
786
|
+
@overload
|
|
787
|
+
def extract(self, state, addr, concrete: Literal[False] = ...) -> claripy.ast.Bool: ...
|
|
788
|
+
|
|
789
|
+
@overload
|
|
790
|
+
def extract(self, state, addr, concrete: Literal[True]) -> bool: ...
|
|
791
|
+
|
|
792
|
+
def extract(self, state, addr, concrete=False):
|
|
793
|
+
ver = super().extract(state, addr, concrete)
|
|
794
|
+
if concrete:
|
|
795
|
+
return ver != b"\0"
|
|
796
|
+
return ver != 0
|
|
797
|
+
|
|
798
|
+
def _init_str(self):
|
|
799
|
+
return f"{self.__class__.__name__}()"
|
|
800
|
+
|
|
801
|
+
def copy(self):
|
|
802
|
+
return self.__class__(signed=self.signed, label=self.label)
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
class SimTypeFd(SimTypeReg):
|
|
806
|
+
"""
|
|
807
|
+
SimTypeFd is a type that specifies a file descriptor.
|
|
808
|
+
"""
|
|
809
|
+
|
|
810
|
+
_fields = SimTypeReg._fields
|
|
811
|
+
_args = ("label",)
|
|
812
|
+
_ident = "fd"
|
|
813
|
+
|
|
814
|
+
def __init__(self, label=None):
|
|
815
|
+
"""
|
|
816
|
+
:param label: the type label
|
|
817
|
+
"""
|
|
818
|
+
# file descriptors are always 32 bits, right?
|
|
819
|
+
# TODO: That's so closed-minded!
|
|
820
|
+
super().__init__(32, label=label)
|
|
821
|
+
|
|
822
|
+
@property
|
|
823
|
+
def size(self):
|
|
824
|
+
return 32
|
|
825
|
+
|
|
826
|
+
def __repr__(self):
|
|
827
|
+
return "fd_t"
|
|
828
|
+
|
|
829
|
+
def copy(self):
|
|
830
|
+
return SimTypeFd(label=self.label)
|
|
831
|
+
|
|
832
|
+
def _init_str(self):
|
|
833
|
+
return "{}({})".format(
|
|
834
|
+
self.__class__.__name__,
|
|
835
|
+
(f'label="{self.label}"') if self.label is not None else "",
|
|
836
|
+
)
|
|
837
|
+
|
|
838
|
+
@overload
|
|
839
|
+
def extract(self, state, addr, concrete: Literal[False] = ...) -> claripy.ast.BV: ...
|
|
840
|
+
|
|
841
|
+
@overload
|
|
842
|
+
def extract(self, state, addr, concrete: Literal[True]) -> int: ...
|
|
843
|
+
|
|
844
|
+
def extract(self, state, addr, concrete=False):
|
|
845
|
+
# TODO: EDG says this looks dangerously closed-minded. Just in case...
|
|
846
|
+
assert self.size % state.arch.byte_width == 0
|
|
847
|
+
|
|
848
|
+
out = state.memory.load(addr, self.size // state.arch.byte_width, endness=state.arch.memory_endness)
|
|
849
|
+
if not concrete:
|
|
850
|
+
return out
|
|
851
|
+
return state.solver.eval(out)
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
class SimTypePointer(SimTypeReg):
|
|
855
|
+
"""
|
|
856
|
+
SimTypePointer is a type that specifies a pointer to some other type.
|
|
857
|
+
"""
|
|
858
|
+
|
|
859
|
+
_fields = (*tuple(x for x in SimTypeReg._fields if x != "size"), "pts_to")
|
|
860
|
+
_args = ("pts_to", "label", "offset")
|
|
861
|
+
_ident = "ptr"
|
|
862
|
+
|
|
863
|
+
def __init__(self, pts_to, label=None, offset=0):
|
|
864
|
+
"""
|
|
865
|
+
:param label: The type label.
|
|
866
|
+
:param pts_to: The type to which this pointer points.
|
|
867
|
+
"""
|
|
868
|
+
super().__init__(None, label=label)
|
|
869
|
+
self.pts_to = pts_to
|
|
870
|
+
self.signed = False
|
|
871
|
+
self.offset = offset
|
|
872
|
+
|
|
873
|
+
def to_json(self, fields: Iterable[str] | None = None, memo: dict[str, SimTypeRef] | None = None) -> dict[str, Any]:
|
|
874
|
+
if memo is None:
|
|
875
|
+
memo = {}
|
|
876
|
+
d = super().to_json(fields=fields, memo=memo)
|
|
877
|
+
if d["offset"] == 0:
|
|
878
|
+
d.pop("offset")
|
|
879
|
+
return d
|
|
880
|
+
|
|
881
|
+
def __repr__(self):
|
|
882
|
+
return f"{self.pts_to}*" if not self.label else self.label
|
|
883
|
+
|
|
884
|
+
def c_repr(
|
|
885
|
+
self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
|
|
886
|
+
): # pylint: disable=unused-argument
|
|
887
|
+
# if pts_to is SimTypeBottom, we return a void*
|
|
888
|
+
if self.label is not None and name is not None:
|
|
889
|
+
return super().c_repr(name=name, full=full, memo=memo, indent=indent, name_parens=name_parens)
|
|
890
|
+
if isinstance(self.pts_to, SimTypeBottom):
|
|
891
|
+
out = "void*"
|
|
892
|
+
if name is None:
|
|
893
|
+
return out
|
|
894
|
+
return f"{out} {name}"
|
|
895
|
+
# if it points to an array, we do not need to add a *
|
|
896
|
+
deref_chr = "*" if not isinstance(self.pts_to, SimTypeArray) else ""
|
|
897
|
+
name_with_deref = deref_chr if name is None else f"{deref_chr}{name}"
|
|
898
|
+
return self.pts_to.c_repr(name_with_deref, full, memo, indent)
|
|
899
|
+
|
|
900
|
+
def make(self, pts_to):
|
|
901
|
+
new = type(self)(pts_to)
|
|
902
|
+
new._arch = self._arch
|
|
903
|
+
return new
|
|
904
|
+
|
|
905
|
+
@property
|
|
906
|
+
def size(self):
|
|
907
|
+
if self._arch is None:
|
|
908
|
+
raise ValueError("Can't tell my size without an arch!")
|
|
909
|
+
return self._arch.bits
|
|
910
|
+
|
|
911
|
+
def _with_arch(self, arch):
|
|
912
|
+
out = SimTypePointer(self.pts_to.with_arch(arch), self.label)
|
|
913
|
+
out._arch = arch
|
|
914
|
+
return out
|
|
915
|
+
|
|
916
|
+
def _init_str(self):
|
|
917
|
+
label_str = f', label="{self.label}"' if self.label is not None else ""
|
|
918
|
+
return f"{self.__class__.__name__}({self.pts_to._init_str()}{label_str}, offset={self.offset})"
|
|
919
|
+
|
|
920
|
+
def copy(self):
|
|
921
|
+
return SimTypePointer(self.pts_to, label=self.label, offset=self.offset)
|
|
922
|
+
|
|
923
|
+
@overload
|
|
924
|
+
def extract(self, state, addr, concrete: Literal[False] = ...) -> claripy.ast.BV: ...
|
|
925
|
+
|
|
926
|
+
@overload
|
|
927
|
+
def extract(self, state, addr, concrete: Literal[True]) -> int: ...
|
|
928
|
+
|
|
929
|
+
def extract(self, state, addr, concrete=False):
|
|
930
|
+
# TODO: EDG says this looks dangerously closed-minded. Just in case...
|
|
931
|
+
assert self.size % state.arch.byte_width == 0
|
|
932
|
+
|
|
933
|
+
out = state.memory.load(addr, self.size // state.arch.byte_width, endness=state.arch.memory_endness)
|
|
934
|
+
if not concrete:
|
|
935
|
+
return out
|
|
936
|
+
return state.solver.eval(out)
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
class SimTypeReference(SimTypeReg):
|
|
940
|
+
"""
|
|
941
|
+
SimTypeReference is a type that specifies a reference to some other type.
|
|
942
|
+
"""
|
|
943
|
+
|
|
944
|
+
_args = ("refs", "label")
|
|
945
|
+
_ident = "ref"
|
|
946
|
+
|
|
947
|
+
def __init__(self, refs, label=None):
|
|
948
|
+
super().__init__(None, label=label)
|
|
949
|
+
self.refs: SimType = refs
|
|
950
|
+
|
|
951
|
+
def __repr__(self):
|
|
952
|
+
return f"{self.refs}&"
|
|
953
|
+
|
|
954
|
+
def c_repr(
|
|
955
|
+
self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
|
|
956
|
+
): # pylint: disable=unused-argument
|
|
957
|
+
name = "&" if name is None else f"&{name}"
|
|
958
|
+
return self.refs.c_repr(name, full, memo, indent)
|
|
959
|
+
|
|
960
|
+
def make(self, refs):
|
|
961
|
+
new = type(self)(refs)
|
|
962
|
+
new._arch = self._arch
|
|
963
|
+
return new
|
|
964
|
+
|
|
965
|
+
@property
|
|
966
|
+
def size(self):
|
|
967
|
+
if self._arch is None:
|
|
968
|
+
raise ValueError("Can't tell my size without an arch!")
|
|
969
|
+
return self._arch.bits
|
|
970
|
+
|
|
971
|
+
def _with_arch(self, arch):
|
|
972
|
+
out = SimTypeReference(self.refs.with_arch(arch), label=self.label)
|
|
973
|
+
out._arch = arch
|
|
974
|
+
return out
|
|
975
|
+
|
|
976
|
+
def _init_str(self):
|
|
977
|
+
return "{}({}{})".format(
|
|
978
|
+
self.__class__.__name__,
|
|
979
|
+
self.refs._init_str(),
|
|
980
|
+
(f', label="{self.label}"') if self.label is not None else "",
|
|
981
|
+
)
|
|
982
|
+
|
|
983
|
+
def copy(self):
|
|
984
|
+
return SimTypeReference(self.refs, label=self.label)
|
|
985
|
+
|
|
986
|
+
@overload
|
|
987
|
+
def extract(self, state, addr, concrete: Literal[False] = ...) -> claripy.ast.BV: ...
|
|
988
|
+
|
|
989
|
+
@overload
|
|
990
|
+
def extract(self, state, addr, concrete: Literal[True]) -> int: ...
|
|
991
|
+
|
|
992
|
+
def extract(self, state, addr, concrete=False):
|
|
993
|
+
# TODO: EDG says this looks dangerously closed-minded. Just in case...
|
|
994
|
+
assert self.size % state.arch.byte_width == 0
|
|
995
|
+
|
|
996
|
+
out = state.memory.load(addr, self.size // state.arch.byte_width, endness=state.arch.memory_endness)
|
|
997
|
+
if not concrete:
|
|
998
|
+
return out
|
|
999
|
+
return state.solver.eval(out)
|
|
1000
|
+
|
|
1001
|
+
|
|
1002
|
+
class SimTypeArray(SimType):
|
|
1003
|
+
"""
|
|
1004
|
+
SimTypeArray is a type that specifies a series of data laid out in sequence.
|
|
1005
|
+
"""
|
|
1006
|
+
|
|
1007
|
+
_fields = ("elem_type", "length")
|
|
1008
|
+
_args = ("elem_type", "length", "label")
|
|
1009
|
+
_ident = "array"
|
|
1010
|
+
|
|
1011
|
+
def __init__(self, elem_type, length=None, label=None):
|
|
1012
|
+
"""
|
|
1013
|
+
:param label: The type label.
|
|
1014
|
+
:param elem_type: The type of each element in the array.
|
|
1015
|
+
:param length: An expression of the length of the array, if known.
|
|
1016
|
+
"""
|
|
1017
|
+
super().__init__(label=label)
|
|
1018
|
+
self.elem_type: SimType = elem_type
|
|
1019
|
+
self.length: int | None = length
|
|
1020
|
+
|
|
1021
|
+
def __repr__(self):
|
|
1022
|
+
return "{}[{}]".format(self.elem_type, "" if self.length is None else self.length)
|
|
1023
|
+
|
|
1024
|
+
def c_repr(
|
|
1025
|
+
self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
|
|
1026
|
+
): # pylint: disable=unused-argument
|
|
1027
|
+
if name is None:
|
|
1028
|
+
return repr(self)
|
|
1029
|
+
|
|
1030
|
+
name = "{}[{}]".format(name, self.length if self.length is not None else "")
|
|
1031
|
+
return self.elem_type.c_repr(name, full, memo, indent)
|
|
1032
|
+
|
|
1033
|
+
@property
|
|
1034
|
+
def size(self):
|
|
1035
|
+
if self.length is None:
|
|
1036
|
+
return 0
|
|
1037
|
+
if self.elem_type.size is None:
|
|
1038
|
+
return None
|
|
1039
|
+
return self.elem_type.size * self.length
|
|
1040
|
+
|
|
1041
|
+
@property
|
|
1042
|
+
def alignment(self):
|
|
1043
|
+
return self.elem_type.alignment
|
|
1044
|
+
|
|
1045
|
+
def _with_arch(self, arch):
|
|
1046
|
+
out = SimTypeArray(self.elem_type.with_arch(arch), self.length, self.label)
|
|
1047
|
+
out._arch = arch
|
|
1048
|
+
return out
|
|
1049
|
+
|
|
1050
|
+
def copy(self):
|
|
1051
|
+
return SimTypeArray(self.elem_type, length=self.length, label=self.label)
|
|
1052
|
+
|
|
1053
|
+
_can_refine_int = True
|
|
1054
|
+
|
|
1055
|
+
def _refine(self, view, k):
|
|
1056
|
+
return view._deeper(
|
|
1057
|
+
addr=view._addr + k * (self.elem_type.size // view.state.arch.byte_width), ty=self.elem_type
|
|
1058
|
+
)
|
|
1059
|
+
|
|
1060
|
+
@overload
|
|
1061
|
+
def extract(self, state, addr, concrete: Literal[False] = ...) -> list[Any]: # associated types...
|
|
1062
|
+
...
|
|
1063
|
+
|
|
1064
|
+
@overload
|
|
1065
|
+
def extract(self, state, addr, concrete: Literal[True] = ...) -> list[Any]: ...
|
|
1066
|
+
|
|
1067
|
+
def extract(self, state, addr, concrete=False):
|
|
1068
|
+
if self.length is None:
|
|
1069
|
+
return []
|
|
1070
|
+
if self.elem_type.size is None:
|
|
1071
|
+
return None
|
|
1072
|
+
return [
|
|
1073
|
+
self.elem_type.extract(state, addr + i * (self.elem_type.size // state.arch.byte_width), concrete)
|
|
1074
|
+
for i in range(self.length)
|
|
1075
|
+
]
|
|
1076
|
+
|
|
1077
|
+
def store(self, state, addr, value: list[StoreType]):
|
|
1078
|
+
if self.elem_type.size is None:
|
|
1079
|
+
raise AngrTypeError("Cannot call store on an array of unsized types")
|
|
1080
|
+
for i, val in enumerate(value):
|
|
1081
|
+
self.elem_type.store(state, addr + i * (self.elem_type.size // state.arch.byte_width), val)
|
|
1082
|
+
|
|
1083
|
+
def _init_str(self):
|
|
1084
|
+
return "{}({}, {}{})".format(
|
|
1085
|
+
self.__class__.__name__,
|
|
1086
|
+
self.elem_type._init_str(),
|
|
1087
|
+
self.length,
|
|
1088
|
+
f", {self.label}" if self.label is not None else "",
|
|
1089
|
+
)
|
|
1090
|
+
|
|
1091
|
+
|
|
1092
|
+
SimTypeFixedSizeArray = SimTypeArray
|
|
1093
|
+
|
|
1094
|
+
|
|
1095
|
+
class SimTypeString(NamedTypeMixin, SimType):
|
|
1096
|
+
"""
|
|
1097
|
+
SimTypeString is a type that represents a C-style string,
|
|
1098
|
+
i.e. a NUL-terminated array of bytes.
|
|
1099
|
+
"""
|
|
1100
|
+
|
|
1101
|
+
_fields = (*SimTypeArray._fields, "length")
|
|
1102
|
+
_args = ("length", "label", "name")
|
|
1103
|
+
_ident = "str"
|
|
1104
|
+
|
|
1105
|
+
def __init__(self, length: int | None = None, label=None, name: str | None = None):
|
|
1106
|
+
"""
|
|
1107
|
+
:param label: The type label.
|
|
1108
|
+
:param length: An expression of the length of the string, if known.
|
|
1109
|
+
"""
|
|
1110
|
+
super().__init__(label=label, name=name)
|
|
1111
|
+
self.elem_type = SimTypeChar()
|
|
1112
|
+
self.length = length
|
|
1113
|
+
|
|
1114
|
+
def __repr__(self):
|
|
1115
|
+
return "string_t"
|
|
1116
|
+
|
|
1117
|
+
def c_repr(
|
|
1118
|
+
self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
|
|
1119
|
+
): # pylint: disable=unused-argument
|
|
1120
|
+
if name is None:
|
|
1121
|
+
return repr(self)
|
|
1122
|
+
|
|
1123
|
+
name = "{}[{}]".format(name, self.length if self.length is not None else "")
|
|
1124
|
+
return self.elem_type.c_repr(name, full, memo, indent)
|
|
1125
|
+
|
|
1126
|
+
@overload
|
|
1127
|
+
def extract(self, state, addr, concrete: Literal[False] = ...) -> claripy.ast.BV: ...
|
|
1128
|
+
|
|
1129
|
+
@overload
|
|
1130
|
+
def extract(self, state, addr, concrete: Literal[True]) -> bytes: ...
|
|
1131
|
+
|
|
1132
|
+
def extract(self, state: SimState, addr, concrete=False):
|
|
1133
|
+
if self.length is None:
|
|
1134
|
+
out = None
|
|
1135
|
+
last_byte = state.memory.load(addr, size=1)
|
|
1136
|
+
# if we try to extract a symbolic string, it's likely that we are going to be trapped in a very large loop.
|
|
1137
|
+
if state.solver.symbolic(last_byte):
|
|
1138
|
+
raise ValueError(f"Trying to extract a symbolic string at {state.solver.eval(addr):#x}")
|
|
1139
|
+
addr += 1
|
|
1140
|
+
while not (claripy.is_true(last_byte == 0) or state.solver.symbolic(last_byte)):
|
|
1141
|
+
out = last_byte if out is None else out.concat(last_byte)
|
|
1142
|
+
last_byte = state.memory.load(addr, size=1)
|
|
1143
|
+
addr += 1
|
|
1144
|
+
else:
|
|
1145
|
+
out = state.memory.load(addr, size=self.length)
|
|
1146
|
+
if not concrete:
|
|
1147
|
+
return out if out is not None else claripy.BVV(0, 0)
|
|
1148
|
+
return state.solver.eval(out, cast_to=bytes) if out is not None else b""
|
|
1149
|
+
|
|
1150
|
+
_can_refine_int = True
|
|
1151
|
+
|
|
1152
|
+
def _refine(self, view, k):
|
|
1153
|
+
return view._deeper(addr=view._addr + k, ty=SimTypeChar())
|
|
1154
|
+
|
|
1155
|
+
@property
|
|
1156
|
+
def size(self):
|
|
1157
|
+
if self.length is None:
|
|
1158
|
+
return 4096 # :/
|
|
1159
|
+
return (self.length + 1) * 8
|
|
1160
|
+
|
|
1161
|
+
@property
|
|
1162
|
+
def alignment(self):
|
|
1163
|
+
return 1
|
|
1164
|
+
|
|
1165
|
+
def _with_arch(self, arch):
|
|
1166
|
+
return self
|
|
1167
|
+
|
|
1168
|
+
def copy(self):
|
|
1169
|
+
return SimTypeString(length=self.length, label=self.label, name=self.name)
|
|
1170
|
+
|
|
1171
|
+
def _init_str(self):
|
|
1172
|
+
return "{}({}, {}{})".format(
|
|
1173
|
+
self.__class__.__name__,
|
|
1174
|
+
self.elem_type._init_str(),
|
|
1175
|
+
self.length,
|
|
1176
|
+
f", {self.label}" if self.label is not None else "",
|
|
1177
|
+
)
|
|
1178
|
+
|
|
1179
|
+
|
|
1180
|
+
class SimTypeWString(NamedTypeMixin, SimType):
|
|
1181
|
+
"""
|
|
1182
|
+
A wide-character null-terminated string, where each character is 2 bytes.
|
|
1183
|
+
"""
|
|
1184
|
+
|
|
1185
|
+
_fields = (*SimTypeArray._fields, "length")
|
|
1186
|
+
_args = ("length", "label", "name")
|
|
1187
|
+
_ident = "wstr"
|
|
1188
|
+
|
|
1189
|
+
def __init__(self, length: int | None = None, label=None, name: str | None = None):
|
|
1190
|
+
super().__init__(label=label, name=name)
|
|
1191
|
+
self.elem_type = SimTypeNum(16, False)
|
|
1192
|
+
self.length = length
|
|
1193
|
+
|
|
1194
|
+
def __repr__(self):
|
|
1195
|
+
return "wstring_t"
|
|
1196
|
+
|
|
1197
|
+
def c_repr(
|
|
1198
|
+
self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
|
|
1199
|
+
): # pylint: disable=unused-argument
|
|
1200
|
+
if name is None:
|
|
1201
|
+
return repr(self)
|
|
1202
|
+
|
|
1203
|
+
name = "{}[{}]".format(name, self.length if self.length is not None else "")
|
|
1204
|
+
return self.elem_type.c_repr(name, full, memo, indent)
|
|
1205
|
+
|
|
1206
|
+
def extract(self, state, addr, concrete=False):
|
|
1207
|
+
if self.length is None:
|
|
1208
|
+
out = None
|
|
1209
|
+
last_byte = state.memory.load(addr, 2)
|
|
1210
|
+
# if we try to extract a symbolic string, it's likely that we are going to be trapped in a very large loop.
|
|
1211
|
+
if state.solver.symbolic(last_byte):
|
|
1212
|
+
raise ValueError(f"Trying to extract a symbolic string at {state.solver.eval(addr):#x}")
|
|
1213
|
+
addr += 2
|
|
1214
|
+
while not (claripy.is_true(last_byte == 0) or state.solver.symbolic(last_byte)):
|
|
1215
|
+
out = last_byte if out is None else out.concat(last_byte)
|
|
1216
|
+
last_byte = state.memory.load(addr, 2)
|
|
1217
|
+
addr += 2
|
|
1218
|
+
else:
|
|
1219
|
+
out = state.memory.load(addr, self.length * 2)
|
|
1220
|
+
if out is None:
|
|
1221
|
+
out = claripy.BVV(0, 0)
|
|
1222
|
+
if not concrete:
|
|
1223
|
+
return out
|
|
1224
|
+
return "".join(
|
|
1225
|
+
chr(state.solver.eval(x.reversed if state.arch.memory_endness == "Iend_LE" else x)) for x in out.chop(16)
|
|
1226
|
+
)
|
|
1227
|
+
|
|
1228
|
+
def store(self, state, addr, value):
|
|
1229
|
+
raise NotImplementedError
|
|
1230
|
+
|
|
1231
|
+
_can_refine_int = True
|
|
1232
|
+
|
|
1233
|
+
def _refine(self, view, k):
|
|
1234
|
+
return view._deeper(addr=view._addr + k * 2, ty=SimTypeNum(16, False))
|
|
1235
|
+
|
|
1236
|
+
@property
|
|
1237
|
+
def size(self):
|
|
1238
|
+
if self.length is None:
|
|
1239
|
+
return 4096
|
|
1240
|
+
return (self.length * 2 + 2) * 8
|
|
1241
|
+
|
|
1242
|
+
@property
|
|
1243
|
+
def alignment(self):
|
|
1244
|
+
return 2
|
|
1245
|
+
|
|
1246
|
+
def _with_arch(self, arch):
|
|
1247
|
+
return self
|
|
1248
|
+
|
|
1249
|
+
def copy(self):
|
|
1250
|
+
return SimTypeWString(length=self.length, label=self.label, name=self.name)
|
|
1251
|
+
|
|
1252
|
+
def _init_str(self):
|
|
1253
|
+
return "{}({}, {}{})".format(
|
|
1254
|
+
self.__class__.__name__,
|
|
1255
|
+
self.elem_type._init_str(),
|
|
1256
|
+
self.length,
|
|
1257
|
+
f", {self.label}" if self.label is not None else "",
|
|
1258
|
+
)
|
|
1259
|
+
|
|
1260
|
+
|
|
1261
|
+
class SimTypeFunction(SimType):
|
|
1262
|
+
"""
|
|
1263
|
+
SimTypeFunction is a type that specifies an actual function (i.e. not a pointer) with certain types of arguments and
|
|
1264
|
+
a certain return value.
|
|
1265
|
+
"""
|
|
1266
|
+
|
|
1267
|
+
_fields = ("args", "returnty", "variadic")
|
|
1268
|
+
_args = ("args", "returnty", "label", "arg_names", "variadic")
|
|
1269
|
+
_ident = "func"
|
|
1270
|
+
base = False
|
|
1271
|
+
|
|
1272
|
+
def __init__(
|
|
1273
|
+
self,
|
|
1274
|
+
args: Iterable[SimType],
|
|
1275
|
+
returnty: SimType | None,
|
|
1276
|
+
label=None,
|
|
1277
|
+
arg_names: Iterable[str] | None = None,
|
|
1278
|
+
variadic=False,
|
|
1279
|
+
):
|
|
1280
|
+
"""
|
|
1281
|
+
:param label: The type label
|
|
1282
|
+
:param args: A tuple of types representing the arguments to the function
|
|
1283
|
+
:param returnty: The return type of the function, or none for void
|
|
1284
|
+
:param variadic: Whether the function accepts varargs
|
|
1285
|
+
"""
|
|
1286
|
+
super().__init__(label=label)
|
|
1287
|
+
self.args: tuple[SimType, ...] = tuple(args)
|
|
1288
|
+
self.returnty: SimType | None = returnty
|
|
1289
|
+
self.arg_names: tuple[str, ...] = tuple(arg_names) if arg_names else ()
|
|
1290
|
+
self.variadic = variadic
|
|
1291
|
+
|
|
1292
|
+
def to_json(self, fields: Iterable[str] | None = None, memo: dict[str, SimTypeRef] | None = None) -> dict[str, Any]:
|
|
1293
|
+
if memo is None:
|
|
1294
|
+
memo = {}
|
|
1295
|
+
d = super().to_json(fields=fields, memo=memo)
|
|
1296
|
+
if d["variadic"] is False:
|
|
1297
|
+
d.pop("variadic")
|
|
1298
|
+
return d
|
|
1299
|
+
|
|
1300
|
+
def __hash__(self):
|
|
1301
|
+
return hash(type(self)) ^ hash(tuple(self.args)) ^ hash(self.returnty)
|
|
1302
|
+
|
|
1303
|
+
def __repr__(self):
|
|
1304
|
+
argstrs = [str(a) for a in self.args]
|
|
1305
|
+
if self.variadic:
|
|
1306
|
+
argstrs.append("...")
|
|
1307
|
+
return "({}) -> {}".format(", ".join(argstrs), self.returnty)
|
|
1308
|
+
|
|
1309
|
+
def c_repr(self, name=None, full=0, memo=None, indent=0, name_parens: bool = True):
|
|
1310
|
+
formatted_args = [
|
|
1311
|
+
a.c_repr(n, full - 1, memo, indent)
|
|
1312
|
+
for a, n in zip(self.args, self.arg_names if self.arg_names and full else (None,) * len(self.args))
|
|
1313
|
+
]
|
|
1314
|
+
if self.variadic:
|
|
1315
|
+
formatted_args.append("...")
|
|
1316
|
+
name_str = f"({name or ''})" if name_parens else name or ""
|
|
1317
|
+
proto = f"{name_str}({', '.join(formatted_args)})"
|
|
1318
|
+
return f"void {proto}" if self.returnty is None else self.returnty.c_repr(proto, full, memo, indent)
|
|
1319
|
+
|
|
1320
|
+
@property
|
|
1321
|
+
def size(self):
|
|
1322
|
+
return 4096 # ???????????
|
|
1323
|
+
|
|
1324
|
+
def _with_arch(self, arch):
|
|
1325
|
+
out = SimTypeFunction(
|
|
1326
|
+
[a.with_arch(arch) for a in self.args],
|
|
1327
|
+
self.returnty.with_arch(arch) if self.returnty is not None else None,
|
|
1328
|
+
label=self.label,
|
|
1329
|
+
arg_names=self.arg_names,
|
|
1330
|
+
variadic=self.variadic,
|
|
1331
|
+
)
|
|
1332
|
+
out._arch = arch
|
|
1333
|
+
return out
|
|
1334
|
+
|
|
1335
|
+
def _arg_names_str(self, show_variadic=True):
|
|
1336
|
+
argnames = list(self.arg_names)
|
|
1337
|
+
if self.variadic and show_variadic:
|
|
1338
|
+
argnames.append("...")
|
|
1339
|
+
return ", ".join(f'"{arg_name}"' for arg_name in argnames)
|
|
1340
|
+
|
|
1341
|
+
def _init_str(self):
|
|
1342
|
+
return "{}([{}], {}{}{}{})".format(
|
|
1343
|
+
self.__class__.__name__,
|
|
1344
|
+
", ".join([arg._init_str() for arg in self.args]),
|
|
1345
|
+
self.returnty._init_str() if self.returnty else "void",
|
|
1346
|
+
(f', label="{self.label}"') if self.label else "",
|
|
1347
|
+
(f", arg_names=[{self._arg_names_str(show_variadic=False)}]") if self.arg_names else "",
|
|
1348
|
+
", variadic=True" if self.variadic else "",
|
|
1349
|
+
)
|
|
1350
|
+
|
|
1351
|
+
def copy(self):
|
|
1352
|
+
return SimTypeFunction(
|
|
1353
|
+
self.args, self.returnty, label=self.label, arg_names=self.arg_names, variadic=self.variadic
|
|
1354
|
+
)
|
|
1355
|
+
|
|
1356
|
+
|
|
1357
|
+
class SimTypeCppFunction(SimTypeFunction):
|
|
1358
|
+
"""
|
|
1359
|
+
SimTypeCppFunction is a type that specifies an actual C++-style function with information about arguments, return
|
|
1360
|
+
value, and more C++-specific properties.
|
|
1361
|
+
|
|
1362
|
+
:ivar ctor: Whether the function is a constructor or not.
|
|
1363
|
+
:ivar dtor: Whether the function is a destructor or not.
|
|
1364
|
+
"""
|
|
1365
|
+
|
|
1366
|
+
_args = ("args", "returnty", "label", "arg_names", "ctor", "dtor", "convention")
|
|
1367
|
+
_ident = "cppfunc"
|
|
1368
|
+
|
|
1369
|
+
def __init__(
|
|
1370
|
+
self,
|
|
1371
|
+
args,
|
|
1372
|
+
returnty,
|
|
1373
|
+
label=None,
|
|
1374
|
+
arg_names: Iterable[str] | None = None,
|
|
1375
|
+
ctor: bool = False,
|
|
1376
|
+
dtor: bool = False,
|
|
1377
|
+
convention: str | None = None,
|
|
1378
|
+
):
|
|
1379
|
+
super().__init__(args, returnty, label=label, arg_names=arg_names, variadic=False)
|
|
1380
|
+
self.ctor = ctor
|
|
1381
|
+
self.dtor = dtor
|
|
1382
|
+
self.convention = convention
|
|
1383
|
+
|
|
1384
|
+
def __repr__(self):
|
|
1385
|
+
argstrs = [str(a) for a in self.args]
|
|
1386
|
+
if self.variadic:
|
|
1387
|
+
argstrs.append("...")
|
|
1388
|
+
return str(self.label) + "({}) -> {}".format(", ".join(argstrs), self.returnty)
|
|
1389
|
+
|
|
1390
|
+
def _init_str(self):
|
|
1391
|
+
return "{}([{}], {}{}{}{})".format(
|
|
1392
|
+
self.__class__.__name__,
|
|
1393
|
+
", ".join([arg._init_str() for arg in self.args]),
|
|
1394
|
+
self.returnty,
|
|
1395
|
+
(f", label={self.label}") if self.label else "",
|
|
1396
|
+
(f", arg_names=[{self._arg_names_str(show_variadic=False)}]") if self.arg_names else "",
|
|
1397
|
+
", variadic=True" if self.variadic else "",
|
|
1398
|
+
)
|
|
1399
|
+
|
|
1400
|
+
def _with_arch(self, arch):
|
|
1401
|
+
out = SimTypeCppFunction(
|
|
1402
|
+
[a.with_arch(arch) for a in self.args],
|
|
1403
|
+
self.returnty.with_arch(arch) if self.returnty is not None else None,
|
|
1404
|
+
label=self.label,
|
|
1405
|
+
arg_names=self.arg_names,
|
|
1406
|
+
ctor=self.ctor,
|
|
1407
|
+
dtor=self.dtor,
|
|
1408
|
+
convention=self.convention,
|
|
1409
|
+
)
|
|
1410
|
+
out._arch = arch
|
|
1411
|
+
return out
|
|
1412
|
+
|
|
1413
|
+
def copy(self):
|
|
1414
|
+
return SimTypeCppFunction(
|
|
1415
|
+
self.args,
|
|
1416
|
+
self.returnty,
|
|
1417
|
+
label=self.label,
|
|
1418
|
+
arg_names=self.arg_names,
|
|
1419
|
+
ctor=self.ctor,
|
|
1420
|
+
dtor=self.dtor,
|
|
1421
|
+
convention=self.convention,
|
|
1422
|
+
)
|
|
1423
|
+
|
|
1424
|
+
|
|
1425
|
+
class SimTypeLength(SimTypeLong):
|
|
1426
|
+
"""
|
|
1427
|
+
SimTypeLength is a type that specifies the length of some buffer in memory.
|
|
1428
|
+
|
|
1429
|
+
...I'm not really sure what the original design of this class was going for
|
|
1430
|
+
"""
|
|
1431
|
+
|
|
1432
|
+
_fields = (*(x for x in SimTypeReg._fields if x != "size"), "addr", "length") # ?
|
|
1433
|
+
_args = ("signed", "addr", "length", "label")
|
|
1434
|
+
_ident = "len"
|
|
1435
|
+
|
|
1436
|
+
def __init__(self, signed=False, addr=None, length=None, label=None):
|
|
1437
|
+
"""
|
|
1438
|
+
:param signed: Whether the value is signed or not
|
|
1439
|
+
:param label: The type label.
|
|
1440
|
+
:param addr: The memory address (expression).
|
|
1441
|
+
:param length: The length (expression).
|
|
1442
|
+
"""
|
|
1443
|
+
super().__init__(signed=signed, label=label)
|
|
1444
|
+
self.addr = addr
|
|
1445
|
+
self.length = length
|
|
1446
|
+
|
|
1447
|
+
def __repr__(self):
|
|
1448
|
+
return "size_t"
|
|
1449
|
+
|
|
1450
|
+
@property
|
|
1451
|
+
def size(self):
|
|
1452
|
+
if self._arch is None:
|
|
1453
|
+
raise ValueError("I can't tell my size without an arch!")
|
|
1454
|
+
return self._arch.bits
|
|
1455
|
+
|
|
1456
|
+
def _init_str(self):
|
|
1457
|
+
return f"{self.__class__.__name__}(size={self.size})"
|
|
1458
|
+
|
|
1459
|
+
def copy(self):
|
|
1460
|
+
return SimTypeLength(signed=self.signed, addr=self.addr, length=self.length, label=self.label)
|
|
1461
|
+
|
|
1462
|
+
|
|
1463
|
+
class SimTypeFloat(SimTypeReg):
|
|
1464
|
+
"""
|
|
1465
|
+
An IEEE754 single-precision floating point number
|
|
1466
|
+
"""
|
|
1467
|
+
|
|
1468
|
+
_base_name = "float"
|
|
1469
|
+
_args = ("label",)
|
|
1470
|
+
_ident = "float"
|
|
1471
|
+
|
|
1472
|
+
def __init__(self, size=32, label=None):
|
|
1473
|
+
super().__init__(size, label=label)
|
|
1474
|
+
|
|
1475
|
+
sort = claripy.FSORT_FLOAT
|
|
1476
|
+
signed = True
|
|
1477
|
+
|
|
1478
|
+
@property
|
|
1479
|
+
def size(self) -> int:
|
|
1480
|
+
return 32
|
|
1481
|
+
|
|
1482
|
+
def extract(self, state, addr, concrete=False):
|
|
1483
|
+
itype = claripy.fpToFP(
|
|
1484
|
+
state.memory.load(addr, self.size // state.arch.byte_width, endness=state.arch.memory_endness), self.sort
|
|
1485
|
+
)
|
|
1486
|
+
if concrete:
|
|
1487
|
+
return state.solver.eval(itype)
|
|
1488
|
+
return itype
|
|
1489
|
+
|
|
1490
|
+
def store(self, state, addr, value: StoreType | claripy.ast.FP):
|
|
1491
|
+
if isinstance(value, (int, float)):
|
|
1492
|
+
value = claripy.FPV(float(value), self.sort)
|
|
1493
|
+
return super().store(state, addr, value) # type: ignore # trust me bro
|
|
1494
|
+
|
|
1495
|
+
def __repr__(self) -> str:
|
|
1496
|
+
return "float"
|
|
1497
|
+
|
|
1498
|
+
def _init_str(self):
|
|
1499
|
+
return f"{self.__class__.__name__}(size={self.size})"
|
|
1500
|
+
|
|
1501
|
+
def copy(self):
|
|
1502
|
+
return SimTypeFloat(self.size)
|
|
1503
|
+
|
|
1504
|
+
|
|
1505
|
+
class SimTypeDouble(SimTypeFloat):
|
|
1506
|
+
"""
|
|
1507
|
+
An IEEE754 double-precision floating point number
|
|
1508
|
+
"""
|
|
1509
|
+
|
|
1510
|
+
_base_name = "double"
|
|
1511
|
+
_args = ("align_double", "label")
|
|
1512
|
+
_ident = "double"
|
|
1513
|
+
|
|
1514
|
+
def __init__(self, align_double=True, label=None):
|
|
1515
|
+
self.align_double = align_double
|
|
1516
|
+
super().__init__(64, label=label)
|
|
1517
|
+
|
|
1518
|
+
sort = claripy.FSORT_DOUBLE
|
|
1519
|
+
|
|
1520
|
+
@property
|
|
1521
|
+
def size(self) -> int:
|
|
1522
|
+
return 64
|
|
1523
|
+
|
|
1524
|
+
def __repr__(self):
|
|
1525
|
+
return "double"
|
|
1526
|
+
|
|
1527
|
+
@property
|
|
1528
|
+
def alignment(self):
|
|
1529
|
+
return 8 if self.align_double else 4
|
|
1530
|
+
|
|
1531
|
+
def _init_str(self):
|
|
1532
|
+
return f"{self.__class__.__name__}(align_double={self.align_double})"
|
|
1533
|
+
|
|
1534
|
+
def copy(self):
|
|
1535
|
+
return SimTypeDouble(align_double=self.align_double)
|
|
1536
|
+
|
|
1537
|
+
|
|
1538
|
+
class SimStruct(NamedTypeMixin, SimType):
|
|
1539
|
+
_fields = ("name", "fields", "anonymous")
|
|
1540
|
+
_args = ("fields", "name", "pack", "align", "anonymous")
|
|
1541
|
+
_ident = "struct"
|
|
1542
|
+
|
|
1543
|
+
def __init__(
|
|
1544
|
+
self,
|
|
1545
|
+
fields: dict[str, SimType] | OrderedDict[str, SimType],
|
|
1546
|
+
name=None,
|
|
1547
|
+
pack=False,
|
|
1548
|
+
align=None,
|
|
1549
|
+
anonymous: bool = False,
|
|
1550
|
+
):
|
|
1551
|
+
super().__init__(None, name="<anon>" if name is None else name)
|
|
1552
|
+
|
|
1553
|
+
self._pack = pack
|
|
1554
|
+
self._align = align
|
|
1555
|
+
self.anonymous = anonymous
|
|
1556
|
+
self.fields: OrderedDict[str, SimType] = OrderedDict(fields)
|
|
1557
|
+
|
|
1558
|
+
# FIXME: Hack for supporting win32 struct definitions
|
|
1559
|
+
if self.name == "_Anonymous_e__Struct":
|
|
1560
|
+
self.anonymous = True
|
|
1561
|
+
|
|
1562
|
+
self._arch_memo = {}
|
|
1563
|
+
|
|
1564
|
+
#
|
|
1565
|
+
# pack and align are for supporting SimType.from_json and SimType.to_json
|
|
1566
|
+
#
|
|
1567
|
+
|
|
1568
|
+
@property
|
|
1569
|
+
def pack(self):
|
|
1570
|
+
return self._pack
|
|
1571
|
+
|
|
1572
|
+
@property
|
|
1573
|
+
def align(self):
|
|
1574
|
+
return self._align
|
|
1575
|
+
|
|
1576
|
+
#
|
|
1577
|
+
# Other properties
|
|
1578
|
+
#
|
|
1579
|
+
|
|
1580
|
+
@property
|
|
1581
|
+
def packed(self):
|
|
1582
|
+
return self._pack
|
|
1583
|
+
|
|
1584
|
+
@property
|
|
1585
|
+
def offsets(self) -> dict[str, int]:
|
|
1586
|
+
if self._arch is None:
|
|
1587
|
+
raise ValueError("Need an arch to calculate offsets")
|
|
1588
|
+
|
|
1589
|
+
offsets = {}
|
|
1590
|
+
offset_so_far = 0
|
|
1591
|
+
for name, ty in self.fields.items():
|
|
1592
|
+
if ty.size is None:
|
|
1593
|
+
l.debug(
|
|
1594
|
+
"Found a bottom field in struct %s. Ignore and increment the offset using the default "
|
|
1595
|
+
"element size.",
|
|
1596
|
+
self.name,
|
|
1597
|
+
)
|
|
1598
|
+
continue
|
|
1599
|
+
if not self._pack:
|
|
1600
|
+
align = ty.alignment
|
|
1601
|
+
if align is NotImplemented:
|
|
1602
|
+
# hack!
|
|
1603
|
+
align = 1
|
|
1604
|
+
if offset_so_far % align != 0:
|
|
1605
|
+
offset_so_far += align - offset_so_far % align
|
|
1606
|
+
offsets[name] = offset_so_far
|
|
1607
|
+
offset_so_far += ty.size // self._arch.byte_width
|
|
1608
|
+
else:
|
|
1609
|
+
offsets[name] = offset_so_far // self._arch.byte_width
|
|
1610
|
+
offset_so_far += ty.size
|
|
1611
|
+
|
|
1612
|
+
return offsets
|
|
1613
|
+
|
|
1614
|
+
def to_json(self, fields: Iterable[str] | None = None, memo: dict[str, SimTypeRef] | None = None) -> dict[str, Any]:
|
|
1615
|
+
if memo is None:
|
|
1616
|
+
memo = {}
|
|
1617
|
+
|
|
1618
|
+
if self.name in memo:
|
|
1619
|
+
return memo[self.name].to_json(fields=fields, memo=memo)
|
|
1620
|
+
memo[self.name] = SimTypeRef(self.name, SimStruct)
|
|
1621
|
+
|
|
1622
|
+
d = super().to_json(fields=fields, memo=memo)
|
|
1623
|
+
if d["pack"] is False:
|
|
1624
|
+
d.pop("pack")
|
|
1625
|
+
if d["align"] is None:
|
|
1626
|
+
d.pop("align")
|
|
1627
|
+
if d["anonymous"] is False:
|
|
1628
|
+
d.pop("anonymous")
|
|
1629
|
+
return d
|
|
1630
|
+
|
|
1631
|
+
def extract(self, state, addr, concrete=False) -> SimStructValue:
|
|
1632
|
+
values = {}
|
|
1633
|
+
for name, offset in self.offsets.items():
|
|
1634
|
+
ty = self.fields[name]
|
|
1635
|
+
v = SimMemView(ty=ty, addr=addr + offset, state=state)
|
|
1636
|
+
if concrete:
|
|
1637
|
+
values[name] = v.concrete
|
|
1638
|
+
else:
|
|
1639
|
+
values[name] = v.resolved
|
|
1640
|
+
|
|
1641
|
+
return SimStructValue(self, values=values)
|
|
1642
|
+
|
|
1643
|
+
def _with_arch(self, arch):
|
|
1644
|
+
if arch.name in self._arch_memo:
|
|
1645
|
+
return self._arch_memo[arch.name]
|
|
1646
|
+
|
|
1647
|
+
out = SimStruct({}, name=self.name, pack=self._pack, align=self._align)
|
|
1648
|
+
out._arch = arch
|
|
1649
|
+
self._arch_memo[arch.name] = out
|
|
1650
|
+
|
|
1651
|
+
out.fields = OrderedDict((k, v.with_arch(arch)) for k, v in self.fields.items())
|
|
1652
|
+
|
|
1653
|
+
# Fixup the offsets to byte aligned addresses for all SimTypeNumOffset types
|
|
1654
|
+
offset_so_far = 0
|
|
1655
|
+
for _, ty in out.fields.items():
|
|
1656
|
+
if isinstance(ty, SimTypeNumOffset):
|
|
1657
|
+
out._pack = True
|
|
1658
|
+
ty.offset = offset_so_far % arch.byte_width
|
|
1659
|
+
offset_so_far += ty.size
|
|
1660
|
+
return out
|
|
1661
|
+
|
|
1662
|
+
def __repr__(self):
|
|
1663
|
+
return f"struct {self.name}"
|
|
1664
|
+
|
|
1665
|
+
def c_repr(
|
|
1666
|
+
self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
|
|
1667
|
+
): # pylint: disable=unused-argument
|
|
1668
|
+
if not full or (memo is not None and self in memo):
|
|
1669
|
+
return super().c_repr(name, full, memo, indent)
|
|
1670
|
+
|
|
1671
|
+
indented = " " * indent if indent is not None else ""
|
|
1672
|
+
new_indent = indent + 4 if indent is not None else None
|
|
1673
|
+
new_indented = " " * new_indent if new_indent is not None else ""
|
|
1674
|
+
newline = "\n" if indent is not None else " "
|
|
1675
|
+
new_memo = (self,) + (memo if memo is not None else ())
|
|
1676
|
+
members = newline.join(
|
|
1677
|
+
new_indented + v.c_repr(k, full - 1, new_memo, new_indent) + ";" for k, v in self.fields.items()
|
|
1678
|
+
)
|
|
1679
|
+
return f"struct {self.name} {{{newline}{members}{newline}{indented}}}{'' if name is None else ' ' + name}"
|
|
1680
|
+
|
|
1681
|
+
def __hash__(self):
|
|
1682
|
+
return hash((SimStruct, self._name, self._align, self._pack, tuple(self.fields.keys())))
|
|
1683
|
+
|
|
1684
|
+
@property
|
|
1685
|
+
def size(self):
|
|
1686
|
+
if not self.offsets:
|
|
1687
|
+
return 0
|
|
1688
|
+
if self._arch is None:
|
|
1689
|
+
raise ValueError("Need an arch to compute size")
|
|
1690
|
+
|
|
1691
|
+
last_name, last_off = list(self.offsets.items())[-1]
|
|
1692
|
+
last_type = self.fields[last_name]
|
|
1693
|
+
if isinstance(last_type, SimTypeNumOffset):
|
|
1694
|
+
return last_off * self._arch.byte_width + (last_type.size + last_type.offset)
|
|
1695
|
+
if last_type.size is None:
|
|
1696
|
+
raise AngrTypeError("Cannot compute the size of a struct with elements with no size")
|
|
1697
|
+
return last_off * self._arch.byte_width + last_type.size
|
|
1698
|
+
|
|
1699
|
+
@property
|
|
1700
|
+
def alignment(self):
|
|
1701
|
+
if self._align is not None:
|
|
1702
|
+
return self._align
|
|
1703
|
+
if all(val.alignment is NotImplemented for val in self.fields.values()):
|
|
1704
|
+
return NotImplemented
|
|
1705
|
+
return max(val.alignment if val.alignment is not NotImplemented else 1 for val in self.fields.values())
|
|
1706
|
+
|
|
1707
|
+
def _refine_dir(self):
|
|
1708
|
+
return list(self.fields.keys())
|
|
1709
|
+
|
|
1710
|
+
def _refine(self, view, k):
|
|
1711
|
+
offset = self.offsets[k]
|
|
1712
|
+
ty = self.fields[k]
|
|
1713
|
+
return view._deeper(ty=ty, addr=view._addr + offset)
|
|
1714
|
+
|
|
1715
|
+
def store(self, state, addr, value: StoreType):
|
|
1716
|
+
if type(value) is dict:
|
|
1717
|
+
pass
|
|
1718
|
+
elif type(value) is SimStructValue:
|
|
1719
|
+
value = value._values
|
|
1720
|
+
else:
|
|
1721
|
+
raise TypeError(f"Can't store struct of type {type(value)}")
|
|
1722
|
+
|
|
1723
|
+
assert isinstance(value, dict)
|
|
1724
|
+
if len(value) != len(self.fields):
|
|
1725
|
+
raise ValueError(f"Passed bad values for {self}; expected {len(self.offsets)}, got {len(value)}")
|
|
1726
|
+
|
|
1727
|
+
for field, offset in self.offsets.items():
|
|
1728
|
+
ty = self.fields[field]
|
|
1729
|
+
ty.store(state, addr + offset, value[field])
|
|
1730
|
+
|
|
1731
|
+
@staticmethod
|
|
1732
|
+
def _field_str(field_name, field_type):
|
|
1733
|
+
return f'("{field_name}", {field_type._init_str()})'
|
|
1734
|
+
|
|
1735
|
+
def _init_str(self):
|
|
1736
|
+
return '{}(OrderedDict(({},)), name="{}", pack={}, align={})'.format(
|
|
1737
|
+
self.__class__.__name__,
|
|
1738
|
+
", ".join([self._field_str(f, ty) for f, ty in self.fields.items()]),
|
|
1739
|
+
self._name,
|
|
1740
|
+
self._pack,
|
|
1741
|
+
self._align,
|
|
1742
|
+
)
|
|
1743
|
+
|
|
1744
|
+
def copy(self):
|
|
1745
|
+
return SimStruct(dict(self.fields), name=self.name, pack=self._pack, align=self._align)
|
|
1746
|
+
|
|
1747
|
+
def __eq__(self, other, avoid: dict[str, set[SimType]] | None = None):
|
|
1748
|
+
if not isinstance(other, SimStruct):
|
|
1749
|
+
return False
|
|
1750
|
+
if not (
|
|
1751
|
+
self._pack == other._pack
|
|
1752
|
+
and self._align == other._align
|
|
1753
|
+
and self.label == other.label
|
|
1754
|
+
and self._name == other._name
|
|
1755
|
+
and self._arch == other._arch
|
|
1756
|
+
):
|
|
1757
|
+
return False
|
|
1758
|
+
# fields comparison that accounts for self references
|
|
1759
|
+
if not self.fields and not other.fields:
|
|
1760
|
+
return True
|
|
1761
|
+
keys_self = list(self.fields)
|
|
1762
|
+
keys_other = list(other.fields)
|
|
1763
|
+
if keys_self != keys_other:
|
|
1764
|
+
return False
|
|
1765
|
+
if avoid is None:
|
|
1766
|
+
avoid = {"self": {self}, "other": {other}}
|
|
1767
|
+
for key in keys_self:
|
|
1768
|
+
field_self = self.fields[key]
|
|
1769
|
+
field_other = other.fields[key]
|
|
1770
|
+
if field_self in avoid["self"] and field_other in avoid["other"]:
|
|
1771
|
+
continue
|
|
1772
|
+
avoid["self"].add(field_self)
|
|
1773
|
+
avoid["other"].add(field_other)
|
|
1774
|
+
if not field_self.__eq__(field_other, avoid=avoid):
|
|
1775
|
+
return False
|
|
1776
|
+
return True
|
|
1777
|
+
|
|
1778
|
+
|
|
1779
|
+
class SimStructValue:
|
|
1780
|
+
"""
|
|
1781
|
+
A SimStruct type paired with some real values
|
|
1782
|
+
"""
|
|
1783
|
+
|
|
1784
|
+
def __init__(self, struct, values=None):
|
|
1785
|
+
"""
|
|
1786
|
+
:param struct: A SimStruct instance describing the type of this struct
|
|
1787
|
+
:param values: A mapping from struct fields to values
|
|
1788
|
+
"""
|
|
1789
|
+
self._struct = struct
|
|
1790
|
+
# since the keys are specified, also support specifying the values as just a list
|
|
1791
|
+
if values is not None and hasattr(values, "__iter__") and not hasattr(values, "items"):
|
|
1792
|
+
values = dict(zip(struct.fields.keys(), values))
|
|
1793
|
+
self._values = defaultdict(lambda: None, values or ())
|
|
1794
|
+
|
|
1795
|
+
@property
|
|
1796
|
+
def struct(self):
|
|
1797
|
+
return self._struct
|
|
1798
|
+
|
|
1799
|
+
def __indented_repr__(self, indent=0):
|
|
1800
|
+
fields = []
|
|
1801
|
+
for name in self._struct.fields:
|
|
1802
|
+
value = self._values[name]
|
|
1803
|
+
try:
|
|
1804
|
+
f = value.__indented_repr__ # type: ignore[reportAttributeAccessIssue]
|
|
1805
|
+
s = f(indent=indent + 2)
|
|
1806
|
+
except AttributeError:
|
|
1807
|
+
s = repr(value)
|
|
1808
|
+
fields.append(" " * (indent + 2) + f".{name} = {s}")
|
|
1809
|
+
|
|
1810
|
+
return "{{\n{}\n{}}}".format(",\n".join(fields), " " * indent)
|
|
1811
|
+
|
|
1812
|
+
def __repr__(self):
|
|
1813
|
+
return self.__indented_repr__()
|
|
1814
|
+
|
|
1815
|
+
def __getattr__(self, k):
|
|
1816
|
+
return self[k]
|
|
1817
|
+
|
|
1818
|
+
def __getitem__(self, k):
|
|
1819
|
+
if type(k) is int:
|
|
1820
|
+
k = self._struct.fields[k]
|
|
1821
|
+
if k not in self._values:
|
|
1822
|
+
for f in self._struct.fields:
|
|
1823
|
+
if isinstance(f, NamedTypeMixin) and f.name is None:
|
|
1824
|
+
try:
|
|
1825
|
+
return f[k] # type: ignore # lukas WHAT
|
|
1826
|
+
except KeyError:
|
|
1827
|
+
continue
|
|
1828
|
+
raise KeyError(k)
|
|
1829
|
+
|
|
1830
|
+
return self._values[k]
|
|
1831
|
+
|
|
1832
|
+
def copy(self):
|
|
1833
|
+
return SimStructValue(self._struct, values=defaultdict(lambda: None, self._values))
|
|
1834
|
+
|
|
1835
|
+
|
|
1836
|
+
class SimUnion(NamedTypeMixin, SimType):
|
|
1837
|
+
fields = ("members", "name")
|
|
1838
|
+
_args = ("members", "name", "label")
|
|
1839
|
+
_ident = "union"
|
|
1840
|
+
|
|
1841
|
+
def __init__(self, members: dict[str, SimType], name=None, label=None):
|
|
1842
|
+
"""
|
|
1843
|
+
:param members: The members of the union, as a mapping name -> type
|
|
1844
|
+
:param name: The name of the union
|
|
1845
|
+
"""
|
|
1846
|
+
super().__init__(label, name=name if name is not None else "<anon>")
|
|
1847
|
+
self.members = members
|
|
1848
|
+
|
|
1849
|
+
@property
|
|
1850
|
+
def size(self):
|
|
1851
|
+
if self._arch is None:
|
|
1852
|
+
raise ValueError("Can't tell my size without an arch!")
|
|
1853
|
+
all_member_sizes: list[int | None] = [
|
|
1854
|
+
ty.size for ty in self.members.values() if not isinstance(ty, (SimTypeBottom, SimTypeRef))
|
|
1855
|
+
]
|
|
1856
|
+
member_sizes: list[int] = [s for s in all_member_sizes if s is not None]
|
|
1857
|
+
# fall back to word size in case all members are SimTypeBottom
|
|
1858
|
+
return max(member_sizes) if member_sizes else self._arch.bytes
|
|
1859
|
+
|
|
1860
|
+
@property
|
|
1861
|
+
def alignment(self):
|
|
1862
|
+
if all(val.alignment is NotImplemented for val in self.members.values()):
|
|
1863
|
+
return NotImplemented
|
|
1864
|
+
return max(val.alignment if val.alignment is not NotImplemented else 1 for val in self.members.values())
|
|
1865
|
+
|
|
1866
|
+
def _refine_dir(self):
|
|
1867
|
+
return list(self.members.keys())
|
|
1868
|
+
|
|
1869
|
+
def _refine(self, view, k):
|
|
1870
|
+
ty = self.members[k]
|
|
1871
|
+
return view._deeper(ty=ty, addr=view._addr)
|
|
1872
|
+
|
|
1873
|
+
def extract(self, state, addr, concrete=False):
|
|
1874
|
+
values = {}
|
|
1875
|
+
for name, ty in self.members.items():
|
|
1876
|
+
v = SimMemView(ty=ty, addr=addr, state=state)
|
|
1877
|
+
if concrete:
|
|
1878
|
+
values[name] = v.concrete
|
|
1879
|
+
else:
|
|
1880
|
+
values[name] = v.resolved
|
|
1881
|
+
|
|
1882
|
+
return SimUnionValue(self, values=values)
|
|
1883
|
+
|
|
1884
|
+
def __repr__(self):
|
|
1885
|
+
# use the str instead of repr of each member to avoid exceed recursion
|
|
1886
|
+
# depth when representing self-referential unions
|
|
1887
|
+
return "union {} {{\n\t{}\n}}".format(
|
|
1888
|
+
self.name, "\n\t".join(f"{name} {ty!s};" for name, ty in self.members.items())
|
|
1889
|
+
)
|
|
1890
|
+
|
|
1891
|
+
def c_repr(
|
|
1892
|
+
self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
|
|
1893
|
+
): # pylint: disable=unused-argument
|
|
1894
|
+
if not full or (memo is not None and self in memo):
|
|
1895
|
+
return super().c_repr(name, full, memo, indent)
|
|
1896
|
+
|
|
1897
|
+
indented = " " * indent if indent is not None else ""
|
|
1898
|
+
new_indent = indent + 4 if indent is not None else None
|
|
1899
|
+
new_indented = " " * new_indent if new_indent is not None else ""
|
|
1900
|
+
newline = "\n" if indent is not None else " "
|
|
1901
|
+
new_memo = (self,) + (memo if memo is not None else ())
|
|
1902
|
+
members = newline.join(
|
|
1903
|
+
new_indented + v.c_repr(k, full - 1, new_memo, new_indent) + ";" for k, v in self.members.items()
|
|
1904
|
+
)
|
|
1905
|
+
return f"union {self.name} {{{newline}{members}{newline}{indented}}}{'' if name is None else ' ' + name}"
|
|
1906
|
+
|
|
1907
|
+
def _init_str(self):
|
|
1908
|
+
return '{}({{{}}}, name="{}", label="{}")'.format(
|
|
1909
|
+
self.__class__.__name__,
|
|
1910
|
+
", ".join([self._field_str(f, ty) for f, ty in self.members.items()]),
|
|
1911
|
+
self._name,
|
|
1912
|
+
self.label,
|
|
1913
|
+
)
|
|
1914
|
+
|
|
1915
|
+
@staticmethod
|
|
1916
|
+
def _field_str(field_name, field_type):
|
|
1917
|
+
return f'"{field_name}": {field_type._init_str()}'
|
|
1918
|
+
|
|
1919
|
+
def __str__(self):
|
|
1920
|
+
return f"union {self.name}"
|
|
1921
|
+
|
|
1922
|
+
def _with_arch(self, arch):
|
|
1923
|
+
out = SimUnion({name: ty.with_arch(arch) for name, ty in self.members.items()}, self.label)
|
|
1924
|
+
out._arch = arch
|
|
1925
|
+
return out
|
|
1926
|
+
|
|
1927
|
+
def copy(self):
|
|
1928
|
+
return SimUnion(dict(self.members), name=self.name, label=self.label)
|
|
1929
|
+
|
|
1930
|
+
|
|
1931
|
+
class SimUnionValue:
|
|
1932
|
+
"""
|
|
1933
|
+
A SimStruct type paired with some real values
|
|
1934
|
+
"""
|
|
1935
|
+
|
|
1936
|
+
def __init__(self, union, values=None):
|
|
1937
|
+
"""
|
|
1938
|
+
:param union: A SimUnion instance describing the type of this union
|
|
1939
|
+
:param values: A mapping from union members to values
|
|
1940
|
+
"""
|
|
1941
|
+
self._union = union
|
|
1942
|
+
self._values = defaultdict(lambda: None, values or ())
|
|
1943
|
+
|
|
1944
|
+
def __indented_repr__(self, indent=0):
|
|
1945
|
+
fields = []
|
|
1946
|
+
for name, value in self._values.items():
|
|
1947
|
+
try:
|
|
1948
|
+
f = value.__indented_repr__ # type: ignore[reportAttributeAccessIssue]
|
|
1949
|
+
s = f(indent=indent + 2)
|
|
1950
|
+
except AttributeError:
|
|
1951
|
+
s = repr(value)
|
|
1952
|
+
fields.append(" " * (indent + 2) + f".{name} = {s}")
|
|
1953
|
+
|
|
1954
|
+
return "{{\n{}\n{}}}".format(",\n".join(fields), " " * indent)
|
|
1955
|
+
|
|
1956
|
+
def __repr__(self):
|
|
1957
|
+
return self.__indented_repr__()
|
|
1958
|
+
|
|
1959
|
+
def __getattr__(self, k):
|
|
1960
|
+
return self[k]
|
|
1961
|
+
|
|
1962
|
+
def __getitem__(self, k):
|
|
1963
|
+
if k not in self._values:
|
|
1964
|
+
raise KeyError(k)
|
|
1965
|
+
return self._values[k]
|
|
1966
|
+
|
|
1967
|
+
def copy(self):
|
|
1968
|
+
return SimUnionValue(self._union, values=self._values)
|
|
1969
|
+
|
|
1970
|
+
|
|
1971
|
+
class SimCppClass(SimStruct):
|
|
1972
|
+
|
|
1973
|
+
_args = (
|
|
1974
|
+
"unique_name",
|
|
1975
|
+
"name",
|
|
1976
|
+
"members",
|
|
1977
|
+
"function_members",
|
|
1978
|
+
"vtable_ptrs",
|
|
1979
|
+
"pack",
|
|
1980
|
+
"align",
|
|
1981
|
+
"size",
|
|
1982
|
+
)
|
|
1983
|
+
_ident = "cppclass"
|
|
1984
|
+
|
|
1985
|
+
def __init__(
|
|
1986
|
+
self,
|
|
1987
|
+
*,
|
|
1988
|
+
unique_name: str | None = None,
|
|
1989
|
+
name: str | None = None,
|
|
1990
|
+
members: dict[str, SimType] | None = None,
|
|
1991
|
+
function_members: dict[str, SimTypeCppFunction] | None = None,
|
|
1992
|
+
vtable_ptrs=None,
|
|
1993
|
+
pack: bool = False,
|
|
1994
|
+
align=None,
|
|
1995
|
+
size: int | None = None,
|
|
1996
|
+
):
|
|
1997
|
+
super().__init__(members or {}, name=name, pack=pack, align=align)
|
|
1998
|
+
self.unique_name = unique_name
|
|
1999
|
+
# these are actually addresses in the binary
|
|
2000
|
+
self.function_members = function_members
|
|
2001
|
+
# this should also be added to the fields once we know the offsets of the members of this object
|
|
2002
|
+
self.vtable_ptrs = [] if vtable_ptrs is None else vtable_ptrs
|
|
2003
|
+
|
|
2004
|
+
# we can force the size (in bits) of a class because sometimes the class can be opaque and we don't know its
|
|
2005
|
+
# layout
|
|
2006
|
+
self._size = size
|
|
2007
|
+
|
|
2008
|
+
@property
|
|
2009
|
+
def members(self):
|
|
2010
|
+
return self.fields
|
|
2011
|
+
|
|
2012
|
+
@members.setter
|
|
2013
|
+
def members(self, value):
|
|
2014
|
+
self.fields = value
|
|
2015
|
+
|
|
2016
|
+
@property
|
|
2017
|
+
def size(self):
|
|
2018
|
+
if self._size is not None:
|
|
2019
|
+
return self._size
|
|
2020
|
+
return super().size
|
|
2021
|
+
|
|
2022
|
+
def __repr__(self):
|
|
2023
|
+
return f"class {self.name}" if not self.name.startswith("class") else self.name
|
|
2024
|
+
|
|
2025
|
+
def extract(self, state, addr, concrete=False) -> SimCppClassValue:
|
|
2026
|
+
values = {}
|
|
2027
|
+
for name, offset in self.offsets.items():
|
|
2028
|
+
ty = self.fields[name]
|
|
2029
|
+
v = SimMemView(ty=ty, addr=addr + offset, state=state)
|
|
2030
|
+
if concrete:
|
|
2031
|
+
values[name] = v.concrete
|
|
2032
|
+
else:
|
|
2033
|
+
values[name] = v.resolved
|
|
2034
|
+
|
|
2035
|
+
return SimCppClassValue(self, values=values)
|
|
2036
|
+
|
|
2037
|
+
def store(self, state, addr, value: StoreType):
|
|
2038
|
+
if type(value) is dict:
|
|
2039
|
+
pass
|
|
2040
|
+
elif type(value) is SimCppClassValue:
|
|
2041
|
+
value = value._values
|
|
2042
|
+
else:
|
|
2043
|
+
raise TypeError(f"Can't store struct of type {type(value)}")
|
|
2044
|
+
|
|
2045
|
+
assert isinstance(value, dict)
|
|
2046
|
+
if len(value) != len(self.fields):
|
|
2047
|
+
raise ValueError(f"Passed bad values for {self}; expected {len(self.offsets)}, got {len(value)}")
|
|
2048
|
+
|
|
2049
|
+
for field, offset in self.offsets.items():
|
|
2050
|
+
ty = self.fields[field]
|
|
2051
|
+
ty.store(state, addr + offset, value[field])
|
|
2052
|
+
|
|
2053
|
+
def _with_arch(self, arch) -> SimCppClass:
|
|
2054
|
+
if arch.name in self._arch_memo:
|
|
2055
|
+
return self._arch_memo[arch.name]
|
|
2056
|
+
|
|
2057
|
+
out = SimCppClass(
|
|
2058
|
+
unique_name=self.unique_name,
|
|
2059
|
+
name=self.name,
|
|
2060
|
+
members={},
|
|
2061
|
+
function_members={},
|
|
2062
|
+
vtable_ptrs=self.vtable_ptrs,
|
|
2063
|
+
pack=self._pack,
|
|
2064
|
+
align=self._align,
|
|
2065
|
+
size=self._size,
|
|
2066
|
+
)
|
|
2067
|
+
out._arch = arch
|
|
2068
|
+
self._arch_memo[arch.name] = out
|
|
2069
|
+
|
|
2070
|
+
out.members = OrderedDict((k, v.with_arch(arch)) for k, v in self.members.items())
|
|
2071
|
+
out.function_members = (
|
|
2072
|
+
OrderedDict((k, v.with_arch(arch)) for k, v in self.function_members.items())
|
|
2073
|
+
if self.function_members is not None
|
|
2074
|
+
else None
|
|
2075
|
+
)
|
|
2076
|
+
|
|
2077
|
+
# Fixup the offsets to byte aligned addresses for all SimTypeNumOffset types
|
|
2078
|
+
offset_so_far = 0
|
|
2079
|
+
for _, ty in out.members.items():
|
|
2080
|
+
if isinstance(ty, SimTypeNumOffset):
|
|
2081
|
+
out._pack = True
|
|
2082
|
+
ty.offset = offset_so_far % arch.byte_width
|
|
2083
|
+
offset_so_far += ty.size
|
|
2084
|
+
return out
|
|
2085
|
+
|
|
2086
|
+
def copy(self):
|
|
2087
|
+
return SimCppClass(
|
|
2088
|
+
unique_name=self.unique_name,
|
|
2089
|
+
name=self.name,
|
|
2090
|
+
members=dict(self.fields),
|
|
2091
|
+
pack=self._pack,
|
|
2092
|
+
align=self._align,
|
|
2093
|
+
function_members=self.function_members,
|
|
2094
|
+
vtable_ptrs=self.vtable_ptrs,
|
|
2095
|
+
size=self._size,
|
|
2096
|
+
)
|
|
2097
|
+
|
|
2098
|
+
|
|
2099
|
+
class SimCppClassValue(SimStructValue):
|
|
2100
|
+
"""
|
|
2101
|
+
A SimCppClass type paired with some real values
|
|
2102
|
+
"""
|
|
2103
|
+
|
|
2104
|
+
def __init__(self, class_type: SimCppClass, values):
|
|
2105
|
+
super().__init__(class_type, values)
|
|
2106
|
+
self._class = class_type
|
|
2107
|
+
|
|
2108
|
+
def __indented_repr__(self, indent=0):
|
|
2109
|
+
fields = []
|
|
2110
|
+
for name in self._class.fields:
|
|
2111
|
+
value = self._values[name]
|
|
2112
|
+
try:
|
|
2113
|
+
f = value.__indented_repr__ # type: ignore[reportAttributeAccessIssue]
|
|
2114
|
+
s = f(indent=indent + 2)
|
|
2115
|
+
except AttributeError:
|
|
2116
|
+
s = repr(value)
|
|
2117
|
+
fields.append(" " * (indent + 2) + f".{name} = {s}")
|
|
2118
|
+
|
|
2119
|
+
return "{{\n{}\n{}}}".format(",\n".join(fields), " " * indent)
|
|
2120
|
+
|
|
2121
|
+
def __repr__(self):
|
|
2122
|
+
return self.__indented_repr__()
|
|
2123
|
+
|
|
2124
|
+
def __getattr__(self, k):
|
|
2125
|
+
return self[k]
|
|
2126
|
+
|
|
2127
|
+
def __getitem__(self, k: int | str):
|
|
2128
|
+
if isinstance(k, int):
|
|
2129
|
+
k = list(self._class.fields.keys())[k]
|
|
2130
|
+
if k not in self._values:
|
|
2131
|
+
for f in self._class.fields:
|
|
2132
|
+
if isinstance(f, NamedTypeMixin) and f.name is None:
|
|
2133
|
+
try:
|
|
2134
|
+
return f[k] # type: ignore # lukas WHAT
|
|
2135
|
+
except KeyError:
|
|
2136
|
+
continue
|
|
2137
|
+
return self._values[k]
|
|
2138
|
+
|
|
2139
|
+
return self._values[k]
|
|
2140
|
+
|
|
2141
|
+
def copy(self):
|
|
2142
|
+
return SimCppClassValue(self._class, values=defaultdict(lambda: None, self._values))
|
|
2143
|
+
|
|
2144
|
+
|
|
2145
|
+
class SimTypeNumOffset(SimTypeNum):
|
|
2146
|
+
"""
|
|
2147
|
+
like SimTypeNum, but supports an offset of 1 to 7 to a byte aligned address to allow structs with bitfields
|
|
2148
|
+
"""
|
|
2149
|
+
|
|
2150
|
+
_fields = (*SimTypeNum._fields, "offset")
|
|
2151
|
+
_args = ("size", "signed", "label", "offset")
|
|
2152
|
+
_ident = "numoff"
|
|
2153
|
+
|
|
2154
|
+
def __init__(self, size, signed=True, label=None, offset=0):
|
|
2155
|
+
super().__init__(size, signed, label)
|
|
2156
|
+
self.offset = offset
|
|
2157
|
+
|
|
2158
|
+
@overload
|
|
2159
|
+
def extract(self, state: SimState, addr, concrete: Literal[False] = ...) -> claripy.ast.BV: ...
|
|
2160
|
+
|
|
2161
|
+
@overload
|
|
2162
|
+
def extract(self, state: SimState, addr, concrete: Literal[True]) -> int: ...
|
|
2163
|
+
|
|
2164
|
+
def extract(self, state: SimState, addr, concrete=False):
|
|
2165
|
+
if state.arch.memory_endness != Endness.LE:
|
|
2166
|
+
raise NotImplementedError("This has only been implemented and tested with Little Endian arches so far")
|
|
2167
|
+
minimum_load_size = self.offset + self.size # because we start from a byte aligned offset _before_ the value
|
|
2168
|
+
# Now round up to the next byte
|
|
2169
|
+
load_size = (minimum_load_size - minimum_load_size % (-state.arch.byte_width)) // state.arch.byte_width
|
|
2170
|
+
out = state.memory.load(addr, size=load_size, endness=state.arch.memory_endness)
|
|
2171
|
+
out = out[self.offset + self.size - 1 : self.offset]
|
|
2172
|
+
|
|
2173
|
+
if not concrete:
|
|
2174
|
+
return out
|
|
2175
|
+
n = state.solver.eval(out)
|
|
2176
|
+
if self.signed and n >= 1 << (self.size - 1):
|
|
2177
|
+
n -= 1 << (self.size)
|
|
2178
|
+
return n
|
|
2179
|
+
|
|
2180
|
+
def store(self, state, addr, value):
|
|
2181
|
+
raise NotImplementedError
|
|
2182
|
+
|
|
2183
|
+
def copy(self):
|
|
2184
|
+
return SimTypeNumOffset(self.size, signed=self.signed, label=self.label, offset=self.offset)
|
|
2185
|
+
|
|
2186
|
+
|
|
2187
|
+
class SimTypeRef(SimType):
|
|
2188
|
+
"""
|
|
2189
|
+
SimTypeRef is a to-be-resolved reference to another SimType.
|
|
2190
|
+
|
|
2191
|
+
SimTypeRef is not SimTypeReference.
|
|
2192
|
+
"""
|
|
2193
|
+
|
|
2194
|
+
_args = ("name", "original_type")
|
|
2195
|
+
_ident = "_ref"
|
|
2196
|
+
|
|
2197
|
+
def __init__(self, name, original_type: type[SimType]):
|
|
2198
|
+
super().__init__(label=name)
|
|
2199
|
+
self.original_type = original_type
|
|
2200
|
+
|
|
2201
|
+
@property
|
|
2202
|
+
def name(self) -> str | None:
|
|
2203
|
+
return self.label
|
|
2204
|
+
|
|
2205
|
+
def set_size(self, v: int):
|
|
2206
|
+
self._size = v
|
|
2207
|
+
|
|
2208
|
+
def __repr__(self):
|
|
2209
|
+
if self.label:
|
|
2210
|
+
return self.label
|
|
2211
|
+
prefix = "struct " if self.original_type is SimStruct else ""
|
|
2212
|
+
return f"{prefix}{self.name}"
|
|
2213
|
+
|
|
2214
|
+
def c_repr(
|
|
2215
|
+
self, name=None, full=0, memo=None, indent=0, name_parens: bool = True
|
|
2216
|
+
) -> str: # pylint: disable=unused-argument
|
|
2217
|
+
prefix = "unknown"
|
|
2218
|
+
if self.original_type is SimStruct:
|
|
2219
|
+
prefix = "struct "
|
|
2220
|
+
if name is None:
|
|
2221
|
+
name = ""
|
|
2222
|
+
return f"{prefix}{self.label} {name}"
|
|
2223
|
+
|
|
2224
|
+
def _init_str(self) -> str:
|
|
2225
|
+
original_type_name = self.original_type.__name__.split(".")[-1]
|
|
2226
|
+
return f'SimTypeRef("{self.name}", {original_type_name})'
|
|
2227
|
+
|
|
2228
|
+
def to_json(self, fields: Iterable[str] | None = None, memo: dict[str, SimTypeRef] | None = None) -> dict[str, Any]:
|
|
2229
|
+
d = {"_t": self._ident, "name": self.name, "ot": self.original_type._ident}
|
|
2230
|
+
if fields is not None:
|
|
2231
|
+
d = {k: d[k] for k in fields}
|
|
2232
|
+
return d
|
|
2233
|
+
|
|
2234
|
+
@staticmethod
|
|
2235
|
+
def from_json(d: dict[str, Any]) -> SimTypeRef:
|
|
2236
|
+
if "ot" not in d:
|
|
2237
|
+
raise ValueError("Missing original type for SimTypeRef")
|
|
2238
|
+
original_type = IDENT_TO_CLS.get(d["ot"], None)
|
|
2239
|
+
if original_type is None:
|
|
2240
|
+
raise ValueError(f"Unknown original type {d['ot']} for SimTypeRef")
|
|
2241
|
+
return SimTypeRef(d["name"], original_type)
|
|
2242
|
+
|
|
2243
|
+
|
|
2244
|
+
IDENT_TO_CLS: dict[str, type[SimType]] = {}
|
|
2245
|
+
_queue = [SimType]
|
|
2246
|
+
while _queue:
|
|
2247
|
+
_cls = _queue.pop()
|
|
2248
|
+
assert _cls._ident not in IDENT_TO_CLS
|
|
2249
|
+
IDENT_TO_CLS[_cls._ident] = _cls
|
|
2250
|
+
_queue.extend(_cls.__subclasses__())
|
|
2251
|
+
|
|
2252
|
+
|
|
2253
|
+
ALL_TYPES: dict[str, SimType] = {}
|
|
2254
|
+
BASIC_TYPES: dict[str, SimType] = {
|
|
2255
|
+
"char": SimTypeChar(),
|
|
2256
|
+
"signed char": SimTypeChar(),
|
|
2257
|
+
"unsigned char": SimTypeChar(signed=False),
|
|
2258
|
+
"short": SimTypeShort(True),
|
|
2259
|
+
"signed short": SimTypeShort(True),
|
|
2260
|
+
"unsigned short": SimTypeShort(False),
|
|
2261
|
+
"short int": SimTypeShort(True),
|
|
2262
|
+
"signed short int": SimTypeShort(True),
|
|
2263
|
+
"unsigned short int": SimTypeShort(False),
|
|
2264
|
+
"int": SimTypeInt(True),
|
|
2265
|
+
"signed": SimTypeInt(True),
|
|
2266
|
+
"unsigned": SimTypeInt(False),
|
|
2267
|
+
"signed int": SimTypeInt(True),
|
|
2268
|
+
"unsigned int": SimTypeInt(False),
|
|
2269
|
+
"long": SimTypeLong(True),
|
|
2270
|
+
"signed long": SimTypeLong(True),
|
|
2271
|
+
"long signed": SimTypeLong(True),
|
|
2272
|
+
"unsigned long": SimTypeLong(False),
|
|
2273
|
+
"long int": SimTypeLong(True),
|
|
2274
|
+
"signed long int": SimTypeLong(True),
|
|
2275
|
+
"unsigned long int": SimTypeLong(False),
|
|
2276
|
+
"long unsigned int": SimTypeLong(False),
|
|
2277
|
+
"long long": SimTypeLongLong(True),
|
|
2278
|
+
"signed long long": SimTypeLongLong(True),
|
|
2279
|
+
"unsigned long long": SimTypeLongLong(False),
|
|
2280
|
+
"long long int": SimTypeLongLong(True),
|
|
2281
|
+
"signed long long int": SimTypeLongLong(True),
|
|
2282
|
+
"unsigned long long int": SimTypeLongLong(False),
|
|
2283
|
+
"__int32": SimTypeInt(True),
|
|
2284
|
+
"__int64": SimTypeLongLong(True),
|
|
2285
|
+
"__int128": SimTypeNum(128, True),
|
|
2286
|
+
"unsigned __int128": SimTypeNum(128, False),
|
|
2287
|
+
"__int256": SimTypeNum(256, True),
|
|
2288
|
+
"unsigned __int256": SimTypeNum(256, False),
|
|
2289
|
+
"bool": SimTypeBool(),
|
|
2290
|
+
"_Bool": SimTypeBool(),
|
|
2291
|
+
"float": SimTypeFloat(),
|
|
2292
|
+
"double": SimTypeDouble(),
|
|
2293
|
+
"long double": SimTypeDouble(),
|
|
2294
|
+
"void": SimTypeBottom(label="void"),
|
|
2295
|
+
}
|
|
2296
|
+
ALL_TYPES.update(BASIC_TYPES)
|
|
2297
|
+
|
|
2298
|
+
STDINT_TYPES = {
|
|
2299
|
+
"int8_t": SimTypeNum(8, True),
|
|
2300
|
+
"uint8_t": SimTypeNum(8, False),
|
|
2301
|
+
"byte": SimTypeNum(8, False),
|
|
2302
|
+
"int16_t": SimTypeNum(16, True),
|
|
2303
|
+
"uint16_t": SimTypeNum(16, False),
|
|
2304
|
+
"word": SimTypeNum(16, False),
|
|
2305
|
+
"int32_t": SimTypeNum(32, True),
|
|
2306
|
+
"uint32_t": SimTypeNum(32, False),
|
|
2307
|
+
"dword": SimTypeNum(32, False),
|
|
2308
|
+
"int64_t": SimTypeNum(64, True),
|
|
2309
|
+
"uint64_t": SimTypeNum(64, False),
|
|
2310
|
+
"qword": SimTypeNum(64, False),
|
|
2311
|
+
"ptrdiff_t": SimTypeLong(True),
|
|
2312
|
+
"size_t": SimTypeLength(False),
|
|
2313
|
+
"ssize_t": SimTypeLength(True),
|
|
2314
|
+
"ssize": SimTypeLength(False),
|
|
2315
|
+
"uintptr_t": SimTypeLong(False),
|
|
2316
|
+
# wide-char types
|
|
2317
|
+
"wchar_t": SimTypeShort(True, label="wchar_t"),
|
|
2318
|
+
"wint_t": SimTypeInt(True, label="wint_t"),
|
|
2319
|
+
"wctype_t": SimTypeInt(True, label="wctype_t"),
|
|
2320
|
+
}
|
|
2321
|
+
ALL_TYPES.update(STDINT_TYPES)
|
|
2322
|
+
|
|
2323
|
+
# Most glibc internal basic types are defined in the following two files:
|
|
2324
|
+
# https://github.com/bminor/glibc/blob/master/bits/typesizes.h
|
|
2325
|
+
# https://github.com/bminor/glibc/blob/master/posix/bits/types.h
|
|
2326
|
+
# Anything that is defined in a different file should probably have a permalink
|
|
2327
|
+
|
|
2328
|
+
GLIBC_INTERNAL_BASIC_TYPES = {
|
|
2329
|
+
"__off_t": ALL_TYPES["long int"],
|
|
2330
|
+
"__off64_t": ALL_TYPES["long long int"],
|
|
2331
|
+
"__pid_t": ALL_TYPES["int"],
|
|
2332
|
+
"__ino_t": ALL_TYPES["unsigned long int"],
|
|
2333
|
+
"__ino64_t": ALL_TYPES["unsigned long long int"],
|
|
2334
|
+
"__mode_t": ALL_TYPES["unsigned int"],
|
|
2335
|
+
"__dev_t": ALL_TYPES["uint64_t"],
|
|
2336
|
+
"__nlink_t": ALL_TYPES["unsigned int"],
|
|
2337
|
+
"__uid_t": ALL_TYPES["unsigned int"],
|
|
2338
|
+
"__gid_t": ALL_TYPES["unsigned int"],
|
|
2339
|
+
"__time_t": ALL_TYPES["long int"],
|
|
2340
|
+
# https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/sysdeps/unix/sysv/linux/x86/bits/siginfo-arch.h#L12
|
|
2341
|
+
"__clock_t": ALL_TYPES["uint32_t"],
|
|
2342
|
+
"__suseconds_t": ALL_TYPES["int64_t"],
|
|
2343
|
+
"socklen_t": ALL_TYPES["uint32_t"],
|
|
2344
|
+
"mode_t": ALL_TYPES["unsigned int"],
|
|
2345
|
+
}
|
|
2346
|
+
ALL_TYPES.update(GLIBC_INTERNAL_BASIC_TYPES)
|
|
2347
|
+
|
|
2348
|
+
GLIBC_EXTERNAL_BASIC_TYPES = {
|
|
2349
|
+
"off_t": ALL_TYPES["__off_t"],
|
|
2350
|
+
"off64_t": ALL_TYPES["__off64_t"],
|
|
2351
|
+
"pid_t": ALL_TYPES["__pid_t"],
|
|
2352
|
+
# https://www.gnu.org/software/libc/manual/html_node/Attribute-Meanings.html
|
|
2353
|
+
# This is "no narrower than unsigned int" but may be wider...
|
|
2354
|
+
# TODO: This should be defined based on the architecture
|
|
2355
|
+
"ino_t": ALL_TYPES["__ino_t"],
|
|
2356
|
+
"ino64_t": ALL_TYPES["__ino64_t"],
|
|
2357
|
+
# https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/bits/sockaddr.h#L28
|
|
2358
|
+
"sa_family_t": ALL_TYPES["unsigned short int"],
|
|
2359
|
+
# https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/inet/netinet/in.h#L123
|
|
2360
|
+
"in_port_t": ALL_TYPES["uint16_t"],
|
|
2361
|
+
# https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/bits/termios.h#L102
|
|
2362
|
+
"tcflag_t": ALL_TYPES["unsigned long int"],
|
|
2363
|
+
# https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/bits/termios.h#L105
|
|
2364
|
+
"cc_t": ALL_TYPES["unsigned char"],
|
|
2365
|
+
# https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/bits/termios.h#L108
|
|
2366
|
+
"speed_t": ALL_TYPES["long int"],
|
|
2367
|
+
"clock_t": ALL_TYPES["__clock_t"],
|
|
2368
|
+
"rlim_t": ALL_TYPES["unsigned long int"],
|
|
2369
|
+
"rlim64_t": ALL_TYPES["uint64_t"],
|
|
2370
|
+
# https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/bits/types/error_t.h#L22
|
|
2371
|
+
"error_t": ALL_TYPES["int"],
|
|
2372
|
+
"sigset_t": ALL_TYPES["int"],
|
|
2373
|
+
"sem_t": ALL_TYPES["int"],
|
|
2374
|
+
"sighandler_t": SimTypePointer(ALL_TYPES["void"], label="sighandler_t"),
|
|
2375
|
+
"comparison_fn_t": SimTypePointer(ALL_TYPES["void"], label="comparison_fn_t"),
|
|
2376
|
+
"DIR": SimStruct({}, name="DIR"),
|
|
2377
|
+
"glob_t": SimStruct({}, name="glob_t"),
|
|
2378
|
+
"glob64_t": SimStruct({}, name="glob64_t"),
|
|
2379
|
+
"__free_fn_t": SimTypePointer(ALL_TYPES["void"], label="__free_fn_t"),
|
|
2380
|
+
"__action_fn_t": SimTypePointer(ALL_TYPES["void"], label="__action_fn_t"),
|
|
2381
|
+
"__ftw_func_t": SimTypePointer(ALL_TYPES["void"], label="__ftw_func_t"),
|
|
2382
|
+
"mbstate_t": SimStruct({}, name="mbstate_t"),
|
|
2383
|
+
"fpos_t": SimStruct({}, name="fpos_t"),
|
|
2384
|
+
"fpos64_t": SimStruct({}, name="fpos64_t"),
|
|
2385
|
+
"regex_t": SimStruct({}, name="regex_t"),
|
|
2386
|
+
"fd_set": SimStruct({}, name="fd_set"),
|
|
2387
|
+
"dev_t": ALL_TYPES["int"],
|
|
2388
|
+
}
|
|
2389
|
+
ALL_TYPES.update(GLIBC_EXTERNAL_BASIC_TYPES)
|
|
2390
|
+
|
|
2391
|
+
# TODO: switch to stl types declared in types_stl
|
|
2392
|
+
CXX_TYPES = {
|
|
2393
|
+
"string": SimTypeString(),
|
|
2394
|
+
"wstring": SimTypeWString(),
|
|
2395
|
+
"std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>": SimTypeString(),
|
|
2396
|
+
"basic_string": SimTypeString(),
|
|
2397
|
+
"CharT": SimTypeChar(),
|
|
2398
|
+
}
|
|
2399
|
+
ALL_TYPES.update(CXX_TYPES)
|
|
2400
|
+
|
|
2401
|
+
|
|
2402
|
+
# Note about structs with self/next pointers -- they will be defined as memberless
|
|
2403
|
+
# name-only structs the same way they would be in C as a forward declaration
|
|
2404
|
+
|
|
2405
|
+
# This dictionary is defined in two steps to allow structs that are members of other
|
|
2406
|
+
# structs to be defined first
|
|
2407
|
+
GLIBC_INTERNAL_TYPES = {
|
|
2408
|
+
"sigval": SimUnion(
|
|
2409
|
+
{
|
|
2410
|
+
"sival_int": ALL_TYPES["int"],
|
|
2411
|
+
"sival_ptr": SimTypePointer(ALL_TYPES["void"], label="void *"),
|
|
2412
|
+
},
|
|
2413
|
+
name="sigval",
|
|
2414
|
+
),
|
|
2415
|
+
"__mbstate_t": SimStruct(
|
|
2416
|
+
{
|
|
2417
|
+
"__count": ALL_TYPES["int"],
|
|
2418
|
+
"__value": SimUnion(
|
|
2419
|
+
{
|
|
2420
|
+
"__wch": ALL_TYPES["unsigned int"],
|
|
2421
|
+
"__wchb": SimTypeArray(ALL_TYPES["char"], length=4),
|
|
2422
|
+
}
|
|
2423
|
+
),
|
|
2424
|
+
},
|
|
2425
|
+
name="__mbstate_t",
|
|
2426
|
+
),
|
|
2427
|
+
"_IO_codecvt": SimStruct(
|
|
2428
|
+
{
|
|
2429
|
+
"__cd_in": SimStruct({}, name="_IO_iconv_t"),
|
|
2430
|
+
"__cd_out": SimStruct({}, name="_IO_iconv_t"),
|
|
2431
|
+
},
|
|
2432
|
+
name="_IO_codecvt",
|
|
2433
|
+
),
|
|
2434
|
+
"argp_option": SimStruct(
|
|
2435
|
+
{
|
|
2436
|
+
"name": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2437
|
+
"key": ALL_TYPES["int"],
|
|
2438
|
+
"arg": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2439
|
+
"flags": ALL_TYPES["int"],
|
|
2440
|
+
"doc": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2441
|
+
"group": ALL_TYPES["int"],
|
|
2442
|
+
},
|
|
2443
|
+
name="argp_option",
|
|
2444
|
+
),
|
|
2445
|
+
"argp_child": SimStruct(
|
|
2446
|
+
{
|
|
2447
|
+
"argp": SimStruct({}, name="argp"),
|
|
2448
|
+
"flags": ALL_TYPES["int"],
|
|
2449
|
+
"header": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2450
|
+
"group": ALL_TYPES["int"],
|
|
2451
|
+
},
|
|
2452
|
+
name="argp_child",
|
|
2453
|
+
),
|
|
2454
|
+
"argp_parser_t": SimTypeFunction(
|
|
2455
|
+
(
|
|
2456
|
+
ALL_TYPES["int"],
|
|
2457
|
+
SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2458
|
+
SimTypePointer(SimStruct({}, name="argp_state")),
|
|
2459
|
+
),
|
|
2460
|
+
ALL_TYPES["error_t"],
|
|
2461
|
+
arg_names=("__key", "__arg", "__state"),
|
|
2462
|
+
),
|
|
2463
|
+
}
|
|
2464
|
+
|
|
2465
|
+
|
|
2466
|
+
GLIBC_INTERNAL_TYPES.update(
|
|
2467
|
+
{
|
|
2468
|
+
"_obstack_chunk": SimStruct(
|
|
2469
|
+
{
|
|
2470
|
+
"limit": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2471
|
+
"prev": SimTypePointer(SimStruct({}, name="_obstack_chunk", pack=False, align=None)),
|
|
2472
|
+
"contents": SimTypeArray(ALL_TYPES["char"], length=4, label="char"),
|
|
2473
|
+
},
|
|
2474
|
+
name="_obstack_chunk",
|
|
2475
|
+
),
|
|
2476
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/misc/search.h#L69
|
|
2477
|
+
"_ENTRY": SimStruct(
|
|
2478
|
+
{
|
|
2479
|
+
"key": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2480
|
+
"data": SimTypePointer(ALL_TYPES["void"], label="void *"),
|
|
2481
|
+
},
|
|
2482
|
+
name="_ENTRY",
|
|
2483
|
+
),
|
|
2484
|
+
# https://man7.org/linux/man-pages/man7/sigevent.7.html
|
|
2485
|
+
"sigevent": SimStruct(
|
|
2486
|
+
{
|
|
2487
|
+
"sigev_notify": ALL_TYPES["int"],
|
|
2488
|
+
"sigev_signo": ALL_TYPES["int"],
|
|
2489
|
+
"sigev_value": GLIBC_INTERNAL_TYPES["sigval"],
|
|
2490
|
+
"sigev_notify_function": SimTypeFunction(
|
|
2491
|
+
(GLIBC_INTERNAL_TYPES["sigval"],),
|
|
2492
|
+
SimTypePointer(ALL_TYPES["void"], label="void *"),
|
|
2493
|
+
),
|
|
2494
|
+
"sigev_notify_attributes": SimTypePointer(ALL_TYPES["void"], label="void *"),
|
|
2495
|
+
"sigev_notify_thread_id": ALL_TYPES["pid_t"],
|
|
2496
|
+
},
|
|
2497
|
+
name="sigevent",
|
|
2498
|
+
),
|
|
2499
|
+
"in_addr": SimStruct({"s_addr": ALL_TYPES["uint32_t"]}, name="in_addr"),
|
|
2500
|
+
"_IO_marker": SimStruct(
|
|
2501
|
+
{
|
|
2502
|
+
"_next": SimTypePointer(SimStruct({}, name="_IO_marker"), label="struct _IO_marker *"),
|
|
2503
|
+
"_sbuf": SimTypePointer(SimStruct({}, name="FILE"), label="FILE *"),
|
|
2504
|
+
"_pos": ALL_TYPES["int"],
|
|
2505
|
+
},
|
|
2506
|
+
name="_IO_marker",
|
|
2507
|
+
),
|
|
2508
|
+
"_IO_iconv_t": SimStruct(
|
|
2509
|
+
{
|
|
2510
|
+
# TODO: Define __gconv structs
|
|
2511
|
+
"step": SimTypePointer(SimStruct({}, name="__gconv_step"), label="struct __gconv_step *"),
|
|
2512
|
+
"step_data": SimStruct({}, name="__gconv_step_data"),
|
|
2513
|
+
},
|
|
2514
|
+
name="_IO_iconv_t",
|
|
2515
|
+
),
|
|
2516
|
+
"_IO_codecvt": GLIBC_INTERNAL_TYPES["_IO_codecvt"],
|
|
2517
|
+
"_IO_lock_t": SimStruct({}, name="pthread_mutex_t"),
|
|
2518
|
+
"__mbstate_t": GLIBC_INTERNAL_TYPES["__mbstate_t"],
|
|
2519
|
+
"_IO_wide_data": SimStruct(
|
|
2520
|
+
{
|
|
2521
|
+
"_IO_read_ptr": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
|
|
2522
|
+
"_IO_read_end": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
|
|
2523
|
+
"_IO_read_base": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
|
|
2524
|
+
"_IO_write_base": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
|
|
2525
|
+
"_IO_write_ptr": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
|
|
2526
|
+
"_IO_write_end": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
|
|
2527
|
+
"_IO_buf_base": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
|
|
2528
|
+
"_IO_buf_end": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
|
|
2529
|
+
"_IO_save_base": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
|
|
2530
|
+
"_IO_backup_base": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
|
|
2531
|
+
"_IO_save_end": SimTypePointer(ALL_TYPES["wchar_t"], label="wchar_t *"),
|
|
2532
|
+
"_IO_state": GLIBC_INTERNAL_TYPES["__mbstate_t"],
|
|
2533
|
+
"_IO_last_state": GLIBC_INTERNAL_TYPES["__mbstate_t"],
|
|
2534
|
+
"_codecvt": GLIBC_INTERNAL_TYPES["_IO_codecvt"],
|
|
2535
|
+
"_shortbuf": SimTypeArray(ALL_TYPES["wchar_t"], length=1, label="wchar_t[1]"),
|
|
2536
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/libio/libioP.h#L293
|
|
2537
|
+
"_wide_vtable": SimStruct({}, name="_IO_jump_t"),
|
|
2538
|
+
},
|
|
2539
|
+
name="_IO_wide_data",
|
|
2540
|
+
),
|
|
2541
|
+
"argp": SimStruct(
|
|
2542
|
+
{
|
|
2543
|
+
"options": SimTypePointer(GLIBC_INTERNAL_TYPES["argp_option"], label="struct argp_option *"),
|
|
2544
|
+
"parser": GLIBC_INTERNAL_TYPES["argp_parser_t"],
|
|
2545
|
+
"args_doc": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2546
|
+
"doc": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2547
|
+
"children": SimTypePointer(GLIBC_INTERNAL_TYPES["argp_child"], label="struct argp_child *"),
|
|
2548
|
+
"help_filter": SimTypeFunction(
|
|
2549
|
+
(
|
|
2550
|
+
ALL_TYPES["int"],
|
|
2551
|
+
SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2552
|
+
SimTypePointer(ALL_TYPES["void"], label="void *"),
|
|
2553
|
+
),
|
|
2554
|
+
SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2555
|
+
arg_names=("__key", "__text", "__input"),
|
|
2556
|
+
),
|
|
2557
|
+
"argp_domain": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2558
|
+
},
|
|
2559
|
+
name="argp",
|
|
2560
|
+
),
|
|
2561
|
+
"timeval": SimStruct(
|
|
2562
|
+
{
|
|
2563
|
+
# TODO: This should be architecture dependent
|
|
2564
|
+
"tv_sec": ALL_TYPES["__time_t"],
|
|
2565
|
+
"tv_usec": ALL_TYPES["__suseconds_t"],
|
|
2566
|
+
},
|
|
2567
|
+
name="timeval",
|
|
2568
|
+
),
|
|
2569
|
+
# https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/time/bits/types/struct_timespec.h#L11
|
|
2570
|
+
"timespec": SimStruct(
|
|
2571
|
+
{
|
|
2572
|
+
# TODO: This should be architecture dependent
|
|
2573
|
+
"tv_sec": ALL_TYPES["__time_t"],
|
|
2574
|
+
"tv_nsec": ALL_TYPES["long int"],
|
|
2575
|
+
# TODO: This should be architecture dependent (byte order)
|
|
2576
|
+
"_pad0": ALL_TYPES["uint32_t"],
|
|
2577
|
+
},
|
|
2578
|
+
name="timeval",
|
|
2579
|
+
),
|
|
2580
|
+
# https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/bits/utmp.h#L50
|
|
2581
|
+
"exit_status": SimStruct(
|
|
2582
|
+
{
|
|
2583
|
+
"e_termination": ALL_TYPES["short int"],
|
|
2584
|
+
"e_exit": ALL_TYPES["short int"],
|
|
2585
|
+
},
|
|
2586
|
+
name="exit_status",
|
|
2587
|
+
),
|
|
2588
|
+
}
|
|
2589
|
+
)
|
|
2590
|
+
ALL_TYPES.update(GLIBC_INTERNAL_TYPES)
|
|
2591
|
+
|
|
2592
|
+
GLIBC_TYPES = {
|
|
2593
|
+
# DO NOT use the glibc manual to define these structs! It is not accurate and does
|
|
2594
|
+
# not contain all fields or even the fields in the correct order!. Instead, you
|
|
2595
|
+
# need to use the glibc source and actually find the struct. In most cases,
|
|
2596
|
+
# a link to the struct is provided.
|
|
2597
|
+
# ABI-defined, for x86_64 it can be found here in sec 3.34:
|
|
2598
|
+
# https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-1.0.pdf
|
|
2599
|
+
# TODO: This should be architecture dependent
|
|
2600
|
+
"va_list": SimTypeArray(
|
|
2601
|
+
SimStruct(
|
|
2602
|
+
{
|
|
2603
|
+
"gp_offset": ALL_TYPES["unsigned int"],
|
|
2604
|
+
"fp_offset": ALL_TYPES["unsigned int"],
|
|
2605
|
+
"overflow_arg_area": SimTypePointer(ALL_TYPES["void"], label="void *"),
|
|
2606
|
+
"reg_save_area": SimTypePointer(ALL_TYPES["void"], label="void *"),
|
|
2607
|
+
},
|
|
2608
|
+
name="va_list",
|
|
2609
|
+
),
|
|
2610
|
+
length=1,
|
|
2611
|
+
label="va_list[1]",
|
|
2612
|
+
),
|
|
2613
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/malloc/malloc.h#L82
|
|
2614
|
+
"mallinfo": SimStruct(
|
|
2615
|
+
{
|
|
2616
|
+
"arena": ALL_TYPES["int"],
|
|
2617
|
+
"ordblks": ALL_TYPES["int"],
|
|
2618
|
+
"smblks": ALL_TYPES["int"],
|
|
2619
|
+
"hblks": ALL_TYPES["int"],
|
|
2620
|
+
"hblkhd": ALL_TYPES["int"],
|
|
2621
|
+
"usmblks": ALL_TYPES["int"],
|
|
2622
|
+
"fsmblks": ALL_TYPES["int"],
|
|
2623
|
+
"uordblks": ALL_TYPES["int"],
|
|
2624
|
+
"fordblks": ALL_TYPES["int"],
|
|
2625
|
+
"keepcost": ALL_TYPES["int"],
|
|
2626
|
+
},
|
|
2627
|
+
name="mallinfo",
|
|
2628
|
+
),
|
|
2629
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/malloc/malloc.h#L99
|
|
2630
|
+
"mallinfo2": SimStruct(
|
|
2631
|
+
{
|
|
2632
|
+
"arena": ALL_TYPES["size_t"],
|
|
2633
|
+
"ordblks": ALL_TYPES["size_t"],
|
|
2634
|
+
"smblks": ALL_TYPES["size_t"],
|
|
2635
|
+
"hblks": ALL_TYPES["size_t"],
|
|
2636
|
+
"hblkhd": ALL_TYPES["size_t"],
|
|
2637
|
+
"usmblks": ALL_TYPES["size_t"],
|
|
2638
|
+
"fsmblks": ALL_TYPES["size_t"],
|
|
2639
|
+
"uordblks": ALL_TYPES["size_t"],
|
|
2640
|
+
"fordblks": ALL_TYPES["size_t"],
|
|
2641
|
+
"keepcost": ALL_TYPES["size_t"],
|
|
2642
|
+
},
|
|
2643
|
+
name="mallinfo2",
|
|
2644
|
+
),
|
|
2645
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/malloc/obstack.h#L153
|
|
2646
|
+
"obstack": SimStruct(
|
|
2647
|
+
{
|
|
2648
|
+
"chunk_size": SimTypeLong(signed=True, label="long"),
|
|
2649
|
+
"chunk": GLIBC_INTERNAL_TYPES["_obstack_chunk"],
|
|
2650
|
+
"object_base": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2651
|
+
"next_free": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2652
|
+
"chunk_limit": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2653
|
+
"temp": SimUnion(
|
|
2654
|
+
{
|
|
2655
|
+
"tempint": ALL_TYPES["ptrdiff_t"],
|
|
2656
|
+
"tempptr": SimTypePointer(ALL_TYPES["void"], label="void *"),
|
|
2657
|
+
}
|
|
2658
|
+
),
|
|
2659
|
+
"alignment_mask": ALL_TYPES["int"],
|
|
2660
|
+
"chunkfun": SimTypeFunction(
|
|
2661
|
+
(SimTypePointer(ALL_TYPES["void"], label="void *"), ALL_TYPES["long"]),
|
|
2662
|
+
SimTypePointer(ALL_TYPES["_obstack_chunk"], label="struct _obstack_chunk *"),
|
|
2663
|
+
),
|
|
2664
|
+
"freefun": SimTypeFunction(
|
|
2665
|
+
(
|
|
2666
|
+
SimTypePointer(ALL_TYPES["void"], label="void *"),
|
|
2667
|
+
SimTypePointer(ALL_TYPES["_obstack_chunk"], label="_obstack_chunk *"),
|
|
2668
|
+
),
|
|
2669
|
+
ALL_TYPES["void"],
|
|
2670
|
+
),
|
|
2671
|
+
"extra_arg": SimTypePointer(ALL_TYPES["void"], label="void *"),
|
|
2672
|
+
"use_extra_arg": SimTypeNumOffset(1, signed=False, label="unsigned"),
|
|
2673
|
+
"maybe_extra_object": SimTypeNumOffset(1, signed=False, label="unsigned"),
|
|
2674
|
+
"alloc_failed": SimTypeNumOffset(1, signed=False, label="unsigned"),
|
|
2675
|
+
},
|
|
2676
|
+
name="obstack",
|
|
2677
|
+
),
|
|
2678
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/locale/locale.h#L51
|
|
2679
|
+
"lconv": SimStruct(
|
|
2680
|
+
{
|
|
2681
|
+
"decimal_point": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2682
|
+
"thousands_sep": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2683
|
+
"grouping": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2684
|
+
"int_curr_symbol": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2685
|
+
"currency_symbol": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2686
|
+
"mon_decimal_point": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2687
|
+
"mon_thousands_sep": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2688
|
+
"mon_grouping": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2689
|
+
"positive_sign": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2690
|
+
"negative_sign": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2691
|
+
"int_frac_digits": ALL_TYPES["char"],
|
|
2692
|
+
"frac_digits": ALL_TYPES["char"],
|
|
2693
|
+
"p_cs_precedes": ALL_TYPES["char"],
|
|
2694
|
+
"p_sep_by_space": ALL_TYPES["char"],
|
|
2695
|
+
"n_cs_precedes": ALL_TYPES["char"],
|
|
2696
|
+
"n_sep_by_space": ALL_TYPES["char"],
|
|
2697
|
+
"p_sign_posn": ALL_TYPES["char"],
|
|
2698
|
+
"n_sign_posn": ALL_TYPES["char"],
|
|
2699
|
+
"int_p_cs_precedes": ALL_TYPES["char"],
|
|
2700
|
+
"int_p_sep_by_space": ALL_TYPES["char"],
|
|
2701
|
+
"int_n_cs_precedes": ALL_TYPES["char"],
|
|
2702
|
+
"int_n_sep_by_space": ALL_TYPES["char"],
|
|
2703
|
+
"int_p_sign_posn": ALL_TYPES["char"],
|
|
2704
|
+
"int_n_sign_posn": ALL_TYPES["char"],
|
|
2705
|
+
},
|
|
2706
|
+
name="lconv",
|
|
2707
|
+
),
|
|
2708
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/misc/search.h#L97
|
|
2709
|
+
"hsearch_data": SimStruct(
|
|
2710
|
+
{
|
|
2711
|
+
"table": SimTypePointer(ALL_TYPES["_ENTRY"], label="struct _ENTRY *"),
|
|
2712
|
+
"size": ALL_TYPES["unsigned int"],
|
|
2713
|
+
"filled": ALL_TYPES["unsigned int"],
|
|
2714
|
+
},
|
|
2715
|
+
name="hsearch_data",
|
|
2716
|
+
),
|
|
2717
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/libio/bits/types/struct_FILE.h#L49
|
|
2718
|
+
"FILE_t": SimStruct(
|
|
2719
|
+
{
|
|
2720
|
+
"_flags": ALL_TYPES["int"],
|
|
2721
|
+
"_IO_read_ptr": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2722
|
+
"_IO_read_end": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2723
|
+
"_IO_read_base": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2724
|
+
"_IO_write_base": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2725
|
+
"_IO_write_ptr": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2726
|
+
"_IO_write_end": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2727
|
+
"_IO_buf_base": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2728
|
+
"_IO_buf_end": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2729
|
+
"_IO_save_base": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2730
|
+
"_IO_backup_base": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2731
|
+
"_IO_save_end": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2732
|
+
"_markers": SimTypePointer(ALL_TYPES["_IO_marker"]),
|
|
2733
|
+
"_chain": SimTypePointer(SimStruct({}, name="_IO_FILE"), label="struct _IO_FILE *"),
|
|
2734
|
+
"_fileno": ALL_TYPES["int"],
|
|
2735
|
+
"_flags2": ALL_TYPES["int"],
|
|
2736
|
+
"_old_offset": ALL_TYPES["__off_t"],
|
|
2737
|
+
"_cur_column": ALL_TYPES["unsigned short"],
|
|
2738
|
+
"_vtable_offset": ALL_TYPES["signed char"],
|
|
2739
|
+
"_shortbuf": SimTypeArray(ALL_TYPES["char"], length=1, label="char[1]"),
|
|
2740
|
+
"_lock": SimTypePointer(ALL_TYPES["_IO_lock_t"]),
|
|
2741
|
+
"_offset": ALL_TYPES["__off64_t"],
|
|
2742
|
+
"_codecvt": SimTypePointer(ALL_TYPES["_IO_codecvt"], label="struct _IO_codecvt *"),
|
|
2743
|
+
"_wide_data": SimTypePointer(ALL_TYPES["_IO_wide_data"], label="struct _IO_wide_data *"),
|
|
2744
|
+
"_freeres_list": SimTypePointer(SimStruct({}, name="_IO_FILE"), label="struct _IO_FILE *"),
|
|
2745
|
+
"__pad5": ALL_TYPES["size_t"],
|
|
2746
|
+
"_mode": ALL_TYPES["int"],
|
|
2747
|
+
"_unused2": SimTypeArray(
|
|
2748
|
+
ALL_TYPES["char"],
|
|
2749
|
+
length=20,
|
|
2750
|
+
label="char[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)]",
|
|
2751
|
+
),
|
|
2752
|
+
},
|
|
2753
|
+
name="FILE_t",
|
|
2754
|
+
),
|
|
2755
|
+
"FILE": SimStruct({}, name="FILE"),
|
|
2756
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/stdio-common/printf.h#L34
|
|
2757
|
+
"printf_info": SimStruct(
|
|
2758
|
+
{
|
|
2759
|
+
"prec": ALL_TYPES["int"],
|
|
2760
|
+
"width": ALL_TYPES["int"],
|
|
2761
|
+
"spec": ALL_TYPES["wchar_t"],
|
|
2762
|
+
"is_long_double": SimTypeNumOffset(1, signed=False, label="unsigned int"),
|
|
2763
|
+
"is_short": SimTypeNumOffset(1, signed=False, label="unsigned int"),
|
|
2764
|
+
"is_long": SimTypeNumOffset(1, signed=False, label="unsigned int"),
|
|
2765
|
+
"alt": SimTypeNumOffset(1, signed=False, label="unsigned int"),
|
|
2766
|
+
"space": SimTypeNumOffset(1, signed=False, label="unsigned int"),
|
|
2767
|
+
"left": SimTypeNumOffset(1, signed=False, label="unsigned int"),
|
|
2768
|
+
"showsign": SimTypeNumOffset(1, signed=False, label="unsigned int"),
|
|
2769
|
+
"group": SimTypeNumOffset(1, signed=False, label="unsigned int"),
|
|
2770
|
+
"extra": SimTypeNumOffset(1, signed=False, label="unsigned int"),
|
|
2771
|
+
"is_char": SimTypeNumOffset(1, signed=False, label="unsigned int"),
|
|
2772
|
+
"wide": SimTypeNumOffset(1, signed=False, label="unsigned int"),
|
|
2773
|
+
"i18n": SimTypeNumOffset(1, signed=False, label="unsigned int"),
|
|
2774
|
+
"is_binary128": SimTypeNumOffset(1, signed=False, label="unsigned int"),
|
|
2775
|
+
"__pad": SimTypeNumOffset(3, signed=False, label="unsigned int"),
|
|
2776
|
+
"user": ALL_TYPES["unsigned short int"],
|
|
2777
|
+
"pad": ALL_TYPES["wchar_t"],
|
|
2778
|
+
},
|
|
2779
|
+
name="printf_info",
|
|
2780
|
+
),
|
|
2781
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/rt/aio.h#L34
|
|
2782
|
+
"aiocb": SimStruct(
|
|
2783
|
+
{
|
|
2784
|
+
"aio_filedes": ALL_TYPES["int"],
|
|
2785
|
+
"aio_lio_opcode": ALL_TYPES["int"],
|
|
2786
|
+
"aio_reqprio": ALL_TYPES["int"],
|
|
2787
|
+
"aio_buf": SimTypePointer(ALL_TYPES["void"], label="void *"),
|
|
2788
|
+
"aio_nbytes": ALL_TYPES["size_t"],
|
|
2789
|
+
"aio_sigevent": ALL_TYPES["sigevent"],
|
|
2790
|
+
"__next_prio": SimTypePointer(SimStruct({}, name="aiocb"), label="struct aiocb *"),
|
|
2791
|
+
"__abs_prio": ALL_TYPES["int"],
|
|
2792
|
+
"__policy": ALL_TYPES["int"],
|
|
2793
|
+
"__error_code": ALL_TYPES["int"],
|
|
2794
|
+
"__return_value": ALL_TYPES["ssize_t"],
|
|
2795
|
+
# TODO: This should be architecture dependent
|
|
2796
|
+
"aio_offset": ALL_TYPES["off_t"],
|
|
2797
|
+
"__glibc_reserved": SimTypeArray(ALL_TYPES["char"], length=32, label="char[32]"),
|
|
2798
|
+
},
|
|
2799
|
+
name="aiocb",
|
|
2800
|
+
),
|
|
2801
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/rt/aio.h#L62
|
|
2802
|
+
"aiocb64": SimStruct(
|
|
2803
|
+
{
|
|
2804
|
+
"aio_filedes": ALL_TYPES["int"],
|
|
2805
|
+
"aio_lio_opcode": ALL_TYPES["int"],
|
|
2806
|
+
"aio_reqprio": ALL_TYPES["int"],
|
|
2807
|
+
"aio_buf": SimTypePointer(ALL_TYPES["void"], label="void *"),
|
|
2808
|
+
"aio_nbytes": ALL_TYPES["size_t"],
|
|
2809
|
+
"aio_sigevent": ALL_TYPES["sigevent"],
|
|
2810
|
+
"__next_prio": SimTypePointer(SimStruct({}, name="aiocb"), label="struct aiocb *"),
|
|
2811
|
+
"__abs_prio": ALL_TYPES["int"],
|
|
2812
|
+
"__policy": ALL_TYPES["int"],
|
|
2813
|
+
"__error_code": ALL_TYPES["int"],
|
|
2814
|
+
"__return_value": ALL_TYPES["ssize_t"],
|
|
2815
|
+
"aio_offset": ALL_TYPES["off64_t"],
|
|
2816
|
+
"__glibc_reserved": SimTypeArray(ALL_TYPES["char"], length=32, label="char[32]"),
|
|
2817
|
+
},
|
|
2818
|
+
name="aiocb64",
|
|
2819
|
+
),
|
|
2820
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/rt/aio.h#L86
|
|
2821
|
+
"aioinit": SimStruct(
|
|
2822
|
+
{
|
|
2823
|
+
"aio_threads": ALL_TYPES["int"],
|
|
2824
|
+
"aio_num": ALL_TYPES["int"],
|
|
2825
|
+
"aio_locks": ALL_TYPES["int"],
|
|
2826
|
+
"aio_debug": ALL_TYPES["int"],
|
|
2827
|
+
"aio_numusers": ALL_TYPES["int"],
|
|
2828
|
+
"aio_idle_time": ALL_TYPES["int"],
|
|
2829
|
+
"aio_reserved": ALL_TYPES["int"],
|
|
2830
|
+
},
|
|
2831
|
+
name="aioinit",
|
|
2832
|
+
),
|
|
2833
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/dirent.h#L23
|
|
2834
|
+
"dirent": SimStruct(
|
|
2835
|
+
{
|
|
2836
|
+
"d_ino": ALL_TYPES["ino_t"],
|
|
2837
|
+
"d_reclen": ALL_TYPES["unsigned short int"],
|
|
2838
|
+
"d_type": ALL_TYPES["unsigned char"],
|
|
2839
|
+
"d_namelen": ALL_TYPES["unsigned char"],
|
|
2840
|
+
"d_name": SimTypeArray(ALL_TYPES["char"], length=1, label="char[1]"),
|
|
2841
|
+
},
|
|
2842
|
+
name="dirent",
|
|
2843
|
+
),
|
|
2844
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/dirent.h#L39
|
|
2845
|
+
"dirent64": SimStruct(
|
|
2846
|
+
{
|
|
2847
|
+
"d_ino": ALL_TYPES["ino64_t"],
|
|
2848
|
+
"d_reclen": ALL_TYPES["unsigned short int"],
|
|
2849
|
+
"d_type": ALL_TYPES["unsigned char"],
|
|
2850
|
+
"d_namelen": ALL_TYPES["unsigned char"],
|
|
2851
|
+
"d_name": SimTypeArray(ALL_TYPES["char"], length=1, label="char[1]"),
|
|
2852
|
+
},
|
|
2853
|
+
name="dirent64",
|
|
2854
|
+
),
|
|
2855
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/stat.h#L31
|
|
2856
|
+
"stat": SimStruct(
|
|
2857
|
+
{
|
|
2858
|
+
"st_mode": ALL_TYPES["__mode_t"],
|
|
2859
|
+
# TODO: This should be architecture dependent
|
|
2860
|
+
"st_ino": ALL_TYPES["__ino_t"],
|
|
2861
|
+
"st_dev": ALL_TYPES["__dev_t"],
|
|
2862
|
+
"st_nlink": ALL_TYPES["__nlink_t"],
|
|
2863
|
+
"st_uid": ALL_TYPES["__uid_t"],
|
|
2864
|
+
"st_gid": ALL_TYPES["__gid_t"],
|
|
2865
|
+
# TODO: This should be architecture dependent
|
|
2866
|
+
"st_size": ALL_TYPES["__off_t"],
|
|
2867
|
+
"st_atime": ALL_TYPES["__time_t"],
|
|
2868
|
+
"st_mtime": ALL_TYPES["__time_t"],
|
|
2869
|
+
"st_ctime": ALL_TYPES["__time_t"],
|
|
2870
|
+
},
|
|
2871
|
+
name="stat",
|
|
2872
|
+
),
|
|
2873
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/stat.h#L86
|
|
2874
|
+
"stat64": SimStruct(
|
|
2875
|
+
{
|
|
2876
|
+
"st_mode": ALL_TYPES["__mode_t"],
|
|
2877
|
+
# TODO: This should be architecture dependent
|
|
2878
|
+
"st_ino": ALL_TYPES["__ino64_t"],
|
|
2879
|
+
"st_dev": ALL_TYPES["__dev_t"],
|
|
2880
|
+
"st_nlink": ALL_TYPES["__nlink_t"],
|
|
2881
|
+
"st_uid": ALL_TYPES["__uid_t"],
|
|
2882
|
+
"st_gid": ALL_TYPES["__gid_t"],
|
|
2883
|
+
# TODO: This should be architecture dependent
|
|
2884
|
+
"st_size": ALL_TYPES["__off64_t"],
|
|
2885
|
+
"st_atime": ALL_TYPES["__time_t"],
|
|
2886
|
+
"st_mtime": ALL_TYPES["__time_t"],
|
|
2887
|
+
"st_ctime": ALL_TYPES["__time_t"],
|
|
2888
|
+
},
|
|
2889
|
+
name="stat64",
|
|
2890
|
+
),
|
|
2891
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/io/utime.h#L36
|
|
2892
|
+
"utimbuf": SimStruct(
|
|
2893
|
+
{
|
|
2894
|
+
# TODO: This should be architecture dependent
|
|
2895
|
+
"actime": ALL_TYPES["__time_t"],
|
|
2896
|
+
"modtime": ALL_TYPES["__time_t"],
|
|
2897
|
+
},
|
|
2898
|
+
name="utimbuf",
|
|
2899
|
+
),
|
|
2900
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/socket.h#L152
|
|
2901
|
+
"sockaddr": SimStruct(
|
|
2902
|
+
{
|
|
2903
|
+
"sin_family": ALL_TYPES["sa_family_t"],
|
|
2904
|
+
"sa_data": SimTypeArray(ALL_TYPES["char"], length=14, label="char[14]"),
|
|
2905
|
+
},
|
|
2906
|
+
name="sockaddr",
|
|
2907
|
+
),
|
|
2908
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/inet/netinet/in.h#L245
|
|
2909
|
+
"sockaddr_in": SimStruct(
|
|
2910
|
+
{
|
|
2911
|
+
"sin_family": ALL_TYPES["sa_family_t"],
|
|
2912
|
+
"sin_port": ALL_TYPES["in_port_t"],
|
|
2913
|
+
"sin_addr": ALL_TYPES["in_addr"],
|
|
2914
|
+
"sin_zero": SimTypeArray(
|
|
2915
|
+
ALL_TYPES["unsigned char"],
|
|
2916
|
+
length=8,
|
|
2917
|
+
label=(
|
|
2918
|
+
"unsigned char[sizeof (struct sockaddr) - __SOCKADDR_COMMON_SIZE - "
|
|
2919
|
+
"sizeof (in_port_t) - sizeof (struct in_addr)]"
|
|
2920
|
+
),
|
|
2921
|
+
),
|
|
2922
|
+
},
|
|
2923
|
+
name="sockaddr_in",
|
|
2924
|
+
),
|
|
2925
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/sysdeps/gnu/net/if.h#L33
|
|
2926
|
+
"if_nameindex": SimStruct(
|
|
2927
|
+
{
|
|
2928
|
+
"if_index": ALL_TYPES["unsigned int"],
|
|
2929
|
+
"if_name": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2930
|
+
},
|
|
2931
|
+
name="if_nameindex",
|
|
2932
|
+
),
|
|
2933
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/resolv/netdb.h#L98
|
|
2934
|
+
"hostent": SimStruct(
|
|
2935
|
+
{
|
|
2936
|
+
"h_name": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2937
|
+
"h_aliases": SimTypePointer(SimTypePointer(ALL_TYPES["char"], label="char *"), label="char **"),
|
|
2938
|
+
"h_addrtype": ALL_TYPES["int"],
|
|
2939
|
+
"h_length": ALL_TYPES["int"],
|
|
2940
|
+
"h_addr_list": SimTypePointer(SimTypePointer(ALL_TYPES["char"], label="char *"), label="char **"),
|
|
2941
|
+
},
|
|
2942
|
+
name="hostent",
|
|
2943
|
+
),
|
|
2944
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/resolv/netdb.h#L255
|
|
2945
|
+
"servent": SimStruct(
|
|
2946
|
+
{
|
|
2947
|
+
"s_name": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2948
|
+
"s_aliases": SimTypePointer(SimTypePointer(ALL_TYPES["char"], label="char *"), label="char **"),
|
|
2949
|
+
"s_port": ALL_TYPES["int"],
|
|
2950
|
+
"s_proto": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2951
|
+
},
|
|
2952
|
+
name="servent",
|
|
2953
|
+
),
|
|
2954
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/resolv/netdb.h#L324
|
|
2955
|
+
"protoent": SimStruct(
|
|
2956
|
+
{
|
|
2957
|
+
"p_name": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2958
|
+
"p_aliases": SimTypePointer(SimTypePointer(ALL_TYPES["char"], label="char *"), label="char **"),
|
|
2959
|
+
"p_proto": ALL_TYPES["int"],
|
|
2960
|
+
},
|
|
2961
|
+
name="protoent",
|
|
2962
|
+
),
|
|
2963
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/netdb.h#L26
|
|
2964
|
+
"netent": SimStruct(
|
|
2965
|
+
{
|
|
2966
|
+
"n_name": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
2967
|
+
"n_aliases": SimTypePointer(SimTypePointer(ALL_TYPES["char"], label="char *"), label="char **"),
|
|
2968
|
+
"n_addrtype": ALL_TYPES["int"],
|
|
2969
|
+
"n_net": ALL_TYPES["uint32_t"],
|
|
2970
|
+
},
|
|
2971
|
+
name="netent",
|
|
2972
|
+
),
|
|
2973
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/termios.h#L111
|
|
2974
|
+
"termios": SimStruct(
|
|
2975
|
+
{
|
|
2976
|
+
"c_iflag": ALL_TYPES["tcflag_t"],
|
|
2977
|
+
"c_oflag": ALL_TYPES["tcflag_t"],
|
|
2978
|
+
"c_cflag": ALL_TYPES["tcflag_t"],
|
|
2979
|
+
"c_lflag": ALL_TYPES["tcflag_t"],
|
|
2980
|
+
"c_cc": SimTypeArray(ALL_TYPES["cc_t"], length=20, label="cc_t[20]"),
|
|
2981
|
+
"__ispeed": ALL_TYPES["speed_t"],
|
|
2982
|
+
"__ospeed": ALL_TYPES["speed_t"],
|
|
2983
|
+
},
|
|
2984
|
+
name="termios",
|
|
2985
|
+
),
|
|
2986
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/ioctl-types.h#L56
|
|
2987
|
+
"sgttyb": SimStruct(
|
|
2988
|
+
{
|
|
2989
|
+
"sg_ispeed": ALL_TYPES["char"],
|
|
2990
|
+
"sg_ospeed": ALL_TYPES["char"],
|
|
2991
|
+
"sg_erase": ALL_TYPES["char"],
|
|
2992
|
+
"sg_kill": ALL_TYPES["char"],
|
|
2993
|
+
"sg_flags": ALL_TYPES["short int"],
|
|
2994
|
+
},
|
|
2995
|
+
name="sgttyb",
|
|
2996
|
+
),
|
|
2997
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/ioctl-types.h#L70
|
|
2998
|
+
"winsize": SimStruct(
|
|
2999
|
+
{
|
|
3000
|
+
"ws_row": ALL_TYPES["unsigned short int"],
|
|
3001
|
+
"ws_col": ALL_TYPES["unsigned short int"],
|
|
3002
|
+
"ws_xpixel": ALL_TYPES["unsigned short int"],
|
|
3003
|
+
"ws_ypixel": ALL_TYPES["unsigned short int"],
|
|
3004
|
+
},
|
|
3005
|
+
name="winsize",
|
|
3006
|
+
),
|
|
3007
|
+
# This type is legitimately opaque
|
|
3008
|
+
"random_data": SimStruct({}),
|
|
3009
|
+
# This type is also legitimately opaque
|
|
3010
|
+
"drand48_data": SimStruct({}),
|
|
3011
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/posix/sys/times.h#L32
|
|
3012
|
+
"tms": SimStruct(
|
|
3013
|
+
{
|
|
3014
|
+
"tms_utime": ALL_TYPES["clock_t"],
|
|
3015
|
+
"tms_stime": ALL_TYPES["clock_t"],
|
|
3016
|
+
"tms_cutime": ALL_TYPES["clock_t"],
|
|
3017
|
+
"tms_cstime": ALL_TYPES["clock_t"],
|
|
3018
|
+
},
|
|
3019
|
+
name="tms",
|
|
3020
|
+
),
|
|
3021
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/time/sys/time.h#L52
|
|
3022
|
+
"timezone": SimStruct(
|
|
3023
|
+
{
|
|
3024
|
+
"tz_minuteswest": ALL_TYPES["int"],
|
|
3025
|
+
"tz_dsttime": ALL_TYPES["int"],
|
|
3026
|
+
},
|
|
3027
|
+
name="timezone",
|
|
3028
|
+
),
|
|
3029
|
+
"timeval": ALL_TYPES["timeval"],
|
|
3030
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/sysdeps/unix/sysv/linux/bits/timex.h#L26
|
|
3031
|
+
"timex": SimStruct(
|
|
3032
|
+
# TODO: This should be architecture dependent
|
|
3033
|
+
{
|
|
3034
|
+
"modes": ALL_TYPES["unsigned int"],
|
|
3035
|
+
"_pad0": ALL_TYPES["uint32_t"],
|
|
3036
|
+
"offset": ALL_TYPES["long long"],
|
|
3037
|
+
"freq": ALL_TYPES["long long"],
|
|
3038
|
+
"maxerror": ALL_TYPES["long long"],
|
|
3039
|
+
"esterror": ALL_TYPES["long long"],
|
|
3040
|
+
"status": ALL_TYPES["int"],
|
|
3041
|
+
"_pad1": ALL_TYPES["uint32_t"],
|
|
3042
|
+
"constant": ALL_TYPES["long long"],
|
|
3043
|
+
"precision": ALL_TYPES["long long"],
|
|
3044
|
+
"tolerance": ALL_TYPES["long long"],
|
|
3045
|
+
"time": ALL_TYPES["timeval"],
|
|
3046
|
+
"tick": ALL_TYPES["long long"],
|
|
3047
|
+
"ppsfreq": ALL_TYPES["long long"],
|
|
3048
|
+
"jitter": ALL_TYPES["long long"],
|
|
3049
|
+
"shift": ALL_TYPES["int"],
|
|
3050
|
+
"_pad2": ALL_TYPES["uint32_t"],
|
|
3051
|
+
"stabil": ALL_TYPES["long long"],
|
|
3052
|
+
"jitcnt": ALL_TYPES["long long"],
|
|
3053
|
+
"calcnt": ALL_TYPES["long long"],
|
|
3054
|
+
"errcnt": ALL_TYPES["long long"],
|
|
3055
|
+
"stbcnt": ALL_TYPES["long long"],
|
|
3056
|
+
"tai": ALL_TYPES["int"],
|
|
3057
|
+
"_pad3": SimTypeArray(ALL_TYPES["uint32_t"], length=11, label="int :32[11]"),
|
|
3058
|
+
},
|
|
3059
|
+
name="timex",
|
|
3060
|
+
),
|
|
3061
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/time/bits/types/struct_tm.h#L7
|
|
3062
|
+
"tm": SimStruct(
|
|
3063
|
+
{
|
|
3064
|
+
"tm_sec": ALL_TYPES["int"],
|
|
3065
|
+
"tm_min": ALL_TYPES["int"],
|
|
3066
|
+
"tm_hour": ALL_TYPES["int"],
|
|
3067
|
+
"tm_mday": ALL_TYPES["int"],
|
|
3068
|
+
"tm_mon": ALL_TYPES["int"],
|
|
3069
|
+
"tm_year": ALL_TYPES["int"],
|
|
3070
|
+
"tm_wday": ALL_TYPES["int"],
|
|
3071
|
+
"tm_yday": ALL_TYPES["int"],
|
|
3072
|
+
"tm_isdst": ALL_TYPES["int"],
|
|
3073
|
+
"tm_gmtoff": ALL_TYPES["long int"],
|
|
3074
|
+
"tm_zone": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
3075
|
+
},
|
|
3076
|
+
name="tm",
|
|
3077
|
+
),
|
|
3078
|
+
# https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/sysdeps/unix/sysv/linux/sys/timex.h#L30
|
|
3079
|
+
"ntptimeval": SimStruct(
|
|
3080
|
+
{
|
|
3081
|
+
"time": ALL_TYPES["timeval"],
|
|
3082
|
+
"maxerror": ALL_TYPES["long int"],
|
|
3083
|
+
"esterror": ALL_TYPES["long int"],
|
|
3084
|
+
"tai": ALL_TYPES["long int"],
|
|
3085
|
+
"__glibc_reserved1": ALL_TYPES["long int"],
|
|
3086
|
+
"__glibc_reserved2": ALL_TYPES["long int"],
|
|
3087
|
+
"__glibc_reserved3": ALL_TYPES["long int"],
|
|
3088
|
+
"__glibc_reserved4": ALL_TYPES["long int"],
|
|
3089
|
+
},
|
|
3090
|
+
name="ntptimeval",
|
|
3091
|
+
),
|
|
3092
|
+
# https://github.com/bminor/glibc/blob/a01a13601c95f5d111d25557656d09fe661cfc89/misc/bits/types/struct_iovec.h#L26
|
|
3093
|
+
"iovec": SimStruct(
|
|
3094
|
+
{
|
|
3095
|
+
"iov_base": SimTypePointer(ALL_TYPES["void"], label="void *"),
|
|
3096
|
+
"iov_len": ALL_TYPES["size_t"],
|
|
3097
|
+
}
|
|
3098
|
+
),
|
|
3099
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/time/sys/time.h#L130
|
|
3100
|
+
"itimerval": SimStruct(
|
|
3101
|
+
{
|
|
3102
|
+
"it_interval": ALL_TYPES["timeval"],
|
|
3103
|
+
"it_value": ALL_TYPES["timeval"],
|
|
3104
|
+
},
|
|
3105
|
+
name="itimerval",
|
|
3106
|
+
),
|
|
3107
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/resource/bits/types/struct_rusage.h#L33
|
|
3108
|
+
"rusage": SimStruct(
|
|
3109
|
+
{
|
|
3110
|
+
"ru_utime": ALL_TYPES["timeval"],
|
|
3111
|
+
"ru_stime": ALL_TYPES["timeval"],
|
|
3112
|
+
"ru_maxrss": ALL_TYPES["long int"],
|
|
3113
|
+
"ru_ixrss": ALL_TYPES["long int"],
|
|
3114
|
+
"ru_idrss": ALL_TYPES["long int"],
|
|
3115
|
+
"ru_isrss": ALL_TYPES["long int"],
|
|
3116
|
+
"ru_minflt": ALL_TYPES["long int"],
|
|
3117
|
+
"ru_majflt": ALL_TYPES["long int"],
|
|
3118
|
+
"ru_nswap": ALL_TYPES["long int"],
|
|
3119
|
+
"ru_inblock": ALL_TYPES["long int"],
|
|
3120
|
+
"ru_oublock": ALL_TYPES["long int"],
|
|
3121
|
+
"ru_msgsnd": ALL_TYPES["long int"],
|
|
3122
|
+
"ru_msgrcv": ALL_TYPES["long int"],
|
|
3123
|
+
"ru_nsignals": ALL_TYPES["long int"],
|
|
3124
|
+
"ru_nvcsw": ALL_TYPES["long int"],
|
|
3125
|
+
"ru_nivcsw": ALL_TYPES["long int"],
|
|
3126
|
+
},
|
|
3127
|
+
name="rusage",
|
|
3128
|
+
),
|
|
3129
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/resource/vtimes.c#L28
|
|
3130
|
+
"vtimes": SimStruct(
|
|
3131
|
+
{
|
|
3132
|
+
"vm_utime": ALL_TYPES["int"],
|
|
3133
|
+
"vm_stime": ALL_TYPES["int"],
|
|
3134
|
+
"vm_idsrss": ALL_TYPES["unsigned int"],
|
|
3135
|
+
"vm_ixrss": ALL_TYPES["unsigned int"],
|
|
3136
|
+
"vm_maxrss": ALL_TYPES["int"],
|
|
3137
|
+
"vm_maxflt": ALL_TYPES["int"],
|
|
3138
|
+
"vm_minflt": ALL_TYPES["int"],
|
|
3139
|
+
"vm_nswap": ALL_TYPES["int"],
|
|
3140
|
+
"vm_inblk": ALL_TYPES["int"],
|
|
3141
|
+
"vm_outblk": ALL_TYPES["int"],
|
|
3142
|
+
},
|
|
3143
|
+
name="vtimes",
|
|
3144
|
+
),
|
|
3145
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/sysdeps/unix/sysv/linux/bits/resource.h#L139
|
|
3146
|
+
"rlimit": SimStruct(
|
|
3147
|
+
{
|
|
3148
|
+
"rlim_cur": ALL_TYPES["rlim_t"],
|
|
3149
|
+
"rlim_max": ALL_TYPES["rlim_t"],
|
|
3150
|
+
},
|
|
3151
|
+
name="rlimit",
|
|
3152
|
+
),
|
|
3153
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/sysdeps/unix/sysv/linux/bits/resource.h#L148
|
|
3154
|
+
"rlimit64": SimStruct(
|
|
3155
|
+
{
|
|
3156
|
+
"rlim_cur": ALL_TYPES["rlim64_t"],
|
|
3157
|
+
"rlim_max": ALL_TYPES["rlim64_t"],
|
|
3158
|
+
},
|
|
3159
|
+
name="rlimit64",
|
|
3160
|
+
),
|
|
3161
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/types/struct_sched_param.h#L23
|
|
3162
|
+
"sched_param": SimStruct(
|
|
3163
|
+
{"sched_priority": ALL_TYPES["int"]},
|
|
3164
|
+
name="sched_param",
|
|
3165
|
+
),
|
|
3166
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/signal/bits/types/struct_sigstack.h#L23
|
|
3167
|
+
"sigstack": SimStruct(
|
|
3168
|
+
{
|
|
3169
|
+
"ss_sp": SimTypePointer(ALL_TYPES["void"], label="void *"),
|
|
3170
|
+
"ss_onstack": ALL_TYPES["int"],
|
|
3171
|
+
},
|
|
3172
|
+
name="sigstack",
|
|
3173
|
+
),
|
|
3174
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/posix/bits/getopt_ext.h#L50
|
|
3175
|
+
"option": SimStruct(
|
|
3176
|
+
{
|
|
3177
|
+
"name": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
3178
|
+
"has_arg": ALL_TYPES["int"],
|
|
3179
|
+
"flag": SimTypePointer(ALL_TYPES["int"], label="int *"),
|
|
3180
|
+
"val": ALL_TYPES["int"],
|
|
3181
|
+
},
|
|
3182
|
+
name="option",
|
|
3183
|
+
),
|
|
3184
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/argp/argp.h#L273
|
|
3185
|
+
"argp_state": SimStruct(
|
|
3186
|
+
{
|
|
3187
|
+
"root_argp": ALL_TYPES["argp"],
|
|
3188
|
+
"argc": ALL_TYPES["int"],
|
|
3189
|
+
"argv": SimTypePointer(SimTypePointer(ALL_TYPES["char"], label="char *"), label="char **"),
|
|
3190
|
+
"next": ALL_TYPES["int"],
|
|
3191
|
+
"flags": ALL_TYPES["unsigned"],
|
|
3192
|
+
"arg_num": ALL_TYPES["unsigned"],
|
|
3193
|
+
"quoted": ALL_TYPES["int"],
|
|
3194
|
+
"input": SimTypePointer(ALL_TYPES["void"], label="void *"),
|
|
3195
|
+
"child_inputs": SimTypePointer(SimTypePointer(ALL_TYPES["void"], label="void *"), label="void **"),
|
|
3196
|
+
"hook": SimTypePointer(ALL_TYPES["void"], label="void *"),
|
|
3197
|
+
"name": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
3198
|
+
"err_stream": SimStruct({}, name="FILE"),
|
|
3199
|
+
"pstate": SimTypePointer(ALL_TYPES["void"], label="void *"),
|
|
3200
|
+
},
|
|
3201
|
+
name="argp_state",
|
|
3202
|
+
),
|
|
3203
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/sysvipc/sys/sem.h#L40
|
|
3204
|
+
"sembuf": SimStruct(
|
|
3205
|
+
{
|
|
3206
|
+
"sem_num": ALL_TYPES["unsigned short int"],
|
|
3207
|
+
"sem_op": ALL_TYPES["short int"],
|
|
3208
|
+
"sem_flg": ALL_TYPES["short int"],
|
|
3209
|
+
},
|
|
3210
|
+
name="sembuf",
|
|
3211
|
+
),
|
|
3212
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/bits/utmp.h#L58
|
|
3213
|
+
"utmp": SimStruct(
|
|
3214
|
+
{
|
|
3215
|
+
"ut_type": ALL_TYPES["short int"],
|
|
3216
|
+
"ut_pid": ALL_TYPES["pid_t"],
|
|
3217
|
+
"ut_line": SimTypeArray(ALL_TYPES["char"], length=32, label="char[32]"),
|
|
3218
|
+
"ut_id": SimTypeArray(ALL_TYPES["char"], length=4, label="char[32]"),
|
|
3219
|
+
"ut_user": SimTypeArray(ALL_TYPES["char"], length=32, label="char[32]"),
|
|
3220
|
+
"ut_host": SimTypeArray(ALL_TYPES["char"], length=256, label="char[32]"),
|
|
3221
|
+
"ut_exit": ALL_TYPES["exit_status"],
|
|
3222
|
+
"ut_session": ALL_TYPES["long int"],
|
|
3223
|
+
"ut_tv": ALL_TYPES["timeval"],
|
|
3224
|
+
"ut_addr_v6": SimTypeArray(ALL_TYPES["int32_t"], length=4, label="int32_t[4]"),
|
|
3225
|
+
"__glibc_reserved": SimTypeArray(ALL_TYPES["char"], length=20, label="char[20]"),
|
|
3226
|
+
},
|
|
3227
|
+
name="utmp",
|
|
3228
|
+
),
|
|
3229
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/sysdeps/gnu/bits/utmpx.h#L55
|
|
3230
|
+
"utmpx": SimStruct(
|
|
3231
|
+
{
|
|
3232
|
+
"ut_type": ALL_TYPES["short int"],
|
|
3233
|
+
"ut_pid": ALL_TYPES["pid_t"],
|
|
3234
|
+
"ut_line": SimTypeArray(ALL_TYPES["char"], length=32, label="char[32]"),
|
|
3235
|
+
"ut_id": SimTypeArray(ALL_TYPES["char"], length=4, label="char[32]"),
|
|
3236
|
+
"ut_user": SimTypeArray(ALL_TYPES["char"], length=32, label="char[32]"),
|
|
3237
|
+
"ut_host": SimTypeArray(ALL_TYPES["char"], length=256, label="char[32]"),
|
|
3238
|
+
"ut_exit": ALL_TYPES["exit_status"],
|
|
3239
|
+
"ut_session": ALL_TYPES["long int"],
|
|
3240
|
+
"ut_tv": ALL_TYPES["timeval"],
|
|
3241
|
+
"ut_addr_v6": SimTypeArray(ALL_TYPES["int32_t"], length=4, label="int32_t[4]"),
|
|
3242
|
+
"__glibc_reserved": SimTypeArray(ALL_TYPES["char"], length=20, label="char[20]"),
|
|
3243
|
+
},
|
|
3244
|
+
name="utmx",
|
|
3245
|
+
),
|
|
3246
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/pwd/pwd.h#L49
|
|
3247
|
+
"passwd": SimStruct(
|
|
3248
|
+
{
|
|
3249
|
+
"pw_name": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
3250
|
+
"pw_passwd": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
3251
|
+
"pw_uid": ALL_TYPES["__uid_t"],
|
|
3252
|
+
"pw_gid": ALL_TYPES["__gid_t"],
|
|
3253
|
+
"pw_gecos": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
3254
|
+
"pw_dir": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
3255
|
+
"pw_shell": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
3256
|
+
},
|
|
3257
|
+
name="passwd",
|
|
3258
|
+
),
|
|
3259
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/grp/grp.h#L42
|
|
3260
|
+
"group": SimStruct(
|
|
3261
|
+
{
|
|
3262
|
+
"gr_name": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
3263
|
+
"gr_passwd": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
3264
|
+
"gr_gid": ALL_TYPES["__gid_t"],
|
|
3265
|
+
"gr_mem": SimTypePointer(SimTypePointer(ALL_TYPES["char"], label="char *"), label="char **"),
|
|
3266
|
+
},
|
|
3267
|
+
name="group",
|
|
3268
|
+
),
|
|
3269
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/posix/sys/utsname.h#L48
|
|
3270
|
+
"utsname": SimStruct(
|
|
3271
|
+
{
|
|
3272
|
+
"sysname": SimTypeArray(ALL_TYPES["char"], length=1024, label="char[1024]"),
|
|
3273
|
+
"nodename": SimTypeArray(ALL_TYPES["char"], length=1024, label="char[1024]"),
|
|
3274
|
+
"release": SimTypeArray(ALL_TYPES["char"], length=1024, label="char[1024]"),
|
|
3275
|
+
"version": SimTypeArray(ALL_TYPES["char"], length=1024, label="char[1024]"),
|
|
3276
|
+
"machine": SimTypeArray(ALL_TYPES["char"], length=1024, label="char[1024]"),
|
|
3277
|
+
"domain": SimTypeArray(ALL_TYPES["char"], length=1024, label="char[1024]"),
|
|
3278
|
+
},
|
|
3279
|
+
name="utsname",
|
|
3280
|
+
),
|
|
3281
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/misc/fstab.h#L57
|
|
3282
|
+
"fstab": SimStruct(
|
|
3283
|
+
{
|
|
3284
|
+
"fs_spec": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
3285
|
+
"fs_file": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
3286
|
+
"fs_vfstype": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
3287
|
+
"fs_mntops": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
3288
|
+
"fs_type": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
3289
|
+
"fs_freq": ALL_TYPES["int"],
|
|
3290
|
+
"fs_passno": ALL_TYPES["int"],
|
|
3291
|
+
},
|
|
3292
|
+
name="fstab",
|
|
3293
|
+
),
|
|
3294
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/misc/mntent.h#L51
|
|
3295
|
+
"mntent": SimStruct(
|
|
3296
|
+
{
|
|
3297
|
+
"mnt_fsname": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
3298
|
+
"mnt_dir": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
3299
|
+
"mnt_type": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
3300
|
+
"mnt_opts": SimTypePointer(ALL_TYPES["char"], label="char *"),
|
|
3301
|
+
"mnt_freq": ALL_TYPES["int"],
|
|
3302
|
+
"mnt_passno": ALL_TYPES["int"],
|
|
3303
|
+
},
|
|
3304
|
+
name="mntent",
|
|
3305
|
+
),
|
|
3306
|
+
# https://github.com/bminor/glibc/blob/2d5ec6692f5746ccb11db60976a6481ef8e9d74f/crypt/crypt.h#L43
|
|
3307
|
+
"crypt_data": SimStruct(
|
|
3308
|
+
{
|
|
3309
|
+
"keysched": SimTypeArray(ALL_TYPES["char"], length=16 * 8, label="char[16 * 8]"),
|
|
3310
|
+
"sb0": SimTypeArray(ALL_TYPES["char"], length=32768, label="char[32768]"),
|
|
3311
|
+
"sb1": SimTypeArray(ALL_TYPES["char"], length=32768, label="char[32768]"),
|
|
3312
|
+
"sb2": SimTypeArray(ALL_TYPES["char"], length=32768, label="char[32768]"),
|
|
3313
|
+
"sb3": SimTypeArray(ALL_TYPES["char"], length=32768, label="char[32768]"),
|
|
3314
|
+
"crypt_3_buf": SimTypeArray(ALL_TYPES["char"], length=14, label="char[14]"),
|
|
3315
|
+
"current_salt": SimTypeArray(ALL_TYPES["char"], length=2, label="char[2]"),
|
|
3316
|
+
"current_saltbits": ALL_TYPES["long int"],
|
|
3317
|
+
"direction": ALL_TYPES["int"],
|
|
3318
|
+
"initialized": ALL_TYPES["int"],
|
|
3319
|
+
},
|
|
3320
|
+
name="crypt_data",
|
|
3321
|
+
),
|
|
3322
|
+
}
|
|
3323
|
+
ALL_TYPES.update(GLIBC_TYPES)
|
|
3324
|
+
|
|
3325
|
+
|
|
3326
|
+
def _make_scope(predefined_types=None):
|
|
3327
|
+
"""
|
|
3328
|
+
Generate CParser scope_stack argument to parse method
|
|
3329
|
+
"""
|
|
3330
|
+
all_types = ChainMap(predefined_types or {}, ALL_TYPES)
|
|
3331
|
+
scope = {}
|
|
3332
|
+
for ty in all_types:
|
|
3333
|
+
if ty in BASIC_TYPES:
|
|
3334
|
+
continue
|
|
3335
|
+
if " " in ty:
|
|
3336
|
+
continue
|
|
3337
|
+
|
|
3338
|
+
typ = all_types[ty]
|
|
3339
|
+
if type(typ) is TypeRef:
|
|
3340
|
+
typ = typ.type
|
|
3341
|
+
if isinstance(typ, (SimTypeFunction, SimTypeString, SimTypeWString)):
|
|
3342
|
+
continue
|
|
3343
|
+
|
|
3344
|
+
scope[ty] = True
|
|
3345
|
+
return [scope]
|
|
3346
|
+
|
|
3347
|
+
|
|
3348
|
+
def register_types(types):
|
|
3349
|
+
"""
|
|
3350
|
+
Pass in some types and they will be registered to the global type store.
|
|
3351
|
+
|
|
3352
|
+
The argument may be either a mapping from name to SimType, or a plain SimType.
|
|
3353
|
+
The plain SimType must be either a struct or union type with a name present.
|
|
3354
|
+
|
|
3355
|
+
>>> register_types(parse_types("typedef int x; typedef float y;"))
|
|
3356
|
+
>>> register_types(parse_type("struct abcd { int ab; float cd; }"))
|
|
3357
|
+
"""
|
|
3358
|
+
if type(types) is SimStruct:
|
|
3359
|
+
if types.name == "<anon>":
|
|
3360
|
+
raise ValueError("Cannot register anonymous struct")
|
|
3361
|
+
ALL_TYPES["struct " + types.name] = types
|
|
3362
|
+
elif type(types) is SimUnion:
|
|
3363
|
+
if types.name == "<anon>":
|
|
3364
|
+
raise ValueError("Cannot register anonymous union")
|
|
3365
|
+
ALL_TYPES["union " + types.name] = types
|
|
3366
|
+
else:
|
|
3367
|
+
ALL_TYPES.update(types)
|
|
3368
|
+
|
|
3369
|
+
|
|
3370
|
+
def do_preprocess(defn, include_path=()):
|
|
3371
|
+
"""
|
|
3372
|
+
Run a string through the C preprocessor that ships with pycparser but is weirdly inaccessible?
|
|
3373
|
+
"""
|
|
3374
|
+
from pycparser.ply import lex, cpp # pylint:disable=import-outside-toplevel
|
|
3375
|
+
|
|
3376
|
+
lexer = lex.lex(cpp)
|
|
3377
|
+
p = cpp.Preprocessor(lexer)
|
|
3378
|
+
for included in include_path:
|
|
3379
|
+
p.add_path(included)
|
|
3380
|
+
p.parse(defn)
|
|
3381
|
+
return "".join(tok.value for tok in p.parser if tok.type not in p.ignore)
|
|
3382
|
+
|
|
3383
|
+
|
|
3384
|
+
def parse_signature(defn, preprocess=True, predefined_types=None, arch=None):
|
|
3385
|
+
"""
|
|
3386
|
+
Parse a single function prototype and return its type
|
|
3387
|
+
"""
|
|
3388
|
+
try:
|
|
3389
|
+
parsed = parse_file(
|
|
3390
|
+
defn.strip(" \n\t;") + ";", preprocess=preprocess, predefined_types=predefined_types, arch=arch
|
|
3391
|
+
)
|
|
3392
|
+
return next(iter(parsed[0].values()))
|
|
3393
|
+
except StopIteration as e:
|
|
3394
|
+
raise ValueError("No declarations found") from e
|
|
3395
|
+
|
|
3396
|
+
|
|
3397
|
+
def parse_defns(defn, preprocess=True, predefined_types=None, arch=None):
|
|
3398
|
+
"""
|
|
3399
|
+
Parse a series of C definitions, returns a mapping from variable name to variable type object
|
|
3400
|
+
"""
|
|
3401
|
+
return parse_file(defn, preprocess=preprocess, predefined_types=predefined_types, arch=arch)[0]
|
|
3402
|
+
|
|
3403
|
+
|
|
3404
|
+
def parse_types(defn, preprocess=True, predefined_types=None, arch=None):
|
|
3405
|
+
"""
|
|
3406
|
+
Parse a series of C definitions, returns a mapping from type name to type object
|
|
3407
|
+
"""
|
|
3408
|
+
return parse_file(defn, preprocess=preprocess, predefined_types=predefined_types, arch=arch)[1]
|
|
3409
|
+
|
|
3410
|
+
|
|
3411
|
+
_include_re = re.compile(r"^\s*#include")
|
|
3412
|
+
|
|
3413
|
+
|
|
3414
|
+
def parse_file(
|
|
3415
|
+
defn,
|
|
3416
|
+
preprocess=True,
|
|
3417
|
+
predefined_types: dict[Any, SimType] | None = None,
|
|
3418
|
+
arch=None,
|
|
3419
|
+
side_effect_types: dict[Any, SimType] | None = None,
|
|
3420
|
+
):
|
|
3421
|
+
"""
|
|
3422
|
+
Parse a series of C definitions, returns a tuple of two type mappings, one for variable
|
|
3423
|
+
definitions and one for type definitions.
|
|
3424
|
+
"""
|
|
3425
|
+
if pycparser is None:
|
|
3426
|
+
raise ImportError("Please install pycparser in order to parse C definitions")
|
|
3427
|
+
|
|
3428
|
+
defn = "\n".join(x for x in defn.split("\n") if _include_re.match(x) is None)
|
|
3429
|
+
|
|
3430
|
+
if preprocess:
|
|
3431
|
+
defn = do_preprocess(defn)
|
|
3432
|
+
|
|
3433
|
+
# pylint: disable=unexpected-keyword-arg
|
|
3434
|
+
node = pycparser.c_parser.CParser().parse(defn, scope_stack=_make_scope(predefined_types))
|
|
3435
|
+
if not isinstance(node, c_ast.FileAST):
|
|
3436
|
+
raise ValueError("Something went horribly wrong using pycparser")
|
|
3437
|
+
out = {}
|
|
3438
|
+
out_types = {}
|
|
3439
|
+
extra_types = ChainMap(side_effect_types if side_effect_types is not None else out_types, predefined_types or {})
|
|
3440
|
+
|
|
3441
|
+
for piece in node.ext:
|
|
3442
|
+
if isinstance(piece, c_ast.FuncDef):
|
|
3443
|
+
out[piece.decl.name] = _decl_to_type(piece.decl.type, extra_types, arch=arch)
|
|
3444
|
+
elif isinstance(piece, c_ast.Decl):
|
|
3445
|
+
ty = _decl_to_type(piece.type, extra_types, arch=arch)
|
|
3446
|
+
if piece.name is not None:
|
|
3447
|
+
out[piece.name] = ty
|
|
3448
|
+
|
|
3449
|
+
# Don't forget to update typedef types
|
|
3450
|
+
ty_real = ty.type if isinstance(ty, TypeRef) else ty
|
|
3451
|
+
if isinstance(ty_real, (SimStruct, SimUnion)) and ty_real.name != "<anon>":
|
|
3452
|
+
if piece.name is None:
|
|
3453
|
+
out_types[("struct " if isinstance(ty, SimStruct) else "union ") + ty_real.name] = ty_real
|
|
3454
|
+
for _, i in out_types.items():
|
|
3455
|
+
if isinstance(i, type(ty_real)) and i.name == ty_real.name:
|
|
3456
|
+
if isinstance(ty_real, SimStruct):
|
|
3457
|
+
assert isinstance(i, SimStruct)
|
|
3458
|
+
i.fields = ty_real.fields
|
|
3459
|
+
else:
|
|
3460
|
+
assert isinstance(i, SimUnion)
|
|
3461
|
+
i.members = ty_real.members
|
|
3462
|
+
|
|
3463
|
+
elif isinstance(piece, c_ast.Typedef):
|
|
3464
|
+
out_types[piece.name] = copy.copy(_decl_to_type(piece.type, extra_types, arch=arch))
|
|
3465
|
+
out_types[piece.name].label = piece.name
|
|
3466
|
+
|
|
3467
|
+
return out, out_types
|
|
3468
|
+
|
|
3469
|
+
|
|
3470
|
+
_type_parser_singleton = None
|
|
3471
|
+
|
|
3472
|
+
|
|
3473
|
+
def type_parser_singleton() -> pycparser.CParser:
|
|
3474
|
+
global _type_parser_singleton # pylint:disable=global-statement
|
|
3475
|
+
if pycparser is not None and _type_parser_singleton is None:
|
|
3476
|
+
_type_parser_singleton = pycparser.CParser()
|
|
3477
|
+
_type_parser_singleton.cparser = pycparser.ply.yacc.yacc(
|
|
3478
|
+
module=_type_parser_singleton,
|
|
3479
|
+
start="parameter_declaration",
|
|
3480
|
+
debug=False,
|
|
3481
|
+
optimize=False,
|
|
3482
|
+
errorlog=errorlog,
|
|
3483
|
+
)
|
|
3484
|
+
assert _type_parser_singleton is not None
|
|
3485
|
+
return _type_parser_singleton
|
|
3486
|
+
|
|
3487
|
+
|
|
3488
|
+
def parse_type(defn, preprocess=True, predefined_types=None, arch=None): # pylint:disable=unused-argument
|
|
3489
|
+
"""
|
|
3490
|
+
Parse a simple type expression into a SimType
|
|
3491
|
+
|
|
3492
|
+
>>> parse_type('int *')
|
|
3493
|
+
"""
|
|
3494
|
+
return parse_type_with_name(defn, preprocess=preprocess, predefined_types=predefined_types, arch=arch)[0]
|
|
3495
|
+
|
|
3496
|
+
|
|
3497
|
+
def parse_type_with_name(
|
|
3498
|
+
defn,
|
|
3499
|
+
preprocess=True,
|
|
3500
|
+
predefined_types: dict[Any, SimType] | None = None,
|
|
3501
|
+
arch=None,
|
|
3502
|
+
side_effect_types: dict[Any, SimType] | None = None,
|
|
3503
|
+
): # pylint:disable=unused-argument
|
|
3504
|
+
"""
|
|
3505
|
+
Parse a simple type expression into a SimType, returning a tuple of the type object and any associated name
|
|
3506
|
+
that might be found in the place a name would go in a type declaration.
|
|
3507
|
+
|
|
3508
|
+
>>> parse_type_with_name('int *foo')
|
|
3509
|
+
"""
|
|
3510
|
+
if pycparser is None:
|
|
3511
|
+
raise ImportError("Please install pycparser in order to parse C definitions")
|
|
3512
|
+
|
|
3513
|
+
if preprocess:
|
|
3514
|
+
defn = re.sub(r"/\*.*?\*/", r"", defn)
|
|
3515
|
+
|
|
3516
|
+
# pylint: disable=unexpected-keyword-arg
|
|
3517
|
+
node = type_parser_singleton().parse(text=defn, scope_stack=_make_scope(predefined_types))
|
|
3518
|
+
if not isinstance(node, c_ast.Typename) and not isinstance(node, c_ast.Decl):
|
|
3519
|
+
raise pycparser.c_parser.ParseError("Got an unexpected type out of pycparser")
|
|
3520
|
+
|
|
3521
|
+
decl = node.type
|
|
3522
|
+
extra_types = ChainMap(side_effect_types if side_effect_types is not None else {}, predefined_types or {})
|
|
3523
|
+
return _decl_to_type(decl, extra_types=extra_types, arch=arch), node.name
|
|
3524
|
+
|
|
3525
|
+
|
|
3526
|
+
def _accepts_scope_stack():
|
|
3527
|
+
"""
|
|
3528
|
+
pycparser hack to include scope_stack as parameter in CParser parse method
|
|
3529
|
+
"""
|
|
3530
|
+
|
|
3531
|
+
def parse(self, text, filename="", debug=False, scope_stack=None):
|
|
3532
|
+
self.clex.filename = filename
|
|
3533
|
+
self.clex.reset_lineno()
|
|
3534
|
+
self._scope_stack = [{}] if scope_stack is None else scope_stack
|
|
3535
|
+
self._last_yielded_token = None
|
|
3536
|
+
return self.cparser.parse(input=text, lexer=self.clex, debug=debug)
|
|
3537
|
+
|
|
3538
|
+
pycparser.CParser.parse = parse
|
|
3539
|
+
|
|
3540
|
+
|
|
3541
|
+
def _decl_to_type(
|
|
3542
|
+
decl, extra_types: MutableMapping[str, SimType] | None = None, bitsize=None, arch: Arch | None = None
|
|
3543
|
+
) -> SimType:
|
|
3544
|
+
if extra_types is None:
|
|
3545
|
+
extra_types = {}
|
|
3546
|
+
|
|
3547
|
+
if isinstance(decl, c_ast.FuncDecl):
|
|
3548
|
+
argtyps = (
|
|
3549
|
+
()
|
|
3550
|
+
if decl.args is None
|
|
3551
|
+
else [
|
|
3552
|
+
(
|
|
3553
|
+
...
|
|
3554
|
+
if type(x) is c_ast.EllipsisParam
|
|
3555
|
+
else (
|
|
3556
|
+
SimTypeBottom().with_arch(arch)
|
|
3557
|
+
if type(x) is c_ast.ID
|
|
3558
|
+
else _decl_to_type(x.type, extra_types, arch=arch)
|
|
3559
|
+
)
|
|
3560
|
+
)
|
|
3561
|
+
for x in decl.args.params
|
|
3562
|
+
]
|
|
3563
|
+
)
|
|
3564
|
+
arg_names = (
|
|
3565
|
+
[arg.name for arg in decl.args.params if type(arg) is not c_ast.EllipsisParam] if decl.args else None
|
|
3566
|
+
)
|
|
3567
|
+
# special handling: func(void) is func()
|
|
3568
|
+
if (
|
|
3569
|
+
len(argtyps) == 1
|
|
3570
|
+
and isinstance(argtyps[0], SimTypeBottom)
|
|
3571
|
+
and arg_names is not None
|
|
3572
|
+
and arg_names[0] is None
|
|
3573
|
+
):
|
|
3574
|
+
argtyps = ()
|
|
3575
|
+
arg_names = None
|
|
3576
|
+
if argtyps and argtyps[-1] is ...:
|
|
3577
|
+
argtyps.pop()
|
|
3578
|
+
variadic = True
|
|
3579
|
+
else:
|
|
3580
|
+
variadic = False
|
|
3581
|
+
r = SimTypeFunction(
|
|
3582
|
+
cast(list[SimType], argtyps),
|
|
3583
|
+
_decl_to_type(decl.type, extra_types, arch=arch),
|
|
3584
|
+
arg_names=arg_names,
|
|
3585
|
+
variadic=variadic,
|
|
3586
|
+
)
|
|
3587
|
+
r._arch = arch
|
|
3588
|
+
return r
|
|
3589
|
+
|
|
3590
|
+
if isinstance(decl, c_ast.TypeDecl):
|
|
3591
|
+
if decl.declname == "TOP":
|
|
3592
|
+
r = SimTypeTop()
|
|
3593
|
+
r._arch = arch
|
|
3594
|
+
return r
|
|
3595
|
+
return _decl_to_type(decl.type, extra_types, bitsize=bitsize, arch=arch)
|
|
3596
|
+
|
|
3597
|
+
if isinstance(decl, c_ast.PtrDecl):
|
|
3598
|
+
pts_to = _decl_to_type(decl.type, extra_types, arch=arch)
|
|
3599
|
+
r = SimTypePointer(pts_to)
|
|
3600
|
+
r._arch = arch
|
|
3601
|
+
return r
|
|
3602
|
+
|
|
3603
|
+
if isinstance(decl, c_ast.ArrayDecl):
|
|
3604
|
+
elem_type = _decl_to_type(decl.type, extra_types, arch=arch)
|
|
3605
|
+
|
|
3606
|
+
if decl.dim is None:
|
|
3607
|
+
r = SimTypeArray(elem_type)
|
|
3608
|
+
r._arch = arch
|
|
3609
|
+
return r
|
|
3610
|
+
try:
|
|
3611
|
+
size = _parse_const(decl.dim, extra_types=extra_types, arch=arch)
|
|
3612
|
+
except ValueError as e:
|
|
3613
|
+
l.warning("Got error parsing array dimension, defaulting to zero: %s", e)
|
|
3614
|
+
size = 0
|
|
3615
|
+
r = SimTypeFixedSizeArray(elem_type, size)
|
|
3616
|
+
r._arch = arch
|
|
3617
|
+
return r
|
|
3618
|
+
|
|
3619
|
+
if isinstance(decl, c_ast.Struct):
|
|
3620
|
+
if decl.decls is not None:
|
|
3621
|
+
fields = OrderedDict(
|
|
3622
|
+
(field.name, _decl_to_type(field.type, extra_types, bitsize=field.bitsize, arch=arch))
|
|
3623
|
+
for field in decl.decls
|
|
3624
|
+
)
|
|
3625
|
+
else:
|
|
3626
|
+
fields = OrderedDict()
|
|
3627
|
+
|
|
3628
|
+
if decl.name is not None:
|
|
3629
|
+
key = "struct " + decl.name
|
|
3630
|
+
struct = extra_types.get(key)
|
|
3631
|
+
from_global = False
|
|
3632
|
+
if struct is None:
|
|
3633
|
+
struct = ALL_TYPES.get(key)
|
|
3634
|
+
if struct is not None:
|
|
3635
|
+
from_global = True
|
|
3636
|
+
struct = struct.with_arch(arch)
|
|
3637
|
+
if struct is None:
|
|
3638
|
+
# fallback to using decl.name as key directly
|
|
3639
|
+
struct = ALL_TYPES.get(decl.name)
|
|
3640
|
+
if struct is not None and (
|
|
3641
|
+
isinstance(struct, SimStruct)
|
|
3642
|
+
or (isinstance(struct, TypeRef) and isinstance(struct.type, SimStruct))
|
|
3643
|
+
):
|
|
3644
|
+
from_global = True
|
|
3645
|
+
struct = struct.with_arch(arch)
|
|
3646
|
+
else:
|
|
3647
|
+
# give up
|
|
3648
|
+
struct = None
|
|
3649
|
+
struct_ref = struct
|
|
3650
|
+
if isinstance(struct_ref, TypeRef):
|
|
3651
|
+
struct = struct_ref.type
|
|
3652
|
+
if struct is not None and not isinstance(struct, SimStruct):
|
|
3653
|
+
raise AngrTypeError("Provided a non-SimStruct value for a type that must be a struct")
|
|
3654
|
+
|
|
3655
|
+
if struct is None:
|
|
3656
|
+
struct = SimStruct(fields, decl.name)
|
|
3657
|
+
struct._arch = arch
|
|
3658
|
+
struct_ref = struct
|
|
3659
|
+
elif not struct.fields:
|
|
3660
|
+
struct.fields = fields
|
|
3661
|
+
elif fields and struct.fields != fields:
|
|
3662
|
+
if from_global:
|
|
3663
|
+
struct = SimStruct(fields, decl.name)
|
|
3664
|
+
struct._arch = arch
|
|
3665
|
+
struct_ref = struct
|
|
3666
|
+
else:
|
|
3667
|
+
raise ValueError("Redefining body of " + key)
|
|
3668
|
+
assert struct_ref is not None
|
|
3669
|
+
|
|
3670
|
+
extra_types[key] = struct_ref
|
|
3671
|
+
else:
|
|
3672
|
+
struct = SimStruct(fields)
|
|
3673
|
+
struct._arch = arch
|
|
3674
|
+
return struct
|
|
3675
|
+
|
|
3676
|
+
if isinstance(decl, c_ast.Union):
|
|
3677
|
+
if decl.decls is not None:
|
|
3678
|
+
fields = {field.name: _decl_to_type(field.type, extra_types, arch=arch) for field in decl.decls}
|
|
3679
|
+
else:
|
|
3680
|
+
fields = {}
|
|
3681
|
+
|
|
3682
|
+
if decl.name is not None:
|
|
3683
|
+
key = "union " + decl.name
|
|
3684
|
+
union = extra_types.get(key)
|
|
3685
|
+
from_global = False
|
|
3686
|
+
if union is None and key in ALL_TYPES:
|
|
3687
|
+
union = ALL_TYPES[key]
|
|
3688
|
+
from_global = True
|
|
3689
|
+
union_ref = union
|
|
3690
|
+
if isinstance(union_ref, TypeRef):
|
|
3691
|
+
union = union_ref.type
|
|
3692
|
+
if union is not None and not isinstance(union, SimUnion):
|
|
3693
|
+
raise AngrTypeError("Provided a non-SimUnion value for a type that must be a union")
|
|
3694
|
+
|
|
3695
|
+
if union is None:
|
|
3696
|
+
union = SimUnion(fields, decl.name)
|
|
3697
|
+
union._arch = arch
|
|
3698
|
+
union_ref = union
|
|
3699
|
+
elif not union.members:
|
|
3700
|
+
union.members = fields
|
|
3701
|
+
elif fields and union.members != fields:
|
|
3702
|
+
if from_global:
|
|
3703
|
+
union = SimStruct(fields, decl.name)
|
|
3704
|
+
union._arch = arch
|
|
3705
|
+
union_ref = union
|
|
3706
|
+
else:
|
|
3707
|
+
raise ValueError("Redefining body of " + key)
|
|
3708
|
+
|
|
3709
|
+
assert union_ref is not None
|
|
3710
|
+
extra_types[key] = union_ref
|
|
3711
|
+
else:
|
|
3712
|
+
union = SimUnion(fields)
|
|
3713
|
+
union._arch = arch
|
|
3714
|
+
return union
|
|
3715
|
+
|
|
3716
|
+
if isinstance(decl, c_ast.IdentifierType):
|
|
3717
|
+
key = " ".join(decl.names)
|
|
3718
|
+
if bitsize is not None:
|
|
3719
|
+
return SimTypeNumOffset(int(bitsize.value), signed=False).with_arch(arch)
|
|
3720
|
+
if key in extra_types:
|
|
3721
|
+
return extra_types[key].with_arch(arch)
|
|
3722
|
+
if key in ALL_TYPES:
|
|
3723
|
+
return ALL_TYPES[key].with_arch(arch)
|
|
3724
|
+
raise TypeError(f"Unknown type '{key}'")
|
|
3725
|
+
|
|
3726
|
+
if isinstance(decl, c_ast.Enum):
|
|
3727
|
+
# See C99 at 6.7.2.2
|
|
3728
|
+
return ALL_TYPES["int"].with_arch(arch)
|
|
3729
|
+
|
|
3730
|
+
raise ValueError("Unknown type!")
|
|
3731
|
+
|
|
3732
|
+
|
|
3733
|
+
def _parse_const(c, arch=None, extra_types=None):
|
|
3734
|
+
if type(c) is c_ast.Constant:
|
|
3735
|
+
return int(c.value, base=0)
|
|
3736
|
+
if type(c) is c_ast.BinaryOp:
|
|
3737
|
+
if c.op == "+":
|
|
3738
|
+
return _parse_const(c.children()[0][1], arch, extra_types) + _parse_const(
|
|
3739
|
+
c.children()[1][1], arch, extra_types
|
|
3740
|
+
)
|
|
3741
|
+
if c.op == "-":
|
|
3742
|
+
return _parse_const(c.children()[0][1], arch, extra_types) - _parse_const(
|
|
3743
|
+
c.children()[1][1], arch, extra_types
|
|
3744
|
+
)
|
|
3745
|
+
if c.op == "*":
|
|
3746
|
+
return _parse_const(c.children()[0][1], arch, extra_types) * _parse_const(
|
|
3747
|
+
c.children()[1][1], arch, extra_types
|
|
3748
|
+
)
|
|
3749
|
+
if c.op == "/":
|
|
3750
|
+
return _parse_const(c.children()[0][1], arch, extra_types) // _parse_const(
|
|
3751
|
+
c.children()[1][1], arch, extra_types
|
|
3752
|
+
)
|
|
3753
|
+
if c.op == "<<":
|
|
3754
|
+
return _parse_const(c.children()[0][1], arch, extra_types) << _parse_const(
|
|
3755
|
+
c.children()[1][1], arch, extra_types
|
|
3756
|
+
)
|
|
3757
|
+
if c.op == ">>":
|
|
3758
|
+
return _parse_const(c.children()[0][1], arch, extra_types) >> _parse_const(
|
|
3759
|
+
c.children()[1][1], arch, extra_types
|
|
3760
|
+
)
|
|
3761
|
+
raise ValueError(f"Binary op {c.op}")
|
|
3762
|
+
if type(c) is c_ast.UnaryOp:
|
|
3763
|
+
if c.op == "sizeof":
|
|
3764
|
+
return _decl_to_type(c.expr.type, extra_types=extra_types, arch=arch).size
|
|
3765
|
+
raise ValueError(f"Unary op {c.op}")
|
|
3766
|
+
if type(c) is c_ast.Cast:
|
|
3767
|
+
return _parse_const(c.expr, arch, extra_types)
|
|
3768
|
+
raise ValueError(c)
|
|
3769
|
+
|
|
3770
|
+
|
|
3771
|
+
CPP_DECL_TYPES = (
|
|
3772
|
+
cxxheaderparser.types.Method
|
|
3773
|
+
| cxxheaderparser.types.Array
|
|
3774
|
+
| cxxheaderparser.types.Pointer
|
|
3775
|
+
| cxxheaderparser.types.MoveReference
|
|
3776
|
+
| cxxheaderparser.types.Reference
|
|
3777
|
+
| cxxheaderparser.types.FunctionType
|
|
3778
|
+
| cxxheaderparser.types.Function
|
|
3779
|
+
| cxxheaderparser.types.Type
|
|
3780
|
+
)
|
|
3781
|
+
|
|
3782
|
+
|
|
3783
|
+
def _cpp_decl_to_type(
|
|
3784
|
+
decl: CPP_DECL_TYPES, extra_types: MutableMapping[str, SimType], opaque_classes: bool = True
|
|
3785
|
+
) -> (
|
|
3786
|
+
SimTypeCppFunction
|
|
3787
|
+
| SimTypeFunction
|
|
3788
|
+
| SimCppClass
|
|
3789
|
+
| SimTypeReference
|
|
3790
|
+
| SimTypePointer
|
|
3791
|
+
| SimTypeArray
|
|
3792
|
+
| SimTypeBottom
|
|
3793
|
+
):
|
|
3794
|
+
if cxxheaderparser is None:
|
|
3795
|
+
raise ImportError("Please install cxxheaderparser to parse C++ definitions")
|
|
3796
|
+
if isinstance(decl, cxxheaderparser.types.Method):
|
|
3797
|
+
the_func = decl
|
|
3798
|
+
func_name = the_func.name.format()
|
|
3799
|
+
# translate parameters
|
|
3800
|
+
args = []
|
|
3801
|
+
arg_names: list[str] = []
|
|
3802
|
+
for idx, param in enumerate(the_func.parameters):
|
|
3803
|
+
arg_type = param.type
|
|
3804
|
+
args.append(_cpp_decl_to_type(arg_type, extra_types, opaque_classes=opaque_classes))
|
|
3805
|
+
arg_name = param.name if param.name is not None else f"arg_{idx}"
|
|
3806
|
+
arg_names.append(arg_name)
|
|
3807
|
+
|
|
3808
|
+
args = tuple(args)
|
|
3809
|
+
arg_names_tuple: tuple[str, ...] = tuple(arg_names)
|
|
3810
|
+
|
|
3811
|
+
# note that the constructor and destructor handling in cxxheaderparser is a bit weird and I could not get it to
|
|
3812
|
+
# work, hence the following hack
|
|
3813
|
+
ctor = dtor = False
|
|
3814
|
+
convention = the_func.msvc_convention
|
|
3815
|
+
if len(the_func.name.segments) >= 2:
|
|
3816
|
+
seg1, seg0 = the_func.name.segments[-2:]
|
|
3817
|
+
seg1 = seg1.format()
|
|
3818
|
+
seg0 = seg0.format()
|
|
3819
|
+
if seg0 == seg1:
|
|
3820
|
+
ctor = True
|
|
3821
|
+
if the_func.return_type is not None:
|
|
3822
|
+
convention = the_func.return_type.format() # it's usually just "__thiscall"
|
|
3823
|
+
elif seg0 == "~" + seg1:
|
|
3824
|
+
dtor = True
|
|
3825
|
+
if the_func.return_type is not None:
|
|
3826
|
+
convention = the_func.return_type.format() # it's usually just "__thiscall"
|
|
3827
|
+
# returns
|
|
3828
|
+
if the_func.return_type is None or ctor or dtor:
|
|
3829
|
+
returnty = SimTypeBottom()
|
|
3830
|
+
else:
|
|
3831
|
+
returnty = _cpp_decl_to_type(the_func.return_type, extra_types, opaque_classes=opaque_classes)
|
|
3832
|
+
return SimTypeCppFunction(
|
|
3833
|
+
args,
|
|
3834
|
+
returnty,
|
|
3835
|
+
label=func_name,
|
|
3836
|
+
arg_names=arg_names_tuple,
|
|
3837
|
+
ctor=ctor,
|
|
3838
|
+
dtor=dtor,
|
|
3839
|
+
convention=convention,
|
|
3840
|
+
)
|
|
3841
|
+
|
|
3842
|
+
if isinstance(decl, cxxheaderparser.types.Function):
|
|
3843
|
+
# a function declaration
|
|
3844
|
+
the_func = decl
|
|
3845
|
+
func_name = the_func.name.format()
|
|
3846
|
+
# translate parameters
|
|
3847
|
+
args = []
|
|
3848
|
+
arg_names: list[str] = []
|
|
3849
|
+
for idx, param in enumerate(the_func.parameters):
|
|
3850
|
+
arg_type = param.type
|
|
3851
|
+
args.append(_cpp_decl_to_type(arg_type, extra_types, opaque_classes=opaque_classes))
|
|
3852
|
+
arg_name = param.name if param.name is not None else f"arg_{idx}"
|
|
3853
|
+
arg_names.append(arg_name)
|
|
3854
|
+
|
|
3855
|
+
args = tuple(args)
|
|
3856
|
+
arg_names_tuple: tuple[str, ...] = tuple(arg_names)
|
|
3857
|
+
# returns
|
|
3858
|
+
if the_func.return_type is None:
|
|
3859
|
+
returnty = SimTypeBottom()
|
|
3860
|
+
else:
|
|
3861
|
+
returnty = _cpp_decl_to_type(the_func.return_type, extra_types, opaque_classes=opaque_classes)
|
|
3862
|
+
|
|
3863
|
+
return SimTypeFunction(args, returnty, label=func_name, arg_names=arg_names_tuple)
|
|
3864
|
+
|
|
3865
|
+
if isinstance(decl, cxxheaderparser.types.Type):
|
|
3866
|
+
# attempt to parse it as one of the existing types
|
|
3867
|
+
lbl = decl.format()
|
|
3868
|
+
lbl = lbl.removeprefix("const ")
|
|
3869
|
+
if lbl in extra_types:
|
|
3870
|
+
t = extra_types[lbl]
|
|
3871
|
+
elif lbl in ALL_TYPES:
|
|
3872
|
+
t = ALL_TYPES[lbl]
|
|
3873
|
+
elif opaque_classes is True:
|
|
3874
|
+
# create a struct or a class without knowing the internal members
|
|
3875
|
+
if decl.typename.classkey == "struct":
|
|
3876
|
+
t = SimTypeRef(lbl.removeprefix("struct "), SimStruct)
|
|
3877
|
+
else:
|
|
3878
|
+
t = SimCppClass(unique_name=lbl, name=lbl, members={}, size=32)
|
|
3879
|
+
else:
|
|
3880
|
+
raise TypeError(f'Unknown type "{lbl}"')
|
|
3881
|
+
|
|
3882
|
+
if isinstance(t, NamedTypeMixin):
|
|
3883
|
+
t = t.copy()
|
|
3884
|
+
t.name = lbl # pylint:disable=attribute-defined-outside-init
|
|
3885
|
+
return t # type:ignore
|
|
3886
|
+
|
|
3887
|
+
if isinstance(decl, cxxheaderparser.types.Array):
|
|
3888
|
+
subt = _cpp_decl_to_type(decl.array_of, extra_types, opaque_classes=opaque_classes)
|
|
3889
|
+
return SimTypeArray(subt, length=decl.size)
|
|
3890
|
+
|
|
3891
|
+
if isinstance(decl, cxxheaderparser.types.MoveReference):
|
|
3892
|
+
subt = _cpp_decl_to_type(decl.moveref_to, extra_types, opaque_classes=opaque_classes)
|
|
3893
|
+
return SimTypeReference(subt) # FIXME: Move reference vs reference
|
|
3894
|
+
|
|
3895
|
+
if isinstance(decl, cxxheaderparser.types.Reference):
|
|
3896
|
+
subt = _cpp_decl_to_type(decl.ref_to, extra_types, opaque_classes=opaque_classes)
|
|
3897
|
+
return SimTypeReference(subt)
|
|
3898
|
+
|
|
3899
|
+
if isinstance(decl, cxxheaderparser.types.Pointer):
|
|
3900
|
+
subt = _cpp_decl_to_type(decl.ptr_to, extra_types, opaque_classes=opaque_classes)
|
|
3901
|
+
return SimTypePointer(subt)
|
|
3902
|
+
|
|
3903
|
+
if isinstance(decl, cxxheaderparser.types.FunctionType):
|
|
3904
|
+
params = tuple(
|
|
3905
|
+
_cpp_decl_to_type(param.type, extra_types, opaque_classes=opaque_classes) for param in decl.parameters
|
|
3906
|
+
)
|
|
3907
|
+
param_names = (
|
|
3908
|
+
tuple(param.name.format() for param in decl.parameters) # type:ignore
|
|
3909
|
+
if all(param.name is not None for param in decl.parameters)
|
|
3910
|
+
else None
|
|
3911
|
+
)
|
|
3912
|
+
returnty = _cpp_decl_to_type(decl.return_type, extra_types, opaque_classes=opaque_classes)
|
|
3913
|
+
return SimTypeCppFunction(params, returnty, arg_names=param_names, convention=decl.msvc_convention)
|
|
3914
|
+
|
|
3915
|
+
raise NotImplementedError
|
|
3916
|
+
|
|
3917
|
+
|
|
3918
|
+
def normalize_cpp_function_name(name: str) -> str:
|
|
3919
|
+
stripped_any = True
|
|
3920
|
+
while stripped_any:
|
|
3921
|
+
stripped_any = False
|
|
3922
|
+
# strip virtual/static/inline/friend keywords
|
|
3923
|
+
prefixes = ["virtual", "static", "inline", "friend"]
|
|
3924
|
+
for pre in prefixes:
|
|
3925
|
+
new_name = name.removeprefix(pre + " ")
|
|
3926
|
+
if new_name != name:
|
|
3927
|
+
name = new_name
|
|
3928
|
+
stripped_any = True
|
|
3929
|
+
|
|
3930
|
+
# strip access specifiers
|
|
3931
|
+
prefixes = ["public:", "protected:", "private:", "[thunk]:"]
|
|
3932
|
+
for pre in prefixes:
|
|
3933
|
+
new_name = name.removeprefix(pre)
|
|
3934
|
+
if new_name != name:
|
|
3935
|
+
name = new_name
|
|
3936
|
+
stripped_any = True
|
|
3937
|
+
|
|
3938
|
+
new_name = name.strip()
|
|
3939
|
+
if new_name != name:
|
|
3940
|
+
name = new_name
|
|
3941
|
+
stripped_any = True
|
|
3942
|
+
|
|
3943
|
+
if "void (__cdecl *)" in name:
|
|
3944
|
+
name = name.replace("void (__cdecl *)", "void ")
|
|
3945
|
+
|
|
3946
|
+
if name.startswith("operator"):
|
|
3947
|
+
# the return type is missing; give it a default type
|
|
3948
|
+
name = "int " + name
|
|
3949
|
+
|
|
3950
|
+
if " __int" in name:
|
|
3951
|
+
name = name.replace(" __int64 ", " long long ")
|
|
3952
|
+
name = name.replace(" __int32 ", " int ")
|
|
3953
|
+
name = name.replace(" __int16 ", " short ")
|
|
3954
|
+
|
|
3955
|
+
return name.removesuffix(";")
|
|
3956
|
+
|
|
3957
|
+
|
|
3958
|
+
def parse_cpp_file(cpp_decl, with_param_names: bool = False): # pylint: disable=unused-argument
|
|
3959
|
+
#
|
|
3960
|
+
# A series of hacks to make cxxheaderparser happy with whatever C++ function prototypes we feed in
|
|
3961
|
+
#
|
|
3962
|
+
|
|
3963
|
+
if cxxheaderparser is None:
|
|
3964
|
+
raise ImportError("Please install cxxheaderparser to parse C++ definitions")
|
|
3965
|
+
|
|
3966
|
+
# CppHeaderParser does not support specialization
|
|
3967
|
+
s = normalize_cpp_function_name(cpp_decl)
|
|
3968
|
+
|
|
3969
|
+
# CppHeaderParser does not like missing function body
|
|
3970
|
+
s += "\n\n{}"
|
|
3971
|
+
|
|
3972
|
+
try:
|
|
3973
|
+
h = cxxheaderparser.simple.parse_string(s)
|
|
3974
|
+
except cxxheaderparser.errors.CxxParseError:
|
|
3975
|
+
# GCC-mangled (and thus, demangled) function names do not have return types encoded; let's try to prefix s with
|
|
3976
|
+
# "void" and try again
|
|
3977
|
+
s = "void " + s
|
|
3978
|
+
try:
|
|
3979
|
+
h = cxxheaderparser.simple.parse_string(s)
|
|
3980
|
+
except cxxheaderparser.errors.CxxParseError:
|
|
3981
|
+
# if it still fails, we give up
|
|
3982
|
+
return None, None
|
|
3983
|
+
|
|
3984
|
+
if not h.namespace:
|
|
3985
|
+
return None, None
|
|
3986
|
+
|
|
3987
|
+
func_decls: dict[str, SimTypeCppFunction | SimTypeFunction] = {}
|
|
3988
|
+
for the_func in h.namespace.functions + h.namespace.method_impls:
|
|
3989
|
+
# FIXME: We always assume that there is a "this" pointer but it is not the case for static methods.
|
|
3990
|
+
proto = cast(SimTypeCppFunction | SimTypeFunction | None, _cpp_decl_to_type(the_func, {}, opaque_classes=True))
|
|
3991
|
+
if proto is not None:
|
|
3992
|
+
func_name = the_func.name.format()
|
|
3993
|
+
if isinstance(proto, SimTypeCppFunction):
|
|
3994
|
+
proto.args = (
|
|
3995
|
+
SimTypePointer(pts_to=SimTypeBottom(label="void")),
|
|
3996
|
+
*proto.args,
|
|
3997
|
+
) # pylint:disable=attribute-defined-outside-init
|
|
3998
|
+
proto.arg_names = ("this", *proto.arg_names) # pylint:disable=attribute-defined-outside-init
|
|
3999
|
+
func_decls[func_name] = proto
|
|
4000
|
+
|
|
4001
|
+
return func_decls, {}
|
|
4002
|
+
|
|
4003
|
+
|
|
4004
|
+
if pycparser is not None:
|
|
4005
|
+
_accepts_scope_stack()
|
|
4006
|
+
|
|
4007
|
+
with contextlib.suppress(ImportError):
|
|
4008
|
+
register_types(
|
|
4009
|
+
parse_types(
|
|
4010
|
+
"""
|
|
4011
|
+
typedef long time_t;
|
|
4012
|
+
|
|
4013
|
+
struct timespec {
|
|
4014
|
+
time_t tv_sec;
|
|
4015
|
+
long tv_nsec;
|
|
4016
|
+
};
|
|
4017
|
+
|
|
4018
|
+
struct timeval {
|
|
4019
|
+
time_t tv_sec;
|
|
4020
|
+
long tv_usec;
|
|
4021
|
+
};
|
|
4022
|
+
"""
|
|
4023
|
+
)
|
|
4024
|
+
)
|
|
4025
|
+
|
|
4026
|
+
from .state_plugins.view import SimMemView
|