├── .ci ├── Dockerfile.conan-ubuntu20 ├── Dockerfile.manylinux2010 ├── Dockerfile.static ├── Dockerfile.ubuntu20 ├── PKGBUILD ├── arm-benchmark.yml ├── gitlab-ci.yml └── run_conan.py ├── .clang-format ├── .dockerignore ├── .flake8 ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ └── binary-disassembles-incorrectly.md └── workflows │ └── actions.yml ├── .gitignore ├── .pre-commit-config.yaml ├── CHANGELOG.md ├── CMakeLists.googletest ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Dockerfile ├── GrammaTech-CLA-ddisasm.pdf ├── LICENSE.txt ├── README.md ├── conanfile.py ├── cpack-config.cmake ├── doc ├── CMakeLists.txt ├── Makefile ├── build_index.py ├── requirements-docs.txt └── source │ ├── APIRef.rst │ ├── DATALOG-API │ └── src_docs │ │ └── .gitignore │ ├── DEVELOPMENT_DOCS │ ├── AuxData.md │ ├── BuildDocumentation.md │ └── DevelopmentGuidelines.md │ ├── DevDocs.rst │ ├── GENERAL │ ├── 1-Installation.md │ ├── 2-Building-Ddisasm.md │ ├── 3-Command-line-options.md │ ├── 4-Testing.md │ └── 5-AdvancedUsage.md │ ├── TUTORIALS │ └── 1-DDISASM-USAGE │ │ └── Hello-world.md │ ├── Tutorials.rst │ ├── _ext │ └── sphinxdatalog │ │ └── datalogdomain.py │ ├── conf.py │ └── index.rst ├── etc ├── README.md └── sstrip ├── examples ├── Makefile ├── arm64 │ ├── hello │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── Makefile.binrats │ │ └── hello.c │ └── password │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── Makefile.binrats │ │ ├── altered_arm64.s │ │ └── password.c ├── arm64_asm_examples │ ├── ex_adr_not_split_load │ │ ├── Makefile │ │ └── src.s │ ├── ex_cfg │ │ ├── Makefile │ │ └── src.s │ ├── ex_cond_branch │ │ ├── Makefile │ │ └── src.s │ ├── ex_op_types │ │ ├── Makefile │ │ └── src.s │ ├── ex_post_index_no_lo12 │ │ ├── Makefile │ │ └── src.s │ ├── ex_registers │ │ ├── Makefile │ │ └── src.s │ ├── ex_stack_split_load │ │ ├── Makefile │ │ └── src.s │ ├── ex_switch1 │ │ ├── Makefile │ │ └── src.s │ ├── ex_switch2 │ │ ├── Makefile │ │ └── src.s │ ├── ex_switch3 │ │ ├── Makefile │ │ └── src.s │ ├── ex_switch4 │ │ ├── Makefile │ │ └── src.s │ └── ex_switch_limited_by_cmp │ │ ├── Makefile │ │ └── src.s ├── arm_asm_examples │ ├── ex1_no_pie │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex1_pie │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_add_as_jump │ │ ├── Makefile │ │ └── ex_add_as_jump.s │ ├── ex_adr_to_code │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_aliased_data │ │ ├── Makefile │ │ └── ex_aliased_data.s │ ├── ex_blx_interwork │ │ ├── Makefile │ │ └── ex_blx_interwork.s │ ├── ex_bx_pc │ │ ├── Makefile │ │ └── ex_bx_pc.s │ ├── ex_cfg │ │ ├── Makefile │ │ └── ex_cfg.s │ ├── ex_code_after_literal_pool │ │ ├── Makefile │ │ └── ex_code_after_literal_pool.s │ ├── ex_func_after_litpool │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_halts │ │ ├── Makefile │ │ └── ex_halts.s │ ├── ex_it_split │ │ ├── Makefile │ │ └── ex_it_split.s │ ├── ex_jumptable │ │ ├── Makefile │ │ └── ex_jumptable.s │ ├── ex_ldcl │ │ ├── Makefile │ │ └── ex_ldcl.s │ ├── ex_ldr │ │ ├── Makefile │ │ └── ex_ldr.s │ ├── ex_ldr_pc_rel_reg │ │ ├── Makefile │ │ └── ex_ldr_pc_rel_reg.s │ ├── ex_litpool │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_movw_movt │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_movw_movt_pie │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_relative_jump_table │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_relative_jump_table2 │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_relative_jump_table3 │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_setend │ │ ├── Makefile │ │ └── ex_setend.s │ ├── ex_stm_reglist_invalid │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_tbb │ │ ├── Makefile │ │ └── ex_tbb.s │ ├── ex_tbb_r3_adr │ │ ├── Makefile │ │ └── ex_tbb.s │ ├── ex_tbb_r3_ldr │ │ ├── Makefile │ │ └── ex_tbb.s │ ├── ex_tbb_zero │ │ ├── Makefile │ │ └── ex_tbb.s │ ├── ex_tbh │ │ ├── Makefile │ │ └── ex_tbh.s │ ├── ex_thumb_at_section_start │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_value_reg │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_vld │ │ ├── Makefile │ │ └── ex_original.s │ └── ex_zero_size_object_sym │ │ ├── Makefile │ │ └── ex_original.s ├── asm_examples │ ├── Makefile │ ├── README.md │ ├── ex_aligned_data_in_code │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_aligned_data_in_code_avx512f │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_base_relative0 │ │ ├── Makefile.windows │ │ └── ex.asm │ ├── ex_base_relative1 │ │ ├── Makefile.windows │ │ └── ex.asm │ ├── ex_boundary_sym_expr │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_boundary_sym_expr2 │ │ ├── Makefile │ │ ├── ex_original.s │ │ └── linker-script.ld │ ├── ex_cfg │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_cfi_directives │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_code_offset_table │ │ ├── Makefile.windows │ │ └── ex.asm │ ├── ex_data_access │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_dll_export_thunk │ │ ├── Makefile.windows │ │ └── ex.asm │ ├── ex_enclosed_instr │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_exceptions5 │ │ ├── Makefile │ │ ├── ex_original.s │ │ └── linker-script.ld │ ├── ex_fde_entry │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_ifunc │ │ ├── Makefile │ │ ├── ex.map │ │ └── ex_original.s │ ├── ex_loop_instructions │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_misaligned_fde │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_moved_base_relative │ │ ├── Makefile.windows │ │ └── ex.asm │ ├── ex_moved_label │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_moved_label_imm │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_noreturn_use_def │ │ ├── Makefile │ │ └── src.s │ ├── ex_npad │ │ ├── Makefile.windows │ │ ├── ex.asm │ │ └── listing.inc │ ├── ex_overlapping_instruction │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_overlapping_instruction_2 │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_overlapping_instruction_3 │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_overlapping_nops │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_plt_nop │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_pointerReattribution3 │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_pointerReattribution3_clang │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_pointerReattribution3_pie │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_referred_string │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_relative_jump_tables │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_relative_jump_tables2 │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_relative_jump_tables3 │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_relative_jump_tables4 │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_relative_switch │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_relative_switch_sizes │ │ ├── Makefile │ │ ├── ex.c │ │ └── ex_original.s │ ├── ex_relative_switch_through_stack │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_return_use_def │ │ ├── Makefile │ │ ├── ex_reference.c │ │ └── src.s │ ├── ex_stack_value_reg │ │ ├── Makefile │ │ └── src.s │ ├── ex_switch_cdqe │ │ ├── Makefile │ │ └── src.s │ ├── ex_switch_in_code │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_switch_in_code2 │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_switch_in_code3 │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_switch_in_code4 │ │ ├── Makefile.windows │ │ └── ex.asm │ ├── ex_switch_in_code5 │ │ ├── Makefile │ │ └── src.s │ ├── ex_switch_in_code_no_cfi │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_switch_limited_by_cmp │ │ ├── Makefile │ │ └── src.s │ ├── ex_switch_limited_by_indirect_cmp │ │ ├── Makefile │ │ └── src.s │ ├── ex_switch_limited_index_table │ │ ├── Makefile │ │ └── src.s │ ├── ex_switch_overlap │ │ ├── Makefile │ │ └── src.s │ ├── ex_sym_minus_sym │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_symbol_selection │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_symbol_selection2 │ │ ├── Makefile │ │ ├── bar.s │ │ ├── ex.c │ │ └── foo.s │ ├── ex_symbolic_operand_heuristics │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_synchronous_access │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_synchronous_access2 │ │ ├── Makefile │ │ ├── ex.c │ │ └── ex_original.s │ ├── ex_synchronous_access3 │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_synchronous_access4 │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_tls │ │ ├── Makefile │ │ ├── ex_original.s │ │ └── fun.s │ ├── ex_tls_local_exec │ │ ├── Makefile │ │ └── ex_original.s │ ├── ex_two_data_accesses │ │ ├── Makefile │ │ ├── ex.c │ │ └── ex_original.s │ └── ex_weird_sections │ │ ├── Makefile │ │ └── ex_original.s ├── ex1 │ ├── .gitignore │ ├── Makefile │ ├── Makefile.windows │ └── ex.c ├── ex_2modulesPIC │ ├── Makefile │ ├── Makefile.windows │ ├── ex.c │ ├── fun.c │ └── fun.h ├── ex_adder │ ├── Makefile │ └── ex.c ├── ex_call_array │ ├── Makefile │ └── ex.c ├── ex_call_once │ ├── Makefile │ └── ex.cpp ├── ex_confusing_data │ ├── Makefile │ ├── Makefile.windows │ └── ex.c ├── ex_copy_relo │ ├── Makefile │ ├── ex.c │ └── foo.c ├── ex_data_limit │ ├── Makefile │ ├── ex.c │ ├── fun.c │ └── fun.h ├── ex_dyn_library │ ├── Makefile │ ├── ex.c │ ├── fun.c │ └── fun.h ├── ex_dyn_library2 │ ├── Makefile │ ├── ex.c │ ├── fun.c │ └── fun.h ├── ex_dynamic_initfini │ ├── Makefile │ └── ex.c ├── ex_dynamic_tls │ ├── .gitignore │ ├── Makefile │ ├── ex.c │ ├── fun.c │ ├── fun.h │ └── fun_initial_exec.c ├── ex_dynamic_tls2 │ ├── Makefile │ ├── ex.c │ ├── foo.c │ └── fun.c ├── ex_emit_relocs │ ├── Makefile │ ├── bar.c │ └── ex.c ├── ex_exceptions1 │ ├── Makefile │ ├── Makefile.windows │ └── ex.cpp ├── ex_exceptions2 │ ├── Makefile │ ├── Makefile.windows │ └── ex.cpp ├── ex_exceptions3 │ ├── Makefile │ ├── Makefile.windows │ └── ex.cpp ├── ex_exceptions4 │ ├── Makefile │ ├── ex.cpp │ └── linker-script.ld ├── ex_false_pointer_array │ ├── Makefile │ ├── Makefile.windows │ └── ex.c ├── ex_float │ ├── Makefile │ ├── Makefile.windows │ └── ex.c ├── ex_fprintf │ ├── Makefile │ ├── Makefile.windows │ └── ex.c ├── ex_getoptlong │ ├── Makefile │ └── ex.c ├── ex_imported_tls_syms │ ├── Makefile │ └── ex.cpp ├── ex_init_array │ ├── Makefile │ ├── ex.hpp │ ├── ex1.c │ └── ex2.c ├── ex_kuser │ ├── Makefile │ ├── Makefile.windows │ └── ex.c ├── ex_legacy_switch.001 │ ├── Makefile │ ├── Makefile.windows │ └── ex.c ├── ex_legacy_switch.002 │ ├── Makefile │ ├── Makefile.windows │ └── ex.c ├── ex_legacy_switch.003 │ ├── Makefile │ ├── Makefile.windows │ └── ex.c ├── ex_legacy_switch.004 │ ├── Makefile │ ├── Makefile.windows │ └── ex.c ├── ex_lib_symbols │ ├── Makefile │ └── ex_so.c ├── ex_memberFunction │ ├── Makefile │ └── ex.cpp ├── ex_memberPointer │ ├── Makefile │ ├── Makefile.windows │ └── ex.cpp ├── ex_ml_sym_mangling │ ├── .gitignore │ ├── Makefile.windows │ ├── baz.c │ ├── baz.h │ ├── ex.c │ ├── foo.c │ └── foo.h ├── ex_noreturn │ ├── Makefile │ ├── Makefile.windows │ └── ex.c ├── ex_obj_debug_reloc │ ├── Makefile │ └── ex.c ├── ex_pointerReattribution │ ├── Makefile │ ├── Makefile.windows │ └── ex.c ├── ex_pointerReattribution2 │ ├── Makefile │ ├── Makefile.windows │ └── ex.c ├── ex_pointerReattribution3 │ ├── Makefile │ ├── Makefile.windows │ └── ex.c ├── ex_rsrc │ ├── .gitignore │ ├── Makefile.windows │ ├── ex.c │ ├── ex.rc │ └── resource.h ├── ex_seh │ ├── Makefile.windows │ └── ex.c ├── ex_simple_dll │ ├── .gitignore │ ├── Makefile │ ├── Makefile.windows │ ├── ex.c │ ├── test.c │ └── test.h ├── ex_stat │ ├── Makefile │ └── ex.c ├── ex_static_lib │ ├── .gitignore │ ├── Makefile │ ├── ex.c │ ├── libmsg.h │ ├── msg_four_with_a_long_name.c │ ├── msg_one.c │ ├── msg_three.c │ └── msg_two.c ├── ex_static_lib_cfg │ ├── .gitignore │ ├── Makefile │ ├── bar.c │ ├── ex.c │ ├── foo.c │ ├── foo_arm32.s │ ├── foo_arm64.s │ ├── foo_x64.s │ └── test.h ├── ex_struct │ ├── Makefile │ ├── Makefile.windows │ └── ex.c ├── ex_switch │ ├── Makefile │ ├── Makefile.windows │ └── ex.c ├── ex_symbol_selection │ ├── Makefile │ ├── bar.c │ ├── data.c │ ├── ex.c │ ├── fun.c │ └── fun.h ├── ex_symver │ ├── Makefile │ ├── bar.c │ ├── ex.c │ ├── ex2.c │ ├── ex3.c │ ├── foo.c │ ├── foo.h │ ├── libbar.map │ └── libfoo.map ├── ex_synchronous_access │ ├── Makefile │ └── ex.c ├── ex_thread_local │ ├── Makefile │ └── ex.c ├── ex_threads │ ├── Makefile │ └── ex.cpp ├── ex_uninitialized_data │ ├── Makefile │ ├── Makefile.windows │ └── ex.c ├── ex_virtualDispatch │ ├── Makefile │ ├── Makefile.windows │ └── ex.cpp ├── mips_asm_examples │ ├── ex_got_ofst │ │ ├── Makefile │ │ └── ex_original.s │ └── ex_nop_block │ │ ├── Makefile │ │ └── ex_original.s ├── trace_examples │ └── tbdisasm_a_20200713.gtirb └── x86_32_asm_examples │ ├── ex_got_relative │ ├── Makefile │ └── src.s │ └── ex_stack_value_reg │ ├── Makefile │ └── src.s ├── python ├── CMakeLists.txt ├── setup.py.in ├── src │ └── ddisasm │ │ ├── __init__.py │ │ ├── __main__.py │ │ └── py.typed └── version.py.in ├── requirements-dev.txt ├── src ├── AnalysisPipeline.cpp ├── AnalysisPipeline.h ├── AuxDataSchema.h ├── CMakeLists.txt ├── CliDriver.cpp ├── CliDriver.h ├── Endian.h ├── FunInfer.cpp ├── Functors.cpp ├── Functors.h ├── Hints.cpp ├── Hints.h ├── Main.cpp ├── Registration.cpp ├── Registration.h ├── Version.h.in ├── datalog │ ├── arch │ │ ├── arch.dl │ │ ├── arm32 │ │ │ ├── arch_arm.dl │ │ │ ├── float_operations.dl │ │ │ ├── interrupt_operations.dl │ │ │ ├── jump_operations.dl │ │ │ ├── memory_access.dl │ │ │ └── registers.dl │ │ ├── arm32_binaries.dl │ │ ├── arm32_code_inference.dl │ │ ├── arm32_code_inference_weights.dl │ │ ├── arm32_jump_tables.dl │ │ ├── arm32_symbolization.dl │ │ ├── arm64 │ │ │ ├── arch_arm64.dl │ │ │ ├── float_operations.dl │ │ │ ├── interrupt_operations.dl │ │ │ ├── jump_operations.dl │ │ │ ├── memory_access.dl │ │ │ └── registers.dl │ │ ├── arm64_symbolization.dl │ │ ├── arm_binaries.dl │ │ ├── intel │ │ │ ├── arch_x86.dl │ │ │ ├── arch_x86_32.dl │ │ │ ├── arch_x86_64.dl │ │ │ ├── float_operations.dl │ │ │ ├── interrupt_operations.dl │ │ │ ├── jump_operations.dl │ │ │ ├── memory_access.dl │ │ │ ├── registers_common.dl │ │ │ ├── registers_x86_32.dl │ │ │ └── registers_x86_64.dl │ │ ├── mips32 │ │ │ ├── arch_mips32.dl │ │ │ ├── float_operations.dl │ │ │ ├── interrupt_operations.dl │ │ │ ├── jump_operations.dl │ │ │ ├── memory_access.dl │ │ │ └── registers.dl │ │ ├── mips_symbolization.dl │ │ ├── x86_32_symbolization.dl │ │ └── x86_64_symbolization.dl │ ├── basic_def_used.dl │ ├── basic_function_inference.dl │ ├── binary │ │ ├── elf │ │ │ ├── elf_binaries.dl │ │ │ ├── exceptions.dl │ │ │ ├── relocations.dl │ │ │ ├── symbolization.dl │ │ │ └── tls.dl │ │ └── pe │ │ │ ├── exceptions.dl │ │ │ ├── jump_tables.dl │ │ │ ├── pe_binaries.dl │ │ │ ├── relocations.dl │ │ │ └── symbolization.dl │ ├── bitmasks.dl │ ├── boundary_value_analysis.dl │ ├── cfg.dl │ ├── code_inference.dl │ ├── code_inference_postprocess.dl │ ├── code_inference_weights.dl │ ├── data.dl │ ├── data_access_analysis.dl │ ├── debug_stats.dl │ ├── empty_range.dl │ ├── jump_tables.dl │ ├── main.dl │ ├── noreturn.dl │ ├── pointer_reattribution.dl │ ├── printable_chars.dl │ ├── register_type_analysis.dl │ ├── relative_jump_tables.dl │ ├── self_diagnose.dl │ ├── straight_line_def_used.dl │ ├── symbolization.dl │ ├── symbols.dl │ ├── use_def_analysis.dl │ └── value_analysis.dl ├── gtirb-builder │ ├── ArchiveReader.cpp │ ├── ArchiveReader.h │ ├── CMakeLists.txt │ ├── ElfReader.cpp │ ├── ElfReader.h │ ├── GtirbBuilder.cpp │ ├── GtirbBuilder.h │ ├── PeReader.cpp │ └── PeReader.h ├── gtirb-decoder │ ├── CMakeLists.txt │ ├── CompositeLoader.h │ ├── DatalogIO.cpp │ ├── DatalogIO.h │ ├── Relations.cpp │ ├── Relations.h │ ├── arch │ │ ├── Arm32Loader.cpp │ │ ├── Arm32Loader.h │ │ ├── Arm64Loader.cpp │ │ ├── Arm64Loader.h │ │ ├── Mips32Loader.cpp │ │ ├── Mips32Loader.h │ │ ├── X64Loader.cpp │ │ ├── X64Loader.h │ │ ├── X86Loader.cpp │ │ └── X86Loader.h │ ├── core │ │ ├── AuxDataLoader.cpp │ │ ├── AuxDataLoader.h │ │ ├── DataLoader.cpp │ │ ├── DataLoader.h │ │ ├── EdgesLoader.cpp │ │ ├── EdgesLoader.h │ │ ├── InstructionLoader.cpp │ │ ├── InstructionLoader.h │ │ ├── ModuleLoader.cpp │ │ ├── ModuleLoader.h │ │ ├── SectionLoader.cpp │ │ ├── SectionLoader.h │ │ ├── SymbolLoader.cpp │ │ ├── SymbolLoader.h │ │ ├── SymbolicExpressionLoader.cpp │ │ └── SymbolicExpressionLoader.h │ ├── format │ │ ├── ElfLoader.cpp │ │ ├── ElfLoader.h │ │ ├── PeLoader.cpp │ │ ├── PeLoader.h │ │ ├── RawLoader.cpp │ │ └── RawLoader.h │ └── target │ │ ├── ElfArm32Loader.h │ │ ├── ElfArm64Loader.h │ │ ├── ElfMips32Loader.h │ │ ├── ElfX64Loader.h │ │ ├── ElfX86Loader.h │ │ ├── PeX64Loader.h │ │ ├── PeX86Loader.h │ │ ├── RawArm32Loader.h │ │ ├── RawArm64Loader.h │ │ ├── RawMips32Loader.h │ │ ├── RawX64Loader.h │ │ └── RawX86Loader.h ├── passes │ ├── AnalysisPass.cpp │ ├── AnalysisPass.h │ ├── CMakeLists.txt │ ├── DatalogAnalysisPass.cpp │ ├── DatalogAnalysisPass.h │ ├── Disassembler.cpp │ ├── Disassembler.h │ ├── DisassemblyPass.cpp │ ├── DisassemblyPass.h │ ├── FunctionInferencePass.cpp │ ├── FunctionInferencePass.h │ ├── Interpreter.cpp │ ├── Interpreter.h │ ├── NoReturnPass.cpp │ ├── NoReturnPass.h │ ├── SccPass.cpp │ ├── SccPass.h │ └── datalog │ │ ├── function_inference.dl │ │ └── no_return_analysis.dl └── tests │ ├── ArchiveReader.Test.cpp │ ├── CMakeLists.txt │ ├── CompositeLoader.Test.cpp │ ├── DatalogIO.Test.cpp │ ├── ElfReader.Test.cpp │ ├── Functors.Test.cpp │ ├── InstructionRelations.Test.cpp │ ├── Main.Test.cpp │ ├── NoReturnPass.Test.cpp │ ├── RawReader.Test.cpp │ ├── SccPass.Test.cpp │ └── inputs │ ├── ar │ ├── basic.a │ ├── bsd.a │ ├── empty.a │ └── gnu.a │ ├── hello.cpp │ ├── hello.x64.elf │ └── man ├── tests ├── arm_misc_test.py ├── asm_db.py ├── cfg_test.py ├── check_gtirb.py ├── data_access_test.py ├── def_used_test.py ├── disassemble_reassemble_check.py ├── end2end_test.py ├── extra_args_test.py ├── fcf_protection_test.py ├── function_inference_test.py ├── jumptable_call_edge_test.py ├── jumptable_unpopulated_test.py ├── linux-elf-x64.yaml ├── linux-elf-x86.yaml ├── main_inference_test.py ├── misc_test.py ├── moved_label_test.py ├── qemu-elf-arm.yaml ├── qemu-elf-arm64.yaml ├── qemu-elf-mips32.yaml ├── raw_gtirb_test.py ├── snippets.py ├── stack_chk_fallthrough_test.py ├── stack_var_test.py ├── static_lib_cfg_test.py ├── static_lib_test.py ├── symbolic_operand_heuristics_test.py ├── synchronous_access_test.py ├── trace_test.py ├── value_reg_test.py ├── windows-pe-x64.yaml ├── windows-pe-x86.yaml └── wine-pe-x86.yaml └── version.txt /.ci/Dockerfile.manylinux2010: -------------------------------------------------------------------------------- 1 | FROM quay.io/pypa/manylinux2010_x86_64 2 | 3 | RUN yum install -y \ 4 | ccache \ 5 | ninja-build \ 6 | wget 7 | 8 | ENV PATH="${PATH}:/opt/python/cp39-cp39/bin/" 9 | 10 | ENV CMAKE_VERSION=3.24.0 11 | RUN wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-x86_64.tar.gz && \ 12 | tar -xzf cmake-${CMAKE_VERSION}-linux-x86_64.tar.gz && \ 13 | mv cmake-${CMAKE_VERSION}-linux-x86_64 /opt/cmake && \ 14 | rm /usr/local/bin/cmake && \ 15 | ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake && \ 16 | rm cmake-${CMAKE_VERSION}-linux-x86_64.tar.gz 17 | -------------------------------------------------------------------------------- /.ci/PKGBUILD: -------------------------------------------------------------------------------- 1 | # Contributor: Eric Schulte 2 | # Maintainer: Eric Schulte 3 | _srcname=ddisasm 4 | pkgname=ddisasm-git 5 | pkgver=v0.1.1.r628.gcd19fb5 6 | pkgrel=1 7 | pkgdesc="A fast and accurate disassembler" 8 | arch=('x86_64') 9 | url="https://github.com/grammatech/ddisasm" 10 | license=('aGPLv3') 11 | depends=('capstone' 'libehp' 'boost') 12 | makedepends=('git' 'cmake' 'souffle' 'mcpp' 'lief' 'gtirb' 'gtirb-pprinter') 13 | provides=('ddisasm') 14 | source=('git://github.com/grammatech/ddisasm.git') 15 | sha512sums=('SKIP') 16 | 17 | pkgver() { 18 | cd "$_srcname" 19 | git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g' 20 | } 21 | 22 | build() { 23 | cd "$_srcname/" 24 | cmake . -Bbuild -DCMAKE_INSTALL_PREFIX=/usr -DLIEF_ROOT=/usr -DLIEF_LIBRARY=/usr/lib/libLIEF.so -DCMAKE_BUILD_TYPE=$BUILD_TYPE 25 | make -C build 26 | } 27 | 28 | package() { 29 | cd "$_srcname/build" 30 | make DESTDIR="$pkgdir" install 31 | } 32 | -------------------------------------------------------------------------------- /.ci/run_conan.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import subprocess 3 | import conanfile 4 | import sys 5 | 6 | 7 | def run_conan(args): 8 | cmd = ["conan"] + args 9 | print("running: %s" % " ".join(cmd)) 10 | sys.stdout.flush() 11 | subprocess.check_call(cmd) 12 | 13 | 14 | def build(argv): 15 | props = conanfile.Properties() 16 | run_conan(["create", "--keep-source", ".", props.conan_ref] + argv) 17 | 18 | 19 | def upload(): 20 | props = conanfile.Properties() 21 | run_conan(["upload", props.conan_recipe, "--all", "--remote", "gitlab"]) 22 | 23 | 24 | def install(argv): 25 | props = conanfile.Properties() 26 | run_conan(["install", props.conan_recipe, "--generator=deploy"] + argv) 27 | 28 | 29 | def handle_bad_args(): 30 | print("Incorrect argument(s)", file=sys.stderr) 31 | sys.exit(1) 32 | 33 | 34 | if __name__ == "__main__": 35 | if len(sys.argv) > 1: 36 | if sys.argv[1] == "upload": 37 | upload() 38 | elif sys.argv[1] == "build": 39 | build(sys.argv[2:]) 40 | elif sys.argv[1] == "install": 41 | install(sys.argv[2:]) 42 | else: 43 | handle_bad_args() 44 | else: 45 | handle_bad_args() 46 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | ./build 2 | ./CMakeCache.txt 3 | ./CMakeFiles 4 | ./CMakeScripts 5 | 6 | ./libehp/build 7 | ./libehp/CMakeCache.txt 8 | ./libehp/CMakeFiles 9 | ./libehp/CMakeScripts 10 | -------------------------------------------------------------------------------- /.flake8: -------------------------------------------------------------------------------- 1 | # Black feels free to violate some rules because they're PEP8 extensions and 2 | # not PEP8 itself. So we must ignore: 3 | # E203: Whitespace before ':': Black does "a[b : c]"; flake8 wants "a[b:c]". 4 | # W503: Line break occurred before a binary operator: Black puts operators in front of lines, flake8 wants them after. 5 | # more detail is available at https://black.readthedocs.io/en/stable/the_black_code_style.html. 6 | 7 | [flake8] 8 | ignore = E203,W503 9 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Treat .a files as binary to ensure their line endings are not rewritten by 2 | # checkout on Windows. 3 | *.a binary 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/binary-disassembles-incorrectly.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Binary disassembles incorrectly 3 | about: Report a binary that ddisasm fails to disassemble correctly 4 | title: "[BINARY] fails disassembly" 5 | labels: binary fails 6 | assignees: aeflores, eschulte 7 | 8 | --- 9 | 10 | Please provide as much of the following information as possible: 11 | - Please attach the binary to this issue. 12 | - What is the version of ddisasm? (Reports against current versions of ddisasm will be prioritized.) 13 | - What went wrong? Please describe the problem or how it manifests itself. 14 | - How can we reproduce? Please paste the command line used to invoke ddisasm and any other relevant information. 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | 4 | bin/souffle_disasm 5 | bin/datalog_decoder 6 | bin/souffle_disasm.* 7 | *.aux 8 | *.log 9 | *.nav 10 | *.out 11 | *.snm 12 | *.toc 13 | doc/*.1.gz 14 | doc/src_docs/* 15 | 16 | standalone_compilation/ 17 | standalone_compilation.tar.bz2 18 | 19 | src/tests/inputs/hello.gtirb 20 | 21 | examples/**/dl_files 22 | examples/**/ex.exe 23 | examples/**/ex.exe.s 24 | examples/**/ex.old 25 | examples/**/ex.s 26 | examples/**/ex.stripped 27 | examples/**/ex.unstripped 28 | examples/**/out.txt 29 | examples/**/check.txt 30 | examples/**/ex 31 | examples/**/ex2 32 | examples/**/ex3 33 | examples/**/ex.o 34 | examples/**/*.so 35 | examples/**/*.i 36 | examples/**/*.ii 37 | examples/**/*.o.s 38 | examples/**/*.so.s 39 | examples/**/*.gtirb 40 | examples/**/*.exp 41 | examples/**/*.lib 42 | 43 | /gtirb 44 | /gtirb-pprinter 45 | /libehp 46 | wiki/ 47 | build/ 48 | __pycache__/ 49 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/psf/black 3 | rev: 22.3.0 4 | hooks: 5 | - id: black 6 | args: ["--line-length", "79"] 7 | - repo: local 8 | hooks: 9 | - id: clang-format 10 | name: clang-format 11 | language: system 12 | files: \.(c|h|cpp|hpp)$ 13 | entry: clang-format -i 14 | - repo: https://github.com/pre-commit/pre-commit-hooks 15 | rev: v2.4.0 16 | hooks: 17 | - id: end-of-file-fixer 18 | exclude: 'src/tests/inputs/ar/.+\.a' 19 | - id: trailing-whitespace 20 | exclude: 'src/tests/inputs/ar/.+\.a' 21 | - id: check-merge-conflict 22 | - repo: https://github.com/iconmaster5326/cmake-format-pre-commit-hook 23 | rev: v0.6.2 24 | hooks: 25 | - id: cmake-format 26 | exclude: build 27 | - repo: https://github.com/PyCQA/flake8 28 | rev: 3.7.9 29 | hooks: 30 | - id: flake8 31 | -------------------------------------------------------------------------------- /CMakeLists.googletest: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.2) 2 | 3 | project(googletest-download NONE) 4 | 5 | include(ExternalProject) 6 | ExternalProject_Add( 7 | googletest 8 | GIT_REPOSITORY https://github.com/google/googletest.git 9 | GIT_TAG v1.15.2 10 | SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src" 11 | BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build" 12 | CONFIGURE_COMMAND "" 13 | BUILD_COMMAND "" 14 | INSTALL_COMMAND "" 15 | TEST_COMMAND "") 16 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | ## Code of Conduct 4 | 5 | Please read the [DDisasm Code of Conduct](CODE_OF_CONDUCT.md). 6 | 7 | ## Contributor License Agreement 8 | 9 | We ask that all contributors complete our Contributor License 10 | Agreement (CLA), which can be found at 11 | [GrammaTech-CLA-ddisasm.pdf](./GrammaTech-CLA-ddisasm.pdf), 12 | and email the completed form to `CLA@GrammaTech.com`. Under this 13 | agreement contributors retain the copyright to their work but grants 14 | GrammaTech unlimited license to the work. 15 | 16 | ## Code Requirements 17 | 18 | Please follow the Code Requirements in 19 | [gtirb/CONTRIBUTING](https://github.com/GrammaTech/gtirb/blob/master/CONTRIBUTING.md#code-requirements). 20 | 21 | # Developer's Guide 22 | 23 | Please check out our [developers's guide](https://grammatech.github.io/ddisasm/). 24 | -------------------------------------------------------------------------------- /GrammaTech-CLA-ddisasm.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GrammaTech/ddisasm/5a8779f427ddfecd085f5bfd86c3a2006251ef8d/GrammaTech-CLA-ddisasm.pdf -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | SPHINXOPTS ?= 2 | SPHINXBUILD ?= sphinx-build 3 | SOURCEDIR = source 4 | BUILDDIR = build 5 | 6 | default: 7 | python3 build_index.py 8 | @$(SPHINXBUILD) "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 9 | 10 | 11 | help: 12 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 13 | 14 | %: 15 | python3 build_index.py 16 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 17 | 18 | clean: 19 | rm -rf build 20 | -------------------------------------------------------------------------------- /doc/requirements-docs.txt: -------------------------------------------------------------------------------- 1 | networkx 2 | recommonmark 3 | sphinx 4 | sphinx_markdown_tables 5 | sphinx_rtd_theme 6 | -------------------------------------------------------------------------------- /doc/source/APIRef.rst: -------------------------------------------------------------------------------- 1 | Datalog API Reference 2 | ============================= 3 | 4 | .. toctree:: 5 | :glob: 6 | :titlesonly: 7 | 8 | DATALOG-API/src_docs/**/* 9 | DATALOG-API/src_docs/* 10 | 11 | :ref:`predicateindex` 12 | -------------------------------------------------------------------------------- /doc/source/DATALOG-API/src_docs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | **/* 3 | -------------------------------------------------------------------------------- /doc/source/DevDocs.rst: -------------------------------------------------------------------------------- 1 | 2 | 3 | Documentation for advanced users and Ddisasm's developers. 4 | 5 | .. toctree:: 6 | :glob: 7 | :maxdepth: 1 8 | :titlesonly: 9 | 10 | 11 | DEVELOPMENT_DOCS/* 12 | APIRef.rst 13 | -------------------------------------------------------------------------------- /doc/source/GENERAL/4-Testing.md: -------------------------------------------------------------------------------- 1 | ## Testing 2 | 3 | ### Prerequisites 4 | 5 | The tests that are run will depend on your platform. On Linux, only linux tests 6 | will be run, whereas on Windows, only Windows tests will be run. 7 | 8 | Linux tests include test of: 9 | 10 | - Binaries of multiple ISAs 11 | - Windows binaries compiled with mingw and run with Wine 12 | 13 | That means that in order to run the test, you need to install a few dependencies: 14 | 15 | 1. GCC and Clang 16 | 2. GCC cross compilers for: 17 | - arm 18 | - aarch64 19 | - mips 20 | 21 | 3. Wine and mingw and uasm 22 | 23 | Take a look at [how we build our testing environment](https://github.com/GrammaTech/ddisasm/blob/main/.ci/Dockerfile.ubuntu20#L88) for an exhaustive list. 24 | 25 | 26 | ### Running the Tests 27 | 28 | To run the test suite, run: 29 | 30 | ``` 31 | cd build && PATH=$(pwd)/bin:$PATH ctest 32 | ``` 33 | -------------------------------------------------------------------------------- /doc/source/Tutorials.rst: -------------------------------------------------------------------------------- 1 | Tutorials 2 | ============================= 3 | 4 | .. toctree:: 5 | :glob: 6 | :titlesonly: 7 | :numbered: 8 | 9 | TUTORIALS/**/* 10 | -------------------------------------------------------------------------------- /doc/source/conf.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | sys.path.append(os.path.abspath("./_ext")) 5 | 6 | extensions = [ 7 | "recommonmark", 8 | "sphinx_markdown_tables", 9 | "sphinxdatalog.datalogdomain", 10 | "sphinx_rtd_theme", 11 | ] 12 | 13 | project = "Ddisasm" 14 | todo_include_todos = True 15 | primary_domain = "dl" 16 | default_role = "pred" 17 | html_title = "Ddisasm documentation" 18 | html_short_title = "Ddisasm docs" 19 | 20 | html_theme = "sphinx_rtd_theme" 21 | -------------------------------------------------------------------------------- /doc/source/index.rst: -------------------------------------------------------------------------------- 1 | General Documentation 2 | =================================== 3 | 4 | .. toctree:: 5 | :glob: 6 | :maxdepth: 2 7 | :titlesonly: 8 | :numbered: 9 | 10 | 11 | GENERAL/* 12 | 13 | Tutorials 14 | ============== 15 | .. toctree:: 16 | :maxdepth: 2 17 | :titlesonly: 18 | 19 | Tutorials.rst 20 | 21 | 22 | Developer's Documentation 23 | ============================= 24 | 25 | Documentation for advanced users and Ddisasm's developers. 26 | 27 | .. toctree:: 28 | :maxdepth: 1 29 | :titlesonly: 30 | 31 | DevDocs.rst 32 | -------------------------------------------------------------------------------- /etc/README.md: -------------------------------------------------------------------------------- 1 | ## Sstrip 2 | 3 | Sstrip is a ELF stripping utility, which was built from [Kickers of ELF](http://muppetlabs.com/~breadbox/software/elfkickers.html) 4 | -------------------------------------------------------------------------------- /etc/sstrip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GrammaTech/ddisasm/5a8779f427ddfecd085f5bfd86c3a2006251ef8d/etc/sstrip -------------------------------------------------------------------------------- /examples/Makefile: -------------------------------------------------------------------------------- 1 | TOPTARGETS := all clean 2 | 3 | SUBDIRS := $(wildcard */.) 4 | 5 | $(TOPTARGETS): $(SUBDIRS) 6 | $(SUBDIRS): 7 | $(MAKE) -C $@ $(MAKECMDGOALS) 8 | 9 | .PHONY: $(TOPTARGETS) $(SUBDIRS) 10 | -------------------------------------------------------------------------------- /examples/arm64/hello/.gitignore: -------------------------------------------------------------------------------- 1 | hello 2 | hello.s 3 | -------------------------------------------------------------------------------- /examples/arm64/hello/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: hello.c 3 | aarch64-linux-gnu-gcc hello.c -o hello 4 | @qemu-aarch64 -L /usr/aarch64-linux-gnu hello > out.txt 5 | clean: 6 | rm -f hello out.txt 7 | check: 8 | qemu-aarch64 -L /usr/aarch64-linux-gnu hello > /tmp/res.txt 9 | @ diff out.txt /tmp/res.txt && echo TEST OK 10 | -------------------------------------------------------------------------------- /examples/arm64/hello/Makefile.binrats: -------------------------------------------------------------------------------- 1 | AMD64CC=x86_64-linux-gnu-gcc 2 | ARM64CC=aarch64-linux-gnu-gcc 3 | 4 | CFLAGS=-g 5 | 6 | TESTNAME=hello 7 | 8 | DD=../../../build/bin/ddisasm 9 | OUT_AMD64=$(TESTNAME)_amd64 10 | OUT_ARM64=$(TESTNAME)_arm64 11 | 12 | .PHONY: all clean 13 | 14 | all: amd64 arm64 15 | 16 | amd64: $(TESTNAME).c 17 | $(AMD64CC) $^ $(CFLAGS) -o $(OUT_AMD64) 18 | $(DD) $(OUT_AMD64) --asm=amd64.s $(DD_FLAGS) 19 | 20 | arm64: $(TESTNAME).c 21 | $(ARM64CC) $^ $(CFLAGS) -o $(OUT_ARM64) 22 | $(DD) $(OUT_ARM64) --asm=arm64.s $(DD_FLAGS) 23 | 24 | clean: 25 | rm -f $(OUT_ARM64) $(OUT_AMD64) arm64.s amd64.s 26 | -------------------------------------------------------------------------------- /examples/arm64/hello/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | puts("!!!Hello World!!!"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /examples/arm64/password/.gitignore: -------------------------------------------------------------------------------- 1 | password 2 | password.s 3 | -------------------------------------------------------------------------------- /examples/arm64/password/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: password.c 3 | aarch64-linux-gnu-gcc password.c -o password 4 | @ echo "foo" \ 5 | | qemu-aarch64 -L /usr/aarch64-linux-gnu password \ 6 | > out.txt 7 | @ echo "admin\n4dm1n__4eva" \ 8 | | qemu-aarch64 -L /usr/aarch64-linux-gnu password \ 9 | >> out.txt 10 | clean: 11 | rm -f password out.txt 12 | check: 13 | @ echo "foo" \ 14 | | qemu-aarch64 -L /usr/aarch64-linux-gnu password \ 15 | > /tmp/res.txt 16 | @ echo "admin\n4dm1n__4eva" \ 17 | | qemu-aarch64 -L /usr/aarch64-linux-gnu password \ 18 | >> /tmp/res.txt 19 | @ diff out.txt /tmp/res.txt && echo TEST OK 20 | -------------------------------------------------------------------------------- /examples/arm64/password/Makefile.binrats: -------------------------------------------------------------------------------- 1 | AMD64CC=x86_64-linux-gnu-gcc 2 | ARM64CC=aarch64-linux-gnu-gcc 3 | 4 | CFLAGS=-g 5 | 6 | TESTNAME=password 7 | 8 | DD=../../../build/bin/ddisasm 9 | OUT_AMD64=$(TESTNAME)_amd64 10 | OUT_ARM64=$(TESTNAME)_arm64 11 | 12 | .PHONY: all clean 13 | 14 | all: amd64 arm64 15 | 16 | amd64: $(TESTNAME).c 17 | $(AMD64CC) $^ $(CFLAGS) -o $(OUT_AMD64) 18 | $(DD) $(OUT_AMD64) --asm=amd64.s $(DD_FLAGS) 19 | 20 | arm64: $(TESTNAME).c 21 | $(ARM64CC) $^ $(CFLAGS) -o $(OUT_ARM64) 22 | $(DD) $(OUT_ARM64) --asm=arm64.s $(DD_FLAGS) 23 | 24 | clean: 25 | rm -f $(OUT_ARM64) $(OUT_AMD64) arm64.s amd64.s 26 | -------------------------------------------------------------------------------- /examples/arm64_asm_examples/ex_adr_not_split_load/Makefile: -------------------------------------------------------------------------------- 1 | CC=aarch64-linux-gnu-gcc 2 | EXEC=qemu-aarch64 -L /usr/aarch64-linux-gnu 3 | 4 | TARGETS=ex out.txt 5 | 6 | .PHONY: all clean check 7 | all: out.txt 8 | check: out.txt 9 | ex: src.s 10 | $(CC) $^ -o $@ 11 | out.txt: ex 12 | $(EXEC) $^ > $@ 13 | clean: 14 | rm -f $(TARGETS) *.gtirb 15 | -------------------------------------------------------------------------------- /examples/arm64_asm_examples/ex_adr_not_split_load/src.s: -------------------------------------------------------------------------------- 1 | # Ensure that an adr...add pattern does *not* generate a split load for 2 | # unaligned addresses. 3 | 4 | .arch armv8-a 5 | .file "src.s" 6 | .text 7 | .global main 8 | .type main, %function 9 | main: 10 | stp fp,lr,[sp,#-64]! 11 | 12 | # load the addr of the structure. 13 | adr x8,my_struct 14 | 15 | # get a reference to the embedded string. 16 | # this can't be a split load, because my_struct is not page-aligned, and 17 | # thus :lo12:my_struct+8 won't produce the literal value #8. 18 | add x0,x8,#8 19 | bl printf 20 | 21 | .exit: 22 | ldp fp,lr,[sp],#64 23 | mov x0, #0 24 | ret 25 | 26 | .section .rodata 27 | # ensure things are not page-aligned. 28 | .zero 84 29 | 30 | # a global structure has an embedded string at offset +8. 31 | my_struct: 32 | .quad 1234 33 | .asciz "hello\n" 34 | -------------------------------------------------------------------------------- /examples/arm64_asm_examples/ex_cfg/Makefile: -------------------------------------------------------------------------------- 1 | CC=aarch64-linux-gnu-gcc 2 | EXEC=qemu-aarch64 -L /usr/aarch64-linux-gnu 3 | 4 | TARGETS=ex out.txt 5 | 6 | .PHONY: all clean check 7 | all: out.txt 8 | check: out.txt 9 | ex: src.s 10 | $(CC) $^ -o $@ 11 | out.txt: ex 12 | $(EXEC) $^ > $@ 13 | clean: 14 | rm -f $(TARGETS) *.gtirb 15 | -------------------------------------------------------------------------------- /examples/arm64_asm_examples/ex_cond_branch/Makefile: -------------------------------------------------------------------------------- 1 | CC=aarch64-linux-gnu-gcc 2 | EXEC=qemu-aarch64 -L /usr/aarch64-linux-gnu 3 | 4 | TARGETS=ex out.txt 5 | 6 | .PHONY: all clean check 7 | all: out.txt 8 | check: out.txt 9 | ex: src.s 10 | $(CC) $^ -o $@ 11 | out.txt: ex 12 | $(EXEC) $^ > $@ 13 | clean: 14 | rm -f $(TARGETS) *.gtirb 15 | -------------------------------------------------------------------------------- /examples/arm64_asm_examples/ex_cond_branch/src.s: -------------------------------------------------------------------------------- 1 | # Test special conditional branch operations (tbz, tbnz, cbz, cbnz) 2 | 3 | .arch armv8-a 4 | .file "src.s" 5 | .text 6 | .global main 7 | .type main, %function 8 | main: 9 | stp fp,lr,[sp,#-16]! 10 | mov fp,sp 11 | 12 | mov x19, #8 13 | .loop: 14 | cbz x19, .zero 15 | cbnz x19, .test 16 | b .exit 17 | 18 | .zero: 19 | adrp x0, .fmt_zero 20 | add x0, x0, :lo12:.fmt_zero 21 | b .print 22 | 23 | .test: 24 | tbz x19, #0, .even 25 | tbnz x19, #0, .odd 26 | b .exit 27 | 28 | .odd: 29 | adrp x0, .fmt_odd 30 | add x0, x0, :lo12:.fmt_odd 31 | b .print 32 | .even: 33 | adrp x0, .fmt_even 34 | add x0, x0, :lo12:.fmt_even 35 | 36 | .print: 37 | mov x1, x19 38 | bl printf 39 | 40 | sub x19, x19, #1 41 | cbnz x19, .loop 42 | 43 | ldp fp,lr,[sp],#16 44 | mov x0, #0 45 | ret 46 | 47 | .exit: 48 | ldp fp,lr,[sp],#16 49 | mov x0, #1 50 | ret 51 | 52 | .section .rodata 53 | .fmt_zero: 54 | .ascii "%d: zero\n\0" 55 | .fmt_odd: 56 | .ascii "%d: odd\n\0" 57 | .fmt_even: 58 | .ascii "%d: even\n\0" 59 | -------------------------------------------------------------------------------- /examples/arm64_asm_examples/ex_op_types/Makefile: -------------------------------------------------------------------------------- 1 | CC=aarch64-linux-gnu-gcc 2 | 3 | TARGETS=ex out.txt 4 | 5 | .PHONY: all clean 6 | all: ex 7 | ex: src.s 8 | $(CC) $^ -o $@ 9 | clean: 10 | rm -f $(TARGETS) *.gtirb 11 | -------------------------------------------------------------------------------- /examples/arm64_asm_examples/ex_op_types/src.s: -------------------------------------------------------------------------------- 1 | # Test strange operand types 2 | .arch armv8-a 3 | .file "src.s" 4 | .text 5 | .global main 6 | .type main, %function 7 | main: 8 | stp fp,lr,[sp,#-16]! 9 | mov fp,sp 10 | 11 | # SYS 12 | mrs x0, tpidr_el0 13 | msr tpidr_el0, x0 14 | 15 | # PSTATE 16 | msr DAIFSet, #10 17 | 18 | # SYS (at_op) 19 | at s12e0r, x0 20 | dc cvau, x2 21 | ic ivau, x0 22 | 23 | ldp fp,lr,[sp],#16 24 | ret 25 | -------------------------------------------------------------------------------- /examples/arm64_asm_examples/ex_post_index_no_lo12/Makefile: -------------------------------------------------------------------------------- 1 | CC=aarch64-linux-gnu-gcc 2 | EXEC=qemu-aarch64 -L /usr/aarch64-linux-gnu 3 | 4 | TARGETS=ex out.txt 5 | 6 | .PHONY: all clean check 7 | all: out.txt 8 | check: out.txt 9 | ex: src.s 10 | $(CC) $^ -o $@ 11 | out.txt: ex 12 | $(EXEC) $^ > $@ 13 | clean: 14 | rm -f $(TARGETS) *.gtirb 15 | -------------------------------------------------------------------------------- /examples/arm64_asm_examples/ex_post_index_no_lo12/src.s: -------------------------------------------------------------------------------- 1 | # Ensure that post-index operands do not get :lo12: attributes. 2 | 3 | .arch armv8-a 4 | .file "src.s" 5 | .text 6 | .global main 7 | .type main, %function 8 | main: 9 | stp fp,lr,[sp,#-64]! 10 | 11 | # load the addr of the structure. 12 | adrp x8,my_struct 13 | mov x0,#0 14 | 15 | # Looks like a split-load, except that :lo12: is not allowed in post-index 16 | # operands. 17 | ldr x1,[x8],#8 18 | 19 | adrp x0, my_string 20 | add x0, x0, :lo12:my_string 21 | bl printf 22 | 23 | .exit: 24 | ldp fp,lr,[sp],#64 25 | mov x0, #0 26 | ret 27 | 28 | .section .rodata 29 | # ensure we are page-aligned. 30 | .balign 4096 31 | my_struct: 32 | .quad 1234 33 | 34 | my_string: 35 | .asciz "my number is: %d\n" 36 | -------------------------------------------------------------------------------- /examples/arm64_asm_examples/ex_registers/Makefile: -------------------------------------------------------------------------------- 1 | CC=aarch64-linux-gnu-gcc 2 | EXEC=qemu-aarch64 -L /usr/aarch64-linux-gnu 3 | 4 | TARGETS=ex out.txt 5 | 6 | .PHONY: all clean check 7 | all: out.txt 8 | check: out.txt 9 | ex: src.s 10 | $(CC) $^ -o $@ 11 | out.txt: ex 12 | $(EXEC) $^ > $@ 13 | clean: 14 | rm -f $(TARGETS) *.gtirb 15 | -------------------------------------------------------------------------------- /examples/arm64_asm_examples/ex_registers/src.s: -------------------------------------------------------------------------------- 1 | # Test special register names 2 | 3 | .arch armv8-a 4 | .file "src.s" 5 | .text 6 | .global main 7 | .type main, %function 8 | main: 9 | stp fp,lr,[sp,#-16]! 10 | 11 | adrp lr, .hello_lr 12 | add x0, lr, #:lo12:.hello_lr 13 | 14 | bl printf 15 | 16 | adrp fp, .hello_fp 17 | add x0, fp, #:lo12:.hello_fp 18 | 19 | bl printf 20 | 21 | .exit: 22 | ldp fp,lr,[sp],#16 23 | mov x0, #0 24 | ret 25 | 26 | .section .rodata 27 | .hello_lr: 28 | .asciz "hello lr\n" 29 | .hello_fp: 30 | .asciz "hello fp\n" 31 | -------------------------------------------------------------------------------- /examples/arm64_asm_examples/ex_stack_split_load/Makefile: -------------------------------------------------------------------------------- 1 | CC=aarch64-linux-gnu-gcc 2 | EXEC=qemu-aarch64 -L /usr/aarch64-linux-gnu 3 | 4 | TARGETS=ex out.txt 5 | 6 | .PHONY: all clean check 7 | all: out.txt 8 | check: out.txt 9 | ex: src.s 10 | $(CC) $^ -o $@ 11 | out.txt: ex 12 | $(EXEC) $^ > $@ 13 | clean: 14 | rm -f $(TARGETS) *.gtirb 15 | -------------------------------------------------------------------------------- /examples/arm64_asm_examples/ex_switch1/Makefile: -------------------------------------------------------------------------------- 1 | CC=aarch64-linux-gnu-gcc 2 | EXEC=qemu-aarch64 -L /usr/aarch64-linux-gnu 3 | 4 | TARGETS=ex out.txt 5 | 6 | .PHONY: all clean check 7 | all: out.txt 8 | check: out.txt 9 | ex: src.s 10 | $(CC) $^ -o $@ 11 | out.txt: ex 12 | $(EXEC) $^ > $@ 13 | clean: 14 | rm -f $(TARGETS) *.gtirb 15 | -------------------------------------------------------------------------------- /examples/arm64_asm_examples/ex_switch1/src.s: -------------------------------------------------------------------------------- 1 | # Test switch with shift in indirect operand 2 | 3 | .arch armv8-a 4 | .file "src.s" 5 | .text 6 | .global main 7 | .type main, %function 8 | main: 9 | stp fp,lr,[sp,#-16]! 10 | mov fp,sp 11 | 12 | mov w0, #2 13 | 14 | adrp x1, .L_jumptable 15 | add x1,x1, :lo12:.L_jumptable 16 | ldr w0,[x1,w0,uxtw #2] 17 | adr x1, .L0 18 | add x0,x1,w0, sxtw #2 19 | br x0 20 | 21 | .L0: 22 | adrp x0, .s_zero 23 | add x0, x0, :lo12:.s_zero 24 | b .L_print 25 | .L1: 26 | adrp x0, .s_one 27 | add x0, x0, :lo12:.s_one 28 | b .L_print 29 | .L2: 30 | adrp x0, .s_two 31 | add x0, x0, :lo12:.s_two 32 | b .L_print 33 | .L3: 34 | adrp x0, .s_three 35 | add x0, x0, :lo12:.s_three 36 | 37 | .L_print: 38 | bl printf 39 | 40 | .L_exit: 41 | ldp fp,lr,[sp],#16 42 | mov x0, #0 43 | ret 44 | 45 | .L_jumptable: 46 | .long (.L0-.L0)/4 47 | .long (.L1-.L0)/4 48 | .long (.L2-.L0)/4 49 | .long (.L3-.L0)/4 50 | 51 | .section .rodata 52 | .s_zero: 53 | .ascii "zero\n\0" 54 | .s_one: 55 | .ascii "one\n\0" 56 | .s_two: 57 | .ascii "two\n\0" 58 | .s_three: 59 | .ascii "three\n\0" 60 | -------------------------------------------------------------------------------- /examples/arm64_asm_examples/ex_switch2/Makefile: -------------------------------------------------------------------------------- 1 | CC=aarch64-linux-gnu-gcc 2 | EXEC=qemu-aarch64 -L /usr/aarch64-linux-gnu 3 | 4 | TARGETS=ex out.txt 5 | 6 | .PHONY: all clean check 7 | all: out.txt 8 | check: out.txt 9 | ex: src.s 10 | $(CC) $^ -o $@ 11 | out.txt: ex 12 | $(EXEC) $^ > $@ 13 | clean: 14 | rm -f $(TARGETS) *.gtirb 15 | -------------------------------------------------------------------------------- /examples/arm64_asm_examples/ex_switch2/src.s: -------------------------------------------------------------------------------- 1 | # Test switch nop as a target 2 | 3 | .arch armv8-a 4 | .file "src.s" 5 | .text 6 | .global main 7 | .type main, %function 8 | main: 9 | stp fp,lr,[sp,#-16]! 10 | mov fp,sp 11 | 12 | mov w0, #2 13 | 14 | adrp x1, .L_jumptable 15 | add x1,x1, :lo12:.L_jumptable 16 | ldr w0,[x1,w0,uxtw #2] 17 | adr x1, .L_exit 18 | add x0,x1,w0, sxtw #2 19 | br x0 20 | 21 | .L0: 22 | nop 23 | adrp x0, .s_zero 24 | add x0, x0, :lo12:.s_zero 25 | b .L_print 26 | .L1: 27 | adrp x0, .s_one 28 | add x0, x0, :lo12:.s_one 29 | b .L_print 30 | .L2: 31 | adrp x0, .s_two 32 | add x0, x0, :lo12:.s_two 33 | b .L_print 34 | .L3: 35 | adrp x0, .s_three 36 | add x0, x0, :lo12:.s_three 37 | 38 | .L_print: 39 | bl printf 40 | 41 | .L_exit: 42 | ldp fp,lr,[sp],#16 43 | mov x0, #0 44 | ret 45 | 46 | .L_jumptable: 47 | .long (.L0-.L_exit)/4 48 | .long (.L1-.L_exit)/4 49 | .long (.L2-.L_exit)/4 50 | .long (.L3-.L_exit)/4 51 | 52 | .section .rodata 53 | .s_zero: 54 | .ascii "zero\n\0" 55 | .s_one: 56 | .ascii "one\n\0" 57 | .s_two: 58 | .ascii "two\n\0" 59 | .s_three: 60 | .ascii "three\n\0" 61 | -------------------------------------------------------------------------------- /examples/arm64_asm_examples/ex_switch3/Makefile: -------------------------------------------------------------------------------- 1 | CC=aarch64-linux-gnu-gcc 2 | EXEC=qemu-aarch64 -L /usr/aarch64-linux-gnu 3 | 4 | TARGETS=ex out.txt 5 | 6 | .PHONY: all clean check 7 | all: out.txt 8 | check: out.txt 9 | ex: src.s 10 | $(CC) $^ -o $@ 11 | out.txt: ex 12 | $(EXEC) $^ > $@ 13 | clean: 14 | rm -f $(TARGETS) *.gtirb 15 | -------------------------------------------------------------------------------- /examples/arm64_asm_examples/ex_switch4/Makefile: -------------------------------------------------------------------------------- 1 | CC=aarch64-linux-gnu-gcc 2 | EXEC=qemu-aarch64 -L /usr/aarch64-linux-gnu 3 | 4 | TARGETS=ex out.txt 5 | 6 | .PHONY: all clean check 7 | all: out.txt 8 | check: out.txt 9 | ex: src.s 10 | $(CC) $^ -o $@ 11 | out.txt: ex 12 | $(EXEC) $^ > $@ 13 | clean: 14 | rm -f $(TARGETS) *.gtirb 15 | -------------------------------------------------------------------------------- /examples/arm64_asm_examples/ex_switch_limited_by_cmp/Makefile: -------------------------------------------------------------------------------- 1 | CC=aarch64-linux-gnu-gcc 2 | EXEC=qemu-aarch64 -L /usr/aarch64-linux-gnu 3 | 4 | TARGETS=ex out.txt 5 | 6 | .PHONY: all clean check 7 | all: out.txt 8 | check: out.txt 9 | ex: src.s 10 | $(CC) $^ -o $@ 11 | out.txt: ex 12 | $(EXEC) $^ > $@ 13 | clean: 14 | rm -f $(TARGETS) *.gtirb 15 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex1_no_pie/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | arm-linux-gnueabihf-gcc ex_original.s -no-pie -o ex 4 | @qemu-arm -L /usr/arm-linux-gnueabihf ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | check: 8 | qemu-arm -L /usr/arm-linux-gnueabihf ex > /tmp/res.txt 9 | @ diff out.txt /tmp/res.txt && echo TEST OK 10 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex1_pie/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | arm-linux-gnueabihf-gcc ex_original.s -pie -o ex 4 | @qemu-arm -L /usr/arm-linux-gnueabihf ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | check: 8 | qemu-arm -L /usr/arm-linux-gnueabihf ex > /tmp/res.txt 9 | @ diff out.txt /tmp/res.txt && echo TEST OK 10 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_add_as_jump/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | ex: ex_add_as_jump.s 5 | arm-linux-gnueabihf-gcc -no-pie -o $@ $^ 6 | clean: 7 | rm -f ex out.txt 8 | check: ex 9 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_add_as_jump/ex_add_as_jump.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | .section .text 3 | 4 | .global main 5 | .type main, %function 6 | main: 7 | ldr r12, [pc] 8 | .add: 9 | add pc, r12, pc 10 | 11 | .long do_print-(.add+8) 12 | .L2: 13 | .long str 14 | 15 | .global do_print 16 | .type do_print, %function 17 | do_print: 18 | push { lr } 19 | ldr r0, .L2 20 | blx printf 21 | mov r0, #0 22 | pop { pc } 23 | 24 | #=================================== 25 | .section .rodata ,"a",%progbits 26 | #=================================== 27 | 28 | .align 2 29 | str: 30 | .string "hello world\n" 31 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_adr_to_code/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | 5 | ex: ex_original.s 6 | arm-linux-gnueabihf-gcc -nostartfiles -o $@ $^ 7 | clean: 8 | rm -f ex out.txt 9 | check: ex 10 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 11 | @ diff out.txt /tmp/res.txt && echo TEST OK 12 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_aliased_data/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | # ex_aliased_data is only meaningful when stripped; ddisasm only gets 5 | # confused about fake code without mapping symbols 6 | # We currently keep __libc_csu* symbols due to issue#493 7 | ex: ex.unstripped 8 | arm-linux-gnueabihf-strip --strip-unneeded --keep-symbol=__libc_csu_init --keep-symbol=__libc_csu_fini -o $@ $^ 9 | ex.unstripped: ex_aliased_data.s 10 | arm-linux-gnueabihf-gcc -pie -o $@ $^ 11 | clean: 12 | rm -f ex ex.unstripped out.txt 13 | check: ex 14 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 15 | @ diff out.txt /tmp/res.txt && echo TEST OK 16 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_aliased_data/ex_aliased_data.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | 3 | #=================================== 4 | .section .text 5 | #=================================== 6 | 7 | .arm 8 | .global main 9 | .type main, %function 10 | main: 11 | push { lr } 12 | cmp r0, #10 13 | 14 | adr r0, .litpool 15 | ldm r0, {r0, r1, r2} 16 | ldr r0, .litpool_format 17 | 18 | blt .print 19 | 20 | mvn r0, #0 21 | pop { pc } 22 | 23 | .litpool: 24 | # This fake code, which ddisasm should (correctly) consider data, create 25 | # an 8-byte data block at litpool_format. The real code creates a 4-byte 26 | # data block at litpool_format. ddisasm should be able to differentiate 27 | # these two data blocks (despite having the same address) and still 28 | # disassemble code at .print successfully. 29 | adr r0, .litpool_format 30 | ldm r0, {r0, r1} 31 | 32 | # ensure this fake code is not considered invalid 33 | b .print 34 | 35 | .litpool_format: 36 | .long print_format 37 | 38 | .print: 39 | bl printf 40 | 41 | mov r0, #0 42 | pop { pc } 43 | 44 | #=================================== 45 | .section .rodata ,"a",%progbits 46 | #=================================== 47 | print_format: 48 | .string "hello world: %x %x\n" 49 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_blx_interwork/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | ex: ex_blx_interwork.s 5 | arm-linux-gnueabihf-gcc -o $@ $^ 6 | clean: 7 | rm -f ex out.txt 8 | check: ex 9 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_blx_interwork/ex_blx_interwork.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | .section .text 3 | 4 | .arm 5 | .global main 6 | .type main, %function 7 | main: 8 | push { lr } 9 | 10 | ldr r0, litpool 11 | blx fun 12 | 13 | mov r0, #0 14 | pop { lr } 15 | bx lr 16 | 17 | .thumb 18 | .global fun 19 | .type fun, %function 20 | fun: 21 | push { lr } 22 | 23 | bl printf 24 | 25 | pop { lr } 26 | bx lr 27 | 28 | litpool: 29 | .word my_str 30 | 31 | .section .data 32 | 33 | my_str: 34 | .string "Hello World\n" 35 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_bx_pc/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | ex: ex_bx_pc.s 5 | arm-linux-gnueabihf-gcc -o $@ $^ 6 | clean: 7 | rm -f ex out.txt 8 | check: ex 9 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_bx_pc/ex_bx_pc.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | .section .text 3 | 4 | .thumb 5 | .global main 6 | .type main, %function 7 | main: 8 | bx pc 9 | nop 10 | .arm 11 | mov r0, #0 12 | bx lr 13 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_cfg/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | ex: ex_cfg.s 5 | arm-linux-gnueabihf-gcc -o $@ $^ 6 | clean: 7 | rm -f ex out.txt 8 | check: ex 9 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_cfg/ex_cfg.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | 3 | #=================================== 4 | .section .text 5 | #=================================== 6 | 7 | .thumb 8 | .global main 9 | .type main, %function 10 | main: 11 | push { lr } 12 | cmp r0, #10 13 | itt eq 14 | moveq r0, #1 15 | bxeq lr 16 | 17 | cmp r0, #7 18 | beq .L1 19 | blx foo 20 | 21 | ldr r0, .L2 22 | blx printf 23 | .L1: 24 | mov r0, #0 25 | pop { pc } 26 | 27 | .arm 28 | .global foo 29 | .type foo, %function 30 | foo: 31 | mov r0, #0 32 | bx lr 33 | 34 | .L2: 35 | .long print_format 36 | 37 | #=================================== 38 | .section .rodata ,"a",%progbits 39 | #=================================== 40 | 41 | .align 2 42 | print_format: 43 | .string "arm32 cfg test\n" 44 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_code_after_literal_pool/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | ex: ex_code_after_literal_pool.s 5 | arm-linux-gnueabihf-gcc -o $@ $^ 6 | clean: 7 | rm -f ex out.txt 8 | check: ex 9 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_code_after_literal_pool/ex_code_after_literal_pool.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | .section .text 3 | 4 | .global main 5 | .type main, %function 6 | main: 7 | push { lr } 8 | ldr r0, .L2 9 | blx printf 10 | mov r0, #0 11 | pop { pc } 12 | .L2: 13 | .long str 14 | 15 | # here, we have some code that nothing references, and occurs after a literal 16 | # pool. We want to ensure it is still considered code. 17 | 18 | mov r1, r0 19 | ldr r0, [r1, #10] 20 | bx lr 21 | 22 | #=================================== 23 | .section .rodata ,"a",%progbits 24 | #=================================== 25 | 26 | .align 2 27 | str: 28 | .string "hello world\n" 29 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_func_after_litpool/Makefile: -------------------------------------------------------------------------------- 1 | AS=arm-linux-gnueabihf-as 2 | LD=arm-linux-gnueabihf-ld 3 | STRIP=arm-linux-gnueabihf-strip 4 | 5 | all: ex 6 | 7 | ex: ex_original.s 8 | $(AS) -march=armv7-a -o ex.o ex_original.s 9 | $(LD) -o ex ex.o 10 | $(STRIP) ex 11 | @qemu-arm -L /usr/arm-linux-gnueabihf ./ex > out.txt 12 | 13 | clean: 14 | rm -f ex ex.o out.txt 15 | 16 | check: 17 | qemu-arm -L /usr/arm-linux-gnueabihf ./ex > /tmp/res.txt 18 | @ diff out.txt /tmp/res.txt && echo TEST OK 19 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_halts/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | ex: ex_halts.s 5 | arm-linux-gnueabihf-gcc -o $@ $^ 6 | clean: 7 | rm -f ex out.txt ex.gtirb 8 | check: ex 9 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_halts/ex_halts.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | .section .text 3 | .thumb 4 | .arch armv8-a 5 | 6 | .global main 7 | .type main, %function 8 | main: 9 | push {lr} 10 | 11 | cmp r0, #10 12 | bgt halt 13 | bgt trap 14 | bgt udf 15 | 16 | ldr r0, =message 17 | bl printf 18 | 19 | mov r0, #0 20 | pop {pc} 21 | 22 | halt: 23 | hlt 24 | 25 | .long 0xffffffff 26 | 27 | trap: 28 | udf 0xfe 29 | 30 | .long 0xffffffff 31 | 32 | udf: 33 | udf 0xff 34 | 35 | .long 0xffffffff 36 | 37 | .section .rodata 38 | message: 39 | .asciz "Hello World!\n" 40 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_it_split/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | ex: ex_it_split.s 5 | arm-linux-gnueabihf-gcc -pie -o $@ $^ 6 | clean: 7 | rm -f ex out.txt 8 | check: ex 9 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_it_split/ex_it_split.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | 3 | #=================================== 4 | .section .text 5 | #=================================== 6 | 7 | .thumb 8 | .global main 9 | .type main, %function 10 | main: 11 | push { lr } 12 | cmp r0, #10 13 | itt eq 14 | test_ptr: 15 | moveq r0, #1 16 | bxeq lr 17 | 18 | cmp r0, #7 19 | beq .L1 20 | blx foo 21 | 22 | ldr r0, .L2 23 | blx printf 24 | .L1: 25 | mov r0, #0 26 | pop { pc } 27 | 28 | .arm 29 | .global foo 30 | .type foo, %function 31 | foo: 32 | mov r0, #0 33 | bx lr 34 | 35 | .L2: 36 | .long print_format 37 | 38 | #=================================== 39 | .section .rodata ,"a",%progbits 40 | #=================================== 41 | .align 2 42 | // Reference the middle of the IT block, which must not be split into two blocks. 43 | .word test_ptr+1 44 | print_format: 45 | .string "arm32 cfg test\n" 46 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_jumptable/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | ex: ex_jumptable.s 3 | arm-linux-gnueabihf-gcc -o $@ ex_jumptable.s 4 | 5 | clean: 6 | rm -f ex ex_jumptable.o 7 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_jumptable/ex_jumptable.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | .section .text 3 | 4 | .global main 5 | .type main, %function 6 | .arm 7 | 8 | main: 9 | push { lr } 10 | 11 | mov r0, #0 12 | cmp r0, #7 13 | ldrls pc, [pc, r0, LSL2] 14 | b .exit 15 | 16 | .jt: 17 | .long .case1 18 | .long .case2 19 | .long .case3 20 | .split: 21 | .long .case4 22 | .long .case5 23 | .long .case6 24 | 25 | @ Using nops for each case ensures that the jump table targets must drive 26 | @ code block boundaries. 27 | .case1: 28 | nop 29 | .case2: 30 | nop 31 | .case3: 32 | nop 33 | .case4: 34 | nop 35 | .case5: 36 | nop 37 | .case6: 38 | nop 39 | 40 | .exit: 41 | mov r0, 0 42 | pop { pc } 43 | 44 | .section .rodata 45 | @ Ensure the jumptable is split into multiple code block candidates with 46 | @ address_in_data() 47 | .long .split 48 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_ldcl/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean 2 | ex: ex_ldcl.s 3 | arm-linux-gnueabihf-gcc -march=armv7-a -o $@ $^ 4 | clean: 5 | rm -f ex out.txt 6 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_ldcl/ex_ldcl.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | .section .text 3 | 4 | .global main 5 | .type main, %function 6 | main: 7 | push {lr} 8 | ldcl p1, c0, [r0], #8 9 | pop {pc} 10 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_ldr/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | ex: ex_ldr.s 5 | arm-linux-gnueabihf-gcc -o $@ $^ 6 | clean: 7 | rm -f ex out.txt 8 | check: ex 9 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_ldr_pc_rel_reg/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | ex: ex_ldr_pc_rel_reg.s 5 | arm-linux-gnueabihf-gcc -no-pie -o $@ $^ 6 | clean: 7 | rm -f ex out.txt 8 | check: ex 9 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_ldr_pc_rel_reg/ex_ldr_pc_rel_reg.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | 3 | #=================================== 4 | .section .text 5 | #=================================== 6 | 7 | .arm 8 | .global main 9 | .type main, %function 10 | main: 11 | push { lr } 12 | 13 | cmp r0, #3 14 | bge .fail 15 | 16 | lsl r0, r0, #2 17 | ldr r1, .offset 18 | add r1, r1, r0 19 | 20 | .ref: 21 | ldr r1, [pc, r1] 22 | ldr r0, .L2 23 | blx printf 24 | mov r0, #0 25 | pop { pc } 26 | 27 | .fail: 28 | mov r0, #1 29 | pop { pc } 30 | 31 | .L2: 32 | .long print_format 33 | 34 | .messages: 35 | .long .one 36 | .long .two 37 | .long .three 38 | 39 | .offset: 40 | .long .messages - (.ref + 8) 41 | 42 | #=================================== 43 | .section .rodata ,"a",%progbits 44 | #=================================== 45 | print_format: 46 | .string "argument count: %s\n" 47 | 48 | .one: 49 | .string "one" 50 | 51 | .two: 52 | .string "two" 53 | 54 | .three: 55 | .string "three" 56 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_litpool/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | arm-linux-gnueabihf-gcc ex_original.s -no-pie -o ex 4 | @qemu-arm -L /usr/arm-linux-gnueabihf ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | check: 8 | qemu-arm -L /usr/arm-linux-gnueabihf ex > /tmp/res.txt 9 | @ diff out.txt /tmp/res.txt && echo TEST OK 10 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_movw_movt/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | arm-linux-gnueabihf-gcc ex_original.s -no-pie -o ex 4 | @qemu-arm -L /usr/arm-linux-gnueabihf ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | check: 8 | qemu-arm -L /usr/arm-linux-gnueabihf ex > /tmp/res.txt 9 | @ diff out.txt /tmp/res.txt && echo TEST OK 10 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_movw_movt/ex_original.s: -------------------------------------------------------------------------------- 1 | .arch armv7-a 2 | 3 | .section .rodata 4 | .align 2 5 | .LC0: 6 | .ascii "!!!Hello World!!!\000" 7 | .LC1: 8 | .ascii "!!!This is a test!!!\000" 9 | print_format: 10 | .string "%d\n" 11 | 12 | .text 13 | .align 2 14 | .thumb 15 | fun: 16 | push { r1, lr } 17 | mov r1, r0 18 | ldr r0, .L_1 19 | bl printf(PLT) 20 | .thumb 21 | mov r0, #0 22 | pop { r1, pc } 23 | .align 2 24 | .L_1: 25 | .word print_format 26 | 27 | .align 2 28 | .global main 29 | .syntax unified 30 | .thumb 31 | .thumb_func 32 | .type main, %function 33 | .thumb 34 | main: 35 | push {r7, lr} 36 | add r7, sp, #0 37 | # (A): There is no corresponding movt to this: it should not be symbolized. 38 | movw r0, #:lower16:.LC1 39 | bl fun 40 | .thumb 41 | # (B) This should be a pair with (C): distance 1 42 | movw r0, #:lower16:.LC0 43 | # (C) This cannot be a pair with (A) 44 | movt r0, #:upper16:.LC0 45 | bl puts(PLT) 46 | # (D) 47 | movw r1, #:lower16:.LC1 48 | movw r0, #7 49 | bl fun 50 | # (E) This should be a pair with (D): distance 3 51 | movt r1, #:upper16:.LC1 52 | mov r0, r1 53 | bl puts(PLT) 54 | .thumb 55 | movs r3, #0 56 | mov r0, r3 57 | pop {r7, pc} 58 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_movw_movt_pie/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | arm-linux-gnueabihf-gcc ex_original.s -pie -o ex 4 | @qemu-arm -L /usr/arm-linux-gnueabihf ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | check: 8 | qemu-arm -L /usr/arm-linux-gnueabihf ex > /tmp/res.txt 9 | @ diff out.txt /tmp/res.txt && echo TEST OK 10 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_movw_movt_pie/ex_original.s: -------------------------------------------------------------------------------- 1 | .arch armv7-a 2 | .section .text 3 | .align 2 4 | .global main 5 | .type main, %function 6 | .thumb 7 | main: 8 | push {r7, lr} 9 | .thumb 10 | ldr r0, .L0 11 | # This address corresponds to _start+4, but it should not symbolize, 12 | # because this is a PIE binary. 13 | # Hopefully the compiler continues to generate the same addresses... 14 | movw r1, #0x409 15 | movt r1, #0 16 | 17 | bl printf 18 | .thumb 19 | mov r0, #0 20 | pop {r7, pc} 21 | 22 | .L0: 23 | .long print_format 24 | 25 | .section .rodata 26 | .align 2 27 | print_format: 28 | .string "%x\n" 29 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_relative_jump_table/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | ex: ex_original.s 5 | arm-linux-gnueabihf-gcc -o $@ $^ 6 | clean: 7 | rm -f ex out.txt 8 | check: ex 9 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_relative_jump_table2/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | ex: ex_original.s 5 | arm-linux-gnueabihf-gcc -o $@ $^ 6 | clean: 7 | rm -f ex out.txt 8 | check: ex 9 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_relative_jump_table2/ex_original.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | .section .text 3 | 4 | .global main 5 | .type main, %function 6 | .arm 7 | .align 4 8 | main: 9 | push { lr } 10 | cmp r0, #3 11 | bhi .exit 12 | 13 | adr r2, .L0 14 | lsl r1, r0, #2 15 | ldr r1, [r1, r2] 16 | add pc, r1, r2 17 | .L0: 18 | .long .case0 - .L0 19 | .long .case1 - .L0 20 | .long .case2 - .L0 21 | .long .case3 - .L0 22 | 23 | .case0: 24 | ldr r0, .L1 25 | b .print 26 | .case1: 27 | ldr r0, .L2 28 | b .print 29 | .case2: 30 | ldr r0, .L3 31 | b .print 32 | .case3: 33 | ldr r0, .L4 34 | b .print 35 | 36 | .print: 37 | add r0, pc, r0 38 | bl printf 39 | 40 | .exit: 41 | mov r0, 0 42 | pop { pc } 43 | 44 | .L1: 45 | .long str_one - (.print + 8) 46 | .L2: 47 | .long str_two - (.print + 8) 48 | .L3: 49 | .long str_three - (.print + 8) 50 | .L4: 51 | .long str_four - (.print + 8) 52 | 53 | .section .rodata 54 | 55 | str_one: 56 | .string "one\n" 57 | str_two: 58 | .string "two\n" 59 | str_three: 60 | .string "three\n" 61 | str_four: 62 | .string "four\n" 63 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_relative_jump_table3/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | ex: ex_original.s 5 | arm-linux-gnueabihf-gcc -o $@ $^ 6 | clean: 7 | rm -f ex out.txt 8 | check: ex 9 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_relative_jump_table3/ex_original.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | .section .text 3 | 4 | .global main 5 | .type main, %function 6 | .arm 7 | .align 4 8 | main: 9 | push { lr } 10 | cmp r0, #3 11 | bhi .exit 12 | 13 | mov r5, r0 14 | ldr ip, [pc, r5, LSL 2] 15 | add pc, pc, ip 16 | bkpt #0 17 | .L0: 18 | .long .case0 - .L0 19 | .long .case1 - .L0 20 | .long .case2 - .L0 21 | .long .case3 - .L0 22 | 23 | .case0: 24 | ldr r0, .L1 25 | b .print 26 | .case1: 27 | ldr r0, .L2 28 | b .print 29 | .case2: 30 | ldr r0, .L3 31 | b .print 32 | .case3: 33 | ldr r0, .L4 34 | b .print 35 | 36 | .print: 37 | add r0, pc, r0 38 | bl printf 39 | 40 | .exit: 41 | mov r0, 0 42 | pop { pc } 43 | 44 | .L1: 45 | .long str_one - (.print + 8) 46 | .L2: 47 | .long str_two - (.print + 8) 48 | .L3: 49 | .long str_three - (.print + 8) 50 | .L4: 51 | .long str_four - (.print + 8) 52 | 53 | .section .rodata 54 | 55 | str_one: 56 | .string "one\n" 57 | str_two: 58 | .string "two\n" 59 | str_three: 60 | .string "three\n" 61 | str_four: 62 | .string "four\n" 63 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_setend/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | ex: ex_setend.s 5 | arm-linux-gnueabihf-gcc -o $@ $^ 6 | clean: 7 | rm -f ex out.txt 8 | check: ex 9 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_setend/ex_setend.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | .section .text 3 | 4 | .global main 5 | .type main, %function 6 | main: 7 | push {lr} 8 | 9 | setend be 10 | ldr r1, myword 11 | setend le 12 | 13 | ldr r0, =print_format 14 | bl printf 15 | 16 | mov r0, #0 17 | pop {pc} 18 | 19 | myword: 20 | .long 0xDEADBEEF 21 | 22 | .section .rodata 23 | print_format: 24 | .ascii "%x\n\0" 25 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_stm_reglist_invalid/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | ex: ex_original.s 5 | arm-linux-gnueabihf-gcc -o $@ $^ 6 | clean: 7 | rm -f ex out.txt 8 | check: ex 9 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_stm_reglist_invalid/ex_original.s: -------------------------------------------------------------------------------- 1 | # Regression test: `stm r0!, {r0, r1}` is not considered an invalid instruction. 2 | # `stm r1!, {r0, r1, r2}` causes a warning but compiles and it has been 3 | # seen in real binaries 4 | 5 | .syntax unified 6 | .section .text 7 | 8 | .global main 9 | .type main, %function 10 | .thumb 11 | .align 4 12 | main: 13 | push { lr } 14 | 15 | ldr r0, =data 16 | stm r0!, {r0, r1} 17 | ldr r1, =data 18 | # this causes a warning "Warning: value stored for r1 is UNKNOWN", but compiles 19 | # if r1 is later not used it is acceptable 20 | stm r1!, {r0, r1, r2} 21 | mov r0, 0 22 | pop { pc } 23 | 24 | .section .data 25 | data: 26 | .long 0 27 | .long 1 28 | .long 2 29 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_tbb/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | ex: ex_tbb.s 5 | arm-linux-gnueabihf-gcc -o $@ $^ 6 | clean: 7 | rm -f ex out.txt 8 | check: ex 9 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_tbb/ex_tbb.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | .section .text 3 | 4 | .global main 5 | .type main, %function 6 | .thumb 7 | .align 4 8 | main: 9 | push { lr } 10 | mov r0, 2 11 | cmp r0, #3 12 | bhi .exit 13 | tbb [pc, r0] 14 | 15 | .jt: 16 | .byte (.case0 - .jt) / 2 17 | .byte (.case1 - .jt) / 2 18 | .byte (.case2 - .jt) / 2 19 | .byte (.case3 - .jt) / 2 20 | 21 | @ Using nops for each case ensures that the jump table targets must drive 22 | @ code block boundaries. 23 | .case0: 24 | nop 25 | .case1: 26 | nop 27 | .case2: 28 | nop 29 | .case3: 30 | nop 31 | 32 | .exit: 33 | mov r0, 0 34 | pop { pc } 35 | 36 | .section .rodata 37 | @ Ensure the jumptable is split into multiple code block candidates with 38 | @ address_in_data() 39 | .long .jt+2 40 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_tbb_r3_adr/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | ex: ex_tbb.s 5 | arm-linux-gnueabihf-gcc -o $@ $^ 6 | clean: 7 | rm -f ex out.txt 8 | check: ex 9 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_tbb_r3_adr/ex_tbb.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | .section .text 3 | 4 | .global main 5 | .type main, %function 6 | .thumb 7 | .align 4 8 | main: 9 | push { lr } 10 | mov r0, 2 11 | cmp r0, #3 12 | bhi .exit 13 | adr r3, table 14 | tbb [r3, r0] 15 | 16 | .jt: 17 | @ Using nops for each case ensures that the jump table targets must drive 18 | @ code block boundaries. 19 | .case0: 20 | nop 21 | .case1: 22 | nop 23 | .case2: 24 | nop 25 | .case3: 26 | nop 27 | 28 | .exit: 29 | mov r0, 0 30 | pop { pc } 31 | 32 | table_ptr: 33 | .long table 34 | 35 | table: 36 | .byte (.case0 - .jt) / 2 37 | .byte (.case1 - .jt) / 2 38 | .byte (.case2 - .jt) / 2 39 | .byte (.case3 - .jt) / 2 40 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_tbb_r3_ldr/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | ex: ex_tbb.s 5 | arm-linux-gnueabihf-gcc -o $@ $^ 6 | clean: 7 | rm -f ex out.txt 8 | check: ex 9 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_tbb_r3_ldr/ex_tbb.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | .section .text 3 | 4 | .global main 5 | .type main, %function 6 | .thumb 7 | .align 4 8 | main: 9 | push { lr } 10 | mov r0, 2 11 | cmp r0, #3 12 | bhi .exit 13 | ldr r3, table_ptr 14 | tbb [r3, r0] 15 | 16 | .jt: 17 | @ Using nops for each case ensures that the jump table targets must drive 18 | @ code block boundaries. 19 | .case0: 20 | nop 21 | .case1: 22 | nop 23 | .case2: 24 | nop 25 | .case3: 26 | nop 27 | 28 | .exit: 29 | mov r0, 0 30 | pop { pc } 31 | 32 | table_ptr: 33 | .long table 34 | 35 | table: 36 | .byte (.case0 - .jt) / 2 37 | .byte (.case1 - .jt) / 2 38 | .byte (.case2 - .jt) / 2 39 | .byte (.case3 - .jt) / 2 40 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_tbb_zero/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | ex: ex_tbb.s 5 | arm-linux-gnueabihf-gcc -o $@ $^ 6 | clean: 7 | rm -f ex out.txt 8 | check: ex 9 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_tbb_zero/ex_tbb.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | .section .text 3 | 4 | .global main 5 | .type main, %function 6 | .thumb 7 | .align 4 8 | main: 9 | push { lr } 10 | ands r0, r0, #3 11 | beq .zero 12 | tbb [pc, r0] 13 | .jt: 14 | .byte 0 15 | .byte (.case1 - .jt) / 2 16 | .byte (.case2 - .jt) / 2 17 | .byte (.case3 - .jt) / 2 18 | .case1: 19 | ldr r0, =.s_one 20 | b .print 21 | .case2: 22 | ldr r0, =.s_two 23 | b .print 24 | .case3: 25 | ldr r0, =.s_three 26 | b .print 27 | .zero: 28 | ldr r0, =.s_zero 29 | b .print 30 | .print: 31 | bl printf 32 | mov r0, #0 33 | pop { pc } 34 | 35 | .section .rodata 36 | .s_zero: 37 | .string "zero\n" 38 | .s_one: 39 | .string "one\n" 40 | .s_two: 41 | .string "two\n" 42 | .s_three: 43 | .string "three\n" 44 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_tbh/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | ex: ex_tbh.s 5 | arm-linux-gnueabihf-gcc -o $@ $^ 6 | clean: 7 | rm -f ex out.txt 8 | check: ex 9 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_tbh/ex_tbh.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | .section .text 3 | 4 | .global main 5 | .type main, %function 6 | .thumb 7 | .align 4 8 | main: 9 | push { lr } 10 | mov r0, 2 11 | cmp r0, #3 12 | bhi .exit 13 | tbh [pc, r0] 14 | 15 | .jt: 16 | .hword (.case0 - .jt) / 2 17 | .hword (.case1 - .jt) / 2 18 | .hword (.case2 - .jt) / 2 19 | .hword (.case3 - .jt) / 2 20 | 21 | @ Using nops for each case ensures that the jump table targets must drive 22 | @ code block boundaries. 23 | .case0: 24 | nop 25 | .case1: 26 | @ emit a large code block of nops. This ensures some of the jump table 27 | @ entries have values that could be misinterpreted as negative if the 28 | @ entries were considered signed. 29 | .fill 32768, 2, 0xbf00 30 | .case2: 31 | nop 32 | .case3: 33 | nop 34 | 35 | .exit: 36 | mov r0, 0 37 | pop { pc } 38 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_thumb_at_section_start/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean 2 | ex: ex_original.s 3 | arm-linux-gnueabihf-gcc -o $@ $^ -nostartfiles 4 | clean: 5 | rm -f ex out.txt 6 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_thumb_at_section_start/ex_original.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | .section .text 3 | # Unreferenced Thumb code at the start of the section 4 | .thumb 5 | ldr r0, =ok_str 6 | bl puts 7 | 8 | mov r0, #0 9 | pop { pc } 10 | 11 | 12 | .align 2 13 | .arm 14 | .global _start 15 | _start: 16 | blx main 17 | bl exit 18 | 19 | .global main 20 | .type main, %function 21 | .thumb 22 | .align 2 23 | main: 24 | push { lr } 25 | mov r0, #0 26 | pop { pc } 27 | 28 | .section .rodata 29 | ok_str: 30 | .ascii "OK\n\0" 31 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_value_reg/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | arm-linux-gnueabihf-gcc ex_original.s -no-pie -o ex 4 | @qemu-arm -L /usr/arm-linux-gnueabihf ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | check: 8 | qemu-arm -L /usr/arm-linux-gnueabihf ex > /tmp/res.txt 9 | @ diff out.txt /tmp/res.txt && echo TEST OK 10 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_vld/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | arm-linux-gnueabihf-gcc ex_original.s -no-pie -o ex 4 | @qemu-arm -L /usr/arm-linux-gnueabihf ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | check: 8 | qemu-arm -L /usr/arm-linux-gnueabihf ex > /tmp/res.txt 9 | @ diff out.txt /tmp/res.txt && echo TEST OK 10 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_zero_size_object_sym/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-arm -L /usr/arm-linux-gnueabihf $^ > $@ 4 | ex: ex_original.s 5 | arm-linux-gnueabihf-gcc -o $@ $^ 6 | clean: 7 | rm -f ex out.txt 8 | check: ex 9 | qemu-arm -L /usr/arm-linux-gnueabihf $^ > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/arm_asm_examples/ex_zero_size_object_sym/ex_original.s: -------------------------------------------------------------------------------- 1 | .syntax unified 2 | .section .text 3 | 4 | .thumb 5 | .global ZERO_OBJECT 6 | .type ZERO_OBJECT, %object 7 | .size ZERO_OBJECT, 0 8 | ZERO_OBJECT: 9 | 10 | .global main 11 | .type main, %function 12 | main: 13 | mov r0, #0 14 | bx lr 15 | -------------------------------------------------------------------------------- /examples/asm_examples/Makefile: -------------------------------------------------------------------------------- 1 | TOPTARGETS := all clean 2 | 3 | SUBDIRS := $(wildcard */.) 4 | 5 | $(TOPTARGETS): $(SUBDIRS) 6 | $(SUBDIRS): 7 | $(MAKE) -C $@ $(MAKECMDGOALS) 8 | 9 | .PHONY: $(TOPTARGETS) $(SUBDIRS) 10 | -------------------------------------------------------------------------------- /examples/asm_examples/README.md: -------------------------------------------------------------------------------- 1 | C examples tests have a big problem, they depend on the version of the compiler used. With different compiler version the examples can end up looking very different. 2 | 3 | Asm examples can be use to exercise specific patterns without relying on the compiler installed in each machine to generate them. 4 | 5 | This can be useful to exercise: 6 | - different kinds of pointer reattribution patterns 7 | - jump table patterns 8 | - weird constructs e.g. overlapping instructions, data in code sections, etc. 9 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_aligned_data_in_code/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_aligned_data_in_code_avx512f/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_base_relative0/Makefile.windows: -------------------------------------------------------------------------------- 1 | all: 2 | ml64.exe ex.asm 3 | @ ex > out.txt 4 | clean: 5 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 6 | del /F /Q ex.unstripped *.s *.old* 7 | check: 8 | @ ex > check.txt 9 | @ FC out.txt check.txt && echo TEST OK 10 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_base_relative0/ex.asm: -------------------------------------------------------------------------------- 1 | INCLUDELIB libcmt 2 | 3 | EXTERN __ImageBase:BYTE 4 | PUBLIC main 5 | EXTRN puts:PROC 6 | 7 | .CODE 8 | main: 9 | SUB RSP, 40 10 | 11 | MOV RAX, 0 12 | LEA RDX,[RAX*8+(IMAGEREL N_180f33e70)] 13 | LEA RCX,[__ImageBase] 14 | ADD RDX,RCX 15 | 16 | MOV RAX, [RDX] 17 | CMP RAX, 48879 18 | JNE exit 19 | 20 | LEA RCX, OFFSET $ok 21 | CALL puts 22 | 23 | exit: 24 | ADD RSP, 40 25 | RET 0 26 | .DATA 27 | $OK DB "ok", 00H 28 | 29 | N_180f33e70 BYTE 0EFH 30 | BYTE 0BEH 31 | BYTE 000H 32 | BYTE 000H 33 | BYTE 000H 34 | BYTE 000H 35 | BYTE 000H 36 | BYTE 000H 37 | 38 | END 39 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_base_relative1/Makefile.windows: -------------------------------------------------------------------------------- 1 | all: 2 | ml64.exe ex.asm 3 | @ ex > out.txt 4 | clean: 5 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 6 | del /F /Q ex.unstripped *.s *.old* 7 | check: 8 | @ ex > check.txt 9 | @ FC out.txt check.txt && echo TEST OK 10 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_boundary_sym_expr/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -no-pie -o ex 4 | @ ./ex > out.txt 5 | clean: 6 | rm -f ex out.txt ex.gtirb 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | @ ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_boundary_sym_expr2/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -no-pie -T linker-script.ld -Wl,-Ttext=0x500000 -o ex 4 | @ ./ex > out.txt 5 | clean: 6 | rm -f ex out.txt ex.gtirb 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | @ ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_boundary_sym_expr2/linker-script.ld: -------------------------------------------------------------------------------- 1 | SECTIONS { 2 | .eh_frame_hdr : { *(.eh_frame_hdr) } 3 | } 4 | INSERT AFTER .data; 5 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_cfg/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s $(CFLAGS) -no-pie -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_cfi_directives/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -no-pie -o ex 4 | clean: 5 | rm -fr ex.s 6 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_cfi_directives/ex_original.s: -------------------------------------------------------------------------------- 1 | .intel_syntax noprefix 2 | 3 | 4 | .globl foo 5 | .align 16 6 | .type foo, @function 7 | foo: 8 | .cfi_startproc 9 | .cfi_lsda 255 10 | .cfi_personality 255 11 | .cfi_def_cfa 7, 8 12 | .cfi_offset 16, -8 13 | push RBP 14 | .cfi_def_cfa_offset 16 15 | .cfi_offset 6, -16 16 | mov RBP,RSP 17 | pop RBP 18 | .cfi_def_cfa 7, 8 19 | ret 20 | # some NOPs 21 | nop 22 | nop 23 | nop 24 | # multiple cfi directives at the end 25 | .cfi_remember_state 26 | .cfi_restore_state 27 | .cfi_endproc 28 | 29 | 30 | .globl main 31 | .align 16 32 | .type main, @function 33 | main: 34 | .cfi_startproc 35 | .cfi_lsda 255 36 | .cfi_personality 255 37 | .cfi_def_cfa 7, 8 38 | .cfi_offset 16, -8 39 | push RBP 40 | .cfi_def_cfa_offset 16 41 | .cfi_offset 6, -16 42 | mov RBP,RSP 43 | call foo 44 | pop RBP 45 | .cfi_def_cfa 7, 8 46 | ret 47 | .cfi_endproc 48 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_code_offset_table/Makefile.windows: -------------------------------------------------------------------------------- 1 | all: 2 | ml64.exe ex.asm 3 | @ ex > out.txt 4 | clean: 5 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 6 | del /F /Q ex.unstripped *.s *.old* 7 | check: 8 | @ ex > check.txt 9 | @ FC out.txt check.txt && echo TEST OK 10 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_data_access/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_dll_export_thunk/Makefile.windows: -------------------------------------------------------------------------------- 1 | all: 2 | ml64.exe /c ex.asm 3 | link.exe ex.obj /DLL /SUBSYSTEM:WINDOWS 4 | clean: 5 | del /F /Q *.dll *.obj 6 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_dll_export_thunk/ex.asm: -------------------------------------------------------------------------------- 1 | INCLUDELIB libcmt 2 | 3 | EXTERN __ImageBase:BYTE 4 | 5 | EXTRN puts:PROC 6 | 7 | .CODE 8 | 9 | 10 | print_ok1 PROC EXPORT 11 | JMP print_ok 12 | print_ok1 ENDP 13 | 14 | print_ok2 PROC EXPORT 15 | JMP print_ok 16 | print_ok2 ENDP 17 | 18 | print_ok3 PROC EXPORT 19 | JMP print_ok 20 | print_ok3 ENDP 21 | 22 | 23 | print_ok: 24 | LEA RCX, OFFSET $OK 25 | CALL puts 26 | 27 | exit: 28 | RET 0 29 | .DATA 30 | $OK DB "ok", 00H 31 | 32 | 33 | END 34 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_enclosed_instr/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_exceptions5/Makefile: -------------------------------------------------------------------------------- 1 | CXX="g++" 2 | EXEC= 3 | 4 | all: ex_original.s 5 | # NOTE: `-T linker-script.ld` 6 | # This is to place .gcc_except_table *before* .note.gnu.build-id 7 | # so that the reference label for the end of the section is aligned 8 | # with the adjacent section. Otherwise, the next section can be some 9 | # discarded one, which would prevent from demonstrating the issue. 10 | # 11 | $(CXX) -T linker-script.ld -o ex ex_original.s 12 | @ $(EXEC) ./ex > out.txt 13 | clean: 14 | rm -f ex out.txt 15 | rm -fr ex.unstripped *.old* dl_files *.gtirb 16 | check: 17 | @ $(EXEC) ./ex >/tmp/res.txt 18 | @ diff out.txt /tmp/res.txt && echo TEST OK 19 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_exceptions5/linker-script.ld: -------------------------------------------------------------------------------- 1 | SECTIONS { 2 | .gcc_except_table : { *(.gcc_except_table) } 3 | } 4 | INSERT BEFORE .note.gnu.build-id; 5 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_fde_entry/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -no-pie -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_fde_entry/ex_original.s: -------------------------------------------------------------------------------- 1 | # Regression test 2 | # This pattern was triggering a ddisasm failure because two block candidates 3 | # were awarded identical point totals (when stripped). 4 | .intel_syntax noprefix 5 | 6 | .text 7 | .type fun_loop, @function 8 | fun_loop: 9 | .cfi_startproc 10 | jmp fun_loop 11 | .cfi_endproc 12 | 13 | .byte 0x66 14 | .byte 0x90 15 | .byte 0x90 16 | .zero 12 17 | break: 18 | # disassembling from here results in different code than the function "fun" 19 | .zero 3 20 | 21 | .type fun, @function 22 | fun: 23 | .cfi_startproc 24 | mov QWORD PTR [RIP+.label],RDI 25 | ret 26 | .cfi_endproc 27 | 28 | .global main 29 | .type main, @function 30 | main: 31 | .cfi_startproc 32 | 33 | // use an address as an immediate to force the nop block above to split 34 | // into two block candidates. 35 | mov rax, break 36 | 37 | ret 38 | .cfi_endproc 39 | 40 | .label: 41 | 42 | .quad 0 43 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_ifunc/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | 4 | all: ex_original.s 5 | $(CC) -shared -Wl,--version-script=ex.map $(CFLAGS) ex_original.s -o ex.so 6 | clean: 7 | rm -f ex.so ex.gtirb out.txt 8 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_ifunc/ex.map: -------------------------------------------------------------------------------- 1 | GLIBC_2.2.5 { 2 | 3 | }; 4 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_ifunc/ex_original.s: -------------------------------------------------------------------------------- 1 | .text 2 | 3 | #----------------------------------- 4 | .type __strcmp, @gnu_indirect_function 5 | __strcmp: 6 | #----------------------------------- 7 | .symver strcmp,strcmp@@@GLIBC_2.2.5 8 | .globl strcmp 9 | .type strcmp, @gnu_indirect_function 10 | #----------------------------------- 11 | strcmp: 12 | #----------------------------------- 13 | .type strcmp_ifunc, @function 14 | #----------------------------------- 15 | strcmp_ifunc: 16 | 17 | ret 18 | 19 | 20 | .globl foo 21 | .type foo, @function 22 | foo: 23 | .LFB6: 24 | pushq %rbp 25 | movq %rsp, %rbp 26 | movl $20, %esi 27 | movl $10, %edi 28 | # prefer locals to ifunc globals 29 | # readelf should not contain an entry as follows in .rela.plt: 30 | # R_X86_64_JUMP_SLO strcmp@@GLIBC_2.2.5() strcmp@@GLIBC_2.2.5 + 0 31 | call __strcmp@PLT 32 | movl $0, %eax 33 | popq %rbp 34 | ret 35 | 36 | .LFE6: 37 | .size foo, .-foo 38 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_loop_instructions/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_loop_instructions/ex_original.s: -------------------------------------------------------------------------------- 1 | # This example shows how ddisasm handles the representation of loop instructions 2 | # and prefixes. 3 | 4 | .intel_syntax noprefix 5 | 6 | .text 7 | .global main 8 | main: 9 | mov rcx, 10 10 | mov rax, 0 11 | countdown: 12 | add rax, 10 13 | loop countdown 14 | rep_prefix: 15 | mov rcx, buffer_end-buffer_begin 16 | lea rdi, qword ptr [rip+buffer_begin] 17 | rep stos byte ptr [rdi] 18 | add al, byte ptr [rip+buffer_end-1] 19 | post_loops: 20 | # print rax; it should now be 200 21 | lea rdi, qword ptr [rip+message] 22 | mov rsi, rax 23 | mov al, 0 24 | call printf@plt 25 | mov eax, 0 26 | ret 27 | 28 | .data 29 | message: 30 | .asciz "Result: %d\n" 31 | buffer_begin: 32 | .zero 128 33 | buffer_end: 34 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_misaligned_fde/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -no-pie -o ex 4 | clean: 5 | rm -fr ex.s ex ex.gtirb 6 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_moved_base_relative/Makefile.windows: -------------------------------------------------------------------------------- 1 | all: 2 | ml64.exe ex.asm 3 | @ ex > out.txt 4 | clean: 5 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 6 | del /F /Q ex.unstripped *.s *.old* 7 | check: 8 | @ ex > check.txt 9 | @ FC out.txt check.txt && echo TEST OK 10 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_moved_label/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -no-pie -o ex 4 | @ ./ex > out.txt 5 | clean: 6 | rm -f ex out.txt ex.gtirb 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | @ ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_moved_label_imm/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -no-pie -o ex 4 | @ ./ex > out.txt 5 | clean: 6 | rm -f ex out.txt ex.gtirb 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | @ ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_noreturn_use_def/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean check 2 | all: out.txt 3 | 4 | out.txt: ex 5 | @./$^ > $@ 6 | ex: src.s 7 | gcc $^ -no-pie -o $@ 8 | 9 | clean: 10 | rm -f ex out.txt 11 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 12 | check: 13 | ./ex > /tmp/res.txt 14 | @ diff out.txt /tmp/res.txt && echo TEST OK 15 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_npad/Makefile.windows: -------------------------------------------------------------------------------- 1 | all: 2 | ml.exe ex.asm /link /opt:ref /entry:main /subsystem:console 3 | @ ex > out.txt 4 | clean: 5 | del /F /Q *.exe *.obj *.lib out.txt check.txt mllink$$.lnk *.def *.lib 6 | check: 7 | @ ex > check.txt 8 | @ FC out.txt check.txt && echo TEST OK 9 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_npad/ex.asm: -------------------------------------------------------------------------------- 1 | .MODEL FLAT, STDCALL 2 | .686P 3 | .XMM 4 | 5 | INCLUDE listing.inc 6 | INCLUDELIB ucrt 7 | 8 | PUBLIC main 9 | EXTRN puts:PROC 10 | 11 | .data 12 | FOR arg:=, <1,2,3,4,5,6,7,8,9,10,11,12,13,14,15> 13 | $&arg DB '&arg', 00H 14 | ENDM 15 | 16 | .code 17 | main: 18 | push ebp 19 | mov ebp, esp 20 | 21 | FOR arg:=, <1,2,3,4,5,6,7,8,9,10,11,12,13,14,15> 22 | push OFFSET $&arg 23 | call puts 24 | add esp, 4 25 | jmp @F 26 | npad &arg 27 | @@: 28 | ENDM 29 | 30 | xor eax, eax 31 | pop ebp 32 | ret 0 33 | END 34 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_overlapping_instruction/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_overlapping_instruction_2/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_overlapping_instruction_2/ex_original.s: -------------------------------------------------------------------------------- 1 | 2 | .text 3 | 4 | .align 16 5 | .globl main 6 | .type main, @function 7 | main: 8 | .LFB6: 9 | pushq %rbp 10 | movq %rsp, %rbp 11 | 12 | movq $1, %rax 13 | movq $1, %rcx 14 | movq $1, %rdx 15 | cmpl $0, %ecx 16 | # This conditional jump ensures .L1+1 is not a known block 17 | jz .L3 18 | 19 | cmpl $0, %ecx 20 | jz .L1+1 21 | .L1: 22 | lock cmpxchgq %rcx,mydata(%rip) 23 | cmpq %rdx,%rcx 24 | je .L2 25 | leaq .LC0(%rip),%rdi 26 | movq $7,%rsi 27 | call printf@PLT 28 | jmp .L3 29 | .L2: 30 | leaq .LC0(%rip),%rdi 31 | movq $8,%rsi 32 | call printf@PLT 33 | .L3: 34 | movl $0, %eax 35 | popq %rbp 36 | ret 37 | 38 | .LFE6: 39 | .size main, .-main 40 | 41 | .section .rodata 42 | .LC0: 43 | .string "%d\n" 44 | 45 | .section .data 46 | 47 | .type mydata,@object 48 | .size mydata,8 49 | mydata: 50 | .byte 0x1 51 | .byte 0x0 52 | .byte 0x0 53 | .byte 0x0 54 | .byte 0x0 55 | .byte 0x0 56 | .byte 0x0 57 | .byte 0x0 58 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_overlapping_instruction_3/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_overlapping_nops/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_plt_nop/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -pie -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_plt_nop/ex_original.s: -------------------------------------------------------------------------------- 1 | .section .plt ,"ax",@progbits 2 | .align 16 3 | bnd jmpq *puts@GOTPCREL(%rip) 4 | bad_ref: 5 | nop 6 | nop 7 | nop 8 | nop 9 | nop 10 | nop 11 | block: 12 | bnd jmpq *puts@GOTPCREL(%rip) 13 | 14 | .text 15 | .globl main 16 | .type main, @function 17 | main: 18 | .LFB6: 19 | pushq %rbp 20 | movq %rsp, %rbp 21 | 22 | leaq .LC0(%rip), %rdi 23 | call puts@PLT 24 | 25 | movl $0, %eax 26 | popq %rbp 27 | ret 28 | .size main, .-main 29 | 30 | .section .rodata 31 | .quad bad_ref 32 | 33 | .LC0: 34 | .string "hello" 35 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_pointerReattribution3/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -no-pie -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_pointerReattribution3_clang/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -no-pie -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_pointerReattribution3_pie/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -pie -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_referred_string/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -no-pie -Wl,-Ttext=0x512350 -o ex 4 | @ ./ex > out.txt 5 | clean: 6 | rm -f ex out.txt ex.gtirb 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | @ ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_referred_string/ex_original.s: -------------------------------------------------------------------------------- 1 | .text 2 | 3 | .globl main 4 | .type main, @function 5 | main: 6 | .LFB6: 7 | pushq %rbp 8 | movq %rsp, %rbp 9 | movl $mystring, %edi 10 | call puts 11 | movl $0, %eax 12 | popq %rbp 13 | ret 14 | 15 | .LFE6: 16 | .size main, .-main 17 | 18 | .align 8 19 | .data 20 | 21 | .quad mydata 22 | .zero 8 23 | # 0x512350 happens to be the address of `_start` (see the Makefile). 24 | # This example is to test that this address is not symbolized as `_start` 25 | # This program is supposed to print out "#Q". 26 | # If this address is symbolized as `_start`, 27 | # it will print out something else. 28 | .ascii "P" # 0x50 29 | mystring: 30 | .string "#Q" # 0x23 0x51 31 | .byte 0x0 32 | .byte 0x0 33 | .byte 0x0 34 | .byte 0x0 35 | 36 | mydata: 37 | .zero 16 38 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_relative_jump_tables/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_relative_jump_tables2/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_relative_jump_tables3/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_relative_jump_tables4/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_relative_switch/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_relative_switch_sizes/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -no-pie -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_relative_switch_through_stack/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_return_use_def/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean check 2 | all: out.txt 3 | 4 | out.txt: ex 5 | @./$^ > $@ 6 | ex: src.s 7 | gcc $^ -no-pie -o $@ 8 | 9 | clean: 10 | rm -f ex out.txt 11 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 12 | check: 13 | ./ex > /tmp/res.txt 14 | @ diff out.txt /tmp/res.txt && echo TEST OK 15 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_return_use_def/ex_reference.c: -------------------------------------------------------------------------------- 1 | /** 2 | Original source included for reference. 3 | 4 | The key properties of this example which make it difficult to correctly generate def_used are: 5 | 6 | * A register is defined in a function, returned, and used by the caller 7 | * The function uses the register in a separate basic block between defining and returning the 8 | register. 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | int count = 0; 15 | 16 | char *hello = "-Hello World"; 17 | char *goodbye = "-Goodbye World"; 18 | 19 | static char *get_ptr(void) 20 | { 21 | char *ptr = hello; 22 | 23 | // Add some control flow 24 | if(count > 0) 25 | { 26 | ptr = goodbye; 27 | } 28 | 29 | if(ptr[0] != ' ') 30 | { 31 | ptr[0] = ' '; 32 | } 33 | 34 | count++; 35 | return ptr; 36 | } 37 | 38 | int main(void) 39 | { 40 | for(int i = 0; i < 2; i++) 41 | { 42 | char *ptr = get_ptr(); 43 | if(!ptr) 44 | continue; 45 | 46 | puts(ptr); 47 | } 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_stack_value_reg/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean check 2 | all: out.txt 3 | 4 | out.txt: ex 5 | @./$^ > $@ 6 | ex: src.s 7 | gcc $^ -o $@ 8 | 9 | clean: 10 | rm -f ex out.txt 11 | check: 12 | ./ex > /tmp/res.txt 13 | @ diff out.txt /tmp/res.txt && echo TEST OK 14 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_switch_cdqe/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean check 2 | all: out.txt 3 | 4 | out.txt: ex 5 | @./$^ > $@ 6 | ex: src.s 7 | gcc $^ -no-pie -o $@ 8 | 9 | clean: 10 | rm -f ex out.txt 11 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 12 | check: 13 | ./ex > /tmp/res.txt 14 | @ diff out.txt /tmp/res.txt && echo TEST OK 15 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_switch_cdqe/src.s: -------------------------------------------------------------------------------- 1 | .intel_syntax noprefix 2 | .file "ex.c" 3 | 4 | .text 5 | .p2align 4, 0x90 6 | .globl main 7 | .type main,@function 8 | 9 | main: 10 | push RBP 11 | mov RBP,RSP 12 | 13 | mov EAX, EDI # argc 14 | sub EAX, 1 15 | 16 | cmp EAX,3 17 | ja .L_default 18 | 19 | # observed this pattern in bzip2 built with gcc -O0 20 | mov EAX,EAX 21 | lea RDX,QWORD PTR [RAX*4] 22 | lea RAX,QWORD PTR [RIP+.L_jumptable] 23 | mov EAX,DWORD PTR [RDX+RAX*1] 24 | cdqe 25 | lea RDX,QWORD PTR [RIP+.L_jumptable] 26 | add RAX,RDX 27 | jmp RAX 28 | 29 | .L_one: 30 | mov RDI, OFFSET .s_one 31 | jmp .L_print 32 | 33 | .L_two: 34 | mov RDI, OFFSET .s_two 35 | jmp .L_print 36 | 37 | .L_three: 38 | mov RDI, OFFSET .s_three 39 | 40 | .L_print: 41 | call puts@PLT 42 | 43 | xor EAX, EAX 44 | pop RBP 45 | ret 46 | 47 | .L_default: 48 | mov EAX, 1 49 | pop RBP 50 | ret 51 | 52 | .section .rodata 53 | .L_jumptable: 54 | .long .L_one - .L_jumptable 55 | .long .L_two - .L_jumptable 56 | .long .L_three - .L_jumptable 57 | .long .L_default - .L_jumptable 58 | 59 | .align 4 60 | .s_one: 61 | .asciz "one" 62 | .s_two: 63 | .asciz "two" 64 | .s_three: 65 | .asciz "three" 66 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_switch_in_code/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -no-pie -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_switch_in_code2/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -no-pie -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_switch_in_code3/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -no-pie -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_switch_in_code3/ex_original.s: -------------------------------------------------------------------------------- 1 | .intel_syntax noprefix 2 | .file "ex.c" 3 | 4 | .text 5 | .p2align 4, 0x90 6 | .globl main 7 | .type main,@function 8 | 9 | main: 10 | mov eax, 0 11 | 12 | switch: 13 | mov eax, eax 14 | lea rdx, 0[0+rax*4] 15 | lea rax, .L33[rip] 16 | mov eax, DWORD PTR [rdx+rax] 17 | movsxd rdx, eax 18 | lea rax, .L33[rip] 19 | add rax, rdx 20 | jmp rax 21 | 22 | done: 23 | xor eax, eax 24 | ret 25 | 26 | .section .rodata 27 | .align 4 28 | .align 4 29 | 30 | .L33: 31 | .long .L32-.L33 32 | 33 | .text 34 | .L32: 35 | lea rdi, [rip + .L.str] 36 | call puts@PLT 37 | 38 | jmp done 39 | 40 | .type .L.str,@object # @.str 41 | .section .rodata.str1.1,"aMS",@progbits,1 42 | .L.str: 43 | .asciz "one" 44 | .size .L.str, 4 45 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_switch_in_code4/Makefile.windows: -------------------------------------------------------------------------------- 1 | all: 2 | ml64.exe ex.asm 3 | @ ex > out.txt 4 | clean: 5 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 6 | del /F /Q ex.unstripped *.s *.old* 7 | check: 8 | @ ex > check.txt 9 | @ FC out.txt check.txt && echo TEST OK 10 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_switch_in_code4/ex.asm: -------------------------------------------------------------------------------- 1 | includelib libcmt 2 | 3 | public main 4 | extrn puts:PROC 5 | 6 | .data 7 | message: 8 | DB "hello world!", 00H 9 | 10 | .code 11 | main: 12 | sub rsp, 40 13 | 14 | mov rdx, 3 15 | call foo 16 | 17 | lea rcx, OFFSET message 18 | add rcx, rax 19 | call puts 20 | 21 | xor eax, eax 22 | 23 | add rsp, 40 24 | ret 0 25 | 26 | foo: 27 | sub rsp, 40 28 | 29 | ; label-relative addressing 30 | lea R8,QWORD PTR [table] 31 | mov R8,QWORD PTR [R8+RDX*8] ; table indexing 32 | lea R9,QWORD PTR [bar] ; base address 33 | add R8,R9 34 | call R8 35 | 36 | add rsp, 40 37 | ret 0 38 | 39 | bar: 40 | mov rax, 0 41 | ret 42 | nop 43 | nop 44 | nop 45 | nop 46 | nop 47 | 48 | baz: 49 | mov rax, 1 50 | ret 51 | 52 | qux: 53 | mov rax, 2 54 | ret 55 | 56 | abc: 57 | mov rax, 3 58 | ret 59 | 60 | xyz: 61 | mov rax, 4 62 | ret 63 | 64 | .data 65 | DB 6 DUP(0FFh) 66 | 67 | table: 68 | QWORD baz - bar 69 | QWORD qux - bar 70 | DB 8 DUP(0) 71 | QWORD abc - bar 72 | QWORD xyz - bar 73 | 74 | 75 | END 76 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_switch_in_code5/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean check 2 | all: out.txt 3 | 4 | out.txt: ex 5 | @./$^ > $@ 6 | ex: src.s 7 | gcc $^ -no-pie -o $@ 8 | 9 | clean: 10 | rm -f ex out.txt 11 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 12 | check: 13 | ./ex > /tmp/res.txt 14 | @ diff out.txt /tmp/res.txt && echo TEST OK 15 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_switch_in_code5/src.s: -------------------------------------------------------------------------------- 1 | .intel_syntax noprefix 2 | .file "ex.c" 3 | 4 | .text 5 | .p2align 4, 0x90 6 | .globl main 7 | .type main,@function 8 | 9 | main: 10 | push RBP 11 | mov RBP,RSP 12 | 13 | mov R14, RDI # argc 14 | 15 | lea R9,QWORD PTR [RIP+.L_jumptable] 16 | mov R10,R14 17 | neg R10 18 | add R10,4 19 | and R10,3 20 | je .L_default 21 | 22 | sub R9,QWORD PTR [R9+R10*8] 23 | jmp R9 24 | 25 | .L_one: 26 | mov RDI, OFFSET .s_one 27 | jmp .L_print 28 | 29 | .L_two: 30 | mov RDI, OFFSET .s_two 31 | jmp .L_print 32 | 33 | .L_three: 34 | mov RDI, OFFSET .s_three 35 | 36 | .L_print: 37 | call puts@PLT 38 | 39 | xor EAX, EAX 40 | pop RBP 41 | ret 42 | 43 | .L_default: 44 | mov EAX, 1 45 | pop RBP 46 | ret 47 | 48 | .align 4 49 | .L_jumptable: 50 | .quad .L_jumptable - .L_default 51 | .quad .L_jumptable - .L_three 52 | .quad .L_jumptable - .L_two 53 | .quad .L_jumptable - .L_one 54 | 55 | .section .rodata 56 | .align 4 57 | .s_one: 58 | .asciz "one" 59 | .s_two: 60 | .asciz "two" 61 | .s_three: 62 | .asciz "three" 63 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_switch_in_code_no_cfi/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -no-pie -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_switch_limited_by_cmp/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean check 2 | all: out.txt 3 | 4 | out.txt: ex 5 | @./$^ > $@ 6 | ex: src.s 7 | gcc $^ -no-pie -o $@ 8 | 9 | clean: 10 | rm -f ex out.txt 11 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 12 | check: 13 | ./ex > /tmp/res.txt 14 | @ diff out.txt /tmp/res.txt && echo TEST OK 15 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_switch_limited_by_indirect_cmp/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean check 2 | all: out.txt 3 | 4 | out.txt: ex 5 | @./$^ > $@ 6 | ex: src.s 7 | gcc $^ -no-pie -o $@ 8 | 9 | clean: 10 | rm -f ex out.txt 11 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 12 | check: 13 | ./ex > /tmp/res.txt 14 | @ diff out.txt /tmp/res.txt && echo TEST OK 15 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_switch_limited_index_table/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean check 2 | all: out.txt 3 | 4 | out.txt: ex 5 | @./$^ > $@ 6 | ex: src.s 7 | gcc $^ -no-pie -g -o $@ 8 | 9 | clean: 10 | rm -f ex out.txt 11 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 12 | check: 13 | ./ex > /tmp/res.txt 14 | @ diff out.txt /tmp/res.txt && echo TEST OK 15 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_switch_overlap/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean check 2 | all: out.txt 3 | 4 | out.txt: ex 5 | @./$^ > $@ 6 | ex: src.s 7 | gcc $^ -no-pie -o $@ 8 | 9 | clean: 10 | rm -f ex out.txt 11 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 12 | check: 13 | ./ex > /tmp/res.txt 14 | @ diff out.txt /tmp/res.txt && echo TEST OK 15 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_sym_minus_sym/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_symbol_selection/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -no-pie -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | check: 8 | ./ex > /tmp/res.txt 9 | @ diff out.txt /tmp/res.txt && echo TEST OK 10 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_symbol_selection2/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: foo.s bar.s ex.c 3 | gcc -shared foo.s -o foo.so 4 | gcc -shared bar.s -o bar.so -L. -l:foo.so 5 | gcc ex.c -no-pie -o ex -L. -l:bar.so -l:foo.so 6 | LD_LIBRARY_PATH=. ./ex > out.txt 7 | clean: 8 | rm -f ex foo.so bar.so out.txt 9 | check: 10 | LD_LIBRARY_PATH=. ./ex > /tmp/res.txt 11 | @ diff out.txt /tmp/res.txt && echo TEST OK 12 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_symbol_selection2/bar.s: -------------------------------------------------------------------------------- 1 | .section .rodata 2 | .LC0_bar: 3 | .string "bar: %d\n" 4 | 5 | fun_ptr: 6 | .quad fun 7 | .section .text 8 | 9 | .weak fun 10 | .type fun, @function 11 | fun: 12 | pushq %rbp 13 | movq %rsp, %rbp 14 | movq $7, %rsi 15 | leaq .LC0_bar(%rip), %rdi 16 | movq $0, %rax 17 | call printf@PLT 18 | movq $0, %rax 19 | popq %rbp 20 | ret 21 | 22 | .align 16 23 | 24 | .globl bar_fun 25 | .type bar_fun, @function 26 | bar_fun: 27 | pushq %rbp 28 | movq %rsp, %rbp 29 | movq fun_ptr(%rip),%rdi 30 | call *%rdi 31 | movq $0, %rax 32 | popq %rbp 33 | ret 34 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_symbol_selection2/ex.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | extern void foo_fun(); 4 | extern void bar_fun(); 5 | 6 | int main() 7 | { 8 | puts("calling foo_fun"); 9 | foo_fun(); 10 | puts("now bar_fun"); 11 | bar_fun(); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_symbol_selection2/foo.s: -------------------------------------------------------------------------------- 1 | .section .rodata 2 | .LC0_foo: 3 | .string "foo: %d\n" 4 | 5 | .text 6 | 7 | .type __fun, @function 8 | __fun: 9 | .globl fun 10 | .type fun, @function 11 | fun: 12 | pushq %rbp 13 | movq %rsp, %rbp 14 | movq $7, %rsi 15 | leaq .LC0_foo(%rip), %rdi 16 | call printf@PLT 17 | movq $0, %rax 18 | popq %rbp 19 | ret 20 | 21 | .align 16 22 | 23 | .globl foo_fun 24 | .type foo_fun, @function 25 | foo_fun: 26 | pushq %rbp 27 | movq %rsp, %rbp 28 | movq $8, %rsi 29 | leaq mydata_local(%rip), %rdi 30 | call *(%rdi) 31 | leaq mydata_global(%rip), %rdi 32 | call *(%rdi) 33 | movq $0, %rax 34 | popq %rbp 35 | ret 36 | 37 | .align 16 38 | 39 | .section .data.rel.ro ,"wa",@progbits 40 | 41 | mydata_local: 42 | .quad __fun 43 | mydata_global: 44 | .quad fun 45 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_symbolic_operand_heuristics/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -no-pie -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_symbolic_operand_heuristics/ex_original.s: -------------------------------------------------------------------------------- 1 | # This example test negative heuristics for symbolic operands 2 | 3 | .intel_syntax noprefix 4 | 5 | .text 6 | .global main 7 | main: 8 | # These should be symbolized 9 | 10 | rip_lea: 11 | lea rdi, qword ptr [rip+message] 12 | call puts@plt 13 | rip_lea_misleading: 14 | lea rdx, qword ptr [rip+message] 15 | imul rdx, 3 16 | rip_lea_misleading_call_rdi: 17 | lea rdi, qword ptr [rip+message] 18 | call aux_fun 19 | imul rdi, 3 20 | rip_lea_misleading_call_rdx: 21 | lea rdx, qword ptr [rip+message] 22 | call aux_fun_rdx 23 | imul rdx, 3 24 | 25 | # These should NOT be symbolized 26 | # We use "message" in the original to ensure it looks like an address 27 | 28 | lea_multiplied: 29 | lea rax, qword ptr [rax+message] 30 | imul rax, 3 31 | lea_cmp: 32 | lea rax, qword ptr [rax+message] 33 | cmp rax, 3 34 | mov rax, 0 35 | ret 36 | 37 | aux_fun: 38 | call puts@plt 39 | ret 40 | 41 | # Functions can return small structs 42 | # in RAX+RDX in linux 43 | aux_fun_rdx: 44 | mov rdi, rdx 45 | call puts@plt 46 | mov rax, 0 47 | mov rdx, 0 48 | ret 49 | 50 | .data 51 | message: 52 | .asciz "Hello" 53 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_synchronous_access/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_synchronous_access2/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_synchronous_access2/ex.c: -------------------------------------------------------------------------------- 1 | /* 2 | The C version of the program is included only for reference. 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | typedef struct combined 10 | { 11 | int16_t num; 12 | char ch; 13 | char ch2; 14 | } combined; 15 | 16 | combined struc_array[10] = {{0, 'a', 'b'}, {0, 'a', 'b'}, {0, 'a', 'b'}, 17 | {0, 'a', 'b'}, {0x4142, 'a', 'b'}, {0x4142, 'a', 'b'}, 18 | {0x4142, 'a', 'b'}, {0x4142, 'a', 'b'}, {0x4142, 'a', 'b'}, 19 | {0, 'a', 'b'}}; 20 | 21 | int main() 22 | { 23 | puts("Printing data"); 24 | 25 | for(int i = 0; i < 10; ++i) 26 | printf("%i %c %c \n", struc_array[i].num, struc_array[i].ch, struc_array[i].ch2); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_synchronous_access3/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -o ex -no-pie 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_synchronous_access3/ex_original.s: -------------------------------------------------------------------------------- 1 | .text 2 | 3 | .type unreachable, @function 4 | unreachable: 5 | xorq %rcx, %rcx 6 | xorq %rdi, %rdi 7 | .LC0: 8 | # The following two access appear a synchronized access, 9 | # but it should not be detected as since PADDING+16 is `stdout`. 10 | movups PADDING(%rdi,%rcx,8), %xmm0 11 | movups PADDING+16(%rdi,%rcx,8), %xmm1 12 | movups %xmm0, -16(%rax,%rbp) 13 | movups %xmm1, (%rax,%rbp) 14 | addq $8, %rcx 15 | jz .LC0 16 | ret 17 | 18 | .globl main 19 | .type main, @function 20 | main: 21 | .LFB6: 22 | pushq %rbp 23 | movq %rsp, %rbp 24 | movl $65, %edi 25 | movq stdout(%rip), %rsi 26 | callq fputc@PLT 27 | movl $0, %eax 28 | popq %rbp 29 | ret 30 | 31 | .LFE6: 32 | .size main, .-main 33 | 34 | .data 35 | 36 | .type PADDING, @object 37 | .size PADDING, 16 38 | PADDING: 39 | .zero 16 40 | 41 | .bss 42 | 43 | .symver stdout_copy,stdout_copy@GLIBC_2.2.5 44 | .globl stdout_copy 45 | .type stdout_copy, @object 46 | .size stdout_copy, 8 47 | stdout_copy: 48 | .zero 8 49 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_synchronous_access4/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -o ex -no-pie 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_synchronous_access4/ex_original.s: -------------------------------------------------------------------------------- 1 | .text 2 | 3 | .type unreachable, @function 4 | unreachable: 5 | xorq %rcx, %rcx 6 | xorq %rdi, %rdi 7 | .LC0: 8 | # The following two accesses appear synchronized accesses. 9 | # However, they should not be detected as such because PADDING+260 10 | # is across my_symbol. 11 | movups PADDING(%rdi,%rcx,8), %xmm0 12 | movups PADDING+260(%rdi,%rcx,8), %xmm1 13 | movups %xmm0, -16(%rax,%rbp) 14 | movups %xmm1, (%rax,%rbp) 15 | addq $8, %rcx 16 | jz .LC0 17 | ret 18 | 19 | .globl main 20 | .type main, @function 21 | main: 22 | .LFB6: 23 | pushq %rbp 24 | movq %rsp, %rbp 25 | movl my_symbol(%rip), %edi 26 | movl $0, %eax 27 | popq %rbp 28 | ret 29 | 30 | .LFE6: 31 | .size main, .-main 32 | 33 | .data 34 | 35 | .type PADDING, @object 36 | .size PADDING, 256 37 | PADDING: 38 | .zero 256 39 | 40 | .type my_symbol, @object 41 | .size my_symbol, 64 42 | my_symbol: 43 | .zero 64 44 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_tls/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s fun.s 3 | gcc -shared -o fun.so fun.s 4 | gcc -o ex ex_original.s -L. -l:fun.so 5 | @LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./ex > out.txt 6 | clean: 7 | rm -f ex out.txt 8 | rm -fr fun.so fun.so.unstripped fun.so.s *.old* dl_files *.gtirb 9 | check: 10 | @LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./ex > /tmp/res.txt 11 | @ diff out.txt /tmp/res.txt && echo TEST OK 12 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_tls/ex_original.s: -------------------------------------------------------------------------------- 1 | 2 | .align 16 3 | .globl main 4 | .type main, @function 5 | main: 6 | .LFB6: 7 | pushq %rbp 8 | movq %rsp, %rbp 9 | call bar@PLT 10 | movl $0, %eax 11 | popq %rbp 12 | ret 13 | 14 | .LFE6: 15 | .size main, .-main 16 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_tls_local_exec/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc -o ex ex_original.s 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | check: 8 | @./ex > /tmp/res.txt 9 | @ diff out.txt /tmp/res.txt && echo TEST OK 10 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_two_data_accesses/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/asm_examples/ex_weird_sections/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: ex_original.s 3 | gcc ex_original.s -no-pie -o ex 4 | @./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex1/.gitignore: -------------------------------------------------------------------------------- 1 | aux 2 | dbg 3 | -------------------------------------------------------------------------------- /examples/ex1/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | clean: 9 | rm -f ex ex.unstripped out.txt *.s *.lib *.exp *.o *.err 10 | check: 11 | @ $(EXEC) ./ex >/tmp/res.txt 12 | @ diff out.txt /tmp/res.txt && echo TEST OK 13 | -------------------------------------------------------------------------------- /examples/ex1/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS="" 2 | 3 | all: ex.c 4 | cl /nologo ex.c $(CFLAGS) 5 | @ ex > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 8 | check: 9 | @ ex >check.txt 10 | @ FC out.txt check.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex1/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void fun(int a, int b) 5 | { 6 | int i = 0; 7 | while(a < b) 8 | { 9 | ++i; 10 | ++a; 11 | } 12 | } 13 | int main() 14 | { 15 | fun(10, 20); 16 | puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */ 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /examples/ex_2modulesPIC/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c fun.c $(CFLAGS) -fPIC -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | clean: 9 | rm -f ex ex.unstripped out.txt *.s *.lib *.exp *.o *.err 10 | check: 11 | @ $(EXEC) ./ex >/tmp/res.txt 12 | @ diff out.txt /tmp/res.txt && echo TEST OK 13 | -------------------------------------------------------------------------------- /examples/ex_2modulesPIC/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS="/Fa" 2 | 3 | all: ex.c 4 | cl /nologo $(CFLAGS) ex.c fun.c 5 | @ ex > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 8 | check: 9 | @ ex >check.txt 10 | @ FC out.txt check.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_2modulesPIC/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "fun.h" 5 | 6 | int main() 7 | { 8 | fun(10, 20); 9 | puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */ 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /examples/ex_2modulesPIC/fun.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void fun(int a, int b) 4 | { 5 | int i = 0; 6 | while(a < b) 7 | { 8 | ++i; 9 | ++a; 10 | printf("%i\n", i); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/ex_2modulesPIC/fun.h: -------------------------------------------------------------------------------- 1 | void fun(int, int); 2 | -------------------------------------------------------------------------------- /examples/ex_adder/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | clean: 9 | rm -f ex out.txt 10 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 11 | check: 12 | @ $(EXEC) ./ex >/tmp/res.txt 13 | @ diff out.txt /tmp/res.txt && echo TEST OK 14 | -------------------------------------------------------------------------------- /examples/ex_adder/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int add(int a, int b) 6 | { 7 | return (a + b); 8 | } 9 | 10 | void main(void) 11 | { 12 | int sum; 13 | int i; 14 | 15 | sum = 0; 16 | i = 1; 17 | while(i < 0xb) 18 | { 19 | sum = add(sum, i); 20 | i = add(i, 1); 21 | printf("sum = %d\n", sum); 22 | printf("i = %d\n", i); 23 | } 24 | return; 25 | } 26 | -------------------------------------------------------------------------------- /examples/ex_call_array/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | clean: 9 | rm -f ex out.txt 10 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 11 | check: 12 | @ $(EXEC) ./ex >/tmp/res.txt 13 | @ diff out.txt /tmp/res.txt && echo TEST OK 14 | -------------------------------------------------------------------------------- /examples/ex_call_array/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int one(int a) 5 | { 6 | puts("one"); 7 | return a; 8 | } 9 | int two(int a) 10 | { 11 | puts("two"); 12 | return a; 13 | } 14 | int three(int a) 15 | { 16 | puts("three"); 17 | return a + 1; 18 | } 19 | int four(int a) 20 | { 21 | puts("four"); 22 | return a; 23 | } 24 | 25 | int (*funcs[])(int a) = {one, two, three, four}; 26 | 27 | void fun(int a, int b) 28 | { 29 | while(a < b) 30 | { 31 | if(a <= sizeof(funcs) / sizeof(funcs[0])) 32 | { 33 | (*funcs[a - 1])(b); 34 | } 35 | ++a; 36 | } 37 | } 38 | int main() 39 | { 40 | puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */ 41 | fun(1, 6); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /examples/ex_call_once/Makefile: -------------------------------------------------------------------------------- 1 | CXX="g++" 2 | all: ex.cpp 3 | $(CXX) ex.cpp $(CXXFLAGS) -lpthread -o ex 4 | ./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex >/tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_call_once/ex.cpp: -------------------------------------------------------------------------------- 1 | // https://en.cppreference.com/w/cpp/thread/call_once 2 | #include 3 | #include 4 | #include 5 | 6 | std::once_flag flag1; 7 | 8 | void simple_do_once() 9 | { 10 | std::call_once(flag1, []() { std::cout << "called once\n"; }); 11 | } 12 | 13 | int main() 14 | { 15 | std::thread st1(simple_do_once); 16 | std::thread st2(simple_do_once); 17 | std::thread st3(simple_do_once); 18 | std::thread st4(simple_do_once); 19 | st1.join(); 20 | st2.join(); 21 | st3.join(); 22 | st4.join(); 23 | 24 | return EXIT_SUCCESS; 25 | } 26 | -------------------------------------------------------------------------------- /examples/ex_confusing_data/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | clean: 9 | rm -f ex ex.unstripped out.txt *.s *.lib *.exp *.o *.err 10 | check: 11 | @ $(EXEC) ./ex >/tmp/res.txt 12 | @ diff out.txt /tmp/res.txt && echo TEST OK 13 | -------------------------------------------------------------------------------- /examples/ex_confusing_data/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS="" 2 | 3 | all: ex.c 4 | cl /nologo $(CFLAGS) ex.c 5 | @ ex > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 8 | check: 9 | @ ex >check.txt 10 | @ FC out.txt check.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_confusing_data/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int16_t array[12] = {10, 11, 12, 1443, 64, 0, 0, 0, // 00 00 00 00 00 40 05 A1 the address of main 6 | 17, 18, 19, 20}; 7 | 8 | void print() 9 | { 10 | for(int i = 0; i < 11; ++i) 11 | printf("%i\n", array[i]); 12 | } 13 | 14 | int main() 15 | { 16 | puts("Printing data"); 17 | print(); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /examples/ex_copy_relo/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c foo.c 6 | $(CC) -c foo.c $(CFLAGS) -o foo.o -fPIC 7 | $(CC) -c ex.c $(CFLAGS) -o ex.o 8 | $(CC) ex.o foo.o $(CFLAGS) -o ex 9 | @ $(EXEC) ./ex > out.txt 10 | clean: 11 | rm -f ex ex.unstripped out.txt *.s *.lib *.exp *.o *.err *.gtirb *.i 12 | check: 13 | @ $(EXEC) ./ex >/tmp/res.txt 14 | @ diff out.txt /tmp/res.txt && echo TEST OK 15 | -------------------------------------------------------------------------------- /examples/ex_copy_relo/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | extern int foo(); 6 | 7 | int main() 8 | { 9 | extern char **environ; 10 | int i = 0; 11 | while(environ[i]) 12 | { 13 | if(strlen(environ[i]) > 4) 14 | { 15 | if(strncmp(environ[i], "HOME", 4) == 0) 16 | { 17 | printf("%s\n", environ[i++]); 18 | } 19 | } 20 | i++; 21 | } 22 | foo(); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /examples/ex_copy_relo/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | extern char **environ; 6 | 7 | int foo() 8 | { 9 | int i = 0; 10 | while(environ[i]) 11 | { 12 | if(strlen(environ[i]) > 4) 13 | { 14 | if(strncmp(environ[i], "HOME", 4) == 0) 15 | { 16 | printf("%s\n", environ[i++]); 17 | } 18 | } 19 | i++; 20 | } 21 | return i; 22 | } 23 | -------------------------------------------------------------------------------- /examples/ex_data_limit/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | 4 | all: ex.c fun.c 5 | $(CC) fun.c -shared $(CFLAGS) -fPIC -o fun.so 6 | $(CC) ex.c $(CFLAGS) -no-pie fun.so -o ex 7 | @LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./ex > out.txt 8 | clean: 9 | rm -f ex out.txt fun.so 10 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 11 | check: 12 | @LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./ex >/tmp/res.txt 13 | @ diff out.txt /tmp/res.txt && echo TEST OK 14 | -------------------------------------------------------------------------------- /examples/ex_data_limit/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "fun.h" 4 | 5 | void foo(const char* str) 6 | { 7 | printf("foo: %s\n", str); 8 | } 9 | 10 | const char* g_str = "Hello World!"; 11 | 12 | A g = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, &foo, 0, &g_str, 0, 0, 0, 0, 0}; 13 | 14 | // The external function 'fun' has explicit references to 'foo' or 'g_str'. 15 | // However, this program itself does not have any. 16 | // In non-pie version of this program, this may make those symbols in data, 17 | // tricky to symbolize. 18 | // A solution is to add a 'data_limit' at the address with non-zero value 19 | // after consecutive zeros. 20 | int main() 21 | { 22 | int i = 0; 23 | while(g.arr[i++] == 0) 24 | { 25 | printf("%d\n", i); 26 | } 27 | 28 | fun(&g); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /examples/ex_data_limit/fun.c: -------------------------------------------------------------------------------- 1 | #include "fun.h" 2 | 3 | #include 4 | 5 | void fun(A* a) 6 | { 7 | (*a->fun_ptr)(*a->str); 8 | } 9 | -------------------------------------------------------------------------------- /examples/ex_data_limit/fun.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef struct 4 | { 5 | int32_t arr[10]; 6 | void (*fun_ptr)(const char*); 7 | int32_t v; 8 | const char** str; 9 | int32_t arr2[5]; 10 | } A; 11 | 12 | void fun(A*); 13 | -------------------------------------------------------------------------------- /examples/ex_dyn_library/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | 4 | all: ex.c fun.c 5 | $(CC) fun.c -shared $(CFLAGS) -fPIC -o fun.so 6 | $(CC) ex.c $(CFLAGS) fun.so -o ex 7 | @LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./ex > out.txt 8 | clean: 9 | rm -f ex out.txt 10 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 11 | check: 12 | @LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./ex >/tmp/res.txt 13 | @ diff out.txt /tmp/res.txt && echo TEST OK 14 | -------------------------------------------------------------------------------- /examples/ex_dyn_library/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "fun.h" 5 | 6 | int main() 7 | { 8 | fun(10, 20); 9 | puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */ 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /examples/ex_dyn_library/fun.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void fun(int a, int b) 4 | { 5 | int i = 0; 6 | while(a < b) 7 | { 8 | ++i; 9 | ++a; 10 | printf("%i\n", i); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/ex_dyn_library/fun.h: -------------------------------------------------------------------------------- 1 | void fun(int, int); 2 | -------------------------------------------------------------------------------- /examples/ex_dyn_library2/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | 4 | all: ex.c fun.c 5 | $(CC) fun.c -shared -lm $(CFLAGS) -o fun.so 6 | $(CC) ex.c $(CFLAGS) fun.so -o ex 7 | LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./ex > out.txt 8 | clean: 9 | rm -f ex out.txt 10 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 11 | check: 12 | LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./ex >/tmp/res.txt 13 | diff out.txt /tmp/res.txt && echo TEST OK 14 | -------------------------------------------------------------------------------- /examples/ex_dyn_library2/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "fun.h" 5 | 6 | int main() 7 | { 8 | fun(10, 20); 9 | fun_all(0.0f); 10 | puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */ 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /examples/ex_dyn_library2/fun.h: -------------------------------------------------------------------------------- 1 | void fun(int, int); 2 | void fun_all(float x); 3 | -------------------------------------------------------------------------------- /examples/ex_dynamic_initfini/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | clean: 9 | rm -f ex ex.unstripped out.txt *.s *.lib *.exp *.o *.err 10 | check: 11 | @ $(EXEC) ./ex >/tmp/res.txt 12 | @ diff out.txt /tmp/res.txt && echo TEST OK 13 | -------------------------------------------------------------------------------- /examples/ex_dynamic_initfini/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static void setup(void) __attribute__((constructor)); 5 | 6 | int i = 0; 7 | 8 | void setup(void) 9 | { 10 | i = 100; 11 | } 12 | 13 | int main() 14 | { 15 | printf("My number is: %d\n", i); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /examples/ex_dynamic_tls/.gitignore: -------------------------------------------------------------------------------- 1 | fun.so.s 2 | -------------------------------------------------------------------------------- /examples/ex_dynamic_tls/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | 4 | all: ex.c fun.c fun_initial_exec.c 5 | $(CC) fun.c -shared $(CFLAGS) -fPIC -o fun.so 6 | $(CC) fun_initial_exec.c -shared $(CFLAGS) -fPIC -o fun_initial_exec.so 7 | $(CC) ex.c $(CFLAGS) fun.so fun_initial_exec.so -o ex 8 | @LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./ex > out.txt 9 | clean: 10 | rm -fr ex ex.unstripped *.so *.s *.i *.o *.gtirb out.txt 11 | check: 12 | @LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./ex >/tmp/res.txt 13 | @diff out.txt /tmp/res.txt && echo TEST OK 14 | -------------------------------------------------------------------------------- /examples/ex_dynamic_tls/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "fun.h" 5 | 6 | int main() 7 | { 8 | fun(); 9 | fun_initial_exec(); 10 | fun(); 11 | fun_initial_exec(); 12 | fun(); 13 | fun_initial_exec(); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /examples/ex_dynamic_tls/fun.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static __thread int index; 4 | static __thread char buffer[16]; 5 | __thread char buffer_lib[16]; 6 | void fun() 7 | { 8 | buffer[index % 16] = '.'; 9 | buffer_lib[index % 16] = '.'; 10 | index++; 11 | printf("%d ", index); 12 | printf("%s ", buffer); 13 | printf("%s\n", buffer_lib); 14 | } 15 | -------------------------------------------------------------------------------- /examples/ex_dynamic_tls/fun.h: -------------------------------------------------------------------------------- 1 | void fun(); 2 | void fun_initial_exec(); 3 | -------------------------------------------------------------------------------- /examples/ex_dynamic_tls/fun_initial_exec.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // By setting these variables to the initial-exec tls model 4 | // the library will be marked with the STATIC_TLS flag in the dynamic section. 5 | 6 | __attribute((tls_model("initial-exec"))) static __thread int index; 7 | __attribute((tls_model("initial-exec"))) static __thread char buffer_initial_exec[16]; 8 | 9 | void fun_initial_exec() 10 | { 11 | buffer_initial_exec[index % 16] = '_'; 12 | index++; 13 | printf("%d ", index); 14 | printf("%s\n", buffer_initial_exec); 15 | } 16 | -------------------------------------------------------------------------------- /examples/ex_dynamic_tls2/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c foo.c fun.c 6 | $(CC) -c foo.c -fPIC $(CFLAGS) -o foo.o 7 | $(CC) fun.c foo.o -shared $(CFLAGS) -fPIC -o fun.so 8 | $(CC) ex.c $(CFLAGS) fun.so -o ex 9 | @LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./ex > out.txt 10 | clean: 11 | rm -f ex fun.so foo.o out.txt 12 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 13 | check: 14 | @LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./ex >/tmp/res.txt 15 | @ diff out.txt /tmp/res.txt && echo TEST OK 16 | -------------------------------------------------------------------------------- /examples/ex_dynamic_tls2/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern void print(); 4 | extern void fun(); 5 | 6 | int main() 7 | { 8 | print(); 9 | fun(); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /examples/ex_dynamic_tls2/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static char buffer[10]; 6 | 7 | void print() 8 | { 9 | for(int i = 0; i < 9; ++i) 10 | buffer[i] = 0x30 + i; 11 | buffer[9] = 0; 12 | printf("%s\n", buffer); 13 | } 14 | -------------------------------------------------------------------------------- /examples/ex_dynamic_tls2/fun.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // This test is to check if multiple symbols with the same name are 4 | // correctly disambiguated. 5 | // 6 | // In this test example, foo.c also defines a static variable named as 7 | // `buffer`. 8 | // 9 | // For fun.so built with -O2, Ddisasm should generate the following: 10 | // leaq buffer_disambig_XXXX_0@TLSLD(%rip),%rdi 11 | // callq __tls_get_addr@PLT 12 | // 13 | // The symbol `buffer` in the load instruction should be correctly 14 | // distinguished from the `buffer` defined in foo.o. 15 | 16 | static __thread char buffer[10]; 17 | 18 | void fun() 19 | { 20 | for(int i = 0; i < 9; ++i) 21 | { 22 | buffer[i] = 0x41 + i; 23 | } 24 | buffer[9] = 0; 25 | printf("%s\n", buffer); 26 | return; 27 | } 28 | -------------------------------------------------------------------------------- /examples/ex_emit_relocs/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c bar.c 6 | $(CC) -c bar.c $(CFLAGS) -o bar.o -fno-pie 7 | $(CC) -c ex.c $(CFLAGS) -o ex.o -fno-pie 8 | $(CC) ex.o bar.o $(CFLAGS) -o ex -no-pie -Wl,--emit-relocs 9 | @ $(EXEC) ./ex > out.txt 10 | clean: 11 | rm -f ex ex.unstripped out.txt *.s *.lib *.exp *.o *.err 12 | check: 13 | @ $(EXEC) ./ex >/tmp/res.txt 14 | @ diff out.txt /tmp/res.txt && echo TEST OK 15 | -------------------------------------------------------------------------------- /examples/ex_emit_relocs/bar.c: -------------------------------------------------------------------------------- 1 | 2 | int curbuf[2]; 3 | 4 | void bar(int a) 5 | { 6 | curbuf[1] = a; 7 | } 8 | -------------------------------------------------------------------------------- /examples/ex_emit_relocs/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // This example is to make sure ddisasm to handle various relocations 5 | // that remain with `--emit-relocs`. 6 | 7 | extern int curbuf[]; 8 | extern void bar(int a); 9 | 10 | void fun(int a, int b) 11 | { 12 | curbuf[0] = a + b; 13 | } 14 | 15 | int main() 16 | { 17 | fun(10, 20); 18 | bar(30); 19 | printf("%d, %d\n", curbuf[0], curbuf[1]); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /examples/ex_exceptions1/Makefile: -------------------------------------------------------------------------------- 1 | CXX="g++" 2 | EXEC= 3 | 4 | all: ex.cpp 5 | $(CXX) ex.cpp $(CXXFLAGS) -o ex 6 | @ $(EXEC) ./ex > out.txt 7 | clean: 8 | rm -f ex out.txt 9 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 10 | check: 11 | @ $(EXEC) ./ex >/tmp/res.txt 12 | @ diff out.txt /tmp/res.txt && echo TEST OK 13 | -------------------------------------------------------------------------------- /examples/ex_exceptions1/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS="" 2 | 3 | all: ex.cpp 4 | cl /nologo ex.cpp $(CFLAGS) 5 | @ ex > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 8 | check: 9 | @ ex >check.txt 10 | @ FC out.txt check.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_exceptions1/ex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | try 7 | { 8 | throw std::logic_error("This is a logic error"); 9 | } 10 | catch(std::exception& e) 11 | { 12 | std::cout << e.what() << std::endl; 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /examples/ex_exceptions2/Makefile: -------------------------------------------------------------------------------- 1 | CXX="g++" 2 | EXEC= 3 | 4 | all: ex.cpp 5 | $(CXX) ex.cpp $(CXXFLAGS) -o ex 6 | @ $(EXEC) ./ex > out.txt 7 | clean: 8 | rm -f ex out.txt 9 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 10 | check: 11 | @ $(EXEC) ./ex >/tmp/res.txt 12 | @ diff out.txt /tmp/res.txt && echo TEST OK 13 | -------------------------------------------------------------------------------- /examples/ex_exceptions2/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS="" 2 | 3 | all: ex.cpp 4 | cl /nologo ex.cpp $(CFLAGS) 5 | @ ex > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.asm out.txt check.txt mllink$$.lnk 8 | check: 9 | @ ex >check.txt 10 | @ FC out.txt check.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_exceptions2/ex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void f1(bool throwExc) 5 | { 6 | if(throwExc) 7 | throw std::invalid_argument("This is an invalid argument"); 8 | } 9 | 10 | void f2(bool throwExc, bool throwExc2) 11 | { 12 | try 13 | { 14 | f1(throwExc); 15 | if(throwExc2) 16 | throw std::domain_error("This is a domaing error"); 17 | throw std::logic_error("This is a logic error"); 18 | } 19 | catch(std::invalid_argument& e) 20 | { 21 | std::cout << e.what() << std::endl; 22 | } 23 | catch(std::domain_error& e) 24 | { 25 | std::cout << e.what() << std::endl; 26 | } 27 | } 28 | 29 | int main() 30 | { 31 | try 32 | { 33 | f2(true, true); 34 | f2(false, true); 35 | f2(false, false); 36 | } 37 | catch(std::exception& e) 38 | { 39 | std::cout << e.what() << std::endl; 40 | } 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /examples/ex_exceptions3/Makefile: -------------------------------------------------------------------------------- 1 | CXX="g++" 2 | EXEC= 3 | 4 | all: ex.cpp 5 | $(CXX) ex.cpp $(CXXFLAGS) -std=c++11 -o ex 6 | @ $(EXEC) ./ex > out.txt 7 | clean: 8 | rm -f ex out.txt 9 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 10 | check: 11 | @ $(EXEC) ./ex >/tmp/res.txt 12 | @ diff out.txt /tmp/res.txt && echo TEST OK 13 | -------------------------------------------------------------------------------- /examples/ex_exceptions3/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS="" 2 | 3 | all: ex.cpp 4 | cl /nologo ex.cpp $(CFLAGS) 5 | @ ex > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 8 | check: 9 | @ ex >check.txt 10 | @ FC out.txt check.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_exceptions3/ex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | class myException : std::logic_error 6 | { 7 | public: 8 | myException(const std::string& msg) : std::logic_error(msg) 9 | { 10 | } 11 | std::string what() 12 | { 13 | return std::logic_error::what(); 14 | } 15 | }; 16 | 17 | void f1(int counter) 18 | { 19 | try 20 | { 21 | if(counter == 0) 22 | throw myException("exception"); 23 | else 24 | f1(counter - 1); 25 | } 26 | catch(myException& e) 27 | { 28 | std::cout << e.what(); 29 | std::cout << " catched in level " << counter << std::endl; 30 | throw myException("exception thrown in level " + std::to_string(counter)); 31 | } 32 | } 33 | 34 | void f2() 35 | { 36 | try 37 | { 38 | f1(10); 39 | } 40 | catch(myException& e) 41 | { 42 | std::cout << e.what(); 43 | std::cout << " catched in f2" << std::endl; 44 | } 45 | } 46 | int main() 47 | { 48 | f2(); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /examples/ex_exceptions4/Makefile: -------------------------------------------------------------------------------- 1 | CXX="g++" 2 | EXEC= 3 | 4 | all: ex.cpp 5 | # NOTE: `-T linker-script.ld` 6 | # This is to place .gcc_except_table *before* .note.gnu.build-id 7 | # so that the reference label for the end of the section is aligned 8 | # with the adjacent section. 9 | # 10 | # With this example, if a boundary_sym_expr is not correctly created 11 | # for symbol_minus_symbol, the assembler will fail with 12 | # "Error: invalid operands for '-'" 13 | $(CXX) ex.cpp $(CXXFLAGS) -T linker-script.ld -o ex 14 | @ $(EXEC) ./ex > out.txt 15 | clean: 16 | rm -f ex out.txt 17 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 18 | check: 19 | @ $(EXEC) ./ex >/tmp/res.txt 20 | @ diff out.txt /tmp/res.txt && echo TEST OK 21 | -------------------------------------------------------------------------------- /examples/ex_exceptions4/ex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | try 7 | { 8 | throw std::logic_error("This is a logic error"); 9 | } 10 | catch(std::exception& e) 11 | { 12 | std::cout << e.what() << std::endl; 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /examples/ex_exceptions4/linker-script.ld: -------------------------------------------------------------------------------- 1 | SECTIONS { 2 | .gcc_except_table : { *(.gcc_except_table) } 3 | } 4 | INSERT BEFORE .note.gnu.build-id; 5 | -------------------------------------------------------------------------------- /examples/ex_false_pointer_array/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | clean: 9 | rm -f ex ex.unstripped out.txt *.s *.lib *.exp *.o *.err 10 | check: 11 | @ $(EXEC) ./ex >/tmp/res.txt 12 | @ diff out.txt /tmp/res.txt && echo TEST OK 13 | -------------------------------------------------------------------------------- /examples/ex_false_pointer_array/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS="" 2 | 3 | all: ex.c 4 | cl /nologo $(CFLAGS) ex.c 5 | @ ex > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 8 | check: 9 | @ ex >check.txt 10 | @ FC out.txt check.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_false_pointer_array/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // the array should no be classified as a pointer even though it has a value 5 | // that coincides with the code section. 6 | 7 | void f() 8 | { 9 | puts("f"); 10 | } 11 | void g() 12 | { 13 | puts("g"); 14 | } 15 | 16 | char array[8] = {0x99, 0x05, 0x40, 0, 0, 0, 0, 0}; 17 | void (*f_pointer)() = &f; 18 | void (*g_pointer)() = &g; 19 | 20 | void print() 21 | { 22 | for(int i = 0; i < 7; ++i) 23 | printf("%i\n", array[i]); 24 | } 25 | 26 | int main() 27 | { 28 | (*f_pointer)(); 29 | (*g_pointer)(); 30 | puts("Printing data"); 31 | print(); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /examples/ex_float/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | clean: 9 | rm -f ex ex.unstripped out.txt *.s *.lib *.exp *.o *.err 10 | check: 11 | @ $(EXEC) ./ex >/tmp/res.txt 12 | @ diff out.txt /tmp/res.txt && echo TEST OK 13 | -------------------------------------------------------------------------------- /examples/ex_float/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS="" 2 | 3 | all: ex.c 4 | cl /nologo $(CFLAGS) ex.c 5 | @ ex > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 8 | check: 9 | @ ex >check.txt 10 | @ FC out.txt check.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_float/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void fun(int a, int b) 6 | { 7 | float fl = 4567765; 8 | double dbl = 984753; 9 | int64_t i64 = 98438765876587657; 10 | int32_t i32 = 98437; 11 | int16_t i16 = 984; 12 | char ch = 5; 13 | 14 | while(a < b) 15 | { 16 | ++a; 17 | ++fl; 18 | ++dbl; 19 | i64++; 20 | i32++; 21 | i16++; 22 | ch++; 23 | } 24 | printf("%f\n", fl); 25 | printf("%f\n", dbl); 26 | 27 | printf("%li\n", i64); 28 | printf("%i\n", i32); 29 | printf("%i\n", i16); 30 | printf("%c\n", ch); 31 | } 32 | int main() 33 | { 34 | puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */ 35 | fun(10, 20); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /examples/ex_fprintf/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | clean: 9 | rm -f ex ex.unstripped out.txt *.s *.lib *.exp *.o *.err 10 | check: 11 | @ $(EXEC) ./ex >/tmp/res.txt 12 | @ diff out.txt /tmp/res.txt && echo TEST OK 13 | -------------------------------------------------------------------------------- /examples/ex_fprintf/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS="/Fa" 2 | 3 | all: ex.c 4 | cl /nologo $(CFLAGS) ex.c 5 | @ ex > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 8 | check: 9 | @ ex >check.txt 10 | @ FC out.txt check.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_fprintf/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | fprintf(stderr, "%s %s %s\n", "a", " string", " in stderr"); 6 | fprintf(stdout, "%s %s %s\n", "a", " string", " in stdout"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /examples/ex_getoptlong/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | clean: 9 | rm -f ex out.txt 10 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 11 | check: 12 | @ $(EXEC) ./ex >/tmp/res.txt 13 | @ diff out.txt /tmp/res.txt && echo TEST OK 14 | -------------------------------------------------------------------------------- /examples/ex_getoptlong/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char **argv) 6 | { 7 | int c; 8 | 9 | while(1) 10 | { 11 | static struct option long_options[] = { 12 | {"verbose", no_argument, 0, 'v'}, {"add", no_argument, 0, 'a'}, {0, 0, 0, 0}}; 13 | /* getopt_long stores the option index here. */ 14 | int option_index = 0; 15 | 16 | c = getopt_long(argc, argv, "av", long_options, &option_index); 17 | 18 | /* Detect the end of the options. */ 19 | if(c == -1) 20 | break; 21 | 22 | switch(c) 23 | { 24 | case 'v': 25 | puts("option -v\n"); 26 | break; 27 | case 'a': 28 | puts("option -a\n"); 29 | break; 30 | case '?': 31 | /* getopt_long already printed an error message. */ 32 | break; 33 | 34 | default: 35 | abort(); 36 | } 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /examples/ex_imported_tls_syms/Makefile: -------------------------------------------------------------------------------- 1 | CXX="g++" 2 | all: ex.cpp 3 | $(CXX) ex.cpp $(CXXFLAGS) -lpthread -o ex 4 | ./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex >/tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_imported_tls_syms/ex.cpp: -------------------------------------------------------------------------------- 1 | // https://en.cppreference.com/w/cpp/thread/call_once 2 | #include 3 | #include 4 | #include 5 | 6 | std::once_flag flag1; 7 | thread_local std::string g_my_tls; 8 | 9 | void simple_do_once() 10 | { 11 | std::call_once(flag1, []() { std::cout << "called once\n"; }); 12 | } 13 | 14 | int main() 15 | { 16 | g_my_tls = "Hello World!"; 17 | 18 | std::thread st1(simple_do_once); 19 | std::thread st2(simple_do_once); 20 | std::thread st3(simple_do_once); 21 | std::thread st4(simple_do_once); 22 | st1.join(); 23 | st2.join(); 24 | st3.join(); 25 | st4.join(); 26 | 27 | std::cout << g_my_tls << std::endl; 28 | 29 | return EXIT_SUCCESS; 30 | } 31 | -------------------------------------------------------------------------------- /examples/ex_init_array/Makefile: -------------------------------------------------------------------------------- 1 | CXX="g++" 2 | CXXFLAGS= 3 | EXEC= 4 | 5 | all: ex1.c ex2.c 6 | $(CXX) ex1.c ex2.c $(CXXFLAGS) -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | clean: 9 | rm -f ex out.txt 10 | check: 11 | @ $(EXEC) ./ex >/tmp/res.txt 12 | @ diff out.txt /tmp/res.txt && echo TEST OK 13 | -------------------------------------------------------------------------------- /examples/ex_init_array/ex.hpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | class Cl1 6 | { 7 | private: 8 | std::string msg; 9 | 10 | public: 11 | Cl1(const char* msg) : msg(msg) 12 | { 13 | std::cout << msg << std::endl; 14 | } 15 | ~Cl1() 16 | { 17 | std::cout << "bye " << msg << std::endl; 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /examples/ex_init_array/ex1.c: -------------------------------------------------------------------------------- 1 | #include "ex.hpp" 2 | 3 | static Cl1 cl("hey"); 4 | -------------------------------------------------------------------------------- /examples/ex_init_array/ex2.c: -------------------------------------------------------------------------------- 1 | #include "ex.hpp" 2 | 3 | static Cl1 s("you"); 4 | 5 | int main(void) 6 | { 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /examples/ex_kuser/Makefile: -------------------------------------------------------------------------------- 1 | CC= 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: 6 | $(CC) ex.c -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | clean: 9 | rm -f ex *.exe *.dll out.txt *.s *.lib *.exp *.o *.err 10 | check: 11 | @ $(EXEC) ./ex >/tmp/res.txt 12 | @ diff out.txt /tmp/res.txt && echo TEST OK 13 | -------------------------------------------------------------------------------- /examples/ex_kuser/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS="" 2 | 3 | all: 4 | cl /nologo ex.c $(CFLAGS) 5 | @ ex > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 8 | check: 9 | @ ex > check.txt 10 | @ FC out.txt check.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_kuser/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define KUSER_SHARED_DATA 0x7ffe0000 5 | #define MAJOR_VERSION_OFFSET 0x026C 6 | #define MINOR_VERSION_OFFSET 0x0270 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | ULONG major = *(PULONG)(KUSER_SHARED_DATA + MAJOR_VERSION_OFFSET); 11 | ULONG minor = *(PULONG)(KUSER_SHARED_DATA + MINOR_VERSION_OFFSET); 12 | printf("%lu.%lu\n", major, minor); 13 | } 14 | -------------------------------------------------------------------------------- /examples/ex_legacy_switch.001/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ for CHAR in A B C D E F G H; do $(EXEC) ./ex.exe "$$CHAR"; done > out.txt 8 | clean: 9 | rm -f ex.exe *.txt *.s *.lib *.exp *.o *.err 10 | check: 11 | @ for CHAR in A B C D E F G H; do $(EXEC) ./ex.exe "$$CHAR"; done > check.txt 12 | @ diff out.txt check.txt && echo TEST OK 13 | -------------------------------------------------------------------------------- /examples/ex_legacy_switch.001/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS = "/Fa" 2 | 3 | all: ex.c 4 | cl $(CFLAGS) ex.c 5 | cmd /C "for %A in (A,B,C,D,E,F,G,H) do @ ex.exe %A" > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.asm out.txt check.txt mllink$$.lnk 8 | del /F /Q ex.unstripped *.s *.old* 9 | if exist dl_files { rmdir /Q /S dl_files } 10 | check: 11 | cmd /C "for %A in (A,B,C,D,E,F,G,H) do @ ex.exe %A" > check.txt 12 | @ FC out.txt check.txt && echo TEST OK 13 | -------------------------------------------------------------------------------- /examples/ex_legacy_switch.002/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ for CHAR in A B C D E F G H I J K L M N O P Q R S T U V W X Y Z; do $(EXEC) ./ex.exe "$$CHAR"; done > out.txt 8 | clean: 9 | rm -f ex.exe *.txt *.s *.lib *.exp *.o *.err 10 | check: 11 | @ for CHAR in A B C D E F G H I J K L M N O P Q R S T U V W X Y Z; do $(EXEC) ./ex.exe "$$CHAR"; done > check.txt 12 | @ diff out.txt check.txt && echo TEST OK 13 | -------------------------------------------------------------------------------- /examples/ex_legacy_switch.002/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS = "/Fa" 2 | 3 | all: ex.c 4 | cl $(CFLAGS) ex.c 5 | cmd /C "for %A in (A,B,C,D,E,F,G,H,I,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z) do @ ex.exe %A" > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 8 | check: 9 | cmd /C "for %A in (A,B,C,D,E,F,G,H,I,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z) do @ ex.exe %A" > check.txt 10 | @ FC out.txt check.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_legacy_switch.003/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ for CHAR in 750 800 900 700 500 250 100 200 600; do $(EXEC) ./ex.exe "$$CHAR"; done > out.txt 8 | clean: 9 | rm -f ex.exe *.txt *.s *.lib *.exp *.o *.err 10 | check: 11 | @ for CHAR in 750 800 900 700 500 250 100 200 600; do $(EXEC) ./ex.exe "$$CHAR"; done > check.txt 12 | @ diff out.txt check.txt && echo TEST OK 13 | -------------------------------------------------------------------------------- /examples/ex_legacy_switch.003/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS = "/Fa" 2 | 3 | all: ex.c 4 | cl $(CFLAGS) ex.c 5 | cmd /C "for %A in (750 800 900 700 500 250 100 200 600) do @ ex.exe %A" > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 8 | check: 9 | cmd /C "for %A in (750 800 900 700 500 250 100 200 600) do @ ex.exe %A" > check.txt 10 | @ FC out.txt check.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_legacy_switch.004/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | SEQUENCE = 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 6 | 7 | all: ex.c 8 | $(CC) ex.c $(CFLAGS) -o ex 9 | @ for CHAR in $(SEQUENCE); do $(EXEC) ./ex.exe "$$CHAR"; done > out.txt 10 | clean: 11 | rm -f ex.exe *.txt *.s *.lib *.exp *.o *.err 12 | check: 13 | @ for CHAR in $(SEQUENCE); do $(EXEC) ./ex.exe "$$CHAR"; done > check.txt 14 | @ diff out.txt check.txt && echo TEST OK 15 | -------------------------------------------------------------------------------- /examples/ex_legacy_switch.004/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS = "/Fa" 2 | SEQUENCE = 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 3 | 4 | all: ex.c 5 | cl $(CFLAGS) ex.c 6 | cmd /C "for %A in ($(SEQUENCE)) do @ ex.exe %A" > out.txt 7 | clean: 8 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 9 | check: 10 | cmd /C "for %A in ($(SEQUENCE)) do @ ex.exe %A" > check.txt 11 | @ FC out.txt check.txt && echo TEST OK 12 | -------------------------------------------------------------------------------- /examples/ex_lib_symbols/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | 4 | 5 | all: ex_so.c 6 | $(CC) ex_so.c -shared $(CFLAGS) -fPIC -o ex.so 7 | clean: 8 | rm -f ex.so 9 | -------------------------------------------------------------------------------- /examples/ex_lib_symbols/ex_so.c: -------------------------------------------------------------------------------- 1 | int foo() 2 | { 3 | return 7; 4 | } 5 | int bar() 6 | { 7 | return foo(); 8 | } 9 | -------------------------------------------------------------------------------- /examples/ex_memberFunction/Makefile: -------------------------------------------------------------------------------- 1 | CXX="g++" 2 | EXEC= 3 | 4 | all: ex.cpp 5 | $(CXX) ex.cpp $(CXXFLAGS) -o ex 6 | @ $(EXEC) ./ex > out.txt 7 | clean: 8 | rm -f ex ex.unstripped out.txt *.s *.lib *.exp *.o *.err *.gtirb 9 | check: 10 | @ $(EXEC) ./ex >/tmp/res.txt 11 | @ diff out.txt /tmp/res.txt && echo TEST OK 12 | -------------------------------------------------------------------------------- /examples/ex_memberFunction/ex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | class a 5 | { 6 | public: 7 | void foo(); 8 | 9 | private: 10 | __attribute__((visibility("hidden"))) void bar(); 11 | void baz() __attribute__((weak)); 12 | }; 13 | 14 | void a::foo() 15 | { 16 | printf("foo\n"); 17 | this->bar(); 18 | this->baz(); 19 | } 20 | 21 | void a::bar() 22 | { 23 | printf("bar\n"); 24 | } 25 | 26 | void a::baz() 27 | { 28 | printf("baz\n"); 29 | } 30 | 31 | int main() 32 | { 33 | a *a1; 34 | a1 = new a(); 35 | a1->foo(); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /examples/ex_memberPointer/Makefile: -------------------------------------------------------------------------------- 1 | CXX="g++" 2 | EXEC= 3 | 4 | all: ex.cpp 5 | $(CXX) ex.cpp $(CXXFLAGS) -o ex 6 | @ $(EXEC) ./ex > out.txt 7 | clean: 8 | rm -f ex ex.unstripped out.txt *.s *.lib *.exp *.o *.err 9 | check: 10 | @ $(EXEC) ./ex >/tmp/res.txt 11 | @ diff out.txt /tmp/res.txt && echo TEST OK 12 | -------------------------------------------------------------------------------- /examples/ex_memberPointer/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS="/Fa" 2 | 3 | all: ex.cpp 4 | cl /nologo $(CFLAGS) ex.cpp 5 | @ ex > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 8 | check: 9 | @ ex >check.txt 10 | @ FC out.txt check.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_memberPointer/ex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | class a 5 | { 6 | public: 7 | // int m[8]={25,255,25,255,25,255,255,25}; 8 | virtual void print(); 9 | virtual void print2(); 10 | virtual void choose(int which); 11 | }; 12 | 13 | void a::print() 14 | { 15 | puts("A1"); 16 | } 17 | 18 | void a::print2() 19 | { 20 | puts("A2"); 21 | } 22 | 23 | typedef void (a::*FPTR)(); 24 | void a::choose(int which) 25 | { 26 | FPTR fptr[4] = {&a::print, &a::print2, &a::print, &a::print}; 27 | FPTR sel = fptr[which]; 28 | (this->*sel)(); 29 | } 30 | 31 | int main() 32 | { 33 | a *a1; 34 | a1 = new a(); 35 | a1->choose(0); 36 | a1->choose(1); 37 | a1->choose(2); 38 | a1->choose(3); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /examples/ex_ml_sym_mangling/.gitignore: -------------------------------------------------------------------------------- 1 | *.dll 2 | *.exp 3 | *.exe 4 | *.obj 5 | *.lib 6 | -------------------------------------------------------------------------------- /examples/ex_ml_sym_mangling/Makefile.windows: -------------------------------------------------------------------------------- 1 | CC=cl 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: foo baz 6 | $(CC) ex.c foo.lib baz.lib 7 | @ ex > out.txt 8 | 9 | foo: foo.h foo.c 10 | $(CC) $(CFLAGS) /LD foo.c 11 | 12 | baz: baz.h baz.c foo 13 | $(CC) $(CFLAGS) /LD baz.c foo.lib 14 | 15 | clean: 16 | rm -f ex *.dll out.txt *.s *.lib *.exp *.o *.err *.obj *.exe 17 | 18 | check: 19 | @ ex > check.txt 20 | @ FC out.txt check.txt && echo TEST OK 21 | 22 | reassemble: 23 | @ $(AS) $(ASFLAGS) /c baz.dll.s 24 | @ lib.exe /subsystem:console /def /export:message baz.dll.obj 25 | @ link.exe /subsystem:console /entry:__EntryPoint /dll baz.dll.obj baz.dll.exp 26 | @ link.exe /out:ex.exe /subsystem:console ex.obj baz.dll.lib 27 | -------------------------------------------------------------------------------- /examples/ex_ml_sym_mangling/baz.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "foo.h" 4 | 5 | __declspec(dllexport) void Baz() 6 | { 7 | Foo(); 8 | _Bar(); 9 | puts("Baz"); 10 | } 11 | __declspec(dllexport) void _Baz() 12 | { 13 | Foo(); 14 | _Bar(); 15 | puts("_Baz"); 16 | } 17 | __declspec(dllexport) void __Baz() 18 | { 19 | Foo(); 20 | _Bar(); 21 | puts("__Baz"); 22 | } 23 | -------------------------------------------------------------------------------- /examples/ex_ml_sym_mangling/baz.h: -------------------------------------------------------------------------------- 1 | __declspec(dllexport) void Baz(); 2 | __declspec(dllexport) void _Baz(); 3 | __declspec(dllexport) void __Baz(); 4 | -------------------------------------------------------------------------------- /examples/ex_ml_sym_mangling/ex.c: -------------------------------------------------------------------------------- 1 | 2 | #include "baz.h" 3 | 4 | int main() 5 | { 6 | Baz(); 7 | _Baz(); 8 | __Baz(); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /examples/ex_ml_sym_mangling/foo.c: -------------------------------------------------------------------------------- 1 | #include "foo.h" 2 | 3 | #include 4 | 5 | __declspec(dllexport) void Foo() 6 | { 7 | puts("Foo"); 8 | } 9 | 10 | __declspec(dllexport) void _Bar() 11 | { 12 | puts("_Bar"); 13 | } 14 | -------------------------------------------------------------------------------- /examples/ex_ml_sym_mangling/foo.h: -------------------------------------------------------------------------------- 1 | __declspec(dllexport) void Foo(); 2 | __declspec(dllexport) void _Bar(); 3 | -------------------------------------------------------------------------------- /examples/ex_noreturn/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | clean: 9 | rm -f ex out.txt 10 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 11 | check: 12 | @ $(EXEC) ./ex >/tmp/res.txt 13 | @ diff out.txt /tmp/res.txt && echo TEST OK 14 | -------------------------------------------------------------------------------- /examples/ex_noreturn/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS="/Fa" 2 | 3 | all: ex.c 4 | cl /nologo $(CFLAGS) ex.c 5 | @ ex > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 8 | check: 9 | @ ex >check.txt 10 | @ FC out.txt check.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_noreturn/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void fun(int a, int b) 5 | { 6 | int i = 0; 7 | while(a < b) 8 | { 9 | ++i; 10 | ++a; 11 | } 12 | } 13 | int main() 14 | { 15 | fun(10, 20); 16 | puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */ 17 | exit(0); 18 | } 19 | -------------------------------------------------------------------------------- /examples/ex_obj_debug_reloc/Makefile: -------------------------------------------------------------------------------- 1 | # Running this test on ARM creates address collisions with instructions that 2 | # may be symbolized and debug relocations. ARM makes this collisions more 3 | # likely since instructions are aligned and fixed size. 4 | 5 | CC=arm-linux-gnueabihf-gcc 6 | CFLAGS=-g -Og 7 | EXEC=qemu-arm -L /usr/arm-linux-gnueabihf 8 | 9 | .PHONY: all clean check 10 | 11 | all: out.txt 12 | ex: ex.o 13 | $(CC) $(CFLAGS) -o $@ $^ 14 | %.o: %.c 15 | $(CC) $(CFLAGS) -c -o $@ $^ 16 | out.txt: ex 17 | @ $(EXEC) ./ex > $@ 18 | clean: 19 | rm -f ex out.txt 20 | rm -fr ex.unstripped *.s *.o *.old* dl_files *.gtirb 21 | check: 22 | @ $(EXEC) ./ex >/tmp/res.txt 23 | @ diff out.txt /tmp/res.txt && echo TEST OK 24 | -------------------------------------------------------------------------------- /examples/ex_obj_debug_reloc/ex.c: -------------------------------------------------------------------------------- 1 | /** 2 | This example is used to verify that debug relocations are not erroneously 3 | applied to other sections. 4 | 5 | This bug was occurring in .o files 6 | 7 | See issue #323. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | struct stru 14 | { 15 | uint32_t a; 16 | uint32_t b; 17 | uint32_t c; 18 | uint32_t d; 19 | }; 20 | 21 | /** 22 | Copy some fields around in a struct. 23 | 24 | These struct operations generate loads of memory access instructions that may 25 | be symbolized. We want some instructions that may be symbolized to collide with 26 | some debug relocations. 27 | */ 28 | void flip_stru(struct stru *stru1, struct stru *stru2) 29 | { 30 | stru2->a = stru1->d; 31 | stru2->b = stru1->c; 32 | stru2->c = stru1->b; 33 | stru2->d = stru1->a; 34 | } 35 | 36 | int main(void) 37 | { 38 | printf("hello world\n"); 39 | 40 | struct stru stru1 = {.a = 1, .b = 2, .c = 3, .d = 4}; 41 | struct stru stru2; 42 | flip_stru(&stru1, &stru2); 43 | 44 | printf("%d %d %d %d\n", stru2.a, stru2.b, stru2.c, stru2.d); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /examples/ex_pointerReattribution/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | clean: 9 | rm -f ex out.txt 10 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 11 | check: 12 | @ $(EXEC) ./ex >/tmp/res.txt 13 | @ diff out.txt /tmp/res.txt && echo TEST OK 14 | -------------------------------------------------------------------------------- /examples/ex_pointerReattribution/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS="/Fa" 2 | 3 | all: ex.c 4 | cl /nologo $(CFLAGS) ex.c 5 | @ ex > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 8 | check: 9 | @ ex >check.txt 10 | @ FC out.txt check.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_pointerReattribution/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | uint64_t state[16] = {0}; 6 | 7 | void sprng(uint64_t seed) 8 | { 9 | uint64_t state_64 = seed; 10 | for(int i = 0; i < 16; i++) 11 | { 12 | state_64 ^= state_64 >> 27; 13 | state_64 ^= state_64 >> 13; 14 | state_64 ^= state_64 >> 46; 15 | state[i] = state_64 * 1865811235122147685; 16 | } 17 | } 18 | 19 | int main() 20 | { 21 | sprng(89876986765987652); 22 | int a = 0; 23 | int b = 4; 24 | a = b + 3; 25 | printf("%i \n", a); 26 | for(int i = 0; i < 16; i++) 27 | printf("%" PRIu64 " \n", state[i]); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /examples/ex_pointerReattribution2/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ echo "A" | $(EXEC) ./ex > out.txt 8 | @ echo "B" | $(EXEC) ./ex >> out.txt 9 | @ echo "C" | $(EXEC) ./ex >> out.txt 10 | clean: 11 | rm -f ex out.txt 12 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 13 | check: 14 | @ echo "A" | $(EXEC) ./ex > /tmp/res.txt 15 | @ echo "B" | $(EXEC) ./ex >> /tmp/res.txt 16 | @ echo "C" | $(EXEC) ./ex >> /tmp/res.txt 17 | @ diff out.txt /tmp/res.txt && echo TEST OK 18 | -------------------------------------------------------------------------------- /examples/ex_pointerReattribution2/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS="/Fa" 2 | 3 | all: ex.c 4 | cl /nologo $(CFLAGS) ex.c 5 | @ echo A |ex > out.txt 6 | @ echo B |ex >> out.txt 7 | @ echo C |ex >> out.txt 8 | clean: 9 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 10 | check: 11 | @ echo A |ex > check.txt 12 | @ echo B |ex >> check.txt 13 | @ echo C |ex >> check.txt 14 | @ FC out.txt check.txt && echo TEST OK 15 | -------------------------------------------------------------------------------- /examples/ex_pointerReattribution2/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int counters[2] = {0}; 6 | 7 | void print() 8 | { 9 | for(int i = 0; i < 2; ++i) 10 | printf("%i\n", counters[i]); 11 | } 12 | 13 | int main() 14 | { 15 | int input; 16 | input = getchar(); 17 | switch(input) 18 | { 19 | case 'A': 20 | puts("option A"); 21 | break; 22 | case 'B': 23 | puts("option B"); 24 | break; 25 | default: 26 | puts("Unknown option."); 27 | return 0; 28 | } 29 | counters[input - 'A']++; 30 | print(); 31 | } 32 | -------------------------------------------------------------------------------- /examples/ex_pointerReattribution3/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | clean: 9 | rm -f ex out.txt 10 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 11 | check: 12 | @ $(EXEC) ./ex > /tmp/res.txt 13 | @ diff out.txt /tmp/res.txt && echo TEST OK 14 | -------------------------------------------------------------------------------- /examples/ex_pointerReattribution3/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS="" 2 | 3 | all: ex.c 4 | cl /nologo $(CFLAGS) ex.c 5 | @ ex > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 8 | check: 9 | @ ex >check.txt 10 | @ FC out.txt check.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_pointerReattribution3/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct big_str 6 | { 7 | uint64_t a; 8 | uint64_t b; 9 | uint64_t c; 10 | uint64_t d; 11 | uint64_t e; 12 | uint64_t f; 13 | uint64_t g; 14 | uint64_t h; 15 | uint64_t i; 16 | uint64_t j; 17 | uint64_t k; 18 | }; 19 | 20 | struct big_str state[16] = { 21 | {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 22 | {2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 23 | {4, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 24 | {6, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 25 | {8, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 26 | {10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {11, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 27 | {12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {13, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 28 | {14, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}; 29 | 30 | int main() 31 | { 32 | int a = 0; 33 | int b = 4; 34 | a = b + 3; 35 | printf("%i \n", a); 36 | for(int i = 15; i >= 0; i--) 37 | printf("%" PRIu64 " \n", state[i].a); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /examples/ex_rsrc/.gitignore: -------------------------------------------------------------------------------- 1 | ex.exe 2 | ex.obj 3 | ex.res 4 | -------------------------------------------------------------------------------- /examples/ex_rsrc/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS="/Fa" 2 | 3 | all: ex.res ex.c 4 | cl /nologo $(CFLAGS) ex.c /link ex.res 5 | @ ex > out.txt 6 | ex.res: ex.rc 7 | rc /nologo ex.rc 8 | clean: 9 | del /F /Q *.exe *.obj *.exp *.def *.lib *.res *.s out.txt check.txt mllink$$.lnk 10 | check: 11 | @ ex >check.txt 12 | @ FC out.txt check.txt && echo TEST OK 13 | -------------------------------------------------------------------------------- /examples/ex_rsrc/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "resource.h" 6 | 7 | int main() 8 | { 9 | HRSRC hResource = FindResourceA(NULL, MAKEINTRESOURCEA(RCDATA1), MAKEINTRESOURCEA(RT_RCDATA)); 10 | if(!hResource) 11 | { 12 | puts("ERROR: FindResource: RCDATA1"); 13 | return EXIT_FAILURE; 14 | } 15 | 16 | HGLOBAL hMemory = LoadResource(NULL, hResource); 17 | if(!hMemory) 18 | { 19 | puts("ERROR: LoadResource: RCDATA1"); 20 | return EXIT_FAILURE; 21 | } 22 | 23 | size_t size = SizeofResource(NULL, hResource); 24 | void* ptr = LockResource(hMemory); 25 | 26 | fprintf(stderr, "%zu @ %p\n", size, ptr); 27 | fprintf(stderr, "%s\n", (char*)ptr); 28 | 29 | puts("OK"); 30 | return EXIT_SUCCESS; 31 | } 32 | -------------------------------------------------------------------------------- /examples/ex_rsrc/ex.rc: -------------------------------------------------------------------------------- 1 | #include "resource.h" 2 | 3 | RCDATA1 RCDATA 4 | { 5 | "hello from rsrc",0x00, 6 | 0x1000, 0x0040, 7 | 0x102f, 0x0040, 8 | 0x1000, 0x4000, 0x0001, 0x0000, 9 | 0x163b, 0x4000, 0x0001, 0x0000 10 | } 11 | -------------------------------------------------------------------------------- /examples/ex_rsrc/resource.h: -------------------------------------------------------------------------------- 1 | #define RCDATA1 101 2 | -------------------------------------------------------------------------------- /examples/ex_seh/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS="" 2 | 3 | all: ex.c 4 | cl /nologo ex.c $(CFLAGS) 5 | @ ex > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 8 | check: 9 | @ ex >check.txt 10 | @ FC out.txt check.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_seh/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | BOOL ReadPtr(const DWORD* p) 5 | { 6 | BOOL bBad = 0; 7 | __try 8 | { 9 | DWORD dwDummy = *p; 10 | printf("%X\n", dwDummy); 11 | } 12 | __except(EXCEPTION_EXECUTE_HANDLER) 13 | { 14 | puts("exception"); 15 | bBad = 1; 16 | } 17 | return (bBad); 18 | } 19 | 20 | int main() 21 | { 22 | int valid = 0xBEEF; 23 | if(ReadPtr(&valid)) 24 | { 25 | puts("ERROR"); 26 | } 27 | if(ReadPtr(0)) 28 | { 29 | puts("OK"); 30 | } 31 | return EXIT_SUCCESS; 32 | } 33 | -------------------------------------------------------------------------------- /examples/ex_simple_dll/.gitignore: -------------------------------------------------------------------------------- 1 | test.dll 2 | -------------------------------------------------------------------------------- /examples/ex_simple_dll/Makefile: -------------------------------------------------------------------------------- 1 | CC= 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: dll 6 | $(CC) ex.c test.dll -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | dll: test.h test.c 9 | $(CC) test.c $(CFLAGS) -shared -o test.dll 10 | clean: 11 | rm -f ex *.dll out.txt *.s *.lib *.exp *.o *.err 12 | check: 13 | @ $(EXEC) ./ex >/tmp/res.txt 14 | @ diff out.txt /tmp/res.txt && echo TEST OK 15 | -------------------------------------------------------------------------------- /examples/ex_simple_dll/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS = "/Fa" 2 | 3 | all: dll 4 | $(CC) ex.c test.lib 5 | @ ex > out.txt 6 | dll: test.h test.c 7 | @ $(CC) $(CFLAGS) /LD test.c 8 | clean: 9 | del /F /Q *.exe *.dll *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 10 | check: 11 | @ ex > check.txt 12 | @ FC out.txt check.txt && echo TEST OK 13 | reassemble: 14 | @ $(AS) $(ASFLAGS) /c test.dll.s 15 | @ lib.exe /subsystem:console /def /export:message test.dll.obj 16 | @ link.exe /subsystem:console /entry:__EntryPoint /dll test.dll.obj test.dll.exp 17 | @ link.exe /out:ex.exe /subsystem:console ex.obj test.dll.lib 18 | -------------------------------------------------------------------------------- /examples/ex_simple_dll/ex.c: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | 3 | int main() 4 | { 5 | message(); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /examples/ex_simple_dll/test.c: -------------------------------------------------------------------------------- 1 | #include "test.h" 2 | 3 | #include 4 | 5 | __declspec(dllexport) void message() 6 | { 7 | puts("hello dll"); 8 | } 9 | -------------------------------------------------------------------------------- /examples/ex_simple_dll/test.h: -------------------------------------------------------------------------------- 1 | __declspec(dllexport) void message(void); 2 | -------------------------------------------------------------------------------- /examples/ex_stat/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | clean: 9 | rm -f ex out.txt 10 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 11 | check: 12 | @ $(EXEC) ./ex >/tmp/res.txt 13 | @ diff out.txt /tmp/res.txt && echo TEST OK 14 | -------------------------------------------------------------------------------- /examples/ex_stat/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | struct stat istat; /* status for input file */ 7 | 8 | int name_too_long(char *name, struct stat *statb) 9 | { 10 | int s = strlen(name); 11 | printf("strlen done %i\n", s); 12 | 13 | char c = name[s - 1]; 14 | struct stat tstat; /* stat for truncated name */ 15 | int res; 16 | 17 | name[s - 1] = 'a'; 18 | 19 | puts("before lstat"); 20 | res = lstat(name, &tstat) == 0; 21 | puts("before same file"); 22 | name[s - 1] = c; 23 | if(res) 24 | { 25 | puts("checking same file"); 26 | return statb->st_ino == tstat.st_ino && statb->st_dev == tstat.st_dev; 27 | } 28 | return res; 29 | } 30 | 31 | int main() 32 | { 33 | char *name = malloc(5); 34 | strcpy(name, "ex.c"); 35 | lstat(name, &istat); 36 | fprintf(stdout, "File %s has %i \n", "ex.c", istat.st_mode); 37 | printf("%i \n", name_too_long(name, &istat)); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /examples/ex_static_lib/.gitignore: -------------------------------------------------------------------------------- 1 | libmsg-tmp 2 | -------------------------------------------------------------------------------- /examples/ex_static_lib/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | AR=ar 3 | CFLAGS= 4 | EXEC= 5 | 6 | LIBMSG_SRC=msg_one.c msg_two.c msg_three.c msg_four_with_a_long_name.c 7 | LIBMSG_OBJ=$(patsubst %.c, %.o, $(LIBMSG_SRC)) 8 | 9 | .PHONY: all check clean 10 | 11 | all: out.txt 12 | 13 | out.txt: ex 14 | @ $(EXEC) ./ex > $@ 15 | 16 | ex: ex.o libmsg.a 17 | $(CC) $(CFLAGS) -o $@ $^ 18 | 19 | libmsg.a: $(LIBMSG_OBJ) 20 | $(AR) -rcs $@ $^ 21 | 22 | %.o: %.c 23 | $(CC) $(CFLAGS) -c -o $@ $^ 24 | 25 | clean: 26 | rm -f ex out.txt libmsg.a ex.o $(LIBMSG_OBJ) 27 | rm -fr ex.unstripped *.s libmsg-tmp 28 | 29 | check: 30 | @ $(EXEC) ./ex >/tmp/res.txt 31 | @ diff out.txt /tmp/res.txt && echo TEST OK 32 | -------------------------------------------------------------------------------- /examples/ex_static_lib/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "libmsg.h" 5 | 6 | int main() 7 | { 8 | printf("%s\n", get_msg_one()); 9 | printf("%s\n", get_msg_two()); 10 | printf("%s\n", get_msg_three()); 11 | printf("%s\n", get_msg_four()); 12 | printf("%s\n", get_msg_five()); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /examples/ex_static_lib/libmsg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | char *get_msg_one(void); 3 | char *get_msg_two(void); 4 | char *get_msg_three(void); 5 | char *get_msg_four(void); 6 | char *get_msg_five(void); 7 | -------------------------------------------------------------------------------- /examples/ex_static_lib/msg_four_with_a_long_name.c: -------------------------------------------------------------------------------- 1 | #include "libmsg.h" 2 | // The name of this file is long to ensure we test an archive with an extended 3 | // name. 4 | 5 | char *get_msg_four(void) 6 | { 7 | return "four"; 8 | } 9 | -------------------------------------------------------------------------------- /examples/ex_static_lib/msg_one.c: -------------------------------------------------------------------------------- 1 | #include "libmsg.h" 2 | 3 | char *get_msg_one(void) 4 | { 5 | return "one"; 6 | } 7 | 8 | // Having a second function implemented here (with a second string) ensures 9 | // there is a string in the .rodata section that is *not* at the section start. 10 | char *get_msg_five(void) 11 | { 12 | return "five"; 13 | } 14 | -------------------------------------------------------------------------------- /examples/ex_static_lib/msg_three.c: -------------------------------------------------------------------------------- 1 | #include "libmsg.h" 2 | 3 | char *get_msg_three(void) 4 | { 5 | return "three"; 6 | } 7 | -------------------------------------------------------------------------------- /examples/ex_static_lib/msg_two.c: -------------------------------------------------------------------------------- 1 | #include "libmsg.h" 2 | 3 | char *get_msg_two(void) 4 | { 5 | return "two"; 6 | } 7 | -------------------------------------------------------------------------------- /examples/ex_static_lib_cfg/.gitignore: -------------------------------------------------------------------------------- 1 | libtest-tmp 2 | -------------------------------------------------------------------------------- /examples/ex_static_lib_cfg/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | AR=ar 3 | CFLAGS= 4 | EXEC= 5 | 6 | ifeq ($(CC),arm-linux-gnueabihf-gcc) 7 | LIB_ASM_SRC=foo_arm32.s 8 | endif 9 | ifeq ($(CC),aarch64-linux-gnu-gcc) 10 | LIB_ASM_SRC=foo_arm64.s 11 | endif 12 | ifeq ($(CC),gcc) 13 | ifneq (,(findstring -m32,$(CFLAGS))) 14 | LIB_ASM_SRC=foo_x64.s 15 | else 16 | LIB_ASM_SRC=foo_x86.s 17 | endif 18 | endif 19 | 20 | LIB_SRC=bar.c 21 | LIB_OBJ=$(patsubst %.c, %.o, $(LIB_SRC)) 22 | LIB_ASM_OBJ=$(patsubst %.s, %.o, $(LIB_ASM_SRC)) 23 | 24 | LIB_ASM_OBJ_ALL=foo_arm32.o foo_arm64.o foo_x64.o 25 | 26 | .PHONY: all check clean 27 | 28 | all: out.txt 29 | 30 | out.txt: ex 31 | @ $(EXEC) ./ex > $@ 32 | 33 | ex: ex.o libtest.a 34 | $(CC) $(CFLAGS) -o $@ $^ 35 | 36 | libtest.a: $(LIB_OBJ) $(LIB_ASM_OBJ) 37 | $(AR) -rcs $@ $^ 38 | 39 | %.o: %.c 40 | $(CC) $(CFLAGS) -c -o $@ $^ 41 | 42 | $(LIB_ASM_OBJ): $(LIB_ASM_SRC) 43 | $(CC) -c -o $@ $^ 44 | 45 | clean: 46 | rm -f ex out.txt libtest.a ex.o $(LIB_OBJ) $(LIB_ASM_OBJ_ALL) 47 | rm -fr ex.unstripped libtest-tmp libtest.gtirb 48 | 49 | check: ex 50 | @ $(EXEC) ./ex >/tmp/res.txt 51 | @ diff out.txt /tmp/res.txt && echo TEST OK 52 | -------------------------------------------------------------------------------- /examples/ex_static_lib_cfg/bar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "test.h" 4 | 5 | int bar(int n) 6 | { 7 | printf("bar: %d\n", n); 8 | return n + 20; 9 | } 10 | -------------------------------------------------------------------------------- /examples/ex_static_lib_cfg/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "test.h" 5 | 6 | int main() 7 | { 8 | printf("%d\n", foo(7)); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /examples/ex_static_lib_cfg/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "test.h" 4 | 5 | int foo(int n) 6 | { 7 | printf("foo: %d\n", n); 8 | return bar(n); 9 | } 10 | -------------------------------------------------------------------------------- /examples/ex_static_lib_cfg/foo_arm32.s: -------------------------------------------------------------------------------- 1 | .arch armv7-a 2 | .eabi_attribute 28, 1 3 | .eabi_attribute 20, 1 4 | .eabi_attribute 21, 1 5 | .eabi_attribute 23, 3 6 | .eabi_attribute 24, 1 7 | .eabi_attribute 25, 1 8 | .eabi_attribute 26, 2 9 | .eabi_attribute 30, 2 10 | .eabi_attribute 34, 1 11 | .eabi_attribute 18, 4 12 | .file "foo.c" 13 | .text 14 | .section .rodata.str1.4,"aMS",%progbits,1 15 | .align 2 16 | .LC0: 17 | .ascii "foo: %d\012\000" 18 | .text 19 | .align 1 20 | .p2align 2,,3 21 | .global foo 22 | .arch armv7-a 23 | .syntax unified 24 | .thumb 25 | .thumb_func 26 | .fpu vfpv3-d16 27 | .type foo, %function 28 | foo: 29 | @ args = 0, pretend = 0, frame = 0 30 | @ frame_needed = 0, uses_anonymous_args = 0 31 | ldr r1, .L4 32 | push {r4, lr} 33 | mov r4, r0 34 | mov r2, r4 35 | .LPIC0: 36 | add r1, pc 37 | movs r0, #1 38 | bl __printf_chk(PLT) 39 | jmp_block: 40 | mov r0, r4 41 | pop {r4, lr} 42 | b bar(PLT) 43 | .L5: 44 | .align 2 45 | .L4: 46 | .word .LC0-(.LPIC0+4) 47 | .size foo, .-foo 48 | .ident "GCC: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0" 49 | .section .note.GNU-stack,"",%progbits 50 | -------------------------------------------------------------------------------- /examples/ex_static_lib_cfg/foo_arm64.s: -------------------------------------------------------------------------------- 1 | .arch armv8-a 2 | .file "foo.c" 3 | .text 4 | .section .rodata.str1.8,"aMS",@progbits,1 5 | .align 3 6 | .LC0: 7 | .string "foo: %d\n" 8 | .text 9 | .align 2 10 | .p2align 3,,7 11 | .global foo 12 | .type foo, %function 13 | foo: 14 | .LFB23: 15 | .cfi_startproc 16 | stp x29, x30, [sp, -32]! 17 | .cfi_def_cfa_offset 32 18 | .cfi_offset 29, -32 19 | .cfi_offset 30, -24 20 | mov w2, w0 21 | adrp x1, .LC0 22 | mov x29, sp 23 | add x1, x1, :lo12:.LC0 24 | str x19, [sp, 16] 25 | .cfi_offset 19, -16 26 | mov w19, w0 27 | mov w0, 1 28 | bl __printf_chk 29 | jmp_block: 30 | mov w0, w19 31 | ldr x19, [sp, 16] 32 | ldp x29, x30, [sp], 32 33 | .cfi_restore 30 34 | .cfi_restore 29 35 | .cfi_restore 19 36 | .cfi_def_cfa_offset 0 37 | b bar 38 | .cfi_endproc 39 | .LFE23: 40 | .size foo, .-foo 41 | .ident "GCC: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0" 42 | .section .note.GNU-stack,"",@progbits 43 | -------------------------------------------------------------------------------- /examples/ex_static_lib_cfg/foo_x64.s: -------------------------------------------------------------------------------- 1 | .file "foo.c" 2 | .text 3 | .section .rodata.str1.1,"aMS",@progbits,1 4 | .LC0: 5 | .string "foo: %d\n" 6 | .text 7 | .p2align 4 8 | .globl foo 9 | .type foo, @function 10 | foo: 11 | .LFB23: 12 | .cfi_startproc 13 | endbr64 14 | pushq %rbp 15 | .cfi_def_cfa_offset 16 16 | .cfi_offset 6, -16 17 | movl %edi, %edx 18 | movl %edi, %ebp 19 | leaq .LC0(%rip), %rsi 20 | movl $1, %edi 21 | xorl %eax, %eax 22 | call __printf_chk@PLT 23 | jmp_block: 24 | movl %ebp, %edi 25 | popq %rbp 26 | .cfi_def_cfa_offset 8 27 | jmp bar@PLT 28 | .cfi_endproc 29 | .LFE23: 30 | .size foo, .-foo 31 | .ident "GCC: (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0" 32 | .section .note.GNU-stack,"",@progbits 33 | .section .note.gnu.property,"a" 34 | .align 8 35 | .long 1f - 0f 36 | .long 4f - 1f 37 | .long 5 38 | 0: 39 | .string "GNU" 40 | 1: 41 | .align 8 42 | .long 0xc0000002 43 | .long 3f - 2f 44 | 2: 45 | .long 0x3 46 | 3: 47 | .align 8 48 | 4: 49 | -------------------------------------------------------------------------------- /examples/ex_static_lib_cfg/test.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | int foo(int); 3 | int bar(int); 4 | -------------------------------------------------------------------------------- /examples/ex_struct/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | clean: 9 | rm -f ex out.txt 10 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 11 | check: 12 | @ $(EXEC) ./ex >/tmp/res.txt 13 | @ diff out.txt /tmp/res.txt && echo TEST OK 14 | -------------------------------------------------------------------------------- /examples/ex_struct/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS="/Fa" 2 | 3 | all: ex.c 4 | cl /nologo $(CFLAGS) ex.c 5 | @ ex > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 8 | check: 9 | @ ex >check.txt 10 | @ FC out.txt check.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_switch/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | clean: 9 | rm -f ex out.txt 10 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 11 | check: 12 | @ $(EXEC) ./ex >/tmp/res.txt 13 | @ diff out.txt /tmp/res.txt && echo TEST OK 14 | -------------------------------------------------------------------------------- /examples/ex_switch/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS="/Fa" 2 | 3 | all: ex.c 4 | cl /nologo $(CFLAGS) ex.c 5 | @ ex > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.asm out.txt check.txt mllink$$.lnk 8 | del /F /Q ex.unstripped *.s *.old* 9 | if exist dl_files { rmdir /Q /S dl_files } 10 | check: 11 | @ ex >check.txt 12 | @ FC out.txt check.txt && echo TEST OK 13 | -------------------------------------------------------------------------------- /examples/ex_switch/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int one(int a) 5 | { 6 | puts("one"); 7 | return a; 8 | } 9 | int two(int a) 10 | { 11 | puts("two"); 12 | return a; 13 | } 14 | int three(int a) 15 | { 16 | puts("three"); 17 | return a + 1; 18 | } 19 | int four(int a) 20 | { 21 | puts("four"); 22 | return a; 23 | } 24 | int def(int a) 25 | { 26 | puts("last"); 27 | return a; 28 | } 29 | 30 | void fun(int a, int b) 31 | { 32 | while(a < b) 33 | { 34 | switch(a) 35 | { 36 | case 1: 37 | one(a); 38 | break; 39 | case 2: 40 | two(a); 41 | break; 42 | case 3: 43 | three(a); 44 | break; 45 | case 4: 46 | four(a); 47 | break; 48 | default: 49 | def(a); 50 | } 51 | ++a; 52 | } 53 | } 54 | int main() 55 | { 56 | puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */ 57 | fun(1, 6); 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /examples/ex_symbol_selection/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | 4 | all: ex.c bar.c data.c fun.c 5 | # Put bar.c first to make the `my_strings` defined in bar.c be the first 6 | # symbol in the symbol set with the same name. 7 | $(CC) bar.c data.c fun.c -shared $(CFLAGS) -fPIC -o fun.so 8 | $(CC) ex.c $(CFLAGS) fun.so -o ex 9 | @LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./ex > out.txt 10 | clean: 11 | rm -f ex fun.so out.txt 12 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 13 | check: 14 | @LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./ex >/tmp/res.txt 15 | @ diff out.txt /tmp/res.txt && echo TEST OK 16 | -------------------------------------------------------------------------------- /examples/ex_symbol_selection/bar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static const char* my_strings[] = {"hello four", "hello five", "hello six"}; 4 | 5 | void bar() 6 | { 7 | int i = 0; 8 | for(; i < 3; i++) 9 | { 10 | printf("bar: %d: %s\n", i, my_strings[i]); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/ex_symbol_selection/data.c: -------------------------------------------------------------------------------- 1 | const char* my_strings[] = {"hello one", "hello two", "hello three"}; 2 | -------------------------------------------------------------------------------- /examples/ex_symbol_selection/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "fun.h" 5 | 6 | int main() 7 | { 8 | bar(); 9 | fun(); 10 | puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */ 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /examples/ex_symbol_selection/fun.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // This example is to check if ddisasm chooses right symbols for GOT entries. 4 | // data.c defines a global array `my_strings` (GLOBAL), which this function 5 | // `fun` refers to. 6 | // Also, bar.c defines a static array with the same name (LOCAL). 7 | // 8 | // Symbols with same name are disambiguated: the global symbol keeps the 9 | // original name, and the other local symbol(s) are suffixed with _disamb_. 10 | // 11 | // Ddisasm should choose GLOBAL symbols over disambiguated local symbols 12 | // for GOT entries. 13 | 14 | extern const char* my_strings[]; 15 | 16 | void fun() 17 | { 18 | int i = 0; 19 | for(i = 0; i < 3; i++) 20 | { 21 | printf("fun: %d: %s\n", i, my_strings[i]); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/ex_symbol_selection/fun.h: -------------------------------------------------------------------------------- 1 | void bar(); 2 | void fun(); 3 | -------------------------------------------------------------------------------- /examples/ex_symver/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | 4 | all: ex.c ex2.c ex3.c foo.c 5 | $(CC) bar.c -o libbar.so -shared $(CFLAGS) -fPIC -Wl,--version-script=libbar.map 6 | $(CC) foo.c libbar.so -o libfoo.so -shared $(CFLAGS) -fPIC -Wl,--version-script=libfoo.map 7 | $(CC) ex.c $(CFLAGS) libfoo.so libbar.so -o ex 8 | $(CC) ex2.c $(CFLAGS) libfoo.so libbar.so -o ex2 9 | $(CC) ex3.c $(CFLAGS) libfoo.so libbar.so -o ex3 10 | @LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./ex > out.txt 11 | @LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./ex2 >> out.txt 12 | @LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./ex3 >> out.txt 13 | clean: 14 | rm -f ex ex2 ex3 libfoo.so libbar.so *.s *.gtirb out.txt 15 | check: 16 | @LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./ex >/tmp/res.txt 17 | @LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./ex2 >> /tmp/res.txt 18 | @LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./ex3 >> /tmp/res.txt 19 | @ diff out.txt /tmp/res.txt && echo TEST OK 20 | -------------------------------------------------------------------------------- /examples/ex_symver/bar.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | __asm__(".symver bar1,bar@LIBBAR_1.0"); 6 | void bar1() 7 | { 8 | puts("bar 1"); 9 | } 10 | 11 | __asm__(".symver bar2,bar@@LIBBAR_2.0"); 12 | void bar2() 13 | { 14 | puts("bar 2"); 15 | } 16 | -------------------------------------------------------------------------------- /examples/ex_symver/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "foo.h" 5 | 6 | __asm__(".symver foo,foo@LIBFOO_1.0"); 7 | 8 | int main() 9 | { 10 | foo(); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /examples/ex_symver/ex2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "foo.h" 5 | 6 | __asm__(".symver foo,foo@LIBFOO_2.0"); 7 | 8 | int main() 9 | { 10 | foo(); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /examples/ex_symver/ex3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "foo.h" 5 | 6 | __asm__(".symver foo,foo@LIBFOO_3.0"); 7 | 8 | int main() 9 | { 10 | foo(); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /examples/ex_symver/foo.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | __asm__(".symver bar,bar@LIBBAR_1.0"); 4 | __asm__(".symver bar2,bar@LIBBAR_2.0"); 5 | 6 | void bar(); 7 | void bar2(); 8 | 9 | __asm__(".symver foo1,foo@LIBFOO_1.0"); 10 | void foo1() 11 | { 12 | puts("foo 1.0"); 13 | bar(); 14 | } 15 | 16 | __asm__(".symver foo2,foo@LIBFOO_2.0"); 17 | 18 | void foo2() 19 | { 20 | puts("foo 2.0"); 21 | bar2(); 22 | } 23 | 24 | __asm__(".symver foo3,foo@@LIBFOO_3.0"); 25 | void foo3() 26 | { 27 | puts("foo 3.0"); 28 | bar2(); 29 | } 30 | -------------------------------------------------------------------------------- /examples/ex_symver/foo.h: -------------------------------------------------------------------------------- 1 | void foo(); 2 | void bar(); 3 | -------------------------------------------------------------------------------- /examples/ex_symver/libbar.map: -------------------------------------------------------------------------------- 1 | LIBBAR_1.0 { 2 | global: 3 | bar; 4 | local: 5 | *; 6 | }; 7 | 8 | LIBBAR_2.0 { 9 | global: 10 | bar; 11 | } LIBBAR_1.0; 12 | -------------------------------------------------------------------------------- /examples/ex_symver/libfoo.map: -------------------------------------------------------------------------------- 1 | LIBFOO_1.0 { 2 | global: 3 | foo; 4 | local: 5 | *; 6 | }; 7 | 8 | LIBFOO_2.0 { 9 | global: 10 | foo; 11 | } LIBFOO_1.0; 12 | 13 | 14 | LIBFOO_3.0 { 15 | global: 16 | foo; 17 | } LIBFOO_2.0; 18 | 19 | 20 | LIBBAR_1.0 { 21 | }; 22 | 23 | LIBBAR_2.0 { 24 | } LIBBAR_1.0; 25 | -------------------------------------------------------------------------------- /examples/ex_synchronous_access/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | clean: 9 | rm -f ex ex.unstripped out.txt *.s *.lib *.exp *.o *.err 10 | check: 11 | @ $(EXEC) ./ex >/tmp/res.txt 12 | @ diff out.txt /tmp/res.txt && echo TEST OK 13 | -------------------------------------------------------------------------------- /examples/ex_synchronous_access/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef struct 4 | { 5 | int f1; 6 | int f2; 7 | } A; 8 | 9 | A array[10]; 10 | 11 | int main() 12 | { 13 | int i; 14 | 15 | for(i = 0; i < 10; ++i) 16 | { 17 | array[i].f1 = i; 18 | } 19 | array[0].f2 = 10; 20 | for(i = 1; i < 10; ++i) 21 | { 22 | array[i].f2 = i + 10; 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /examples/ex_thread_local/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | clean: 9 | rm -f ex out.txt 10 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 11 | check: 12 | @ $(EXEC) ./ex >/tmp/res.txt 13 | @ diff out.txt /tmp/res.txt && echo TEST OK 14 | -------------------------------------------------------------------------------- /examples/ex_thread_local/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Initialized thread-local object (.tdata): 4 | __thread int i = 4; 5 | 6 | // Uninitialized thread-local object (.tbss): 7 | __thread int j; 8 | 9 | __thread long k = 10; 10 | 11 | __thread int l; 12 | 13 | int main() 14 | { 15 | i++; 16 | printf("%d\n", i); 17 | j++; 18 | printf("%d\n", j); 19 | k++; 20 | printf("%ld\n", k); 21 | l++; 22 | printf("%d\n", l); 23 | } 24 | -------------------------------------------------------------------------------- /examples/ex_threads/Makefile: -------------------------------------------------------------------------------- 1 | CXX="g++" 2 | all: ex.cpp 3 | $(CXX) ex.cpp $(CXXFLAGS) -std=c++11 -lpthread -o ex 4 | ./ex > out.txt 5 | clean: 6 | rm -f ex out.txt 7 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 8 | check: 9 | ./ex >/tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_threads/ex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | thread_local int threadLocal = 0; 5 | 6 | void foo() 7 | { 8 | std::cout << "foo " << threadLocal << std::endl; 9 | threadLocal++; 10 | } 11 | 12 | void bar(int x) 13 | { 14 | std::cout << "bar " << threadLocal << std::endl; 15 | threadLocal++; 16 | } 17 | 18 | int main() 19 | { 20 | std::cout << "foo and bar will be executed\n"; 21 | std::thread first(foo); 22 | first.join(); 23 | std::thread second(bar, 0); 24 | second.join(); 25 | std::cout << "foo and bar completed.\n"; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /examples/ex_uninitialized_data/Makefile: -------------------------------------------------------------------------------- 1 | CC="gcc" 2 | CFLAGS= 3 | EXEC= 4 | 5 | all: ex.c 6 | $(CC) ex.c $(CFLAGS) -o ex 7 | @ $(EXEC) ./ex > out.txt 8 | clean: 9 | rm -f ex out.txt 10 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 11 | check: 12 | @ $(EXEC) ./ex >/tmp/res.txt 13 | @ diff out.txt /tmp/res.txt && echo TEST OK 14 | -------------------------------------------------------------------------------- /examples/ex_uninitialized_data/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS="/Fa" 2 | 3 | all: ex.c 4 | cl /nologo $(CFLAGS) ex.c 5 | @ ex > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 8 | check: 9 | @ ex >check.txt 10 | @ FC out.txt check.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_uninitialized_data/ex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int array[1000]; 5 | 6 | void init() 7 | { 8 | for(int i = 0; i < 10; ++i) 9 | array[i] = i; 10 | } 11 | 12 | void print() 13 | { 14 | for(int i = 0; i < 10; ++i) 15 | printf("%i\n", array[i]); 16 | } 17 | 18 | int main() 19 | { 20 | puts("Storing data"); 21 | init(); 22 | puts("Printing data"); 23 | print(); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /examples/ex_virtualDispatch/Makefile: -------------------------------------------------------------------------------- 1 | CXX="g++" 2 | EXEC= 3 | 4 | all: ex.cpp 5 | $(CXX) ex.cpp $(CXXFLAGS) -o ex 6 | @ $(EXEC) ./ex > out.txt 7 | clean: 8 | rm -f ex out.txt 9 | rm -fr ex.unstripped *.s *.old* dl_files *.gtirb 10 | check: 11 | @ $(EXEC) ./ex >/tmp/res.txt 12 | @ diff out.txt /tmp/res.txt && echo TEST OK 13 | -------------------------------------------------------------------------------- /examples/ex_virtualDispatch/Makefile.windows: -------------------------------------------------------------------------------- 1 | CFLAGS="/Fa" 2 | 3 | all: ex.cpp 4 | cl /nologo $(CFLAGS) ex.cpp 5 | @ ex > out.txt 6 | clean: 7 | del /F /Q *.exe *.obj *.exp *.def *.lib *.s out.txt check.txt mllink$$.lnk 8 | check: 9 | @ ex >check.txt 10 | @ FC out.txt check.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/ex_virtualDispatch/ex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | class a 5 | { 6 | public: 7 | virtual void print() = 0; 8 | }; 9 | 10 | class a1 : public a 11 | { 12 | public: 13 | virtual void print(); 14 | }; 15 | 16 | class a2 : public a 17 | { 18 | public: 19 | virtual void print(); 20 | }; 21 | 22 | void a1::print() 23 | { 24 | puts("A1"); 25 | } 26 | 27 | void a2::print() 28 | { 29 | puts("A2"); 30 | } 31 | 32 | int main() 33 | { 34 | a1 a1; 35 | a2 a2; 36 | 37 | a* a = &a1; 38 | a->print(); 39 | a = &a2; 40 | a->print(); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /examples/mips_asm_examples/ex_got_ofst/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-mips -L /usr/mips-linux-gnu $^ 2 > $@ 4 | ex: ex_original.s 5 | mips-linux-gnu-gcc -no-pie -o $@ $^ -lm 6 | clean: 7 | rm -f ex out.txt ex.gtirb 8 | check: ex 9 | qemu-mips -L /usr/mips-linux-gnu $^ 2 > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/mips_asm_examples/ex_nop_block/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean check 2 | out.txt: ex 3 | @qemu-mips -L /usr/mips-linux-gnu $^ 2 > $@ 4 | ex: ex_original.s 5 | mips-linux-gnu-gcc -no-pie -o $@ $^ -lm 6 | clean: 7 | rm -f ex out.txt ex.gtirb 8 | check: ex 9 | qemu-mips -L /usr/mips-linux-gnu $^ 2 > /tmp/res.txt 10 | @ diff out.txt /tmp/res.txt && echo TEST OK 11 | -------------------------------------------------------------------------------- /examples/trace_examples/tbdisasm_a_20200713.gtirb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GrammaTech/ddisasm/5a8779f427ddfecd085f5bfd86c3a2006251ef8d/examples/trace_examples/tbdisasm_a_20200713.gtirb -------------------------------------------------------------------------------- /examples/x86_32_asm_examples/ex_got_relative/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean check 2 | all: out.txt 3 | 4 | out.txt: ex 5 | @./$^ > $@ 6 | ex: src.s 7 | gcc $^ -pie -m32 -o $@ 8 | 9 | clean: 10 | rm -f ex out.txt 11 | rm -fr ex.unstripped ex.s *.old* dl_files *.gtirb 12 | check: 13 | ./ex > /tmp/res.txt 14 | @ diff out.txt /tmp/res.txt && echo TEST OK 15 | -------------------------------------------------------------------------------- /examples/x86_32_asm_examples/ex_stack_value_reg/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all clean check 2 | all: out.txt 3 | 4 | out.txt: ex 5 | @./$^ > $@ 6 | ex: src.s 7 | gcc $^ -pie -m32 -o $@ 8 | 9 | clean: 10 | rm -f ex out.txt 11 | check: 12 | ./ex > /tmp/res.txt 13 | @ diff out.txt /tmp/res.txt && echo TEST OK 14 | -------------------------------------------------------------------------------- /python/src/ddisasm/__init__.py: -------------------------------------------------------------------------------- 1 | import importlib.resources as native_importlib_resources 2 | import pathlib 3 | import platform 4 | from contextlib import contextmanager 5 | from typing import Iterator 6 | 7 | from .version import __version__ 8 | 9 | if hasattr(native_importlib_resources, "files"): 10 | importlib_resources = native_importlib_resources 11 | else: 12 | import importlib_resources # type: ignore 13 | 14 | 15 | __all__ = ["ddisasm_path", "__version__"] 16 | 17 | 18 | @contextmanager 19 | def ddisasm_path() -> Iterator[pathlib.Path]: 20 | """ 21 | Retrieves the path on disk to the ddisasm executable. 22 | """ 23 | 24 | if platform.system() == "Windows": 25 | executable_name = "ddisasm.exe" 26 | else: 27 | executable_name = "ddisasm" 28 | 29 | template_path = importlib_resources.files(__package__) / executable_name 30 | with importlib_resources.as_file(template_path) as actual_path: 31 | yield actual_path 32 | -------------------------------------------------------------------------------- /python/src/ddisasm/__main__.py: -------------------------------------------------------------------------------- 1 | from ddisasm import ddisasm_path 2 | import subprocess 3 | import sys 4 | 5 | 6 | def _main(): 7 | with ddisasm_path() as tool_path: 8 | ret = subprocess.run( 9 | sys.argv, check=False, close_fds=False, executable=tool_path 10 | ) 11 | sys.exit(ret.returncode) 12 | 13 | 14 | if __name__ == "__main__": 15 | _main() 16 | -------------------------------------------------------------------------------- /python/src/ddisasm/py.typed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GrammaTech/ddisasm/5a8779f427ddfecd085f5bfd86c3a2006251ef8d/python/src/ddisasm/py.typed -------------------------------------------------------------------------------- /python/version.py.in: -------------------------------------------------------------------------------- 1 | __version__ = ( 2 | "@PROJECT_VERSION_MAJOR@." 3 | "@PROJECT_VERSION_MINOR@." 4 | "@PROJECT_VERSION_PATCH@" 5 | "@DDISASM_PYTHON_DEV_SUFFIX@" 6 | ) 7 | -------------------------------------------------------------------------------- /requirements-dev.txt: -------------------------------------------------------------------------------- 1 | capstone-gt 2 | gtirb 3 | gtirb-capstone 4 | lief==0.16.6 5 | -------------------------------------------------------------------------------- /src/Endian.h: -------------------------------------------------------------------------------- 1 | #ifndef SRC_GTIRB_DECODER_ENDIAN_H_ 2 | #define SRC_GTIRB_DECODER_ENDIAN_H_ 3 | 4 | #ifdef _WIN32 5 | #include 6 | #endif // _WIN32 7 | 8 | #if defined(_WIN32) || defined(__APPLE__) 9 | #if defined(_MSC_VER) 10 | 11 | #define be16toh(x) _byteswap_ushort(x) 12 | #define le16toh(x) (x) 13 | 14 | #define be32toh(x) _byteswap_ulong(x) 15 | #define le32toh(x) (x) 16 | 17 | #define be64toh(x) _byteswap_uint64(x) 18 | #define le64toh(x) (x) 19 | 20 | #elif defined(__GNUC__) || defined(__clang__) 21 | 22 | #define be16toh(x) __builtin_bswap16(x) 23 | #define le16toh(x) (x) 24 | 25 | #define be32toh(x) __builtin_bswap32(x) 26 | #define le32toh(x) (x) 27 | 28 | #define be64toh(x) __builtin_bswap64(x) 29 | #define le64toh(x) (x) 30 | 31 | #endif // _MSC_VER 32 | #endif // defined(_WIN32) || defined(__APPLE__) 33 | 34 | #endif // SRC_GTIRB_DECODER_ENDIAN_H_ 35 | -------------------------------------------------------------------------------- /src/datalog/printable_chars.dl: -------------------------------------------------------------------------------- 1 | //===- printable_chars.dl -----------------------------------*- datalog -*-===// 2 | // 3 | // Copyright (C) 2019 GrammaTech, Inc. 4 | // 5 | // This code is licensed under the GNU Affero General Public License 6 | // as published by the Free Software Foundation, either version 3 of 7 | // the License, or (at your option) any later version. See the 8 | // LICENSE.txt file in the project root for license terms or visit 9 | // https://www.gnu.org/licenses/agpl.txt. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU Affero General Public License for more details. 15 | // 16 | // This project is sponsored by the Office of Naval Research, One Liberty 17 | // Center, 875 N. Randolph Street, Arlington, VA 22203 under contract # 18 | // N68335-17-C-0700. The content of the information does not necessarily 19 | // reflect the position or policy of the Government and no official 20 | // endorsement should be inferred. 21 | // 22 | //===----------------------------------------------------------------------===// 23 | /* 24 | The set of printable ascii characters. 25 | */ 26 | -------------------------------------------------------------------------------- /src/tests/Functors.Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | #include "../Functors.h" 7 | 8 | TEST(Thumb32BranchOffsetTest, read_branch_offset) 9 | { 10 | // 00000030
: 11 | // 30: b580 push {r7, lr} 12 | // 32: af00 add r7, sp, #0 13 | // 34: 2114 movs r1, #20 14 | // 36: 200a movs r0, #10 15 | // 38: f7ff fffe bl 0 16 | // ____ ____ 17 | // │ └── lower instruction 18 | // └── upper instruction 19 | // 20 | EXPECT_EQ(functor_thumb32_branch_offset(0xfffef7ff), -4); 21 | } 22 | -------------------------------------------------------------------------------- /src/tests/RawReader.Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../gtirb-builder/ElfReader.h" 8 | #include "../gtirb-builder/GtirbBuilder.h" 9 | 10 | using GTIRB = GtirbBuilder::GTIRB; 11 | 12 | TEST(RawReaderTest, read_gtirb) 13 | { 14 | { 15 | // Read binary to GTIRB. 16 | gtirb::ErrorOr GTIRB = GtirbBuilder::read("inputs/hello.x64.elf"); 17 | EXPECT_TRUE(GTIRB); 18 | 19 | // Save GTIRB to file. 20 | std::ofstream Stream("inputs/hello.gtirb", std::ios::out | std::ios::binary); 21 | GTIRB->IR->save(Stream); 22 | } 23 | { 24 | // Read GTIRB. 25 | gtirb::ErrorOr GTIRB = GtirbBuilder::read("inputs/hello.gtirb"); 26 | EXPECT_TRUE(GTIRB); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/tests/inputs/ar/basic.a: -------------------------------------------------------------------------------- 1 | ! 2 | file1/ 1641933455 1000 100 100644 9 ` 3 | contents1 4 | file2/ 1641933455 1000 100 100644 9 ` 5 | contents2 -------------------------------------------------------------------------------- /src/tests/inputs/ar/bsd.a: -------------------------------------------------------------------------------- 1 | ! 2 | #1/24 1641933455 1000 1000 100644 24 ` 3 | long_archive_member_namefile 1641933455 1000 1000 100644 0 ` 4 | -------------------------------------------------------------------------------- /src/tests/inputs/ar/empty.a: -------------------------------------------------------------------------------- 1 | ! 2 | -------------------------------------------------------------------------------- /src/tests/inputs/ar/gnu.a: -------------------------------------------------------------------------------- 1 | ! 2 | // 53 ` 3 | long_archive_member_name/ 4 | other_archive_member_name/ 5 | 6 | /0 1641933455 1000 1000 100644 0 ` 7 | file/ 1641933455 1000 1000 100644 0 ` 8 | /26 1641933455 1000 1000 100644 0 ` -------------------------------------------------------------------------------- /src/tests/inputs/hello.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) 4 | { 5 | std::cout << "hello world" << std::endl; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /src/tests/inputs/hello.x64.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GrammaTech/ddisasm/5a8779f427ddfecd085f5bfd86c3a2006251ef8d/src/tests/inputs/hello.x64.elf -------------------------------------------------------------------------------- /src/tests/inputs/man: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GrammaTech/ddisasm/5a8779f427ddfecd085f5bfd86c3a2006251ef8d/src/tests/inputs/man -------------------------------------------------------------------------------- /version.txt: -------------------------------------------------------------------------------- 1 | VERSION_MAJOR 1 2 | VERSION_MINOR 9 3 | VERSION_PATCH 2 4 | --------------------------------------------------------------------------------