├── .gitattributes ├── tests ├── ario │ ├── empty.a │ ├── libgcov.a │ ├── invalid_magic.a │ ├── simple_text.a │ └── long_name.a ├── elf_examples │ ├── asm │ ├── asm.o │ ├── asm64 │ ├── ctors │ ├── main │ ├── main32 │ ├── asm64.o │ ├── hello_32 │ ├── hello_64 │ ├── test_ppc │ ├── zavl.ko │ ├── crash.elf │ ├── entropy.so │ ├── hello_32.o │ ├── hello_64.o │ ├── hello_arm │ ├── hello_arm.o │ ├── libfunc.so │ ├── startup.eln │ ├── test_ppc.o │ ├── 64bitLOAD.elf │ ├── ARMSCII-8.so │ ├── libfunc32.so │ ├── x86_64_static │ ├── helloworld.rpx │ ├── libversion_d.so │ ├── startup_orig.eln │ ├── hello_arm_stripped │ ├── arm_v7m_test_debug.elf │ ├── elf_header_i386_32.elf │ ├── hello.c │ ├── mismatched_segments.elf │ ├── ppc-32bit-specimen3.elf │ ├── write_exe_i386_32_match │ ├── arm_v7m_test_release.elf │ ├── null_endianess_convertor │ ├── read_write_arm_elf32_input │ ├── write_obj_i386_32_match.o │ ├── write_obj_i386_64_match.o │ ├── test_ppc.cpp │ ├── crash-060833f08dc14d1712428742b3cad7af17b36bb7 │ ├── crash-7d695153fd8052529d480c2352d4ada33a44bada │ ├── crash-b82f05b0b25c8fdc98480e6d76b6d5f9164ae2bc │ ├── crash-e1ce7cecf01cf800397a4302854d9d76fa19763c │ ├── crash-e3c41070342cf84dea077356ddbb8ebf4326a601 │ ├── version_d.cpp │ ├── version_d.map │ ├── asm.s │ ├── asm.lst │ ├── asm64.lst │ ├── asm.readelf │ ├── write_exe_i386_32_work_dump.txt │ ├── hello_32_o.txt │ ├── hello_64_o.txt │ └── test_ppc_o.txt ├── runELFtests ├── elfio_fuzzer.cpp └── CMakeLists.txt ├── doc ├── elfio.docx ├── elfio.pdf ├── images │ ├── up.gif │ ├── up.png │ ├── blank.png │ ├── draft.png │ ├── home.gif │ ├── home.png │ ├── next.gif │ ├── next.png │ ├── note.gif │ ├── note.png │ ├── note.tif │ ├── prev.gif │ ├── prev.png │ ├── tip.gif │ ├── tip.png │ ├── tip.tif │ ├── caution.gif │ ├── caution.png │ ├── caution.tif │ ├── warning.gif │ ├── warning.png │ ├── warning.tif │ ├── annot-open.png │ ├── callouts │ │ ├── 1.gif │ │ ├── 1.png │ │ ├── 2.gif │ │ ├── 2.png │ │ ├── 3.gif │ │ ├── 3.png │ │ ├── 4.gif │ │ ├── 4.png │ │ ├── 5.gif │ │ ├── 5.png │ │ ├── 6.gif │ │ ├── 6.png │ │ ├── 7.gif │ │ ├── 7.png │ │ ├── 8.gif │ │ ├── 8.png │ │ ├── 9.gif │ │ ├── 9.png │ │ ├── 10.gif │ │ ├── 10.png │ │ ├── 11.gif │ │ ├── 11.png │ │ ├── 12.gif │ │ ├── 12.png │ │ ├── 13.gif │ │ ├── 13.png │ │ ├── 14.gif │ │ ├── 14.png │ │ ├── 15.gif │ │ ├── 15.png │ │ ├── 1.svg │ │ ├── 7.svg │ │ ├── 4.svg │ │ ├── 11.svg │ │ ├── 17.svg │ │ ├── 14.svg │ │ ├── 2.svg │ │ ├── 5.svg │ │ ├── 10.svg │ │ ├── 12.svg │ │ ├── 21.svg │ │ ├── 3.svg │ │ ├── 9.svg │ │ ├── 15.svg │ │ ├── 27.svg │ │ ├── 6.svg │ │ ├── 24.svg │ │ ├── 13.svg │ │ ├── 19.svg │ │ ├── 8.svg │ │ ├── 16.svg │ │ ├── 20.svg │ │ ├── 22.svg │ │ ├── 25.svg │ │ ├── 18.svg │ │ ├── 30.svg │ │ ├── 23.svg │ │ ├── 29.svg │ │ ├── 26.svg │ │ └── 28.svg │ ├── important.gif │ ├── important.png │ ├── important.tif │ ├── res │ │ ├── title.png │ │ └── 20231119165006-100.png │ ├── toc-blank.png │ ├── toc-minus.png │ ├── toc-plus.png │ ├── annot-close.png │ ├── res2 │ │ ├── iceland.jpeg │ │ ├── 20231119095119.jpg │ │ ├── 20231119095351.jpg │ │ ├── 20231119095425.jpg │ │ ├── 20231119095558.jpg │ │ ├── 20231119095613.jpg │ │ ├── 20231119095721.jpg │ │ ├── 20231119095920.jpg │ │ ├── 20231119095932.jpg │ │ ├── 20231119095944.jpg │ │ ├── 20231119100133.jpg │ │ ├── 20231119100142.jpg │ │ ├── 20231119165006.jpg │ │ ├── 20231119165016.jpg │ │ ├── 20231119165024.jpg │ │ ├── 20231119165842.jpg │ │ ├── 20231119165851.jpg │ │ ├── 20231119165907.jpg │ │ ├── 20231119165912.jpg │ │ ├── 20231119165006-1.jpg │ │ └── 20231119165006-256.png │ ├── up.svg │ ├── next.svg │ ├── prev.svg │ ├── warning.svg │ ├── caution.svg │ ├── important.svg │ ├── note.svg │ ├── home.svg │ └── tip.svg └── site │ ├── style.css │ └── index.htm ├── examples ├── arion │ ├── CMakeLists.txt │ └── arion.cpp ├── writer │ ├── CMakeLists.txt │ └── writer.cpp ├── elfdump │ ├── CMakeLists.txt │ └── elfdump.cpp ├── proc_mem │ ├── CMakeLists.txt │ └── proc_mem.cpp ├── tutorial │ ├── CMakeLists.txt │ └── tutorial.cpp ├── arioso │ └── CMakeLists.txt ├── elfio_ldd │ ├── CMakeLists.txt │ └── elfio_ldd.cpp ├── write_obj │ ├── CMakeLists.txt │ └── write_obj.cpp ├── add_section │ ├── CMakeLists.txt │ └── add_section.cpp ├── anonymizer │ ├── CMakeLists.txt │ └── anonymizer.cpp ├── c_wrapper │ └── CMakeLists.txt ├── sudo_gdb.sh └── CMakeLists.txt ├── cmake └── elfioConfig.cmake.in ├── elfio ├── elfio_version.hpp ├── elfio_array.hpp ├── elfio_strings.hpp ├── elfio_modinfo.hpp └── elfio_header.hpp ├── .vscode ├── c_cpp_properties.json ├── tasks.json ├── settings.json └── launch.json ├── LICENSE.txt ├── .clang-format ├── .gitignore ├── .github └── workflows │ ├── codeql-analysis.yml │ └── c-cpp.yml ├── CMakeLists.txt └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | *.a binary 2 | -------------------------------------------------------------------------------- /tests/ario/empty.a: -------------------------------------------------------------------------------- 1 | ! 2 | -------------------------------------------------------------------------------- /doc/elfio.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/elfio.docx -------------------------------------------------------------------------------- /doc/elfio.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/elfio.pdf -------------------------------------------------------------------------------- /doc/images/up.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/up.gif -------------------------------------------------------------------------------- /doc/images/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/up.png -------------------------------------------------------------------------------- /doc/images/blank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/blank.png -------------------------------------------------------------------------------- /doc/images/draft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/draft.png -------------------------------------------------------------------------------- /doc/images/home.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/home.gif -------------------------------------------------------------------------------- /doc/images/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/home.png -------------------------------------------------------------------------------- /doc/images/next.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/next.gif -------------------------------------------------------------------------------- /doc/images/next.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/next.png -------------------------------------------------------------------------------- /doc/images/note.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/note.gif -------------------------------------------------------------------------------- /doc/images/note.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/note.png -------------------------------------------------------------------------------- /doc/images/note.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/note.tif -------------------------------------------------------------------------------- /doc/images/prev.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/prev.gif -------------------------------------------------------------------------------- /doc/images/prev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/prev.png -------------------------------------------------------------------------------- /doc/images/tip.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/tip.gif -------------------------------------------------------------------------------- /doc/images/tip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/tip.png -------------------------------------------------------------------------------- /doc/images/tip.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/tip.tif -------------------------------------------------------------------------------- /tests/ario/libgcov.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/ario/libgcov.a -------------------------------------------------------------------------------- /doc/images/caution.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/caution.gif -------------------------------------------------------------------------------- /doc/images/caution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/caution.png -------------------------------------------------------------------------------- /doc/images/caution.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/caution.tif -------------------------------------------------------------------------------- /doc/images/warning.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/warning.gif -------------------------------------------------------------------------------- /doc/images/warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/warning.png -------------------------------------------------------------------------------- /doc/images/warning.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/warning.tif -------------------------------------------------------------------------------- /tests/elf_examples/asm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/asm -------------------------------------------------------------------------------- /doc/images/annot-open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/annot-open.png -------------------------------------------------------------------------------- /doc/images/callouts/1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/1.gif -------------------------------------------------------------------------------- /doc/images/callouts/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/1.png -------------------------------------------------------------------------------- /doc/images/callouts/2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/2.gif -------------------------------------------------------------------------------- /doc/images/callouts/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/2.png -------------------------------------------------------------------------------- /doc/images/callouts/3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/3.gif -------------------------------------------------------------------------------- /doc/images/callouts/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/3.png -------------------------------------------------------------------------------- /doc/images/callouts/4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/4.gif -------------------------------------------------------------------------------- /doc/images/callouts/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/4.png -------------------------------------------------------------------------------- /doc/images/callouts/5.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/5.gif -------------------------------------------------------------------------------- /doc/images/callouts/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/5.png -------------------------------------------------------------------------------- /doc/images/callouts/6.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/6.gif -------------------------------------------------------------------------------- /doc/images/callouts/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/6.png -------------------------------------------------------------------------------- /doc/images/callouts/7.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/7.gif -------------------------------------------------------------------------------- /doc/images/callouts/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/7.png -------------------------------------------------------------------------------- /doc/images/callouts/8.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/8.gif -------------------------------------------------------------------------------- /doc/images/callouts/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/8.png -------------------------------------------------------------------------------- /doc/images/callouts/9.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/9.gif -------------------------------------------------------------------------------- /doc/images/callouts/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/9.png -------------------------------------------------------------------------------- /doc/images/important.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/important.gif -------------------------------------------------------------------------------- /doc/images/important.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/important.png -------------------------------------------------------------------------------- /doc/images/important.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/important.tif -------------------------------------------------------------------------------- /doc/images/res/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res/title.png -------------------------------------------------------------------------------- /doc/images/toc-blank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/toc-blank.png -------------------------------------------------------------------------------- /doc/images/toc-minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/toc-minus.png -------------------------------------------------------------------------------- /doc/images/toc-plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/toc-plus.png -------------------------------------------------------------------------------- /tests/elf_examples/asm.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/asm.o -------------------------------------------------------------------------------- /tests/elf_examples/asm64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/asm64 -------------------------------------------------------------------------------- /tests/elf_examples/ctors: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/ctors -------------------------------------------------------------------------------- /tests/elf_examples/main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/main -------------------------------------------------------------------------------- /tests/elf_examples/main32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/main32 -------------------------------------------------------------------------------- /doc/images/annot-close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/annot-close.png -------------------------------------------------------------------------------- /doc/images/callouts/10.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/10.gif -------------------------------------------------------------------------------- /doc/images/callouts/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/10.png -------------------------------------------------------------------------------- /doc/images/callouts/11.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/11.gif -------------------------------------------------------------------------------- /doc/images/callouts/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/11.png -------------------------------------------------------------------------------- /doc/images/callouts/12.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/12.gif -------------------------------------------------------------------------------- /doc/images/callouts/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/12.png -------------------------------------------------------------------------------- /doc/images/callouts/13.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/13.gif -------------------------------------------------------------------------------- /doc/images/callouts/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/13.png -------------------------------------------------------------------------------- /doc/images/callouts/14.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/14.gif -------------------------------------------------------------------------------- /doc/images/callouts/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/14.png -------------------------------------------------------------------------------- /doc/images/callouts/15.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/15.gif -------------------------------------------------------------------------------- /doc/images/callouts/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/callouts/15.png -------------------------------------------------------------------------------- /tests/elf_examples/asm64.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/asm64.o -------------------------------------------------------------------------------- /tests/elf_examples/hello_32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/hello_32 -------------------------------------------------------------------------------- /tests/elf_examples/hello_64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/hello_64 -------------------------------------------------------------------------------- /tests/elf_examples/test_ppc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/test_ppc -------------------------------------------------------------------------------- /tests/elf_examples/zavl.ko: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/zavl.ko -------------------------------------------------------------------------------- /doc/images/res2/iceland.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res2/iceland.jpeg -------------------------------------------------------------------------------- /tests/elf_examples/crash.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/crash.elf -------------------------------------------------------------------------------- /tests/elf_examples/entropy.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/entropy.so -------------------------------------------------------------------------------- /tests/elf_examples/hello_32.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/hello_32.o -------------------------------------------------------------------------------- /tests/elf_examples/hello_64.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/hello_64.o -------------------------------------------------------------------------------- /tests/elf_examples/hello_arm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/hello_arm -------------------------------------------------------------------------------- /tests/elf_examples/hello_arm.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/hello_arm.o -------------------------------------------------------------------------------- /tests/elf_examples/libfunc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/libfunc.so -------------------------------------------------------------------------------- /tests/elf_examples/startup.eln: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/startup.eln -------------------------------------------------------------------------------- /tests/elf_examples/test_ppc.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/test_ppc.o -------------------------------------------------------------------------------- /tests/elf_examples/64bitLOAD.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/64bitLOAD.elf -------------------------------------------------------------------------------- /tests/elf_examples/ARMSCII-8.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/ARMSCII-8.so -------------------------------------------------------------------------------- /tests/elf_examples/libfunc32.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/libfunc32.so -------------------------------------------------------------------------------- /tests/elf_examples/x86_64_static: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/x86_64_static -------------------------------------------------------------------------------- /doc/images/res2/20231119095119.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res2/20231119095119.jpg -------------------------------------------------------------------------------- /doc/images/res2/20231119095351.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res2/20231119095351.jpg -------------------------------------------------------------------------------- /doc/images/res2/20231119095425.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res2/20231119095425.jpg -------------------------------------------------------------------------------- /doc/images/res2/20231119095558.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res2/20231119095558.jpg -------------------------------------------------------------------------------- /doc/images/res2/20231119095613.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res2/20231119095613.jpg -------------------------------------------------------------------------------- /doc/images/res2/20231119095721.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res2/20231119095721.jpg -------------------------------------------------------------------------------- /doc/images/res2/20231119095920.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res2/20231119095920.jpg -------------------------------------------------------------------------------- /doc/images/res2/20231119095932.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res2/20231119095932.jpg -------------------------------------------------------------------------------- /doc/images/res2/20231119095944.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res2/20231119095944.jpg -------------------------------------------------------------------------------- /doc/images/res2/20231119100133.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res2/20231119100133.jpg -------------------------------------------------------------------------------- /doc/images/res2/20231119100142.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res2/20231119100142.jpg -------------------------------------------------------------------------------- /doc/images/res2/20231119165006.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res2/20231119165006.jpg -------------------------------------------------------------------------------- /doc/images/res2/20231119165016.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res2/20231119165016.jpg -------------------------------------------------------------------------------- /doc/images/res2/20231119165024.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res2/20231119165024.jpg -------------------------------------------------------------------------------- /doc/images/res2/20231119165842.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res2/20231119165842.jpg -------------------------------------------------------------------------------- /doc/images/res2/20231119165851.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res2/20231119165851.jpg -------------------------------------------------------------------------------- /doc/images/res2/20231119165907.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res2/20231119165907.jpg -------------------------------------------------------------------------------- /doc/images/res2/20231119165912.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res2/20231119165912.jpg -------------------------------------------------------------------------------- /tests/elf_examples/helloworld.rpx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/helloworld.rpx -------------------------------------------------------------------------------- /tests/elf_examples/libversion_d.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/libversion_d.so -------------------------------------------------------------------------------- /tests/elf_examples/startup_orig.eln: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/startup_orig.eln -------------------------------------------------------------------------------- /doc/images/res/20231119165006-100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res/20231119165006-100.png -------------------------------------------------------------------------------- /doc/images/res2/20231119165006-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res2/20231119165006-1.jpg -------------------------------------------------------------------------------- /examples/arion/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_executable(arion arion.cpp) 3 | target_link_libraries(arion PRIVATE ario::ario) 4 | -------------------------------------------------------------------------------- /tests/elf_examples/hello_arm_stripped: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/hello_arm_stripped -------------------------------------------------------------------------------- /doc/images/res2/20231119165006-256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/doc/images/res2/20231119165006-256.png -------------------------------------------------------------------------------- /examples/writer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_executable(writer writer.cpp) 3 | target_link_libraries(writer PRIVATE elfio::elfio) 4 | -------------------------------------------------------------------------------- /examples/elfdump/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_executable(elfdump elfdump.cpp) 3 | target_link_libraries(elfdump PRIVATE elfio::elfio) 4 | -------------------------------------------------------------------------------- /tests/elf_examples/arm_v7m_test_debug.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/arm_v7m_test_debug.elf -------------------------------------------------------------------------------- /tests/elf_examples/elf_header_i386_32.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/elf_header_i386_32.elf -------------------------------------------------------------------------------- /tests/elf_examples/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | printf( "Hello\n" ); 6 | 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/elf_examples/mismatched_segments.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/mismatched_segments.elf -------------------------------------------------------------------------------- /tests/elf_examples/ppc-32bit-specimen3.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/ppc-32bit-specimen3.elf -------------------------------------------------------------------------------- /tests/elf_examples/write_exe_i386_32_match: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/write_exe_i386_32_match -------------------------------------------------------------------------------- /examples/proc_mem/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_executable(proc_mem proc_mem.cpp) 3 | target_link_libraries(proc_mem PRIVATE elfio::elfio) 4 | -------------------------------------------------------------------------------- /examples/tutorial/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_executable(tutorial tutorial.cpp) 3 | target_link_libraries(tutorial PRIVATE elfio::elfio) 4 | -------------------------------------------------------------------------------- /tests/elf_examples/arm_v7m_test_release.elf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/arm_v7m_test_release.elf -------------------------------------------------------------------------------- /tests/elf_examples/null_endianess_convertor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/null_endianess_convertor -------------------------------------------------------------------------------- /tests/elf_examples/read_write_arm_elf32_input: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/read_write_arm_elf32_input -------------------------------------------------------------------------------- /tests/elf_examples/write_obj_i386_32_match.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/write_obj_i386_32_match.o -------------------------------------------------------------------------------- /tests/elf_examples/write_obj_i386_64_match.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/write_obj_i386_64_match.o -------------------------------------------------------------------------------- /examples/arioso/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_executable(arioso arioso.cpp) 3 | target_link_libraries(arioso PRIVATE ario::ario elfio::elfio) 4 | -------------------------------------------------------------------------------- /examples/elfio_ldd/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_executable(elfio-ldd elfio_ldd.cpp) 3 | target_link_libraries(elfio-ldd PRIVATE elfio::elfio) 4 | -------------------------------------------------------------------------------- /examples/write_obj/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_executable(write_obj write_obj.cpp) 3 | target_link_libraries(write_obj PRIVATE elfio::elfio) 4 | -------------------------------------------------------------------------------- /examples/add_section/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_executable(add_section add_section.cpp) 3 | target_link_libraries(add_section PRIVATE elfio::elfio) 4 | -------------------------------------------------------------------------------- /examples/anonymizer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_executable(anonymizer anonymizer.cpp) 3 | target_link_libraries(anonymizer PRIVATE elfio::elfio) 4 | -------------------------------------------------------------------------------- /tests/elf_examples/test_ppc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | std::cout << "Hello" << std::endl; 6 | 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /examples/c_wrapper/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_executable(c_example c_example.c elfio_c_wrapper.cpp elfio_c_wrapper.h) 3 | target_link_libraries(c_example PRIVATE elfio::elfio) 4 | -------------------------------------------------------------------------------- /tests/elf_examples/crash-060833f08dc14d1712428742b3cad7af17b36bb7: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/crash-060833f08dc14d1712428742b3cad7af17b36bb7 -------------------------------------------------------------------------------- /tests/elf_examples/crash-7d695153fd8052529d480c2352d4ada33a44bada: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/crash-7d695153fd8052529d480c2352d4ada33a44bada -------------------------------------------------------------------------------- /tests/elf_examples/crash-b82f05b0b25c8fdc98480e6d76b6d5f9164ae2bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/crash-b82f05b0b25c8fdc98480e6d76b6d5f9164ae2bc -------------------------------------------------------------------------------- /tests/elf_examples/crash-e1ce7cecf01cf800397a4302854d9d76fa19763c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/crash-e1ce7cecf01cf800397a4302854d9d76fa19763c -------------------------------------------------------------------------------- /tests/elf_examples/crash-e3c41070342cf84dea077356ddbb8ebf4326a601: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serge1/ELFIO/HEAD/tests/elf_examples/crash-e3c41070342cf84dea077356ddbb8ebf4326a601 -------------------------------------------------------------------------------- /tests/elf_examples/version_d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void print_hello_world_v1() { printf( "hello v1" ); } 4 | 5 | void print_hello_world_v2() { printf( "hello v2" ); } -------------------------------------------------------------------------------- /tests/elf_examples/version_d.map: -------------------------------------------------------------------------------- 1 | HELLO_1.0 { 2 | global: 3 | _Z20print_hello_world_v1v; 4 | }; 5 | 6 | HELLO_2.0 { 7 | global: 8 | _Z20print_hello_world_v2v; 9 | }; 10 | -------------------------------------------------------------------------------- /tests/runELFtests: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # ELFIOTest requires to have the current working directory here, 4 | # otherwise it would not find its test files 5 | cd `dirname $0` 6 | ./ELFIOTest 7 | -------------------------------------------------------------------------------- /examples/sudo_gdb.sh: -------------------------------------------------------------------------------- 1 | # The file is used for VSCode debugging with sudo. Use it as following: 2 | # "miDebuggerPath": "/home/user/ELFIO/examples/sudo_gdb.sh" 3 | sudo /usr/bin/gdb "$@" 4 | -------------------------------------------------------------------------------- /cmake/elfioConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # Basic CMake package config file 2 | @PACKAGE_INIT@ 3 | 4 | include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") 5 | check_required_components("@PROJECT_NAME@") -------------------------------------------------------------------------------- /elfio/elfio_version.hpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | //! \def ELFIO_VERSION 3 | //! \brief Defines the version of the ELFIO library 4 | #define ELFIO_VERSION "3.14" 5 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(add_section) 2 | add_subdirectory(anonymizer) 3 | add_subdirectory(elfdump) 4 | add_subdirectory(elfio_ldd) 5 | add_subdirectory(proc_mem) 6 | add_subdirectory(tutorial) 7 | add_subdirectory(write_obj) 8 | add_subdirectory(writer) 9 | #add_subdirectory(c_wrapper) 10 | add_subdirectory(arion) 11 | add_subdirectory(arioso) 12 | -------------------------------------------------------------------------------- /tests/ario/invalid_magic.a: -------------------------------------------------------------------------------- 1 | ! 2 | hello.c/ 0 0 0 644 45 ` 3 | int my_func(int param) 4 | { 5 | return 2*param; 6 | } 7 | 8 | hello2.c/ 0 0 0 644 7 ` 9 | Hello2 10 | 11 | hello3.c/ 0 0 0 644 8 ` 12 | Hello23 13 | hello4.c/ 0 0 0 644 10 ` 14 | Hello24== 15 | hello41.c/ 0 0 0 644 11 ` 16 | Hello24== 17 | 18 | 19 | hello5.c/ 0 0 0 644 8 ` 20 | Hello25 21 | -------------------------------------------------------------------------------- /tests/ario/simple_text.a: -------------------------------------------------------------------------------- 1 | ! 2 | hello.c/ 0 0 0 644 45 ` 3 | int my_func(int param) 4 | { 5 | return 2*param; 6 | } 7 | 8 | hello2.c/ 0 0 0 644 7 ` 9 | Hello2 10 | 11 | hello3.c/ 0 0 0 644 8 ` 12 | Hello23 13 | hello4.c/ 0 0 0 644 10 ` 14 | Hello24== 15 | hello41.c/ 0 0 0 644 11 ` 16 | Hello24== 17 | 18 | 19 | hello5.c/ 0 0 0 644 8 ` 20 | Hello25 21 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Linux", 5 | "includePath": [ 6 | "${workspaceFolder}", 7 | "${workspaceFolder}/**" 8 | ], 9 | "defines": [], 10 | "compilerPath": "/usr/bin/g++", 11 | "cStandard": "c11", 12 | "cppStandard": "c++17", 13 | "intelliSenseMode": "clang-x64", 14 | "compileCommands": "${workspaceFolder}/build/compile_commands.json", 15 | "configurationProvider": "ms-vscode.cmake-tools" 16 | } 17 | ], 18 | "version": 4 19 | } -------------------------------------------------------------------------------- /tests/elf_examples/asm.s: -------------------------------------------------------------------------------- 1 | ; nasm -f elf hello.asm # this will produce hello.o ELF object file 2 | ; ld -s -o hello hello.o # this will produce hello executable 3 | 4 | section .text 5 | global _start ;must be declared for linker (ld) 6 | 7 | _start: ;tell linker entry point 8 | 9 | mov edx,len ;message length 10 | mov ecx,msg ;message to write 11 | mov ebx,1 ;file descriptor (stdout) 12 | mov eax,4 ;system call number (sys_write) 13 | int 0x80 ;call kernel 14 | 15 | mov eax,1 ;system call number (sys_exit) 16 | int 0x80 ;call kernel 17 | 18 | section .data 19 | 20 | msg db 'Hello, world!',0xa ;our dear string 21 | len equ $ - msg ;length of our dear string 22 | 23 | -------------------------------------------------------------------------------- /doc/images/callouts/1.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /doc/images/callouts/7.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /doc/images/callouts/4.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /tests/elfio_fuzzer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | using namespace ELFIO; 8 | 9 | extern "C" int LLVMFuzzerTestOneInput( const std::uint8_t* Data, size_t Size ) 10 | { 11 | std::string str( (const char*)Data, Size ); 12 | std::istringstream ss( str ); 13 | std::ostringstream oss; 14 | 15 | elfio elf; 16 | 17 | if ( !elf.load( ss ) ) { 18 | return 0; 19 | } 20 | 21 | dump::header( oss, elf ); 22 | dump::section_headers( oss, elf ); 23 | dump::segment_headers( oss, elf ); 24 | dump::symbol_tables( oss, elf ); 25 | dump::notes( oss, elf ); 26 | dump::modinfo( oss, elf ); 27 | dump::dynamic_tags( oss, elf ); 28 | dump::section_datas( oss, elf ); 29 | dump::segment_datas( oss, elf ); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /doc/images/callouts/11.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /tests/ario/long_name.a: -------------------------------------------------------------------------------- 1 | ! 2 | // 98 ` 3 | a_file_with_very_long_name.txt/ 4 | a_file_with_very_long_name2.txt/ 5 | a_file_with_very_long_name3.txt/ 6 | hello.c/ 0 0 0 644 45 ` 7 | int my_func(int param) 8 | { 9 | return 2*param; 10 | } 11 | 12 | hello2.c/ 0 0 0 644 7 ` 13 | Hello2 14 | 15 | hello3.c/ 0 0 0 644 8 ` 16 | Hello23 17 | hello4.c/ 0 0 0 644 10 ` 18 | Hello24== 19 | hello41.c/ 0 0 0 644 11 ` 20 | Hello24== 21 | 22 | 23 | hello5.c/ 0 0 0 644 8 ` 24 | Hello25 25 | /0 0 0 0 644 6 ` 26 | Hello 27 | /32 0 0 0 644 6 ` 28 | Hello 29 | /65 0 0 0 644 6 ` 30 | Hello 31 | -------------------------------------------------------------------------------- /doc/images/callouts/17.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/images/callouts/14.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/images/callouts/2.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/images/callouts/5.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/images/up.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | ]> 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/images/next.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | ]> 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/images/prev.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | ]> 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/images/callouts/10.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/images/callouts/12.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/images/callouts/21.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (C) 2001-present by Serge Lamikhov-Center 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /doc/images/callouts/3.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/images/callouts/9.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/images/callouts/15.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/images/callouts/27.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 15 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/images/callouts/6.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/images/callouts/24.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 15 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/images/warning.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | ]> 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /doc/images/callouts/13.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /doc/images/callouts/19.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /doc/images/callouts/8.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /doc/images/callouts/16.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /doc/images/callouts/20.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 15 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /doc/images/caution.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | ]> 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /doc/images/callouts/22.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 15 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /doc/images/important.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | ]> 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /doc/images/callouts/25.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 15 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /doc/images/callouts/18.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle : LLVM 2 | 3 | AccessModifierOffset : -2 4 | AlignAfterOpenBracket : true 5 | AlignConsecutiveAssignments : true 6 | AlignConsecutiveDeclarations : true 7 | AlignConsecutiveMacros : true 8 | AlignEscapedNewlines : true 9 | AlignOperands : true 10 | AlignTrailingComments : true 11 | BinPackParameters : false 12 | BraceWrapping: 13 | AfterCaseLabel : true 14 | AfterClass : true 15 | AfterEnum : true 16 | AfterFunction : true 17 | AfterNamespace : false 18 | AfterStruct : true 19 | AfterExternBlock : true 20 | BeforeCatch : true 21 | BeforeElse : true 22 | BreakBeforeBraces : Custom 23 | ColumnLimit : 80 24 | FixNamespaceComments : true 25 | IndentCaseLabels : false 26 | IndentWidth : 4 27 | NamespaceIndentation : Inner 28 | PointerAlignment : Left 29 | ReflowComments : false 30 | SortIncludes : false 31 | SpacesInConditionalStatement : true 32 | SpacesInParentheses : true 33 | TabWidth : 4 34 | UseTab : Never 35 | -------------------------------------------------------------------------------- /doc/images/callouts/30.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 17 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /doc/images/callouts/23.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 15 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /doc/images/callouts/29.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 15 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /doc/images/callouts/26.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 15 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/elf_examples/asm.lst: -------------------------------------------------------------------------------- 1 | 1 ; nasm -f elf hello.asm # this will produce hello.o ELF object file 2 | 2 ; ld -s -o hello hello.o # this will produce hello executable 3 | 3 4 | 4 section .text 5 | 5 global _start ;must be declared for linker (ld) 6 | 6 7 | 7 _start: ;tell linker entry point 8 | 8 9 | 9 00000000 BA0E000000 mov edx,len ;message length 10 | 10 00000005 B9[00000000] mov ecx,msg ;message to write 11 | 11 0000000A BB01000000 mov ebx,1 ;file descriptor (stdout) 12 | 12 0000000F B804000000 mov eax,4 ;system call number (sys_write) 13 | 13 00000014 CD80 int 0x80 ;call kernel 14 | 14 15 | 15 00000016 B801000000 mov eax,1 ;system call number (sys_exit) 16 | 16 0000001B CD80 int 0x80 ;call kernel 17 | 17 18 | 18 section .data 19 | 19 20 | 20 00000000 48656C6C6F2C20776F- msg db 'Hello, world!',0xa ;our dear string 21 | 21 00000009 726C64210A 22 | 22 len equ $ - msg ;length of our dear string 23 | 23 24 | -------------------------------------------------------------------------------- /tests/elf_examples/asm64.lst: -------------------------------------------------------------------------------- 1 | 1 ; nasm -f elf hello.asm # this will produce hello.o ELF object file 2 | 2 ; ld -s -o hello hello.o # this will produce hello executable 3 | 3 4 | 4 section .text 5 | 5 global _start ;must be declared for linker (ld) 6 | 6 7 | 7 _start: ;tell linker entry point 8 | 8 9 | 9 00000000 BA0E000000 mov edx,len ;message length 10 | 10 00000005 B9[00000000] mov ecx,msg ;message to write 11 | 11 0000000A BB01000000 mov ebx,1 ;file descriptor (stdout) 12 | 12 0000000F B804000000 mov eax,4 ;system call number (sys_write) 13 | 13 00000014 CD80 int 0x80 ;call kernel 14 | 14 15 | 15 00000016 B801000000 mov eax,1 ;system call number (sys_exit) 16 | 16 0000001B CD80 int 0x80 ;call kernel 17 | 17 18 | 18 section .data 19 | 19 20 | 20 00000000 48656C6C6F2C20776F- msg db 'Hello, world!',0xa ;our dear string 21 | 21 00000009 726C64210A 22 | 22 len equ $ - msg ;length of our dear string 23 | 23 24 | -------------------------------------------------------------------------------- /doc/images/callouts/28.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 15 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /doc/images/note.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | ]> 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /examples/elfio_ldd/elfio_ldd.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | elfio_ldd.cpp - Use ELFIO library to list dynamic libraries required by ELF file. 3 | 4 | 2025 Pasha-From-Russia 5 | 6 | ELFIO Copyright (C) 2001-present by Serge Lamikhov-Center 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | */ 26 | 27 | #ifdef _MSC_VER 28 | #define _SCL_SECURE_NO_WARNINGS 29 | #define ELFIO_NO_INTTYPES 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | using namespace ELFIO; 36 | 37 | static const bool kPrintNamesOnly = true; 38 | 39 | int main( int argc, char** argv ) 40 | { 41 | if ( argc != 2 ) { 42 | printf( "Usage: elfio_ldd \n" ); 43 | return 1; 44 | } 45 | 46 | elfio reader; 47 | 48 | if ( !reader.load( argv[1] ) ) { 49 | printf( "File %s is not found or it is not an ELF file\n", argv[1] ); 50 | return 1; 51 | } 52 | 53 | dump::dynamic_tags( std::cout, reader, kPrintNamesOnly ); 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /examples/add_section/add_section.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2001-present by Serge Lamikhov-Center 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | using namespace ELFIO; 27 | 28 | int main( int argc, char** argv ) 29 | { 30 | if ( argc != 2 ) { 31 | std::cout << "Usage: add_section " << std::endl; 32 | return 1; 33 | } 34 | 35 | // Create an elfio reader 36 | elfio reader; 37 | 38 | // Load ELF data 39 | if ( !reader.load( argv[1] ) ) { 40 | std::cout << "Can't find or process ELF file " << argv[1] << std::endl; 41 | return 2; 42 | } 43 | 44 | // Create additional section at the end of the file 45 | section* note_sec = reader.sections.add( ".note.ELFIO" ); 46 | note_sec->set_type( SHT_NOTE ); 47 | note_section_accessor note_writer( reader, note_sec ); 48 | note_writer.add_note( 0x01, "Created by ELFIO", "My data", 8 ); 49 | 50 | reader.save( "./result.elf" ); 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /doc/images/home.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | ]> 11 | 12 | 13 | 14 | 16 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /examples/elfdump/elfdump.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | elfdump.cpp - Dump ELF file using ELFIO library. 3 | 4 | Copyright (C) 2001-present by Serge Lamikhov-Center 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | */ 24 | 25 | #ifdef _MSC_VER 26 | #define _SCL_SECURE_NO_WARNINGS 27 | #define ELFIO_NO_INTTYPES 28 | #endif 29 | 30 | #include 31 | #include 32 | 33 | using namespace ELFIO; 34 | 35 | int main( int argc, char** argv ) 36 | { 37 | if ( argc != 2 ) { 38 | printf( "Usage: elfdump \n" ); 39 | return 1; 40 | } 41 | 42 | elfio reader; 43 | 44 | if ( !reader.load( argv[1] ) ) { 45 | printf( "File %s is not found or it is not an ELF file\n", argv[1] ); 46 | return 1; 47 | } 48 | 49 | dump::header( std::cout, reader ); 50 | dump::section_headers( std::cout, reader ); 51 | dump::segment_headers( std::cout, reader ); 52 | dump::symbol_tables( std::cout, reader ); 53 | dump::notes( std::cout, reader ); 54 | dump::modinfo( std::cout, reader ); 55 | dump::dynamic_tags( std::cout, reader ); 56 | dump::section_datas( std::cout, reader ); 57 | dump::segment_datas( std::cout, reader ); 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /tests/elf_examples/asm.readelf: -------------------------------------------------------------------------------- 1 | ELF Header: 2 | Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 3 | Class: ELF32 4 | Data: 2's complement, little endian 5 | Version: 1 (current) 6 | OS/ABI: UNIX - System V 7 | ABI Version: 0 8 | Type: EXEC (Executable file) 9 | Machine: Intel 80386 10 | Version: 0x1 11 | Entry point address: 0x8048080 12 | Start of program headers: 52 (bytes into file) 13 | Start of section headers: 200 (bytes into file) 14 | Flags: 0x0 15 | Size of this header: 52 (bytes) 16 | Size of program headers: 32 (bytes) 17 | Number of program headers: 2 18 | Size of section headers: 40 (bytes) 19 | Number of section headers: 4 20 | Section header string table index: 3 21 | 22 | Section Headers: 23 | [Nr] Name Type Addr Off Size ES Flg Lk Inf Al 24 | [ 0] NULL 00000000 000000 000000 00 0 0 0 25 | [ 1] .text PROGBITS 08048080 000080 00001d 00 AX 0 0 16 26 | [ 2] .data PROGBITS 080490a0 0000a0 00000e 00 WA 0 0 4 27 | [ 3] .shstrtab STRTAB 00000000 0000ae 000017 00 0 0 1 28 | Key to Flags: 29 | W (write), A (alloc), X (execute), M (merge), S (strings) 30 | I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown) 31 | O (extra OS processing required) o (OS specific), p (processor specific) 32 | 33 | There are no section groups in this file. 34 | 35 | Program Headers: 36 | Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align 37 | LOAD 0x000000 0x08048000 0x08048000 0x0009d 0x0009d R E 0x1000 38 | LOAD 0x0000a0 0x080490a0 0x080490a0 0x0000e 0x0000e RW 0x1000 39 | 40 | Section to Segment mapping: 41 | Segment Sections... 42 | 00 .text 43 | 01 .data 44 | 45 | There is no dynamic section in this file. 46 | 47 | There are no relocations in this file. 48 | 49 | The decoding of unwind sections for machine type Intel 80386 is not currently supported. 50 | 51 | No version information found in this file. 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | autom4te.cache 2 | Debug 3 | Release 4 | .vs 5 | tmp/ 6 | docs 7 | 8 | tests/Debug 9 | tests/Release 10 | tests/ELFIOTest 11 | tests/ELFIOTest.exe 12 | tests/runELFtests.trs 13 | 14 | 15 | examples/ELFDump/Debug 16 | examples/anonymizer/anonymizer 17 | examples/anonymizer/anonymizer.exe 18 | examples/elfdump/elfdump 19 | examples/elfdump/elfdump.exe 20 | examples/tutorial/tutorial 21 | examples/tutorial/tutorial.exe 22 | examples/write_obj/write_obj 23 | examples/write_obj/write_obj.exe 24 | examples/writer/writer 25 | examples/writer/writer.exe 26 | 27 | 28 | # generated elf files 29 | tests/elf_examples/*_copy 30 | tests/elf_examples/*_copy.elf 31 | tests/elf_examples/elf_dummy_header_i386_32.elf 32 | tests/elf_examples/elf_dummy_header_i386_64.elf 33 | tests/elf_examples/elf_dummy_header_ppc_32.elf 34 | tests/elf_examples/elf_dummy_header_ppc_64.elf 35 | tests/elf_examples/write_exe_i386_32 36 | tests/elf_examples/write_exe_i386_32_w_addr 37 | tests/elf_examples/write_exe_i386_32_wo_addr 38 | tests/elf_examples/write_exe_i386_32_section_added 39 | tests/elf_examples/ppc-32bit-testcopy*.elf 40 | tests/elf_examples/null_section_inside_segment* 41 | tests/elf_examples/segment_containing_no_section* 42 | tests/elf_examples/test_symbols_order.elf 43 | tests/elf_examples/zavl_gen.ko 44 | 45 | tests/elfio_fuzzer 46 | tests/corpus 47 | 48 | examples/writer/hello_x86_64 49 | examples/write_obj/hello 50 | examples/c_wrapper/c_example 51 | examples/add_section/add_section 52 | examples/elfdump/elfdump.trs 53 | 54 | # various unwanted files (backups, objects, cmake artifacts) 55 | *~ 56 | *.o 57 | *.kate-swp 58 | *.swp 59 | .#* 60 | \#*# 61 | CMakeCache.txt 62 | CMakeSettings.json 63 | Makefile 64 | CMakeFiles 65 | /build*/ 66 | out 67 | *.res 68 | 69 | # autotools artifacts 70 | .deps 71 | config.status 72 | ELFIOTest/runELFtests.trs 73 | 74 | # eclipse project files 75 | .settings 76 | .project 77 | .cproject 78 | .cdtproject 79 | .cdtbuild 80 | 81 | # netbeans project files 82 | /dist/ 83 | Makefile 84 | .dep.inc 85 | nbproject 86 | 87 | # QtCreator project files 88 | CMakeLists.txt.user 89 | 90 | # ignore all _ prefixed directories (usually used for generated directories) 91 | _*/ 92 | 93 | # Latex build output 94 | *.pdf 95 | *.log 96 | *.out 97 | *.aux 98 | *.bbl 99 | *.toc 100 | *.blg 101 | -------------------------------------------------------------------------------- /doc/site/style.css: -------------------------------------------------------------------------------- 1 | /* 2 | color:#ffffff; white 3 | color:#e0e0e0; light gray 4 | color:#f8f8f8; light gray 5 | color:#003366; dark blue 6 | color:#555555; gray 7 | color:#ff9933; light orange 8 | color:#cc3300; red/brown/orange 9 | color:#660066; purple 10 | color:#669900; green 11 | */ 12 | 13 | a { 14 | color:#003366; 15 | text-decoration:underline; 16 | } 17 | 18 | a:hover { 19 | color:#ff9933; 20 | } 21 | 22 | body { 23 | font-family: verdana, tahoma, helvetica, arial, sans-serif; 24 | font-size: 90%; 25 | background-color:#ffffff; 26 | margin: 1em; 27 | } 28 | 29 | pre { 30 | font-family: courier, serif; 31 | background-color:#f8f8f8; 32 | margin: 1.5em; 33 | font-size:90%; 34 | } 35 | 36 | ul { 37 | list-style: circle outside; 38 | font-stretch:extra-expanded; 39 | /* font-size:90%;*/ 40 | } 41 | 42 | ul.menu { /* inherits from ul */ 43 | padding-left: 1em; 44 | } 45 | 46 | 47 | em { 48 | color:#FF7700; 49 | font-size:110%; 50 | } 51 | 52 | h1,h2,h3{ 53 | color:#FF7700; 54 | } 55 | 56 | h1 { 57 | border-color:#d0d0d0; 58 | border-style:solid; 59 | border-width:1px; 60 | font-weight:bold; 61 | padding: 0.2em; 62 | background-color:#f8f8f8 63 | } 64 | 65 | h2 { 66 | font-size:120%; 67 | font-weight:bold; 68 | border-bottom-style:solid; 69 | border-bottom-width:1px; 70 | border-bottom-color:#d0d0d0; 71 | } 72 | 73 | h3 { 74 | font-size:110%; 75 | font-weight:bold; 76 | font-style:italic; 77 | } 78 | 79 | tt { 80 | font-family: courier, serif; 81 | } 82 | 83 | tt.classname { 84 | font-weight:bold; 85 | } 86 | 87 | tt.constant { 88 | font-weight:bold; 89 | } 90 | 91 | 92 | p { 93 | line-height: 1.5em; 94 | } 95 | 96 | 97 | p.author { 98 | /* line-height: 0.5em; */ 99 | font-size:70%; 100 | } 101 | 102 | 103 | div.links{ 104 | float: left; 105 | clear: left; 106 | width: 12em; 107 | background-color:#f8f8f8; 108 | border-style:solid; 109 | border-width:1px; 110 | border-color:#d0d0d0; 111 | margin-bottom: 0.5em; 112 | padding: 0.5em 0.5em 0.5em 0.5em; 113 | margin: 0.5em 0.5em 0em 0em; 114 | } 115 | 116 | div.main{ 117 | border-style:solid; 118 | border-width:1px; 119 | border-color:#d0d0d0; 120 | margin: 0.5em 0em 0.5em 14em; 121 | padding: 0.5em 0.5em 0.5em 0.5em; 122 | } 123 | 124 | div.by{ 125 | line-height: 0.5em; 126 | border-width:1px; 127 | border-color:#d0d0d0; 128 | margin: 0.5em 0em 0.5em 14em; 129 | padding: 0.5em 0.5em 0.5em 0.5em; 130 | } 131 | 132 | -------------------------------------------------------------------------------- /doc/images/tip.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | ]> 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | name: "CodeQL" 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | # The branches below must be a subset of the branches above 8 | branches: [master] 9 | schedule: 10 | - cron: '0 15 * * 5' 11 | 12 | permissions: 13 | contents: read 14 | 15 | jobs: 16 | analyze: 17 | permissions: 18 | actions: read # for github/codeql-action/init to get workflow details 19 | contents: read # for actions/checkout to fetch code 20 | security-events: write # for github/codeql-action/analyze to upload SARIF results 21 | name: Analyze 22 | runs-on: ubuntu-latest 23 | 24 | strategy: 25 | fail-fast: false 26 | matrix: 27 | # Override automatic language detection by changing the below list 28 | # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] 29 | language: ['cpp'] 30 | # Learn more... 31 | # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection 32 | 33 | steps: 34 | - name: Checkout repository 35 | uses: actions/checkout@v4 36 | with: 37 | # We must fetch at least the immediate parents so that if this is 38 | # a pull request then we can checkout the head. 39 | fetch-depth: 2 40 | 41 | # If this run was triggered by a pull request event, then checkout 42 | # the head of the pull request instead of the merge commit. 43 | #- run: git checkout HEAD^2 44 | # if: ${{ github.event_name == 'pull_request' }} 45 | 46 | # Initializes the CodeQL tools for scanning. 47 | - name: Initialize CodeQL 48 | uses: github/codeql-action/init@v3 49 | with: 50 | languages: ${{ matrix.language }} 51 | 52 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 53 | # If this step fails, then you should remove it and run the build manually (see below) 54 | #- name: Autobuild 55 | # uses: github/codeql-action/autobuild@v1 56 | 57 | # ℹ️ Command-line programs to run using the OS shell. 58 | # 📚 https://git.io/JvXDl 59 | 60 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 61 | # and modify them (or add more) to build your code if your project 62 | # uses a compiled language 63 | 64 | - run: | 65 | cmake -B build -D ELFIO_BUILD_EXAMPLES=ON 66 | cmake --build build 67 | 68 | - name: Perform CodeQL Analysis 69 | uses: github/codeql-action/analyze@v3 70 | -------------------------------------------------------------------------------- /tests/elf_examples/write_exe_i386_32_work_dump.txt: -------------------------------------------------------------------------------- 1 | 2 | write_exe_i386_32_work: file format elf32-i386 3 | write_exe_i386_32_work 4 | architecture: i386, flags 0x00000102: 5 | EXEC_P, D_PAGED 6 | start address 0x08048080 7 | 8 | Program Header: 9 | LOAD off 0x00000000 vaddr 0x08048000 paddr 0x08048000 align 2**12 10 | filesz 0x0000009d memsz 0x0000009d flags r-x 11 | LOAD off 0x000000a0 vaddr 0x080490a0 paddr 0x080490a0 align 2**12 12 | filesz 0x0000000e memsz 0x0000000e flags rw- 13 | 14 | Sections: 15 | Idx Name Size VMA LMA File off Algn 16 | 0 .text 0000001d 08048080 08048080 00000080 2**4 17 | CONTENTS, ALLOC, LOAD, READONLY, CODE 18 | 1 .data 0000000e 080490a0 080490a0 000000a0 2**2 19 | CONTENTS, ALLOC, LOAD, DATA 20 | 2 .note 00000020 00000000 00000000 000000ae 2**0 21 | CONTENTS, READONLY 22 | SYMBOL TABLE: 23 | no symbols 24 | 25 | 26 | 27 | Disassembly of section .text: 28 | 29 | 08048080 <.text>: 30 | 8048080: b8 04 00 00 00 mov $0x4,%eax 31 | 8048085: bb 01 00 00 00 mov $0x1,%ebx 32 | 804808a: b9 a0 90 04 08 mov $0x80490a0,%ecx 33 | 804808f: ba 0e 00 00 00 mov $0xe,%edx 34 | 8048094: cd 80 int $0x80 35 | 8048096: b8 01 00 00 00 mov $0x1,%eax 36 | 804809b: cd 80 int $0x80 37 | 38 | Disassembly of section .data: 39 | 40 | 080490a0 <.data>: 41 | 80490a0: 48 dec %eax 42 | 80490a1: 65 gs 43 | 80490a2: 6c insb (%dx),%es:(%edi) 44 | 80490a3: 6c insb (%dx),%es:(%edi) 45 | 80490a4: 6f outsl %ds:(%esi),(%dx) 46 | 80490a5: 2c 20 sub $0x20,%al 47 | 80490a7: 57 push %edi 48 | 80490a8: 6f outsl %ds:(%esi),(%dx) 49 | 80490a9: 72 6c jb 0x8049117 50 | 80490ab: 64 21 0a and %ecx,%fs:(%edx) 51 | 52 | Disassembly of section .note: 53 | 54 | 00000000 <.note>: 55 | 0: 11 00 adc %eax,(%eax) 56 | 2: 00 00 add %al,(%eax) 57 | 4: 00 00 add %al,(%eax) 58 | 6: 00 00 add %al,(%eax) 59 | 8: 77 00 ja 0xa 60 | a: 00 00 add %al,(%eax) 61 | c: 43 inc %ebx 62 | d: 72 65 jb 0x74 63 | f: 61 popa 64 | 10: 74 65 je 0x77 65 | 12: 64 20 62 79 and %ah,%fs:0x79(%edx) 66 | 16: 20 45 4c and %al,0x4c(%ebp) 67 | 19: 46 inc %esi 68 | 1a: 49 dec %ecx 69 | 1b: 4f dec %edi 70 | 1c: 00 00 add %al,(%eax) 71 | ... 72 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "type": "shell", 5 | "label": "ELFIO Test build", 6 | "command": "make", 7 | "args": ["INCLUDES=-I..", "CXXFLAGS='-g -O0'"], 8 | "options": { 9 | "cwd": "${workspaceRoot}/build/tests" 10 | }, 11 | "group": { 12 | "kind": "build", 13 | "isDefault": true 14 | }, 15 | "problemMatcher": ["$gcc"] 16 | }, 17 | { 18 | "type": "shell", 19 | "label": "ELF Dump Build", 20 | "command": "make", 21 | "args": ["INCLUDES=-I..", "CXXFLAGS='-g -O0'"], 22 | "options": { 23 | "cwd": "${workspaceRoot}/build" 24 | }, 25 | "group": { 26 | "kind": "build", 27 | "isDefault": true 28 | } 29 | }, 30 | { 31 | "type": "shell", 32 | "label": "clang-tidy", 33 | "command": "clang-tidy", 34 | "args": [ 35 | "--checks=*,-modernize-use-trailing-return-type,-modernize-avoid-c-arrays,-llvm*,-fuchsia-*,-altera-*", 36 | "-header-filter=./*", 37 | "examples/elfdump/elfdump.cpp", 38 | "--", 39 | "-I." 40 | ], 41 | "options": { 42 | "cwd": "${workspaceRoot}" 43 | }, 44 | "group": { 45 | "kind": "build", 46 | "isDefault": true 47 | }, 48 | "problemMatcher": ["$gcc"] 49 | }, 50 | { 51 | "type": "shell", 52 | "label": "Fuzzer", 53 | "command": "clang", 54 | "args": [ 55 | "-g", 56 | "-O0", 57 | "-fsanitize=fuzzer,address", 58 | "-I..", 59 | "elfio_fuzzer.cpp", 60 | "-o", 61 | "elfio_fuzzer" 62 | ], 63 | "options": { 64 | "cwd": "${workspaceRoot}/tests" 65 | }, 66 | "group": { 67 | "kind": "build", 68 | "isDefault": true 69 | }, 70 | "problemMatcher": ["$gcc"] 71 | }, 72 | { 73 | "type": "shell", 74 | "label": "Fuzzer Tests", 75 | "command": "./elfio_fuzzer", 76 | "args": ["-jobs=8", "corpus"], 77 | "options": { 78 | "cwd": "${workspaceRoot}/tests" 79 | }, 80 | "group": { 81 | "kind": "build", 82 | "isDefault": true 83 | }, 84 | "problemMatcher": ["$gcc"] 85 | }, 86 | { 87 | "type": "cmake", 88 | "label": "CMake: clean", 89 | "command": "clean", 90 | "problemMatcher": [], 91 | "detail": "CMake template clean task" 92 | }, 93 | { 94 | "type": "cmake", 95 | "label": "CMake: clean rebuild", 96 | "command": "cleanRebuild", 97 | "targets": ["ALL_BUILD"], 98 | "group": "build", 99 | "problemMatcher": [], 100 | "detail": "CMake template clean rebuild task" 101 | } 102 | ], 103 | "version": "2.0.0" 104 | } 105 | -------------------------------------------------------------------------------- /doc/site/index.htm: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | ELFIO - C++ library for reading and generating ELF files 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 16 | 17 |
14 |

ELFIO - C++ library for reading and generating ELF files

15 |
18 | 19 | 43 | 44 |
45 | 46 |

47 | ELFIO is a small, header-only C++ library that provides a simple interface for 48 | reading and generating files in ELF binary format. 49 |

50 |

51 | It is used as a standalone library - it is not dependent on any other product 52 | or project. Adhering to ISO C++, it compiles on a wide variety of architectures 53 | and compilers. 54 |

55 |

56 | While the library is easy to use, some basic knowledge of the ELF binary format 57 | is required. Such Information can be easily found on the Web. 58 |

59 |

60 | The current version of ELFIO library is 3.x and it is distributed under 61 | MIT License conditions. 62 |

63 |

64 | Note for users of previous library versions 1.0.x: Version 3.x is not source 65 | compatible to earlier versions. Transition to the new library interface is 66 | straightforward though. 67 |

68 | 69 |
70 | 71 |
72 |

73 | The library and the page is maintained by 74 | Serge Lamikhov-Center.
75 |

76 | 77 | 78 | 79 | 84 | 87 | 88 |
80 |

81 | Project Web Hosted by 82 |

83 |
85 | Get ELFIO library 86 |
89 | 90 | 91 |
92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(FetchContent) 2 | 3 | if(${CMAKE_VERSION} VERSION_LESS "3.24.0") 4 | FetchContent_Declare( 5 | googletest 6 | URL https://github.com/google/googletest/archive/530d5c8c84.zip 7 | ) 8 | else() 9 | FetchContent_Declare( 10 | googletest 11 | URL https://github.com/google/googletest/archive/refs/tags/v1.16.0.zip 12 | FIND_PACKAGE_ARGS NAMES GTest 13 | DOWNLOAD_EXTRACT_TIMESTAMP = TRUE 14 | ) 15 | endif() 16 | 17 | # For Windows: Prevent overriding the parent project's compiler/linker settings 18 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) 19 | 20 | FetchContent_MakeAvailable(googletest) 21 | 22 | enable_testing() 23 | 24 | # Find all the binary files used for testing and copy them into the build 25 | # directory. This allows the test to be run from the build directory 26 | 27 | # First, create an elf_examples folder under the current build directory 28 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/elf_examples) 29 | 30 | # Second, glob all files under elf_examples 31 | file(GLOB elf_examples 32 | LIST_DIRECTORIES 33 | false 34 | CONFIGURE_DEPENDS 35 | elf_examples/*) 36 | 37 | # Third, copy each file globbed to the elf_examples folder under the current 38 | # build directory 39 | foreach(example ${elf_examples}) 40 | configure_file(${example} ${CMAKE_CURRENT_BINARY_DIR}/elf_examples COPYONLY) 41 | endforeach() 42 | 43 | # First, create an ario folder under the current build directory 44 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/ario) 45 | 46 | # Second, glob all files under ario 47 | file(GLOB ario 48 | LIST_DIRECTORIES 49 | false 50 | CONFIGURE_DEPENDS 51 | ario/*) 52 | 53 | # Third, copy each file globbed to the ario folder under the current 54 | # build directory 55 | foreach(example ${ario}) 56 | configure_file(${example} ${CMAKE_CURRENT_BINARY_DIR}/ario COPYONLY) 57 | endforeach() 58 | 59 | 60 | # Lastly, copy the script to run the tests 61 | configure_file(runELFtests ${CMAKE_CURRENT_BINARY_DIR}/runELFtests COPYONLY) 62 | 63 | add_executable( 64 | ELFIOTest 65 | ELFIOTest.cpp 66 | ELFIOTest1.cpp 67 | ELFIOTest2.cpp 68 | ARIOTest.cpp) 69 | 70 | target_link_libraries( 71 | ELFIOTest 72 | PRIVATE 73 | elfio::elfio 74 | ario::ario 75 | gtest_main 76 | GTest::gtest_main) 77 | 78 | add_test( 79 | NAME 80 | ELFIOTest 81 | COMMAND 82 | ${CMAKE_CURRENT_BINARY_DIR}/ELFIOTest 83 | WORKING_DIRECTORY 84 | ${CMAKE_CURRENT_BINARY_DIR}) 85 | 86 | if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") 87 | add_executable( 88 | elfio_fuzzer 89 | elfio_fuzzer.cpp) 90 | 91 | target_link_libraries( 92 | elfio_fuzzer 93 | PRIVATE 94 | elfio::elfio) 95 | 96 | target_compile_options(elfio_fuzzer 97 | PRIVATE $<$:-g -O1 -fsanitize=fuzzer,address> 98 | ) 99 | 100 | target_link_libraries(elfio_fuzzer 101 | PRIVATE $<$:-fsanitize=fuzzer,address> 102 | ) 103 | endif() 104 | 105 | add_dependencies(check ELFIOTest) 106 | 107 | include(GoogleTest) 108 | gtest_discover_tests(ELFIOTest) 109 | -------------------------------------------------------------------------------- /tests/elf_examples/hello_32_o.txt: -------------------------------------------------------------------------------- 1 | ELF Header: 2 | Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 3 | Class: ELF32 4 | Data: 2's complement, little endian 5 | Version: 1 (current) 6 | OS/ABI: UNIX - System V 7 | ABI Version: 0 8 | Type: REL (Relocatable file) 9 | Machine: Intel 80386 10 | Version: 0x1 11 | Entry point address: 0x0 12 | Start of program headers: 0 (bytes into file) 13 | Start of section headers: 232 (bytes into file) 14 | Flags: 0x0 15 | Size of this header: 52 (bytes) 16 | Size of program headers: 0 (bytes) 17 | Number of program headers: 0 18 | Size of section headers: 40 (bytes) 19 | Number of section headers: 11 20 | Section header string table index: 8 21 | 22 | Section Headers: 23 | [Nr] Name Type Addr Off Size ES Flg Lk Inf Al 24 | [ 0] NULL 00000000 000000 000000 00 0 0 0 25 | [ 1] .text PROGBITS 00000000 000034 00002b 00 AX 0 0 4 26 | [ 2] .rel.text REL 00000000 000354 000010 08 9 1 4 27 | [ 3] .data PROGBITS 00000000 000060 000000 00 WA 0 0 4 28 | [ 4] .bss NOBITS 00000000 000060 000000 00 WA 0 0 4 29 | [ 5] .rodata PROGBITS 00000000 000060 000006 00 A 0 0 1 30 | [ 6] .comment PROGBITS 00000000 000066 00002e 00 0 0 1 31 | [ 7] .note.GNU-stack PROGBITS 00000000 000094 000000 00 0 0 1 32 | [ 8] .shstrtab STRTAB 00000000 000094 000051 00 0 0 1 33 | [ 9] .symtab SYMTAB 00000000 0002a0 0000a0 10 10 8 4 34 | [10] .strtab STRTAB 00000000 000340 000013 00 0 0 1 35 | Key to Flags: 36 | W (write), A (alloc), X (execute), M (merge), S (strings) 37 | I (info), L (link order), G (group), x (unknown) 38 | O (extra OS processing required) o (OS specific), p (processor specific) 39 | 40 | There are no section groups in this file. 41 | 42 | There are no program headers in this file. 43 | 44 | Relocation section '.rel.text' at offset 0x354 contains 2 entries: 45 | Offset Info Type Sym.Value Sym. Name 46 | 00000014 00000501 R_386_32 00000000 .rodata 47 | 00000019 00000902 R_386_PC32 00000000 puts 48 | 49 | There are no unwind sections in this file. 50 | 51 | Symbol table '.symtab' contains 10 entries: 52 | Num: Value Size Type Bind Vis Ndx Name 53 | 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 54 | 1: 00000000 0 FILE LOCAL DEFAULT ABS hello.c 55 | 2: 00000000 0 SECTION LOCAL DEFAULT 1 56 | 3: 00000000 0 SECTION LOCAL DEFAULT 3 57 | 4: 00000000 0 SECTION LOCAL DEFAULT 4 58 | 5: 00000000 0 SECTION LOCAL DEFAULT 5 59 | 6: 00000000 0 SECTION LOCAL DEFAULT 7 60 | 7: 00000000 0 SECTION LOCAL DEFAULT 6 61 | 8: 00000000 43 FUNC GLOBAL DEFAULT 1 main 62 | 9: 00000000 0 NOTYPE GLOBAL DEFAULT UND puts 63 | 64 | No version information found in this file. 65 | -------------------------------------------------------------------------------- /.github/workflows/c-cpp.yml: -------------------------------------------------------------------------------- 1 | name: C/C++ CI 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | workflow_call: 9 | workflow_dispatch: 10 | 11 | permissions: 12 | contents: read 13 | 14 | jobs: 15 | build: 16 | name: CMake Build & Test 17 | runs-on: ${{ matrix.os }} 18 | 19 | strategy: 20 | matrix: 21 | os: [ubuntu-latest, ubuntu-22.04, windows-latest, windows-2022, macos-13, macos-15] 22 | build_type: [Release, Debug] 23 | cpp_compiler: [g++, clang++, cl] 24 | include: 25 | - os: windows-latest 26 | cpp_compiler: cl 27 | c_compiler: cl 28 | - os: windows-2022 29 | cpp_compiler: cl 30 | c_compiler: cl 31 | - os: ubuntu-latest 32 | cpp_compiler: g++ 33 | c_compiler: gcc 34 | - os: ubuntu-latest 35 | cpp_compiler: clang++ 36 | c_compiler: clang 37 | - os: ubuntu-22.04 38 | cpp_compiler: g++ 39 | c_compiler: gcc 40 | - os: ubuntu-22.04 41 | cpp_compiler: clang++ 42 | c_compiler: clang 43 | - os: macos-13 44 | cpp_compiler: g++ 45 | c_compiler: gcc 46 | - os: macos-13 47 | cpp_compiler: clang++ 48 | c_compiler: clang 49 | - os: macos-15 50 | cpp_compiler: g++ 51 | c_compiler: gcc 52 | - os: macos-15 53 | cpp_compiler: clang++ 54 | c_compiler: clang 55 | exclude: 56 | - os: windows-latest 57 | cpp_compiler: g++ 58 | - os: windows-latest 59 | cpp_compiler: clang++ 60 | - os: windows-2022 61 | cpp_compiler: g++ 62 | - os: windows-2022 63 | cpp_compiler: clang++ 64 | - os: ubuntu-latest 65 | cpp_compiler: cl 66 | - os: ubuntu-22.04 67 | cpp_compiler: cl 68 | - os: macos-13 69 | cpp_compiler: cl 70 | - os: macos-15 71 | cpp_compiler: cl 72 | 73 | steps: 74 | - uses: actions/checkout@v4 75 | with: 76 | repository: 'Serge1/ELFIO' 77 | 78 | - name: Set reusable strings 79 | # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. 80 | id: strings 81 | shell: bash 82 | run: | 83 | echo "build-output-dir=${{ github.workspace }}/build/${{ matrix.build_type }}/${{ matrix.cpp_compiler }}" >> "$GITHUB_OUTPUT" 84 | 85 | - name: Configure CMake 86 | run: > 87 | cmake -B ${{ steps.strings.outputs.build-output-dir }} 88 | -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} 89 | -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} 90 | -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} 91 | -DELFIO_BUILD_EXAMPLES=YES -DELFIO_BUILD_TESTS=YES 92 | -S ${{ github.workspace }} 93 | 94 | - name: Build 95 | run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} 96 | 97 | - name: Test 98 | working-directory: ${{ steps.strings.outputs.build-output-dir }} 99 | run: ctest --build-config ${{ matrix.build_type }} --output-on-failure --verbose 100 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "copyright": "json", 4 | "*.ipp": "cpp", 5 | "strstream": "cpp", 6 | "cerrno": "cpp", 7 | "csetjmp": "cpp", 8 | "cstdarg": "cpp", 9 | "rope": "cpp", 10 | "iostream": "cpp", 11 | "streambuf": "cpp", 12 | "*.tcc": "cpp", 13 | "regex": "cpp", 14 | "algorithm": "cpp", 15 | "array": "cpp", 16 | "atomic": "cpp", 17 | "bit": "cpp", 18 | "bitset": "cpp", 19 | "cassert": "cpp", 20 | "cctype": "cpp", 21 | "cfloat": "cpp", 22 | "chrono": "cpp", 23 | "ciso646": "cpp", 24 | "climits": "cpp", 25 | "clocale": "cpp", 26 | "cmath": "cpp", 27 | "complex": "cpp", 28 | "cstddef": "cpp", 29 | "cstdint": "cpp", 30 | "cstdio": "cpp", 31 | "cstdlib": "cpp", 32 | "cstring": "cpp", 33 | "ctime": "cpp", 34 | "cwchar": "cpp", 35 | "cwctype": "cpp", 36 | "deque": "cpp", 37 | "list": "cpp", 38 | "map": "cpp", 39 | "set": "cpp", 40 | "string": "cpp", 41 | "unordered_map": "cpp", 42 | "vector": "cpp", 43 | "exception": "cpp", 44 | "functional": "cpp", 45 | "iterator": "cpp", 46 | "memory": "cpp", 47 | "memory_resource": "cpp", 48 | "numeric": "cpp", 49 | "optional": "cpp", 50 | "random": "cpp", 51 | "ratio": "cpp", 52 | "string_view": "cpp", 53 | "system_error": "cpp", 54 | "tuple": "cpp", 55 | "type_traits": "cpp", 56 | "utility": "cpp", 57 | "fstream": "cpp", 58 | "initializer_list": "cpp", 59 | "iomanip": "cpp", 60 | "ios": "cpp", 61 | "iosfwd": "cpp", 62 | "istream": "cpp", 63 | "limits": "cpp", 64 | "locale": "cpp", 65 | "new": "cpp", 66 | "ostream": "cpp", 67 | "queue": "cpp", 68 | "sstream": "cpp", 69 | "stdexcept": "cpp", 70 | "thread": "cpp", 71 | "cfenv": "cpp", 72 | "cinttypes": "cpp", 73 | "typeindex": "cpp", 74 | "typeinfo": "cpp", 75 | "variant": "cpp", 76 | "compare": "cpp", 77 | "any": "cpp", 78 | "charconv": "cpp", 79 | "concepts": "cpp", 80 | "condition_variable": "cpp", 81 | "csignal": "cpp", 82 | "filesystem": "cpp", 83 | "format": "cpp", 84 | "forward_list": "cpp", 85 | "mutex": "cpp", 86 | "span": "cpp", 87 | "stop_token": "cpp", 88 | "unordered_set": "cpp", 89 | "xfacet": "cpp", 90 | "xhash": "cpp", 91 | "xiosbase": "cpp", 92 | "xlocale": "cpp", 93 | "xlocbuf": "cpp", 94 | "xlocinfo": "cpp", 95 | "xlocmes": "cpp", 96 | "xlocmon": "cpp", 97 | "xlocnum": "cpp", 98 | "xloctime": "cpp", 99 | "xmemory": "cpp", 100 | "xstring": "cpp", 101 | "xtr1common": "cpp", 102 | "xtree": "cpp", 103 | "xutility": "cpp" 104 | }, 105 | "svn.ignoreMissingSvnWarning": true, 106 | "editor.tokenColorCustomizations": { 107 | "textMateRules": [ 108 | { 109 | "scope": "googletest.failed", 110 | "settings": { 111 | "foreground": "#f00" 112 | } 113 | }, 114 | { 115 | "scope": "googletest.passed", 116 | "settings": { 117 | "foreground": "#0f0" 118 | } 119 | }, 120 | { 121 | "scope": "googletest.run", 122 | "settings": { 123 | "foreground": "#0f0" 124 | } 125 | } 126 | ] 127 | }, 128 | "gtest-adapter.debugConfig": "Run ELFIO Tests", 129 | "gtest-adapter.supportLocation": true, 130 | "sonarlint.pathToCompileCommands": "${workspaceFolder}/build/compile_commands.json" 131 | } 132 | -------------------------------------------------------------------------------- /examples/anonymizer/anonymizer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | anonymizer.cpp - Overwrites string table for a function name. 3 | 4 | Copyright (C) 2017 by Martin Bickel 5 | Copyright (C) 2020 by Serge Lamikhov-Center 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | */ 25 | 26 | /* 27 | To run the example, you may use the following script: 28 | 29 | #!/usr/bin/bash 30 | 31 | make 32 | cp anonymizer temp.elf 33 | readelf -a temp.elf > before.txt 34 | ./anonymizer temp.elf 35 | readelf -a temp.elf > after.txt 36 | diff before.txt after.txt 37 | 38 | */ 39 | 40 | #ifdef _MSC_VER 41 | #define _SCL_SECURE_NO_WARNINGS 42 | #define ELFIO_NO_INTTYPES 43 | #endif 44 | 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | using namespace ELFIO; 51 | 52 | void overwrite_data( const std::string& filename, 53 | Elf64_Off offset, 54 | const std::string& str ) 55 | { 56 | std::ofstream file( filename, 57 | std::ios::in | std::ios::out | std::ios::binary ); 58 | if ( !file ) 59 | throw "Error opening file" + filename; 60 | std::string data( str.length(), '-' ); 61 | file.seekp( (std::streampos)offset ); 62 | file.write( data.c_str(), data.length() + 1 ); 63 | } 64 | 65 | void process_string_table( const section* s, const std::string& filename ) 66 | { 67 | std::cout << "Info: processing string table section" << std::endl; 68 | size_t index = 1; 69 | while ( index < s->get_size() ) { 70 | auto str = std::string( s->get_data() + index ); 71 | // For the example purpose, we rename main function name only 72 | if ( str == "main" ) 73 | overwrite_data( filename, s->get_offset() + index, str ); 74 | index += str.length() + 1; 75 | } 76 | } 77 | 78 | int main( int argc, char** argv ) 79 | { 80 | if ( argc != 2 ) { 81 | std::cout << "Usage: anonymizer \n"; 82 | return 1; 83 | } 84 | 85 | std::string filename = argv[1]; 86 | 87 | elfio reader; 88 | 89 | if ( !reader.load( filename ) ) { 90 | std::cerr << "File " << filename 91 | << " is not found or it is not an ELF file\n"; 92 | return 1; 93 | } 94 | 95 | for ( const auto& section : reader.sections ) { 96 | if ( section->get_type() == SHT_STRTAB && 97 | std::string( section->get_name() ) == std::string( ".strtab" ) ) { 98 | process_string_table( section.get(), filename ); 99 | } 100 | } 101 | return 0; 102 | } 103 | -------------------------------------------------------------------------------- /examples/arion/arion.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2025-present by Serge Lamikhov-Center 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | //------------------------------------------------------------------------------ 24 | // arion.cpp 25 | // 26 | // This example demonstrates how to use the ARIO library to inspect and list the 27 | // contents of a UNIX archive (.ar) file. It provides a simple command-line tool 28 | // that displays information about each member of the archive, including its name, 29 | // size, file mode, and any associated symbols. 30 | // 31 | // Purpose: 32 | // - Showcase ARIO’s API for reading and iterating over archive members. 33 | // - Provide a minimal example for archive inspection and symbol listing. 34 | // 35 | // Abilities: 36 | // - Loads and parses a specified archive file. 37 | // - Lists all members with their names, sizes, and file modes. 38 | // - Displays symbols associated with each member, if available. 39 | // - Command-line interface: Accepts the archive file name as an argument. 40 | // 41 | // This example serves as a reference for basic ARIO usage and as a foundation 42 | // for building custom archive inspection tools. 43 | //------------------------------------------------------------------------------ 44 | 45 | #include 46 | #include 47 | 48 | using namespace ARIO; 49 | 50 | int main( int argc, char** argv ) 51 | { 52 | if ( argc != 2 ) { 53 | std::cout << "Usage: arion " << std::endl; 54 | return 1; 55 | } 56 | 57 | ario archive; 58 | 59 | const auto result = archive.load( argv[1] ); 60 | if ( !result.ok() ) { 61 | std::cerr << "Error loading archive: " << result.what() << std::endl; 62 | return 1; 63 | } 64 | 65 | for ( const auto& member : archive.members ) { 66 | std::cout << "Member: " << std::setw( 40 ) << std::left << member.name 67 | << " Size: " << std::setw( 8 ) << std::right << member.size 68 | << " Mode: " << std::setw( 3 ) << std::oct << member.mode 69 | << std::dec << std::endl; 70 | std::vector symbols; 71 | if ( archive.get_symbols_for_member( member, symbols ).ok() ) { 72 | auto first_time = true; 73 | for ( const auto& symbol : symbols ) { 74 | if ( first_time ) { 75 | std::cout << " "; 76 | first_time = false; 77 | } 78 | else { 79 | std::cout << ", "; 80 | } 81 | std::cout << symbol; 82 | } 83 | if ( !first_time ) { 84 | std::cout << std::endl; 85 | } 86 | } 87 | } 88 | 89 | return 0; 90 | } 91 | -------------------------------------------------------------------------------- /examples/proc_mem/proc_mem.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2001-present by Serge Lamikhov-Center 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | using namespace ELFIO; 32 | 33 | //------------------------------------------------------------------------------ 34 | void get_translation_ranges( std::ifstream& proc_maps, 35 | const std::string& file_name, 36 | std::vector& result ) 37 | { 38 | result.clear(); 39 | 40 | const std::regex rexpr( 41 | "([0-9A-Fa-f]+)-([0-9A-Fa-f]+) ([-r]...) ([0-9A-Fa-f]+) (.....) " 42 | "([0-9]+)([[:blank:]]*)([[:graph:]]*)" ); 43 | std::smatch match; 44 | while ( proc_maps ) { 45 | std::string line; 46 | std::getline( proc_maps, line ); 47 | 48 | if ( std::regex_match( line, match, rexpr ) ) { 49 | if ( match.size() == 9 && match[8].str() == file_name ) { 50 | unsigned long start = std::stoul( match[1].str(), 0, 16 ); 51 | unsigned long end = std::stoul( match[2].str(), 0, 16 ); 52 | unsigned long actual = std::stoul( match[4].str(), 0, 16 ); 53 | result.emplace_back( actual, end - start, start ); 54 | } 55 | } 56 | } 57 | } 58 | 59 | //------------------------------------------------------------------------------ 60 | int main( int argc, char** argv ) 61 | { 62 | if ( argc != 3 ) { 63 | std::cout << "Usage: proc_mem " << std::endl; 64 | return 1; 65 | } 66 | 67 | // Process file translation regions for the ELF file from /proc/pid/maps 68 | std::ifstream proc_maps( std::string( "/proc/" ) + argv[1] + "/maps" ); 69 | if ( !proc_maps ) { 70 | std::cout << "Can't open " 71 | << std::string( "/proc/" ) + argv[1] + "/maps" << " file" 72 | << std::endl; 73 | return 2; 74 | } 75 | 76 | // Retrieve memory address translation ranges 77 | std::vector ranges; 78 | get_translation_ranges( proc_maps, argv[2], ranges ); 79 | 80 | // Set address translation ranges prior loading ELF file 81 | elfio elffile; 82 | elffile.set_address_translation( ranges ); 83 | 84 | // The 'load' will use the provided address translation now 85 | if ( elffile.load( std::string( "/proc/" ) + argv[1] + "/mem", true ) ) { 86 | dump::header( std::cout, elffile ); 87 | dump::segment_headers( std::cout, elffile ); 88 | dump::segment_datas( std::cout, elffile ); 89 | } 90 | else { 91 | std::cout << "Can't open " << std::string( "/proc/" ) + argv[1] + "/mem" 92 | << " file" << std::endl; 93 | } 94 | 95 | return 0; 96 | } 97 | -------------------------------------------------------------------------------- /examples/tutorial/tutorial.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2001-present by Serge Lamikhov-Center 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | using namespace ELFIO; 27 | 28 | int main( int argc, char** argv ) 29 | { 30 | if ( argc != 2 ) { 31 | std::cout << "Usage: tutorial " << std::endl; 32 | return 1; 33 | } 34 | 35 | // Create an elfio reader 36 | elfio reader; 37 | 38 | // Load ELF data 39 | if ( !reader.load( argv[1] ) ) { 40 | std::cout << "Can't find or process ELF file " << argv[1] << std::endl; 41 | return 2; 42 | } 43 | 44 | // Print ELF file properties 45 | std::cout << "ELF file class : "; 46 | if ( reader.get_class() == ELFCLASS32 ) 47 | std::cout << "ELF32" << std::endl; 48 | else 49 | std::cout << "ELF64" << std::endl; 50 | 51 | std::cout << "ELF file encoding : "; 52 | if ( reader.get_encoding() == ELFDATA2LSB ) 53 | std::cout << "Little endian" << std::endl; 54 | else 55 | std::cout << "Big endian" << std::endl; 56 | 57 | // Print ELF file sections info 58 | Elf_Half sec_num = reader.sections.size(); 59 | std::cout << "Number of sections: " << sec_num << std::endl; 60 | for ( int i = 0; i < sec_num; ++i ) { 61 | section* psec = reader.sections[i]; 62 | std::cout << " [" << i << "] " << psec->get_name() << "\t" 63 | << psec->get_size() << std::endl; 64 | // Access to section's data 65 | // const char* p = reader.sections[i]->get_data() 66 | } 67 | 68 | // Print ELF file segments info 69 | Elf_Half seg_num = reader.segments.size(); 70 | std::cout << "Number of segments: " << seg_num << std::endl; 71 | for ( int i = 0; i < seg_num; ++i ) { 72 | const segment* pseg = reader.segments[i]; 73 | std::cout << " [" << i << "] 0x" << std::hex << pseg->get_flags() 74 | << "\t0x" << pseg->get_virtual_address() << "\t0x" 75 | << pseg->get_file_size() << "\t0x" << pseg->get_memory_size() 76 | << std::endl; 77 | // Access to segments's data 78 | // const char* p = reader.segments[i]->get_data() 79 | } 80 | 81 | for ( int i = 0; i < sec_num; ++i ) { 82 | section* psec = reader.sections[i]; 83 | // Check section type 84 | if ( psec->get_type() == SHT_SYMTAB ) { 85 | const symbol_section_accessor symbols( reader, psec ); 86 | for ( unsigned int j = 0; j < symbols.get_symbols_num(); ++j ) { 87 | std::string name; 88 | Elf64_Addr value; 89 | Elf_Xword size; 90 | unsigned char bind; 91 | unsigned char type; 92 | Elf_Half section_index; 93 | unsigned char other; 94 | 95 | // Read symbol properties 96 | symbols.get_symbol( j, name, value, size, bind, type, 97 | section_index, other ); 98 | std::cout << j << " " << name << " " << value << std::endl; 99 | } 100 | } 101 | } 102 | 103 | return 0; 104 | } 105 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Run ELFIO Tests", 9 | "type": "cppdbg", 10 | "request": "launch", 11 | "program": "${workspaceFolder}/build/tests/ELFIOTest", 12 | "args": [ 13 | //"--gtest_filter=ELFIOTest.load32", 14 | ], 15 | "stopAtEntry": false, 16 | "cwd": "${workspaceFolder}/build/tests", 17 | "environment": [], 18 | "externalConsole": false, 19 | "MIMode": "gdb", 20 | "setupCommands": [ 21 | { 22 | "description": "Enable pretty-printing for gdb", 23 | "text": "-enable-pretty-printing", 24 | "ignoreFailures": true 25 | } 26 | ], 27 | //"preLaunchTask": "ELFIO Test build", 28 | "miDebuggerPath": "/usr/bin/gdb" 29 | }, 30 | { 31 | "name": "Run ELFIO Tests (Windows)", 32 | "type": "cppvsdbg", 33 | "request": "launch", 34 | "program": "${workspaceFolder}/build/tests/Debug/ELFIOTest.exe", 35 | "args": [], 36 | "stopAtEntry": false, 37 | "cwd": "${workspaceFolder}/build/tests", 38 | "environment": [], 39 | "console": "externalTerminal" 40 | }, 41 | { 42 | "name": "arioso (Windows)", 43 | "type": "cppvsdbg", 44 | "request": "launch", 45 | "program": "${workspaceFolder}/build/examples/arioso/Debug/arioso.exe", 46 | "args": ["${workspaceFolder}/build/tests/ario/simple_text.a", "-e", "hello.c", "-d", "hello.c", "-a", "hello.c"], 47 | "stopAtEntry": false, 48 | "cwd": "${workspaceFolder}/build/examples/arioso", 49 | "environment": [], 50 | "console": "externalTerminal" 51 | }, 52 | { 53 | "name": "Run ELF Dump", 54 | "type": "cppdbg", 55 | "request": "launch", 56 | "program": "${workspaceFolder}/build/examples/elfdump/elfdump", 57 | "args": ["build/tests/crash-de896e9e31bf6f4c540e7462ccc0440018e4f0de"], 58 | "stopAtEntry": false, 59 | "cwd": "${workspaceFolder}", 60 | "environment": [], 61 | "externalConsole": false, 62 | "MIMode": "gdb", 63 | "setupCommands": [ 64 | { 65 | "description": "Enable pretty-printing for gdb", 66 | "text": "-enable-pretty-printing", 67 | "ignoreFailures": true 68 | } 69 | ], 70 | "preLaunchTask": "ELF Dump Build", 71 | "miDebuggerPath": "/usr/bin/gdb" 72 | }, 73 | { 74 | "name": "Run proc_mem", 75 | "type": "cppdbg", 76 | "request": "launch", 77 | "program": "${workspaceFolder}/build/examples/proc_mem/proc_mem", 78 | "args": ["11706", "/usr/bin/bash"], 79 | "stopAtEntry": false, 80 | "cwd": "${workspaceFolder}", 81 | "environment": [], 82 | "externalConsole": false, 83 | "MIMode": "gdb", 84 | "setupCommands": [ 85 | { 86 | "description": "Enable pretty-printing for gdb", 87 | "text": "-enable-pretty-printing", 88 | "ignoreFailures": true 89 | } 90 | ], 91 | "miDebuggerPath": "/home/user/ELFIO/examples/sudo_gdb.sh" 92 | }, 93 | { 94 | "name": "Run dump for /proc/kcore", 95 | "type": "cppdbg", 96 | "request": "launch", 97 | "program": "${workspaceFolder}/build/examples/elfdump/elfdump", 98 | "args": ["/proc/kcore"], 99 | "stopAtEntry": false, 100 | "cwd": "${workspaceFolder}", 101 | "environment": [], 102 | "externalConsole": false, 103 | "MIMode": "gdb", 104 | "setupCommands": [ 105 | { 106 | "description": "Enable pretty-printing for gdb", 107 | "text": "-enable-pretty-printing", 108 | "ignoreFailures": true 109 | } 110 | ], 111 | "miDebuggerPath": "/home/user/ELFIO/examples/sudo_gdb.sh" 112 | }, 113 | { 114 | "name": "Fuzzer", 115 | "type": "lldb", 116 | "request": "launch", 117 | "program": "${workspaceFolder}/build/tests/elfio_fuzzer", 118 | "args": ["crash-7143f5e49745dc6ce8909e642f9351d9d6496020"], 119 | "cwd": "${workspaceFolder}/build/tests" 120 | } 121 | ] 122 | } 123 | -------------------------------------------------------------------------------- /tests/elf_examples/hello_64_o.txt: -------------------------------------------------------------------------------- 1 | ELF Header: 2 | Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 3 | Class: ELF64 4 | Data: 2's complement, little endian 5 | Version: 1 (current) 6 | OS/ABI: UNIX - System V 7 | ABI Version: 0 8 | Type: REL (Relocatable file) 9 | Machine: Advanced Micro Devices X86-64 10 | Version: 0x1 11 | Entry point address: 0x0 12 | Start of program headers: 0 (bytes into file) 13 | Start of section headers: 296 (bytes into file) 14 | Flags: 0x0 15 | Size of this header: 64 (bytes) 16 | Size of program headers: 0 (bytes) 17 | Number of program headers: 0 18 | Size of section headers: 64 (bytes) 19 | Number of section headers: 13 20 | Section header string table index: 10 21 | 22 | Section Headers: 23 | [Nr] Name Type Address Offset 24 | Size EntSize Flags Link Info Align 25 | [ 0] NULL 0000000000000000 00000000 26 | 0000000000000000 0000000000000000 0 0 0 27 | [ 1] .text PROGBITS 0000000000000000 00000040 28 | 0000000000000015 0000000000000000 AX 0 0 4 29 | [ 2] .rela.text RELA 0000000000000000 00000588 30 | 0000000000000030 0000000000000018 11 1 8 31 | [ 3] .data PROGBITS 0000000000000000 00000058 32 | 0000000000000000 0000000000000000 WA 0 0 4 33 | [ 4] .bss NOBITS 0000000000000000 00000058 34 | 0000000000000000 0000000000000000 WA 0 0 4 35 | [ 5] .rodata PROGBITS 0000000000000000 00000058 36 | 0000000000000006 0000000000000000 A 0 0 1 37 | [ 6] .eh_frame PROGBITS 0000000000000000 00000060 38 | 0000000000000038 0000000000000000 A 0 0 8 39 | [ 7] .rela.eh_frame RELA 0000000000000000 000005b8 40 | 0000000000000018 0000000000000018 11 6 8 41 | [ 8] .comment PROGBITS 0000000000000000 00000098 42 | 000000000000002e 0000000000000000 0 0 1 43 | [ 9] .note.GNU-stack PROGBITS 0000000000000000 000000c6 44 | 0000000000000000 0000000000000000 0 0 1 45 | [10] .shstrtab STRTAB 0000000000000000 000000c6 46 | 0000000000000061 0000000000000000 0 0 1 47 | [11] .symtab SYMTAB 0000000000000000 00000468 48 | 0000000000000108 0000000000000018 12 9 8 49 | [12] .strtab STRTAB 0000000000000000 00000570 50 | 0000000000000013 0000000000000000 0 0 1 51 | Key to Flags: 52 | W (write), A (alloc), X (execute), M (merge), S (strings) 53 | I (info), L (link order), G (group), x (unknown) 54 | O (extra OS processing required) o (OS specific), p (processor specific) 55 | 56 | There are no section groups in this file. 57 | 58 | There are no program headers in this file. 59 | 60 | Relocation section '.rela.text' at offset 0x588 contains 2 entries: 61 | Offset Info Type Sym. Value Sym. Name + Addend 62 | 000000000005 00050000000a R_X86_64_32 0000000000000000 .rodata + 0 63 | 00000000000a 000a00000002 R_X86_64_PC32 0000000000000000 puts + fffffffffffffffc 64 | 65 | Relocation section '.rela.eh_frame' at offset 0x5b8 contains 1 entries: 66 | Offset Info Type Sym. Value Sym. Name + Addend 67 | 000000000020 00020000000a R_X86_64_32 0000000000000000 .text + 0 68 | 69 | There are no unwind sections in this file. 70 | 71 | Symbol table '.symtab' contains 11 entries: 72 | Num: Value Size Type Bind Vis Ndx Name 73 | 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 74 | 1: 0000000000000000 0 FILE LOCAL DEFAULT ABS hello.c 75 | 2: 0000000000000000 0 SECTION LOCAL DEFAULT 1 76 | 3: 0000000000000000 0 SECTION LOCAL DEFAULT 3 77 | 4: 0000000000000000 0 SECTION LOCAL DEFAULT 4 78 | 5: 0000000000000000 0 SECTION LOCAL DEFAULT 5 79 | 6: 0000000000000000 0 SECTION LOCAL DEFAULT 6 80 | 7: 0000000000000000 0 SECTION LOCAL DEFAULT 9 81 | 8: 0000000000000000 0 SECTION LOCAL DEFAULT 8 82 | 9: 0000000000000000 21 FUNC GLOBAL DEFAULT 1 main 83 | 10: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND puts 84 | 85 | No version information found in this file. 86 | -------------------------------------------------------------------------------- /elfio/elfio_array.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2001-present by Serge Lamikhov-Center 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef ELFIO_ARRAY_HPP 24 | #define ELFIO_ARRAY_HPP 25 | 26 | #include 27 | 28 | namespace ELFIO { 29 | 30 | //------------------------------------------------------------------------------ 31 | // Template class for accessing array sections 32 | template class array_section_accessor_template 33 | { 34 | public: 35 | //------------------------------------------------------------------------------ 36 | // Constructor 37 | explicit array_section_accessor_template( const elfio& elf_file, 38 | S* section ); 39 | 40 | //------------------------------------------------------------------------------ 41 | // Returns the number of entries in the array section 42 | Elf_Xword get_entries_num() const; 43 | 44 | //------------------------------------------------------------------------------ 45 | // Retrieves an entry from the array section 46 | bool get_entry( Elf_Xword index, Elf64_Addr& address ) const; 47 | 48 | //------------------------------------------------------------------------------ 49 | // Adds an entry to the array section 50 | void add_entry( Elf64_Addr address ); 51 | 52 | private: 53 | //------------------------------------------------------------------------------ 54 | // Reference to the ELF file 55 | const elfio& elf_file; 56 | //------------------------------------------------------------------------------ 57 | // Pointer to the array section 58 | S* array_section; 59 | }; 60 | 61 | //------------------------------------------------------------------------------ 62 | // Constructor 63 | template 64 | array_section_accessor_template::array_section_accessor_template( 65 | const elfio& elf_file, S* section ) 66 | : elf_file( elf_file ), array_section( section ) 67 | { 68 | } 69 | 70 | //------------------------------------------------------------------------------ 71 | // Returns the number of entries in the array section 72 | template 73 | Elf_Xword array_section_accessor_template::get_entries_num() const 74 | { 75 | Elf_Xword entry_size = sizeof( T ); 76 | return array_section->get_size() / entry_size; 77 | } 78 | 79 | //------------------------------------------------------------------------------ 80 | // Retrieves an entry from the array section 81 | template 82 | bool array_section_accessor_template::get_entry( 83 | Elf_Xword index, Elf64_Addr& address ) const 84 | { 85 | if ( index >= get_entries_num() ) { // Is index valid 86 | return false; 87 | } 88 | 89 | const auto& convertor = elf_file.get_convertor(); 90 | 91 | const T temp = *reinterpret_cast( array_section->get_data() + 92 | index * sizeof( T ) ); 93 | address = ( *convertor )( temp ); 94 | 95 | return true; 96 | } 97 | 98 | //------------------------------------------------------------------------------ 99 | // Adds an entry to the array section 100 | template 101 | void array_section_accessor_template::add_entry( Elf64_Addr address ) 102 | { 103 | const auto& convertor = elf_file.get_convertor(); 104 | 105 | T temp = ( *convertor )( (T)address ); 106 | array_section->append_data( reinterpret_cast( &temp ), 107 | sizeof( temp ) ); 108 | } 109 | 110 | // Type aliases for array section accessors 111 | template 112 | using array_section_accessor = array_section_accessor_template; 113 | template 114 | using const_array_section_accessor = 115 | array_section_accessor_template; 116 | 117 | } // namespace ELFIO 118 | 119 | #endif // ELFIO_ARRAY_HPP 120 | -------------------------------------------------------------------------------- /examples/writer/writer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2001-present by Serge Lamikhov-Center 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | /* 24 | * This example shows how to create ELF executable file for Linux on x86-64 25 | * 26 | * Instructions: 27 | * 1. Compile and link this file with ELFIO library 28 | * g++ writer.cpp -o writer 29 | * 2. Execute result file writer 30 | * ./writer 31 | * 3. Add executable flag for the output file 32 | * chmod +x hello_x86_64 33 | * 4. Run the result file: 34 | * ./hello_x86_64 35 | */ 36 | 37 | #include 38 | 39 | using namespace ELFIO; 40 | 41 | const Elf64_Addr CODE_ADDR = 0x00401000; 42 | const Elf_Xword PAGE_SIZE = 0x1000; 43 | const Elf64_Addr DATA_ADDR = CODE_ADDR + PAGE_SIZE; 44 | 45 | int main( void ) 46 | { 47 | elfio writer; 48 | 49 | // You can't proceed without this function call! 50 | writer.create( ELFCLASS64, ELFDATA2LSB ); 51 | 52 | writer.set_os_abi( ELFOSABI_LINUX ); 53 | writer.set_type( ET_EXEC ); 54 | writer.set_machine( EM_X86_64 ); 55 | 56 | // Create code section 57 | section* text_sec = writer.sections.add( ".text" ); 58 | text_sec->set_type( SHT_PROGBITS ); 59 | text_sec->set_flags( SHF_ALLOC | SHF_EXECINSTR ); 60 | text_sec->set_addr_align( 0x10 ); 61 | 62 | // Add data into it 63 | char text[] = { 64 | '\xB8', '\x04', '\x00', '\x00', '\x00', // mov eax, 4 65 | '\xBB', '\x01', '\x00', '\x00', '\x00', // mov ebx, 1 66 | '\xB9', '\x00', '\x00', '\x00', '\x00', // mov ecx, msg 67 | '\xBA', '\x0E', '\x00', '\x00', '\x00', // mov edx, 14 68 | '\xCD', '\x80', // int 0x80 69 | '\xB8', '\x01', '\x00', '\x00', '\x00', // mov eax, 1 70 | '\xCD', '\x80' // int 0x80 71 | }; 72 | // Adjust data address for 'msg' 73 | *(std::uint32_t*)( text + 11 ) = DATA_ADDR; 74 | 75 | text_sec->set_data( text, sizeof( text ) ); 76 | 77 | // Create a loadable segment 78 | segment* text_seg = writer.segments.add(); 79 | text_seg->set_type( PT_LOAD ); 80 | text_seg->set_virtual_address( CODE_ADDR ); 81 | text_seg->set_physical_address( CODE_ADDR ); 82 | text_seg->set_flags( PF_X | PF_R ); 83 | text_seg->set_align( PAGE_SIZE ); 84 | 85 | // Add code section into program segment 86 | text_seg->add_section( text_sec, text_sec->get_addr_align() ); 87 | 88 | // Create data section 89 | section* data_sec = writer.sections.add( ".data" ); 90 | data_sec->set_type( SHT_PROGBITS ); 91 | data_sec->set_flags( SHF_ALLOC | SHF_WRITE ); 92 | data_sec->set_addr_align( 0x4 ); 93 | 94 | char data[] = { 95 | '\x48', '\x65', '\x6C', '\x6C', '\x6F', // msg: db 'Hello, World!', 10 96 | '\x2C', '\x20', '\x57', '\x6F', '\x72', 97 | '\x6C', '\x64', '\x21', '\x0A' }; 98 | data_sec->set_data( data, sizeof( data ) ); 99 | 100 | // Create a read/write segment 101 | segment* data_seg = writer.segments.add(); 102 | data_seg->set_type( PT_LOAD ); 103 | data_seg->set_virtual_address( DATA_ADDR ); 104 | data_seg->set_physical_address( DATA_ADDR ); 105 | data_seg->set_flags( PF_W | PF_R ); 106 | data_seg->set_align( PAGE_SIZE ); 107 | 108 | // Add code section into program segment 109 | data_seg->add_section( data_sec, data_sec->get_addr_align() ); 110 | 111 | // Add optional signature for the file producer 112 | section* note_sec = writer.sections.add( ".note" ); 113 | note_sec->set_type( SHT_NOTE ); 114 | note_sec->set_addr_align( 1 ); 115 | 116 | note_section_accessor note_writer( writer, note_sec ); 117 | note_writer.add_note( 0x01, "Created by ELFIO", 0, 0 ); 118 | char descr[6] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36 }; 119 | note_writer.add_note( 0x01, "Never easier!", descr, sizeof( descr ) ); 120 | 121 | // Setup entry point. Usually, a linker sets this address on base of 122 | // ‘_start’ label. 123 | // In this example, the code starts at the first address of the 124 | // 'text_seg' segment. Therefore, the start address is set 125 | // to be equal to the segment location 126 | writer.set_entry( text_seg->get_virtual_address() ); 127 | 128 | // Create ELF file 129 | writer.save( "hello_x86_64" ); 130 | 131 | return 0; 132 | } 133 | -------------------------------------------------------------------------------- /elfio/elfio_strings.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2001-present by Serge Lamikhov-Center 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef ELFIO_STRINGS_HPP 24 | #define ELFIO_STRINGS_HPP 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | namespace ELFIO { 32 | 33 | //------------------------------------------------------------------------------ 34 | //! \class string_section_accessor_template 35 | //! \brief Class for accessing string section data 36 | template class string_section_accessor_template 37 | { 38 | public: 39 | //------------------------------------------------------------------------------ 40 | //! \brief Constructor 41 | //! \param section Pointer to the section 42 | explicit string_section_accessor_template( S* section ) 43 | : string_section( section ) 44 | { 45 | } 46 | 47 | //------------------------------------------------------------------------------ 48 | //! \brief Get a string from the section 49 | //! \param index Index of the string 50 | //! \return Pointer to the string, or nullptr if not found 51 | const char* get_string( Elf_Word index ) const 52 | { 53 | if ( string_section ) { 54 | const char* data = string_section->get_data(); 55 | size_t section_size = 56 | static_cast( string_section->get_size() ); 57 | 58 | // Check if index is within bounds 59 | if ( index >= section_size || nullptr == data ) { 60 | return nullptr; 61 | } 62 | 63 | // Check for integer overflow in size calculation 64 | size_t remaining_size = section_size - index; 65 | if ( remaining_size > section_size ) { // Check for underflow 66 | return nullptr; 67 | } 68 | 69 | // Use standard C++ functions to find string length 70 | const char* str = data + index; 71 | const char* end = 72 | (const char*)std::memchr( str, '\0', remaining_size ); 73 | if ( end != nullptr && end < str + remaining_size ) { 74 | return str; 75 | } 76 | } 77 | 78 | return nullptr; 79 | } 80 | 81 | //------------------------------------------------------------------------------ 82 | //! \brief Add a string to the section 83 | //! \param str Pointer to the string 84 | //! \return Index of the added string 85 | Elf_Word add_string( const char* str ) 86 | { 87 | if ( !str ) { 88 | return 0; // Return index of empty string for null input 89 | } 90 | 91 | Elf_Word current_position = 0; 92 | 93 | if ( string_section ) { 94 | // Strings are added to the end of the current section data 95 | current_position = 96 | static_cast( string_section->get_size() ); 97 | 98 | if ( current_position == 0 ) { 99 | char empty_string = '\0'; 100 | string_section->append_data( &empty_string, 1 ); 101 | current_position++; 102 | } 103 | 104 | // Calculate string length and check for overflow 105 | size_t str_len = std::strlen( str ); 106 | if ( str_len > std::numeric_limits::max() - 1 ) { 107 | return 0; // String too long 108 | } 109 | 110 | // Check if appending would overflow section size 111 | Elf_Word append_size = static_cast( str_len + 1 ); 112 | if ( append_size > 113 | std::numeric_limits::max() - current_position ) { 114 | return 0; // Would overflow section size 115 | } 116 | 117 | string_section->append_data( str, append_size ); 118 | } 119 | 120 | return current_position; 121 | } 122 | 123 | //------------------------------------------------------------------------------ 124 | //! \brief Add a string to the section 125 | //! \param str The string to add 126 | //! \return Index of the added string 127 | Elf_Word add_string( const std::string& str ) 128 | { 129 | return add_string( str.c_str() ); 130 | } 131 | 132 | //------------------------------------------------------------------------------ 133 | private: 134 | S* string_section; //!< Pointer to the section 135 | }; 136 | 137 | using string_section_accessor = string_section_accessor_template
; 138 | using const_string_section_accessor = 139 | string_section_accessor_template; 140 | 141 | } // namespace ELFIO 142 | 143 | #endif // ELFIO_STRINGS_HPP 144 | -------------------------------------------------------------------------------- /examples/write_obj/write_obj.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2001-present by Serge Lamikhov-Center 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | /* 24 | * This example shows how to create ELF object file for Linux on x86 25 | * 26 | * Instructions: 27 | * 1. Compile and link this file with ELFIO library 28 | * g++ write_obj.cpp -o writer_obj 29 | * 2. Execute result file write_obj 30 | * ./write_obj 31 | * 3. Link output file hello.o: 32 | * ld -o hello hello.o 33 | * 4. Run the result file: 34 | * ./hello 35 | */ 36 | 37 | #include 38 | 39 | using namespace ELFIO; 40 | 41 | int main( void ) 42 | { 43 | elfio writer; 44 | 45 | // You can't proceed before this function call! 46 | writer.create( ELFCLASS64, ELFDATA2LSB ); 47 | 48 | writer.set_os_abi( ELFOSABI_LINUX ); 49 | writer.set_type( ET_REL ); 50 | writer.set_machine( EM_X86_64 ); 51 | 52 | // This is our code 53 | char text[] = { 54 | '\xB8', '\x04', '\x00', '\x00', '\x00', // mov eax, 4 55 | '\xBB', '\x01', '\x00', '\x00', '\x00', // mov ebx, 1 56 | '\xB9', '\x00', '\x00', '\x00', '\x00', // mov ecx, msg 57 | '\xBA', '\x0E', '\x00', '\x00', '\x00', // mov edx, 14 58 | '\xCD', '\x80', // int 0x80 59 | '\xB8', '\x01', '\x00', '\x00', '\x00', // mov eax, 1 60 | '\xCD', '\x80', // int 0x80 61 | '\x48', '\x65', '\x6C', '\x6C', '\x6F', // msg: db 'Hello, World!', 10 62 | '\x2C', '\x20', '\x57', '\x6F', '\x72', 63 | '\x6C', '\x64', '\x21', '\x0A' }; 64 | Elf64_Addr place_to_adjust = 11; 65 | 66 | // Create code section 67 | section* text_sec = writer.sections.add( ".text" ); 68 | text_sec->set_type( SHT_PROGBITS ); 69 | text_sec->set_flags( SHF_ALLOC | SHF_EXECINSTR ); 70 | text_sec->set_addr_align( 0x10 ); 71 | text_sec->set_data( text, sizeof( text ) ); 72 | 73 | // Create string table section 74 | section* str_sec = writer.sections.add( ".strtab" ); 75 | str_sec->set_type( SHT_STRTAB ); 76 | 77 | // Create string table writer 78 | string_section_accessor stra( str_sec ); 79 | // Add label name 80 | Elf32_Word str_index = stra.add_string( "msg" ); 81 | 82 | // Create symbol table section 83 | section* sym_sec = writer.sections.add( ".symtab" ); 84 | sym_sec->set_type( SHT_SYMTAB ); 85 | sym_sec->set_info( 1 ); 86 | sym_sec->set_addr_align( 0x4 ); 87 | sym_sec->set_entry_size( writer.get_default_entry_size( SHT_SYMTAB ) ); 88 | sym_sec->set_link( str_sec->get_index() ); 89 | 90 | // Create symbol table writer 91 | symbol_section_accessor syma( writer, sym_sec ); 92 | // Add symbol entry (msg has offset == 29) 93 | Elf_Word sym_to_adjust = syma.add_symbol( 94 | str_index, 29, 0, STB_GLOBAL, STT_OBJECT, 0, text_sec->get_index() ); 95 | // Another way to add symbol 96 | syma.add_symbol( stra, "_start", 0x00000000, 0, STB_WEAK, STT_FUNC, 0, 97 | text_sec->get_index() ); 98 | 99 | // Create relocation table section 100 | section* rel_sec = writer.sections.add( ".rel.text" ); 101 | rel_sec->set_type( SHT_REL ); 102 | rel_sec->set_info( text_sec->get_index() ); 103 | rel_sec->set_addr_align( 0x4 ); 104 | rel_sec->set_entry_size( writer.get_default_entry_size( SHT_REL ) ); 105 | rel_sec->set_link( sym_sec->get_index() ); 106 | 107 | // Create relocation table writer 108 | relocation_section_accessor rela( writer, rel_sec ); 109 | // Add relocation entry (adjust address at offset 11) 110 | rela.add_entry( place_to_adjust, sym_to_adjust, 111 | (unsigned char)R_X86_64_32 ); 112 | 113 | // Another method to add the same relocation entry at one step is: 114 | // rela.add_entry( stra, "msg", 115 | // syma, 29, 0, 116 | // ELF_ST_INFO( STB_GLOBAL, STT_OBJECT ), 0, 117 | // text_sec->get_index(), 118 | // place_to_adjust, (unsigned char)R_386_RELATIVE ); 119 | 120 | // Create note section 121 | section* note_sec = writer.sections.add( ".note" ); 122 | note_sec->set_type( SHT_NOTE ); 123 | 124 | note_section_accessor note_writer( writer, note_sec ); 125 | note_writer.add_note( 0x01, "Created by ELFIO", 0, 0 ); 126 | char descr[6] = { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36 }; 127 | note_writer.add_note( 0x01, "Never easier!", descr, sizeof( descr ) ); 128 | 129 | // We don't use local symbols here. There is no need to rearrange them. 130 | // But, for the completeness, we do this just prior 'save' 131 | syma.arrange_local_symbols( [&]( Elf_Xword first, Elf_Xword second ) { 132 | rela.swap_symbols( first, second ); 133 | } ); 134 | 135 | // Create ELF object file 136 | writer.save( "hello.o" ); 137 | 138 | return 0; 139 | } 140 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | # Detect if we are the top level CMakeLists.txt or are we included in some 4 | # other project 5 | if(NOT DEFINED PROJECT_NAME) 6 | set(IS_TOP_PROJECT TRUE) 7 | endif() 8 | 9 | if(IS_TOP_PROJECT) 10 | # Turn this on in order to build elfio examples 11 | option(ELFIO_BUILD_EXAMPLES "Build ELFIO examples" ON) 12 | 13 | # Turn this on in order to build tests 14 | option(ELFIO_BUILD_TESTS "Build ELFIO tests" OFF) 15 | 16 | # Generate output of compile commands during generation 17 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 18 | endif() 19 | 20 | # Read version from header file 21 | set(version_header "elfio/elfio_version.hpp") 22 | file(READ ${version_header} ver) 23 | string(REGEX MATCH "#define ELFIO_VERSION \"([0-9\.]+)\"" _ ${ver}) 24 | 25 | if(NOT CMAKE_MATCH_1) 26 | message(FATAL_ERROR "Unable to parse version from ${version_header}") 27 | endif() 28 | 29 | set(version ${CMAKE_MATCH_1}) 30 | 31 | # Use configure_file to make configure step depend on elfio_version.hpp 32 | configure_file(${version_header} ${CMAKE_CURRENT_BINARY_DIR}/elfio_version.hpp.copy COPYONLY) 33 | 34 | project(elfio VERSION ${version} LANGUAGES C CXX) 35 | 36 | include(GNUInstallDirs) 37 | 38 | # Create a header only CMake target for elfio 39 | add_library(elfio INTERFACE) 40 | add_library(elfio::elfio ALIAS elfio) 41 | add_library(ario INTERFACE) 42 | add_library(ario::ario ALIAS ario) 43 | 44 | target_include_directories( 45 | elfio 46 | INTERFACE 47 | $ 48 | $) 49 | 50 | target_include_directories( 51 | ario 52 | INTERFACE 53 | $ 54 | $) 55 | 56 | # If this is the top level project, add in logic to install elfio 57 | if(IS_TOP_PROJECT) 58 | # Enable C++17 for examples and tests 59 | if(ELFIO_BUILD_EXAMPLES OR ELFIO_BUILD_TESTS) 60 | set(CMAKE_CXX_STANDARD 17) 61 | endif() 62 | 63 | if(ELFIO_BUILD_EXAMPLES) 64 | # set (CMAKE_CXX_FLAGS "-Wall") 65 | add_subdirectory(examples) 66 | endif() 67 | 68 | if(ELFIO_BUILD_TESTS) 69 | # set (CMAKE_CXX_FLAGS "-Wall") 70 | enable_testing() 71 | add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} USES_TERMINAL) 72 | add_subdirectory(tests) 73 | endif() 74 | 75 | include(CMakePackageConfigHelpers) 76 | 77 | # Create a file that includes the current project version. This will be 78 | # installed with the elfio CMake package. 79 | write_basic_package_version_file( 80 | "${PROJECT_NAME}ConfigVersion.cmake" 81 | VERSION 82 | ${PROJECT_VERSION} 83 | COMPATIBILITY 84 | SameMajorVersion) 85 | 86 | # Create the default ${PROJECT_NAME}Config.cmake file which will be 87 | # installed and found by calls to `find_package(elfio)`. 88 | configure_package_config_file( 89 | "${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in" 90 | "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" 91 | INSTALL_DESTINATION 92 | ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake) 93 | 94 | # Install the previously generated "config" and "version" files 95 | install( 96 | FILES 97 | "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" 98 | "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" 99 | DESTINATION 100 | ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake) 101 | 102 | # Install the entire local `elfio` directory to the include directory 103 | install( 104 | DIRECTORY 105 | elfio 106 | DESTINATION 107 | ${CMAKE_INSTALL_INCLUDEDIR}) 108 | 109 | # Create a ${PROJECT_NAME}Targets.cmake file that is referenced by the 110 | # ${PROJECT_NAME}Config.cmake file and includes the target information 111 | # needed to compile/link against all targets exported under the 112 | # ${PROJECT_NAME}_Targets export 113 | install( 114 | EXPORT 115 | ${PROJECT_NAME}_Targets 116 | FILE 117 | ${PROJECT_NAME}Targets.cmake 118 | NAMESPACE 119 | ${PROJECT_NAME}:: 120 | DESTINATION 121 | ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake) 122 | 123 | # Add the elfio target to the ${PROJECT_NAME}_Targets export 124 | install( 125 | TARGETS 126 | elfio 127 | EXPORT 128 | ${PROJECT_NAME}_Targets) 129 | 130 | # cmake -B build; cmake --build build; cpack --config build/CPackSourceConfig.cmake 131 | # cmake -B build -D ELFIO_BUILD_EXAMPLES=ON -DELFIO_BUILD_TESTS=ON -G Ninja; cmake --build build; cpack --config build/CPackSourceConfig.cmake 132 | set(_fmt TGZ) 133 | 134 | if(WIN32) 135 | set(_fmt ZIP) 136 | endif() 137 | 138 | set(CPACK_GENERATOR ${_fmt}) 139 | set(CPACK_SOURCE_GENERATOR ${_fmt}) 140 | set(CPACK_PACKAGE_VENDOR "ELFIO") 141 | set(CPACK_PACKAGE_CONTACT "Serge Lamikhov-Center") 142 | set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt") 143 | set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md") 144 | set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/package") 145 | set(CPACK_PACKAGE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) 146 | string(TOLOWER ${CMAKE_SYSTEM_NAME} _sys) 147 | string(TOLOWER ${PROJECT_NAME} _project_lower) 148 | set(CPACK_PACKAGE_FILE_NAME "${_project_lower}-${_sys}") 149 | set(CPACK_SOURCE_PACKAGE_FILE_NAME "${_project_lower}-${PROJECT_VERSION}") 150 | 151 | set(CPACK_SOURCE_IGNORE_FILES "/.git.*;/.vs.*;/build;/.clang-format;/doc/site;/doc/elfio.docx;/doc/images/callouts/;/doc/images/colorsvg/;/doc/images/res2/;/doc/images/.*\.svg;/doc/images/.*\.gif;/doc/images/[^/]*\.png$;/doc/images/.*\.tif;/examples/sudo_gdb.sh;/tests") 152 | 153 | install(FILES ${CPACK_RESOURCE_FILE_README} ${CPACK_RESOURCE_FILE_LICENSE} 154 | DESTINATION share/docs/${PROJECT_NAME}) 155 | 156 | include(CPack) 157 | endif() 158 | -------------------------------------------------------------------------------- /elfio/elfio_modinfo.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2001-present by Serge Lamikhov-Center 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef ELFIO_MODINFO_HPP 24 | #define ELFIO_MODINFO_HPP 25 | 26 | #include 27 | #include 28 | 29 | namespace ELFIO { 30 | 31 | //------------------------------------------------------------------------------ 32 | /** 33 | * @class modinfo_section_accessor_template 34 | * @brief A template class to access modinfo section. 35 | * 36 | * @tparam S The section type. 37 | */ 38 | template class modinfo_section_accessor_template 39 | { 40 | public: 41 | //------------------------------------------------------------------------------ 42 | /** 43 | * @brief Construct a new modinfo section accessor template object. 44 | * 45 | * @param section The section to be accessed. 46 | */ 47 | explicit modinfo_section_accessor_template( S* section ) 48 | : modinfo_section( section ) 49 | { 50 | process_section(); 51 | } 52 | 53 | //------------------------------------------------------------------------------ 54 | /** 55 | * @brief Get the number of attributes. 56 | * 57 | * @return Elf_Word The number of attributes. 58 | */ 59 | Elf_Word get_attribute_num() const { return (Elf_Word)content.size(); } 60 | 61 | //------------------------------------------------------------------------------ 62 | /** 63 | * @brief Get the attribute by index. 64 | * 65 | * @param no The index of the attribute. 66 | * @param field The field name of the attribute. 67 | * @param value The value of the attribute. 68 | * @return true If the attribute is found. 69 | * @return false If the attribute is not found. 70 | */ 71 | bool 72 | get_attribute( Elf_Word no, std::string& field, std::string& value ) const 73 | { 74 | if ( no < content.size() ) { 75 | field = content[no].first; 76 | value = content[no].second; 77 | return true; 78 | } 79 | 80 | return false; 81 | } 82 | 83 | //------------------------------------------------------------------------------ 84 | /** 85 | * @brief Get the attribute by field name. 86 | * 87 | * @param field_name The field name of the attribute. 88 | * @param value The value of the attribute. 89 | * @return true If the attribute is found. 90 | * @return false If the attribute is not found. 91 | */ 92 | bool get_attribute( const std::string_view& field_name, 93 | std::string& value ) const 94 | { 95 | for ( const auto& [first, second] : content ) { 96 | if ( field_name == first ) { 97 | value = second; 98 | return true; 99 | } 100 | } 101 | 102 | return false; 103 | } 104 | 105 | //------------------------------------------------------------------------------ 106 | /** 107 | * @brief Add a new attribute. 108 | * 109 | * @param field The field name of the attribute. 110 | * @param value The value of the attribute. 111 | * @return Elf_Word The position of the new attribute. 112 | */ 113 | Elf_Word add_attribute( const std::string& field, const std::string& value ) 114 | { 115 | Elf_Word current_position = 0; 116 | 117 | if ( modinfo_section ) { 118 | // Strings are addeded to the end of the current section data 119 | current_position = (Elf_Word)modinfo_section->get_size(); 120 | 121 | std::string attribute = field + "=" + value; 122 | 123 | modinfo_section->append_data( attribute + '\0' ); 124 | content.emplace_back( field, value ); 125 | } 126 | 127 | return current_position; 128 | } 129 | 130 | //------------------------------------------------------------------------------ 131 | private: 132 | /** 133 | * @brief Process the section to extract attributes. 134 | */ 135 | void process_section() 136 | { 137 | const char* pdata = modinfo_section->get_data(); 138 | if ( pdata ) { 139 | ELFIO::Elf_Xword i = 0; 140 | while ( i < modinfo_section->get_size() ) { 141 | while ( i < modinfo_section->get_size() && !pdata[i] ) 142 | i++; 143 | if ( i < modinfo_section->get_size() ) { 144 | std::string info = pdata + i; 145 | size_t loc = info.find( '=' ); 146 | content.emplace_back( info.substr( 0, loc ), 147 | info.substr( loc + 1 ) ); 148 | 149 | i += info.length(); 150 | } 151 | } 152 | } 153 | } 154 | 155 | //------------------------------------------------------------------------------ 156 | private: 157 | S* modinfo_section; ///< The section to be accessed. 158 | std::vector> 159 | content; ///< The list of attributes. 160 | }; 161 | 162 | using modinfo_section_accessor = modinfo_section_accessor_template
; 163 | using const_modinfo_section_accessor = 164 | modinfo_section_accessor_template; 165 | 166 | } // namespace ELFIO 167 | 168 | #endif // ELFIO_MODINFO_HPP 169 | -------------------------------------------------------------------------------- /tests/elf_examples/test_ppc_o.txt: -------------------------------------------------------------------------------- 1 | ELF Header: 2 | Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00 3 | Class: ELF32 4 | Data: 2's complement, big endian 5 | Version: 1 (current) 6 | OS/ABI: UNIX - System V 7 | ABI Version: 0 8 | Type: REL (Relocatable file) 9 | Machine: PowerPC 10 | Version: 0x1 11 | Entry point address: 0x0 12 | Start of program headers: 0 (bytes into file) 13 | Start of section headers: 616 (bytes into file) 14 | Flags: 0x0 15 | Size of this header: 52 (bytes) 16 | Size of program headers: 0 (bytes) 17 | Number of program headers: 0 18 | Size of section headers: 40 (bytes) 19 | Number of section headers: 16 20 | Section header string table index: 13 21 | 22 | Section Headers: 23 | [Nr] Name Type Addr Off Size ES Flg Lk Inf Al 24 | [ 0] NULL 00000000 000000 000000 00 0 0 0 25 | [ 1] .text PROGBITS 00000000 000034 000118 00 AX 0 0 4 26 | [ 2] .rela.text RELA 00000000 0007b8 0000d8 0c 14 1 4 27 | [ 3] .data PROGBITS 00000000 00014c 000000 00 WA 0 0 1 28 | [ 4] .bss NOBITS 00000000 00014c 000001 00 WA 0 0 1 29 | [ 5] .rodata PROGBITS 00000000 00014c 000006 00 A 0 0 4 30 | [ 6] .ctors PROGBITS 00000000 000154 000004 00 WA 0 0 4 31 | [ 7] .rela.ctors RELA 00000000 000890 00000c 0c 14 6 4 32 | [ 8] .eh_frame PROGBITS 00000000 000158 000058 00 A 0 0 4 33 | [ 9] .rela.eh_frame RELA 00000000 00089c 000024 0c 14 8 4 34 | [10] .comment PROGBITS 00000000 0001b0 000027 00 0 0 1 35 | [11] .note.GNU-stack PROGBITS 00000000 0001d7 000000 00 0 0 1 36 | [12] .gnu.attributes LOOS+ffffff5 00000000 0001d7 000014 00 0 0 1 37 | [13] .shstrtab STRTAB 00000000 0001eb 00007d 00 0 0 1 38 | [14] .symtab SYMTAB 00000000 0004e8 000180 10 15 14 4 39 | [15] .strtab STRTAB 00000000 000668 00014f 00 0 0 1 40 | Key to Flags: 41 | W (write), A (alloc), X (execute), M (merge), S (strings) 42 | I (info), L (link order), G (group), x (unknown) 43 | O (extra OS processing required) o (OS specific), p (processor specific) 44 | 45 | There are no section groups in this file. 46 | 47 | There are no program headers in this file. 48 | 49 | Relocation section '.rela.text' at offset 0x7b8 contains 18 entries: 50 | Offset Info Type Sym.Value Sym. Name + Addend 51 | 00000016 00000f06 R_PPC_ADDR16_HA 00000000 _ZSt4cout + 0 52 | 0000001a 00000f04 R_PPC_ADDR16_LO 00000000 _ZSt4cout + 0 53 | 0000001e 00000506 R_PPC_ADDR16_HA 00000000 .rodata + 0 54 | 00000022 00000504 R_PPC_ADDR16_LO 00000000 .rodata + 0 55 | 00000024 0000100a R_PPC_REL24 00000000 _ZStlsISt11char_traits + 0 56 | 00000032 00001106 R_PPC_ADDR16_HA 00000000 _ZSt4endlIcSt11char_tr + 0 57 | 00000036 00001104 R_PPC_ADDR16_LO 00000000 _ZSt4endlIcSt11char_tr + 0 58 | 00000038 0000120a R_PPC_REL24 00000000 _ZNSolsEPFRSoS_E + 0 59 | 0000009a 00000406 R_PPC_ADDR16_HA 00000000 .bss + 0 60 | 0000009e 00000404 R_PPC_ADDR16_LO 00000000 .bss + 0 61 | 000000a0 0000130a R_PPC_REL24 00000000 _ZNSt8ios_base4InitC1E + 0 62 | 000000a6 00001406 R_PPC_ADDR16_HA 00000000 _ZNSt8ios_base4InitD1E + 0 63 | 000000aa 00001404 R_PPC_ADDR16_LO 00000000 _ZNSt8ios_base4InitD1E + 0 64 | 000000b2 00000406 R_PPC_ADDR16_HA 00000000 .bss + 0 65 | 000000b6 00000404 R_PPC_ADDR16_LO 00000000 .bss + 0 66 | 000000ba 00001506 R_PPC_ADDR16_HA 00000000 __dso_handle + 0 67 | 000000be 00001504 R_PPC_ADDR16_LO 00000000 __dso_handle + 0 68 | 000000c0 0000160a R_PPC_REL24 00000000 __cxa_atexit + 0 69 | 70 | Relocation section '.rela.ctors' at offset 0x890 contains 1 entries: 71 | Offset Info Type Sym.Value Sym. Name + Addend 72 | 00000000 00000201 R_PPC_ADDR32 00000000 .text + dc 73 | 74 | Relocation section '.rela.eh_frame' at offset 0x89c contains 3 entries: 75 | Offset Info Type Sym.Value Sym. Name + Addend 76 | 00000011 00001701 R_PPC_ADDR32 00000000 __gxx_personality_v0 + 0 77 | 00000020 00000201 R_PPC_ADDR32 00000000 .text + 0 78 | 00000040 00000201 R_PPC_ADDR32 00000000 .text + 5c 79 | 80 | There are no unwind sections in this file. 81 | 82 | Symbol table '.symtab' contains 24 entries: 83 | Num: Value Size Type Bind Vis Ndx Name 84 | 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 85 | 1: 00000000 0 FILE LOCAL DEFAULT ABS test_ppc.cpp 86 | 2: 00000000 0 SECTION LOCAL DEFAULT 1 87 | 3: 00000000 0 SECTION LOCAL DEFAULT 3 88 | 4: 00000000 0 SECTION LOCAL DEFAULT 4 89 | 5: 00000000 0 SECTION LOCAL DEFAULT 5 90 | 6: 0000005c 128 FUNC LOCAL DEFAULT 1 _Z41__static_initializati 91 | 7: 00000000 1 OBJECT LOCAL DEFAULT 4 _ZStL8__ioinit 92 | 8: 000000dc 60 FUNC LOCAL DEFAULT 1 _GLOBAL__I_main 93 | 9: 00000000 0 SECTION LOCAL DEFAULT 6 94 | 10: 00000000 0 SECTION LOCAL DEFAULT 8 95 | 11: 00000000 0 SECTION LOCAL DEFAULT 11 96 | 12: 00000000 0 SECTION LOCAL DEFAULT 10 97 | 13: 00000000 0 SECTION LOCAL DEFAULT 12 98 | 14: 00000000 92 FUNC GLOBAL DEFAULT 1 main 99 | 15: 00000000 0 NOTYPE GLOBAL DEFAULT UND _ZSt4cout 100 | 16: 00000000 0 NOTYPE GLOBAL DEFAULT UND _ZStlsISt11char_traitsIcE 101 | 17: 00000000 0 NOTYPE GLOBAL DEFAULT UND _ZSt4endlIcSt11char_trait 102 | 18: 00000000 0 NOTYPE GLOBAL DEFAULT UND _ZNSolsEPFRSoS_E 103 | 19: 00000000 0 NOTYPE GLOBAL DEFAULT UND _ZNSt8ios_base4InitC1Ev 104 | 20: 00000000 0 NOTYPE GLOBAL DEFAULT UND _ZNSt8ios_base4InitD1Ev 105 | 21: 00000000 0 NOTYPE GLOBAL DEFAULT UND __dso_handle 106 | 22: 00000000 0 NOTYPE GLOBAL DEFAULT UND __cxa_atexit 107 | 23: 00000000 0 NOTYPE GLOBAL DEFAULT UND __gxx_personality_v0 108 | 109 | No version information found in this file. 110 | Attribute Section: gnu 111 | File Attributes 112 | Tag_GNU_Power_ABI_FP: Hard float 113 | Tag_GNU_Power_ABI_Vector: Generic 114 | Tag_GNU_Power_ABI_Struct_Return: Memory 115 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # ![ELFIO Logo](doc/images/res/20231119165006-100.png "ELFIO") ![ELFIO Title](doc/images/res/title.png "ELFIO") 3 | 4 | ![C/C++ CI](https://github.com/serge1/ELFIO/workflows/C/C++%20CI/badge.svg) 5 | ![CodeQL](https://github.com/serge1/ELFIO/workflows/CodeQL/badge.svg) 6 | [![Documentation](https://img.shields.io/badge/doc-download-brightgreen)](http://elfio.sourceforge.net/elfio.pdf) 7 | [![License](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://github.com/serge1/ELFIO/blob/master/COPYING) 8 | 9 | --- 10 | 11 | ## Table of Contents 12 | 13 | - [Overview](#overview) 14 | - [ELFIO: ELF Object and Executable File Reader/Writer](#elfio-elf-object-and-executable-file-readerwriter) 15 | - [ARIO: Advanced Archive Input/Output Library](#ario-advanced-archive-inputoutput-library) 16 | - [Who Uses ELFIO & ARIO?](#who-uses-elfio--ario) 17 | - [Installation](#installation) 18 | - [Getting Started](#getting-started) 19 | - [Project Structure](#project-structure) 20 | - [Examples](#examples) 21 | - [Support](#support) 22 | - [Contributing](#contributing) 23 | - [License](#license) 24 | - [Resources](#resources) 25 | 26 | --- 27 | 28 | ## Overview 29 | 30 | **ELFIO** and **ARIO** are robust, header-only C++ libraries designed to make binary file and archive manipulation effortless, efficient, and portable. Whether you are building compilers, linkers, binary analysis tools, or custom build systems, these libraries provide the foundation you need for working with ELF files and UNIX archives. 31 | 32 | --- 33 | 34 | ## ELFIO: ELF Object and Executable File Reader/Writer 35 | 36 | **ELFIO** is a lightweight, header-only C++ library for reading and generating ELF (Executable and Linkable Format) binary files. It is completely standalone, requiring no external dependencies, and integrates seamlessly into any C++ project. Built to ISO C++ standards, ELFIO ensures compatibility across a wide range of architectures and compilers. 37 | 38 | **Key Features:** 39 | 40 | - **Header-only:** Just include the header files—no need to build or link external libraries. 41 | - **No dependencies:** Pure C++ implementation. 42 | - **Cross-platform:** Works on Windows, Linux, and macOS. 43 | - **Comprehensive ELF support:** Read, create, and modify ELF files, including sections, segments, and symbols. 44 | - **Easy integration:** Designed for both small utilities and large-scale applications. 45 | - **Actively maintained:** Trusted by open-source and commercial projects worldwide. 46 | 47 | > 📖 Comprehensive documentation is available in the [ELFIO - Tutorial and User Manual (PDF)](http://elfio.sourceforge.net/elfio.pdf). 48 | 49 | --- 50 | 51 | ## ARIO: Advanced Archive Input/Output Library 52 | 53 | **ARIO** is a modern, high-performance, header-only C++ library for reading, creating, and modifying UNIX `ar` archive files (commonly used for static libraries). ARIO is designed to work seamlessly with ELFIO, providing a unified and intuitive interface for archive manipulation and binary data management. 54 | 55 | **Why Choose ARIO?** 56 | 57 | - **Header-only:** Effortless integration—just include `ario.hpp` in your project. 58 | - **Zero dependencies:** No need for external libraries or build steps. 59 | - **Universal access:** Read and write to files, memory, and custom streams. 60 | - **Cross-platform:** Consistent behavior on Windows, Linux, and macOS. 61 | - **Optimized for performance:** Minimal overhead for high-throughput applications. 62 | - **Seamless ELFIO integration:** Easily combine ELF and archive operations in your toolchain. 63 | - **Intuitive API:** Designed for productivity and ease of use. 64 | 65 | **Typical Use Cases:** 66 | 67 | - Building and modifying static libraries (`.a` files) 68 | - Extracting or replacing object files within archives 69 | - Analyzing and manipulating symbol tables in archives 70 | - Custom build tools and binary utilities 71 | - Automated toolchains and CI/CD systems 72 | 73 | --- 74 | 75 | ## Who Uses ELFIO & ARIO? 76 | 77 | - Open-source projects 78 | - Commercial toolchains 79 | - Academic research 80 | - Embedded systems 81 | - Binary analysis and reverse engineering tools 82 | 83 | --- 84 | 85 | ## Installation 86 | 87 | Simply copy the `elfio` and/or `ario` directories into your project and include the relevant headers. No build or linking steps are required. 88 | 89 | --- 90 | 91 | ## Getting Started 92 | 93 | 1. **Add the header files** to your project: 94 | - For ELFIO: `#include ` 95 | - For ARIO: `#include ` 96 | 97 | 2. **No build steps required:** Both libraries are header-only. 98 | 99 | 3. **Example: Reading an ELF file** 100 | 101 | ```cpp 102 | #include 103 | ELFIO::elfio reader; 104 | if (reader.load("my_binary.elf")) { 105 | // Access ELF sections, segments, symbols, etc. 106 | } 107 | ``` 108 | 109 | 4. **Example: Reading an archive file** 110 | 111 | ```cpp 112 | #include 113 | ARIO::ario archive; 114 | if (archive.load("libmylib.a").ok()) { 115 | for (const auto& member : archive.members) { 116 | std::cout << "Member: " << member.name << std::endl; 117 | } 118 | } 119 | ``` 120 | 121 | --- 122 | 123 | ## Project Structure 124 | 125 | - `elfio/` — ELFIO header files 126 | - `ario/` — ARIO header files 127 | - `examples/` — Example usage and sample tools 128 | 129 | --- 130 | 131 | ## Examples 132 | 133 | The `examples/` directory contains a collection of sample programs demonstrating how to use ELFIO and ARIO in real-world scenarios. Each example focuses on a specific use case, such as reading and modifying ELF files, manipulating archive files, or integrating with C code. These examples serve both as practical tutorials and as a starting point for your own tools and applications. 134 | 135 | **Purpose:** 136 | 137 | - Illustrate typical usage patterns for ELFIO and ARIO 138 | - Provide ready-to-use code for common binary and archive operations 139 | - Help users quickly get started and understand library capabilities 140 | 141 | Explore the `examples/` subdirectories for detailed demonstrations, including adding sections to ELF files, anonymizing binaries, working with archives, and more. 142 | 143 | --- 144 | 145 | ## Support 146 | 147 | For questions or support, please open an issue on [GitHub](https://github.com/serge1/ELFIO/issues). 148 | 149 | --- 150 | 151 | ## Contributing 152 | 153 | Contributions, bug reports, and feature requests are welcome! Please open an issue or submit a pull request on [GitHub](https://github.com/serge1/ELFIO). 154 | 155 | --- 156 | 157 | ## License 158 | 159 | This project is licensed under the [MIT License](https://github.com/serge1/ELFIO/blob/main/LICENSE.txt). 160 | 161 | --- 162 | 163 | ## Resources 164 | 165 | - [ELFIO Documentation (PDF)](http://elfio.sourceforge.net/elfio.pdf) 166 | - [ELFIO on GitHub](https://github.com/serge1/ELFIO) 167 | - [ELF Specification](https://refspecs.linuxbase.org/elf/elf.pdf) 168 | -------------------------------------------------------------------------------- /elfio/elfio_header.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2001-present by Serge Lamikhov-Center 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef ELF_HEADER_HPP 24 | #define ELF_HEADER_HPP 25 | 26 | #include 27 | 28 | namespace ELFIO { 29 | 30 | /** 31 | * @class elf_header 32 | * @brief Abstract base class for ELF header. 33 | */ 34 | class elf_header 35 | { 36 | public: 37 | /** 38 | * @brief Virtual destructor. 39 | */ 40 | virtual ~elf_header() = default; 41 | 42 | /** 43 | * @brief Load ELF header from stream. 44 | * @param stream Input stream. 45 | * @return True if successful, false otherwise. 46 | */ 47 | virtual bool load( std::istream& stream ) = 0; 48 | 49 | /** 50 | * @brief Save ELF header to stream. 51 | * @param stream Output stream. 52 | * @return True if successful, false otherwise. 53 | */ 54 | virtual bool save( std::ostream& stream ) const = 0; 55 | 56 | // ELF header functions 57 | ELFIO_GET_ACCESS_DECL( unsigned char, class ); 58 | ELFIO_GET_ACCESS_DECL( unsigned char, elf_version ); 59 | ELFIO_GET_ACCESS_DECL( unsigned char, encoding ); 60 | ELFIO_GET_ACCESS_DECL( Elf_Half, header_size ); 61 | ELFIO_GET_ACCESS_DECL( Elf_Half, section_entry_size ); 62 | ELFIO_GET_ACCESS_DECL( Elf_Half, segment_entry_size ); 63 | 64 | ELFIO_GET_SET_ACCESS_DECL( Elf_Word, version ); 65 | ELFIO_GET_SET_ACCESS_DECL( unsigned char, os_abi ); 66 | ELFIO_GET_SET_ACCESS_DECL( unsigned char, abi_version ); 67 | ELFIO_GET_SET_ACCESS_DECL( Elf_Half, type ); 68 | ELFIO_GET_SET_ACCESS_DECL( Elf_Half, machine ); 69 | ELFIO_GET_SET_ACCESS_DECL( Elf_Word, flags ); 70 | ELFIO_GET_SET_ACCESS_DECL( Elf64_Addr, entry ); 71 | ELFIO_GET_SET_ACCESS_DECL( Elf_Half, sections_num ); 72 | ELFIO_GET_SET_ACCESS_DECL( Elf64_Off, sections_offset ); 73 | ELFIO_GET_SET_ACCESS_DECL( Elf_Half, segments_num ); 74 | ELFIO_GET_SET_ACCESS_DECL( Elf64_Off, segments_offset ); 75 | ELFIO_GET_SET_ACCESS_DECL( Elf_Half, section_name_str_index ); 76 | }; 77 | 78 | /** 79 | * @struct elf_header_impl_types 80 | * @brief Template specialization for ELF header implementation types. 81 | */ 82 | template struct elf_header_impl_types; 83 | template <> struct elf_header_impl_types 84 | { 85 | using Phdr_type = Elf32_Phdr; 86 | using Shdr_type = Elf32_Shdr; 87 | static const unsigned char file_class = ELFCLASS32; 88 | }; 89 | template <> struct elf_header_impl_types 90 | { 91 | using Phdr_type = Elf64_Phdr; 92 | using Shdr_type = Elf64_Shdr; 93 | static const unsigned char file_class = ELFCLASS64; 94 | }; 95 | 96 | /** 97 | * @class elf_header_impl 98 | * @brief Template class for ELF header implementation. 99 | */ 100 | template class elf_header_impl : public elf_header 101 | { 102 | public: 103 | /** 104 | * @brief Constructor. 105 | * @param convertor Endianness convertor. 106 | * @param encoding Encoding type. 107 | * @param translator Address translator. 108 | */ 109 | elf_header_impl( std::shared_ptr convertor, 110 | unsigned char encoding, 111 | std::shared_ptr translator ) 112 | : convertor( convertor ), translator( translator ) 113 | { 114 | header.e_ident[EI_MAG0] = ELFMAG0; 115 | header.e_ident[EI_MAG1] = ELFMAG1; 116 | header.e_ident[EI_MAG2] = ELFMAG2; 117 | header.e_ident[EI_MAG3] = ELFMAG3; 118 | header.e_ident[EI_CLASS] = elf_header_impl_types::file_class; 119 | header.e_ident[EI_DATA] = encoding; 120 | header.e_ident[EI_VERSION] = EV_CURRENT; 121 | header.e_version = ( *convertor )( (Elf_Word)EV_CURRENT ); 122 | header.e_ehsize = ( sizeof( header ) ); 123 | header.e_ehsize = ( *convertor )( header.e_ehsize ); 124 | header.e_shstrndx = ( *convertor )( (Elf_Half)1 ); 125 | header.e_phentsize = 126 | sizeof( typename elf_header_impl_types::Phdr_type ); 127 | header.e_shentsize = 128 | sizeof( typename elf_header_impl_types::Shdr_type ); 129 | header.e_phentsize = ( *convertor )( header.e_phentsize ); 130 | header.e_shentsize = ( *convertor )( header.e_shentsize ); 131 | } 132 | 133 | /** 134 | * @brief Load ELF header from stream. 135 | * @param stream Input stream. 136 | * @return True if successful, false otherwise. 137 | */ 138 | bool load( std::istream& stream ) override 139 | { 140 | stream.seekg( ( *translator )[0] ); 141 | stream.read( reinterpret_cast( &header ), sizeof( header ) ); 142 | 143 | return ( stream.gcount() == sizeof( header ) ); 144 | } 145 | 146 | /** 147 | * @brief Save ELF header to stream. 148 | * @param stream Output stream. 149 | * @return True if successful, false otherwise. 150 | */ 151 | bool save( std::ostream& stream ) const override 152 | { 153 | stream.seekp( ( *translator )[0] ); 154 | stream.write( reinterpret_cast( &header ), 155 | sizeof( header ) ); 156 | 157 | return stream.good(); 158 | } 159 | 160 | //------------------------------------------------------------------------------ 161 | // ELF header functions 162 | ELFIO_GET_ACCESS( unsigned char, class, header.e_ident[EI_CLASS] ); 163 | ELFIO_GET_ACCESS( unsigned char, elf_version, header.e_ident[EI_VERSION] ); 164 | ELFIO_GET_ACCESS( unsigned char, encoding, header.e_ident[EI_DATA] ); 165 | ELFIO_GET_ACCESS( Elf_Half, header_size, header.e_ehsize ); 166 | ELFIO_GET_ACCESS( Elf_Half, section_entry_size, header.e_shentsize ); 167 | ELFIO_GET_ACCESS( Elf_Half, segment_entry_size, header.e_phentsize ); 168 | 169 | ELFIO_GET_SET_ACCESS( Elf_Word, version, header.e_version ); 170 | ELFIO_GET_SET_ACCESS( unsigned char, os_abi, header.e_ident[EI_OSABI] ); 171 | ELFIO_GET_SET_ACCESS( unsigned char, 172 | abi_version, 173 | header.e_ident[EI_ABIVERSION] ); 174 | ELFIO_GET_SET_ACCESS( Elf_Half, type, header.e_type ); 175 | ELFIO_GET_SET_ACCESS( Elf_Half, machine, header.e_machine ); 176 | ELFIO_GET_SET_ACCESS( Elf_Word, flags, header.e_flags ); 177 | ELFIO_GET_SET_ACCESS( Elf_Half, section_name_str_index, header.e_shstrndx ); 178 | ELFIO_GET_SET_ACCESS( Elf64_Addr, entry, header.e_entry ); 179 | ELFIO_GET_SET_ACCESS( Elf_Half, sections_num, header.e_shnum ); 180 | ELFIO_GET_SET_ACCESS( Elf64_Off, sections_offset, header.e_shoff ); 181 | ELFIO_GET_SET_ACCESS( Elf_Half, segments_num, header.e_phnum ); 182 | ELFIO_GET_SET_ACCESS( Elf64_Off, segments_offset, header.e_phoff ); 183 | 184 | private: 185 | T header = {}; 186 | std::shared_ptr convertor = nullptr; 187 | std::shared_ptr translator = nullptr; 188 | }; 189 | 190 | } // namespace ELFIO 191 | 192 | #endif // ELF_HEADER_HPP 193 | --------------------------------------------------------------------------------