diff --git a/.gitignore b/.gitignore index b437012ccce7f1b3dbbcc19eeeaf20e943ea9954..e7202f1113edd4602dbbb3b4f8cc8d64a5533a7a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,10 @@ -autom4te.cache -build -Debug -ELFIO.sdf -ELFIO.v11.suo -ELFIO.opensdf - -ELFIOTest/Debug - -examples/ELFDump/Debug +autom4te.cache +build +Debug +ELFIO.sdf +ELFIO.v11.suo +ELFIO.opensdf + +ELFIOTest/Debug + +examples/ELFDump/Debug diff --git a/AUTHORS b/AUTHORS index 436fc0b51be32de01446588969fbac924742e182..2aee04c54c43155ca4e920b3735460225fcf9743 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,5 +1,2 @@ -ELFIO library implemented by - Serge Lamikhov-Center <to_serge@users.sourceforge.net> - -ELFIO tutorial - Serge Lamikhov-Center - Allan Finch +ELFIO library implemented by + Serge Lamikhov-Center <to_serge@users.sourceforge.net> diff --git a/COPYING b/COPYING index af4ead53a424aeb5177083012f15ad3a1f93dd15..b0cd4ac1ce8be3318345d74a803c3c244da5880e 100644 --- a/COPYING +++ b/COPYING @@ -1,21 +1,21 @@ -MIT License - -Copyright (C) 2001-2011 by Serge Lamikhov-Center - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +MIT License + +Copyright (C) 2001-2011 by Serge Lamikhov-Center + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/ELFIOTest/ELFIOTest.cpp b/ELFIOTest/ELFIOTest.cpp index 5555840a08c7002c38b7b5aed4b9bb89e76deced..8312879ff265136dcdcde512d8e38e18d5665627 100644 --- a/ELFIOTest/ELFIOTest.cpp +++ b/ELFIOTest/ELFIOTest.cpp @@ -1,923 +1,923 @@ -#ifdef _MSC_VER -#define _SCL_SECURE_NO_WARNINGS -#define ELFIO_NO_INTTYPES -#endif - -#define BOOST_TEST_MODULE ELFIO_Test -#include <boost/test/unit_test.hpp> - -#include <elfio/elfio.hpp> - -using namespace ELFIO; - -//////////////////////////////////////////////////////////////////////////////// -void -checkHeader( elfio& reader, - unsigned char nClass, - unsigned char encoding, - unsigned char elfVersion, - Elf_Half type, - Elf_Half machine, - Elf_Word version, - Elf64_Addr entry, - Elf_Word flags, - Elf_Half secNum, - Elf_Half segNum, - unsigned char OSABI, - unsigned char ABIVersion ) -{ - BOOST_CHECK_EQUAL( reader.get_class(), nClass ); - BOOST_CHECK_EQUAL( reader.get_encoding(), encoding ); - BOOST_CHECK_EQUAL( reader.get_elf_version(), elfVersion ); - BOOST_CHECK_EQUAL( reader.get_os_abi(), OSABI ); - BOOST_CHECK_EQUAL( reader.get_abi_version(), ABIVersion ); - BOOST_CHECK_EQUAL( reader.get_type(), type ); - BOOST_CHECK_EQUAL( reader.get_machine(), machine ); - BOOST_CHECK_EQUAL( reader.get_version(), version ); - BOOST_CHECK_EQUAL( reader.get_entry(), entry ); - BOOST_CHECK_EQUAL( reader.get_flags(), flags ); - BOOST_CHECK_EQUAL( reader.sections.size(), secNum ); - BOOST_CHECK_EQUAL( reader.segments.size(), segNum ); -} - - -//////////////////////////////////////////////////////////////////////////////// -void -checkSection( const section* sec, - Elf_Half index, - std::string name, - Elf_Word type, - Elf_Xword flags, - Elf64_Addr address, - Elf_Xword size, - Elf_Word link, - Elf_Word info, - Elf_Xword addrAlign, - Elf_Xword entrySize ) -{ - BOOST_CHECK_EQUAL( sec->get_index(), index ); - BOOST_CHECK_EQUAL( sec->get_name(), name ); - BOOST_CHECK_EQUAL( sec->get_type(), type ); - BOOST_CHECK_EQUAL( sec->get_flags(), flags ); - BOOST_CHECK_EQUAL( sec->get_address(), address ); - BOOST_CHECK_EQUAL( sec->get_size(), size ); - BOOST_CHECK_EQUAL( sec->get_link(), link ); - BOOST_CHECK_EQUAL( sec->get_info(), info ); - BOOST_CHECK_EQUAL( sec->get_addr_align(), addrAlign ); - BOOST_CHECK_EQUAL( sec->get_entry_size(), entrySize ); -} - - -//////////////////////////////////////////////////////////////////////////////// -void -checkSection( const section* sec, - std::string name, - Elf_Word type, - Elf_Xword flags, - Elf64_Addr address, - Elf_Xword size, - Elf_Word link, - Elf_Word info, - Elf_Xword addrAlign, - Elf_Xword entrySize ) -{ - checkSection( sec, sec->get_index(), name, type, flags, address, size, link, - info, addrAlign, entrySize ); -} - - -//////////////////////////////////////////////////////////////////////////////// -void -checkSegment( const segment* seg, - Elf_Word type, - Elf64_Addr vaddr, - Elf64_Addr paddr, - Elf_Xword fsize, - Elf_Xword msize, - Elf_Word flags, - Elf_Xword align ) -{ - BOOST_CHECK_EQUAL( seg->get_type(), type ); - BOOST_CHECK_EQUAL( seg->get_virtual_address(), vaddr ); - BOOST_CHECK_EQUAL( seg->get_physical_address(), paddr ); - BOOST_CHECK_EQUAL( seg->get_file_size(), fsize ); - BOOST_CHECK_EQUAL( seg->get_memory_size(), msize ); - BOOST_CHECK_EQUAL( seg->get_flags(), flags ); - BOOST_CHECK_EQUAL( seg->get_align(), align ); -} - - -//////////////////////////////////////////////////////////////////////////////// -void -checkSymbol( const symbol_section_accessor& sr, Elf_Xword index, - std::string name_, Elf64_Addr value_, - Elf_Xword size_, - unsigned char bind_, unsigned char type_, - Elf_Half section_, unsigned char other_ ) -{ - std::string name; - Elf64_Addr value; - Elf_Xword size; - unsigned char bind; - unsigned char type; - Elf_Half section; - unsigned char other; - - BOOST_REQUIRE_EQUAL( sr.get_symbol( index, name, value, size, bind, type, section, other ), - true ); - BOOST_CHECK_EQUAL( name, name_ ); - BOOST_CHECK_EQUAL( value, value_ ); - BOOST_CHECK_EQUAL( size, size_ ); - BOOST_CHECK_EQUAL( bind, bind_ ); - BOOST_CHECK_EQUAL( type, type_ ); - BOOST_CHECK_EQUAL( section, section_ ); - BOOST_CHECK_EQUAL( other, other_ ); -} - - -//////////////////////////////////////////////////////////////////////////////// -void -checkRelocation( const relocation_section_accessor* pRT, Elf_Xword index, - Elf64_Addr offset_, Elf64_Addr symbolValue_, - std::string symbolName_, - unsigned char type_, Elf_Sxword addend_, - Elf_Sxword calcValue_ ) -{ - Elf64_Addr offset; - Elf64_Addr symbolValue; - std::string symbolName; - Elf_Word type; - Elf_Sxword addend; - Elf_Sxword calcValue; - - BOOST_REQUIRE_EQUAL( pRT->get_entry( index, offset, symbolValue, symbolName, - type, addend, calcValue ), - true ); - BOOST_CHECK_EQUAL( offset, offset_ ); - BOOST_CHECK_EQUAL( symbolValue, symbolValue_ ); - BOOST_CHECK_EQUAL( symbolName, symbolName_ ); - BOOST_CHECK_EQUAL( type, type_ ); - BOOST_CHECK_EQUAL( addend, addend_ ); - BOOST_CHECK_EQUAL( calcValue, calcValue_ ); -} - - -//////////////////////////////////////////////////////////////////////////////// -void - checkNote( const note_section_accessor& notes, Elf_Word index, - Elf_Word type_, std::string name_, - Elf_Word descSize_ ) -{ - Elf_Word type; - std::string name; - void* desc; - Elf_Word descSize; - - BOOST_REQUIRE_EQUAL( notes.get_note( index, type, name, desc, descSize ), - true ); - BOOST_CHECK_EQUAL( type, type_ ); - BOOST_CHECK_EQUAL( name, name_ ); - BOOST_CHECK_EQUAL( descSize, descSize_ ); -} - - -//////////////////////////////////////////////////////////////////////////////// -BOOST_AUTO_TEST_CASE( load32 ) -{ - elfio reader; - BOOST_REQUIRE_EQUAL( reader.load( "../elf_examples/hello_32" ), true ); - checkHeader( reader, ELFCLASS32, ELFDATA2LSB, EV_CURRENT, ET_EXEC, - EM_386, 1, 0x80482b0, 0, 28, 7, 0, 0 ); - - //////////////////////////////////////////////////////////////////////////// - // Check sections - section* sec = reader.sections[0]; - checkSection( sec, 0, "", SHT_NULL, 0, 0, 0, 0, 0, 0, 0 ); - - sec = reader.sections[1]; - checkSection( sec, 1, ".interp", SHT_PROGBITS, SHF_ALLOC, - 0x08048114, 0x13, 0, 0, 1, 0 ); - - sec = reader.sections[9]; - checkSection( sec, 9, ".rel.plt", SHT_REL, SHF_ALLOC, - 0x08048234, 0x18, 4, 11, 4, 8 ); - - sec = reader.sections[19]; - checkSection( sec, 19, ".dynamic", SHT_DYNAMIC, SHF_WRITE | SHF_ALLOC, - 0x080494a0, 0xc8, 5, 0, 4, 8 ); - - sec = reader.sections[27]; - checkSection( sec, 27, ".strtab", SHT_STRTAB, 0, - 0x0, 0x259, 0, 0, 1, 0 ); - - const section* sec1 = reader.sections[ ".strtab" ]; - BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); - - //////////////////////////////////////////////////////////////////////////// - // Check segments - segment* seg = reader.segments[0]; - checkSegment( seg, PT_PHDR, 0x08048034, 0x08048034, - 0x000e0, 0x000e0, PF_R + PF_X, 4 ); - - seg = reader.segments[4]; - checkSegment( seg, PT_DYNAMIC, 0x080494a0, 0x080494a0, - 0x000c8, 0x000c8, PF_R + PF_W, 4 ); - - seg = reader.segments[6]; - checkSegment( seg, 0x6474E551, 0x0, 0x0, - 0x0, 0x0, PF_R + PF_W, 4 ); - - //////////////////////////////////////////////////////////////////////////// - // Check symbol table - sec = reader.sections[ ".symtab" ]; - - - symbol_section_accessor sr( reader, sec ); - - BOOST_CHECK_EQUAL( sr.get_symbols_num(), 68 ); - checkSymbol( sr, 0, "", 0x00000000, 0, STB_LOCAL, STT_NOTYPE, STN_UNDEF, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - checkSymbol( sr, 1, "", 0x08048114, 0, STB_LOCAL, STT_SECTION, 1, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - checkSymbol( sr, 39, "hello.c", 0x00000000, 0, STB_LOCAL, STT_FILE, SHN_ABS, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - checkSymbol( sr, 65, "__i686.get_pc_thunk.bx", 0x08048429, 0, STB_GLOBAL, STT_FUNC, 12, - ELF_ST_VISIBILITY( STV_HIDDEN ) ); - checkSymbol( sr, 66, "main", 0x08048384, 43, STB_GLOBAL, STT_FUNC, 12, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - checkSymbol( sr, 67, "_init", 0x0804824c, 0, STB_GLOBAL, STT_FUNC, 10, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - - //////////////////////////////////////////////////////////////////////////// - // Check relocation table - sec = reader.sections[ ".rel.dyn" ]; - - - relocation_section_accessor reloc( reader, sec ); - BOOST_CHECK_EQUAL( reloc.get_entries_num(), 1 ); - - checkRelocation( &reloc, 0, 0x08049568, 0x0, "__gmon_start__", R_386_GLOB_DAT, 0, 0 ); - - sec = reader.sections[ ".rel.plt" ]; - - - relocation_section_accessor reloc1( reader, sec ); - BOOST_CHECK_EQUAL( reloc1.get_entries_num(), 3 ); - - checkRelocation( &reloc1, 0, 0x08049578, 0x0, "__gmon_start__", R_X86_64_JUMP_SLOT, 0, 0 ); - checkRelocation( &reloc1, 1, 0x0804957c, 0x0, "__libc_start_main", R_X86_64_JUMP_SLOT, 0, 0 ); - checkRelocation( &reloc1, 2, 0x08049580, 0x0, "puts", R_X86_64_JUMP_SLOT, 0, 0 ); - - //////////////////////////////////////////////////////////////////////////// - // Check note reader - sec = reader.sections[ ".note.ABI-tag" ]; - - - note_section_accessor notes( reader, sec ); - BOOST_CHECK_EQUAL( notes.get_notes_num(), 1 ); - - checkNote( notes, 0, 1, std::string( "GNU" ) + '\0', 16 ); -} - - -//////////////////////////////////////////////////////////////////////////////// -BOOST_AUTO_TEST_CASE( load64 ) -{ - elfio reader; - - BOOST_REQUIRE_EQUAL( reader.load( "../elf_examples/hello_64" ), true ); - - //////////////////////////////////////////////////////////////////////////// - // Check ELF header - checkHeader( reader, ELFCLASS64, ELFDATA2LSB, EV_CURRENT, ET_EXEC, - EM_X86_64, 1, 0x4003c0, 0, 29, 8, 0, 0 ); - - //////////////////////////////////////////////////////////////////////////// - // Check sections - section* sec = reader.sections[ 0 ]; - - checkSection( sec, 0, "", SHT_NULL, 0, 0, 0, 0, 0, 0, 0 ); - - sec =reader.sections[ 1 ]; - - checkSection( sec, 1, ".interp", SHT_PROGBITS, SHF_ALLOC, - 0x0000000000400200, 0x1c, 0, 0, 1, 0 ); - - sec =reader.sections[ 9 ]; - - checkSection( sec, 9, ".rela.plt", SHT_RELA, SHF_ALLOC, - 0x0000000000400340, 0x30, 4, 11, 8, 0x18 ); - - sec =reader.sections[ 20 ]; - - checkSection( sec, 20, ".dynamic", SHT_DYNAMIC, SHF_WRITE | SHF_ALLOC, - 0x0000000000600698, 0x190, 5, 0, 8, 0x10 ); - - sec =reader.sections[ 28 ]; - - checkSection( sec, 28, ".strtab", SHT_STRTAB, 0, - 0x0, 0x23f, 0, 0, 1, 0 ); - - const section* sec1 = reader.sections[ ".strtab" ]; - BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); - - //////////////////////////////////////////////////////////////////////////// - // Check segments - segment* seg = reader.segments[0]; - checkSegment( seg, PT_PHDR, 0x0000000000400040, 0x0000000000400040, - 0x00000000000001c0, 0x00000000000001c0, PF_R + PF_X, 8 ); - - seg = reader.segments[2]; - checkSegment( seg, PT_LOAD, 0x0000000000400000, 0x0000000000400000, - 0x000000000000066c, 0x000000000000066c, PF_R + PF_X, 0x200000 ); - - seg = reader.segments[7]; - checkSegment( seg, 0x6474E551, 0x0, 0x0, - 0x0, 0x0, PF_R + PF_W, 8 ); - - //////////////////////////////////////////////////////////////////////////// - // Check symbol table - sec =reader.sections[ ".symtab" ]; - - - symbol_section_accessor sr( reader, sec ); - - BOOST_CHECK_EQUAL( sr.get_symbols_num(), 67 ); - checkSymbol( sr, 0, "", 0x00000000, 0, STB_LOCAL, STT_NOTYPE, STN_UNDEF, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - checkSymbol( sr, 1, "", 0x00400200, 0, STB_LOCAL, STT_SECTION, 1, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - checkSymbol( sr, 40, "hello.c", 0x00000000, 0, STB_LOCAL, STT_FILE, SHN_ABS, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - checkSymbol( sr, 52, "__gmon_start__", 0x00000000, 0, STB_WEAK, STT_NOTYPE, STN_UNDEF, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - checkSymbol( sr, 64, "_edata", 0x0060085c, 0, STB_GLOBAL, STT_NOTYPE, SHN_ABS, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - checkSymbol( sr, 65, "main", 0x00400498, 21, STB_GLOBAL, STT_FUNC, 12, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - checkSymbol( sr, 66, "_init", 0x00400370, 0, STB_GLOBAL, STT_FUNC, 10, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - - //////////////////////////////////////////////////////////////////////////// - // Check relocation table - sec =reader.sections[ ".rela.dyn" ]; - - - relocation_section_accessor reloc( reader, sec ); - BOOST_CHECK_EQUAL( reloc.get_entries_num(), 1 ); - - checkRelocation( &reloc, 0, 0x00600828, 0x0, "__gmon_start__", R_X86_64_GLOB_DAT, 0, 0 ); - - sec =reader.sections[ ".rela.plt" ]; - - - relocation_section_accessor reloc1( reader, sec ); - BOOST_CHECK_EQUAL( reloc1.get_entries_num(), 2 ); - - checkRelocation( &reloc1, 0, 0x00600848, 0x0, "puts", R_X86_64_JUMP_SLOT, 0, 0 ); - checkRelocation( &reloc1, 1, 0x00600850, 0x0, "__libc_start_main", R_X86_64_JUMP_SLOT, 0, 0 ); - - //////////////////////////////////////////////////////////////////////////// - // Check note reader - sec =reader.sections[ ".note.ABI-tag" ]; - - - note_section_accessor notes( reader, sec ); - BOOST_CHECK_EQUAL( notes.get_notes_num(), 1 ); - - checkNote( notes, 0, 1, std::string( "GNU" ) + '\0', 16 ); -} - - -//////////////////////////////////////////////////////////////////////////////// -BOOST_AUTO_TEST_CASE( hello_64_o ) -{ - elfio reader; - - BOOST_REQUIRE_EQUAL( reader.load( "../elf_examples/hello_64.o" ), true ); - - //////////////////////////////////////////////////////////////////////////// - // Check ELF header - checkHeader( reader, ELFCLASS64, ELFDATA2LSB, EV_CURRENT, ET_REL, - EM_X86_64, 1, 0, 0, 13, 0, 0, 0 ); - - //////////////////////////////////////////////////////////////////////////// - // Check sections - section* sec = reader.sections[ 0 ]; - - checkSection( sec, 0, "", SHT_NULL, 0, 0, 0, 0, 0, 0, 0 ); - - sec =reader.sections[ 1 ]; - - checkSection( sec, 1, ".text", SHT_PROGBITS, SHF_ALLOC | SHF_EXECINSTR, - 0x0, 0x15, 0, 0, 4, 0 ); - - section* sec1 = reader.sections[ ".text" ]; - BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); - - sec = reader.sections[12]; - checkSection( sec, 12, ".strtab", SHT_STRTAB, 0, - 0x0, 0x13, 0, 0, 1, 0 ); - - sec1 = reader.sections[ ".strtab" ]; - BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); - - //////////////////////////////////////////////////////////////////////////// - // Check symbol table - sec =reader.sections[ ".symtab" ]; - - - symbol_section_accessor sr( reader, sec ); - - BOOST_CHECK_EQUAL( sr.get_symbols_num(), 11 ); - checkSymbol( sr, 9, "main", 0x00000000, 21, STB_GLOBAL, STT_FUNC, 1, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - - //////////////////////////////////////////////////////////////////////////// - // Check relocation table - sec =reader.sections[ ".rela.text" ]; - - - relocation_section_accessor reloc( reader, sec ); - BOOST_CHECK_EQUAL( reloc.get_entries_num(), 2 ); - - checkRelocation( &reloc, 0, 0x00000005, 0x0, "", R_X86_64_32, 0, 0 ); - checkRelocation( &reloc, 1, 0x0000000A, 0x0, "puts", R_X86_64_PC32, 0xfffffffffffffffcULL, -14 ); - - sec =reader.sections[ ".rela.eh_frame" ]; - - - relocation_section_accessor reloc1( reader, sec ); - BOOST_CHECK_EQUAL( reloc1.get_entries_num(), 1 ); - - checkRelocation( &reloc1, 0, 0x00000020, 0x0, "", R_X86_64_32, 0, 0 ); -} - - -//////////////////////////////////////////////////////////////////////////////// -BOOST_AUTO_TEST_CASE( hello_32_o ) -{ - elfio reader; - - BOOST_REQUIRE_EQUAL( reader.load( "../elf_examples/hello_32.o" ), true ); - - //////////////////////////////////////////////////////////////////////////// - // Check ELF header - checkHeader( reader, ELFCLASS32, ELFDATA2LSB, EV_CURRENT, ET_REL, - EM_386, 1, 0, 0, 11, 0, 0, 0 ); - - //////////////////////////////////////////////////////////////////////////// - // Check sections - section* sec = reader.sections[ 0 ]; - - checkSection( sec, 0, "", SHT_NULL, 0, 0, 0, 0, 0, 0, 0 ); - - sec =reader.sections[ 1 ]; - - checkSection( sec, 1, ".text", SHT_PROGBITS, SHF_ALLOC | SHF_EXECINSTR, - 0x0, 0x2b, 0, 0, 4, 0 ); - - section* sec1 = reader.sections[ ".text" ]; - BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); - - - sec = reader.sections[ 10 ]; - - checkSection( sec, 10, ".strtab", SHT_STRTAB, 0, - 0x0, 0x13, 0, 0, 1, 0 ); - - sec1 = reader.sections[ ".strtab" ]; - BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); - - //////////////////////////////////////////////////////////////////////////// - // Check symbol table - sec =reader.sections[ ".symtab" ]; - - - symbol_section_accessor sr( reader, sec ); - - BOOST_CHECK_EQUAL( sr.get_symbols_num(), 10 ); - checkSymbol( sr, 8, "main", 0x00000000, 43, STB_GLOBAL, STT_FUNC, 1, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - - //////////////////////////////////////////////////////////////////////////// - // Check relocation table - sec =reader.sections[ ".rel.text" ]; - - - relocation_section_accessor reloc( reader, sec ); - BOOST_CHECK_EQUAL( reloc.get_entries_num(), 2 ); - - checkRelocation( &reloc, 0, 0x00000014, 0x0, "", R_386_32, 0, 0 ); - checkRelocation( &reloc, 1, 0x00000019, 0x0, "puts", R_386_PC32, 0x0, -25 ); -} - - -//////////////////////////////////////////////////////////////////////////////// -BOOST_AUTO_TEST_CASE( test_ppc_o ) -{ - elfio reader; - - BOOST_REQUIRE_EQUAL( reader.load( "../elf_examples/test_ppc.o" ), true ); - - //////////////////////////////////////////////////////////////////////////// - // Check ELF header - checkHeader( reader, ELFCLASS32, ELFDATA2MSB, EV_CURRENT, ET_REL, - EM_PPC, 1, 0, 0, 16, 0, 0, 0 ); - - //////////////////////////////////////////////////////////////////////////// - // Check sections - section* sec = reader.sections[ 0 ]; - - checkSection( sec, 0, "", SHT_NULL, 0, 0, 0, 0, 0, 0, 0 ); - - sec =reader.sections[ 1 ]; - - checkSection( sec, 1, ".text", SHT_PROGBITS, SHF_ALLOC | SHF_EXECINSTR, - 0x0, 0x118, 0, 0, 4, 0 ); - - section* sec1 = reader.sections[ ".text" ]; - BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); - - sec =reader.sections[ 15 ]; - - checkSection( sec, 15, ".strtab", SHT_STRTAB, 0, - 0x0, 0x14f, 0, 0, 1, 0 ); - - sec1 = reader.sections[ ".strtab" ]; - BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); - - //////////////////////////////////////////////////////////////////////////// - // Check symbol table - sec =reader.sections[ ".symtab" ]; - - - symbol_section_accessor sr( reader, sec ); - - BOOST_CHECK_EQUAL( sr.get_symbols_num(), 24 ); - checkSymbol( sr, 14, "main", 0x00000000, 92, STB_GLOBAL, STT_FUNC, 1, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - checkSymbol( sr, 8, "_GLOBAL__I_main", 0x000000DC, 60, STB_LOCAL, STT_FUNC, 1, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - - //////////////////////////////////////////////////////////////////////////// - // Check relocation table - sec =reader.sections[ ".rela.text" ]; - - - relocation_section_accessor reloc( reader, sec ); - BOOST_CHECK_EQUAL( reloc.get_entries_num(), 18 ); - - checkRelocation( &reloc, 0, 0x00000016, 0x0, "_ZSt4cout", 6, 0, 0 ); - checkRelocation( &reloc, 1, 0x0000001a, 0x0, "_ZSt4cout", 4, 0x0, 0 ); - checkRelocation( &reloc, 17, 0x000000c0, 0x0, "__cxa_atexit", 10, 0x0, 0 ); - - sec =reader.sections[ ".rela.ctors" ]; - - - relocation_section_accessor reloc1( reader, sec ); - BOOST_CHECK_EQUAL( reloc1.get_entries_num(), 1 ); - - checkRelocation( &reloc1, 0, 0x00000000, 0x0, "", 1, 0xDC, 0xDC ); - - sec =reader.sections[ ".rela.eh_frame" ]; - - - relocation_section_accessor reloc2( reader, sec ); - BOOST_CHECK_EQUAL( reloc2.get_entries_num(), 3 ); - - checkRelocation( &reloc2, 1, 0x00000020, 0x0, "", 1, 0x0, 0x0 ); -} - - -//////////////////////////////////////////////////////////////////////////////// -BOOST_AUTO_TEST_CASE( test_ppc ) -{ - elfio reader; - - BOOST_REQUIRE_EQUAL( reader.load( "../elf_examples/test_ppc" ), true ); - - //////////////////////////////////////////////////////////////////////////// - // Check ELF header - checkHeader( reader, ELFCLASS32, ELFDATA2MSB, EV_CURRENT, ET_EXEC, - EM_PPC, 1, 0x10000550, 0, 31, 8, 0, 0 ); - - //////////////////////////////////////////////////////////////////////////// - // Check sections - section* sec = reader.sections[ 0 ]; - - checkSection( sec, 0, "", SHT_NULL, 0, 0, 0, 0, 0, 0, 0 ); - - sec =reader.sections[ 1 ]; - - checkSection( sec, 1, ".interp", SHT_PROGBITS, SHF_ALLOC, - 0x0000000010000134, 0xd, 0, 0, 1, 0 ); - - sec =reader.sections[ 9 ]; - - checkSection( sec, 9, ".rela.plt", SHT_RELA, SHF_ALLOC, - 0x00000000010000494, 0x6c, 4, 22, 4, 0xc ); - - sec =reader.sections[ 20 ]; - - checkSection( sec, 20, ".dynamic", SHT_DYNAMIC, SHF_WRITE | SHF_ALLOC, - 0x0000000010010aec, 0xe8, 5, 0, 4, 0x8 ); - - sec =reader.sections[ 28 ]; - - checkSection( sec, 28, ".shstrtab", SHT_STRTAB, 0, - 0x0, 0x101, 0, 0, 1, 0 ); - - const section* sec1 = reader.sections[ ".shstrtab" ]; - BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); - - - //////////////////////////////////////////////////////////////////////////// - // Check segments - segment* seg = reader.segments[0]; - checkSegment( seg, PT_PHDR, 0x10000034, 0x10000034, - 0x00100, 0x00100, PF_R + PF_X, 4 ); - - seg = reader.segments[2]; - checkSegment( seg, PT_LOAD, 0x10000000, 0x10000000, - 0x00acc, 0x00acc, PF_R + PF_X, 0x10000 ); - - seg = reader.segments[7]; - checkSegment( seg, 0x6474E551, 0x0, 0x0, - 0x0, 0x0, PF_R + PF_W, 0x4 ); - - //////////////////////////////////////////////////////////////////////////// - // Check symbol table - sec =reader.sections[ ".symtab" ]; - - - symbol_section_accessor sr( reader, sec ); - - BOOST_CHECK_EQUAL( sr.get_symbols_num(), 80 ); - checkSymbol( sr, 0, "", 0x00000000, 0, STB_LOCAL, STT_NOTYPE, STN_UNDEF, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - checkSymbol( sr, 1, "", 0x10000134, 0, STB_LOCAL, STT_SECTION, 1, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - checkSymbol( sr, 40, "__CTOR_END__", 0x10010AD4, 0, STB_LOCAL, STT_OBJECT, 16, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - checkSymbol( sr, 52, "__init_array_start", 0x10010acc, 0, STB_LOCAL, STT_NOTYPE, 16, - ELF_ST_VISIBILITY( STV_HIDDEN ) ); - checkSymbol( sr, 64, "_ZNSt8ios_base4InitD1Ev@@GLIBCXX_3.4", 0x10000920, 204, STB_GLOBAL, STT_FUNC, SHN_UNDEF, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - checkSymbol( sr, 78, "main", 0x1000069c, 92, STB_GLOBAL, STT_FUNC, 11, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - checkSymbol( sr, 79, "_init", 0x10000500, 0, STB_GLOBAL, STT_FUNC, 10, - ELF_ST_VISIBILITY( STV_DEFAULT ) ); - - //////////////////////////////////////////////////////////////////////////// - // Check relocation table - sec =reader.sections[ ".rela.dyn" ]; - - - relocation_section_accessor reloc( reader, sec ); - BOOST_CHECK_EQUAL( reloc.get_entries_num(), 2 ); - - checkRelocation( &reloc, 1, 0x10010c0c, 0x10010c0c, "_ZSt4cout", 19, 0, 0 ); - - sec =reader.sections[ ".rela.plt" ]; - - - relocation_section_accessor reloc1( reader, sec ); - BOOST_CHECK_EQUAL( reloc1.get_entries_num(), 9 ); - - checkRelocation( &reloc1, 0, 0x10010be4, 0x100008e0, "__cxa_atexit", 21, 0, 0 ); - checkRelocation( &reloc1, 1, 0x10010be8, 0x0, "__gmon_start__", 21, 0, 0 ); - - //////////////////////////////////////////////////////////////////////////// - // Check note reader - sec =reader.sections[ ".note.ABI-tag" ]; - - - note_section_accessor notes( reader, sec ); - BOOST_CHECK_EQUAL( notes.get_notes_num(), 1 ); - - checkNote( notes, 0, 1, std::string( "GNU" ) + '\0', 16 ); -} - -//////////////////////////////////////////////////////////////////////////////// -BOOST_AUTO_TEST_CASE( test_dummy_out_i386_32 ) -{ - elfio writer; - - writer.create( ELFCLASS32, ELFDATA2LSB ); - - writer.set_os_abi( 0 ); - writer.set_abi_version( 0 ); - writer.set_type( ET_REL ); - writer.set_machine( EM_386 ); - writer.set_flags( 0 ); - - // Set program entry point - writer.set_entry( 0x80482b0 ); - - // Add Note section - section* note_sec = writer.sections.add( ".note" ); - note_sec->set_type( SHT_NOTE ); - note_sec->set_flags( SHF_ALLOC ); - note_sec->set_addr_align( 4 ); - note_section_accessor note_writer( writer, note_sec ); - char descr[6] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16}; - note_writer.add_note( 0x77, "Hello", &descr, 6 ); - BOOST_CHECK_EQUAL( note_sec->get_index(), 2 ); - - // Create ELF file - writer.save( "../elf_examples/elf_dummy_header_i386_32.elf" ); - - elfio reader; - BOOST_REQUIRE_EQUAL( reader.load( "../elf_examples/elf_dummy_header_i386_32.elf" ), - true ); - - //////////////////////////////////////////////////////////////////////////// - // Check ELF header - checkHeader( reader, ELFCLASS32, ELFDATA2LSB, EV_CURRENT, ET_REL, - EM_386, EV_CURRENT, 0x80482b0, 0, 3, 0, 0, 0 ); - //////////////////////////////////////////////////////////////////////////// - // Check sections - section* sec = reader.sections[ "" ]; - - checkSection( sec, 0, "", SHT_NULL, 0, 0, 0, 0, 0, 0, 0 ); - - sec = reader.sections[ ".shstrtab" ]; - - checkSection( sec, 1, ".shstrtab", SHT_STRTAB, 0, - 0, 17, 0, 0, 0, 0 ); - - sec =reader.sections[ ".note" ]; - - BOOST_CHECK_EQUAL( sec->get_index(), 2 ); - checkSection( sec, 2, ".note", SHT_NOTE, SHF_ALLOC, - 0, 28, 0, 0, 4, 0 ); -} - - -//////////////////////////////////////////////////////////////////////////////// -BOOST_AUTO_TEST_CASE( test_dummy_out_ppc_32 ) -{ - elfio writer; - - writer.create( ELFCLASS32, ELFDATA2MSB ); - - writer.set_os_abi( 0 ); - writer.set_abi_version( 0 ); - writer.set_type( ET_REL ); - writer.set_machine( EM_PPC ); - writer.set_flags( 0 ); - - // Set program entry point - writer.set_entry( 0x80482b0 ); - - // Add Note section - section* note_sec = writer.sections.add( ".note" ); - note_sec->set_type( SHT_NOTE ); - note_sec->set_flags( SHF_ALLOC ); - note_sec->set_addr_align( 4 ); - note_section_accessor note_writer( writer, note_sec ); - char descr[6] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16}; - note_writer.add_note( 0x77, "Hello", &descr, 6 ); - BOOST_CHECK_EQUAL( note_sec->get_index(), 2 ); - - // Create ELF file - writer.save( "../elf_examples/elf_dummy_header_ppc_32.elf" ); - - elfio reader; - BOOST_REQUIRE_EQUAL( reader.load( "../elf_examples/elf_dummy_header_ppc_32.elf" ), - true ); - - //////////////////////////////////////////////////////////////////////////// - // Check ELF header - checkHeader( reader, ELFCLASS32, ELFDATA2MSB, EV_CURRENT, ET_REL, - EM_PPC, EV_CURRENT, 0x80482b0, 0, 3, 0, 0, 0 ); - //////////////////////////////////////////////////////////////////////////// - // Check sections - section* sec = reader.sections[ "" ]; - - checkSection( sec, 0, "", SHT_NULL, 0, 0, 0, 0, 0, 0, 0 ); - - sec =reader.sections[ ".note" ]; - - BOOST_CHECK_EQUAL( sec->get_index(), 2 ); - checkSection( sec, 2, ".note", SHT_NOTE, SHF_ALLOC, - 0, 28, 0, 0, 4, 0 ); - - sec =reader.sections[ ".shstrtab" ]; - - checkSection( sec, 1, ".shstrtab", SHT_STRTAB, 0, - 0, 17, 0, 0, 0, 0 ); -} - - -//////////////////////////////////////////////////////////////////////////////// -BOOST_AUTO_TEST_CASE( test_dummy_out_i386_64 ) -{ - elfio writer; - - writer.create( ELFCLASS64, ELFDATA2LSB ); - - writer.set_os_abi( 0 ); - writer.set_abi_version( 0 ); - writer.set_type( ET_REL ); - writer.set_machine( EM_X86_64 ); - writer.set_flags( 0 ); - - // Set program entry point - writer.set_entry( 0x120380482b0ull ); - - // Add Note section - section* note_sec = writer.sections.add( ".note" ); - note_sec->set_type( SHT_NOTE ); - note_sec->set_flags( SHF_ALLOC ); - note_sec->set_addr_align( 4 ); - note_section_accessor note_writer( writer, note_sec ); - char descr[6] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16}; - note_writer.add_note( 0x77, "Hello", &descr, 6 ); - BOOST_CHECK_EQUAL( note_sec->get_index(), 2 ); - - // Create ELF file - writer.save( "../elf_examples/elf_dummy_header_i386_64.elf" ); - - elfio reader; - BOOST_REQUIRE_EQUAL( reader.load( "../elf_examples/elf_dummy_header_i386_64.elf" ), - true ); - - //////////////////////////////////////////////////////////////////////////// - // Check ELF header - checkHeader( reader, ELFCLASS64, ELFDATA2LSB, EV_CURRENT, ET_REL, - EM_X86_64, EV_CURRENT, 0x120380482b0ull, 0, 3, 0, 0, 0 ); - //////////////////////////////////////////////////////////////////////////// - // Check sections - section* sec = reader.sections[ "" ]; - - checkSection( sec, 0, "", SHT_NULL, 0, 0, 0, 0, 0, 0, 0 ); - - sec =reader.sections[ ".note" ]; - - BOOST_CHECK_EQUAL( sec->get_index(), 2 ); - checkSection( sec, 2, ".note", SHT_NOTE, SHF_ALLOC, - 0, 28, 0, 0, 4, 0 ); - - sec =reader.sections[ ".shstrtab" ]; - - checkSection( sec, 1, ".shstrtab", SHT_STRTAB, 0, - 0, 17, 0, 0, 0, 0 ); -} - - -//////////////////////////////////////////////////////////////////////////////// -BOOST_AUTO_TEST_CASE( test_dummy_out_ppc_64 ) -{ - elfio writer; - - writer.create( ELFCLASS64, ELFDATA2MSB ); - - writer.set_os_abi( 0 ); - writer.set_abi_version( 0 ); - writer.set_type( ET_REL ); - writer.set_machine( EM_PPC64 ); - writer.set_flags( 0 ); - - // Set program entry point - writer.set_entry( 0x120380482b0ull ); - - // Add Note section - section* note_sec = writer.sections.add( ".note" ); - note_sec->set_type( SHT_NOTE ); - note_sec->set_flags( SHF_ALLOC ); - note_sec->set_addr_align( 4 ); - note_section_accessor note_writer( writer, note_sec ); - char descr[6] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16}; - note_writer.add_note( 0x77, "Hello", &descr, 6 ); - BOOST_CHECK_EQUAL( note_sec->get_index(), 2 ); - - // Create ELF file - writer.save( "../elf_examples/elf_dummy_header_ppc_64.elf" ); - - elfio reader; - BOOST_REQUIRE_EQUAL( reader.load( "../elf_examples/elf_dummy_header_ppc_64.elf" ), - true ); - - //////////////////////////////////////////////////////////////////////////// - // Check ELF header - checkHeader( reader, ELFCLASS64, ELFDATA2MSB, EV_CURRENT, ET_REL, - EM_PPC64, EV_CURRENT, 0x120380482b0ull, 0, 3, 0, 0, 0 ); - //////////////////////////////////////////////////////////////////////////// - // Check sections - section* sec = reader.sections[ "" ]; - - checkSection( sec, 0, "", SHT_NULL, 0, 0, 0, 0, 0, 0, 0 ); - - sec =reader.sections[ ".shstrtab" ]; - - checkSection( sec, 1, ".shstrtab", SHT_STRTAB, 0, - 0, 17, 0, 0, 0, 0 ); - - sec =reader.sections[ ".note" ]; - - BOOST_CHECK_EQUAL( sec->get_index(), 2 ); - checkSection( sec, 2, ".note", SHT_NOTE, SHF_ALLOC, - 0, 28, 0, 0, 4, 0 ); -} +#ifdef _MSC_VER +#define _SCL_SECURE_NO_WARNINGS +#define ELFIO_NO_INTTYPES +#endif + +#define BOOST_TEST_MODULE ELFIO_Test +#include <boost/test/unit_test.hpp> + +#include <elfio/elfio.hpp> + +using namespace ELFIO; + +//////////////////////////////////////////////////////////////////////////////// +void +checkHeader( elfio& reader, + unsigned char nClass, + unsigned char encoding, + unsigned char elfVersion, + Elf_Half type, + Elf_Half machine, + Elf_Word version, + Elf64_Addr entry, + Elf_Word flags, + Elf_Half secNum, + Elf_Half segNum, + unsigned char OSABI, + unsigned char ABIVersion ) +{ + BOOST_CHECK_EQUAL( reader.get_class(), nClass ); + BOOST_CHECK_EQUAL( reader.get_encoding(), encoding ); + BOOST_CHECK_EQUAL( reader.get_elf_version(), elfVersion ); + BOOST_CHECK_EQUAL( reader.get_os_abi(), OSABI ); + BOOST_CHECK_EQUAL( reader.get_abi_version(), ABIVersion ); + BOOST_CHECK_EQUAL( reader.get_type(), type ); + BOOST_CHECK_EQUAL( reader.get_machine(), machine ); + BOOST_CHECK_EQUAL( reader.get_version(), version ); + BOOST_CHECK_EQUAL( reader.get_entry(), entry ); + BOOST_CHECK_EQUAL( reader.get_flags(), flags ); + BOOST_CHECK_EQUAL( reader.sections.size(), secNum ); + BOOST_CHECK_EQUAL( reader.segments.size(), segNum ); +} + + +//////////////////////////////////////////////////////////////////////////////// +void +checkSection( const section* sec, + Elf_Half index, + std::string name, + Elf_Word type, + Elf_Xword flags, + Elf64_Addr address, + Elf_Xword size, + Elf_Word link, + Elf_Word info, + Elf_Xword addrAlign, + Elf_Xword entrySize ) +{ + BOOST_CHECK_EQUAL( sec->get_index(), index ); + BOOST_CHECK_EQUAL( sec->get_name(), name ); + BOOST_CHECK_EQUAL( sec->get_type(), type ); + BOOST_CHECK_EQUAL( sec->get_flags(), flags ); + BOOST_CHECK_EQUAL( sec->get_address(), address ); + BOOST_CHECK_EQUAL( sec->get_size(), size ); + BOOST_CHECK_EQUAL( sec->get_link(), link ); + BOOST_CHECK_EQUAL( sec->get_info(), info ); + BOOST_CHECK_EQUAL( sec->get_addr_align(), addrAlign ); + BOOST_CHECK_EQUAL( sec->get_entry_size(), entrySize ); +} + + +//////////////////////////////////////////////////////////////////////////////// +void +checkSection( const section* sec, + std::string name, + Elf_Word type, + Elf_Xword flags, + Elf64_Addr address, + Elf_Xword size, + Elf_Word link, + Elf_Word info, + Elf_Xword addrAlign, + Elf_Xword entrySize ) +{ + checkSection( sec, sec->get_index(), name, type, flags, address, size, link, + info, addrAlign, entrySize ); +} + + +//////////////////////////////////////////////////////////////////////////////// +void +checkSegment( const segment* seg, + Elf_Word type, + Elf64_Addr vaddr, + Elf64_Addr paddr, + Elf_Xword fsize, + Elf_Xword msize, + Elf_Word flags, + Elf_Xword align ) +{ + BOOST_CHECK_EQUAL( seg->get_type(), type ); + BOOST_CHECK_EQUAL( seg->get_virtual_address(), vaddr ); + BOOST_CHECK_EQUAL( seg->get_physical_address(), paddr ); + BOOST_CHECK_EQUAL( seg->get_file_size(), fsize ); + BOOST_CHECK_EQUAL( seg->get_memory_size(), msize ); + BOOST_CHECK_EQUAL( seg->get_flags(), flags ); + BOOST_CHECK_EQUAL( seg->get_align(), align ); +} + + +//////////////////////////////////////////////////////////////////////////////// +void +checkSymbol( const symbol_section_accessor& sr, Elf_Xword index, + std::string name_, Elf64_Addr value_, + Elf_Xword size_, + unsigned char bind_, unsigned char type_, + Elf_Half section_, unsigned char other_ ) +{ + std::string name; + Elf64_Addr value; + Elf_Xword size; + unsigned char bind; + unsigned char type; + Elf_Half section; + unsigned char other; + + BOOST_REQUIRE_EQUAL( sr.get_symbol( index, name, value, size, bind, type, section, other ), + true ); + BOOST_CHECK_EQUAL( name, name_ ); + BOOST_CHECK_EQUAL( value, value_ ); + BOOST_CHECK_EQUAL( size, size_ ); + BOOST_CHECK_EQUAL( bind, bind_ ); + BOOST_CHECK_EQUAL( type, type_ ); + BOOST_CHECK_EQUAL( section, section_ ); + BOOST_CHECK_EQUAL( other, other_ ); +} + + +//////////////////////////////////////////////////////////////////////////////// +void +checkRelocation( const relocation_section_accessor* pRT, Elf_Xword index, + Elf64_Addr offset_, Elf64_Addr symbolValue_, + std::string symbolName_, + unsigned char type_, Elf_Sxword addend_, + Elf_Sxword calcValue_ ) +{ + Elf64_Addr offset; + Elf64_Addr symbolValue; + std::string symbolName; + Elf_Word type; + Elf_Sxword addend; + Elf_Sxword calcValue; + + BOOST_REQUIRE_EQUAL( pRT->get_entry( index, offset, symbolValue, symbolName, + type, addend, calcValue ), + true ); + BOOST_CHECK_EQUAL( offset, offset_ ); + BOOST_CHECK_EQUAL( symbolValue, symbolValue_ ); + BOOST_CHECK_EQUAL( symbolName, symbolName_ ); + BOOST_CHECK_EQUAL( type, type_ ); + BOOST_CHECK_EQUAL( addend, addend_ ); + BOOST_CHECK_EQUAL( calcValue, calcValue_ ); +} + + +//////////////////////////////////////////////////////////////////////////////// +void + checkNote( const note_section_accessor& notes, Elf_Word index, + Elf_Word type_, std::string name_, + Elf_Word descSize_ ) +{ + Elf_Word type; + std::string name; + void* desc; + Elf_Word descSize; + + BOOST_REQUIRE_EQUAL( notes.get_note( index, type, name, desc, descSize ), + true ); + BOOST_CHECK_EQUAL( type, type_ ); + BOOST_CHECK_EQUAL( name, name_ ); + BOOST_CHECK_EQUAL( descSize, descSize_ ); +} + + +//////////////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE( load32 ) +{ + elfio reader; + BOOST_REQUIRE_EQUAL( reader.load( "../elf_examples/hello_32" ), true ); + checkHeader( reader, ELFCLASS32, ELFDATA2LSB, EV_CURRENT, ET_EXEC, + EM_386, 1, 0x80482b0, 0, 28, 7, 0, 0 ); + + //////////////////////////////////////////////////////////////////////////// + // Check sections + section* sec = reader.sections[0]; + checkSection( sec, 0, "", SHT_NULL, 0, 0, 0, 0, 0, 0, 0 ); + + sec = reader.sections[1]; + checkSection( sec, 1, ".interp", SHT_PROGBITS, SHF_ALLOC, + 0x08048114, 0x13, 0, 0, 1, 0 ); + + sec = reader.sections[9]; + checkSection( sec, 9, ".rel.plt", SHT_REL, SHF_ALLOC, + 0x08048234, 0x18, 4, 11, 4, 8 ); + + sec = reader.sections[19]; + checkSection( sec, 19, ".dynamic", SHT_DYNAMIC, SHF_WRITE | SHF_ALLOC, + 0x080494a0, 0xc8, 5, 0, 4, 8 ); + + sec = reader.sections[27]; + checkSection( sec, 27, ".strtab", SHT_STRTAB, 0, + 0x0, 0x259, 0, 0, 1, 0 ); + + const section* sec1 = reader.sections[ ".strtab" ]; + BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); + + //////////////////////////////////////////////////////////////////////////// + // Check segments + segment* seg = reader.segments[0]; + checkSegment( seg, PT_PHDR, 0x08048034, 0x08048034, + 0x000e0, 0x000e0, PF_R + PF_X, 4 ); + + seg = reader.segments[4]; + checkSegment( seg, PT_DYNAMIC, 0x080494a0, 0x080494a0, + 0x000c8, 0x000c8, PF_R + PF_W, 4 ); + + seg = reader.segments[6]; + checkSegment( seg, 0x6474E551, 0x0, 0x0, + 0x0, 0x0, PF_R + PF_W, 4 ); + + //////////////////////////////////////////////////////////////////////////// + // Check symbol table + sec = reader.sections[ ".symtab" ]; + + + symbol_section_accessor sr( reader, sec ); + + BOOST_CHECK_EQUAL( sr.get_symbols_num(), 68 ); + checkSymbol( sr, 0, "", 0x00000000, 0, STB_LOCAL, STT_NOTYPE, STN_UNDEF, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + checkSymbol( sr, 1, "", 0x08048114, 0, STB_LOCAL, STT_SECTION, 1, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + checkSymbol( sr, 39, "hello.c", 0x00000000, 0, STB_LOCAL, STT_FILE, SHN_ABS, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + checkSymbol( sr, 65, "__i686.get_pc_thunk.bx", 0x08048429, 0, STB_GLOBAL, STT_FUNC, 12, + ELF_ST_VISIBILITY( STV_HIDDEN ) ); + checkSymbol( sr, 66, "main", 0x08048384, 43, STB_GLOBAL, STT_FUNC, 12, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + checkSymbol( sr, 67, "_init", 0x0804824c, 0, STB_GLOBAL, STT_FUNC, 10, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + + //////////////////////////////////////////////////////////////////////////// + // Check relocation table + sec = reader.sections[ ".rel.dyn" ]; + + + relocation_section_accessor reloc( reader, sec ); + BOOST_CHECK_EQUAL( reloc.get_entries_num(), 1 ); + + checkRelocation( &reloc, 0, 0x08049568, 0x0, "__gmon_start__", R_386_GLOB_DAT, 0, 0 ); + + sec = reader.sections[ ".rel.plt" ]; + + + relocation_section_accessor reloc1( reader, sec ); + BOOST_CHECK_EQUAL( reloc1.get_entries_num(), 3 ); + + checkRelocation( &reloc1, 0, 0x08049578, 0x0, "__gmon_start__", R_X86_64_JUMP_SLOT, 0, 0 ); + checkRelocation( &reloc1, 1, 0x0804957c, 0x0, "__libc_start_main", R_X86_64_JUMP_SLOT, 0, 0 ); + checkRelocation( &reloc1, 2, 0x08049580, 0x0, "puts", R_X86_64_JUMP_SLOT, 0, 0 ); + + //////////////////////////////////////////////////////////////////////////// + // Check note reader + sec = reader.sections[ ".note.ABI-tag" ]; + + + note_section_accessor notes( reader, sec ); + BOOST_CHECK_EQUAL( notes.get_notes_num(), 1 ); + + checkNote( notes, 0, 1, std::string( "GNU" ) + '\0', 16 ); +} + + +//////////////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE( load64 ) +{ + elfio reader; + + BOOST_REQUIRE_EQUAL( reader.load( "../elf_examples/hello_64" ), true ); + + //////////////////////////////////////////////////////////////////////////// + // Check ELF header + checkHeader( reader, ELFCLASS64, ELFDATA2LSB, EV_CURRENT, ET_EXEC, + EM_X86_64, 1, 0x4003c0, 0, 29, 8, 0, 0 ); + + //////////////////////////////////////////////////////////////////////////// + // Check sections + section* sec = reader.sections[ 0 ]; + + checkSection( sec, 0, "", SHT_NULL, 0, 0, 0, 0, 0, 0, 0 ); + + sec =reader.sections[ 1 ]; + + checkSection( sec, 1, ".interp", SHT_PROGBITS, SHF_ALLOC, + 0x0000000000400200, 0x1c, 0, 0, 1, 0 ); + + sec =reader.sections[ 9 ]; + + checkSection( sec, 9, ".rela.plt", SHT_RELA, SHF_ALLOC, + 0x0000000000400340, 0x30, 4, 11, 8, 0x18 ); + + sec =reader.sections[ 20 ]; + + checkSection( sec, 20, ".dynamic", SHT_DYNAMIC, SHF_WRITE | SHF_ALLOC, + 0x0000000000600698, 0x190, 5, 0, 8, 0x10 ); + + sec =reader.sections[ 28 ]; + + checkSection( sec, 28, ".strtab", SHT_STRTAB, 0, + 0x0, 0x23f, 0, 0, 1, 0 ); + + const section* sec1 = reader.sections[ ".strtab" ]; + BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); + + //////////////////////////////////////////////////////////////////////////// + // Check segments + segment* seg = reader.segments[0]; + checkSegment( seg, PT_PHDR, 0x0000000000400040, 0x0000000000400040, + 0x00000000000001c0, 0x00000000000001c0, PF_R + PF_X, 8 ); + + seg = reader.segments[2]; + checkSegment( seg, PT_LOAD, 0x0000000000400000, 0x0000000000400000, + 0x000000000000066c, 0x000000000000066c, PF_R + PF_X, 0x200000 ); + + seg = reader.segments[7]; + checkSegment( seg, 0x6474E551, 0x0, 0x0, + 0x0, 0x0, PF_R + PF_W, 8 ); + + //////////////////////////////////////////////////////////////////////////// + // Check symbol table + sec =reader.sections[ ".symtab" ]; + + + symbol_section_accessor sr( reader, sec ); + + BOOST_CHECK_EQUAL( sr.get_symbols_num(), 67 ); + checkSymbol( sr, 0, "", 0x00000000, 0, STB_LOCAL, STT_NOTYPE, STN_UNDEF, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + checkSymbol( sr, 1, "", 0x00400200, 0, STB_LOCAL, STT_SECTION, 1, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + checkSymbol( sr, 40, "hello.c", 0x00000000, 0, STB_LOCAL, STT_FILE, SHN_ABS, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + checkSymbol( sr, 52, "__gmon_start__", 0x00000000, 0, STB_WEAK, STT_NOTYPE, STN_UNDEF, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + checkSymbol( sr, 64, "_edata", 0x0060085c, 0, STB_GLOBAL, STT_NOTYPE, SHN_ABS, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + checkSymbol( sr, 65, "main", 0x00400498, 21, STB_GLOBAL, STT_FUNC, 12, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + checkSymbol( sr, 66, "_init", 0x00400370, 0, STB_GLOBAL, STT_FUNC, 10, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + + //////////////////////////////////////////////////////////////////////////// + // Check relocation table + sec =reader.sections[ ".rela.dyn" ]; + + + relocation_section_accessor reloc( reader, sec ); + BOOST_CHECK_EQUAL( reloc.get_entries_num(), 1 ); + + checkRelocation( &reloc, 0, 0x00600828, 0x0, "__gmon_start__", R_X86_64_GLOB_DAT, 0, 0 ); + + sec =reader.sections[ ".rela.plt" ]; + + + relocation_section_accessor reloc1( reader, sec ); + BOOST_CHECK_EQUAL( reloc1.get_entries_num(), 2 ); + + checkRelocation( &reloc1, 0, 0x00600848, 0x0, "puts", R_X86_64_JUMP_SLOT, 0, 0 ); + checkRelocation( &reloc1, 1, 0x00600850, 0x0, "__libc_start_main", R_X86_64_JUMP_SLOT, 0, 0 ); + + //////////////////////////////////////////////////////////////////////////// + // Check note reader + sec =reader.sections[ ".note.ABI-tag" ]; + + + note_section_accessor notes( reader, sec ); + BOOST_CHECK_EQUAL( notes.get_notes_num(), 1 ); + + checkNote( notes, 0, 1, std::string( "GNU" ) + '\0', 16 ); +} + + +//////////////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE( hello_64_o ) +{ + elfio reader; + + BOOST_REQUIRE_EQUAL( reader.load( "../elf_examples/hello_64.o" ), true ); + + //////////////////////////////////////////////////////////////////////////// + // Check ELF header + checkHeader( reader, ELFCLASS64, ELFDATA2LSB, EV_CURRENT, ET_REL, + EM_X86_64, 1, 0, 0, 13, 0, 0, 0 ); + + //////////////////////////////////////////////////////////////////////////// + // Check sections + section* sec = reader.sections[ 0 ]; + + checkSection( sec, 0, "", SHT_NULL, 0, 0, 0, 0, 0, 0, 0 ); + + sec =reader.sections[ 1 ]; + + checkSection( sec, 1, ".text", SHT_PROGBITS, SHF_ALLOC | SHF_EXECINSTR, + 0x0, 0x15, 0, 0, 4, 0 ); + + section* sec1 = reader.sections[ ".text" ]; + BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); + + sec = reader.sections[12]; + checkSection( sec, 12, ".strtab", SHT_STRTAB, 0, + 0x0, 0x13, 0, 0, 1, 0 ); + + sec1 = reader.sections[ ".strtab" ]; + BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); + + //////////////////////////////////////////////////////////////////////////// + // Check symbol table + sec =reader.sections[ ".symtab" ]; + + + symbol_section_accessor sr( reader, sec ); + + BOOST_CHECK_EQUAL( sr.get_symbols_num(), 11 ); + checkSymbol( sr, 9, "main", 0x00000000, 21, STB_GLOBAL, STT_FUNC, 1, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + + //////////////////////////////////////////////////////////////////////////// + // Check relocation table + sec =reader.sections[ ".rela.text" ]; + + + relocation_section_accessor reloc( reader, sec ); + BOOST_CHECK_EQUAL( reloc.get_entries_num(), 2 ); + + checkRelocation( &reloc, 0, 0x00000005, 0x0, "", R_X86_64_32, 0, 0 ); + checkRelocation( &reloc, 1, 0x0000000A, 0x0, "puts", R_X86_64_PC32, 0xfffffffffffffffcULL, -14 ); + + sec =reader.sections[ ".rela.eh_frame" ]; + + + relocation_section_accessor reloc1( reader, sec ); + BOOST_CHECK_EQUAL( reloc1.get_entries_num(), 1 ); + + checkRelocation( &reloc1, 0, 0x00000020, 0x0, "", R_X86_64_32, 0, 0 ); +} + + +//////////////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE( hello_32_o ) +{ + elfio reader; + + BOOST_REQUIRE_EQUAL( reader.load( "../elf_examples/hello_32.o" ), true ); + + //////////////////////////////////////////////////////////////////////////// + // Check ELF header + checkHeader( reader, ELFCLASS32, ELFDATA2LSB, EV_CURRENT, ET_REL, + EM_386, 1, 0, 0, 11, 0, 0, 0 ); + + //////////////////////////////////////////////////////////////////////////// + // Check sections + section* sec = reader.sections[ 0 ]; + + checkSection( sec, 0, "", SHT_NULL, 0, 0, 0, 0, 0, 0, 0 ); + + sec =reader.sections[ 1 ]; + + checkSection( sec, 1, ".text", SHT_PROGBITS, SHF_ALLOC | SHF_EXECINSTR, + 0x0, 0x2b, 0, 0, 4, 0 ); + + section* sec1 = reader.sections[ ".text" ]; + BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); + + + sec = reader.sections[ 10 ]; + + checkSection( sec, 10, ".strtab", SHT_STRTAB, 0, + 0x0, 0x13, 0, 0, 1, 0 ); + + sec1 = reader.sections[ ".strtab" ]; + BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); + + //////////////////////////////////////////////////////////////////////////// + // Check symbol table + sec =reader.sections[ ".symtab" ]; + + + symbol_section_accessor sr( reader, sec ); + + BOOST_CHECK_EQUAL( sr.get_symbols_num(), 10 ); + checkSymbol( sr, 8, "main", 0x00000000, 43, STB_GLOBAL, STT_FUNC, 1, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + + //////////////////////////////////////////////////////////////////////////// + // Check relocation table + sec =reader.sections[ ".rel.text" ]; + + + relocation_section_accessor reloc( reader, sec ); + BOOST_CHECK_EQUAL( reloc.get_entries_num(), 2 ); + + checkRelocation( &reloc, 0, 0x00000014, 0x0, "", R_386_32, 0, 0 ); + checkRelocation( &reloc, 1, 0x00000019, 0x0, "puts", R_386_PC32, 0x0, -25 ); +} + + +//////////////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE( test_ppc_o ) +{ + elfio reader; + + BOOST_REQUIRE_EQUAL( reader.load( "../elf_examples/test_ppc.o" ), true ); + + //////////////////////////////////////////////////////////////////////////// + // Check ELF header + checkHeader( reader, ELFCLASS32, ELFDATA2MSB, EV_CURRENT, ET_REL, + EM_PPC, 1, 0, 0, 16, 0, 0, 0 ); + + //////////////////////////////////////////////////////////////////////////// + // Check sections + section* sec = reader.sections[ 0 ]; + + checkSection( sec, 0, "", SHT_NULL, 0, 0, 0, 0, 0, 0, 0 ); + + sec =reader.sections[ 1 ]; + + checkSection( sec, 1, ".text", SHT_PROGBITS, SHF_ALLOC | SHF_EXECINSTR, + 0x0, 0x118, 0, 0, 4, 0 ); + + section* sec1 = reader.sections[ ".text" ]; + BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); + + sec =reader.sections[ 15 ]; + + checkSection( sec, 15, ".strtab", SHT_STRTAB, 0, + 0x0, 0x14f, 0, 0, 1, 0 ); + + sec1 = reader.sections[ ".strtab" ]; + BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); + + //////////////////////////////////////////////////////////////////////////// + // Check symbol table + sec =reader.sections[ ".symtab" ]; + + + symbol_section_accessor sr( reader, sec ); + + BOOST_CHECK_EQUAL( sr.get_symbols_num(), 24 ); + checkSymbol( sr, 14, "main", 0x00000000, 92, STB_GLOBAL, STT_FUNC, 1, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + checkSymbol( sr, 8, "_GLOBAL__I_main", 0x000000DC, 60, STB_LOCAL, STT_FUNC, 1, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + + //////////////////////////////////////////////////////////////////////////// + // Check relocation table + sec =reader.sections[ ".rela.text" ]; + + + relocation_section_accessor reloc( reader, sec ); + BOOST_CHECK_EQUAL( reloc.get_entries_num(), 18 ); + + checkRelocation( &reloc, 0, 0x00000016, 0x0, "_ZSt4cout", 6, 0, 0 ); + checkRelocation( &reloc, 1, 0x0000001a, 0x0, "_ZSt4cout", 4, 0x0, 0 ); + checkRelocation( &reloc, 17, 0x000000c0, 0x0, "__cxa_atexit", 10, 0x0, 0 ); + + sec =reader.sections[ ".rela.ctors" ]; + + + relocation_section_accessor reloc1( reader, sec ); + BOOST_CHECK_EQUAL( reloc1.get_entries_num(), 1 ); + + checkRelocation( &reloc1, 0, 0x00000000, 0x0, "", 1, 0xDC, 0xDC ); + + sec =reader.sections[ ".rela.eh_frame" ]; + + + relocation_section_accessor reloc2( reader, sec ); + BOOST_CHECK_EQUAL( reloc2.get_entries_num(), 3 ); + + checkRelocation( &reloc2, 1, 0x00000020, 0x0, "", 1, 0x0, 0x0 ); +} + + +//////////////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE( test_ppc ) +{ + elfio reader; + + BOOST_REQUIRE_EQUAL( reader.load( "../elf_examples/test_ppc" ), true ); + + //////////////////////////////////////////////////////////////////////////// + // Check ELF header + checkHeader( reader, ELFCLASS32, ELFDATA2MSB, EV_CURRENT, ET_EXEC, + EM_PPC, 1, 0x10000550, 0, 31, 8, 0, 0 ); + + //////////////////////////////////////////////////////////////////////////// + // Check sections + section* sec = reader.sections[ 0 ]; + + checkSection( sec, 0, "", SHT_NULL, 0, 0, 0, 0, 0, 0, 0 ); + + sec =reader.sections[ 1 ]; + + checkSection( sec, 1, ".interp", SHT_PROGBITS, SHF_ALLOC, + 0x0000000010000134, 0xd, 0, 0, 1, 0 ); + + sec =reader.sections[ 9 ]; + + checkSection( sec, 9, ".rela.plt", SHT_RELA, SHF_ALLOC, + 0x00000000010000494, 0x6c, 4, 22, 4, 0xc ); + + sec =reader.sections[ 20 ]; + + checkSection( sec, 20, ".dynamic", SHT_DYNAMIC, SHF_WRITE | SHF_ALLOC, + 0x0000000010010aec, 0xe8, 5, 0, 4, 0x8 ); + + sec =reader.sections[ 28 ]; + + checkSection( sec, 28, ".shstrtab", SHT_STRTAB, 0, + 0x0, 0x101, 0, 0, 1, 0 ); + + const section* sec1 = reader.sections[ ".shstrtab" ]; + BOOST_CHECK_EQUAL( sec->get_index(), sec1->get_index() ); + + + //////////////////////////////////////////////////////////////////////////// + // Check segments + segment* seg = reader.segments[0]; + checkSegment( seg, PT_PHDR, 0x10000034, 0x10000034, + 0x00100, 0x00100, PF_R + PF_X, 4 ); + + seg = reader.segments[2]; + checkSegment( seg, PT_LOAD, 0x10000000, 0x10000000, + 0x00acc, 0x00acc, PF_R + PF_X, 0x10000 ); + + seg = reader.segments[7]; + checkSegment( seg, 0x6474E551, 0x0, 0x0, + 0x0, 0x0, PF_R + PF_W, 0x4 ); + + //////////////////////////////////////////////////////////////////////////// + // Check symbol table + sec =reader.sections[ ".symtab" ]; + + + symbol_section_accessor sr( reader, sec ); + + BOOST_CHECK_EQUAL( sr.get_symbols_num(), 80 ); + checkSymbol( sr, 0, "", 0x00000000, 0, STB_LOCAL, STT_NOTYPE, STN_UNDEF, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + checkSymbol( sr, 1, "", 0x10000134, 0, STB_LOCAL, STT_SECTION, 1, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + checkSymbol( sr, 40, "__CTOR_END__", 0x10010AD4, 0, STB_LOCAL, STT_OBJECT, 16, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + checkSymbol( sr, 52, "__init_array_start", 0x10010acc, 0, STB_LOCAL, STT_NOTYPE, 16, + ELF_ST_VISIBILITY( STV_HIDDEN ) ); + checkSymbol( sr, 64, "_ZNSt8ios_base4InitD1Ev@@GLIBCXX_3.4", 0x10000920, 204, STB_GLOBAL, STT_FUNC, SHN_UNDEF, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + checkSymbol( sr, 78, "main", 0x1000069c, 92, STB_GLOBAL, STT_FUNC, 11, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + checkSymbol( sr, 79, "_init", 0x10000500, 0, STB_GLOBAL, STT_FUNC, 10, + ELF_ST_VISIBILITY( STV_DEFAULT ) ); + + //////////////////////////////////////////////////////////////////////////// + // Check relocation table + sec =reader.sections[ ".rela.dyn" ]; + + + relocation_section_accessor reloc( reader, sec ); + BOOST_CHECK_EQUAL( reloc.get_entries_num(), 2 ); + + checkRelocation( &reloc, 1, 0x10010c0c, 0x10010c0c, "_ZSt4cout", 19, 0, 0 ); + + sec =reader.sections[ ".rela.plt" ]; + + + relocation_section_accessor reloc1( reader, sec ); + BOOST_CHECK_EQUAL( reloc1.get_entries_num(), 9 ); + + checkRelocation( &reloc1, 0, 0x10010be4, 0x100008e0, "__cxa_atexit", 21, 0, 0 ); + checkRelocation( &reloc1, 1, 0x10010be8, 0x0, "__gmon_start__", 21, 0, 0 ); + + //////////////////////////////////////////////////////////////////////////// + // Check note reader + sec =reader.sections[ ".note.ABI-tag" ]; + + + note_section_accessor notes( reader, sec ); + BOOST_CHECK_EQUAL( notes.get_notes_num(), 1 ); + + checkNote( notes, 0, 1, std::string( "GNU" ) + '\0', 16 ); +} + +//////////////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE( test_dummy_out_i386_32 ) +{ + elfio writer; + + writer.create( ELFCLASS32, ELFDATA2LSB ); + + writer.set_os_abi( 0 ); + writer.set_abi_version( 0 ); + writer.set_type( ET_REL ); + writer.set_machine( EM_386 ); + writer.set_flags( 0 ); + + // Set program entry point + writer.set_entry( 0x80482b0 ); + + // Add Note section + section* note_sec = writer.sections.add( ".note" ); + note_sec->set_type( SHT_NOTE ); + note_sec->set_flags( SHF_ALLOC ); + note_sec->set_addr_align( 4 ); + note_section_accessor note_writer( writer, note_sec ); + char descr[6] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16}; + note_writer.add_note( 0x77, "Hello", &descr, 6 ); + BOOST_CHECK_EQUAL( note_sec->get_index(), 2 ); + + // Create ELF file + writer.save( "../elf_examples/elf_dummy_header_i386_32.elf" ); + + elfio reader; + BOOST_REQUIRE_EQUAL( reader.load( "../elf_examples/elf_dummy_header_i386_32.elf" ), + true ); + + //////////////////////////////////////////////////////////////////////////// + // Check ELF header + checkHeader( reader, ELFCLASS32, ELFDATA2LSB, EV_CURRENT, ET_REL, + EM_386, EV_CURRENT, 0x80482b0, 0, 3, 0, 0, 0 ); + //////////////////////////////////////////////////////////////////////////// + // Check sections + section* sec = reader.sections[ "" ]; + + checkSection( sec, 0, "", SHT_NULL, 0, 0, 0, 0, 0, 0, 0 ); + + sec = reader.sections[ ".shstrtab" ]; + + checkSection( sec, 1, ".shstrtab", SHT_STRTAB, 0, + 0, 17, 0, 0, 0, 0 ); + + sec =reader.sections[ ".note" ]; + + BOOST_CHECK_EQUAL( sec->get_index(), 2 ); + checkSection( sec, 2, ".note", SHT_NOTE, SHF_ALLOC, + 0, 28, 0, 0, 4, 0 ); +} + + +//////////////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE( test_dummy_out_ppc_32 ) +{ + elfio writer; + + writer.create( ELFCLASS32, ELFDATA2MSB ); + + writer.set_os_abi( 0 ); + writer.set_abi_version( 0 ); + writer.set_type( ET_REL ); + writer.set_machine( EM_PPC ); + writer.set_flags( 0 ); + + // Set program entry point + writer.set_entry( 0x80482b0 ); + + // Add Note section + section* note_sec = writer.sections.add( ".note" ); + note_sec->set_type( SHT_NOTE ); + note_sec->set_flags( SHF_ALLOC ); + note_sec->set_addr_align( 4 ); + note_section_accessor note_writer( writer, note_sec ); + char descr[6] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16}; + note_writer.add_note( 0x77, "Hello", &descr, 6 ); + BOOST_CHECK_EQUAL( note_sec->get_index(), 2 ); + + // Create ELF file + writer.save( "../elf_examples/elf_dummy_header_ppc_32.elf" ); + + elfio reader; + BOOST_REQUIRE_EQUAL( reader.load( "../elf_examples/elf_dummy_header_ppc_32.elf" ), + true ); + + //////////////////////////////////////////////////////////////////////////// + // Check ELF header + checkHeader( reader, ELFCLASS32, ELFDATA2MSB, EV_CURRENT, ET_REL, + EM_PPC, EV_CURRENT, 0x80482b0, 0, 3, 0, 0, 0 ); + //////////////////////////////////////////////////////////////////////////// + // Check sections + section* sec = reader.sections[ "" ]; + + checkSection( sec, 0, "", SHT_NULL, 0, 0, 0, 0, 0, 0, 0 ); + + sec =reader.sections[ ".note" ]; + + BOOST_CHECK_EQUAL( sec->get_index(), 2 ); + checkSection( sec, 2, ".note", SHT_NOTE, SHF_ALLOC, + 0, 28, 0, 0, 4, 0 ); + + sec =reader.sections[ ".shstrtab" ]; + + checkSection( sec, 1, ".shstrtab", SHT_STRTAB, 0, + 0, 17, 0, 0, 0, 0 ); +} + + +//////////////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE( test_dummy_out_i386_64 ) +{ + elfio writer; + + writer.create( ELFCLASS64, ELFDATA2LSB ); + + writer.set_os_abi( 0 ); + writer.set_abi_version( 0 ); + writer.set_type( ET_REL ); + writer.set_machine( EM_X86_64 ); + writer.set_flags( 0 ); + + // Set program entry point + writer.set_entry( 0x120380482b0ull ); + + // Add Note section + section* note_sec = writer.sections.add( ".note" ); + note_sec->set_type( SHT_NOTE ); + note_sec->set_flags( SHF_ALLOC ); + note_sec->set_addr_align( 4 ); + note_section_accessor note_writer( writer, note_sec ); + char descr[6] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16}; + note_writer.add_note( 0x77, "Hello", &descr, 6 ); + BOOST_CHECK_EQUAL( note_sec->get_index(), 2 ); + + // Create ELF file + writer.save( "../elf_examples/elf_dummy_header_i386_64.elf" ); + + elfio reader; + BOOST_REQUIRE_EQUAL( reader.load( "../elf_examples/elf_dummy_header_i386_64.elf" ), + true ); + + //////////////////////////////////////////////////////////////////////////// + // Check ELF header + checkHeader( reader, ELFCLASS64, ELFDATA2LSB, EV_CURRENT, ET_REL, + EM_X86_64, EV_CURRENT, 0x120380482b0ull, 0, 3, 0, 0, 0 ); + //////////////////////////////////////////////////////////////////////////// + // Check sections + section* sec = reader.sections[ "" ]; + + checkSection( sec, 0, "", SHT_NULL, 0, 0, 0, 0, 0, 0, 0 ); + + sec =reader.sections[ ".note" ]; + + BOOST_CHECK_EQUAL( sec->get_index(), 2 ); + checkSection( sec, 2, ".note", SHT_NOTE, SHF_ALLOC, + 0, 28, 0, 0, 4, 0 ); + + sec =reader.sections[ ".shstrtab" ]; + + checkSection( sec, 1, ".shstrtab", SHT_STRTAB, 0, + 0, 17, 0, 0, 0, 0 ); +} + + +//////////////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE( test_dummy_out_ppc_64 ) +{ + elfio writer; + + writer.create( ELFCLASS64, ELFDATA2MSB ); + + writer.set_os_abi( 0 ); + writer.set_abi_version( 0 ); + writer.set_type( ET_REL ); + writer.set_machine( EM_PPC64 ); + writer.set_flags( 0 ); + + // Set program entry point + writer.set_entry( 0x120380482b0ull ); + + // Add Note section + section* note_sec = writer.sections.add( ".note" ); + note_sec->set_type( SHT_NOTE ); + note_sec->set_flags( SHF_ALLOC ); + note_sec->set_addr_align( 4 ); + note_section_accessor note_writer( writer, note_sec ); + char descr[6] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16}; + note_writer.add_note( 0x77, "Hello", &descr, 6 ); + BOOST_CHECK_EQUAL( note_sec->get_index(), 2 ); + + // Create ELF file + writer.save( "../elf_examples/elf_dummy_header_ppc_64.elf" ); + + elfio reader; + BOOST_REQUIRE_EQUAL( reader.load( "../elf_examples/elf_dummy_header_ppc_64.elf" ), + true ); + + //////////////////////////////////////////////////////////////////////////// + // Check ELF header + checkHeader( reader, ELFCLASS64, ELFDATA2MSB, EV_CURRENT, ET_REL, + EM_PPC64, EV_CURRENT, 0x120380482b0ull, 0, 3, 0, 0, 0 ); + //////////////////////////////////////////////////////////////////////////// + // Check sections + section* sec = reader.sections[ "" ]; + + checkSection( sec, 0, "", SHT_NULL, 0, 0, 0, 0, 0, 0, 0 ); + + sec =reader.sections[ ".shstrtab" ]; + + checkSection( sec, 1, ".shstrtab", SHT_STRTAB, 0, + 0, 17, 0, 0, 0, 0 ); + + sec =reader.sections[ ".note" ]; + + BOOST_CHECK_EQUAL( sec->get_index(), 2 ); + checkSection( sec, 2, ".note", SHT_NOTE, SHF_ALLOC, + 0, 28, 0, 0, 4, 0 ); +} diff --git a/ELFIOTest/ELFIOTest1.cpp b/ELFIOTest/ELFIOTest1.cpp index bb13b7f69a03755a9d12c94b5ae6326740578c0a..b713aca707b0c19e885986f16d2f5c05e6963b62 100644 --- a/ELFIOTest/ELFIOTest1.cpp +++ b/ELFIOTest/ELFIOTest1.cpp @@ -1,345 +1,345 @@ -#ifdef _MSC_VER -#define _SCL_SECURE_NO_WARNINGS -#define ELFIO_NO_INTTYPES -#endif - -#include <boost/test/unit_test.hpp> -#include <boost/test/output_test_stream.hpp> -using boost::test_tools::output_test_stream; - -#include <elfio/elfio.hpp> - -using namespace ELFIO; - - -bool write_obj_i386( bool is64bit ) -{ - elfio writer; - - writer.create( is64bit ? ELFCLASS64 : ELFCLASS32, ELFDATA2LSB ); - writer.set_type( ET_REL ); - writer.set_os_abi( ELFOSABI_LINUX ); - writer.set_machine( is64bit ? EM_X86_64 : EM_386 ); - - // Create code section* - section* text_sec = writer.sections.add( ".text" ); - text_sec->set_type( SHT_PROGBITS ); - text_sec->set_flags( SHF_ALLOC | SHF_EXECINSTR ); - text_sec->set_addr_align( 0x10 ); - - // Add data into it - char text[] = { '\xB8', '\x04', '\x00', '\x00', '\x00', // mov eax, 4 - '\xBB', '\x01', '\x00', '\x00', '\x00', // mov ebx, 1 - '\xB9', '\x00', '\x00', '\x00', '\x00', // mov ecx, msg - '\xBA', '\x0E', '\x00', '\x00', '\x00', // mov edx, 14 - '\xCD', '\x80', // int 0x80 - '\xB8', '\x01', '\x00', '\x00', '\x00', // mov eax, 1 - '\xCD', '\x80' // int 0x80 - }; - text_sec->set_data( text, sizeof( text ) ); - - // Create data section* - section* data_sec = writer.sections.add( ".data" ); - data_sec->set_type( SHT_PROGBITS ); - data_sec->set_flags( SHF_ALLOC | SHF_WRITE ); - data_sec->set_addr_align( 4 ); - - char data[] = { '\x48', '\x65', '\x6C', '\x6C', '\x6F', // msg: db 'Hello, World!', 10 - '\x2C', '\x20', '\x57', '\x6F', '\x72', - '\x6C', '\x64', '\x21', '\x0A' - }; - data_sec->set_data( data, sizeof( data ) ); - - section* str_sec = writer.sections.add( ".strtab" ); - str_sec->set_type( SHT_STRTAB ); - str_sec->set_addr_align( 0x1 ); - - string_section_accessor str_writer( str_sec ); - Elf_Word nStrIndex = str_writer.add_string( "msg" ); - - section* sym_sec = writer.sections.add( ".symtab" ); - sym_sec->set_type( SHT_SYMTAB ); - sym_sec->set_info( 2 ); - sym_sec->set_link( str_sec->get_index() ); - sym_sec->set_addr_align( 4 ); - sym_sec->set_entry_size( writer.get_default_entry_size( SHT_SYMTAB ) ); - - symbol_section_accessor symbol_writer( writer, sym_sec ); - Elf_Word nSymIndex = symbol_writer.add_symbol( nStrIndex, 0, 0, - STB_LOCAL, STT_NOTYPE, 0, - data_sec->get_index() ); - - // Another way to add symbol - symbol_writer.add_symbol( str_writer, "_start", 0x00000000, 0, - STB_WEAK, STT_FUNC, 0, - text_sec->get_index() ); - - // Create relocation table section* - section* rel_sec = writer.sections.add( ".rel.text" ); - rel_sec->set_type( SHT_REL ); - rel_sec->set_info( text_sec->get_index() ); - rel_sec->set_link( sym_sec->get_index() ); - rel_sec->set_addr_align( 4 ); - rel_sec->set_entry_size( writer.get_default_entry_size( SHT_REL ) ); - - relocation_section_accessor rel_writer( writer, rel_sec ); - rel_writer.add_entry( 11, nSymIndex, (unsigned char)R_386_RELATIVE ); - - // Another method to add the same relocation entry - // pRelWriter->AddEntry( pStrWriter, "msg", - // pSymWriter, 29, 0, - // ELF32_ST_INFO( STB_GLOBAL, STT_OBJECT ), 0, - // data_sec->GetIndex(), - // 0, (unsigned char)R_386_RELATIVE ); - - // Create note section* - section* note_sec = writer.sections.add( ".note" ); - note_sec->set_type( SHT_NOTE ); - note_sec->set_addr_align( 1 ); - - // Create notes writer - note_section_accessor note_writer( writer, note_sec ); - note_writer.add_note( 0x77, "Created by ELFIO", 0, 0 ); - - // Create ELF file - writer.save( - is64bit ? - "../elf_examples/write_obj_i386_64.o" : - "../elf_examples/write_obj_i386_32.o" - ); - - return true; -} - - -//////////////////////////////////////////////////////////////////////////////// -BOOST_AUTO_TEST_CASE( write_obj_i386_32 ) -{ - BOOST_CHECK_EQUAL( true, write_obj_i386( false ) ); - output_test_stream output( "../elf_examples/write_obj_i386_32_match.o", true, false ); - std::ifstream input( "../elf_examples/write_obj_i386_32.o", std::ios::binary ); - output << input.rdbuf(); - BOOST_CHECK( output.match_pattern() ); -} - - -//////////////////////////////////////////////////////////////////////////////// -BOOST_AUTO_TEST_CASE( write_obj_i386_64 ) -{ - BOOST_CHECK_EQUAL( true, write_obj_i386( true ) ); - output_test_stream output( "../elf_examples/write_obj_i386_64_match.o", true, false ); - std::ifstream input( "../elf_examples/write_obj_i386_64.o", std::ios::binary ); - output << input.rdbuf(); - BOOST_CHECK( output.match_pattern() ); -} - -bool write_exe_i386( bool is64bit, bool set_addr = false, Elf64_Addr addr = 0 ) -{ - elfio writer; - - writer.create( is64bit ? ELFCLASS64 : ELFCLASS32, ELFDATA2LSB ); - writer.set_os_abi( ELFOSABI_LINUX ); - writer.set_type( ET_EXEC ); - writer.set_machine( is64bit ? EM_X86_64 : EM_386 ); - - // Create code section* - section* text_sec = writer.sections.add( ".text" ); - text_sec->set_type( SHT_PROGBITS ); - text_sec->set_flags( SHF_ALLOC | SHF_EXECINSTR ); - text_sec->set_addr_align( 0x10 ); - if ( set_addr ) { - text_sec->set_address( addr ); - } - - // Add data into it - char text[] = { '\xB8', '\x04', '\x00', '\x00', '\x00', // mov eax, 4 - '\xBB', '\x01', '\x00', '\x00', '\x00', // mov ebx, 1 - '\xB9', '\x20', '\x80', '\x04', '\x08', // mov ecx, msg - '\xBA', '\x0E', '\x00', '\x00', '\x00', // mov edx, 14 - '\xCD', '\x80', // int 0x80 - '\xB8', '\x01', '\x00', '\x00', '\x00', // mov eax, 1 - '\xCD', '\x80' // int 0x80 - }; - text_sec->set_data( text, sizeof( text ) ); - - segment* text_seg = writer.segments.add(); - text_seg->set_type( PT_LOAD ); - text_seg->set_virtual_address( 0x08048000 ); - text_seg->set_physical_address( 0x08048000 ); - text_seg->set_flags( PF_X | PF_R ); - text_seg->set_align( 0x1000 ); - text_seg->add_section_index( text_sec->get_index(), text_sec->get_addr_align() ); - - // Create data section* - section* data_sec = writer.sections.add( ".data" ); - data_sec->set_type( SHT_PROGBITS ); - data_sec->set_flags( SHF_ALLOC | SHF_WRITE ); - data_sec->set_addr_align( 0x4 ); - - char data[] = { '\x48', '\x65', '\x6C', '\x6C', '\x6F', // msg: db 'Hello, World!', 10 - '\x2C', '\x20', '\x57', '\x6F', '\x72', - '\x6C', '\x64', '\x21', '\x0A' - }; - data_sec->set_data( data, sizeof( data ) ); - - segment* data_seg = writer.segments.add(); - data_seg->set_type( PT_LOAD ); - data_seg->set_virtual_address( 0x08048020 ); - data_seg->set_physical_address( 0x08048020 ); - data_seg->set_flags( PF_W | PF_R ); - data_seg->set_align( 0x10 ); - data_seg->add_section_index( data_sec->get_index(), data_sec->get_addr_align() ); - - section* note_sec = writer.sections.add( ".note" ); - note_sec->set_type( SHT_NOTE ); - note_sec->set_addr_align( 1 ); - note_section_accessor note_writer( writer, note_sec ); - note_writer.add_note( 0x01, "Created by ELFIO", 0, 0 ); - char descr[6] = {0x31, 0x32, 0x33, 0x34, 0x35, 0x36}; - note_writer.add_note( 0x01, "Never easier!", descr, sizeof( descr ) ); - - // Create ELF file - writer.set_entry( 0x08048000 ); - - writer.save( - is64bit ? - "../elf_examples/write_exe_i386_64" : - "../elf_examples/write_exe_i386_32" - ); - - return true; -} - - -//////////////////////////////////////////////////////////////////////////////// -BOOST_AUTO_TEST_CASE( write_exe_i386_32 ) -{ - BOOST_CHECK_EQUAL( true, write_exe_i386( false ) ); - output_test_stream output( "../elf_examples/write_exe_i386_32_match", true, false ); - std::ifstream input( "../elf_examples/write_exe_i386_32", std::ios::binary ); - output << input.rdbuf(); - BOOST_CHECK( output.match_pattern() ); -} - - -void checkObjestsAreEqual( std::string file_name1, std::string file_name2 ) -{ - elfio file1; - elfio file2; - BOOST_REQUIRE_EQUAL( file1.load( file_name1 ), true ); - BOOST_CHECK_EQUAL( file1.save( file_name2 ), true ); - BOOST_REQUIRE_EQUAL( file2.load( file_name2 ), true ); - - for (int i = 0; i < file1.sections.size(); ++i ) { - const char* pdata1 = file1.sections[i]->get_data(); - const char* pdata2 = file2.sections[i]->get_data(); - - BOOST_CHECK_EQUAL( file1.sections[i]->get_size(), - file2.sections[i]->get_size() ); - if ( ( file2.sections[i]->get_type() != SHT_NULL ) && - ( file2.sections[i]->get_type() != SHT_NOBITS ) ) { - BOOST_CHECK_EQUAL_COLLECTIONS( pdata1, - pdata1 + file1.sections[i]->get_size(), - pdata2, - pdata2 + file2.sections[i]->get_size() ); - } - } -} - - -void checkExeAreEqual( std::string file_name1, std::string file_name2 ) -{ - checkObjestsAreEqual( file_name1, file_name2 ); - - elfio file1; - elfio file2; - BOOST_REQUIRE_EQUAL( file1.load( file_name1 ), true ); - BOOST_CHECK_EQUAL( file1.save( file_name2 ), true ); - BOOST_REQUIRE_EQUAL( file2.load( file_name2 ), true ); - - for (int i = 0; i < file1.segments.size(); ++i ) { - const char* pdata1 = file1.segments[i]->get_data(); - const char* pdata2 = file2.segments[i]->get_data(); - - BOOST_CHECK_EQUAL( file1.segments[i]->get_file_size(), - file2.segments[i]->get_file_size() ); - if ( ( file2.segments[i]->get_type() != SHT_NULL ) && - ( file2.segments[i]->get_type() != SHT_NOBITS ) ) { - BOOST_CHECK_EQUAL_COLLECTIONS( pdata1, - pdata1 + file1.segments[i]->get_file_size(), - pdata2, - pdata2 + file2.segments[i]->get_file_size() ); - } - } -} - - -//////////////////////////////////////////////////////////////////////////////// -BOOST_AUTO_TEST_CASE( elf_object_copy_32 ) -{ - checkObjestsAreEqual( "../elf_examples/hello_32.o", - "../elf_examples/hello_32_copy.o" ); - checkObjestsAreEqual( "../elf_examples/hello_64.o", - "../elf_examples/hello_64_copy.o" ); - checkObjestsAreEqual( "../elf_examples/test_ppc.o", - "../elf_examples/test_ppc_copy.o" ); - checkObjestsAreEqual( "../elf_examples/write_obj_i386_32.o", - "../elf_examples/write_obj_i386_32_copy.o" ); - checkObjestsAreEqual( "../elf_examples/write_obj_i386_64.o", - "../elf_examples/write_obj_i386_64_copy.o" ); -} - - -//////////////////////////////////////////////////////////////////////////////// -BOOST_AUTO_TEST_CASE( elf_exe_copy_32 ) -{ - checkExeAreEqual( "../elf_examples/asm", - "../elf_examples/asm_copy" ); - checkExeAreEqual( "../elf_examples/asm64", - "../elf_examples/asm64_copy" ); - checkExeAreEqual( "../elf_examples/hello_32", - "../elf_examples/hello_32_copy" ); - checkExeAreEqual( "../elf_examples/hello_64", - "../elf_examples/hello_64_copy" ); - checkExeAreEqual( "../elf_examples/test_ppc", - "../elf_examples/test_ppc_copy" ); -} - - -//////////////////////////////////////////////////////////////////////////////// -BOOST_AUTO_TEST_CASE( section_header_address_update ) -{ - elfio reader; - - write_exe_i386( false, true, 0x0100 ); - - reader.load( "../elf_examples/write_exe_i386_32" ); - section* sec = reader.sections[".text"]; - BOOST_REQUIRE_NE( sec, (section*)0 ); - BOOST_CHECK_EQUAL( sec->get_address(), 0x00000100 ); - - write_exe_i386( false, false, 0 ); - - reader.load( "../elf_examples/write_exe_i386_32" ); - sec = reader.sections[".text"]; - BOOST_REQUIRE_NE( sec, (section*)0 ); - BOOST_CHECK_EQUAL( sec->get_address(), 0x08048000 ); -} - - -//////////////////////////////////////////////////////////////////////////////// -BOOST_AUTO_TEST_CASE( elfio_copy ) -{ - elfio e; - - write_exe_i386( false, true, 0x0100 ); - - e.load( "../elf_examples/write_exe_i386_32" ); - Elf_Half num = e.sections.size(); - section* new_sec = e.sections.add( "new" ); - e.save( "../elf_examples/write_exe_i386_32" ); - BOOST_CHECK_EQUAL( num + 1, e.sections.size() ); - - // Just return back the overwritten file - write_exe_i386( false, false, 0 ); -} +#ifdef _MSC_VER +#define _SCL_SECURE_NO_WARNINGS +#define ELFIO_NO_INTTYPES +#endif + +#include <boost/test/unit_test.hpp> +#include <boost/test/output_test_stream.hpp> +using boost::test_tools::output_test_stream; + +#include <elfio/elfio.hpp> + +using namespace ELFIO; + + +bool write_obj_i386( bool is64bit ) +{ + elfio writer; + + writer.create( is64bit ? ELFCLASS64 : ELFCLASS32, ELFDATA2LSB ); + writer.set_type( ET_REL ); + writer.set_os_abi( ELFOSABI_LINUX ); + writer.set_machine( is64bit ? EM_X86_64 : EM_386 ); + + // Create code section* + section* text_sec = writer.sections.add( ".text" ); + text_sec->set_type( SHT_PROGBITS ); + text_sec->set_flags( SHF_ALLOC | SHF_EXECINSTR ); + text_sec->set_addr_align( 0x10 ); + + // Add data into it + char text[] = { '\xB8', '\x04', '\x00', '\x00', '\x00', // mov eax, 4 + '\xBB', '\x01', '\x00', '\x00', '\x00', // mov ebx, 1 + '\xB9', '\x00', '\x00', '\x00', '\x00', // mov ecx, msg + '\xBA', '\x0E', '\x00', '\x00', '\x00', // mov edx, 14 + '\xCD', '\x80', // int 0x80 + '\xB8', '\x01', '\x00', '\x00', '\x00', // mov eax, 1 + '\xCD', '\x80' // int 0x80 + }; + text_sec->set_data( text, sizeof( text ) ); + + // Create data section* + section* data_sec = writer.sections.add( ".data" ); + data_sec->set_type( SHT_PROGBITS ); + data_sec->set_flags( SHF_ALLOC | SHF_WRITE ); + data_sec->set_addr_align( 4 ); + + char data[] = { '\x48', '\x65', '\x6C', '\x6C', '\x6F', // msg: db 'Hello, World!', 10 + '\x2C', '\x20', '\x57', '\x6F', '\x72', + '\x6C', '\x64', '\x21', '\x0A' + }; + data_sec->set_data( data, sizeof( data ) ); + + section* str_sec = writer.sections.add( ".strtab" ); + str_sec->set_type( SHT_STRTAB ); + str_sec->set_addr_align( 0x1 ); + + string_section_accessor str_writer( str_sec ); + Elf_Word nStrIndex = str_writer.add_string( "msg" ); + + section* sym_sec = writer.sections.add( ".symtab" ); + sym_sec->set_type( SHT_SYMTAB ); + sym_sec->set_info( 2 ); + sym_sec->set_link( str_sec->get_index() ); + sym_sec->set_addr_align( 4 ); + sym_sec->set_entry_size( writer.get_default_entry_size( SHT_SYMTAB ) ); + + symbol_section_accessor symbol_writer( writer, sym_sec ); + Elf_Word nSymIndex = symbol_writer.add_symbol( nStrIndex, 0, 0, + STB_LOCAL, STT_NOTYPE, 0, + data_sec->get_index() ); + + // Another way to add symbol + symbol_writer.add_symbol( str_writer, "_start", 0x00000000, 0, + STB_WEAK, STT_FUNC, 0, + text_sec->get_index() ); + + // Create relocation table section* + section* rel_sec = writer.sections.add( ".rel.text" ); + rel_sec->set_type( SHT_REL ); + rel_sec->set_info( text_sec->get_index() ); + rel_sec->set_link( sym_sec->get_index() ); + rel_sec->set_addr_align( 4 ); + rel_sec->set_entry_size( writer.get_default_entry_size( SHT_REL ) ); + + relocation_section_accessor rel_writer( writer, rel_sec ); + rel_writer.add_entry( 11, nSymIndex, (unsigned char)R_386_RELATIVE ); + + // Another method to add the same relocation entry + // pRelWriter->AddEntry( pStrWriter, "msg", + // pSymWriter, 29, 0, + // ELF32_ST_INFO( STB_GLOBAL, STT_OBJECT ), 0, + // data_sec->GetIndex(), + // 0, (unsigned char)R_386_RELATIVE ); + + // Create note section* + section* note_sec = writer.sections.add( ".note" ); + note_sec->set_type( SHT_NOTE ); + note_sec->set_addr_align( 1 ); + + // Create notes writer + note_section_accessor note_writer( writer, note_sec ); + note_writer.add_note( 0x77, "Created by ELFIO", 0, 0 ); + + // Create ELF file + writer.save( + is64bit ? + "../elf_examples/write_obj_i386_64.o" : + "../elf_examples/write_obj_i386_32.o" + ); + + return true; +} + + +//////////////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE( write_obj_i386_32 ) +{ + BOOST_CHECK_EQUAL( true, write_obj_i386( false ) ); + output_test_stream output( "../elf_examples/write_obj_i386_32_match.o", true, false ); + std::ifstream input( "../elf_examples/write_obj_i386_32.o", std::ios::binary ); + output << input.rdbuf(); + BOOST_CHECK( output.match_pattern() ); +} + + +//////////////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE( write_obj_i386_64 ) +{ + BOOST_CHECK_EQUAL( true, write_obj_i386( true ) ); + output_test_stream output( "../elf_examples/write_obj_i386_64_match.o", true, false ); + std::ifstream input( "../elf_examples/write_obj_i386_64.o", std::ios::binary ); + output << input.rdbuf(); + BOOST_CHECK( output.match_pattern() ); +} + +bool write_exe_i386( bool is64bit, bool set_addr = false, Elf64_Addr addr = 0 ) +{ + elfio writer; + + writer.create( is64bit ? ELFCLASS64 : ELFCLASS32, ELFDATA2LSB ); + writer.set_os_abi( ELFOSABI_LINUX ); + writer.set_type( ET_EXEC ); + writer.set_machine( is64bit ? EM_X86_64 : EM_386 ); + + // Create code section* + section* text_sec = writer.sections.add( ".text" ); + text_sec->set_type( SHT_PROGBITS ); + text_sec->set_flags( SHF_ALLOC | SHF_EXECINSTR ); + text_sec->set_addr_align( 0x10 ); + if ( set_addr ) { + text_sec->set_address( addr ); + } + + // Add data into it + char text[] = { '\xB8', '\x04', '\x00', '\x00', '\x00', // mov eax, 4 + '\xBB', '\x01', '\x00', '\x00', '\x00', // mov ebx, 1 + '\xB9', '\x20', '\x80', '\x04', '\x08', // mov ecx, msg + '\xBA', '\x0E', '\x00', '\x00', '\x00', // mov edx, 14 + '\xCD', '\x80', // int 0x80 + '\xB8', '\x01', '\x00', '\x00', '\x00', // mov eax, 1 + '\xCD', '\x80' // int 0x80 + }; + text_sec->set_data( text, sizeof( text ) ); + + segment* text_seg = writer.segments.add(); + text_seg->set_type( PT_LOAD ); + text_seg->set_virtual_address( 0x08048000 ); + text_seg->set_physical_address( 0x08048000 ); + text_seg->set_flags( PF_X | PF_R ); + text_seg->set_align( 0x1000 ); + text_seg->add_section_index( text_sec->get_index(), text_sec->get_addr_align() ); + + // Create data section* + section* data_sec = writer.sections.add( ".data" ); + data_sec->set_type( SHT_PROGBITS ); + data_sec->set_flags( SHF_ALLOC | SHF_WRITE ); + data_sec->set_addr_align( 0x4 ); + + char data[] = { '\x48', '\x65', '\x6C', '\x6C', '\x6F', // msg: db 'Hello, World!', 10 + '\x2C', '\x20', '\x57', '\x6F', '\x72', + '\x6C', '\x64', '\x21', '\x0A' + }; + data_sec->set_data( data, sizeof( data ) ); + + segment* data_seg = writer.segments.add(); + data_seg->set_type( PT_LOAD ); + data_seg->set_virtual_address( 0x08048020 ); + data_seg->set_physical_address( 0x08048020 ); + data_seg->set_flags( PF_W | PF_R ); + data_seg->set_align( 0x10 ); + data_seg->add_section_index( data_sec->get_index(), data_sec->get_addr_align() ); + + section* note_sec = writer.sections.add( ".note" ); + note_sec->set_type( SHT_NOTE ); + note_sec->set_addr_align( 1 ); + note_section_accessor note_writer( writer, note_sec ); + note_writer.add_note( 0x01, "Created by ELFIO", 0, 0 ); + char descr[6] = {0x31, 0x32, 0x33, 0x34, 0x35, 0x36}; + note_writer.add_note( 0x01, "Never easier!", descr, sizeof( descr ) ); + + // Create ELF file + writer.set_entry( 0x08048000 ); + + writer.save( + is64bit ? + "../elf_examples/write_exe_i386_64" : + "../elf_examples/write_exe_i386_32" + ); + + return true; +} + + +//////////////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE( write_exe_i386_32 ) +{ + BOOST_CHECK_EQUAL( true, write_exe_i386( false ) ); + output_test_stream output( "../elf_examples/write_exe_i386_32_match", true, false ); + std::ifstream input( "../elf_examples/write_exe_i386_32", std::ios::binary ); + output << input.rdbuf(); + BOOST_CHECK( output.match_pattern() ); +} + + +void checkObjestsAreEqual( std::string file_name1, std::string file_name2 ) +{ + elfio file1; + elfio file2; + BOOST_REQUIRE_EQUAL( file1.load( file_name1 ), true ); + BOOST_CHECK_EQUAL( file1.save( file_name2 ), true ); + BOOST_REQUIRE_EQUAL( file2.load( file_name2 ), true ); + + for (int i = 0; i < file1.sections.size(); ++i ) { + const char* pdata1 = file1.sections[i]->get_data(); + const char* pdata2 = file2.sections[i]->get_data(); + + BOOST_CHECK_EQUAL( file1.sections[i]->get_size(), + file2.sections[i]->get_size() ); + if ( ( file2.sections[i]->get_type() != SHT_NULL ) && + ( file2.sections[i]->get_type() != SHT_NOBITS ) ) { + BOOST_CHECK_EQUAL_COLLECTIONS( pdata1, + pdata1 + file1.sections[i]->get_size(), + pdata2, + pdata2 + file2.sections[i]->get_size() ); + } + } +} + + +void checkExeAreEqual( std::string file_name1, std::string file_name2 ) +{ + checkObjestsAreEqual( file_name1, file_name2 ); + + elfio file1; + elfio file2; + BOOST_REQUIRE_EQUAL( file1.load( file_name1 ), true ); + BOOST_CHECK_EQUAL( file1.save( file_name2 ), true ); + BOOST_REQUIRE_EQUAL( file2.load( file_name2 ), true ); + + for (int i = 0; i < file1.segments.size(); ++i ) { + const char* pdata1 = file1.segments[i]->get_data(); + const char* pdata2 = file2.segments[i]->get_data(); + + BOOST_CHECK_EQUAL( file1.segments[i]->get_file_size(), + file2.segments[i]->get_file_size() ); + if ( ( file2.segments[i]->get_type() != SHT_NULL ) && + ( file2.segments[i]->get_type() != SHT_NOBITS ) ) { + BOOST_CHECK_EQUAL_COLLECTIONS( pdata1, + pdata1 + file1.segments[i]->get_file_size(), + pdata2, + pdata2 + file2.segments[i]->get_file_size() ); + } + } +} + + +//////////////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE( elf_object_copy_32 ) +{ + checkObjestsAreEqual( "../elf_examples/hello_32.o", + "../elf_examples/hello_32_copy.o" ); + checkObjestsAreEqual( "../elf_examples/hello_64.o", + "../elf_examples/hello_64_copy.o" ); + checkObjestsAreEqual( "../elf_examples/test_ppc.o", + "../elf_examples/test_ppc_copy.o" ); + checkObjestsAreEqual( "../elf_examples/write_obj_i386_32.o", + "../elf_examples/write_obj_i386_32_copy.o" ); + checkObjestsAreEqual( "../elf_examples/write_obj_i386_64.o", + "../elf_examples/write_obj_i386_64_copy.o" ); +} + + +//////////////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE( elf_exe_copy_32 ) +{ + checkExeAreEqual( "../elf_examples/asm", + "../elf_examples/asm_copy" ); + checkExeAreEqual( "../elf_examples/asm64", + "../elf_examples/asm64_copy" ); + checkExeAreEqual( "../elf_examples/hello_32", + "../elf_examples/hello_32_copy" ); + checkExeAreEqual( "../elf_examples/hello_64", + "../elf_examples/hello_64_copy" ); + checkExeAreEqual( "../elf_examples/test_ppc", + "../elf_examples/test_ppc_copy" ); +} + + +//////////////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE( section_header_address_update ) +{ + elfio reader; + + write_exe_i386( false, true, 0x0100 ); + + reader.load( "../elf_examples/write_exe_i386_32" ); + section* sec = reader.sections[".text"]; + BOOST_REQUIRE_NE( sec, (section*)0 ); + BOOST_CHECK_EQUAL( sec->get_address(), 0x00000100 ); + + write_exe_i386( false, false, 0 ); + + reader.load( "../elf_examples/write_exe_i386_32" ); + sec = reader.sections[".text"]; + BOOST_REQUIRE_NE( sec, (section*)0 ); + BOOST_CHECK_EQUAL( sec->get_address(), 0x08048000 ); +} + + +//////////////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE( elfio_copy ) +{ + elfio e; + + write_exe_i386( false, true, 0x0100 ); + + e.load( "../elf_examples/write_exe_i386_32" ); + Elf_Half num = e.sections.size(); + section* new_sec = e.sections.add( "new" ); + e.save( "../elf_examples/write_exe_i386_32" ); + BOOST_CHECK_EQUAL( num + 1, e.sections.size() ); + + // Just return back the overwritten file + write_exe_i386( false, false, 0 ); +} diff --git a/ELFIOTest/Makefile b/ELFIOTest/Makefile index 94feefa75483e9f9b2104cc512e857e1cae06c3b..644e4026931ff26339b46151d85657c442ccb531 100644 --- a/ELFIOTest/Makefile +++ b/ELFIOTest/Makefile @@ -1,27 +1,27 @@ -CXX=g++ -CPPFLAGS=-c -Wall -std=c++0x -I../elfio -LDLIBS=-lboost_test_exec_monitor-mt - -ELFIODIR=../elfio/ -SOURCES=ELFIOTest.cpp ELFIOTest1.cpp -INCLUDES=$(ELFIODIR)elfio.hpp $(ELFIODIR)elfio_header.hpp \ - $(ELFIODIR)elfio_note.hpp $(ELFIODIR)elfio_section.hpp \ - $(ELFIODIR)elfio_segment.hpp $(ELFIODIR)elfio_strings.hpp \ - $(ELFIODIR)elfio_symbols.hpp $(ELFIODIR)elfio_utils.hpp \ - $(ELFIODIR)elf_types.hpp -OBJECTS=$(SOURCES:.cpp=.o) -EXECUTABLE=ELFIOTest - -all: $(SOURCES) $(EXECUTABLE) $(INCLUDES) - -$(EXECUTABLE): $(OBJECTS) - $(CXX) $(LDFLAGS) $(OBJECTS) $(LDLIBS) -o $@ - -.cpp.o: - $(CXX) $(CPPFLAGS) $< -o $@ - -test: $(EXECUTABLE) - ./$(EXECUTABLE) -r short - -clean: - rm $(OBJECTS) $(EXECUTABLE) +CXX=g++ +CPPFLAGS=-c -Wall -std=c++0x -I../elfio +LDLIBS=-lboost_test_exec_monitor-mt + +ELFIODIR=../elfio/ +SOURCES=ELFIOTest.cpp ELFIOTest1.cpp +INCLUDES=$(ELFIODIR)elfio.hpp $(ELFIODIR)elfio_header.hpp \ + $(ELFIODIR)elfio_note.hpp $(ELFIODIR)elfio_section.hpp \ + $(ELFIODIR)elfio_segment.hpp $(ELFIODIR)elfio_strings.hpp \ + $(ELFIODIR)elfio_symbols.hpp $(ELFIODIR)elfio_utils.hpp \ + $(ELFIODIR)elf_types.hpp +OBJECTS=$(SOURCES:.cpp=.o) +EXECUTABLE=ELFIOTest + +all: $(SOURCES) $(EXECUTABLE) $(INCLUDES) + +$(EXECUTABLE): $(OBJECTS) + $(CXX) $(LDFLAGS) $(OBJECTS) $(LDLIBS) -o $@ + +.cpp.o: + $(CXX) $(CPPFLAGS) $< -o $@ + +test: $(EXECUTABLE) + ./$(EXECUTABLE) -r short + +clean: + rm $(OBJECTS) $(EXECUTABLE) diff --git a/Makefile.am b/Makefile.am index 9af7318963beda086456dec78eaa863f7b852b58..56573d9f60c67ab96ea4477fd6a5e63685bc9fc7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,9 +1,9 @@ -SUBDIRS = examples -nobase_include_HEADERS = elfio/elf_types.hpp elfio/elfi_dynamic.hpp \ - elfio/elfio.hpp elfio/elfio_header.hpp \ - elfio/elfio_note.hpp elfio/elfio_relocation.hpp \ - elfio/elfio_section.hpp elfio/elfio_segment.hpp \ - elfio/elfio_strings.hpp elfio/elfio_symbols.hpp \ - elfio/elfio_utils.hpp elfio/elfo_dynamic.hpp \ - elfio/elfio_dump.hpp -EXTRA_DIST = doc/elfio.pdf +SUBDIRS = examples +nobase_include_HEADERS = elfio/elf_types.hpp elfio/elfi_dynamic.hpp \ + elfio/elfio.hpp elfio/elfio_header.hpp \ + elfio/elfio_note.hpp elfio/elfio_relocation.hpp \ + elfio/elfio_section.hpp elfio/elfio_segment.hpp \ + elfio/elfio_strings.hpp elfio/elfio_symbols.hpp \ + elfio/elfio_utils.hpp elfio/elfo_dynamic.hpp \ + elfio/elfio_dump.hpp +EXTRA_DIST = doc/elfio.pdf diff --git a/Makefile.in b/Makefile.in index 00ffdb0652bcfe7b5a9f63defc49350f08443116..e2a62c462a541f264f47f8258cebcb2155dbf4dc 100644 --- a/Makefile.in +++ b/Makefile.in @@ -38,7 +38,7 @@ DIST_COMMON = README $(am__configure_deps) $(nobase_include_HEADERS) \ $(top_srcdir)/configure AUTHORS COPYING ChangeLog INSTALL NEWS \ depcomp install-sh missing ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/configure.in +am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ @@ -234,15 +234,15 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ - echo ' cd $(srcdir) && $(AUTOMAKE) --gnu'; \ - $(am__cd) $(srcdir) && $(AUTOMAKE) --gnu \ + echo ' cd $(srcdir) && $(AUTOMAKE) --foreign'; \ + $(am__cd) $(srcdir) && $(AUTOMAKE) --foreign \ && exit 0; \ exit 1;; \ esac; \ done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu Makefile'; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign Makefile'; \ $(am__cd) $(top_srcdir) && \ - $(AUTOMAKE) --gnu Makefile + $(AUTOMAKE) --foreign Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ diff --git a/README b/README index 33609f8805d764b855c2cc992663582bc8f9ea88..89e5c5e8e109feac0aca1d2a5350389b004bb9cf 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -ELFIO is a C++ library for reading and generating files in the ELF binary -format. This library is unique and not based on any other product. It is also -platform independent. The library uses standard ANSI C++ constructions and -runs on a wide variety of architectures. +ELFIO is a C++ library for reading and generating files in the ELF binary +format. This library is unique and not based on any other product. It is also +platform independent. The library uses standard ANSI C++ constructions and +runs on a wide variety of architectures. diff --git a/configure b/configure index 4398d019a5f76f83745f879f4131ee4265875f06..792dbe1a93efa8c2db27642aa5edffbc58a57d01 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.68 for ELFIO 2.0.0. +# Generated by GNU Autoconf 2.68 for ELFIO 2.0. # # # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, @@ -556,8 +556,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='ELFIO' PACKAGE_TARNAME='elfio' -PACKAGE_VERSION='2.0.0' -PACKAGE_STRING='ELFIO 2.0.0' +PACKAGE_VERSION='2.0' +PACKAGE_STRING='ELFIO 2.0' PACKAGE_BUGREPORT='' PACKAGE_URL='' @@ -1199,7 +1199,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures ELFIO 2.0.0 to adapt to many kinds of systems. +\`configure' configures ELFIO 2.0 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1265,7 +1265,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of ELFIO 2.0.0:";; + short | recursive ) echo "Configuration of ELFIO 2.0:";; esac cat <<\_ACEOF @@ -1351,7 +1351,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -ELFIO configure 2.0.0 +ELFIO configure 2.0 generated by GNU Autoconf 2.68 Copyright (C) 2010 Free Software Foundation, Inc. @@ -1406,7 +1406,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by ELFIO $as_me 2.0.0, which was +It was created by ELFIO $as_me 2.0, which was generated by GNU Autoconf 2.68. Invocation command line was $ $0 $@ @@ -1754,7 +1754,6 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu - am__api_version='1.11' ac_aux_dir= @@ -2221,8 +2220,8 @@ fi # Define the identity of the package. - PACKAGE=ELFIO - VERSION=2.0.0 + PACKAGE='elfio' + VERSION='2.0' cat >>confdefs.h <<_ACEOF @@ -2262,7 +2261,6 @@ am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -' - ac_ext=cpp ac_cpp='$CXXCPP $CPPFLAGS' ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -2961,12 +2959,6 @@ else fi - - - - - - ac_config_files="$ac_config_files Makefile examples/Makefile examples/elfdump/Makefile examples/tutorial/Makefile examples/writer/Makefile examples/write_obj/Makefile" cat >confcache <<\_ACEOF @@ -3539,7 +3531,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by ELFIO $as_me 2.0.0, which was +This file was extended by ELFIO $as_me 2.0, which was generated by GNU Autoconf 2.68. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -3596,7 +3588,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -ELFIO config.status 2.0.0 +ELFIO config.status 2.0 configured by $0, generated by GNU Autoconf 2.68, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000000000000000000000000000000000000..96e4603e13117569979d091666ea0367da6e20f7 --- /dev/null +++ b/configure.ac @@ -0,0 +1,12 @@ +AC_INIT([ELFIO], [2.0]) +AM_INIT_AUTOMAKE([-Wall -Werror foreign]) +AC_PROG_CXX +AC_CONFIG_FILES([ + Makefile + examples/Makefile + examples/elfdump/Makefile + examples/tutorial/Makefile + examples/writer/Makefile + examples/write_obj/Makefile +]) +AC_OUTPUT diff --git a/configure.in b/configure.in deleted file mode 100644 index 258b03f347b25f97dfa00548cd2067e190ba9563..0000000000000000000000000000000000000000 --- a/configure.in +++ /dev/null @@ -1,23 +0,0 @@ -dnl Process this file with autoconf to produce a configure script. -AC_INIT(ELFIO, 2.0.0) - -AM_INIT_AUTOMAKE(ELFIO, 2.0.0) - -dnl Checks for programs. -AC_PROG_CXX -AC_PROG_INSTALL - -dnl Checks for libraries. - -dnl Checks for header files. - -dnl Checks for typedefs, structures, and compiler characteristics. - -dnl Checks for library functions. - -AC_OUTPUT([Makefile - examples/Makefile - examples/elfdump/Makefile - examples/tutorial/Makefile - examples/writer/Makefile - examples/write_obj/Makefile]) diff --git a/cygwin/CYGWIN-PATCHES/ELFIO-1.0.0.README b/cygwin/CYGWIN-PATCHES/ELFIO-1.0.0.README index ff66c61bcf2594d7b84cfedacde11af753e3d262..525cf6b81870234ff2aabefb612bac779bdcfb16 100644 --- a/cygwin/CYGWIN-PATCHES/ELFIO-1.0.0.README +++ b/cygwin/CYGWIN-PATCHES/ELFIO-1.0.0.README @@ -1,62 +1,62 @@ -ELFIO-1.0.0 ------------------------------------------- -ELFIO is a C++ library for reading and generating files in the -ELF (Executable and Linkable Format) binary format. This library is -unique and not based on any other product. It is also platform -independent. The library uses standard ANSI C++ constructions and runs -on a wide variety of architectures. - -More examples for using this library located at Examples directory -of the source package distribution. - - -Runtime requirements: - cygwin-1.3.10 or newer - -Build requirements: - cygwin-1.3.10 or newer - -Canonical homepage: - http://sourceforge.net/projects/elfio - -Canonical download: - http://sourceforge.net/project/showfiles.php?group_id=19959 - ------------------------------------- - -Build instructions: - unpack ELFIO-1.0.0-1-src.tar.bz2 - cd /usr/src - ./ELFIO-1.0.0-1.sh all - -This will create: - /usr/src/ELFIO-1.0.0-1.tar.bz2 - /usr/src/ELFIO-1.0.0-1-src.tar.bz2 - -------------------------------------------- - -Files included in the binary distro - - /lib/libELFIO.a - /usr/bin/ELFDump - /usr/include/ELFIO.h - /usr/include/ELFI.h - /usr/include/ELFO.h - /usr/include/ELFTypes.h - /usr/doc/ELFIO-1.0.0/AUTHORS - /usr/doc/ELFIO-1.0.0/COPYING - /usr/doc/ELFIO-1.0.0/README - /usr/doc/ELFIO-1.0.0/tutorial.pdf - /usr/doc/ELFIO-1.0.0/tutorial.cpp - /usr/doc/Cygwin/ELFIO-1.0.0.README - ------------------- - -Port Notes: - ------ version 1.0.0 ----- -Initial release - - -Cygwin port maintained by: Serge Lamikhov-Center to_serge@sourceforge.net - +ELFIO-1.0.0 +------------------------------------------ +ELFIO is a C++ library for reading and generating files in the +ELF (Executable and Linkable Format) binary format. This library is +unique and not based on any other product. It is also platform +independent. The library uses standard ANSI C++ constructions and runs +on a wide variety of architectures. + +More examples for using this library located at Examples directory +of the source package distribution. + + +Runtime requirements: + cygwin-1.3.10 or newer + +Build requirements: + cygwin-1.3.10 or newer + +Canonical homepage: + http://sourceforge.net/projects/elfio + +Canonical download: + http://sourceforge.net/project/showfiles.php?group_id=19959 + +------------------------------------ + +Build instructions: + unpack ELFIO-1.0.0-1-src.tar.bz2 + cd /usr/src + ./ELFIO-1.0.0-1.sh all + +This will create: + /usr/src/ELFIO-1.0.0-1.tar.bz2 + /usr/src/ELFIO-1.0.0-1-src.tar.bz2 + +------------------------------------------- + +Files included in the binary distro + + /lib/libELFIO.a + /usr/bin/ELFDump + /usr/include/ELFIO.h + /usr/include/ELFI.h + /usr/include/ELFO.h + /usr/include/ELFTypes.h + /usr/doc/ELFIO-1.0.0/AUTHORS + /usr/doc/ELFIO-1.0.0/COPYING + /usr/doc/ELFIO-1.0.0/README + /usr/doc/ELFIO-1.0.0/tutorial.pdf + /usr/doc/ELFIO-1.0.0/tutorial.cpp + /usr/doc/Cygwin/ELFIO-1.0.0.README + +------------------ + +Port Notes: + +----- version 1.0.0 ----- +Initial release + + +Cygwin port maintained by: Serge Lamikhov-Center to_serge@sourceforge.net + diff --git a/cygwin/CYGWIN-PATCHES/setup.hint b/cygwin/CYGWIN-PATCHES/setup.hint index 0ea04329db3ee4ebe7ac7fe7ebb4b4e111095185..cd567acdb1401b472af1f09725cabec7cedb7f35 100644 --- a/cygwin/CYGWIN-PATCHES/setup.hint +++ b/cygwin/CYGWIN-PATCHES/setup.hint @@ -1,9 +1,9 @@ -# ELFIO library -category: Devel Libs -requires: cygwin -sdesc: "ELF file reader and producer implemented as a C++ library" -ldesc: "ELFIO is a C++ library for reading and generating files in the -ELF (Executable and Linkable Format) binary format. This library is -unique and not based on any other product. It is also platform -independent. The library uses standard ANSI C++ constructions and runs -on a wide variety of architectures." +# ELFIO library +category: Devel Libs +requires: cygwin +sdesc: "ELF file reader and producer implemented as a C++ library" +ldesc: "ELFIO is a C++ library for reading and generating files in the +ELF (Executable and Linkable Format) binary format. This library is +unique and not based on any other product. It is also platform +independent. The library uses standard ANSI C++ constructions and runs +on a wide variety of architectures." diff --git a/cygwin/ELFIO-1.0.0-1.sh b/cygwin/ELFIO-1.0.0-1.sh index 7ff4a6a672a826d48b54510e0dfdfb8c6cfe22b4..a230ea29bd42b19debc63d3d853e0d7f0460e0c1 100755 --- a/cygwin/ELFIO-1.0.0-1.sh +++ b/cygwin/ELFIO-1.0.0-1.sh @@ -1,179 +1,179 @@ -#!/bin/sh -# find out where the build script is located -tdir=`echo "$0" | sed 's%[\\/][^\\/][^\\/]*$%%'` -test "x$tdir" = "x$0" && tdir=. -scriptdir=`cd $tdir; pwd` -# find src directory. -# If scriptdir ends in SPECS, then topdir is $scriptdir/.. -# If scriptdir ends in CYGWIN-PATCHES, then topdir is $scriptdir/../.. -# Otherwise, we assume that topdir = scriptdir -topdir1=`echo ${scriptdir} | sed 's%/SPECS$%%'` -topdir2=`echo ${scriptdir} | sed 's%/CYGWIN-PATCHES$%%'` -if [ "x$topdir1" != "x$scriptdir" ] ; then # SPECS - topdir=`cd ${scriptdir}/..; pwd` -else - if [ "x$topdir2" != "x$scriptdir" ] ; then # CYGWIN-PATCHES - topdir=`cd ${scriptdir}/../..; pwd` - else - topdir=`cd ${scriptdir}; pwd` - fi -fi - -tscriptname=`basename $0 .sh` -export PKG=`echo $tscriptname | sed -e 's/\-[^\-]*\-[^\-]*$//'` -export VER=`echo $tscriptname | sed -e 's/^[^\-]*\-//' -e 's/\-[^\-]*$//'` -export REL=`echo $tscriptname | sed -e 's/^[^\-]*\-[^\-]*\-//'` -export FULLPKG=${PKG}-${VER}-${REL} -# if the orig src package is bzip2'ed, remember to -# change 'z' to 'j' in the 'tar xvzf' commands in the -# prep) and mkpatch) sections -export src_orig_pkg_name=${PKG}-${VER}.tar.gz -export src_pkg_name=${FULLPKG}-src.tar.bz2 -export src_patch_name=${FULLPKG}.patch -export bin_pkg_name=${FULLPKG}.tar.bz2 - -export src_orig_pkg=${topdir}/${src_orig_pkg_name} -export src_pkg=${topdir}/${src_pkg_name} -export src_patch=${topdir}/${src_patch_name} -export bin_pkg=${topdir}/${bin_pkg_name} -export srcdir=${topdir}/${PKG}-${VER} -export objdir=${srcdir}/.build -export instdir=${srcdir}/.inst -export srcinstdir=${srcdir}/.sinst -export checkfile=${topdir}/${FULLPKG}.check -# run on -host=i686-pc-cygwin -# if this package creates binaries, they run on -target=i686-pc-cygwin -prefix=/usr -sysconfdir=/etc -MY_CFLAGS="-O2" -MY_CXXFLAGS="-O2" -MY_LDFLAGS= - -mkdirs() { - (cd ${topdir} && \ - mkdir -p ${objdir} && \ - mkdir -p ${instdir} && \ - mkdir -p ${srcinstdir} ) -} -prep() { - (cd ${topdir} && \ - tar xvzf ${src_orig_pkg} ; \ - cd ${topdir} && \ - patch -p0 < ${src_patch} - && mkdirs ) -} -conf() { - (cd ${objdir} && \ - CFLAGS="${MY_CFLAGS}" LDFLAGS="${MY_LDFLAGS}" \ - CXXFLAGS="${MY_CXXFLAGS}" LDFLAGS="${MY_LDFLAGS}" \ - ${srcdir}/configure --host=${host} --target=${target} \ - --srcdir=${srcdir} --prefix=${prefix} \ - --exec-prefix=${prefix} --sysconfdir=${sysconfdir} \ - --libdir=/lib --includedir=${prefix}/include \ - --libexecdir='${sbindir}' --localstatedir=/var \ - --datadir='${prefix}/share' -) -} -build() { - (cd ${objdir} && \ - CFLAGS="${MY_CFLAGS}" make ) -} -check() { - (cd ${objdir} && \ - make test | tee ${checkfile} 2>&1 ) -} -clean() { - (cd ${objdir} && \ - make clean ) -} -install() { - (cd ${objdir} && \ - make install DESTDIR=${instdir} - if [ -f ${instdir}${prefix}/info/dir ] ; then \ - rm ${instdir}${prefix}/info/dir ; \ - fi && \ - if [ ! -d ${instdir}${prefix}/doc/${PKG}-${VER} ]; then \ - mkdir -p ${instdir}${prefix}/doc/${PKG}-${VER} ; \ - fi && \ - if [ ! -d ${instdir}${prefix}/doc/Cygwin ]; then \ - mkdir -p ${instdir}${prefix}/doc/Cygwin ; \ - fi && \ - templist=""; \ - for f in ${srcdir}/ANNOUNCE ${srcdir}/CHANGES ${srcdir}/INSTALL \ - ${srcdir}/KNOWNBUG ${srcdir}/LICENSE ${srcdir}/README \ - ${srcdir}/AUTHORS ${srcdir}/KNOWNBUG ${srcdir}/COPYING \ - ${srcdir}/doc/tutorial.pdf \ - ${srcdir}/Examples/tutorial/tutorial.cpp \ - ${srcdir}/TODO ; do \ - if [ -f $f ] ; then \ - templist="$templist $f"; \ - fi ; \ - done && \ - if [ ! "x$templist" = "x" ]; then \ - /usr/bin/install -m 644 $templist \ - ${instdir}${prefix}/doc/${PKG}-${VER} ; - fi && \ - if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}-${VER}.README ]; then \ - /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/${PKG}-${VER}.README \ - ${instdir}${prefix}/doc/Cygwin/${PKG}-${VER}.README ; \ - else \ - if [ -f ${srcdir}/CYGWIN-PATCHES/README ]; then \ - /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/README \ - ${instdir}${prefix}/doc/Cygwin/${PKG}-${VER}.README ; \ - fi ;\ - fi ; ) -} -strip() { - (cd ${instdir} && \ - find . -name "*.dll" | xargs strip > /dev/null 2>&1 - find . -name "*.exe" | xargs strip > /dev/null 2>&1 ) -} -pkg() { - (cd ${instdir} && \ - tar cvjf ${bin_pkg} * ) -} -mkpatch() { - (cd ${srcdir} && \ - tar xvzf ${src_orig_pkg} ;\ - mv ${PKG}-${VER} ../${PKG}-${VER}-orig && \ - cd ${topdir} && \ - diff -urN -x '.build' -x '.inst' -x '.sinst' \ - ${PKG}-${VER}-orig ${PKG}-${VER} > \ - ${srcinstdir}/${src_patch_name} ; \ - rm -rf ${PKG}-${VER}-orig ) -} -spkg() { - (mkpatch && \ - cp ${src_orig_pkg} ${srcinstdir}/${src_orig_pkg_name} && \ - cp $0 ${srcinstdir}/`basename $0` && \ - cd ${srcinstdir} && \ - tar cvjf ${src_pkg} * ) -} -finish() { - rm -rf ${srcdir} -} -case $1 in - prep) prep ; STATUS=$? ;; - mkdirs) mkdirs; STATUS=$? ;; - conf) conf ; STATUS=$? ;; - build) build ; STATUS=$? ;; - check) check ; STATUS=$? ;; - clean) clean ; STATUS=$? ;; - install) install ; STATUS=$? ;; - strip) strip ; STATUS=$? ;; - package) pkg ; STATUS=$? ;; - pkg) pkg ; STATUS=$? ;; - mkpatch) mkpatch ; STATUS=$? ;; - src-package) spkg ; STATUS=$? ;; - spkg) spkg ; STATUS=$? ;; - finish) finish ; STATUS=$? ;; - all) prep && conf && build && install && \ - strip && pkg && spkg && finish ; \ - STATUS=$? ;; - *) echo "Error: bad arguments" ; exit 1 ;; -esac -exit ${STATUS} - - +#!/bin/sh +# find out where the build script is located +tdir=`echo "$0" | sed 's%[\\/][^\\/][^\\/]*$%%'` +test "x$tdir" = "x$0" && tdir=. +scriptdir=`cd $tdir; pwd` +# find src directory. +# If scriptdir ends in SPECS, then topdir is $scriptdir/.. +# If scriptdir ends in CYGWIN-PATCHES, then topdir is $scriptdir/../.. +# Otherwise, we assume that topdir = scriptdir +topdir1=`echo ${scriptdir} | sed 's%/SPECS$%%'` +topdir2=`echo ${scriptdir} | sed 's%/CYGWIN-PATCHES$%%'` +if [ "x$topdir1" != "x$scriptdir" ] ; then # SPECS + topdir=`cd ${scriptdir}/..; pwd` +else + if [ "x$topdir2" != "x$scriptdir" ] ; then # CYGWIN-PATCHES + topdir=`cd ${scriptdir}/../..; pwd` + else + topdir=`cd ${scriptdir}; pwd` + fi +fi + +tscriptname=`basename $0 .sh` +export PKG=`echo $tscriptname | sed -e 's/\-[^\-]*\-[^\-]*$//'` +export VER=`echo $tscriptname | sed -e 's/^[^\-]*\-//' -e 's/\-[^\-]*$//'` +export REL=`echo $tscriptname | sed -e 's/^[^\-]*\-[^\-]*\-//'` +export FULLPKG=${PKG}-${VER}-${REL} +# if the orig src package is bzip2'ed, remember to +# change 'z' to 'j' in the 'tar xvzf' commands in the +# prep) and mkpatch) sections +export src_orig_pkg_name=${PKG}-${VER}.tar.gz +export src_pkg_name=${FULLPKG}-src.tar.bz2 +export src_patch_name=${FULLPKG}.patch +export bin_pkg_name=${FULLPKG}.tar.bz2 + +export src_orig_pkg=${topdir}/${src_orig_pkg_name} +export src_pkg=${topdir}/${src_pkg_name} +export src_patch=${topdir}/${src_patch_name} +export bin_pkg=${topdir}/${bin_pkg_name} +export srcdir=${topdir}/${PKG}-${VER} +export objdir=${srcdir}/.build +export instdir=${srcdir}/.inst +export srcinstdir=${srcdir}/.sinst +export checkfile=${topdir}/${FULLPKG}.check +# run on +host=i686-pc-cygwin +# if this package creates binaries, they run on +target=i686-pc-cygwin +prefix=/usr +sysconfdir=/etc +MY_CFLAGS="-O2" +MY_CXXFLAGS="-O2" +MY_LDFLAGS= + +mkdirs() { + (cd ${topdir} && \ + mkdir -p ${objdir} && \ + mkdir -p ${instdir} && \ + mkdir -p ${srcinstdir} ) +} +prep() { + (cd ${topdir} && \ + tar xvzf ${src_orig_pkg} ; \ + cd ${topdir} && \ + patch -p0 < ${src_patch} + && mkdirs ) +} +conf() { + (cd ${objdir} && \ + CFLAGS="${MY_CFLAGS}" LDFLAGS="${MY_LDFLAGS}" \ + CXXFLAGS="${MY_CXXFLAGS}" LDFLAGS="${MY_LDFLAGS}" \ + ${srcdir}/configure --host=${host} --target=${target} \ + --srcdir=${srcdir} --prefix=${prefix} \ + --exec-prefix=${prefix} --sysconfdir=${sysconfdir} \ + --libdir=/lib --includedir=${prefix}/include \ + --libexecdir='${sbindir}' --localstatedir=/var \ + --datadir='${prefix}/share' +) +} +build() { + (cd ${objdir} && \ + CFLAGS="${MY_CFLAGS}" make ) +} +check() { + (cd ${objdir} && \ + make test | tee ${checkfile} 2>&1 ) +} +clean() { + (cd ${objdir} && \ + make clean ) +} +install() { + (cd ${objdir} && \ + make install DESTDIR=${instdir} + if [ -f ${instdir}${prefix}/info/dir ] ; then \ + rm ${instdir}${prefix}/info/dir ; \ + fi && \ + if [ ! -d ${instdir}${prefix}/doc/${PKG}-${VER} ]; then \ + mkdir -p ${instdir}${prefix}/doc/${PKG}-${VER} ; \ + fi && \ + if [ ! -d ${instdir}${prefix}/doc/Cygwin ]; then \ + mkdir -p ${instdir}${prefix}/doc/Cygwin ; \ + fi && \ + templist=""; \ + for f in ${srcdir}/ANNOUNCE ${srcdir}/CHANGES ${srcdir}/INSTALL \ + ${srcdir}/KNOWNBUG ${srcdir}/LICENSE ${srcdir}/README \ + ${srcdir}/AUTHORS ${srcdir}/KNOWNBUG ${srcdir}/COPYING \ + ${srcdir}/doc/tutorial.pdf \ + ${srcdir}/Examples/tutorial/tutorial.cpp \ + ${srcdir}/TODO ; do \ + if [ -f $f ] ; then \ + templist="$templist $f"; \ + fi ; \ + done && \ + if [ ! "x$templist" = "x" ]; then \ + /usr/bin/install -m 644 $templist \ + ${instdir}${prefix}/doc/${PKG}-${VER} ; + fi && \ + if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}-${VER}.README ]; then \ + /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/${PKG}-${VER}.README \ + ${instdir}${prefix}/doc/Cygwin/${PKG}-${VER}.README ; \ + else \ + if [ -f ${srcdir}/CYGWIN-PATCHES/README ]; then \ + /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/README \ + ${instdir}${prefix}/doc/Cygwin/${PKG}-${VER}.README ; \ + fi ;\ + fi ; ) +} +strip() { + (cd ${instdir} && \ + find . -name "*.dll" | xargs strip > /dev/null 2>&1 + find . -name "*.exe" | xargs strip > /dev/null 2>&1 ) +} +pkg() { + (cd ${instdir} && \ + tar cvjf ${bin_pkg} * ) +} +mkpatch() { + (cd ${srcdir} && \ + tar xvzf ${src_orig_pkg} ;\ + mv ${PKG}-${VER} ../${PKG}-${VER}-orig && \ + cd ${topdir} && \ + diff -urN -x '.build' -x '.inst' -x '.sinst' \ + ${PKG}-${VER}-orig ${PKG}-${VER} > \ + ${srcinstdir}/${src_patch_name} ; \ + rm -rf ${PKG}-${VER}-orig ) +} +spkg() { + (mkpatch && \ + cp ${src_orig_pkg} ${srcinstdir}/${src_orig_pkg_name} && \ + cp $0 ${srcinstdir}/`basename $0` && \ + cd ${srcinstdir} && \ + tar cvjf ${src_pkg} * ) +} +finish() { + rm -rf ${srcdir} +} +case $1 in + prep) prep ; STATUS=$? ;; + mkdirs) mkdirs; STATUS=$? ;; + conf) conf ; STATUS=$? ;; + build) build ; STATUS=$? ;; + check) check ; STATUS=$? ;; + clean) clean ; STATUS=$? ;; + install) install ; STATUS=$? ;; + strip) strip ; STATUS=$? ;; + package) pkg ; STATUS=$? ;; + pkg) pkg ; STATUS=$? ;; + mkpatch) mkpatch ; STATUS=$? ;; + src-package) spkg ; STATUS=$? ;; + spkg) spkg ; STATUS=$? ;; + finish) finish ; STATUS=$? ;; + all) prep && conf && build && install && \ + strip && pkg && spkg && finish ; \ + STATUS=$? ;; + *) echo "Error: bad arguments" ; exit 1 ;; +esac +exit ${STATUS} + + diff --git a/cygwin/ELFIO-1.0.0-2.sh b/cygwin/ELFIO-1.0.0-2.sh index 7ff4a6a672a826d48b54510e0dfdfb8c6cfe22b4..a230ea29bd42b19debc63d3d853e0d7f0460e0c1 100755 --- a/cygwin/ELFIO-1.0.0-2.sh +++ b/cygwin/ELFIO-1.0.0-2.sh @@ -1,179 +1,179 @@ -#!/bin/sh -# find out where the build script is located -tdir=`echo "$0" | sed 's%[\\/][^\\/][^\\/]*$%%'` -test "x$tdir" = "x$0" && tdir=. -scriptdir=`cd $tdir; pwd` -# find src directory. -# If scriptdir ends in SPECS, then topdir is $scriptdir/.. -# If scriptdir ends in CYGWIN-PATCHES, then topdir is $scriptdir/../.. -# Otherwise, we assume that topdir = scriptdir -topdir1=`echo ${scriptdir} | sed 's%/SPECS$%%'` -topdir2=`echo ${scriptdir} | sed 's%/CYGWIN-PATCHES$%%'` -if [ "x$topdir1" != "x$scriptdir" ] ; then # SPECS - topdir=`cd ${scriptdir}/..; pwd` -else - if [ "x$topdir2" != "x$scriptdir" ] ; then # CYGWIN-PATCHES - topdir=`cd ${scriptdir}/../..; pwd` - else - topdir=`cd ${scriptdir}; pwd` - fi -fi - -tscriptname=`basename $0 .sh` -export PKG=`echo $tscriptname | sed -e 's/\-[^\-]*\-[^\-]*$//'` -export VER=`echo $tscriptname | sed -e 's/^[^\-]*\-//' -e 's/\-[^\-]*$//'` -export REL=`echo $tscriptname | sed -e 's/^[^\-]*\-[^\-]*\-//'` -export FULLPKG=${PKG}-${VER}-${REL} -# if the orig src package is bzip2'ed, remember to -# change 'z' to 'j' in the 'tar xvzf' commands in the -# prep) and mkpatch) sections -export src_orig_pkg_name=${PKG}-${VER}.tar.gz -export src_pkg_name=${FULLPKG}-src.tar.bz2 -export src_patch_name=${FULLPKG}.patch -export bin_pkg_name=${FULLPKG}.tar.bz2 - -export src_orig_pkg=${topdir}/${src_orig_pkg_name} -export src_pkg=${topdir}/${src_pkg_name} -export src_patch=${topdir}/${src_patch_name} -export bin_pkg=${topdir}/${bin_pkg_name} -export srcdir=${topdir}/${PKG}-${VER} -export objdir=${srcdir}/.build -export instdir=${srcdir}/.inst -export srcinstdir=${srcdir}/.sinst -export checkfile=${topdir}/${FULLPKG}.check -# run on -host=i686-pc-cygwin -# if this package creates binaries, they run on -target=i686-pc-cygwin -prefix=/usr -sysconfdir=/etc -MY_CFLAGS="-O2" -MY_CXXFLAGS="-O2" -MY_LDFLAGS= - -mkdirs() { - (cd ${topdir} && \ - mkdir -p ${objdir} && \ - mkdir -p ${instdir} && \ - mkdir -p ${srcinstdir} ) -} -prep() { - (cd ${topdir} && \ - tar xvzf ${src_orig_pkg} ; \ - cd ${topdir} && \ - patch -p0 < ${src_patch} - && mkdirs ) -} -conf() { - (cd ${objdir} && \ - CFLAGS="${MY_CFLAGS}" LDFLAGS="${MY_LDFLAGS}" \ - CXXFLAGS="${MY_CXXFLAGS}" LDFLAGS="${MY_LDFLAGS}" \ - ${srcdir}/configure --host=${host} --target=${target} \ - --srcdir=${srcdir} --prefix=${prefix} \ - --exec-prefix=${prefix} --sysconfdir=${sysconfdir} \ - --libdir=/lib --includedir=${prefix}/include \ - --libexecdir='${sbindir}' --localstatedir=/var \ - --datadir='${prefix}/share' -) -} -build() { - (cd ${objdir} && \ - CFLAGS="${MY_CFLAGS}" make ) -} -check() { - (cd ${objdir} && \ - make test | tee ${checkfile} 2>&1 ) -} -clean() { - (cd ${objdir} && \ - make clean ) -} -install() { - (cd ${objdir} && \ - make install DESTDIR=${instdir} - if [ -f ${instdir}${prefix}/info/dir ] ; then \ - rm ${instdir}${prefix}/info/dir ; \ - fi && \ - if [ ! -d ${instdir}${prefix}/doc/${PKG}-${VER} ]; then \ - mkdir -p ${instdir}${prefix}/doc/${PKG}-${VER} ; \ - fi && \ - if [ ! -d ${instdir}${prefix}/doc/Cygwin ]; then \ - mkdir -p ${instdir}${prefix}/doc/Cygwin ; \ - fi && \ - templist=""; \ - for f in ${srcdir}/ANNOUNCE ${srcdir}/CHANGES ${srcdir}/INSTALL \ - ${srcdir}/KNOWNBUG ${srcdir}/LICENSE ${srcdir}/README \ - ${srcdir}/AUTHORS ${srcdir}/KNOWNBUG ${srcdir}/COPYING \ - ${srcdir}/doc/tutorial.pdf \ - ${srcdir}/Examples/tutorial/tutorial.cpp \ - ${srcdir}/TODO ; do \ - if [ -f $f ] ; then \ - templist="$templist $f"; \ - fi ; \ - done && \ - if [ ! "x$templist" = "x" ]; then \ - /usr/bin/install -m 644 $templist \ - ${instdir}${prefix}/doc/${PKG}-${VER} ; - fi && \ - if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}-${VER}.README ]; then \ - /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/${PKG}-${VER}.README \ - ${instdir}${prefix}/doc/Cygwin/${PKG}-${VER}.README ; \ - else \ - if [ -f ${srcdir}/CYGWIN-PATCHES/README ]; then \ - /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/README \ - ${instdir}${prefix}/doc/Cygwin/${PKG}-${VER}.README ; \ - fi ;\ - fi ; ) -} -strip() { - (cd ${instdir} && \ - find . -name "*.dll" | xargs strip > /dev/null 2>&1 - find . -name "*.exe" | xargs strip > /dev/null 2>&1 ) -} -pkg() { - (cd ${instdir} && \ - tar cvjf ${bin_pkg} * ) -} -mkpatch() { - (cd ${srcdir} && \ - tar xvzf ${src_orig_pkg} ;\ - mv ${PKG}-${VER} ../${PKG}-${VER}-orig && \ - cd ${topdir} && \ - diff -urN -x '.build' -x '.inst' -x '.sinst' \ - ${PKG}-${VER}-orig ${PKG}-${VER} > \ - ${srcinstdir}/${src_patch_name} ; \ - rm -rf ${PKG}-${VER}-orig ) -} -spkg() { - (mkpatch && \ - cp ${src_orig_pkg} ${srcinstdir}/${src_orig_pkg_name} && \ - cp $0 ${srcinstdir}/`basename $0` && \ - cd ${srcinstdir} && \ - tar cvjf ${src_pkg} * ) -} -finish() { - rm -rf ${srcdir} -} -case $1 in - prep) prep ; STATUS=$? ;; - mkdirs) mkdirs; STATUS=$? ;; - conf) conf ; STATUS=$? ;; - build) build ; STATUS=$? ;; - check) check ; STATUS=$? ;; - clean) clean ; STATUS=$? ;; - install) install ; STATUS=$? ;; - strip) strip ; STATUS=$? ;; - package) pkg ; STATUS=$? ;; - pkg) pkg ; STATUS=$? ;; - mkpatch) mkpatch ; STATUS=$? ;; - src-package) spkg ; STATUS=$? ;; - spkg) spkg ; STATUS=$? ;; - finish) finish ; STATUS=$? ;; - all) prep && conf && build && install && \ - strip && pkg && spkg && finish ; \ - STATUS=$? ;; - *) echo "Error: bad arguments" ; exit 1 ;; -esac -exit ${STATUS} - - +#!/bin/sh +# find out where the build script is located +tdir=`echo "$0" | sed 's%[\\/][^\\/][^\\/]*$%%'` +test "x$tdir" = "x$0" && tdir=. +scriptdir=`cd $tdir; pwd` +# find src directory. +# If scriptdir ends in SPECS, then topdir is $scriptdir/.. +# If scriptdir ends in CYGWIN-PATCHES, then topdir is $scriptdir/../.. +# Otherwise, we assume that topdir = scriptdir +topdir1=`echo ${scriptdir} | sed 's%/SPECS$%%'` +topdir2=`echo ${scriptdir} | sed 's%/CYGWIN-PATCHES$%%'` +if [ "x$topdir1" != "x$scriptdir" ] ; then # SPECS + topdir=`cd ${scriptdir}/..; pwd` +else + if [ "x$topdir2" != "x$scriptdir" ] ; then # CYGWIN-PATCHES + topdir=`cd ${scriptdir}/../..; pwd` + else + topdir=`cd ${scriptdir}; pwd` + fi +fi + +tscriptname=`basename $0 .sh` +export PKG=`echo $tscriptname | sed -e 's/\-[^\-]*\-[^\-]*$//'` +export VER=`echo $tscriptname | sed -e 's/^[^\-]*\-//' -e 's/\-[^\-]*$//'` +export REL=`echo $tscriptname | sed -e 's/^[^\-]*\-[^\-]*\-//'` +export FULLPKG=${PKG}-${VER}-${REL} +# if the orig src package is bzip2'ed, remember to +# change 'z' to 'j' in the 'tar xvzf' commands in the +# prep) and mkpatch) sections +export src_orig_pkg_name=${PKG}-${VER}.tar.gz +export src_pkg_name=${FULLPKG}-src.tar.bz2 +export src_patch_name=${FULLPKG}.patch +export bin_pkg_name=${FULLPKG}.tar.bz2 + +export src_orig_pkg=${topdir}/${src_orig_pkg_name} +export src_pkg=${topdir}/${src_pkg_name} +export src_patch=${topdir}/${src_patch_name} +export bin_pkg=${topdir}/${bin_pkg_name} +export srcdir=${topdir}/${PKG}-${VER} +export objdir=${srcdir}/.build +export instdir=${srcdir}/.inst +export srcinstdir=${srcdir}/.sinst +export checkfile=${topdir}/${FULLPKG}.check +# run on +host=i686-pc-cygwin +# if this package creates binaries, they run on +target=i686-pc-cygwin +prefix=/usr +sysconfdir=/etc +MY_CFLAGS="-O2" +MY_CXXFLAGS="-O2" +MY_LDFLAGS= + +mkdirs() { + (cd ${topdir} && \ + mkdir -p ${objdir} && \ + mkdir -p ${instdir} && \ + mkdir -p ${srcinstdir} ) +} +prep() { + (cd ${topdir} && \ + tar xvzf ${src_orig_pkg} ; \ + cd ${topdir} && \ + patch -p0 < ${src_patch} + && mkdirs ) +} +conf() { + (cd ${objdir} && \ + CFLAGS="${MY_CFLAGS}" LDFLAGS="${MY_LDFLAGS}" \ + CXXFLAGS="${MY_CXXFLAGS}" LDFLAGS="${MY_LDFLAGS}" \ + ${srcdir}/configure --host=${host} --target=${target} \ + --srcdir=${srcdir} --prefix=${prefix} \ + --exec-prefix=${prefix} --sysconfdir=${sysconfdir} \ + --libdir=/lib --includedir=${prefix}/include \ + --libexecdir='${sbindir}' --localstatedir=/var \ + --datadir='${prefix}/share' +) +} +build() { + (cd ${objdir} && \ + CFLAGS="${MY_CFLAGS}" make ) +} +check() { + (cd ${objdir} && \ + make test | tee ${checkfile} 2>&1 ) +} +clean() { + (cd ${objdir} && \ + make clean ) +} +install() { + (cd ${objdir} && \ + make install DESTDIR=${instdir} + if [ -f ${instdir}${prefix}/info/dir ] ; then \ + rm ${instdir}${prefix}/info/dir ; \ + fi && \ + if [ ! -d ${instdir}${prefix}/doc/${PKG}-${VER} ]; then \ + mkdir -p ${instdir}${prefix}/doc/${PKG}-${VER} ; \ + fi && \ + if [ ! -d ${instdir}${prefix}/doc/Cygwin ]; then \ + mkdir -p ${instdir}${prefix}/doc/Cygwin ; \ + fi && \ + templist=""; \ + for f in ${srcdir}/ANNOUNCE ${srcdir}/CHANGES ${srcdir}/INSTALL \ + ${srcdir}/KNOWNBUG ${srcdir}/LICENSE ${srcdir}/README \ + ${srcdir}/AUTHORS ${srcdir}/KNOWNBUG ${srcdir}/COPYING \ + ${srcdir}/doc/tutorial.pdf \ + ${srcdir}/Examples/tutorial/tutorial.cpp \ + ${srcdir}/TODO ; do \ + if [ -f $f ] ; then \ + templist="$templist $f"; \ + fi ; \ + done && \ + if [ ! "x$templist" = "x" ]; then \ + /usr/bin/install -m 644 $templist \ + ${instdir}${prefix}/doc/${PKG}-${VER} ; + fi && \ + if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}-${VER}.README ]; then \ + /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/${PKG}-${VER}.README \ + ${instdir}${prefix}/doc/Cygwin/${PKG}-${VER}.README ; \ + else \ + if [ -f ${srcdir}/CYGWIN-PATCHES/README ]; then \ + /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/README \ + ${instdir}${prefix}/doc/Cygwin/${PKG}-${VER}.README ; \ + fi ;\ + fi ; ) +} +strip() { + (cd ${instdir} && \ + find . -name "*.dll" | xargs strip > /dev/null 2>&1 + find . -name "*.exe" | xargs strip > /dev/null 2>&1 ) +} +pkg() { + (cd ${instdir} && \ + tar cvjf ${bin_pkg} * ) +} +mkpatch() { + (cd ${srcdir} && \ + tar xvzf ${src_orig_pkg} ;\ + mv ${PKG}-${VER} ../${PKG}-${VER}-orig && \ + cd ${topdir} && \ + diff -urN -x '.build' -x '.inst' -x '.sinst' \ + ${PKG}-${VER}-orig ${PKG}-${VER} > \ + ${srcinstdir}/${src_patch_name} ; \ + rm -rf ${PKG}-${VER}-orig ) +} +spkg() { + (mkpatch && \ + cp ${src_orig_pkg} ${srcinstdir}/${src_orig_pkg_name} && \ + cp $0 ${srcinstdir}/`basename $0` && \ + cd ${srcinstdir} && \ + tar cvjf ${src_pkg} * ) +} +finish() { + rm -rf ${srcdir} +} +case $1 in + prep) prep ; STATUS=$? ;; + mkdirs) mkdirs; STATUS=$? ;; + conf) conf ; STATUS=$? ;; + build) build ; STATUS=$? ;; + check) check ; STATUS=$? ;; + clean) clean ; STATUS=$? ;; + install) install ; STATUS=$? ;; + strip) strip ; STATUS=$? ;; + package) pkg ; STATUS=$? ;; + pkg) pkg ; STATUS=$? ;; + mkpatch) mkpatch ; STATUS=$? ;; + src-package) spkg ; STATUS=$? ;; + spkg) spkg ; STATUS=$? ;; + finish) finish ; STATUS=$? ;; + all) prep && conf && build && install && \ + strip && pkg && spkg && finish ; \ + STATUS=$? ;; + *) echo "Error: bad arguments" ; exit 1 ;; +esac +exit ${STATUS} + + diff --git a/cygwin/ELFIO-1.0.2-1.sh b/cygwin/ELFIO-1.0.2-1.sh index 0ea4c9fff209d530356d35045aa8c1c7acc865ed..c4a4564b003462e492f60e174838b5b06649b36b 100755 --- a/cygwin/ELFIO-1.0.2-1.sh +++ b/cygwin/ELFIO-1.0.2-1.sh @@ -1,179 +1,179 @@ -#!/bin/sh -# find out where the build script is located -tdir=`echo "$0" | sed 's%[\\/][^\\/][^\\/]*$%%'` -test "x$tdir" = "x$0" && tdir=. -scriptdir=`cd $tdir; pwd` -# find src directory. -# If scriptdir ends in SPECS, then topdir is $scriptdir/.. -# If scriptdir ends in CYGWIN-PATCHES, then topdir is $scriptdir/../.. -# Otherwise, we assume that topdir = scriptdir -topdir1=`echo ${scriptdir} | sed 's%/SPECS$%%'` -topdir2=`echo ${scriptdir} | sed 's%/CYGWIN-PATCHES$%%'` -if [ "x$topdir1" != "x$scriptdir" ] ; then # SPECS - topdir=`cd ${scriptdir}/..; pwd` -else - if [ "x$topdir2" != "x$scriptdir" ] ; then # CYGWIN-PATCHES - topdir=`cd ${scriptdir}/../..; pwd` - else - topdir=`cd ${scriptdir}; pwd` - fi -fi - -tscriptname=`basename $0 .sh` -export PKG=`echo $tscriptname | sed -e 's/\-[^\-]*\-[^\-]*$//'` -export VER=`echo $tscriptname | sed -e 's/^[^\-]*\-//' -e 's/\-[^\-]*$//'` -export REL=`echo $tscriptname | sed -e 's/^[^\-]*\-[^\-]*\-//'` -export FULLPKG=${PKG}-${VER}-${REL} -# if the orig src package is bzip2'ed, remember to -# change 'z' to 'j' in the 'tar xvzf' commands in the -# prep) and mkpatch) sections -export src_orig_pkg_name=${PKG}-${VER}.tar.gz -export src_pkg_name=${FULLPKG}-src.tar.bz2 -export src_patch_name=${FULLPKG}.patch -export bin_pkg_name=${FULLPKG}.tar.bz2 - -export src_orig_pkg=${topdir}/${src_orig_pkg_name} -export src_pkg=${topdir}/${src_pkg_name} -export src_patch=${topdir}/${src_patch_name} -export bin_pkg=${topdir}/${bin_pkg_name} -export srcdir=${topdir}/${PKG}-${VER} -export objdir=${srcdir}/.build -export instdir=${srcdir}/.inst -export srcinstdir=${srcdir}/.sinst -export checkfile=${topdir}/${FULLPKG}.check -# run on -host=i686-pc-cygwin -# if this package creates binaries, they run on -target=i686-pc-cygwin -prefix=/usr -sysconfdir=/etc -MY_CFLAGS="-O2" -MY_CXXFLAGS="-O2" -MY_LDFLAGS= - -mkdirs() { - (cd ${topdir} && \ - mkdir -p ${objdir} && \ - mkdir -p ${instdir} && \ - mkdir -p ${srcinstdir} ) -} -prep() { - (cd ${topdir} && \ - tar xvzf ${src_orig_pkg} ; \ - cd ${topdir} && \ - patch -p0 < ${src_patch} \ - && mkdirs ) -} -conf() { - (cd ${objdir} && \ - CFLAGS="${MY_CFLAGS}" LDFLAGS="${MY_LDFLAGS}" \ - CXXFLAGS="${MY_CXXFLAGS}" LDFLAGS="${MY_LDFLAGS}" \ - ${srcdir}/configure --host=${host} --target=${target} \ - --srcdir=${srcdir} --prefix=${prefix} \ - --exec-prefix=${prefix} --sysconfdir=${sysconfdir} \ - --libdir=/lib --includedir=${prefix}/include \ - --libexecdir='${sbindir}' --localstatedir=/var \ - --datadir='${prefix}/share' -) -} -build() { - (cd ${objdir} && \ - CFLAGS="${MY_CFLAGS}" make ) -} -check() { - (cd ${objdir} && \ - make test | tee ${checkfile} 2>&1 ) -} -clean() { - (cd ${objdir} && \ - make clean ) -} -install() { - (cd ${objdir} && \ - make install DESTDIR=${instdir} - if [ -f ${instdir}${prefix}/info/dir ] ; then \ - rm ${instdir}${prefix}/info/dir ; \ - fi && \ - if [ ! -d ${instdir}${prefix}/doc/${PKG}-${VER} ]; then \ - mkdir -p ${instdir}${prefix}/doc/${PKG}-${VER} ; \ - fi && \ - if [ ! -d ${instdir}${prefix}/doc/Cygwin ]; then \ - mkdir -p ${instdir}${prefix}/doc/Cygwin ; \ - fi && \ - templist=""; \ - for f in ${srcdir}/ANNOUNCE ${srcdir}/CHANGES ${srcdir}/INSTALL \ - ${srcdir}/KNOWNBUG ${srcdir}/LICENSE ${srcdir}/README \ - ${srcdir}/AUTHORS ${srcdir}/KNOWNBUG ${srcdir}/COPYING \ - ${srcdir}/doc/tutorial.pdf \ - ${srcdir}/Examples/tutorial/tutorial.cpp \ - ${srcdir}/TODO ; do \ - if [ -f $f ] ; then \ - templist="$templist $f"; \ - fi ; \ - done && \ - if [ ! "x$templist" = "x" ]; then \ - /usr/bin/install -m 644 $templist \ - ${instdir}${prefix}/doc/${PKG}-${VER} ; - fi && \ - if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}-${VER}.README ]; then \ - /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/${PKG}-${VER}.README \ - ${instdir}${prefix}/doc/Cygwin/${PKG}-${VER}.README ; \ - else \ - if [ -f ${srcdir}/CYGWIN-PATCHES/README ]; then \ - /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/README \ - ${instdir}${prefix}/doc/Cygwin/${PKG}-${VER}.README ; \ - fi ;\ - fi ; ) -} -strip() { - (cd ${instdir} && \ - find . -name "*.dll" | xargs strip > /dev/null 2>&1 - find . -name "*.exe" | xargs strip > /dev/null 2>&1 ) -} -pkg() { - (cd ${instdir} && \ - tar cvjf ${bin_pkg} * ) -} -mkpatch() { - (cd ${srcdir} && \ - tar xvzf ${src_orig_pkg} ;\ - mv ${PKG}-${VER} ../${PKG}-${VER}-orig && \ - cd ${topdir} && \ - diff -urN -x '.build' -x '.inst' -x '.sinst' \ - ${PKG}-${VER}-orig ${PKG}-${VER} > \ - ${srcinstdir}/${src_patch_name} ; \ - rm -rf ${PKG}-${VER}-orig ) -} -spkg() { - (mkpatch && \ - cp ${src_orig_pkg} ${srcinstdir}/${src_orig_pkg_name} && \ - cp $0 ${srcinstdir}/`basename $0` && \ - cd ${srcinstdir} && \ - tar cvjf ${src_pkg} * ) -} -finish() { - rm -rf ${srcdir} -} -case $1 in - prep) prep ; STATUS=$? ;; - mkdirs) mkdirs; STATUS=$? ;; - conf) conf ; STATUS=$? ;; - build) build ; STATUS=$? ;; - check) check ; STATUS=$? ;; - clean) clean ; STATUS=$? ;; - install) install ; STATUS=$? ;; - strip) strip ; STATUS=$? ;; - package) pkg ; STATUS=$? ;; - pkg) pkg ; STATUS=$? ;; - mkpatch) mkpatch ; STATUS=$? ;; - src-package) spkg ; STATUS=$? ;; - spkg) spkg ; STATUS=$? ;; - finish) finish ; STATUS=$? ;; - all) prep && conf && build && install && \ - strip && pkg && spkg && finish ; \ - STATUS=$? ;; - *) echo "Error: bad arguments" ; exit 1 ;; -esac -exit ${STATUS} - - +#!/bin/sh +# find out where the build script is located +tdir=`echo "$0" | sed 's%[\\/][^\\/][^\\/]*$%%'` +test "x$tdir" = "x$0" && tdir=. +scriptdir=`cd $tdir; pwd` +# find src directory. +# If scriptdir ends in SPECS, then topdir is $scriptdir/.. +# If scriptdir ends in CYGWIN-PATCHES, then topdir is $scriptdir/../.. +# Otherwise, we assume that topdir = scriptdir +topdir1=`echo ${scriptdir} | sed 's%/SPECS$%%'` +topdir2=`echo ${scriptdir} | sed 's%/CYGWIN-PATCHES$%%'` +if [ "x$topdir1" != "x$scriptdir" ] ; then # SPECS + topdir=`cd ${scriptdir}/..; pwd` +else + if [ "x$topdir2" != "x$scriptdir" ] ; then # CYGWIN-PATCHES + topdir=`cd ${scriptdir}/../..; pwd` + else + topdir=`cd ${scriptdir}; pwd` + fi +fi + +tscriptname=`basename $0 .sh` +export PKG=`echo $tscriptname | sed -e 's/\-[^\-]*\-[^\-]*$//'` +export VER=`echo $tscriptname | sed -e 's/^[^\-]*\-//' -e 's/\-[^\-]*$//'` +export REL=`echo $tscriptname | sed -e 's/^[^\-]*\-[^\-]*\-//'` +export FULLPKG=${PKG}-${VER}-${REL} +# if the orig src package is bzip2'ed, remember to +# change 'z' to 'j' in the 'tar xvzf' commands in the +# prep) and mkpatch) sections +export src_orig_pkg_name=${PKG}-${VER}.tar.gz +export src_pkg_name=${FULLPKG}-src.tar.bz2 +export src_patch_name=${FULLPKG}.patch +export bin_pkg_name=${FULLPKG}.tar.bz2 + +export src_orig_pkg=${topdir}/${src_orig_pkg_name} +export src_pkg=${topdir}/${src_pkg_name} +export src_patch=${topdir}/${src_patch_name} +export bin_pkg=${topdir}/${bin_pkg_name} +export srcdir=${topdir}/${PKG}-${VER} +export objdir=${srcdir}/.build +export instdir=${srcdir}/.inst +export srcinstdir=${srcdir}/.sinst +export checkfile=${topdir}/${FULLPKG}.check +# run on +host=i686-pc-cygwin +# if this package creates binaries, they run on +target=i686-pc-cygwin +prefix=/usr +sysconfdir=/etc +MY_CFLAGS="-O2" +MY_CXXFLAGS="-O2" +MY_LDFLAGS= + +mkdirs() { + (cd ${topdir} && \ + mkdir -p ${objdir} && \ + mkdir -p ${instdir} && \ + mkdir -p ${srcinstdir} ) +} +prep() { + (cd ${topdir} && \ + tar xvzf ${src_orig_pkg} ; \ + cd ${topdir} && \ + patch -p0 < ${src_patch} \ + && mkdirs ) +} +conf() { + (cd ${objdir} && \ + CFLAGS="${MY_CFLAGS}" LDFLAGS="${MY_LDFLAGS}" \ + CXXFLAGS="${MY_CXXFLAGS}" LDFLAGS="${MY_LDFLAGS}" \ + ${srcdir}/configure --host=${host} --target=${target} \ + --srcdir=${srcdir} --prefix=${prefix} \ + --exec-prefix=${prefix} --sysconfdir=${sysconfdir} \ + --libdir=/lib --includedir=${prefix}/include \ + --libexecdir='${sbindir}' --localstatedir=/var \ + --datadir='${prefix}/share' +) +} +build() { + (cd ${objdir} && \ + CFLAGS="${MY_CFLAGS}" make ) +} +check() { + (cd ${objdir} && \ + make test | tee ${checkfile} 2>&1 ) +} +clean() { + (cd ${objdir} && \ + make clean ) +} +install() { + (cd ${objdir} && \ + make install DESTDIR=${instdir} + if [ -f ${instdir}${prefix}/info/dir ] ; then \ + rm ${instdir}${prefix}/info/dir ; \ + fi && \ + if [ ! -d ${instdir}${prefix}/doc/${PKG}-${VER} ]; then \ + mkdir -p ${instdir}${prefix}/doc/${PKG}-${VER} ; \ + fi && \ + if [ ! -d ${instdir}${prefix}/doc/Cygwin ]; then \ + mkdir -p ${instdir}${prefix}/doc/Cygwin ; \ + fi && \ + templist=""; \ + for f in ${srcdir}/ANNOUNCE ${srcdir}/CHANGES ${srcdir}/INSTALL \ + ${srcdir}/KNOWNBUG ${srcdir}/LICENSE ${srcdir}/README \ + ${srcdir}/AUTHORS ${srcdir}/KNOWNBUG ${srcdir}/COPYING \ + ${srcdir}/doc/tutorial.pdf \ + ${srcdir}/Examples/tutorial/tutorial.cpp \ + ${srcdir}/TODO ; do \ + if [ -f $f ] ; then \ + templist="$templist $f"; \ + fi ; \ + done && \ + if [ ! "x$templist" = "x" ]; then \ + /usr/bin/install -m 644 $templist \ + ${instdir}${prefix}/doc/${PKG}-${VER} ; + fi && \ + if [ -f ${srcdir}/CYGWIN-PATCHES/${PKG}-${VER}.README ]; then \ + /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/${PKG}-${VER}.README \ + ${instdir}${prefix}/doc/Cygwin/${PKG}-${VER}.README ; \ + else \ + if [ -f ${srcdir}/CYGWIN-PATCHES/README ]; then \ + /usr/bin/install -m 644 ${srcdir}/CYGWIN-PATCHES/README \ + ${instdir}${prefix}/doc/Cygwin/${PKG}-${VER}.README ; \ + fi ;\ + fi ; ) +} +strip() { + (cd ${instdir} && \ + find . -name "*.dll" | xargs strip > /dev/null 2>&1 + find . -name "*.exe" | xargs strip > /dev/null 2>&1 ) +} +pkg() { + (cd ${instdir} && \ + tar cvjf ${bin_pkg} * ) +} +mkpatch() { + (cd ${srcdir} && \ + tar xvzf ${src_orig_pkg} ;\ + mv ${PKG}-${VER} ../${PKG}-${VER}-orig && \ + cd ${topdir} && \ + diff -urN -x '.build' -x '.inst' -x '.sinst' \ + ${PKG}-${VER}-orig ${PKG}-${VER} > \ + ${srcinstdir}/${src_patch_name} ; \ + rm -rf ${PKG}-${VER}-orig ) +} +spkg() { + (mkpatch && \ + cp ${src_orig_pkg} ${srcinstdir}/${src_orig_pkg_name} && \ + cp $0 ${srcinstdir}/`basename $0` && \ + cd ${srcinstdir} && \ + tar cvjf ${src_pkg} * ) +} +finish() { + rm -rf ${srcdir} +} +case $1 in + prep) prep ; STATUS=$? ;; + mkdirs) mkdirs; STATUS=$? ;; + conf) conf ; STATUS=$? ;; + build) build ; STATUS=$? ;; + check) check ; STATUS=$? ;; + clean) clean ; STATUS=$? ;; + install) install ; STATUS=$? ;; + strip) strip ; STATUS=$? ;; + package) pkg ; STATUS=$? ;; + pkg) pkg ; STATUS=$? ;; + mkpatch) mkpatch ; STATUS=$? ;; + src-package) spkg ; STATUS=$? ;; + spkg) spkg ; STATUS=$? ;; + finish) finish ; STATUS=$? ;; + all) prep && conf && build && install && \ + strip && pkg && spkg && finish ; \ + STATUS=$? ;; + *) echo "Error: bad arguments" ; exit 1 ;; +esac +exit ${STATUS} + + diff --git a/doc/Makefile.in b/doc/Makefile.in deleted file mode 100644 index 6f4cf6588994ca810e7670c5af30049995c7df0a..0000000000000000000000000000000000000000 --- a/doc/Makefile.in +++ /dev/null @@ -1,315 +0,0 @@ -# Makefile.in generated by automake 1.11.3 from Makefile.am. -# @configure_input@ - -# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software -# Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -@SET_MAKE@ -VPATH = @srcdir@ -pkgdatadir = $(datadir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkglibexecdir = $(libexecdir)/@PACKAGE@ -am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd -install_sh_DATA = $(install_sh) -c -m 644 -install_sh_PROGRAM = $(install_sh) -c -install_sh_SCRIPT = $(install_sh) -c -INSTALL_HEADER = $(INSTALL_DATA) -transform = $(program_transform_name) -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -subdir = doc -DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/configure.in -am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ - $(ACLOCAL_M4) -mkinstalldirs = $(install_sh) -d -CONFIG_CLEAN_FILES = -CONFIG_CLEAN_VPATH_FILES = -SOURCES = -DIST_SOURCES = -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -ACLOCAL = @ACLOCAL@ -AMTAR = @AMTAR@ -AUTOCONF = @AUTOCONF@ -AUTOHEADER = @AUTOHEADER@ -AUTOMAKE = @AUTOMAKE@ -AWK = @AWK@ -CPPFLAGS = @CPPFLAGS@ -CXX = @CXX@ -CXXDEPMODE = @CXXDEPMODE@ -CXXFLAGS = @CXXFLAGS@ -CYGPATH_W = @CYGPATH_W@ -DEFS = @DEFS@ -DEPDIR = @DEPDIR@ -ECHO_C = @ECHO_C@ -ECHO_N = @ECHO_N@ -ECHO_T = @ECHO_T@ -EXEEXT = @EXEEXT@ -INSTALL = @INSTALL@ -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ -LDFLAGS = @LDFLAGS@ -LIBOBJS = @LIBOBJS@ -LIBS = @LIBS@ -LTLIBOBJS = @LTLIBOBJS@ -MAKEINFO = @MAKEINFO@ -MKDIR_P = @MKDIR_P@ -OBJEXT = @OBJEXT@ -PACKAGE = @PACKAGE@ -PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ -PACKAGE_NAME = @PACKAGE_NAME@ -PACKAGE_STRING = @PACKAGE_STRING@ -PACKAGE_TARNAME = @PACKAGE_TARNAME@ -PACKAGE_URL = @PACKAGE_URL@ -PACKAGE_VERSION = @PACKAGE_VERSION@ -PATH_SEPARATOR = @PATH_SEPARATOR@ -SET_MAKE = @SET_MAKE@ -SHELL = @SHELL@ -STRIP = @STRIP@ -VERSION = @VERSION@ -abs_builddir = @abs_builddir@ -abs_srcdir = @abs_srcdir@ -abs_top_builddir = @abs_top_builddir@ -abs_top_srcdir = @abs_top_srcdir@ -ac_ct_CXX = @ac_ct_CXX@ -am__include = @am__include@ -am__leading_dot = @am__leading_dot@ -am__quote = @am__quote@ -am__tar = @am__tar@ -am__untar = @am__untar@ -bindir = @bindir@ -build_alias = @build_alias@ -builddir = @builddir@ -datadir = @datadir@ -datarootdir = @datarootdir@ -docdir = @docdir@ -dvidir = @dvidir@ -exec_prefix = @exec_prefix@ -host_alias = @host_alias@ -htmldir = @htmldir@ -includedir = @includedir@ -infodir = @infodir@ -install_sh = @install_sh@ -libdir = @libdir@ -libexecdir = @libexecdir@ -localedir = @localedir@ -localstatedir = @localstatedir@ -mandir = @mandir@ -mkdir_p = @mkdir_p@ -oldincludedir = @oldincludedir@ -pdfdir = @pdfdir@ -prefix = @prefix@ -program_transform_name = @program_transform_name@ -psdir = @psdir@ -sbindir = @sbindir@ -sharedstatedir = @sharedstatedir@ -srcdir = @srcdir@ -sysconfdir = @sysconfdir@ -target_alias = @target_alias@ -top_build_prefix = @top_build_prefix@ -top_builddir = @top_builddir@ -top_srcdir = @top_srcdir@ -EXTRA_DIST = elfio.docbook elfio.pdf -all: all-am - -.SUFFIXES: -$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) - @for dep in $?; do \ - case '$(am__configure_deps)' in \ - *$$dep*) \ - ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ - && { if test -f $@; then exit 0; else break; fi; }; \ - exit 1;; \ - esac; \ - done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu doc/Makefile'; \ - $(am__cd) $(top_srcdir) && \ - $(AUTOMAKE) --gnu doc/Makefile -.PRECIOUS: Makefile -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - @case '$?' in \ - *config.status*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ - *) \ - echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ - cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ - esac; - -$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh - -$(top_srcdir)/configure: $(am__configure_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): $(am__aclocal_m4_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(am__aclocal_m4_deps): -tags: TAGS -TAGS: - -ctags: CTAGS -CTAGS: - - -distdir: $(DISTFILES) - @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ - topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ - list='$(DISTFILES)'; \ - dist_files=`for file in $$list; do echo $$file; done | \ - sed -e "s|^$$srcdirstrip/||;t" \ - -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ - case $$dist_files in \ - */*) $(MKDIR_P) `echo "$$dist_files" | \ - sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ - sort -u` ;; \ - esac; \ - for file in $$dist_files; do \ - if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ - if test -d $$d/$$file; then \ - dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ - if test -d "$(distdir)/$$file"; then \ - find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ - fi; \ - if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ - find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ - fi; \ - cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ - else \ - test -f "$(distdir)/$$file" \ - || cp -p $$d/$$file "$(distdir)/$$file" \ - || exit 1; \ - fi; \ - done -check-am: all-am -check: check-am -all-am: Makefile -installdirs: -install: install-am -install-exec: install-exec-am -install-data: install-data-am -uninstall: uninstall-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am - -installcheck: installcheck-am -install-strip: - if test -z '$(STRIP)'; then \ - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - install; \ - else \ - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ - fi -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) - -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) - -maintainer-clean-generic: - @echo "This command is intended for maintainers to use" - @echo "it deletes files that may require special tools to rebuild." -clean: clean-am - -clean-am: clean-generic mostlyclean-am - -distclean: distclean-am - -rm -f Makefile -distclean-am: clean-am distclean-generic - -dvi: dvi-am - -dvi-am: - -html: html-am - -html-am: - -info: info-am - -info-am: - -install-data-am: - -install-dvi: install-dvi-am - -install-dvi-am: - -install-exec-am: - -install-html: install-html-am - -install-html-am: - -install-info: install-info-am - -install-info-am: - -install-man: - -install-pdf: install-pdf-am - -install-pdf-am: - -install-ps: install-ps-am - -install-ps-am: - -installcheck-am: - -maintainer-clean: maintainer-clean-am - -rm -f Makefile -maintainer-clean-am: distclean-am maintainer-clean-generic - -mostlyclean: mostlyclean-am - -mostlyclean-am: mostlyclean-generic - -pdf: pdf-am - -pdf-am: - -ps: ps-am - -ps-am: - -uninstall-am: - -.MAKE: install-am install-strip - -.PHONY: all all-am check check-am clean clean-generic distclean \ - distclean-generic distdir dvi dvi-am html html-am info info-am \ - install install-am install-data install-data-am install-dvi \ - install-dvi-am install-exec install-exec-am install-html \ - install-html-am install-info install-info-am install-man \ - install-pdf install-pdf-am install-ps install-ps-am \ - install-strip installcheck installcheck-am installdirs \ - maintainer-clean maintainer-clean-generic mostlyclean \ - mostlyclean-generic pdf pdf-am ps ps-am uninstall uninstall-am - - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/doc/site/index.htm b/doc/site/index.htm index 3a8678ec70763173545ff341e78373358aa7c84d..88b10fef490a7ec3e4f0c2ff903fec556f818507 100755 --- a/doc/site/index.htm +++ b/doc/site/index.htm @@ -1,84 +1,84 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml"> -<head> -<title>ELFIO - C++ library for reading and generating ELF files</title> -<link rel="stylesheet" href="style.css" type="text/css"/> -</head> - -<body> - -<table summary="Title and Sourceforge logo."> -<tr> -<td align="left"> -<h1>ELFIO - C++ library for reading and generating ELF files</h1> -</td> -</tr> -</table> - -<div class="links"> -<h3>Links</h3> -<ul class="menu"> -<li><a href="http://sourceforge.net/projects/elfio/files/">Download</a> the source</li><br/> -<li>Read the <a href="elfio.pdf">User's Guide</a></li><br/> -<li>Read the <a href="html/index.html">API documentation</a></li><br/> -<li>Visit the -<a href="http://sourceforge.net/projects/elfio/">SourceForge project page</a></li><br/> -<li><a href="oldsite/index.htm">Old documentation</a> for outdated 1.0.3 version of the library</li><br/> -<li>Send <a href="mailto:to_serge@users.sourceforge.net">feedback, comments, patches, etc.</a></li></br> -</ul> -</div> - -<div class="main"> - -<p> -<em>ELFIO</em> is a small, header only C++ library that provides a simple interface for -reading and generating files in ELF binary format. -</p> -<p> -<em>ELFIO</em> library is independent and does not rely on any other additional projects. -It is also cross-platform - the library uses standard ANSI C++ constructions -and runs on wide variety of architectures. -</p> -<p> -While the library's implementation does make your work much easier: basic -knowledge of the ELF binary format is required. Information about ELF -binary format can be found widely on the web. -</p> -<p> -Current version of <em>ELFIO</em> library is 2.0 and it is distributed under -<a href="http://www.opensource.org/licenses/MIT">MIT License</a> conditions. -</p> -<p> -Note for users of previous library versions 1.0.x: Version 2.0 is not source -compatible to earlier versions. But, for many projects, transition to a new library -interface does not take more than several minutes. -</p> - -</div> - -<div class="by"> -<p class="author"> -The library and the page is maintained by -<a href="mailto:to_serge@users.sourceforge.net">Serge Lamikhov-Center</a>.</br> -</p> - -<table summary="Title and Sourceforge logo."> -<tr> -<td align="left" class=""author> -<p class="author"> -Project Web Hosted by -</p> -</td> -<td align="left"> -<a href="http://sourceforge.net/projects/elfio"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=19959&type=10" width="80" height="15" border="0" alt="Get ELFIO library" /></a> -</td> -</tr> -</table> - - -</div> - -</body> - -</html> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<title>ELFIO - C++ library for reading and generating ELF files</title> +<link rel="stylesheet" href="style.css" type="text/css"/> +</head> + +<body> + +<table summary="Title and Sourceforge logo."> +<tr> +<td align="left"> +<h1>ELFIO - C++ library for reading and generating ELF files</h1> +</td> +</tr> +</table> + +<div class="links"> +<h3>Links</h3> +<ul class="menu"> +<li><a href="http://sourceforge.net/projects/elfio/files/">Download</a> the source</li><br/> +<li>Read the <a href="elfio.pdf">User's Guide</a></li><br/> +<li>Read the <a href="html/index.html">API documentation</a></li><br/> +<li>Visit the +<a href="http://sourceforge.net/projects/elfio/">SourceForge project page</a></li><br/> +<li><a href="oldsite/index.htm">Old documentation</a> for outdated 1.0.3 version of the library</li><br/> +<li>Send <a href="mailto:to_serge@users.sourceforge.net">feedback, comments, patches, etc.</a></li></br> +</ul> +</div> + +<div class="main"> + +<p> +<em>ELFIO</em> is a small, header only C++ library that provides a simple interface for +reading and generating files in ELF binary format. +</p> +<p> +<em>ELFIO</em> library is independent and does not rely on any other additional projects. +It is also cross-platform - the library uses standard ANSI C++ constructions +and runs on wide variety of architectures. +</p> +<p> +While the library's implementation does make your work much easier: basic +knowledge of the ELF binary format is required. Information about ELF +binary format can be found widely on the web. +</p> +<p> +Current version of <em>ELFIO</em> library is 2.0 and it is distributed under +<a href="http://www.opensource.org/licenses/MIT">MIT License</a> conditions. +</p> +<p> +Note for users of previous library versions 1.0.x: Version 2.0 is not source +compatible to earlier versions. But, for many projects, transition to a new library +interface does not take more than several minutes. +</p> + +</div> + +<div class="by"> +<p class="author"> +The library and the page is maintained by +<a href="mailto:to_serge@users.sourceforge.net">Serge Lamikhov-Center</a>.</br> +</p> + +<table summary="Title and Sourceforge logo."> +<tr> +<td align="left" class=""author> +<p class="author"> +Project Web Hosted by +</p> +</td> +<td align="left"> +<a href="http://sourceforge.net/projects/elfio"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=19959&type=10" width="80" height="15" border="0" alt="Get ELFIO library" /></a> +</td> +</tr> +</table> + + +</div> + +</body> + +</html> diff --git a/doc/site/style.css b/doc/site/style.css index 41a2eee1bc53f67f0512497927744111a7f16b3a..9e9da1f0c174f809a3aa3e4d1fa0a78d67f9fe86 100755 --- a/doc/site/style.css +++ b/doc/site/style.css @@ -1,131 +1,131 @@ -/* -color:#ffffff; white -color:#e0e0e0; light gray -color:#f8f8f8; light gray -color:#003366; dark blue -color:#555555; gray -color:#ff9933; light orange -color:#cc3300; red/brown/orange -color:#660066; purple -color:#669900; green -*/ - -a { - color:#003366; - text-decoration:underline; -} - -a:hover { - color:#ff9933; -} - -body { - font-family: verdana, tahoma, helvetica, arial, sans-serif; - font-size: 90%; - background-color:#ffffff; - margin: 1em; -} - -pre { - font-family: courier, serif; - background-color:#f8f8f8; - margin: 1.5em; - font-size:90%; -} - -ul { - list-style: circle outside; - font-stretch:extra-expanded; -/* font-size:90%;*/ -} - -ul.menu { /* inherits from ul */ - padding-left: 1em; -} - - -em { - color:#FF7700; - font-size:110%; -} - -h1,h2,h3{ - color:#FF7700; -} - -h1 { - border-color:#d0d0d0; - border-style:solid; - border-width:1px; - font-weight:bold; - padding: 0.2em; - background-color:#f8f8f8 -} - -h2 { - font-size:120%; - font-weight:bold; - border-bottom-style:solid; - border-bottom-width:1px; - border-bottom-color:#d0d0d0; -} - -h3 { - font-size:110%; - font-weight:bold; - font-style:italic; -} - -tt { - font-family: courier, serif; -} - -tt.classname { - font-weight:bold; -} - -tt.constant { - font-weight:bold; -} - - -p { - line-height: 1.5em; -} - - -p.author { -/* line-height: 0.5em; */ - font-size:70%; -} - - -div.links{ - float: left; - clear: left; - width: 12em; - background-color:#f8f8f8; - border-style:solid; - border-width:1px; - border-color:#d0d0d0; - margin-bottom: 0.5em; - padding: 0.5em 0.5em 0.5em 0.5em; - margin: 0.5em 0.5em 0em 0em; -} - -div.main{ - border-style:solid; - border-width:1px; - border-color:#d0d0d0; - margin: 0.5em 0em 0.5em 14em; - padding: 0.5em 0.5em 0.5em 0.5em; -} - -div.by{ - line-height: 0.5em; - border-width:1px; - border-color:#d0d0d0; - margin: 0.5em 0em 0.5em 14em; - padding: 0.5em 0.5em 0.5em 0.5em; -} - +/* +color:#ffffff; white +color:#e0e0e0; light gray +color:#f8f8f8; light gray +color:#003366; dark blue +color:#555555; gray +color:#ff9933; light orange +color:#cc3300; red/brown/orange +color:#660066; purple +color:#669900; green +*/ + +a { + color:#003366; + text-decoration:underline; +} + +a:hover { + color:#ff9933; +} + +body { + font-family: verdana, tahoma, helvetica, arial, sans-serif; + font-size: 90%; + background-color:#ffffff; + margin: 1em; +} + +pre { + font-family: courier, serif; + background-color:#f8f8f8; + margin: 1.5em; + font-size:90%; +} + +ul { + list-style: circle outside; + font-stretch:extra-expanded; +/* font-size:90%;*/ +} + +ul.menu { /* inherits from ul */ + padding-left: 1em; +} + + +em { + color:#FF7700; + font-size:110%; +} + +h1,h2,h3{ + color:#FF7700; +} + +h1 { + border-color:#d0d0d0; + border-style:solid; + border-width:1px; + font-weight:bold; + padding: 0.2em; + background-color:#f8f8f8 +} + +h2 { + font-size:120%; + font-weight:bold; + border-bottom-style:solid; + border-bottom-width:1px; + border-bottom-color:#d0d0d0; +} + +h3 { + font-size:110%; + font-weight:bold; + font-style:italic; +} + +tt { + font-family: courier, serif; +} + +tt.classname { + font-weight:bold; +} + +tt.constant { + font-weight:bold; +} + + +p { + line-height: 1.5em; +} + + +p.author { +/* line-height: 0.5em; */ + font-size:70%; +} + + +div.links{ + float: left; + clear: left; + width: 12em; + background-color:#f8f8f8; + border-style:solid; + border-width:1px; + border-color:#d0d0d0; + margin-bottom: 0.5em; + padding: 0.5em 0.5em 0.5em 0.5em; + margin: 0.5em 0.5em 0em 0em; +} + +div.main{ + border-style:solid; + border-width:1px; + border-color:#d0d0d0; + margin: 0.5em 0em 0.5em 14em; + padding: 0.5em 0.5em 0.5em 0.5em; +} + +div.by{ + line-height: 0.5em; + border-width:1px; + border-color:#d0d0d0; + margin: 0.5em 0em 0.5em 14em; + padding: 0.5em 0.5em 0.5em 0.5em; +} + diff --git a/elf_examples/asm.lst b/elf_examples/asm.lst index 359f4f1f32750ee44bc977e4ae5a92d532577988..aa1fd648de2839d6792612360861b853154d9a9c 100644 --- a/elf_examples/asm.lst +++ b/elf_examples/asm.lst @@ -1,23 +1,23 @@ - 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 00000000 BA0E000000 mov edx,len ;message length - 10 00000005 B9[00000000] mov ecx,msg ;message to write - 11 0000000A BB01000000 mov ebx,1 ;file descriptor (stdout) - 12 0000000F B804000000 mov eax,4 ;system call number (sys_write) - 13 00000014 CD80 int 0x80 ;call kernel - 14 - 15 00000016 B801000000 mov eax,1 ;system call number (sys_exit) - 16 0000001B CD80 int 0x80 ;call kernel - 17 - 18 section .data - 19 - 20 00000000 48656C6C6F2C20776F- msg db 'Hello, world!',0xa ;our dear string - 21 00000009 726C64210A - 22 len equ $ - msg ;length of our dear string - 23 + 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 00000000 BA0E000000 mov edx,len ;message length + 10 00000005 B9[00000000] mov ecx,msg ;message to write + 11 0000000A BB01000000 mov ebx,1 ;file descriptor (stdout) + 12 0000000F B804000000 mov eax,4 ;system call number (sys_write) + 13 00000014 CD80 int 0x80 ;call kernel + 14 + 15 00000016 B801000000 mov eax,1 ;system call number (sys_exit) + 16 0000001B CD80 int 0x80 ;call kernel + 17 + 18 section .data + 19 + 20 00000000 48656C6C6F2C20776F- msg db 'Hello, world!',0xa ;our dear string + 21 00000009 726C64210A + 22 len equ $ - msg ;length of our dear string + 23 diff --git a/elf_examples/asm.s b/elf_examples/asm.s index 59e6e17f5667dff07cece203f93e79b80a736100..c9f5221278d25ffee64a187ae7b8e796e3f43c3f 100644 --- a/elf_examples/asm.s +++ b/elf_examples/asm.s @@ -1,22 +1,22 @@ -; nasm -f elf hello.asm # this will produce hello.o ELF object file -; ld -s -o hello hello.o # this will produce hello executable - -section .text - global _start ;must be declared for linker (ld) - -_start: ;tell linker entry point - - mov edx,len ;message length - mov ecx,msg ;message to write - mov ebx,1 ;file descriptor (stdout) - mov eax,4 ;system call number (sys_write) - int 0x80 ;call kernel - - mov eax,1 ;system call number (sys_exit) - int 0x80 ;call kernel - -section .data - -msg db 'Hello, world!',0xa ;our dear string -len equ $ - msg ;length of our dear string - +; nasm -f elf hello.asm # this will produce hello.o ELF object file +; ld -s -o hello hello.o # this will produce hello executable + +section .text + global _start ;must be declared for linker (ld) + +_start: ;tell linker entry point + + mov edx,len ;message length + mov ecx,msg ;message to write + mov ebx,1 ;file descriptor (stdout) + mov eax,4 ;system call number (sys_write) + int 0x80 ;call kernel + + mov eax,1 ;system call number (sys_exit) + int 0x80 ;call kernel + +section .data + +msg db 'Hello, world!',0xa ;our dear string +len equ $ - msg ;length of our dear string + diff --git a/elf_examples/asm64.lst b/elf_examples/asm64.lst index 359f4f1f32750ee44bc977e4ae5a92d532577988..aa1fd648de2839d6792612360861b853154d9a9c 100644 --- a/elf_examples/asm64.lst +++ b/elf_examples/asm64.lst @@ -1,23 +1,23 @@ - 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 00000000 BA0E000000 mov edx,len ;message length - 10 00000005 B9[00000000] mov ecx,msg ;message to write - 11 0000000A BB01000000 mov ebx,1 ;file descriptor (stdout) - 12 0000000F B804000000 mov eax,4 ;system call number (sys_write) - 13 00000014 CD80 int 0x80 ;call kernel - 14 - 15 00000016 B801000000 mov eax,1 ;system call number (sys_exit) - 16 0000001B CD80 int 0x80 ;call kernel - 17 - 18 section .data - 19 - 20 00000000 48656C6C6F2C20776F- msg db 'Hello, world!',0xa ;our dear string - 21 00000009 726C64210A - 22 len equ $ - msg ;length of our dear string - 23 + 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 00000000 BA0E000000 mov edx,len ;message length + 10 00000005 B9[00000000] mov ecx,msg ;message to write + 11 0000000A BB01000000 mov ebx,1 ;file descriptor (stdout) + 12 0000000F B804000000 mov eax,4 ;system call number (sys_write) + 13 00000014 CD80 int 0x80 ;call kernel + 14 + 15 00000016 B801000000 mov eax,1 ;system call number (sys_exit) + 16 0000001B CD80 int 0x80 ;call kernel + 17 + 18 section .data + 19 + 20 00000000 48656C6C6F2C20776F- msg db 'Hello, world!',0xa ;our dear string + 21 00000009 726C64210A + 22 len equ $ - msg ;length of our dear string + 23 diff --git a/elf_examples/hello.c b/elf_examples/hello.c index 97a1b81adc53452b87d41b58a4316da7904ae342..65f198c05467029a849ba026f13405cbb808ba2b 100644 --- a/elf_examples/hello.c +++ b/elf_examples/hello.c @@ -1,8 +1,8 @@ -#include <stdio.h> - -int main() -{ - printf( "Hello\n" ); - - return 0; -} +#include <stdio.h> + +int main() +{ + printf( "Hello\n" ); + + return 0; +} diff --git a/elf_examples/hello_32.txt b/elf_examples/hello_32.txt index ec96c844d9224be29c0b9780e25dc3095b38780c..bf898069173601dd54412a112f13c58b924c4ad6 100644 --- a/elf_examples/hello_32.txt +++ b/elf_examples/hello_32.txt @@ -1,211 +1,211 @@ -ELF Header: - Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 - Class: ELF32 - Data: 2's complement, little endian - Version: 1 (current) - OS/ABI: UNIX - System V - ABI Version: 0 - Type: EXEC (Executable file) - Machine: Intel 80386 - Version: 0x1 - Entry point address: 0x80482b0 - Start of program headers: 52 (bytes into file) - Start of section headers: 1912 (bytes into file) - Flags: 0x0 - Size of this header: 52 (bytes) - Size of program headers: 32 (bytes) - Number of program headers: 7 - Size of section headers: 40 (bytes) - Number of section headers: 28 - Section header string table index: 25 - -Section Headers: - [Nr] Name Type Addr Off Size ES Flg Lk Inf Al - [ 0] NULL 00000000 000000 000000 00 0 0 0 - [ 1] .interp PROGBITS 08048114 000114 000013 00 A 0 0 1 - [ 2] .note.ABI-tag NOTE 08048128 000128 000020 00 A 0 0 4 - [ 3] .gnu.hash GNU_HASH 08048148 000148 000020 04 A 4 0 4 - [ 4] .dynsym DYNSYM 08048168 000168 000050 10 A 5 1 4 - [ 5] .dynstr STRTAB 080481b8 0001b8 00004a 00 A 0 0 1 - [ 6] .gnu.version VERSYM 08048202 000202 00000a 02 A 4 0 2 - [ 7] .gnu.version_r VERNEED 0804820c 00020c 000020 00 A 5 1 4 - [ 8] .rel.dyn REL 0804822c 00022c 000008 08 A 4 0 4 - [ 9] .rel.plt REL 08048234 000234 000018 08 A 4 11 4 - [10] .init PROGBITS 0804824c 00024c 000017 00 AX 0 0 4 - [11] .plt PROGBITS 08048264 000264 000040 04 AX 0 0 4 - [12] .text PROGBITS 080482b0 0002b0 0001a8 00 AX 0 0 16 - [13] .fini PROGBITS 08048458 000458 00001c 00 AX 0 0 4 - [14] .rodata PROGBITS 08048474 000474 000012 00 A 0 0 4 - [15] .eh_frame PROGBITS 08048488 000488 000004 00 A 0 0 4 - [16] .ctors PROGBITS 0804948c 00048c 000008 00 WA 0 0 4 - [17] .dtors PROGBITS 08049494 000494 000008 00 WA 0 0 4 - [18] .jcr PROGBITS 0804949c 00049c 000004 00 WA 0 0 4 - [19] .dynamic DYNAMIC 080494a0 0004a0 0000c8 08 WA 5 0 4 - [20] .got PROGBITS 08049568 000568 000004 04 WA 0 0 4 - [21] .got.plt PROGBITS 0804956c 00056c 000018 04 WA 0 0 4 - [22] .data PROGBITS 08049584 000584 000004 00 WA 0 0 4 - [23] .bss NOBITS 08049588 000588 000008 00 WA 0 0 4 - [24] .comment PROGBITS 00000000 000588 000114 00 0 0 1 - [25] .shstrtab STRTAB 00000000 00069c 0000db 00 0 0 1 - [26] .symtab SYMTAB 00000000 000bd8 000440 10 27 48 4 - [27] .strtab STRTAB 00000000 001018 000259 00 0 0 1 -Key to Flags: - W (write), A (alloc), X (execute), M (merge), S (strings) - I (info), L (link order), G (group), x (unknown) - O (extra OS processing required) o (OS specific), p (processor specific) - -There are no section groups in this file. - -Program Headers: - Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align - PHDR 0x000034 0x08048034 0x08048034 0x000e0 0x000e0 R E 0x4 - INTERP 0x000114 0x08048114 0x08048114 0x00013 0x00013 R 0x1 - [Requesting program interpreter: /lib/ld-linux.so.2] - LOAD 0x000000 0x08048000 0x08048000 0x0048c 0x0048c R E 0x1000 - LOAD 0x00048c 0x0804948c 0x0804948c 0x000fc 0x00104 RW 0x1000 - DYNAMIC 0x0004a0 0x080494a0 0x080494a0 0x000c8 0x000c8 RW 0x4 - NOTE 0x000128 0x08048128 0x08048128 0x00020 0x00020 R 0x4 - GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4 - - Section to Segment mapping: - Segment Sections... - 00 - 01 .interp - 02 .interp .note.ABI-tag .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .eh_frame - 03 .ctors .dtors .jcr .dynamic .got .got.plt .data .bss - 04 .dynamic - 05 .note.ABI-tag - 06 - -Dynamic section at offset 0x4a0 contains 20 entries: - Tag Type Name/Value - 0x00000001 (NEEDED) Shared library: [libc.so.6] - 0x0000000c (INIT) 0x804824c - 0x0000000d (FINI) 0x8048458 - 0x6ffffef5 (GNU_HASH) 0x8048148 - 0x00000005 (STRTAB) 0x80481b8 - 0x00000006 (SYMTAB) 0x8048168 - 0x0000000a (STRSZ) 74 (bytes) - 0x0000000b (SYMENT) 16 (bytes) - 0x00000015 (DEBUG) 0x0 - 0x00000003 (PLTGOT) 0x804956c - 0x00000002 (PLTRELSZ) 24 (bytes) - 0x00000014 (PLTREL) REL - 0x00000017 (JMPREL) 0x8048234 - 0x00000011 (REL) 0x804822c - 0x00000012 (RELSZ) 8 (bytes) - 0x00000013 (RELENT) 8 (bytes) - 0x6ffffffe (VERNEED) 0x804820c - 0x6fffffff (VERNEEDNUM) 1 - 0x6ffffff0 (VERSYM) 0x8048202 - 0x00000000 (NULL) 0x0 - -Relocation section '.rel.dyn' at offset 0x22c contains 1 entries: - Offset Info Type Sym.Value Sym. Name -08049568 00000106 R_386_GLOB_DAT 00000000 __gmon_start__ - -Relocation section '.rel.plt' at offset 0x234 contains 3 entries: - Offset Info Type Sym.Value Sym. Name -08049578 00000107 R_386_JUMP_SLOT 00000000 __gmon_start__ -0804957c 00000207 R_386_JUMP_SLOT 00000000 __libc_start_main -08049580 00000307 R_386_JUMP_SLOT 00000000 puts - -There are no unwind sections in this file. - -Symbol table '.dynsym' contains 5 entries: - Num: Value Size Type Bind Vis Ndx Name - 0: 00000000 0 NOTYPE LOCAL DEFAULT UND - 1: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ - 2: 00000000 415 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.0 (2) - 3: 00000000 399 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.0 (2) - 4: 08048478 4 OBJECT GLOBAL DEFAULT 14 _IO_stdin_used - -Symbol table '.symtab' contains 68 entries: - Num: Value Size Type Bind Vis Ndx Name - 0: 00000000 0 NOTYPE LOCAL DEFAULT UND - 1: 08048114 0 SECTION LOCAL DEFAULT 1 - 2: 08048128 0 SECTION LOCAL DEFAULT 2 - 3: 08048148 0 SECTION LOCAL DEFAULT 3 - 4: 08048168 0 SECTION LOCAL DEFAULT 4 - 5: 080481b8 0 SECTION LOCAL DEFAULT 5 - 6: 08048202 0 SECTION LOCAL DEFAULT 6 - 7: 0804820c 0 SECTION LOCAL DEFAULT 7 - 8: 0804822c 0 SECTION LOCAL DEFAULT 8 - 9: 08048234 0 SECTION LOCAL DEFAULT 9 - 10: 0804824c 0 SECTION LOCAL DEFAULT 10 - 11: 08048264 0 SECTION LOCAL DEFAULT 11 - 12: 080482b0 0 SECTION LOCAL DEFAULT 12 - 13: 08048458 0 SECTION LOCAL DEFAULT 13 - 14: 08048474 0 SECTION LOCAL DEFAULT 14 - 15: 08048488 0 SECTION LOCAL DEFAULT 15 - 16: 0804948c 0 SECTION LOCAL DEFAULT 16 - 17: 08049494 0 SECTION LOCAL DEFAULT 17 - 18: 0804949c 0 SECTION LOCAL DEFAULT 18 - 19: 080494a0 0 SECTION LOCAL DEFAULT 19 - 20: 08049568 0 SECTION LOCAL DEFAULT 20 - 21: 0804956c 0 SECTION LOCAL DEFAULT 21 - 22: 08049584 0 SECTION LOCAL DEFAULT 22 - 23: 08049588 0 SECTION LOCAL DEFAULT 23 - 24: 00000000 0 SECTION LOCAL DEFAULT 24 - 25: 080482d4 0 FUNC LOCAL DEFAULT 12 call_gmon_start - 26: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c - 27: 0804948c 0 OBJECT LOCAL DEFAULT 16 __CTOR_LIST__ - 28: 08049494 0 OBJECT LOCAL DEFAULT 17 __DTOR_LIST__ - 29: 0804949c 0 OBJECT LOCAL DEFAULT 18 __JCR_LIST__ - 30: 08049588 4 OBJECT LOCAL DEFAULT 23 dtor_idx.5805 - 31: 0804958c 1 OBJECT LOCAL DEFAULT 23 completed.5803 - 32: 08048300 0 FUNC LOCAL DEFAULT 12 __do_global_dtors_aux - 33: 08048360 0 FUNC LOCAL DEFAULT 12 frame_dummy - 34: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c - 35: 08049490 0 OBJECT LOCAL DEFAULT 16 __CTOR_END__ - 36: 08048488 0 OBJECT LOCAL DEFAULT 15 __FRAME_END__ - 37: 0804949c 0 OBJECT LOCAL DEFAULT 18 __JCR_END__ - 38: 08048430 0 FUNC LOCAL DEFAULT 12 __do_global_ctors_aux - 39: 00000000 0 FILE LOCAL DEFAULT ABS hello.c - 40: 0804948c 0 NOTYPE LOCAL HIDDEN 16 __preinit_array_start - 41: 0804948c 0 NOTYPE LOCAL HIDDEN 16 __fini_array_end - 42: 0804956c 0 OBJECT LOCAL HIDDEN 21 _GLOBAL_OFFSET_TABLE_ - 43: 0804948c 0 NOTYPE LOCAL HIDDEN 16 __preinit_array_end - 44: 0804948c 0 NOTYPE LOCAL HIDDEN 16 __fini_array_start - 45: 0804948c 0 NOTYPE LOCAL HIDDEN 16 __init_array_end - 46: 0804948c 0 NOTYPE LOCAL HIDDEN 16 __init_array_start - 47: 080494a0 0 OBJECT LOCAL HIDDEN 19 _DYNAMIC - 48: 08049584 0 NOTYPE WEAK DEFAULT 22 data_start - 49: 080483b0 5 FUNC GLOBAL DEFAULT 12 __libc_csu_fini - 50: 080482b0 0 FUNC GLOBAL DEFAULT 12 _start - 51: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ - 52: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses - 53: 08048474 4 OBJECT GLOBAL DEFAULT 14 _fp_hw - 54: 08048458 0 FUNC GLOBAL DEFAULT 13 _fini - 55: 00000000 415 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_ - 56: 08048478 4 OBJECT GLOBAL DEFAULT 14 _IO_stdin_used - 57: 08049584 0 NOTYPE GLOBAL DEFAULT 22 __data_start - 58: 0804847c 0 OBJECT GLOBAL HIDDEN 14 __dso_handle - 59: 08049498 0 OBJECT GLOBAL HIDDEN 17 __DTOR_END__ - 60: 080483c0 105 FUNC GLOBAL DEFAULT 12 __libc_csu_init - 61: 08049588 0 NOTYPE GLOBAL DEFAULT ABS __bss_start - 62: 08049590 0 NOTYPE GLOBAL DEFAULT ABS _end - 63: 00000000 399 FUNC GLOBAL DEFAULT UND puts@@GLIBC_2.0 - 64: 08049588 0 NOTYPE GLOBAL DEFAULT ABS _edata - 65: 08048429 0 FUNC GLOBAL HIDDEN 12 __i686.get_pc_thunk.bx - 66: 08048384 43 FUNC GLOBAL DEFAULT 12 main - 67: 0804824c 0 FUNC GLOBAL DEFAULT 10 _init - -Histogram for `.gnu.hash' bucket list length (total of 2 buckets): - Length Number % of total Coverage - 0 1 ( 50.0%) - 1 1 ( 50.0%) 100.0% - -Version symbols section '.gnu.version' contains 5 entries: - Addr: 0000000008048202 Offset: 0x000202 Link: 4 (.dynsym) - 000: 0 (*local*) 0 (*local*) 2 (GLIBC_2.0) 2 (GLIBC_2.0) - 004: 1 (*global*) - -Version needs section '.gnu.version_r' contains 1 entries: - Addr: 0x000000000804820c Offset: 0x00020c Link to section: 5 (.dynstr) - 000000: Version: 1 File: libc.so.6 Cnt: 1 - 0x0010: Name: GLIBC_2.0 Flags: none Version: 2 - -Notes at offset 0x00000128 with length 0x00000020: - Owner Data size Description - GNU 0x00000010 NT_VERSION (version) +ELF Header: + Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 + Class: ELF32 + Data: 2's complement, little endian + Version: 1 (current) + OS/ABI: UNIX - System V + ABI Version: 0 + Type: EXEC (Executable file) + Machine: Intel 80386 + Version: 0x1 + Entry point address: 0x80482b0 + Start of program headers: 52 (bytes into file) + Start of section headers: 1912 (bytes into file) + Flags: 0x0 + Size of this header: 52 (bytes) + Size of program headers: 32 (bytes) + Number of program headers: 7 + Size of section headers: 40 (bytes) + Number of section headers: 28 + Section header string table index: 25 + +Section Headers: + [Nr] Name Type Addr Off Size ES Flg Lk Inf Al + [ 0] NULL 00000000 000000 000000 00 0 0 0 + [ 1] .interp PROGBITS 08048114 000114 000013 00 A 0 0 1 + [ 2] .note.ABI-tag NOTE 08048128 000128 000020 00 A 0 0 4 + [ 3] .gnu.hash GNU_HASH 08048148 000148 000020 04 A 4 0 4 + [ 4] .dynsym DYNSYM 08048168 000168 000050 10 A 5 1 4 + [ 5] .dynstr STRTAB 080481b8 0001b8 00004a 00 A 0 0 1 + [ 6] .gnu.version VERSYM 08048202 000202 00000a 02 A 4 0 2 + [ 7] .gnu.version_r VERNEED 0804820c 00020c 000020 00 A 5 1 4 + [ 8] .rel.dyn REL 0804822c 00022c 000008 08 A 4 0 4 + [ 9] .rel.plt REL 08048234 000234 000018 08 A 4 11 4 + [10] .init PROGBITS 0804824c 00024c 000017 00 AX 0 0 4 + [11] .plt PROGBITS 08048264 000264 000040 04 AX 0 0 4 + [12] .text PROGBITS 080482b0 0002b0 0001a8 00 AX 0 0 16 + [13] .fini PROGBITS 08048458 000458 00001c 00 AX 0 0 4 + [14] .rodata PROGBITS 08048474 000474 000012 00 A 0 0 4 + [15] .eh_frame PROGBITS 08048488 000488 000004 00 A 0 0 4 + [16] .ctors PROGBITS 0804948c 00048c 000008 00 WA 0 0 4 + [17] .dtors PROGBITS 08049494 000494 000008 00 WA 0 0 4 + [18] .jcr PROGBITS 0804949c 00049c 000004 00 WA 0 0 4 + [19] .dynamic DYNAMIC 080494a0 0004a0 0000c8 08 WA 5 0 4 + [20] .got PROGBITS 08049568 000568 000004 04 WA 0 0 4 + [21] .got.plt PROGBITS 0804956c 00056c 000018 04 WA 0 0 4 + [22] .data PROGBITS 08049584 000584 000004 00 WA 0 0 4 + [23] .bss NOBITS 08049588 000588 000008 00 WA 0 0 4 + [24] .comment PROGBITS 00000000 000588 000114 00 0 0 1 + [25] .shstrtab STRTAB 00000000 00069c 0000db 00 0 0 1 + [26] .symtab SYMTAB 00000000 000bd8 000440 10 27 48 4 + [27] .strtab STRTAB 00000000 001018 000259 00 0 0 1 +Key to Flags: + W (write), A (alloc), X (execute), M (merge), S (strings) + I (info), L (link order), G (group), x (unknown) + O (extra OS processing required) o (OS specific), p (processor specific) + +There are no section groups in this file. + +Program Headers: + Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align + PHDR 0x000034 0x08048034 0x08048034 0x000e0 0x000e0 R E 0x4 + INTERP 0x000114 0x08048114 0x08048114 0x00013 0x00013 R 0x1 + [Requesting program interpreter: /lib/ld-linux.so.2] + LOAD 0x000000 0x08048000 0x08048000 0x0048c 0x0048c R E 0x1000 + LOAD 0x00048c 0x0804948c 0x0804948c 0x000fc 0x00104 RW 0x1000 + DYNAMIC 0x0004a0 0x080494a0 0x080494a0 0x000c8 0x000c8 RW 0x4 + NOTE 0x000128 0x08048128 0x08048128 0x00020 0x00020 R 0x4 + GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4 + + Section to Segment mapping: + Segment Sections... + 00 + 01 .interp + 02 .interp .note.ABI-tag .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .eh_frame + 03 .ctors .dtors .jcr .dynamic .got .got.plt .data .bss + 04 .dynamic + 05 .note.ABI-tag + 06 + +Dynamic section at offset 0x4a0 contains 20 entries: + Tag Type Name/Value + 0x00000001 (NEEDED) Shared library: [libc.so.6] + 0x0000000c (INIT) 0x804824c + 0x0000000d (FINI) 0x8048458 + 0x6ffffef5 (GNU_HASH) 0x8048148 + 0x00000005 (STRTAB) 0x80481b8 + 0x00000006 (SYMTAB) 0x8048168 + 0x0000000a (STRSZ) 74 (bytes) + 0x0000000b (SYMENT) 16 (bytes) + 0x00000015 (DEBUG) 0x0 + 0x00000003 (PLTGOT) 0x804956c + 0x00000002 (PLTRELSZ) 24 (bytes) + 0x00000014 (PLTREL) REL + 0x00000017 (JMPREL) 0x8048234 + 0x00000011 (REL) 0x804822c + 0x00000012 (RELSZ) 8 (bytes) + 0x00000013 (RELENT) 8 (bytes) + 0x6ffffffe (VERNEED) 0x804820c + 0x6fffffff (VERNEEDNUM) 1 + 0x6ffffff0 (VERSYM) 0x8048202 + 0x00000000 (NULL) 0x0 + +Relocation section '.rel.dyn' at offset 0x22c contains 1 entries: + Offset Info Type Sym.Value Sym. Name +08049568 00000106 R_386_GLOB_DAT 00000000 __gmon_start__ + +Relocation section '.rel.plt' at offset 0x234 contains 3 entries: + Offset Info Type Sym.Value Sym. Name +08049578 00000107 R_386_JUMP_SLOT 00000000 __gmon_start__ +0804957c 00000207 R_386_JUMP_SLOT 00000000 __libc_start_main +08049580 00000307 R_386_JUMP_SLOT 00000000 puts + +There are no unwind sections in this file. + +Symbol table '.dynsym' contains 5 entries: + Num: Value Size Type Bind Vis Ndx Name + 0: 00000000 0 NOTYPE LOCAL DEFAULT UND + 1: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ + 2: 00000000 415 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.0 (2) + 3: 00000000 399 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.0 (2) + 4: 08048478 4 OBJECT GLOBAL DEFAULT 14 _IO_stdin_used + +Symbol table '.symtab' contains 68 entries: + Num: Value Size Type Bind Vis Ndx Name + 0: 00000000 0 NOTYPE LOCAL DEFAULT UND + 1: 08048114 0 SECTION LOCAL DEFAULT 1 + 2: 08048128 0 SECTION LOCAL DEFAULT 2 + 3: 08048148 0 SECTION LOCAL DEFAULT 3 + 4: 08048168 0 SECTION LOCAL DEFAULT 4 + 5: 080481b8 0 SECTION LOCAL DEFAULT 5 + 6: 08048202 0 SECTION LOCAL DEFAULT 6 + 7: 0804820c 0 SECTION LOCAL DEFAULT 7 + 8: 0804822c 0 SECTION LOCAL DEFAULT 8 + 9: 08048234 0 SECTION LOCAL DEFAULT 9 + 10: 0804824c 0 SECTION LOCAL DEFAULT 10 + 11: 08048264 0 SECTION LOCAL DEFAULT 11 + 12: 080482b0 0 SECTION LOCAL DEFAULT 12 + 13: 08048458 0 SECTION LOCAL DEFAULT 13 + 14: 08048474 0 SECTION LOCAL DEFAULT 14 + 15: 08048488 0 SECTION LOCAL DEFAULT 15 + 16: 0804948c 0 SECTION LOCAL DEFAULT 16 + 17: 08049494 0 SECTION LOCAL DEFAULT 17 + 18: 0804949c 0 SECTION LOCAL DEFAULT 18 + 19: 080494a0 0 SECTION LOCAL DEFAULT 19 + 20: 08049568 0 SECTION LOCAL DEFAULT 20 + 21: 0804956c 0 SECTION LOCAL DEFAULT 21 + 22: 08049584 0 SECTION LOCAL DEFAULT 22 + 23: 08049588 0 SECTION LOCAL DEFAULT 23 + 24: 00000000 0 SECTION LOCAL DEFAULT 24 + 25: 080482d4 0 FUNC LOCAL DEFAULT 12 call_gmon_start + 26: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c + 27: 0804948c 0 OBJECT LOCAL DEFAULT 16 __CTOR_LIST__ + 28: 08049494 0 OBJECT LOCAL DEFAULT 17 __DTOR_LIST__ + 29: 0804949c 0 OBJECT LOCAL DEFAULT 18 __JCR_LIST__ + 30: 08049588 4 OBJECT LOCAL DEFAULT 23 dtor_idx.5805 + 31: 0804958c 1 OBJECT LOCAL DEFAULT 23 completed.5803 + 32: 08048300 0 FUNC LOCAL DEFAULT 12 __do_global_dtors_aux + 33: 08048360 0 FUNC LOCAL DEFAULT 12 frame_dummy + 34: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c + 35: 08049490 0 OBJECT LOCAL DEFAULT 16 __CTOR_END__ + 36: 08048488 0 OBJECT LOCAL DEFAULT 15 __FRAME_END__ + 37: 0804949c 0 OBJECT LOCAL DEFAULT 18 __JCR_END__ + 38: 08048430 0 FUNC LOCAL DEFAULT 12 __do_global_ctors_aux + 39: 00000000 0 FILE LOCAL DEFAULT ABS hello.c + 40: 0804948c 0 NOTYPE LOCAL HIDDEN 16 __preinit_array_start + 41: 0804948c 0 NOTYPE LOCAL HIDDEN 16 __fini_array_end + 42: 0804956c 0 OBJECT LOCAL HIDDEN 21 _GLOBAL_OFFSET_TABLE_ + 43: 0804948c 0 NOTYPE LOCAL HIDDEN 16 __preinit_array_end + 44: 0804948c 0 NOTYPE LOCAL HIDDEN 16 __fini_array_start + 45: 0804948c 0 NOTYPE LOCAL HIDDEN 16 __init_array_end + 46: 0804948c 0 NOTYPE LOCAL HIDDEN 16 __init_array_start + 47: 080494a0 0 OBJECT LOCAL HIDDEN 19 _DYNAMIC + 48: 08049584 0 NOTYPE WEAK DEFAULT 22 data_start + 49: 080483b0 5 FUNC GLOBAL DEFAULT 12 __libc_csu_fini + 50: 080482b0 0 FUNC GLOBAL DEFAULT 12 _start + 51: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ + 52: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses + 53: 08048474 4 OBJECT GLOBAL DEFAULT 14 _fp_hw + 54: 08048458 0 FUNC GLOBAL DEFAULT 13 _fini + 55: 00000000 415 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_ + 56: 08048478 4 OBJECT GLOBAL DEFAULT 14 _IO_stdin_used + 57: 08049584 0 NOTYPE GLOBAL DEFAULT 22 __data_start + 58: 0804847c 0 OBJECT GLOBAL HIDDEN 14 __dso_handle + 59: 08049498 0 OBJECT GLOBAL HIDDEN 17 __DTOR_END__ + 60: 080483c0 105 FUNC GLOBAL DEFAULT 12 __libc_csu_init + 61: 08049588 0 NOTYPE GLOBAL DEFAULT ABS __bss_start + 62: 08049590 0 NOTYPE GLOBAL DEFAULT ABS _end + 63: 00000000 399 FUNC GLOBAL DEFAULT UND puts@@GLIBC_2.0 + 64: 08049588 0 NOTYPE GLOBAL DEFAULT ABS _edata + 65: 08048429 0 FUNC GLOBAL HIDDEN 12 __i686.get_pc_thunk.bx + 66: 08048384 43 FUNC GLOBAL DEFAULT 12 main + 67: 0804824c 0 FUNC GLOBAL DEFAULT 10 _init + +Histogram for `.gnu.hash' bucket list length (total of 2 buckets): + Length Number % of total Coverage + 0 1 ( 50.0%) + 1 1 ( 50.0%) 100.0% + +Version symbols section '.gnu.version' contains 5 entries: + Addr: 0000000008048202 Offset: 0x000202 Link: 4 (.dynsym) + 000: 0 (*local*) 0 (*local*) 2 (GLIBC_2.0) 2 (GLIBC_2.0) + 004: 1 (*global*) + +Version needs section '.gnu.version_r' contains 1 entries: + Addr: 0x000000000804820c Offset: 0x00020c Link to section: 5 (.dynstr) + 000000: Version: 1 File: libc.so.6 Cnt: 1 + 0x0010: Name: GLIBC_2.0 Flags: none Version: 2 + +Notes at offset 0x00000128 with length 0x00000020: + Owner Data size Description + GNU 0x00000010 NT_VERSION (version) diff --git a/elf_examples/hello_32_o.txt b/elf_examples/hello_32_o.txt index b21ebaf27b47aa6403825caec7e686e880c75889..ccf7efb00babfe016e4ac0619c22586f5b28cb83 100644 --- a/elf_examples/hello_32_o.txt +++ b/elf_examples/hello_32_o.txt @@ -1,64 +1,64 @@ -ELF Header: - Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 - Class: ELF32 - Data: 2's complement, little endian - Version: 1 (current) - OS/ABI: UNIX - System V - ABI Version: 0 - Type: REL (Relocatable file) - Machine: Intel 80386 - Version: 0x1 - Entry point address: 0x0 - Start of program headers: 0 (bytes into file) - Start of section headers: 232 (bytes into file) - Flags: 0x0 - Size of this header: 52 (bytes) - Size of program headers: 0 (bytes) - Number of program headers: 0 - Size of section headers: 40 (bytes) - Number of section headers: 11 - Section header string table index: 8 - -Section Headers: - [Nr] Name Type Addr Off Size ES Flg Lk Inf Al - [ 0] NULL 00000000 000000 000000 00 0 0 0 - [ 1] .text PROGBITS 00000000 000034 00002b 00 AX 0 0 4 - [ 2] .rel.text REL 00000000 000354 000010 08 9 1 4 - [ 3] .data PROGBITS 00000000 000060 000000 00 WA 0 0 4 - [ 4] .bss NOBITS 00000000 000060 000000 00 WA 0 0 4 - [ 5] .rodata PROGBITS 00000000 000060 000006 00 A 0 0 1 - [ 6] .comment PROGBITS 00000000 000066 00002e 00 0 0 1 - [ 7] .note.GNU-stack PROGBITS 00000000 000094 000000 00 0 0 1 - [ 8] .shstrtab STRTAB 00000000 000094 000051 00 0 0 1 - [ 9] .symtab SYMTAB 00000000 0002a0 0000a0 10 10 8 4 - [10] .strtab STRTAB 00000000 000340 000013 00 0 0 1 -Key to Flags: - W (write), A (alloc), X (execute), M (merge), S (strings) - I (info), L (link order), G (group), x (unknown) - O (extra OS processing required) o (OS specific), p (processor specific) - -There are no section groups in this file. - -There are no program headers in this file. - -Relocation section '.rel.text' at offset 0x354 contains 2 entries: - Offset Info Type Sym.Value Sym. Name -00000014 00000501 R_386_32 00000000 .rodata -00000019 00000902 R_386_PC32 00000000 puts - -There are no unwind sections in this file. - -Symbol table '.symtab' contains 10 entries: - Num: Value Size Type Bind Vis Ndx Name - 0: 00000000 0 NOTYPE LOCAL DEFAULT UND - 1: 00000000 0 FILE LOCAL DEFAULT ABS hello.c - 2: 00000000 0 SECTION LOCAL DEFAULT 1 - 3: 00000000 0 SECTION LOCAL DEFAULT 3 - 4: 00000000 0 SECTION LOCAL DEFAULT 4 - 5: 00000000 0 SECTION LOCAL DEFAULT 5 - 6: 00000000 0 SECTION LOCAL DEFAULT 7 - 7: 00000000 0 SECTION LOCAL DEFAULT 6 - 8: 00000000 43 FUNC GLOBAL DEFAULT 1 main - 9: 00000000 0 NOTYPE GLOBAL DEFAULT UND puts - -No version information found in this file. +ELF Header: + Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 + Class: ELF32 + Data: 2's complement, little endian + Version: 1 (current) + OS/ABI: UNIX - System V + ABI Version: 0 + Type: REL (Relocatable file) + Machine: Intel 80386 + Version: 0x1 + Entry point address: 0x0 + Start of program headers: 0 (bytes into file) + Start of section headers: 232 (bytes into file) + Flags: 0x0 + Size of this header: 52 (bytes) + Size of program headers: 0 (bytes) + Number of program headers: 0 + Size of section headers: 40 (bytes) + Number of section headers: 11 + Section header string table index: 8 + +Section Headers: + [Nr] Name Type Addr Off Size ES Flg Lk Inf Al + [ 0] NULL 00000000 000000 000000 00 0 0 0 + [ 1] .text PROGBITS 00000000 000034 00002b 00 AX 0 0 4 + [ 2] .rel.text REL 00000000 000354 000010 08 9 1 4 + [ 3] .data PROGBITS 00000000 000060 000000 00 WA 0 0 4 + [ 4] .bss NOBITS 00000000 000060 000000 00 WA 0 0 4 + [ 5] .rodata PROGBITS 00000000 000060 000006 00 A 0 0 1 + [ 6] .comment PROGBITS 00000000 000066 00002e 00 0 0 1 + [ 7] .note.GNU-stack PROGBITS 00000000 000094 000000 00 0 0 1 + [ 8] .shstrtab STRTAB 00000000 000094 000051 00 0 0 1 + [ 9] .symtab SYMTAB 00000000 0002a0 0000a0 10 10 8 4 + [10] .strtab STRTAB 00000000 000340 000013 00 0 0 1 +Key to Flags: + W (write), A (alloc), X (execute), M (merge), S (strings) + I (info), L (link order), G (group), x (unknown) + O (extra OS processing required) o (OS specific), p (processor specific) + +There are no section groups in this file. + +There are no program headers in this file. + +Relocation section '.rel.text' at offset 0x354 contains 2 entries: + Offset Info Type Sym.Value Sym. Name +00000014 00000501 R_386_32 00000000 .rodata +00000019 00000902 R_386_PC32 00000000 puts + +There are no unwind sections in this file. + +Symbol table '.symtab' contains 10 entries: + Num: Value Size Type Bind Vis Ndx Name + 0: 00000000 0 NOTYPE LOCAL DEFAULT UND + 1: 00000000 0 FILE LOCAL DEFAULT ABS hello.c + 2: 00000000 0 SECTION LOCAL DEFAULT 1 + 3: 00000000 0 SECTION LOCAL DEFAULT 3 + 4: 00000000 0 SECTION LOCAL DEFAULT 4 + 5: 00000000 0 SECTION LOCAL DEFAULT 5 + 6: 00000000 0 SECTION LOCAL DEFAULT 7 + 7: 00000000 0 SECTION LOCAL DEFAULT 6 + 8: 00000000 43 FUNC GLOBAL DEFAULT 1 main + 9: 00000000 0 NOTYPE GLOBAL DEFAULT UND puts + +No version information found in this file. diff --git a/elf_examples/hello_64.txt b/elf_examples/hello_64.txt index 4856d227284836e9334dd08122ae6b4a1a80306c..6597d9cb5dc850d2dc3c0b14ae5570d14f4b3ab5 100644 --- a/elf_examples/hello_64.txt +++ b/elf_examples/hello_64.txt @@ -1,244 +1,244 @@ -ELF Header: - Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 - Class: ELF64 - Data: 2's complement, little endian - Version: 1 (current) - OS/ABI: UNIX - System V - ABI Version: 0 - Type: EXEC (Executable file) - Machine: Advanced Micro Devices X86-64 - Version: 0x1 - Entry point address: 0x4003c0 - Start of program headers: 64 (bytes into file) - Start of section headers: 2656 (bytes into file) - Flags: 0x0 - Size of this header: 64 (bytes) - Size of program headers: 56 (bytes) - Number of program headers: 8 - Size of section headers: 64 (bytes) - Number of section headers: 29 - Section header string table index: 26 - -Section Headers: - [Nr] Name Type Address Offset - Size EntSize Flags Link Info Align - [ 0] NULL 0000000000000000 00000000 - 0000000000000000 0000000000000000 0 0 0 - [ 1] .interp PROGBITS 0000000000400200 00000200 - 000000000000001c 0000000000000000 A 0 0 1 - [ 2] .note.ABI-tag NOTE 000000000040021c 0000021c - 0000000000000020 0000000000000000 A 0 0 4 - [ 3] .gnu.hash GNU_HASH 0000000000400240 00000240 - 000000000000001c 0000000000000000 A 4 0 8 - [ 4] .dynsym DYNSYM 0000000000400260 00000260 - 0000000000000060 0000000000000018 A 5 1 8 - [ 5] .dynstr STRTAB 00000000004002c0 000002c0 - 000000000000003d 0000000000000000 A 0 0 1 - [ 6] .gnu.version VERSYM 00000000004002fe 000002fe - 0000000000000008 0000000000000002 A 4 0 2 - [ 7] .gnu.version_r VERNEED 0000000000400308 00000308 - 0000000000000020 0000000000000000 A 5 1 8 - [ 8] .rela.dyn RELA 0000000000400328 00000328 - 0000000000000018 0000000000000018 A 4 0 8 - [ 9] .rela.plt RELA 0000000000400340 00000340 - 0000000000000030 0000000000000018 A 4 11 8 - [10] .init PROGBITS 0000000000400370 00000370 - 0000000000000018 0000000000000000 AX 0 0 4 - [11] .plt PROGBITS 0000000000400388 00000388 - 0000000000000030 0000000000000010 AX 0 0 4 - [12] .text PROGBITS 00000000004003c0 000003c0 - 00000000000001c8 0000000000000000 AX 0 0 16 - [13] .fini PROGBITS 0000000000400588 00000588 - 000000000000000e 0000000000000000 AX 0 0 4 - [14] .rodata PROGBITS 0000000000400598 00000598 - 0000000000000016 0000000000000000 A 0 0 8 - [15] .eh_frame_hdr PROGBITS 00000000004005b0 000005b0 - 0000000000000024 0000000000000000 A 0 0 4 - [16] .eh_frame PROGBITS 00000000004005d8 000005d8 - 0000000000000094 0000000000000000 A 0 0 8 - [17] .ctors PROGBITS 0000000000600670 00000670 - 0000000000000010 0000000000000000 WA 0 0 8 - [18] .dtors PROGBITS 0000000000600680 00000680 - 0000000000000010 0000000000000000 WA 0 0 8 - [19] .jcr PROGBITS 0000000000600690 00000690 - 0000000000000008 0000000000000000 WA 0 0 8 - [20] .dynamic DYNAMIC 0000000000600698 00000698 - 0000000000000190 0000000000000010 WA 5 0 8 - [21] .got PROGBITS 0000000000600828 00000828 - 0000000000000008 0000000000000008 WA 0 0 8 - [22] .got.plt PROGBITS 0000000000600830 00000830 - 0000000000000028 0000000000000008 WA 0 0 8 - [23] .data PROGBITS 0000000000600858 00000858 - 0000000000000004 0000000000000000 WA 0 0 4 - [24] .bss NOBITS 0000000000600860 0000085c - 0000000000000010 0000000000000000 WA 0 0 8 - [25] .comment PROGBITS 0000000000000000 0000085c - 0000000000000114 0000000000000000 0 0 1 - [26] .shstrtab STRTAB 0000000000000000 00000970 - 00000000000000eb 0000000000000000 0 0 1 - [27] .symtab SYMTAB 0000000000000000 000011a0 - 0000000000000648 0000000000000018 28 49 8 - [28] .strtab STRTAB 0000000000000000 000017e8 - 000000000000023f 0000000000000000 0 0 1 -Key to Flags: - W (write), A (alloc), X (execute), M (merge), S (strings) - I (info), L (link order), G (group), x (unknown) - O (extra OS processing required) o (OS specific), p (processor specific) - -There are no section groups in this file. - -Program Headers: - Type Offset VirtAddr PhysAddr - FileSiz MemSiz Flags Align - PHDR 0x0000000000000040 0x0000000000400040 0x0000000000400040 - 0x00000000000001c0 0x00000000000001c0 R E 8 - INTERP 0x0000000000000200 0x0000000000400200 0x0000000000400200 - 0x000000000000001c 0x000000000000001c R 1 - [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2] - LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000 - 0x000000000000066c 0x000000000000066c R E 200000 - LOAD 0x0000000000000670 0x0000000000600670 0x0000000000600670 - 0x00000000000001ec 0x0000000000000200 RW 200000 - DYNAMIC 0x0000000000000698 0x0000000000600698 0x0000000000600698 - 0x0000000000000190 0x0000000000000190 RW 8 - NOTE 0x000000000000021c 0x000000000040021c 0x000000000040021c - 0x0000000000000020 0x0000000000000020 R 4 - GNU_EH_FRAME 0x00000000000005b0 0x00000000004005b0 0x00000000004005b0 - 0x0000000000000024 0x0000000000000024 R 4 - GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000 - 0x0000000000000000 0x0000000000000000 RW 8 - - Section to Segment mapping: - Segment Sections... - 00 - 01 .interp - 02 .interp .note.ABI-tag .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .text .fini .rodata .eh_frame_hdr .eh_frame - 03 .ctors .dtors .jcr .dynamic .got .got.plt .data .bss - 04 .dynamic - 05 .note.ABI-tag - 06 .eh_frame_hdr - 07 - -Dynamic section at offset 0x698 contains 20 entries: - Tag Type Name/Value - 0x0000000000000001 (NEEDED) Shared library: [libc.so.6] - 0x000000000000000c (INIT) 0x400370 - 0x000000000000000d (FINI) 0x400588 - 0x000000006ffffef5 (GNU_HASH) 0x400240 - 0x0000000000000005 (STRTAB) 0x4002c0 - 0x0000000000000006 (SYMTAB) 0x400260 - 0x000000000000000a (STRSZ) 61 (bytes) - 0x000000000000000b (SYMENT) 24 (bytes) - 0x0000000000000015 (DEBUG) 0x0 - 0x0000000000000003 (PLTGOT) 0x600830 - 0x0000000000000002 (PLTRELSZ) 48 (bytes) - 0x0000000000000014 (PLTREL) RELA - 0x0000000000000017 (JMPREL) 0x400340 - 0x0000000000000007 (RELA) 0x400328 - 0x0000000000000008 (RELASZ) 24 (bytes) - 0x0000000000000009 (RELAENT) 24 (bytes) - 0x000000006ffffffe (VERNEED) 0x400308 - 0x000000006fffffff (VERNEEDNUM) 1 - 0x000000006ffffff0 (VERSYM) 0x4002fe - 0x0000000000000000 (NULL) 0x0 - -Relocation section '.rela.dyn' at offset 0x328 contains 1 entries: - Offset Info Type Sym. Value Sym. Name + Addend -000000600828 000100000006 R_X86_64_GLOB_DAT 0000000000000000 __gmon_start__ + 0 - -Relocation section '.rela.plt' at offset 0x340 contains 2 entries: - Offset Info Type Sym. Value Sym. Name + Addend -000000600848 000200000007 R_X86_64_JUMP_SLO 0000000000000000 puts + 0 -000000600850 000300000007 R_X86_64_JUMP_SLO 0000000000000000 __libc_start_main + 0 - -There are no unwind sections in this file. - -Symbol table '.dynsym' contains 4 entries: - Num: Value Size Type Bind Vis Ndx Name - 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND - 1: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ - 2: 0000000000000000 396 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.2.5 (2) - 3: 0000000000000000 421 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.2.5 (2) - -Symbol table '.symtab' contains 67 entries: - Num: Value Size Type Bind Vis Ndx Name - 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND - 1: 0000000000400200 0 SECTION LOCAL DEFAULT 1 - 2: 000000000040021c 0 SECTION LOCAL DEFAULT 2 - 3: 0000000000400240 0 SECTION LOCAL DEFAULT 3 - 4: 0000000000400260 0 SECTION LOCAL DEFAULT 4 - 5: 00000000004002c0 0 SECTION LOCAL DEFAULT 5 - 6: 00000000004002fe 0 SECTION LOCAL DEFAULT 6 - 7: 0000000000400308 0 SECTION LOCAL DEFAULT 7 - 8: 0000000000400328 0 SECTION LOCAL DEFAULT 8 - 9: 0000000000400340 0 SECTION LOCAL DEFAULT 9 - 10: 0000000000400370 0 SECTION LOCAL DEFAULT 10 - 11: 0000000000400388 0 SECTION LOCAL DEFAULT 11 - 12: 00000000004003c0 0 SECTION LOCAL DEFAULT 12 - 13: 0000000000400588 0 SECTION LOCAL DEFAULT 13 - 14: 0000000000400598 0 SECTION LOCAL DEFAULT 14 - 15: 00000000004005b0 0 SECTION LOCAL DEFAULT 15 - 16: 00000000004005d8 0 SECTION LOCAL DEFAULT 16 - 17: 0000000000600670 0 SECTION LOCAL DEFAULT 17 - 18: 0000000000600680 0 SECTION LOCAL DEFAULT 18 - 19: 0000000000600690 0 SECTION LOCAL DEFAULT 19 - 20: 0000000000600698 0 SECTION LOCAL DEFAULT 20 - 21: 0000000000600828 0 SECTION LOCAL DEFAULT 21 - 22: 0000000000600830 0 SECTION LOCAL DEFAULT 22 - 23: 0000000000600858 0 SECTION LOCAL DEFAULT 23 - 24: 0000000000600860 0 SECTION LOCAL DEFAULT 24 - 25: 0000000000000000 0 SECTION LOCAL DEFAULT 25 - 26: 00000000004003ec 0 FUNC LOCAL DEFAULT 12 call_gmon_start - 27: 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c - 28: 0000000000600670 0 OBJECT LOCAL DEFAULT 17 __CTOR_LIST__ - 29: 0000000000600680 0 OBJECT LOCAL DEFAULT 18 __DTOR_LIST__ - 30: 0000000000600690 0 OBJECT LOCAL DEFAULT 19 __JCR_LIST__ - 31: 0000000000600860 8 OBJECT LOCAL DEFAULT 24 dtor_idx.6147 - 32: 0000000000600868 1 OBJECT LOCAL DEFAULT 24 completed.6145 - 33: 0000000000400410 0 FUNC LOCAL DEFAULT 12 __do_global_dtors_aux - 34: 0000000000400470 0 FUNC LOCAL DEFAULT 12 frame_dummy - 35: 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c - 36: 0000000000600678 0 OBJECT LOCAL DEFAULT 17 __CTOR_END__ - 37: 0000000000400668 0 OBJECT LOCAL DEFAULT 16 __FRAME_END__ - 38: 0000000000600690 0 OBJECT LOCAL DEFAULT 19 __JCR_END__ - 39: 0000000000400550 0 FUNC LOCAL DEFAULT 12 __do_global_ctors_aux - 40: 0000000000000000 0 FILE LOCAL DEFAULT ABS hello.c - 41: 000000000060066c 0 NOTYPE LOCAL HIDDEN 17 __preinit_array_start - 42: 000000000060066c 0 NOTYPE LOCAL HIDDEN 17 __fini_array_end - 43: 0000000000600830 0 OBJECT LOCAL HIDDEN 22 _GLOBAL_OFFSET_TABLE_ - 44: 000000000060066c 0 NOTYPE LOCAL HIDDEN 17 __preinit_array_end - 45: 000000000060066c 0 NOTYPE LOCAL HIDDEN 17 __fini_array_start - 46: 000000000060066c 0 NOTYPE LOCAL HIDDEN 17 __init_array_end - 47: 000000000060066c 0 NOTYPE LOCAL HIDDEN 17 __init_array_start - 48: 0000000000600698 0 OBJECT LOCAL HIDDEN 20 _DYNAMIC - 49: 0000000000600858 0 NOTYPE WEAK DEFAULT 23 data_start - 50: 00000000004004b0 2 FUNC GLOBAL DEFAULT 12 __libc_csu_fini - 51: 00000000004003c0 0 FUNC GLOBAL DEFAULT 12 _start - 52: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ - 53: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses - 54: 0000000000000000 396 FUNC GLOBAL DEFAULT UND puts@@GLIBC_2.2.5 - 55: 0000000000400588 0 FUNC GLOBAL DEFAULT 13 _fini - 56: 0000000000000000 421 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_ - 57: 0000000000400598 4 OBJECT GLOBAL DEFAULT 14 _IO_stdin_used - 58: 0000000000600858 0 NOTYPE GLOBAL DEFAULT 23 __data_start - 59: 00000000004005a0 0 OBJECT GLOBAL HIDDEN 14 __dso_handle - 60: 0000000000600688 0 OBJECT GLOBAL HIDDEN 18 __DTOR_END__ - 61: 00000000004004c0 139 FUNC GLOBAL DEFAULT 12 __libc_csu_init - 62: 000000000060085c 0 NOTYPE GLOBAL DEFAULT ABS __bss_start - 63: 0000000000600870 0 NOTYPE GLOBAL DEFAULT ABS _end - 64: 000000000060085c 0 NOTYPE GLOBAL DEFAULT ABS _edata - 65: 0000000000400498 21 FUNC GLOBAL DEFAULT 12 main - 66: 0000000000400370 0 FUNC GLOBAL DEFAULT 10 _init - -Version symbols section '.gnu.version' contains 4 entries: - Addr: 00000000004002fe Offset: 0x0002fe Link: 4 (.dynsym) - 000: 0 (*local*) 0 (*local*) 2 (GLIBC_2.2.5) 2 (GLIBC_2.2.5) - -Version needs section '.gnu.version_r' contains 1 entries: - Addr: 0x0000000000400308 Offset: 0x000308 Link to section: 5 (.dynstr) - 000000: Version: 1 File: libc.so.6 Cnt: 1 - 0x0010: Name: GLIBC_2.2.5 Flags: none Version: 2 - -Notes at offset 0x0000021c with length 0x00000020: - Owner Data size Description - GNU 0x00000010 NT_VERSION (version) +ELF Header: + Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 + Class: ELF64 + Data: 2's complement, little endian + Version: 1 (current) + OS/ABI: UNIX - System V + ABI Version: 0 + Type: EXEC (Executable file) + Machine: Advanced Micro Devices X86-64 + Version: 0x1 + Entry point address: 0x4003c0 + Start of program headers: 64 (bytes into file) + Start of section headers: 2656 (bytes into file) + Flags: 0x0 + Size of this header: 64 (bytes) + Size of program headers: 56 (bytes) + Number of program headers: 8 + Size of section headers: 64 (bytes) + Number of section headers: 29 + Section header string table index: 26 + +Section Headers: + [Nr] Name Type Address Offset + Size EntSize Flags Link Info Align + [ 0] NULL 0000000000000000 00000000 + 0000000000000000 0000000000000000 0 0 0 + [ 1] .interp PROGBITS 0000000000400200 00000200 + 000000000000001c 0000000000000000 A 0 0 1 + [ 2] .note.ABI-tag NOTE 000000000040021c 0000021c + 0000000000000020 0000000000000000 A 0 0 4 + [ 3] .gnu.hash GNU_HASH 0000000000400240 00000240 + 000000000000001c 0000000000000000 A 4 0 8 + [ 4] .dynsym DYNSYM 0000000000400260 00000260 + 0000000000000060 0000000000000018 A 5 1 8 + [ 5] .dynstr STRTAB 00000000004002c0 000002c0 + 000000000000003d 0000000000000000 A 0 0 1 + [ 6] .gnu.version VERSYM 00000000004002fe 000002fe + 0000000000000008 0000000000000002 A 4 0 2 + [ 7] .gnu.version_r VERNEED 0000000000400308 00000308 + 0000000000000020 0000000000000000 A 5 1 8 + [ 8] .rela.dyn RELA 0000000000400328 00000328 + 0000000000000018 0000000000000018 A 4 0 8 + [ 9] .rela.plt RELA 0000000000400340 00000340 + 0000000000000030 0000000000000018 A 4 11 8 + [10] .init PROGBITS 0000000000400370 00000370 + 0000000000000018 0000000000000000 AX 0 0 4 + [11] .plt PROGBITS 0000000000400388 00000388 + 0000000000000030 0000000000000010 AX 0 0 4 + [12] .text PROGBITS 00000000004003c0 000003c0 + 00000000000001c8 0000000000000000 AX 0 0 16 + [13] .fini PROGBITS 0000000000400588 00000588 + 000000000000000e 0000000000000000 AX 0 0 4 + [14] .rodata PROGBITS 0000000000400598 00000598 + 0000000000000016 0000000000000000 A 0 0 8 + [15] .eh_frame_hdr PROGBITS 00000000004005b0 000005b0 + 0000000000000024 0000000000000000 A 0 0 4 + [16] .eh_frame PROGBITS 00000000004005d8 000005d8 + 0000000000000094 0000000000000000 A 0 0 8 + [17] .ctors PROGBITS 0000000000600670 00000670 + 0000000000000010 0000000000000000 WA 0 0 8 + [18] .dtors PROGBITS 0000000000600680 00000680 + 0000000000000010 0000000000000000 WA 0 0 8 + [19] .jcr PROGBITS 0000000000600690 00000690 + 0000000000000008 0000000000000000 WA 0 0 8 + [20] .dynamic DYNAMIC 0000000000600698 00000698 + 0000000000000190 0000000000000010 WA 5 0 8 + [21] .got PROGBITS 0000000000600828 00000828 + 0000000000000008 0000000000000008 WA 0 0 8 + [22] .got.plt PROGBITS 0000000000600830 00000830 + 0000000000000028 0000000000000008 WA 0 0 8 + [23] .data PROGBITS 0000000000600858 00000858 + 0000000000000004 0000000000000000 WA 0 0 4 + [24] .bss NOBITS 0000000000600860 0000085c + 0000000000000010 0000000000000000 WA 0 0 8 + [25] .comment PROGBITS 0000000000000000 0000085c + 0000000000000114 0000000000000000 0 0 1 + [26] .shstrtab STRTAB 0000000000000000 00000970 + 00000000000000eb 0000000000000000 0 0 1 + [27] .symtab SYMTAB 0000000000000000 000011a0 + 0000000000000648 0000000000000018 28 49 8 + [28] .strtab STRTAB 0000000000000000 000017e8 + 000000000000023f 0000000000000000 0 0 1 +Key to Flags: + W (write), A (alloc), X (execute), M (merge), S (strings) + I (info), L (link order), G (group), x (unknown) + O (extra OS processing required) o (OS specific), p (processor specific) + +There are no section groups in this file. + +Program Headers: + Type Offset VirtAddr PhysAddr + FileSiz MemSiz Flags Align + PHDR 0x0000000000000040 0x0000000000400040 0x0000000000400040 + 0x00000000000001c0 0x00000000000001c0 R E 8 + INTERP 0x0000000000000200 0x0000000000400200 0x0000000000400200 + 0x000000000000001c 0x000000000000001c R 1 + [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2] + LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000 + 0x000000000000066c 0x000000000000066c R E 200000 + LOAD 0x0000000000000670 0x0000000000600670 0x0000000000600670 + 0x00000000000001ec 0x0000000000000200 RW 200000 + DYNAMIC 0x0000000000000698 0x0000000000600698 0x0000000000600698 + 0x0000000000000190 0x0000000000000190 RW 8 + NOTE 0x000000000000021c 0x000000000040021c 0x000000000040021c + 0x0000000000000020 0x0000000000000020 R 4 + GNU_EH_FRAME 0x00000000000005b0 0x00000000004005b0 0x00000000004005b0 + 0x0000000000000024 0x0000000000000024 R 4 + GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000 + 0x0000000000000000 0x0000000000000000 RW 8 + + Section to Segment mapping: + Segment Sections... + 00 + 01 .interp + 02 .interp .note.ABI-tag .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .text .fini .rodata .eh_frame_hdr .eh_frame + 03 .ctors .dtors .jcr .dynamic .got .got.plt .data .bss + 04 .dynamic + 05 .note.ABI-tag + 06 .eh_frame_hdr + 07 + +Dynamic section at offset 0x698 contains 20 entries: + Tag Type Name/Value + 0x0000000000000001 (NEEDED) Shared library: [libc.so.6] + 0x000000000000000c (INIT) 0x400370 + 0x000000000000000d (FINI) 0x400588 + 0x000000006ffffef5 (GNU_HASH) 0x400240 + 0x0000000000000005 (STRTAB) 0x4002c0 + 0x0000000000000006 (SYMTAB) 0x400260 + 0x000000000000000a (STRSZ) 61 (bytes) + 0x000000000000000b (SYMENT) 24 (bytes) + 0x0000000000000015 (DEBUG) 0x0 + 0x0000000000000003 (PLTGOT) 0x600830 + 0x0000000000000002 (PLTRELSZ) 48 (bytes) + 0x0000000000000014 (PLTREL) RELA + 0x0000000000000017 (JMPREL) 0x400340 + 0x0000000000000007 (RELA) 0x400328 + 0x0000000000000008 (RELASZ) 24 (bytes) + 0x0000000000000009 (RELAENT) 24 (bytes) + 0x000000006ffffffe (VERNEED) 0x400308 + 0x000000006fffffff (VERNEEDNUM) 1 + 0x000000006ffffff0 (VERSYM) 0x4002fe + 0x0000000000000000 (NULL) 0x0 + +Relocation section '.rela.dyn' at offset 0x328 contains 1 entries: + Offset Info Type Sym. Value Sym. Name + Addend +000000600828 000100000006 R_X86_64_GLOB_DAT 0000000000000000 __gmon_start__ + 0 + +Relocation section '.rela.plt' at offset 0x340 contains 2 entries: + Offset Info Type Sym. Value Sym. Name + Addend +000000600848 000200000007 R_X86_64_JUMP_SLO 0000000000000000 puts + 0 +000000600850 000300000007 R_X86_64_JUMP_SLO 0000000000000000 __libc_start_main + 0 + +There are no unwind sections in this file. + +Symbol table '.dynsym' contains 4 entries: + Num: Value Size Type Bind Vis Ndx Name + 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND + 1: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ + 2: 0000000000000000 396 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.2.5 (2) + 3: 0000000000000000 421 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.2.5 (2) + +Symbol table '.symtab' contains 67 entries: + Num: Value Size Type Bind Vis Ndx Name + 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND + 1: 0000000000400200 0 SECTION LOCAL DEFAULT 1 + 2: 000000000040021c 0 SECTION LOCAL DEFAULT 2 + 3: 0000000000400240 0 SECTION LOCAL DEFAULT 3 + 4: 0000000000400260 0 SECTION LOCAL DEFAULT 4 + 5: 00000000004002c0 0 SECTION LOCAL DEFAULT 5 + 6: 00000000004002fe 0 SECTION LOCAL DEFAULT 6 + 7: 0000000000400308 0 SECTION LOCAL DEFAULT 7 + 8: 0000000000400328 0 SECTION LOCAL DEFAULT 8 + 9: 0000000000400340 0 SECTION LOCAL DEFAULT 9 + 10: 0000000000400370 0 SECTION LOCAL DEFAULT 10 + 11: 0000000000400388 0 SECTION LOCAL DEFAULT 11 + 12: 00000000004003c0 0 SECTION LOCAL DEFAULT 12 + 13: 0000000000400588 0 SECTION LOCAL DEFAULT 13 + 14: 0000000000400598 0 SECTION LOCAL DEFAULT 14 + 15: 00000000004005b0 0 SECTION LOCAL DEFAULT 15 + 16: 00000000004005d8 0 SECTION LOCAL DEFAULT 16 + 17: 0000000000600670 0 SECTION LOCAL DEFAULT 17 + 18: 0000000000600680 0 SECTION LOCAL DEFAULT 18 + 19: 0000000000600690 0 SECTION LOCAL DEFAULT 19 + 20: 0000000000600698 0 SECTION LOCAL DEFAULT 20 + 21: 0000000000600828 0 SECTION LOCAL DEFAULT 21 + 22: 0000000000600830 0 SECTION LOCAL DEFAULT 22 + 23: 0000000000600858 0 SECTION LOCAL DEFAULT 23 + 24: 0000000000600860 0 SECTION LOCAL DEFAULT 24 + 25: 0000000000000000 0 SECTION LOCAL DEFAULT 25 + 26: 00000000004003ec 0 FUNC LOCAL DEFAULT 12 call_gmon_start + 27: 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c + 28: 0000000000600670 0 OBJECT LOCAL DEFAULT 17 __CTOR_LIST__ + 29: 0000000000600680 0 OBJECT LOCAL DEFAULT 18 __DTOR_LIST__ + 30: 0000000000600690 0 OBJECT LOCAL DEFAULT 19 __JCR_LIST__ + 31: 0000000000600860 8 OBJECT LOCAL DEFAULT 24 dtor_idx.6147 + 32: 0000000000600868 1 OBJECT LOCAL DEFAULT 24 completed.6145 + 33: 0000000000400410 0 FUNC LOCAL DEFAULT 12 __do_global_dtors_aux + 34: 0000000000400470 0 FUNC LOCAL DEFAULT 12 frame_dummy + 35: 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c + 36: 0000000000600678 0 OBJECT LOCAL DEFAULT 17 __CTOR_END__ + 37: 0000000000400668 0 OBJECT LOCAL DEFAULT 16 __FRAME_END__ + 38: 0000000000600690 0 OBJECT LOCAL DEFAULT 19 __JCR_END__ + 39: 0000000000400550 0 FUNC LOCAL DEFAULT 12 __do_global_ctors_aux + 40: 0000000000000000 0 FILE LOCAL DEFAULT ABS hello.c + 41: 000000000060066c 0 NOTYPE LOCAL HIDDEN 17 __preinit_array_start + 42: 000000000060066c 0 NOTYPE LOCAL HIDDEN 17 __fini_array_end + 43: 0000000000600830 0 OBJECT LOCAL HIDDEN 22 _GLOBAL_OFFSET_TABLE_ + 44: 000000000060066c 0 NOTYPE LOCAL HIDDEN 17 __preinit_array_end + 45: 000000000060066c 0 NOTYPE LOCAL HIDDEN 17 __fini_array_start + 46: 000000000060066c 0 NOTYPE LOCAL HIDDEN 17 __init_array_end + 47: 000000000060066c 0 NOTYPE LOCAL HIDDEN 17 __init_array_start + 48: 0000000000600698 0 OBJECT LOCAL HIDDEN 20 _DYNAMIC + 49: 0000000000600858 0 NOTYPE WEAK DEFAULT 23 data_start + 50: 00000000004004b0 2 FUNC GLOBAL DEFAULT 12 __libc_csu_fini + 51: 00000000004003c0 0 FUNC GLOBAL DEFAULT 12 _start + 52: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ + 53: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses + 54: 0000000000000000 396 FUNC GLOBAL DEFAULT UND puts@@GLIBC_2.2.5 + 55: 0000000000400588 0 FUNC GLOBAL DEFAULT 13 _fini + 56: 0000000000000000 421 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_ + 57: 0000000000400598 4 OBJECT GLOBAL DEFAULT 14 _IO_stdin_used + 58: 0000000000600858 0 NOTYPE GLOBAL DEFAULT 23 __data_start + 59: 00000000004005a0 0 OBJECT GLOBAL HIDDEN 14 __dso_handle + 60: 0000000000600688 0 OBJECT GLOBAL HIDDEN 18 __DTOR_END__ + 61: 00000000004004c0 139 FUNC GLOBAL DEFAULT 12 __libc_csu_init + 62: 000000000060085c 0 NOTYPE GLOBAL DEFAULT ABS __bss_start + 63: 0000000000600870 0 NOTYPE GLOBAL DEFAULT ABS _end + 64: 000000000060085c 0 NOTYPE GLOBAL DEFAULT ABS _edata + 65: 0000000000400498 21 FUNC GLOBAL DEFAULT 12 main + 66: 0000000000400370 0 FUNC GLOBAL DEFAULT 10 _init + +Version symbols section '.gnu.version' contains 4 entries: + Addr: 00000000004002fe Offset: 0x0002fe Link: 4 (.dynsym) + 000: 0 (*local*) 0 (*local*) 2 (GLIBC_2.2.5) 2 (GLIBC_2.2.5) + +Version needs section '.gnu.version_r' contains 1 entries: + Addr: 0x0000000000400308 Offset: 0x000308 Link to section: 5 (.dynstr) + 000000: Version: 1 File: libc.so.6 Cnt: 1 + 0x0010: Name: GLIBC_2.2.5 Flags: none Version: 2 + +Notes at offset 0x0000021c with length 0x00000020: + Owner Data size Description + GNU 0x00000010 NT_VERSION (version) diff --git a/elf_examples/hello_64_o.txt b/elf_examples/hello_64_o.txt index fd363a507be426ba24db6f5407830c885315f17f..4dfda23260d96f2255fc18b79f29514c6dfde896 100644 --- a/elf_examples/hello_64_o.txt +++ b/elf_examples/hello_64_o.txt @@ -1,85 +1,85 @@ -ELF Header: - Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 - Class: ELF64 - Data: 2's complement, little endian - Version: 1 (current) - OS/ABI: UNIX - System V - ABI Version: 0 - Type: REL (Relocatable file) - Machine: Advanced Micro Devices X86-64 - Version: 0x1 - Entry point address: 0x0 - Start of program headers: 0 (bytes into file) - Start of section headers: 296 (bytes into file) - Flags: 0x0 - Size of this header: 64 (bytes) - Size of program headers: 0 (bytes) - Number of program headers: 0 - Size of section headers: 64 (bytes) - Number of section headers: 13 - Section header string table index: 10 - -Section Headers: - [Nr] Name Type Address Offset - Size EntSize Flags Link Info Align - [ 0] NULL 0000000000000000 00000000 - 0000000000000000 0000000000000000 0 0 0 - [ 1] .text PROGBITS 0000000000000000 00000040 - 0000000000000015 0000000000000000 AX 0 0 4 - [ 2] .rela.text RELA 0000000000000000 00000588 - 0000000000000030 0000000000000018 11 1 8 - [ 3] .data PROGBITS 0000000000000000 00000058 - 0000000000000000 0000000000000000 WA 0 0 4 - [ 4] .bss NOBITS 0000000000000000 00000058 - 0000000000000000 0000000000000000 WA 0 0 4 - [ 5] .rodata PROGBITS 0000000000000000 00000058 - 0000000000000006 0000000000000000 A 0 0 1 - [ 6] .eh_frame PROGBITS 0000000000000000 00000060 - 0000000000000038 0000000000000000 A 0 0 8 - [ 7] .rela.eh_frame RELA 0000000000000000 000005b8 - 0000000000000018 0000000000000018 11 6 8 - [ 8] .comment PROGBITS 0000000000000000 00000098 - 000000000000002e 0000000000000000 0 0 1 - [ 9] .note.GNU-stack PROGBITS 0000000000000000 000000c6 - 0000000000000000 0000000000000000 0 0 1 - [10] .shstrtab STRTAB 0000000000000000 000000c6 - 0000000000000061 0000000000000000 0 0 1 - [11] .symtab SYMTAB 0000000000000000 00000468 - 0000000000000108 0000000000000018 12 9 8 - [12] .strtab STRTAB 0000000000000000 00000570 - 0000000000000013 0000000000000000 0 0 1 -Key to Flags: - W (write), A (alloc), X (execute), M (merge), S (strings) - I (info), L (link order), G (group), x (unknown) - O (extra OS processing required) o (OS specific), p (processor specific) - -There are no section groups in this file. - -There are no program headers in this file. - -Relocation section '.rela.text' at offset 0x588 contains 2 entries: - Offset Info Type Sym. Value Sym. Name + Addend -000000000005 00050000000a R_X86_64_32 0000000000000000 .rodata + 0 -00000000000a 000a00000002 R_X86_64_PC32 0000000000000000 puts + fffffffffffffffc - -Relocation section '.rela.eh_frame' at offset 0x5b8 contains 1 entries: - Offset Info Type Sym. Value Sym. Name + Addend -000000000020 00020000000a R_X86_64_32 0000000000000000 .text + 0 - -There are no unwind sections in this file. - -Symbol table '.symtab' contains 11 entries: - Num: Value Size Type Bind Vis Ndx Name - 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND - 1: 0000000000000000 0 FILE LOCAL DEFAULT ABS hello.c - 2: 0000000000000000 0 SECTION LOCAL DEFAULT 1 - 3: 0000000000000000 0 SECTION LOCAL DEFAULT 3 - 4: 0000000000000000 0 SECTION LOCAL DEFAULT 4 - 5: 0000000000000000 0 SECTION LOCAL DEFAULT 5 - 6: 0000000000000000 0 SECTION LOCAL DEFAULT 6 - 7: 0000000000000000 0 SECTION LOCAL DEFAULT 9 - 8: 0000000000000000 0 SECTION LOCAL DEFAULT 8 - 9: 0000000000000000 21 FUNC GLOBAL DEFAULT 1 main - 10: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND puts - -No version information found in this file. +ELF Header: + Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 + Class: ELF64 + Data: 2's complement, little endian + Version: 1 (current) + OS/ABI: UNIX - System V + ABI Version: 0 + Type: REL (Relocatable file) + Machine: Advanced Micro Devices X86-64 + Version: 0x1 + Entry point address: 0x0 + Start of program headers: 0 (bytes into file) + Start of section headers: 296 (bytes into file) + Flags: 0x0 + Size of this header: 64 (bytes) + Size of program headers: 0 (bytes) + Number of program headers: 0 + Size of section headers: 64 (bytes) + Number of section headers: 13 + Section header string table index: 10 + +Section Headers: + [Nr] Name Type Address Offset + Size EntSize Flags Link Info Align + [ 0] NULL 0000000000000000 00000000 + 0000000000000000 0000000000000000 0 0 0 + [ 1] .text PROGBITS 0000000000000000 00000040 + 0000000000000015 0000000000000000 AX 0 0 4 + [ 2] .rela.text RELA 0000000000000000 00000588 + 0000000000000030 0000000000000018 11 1 8 + [ 3] .data PROGBITS 0000000000000000 00000058 + 0000000000000000 0000000000000000 WA 0 0 4 + [ 4] .bss NOBITS 0000000000000000 00000058 + 0000000000000000 0000000000000000 WA 0 0 4 + [ 5] .rodata PROGBITS 0000000000000000 00000058 + 0000000000000006 0000000000000000 A 0 0 1 + [ 6] .eh_frame PROGBITS 0000000000000000 00000060 + 0000000000000038 0000000000000000 A 0 0 8 + [ 7] .rela.eh_frame RELA 0000000000000000 000005b8 + 0000000000000018 0000000000000018 11 6 8 + [ 8] .comment PROGBITS 0000000000000000 00000098 + 000000000000002e 0000000000000000 0 0 1 + [ 9] .note.GNU-stack PROGBITS 0000000000000000 000000c6 + 0000000000000000 0000000000000000 0 0 1 + [10] .shstrtab STRTAB 0000000000000000 000000c6 + 0000000000000061 0000000000000000 0 0 1 + [11] .symtab SYMTAB 0000000000000000 00000468 + 0000000000000108 0000000000000018 12 9 8 + [12] .strtab STRTAB 0000000000000000 00000570 + 0000000000000013 0000000000000000 0 0 1 +Key to Flags: + W (write), A (alloc), X (execute), M (merge), S (strings) + I (info), L (link order), G (group), x (unknown) + O (extra OS processing required) o (OS specific), p (processor specific) + +There are no section groups in this file. + +There are no program headers in this file. + +Relocation section '.rela.text' at offset 0x588 contains 2 entries: + Offset Info Type Sym. Value Sym. Name + Addend +000000000005 00050000000a R_X86_64_32 0000000000000000 .rodata + 0 +00000000000a 000a00000002 R_X86_64_PC32 0000000000000000 puts + fffffffffffffffc + +Relocation section '.rela.eh_frame' at offset 0x5b8 contains 1 entries: + Offset Info Type Sym. Value Sym. Name + Addend +000000000020 00020000000a R_X86_64_32 0000000000000000 .text + 0 + +There are no unwind sections in this file. + +Symbol table '.symtab' contains 11 entries: + Num: Value Size Type Bind Vis Ndx Name + 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND + 1: 0000000000000000 0 FILE LOCAL DEFAULT ABS hello.c + 2: 0000000000000000 0 SECTION LOCAL DEFAULT 1 + 3: 0000000000000000 0 SECTION LOCAL DEFAULT 3 + 4: 0000000000000000 0 SECTION LOCAL DEFAULT 4 + 5: 0000000000000000 0 SECTION LOCAL DEFAULT 5 + 6: 0000000000000000 0 SECTION LOCAL DEFAULT 6 + 7: 0000000000000000 0 SECTION LOCAL DEFAULT 9 + 8: 0000000000000000 0 SECTION LOCAL DEFAULT 8 + 9: 0000000000000000 21 FUNC GLOBAL DEFAULT 1 main + 10: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND puts + +No version information found in this file. diff --git a/elf_examples/test_ppc.cpp b/elf_examples/test_ppc.cpp index dbc754277a166578f9d754200c42d8429717b409..d07f900f21ded103bf054cd54e48a5577dae5f2b 100644 --- a/elf_examples/test_ppc.cpp +++ b/elf_examples/test_ppc.cpp @@ -1,8 +1,8 @@ -#include <iostream> - -int main() -{ - std::cout << "Hello" << std::endl; - - return 0; -} +#include <iostream> + +int main() +{ + std::cout << "Hello" << std::endl; + + return 0; +} diff --git a/elf_examples/test_ppc.txt b/elf_examples/test_ppc.txt index 93a3a941b12c5646c9356c314660e121c388d568..3a088117a9578a8a92d01474b21f92a767011bfd 100644 --- a/elf_examples/test_ppc.txt +++ b/elf_examples/test_ppc.txt @@ -1,263 +1,263 @@ -ELF Header: - Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00 - Class: ELF32 - Data: 2's complement, big endian - Version: 1 (current) - OS/ABI: UNIX - System V - ABI Version: 0 - Type: EXEC (Executable file) - Machine: PowerPC - Version: 0x1 - Entry point address: 0x10000550 - Start of program headers: 52 (bytes into file) - Start of section headers: 3484 (bytes into file) - Flags: 0x0 - Size of this header: 52 (bytes) - Size of program headers: 32 (bytes) - Number of program headers: 8 - Size of section headers: 40 (bytes) - Number of section headers: 31 - Section header string table index: 28 - -Section Headers: - [Nr] Name Type Addr Off Size ES Flg Lk Inf Al - [ 0] NULL 00000000 000000 000000 00 0 0 0 - [ 1] .interp PROGBITS 10000134 000134 00000d 00 A 0 0 1 - [ 2] .note.ABI-tag NOTE 10000144 000144 000020 00 A 0 0 4 - [ 3] .hash HASH 10000164 000164 000048 04 A 4 0 4 - [ 4] .dynsym DYNSYM 100001ac 0001ac 0000d0 10 A 5 1 4 - [ 5] .dynstr STRTAB 1000027c 00027c 000183 00 A 0 0 1 - [ 6] .gnu.version VERSYM 10000400 000400 00001a 02 A 4 0 2 - [ 7] .gnu.version_r VERNEED 1000041c 00041c 000060 00 A 5 2 4 - [ 8] .rela.dyn RELA 1000047c 00047c 000018 0c A 4 0 4 - [ 9] .rela.plt RELA 10000494 000494 00006c 0c A 4 22 4 - [10] .init PROGBITS 10000500 000500 00004c 00 AX 0 0 4 - [11] .text PROGBITS 10000550 000550 000480 00 AX 0 0 16 - [12] .fini PROGBITS 100009d0 0009d0 000038 00 AX 0 0 4 - [13] .rodata PROGBITS 10000a08 000a08 00001a 00 A 0 0 4 - [14] .eh_frame_hdr PROGBITS 10000a24 000a24 000024 00 A 0 0 4 - [15] .eh_frame PROGBITS 10000a48 000a48 000084 00 A 0 0 4 - [16] .ctors PROGBITS 10010acc 000acc 00000c 00 WA 0 0 4 - [17] .dtors PROGBITS 10010ad8 000ad8 000008 00 WA 0 0 4 - [18] .jcr PROGBITS 10010ae0 000ae0 000004 00 WA 0 0 4 - [19] .got2 PROGBITS 10010ae4 000ae4 000008 00 WA 0 0 1 - [20] .dynamic DYNAMIC 10010aec 000aec 0000e8 08 WA 5 0 4 - [21] .got PROGBITS 10010bd4 000bd4 000010 04 WA 0 0 4 - [22] .plt PROGBITS 10010be4 000be4 000024 00 WA 0 0 4 - [23] .data PROGBITS 10010c08 000c08 000004 00 WA 0 0 4 - [24] .bss NOBITS 10010c0c 000c0c 000098 00 WA 0 0 4 - [25] .comment PROGBITS 00000000 000c0c 000027 00 0 0 1 - [26] .debug_frame PROGBITS 00000000 000c34 000050 00 0 0 4 - [27] .gnu.attributes LOOS+ffffff5 00000000 000c84 000014 00 0 0 1 - [28] .shstrtab STRTAB 00000000 000c98 000101 00 0 0 1 - [29] .symtab SYMTAB 00000000 001274 000500 10 30 54 4 - [30] .strtab STRTAB 00000000 001774 0003cc 00 0 0 1 -Key to Flags: - W (write), A (alloc), X (execute), M (merge), S (strings) - I (info), L (link order), G (group), x (unknown) - O (extra OS processing required) o (OS specific), p (processor specific) - -There are no section groups in this file. - -Program Headers: - Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align - PHDR 0x000034 0x10000034 0x10000034 0x00100 0x00100 R E 0x4 - INTERP 0x000134 0x10000134 0x10000134 0x0000d 0x0000d R 0x1 - [Requesting program interpreter: /lib/ld.so.1] - LOAD 0x000000 0x10000000 0x10000000 0x00acc 0x00acc R E 0x10000 - LOAD 0x000acc 0x10010acc 0x10010acc 0x00140 0x001d8 RW 0x10000 - DYNAMIC 0x000aec 0x10010aec 0x10010aec 0x000e8 0x000e8 RW 0x4 - NOTE 0x000144 0x10000144 0x10000144 0x00020 0x00020 R 0x4 - GNU_EH_FRAME 0x000a24 0x10000a24 0x10000a24 0x00024 0x00024 R 0x4 - GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4 - - Section to Segment mapping: - Segment Sections... - 00 - 01 .interp - 02 .interp .note.ABI-tag .hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .text .fini .rodata .eh_frame_hdr .eh_frame - 03 .ctors .dtors .jcr .got2 .dynamic .got .plt .data .bss - 04 .dynamic - 05 .note.ABI-tag - 06 .eh_frame_hdr - 07 - -Dynamic section at offset 0xaec contains 24 entries: - Tag Type Name/Value - 0x00000001 (NEEDED) Shared library: [libstdc++.so.6] - 0x00000001 (NEEDED) Shared library: [libm.so.6] - 0x00000001 (NEEDED) Shared library: [libgcc_s.so.1] - 0x00000001 (NEEDED) Shared library: [libc.so.6] - 0x0000000c (INIT) 0x10000500 - 0x0000000d (FINI) 0x100009d0 - 0x00000004 (HASH) 0x10000164 - 0x00000005 (STRTAB) 0x1000027c - 0x00000006 (SYMTAB) 0x100001ac - 0x0000000a (STRSZ) 387 (bytes) - 0x0000000b (SYMENT) 16 (bytes) - 0x00000015 (DEBUG) 0x0 - 0x00000003 (PLTGOT) 0x10010be4 - 0x00000002 (PLTRELSZ) 108 (bytes) - 0x00000014 (PLTREL) RELA - 0x00000017 (JMPREL) 0x10000494 - 0x70000000 (PPC_GOT) 0x10010bd8 - 0x00000007 (RELA) 0x1000047c - 0x00000008 (RELASZ) 132 (bytes) - 0x00000009 (RELAENT) 12 (bytes) - 0x6ffffffe (VERNEED) 0x1000041c - 0x6fffffff (VERNEEDNUM) 2 - 0x6ffffff0 (VERSYM) 0x10000400 - 0x00000000 (NULL) 0x0 - -Relocation section '.rela.dyn' at offset 0x47c contains 2 entries: - Offset Info Type Sym.Value Sym. Name + Addend -10010bd4 00000214 R_PPC_GLOB_DAT 00000000 __gmon_start__ + 0 -10010c0c 00000913 R_PPC_COPY 10010c0c _ZSt4cout + 0 - -Relocation section '.rela.plt' at offset 0x494 contains 9 entries: - Offset Info Type Sym.Value Sym. Name + Addend -10010be4 00000115 R_PPC_JMP_SLOT 100008e0 __cxa_atexit + 0 -10010be8 00000215 R_PPC_JMP_SLOT 00000000 __gmon_start__ + 0 -10010bec 00000415 R_PPC_JMP_SLOT 10000900 _ZNSt8ios_base4InitC1E + 0 -10010bf0 00000515 R_PPC_JMP_SLOT 10000910 __libc_start_main + 0 -10010bf4 00000615 R_PPC_JMP_SLOT 10000920 _ZNSt8ios_base4InitD1E + 0 -10010bf8 00000715 R_PPC_JMP_SLOT 10000930 _ZStlsISt11char_traits + 0 -10010bfc 00000a15 R_PPC_JMP_SLOT 10000940 _ZNSolsEPFRSoS_E + 0 -10010c00 00000b15 R_PPC_JMP_SLOT 10000950 _ZSt4endlIcSt11char_tr + 0 -10010c04 00000c15 R_PPC_JMP_SLOT 10000960 __gxx_personality_v0 + 0 - -There are no unwind sections in this file. - -Symbol table '.dynsym' contains 13 entries: - Num: Value Size Type Bind Vis Ndx Name - 0: 00000000 0 NOTYPE LOCAL DEFAULT UND - 1: 100008e0 144 FUNC GLOBAL DEFAULT UND __cxa_atexit@GLIBC_2.1.3 (2) - 2: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ - 3: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses - 4: 10000900 1452 FUNC GLOBAL DEFAULT UND _ZNSt8ios_base4InitC1Ev@GLIBCXX_3.4 (3) - 5: 10000910 232 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.0 (4) - 6: 10000920 204 FUNC GLOBAL DEFAULT UND _ZNSt8ios_base4InitD1Ev@GLIBCXX_3.4 (3) - 7: 10000930 164 FUNC GLOBAL DEFAULT UND _ZStlsISt11char_traitsIcE@GLIBCXX_3.4 (3) - 8: 10000a18 4 OBJECT GLOBAL DEFAULT 13 _IO_stdin_used - 9: 10010c0c 140 OBJECT GLOBAL DEFAULT 24 _ZSt4cout@GLIBCXX_3.4 (3) - 10: 10000940 36 FUNC GLOBAL DEFAULT UND _ZNSolsEPFRSoS_E@GLIBCXX_3.4 (3) - 11: 10000950 336 FUNC GLOBAL DEFAULT UND _ZSt4endlIcSt11char_trait@GLIBCXX_3.4 (3) - 12: 10000960 1420 FUNC GLOBAL DEFAULT UND __gxx_personality_v0@CXXABI_1.3 (5) - -Symbol table '.symtab' contains 80 entries: - Num: Value Size Type Bind Vis Ndx Name - 0: 00000000 0 NOTYPE LOCAL DEFAULT UND - 1: 10000134 0 SECTION LOCAL DEFAULT 1 - 2: 10000144 0 SECTION LOCAL DEFAULT 2 - 3: 10000164 0 SECTION LOCAL DEFAULT 3 - 4: 100001ac 0 SECTION LOCAL DEFAULT 4 - 5: 1000027c 0 SECTION LOCAL DEFAULT 5 - 6: 10000400 0 SECTION LOCAL DEFAULT 6 - 7: 1000041c 0 SECTION LOCAL DEFAULT 7 - 8: 1000047c 0 SECTION LOCAL DEFAULT 8 - 9: 10000494 0 SECTION LOCAL DEFAULT 9 - 10: 10000500 0 SECTION LOCAL DEFAULT 10 - 11: 10000550 0 SECTION LOCAL DEFAULT 11 - 12: 100009d0 0 SECTION LOCAL DEFAULT 12 - 13: 10000a08 0 SECTION LOCAL DEFAULT 13 - 14: 10000a24 0 SECTION LOCAL DEFAULT 14 - 15: 10000a48 0 SECTION LOCAL DEFAULT 15 - 16: 10010acc 0 SECTION LOCAL DEFAULT 16 - 17: 10010ad8 0 SECTION LOCAL DEFAULT 17 - 18: 10010ae0 0 SECTION LOCAL DEFAULT 18 - 19: 10010ae4 0 SECTION LOCAL DEFAULT 19 - 20: 10010aec 0 SECTION LOCAL DEFAULT 20 - 21: 10010bd4 0 SECTION LOCAL DEFAULT 21 - 22: 10010be4 0 SECTION LOCAL DEFAULT 22 - 23: 10010c08 0 SECTION LOCAL DEFAULT 23 - 24: 10010c0c 0 SECTION LOCAL DEFAULT 24 - 25: 00000000 0 SECTION LOCAL DEFAULT 25 - 26: 00000000 0 SECTION LOCAL DEFAULT 26 - 27: 00000000 0 SECTION LOCAL DEFAULT 27 - 28: 00000000 0 FILE LOCAL DEFAULT ABS init.c - 29: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c - 30: 10010acc 0 OBJECT LOCAL DEFAULT 16 __CTOR_LIST__ - 31: 10010ad8 0 OBJECT LOCAL DEFAULT 17 __DTOR_LIST__ - 32: 10010ae0 0 OBJECT LOCAL DEFAULT 18 __JCR_LIST__ - 33: 10000574 0 FUNC LOCAL DEFAULT 11 __do_global_dtors_aux - 34: 10010c98 1 OBJECT LOCAL DEFAULT 24 completed.6348 - 35: 10010c9c 4 OBJECT LOCAL DEFAULT 24 dtor_idx.6350 - 36: 1000061c 0 FUNC LOCAL DEFAULT 11 call___do_global_dtors_au - 37: 10000638 0 FUNC LOCAL DEFAULT 11 frame_dummy - 38: 10000680 0 FUNC LOCAL DEFAULT 11 call_frame_dummy - 39: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c - 40: 10010ad4 0 OBJECT LOCAL DEFAULT 16 __CTOR_END__ - 41: 10000ac8 0 OBJECT LOCAL DEFAULT 15 __FRAME_END__ - 42: 10010ae0 0 OBJECT LOCAL DEFAULT 18 __JCR_END__ - 43: 1000086c 0 FUNC LOCAL DEFAULT 11 __do_global_ctors_aux - 44: 100008bc 0 FUNC LOCAL DEFAULT 11 call___do_global_ctors_au - 45: 00000000 0 FILE LOCAL DEFAULT ABS test_ppc.cpp - 46: 100006f8 128 FUNC LOCAL DEFAULT 11 _Z41__static_initializati - 47: 10010ca0 1 OBJECT LOCAL DEFAULT 24 _ZStL8__ioinit - 48: 10000778 60 FUNC LOCAL DEFAULT 11 _GLOBAL__I_main - 49: 00000000 0 FILE LOCAL DEFAULT ABS elf-init.c - 50: 10010bd8 0 OBJECT LOCAL HIDDEN 21 _GLOBAL_OFFSET_TABLE_ - 51: 10010acc 0 NOTYPE LOCAL HIDDEN 16 __init_array_end - 52: 10010acc 0 NOTYPE LOCAL HIDDEN 16 __init_array_start - 53: 10010aec 0 OBJECT LOCAL HIDDEN 20 _DYNAMIC - 54: 10010c08 0 NOTYPE WEAK DEFAULT 23 data_start - 55: 100008e0 144 FUNC GLOBAL DEFAULT UND __cxa_atexit@@GLIBC_2.1.3 - 56: 100007b4 4 FUNC GLOBAL DEFAULT 11 __libc_csu_fini - 57: 10000550 36 FUNC GLOBAL DEFAULT 11 _start - 58: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ - 59: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses - 60: 100009d0 0 FUNC GLOBAL DEFAULT 12 _fini - 61: 10000900 1452 FUNC GLOBAL DEFAULT UND _ZNSt8ios_base4InitC1Ev@@ - 62: 10018c0c 0 NOTYPE GLOBAL DEFAULT 24 _SDA_BASE_ - 63: 10000910 232 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_ - 64: 10000920 204 FUNC GLOBAL DEFAULT UND _ZNSt8ios_base4InitD1Ev@@ - 65: 10000930 164 FUNC GLOBAL DEFAULT UND _ZStlsISt11char_traitsIcE - 66: 10000a18 4 OBJECT GLOBAL DEFAULT 13 _IO_stdin_used - 67: 10010c08 0 NOTYPE GLOBAL DEFAULT 23 __data_start - 68: 10010c0c 140 OBJECT GLOBAL DEFAULT 24 _ZSt4cout@@GLIBCXX_3.4 - 69: 10010c08 0 OBJECT GLOBAL HIDDEN 23 __dso_handle - 70: 10010adc 0 OBJECT GLOBAL HIDDEN 17 __DTOR_END__ - 71: 100007b8 180 FUNC GLOBAL DEFAULT 11 __libc_csu_init - 72: 10010c0c 0 NOTYPE GLOBAL DEFAULT ABS __bss_start - 73: 10010ca4 0 NOTYPE GLOBAL DEFAULT ABS _end - 74: 10000940 36 FUNC GLOBAL DEFAULT UND _ZNSolsEPFRSoS_E@@GLIBCXX - 75: 10000950 336 FUNC GLOBAL DEFAULT UND _ZSt4endlIcSt11char_trait - 76: 10010c0c 0 NOTYPE GLOBAL DEFAULT ABS _edata - 77: 10000960 1420 FUNC GLOBAL DEFAULT UND __gxx_personality_v0@@CXX - 78: 1000069c 92 FUNC GLOBAL DEFAULT 11 main - 79: 10000500 0 FUNC GLOBAL DEFAULT 10 _init - -Histogram for bucket list length (total of 3 buckets): - Length Number % of total Coverage - 0 0 ( 0.0%) - 1 0 ( 0.0%) 0.0% - 2 1 ( 33.3%) 16.7% - 3 0 ( 0.0%) 16.7% - 4 1 ( 33.3%) 50.0% - 5 0 ( 0.0%) 50.0% - 6 1 ( 33.3%) 100.0% - -Version symbols section '.gnu.version' contains 13 entries: - Addr: 0000000010000400 Offset: 0x000400 Link: 4 (.dynsym) - 000: 0 (*local*) 2 (GLIBC_2.1.3) 0 (*local*) 0 (*local*) - 004: 3 (GLIBCXX_3.4) 4 (GLIBC_2.0) 3 (GLIBCXX_3.4) 3 (GLIBCXX_3.4) - 008: 1 (*global*) 3 (GLIBCXX_3.4) 3 (GLIBCXX_3.4) 3 (GLIBCXX_3.4) - 00c: 5 (CXXABI_1.3) - -Version needs section '.gnu.version_r' contains 2 entries: - Addr: 0x000000001000041c Offset: 0x00041c Link: 5 (.dynstr) - 000000: Version: 1 File: libstdc++.so.6 Cnt: 2 - 0x0010: Name: CXXABI_1.3 Flags: none Version: 5 - 0x0020: Name: GLIBCXX_3.4 Flags: none Version: 3 - 0x0030: Version: 1 File: libc.so.6 Cnt: 2 - 0x0040: Name: GLIBC_2.0 Flags: none Version: 4 - 0x0050: Name: GLIBC_2.1.3 Flags: none Version: 2 - -Notes at offset 0x00000144 with length 0x00000020: - Owner Data size Description - GNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag) -Attribute Section: gnu -File Attributes - Tag_GNU_Power_ABI_FP: Hard float - Tag_GNU_Power_ABI_Vector: Generic - Tag_GNU_Power_ABI_Struct_Return: Memory +ELF Header: + Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00 + Class: ELF32 + Data: 2's complement, big endian + Version: 1 (current) + OS/ABI: UNIX - System V + ABI Version: 0 + Type: EXEC (Executable file) + Machine: PowerPC + Version: 0x1 + Entry point address: 0x10000550 + Start of program headers: 52 (bytes into file) + Start of section headers: 3484 (bytes into file) + Flags: 0x0 + Size of this header: 52 (bytes) + Size of program headers: 32 (bytes) + Number of program headers: 8 + Size of section headers: 40 (bytes) + Number of section headers: 31 + Section header string table index: 28 + +Section Headers: + [Nr] Name Type Addr Off Size ES Flg Lk Inf Al + [ 0] NULL 00000000 000000 000000 00 0 0 0 + [ 1] .interp PROGBITS 10000134 000134 00000d 00 A 0 0 1 + [ 2] .note.ABI-tag NOTE 10000144 000144 000020 00 A 0 0 4 + [ 3] .hash HASH 10000164 000164 000048 04 A 4 0 4 + [ 4] .dynsym DYNSYM 100001ac 0001ac 0000d0 10 A 5 1 4 + [ 5] .dynstr STRTAB 1000027c 00027c 000183 00 A 0 0 1 + [ 6] .gnu.version VERSYM 10000400 000400 00001a 02 A 4 0 2 + [ 7] .gnu.version_r VERNEED 1000041c 00041c 000060 00 A 5 2 4 + [ 8] .rela.dyn RELA 1000047c 00047c 000018 0c A 4 0 4 + [ 9] .rela.plt RELA 10000494 000494 00006c 0c A 4 22 4 + [10] .init PROGBITS 10000500 000500 00004c 00 AX 0 0 4 + [11] .text PROGBITS 10000550 000550 000480 00 AX 0 0 16 + [12] .fini PROGBITS 100009d0 0009d0 000038 00 AX 0 0 4 + [13] .rodata PROGBITS 10000a08 000a08 00001a 00 A 0 0 4 + [14] .eh_frame_hdr PROGBITS 10000a24 000a24 000024 00 A 0 0 4 + [15] .eh_frame PROGBITS 10000a48 000a48 000084 00 A 0 0 4 + [16] .ctors PROGBITS 10010acc 000acc 00000c 00 WA 0 0 4 + [17] .dtors PROGBITS 10010ad8 000ad8 000008 00 WA 0 0 4 + [18] .jcr PROGBITS 10010ae0 000ae0 000004 00 WA 0 0 4 + [19] .got2 PROGBITS 10010ae4 000ae4 000008 00 WA 0 0 1 + [20] .dynamic DYNAMIC 10010aec 000aec 0000e8 08 WA 5 0 4 + [21] .got PROGBITS 10010bd4 000bd4 000010 04 WA 0 0 4 + [22] .plt PROGBITS 10010be4 000be4 000024 00 WA 0 0 4 + [23] .data PROGBITS 10010c08 000c08 000004 00 WA 0 0 4 + [24] .bss NOBITS 10010c0c 000c0c 000098 00 WA 0 0 4 + [25] .comment PROGBITS 00000000 000c0c 000027 00 0 0 1 + [26] .debug_frame PROGBITS 00000000 000c34 000050 00 0 0 4 + [27] .gnu.attributes LOOS+ffffff5 00000000 000c84 000014 00 0 0 1 + [28] .shstrtab STRTAB 00000000 000c98 000101 00 0 0 1 + [29] .symtab SYMTAB 00000000 001274 000500 10 30 54 4 + [30] .strtab STRTAB 00000000 001774 0003cc 00 0 0 1 +Key to Flags: + W (write), A (alloc), X (execute), M (merge), S (strings) + I (info), L (link order), G (group), x (unknown) + O (extra OS processing required) o (OS specific), p (processor specific) + +There are no section groups in this file. + +Program Headers: + Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align + PHDR 0x000034 0x10000034 0x10000034 0x00100 0x00100 R E 0x4 + INTERP 0x000134 0x10000134 0x10000134 0x0000d 0x0000d R 0x1 + [Requesting program interpreter: /lib/ld.so.1] + LOAD 0x000000 0x10000000 0x10000000 0x00acc 0x00acc R E 0x10000 + LOAD 0x000acc 0x10010acc 0x10010acc 0x00140 0x001d8 RW 0x10000 + DYNAMIC 0x000aec 0x10010aec 0x10010aec 0x000e8 0x000e8 RW 0x4 + NOTE 0x000144 0x10000144 0x10000144 0x00020 0x00020 R 0x4 + GNU_EH_FRAME 0x000a24 0x10000a24 0x10000a24 0x00024 0x00024 R 0x4 + GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4 + + Section to Segment mapping: + Segment Sections... + 00 + 01 .interp + 02 .interp .note.ABI-tag .hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .text .fini .rodata .eh_frame_hdr .eh_frame + 03 .ctors .dtors .jcr .got2 .dynamic .got .plt .data .bss + 04 .dynamic + 05 .note.ABI-tag + 06 .eh_frame_hdr + 07 + +Dynamic section at offset 0xaec contains 24 entries: + Tag Type Name/Value + 0x00000001 (NEEDED) Shared library: [libstdc++.so.6] + 0x00000001 (NEEDED) Shared library: [libm.so.6] + 0x00000001 (NEEDED) Shared library: [libgcc_s.so.1] + 0x00000001 (NEEDED) Shared library: [libc.so.6] + 0x0000000c (INIT) 0x10000500 + 0x0000000d (FINI) 0x100009d0 + 0x00000004 (HASH) 0x10000164 + 0x00000005 (STRTAB) 0x1000027c + 0x00000006 (SYMTAB) 0x100001ac + 0x0000000a (STRSZ) 387 (bytes) + 0x0000000b (SYMENT) 16 (bytes) + 0x00000015 (DEBUG) 0x0 + 0x00000003 (PLTGOT) 0x10010be4 + 0x00000002 (PLTRELSZ) 108 (bytes) + 0x00000014 (PLTREL) RELA + 0x00000017 (JMPREL) 0x10000494 + 0x70000000 (PPC_GOT) 0x10010bd8 + 0x00000007 (RELA) 0x1000047c + 0x00000008 (RELASZ) 132 (bytes) + 0x00000009 (RELAENT) 12 (bytes) + 0x6ffffffe (VERNEED) 0x1000041c + 0x6fffffff (VERNEEDNUM) 2 + 0x6ffffff0 (VERSYM) 0x10000400 + 0x00000000 (NULL) 0x0 + +Relocation section '.rela.dyn' at offset 0x47c contains 2 entries: + Offset Info Type Sym.Value Sym. Name + Addend +10010bd4 00000214 R_PPC_GLOB_DAT 00000000 __gmon_start__ + 0 +10010c0c 00000913 R_PPC_COPY 10010c0c _ZSt4cout + 0 + +Relocation section '.rela.plt' at offset 0x494 contains 9 entries: + Offset Info Type Sym.Value Sym. Name + Addend +10010be4 00000115 R_PPC_JMP_SLOT 100008e0 __cxa_atexit + 0 +10010be8 00000215 R_PPC_JMP_SLOT 00000000 __gmon_start__ + 0 +10010bec 00000415 R_PPC_JMP_SLOT 10000900 _ZNSt8ios_base4InitC1E + 0 +10010bf0 00000515 R_PPC_JMP_SLOT 10000910 __libc_start_main + 0 +10010bf4 00000615 R_PPC_JMP_SLOT 10000920 _ZNSt8ios_base4InitD1E + 0 +10010bf8 00000715 R_PPC_JMP_SLOT 10000930 _ZStlsISt11char_traits + 0 +10010bfc 00000a15 R_PPC_JMP_SLOT 10000940 _ZNSolsEPFRSoS_E + 0 +10010c00 00000b15 R_PPC_JMP_SLOT 10000950 _ZSt4endlIcSt11char_tr + 0 +10010c04 00000c15 R_PPC_JMP_SLOT 10000960 __gxx_personality_v0 + 0 + +There are no unwind sections in this file. + +Symbol table '.dynsym' contains 13 entries: + Num: Value Size Type Bind Vis Ndx Name + 0: 00000000 0 NOTYPE LOCAL DEFAULT UND + 1: 100008e0 144 FUNC GLOBAL DEFAULT UND __cxa_atexit@GLIBC_2.1.3 (2) + 2: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ + 3: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses + 4: 10000900 1452 FUNC GLOBAL DEFAULT UND _ZNSt8ios_base4InitC1Ev@GLIBCXX_3.4 (3) + 5: 10000910 232 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.0 (4) + 6: 10000920 204 FUNC GLOBAL DEFAULT UND _ZNSt8ios_base4InitD1Ev@GLIBCXX_3.4 (3) + 7: 10000930 164 FUNC GLOBAL DEFAULT UND _ZStlsISt11char_traitsIcE@GLIBCXX_3.4 (3) + 8: 10000a18 4 OBJECT GLOBAL DEFAULT 13 _IO_stdin_used + 9: 10010c0c 140 OBJECT GLOBAL DEFAULT 24 _ZSt4cout@GLIBCXX_3.4 (3) + 10: 10000940 36 FUNC GLOBAL DEFAULT UND _ZNSolsEPFRSoS_E@GLIBCXX_3.4 (3) + 11: 10000950 336 FUNC GLOBAL DEFAULT UND _ZSt4endlIcSt11char_trait@GLIBCXX_3.4 (3) + 12: 10000960 1420 FUNC GLOBAL DEFAULT UND __gxx_personality_v0@CXXABI_1.3 (5) + +Symbol table '.symtab' contains 80 entries: + Num: Value Size Type Bind Vis Ndx Name + 0: 00000000 0 NOTYPE LOCAL DEFAULT UND + 1: 10000134 0 SECTION LOCAL DEFAULT 1 + 2: 10000144 0 SECTION LOCAL DEFAULT 2 + 3: 10000164 0 SECTION LOCAL DEFAULT 3 + 4: 100001ac 0 SECTION LOCAL DEFAULT 4 + 5: 1000027c 0 SECTION LOCAL DEFAULT 5 + 6: 10000400 0 SECTION LOCAL DEFAULT 6 + 7: 1000041c 0 SECTION LOCAL DEFAULT 7 + 8: 1000047c 0 SECTION LOCAL DEFAULT 8 + 9: 10000494 0 SECTION LOCAL DEFAULT 9 + 10: 10000500 0 SECTION LOCAL DEFAULT 10 + 11: 10000550 0 SECTION LOCAL DEFAULT 11 + 12: 100009d0 0 SECTION LOCAL DEFAULT 12 + 13: 10000a08 0 SECTION LOCAL DEFAULT 13 + 14: 10000a24 0 SECTION LOCAL DEFAULT 14 + 15: 10000a48 0 SECTION LOCAL DEFAULT 15 + 16: 10010acc 0 SECTION LOCAL DEFAULT 16 + 17: 10010ad8 0 SECTION LOCAL DEFAULT 17 + 18: 10010ae0 0 SECTION LOCAL DEFAULT 18 + 19: 10010ae4 0 SECTION LOCAL DEFAULT 19 + 20: 10010aec 0 SECTION LOCAL DEFAULT 20 + 21: 10010bd4 0 SECTION LOCAL DEFAULT 21 + 22: 10010be4 0 SECTION LOCAL DEFAULT 22 + 23: 10010c08 0 SECTION LOCAL DEFAULT 23 + 24: 10010c0c 0 SECTION LOCAL DEFAULT 24 + 25: 00000000 0 SECTION LOCAL DEFAULT 25 + 26: 00000000 0 SECTION LOCAL DEFAULT 26 + 27: 00000000 0 SECTION LOCAL DEFAULT 27 + 28: 00000000 0 FILE LOCAL DEFAULT ABS init.c + 29: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c + 30: 10010acc 0 OBJECT LOCAL DEFAULT 16 __CTOR_LIST__ + 31: 10010ad8 0 OBJECT LOCAL DEFAULT 17 __DTOR_LIST__ + 32: 10010ae0 0 OBJECT LOCAL DEFAULT 18 __JCR_LIST__ + 33: 10000574 0 FUNC LOCAL DEFAULT 11 __do_global_dtors_aux + 34: 10010c98 1 OBJECT LOCAL DEFAULT 24 completed.6348 + 35: 10010c9c 4 OBJECT LOCAL DEFAULT 24 dtor_idx.6350 + 36: 1000061c 0 FUNC LOCAL DEFAULT 11 call___do_global_dtors_au + 37: 10000638 0 FUNC LOCAL DEFAULT 11 frame_dummy + 38: 10000680 0 FUNC LOCAL DEFAULT 11 call_frame_dummy + 39: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c + 40: 10010ad4 0 OBJECT LOCAL DEFAULT 16 __CTOR_END__ + 41: 10000ac8 0 OBJECT LOCAL DEFAULT 15 __FRAME_END__ + 42: 10010ae0 0 OBJECT LOCAL DEFAULT 18 __JCR_END__ + 43: 1000086c 0 FUNC LOCAL DEFAULT 11 __do_global_ctors_aux + 44: 100008bc 0 FUNC LOCAL DEFAULT 11 call___do_global_ctors_au + 45: 00000000 0 FILE LOCAL DEFAULT ABS test_ppc.cpp + 46: 100006f8 128 FUNC LOCAL DEFAULT 11 _Z41__static_initializati + 47: 10010ca0 1 OBJECT LOCAL DEFAULT 24 _ZStL8__ioinit + 48: 10000778 60 FUNC LOCAL DEFAULT 11 _GLOBAL__I_main + 49: 00000000 0 FILE LOCAL DEFAULT ABS elf-init.c + 50: 10010bd8 0 OBJECT LOCAL HIDDEN 21 _GLOBAL_OFFSET_TABLE_ + 51: 10010acc 0 NOTYPE LOCAL HIDDEN 16 __init_array_end + 52: 10010acc 0 NOTYPE LOCAL HIDDEN 16 __init_array_start + 53: 10010aec 0 OBJECT LOCAL HIDDEN 20 _DYNAMIC + 54: 10010c08 0 NOTYPE WEAK DEFAULT 23 data_start + 55: 100008e0 144 FUNC GLOBAL DEFAULT UND __cxa_atexit@@GLIBC_2.1.3 + 56: 100007b4 4 FUNC GLOBAL DEFAULT 11 __libc_csu_fini + 57: 10000550 36 FUNC GLOBAL DEFAULT 11 _start + 58: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__ + 59: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses + 60: 100009d0 0 FUNC GLOBAL DEFAULT 12 _fini + 61: 10000900 1452 FUNC GLOBAL DEFAULT UND _ZNSt8ios_base4InitC1Ev@@ + 62: 10018c0c 0 NOTYPE GLOBAL DEFAULT 24 _SDA_BASE_ + 63: 10000910 232 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_ + 64: 10000920 204 FUNC GLOBAL DEFAULT UND _ZNSt8ios_base4InitD1Ev@@ + 65: 10000930 164 FUNC GLOBAL DEFAULT UND _ZStlsISt11char_traitsIcE + 66: 10000a18 4 OBJECT GLOBAL DEFAULT 13 _IO_stdin_used + 67: 10010c08 0 NOTYPE GLOBAL DEFAULT 23 __data_start + 68: 10010c0c 140 OBJECT GLOBAL DEFAULT 24 _ZSt4cout@@GLIBCXX_3.4 + 69: 10010c08 0 OBJECT GLOBAL HIDDEN 23 __dso_handle + 70: 10010adc 0 OBJECT GLOBAL HIDDEN 17 __DTOR_END__ + 71: 100007b8 180 FUNC GLOBAL DEFAULT 11 __libc_csu_init + 72: 10010c0c 0 NOTYPE GLOBAL DEFAULT ABS __bss_start + 73: 10010ca4 0 NOTYPE GLOBAL DEFAULT ABS _end + 74: 10000940 36 FUNC GLOBAL DEFAULT UND _ZNSolsEPFRSoS_E@@GLIBCXX + 75: 10000950 336 FUNC GLOBAL DEFAULT UND _ZSt4endlIcSt11char_trait + 76: 10010c0c 0 NOTYPE GLOBAL DEFAULT ABS _edata + 77: 10000960 1420 FUNC GLOBAL DEFAULT UND __gxx_personality_v0@@CXX + 78: 1000069c 92 FUNC GLOBAL DEFAULT 11 main + 79: 10000500 0 FUNC GLOBAL DEFAULT 10 _init + +Histogram for bucket list length (total of 3 buckets): + Length Number % of total Coverage + 0 0 ( 0.0%) + 1 0 ( 0.0%) 0.0% + 2 1 ( 33.3%) 16.7% + 3 0 ( 0.0%) 16.7% + 4 1 ( 33.3%) 50.0% + 5 0 ( 0.0%) 50.0% + 6 1 ( 33.3%) 100.0% + +Version symbols section '.gnu.version' contains 13 entries: + Addr: 0000000010000400 Offset: 0x000400 Link: 4 (.dynsym) + 000: 0 (*local*) 2 (GLIBC_2.1.3) 0 (*local*) 0 (*local*) + 004: 3 (GLIBCXX_3.4) 4 (GLIBC_2.0) 3 (GLIBCXX_3.4) 3 (GLIBCXX_3.4) + 008: 1 (*global*) 3 (GLIBCXX_3.4) 3 (GLIBCXX_3.4) 3 (GLIBCXX_3.4) + 00c: 5 (CXXABI_1.3) + +Version needs section '.gnu.version_r' contains 2 entries: + Addr: 0x000000001000041c Offset: 0x00041c Link: 5 (.dynstr) + 000000: Version: 1 File: libstdc++.so.6 Cnt: 2 + 0x0010: Name: CXXABI_1.3 Flags: none Version: 5 + 0x0020: Name: GLIBCXX_3.4 Flags: none Version: 3 + 0x0030: Version: 1 File: libc.so.6 Cnt: 2 + 0x0040: Name: GLIBC_2.0 Flags: none Version: 4 + 0x0050: Name: GLIBC_2.1.3 Flags: none Version: 2 + +Notes at offset 0x00000144 with length 0x00000020: + Owner Data size Description + GNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag) +Attribute Section: gnu +File Attributes + Tag_GNU_Power_ABI_FP: Hard float + Tag_GNU_Power_ABI_Vector: Generic + Tag_GNU_Power_ABI_Struct_Return: Memory diff --git a/elf_examples/test_ppc_o.txt b/elf_examples/test_ppc_o.txt index d04ce3cd25902ebd7fffe6f4b5d167cab8fde932..cffbe17931d9b9b54d417e1e58323cfaea51e860 100644 --- a/elf_examples/test_ppc_o.txt +++ b/elf_examples/test_ppc_o.txt @@ -1,114 +1,114 @@ -ELF Header: - Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00 - Class: ELF32 - Data: 2's complement, big endian - Version: 1 (current) - OS/ABI: UNIX - System V - ABI Version: 0 - Type: REL (Relocatable file) - Machine: PowerPC - Version: 0x1 - Entry point address: 0x0 - Start of program headers: 0 (bytes into file) - Start of section headers: 616 (bytes into file) - Flags: 0x0 - Size of this header: 52 (bytes) - Size of program headers: 0 (bytes) - Number of program headers: 0 - Size of section headers: 40 (bytes) - Number of section headers: 16 - Section header string table index: 13 - -Section Headers: - [Nr] Name Type Addr Off Size ES Flg Lk Inf Al - [ 0] NULL 00000000 000000 000000 00 0 0 0 - [ 1] .text PROGBITS 00000000 000034 000118 00 AX 0 0 4 - [ 2] .rela.text RELA 00000000 0007b8 0000d8 0c 14 1 4 - [ 3] .data PROGBITS 00000000 00014c 000000 00 WA 0 0 1 - [ 4] .bss NOBITS 00000000 00014c 000001 00 WA 0 0 1 - [ 5] .rodata PROGBITS 00000000 00014c 000006 00 A 0 0 4 - [ 6] .ctors PROGBITS 00000000 000154 000004 00 WA 0 0 4 - [ 7] .rela.ctors RELA 00000000 000890 00000c 0c 14 6 4 - [ 8] .eh_frame PROGBITS 00000000 000158 000058 00 A 0 0 4 - [ 9] .rela.eh_frame RELA 00000000 00089c 000024 0c 14 8 4 - [10] .comment PROGBITS 00000000 0001b0 000027 00 0 0 1 - [11] .note.GNU-stack PROGBITS 00000000 0001d7 000000 00 0 0 1 - [12] .gnu.attributes LOOS+ffffff5 00000000 0001d7 000014 00 0 0 1 - [13] .shstrtab STRTAB 00000000 0001eb 00007d 00 0 0 1 - [14] .symtab SYMTAB 00000000 0004e8 000180 10 15 14 4 - [15] .strtab STRTAB 00000000 000668 00014f 00 0 0 1 -Key to Flags: - W (write), A (alloc), X (execute), M (merge), S (strings) - I (info), L (link order), G (group), x (unknown) - O (extra OS processing required) o (OS specific), p (processor specific) - -There are no section groups in this file. - -There are no program headers in this file. - -Relocation section '.rela.text' at offset 0x7b8 contains 18 entries: - Offset Info Type Sym.Value Sym. Name + Addend -00000016 00000f06 R_PPC_ADDR16_HA 00000000 _ZSt4cout + 0 -0000001a 00000f04 R_PPC_ADDR16_LO 00000000 _ZSt4cout + 0 -0000001e 00000506 R_PPC_ADDR16_HA 00000000 .rodata + 0 -00000022 00000504 R_PPC_ADDR16_LO 00000000 .rodata + 0 -00000024 0000100a R_PPC_REL24 00000000 _ZStlsISt11char_traits + 0 -00000032 00001106 R_PPC_ADDR16_HA 00000000 _ZSt4endlIcSt11char_tr + 0 -00000036 00001104 R_PPC_ADDR16_LO 00000000 _ZSt4endlIcSt11char_tr + 0 -00000038 0000120a R_PPC_REL24 00000000 _ZNSolsEPFRSoS_E + 0 -0000009a 00000406 R_PPC_ADDR16_HA 00000000 .bss + 0 -0000009e 00000404 R_PPC_ADDR16_LO 00000000 .bss + 0 -000000a0 0000130a R_PPC_REL24 00000000 _ZNSt8ios_base4InitC1E + 0 -000000a6 00001406 R_PPC_ADDR16_HA 00000000 _ZNSt8ios_base4InitD1E + 0 -000000aa 00001404 R_PPC_ADDR16_LO 00000000 _ZNSt8ios_base4InitD1E + 0 -000000b2 00000406 R_PPC_ADDR16_HA 00000000 .bss + 0 -000000b6 00000404 R_PPC_ADDR16_LO 00000000 .bss + 0 -000000ba 00001506 R_PPC_ADDR16_HA 00000000 __dso_handle + 0 -000000be 00001504 R_PPC_ADDR16_LO 00000000 __dso_handle + 0 -000000c0 0000160a R_PPC_REL24 00000000 __cxa_atexit + 0 - -Relocation section '.rela.ctors' at offset 0x890 contains 1 entries: - Offset Info Type Sym.Value Sym. Name + Addend -00000000 00000201 R_PPC_ADDR32 00000000 .text + dc - -Relocation section '.rela.eh_frame' at offset 0x89c contains 3 entries: - Offset Info Type Sym.Value Sym. Name + Addend -00000011 00001701 R_PPC_ADDR32 00000000 __gxx_personality_v0 + 0 -00000020 00000201 R_PPC_ADDR32 00000000 .text + 0 -00000040 00000201 R_PPC_ADDR32 00000000 .text + 5c - -There are no unwind sections in this file. - -Symbol table '.symtab' contains 24 entries: - Num: Value Size Type Bind Vis Ndx Name - 0: 00000000 0 NOTYPE LOCAL DEFAULT UND - 1: 00000000 0 FILE LOCAL DEFAULT ABS test_ppc.cpp - 2: 00000000 0 SECTION LOCAL DEFAULT 1 - 3: 00000000 0 SECTION LOCAL DEFAULT 3 - 4: 00000000 0 SECTION LOCAL DEFAULT 4 - 5: 00000000 0 SECTION LOCAL DEFAULT 5 - 6: 0000005c 128 FUNC LOCAL DEFAULT 1 _Z41__static_initializati - 7: 00000000 1 OBJECT LOCAL DEFAULT 4 _ZStL8__ioinit - 8: 000000dc 60 FUNC LOCAL DEFAULT 1 _GLOBAL__I_main - 9: 00000000 0 SECTION LOCAL DEFAULT 6 - 10: 00000000 0 SECTION LOCAL DEFAULT 8 - 11: 00000000 0 SECTION LOCAL DEFAULT 11 - 12: 00000000 0 SECTION LOCAL DEFAULT 10 - 13: 00000000 0 SECTION LOCAL DEFAULT 12 - 14: 00000000 92 FUNC GLOBAL DEFAULT 1 main - 15: 00000000 0 NOTYPE GLOBAL DEFAULT UND _ZSt4cout - 16: 00000000 0 NOTYPE GLOBAL DEFAULT UND _ZStlsISt11char_traitsIcE - 17: 00000000 0 NOTYPE GLOBAL DEFAULT UND _ZSt4endlIcSt11char_trait - 18: 00000000 0 NOTYPE GLOBAL DEFAULT UND _ZNSolsEPFRSoS_E - 19: 00000000 0 NOTYPE GLOBAL DEFAULT UND _ZNSt8ios_base4InitC1Ev - 20: 00000000 0 NOTYPE GLOBAL DEFAULT UND _ZNSt8ios_base4InitD1Ev - 21: 00000000 0 NOTYPE GLOBAL DEFAULT UND __dso_handle - 22: 00000000 0 NOTYPE GLOBAL DEFAULT UND __cxa_atexit - 23: 00000000 0 NOTYPE GLOBAL DEFAULT UND __gxx_personality_v0 - -No version information found in this file. -Attribute Section: gnu -File Attributes - Tag_GNU_Power_ABI_FP: Hard float - Tag_GNU_Power_ABI_Vector: Generic - Tag_GNU_Power_ABI_Struct_Return: Memory +ELF Header: + Magic: 7f 45 4c 46 01 02 01 00 00 00 00 00 00 00 00 00 + Class: ELF32 + Data: 2's complement, big endian + Version: 1 (current) + OS/ABI: UNIX - System V + ABI Version: 0 + Type: REL (Relocatable file) + Machine: PowerPC + Version: 0x1 + Entry point address: 0x0 + Start of program headers: 0 (bytes into file) + Start of section headers: 616 (bytes into file) + Flags: 0x0 + Size of this header: 52 (bytes) + Size of program headers: 0 (bytes) + Number of program headers: 0 + Size of section headers: 40 (bytes) + Number of section headers: 16 + Section header string table index: 13 + +Section Headers: + [Nr] Name Type Addr Off Size ES Flg Lk Inf Al + [ 0] NULL 00000000 000000 000000 00 0 0 0 + [ 1] .text PROGBITS 00000000 000034 000118 00 AX 0 0 4 + [ 2] .rela.text RELA 00000000 0007b8 0000d8 0c 14 1 4 + [ 3] .data PROGBITS 00000000 00014c 000000 00 WA 0 0 1 + [ 4] .bss NOBITS 00000000 00014c 000001 00 WA 0 0 1 + [ 5] .rodata PROGBITS 00000000 00014c 000006 00 A 0 0 4 + [ 6] .ctors PROGBITS 00000000 000154 000004 00 WA 0 0 4 + [ 7] .rela.ctors RELA 00000000 000890 00000c 0c 14 6 4 + [ 8] .eh_frame PROGBITS 00000000 000158 000058 00 A 0 0 4 + [ 9] .rela.eh_frame RELA 00000000 00089c 000024 0c 14 8 4 + [10] .comment PROGBITS 00000000 0001b0 000027 00 0 0 1 + [11] .note.GNU-stack PROGBITS 00000000 0001d7 000000 00 0 0 1 + [12] .gnu.attributes LOOS+ffffff5 00000000 0001d7 000014 00 0 0 1 + [13] .shstrtab STRTAB 00000000 0001eb 00007d 00 0 0 1 + [14] .symtab SYMTAB 00000000 0004e8 000180 10 15 14 4 + [15] .strtab STRTAB 00000000 000668 00014f 00 0 0 1 +Key to Flags: + W (write), A (alloc), X (execute), M (merge), S (strings) + I (info), L (link order), G (group), x (unknown) + O (extra OS processing required) o (OS specific), p (processor specific) + +There are no section groups in this file. + +There are no program headers in this file. + +Relocation section '.rela.text' at offset 0x7b8 contains 18 entries: + Offset Info Type Sym.Value Sym. Name + Addend +00000016 00000f06 R_PPC_ADDR16_HA 00000000 _ZSt4cout + 0 +0000001a 00000f04 R_PPC_ADDR16_LO 00000000 _ZSt4cout + 0 +0000001e 00000506 R_PPC_ADDR16_HA 00000000 .rodata + 0 +00000022 00000504 R_PPC_ADDR16_LO 00000000 .rodata + 0 +00000024 0000100a R_PPC_REL24 00000000 _ZStlsISt11char_traits + 0 +00000032 00001106 R_PPC_ADDR16_HA 00000000 _ZSt4endlIcSt11char_tr + 0 +00000036 00001104 R_PPC_ADDR16_LO 00000000 _ZSt4endlIcSt11char_tr + 0 +00000038 0000120a R_PPC_REL24 00000000 _ZNSolsEPFRSoS_E + 0 +0000009a 00000406 R_PPC_ADDR16_HA 00000000 .bss + 0 +0000009e 00000404 R_PPC_ADDR16_LO 00000000 .bss + 0 +000000a0 0000130a R_PPC_REL24 00000000 _ZNSt8ios_base4InitC1E + 0 +000000a6 00001406 R_PPC_ADDR16_HA 00000000 _ZNSt8ios_base4InitD1E + 0 +000000aa 00001404 R_PPC_ADDR16_LO 00000000 _ZNSt8ios_base4InitD1E + 0 +000000b2 00000406 R_PPC_ADDR16_HA 00000000 .bss + 0 +000000b6 00000404 R_PPC_ADDR16_LO 00000000 .bss + 0 +000000ba 00001506 R_PPC_ADDR16_HA 00000000 __dso_handle + 0 +000000be 00001504 R_PPC_ADDR16_LO 00000000 __dso_handle + 0 +000000c0 0000160a R_PPC_REL24 00000000 __cxa_atexit + 0 + +Relocation section '.rela.ctors' at offset 0x890 contains 1 entries: + Offset Info Type Sym.Value Sym. Name + Addend +00000000 00000201 R_PPC_ADDR32 00000000 .text + dc + +Relocation section '.rela.eh_frame' at offset 0x89c contains 3 entries: + Offset Info Type Sym.Value Sym. Name + Addend +00000011 00001701 R_PPC_ADDR32 00000000 __gxx_personality_v0 + 0 +00000020 00000201 R_PPC_ADDR32 00000000 .text + 0 +00000040 00000201 R_PPC_ADDR32 00000000 .text + 5c + +There are no unwind sections in this file. + +Symbol table '.symtab' contains 24 entries: + Num: Value Size Type Bind Vis Ndx Name + 0: 00000000 0 NOTYPE LOCAL DEFAULT UND + 1: 00000000 0 FILE LOCAL DEFAULT ABS test_ppc.cpp + 2: 00000000 0 SECTION LOCAL DEFAULT 1 + 3: 00000000 0 SECTION LOCAL DEFAULT 3 + 4: 00000000 0 SECTION LOCAL DEFAULT 4 + 5: 00000000 0 SECTION LOCAL DEFAULT 5 + 6: 0000005c 128 FUNC LOCAL DEFAULT 1 _Z41__static_initializati + 7: 00000000 1 OBJECT LOCAL DEFAULT 4 _ZStL8__ioinit + 8: 000000dc 60 FUNC LOCAL DEFAULT 1 _GLOBAL__I_main + 9: 00000000 0 SECTION LOCAL DEFAULT 6 + 10: 00000000 0 SECTION LOCAL DEFAULT 8 + 11: 00000000 0 SECTION LOCAL DEFAULT 11 + 12: 00000000 0 SECTION LOCAL DEFAULT 10 + 13: 00000000 0 SECTION LOCAL DEFAULT 12 + 14: 00000000 92 FUNC GLOBAL DEFAULT 1 main + 15: 00000000 0 NOTYPE GLOBAL DEFAULT UND _ZSt4cout + 16: 00000000 0 NOTYPE GLOBAL DEFAULT UND _ZStlsISt11char_traitsIcE + 17: 00000000 0 NOTYPE GLOBAL DEFAULT UND _ZSt4endlIcSt11char_trait + 18: 00000000 0 NOTYPE GLOBAL DEFAULT UND _ZNSolsEPFRSoS_E + 19: 00000000 0 NOTYPE GLOBAL DEFAULT UND _ZNSt8ios_base4InitC1Ev + 20: 00000000 0 NOTYPE GLOBAL DEFAULT UND _ZNSt8ios_base4InitD1Ev + 21: 00000000 0 NOTYPE GLOBAL DEFAULT UND __dso_handle + 22: 00000000 0 NOTYPE GLOBAL DEFAULT UND __cxa_atexit + 23: 00000000 0 NOTYPE GLOBAL DEFAULT UND __gxx_personality_v0 + +No version information found in this file. +Attribute Section: gnu +File Attributes + Tag_GNU_Power_ABI_FP: Hard float + Tag_GNU_Power_ABI_Vector: Generic + Tag_GNU_Power_ABI_Struct_Return: Memory diff --git a/elf_examples/write_exe_i386_32_work_dump.txt b/elf_examples/write_exe_i386_32_work_dump.txt index 15edaf832e78c276befb69614c91fab04e86b9b6..ca06c1d8a60a0344efc11a587e76b8c1d40955d2 100644 --- a/elf_examples/write_exe_i386_32_work_dump.txt +++ b/elf_examples/write_exe_i386_32_work_dump.txt @@ -1,71 +1,71 @@ - -write_exe_i386_32_work: file format elf32-i386 -write_exe_i386_32_work -architecture: i386, flags 0x00000102: -EXEC_P, D_PAGED -start address 0x08048080 - -Program Header: - LOAD off 0x00000000 vaddr 0x08048000 paddr 0x08048000 align 2**12 - filesz 0x0000009d memsz 0x0000009d flags r-x - LOAD off 0x000000a0 vaddr 0x080490a0 paddr 0x080490a0 align 2**12 - filesz 0x0000000e memsz 0x0000000e flags rw- - -Sections: -Idx Name Size VMA LMA File off Algn - 0 .text 0000001d 08048080 08048080 00000080 2**4 - CONTENTS, ALLOC, LOAD, READONLY, CODE - 1 .data 0000000e 080490a0 080490a0 000000a0 2**2 - CONTENTS, ALLOC, LOAD, DATA - 2 .note 00000020 00000000 00000000 000000ae 2**0 - CONTENTS, READONLY -SYMBOL TABLE: -no symbols - - - -Disassembly of section .text: - -08048080 <.text>: - 8048080: b8 04 00 00 00 mov $0x4,%eax - 8048085: bb 01 00 00 00 mov $0x1,%ebx - 804808a: b9 a0 90 04 08 mov $0x80490a0,%ecx - 804808f: ba 0e 00 00 00 mov $0xe,%edx - 8048094: cd 80 int $0x80 - 8048096: b8 01 00 00 00 mov $0x1,%eax - 804809b: cd 80 int $0x80 - -Disassembly of section .data: - -080490a0 <.data>: - 80490a0: 48 dec %eax - 80490a1: 65 gs - 80490a2: 6c insb (%dx),%es:(%edi) - 80490a3: 6c insb (%dx),%es:(%edi) - 80490a4: 6f outsl %ds:(%esi),(%dx) - 80490a5: 2c 20 sub $0x20,%al - 80490a7: 57 push %edi - 80490a8: 6f outsl %ds:(%esi),(%dx) - 80490a9: 72 6c jb 0x8049117 - 80490ab: 64 21 0a and %ecx,%fs:(%edx) - -Disassembly of section .note: - -00000000 <.note>: - 0: 11 00 adc %eax,(%eax) - 2: 00 00 add %al,(%eax) - 4: 00 00 add %al,(%eax) - 6: 00 00 add %al,(%eax) - 8: 77 00 ja 0xa - a: 00 00 add %al,(%eax) - c: 43 inc %ebx - d: 72 65 jb 0x74 - f: 61 popa - 10: 74 65 je 0x77 - 12: 64 20 62 79 and %ah,%fs:0x79(%edx) - 16: 20 45 4c and %al,0x4c(%ebp) - 19: 46 inc %esi - 1a: 49 dec %ecx - 1b: 4f dec %edi - 1c: 00 00 add %al,(%eax) - ... + +write_exe_i386_32_work: file format elf32-i386 +write_exe_i386_32_work +architecture: i386, flags 0x00000102: +EXEC_P, D_PAGED +start address 0x08048080 + +Program Header: + LOAD off 0x00000000 vaddr 0x08048000 paddr 0x08048000 align 2**12 + filesz 0x0000009d memsz 0x0000009d flags r-x + LOAD off 0x000000a0 vaddr 0x080490a0 paddr 0x080490a0 align 2**12 + filesz 0x0000000e memsz 0x0000000e flags rw- + +Sections: +Idx Name Size VMA LMA File off Algn + 0 .text 0000001d 08048080 08048080 00000080 2**4 + CONTENTS, ALLOC, LOAD, READONLY, CODE + 1 .data 0000000e 080490a0 080490a0 000000a0 2**2 + CONTENTS, ALLOC, LOAD, DATA + 2 .note 00000020 00000000 00000000 000000ae 2**0 + CONTENTS, READONLY +SYMBOL TABLE: +no symbols + + + +Disassembly of section .text: + +08048080 <.text>: + 8048080: b8 04 00 00 00 mov $0x4,%eax + 8048085: bb 01 00 00 00 mov $0x1,%ebx + 804808a: b9 a0 90 04 08 mov $0x80490a0,%ecx + 804808f: ba 0e 00 00 00 mov $0xe,%edx + 8048094: cd 80 int $0x80 + 8048096: b8 01 00 00 00 mov $0x1,%eax + 804809b: cd 80 int $0x80 + +Disassembly of section .data: + +080490a0 <.data>: + 80490a0: 48 dec %eax + 80490a1: 65 gs + 80490a2: 6c insb (%dx),%es:(%edi) + 80490a3: 6c insb (%dx),%es:(%edi) + 80490a4: 6f outsl %ds:(%esi),(%dx) + 80490a5: 2c 20 sub $0x20,%al + 80490a7: 57 push %edi + 80490a8: 6f outsl %ds:(%esi),(%dx) + 80490a9: 72 6c jb 0x8049117 + 80490ab: 64 21 0a and %ecx,%fs:(%edx) + +Disassembly of section .note: + +00000000 <.note>: + 0: 11 00 adc %eax,(%eax) + 2: 00 00 add %al,(%eax) + 4: 00 00 add %al,(%eax) + 6: 00 00 add %al,(%eax) + 8: 77 00 ja 0xa + a: 00 00 add %al,(%eax) + c: 43 inc %ebx + d: 72 65 jb 0x74 + f: 61 popa + 10: 74 65 je 0x77 + 12: 64 20 62 79 and %ah,%fs:0x79(%edx) + 16: 20 45 4c and %al,0x4c(%ebp) + 19: 46 inc %esi + 1a: 49 dec %ecx + 1b: 4f dec %edi + 1c: 00 00 add %al,(%eax) + ... diff --git a/elfio/elf_types.hpp b/elfio/elf_types.hpp index e5b341312ebc9d61920deebe35aa862a604f4809..ac7c2aafbedf469d4058126e0169d83eb5d57c97 100644 --- a/elfio/elf_types.hpp +++ b/elfio/elf_types.hpp @@ -1,710 +1,710 @@ -/* -Copyright (C) 2001-2011 by Serge Lamikhov-Center - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef ELFTYPES_H -#define ELFTYPES_H - -#ifndef ELFIO_NO_OWN_TYPES - #if !defined(ELFIO_NO_CSTDINT) && !defined(ELFIO_NO_INTTYPES) - #include <stdint.h> - #else - typedef unsigned char uint8_t; - typedef signed char int8_t; - typedef unsigned short uint16_t; - typedef signed short int16_t; - #ifdef _MSC_VER - typedef unsigned __int32 uint32_t; - typedef signed __int32 int32_t; - typedef unsigned __int64 uint64_t; - typedef signed __int64 int64_t; - #else - typedef unsigned int uint32_t; - typedef signed int int32_t; - typedef unsigned long long uint64_t; - typedef signed long long int64_t; - #endif // _MSC_VER - #endif // ELFIO_NO_CSTDINT -#endif // ELFIO_NO_OWN_TYPES - -namespace ELFIO { - -// Attention! Platform depended definitions. -typedef uint16_t Elf_Half; -typedef uint32_t Elf_Word; -typedef int32_t Elf_Sword; -typedef uint64_t Elf_Xword; -typedef int64_t Elf_Sxword; - -typedef uint32_t Elf32_Addr; -typedef uint32_t Elf32_Off; -typedef uint64_t Elf64_Addr; -typedef uint64_t Elf64_Off; - -#define Elf32_Half Elf_Half -#define Elf64_Half Elf_Half -#define Elf32_Word Elf_Word -#define Elf64_Word Elf_Word -#define Elf32_Sword Elf_Sword -#define Elf64_Sword Elf_Sword - -/////////////////////// -// ELF Header Constants - -// File type -#define ET_NONE 0 -#define ET_REL 1 -#define ET_EXEC 2 -#define ET_DYN 3 -#define ET_CORE 4 -#define ET_LOOS 0xFE00 -#define ET_HIOS 0xFEFF -#define ET_LOPROC 0xFF00 -#define ET_HIPROC 0xFFFF - - -#define EM_NONE 0 // No machine -#define EM_M32 1 // AT&T WE 32100 -#define EM_SPARC 2 // SUN SPARC -#define EM_386 3 // Intel 80386 -#define EM_68K 4 // Motorola m68k family -#define EM_88K 5 // Motorola m88k family -#define EM_486 6 // Intel 80486// Reserved for future use -#define EM_860 7 // Intel 80860 -#define EM_MIPS 8 // MIPS R3000 (officially, big-endian only) -#define EM_S370 9 // IBM System/370 -#define EM_MIPS_RS3_LE 10 // MIPS R3000 little-endian (Oct 4 1999 Draft) Deprecated -#define EM_res011 11 // Reserved -#define EM_res012 12 // Reserved -#define EM_res013 13 // Reserved -#define EM_res014 14 // Reserved -#define EM_PARISC 15 // HPPA -#define EM_res016 16 // Reserved -#define EM_VPP550 17 // Fujitsu VPP500 -#define EM_SPARC32PLUS 18 // Sun's "v8plus" -#define EM_960 19 // Intel 80960 -#define EM_PPC 20 // PowerPC -#define EM_PPC64 21 // 64-bit PowerPC -#define EM_S390 22 // IBM S/390 -#define EM_SPU 23 // Sony/Toshiba/IBM SPU -#define EM_res024 24 // Reserved -#define EM_res025 25 // Reserved -#define EM_res026 26 // Reserved -#define EM_res027 27 // Reserved -#define EM_res028 28 // Reserved -#define EM_res029 29 // Reserved -#define EM_res030 30 // Reserved -#define EM_res031 31 // Reserved -#define EM_res032 32 // Reserved -#define EM_res033 33 // Reserved -#define EM_res034 34 // Reserved -#define EM_res035 35 // Reserved -#define EM_V800 36 // NEC V800 series -#define EM_FR20 37 // Fujitsu FR20 -#define EM_RH32 38 // TRW RH32 -#define EM_MCORE 39 // Motorola M*Core // May also be taken by Fujitsu MMA -#define EM_RCE 39 // Old name for MCore -#define EM_ARM 40 // ARM -#define EM_OLD_ALPHA 41 // Digital Alpha -#define EM_SH 42 // Renesas (formerly Hitachi) / SuperH SH -#define EM_SPARCV9 43 // SPARC v9 64-bit -#define EM_TRICORE 44 // Siemens Tricore embedded processor -#define EM_ARC 45 // ARC Cores -#define EM_H8_300 46 // Renesas (formerly Hitachi) H8/300 -#define EM_H8_300H 47 // Renesas (formerly Hitachi) H8/300H -#define EM_H8S 48 // Renesas (formerly Hitachi) H8S -#define EM_H8_500 49 // Renesas (formerly Hitachi) H8/500 -#define EM_IA_64 50 // Intel IA-64 Processor -#define EM_MIPS_X 51 // Stanford MIPS-X -#define EM_COLDFIRE 52 // Motorola Coldfire -#define EM_68HC12 53 // Motorola M68HC12 -#define EM_MMA 54 // Fujitsu Multimedia Accelerator -#define EM_PCP 55 // Siemens PCP -#define EM_NCPU 56 // Sony nCPU embedded RISC processor -#define EM_NDR1 57 // Denso NDR1 microprocesspr -#define EM_STARCORE 58 // Motorola Star*Core processor -#define EM_ME16 59 // Toyota ME16 processor -#define EM_ST100 60 // STMicroelectronics ST100 processor -#define EM_TINYJ 61 // Advanced Logic Corp. TinyJ embedded processor -#define EM_X86_64 62 // Advanced Micro Devices X86-64 processor -#define EM_PDSP 63 // Sony DSP Processor -#define EM_PDP10 64 // Digital Equipment Corp. PDP-10 -#define EM_PDP11 65 // Digital Equipment Corp. PDP-11 -#define EM_FX66 66 // Siemens FX66 microcontroller -#define EM_ST9PLUS 67 // STMicroelectronics ST9+ 8/16 bit microcontroller -#define EM_ST7 68 // STMicroelectronics ST7 8-bit microcontroller -#define EM_68HC16 69 // Motorola MC68HC16 Microcontroller -#define EM_68HC11 70 // Motorola MC68HC11 Microcontroller -#define EM_68HC08 71 // Motorola MC68HC08 Microcontroller -#define EM_68HC05 72 // Motorola MC68HC05 Microcontroller -#define EM_SVX 73 // Silicon Graphics SVx -#define EM_ST19 74 // STMicroelectronics ST19 8-bit cpu -#define EM_VAX 75 // Digital VAX -#define EM_CRIS 76 // Axis Communications 32-bit embedded processor -#define EM_JAVELIN 77 // Infineon Technologies 32-bit embedded cpu -#define EM_FIREPATH 78 // Element 14 64-bit DSP processor -#define EM_ZSP 79 // LSI Logic's 16-bit DSP processor -#define EM_MMIX 80 // Donald Knuth's educational 64-bit processor -#define EM_HUANY 81 // Harvard's machine-independent format -#define EM_PRISM 82 // SiTera Prism -#define EM_AVR 83 // Atmel AVR 8-bit microcontroller -#define EM_FR30 84 // Fujitsu FR30 -#define EM_D10V 85 // Mitsubishi D10V -#define EM_D30V 86 // Mitsubishi D30V -#define EM_V850 87 // NEC v850 -#define EM_M32R 88 // Renesas M32R (formerly Mitsubishi M32R) -#define EM_MN10300 89 // Matsushita MN10300 -#define EM_MN10200 90 // Matsushita MN10200 -#define EM_PJ 91 // picoJava -#define EM_OPENRISC 92 // OpenRISC 32-bit embedded processor -#define EM_ARC_A5 93 // ARC Cores Tangent-A5 -#define EM_XTENSA 94 // Tensilica Xtensa Architecture -#define EM_VIDEOCORE 95 // Alphamosaic VideoCore processor -#define EM_TMM_GPP 96 // Thompson Multimedia General Purpose Processor -#define EM_NS32K 97 // National Semiconductor 32000 series -#define EM_TPC 98 // Tenor Network TPC processor -#define EM_SNP1K 99 // Trebia SNP 1000 processor -#define EM_ST200 100 // STMicroelectronics ST200 microcontroller -#define EM_IP2K 101 // Ubicom IP2022 micro controller -#define EM_MAX 102 // MAX Processor -#define EM_CR 103 // National Semiconductor CompactRISC -#define EM_F2MC16 104 // Fujitsu F2MC16 -#define EM_MSP430 105 // TI msp430 micro controller -#define EM_BLACKFIN 106 // ADI Blackfin -#define EM_SE_C33 107 // S1C33 Family of Seiko Epson processors -#define EM_SEP 108 // Sharp embedded microprocessor -#define EM_ARCA 109 // Arca RISC Microprocessor -#define EM_UNICORE 110 // Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University -#define EM_EXCESS 111 // eXcess: 16/32/64-bit configurable embedded CPU -#define EM_DXP 112 // Icera Semiconductor Inc. Deep Execution Processor -#define EM_ALTERA_NIOS2 113 // Altera Nios II soft-core processor -#define EM_CRX 114 // National Semiconductor CRX -#define EM_XGATE 115 // Motorola XGATE embedded processor -#define EM_C166 116 // Infineon C16x/XC16x processor -#define EM_M16C 117 // Renesas M16C series microprocessors -#define EM_DSPIC30F 118 // Microchip Technology dsPIC30F Digital Signal Controller -#define EM_CE 119 // Freescale Communication Engine RISC core -#define EM_M32C 120 // Renesas M32C series microprocessors -#define EM_res121 121 // Reserved -#define EM_res122 122 // Reserved -#define EM_res123 123 // Reserved -#define EM_res124 124 // Reserved -#define EM_res125 125 // Reserved -#define EM_res126 126 // Reserved -#define EM_res127 127 // Reserved -#define EM_res128 128 // Reserved -#define EM_res129 129 // Reserved -#define EM_res130 130 // Reserved -#define EM_TSK3000 131 // Altium TSK3000 core -#define EM_RS08 132 // Freescale RS08 embedded processor -#define EM_res133 133 // Reserved -#define EM_ECOG2 134 // Cyan Technology eCOG2 microprocessor -#define EM_SCORE 135 // Sunplus Score -#define EM_SCORE7 135 // Sunplus S+core7 RISC processor -#define EM_DSP24 136 // New Japan Radio (NJR) 24-bit DSP Processor -#define EM_VIDEOCORE3 137 // Broadcom VideoCore III processor -#define EM_LATTICEMICO32 138 // RISC processor for Lattice FPGA architecture -#define EM_SE_C17 139 // Seiko Epson C17 family -#define EM_TI_C6000 140 // Texas Instruments TMS320C6000 DSP family -#define EM_TI_C2000 141 // Texas Instruments TMS320C2000 DSP family -#define EM_TI_C5500 142 // Texas Instruments TMS320C55x DSP family -#define EM_res143 143 // Reserved -#define EM_res144 144 // Reserved -#define EM_res145 145 // Reserved -#define EM_res146 146 // Reserved -#define EM_res147 147 // Reserved -#define EM_res148 148 // Reserved -#define EM_res149 149 // Reserved -#define EM_res150 150 // Reserved -#define EM_res151 151 // Reserved -#define EM_res152 152 // Reserved -#define EM_res153 153 // Reserved -#define EM_res154 154 // Reserved -#define EM_res155 155 // Reserved -#define EM_res156 156 // Reserved -#define EM_res157 157 // Reserved -#define EM_res158 158 // Reserved -#define EM_res159 159 // Reserved -#define EM_MMDSP_PLUS 160 // STMicroelectronics 64bit VLIW Data Signal Processor -#define EM_CYPRESS_M8C 161 // Cypress M8C microprocessor -#define EM_R32C 162 // Renesas R32C series microprocessors -#define EM_TRIMEDIA 163 // NXP Semiconductors TriMedia architecture family -#define EM_QDSP6 164 // QUALCOMM DSP6 Processor -#define EM_8051 165 // Intel 8051 and variants -#define EM_STXP7X 166 // STMicroelectronics STxP7x family -#define EM_NDS32 167 // Andes Technology compact code size embedded RISC processor family -#define EM_ECOG1 168 // Cyan Technology eCOG1X family -#define EM_ECOG1X 168 // Cyan Technology eCOG1X family -#define EM_MAXQ30 169 // Dallas Semiconductor MAXQ30 Core Micro-controllers -#define EM_XIMO16 170 // New Japan Radio (NJR) 16-bit DSP Processor -#define EM_MANIK 171 // M2000 Reconfigurable RISC Microprocessor -#define EM_CRAYNV2 172 // Cray Inc. NV2 vector architecture -#define EM_RX 173 // Renesas RX family -#define EM_METAG 174 // Imagination Technologies META processor architecture -#define EM_MCST_ELBRUS 175 // MCST Elbrus general purpose hardware architecture -#define EM_ECOG16 176 // Cyan Technology eCOG16 family -#define EM_CR16 177 // National Semiconductor CompactRISC 16-bit processor -#define EM_ETPU 178 // Freescale Extended Time Processing Unit -#define EM_SLE9X 179 // Infineon Technologies SLE9X core -#define EM_L1OM 180 // Intel L1OM -#define EM_INTEL181 181 // Reserved by Intel -#define EM_INTEL182 182 // Reserved by Intel -#define EM_res183 183 // Reserved by ARM -#define EM_res184 184 // Reserved by ARM -#define EM_AVR32 185 // Atmel Corporation 32-bit microprocessor family -#define EM_STM8 186 // STMicroeletronics STM8 8-bit microcontroller -#define EM_TILE64 187 // Tilera TILE64 multicore architecture family -#define EM_TILEPRO 188 // Tilera TILEPro multicore architecture family -#define EM_MICROBLAZE 189 // Xilinx MicroBlaze 32-bit RISC soft processor core -#define EM_CUDA 190 // NVIDIA CUDA architecture - - -// File version -#define EV_NONE 0 -#define EV_CURRENT 1 - -// Identification index -#define EI_MAG0 0 -#define EI_MAG1 1 -#define EI_MAG2 2 -#define EI_MAG3 3 -#define EI_CLASS 4 -#define EI_DATA 5 -#define EI_VERSION 6 -#define EI_OSABI 7 -#define EI_ABIVERSION 8 -#define EI_PAD 9 -#define EI_NIDENT 16 - -// Magic number -#define ELFMAG0 0x7F -#define ELFMAG1 'E' -#define ELFMAG2 'L' -#define ELFMAG3 'F' - -// File class -#define ELFCLASSNONE 0 -#define ELFCLASS32 1 -#define ELFCLASS64 2 - -// Encoding -#define ELFDATANONE 0 -#define ELFDATA2LSB 1 -#define ELFDATA2MSB 2 - -// OS extensions -#define ELFOSABI_NONE 0 // No extensions or unspecified -#define ELFOSABI_HPUX 1 // Hewlett-Packard HP-UX -#define ELFOSABI_NETBSD 2 // NetBSD -#define ELFOSABI_LINUX 3 // Linux -#define ELFOSABI_SOLARIS 6 // Sun Solaris -#define ELFOSABI_AIX 7 // AIX -#define ELFOSABI_IRIX 8 // IRIX -#define ELFOSABI_FREEBSD 9 // FreeBSD -#define ELFOSABI_TRU64 10 // Compaq TRU64 UNIX -#define ELFOSABI_MODESTO 11 // Novell Modesto -#define ELFOSABI_OPENBSD 12 // Open BSD -#define ELFOSABI_OPENVMS 13 // Open VMS -#define ELFOSABI_NSK 14 // Hewlett-Packard Non-Stop Kernel -#define ELFOSABI_AROS 15 // Amiga Research OS -#define ELFOSABI_FENIXOS 16 // The FenixOS highly scalable multi-core OS -// 64-255 Architecture-specific value range - - - -///////////////////// -// Sections constants - -// Section indexes -#define SHN_UNDEF 0 -#define SHN_LORESERVE 0xFF00 -#define SHN_LOPROC 0xFF00 -#define SHN_HIPROC 0xFF1F -#define SHN_LOOS 0xFF20 -#define SHN_HIOS 0xFF3F -#define SHN_ABS 0xFFF1 -#define SHN_COMMON 0xFFF2 -#define SHN_XINDEX 0xFFFF -#define SHN_HIRESERVE 0xFFFF - -// Section types -#define SHT_NULL 0 -#define SHT_PROGBITS 1 -#define SHT_SYMTAB 2 -#define SHT_STRTAB 3 -#define SHT_RELA 4 -#define SHT_HASH 5 -#define SHT_DYNAMIC 6 -#define SHT_NOTE 7 -#define SHT_NOBITS 8 -#define SHT_REL 9 -#define SHT_SHLIB 10 -#define SHT_DYNSYM 11 -#define SHT_INIT_ARRAY 14 -#define SHT_FINI_ARRAY 15 -#define SHT_PREINIT_ARRAY 16 -#define SHT_GROUP 17 -#define SHT_SYMTAB_SHNDX 18 -#define SHT_LOOS 0x60000000 -#define SHT_HIOS 0x6fffffff -#define SHT_LOPROC 0x70000000 -#define SHT_HIPROC 0x7FFFFFFF -#define SHT_LOUSER 0x80000000 -#define SHT_HIUSER 0xFFFFFFFF - -// Section attribute flags -#define SHF_WRITE 0x1 -#define SHF_ALLOC 0x2 -#define SHF_EXECINSTR 0x4 -#define SHF_MERGE 0x10 -#define SHF_STRINGS 0x20 -#define SHF_INFO_LINK 0x40 -#define SHF_LINK_ORDER 0x80 -#define SHF_OS_NONCONFORMING 0x100 -#define SHF_GROUP 0x200 -#define SHF_TLS 0x400 -#define SHF_MASKOS 0x0ff00000 -#define SHF_MASKPROC 0xF0000000 - -// Section group flags -#define GRP_COMDAT 0x1 -#define GRP_MASKOS 0x0ff00000 -#define GRP_MASKPROC 0xf0000000 - -// Symbol binding -#define STB_LOCAL 0 -#define STB_GLOBAL 1 -#define STB_WEAK 2 -#define STB_LOOS 10 -#define STB_HIOS 12 -#define STB_MULTIDEF 13 -#define STB_LOPROC 13 -#define STB_HIPROC 15 - -// Symbol types -#define STT_NOTYPE 0 -#define STT_OBJECT 1 -#define STT_FUNC 2 -#define STT_SECTION 3 -#define STT_FILE 4 -#define STT_COMMON 5 -#define STT_TLS 6 -#define STT_LOOS 10 -#define STT_HIOS 12 -#define STT_LOPROC 13 -#define STT_HIPROC 15 - -// Symbol visibility -#define STV_DEFAULT 0 -#define STV_INTERNAL 1 -#define STV_HIDDEN 2 -#define STV_PROTECTED 3 - -// Undefined name -#define STN_UNDEF 0 - -// Relocation types -#define R_386_NONE 0 -#define R_X86_64_NONE 0 -#define R_386_32 1 -#define R_X86_64_64 1 -#define R_386_PC32 2 -#define R_X86_64_PC32 2 -#define R_386_GOT32 3 -#define R_X86_64_GOT32 3 -#define R_386_PLT32 4 -#define R_X86_64_PLT32 4 -#define R_386_COPY 5 -#define R_X86_64_COPY 5 -#define R_386_GLOB_DAT 6 -#define R_X86_64_GLOB_DAT 6 -#define R_386_JMP_SLOT 7 -#define R_X86_64_JUMP_SLOT 7 -#define R_386_RELATIVE 8 -#define R_X86_64_RELATIVE 8 -#define R_386_GOTOFF 9 -#define R_X86_64_GOTPCREL 9 -#define R_386_GOTPC 10 -#define R_X86_64_32 10 -#define R_X86_64_32S 11 -#define R_X86_64_16 12 -#define R_X86_64_PC16 13 -#define R_X86_64_8 14 -#define R_X86_64_PC8 15 -#define R_X86_64_DTPMOD64 16 -#define R_X86_64_DTPOFF64 17 -#define R_X86_64_TPOFF64 18 -#define R_X86_64_TLSGD 19 -#define R_X86_64_TLSLD 20 -#define R_X86_64_DTPOFF32 21 -#define R_X86_64_GOTTPOFF 22 -#define R_X86_64_TPOFF32 23 -#define R_X86_64_PC64 24 -#define R_X86_64_GOTOFF64 25 -#define R_X86_64_GOTPC32 26 -#define R_X86_64_GOT64 27 -#define R_X86_64_GOTPCREL64 28 -#define R_X86_64_GOTPC64 29 -#define R_X86_64_GOTPLT64 30 -#define R_X86_64_PLTOFF64 31 -#define R_X86_64_GOTPC32_TLSDESC 34 -#define R_X86_64_TLSDESC_CALL 35 -#define R_X86_64_TLSDESC 36 -#define R_X86_64_IRELATIVE 37 -#define R_X86_64_GNU_VTINHERIT 250 -#define R_X86_64_GNU_VTENTRY 251 - -// Segment types -#define PT_NULL 0 -#define PT_LOAD 1 -#define PT_DYNAMIC 2 -#define PT_INTERP 3 -#define PT_NOTE 4 -#define PT_SHLIB 5 -#define PT_PHDR 6 -#define PT_TLS 7 -#define PT_LOOS 0x60000000 -#define PT_HIOS 0x6fffffff -#define PT_LOPROC 0x70000000 -#define PT_HIPROC 0x7FFFFFFF - -// Segment flags -#define PF_X 1 // Execute -#define PF_W 2 // Write -#define PF_R 4 // Read -#define PF_MASKOS 0x0ff00000 // Unspecified -#define PF_MASKPROC 0xf0000000 // Unspecified - -// Dynamic Array Tags -#define DT_NULL 0 -#define DT_NEEDED 1 -#define DT_PLTRELSZ 2 -#define DT_PLTGOT 3 -#define DT_HASH 4 -#define DT_STRTAB 5 -#define DT_SYMTAB 6 -#define DT_RELA 7 -#define DT_RELASZ 8 -#define DT_RELAENT 9 -#define DT_STRSZ 10 -#define DT_SYMENT 11 -#define DT_INIT 12 -#define DT_FINI 13 -#define DT_SONAME 14 -#define DT_RPATH 15 -#define DT_SYMBOLIC 16 -#define DT_REL 17 -#define DT_RELSZ 18 -#define DT_RELENT 19 -#define DT_PLTREL 20 -#define DT_DEBUG 21 -#define DT_TEXTREL 22 -#define DT_JMPREL 23 -#define DT_BIND_NOW 24 -#define DT_INIT_ARRAY 25 -#define DT_FINI_ARRAY 26 -#define DT_INIT_ARRAYSZ 27 -#define DT_FINI_ARRAYSZ 28 -#define DT_RUNPATH 29 -#define DT_FLAGS 30 -#define DT_ENCODING 32 -#define DT_PREINIT_ARRAY 32 -#define DT_PREINIT_ARRAYSZ 33 -#define DT_LOOS 0x6000000D -#define DT_HIOS 0x6ffff000 -#define DT_LOPROC 0x70000000 -#define DT_HIPROC 0x7FFFFFFF - -// DT_FLAGS values -#define DF_ORIGIN 0x1 -#define DF_SYMBOLIC 0x2 -#define DF_TEXTREL 0x4 -#define DF_BIND_NOW 0x8 -#define DF_STATIC_TLS 0x10 - - -// ELF file header -struct Elf32_Ehdr { - unsigned char e_ident[EI_NIDENT]; - Elf_Half e_type; - Elf_Half e_machine; - Elf_Word e_version; - Elf32_Addr e_entry; - Elf32_Off e_phoff; - Elf32_Off e_shoff; - Elf_Word e_flags; - Elf_Half e_ehsize; - Elf_Half e_phentsize; - Elf_Half e_phnum; - Elf_Half e_shentsize; - Elf_Half e_shnum; - Elf_Half e_shstrndx; -}; - -struct Elf64_Ehdr { - unsigned char e_ident[EI_NIDENT]; - Elf_Half e_type; - Elf_Half e_machine; - Elf_Word e_version; - Elf64_Addr e_entry; - Elf64_Off e_phoff; - Elf64_Off e_shoff; - Elf_Word e_flags; - Elf_Half e_ehsize; - Elf_Half e_phentsize; - Elf_Half e_phnum; - Elf_Half e_shentsize; - Elf_Half e_shnum; - Elf_Half e_shstrndx; -}; - - -// Section header -struct Elf32_Shdr { - Elf_Word sh_name; - Elf_Word sh_type; - Elf_Word sh_flags; - Elf32_Addr sh_addr; - Elf32_Off sh_offset; - Elf_Word sh_size; - Elf_Word sh_link; - Elf_Word sh_info; - Elf_Word sh_addralign; - Elf_Word sh_entsize; -}; - -struct Elf64_Shdr { - Elf_Word sh_name; - Elf_Word sh_type; - Elf_Xword sh_flags; - Elf64_Addr sh_addr; - Elf64_Off sh_offset; - Elf_Xword sh_size; - Elf_Word sh_link; - Elf_Word sh_info; - Elf_Xword sh_addralign; - Elf_Xword sh_entsize; -}; - - -// Segment header -struct Elf32_Phdr { - Elf_Word p_type; - Elf32_Off p_offset; - Elf32_Addr p_vaddr; - Elf32_Addr p_paddr; - Elf_Word p_filesz; - Elf_Word p_memsz; - Elf_Word p_flags; - Elf_Word p_align; -}; - -struct Elf64_Phdr { - Elf_Word p_type; - Elf_Word p_flags; - Elf64_Off p_offset; - Elf64_Addr p_vaddr; - Elf64_Addr p_paddr; - Elf_Xword p_filesz; - Elf_Xword p_memsz; - Elf_Xword p_align; -}; - - -// Symbol table entry -struct Elf32_Sym { - Elf_Word st_name; - Elf32_Addr st_value; - Elf_Word st_size; - unsigned char st_info; - unsigned char st_other; - Elf_Half st_shndx; -}; - -struct Elf64_Sym { - Elf_Word st_name; - unsigned char st_info; - unsigned char st_other; - Elf_Half st_shndx; - Elf64_Addr st_value; - Elf_Xword st_size; -}; - - -#define ELF_ST_BIND(i) ((i)>>4) -#define ELF_ST_TYPE(i) ((i)&0xf) -#define ELF_ST_INFO(b,t) (((b)<<4)+((t)&0xf)) - -#define ELF_ST_VISIBILITY(o) ((o)&0x3) - - -// Relocation entries -struct Elf32_Rel { - Elf32_Addr r_offset; - Elf_Word r_info; -}; - -struct Elf32_Rela { - Elf32_Addr r_offset; - Elf_Word r_info; - Elf_Sword r_addend; -}; - -struct Elf64_Rel { - Elf64_Addr r_offset; - Elf_Xword r_info; -}; - -struct Elf64_Rela { - Elf64_Addr r_offset; - Elf_Xword r_info; - Elf_Sxword r_addend; -}; - - -#define ELF32_R_SYM(i) ((i)>>8) -#define ELF32_R_TYPE(i) ((unsigned char)(i)) -#define ELF32_R_INFO(s,t) (((s)<<8 )+(unsigned char)(t)) - -#define ELF64_R_SYM(i) ((i)>>32) -#define ELF64_R_TYPE(i) ((i)&0xffffffffL) -#define ELF64_R_INFO(s,t) ((((int64_t)s)<<32)+((t)&0xffffffffL)) - -// Dynamic structure -struct Elf32_Dyn { - Elf_Sword d_tag; - union { - Elf_Word d_val; - Elf32_Addr d_ptr; - } d_un; -}; - -struct Elf64_Dyn { - Elf_Sxword d_tag; - union { - Elf_Xword d_val; - Elf64_Addr d_ptr; - } d_un; -}; - -} // namespace ELFIO - -#endif // ELFTYPES_H +/* +Copyright (C) 2001-2011 by Serge Lamikhov-Center + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef ELFTYPES_H +#define ELFTYPES_H + +#ifndef ELFIO_NO_OWN_TYPES + #if !defined(ELFIO_NO_CSTDINT) && !defined(ELFIO_NO_INTTYPES) + #include <stdint.h> + #else + typedef unsigned char uint8_t; + typedef signed char int8_t; + typedef unsigned short uint16_t; + typedef signed short int16_t; + #ifdef _MSC_VER + typedef unsigned __int32 uint32_t; + typedef signed __int32 int32_t; + typedef unsigned __int64 uint64_t; + typedef signed __int64 int64_t; + #else + typedef unsigned int uint32_t; + typedef signed int int32_t; + typedef unsigned long long uint64_t; + typedef signed long long int64_t; + #endif // _MSC_VER + #endif // ELFIO_NO_CSTDINT +#endif // ELFIO_NO_OWN_TYPES + +namespace ELFIO { + +// Attention! Platform depended definitions. +typedef uint16_t Elf_Half; +typedef uint32_t Elf_Word; +typedef int32_t Elf_Sword; +typedef uint64_t Elf_Xword; +typedef int64_t Elf_Sxword; + +typedef uint32_t Elf32_Addr; +typedef uint32_t Elf32_Off; +typedef uint64_t Elf64_Addr; +typedef uint64_t Elf64_Off; + +#define Elf32_Half Elf_Half +#define Elf64_Half Elf_Half +#define Elf32_Word Elf_Word +#define Elf64_Word Elf_Word +#define Elf32_Sword Elf_Sword +#define Elf64_Sword Elf_Sword + +/////////////////////// +// ELF Header Constants + +// File type +#define ET_NONE 0 +#define ET_REL 1 +#define ET_EXEC 2 +#define ET_DYN 3 +#define ET_CORE 4 +#define ET_LOOS 0xFE00 +#define ET_HIOS 0xFEFF +#define ET_LOPROC 0xFF00 +#define ET_HIPROC 0xFFFF + + +#define EM_NONE 0 // No machine +#define EM_M32 1 // AT&T WE 32100 +#define EM_SPARC 2 // SUN SPARC +#define EM_386 3 // Intel 80386 +#define EM_68K 4 // Motorola m68k family +#define EM_88K 5 // Motorola m88k family +#define EM_486 6 // Intel 80486// Reserved for future use +#define EM_860 7 // Intel 80860 +#define EM_MIPS 8 // MIPS R3000 (officially, big-endian only) +#define EM_S370 9 // IBM System/370 +#define EM_MIPS_RS3_LE 10 // MIPS R3000 little-endian (Oct 4 1999 Draft) Deprecated +#define EM_res011 11 // Reserved +#define EM_res012 12 // Reserved +#define EM_res013 13 // Reserved +#define EM_res014 14 // Reserved +#define EM_PARISC 15 // HPPA +#define EM_res016 16 // Reserved +#define EM_VPP550 17 // Fujitsu VPP500 +#define EM_SPARC32PLUS 18 // Sun's "v8plus" +#define EM_960 19 // Intel 80960 +#define EM_PPC 20 // PowerPC +#define EM_PPC64 21 // 64-bit PowerPC +#define EM_S390 22 // IBM S/390 +#define EM_SPU 23 // Sony/Toshiba/IBM SPU +#define EM_res024 24 // Reserved +#define EM_res025 25 // Reserved +#define EM_res026 26 // Reserved +#define EM_res027 27 // Reserved +#define EM_res028 28 // Reserved +#define EM_res029 29 // Reserved +#define EM_res030 30 // Reserved +#define EM_res031 31 // Reserved +#define EM_res032 32 // Reserved +#define EM_res033 33 // Reserved +#define EM_res034 34 // Reserved +#define EM_res035 35 // Reserved +#define EM_V800 36 // NEC V800 series +#define EM_FR20 37 // Fujitsu FR20 +#define EM_RH32 38 // TRW RH32 +#define EM_MCORE 39 // Motorola M*Core // May also be taken by Fujitsu MMA +#define EM_RCE 39 // Old name for MCore +#define EM_ARM 40 // ARM +#define EM_OLD_ALPHA 41 // Digital Alpha +#define EM_SH 42 // Renesas (formerly Hitachi) / SuperH SH +#define EM_SPARCV9 43 // SPARC v9 64-bit +#define EM_TRICORE 44 // Siemens Tricore embedded processor +#define EM_ARC 45 // ARC Cores +#define EM_H8_300 46 // Renesas (formerly Hitachi) H8/300 +#define EM_H8_300H 47 // Renesas (formerly Hitachi) H8/300H +#define EM_H8S 48 // Renesas (formerly Hitachi) H8S +#define EM_H8_500 49 // Renesas (formerly Hitachi) H8/500 +#define EM_IA_64 50 // Intel IA-64 Processor +#define EM_MIPS_X 51 // Stanford MIPS-X +#define EM_COLDFIRE 52 // Motorola Coldfire +#define EM_68HC12 53 // Motorola M68HC12 +#define EM_MMA 54 // Fujitsu Multimedia Accelerator +#define EM_PCP 55 // Siemens PCP +#define EM_NCPU 56 // Sony nCPU embedded RISC processor +#define EM_NDR1 57 // Denso NDR1 microprocesspr +#define EM_STARCORE 58 // Motorola Star*Core processor +#define EM_ME16 59 // Toyota ME16 processor +#define EM_ST100 60 // STMicroelectronics ST100 processor +#define EM_TINYJ 61 // Advanced Logic Corp. TinyJ embedded processor +#define EM_X86_64 62 // Advanced Micro Devices X86-64 processor +#define EM_PDSP 63 // Sony DSP Processor +#define EM_PDP10 64 // Digital Equipment Corp. PDP-10 +#define EM_PDP11 65 // Digital Equipment Corp. PDP-11 +#define EM_FX66 66 // Siemens FX66 microcontroller +#define EM_ST9PLUS 67 // STMicroelectronics ST9+ 8/16 bit microcontroller +#define EM_ST7 68 // STMicroelectronics ST7 8-bit microcontroller +#define EM_68HC16 69 // Motorola MC68HC16 Microcontroller +#define EM_68HC11 70 // Motorola MC68HC11 Microcontroller +#define EM_68HC08 71 // Motorola MC68HC08 Microcontroller +#define EM_68HC05 72 // Motorola MC68HC05 Microcontroller +#define EM_SVX 73 // Silicon Graphics SVx +#define EM_ST19 74 // STMicroelectronics ST19 8-bit cpu +#define EM_VAX 75 // Digital VAX +#define EM_CRIS 76 // Axis Communications 32-bit embedded processor +#define EM_JAVELIN 77 // Infineon Technologies 32-bit embedded cpu +#define EM_FIREPATH 78 // Element 14 64-bit DSP processor +#define EM_ZSP 79 // LSI Logic's 16-bit DSP processor +#define EM_MMIX 80 // Donald Knuth's educational 64-bit processor +#define EM_HUANY 81 // Harvard's machine-independent format +#define EM_PRISM 82 // SiTera Prism +#define EM_AVR 83 // Atmel AVR 8-bit microcontroller +#define EM_FR30 84 // Fujitsu FR30 +#define EM_D10V 85 // Mitsubishi D10V +#define EM_D30V 86 // Mitsubishi D30V +#define EM_V850 87 // NEC v850 +#define EM_M32R 88 // Renesas M32R (formerly Mitsubishi M32R) +#define EM_MN10300 89 // Matsushita MN10300 +#define EM_MN10200 90 // Matsushita MN10200 +#define EM_PJ 91 // picoJava +#define EM_OPENRISC 92 // OpenRISC 32-bit embedded processor +#define EM_ARC_A5 93 // ARC Cores Tangent-A5 +#define EM_XTENSA 94 // Tensilica Xtensa Architecture +#define EM_VIDEOCORE 95 // Alphamosaic VideoCore processor +#define EM_TMM_GPP 96 // Thompson Multimedia General Purpose Processor +#define EM_NS32K 97 // National Semiconductor 32000 series +#define EM_TPC 98 // Tenor Network TPC processor +#define EM_SNP1K 99 // Trebia SNP 1000 processor +#define EM_ST200 100 // STMicroelectronics ST200 microcontroller +#define EM_IP2K 101 // Ubicom IP2022 micro controller +#define EM_MAX 102 // MAX Processor +#define EM_CR 103 // National Semiconductor CompactRISC +#define EM_F2MC16 104 // Fujitsu F2MC16 +#define EM_MSP430 105 // TI msp430 micro controller +#define EM_BLACKFIN 106 // ADI Blackfin +#define EM_SE_C33 107 // S1C33 Family of Seiko Epson processors +#define EM_SEP 108 // Sharp embedded microprocessor +#define EM_ARCA 109 // Arca RISC Microprocessor +#define EM_UNICORE 110 // Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University +#define EM_EXCESS 111 // eXcess: 16/32/64-bit configurable embedded CPU +#define EM_DXP 112 // Icera Semiconductor Inc. Deep Execution Processor +#define EM_ALTERA_NIOS2 113 // Altera Nios II soft-core processor +#define EM_CRX 114 // National Semiconductor CRX +#define EM_XGATE 115 // Motorola XGATE embedded processor +#define EM_C166 116 // Infineon C16x/XC16x processor +#define EM_M16C 117 // Renesas M16C series microprocessors +#define EM_DSPIC30F 118 // Microchip Technology dsPIC30F Digital Signal Controller +#define EM_CE 119 // Freescale Communication Engine RISC core +#define EM_M32C 120 // Renesas M32C series microprocessors +#define EM_res121 121 // Reserved +#define EM_res122 122 // Reserved +#define EM_res123 123 // Reserved +#define EM_res124 124 // Reserved +#define EM_res125 125 // Reserved +#define EM_res126 126 // Reserved +#define EM_res127 127 // Reserved +#define EM_res128 128 // Reserved +#define EM_res129 129 // Reserved +#define EM_res130 130 // Reserved +#define EM_TSK3000 131 // Altium TSK3000 core +#define EM_RS08 132 // Freescale RS08 embedded processor +#define EM_res133 133 // Reserved +#define EM_ECOG2 134 // Cyan Technology eCOG2 microprocessor +#define EM_SCORE 135 // Sunplus Score +#define EM_SCORE7 135 // Sunplus S+core7 RISC processor +#define EM_DSP24 136 // New Japan Radio (NJR) 24-bit DSP Processor +#define EM_VIDEOCORE3 137 // Broadcom VideoCore III processor +#define EM_LATTICEMICO32 138 // RISC processor for Lattice FPGA architecture +#define EM_SE_C17 139 // Seiko Epson C17 family +#define EM_TI_C6000 140 // Texas Instruments TMS320C6000 DSP family +#define EM_TI_C2000 141 // Texas Instruments TMS320C2000 DSP family +#define EM_TI_C5500 142 // Texas Instruments TMS320C55x DSP family +#define EM_res143 143 // Reserved +#define EM_res144 144 // Reserved +#define EM_res145 145 // Reserved +#define EM_res146 146 // Reserved +#define EM_res147 147 // Reserved +#define EM_res148 148 // Reserved +#define EM_res149 149 // Reserved +#define EM_res150 150 // Reserved +#define EM_res151 151 // Reserved +#define EM_res152 152 // Reserved +#define EM_res153 153 // Reserved +#define EM_res154 154 // Reserved +#define EM_res155 155 // Reserved +#define EM_res156 156 // Reserved +#define EM_res157 157 // Reserved +#define EM_res158 158 // Reserved +#define EM_res159 159 // Reserved +#define EM_MMDSP_PLUS 160 // STMicroelectronics 64bit VLIW Data Signal Processor +#define EM_CYPRESS_M8C 161 // Cypress M8C microprocessor +#define EM_R32C 162 // Renesas R32C series microprocessors +#define EM_TRIMEDIA 163 // NXP Semiconductors TriMedia architecture family +#define EM_QDSP6 164 // QUALCOMM DSP6 Processor +#define EM_8051 165 // Intel 8051 and variants +#define EM_STXP7X 166 // STMicroelectronics STxP7x family +#define EM_NDS32 167 // Andes Technology compact code size embedded RISC processor family +#define EM_ECOG1 168 // Cyan Technology eCOG1X family +#define EM_ECOG1X 168 // Cyan Technology eCOG1X family +#define EM_MAXQ30 169 // Dallas Semiconductor MAXQ30 Core Micro-controllers +#define EM_XIMO16 170 // New Japan Radio (NJR) 16-bit DSP Processor +#define EM_MANIK 171 // M2000 Reconfigurable RISC Microprocessor +#define EM_CRAYNV2 172 // Cray Inc. NV2 vector architecture +#define EM_RX 173 // Renesas RX family +#define EM_METAG 174 // Imagination Technologies META processor architecture +#define EM_MCST_ELBRUS 175 // MCST Elbrus general purpose hardware architecture +#define EM_ECOG16 176 // Cyan Technology eCOG16 family +#define EM_CR16 177 // National Semiconductor CompactRISC 16-bit processor +#define EM_ETPU 178 // Freescale Extended Time Processing Unit +#define EM_SLE9X 179 // Infineon Technologies SLE9X core +#define EM_L1OM 180 // Intel L1OM +#define EM_INTEL181 181 // Reserved by Intel +#define EM_INTEL182 182 // Reserved by Intel +#define EM_res183 183 // Reserved by ARM +#define EM_res184 184 // Reserved by ARM +#define EM_AVR32 185 // Atmel Corporation 32-bit microprocessor family +#define EM_STM8 186 // STMicroeletronics STM8 8-bit microcontroller +#define EM_TILE64 187 // Tilera TILE64 multicore architecture family +#define EM_TILEPRO 188 // Tilera TILEPro multicore architecture family +#define EM_MICROBLAZE 189 // Xilinx MicroBlaze 32-bit RISC soft processor core +#define EM_CUDA 190 // NVIDIA CUDA architecture + + +// File version +#define EV_NONE 0 +#define EV_CURRENT 1 + +// Identification index +#define EI_MAG0 0 +#define EI_MAG1 1 +#define EI_MAG2 2 +#define EI_MAG3 3 +#define EI_CLASS 4 +#define EI_DATA 5 +#define EI_VERSION 6 +#define EI_OSABI 7 +#define EI_ABIVERSION 8 +#define EI_PAD 9 +#define EI_NIDENT 16 + +// Magic number +#define ELFMAG0 0x7F +#define ELFMAG1 'E' +#define ELFMAG2 'L' +#define ELFMAG3 'F' + +// File class +#define ELFCLASSNONE 0 +#define ELFCLASS32 1 +#define ELFCLASS64 2 + +// Encoding +#define ELFDATANONE 0 +#define ELFDATA2LSB 1 +#define ELFDATA2MSB 2 + +// OS extensions +#define ELFOSABI_NONE 0 // No extensions or unspecified +#define ELFOSABI_HPUX 1 // Hewlett-Packard HP-UX +#define ELFOSABI_NETBSD 2 // NetBSD +#define ELFOSABI_LINUX 3 // Linux +#define ELFOSABI_SOLARIS 6 // Sun Solaris +#define ELFOSABI_AIX 7 // AIX +#define ELFOSABI_IRIX 8 // IRIX +#define ELFOSABI_FREEBSD 9 // FreeBSD +#define ELFOSABI_TRU64 10 // Compaq TRU64 UNIX +#define ELFOSABI_MODESTO 11 // Novell Modesto +#define ELFOSABI_OPENBSD 12 // Open BSD +#define ELFOSABI_OPENVMS 13 // Open VMS +#define ELFOSABI_NSK 14 // Hewlett-Packard Non-Stop Kernel +#define ELFOSABI_AROS 15 // Amiga Research OS +#define ELFOSABI_FENIXOS 16 // The FenixOS highly scalable multi-core OS +// 64-255 Architecture-specific value range + + + +///////////////////// +// Sections constants + +// Section indexes +#define SHN_UNDEF 0 +#define SHN_LORESERVE 0xFF00 +#define SHN_LOPROC 0xFF00 +#define SHN_HIPROC 0xFF1F +#define SHN_LOOS 0xFF20 +#define SHN_HIOS 0xFF3F +#define SHN_ABS 0xFFF1 +#define SHN_COMMON 0xFFF2 +#define SHN_XINDEX 0xFFFF +#define SHN_HIRESERVE 0xFFFF + +// Section types +#define SHT_NULL 0 +#define SHT_PROGBITS 1 +#define SHT_SYMTAB 2 +#define SHT_STRTAB 3 +#define SHT_RELA 4 +#define SHT_HASH 5 +#define SHT_DYNAMIC 6 +#define SHT_NOTE 7 +#define SHT_NOBITS 8 +#define SHT_REL 9 +#define SHT_SHLIB 10 +#define SHT_DYNSYM 11 +#define SHT_INIT_ARRAY 14 +#define SHT_FINI_ARRAY 15 +#define SHT_PREINIT_ARRAY 16 +#define SHT_GROUP 17 +#define SHT_SYMTAB_SHNDX 18 +#define SHT_LOOS 0x60000000 +#define SHT_HIOS 0x6fffffff +#define SHT_LOPROC 0x70000000 +#define SHT_HIPROC 0x7FFFFFFF +#define SHT_LOUSER 0x80000000 +#define SHT_HIUSER 0xFFFFFFFF + +// Section attribute flags +#define SHF_WRITE 0x1 +#define SHF_ALLOC 0x2 +#define SHF_EXECINSTR 0x4 +#define SHF_MERGE 0x10 +#define SHF_STRINGS 0x20 +#define SHF_INFO_LINK 0x40 +#define SHF_LINK_ORDER 0x80 +#define SHF_OS_NONCONFORMING 0x100 +#define SHF_GROUP 0x200 +#define SHF_TLS 0x400 +#define SHF_MASKOS 0x0ff00000 +#define SHF_MASKPROC 0xF0000000 + +// Section group flags +#define GRP_COMDAT 0x1 +#define GRP_MASKOS 0x0ff00000 +#define GRP_MASKPROC 0xf0000000 + +// Symbol binding +#define STB_LOCAL 0 +#define STB_GLOBAL 1 +#define STB_WEAK 2 +#define STB_LOOS 10 +#define STB_HIOS 12 +#define STB_MULTIDEF 13 +#define STB_LOPROC 13 +#define STB_HIPROC 15 + +// Symbol types +#define STT_NOTYPE 0 +#define STT_OBJECT 1 +#define STT_FUNC 2 +#define STT_SECTION 3 +#define STT_FILE 4 +#define STT_COMMON 5 +#define STT_TLS 6 +#define STT_LOOS 10 +#define STT_HIOS 12 +#define STT_LOPROC 13 +#define STT_HIPROC 15 + +// Symbol visibility +#define STV_DEFAULT 0 +#define STV_INTERNAL 1 +#define STV_HIDDEN 2 +#define STV_PROTECTED 3 + +// Undefined name +#define STN_UNDEF 0 + +// Relocation types +#define R_386_NONE 0 +#define R_X86_64_NONE 0 +#define R_386_32 1 +#define R_X86_64_64 1 +#define R_386_PC32 2 +#define R_X86_64_PC32 2 +#define R_386_GOT32 3 +#define R_X86_64_GOT32 3 +#define R_386_PLT32 4 +#define R_X86_64_PLT32 4 +#define R_386_COPY 5 +#define R_X86_64_COPY 5 +#define R_386_GLOB_DAT 6 +#define R_X86_64_GLOB_DAT 6 +#define R_386_JMP_SLOT 7 +#define R_X86_64_JUMP_SLOT 7 +#define R_386_RELATIVE 8 +#define R_X86_64_RELATIVE 8 +#define R_386_GOTOFF 9 +#define R_X86_64_GOTPCREL 9 +#define R_386_GOTPC 10 +#define R_X86_64_32 10 +#define R_X86_64_32S 11 +#define R_X86_64_16 12 +#define R_X86_64_PC16 13 +#define R_X86_64_8 14 +#define R_X86_64_PC8 15 +#define R_X86_64_DTPMOD64 16 +#define R_X86_64_DTPOFF64 17 +#define R_X86_64_TPOFF64 18 +#define R_X86_64_TLSGD 19 +#define R_X86_64_TLSLD 20 +#define R_X86_64_DTPOFF32 21 +#define R_X86_64_GOTTPOFF 22 +#define R_X86_64_TPOFF32 23 +#define R_X86_64_PC64 24 +#define R_X86_64_GOTOFF64 25 +#define R_X86_64_GOTPC32 26 +#define R_X86_64_GOT64 27 +#define R_X86_64_GOTPCREL64 28 +#define R_X86_64_GOTPC64 29 +#define R_X86_64_GOTPLT64 30 +#define R_X86_64_PLTOFF64 31 +#define R_X86_64_GOTPC32_TLSDESC 34 +#define R_X86_64_TLSDESC_CALL 35 +#define R_X86_64_TLSDESC 36 +#define R_X86_64_IRELATIVE 37 +#define R_X86_64_GNU_VTINHERIT 250 +#define R_X86_64_GNU_VTENTRY 251 + +// Segment types +#define PT_NULL 0 +#define PT_LOAD 1 +#define PT_DYNAMIC 2 +#define PT_INTERP 3 +#define PT_NOTE 4 +#define PT_SHLIB 5 +#define PT_PHDR 6 +#define PT_TLS 7 +#define PT_LOOS 0x60000000 +#define PT_HIOS 0x6fffffff +#define PT_LOPROC 0x70000000 +#define PT_HIPROC 0x7FFFFFFF + +// Segment flags +#define PF_X 1 // Execute +#define PF_W 2 // Write +#define PF_R 4 // Read +#define PF_MASKOS 0x0ff00000 // Unspecified +#define PF_MASKPROC 0xf0000000 // Unspecified + +// Dynamic Array Tags +#define DT_NULL 0 +#define DT_NEEDED 1 +#define DT_PLTRELSZ 2 +#define DT_PLTGOT 3 +#define DT_HASH 4 +#define DT_STRTAB 5 +#define DT_SYMTAB 6 +#define DT_RELA 7 +#define DT_RELASZ 8 +#define DT_RELAENT 9 +#define DT_STRSZ 10 +#define DT_SYMENT 11 +#define DT_INIT 12 +#define DT_FINI 13 +#define DT_SONAME 14 +#define DT_RPATH 15 +#define DT_SYMBOLIC 16 +#define DT_REL 17 +#define DT_RELSZ 18 +#define DT_RELENT 19 +#define DT_PLTREL 20 +#define DT_DEBUG 21 +#define DT_TEXTREL 22 +#define DT_JMPREL 23 +#define DT_BIND_NOW 24 +#define DT_INIT_ARRAY 25 +#define DT_FINI_ARRAY 26 +#define DT_INIT_ARRAYSZ 27 +#define DT_FINI_ARRAYSZ 28 +#define DT_RUNPATH 29 +#define DT_FLAGS 30 +#define DT_ENCODING 32 +#define DT_PREINIT_ARRAY 32 +#define DT_PREINIT_ARRAYSZ 33 +#define DT_LOOS 0x6000000D +#define DT_HIOS 0x6ffff000 +#define DT_LOPROC 0x70000000 +#define DT_HIPROC 0x7FFFFFFF + +// DT_FLAGS values +#define DF_ORIGIN 0x1 +#define DF_SYMBOLIC 0x2 +#define DF_TEXTREL 0x4 +#define DF_BIND_NOW 0x8 +#define DF_STATIC_TLS 0x10 + + +// ELF file header +struct Elf32_Ehdr { + unsigned char e_ident[EI_NIDENT]; + Elf_Half e_type; + Elf_Half e_machine; + Elf_Word e_version; + Elf32_Addr e_entry; + Elf32_Off e_phoff; + Elf32_Off e_shoff; + Elf_Word e_flags; + Elf_Half e_ehsize; + Elf_Half e_phentsize; + Elf_Half e_phnum; + Elf_Half e_shentsize; + Elf_Half e_shnum; + Elf_Half e_shstrndx; +}; + +struct Elf64_Ehdr { + unsigned char e_ident[EI_NIDENT]; + Elf_Half e_type; + Elf_Half e_machine; + Elf_Word e_version; + Elf64_Addr e_entry; + Elf64_Off e_phoff; + Elf64_Off e_shoff; + Elf_Word e_flags; + Elf_Half e_ehsize; + Elf_Half e_phentsize; + Elf_Half e_phnum; + Elf_Half e_shentsize; + Elf_Half e_shnum; + Elf_Half e_shstrndx; +}; + + +// Section header +struct Elf32_Shdr { + Elf_Word sh_name; + Elf_Word sh_type; + Elf_Word sh_flags; + Elf32_Addr sh_addr; + Elf32_Off sh_offset; + Elf_Word sh_size; + Elf_Word sh_link; + Elf_Word sh_info; + Elf_Word sh_addralign; + Elf_Word sh_entsize; +}; + +struct Elf64_Shdr { + Elf_Word sh_name; + Elf_Word sh_type; + Elf_Xword sh_flags; + Elf64_Addr sh_addr; + Elf64_Off sh_offset; + Elf_Xword sh_size; + Elf_Word sh_link; + Elf_Word sh_info; + Elf_Xword sh_addralign; + Elf_Xword sh_entsize; +}; + + +// Segment header +struct Elf32_Phdr { + Elf_Word p_type; + Elf32_Off p_offset; + Elf32_Addr p_vaddr; + Elf32_Addr p_paddr; + Elf_Word p_filesz; + Elf_Word p_memsz; + Elf_Word p_flags; + Elf_Word p_align; +}; + +struct Elf64_Phdr { + Elf_Word p_type; + Elf_Word p_flags; + Elf64_Off p_offset; + Elf64_Addr p_vaddr; + Elf64_Addr p_paddr; + Elf_Xword p_filesz; + Elf_Xword p_memsz; + Elf_Xword p_align; +}; + + +// Symbol table entry +struct Elf32_Sym { + Elf_Word st_name; + Elf32_Addr st_value; + Elf_Word st_size; + unsigned char st_info; + unsigned char st_other; + Elf_Half st_shndx; +}; + +struct Elf64_Sym { + Elf_Word st_name; + unsigned char st_info; + unsigned char st_other; + Elf_Half st_shndx; + Elf64_Addr st_value; + Elf_Xword st_size; +}; + + +#define ELF_ST_BIND(i) ((i)>>4) +#define ELF_ST_TYPE(i) ((i)&0xf) +#define ELF_ST_INFO(b,t) (((b)<<4)+((t)&0xf)) + +#define ELF_ST_VISIBILITY(o) ((o)&0x3) + + +// Relocation entries +struct Elf32_Rel { + Elf32_Addr r_offset; + Elf_Word r_info; +}; + +struct Elf32_Rela { + Elf32_Addr r_offset; + Elf_Word r_info; + Elf_Sword r_addend; +}; + +struct Elf64_Rel { + Elf64_Addr r_offset; + Elf_Xword r_info; +}; + +struct Elf64_Rela { + Elf64_Addr r_offset; + Elf_Xword r_info; + Elf_Sxword r_addend; +}; + + +#define ELF32_R_SYM(i) ((i)>>8) +#define ELF32_R_TYPE(i) ((unsigned char)(i)) +#define ELF32_R_INFO(s,t) (((s)<<8 )+(unsigned char)(t)) + +#define ELF64_R_SYM(i) ((i)>>32) +#define ELF64_R_TYPE(i) ((i)&0xffffffffL) +#define ELF64_R_INFO(s,t) ((((int64_t)s)<<32)+((t)&0xffffffffL)) + +// Dynamic structure +struct Elf32_Dyn { + Elf_Sword d_tag; + union { + Elf_Word d_val; + Elf32_Addr d_ptr; + } d_un; +}; + +struct Elf64_Dyn { + Elf_Sxword d_tag; + union { + Elf_Xword d_val; + Elf64_Addr d_ptr; + } d_un; +}; + +} // namespace ELFIO + +#endif // ELFTYPES_H diff --git a/elfio/elfi_dynamic.hpp b/elfio/elfi_dynamic.hpp index 8ffa1dbd9fe3cabfcf6f92bf26b50ce08d9f8598..ce8d073b257c405363086feb7a0e23a8f1b722d5 100644 --- a/elfio/elfi_dynamic.hpp +++ b/elfio/elfi_dynamic.hpp @@ -1,58 +1,58 @@ -#ifndef ELFI_DYNAMIC_HPP -#define ELFI_DYNAMIC_HPP - -class ELFIDynamicReader : virtual public ELFIReaderImpl, virtual public IELFIDynamicReader -{ - public: - ELFIDynamicReader( const IELFI* pIELFI, const section* pSection ); - virtual ~ELFIDynamicReader(); - - // Dynamic reader functions - virtual Elf_Xword getEntriesNum() const; - virtual ELFIO_Err get_entry( Elf_Xword index, - Elf_Sxword& tag, - Elf_Xword& value ) const; -}; - - -ELFIDynamicReader::ELFIDynamicReader( const IELFI* pIELFI, const section* pSection ) : - ELFIReaderImpl( pIELFI, pSection ) -{ -} - - -ELFIDynamicReader::~ELFIDynamicReader() -{ -} - - -Elf_Xword -ELFIDynamicReader::getEntriesNum() const -{ - Elf_Xword nRet = 0; - if ( 0 != m_pSection->get_entry_size() ) { - nRet = m_pSection->get_size() / m_pSection->get_entry_size(); - } - - return nRet; -} - - -ELFIO_Err -ELFIDynamicReader::get_entry( Elf_Xword index, - Elf_Sxword& tag, - Elf_Xword& value ) const -{ - if ( index >= getEntriesNum() ) { // Is index valid - return ERR_ELFIO_INDEX_ERROR; - } - - const Elf64_Dyn* pEntry = reinterpret_cast<const Elf64_Dyn*>( - m_pSection->get_data() + index * m_pSection->get_entry_size() ); - tag = convert2host( pEntry->d_tag, m_pIELFI->get_encoding() ); - value = convert2host( pEntry->d_un.d_val, m_pIELFI->get_encoding() ); - - return ERR_ELFIO_NO_ERROR; -} - -#endif // ELFI_DYNAMIC_HPP +#ifndef ELFI_DYNAMIC_HPP +#define ELFI_DYNAMIC_HPP + +class ELFIDynamicReader : virtual public ELFIReaderImpl, virtual public IELFIDynamicReader +{ + public: + ELFIDynamicReader( const IELFI* pIELFI, const section* pSection ); + virtual ~ELFIDynamicReader(); + + // Dynamic reader functions + virtual Elf_Xword getEntriesNum() const; + virtual ELFIO_Err get_entry( Elf_Xword index, + Elf_Sxword& tag, + Elf_Xword& value ) const; +}; + + +ELFIDynamicReader::ELFIDynamicReader( const IELFI* pIELFI, const section* pSection ) : + ELFIReaderImpl( pIELFI, pSection ) +{ +} + + +ELFIDynamicReader::~ELFIDynamicReader() +{ +} + + +Elf_Xword +ELFIDynamicReader::getEntriesNum() const +{ + Elf_Xword nRet = 0; + if ( 0 != m_pSection->get_entry_size() ) { + nRet = m_pSection->get_size() / m_pSection->get_entry_size(); + } + + return nRet; +} + + +ELFIO_Err +ELFIDynamicReader::get_entry( Elf_Xword index, + Elf_Sxword& tag, + Elf_Xword& value ) const +{ + if ( index >= getEntriesNum() ) { // Is index valid + return ERR_ELFIO_INDEX_ERROR; + } + + const Elf64_Dyn* pEntry = reinterpret_cast<const Elf64_Dyn*>( + m_pSection->get_data() + index * m_pSection->get_entry_size() ); + tag = convert2host( pEntry->d_tag, m_pIELFI->get_encoding() ); + value = convert2host( pEntry->d_un.d_val, m_pIELFI->get_encoding() ); + + return ERR_ELFIO_NO_ERROR; +} + +#endif // ELFI_DYNAMIC_HPP diff --git a/elfio/elfio.hpp b/elfio/elfio.hpp index 3d72cff78d3b9a0ad274698d0ca103ecc3689592..c75c32d08bbf13e80d9178f843412c7e3608557b 100644 --- a/elfio/elfio.hpp +++ b/elfio/elfio.hpp @@ -1,617 +1,617 @@ -/* -Copyright (C) 2001-2012 by Serge Lamikhov-Center - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef ELFIO_HPP -#define ELFIO_HPP - -#ifdef _MSC_VER -#pragma warning ( push ) -#pragma warning(disable:4996) -#pragma warning(disable:4355) -#pragma warning(disable:4244) -#endif - -#include <string> -#include <fstream> -#include <fstream> -#include <algorithm> -#include <vector> -#include <typeinfo> - -#include <elfio/elf_types.hpp> -#include <elfio/elfio_utils.hpp> -#include <elfio/elfio_header.hpp> -#include <elfio/elfio_section.hpp> -#include <elfio/elfio_segment.hpp> -#include <elfio/elfio_strings.hpp> - - -#define ELFIO_HEADER_ACCESS_GET( TYPE, FNAME ) \ -TYPE \ -get_##FNAME() const \ -{ \ - return header->get_##FNAME(); \ -} - -#define ELFIO_HEADER_ACCESS_GET_SET( TYPE, FNAME ) \ -TYPE \ -get_##FNAME() const \ -{ \ - return header->get_##FNAME(); \ -} \ -void \ -set_##FNAME( TYPE val ) \ -{ \ - header->set_##FNAME( val ); \ -} \ - -namespace ELFIO { - -//------------------------------------------------------------------------------ -class elfio -{ - public: -//------------------------------------------------------------------------------ - elfio() : sections( this ), segments( this ) - { - header = 0; - create( ELFCLASS32, ELFDATA2LSB ); - } - -//------------------------------------------------------------------------------ - ~elfio() - { - clean(); - } - -//------------------------------------------------------------------------------ - void create( unsigned char file_class, unsigned char encoding ) - { - clean(); - convertor.setup( encoding ); - header = create_header( file_class, encoding ); - create_mandatory_sections(); - } - -//------------------------------------------------------------------------------ - bool load( const std::string& file_name ) - { - clean(); - - std::ifstream stream; - stream.open( file_name.c_str(), std::ios::in | std::ios::binary ); - if ( !stream ) { - return false; - } - - unsigned char e_ident[EI_NIDENT]; - - // Read ELF file signature - stream.seekg( 0 ); - stream.read( reinterpret_cast<char*>( &e_ident ), sizeof( e_ident ) ); - - // Is it ELF file? - if ( stream.gcount() != sizeof( e_ident ) || - e_ident[EI_MAG0] != ELFMAG0 || - e_ident[EI_MAG1] != ELFMAG1 || - e_ident[EI_MAG2] != ELFMAG2 || - e_ident[EI_MAG3] != ELFMAG3 ) { - return false; - } - - if ( ( e_ident[EI_CLASS] != ELFCLASS64 ) && - ( e_ident[EI_CLASS] != ELFCLASS32 )) { - return false; - } - - convertor.setup( e_ident[EI_DATA] ); - - header = create_header( e_ident[EI_CLASS], e_ident[EI_DATA] ); - if ( 0 == header ) { - return false; - } - if ( !header->load( stream ) ) { - return false; - } - - load_sections( stream ); - load_segments( stream ); - - return true; - } - -//------------------------------------------------------------------------------ - bool save( const std::string& file_name ) - { - std::ofstream f( file_name.c_str(), std::ios::out | std::ios::binary ); - - if ( !f ) { - return false; - } - - bool is_still_good = true; - fill_final_attributes(); - set_current_file_position(); - - is_still_good = is_still_good && save_header( f ); - is_still_good = is_still_good && save_sections_without_segments( f ); - is_still_good = is_still_good && save_segments_and_their_sections( f ); - - f.close(); - - return is_still_good; - } - -//------------------------------------------------------------------------------ - // ELF header access functions - ELFIO_HEADER_ACCESS_GET( unsigned char, class ); - ELFIO_HEADER_ACCESS_GET( unsigned char, elf_version ); - ELFIO_HEADER_ACCESS_GET( unsigned char, encoding ); - ELFIO_HEADER_ACCESS_GET( Elf_Word, version ); - ELFIO_HEADER_ACCESS_GET( Elf_Half, header_size ); - ELFIO_HEADER_ACCESS_GET( Elf_Half, section_entry_size ); - ELFIO_HEADER_ACCESS_GET( Elf_Half, segment_entry_size ); - - ELFIO_HEADER_ACCESS_GET_SET( unsigned char, os_abi ); - ELFIO_HEADER_ACCESS_GET_SET( unsigned char, abi_version ); - ELFIO_HEADER_ACCESS_GET_SET( Elf_Half, type ); - ELFIO_HEADER_ACCESS_GET_SET( Elf_Half, machine ); - ELFIO_HEADER_ACCESS_GET_SET( Elf_Word, flags ); - ELFIO_HEADER_ACCESS_GET_SET( Elf64_Addr, entry ); - ELFIO_HEADER_ACCESS_GET_SET( Elf64_Off, sections_offset ); - ELFIO_HEADER_ACCESS_GET_SET( Elf64_Off, segments_offset ); - ELFIO_HEADER_ACCESS_GET_SET( Elf_Half, section_name_str_index ); - -//------------------------------------------------------------------------------ - const endianess_convertor& get_convertor() const - { - return convertor; - } - -//------------------------------------------------------------------------------ - Elf_Xword get_default_entry_size( Elf_Word section_type ) const - { - switch( section_type ) { - case SHT_RELA: - if ( header->get_class() == ELFCLASS64 ) { - return sizeof( Elf64_Rela ); - } - else { - return sizeof( Elf32_Rela ); - } - case SHT_REL: - if ( header->get_class() == ELFCLASS64 ) { - return sizeof( Elf64_Rel ); - } - else { - return sizeof( Elf32_Rel ); - } - case SHT_SYMTAB: - if ( header->get_class() == ELFCLASS64 ) { - return sizeof( Elf64_Sym ); - } - else { - return sizeof( Elf32_Sym ); - } - case SHT_DYNAMIC: - if ( header->get_class() == ELFCLASS64 ) { - return sizeof( Elf64_Dyn ); - } - else { - return sizeof( Elf32_Dyn ); - } - default: - return 0; - } - } - -//------------------------------------------------------------------------------ - private: -//------------------------------------------------------------------------------ - void clean() - { - // TODO: Instead of deletion, substitute to NULL object - delete header; - header = 0; - - std::vector<section*>::const_iterator it; - for ( it = sections_.begin(); it != sections_.end(); ++it ) { - delete *it; - } - sections_.clear(); - - std::vector<segment*>::const_iterator it1; - for ( it1 = segments_.begin(); it1 != segments_.end(); ++it1 ) { - delete *it1; - } - segments_.clear(); - } - -//------------------------------------------------------------------------------ - elf_header* create_header( unsigned char file_class, unsigned char encoding ) - { - elf_header* new_header = 0; - - if ( file_class == ELFCLASS64 ) { - new_header = new elf_header_impl< Elf64_Ehdr >( &convertor, - encoding ); - } - else if ( file_class == ELFCLASS32 ) { - new_header = new elf_header_impl< Elf32_Ehdr >( &convertor, - encoding ); - } - else { - return 0; - } - - return new_header; - } - -//------------------------------------------------------------------------------ - section* create_section() - { - section* new_section; - unsigned char file_class = get_class(); - - if ( file_class == ELFCLASS64 ) { - new_section = new section_impl<Elf64_Shdr>( &convertor ); - } - else if ( file_class == ELFCLASS32 ) { - new_section = new section_impl<Elf32_Shdr>( &convertor ); - } - else { - return 0; - } - - new_section->set_index( (Elf_Half)sections_.size() ); - sections_.push_back( new_section ); - - return new_section; - } - - -//------------------------------------------------------------------------------ - segment* create_segment() - { - segment* new_segment; - unsigned char file_class = header->get_class(); - - if ( file_class == ELFCLASS64 ) { - new_segment = new segment_impl<Elf64_Phdr>( &convertor ); - } - else if ( file_class == ELFCLASS32 ) { - new_segment = new segment_impl<Elf32_Phdr>( &convertor ); - } - else { - return 0; - } - - segments_.push_back( new_segment ); - - return new_segment; - } - -//------------------------------------------------------------------------------ - void create_mandatory_sections() - { - // Create null section without calling to 'add_section' as no string - // section containing section names exists yet - section* sec0 = create_section(); - sec0->set_index( 0 ); - sec0->set_name( "" ); - sec0->set_name_string_offset( 0 ); - - set_section_name_str_index( 1 ); - section* shstrtab = sections.add( ".shstrtab" ); - shstrtab->set_type( SHT_STRTAB ); - } - -//------------------------------------------------------------------------------ - Elf_Half load_sections( std::ifstream& stream ) - { - Elf_Half entry_size = header->get_section_entry_size(); - Elf_Half num = header->get_sections_num(); - Elf64_Off offset = header->get_sections_offset(); - - for ( Elf_Half i = 0; i < num; ++i ) { - section* sec = create_section(); - sec->load( stream, (std::streamoff)offset + i * entry_size ); - sec->set_index( i ); - } - - Elf_Half shstrndx = get_section_name_str_index(); - - if ( SHN_UNDEF != shstrndx ) { - string_section_accessor str_reader( sections[shstrndx] ); - for ( Elf_Half i = 0; i < num; ++i ) { - Elf_Word offset = sections[i]->get_name_string_offset(); - const char* p = str_reader.get_string( offset ); - if ( p != 0 ) { - sections[i]->set_name( p ); - } - } - } - - return num; - } - -//------------------------------------------------------------------------------ - bool load_segments( std::ifstream& stream ) - { - Elf_Half entry_size = header->get_segment_entry_size(); - Elf_Half num = header->get_segments_num(); - Elf64_Off offset = header->get_segments_offset(); - - for ( Elf_Half i = 0; i < num; ++i ) { - segment* seg; - unsigned char file_class = header->get_class(); - - if ( file_class == ELFCLASS64 ) { - seg = new segment_impl<Elf64_Phdr>( &convertor ); - } - else if ( file_class == ELFCLASS32 ) { - seg = new segment_impl<Elf32_Phdr>( &convertor ); - } - else { - return false; - } - - seg->load( stream, (std::streamoff)offset + i * entry_size ); - seg->set_index( i ); - - // Add section into the segments' container - segments_.push_back( seg ); - } - - return true; - } - -//------------------------------------------------------------------------------ - void fill_final_attributes() - { - // Fill not completed fields in the header - header->set_segments_num( segments.size() ); - header->set_segments_offset( header->get_header_size() ); - header->set_sections_num( sections.size() ); - header->set_sections_offset( header->get_header_size() + - header->get_segment_entry_size() * segments.size() ); - } - -//------------------------------------------------------------------------------ - bool save_header( std::ofstream& f ) - { - return header->save( f ); - } - - -//------------------------------------------------------------------------------ - void set_current_file_position() - { - current_file_pos = header->get_header_size() + - header->get_segment_entry_size() * header->get_segments_num() + - header->get_section_entry_size() * header->get_sections_num(); - } - - -//------------------------------------------------------------------------------ - bool is_section_without_segment( unsigned int section_index ) - { - bool found = false; - for ( unsigned int j = 0; !found && ( j < segments.size() ); ++j ) { - for ( unsigned int k = 0; !found && ( k < segments[j]->get_sections_num() ); ++k ) { - found = segments[j]->get_section_index_at( k ) == section_index; - } - } - - return !found; - } - - -//------------------------------------------------------------------------------ - bool save_sections_without_segments( std::ofstream& f ) - { - for ( unsigned int i = 0; i < sections_.size(); ++i ) { - if ( is_section_without_segment( i ) ) { - Elf_Xword section_align = sections_[i]->get_addr_align(); - if ( section_align > 1 && current_file_pos % section_align != 0 ) { - current_file_pos += section_align - - current_file_pos % section_align; - } - - std::streampos headerPosition = (std::streamoff)header->get_sections_offset() + - header->get_section_entry_size() * sections_[i]->get_index(); - - sections_[i]->save( f, headerPosition, (std::streamoff)current_file_pos ); - - if ( SHT_NOBITS != sections_[i]->get_type() ) { - current_file_pos += sections_[i]->get_size(); - } - } - } - - return true; - } - - -//------------------------------------------------------------------------------ - bool save_segments_and_their_sections( std::ofstream& f ) - { - Elf64_Off segment_header_position = header->get_segments_offset(); - - for ( unsigned int i = 0; i < segments.size(); ++i ) { - Elf_Xword segment_align = segments[i]->get_align(); - if ( segment_align > 1 && current_file_pos % segment_align != 0 ) { - current_file_pos += segment_align - current_file_pos % segment_align; - } - - Elf_Xword current_data_pos = current_file_pos; - // Write segment's data - for ( unsigned int j = 0; j <segments[i]->get_sections_num(); ++j ) { - section* sec = sections[ segments[i]->get_section_index_at( j )]; - - Elf_Xword secAlign = sec->get_addr_align(); - if ( secAlign > 1 && current_data_pos % secAlign != 0 ) { - current_data_pos += secAlign - current_data_pos % secAlign; - } - - std::streampos headerPosition = (std::streamoff)header->get_sections_offset() + - header->get_section_entry_size()*sec->get_index(); - if ( !sec->is_address_initialized() ) { - sec->set_address( segments[i]->get_virtual_address() ); - } - sec->save( f, headerPosition, (std::streamoff)current_data_pos ); - current_data_pos += sec->get_size(); - } - - segments[i]->set_file_size( current_data_pos - current_file_pos ); - segments[i]->set_memory_size( current_data_pos - current_file_pos + - segments[i]->get_memory_size() ); - segments[i]->save( f, (std::streamoff)segment_header_position, (std::streamoff)current_file_pos ); - current_file_pos = current_data_pos; - segment_header_position += header->get_segment_entry_size(); - } - - return true; - } - - -//------------------------------------------------------------------------------ - public: - friend class Sections; - class Sections { - public: -//------------------------------------------------------------------------------ - Sections( elfio* parent_ ) : - parent( parent_ ) - { - } - -//------------------------------------------------------------------------------ - Elf_Half size() const - { - return (Elf_Half)parent->sections_.size(); - } - -//------------------------------------------------------------------------------ - section* operator[]( unsigned int index ) const - { - section* sec = 0; - - if ( index < parent->sections_.size() ) { - sec = parent->sections_[index]; - } - - return sec; - } - -//------------------------------------------------------------------------------ - section* operator[]( const std::string& name ) const - { - section* sec = 0; - - std::vector<section*>::const_iterator it; - for ( it = parent->sections_.begin(); it != parent->sections_.end(); ++it ) { - if ( (*it)->get_name() == name ) { - sec = *it; - break; - } - } - - return sec; - } - -//------------------------------------------------------------------------------ - section* add( const std::string& name ) - { - section* new_section = parent->create_section(); - new_section->set_name( name ); - - Elf_Half str_index = parent->get_section_name_str_index(); - section* string_table( parent->sections_[str_index] ); - string_section_accessor str_writer( string_table ); - Elf_Word pos = str_writer.add_string( name ); - new_section->set_name_string_offset( pos ); - - return new_section; - } - -//------------------------------------------------------------------------------ - private: - elfio* parent; - } sections; - -//------------------------------------------------------------------------------ - public: - friend class Segments; - class Segments { - public: -//------------------------------------------------------------------------------ - Segments( elfio* parent_ ) : - parent( parent_ ) - { - } - -//------------------------------------------------------------------------------ - Elf_Half size() const - { - return (Elf_Half)parent->segments_.size(); - } - -//------------------------------------------------------------------------------ - segment* operator[]( unsigned int index ) const - { - return parent->segments_[index]; - } - - -//------------------------------------------------------------------------------ - segment* add() - { - return parent->create_segment(); - } - -//------------------------------------------------------------------------------ - private: - elfio* parent; - } segments; - -//------------------------------------------------------------------------------ - private: - elf_header* header; - std::vector<section*> sections_; - std::vector<segment*> segments_; - endianess_convertor convertor; - - Elf_Xword current_file_pos; -}; - -} // namespace ELFIO - -#include "elfio_symbols.hpp" -#include "elfio_note.hpp" -#include "elfio_relocation.hpp" - -#ifdef _MSC_VER -#pragma warning ( pop ) -#endif - -#endif // ELFIO_HPP +/* +Copyright (C) 2001-2012 by Serge Lamikhov-Center + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef ELFIO_HPP +#define ELFIO_HPP + +#ifdef _MSC_VER +#pragma warning ( push ) +#pragma warning(disable:4996) +#pragma warning(disable:4355) +#pragma warning(disable:4244) +#endif + +#include <string> +#include <fstream> +#include <fstream> +#include <algorithm> +#include <vector> +#include <typeinfo> + +#include <elfio/elf_types.hpp> +#include <elfio/elfio_utils.hpp> +#include <elfio/elfio_header.hpp> +#include <elfio/elfio_section.hpp> +#include <elfio/elfio_segment.hpp> +#include <elfio/elfio_strings.hpp> + + +#define ELFIO_HEADER_ACCESS_GET( TYPE, FNAME ) \ +TYPE \ +get_##FNAME() const \ +{ \ + return header->get_##FNAME(); \ +} + +#define ELFIO_HEADER_ACCESS_GET_SET( TYPE, FNAME ) \ +TYPE \ +get_##FNAME() const \ +{ \ + return header->get_##FNAME(); \ +} \ +void \ +set_##FNAME( TYPE val ) \ +{ \ + header->set_##FNAME( val ); \ +} \ + +namespace ELFIO { + +//------------------------------------------------------------------------------ +class elfio +{ + public: +//------------------------------------------------------------------------------ + elfio() : sections( this ), segments( this ) + { + header = 0; + create( ELFCLASS32, ELFDATA2LSB ); + } + +//------------------------------------------------------------------------------ + ~elfio() + { + clean(); + } + +//------------------------------------------------------------------------------ + void create( unsigned char file_class, unsigned char encoding ) + { + clean(); + convertor.setup( encoding ); + header = create_header( file_class, encoding ); + create_mandatory_sections(); + } + +//------------------------------------------------------------------------------ + bool load( const std::string& file_name ) + { + clean(); + + std::ifstream stream; + stream.open( file_name.c_str(), std::ios::in | std::ios::binary ); + if ( !stream ) { + return false; + } + + unsigned char e_ident[EI_NIDENT]; + + // Read ELF file signature + stream.seekg( 0 ); + stream.read( reinterpret_cast<char*>( &e_ident ), sizeof( e_ident ) ); + + // Is it ELF file? + if ( stream.gcount() != sizeof( e_ident ) || + e_ident[EI_MAG0] != ELFMAG0 || + e_ident[EI_MAG1] != ELFMAG1 || + e_ident[EI_MAG2] != ELFMAG2 || + e_ident[EI_MAG3] != ELFMAG3 ) { + return false; + } + + if ( ( e_ident[EI_CLASS] != ELFCLASS64 ) && + ( e_ident[EI_CLASS] != ELFCLASS32 )) { + return false; + } + + convertor.setup( e_ident[EI_DATA] ); + + header = create_header( e_ident[EI_CLASS], e_ident[EI_DATA] ); + if ( 0 == header ) { + return false; + } + if ( !header->load( stream ) ) { + return false; + } + + load_sections( stream ); + load_segments( stream ); + + return true; + } + +//------------------------------------------------------------------------------ + bool save( const std::string& file_name ) + { + std::ofstream f( file_name.c_str(), std::ios::out | std::ios::binary ); + + if ( !f ) { + return false; + } + + bool is_still_good = true; + fill_final_attributes(); + set_current_file_position(); + + is_still_good = is_still_good && save_header( f ); + is_still_good = is_still_good && save_sections_without_segments( f ); + is_still_good = is_still_good && save_segments_and_their_sections( f ); + + f.close(); + + return is_still_good; + } + +//------------------------------------------------------------------------------ + // ELF header access functions + ELFIO_HEADER_ACCESS_GET( unsigned char, class ); + ELFIO_HEADER_ACCESS_GET( unsigned char, elf_version ); + ELFIO_HEADER_ACCESS_GET( unsigned char, encoding ); + ELFIO_HEADER_ACCESS_GET( Elf_Word, version ); + ELFIO_HEADER_ACCESS_GET( Elf_Half, header_size ); + ELFIO_HEADER_ACCESS_GET( Elf_Half, section_entry_size ); + ELFIO_HEADER_ACCESS_GET( Elf_Half, segment_entry_size ); + + ELFIO_HEADER_ACCESS_GET_SET( unsigned char, os_abi ); + ELFIO_HEADER_ACCESS_GET_SET( unsigned char, abi_version ); + ELFIO_HEADER_ACCESS_GET_SET( Elf_Half, type ); + ELFIO_HEADER_ACCESS_GET_SET( Elf_Half, machine ); + ELFIO_HEADER_ACCESS_GET_SET( Elf_Word, flags ); + ELFIO_HEADER_ACCESS_GET_SET( Elf64_Addr, entry ); + ELFIO_HEADER_ACCESS_GET_SET( Elf64_Off, sections_offset ); + ELFIO_HEADER_ACCESS_GET_SET( Elf64_Off, segments_offset ); + ELFIO_HEADER_ACCESS_GET_SET( Elf_Half, section_name_str_index ); + +//------------------------------------------------------------------------------ + const endianess_convertor& get_convertor() const + { + return convertor; + } + +//------------------------------------------------------------------------------ + Elf_Xword get_default_entry_size( Elf_Word section_type ) const + { + switch( section_type ) { + case SHT_RELA: + if ( header->get_class() == ELFCLASS64 ) { + return sizeof( Elf64_Rela ); + } + else { + return sizeof( Elf32_Rela ); + } + case SHT_REL: + if ( header->get_class() == ELFCLASS64 ) { + return sizeof( Elf64_Rel ); + } + else { + return sizeof( Elf32_Rel ); + } + case SHT_SYMTAB: + if ( header->get_class() == ELFCLASS64 ) { + return sizeof( Elf64_Sym ); + } + else { + return sizeof( Elf32_Sym ); + } + case SHT_DYNAMIC: + if ( header->get_class() == ELFCLASS64 ) { + return sizeof( Elf64_Dyn ); + } + else { + return sizeof( Elf32_Dyn ); + } + default: + return 0; + } + } + +//------------------------------------------------------------------------------ + private: +//------------------------------------------------------------------------------ + void clean() + { + // TODO: Instead of deletion, substitute to NULL object + delete header; + header = 0; + + std::vector<section*>::const_iterator it; + for ( it = sections_.begin(); it != sections_.end(); ++it ) { + delete *it; + } + sections_.clear(); + + std::vector<segment*>::const_iterator it1; + for ( it1 = segments_.begin(); it1 != segments_.end(); ++it1 ) { + delete *it1; + } + segments_.clear(); + } + +//------------------------------------------------------------------------------ + elf_header* create_header( unsigned char file_class, unsigned char encoding ) + { + elf_header* new_header = 0; + + if ( file_class == ELFCLASS64 ) { + new_header = new elf_header_impl< Elf64_Ehdr >( &convertor, + encoding ); + } + else if ( file_class == ELFCLASS32 ) { + new_header = new elf_header_impl< Elf32_Ehdr >( &convertor, + encoding ); + } + else { + return 0; + } + + return new_header; + } + +//------------------------------------------------------------------------------ + section* create_section() + { + section* new_section; + unsigned char file_class = get_class(); + + if ( file_class == ELFCLASS64 ) { + new_section = new section_impl<Elf64_Shdr>( &convertor ); + } + else if ( file_class == ELFCLASS32 ) { + new_section = new section_impl<Elf32_Shdr>( &convertor ); + } + else { + return 0; + } + + new_section->set_index( (Elf_Half)sections_.size() ); + sections_.push_back( new_section ); + + return new_section; + } + + +//------------------------------------------------------------------------------ + segment* create_segment() + { + segment* new_segment; + unsigned char file_class = header->get_class(); + + if ( file_class == ELFCLASS64 ) { + new_segment = new segment_impl<Elf64_Phdr>( &convertor ); + } + else if ( file_class == ELFCLASS32 ) { + new_segment = new segment_impl<Elf32_Phdr>( &convertor ); + } + else { + return 0; + } + + segments_.push_back( new_segment ); + + return new_segment; + } + +//------------------------------------------------------------------------------ + void create_mandatory_sections() + { + // Create null section without calling to 'add_section' as no string + // section containing section names exists yet + section* sec0 = create_section(); + sec0->set_index( 0 ); + sec0->set_name( "" ); + sec0->set_name_string_offset( 0 ); + + set_section_name_str_index( 1 ); + section* shstrtab = sections.add( ".shstrtab" ); + shstrtab->set_type( SHT_STRTAB ); + } + +//------------------------------------------------------------------------------ + Elf_Half load_sections( std::ifstream& stream ) + { + Elf_Half entry_size = header->get_section_entry_size(); + Elf_Half num = header->get_sections_num(); + Elf64_Off offset = header->get_sections_offset(); + + for ( Elf_Half i = 0; i < num; ++i ) { + section* sec = create_section(); + sec->load( stream, (std::streamoff)offset + i * entry_size ); + sec->set_index( i ); + } + + Elf_Half shstrndx = get_section_name_str_index(); + + if ( SHN_UNDEF != shstrndx ) { + string_section_accessor str_reader( sections[shstrndx] ); + for ( Elf_Half i = 0; i < num; ++i ) { + Elf_Word offset = sections[i]->get_name_string_offset(); + const char* p = str_reader.get_string( offset ); + if ( p != 0 ) { + sections[i]->set_name( p ); + } + } + } + + return num; + } + +//------------------------------------------------------------------------------ + bool load_segments( std::ifstream& stream ) + { + Elf_Half entry_size = header->get_segment_entry_size(); + Elf_Half num = header->get_segments_num(); + Elf64_Off offset = header->get_segments_offset(); + + for ( Elf_Half i = 0; i < num; ++i ) { + segment* seg; + unsigned char file_class = header->get_class(); + + if ( file_class == ELFCLASS64 ) { + seg = new segment_impl<Elf64_Phdr>( &convertor ); + } + else if ( file_class == ELFCLASS32 ) { + seg = new segment_impl<Elf32_Phdr>( &convertor ); + } + else { + return false; + } + + seg->load( stream, (std::streamoff)offset + i * entry_size ); + seg->set_index( i ); + + // Add section into the segments' container + segments_.push_back( seg ); + } + + return true; + } + +//------------------------------------------------------------------------------ + void fill_final_attributes() + { + // Fill not completed fields in the header + header->set_segments_num( segments.size() ); + header->set_segments_offset( header->get_header_size() ); + header->set_sections_num( sections.size() ); + header->set_sections_offset( header->get_header_size() + + header->get_segment_entry_size() * segments.size() ); + } + +//------------------------------------------------------------------------------ + bool save_header( std::ofstream& f ) + { + return header->save( f ); + } + + +//------------------------------------------------------------------------------ + void set_current_file_position() + { + current_file_pos = header->get_header_size() + + header->get_segment_entry_size() * header->get_segments_num() + + header->get_section_entry_size() * header->get_sections_num(); + } + + +//------------------------------------------------------------------------------ + bool is_section_without_segment( unsigned int section_index ) + { + bool found = false; + for ( unsigned int j = 0; !found && ( j < segments.size() ); ++j ) { + for ( unsigned int k = 0; !found && ( k < segments[j]->get_sections_num() ); ++k ) { + found = segments[j]->get_section_index_at( k ) == section_index; + } + } + + return !found; + } + + +//------------------------------------------------------------------------------ + bool save_sections_without_segments( std::ofstream& f ) + { + for ( unsigned int i = 0; i < sections_.size(); ++i ) { + if ( is_section_without_segment( i ) ) { + Elf_Xword section_align = sections_[i]->get_addr_align(); + if ( section_align > 1 && current_file_pos % section_align != 0 ) { + current_file_pos += section_align - + current_file_pos % section_align; + } + + std::streampos headerPosition = (std::streamoff)header->get_sections_offset() + + header->get_section_entry_size() * sections_[i]->get_index(); + + sections_[i]->save( f, headerPosition, (std::streamoff)current_file_pos ); + + if ( SHT_NOBITS != sections_[i]->get_type() ) { + current_file_pos += sections_[i]->get_size(); + } + } + } + + return true; + } + + +//------------------------------------------------------------------------------ + bool save_segments_and_their_sections( std::ofstream& f ) + { + Elf64_Off segment_header_position = header->get_segments_offset(); + + for ( unsigned int i = 0; i < segments.size(); ++i ) { + Elf_Xword segment_align = segments[i]->get_align(); + if ( segment_align > 1 && current_file_pos % segment_align != 0 ) { + current_file_pos += segment_align - current_file_pos % segment_align; + } + + Elf_Xword current_data_pos = current_file_pos; + // Write segment's data + for ( unsigned int j = 0; j <segments[i]->get_sections_num(); ++j ) { + section* sec = sections[ segments[i]->get_section_index_at( j )]; + + Elf_Xword secAlign = sec->get_addr_align(); + if ( secAlign > 1 && current_data_pos % secAlign != 0 ) { + current_data_pos += secAlign - current_data_pos % secAlign; + } + + std::streampos headerPosition = (std::streamoff)header->get_sections_offset() + + header->get_section_entry_size()*sec->get_index(); + if ( !sec->is_address_initialized() ) { + sec->set_address( segments[i]->get_virtual_address() ); + } + sec->save( f, headerPosition, (std::streamoff)current_data_pos ); + current_data_pos += sec->get_size(); + } + + segments[i]->set_file_size( current_data_pos - current_file_pos ); + segments[i]->set_memory_size( current_data_pos - current_file_pos + + segments[i]->get_memory_size() ); + segments[i]->save( f, (std::streamoff)segment_header_position, (std::streamoff)current_file_pos ); + current_file_pos = current_data_pos; + segment_header_position += header->get_segment_entry_size(); + } + + return true; + } + + +//------------------------------------------------------------------------------ + public: + friend class Sections; + class Sections { + public: +//------------------------------------------------------------------------------ + Sections( elfio* parent_ ) : + parent( parent_ ) + { + } + +//------------------------------------------------------------------------------ + Elf_Half size() const + { + return (Elf_Half)parent->sections_.size(); + } + +//------------------------------------------------------------------------------ + section* operator[]( unsigned int index ) const + { + section* sec = 0; + + if ( index < parent->sections_.size() ) { + sec = parent->sections_[index]; + } + + return sec; + } + +//------------------------------------------------------------------------------ + section* operator[]( const std::string& name ) const + { + section* sec = 0; + + std::vector<section*>::const_iterator it; + for ( it = parent->sections_.begin(); it != parent->sections_.end(); ++it ) { + if ( (*it)->get_name() == name ) { + sec = *it; + break; + } + } + + return sec; + } + +//------------------------------------------------------------------------------ + section* add( const std::string& name ) + { + section* new_section = parent->create_section(); + new_section->set_name( name ); + + Elf_Half str_index = parent->get_section_name_str_index(); + section* string_table( parent->sections_[str_index] ); + string_section_accessor str_writer( string_table ); + Elf_Word pos = str_writer.add_string( name ); + new_section->set_name_string_offset( pos ); + + return new_section; + } + +//------------------------------------------------------------------------------ + private: + elfio* parent; + } sections; + +//------------------------------------------------------------------------------ + public: + friend class Segments; + class Segments { + public: +//------------------------------------------------------------------------------ + Segments( elfio* parent_ ) : + parent( parent_ ) + { + } + +//------------------------------------------------------------------------------ + Elf_Half size() const + { + return (Elf_Half)parent->segments_.size(); + } + +//------------------------------------------------------------------------------ + segment* operator[]( unsigned int index ) const + { + return parent->segments_[index]; + } + + +//------------------------------------------------------------------------------ + segment* add() + { + return parent->create_segment(); + } + +//------------------------------------------------------------------------------ + private: + elfio* parent; + } segments; + +//------------------------------------------------------------------------------ + private: + elf_header* header; + std::vector<section*> sections_; + std::vector<segment*> segments_; + endianess_convertor convertor; + + Elf_Xword current_file_pos; +}; + +} // namespace ELFIO + +#include "elfio_symbols.hpp" +#include "elfio_note.hpp" +#include "elfio_relocation.hpp" + +#ifdef _MSC_VER +#pragma warning ( pop ) +#endif + +#endif // ELFIO_HPP diff --git a/elfio/elfio_dump.hpp b/elfio/elfio_dump.hpp index 274dd156539200aa64580fc95a5315d040aad2c4..c198f03e0a656c256b326473a8a45f66d738d186 100644 --- a/elfio/elfio_dump.hpp +++ b/elfio/elfio_dump.hpp @@ -1,685 +1,685 @@ -/* -Copyright (C) 2001-2011 by Serge Lamikhov-Center - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef ELFIO_DUMP_HPP -#define ELFIO_DUMP_HPP - -#include <string> -#include <ostream> -#include <sstream> -#include <iomanip> -#include <elfio/elfio.hpp> - -namespace ELFIO { - - -static struct class_table_t { - const char key; - const char* str; -} class_table [] = -{ - { ELFCLASS32, "ELF32" }, - { ELFCLASS64, "ELF64" }, -}; - - -static struct endian_table_t { - const char key; - const char* str; -} endian_table [] = -{ - { ELFDATANONE, "None" }, - { ELFDATA2LSB, "Little endian" }, - { ELFDATA2MSB, "Big endian" }, -}; - - -static struct version_table_t { - const Elf64_Word key; - const char* str; -} version_table [] = -{ - { EV_NONE , "None" }, - { EV_CURRENT, "Current" }, -}; - - -static struct type_table_t { - const Elf32_Half key; - const char* str; -} type_table [] = -{ - { ET_NONE, "No file type" }, - { ET_REL , "Relocatable file" }, - { ET_EXEC, "Executable file" }, - { ET_DYN , "Shared object file" }, - { ET_CORE, "Core file" }, -}; - - -static struct machine_table_t { - const Elf64_Half key; - const char* str; -} machine_table [] = -{ - { EM_NONE , "No machine" }, - { EM_M32 , "AT&T WE 32100" }, - { EM_SPARC , "SUN SPARC" }, - { EM_386 , "Intel 80386" }, - { EM_68K , "Motorola m68k family" }, - { EM_88K , "Motorola m88k family" }, - { EM_486 , "Intel 80486// Reserved for future use" }, - { EM_860 , "Intel 80860" }, - { EM_MIPS , "MIPS R3000 (officially, big-endian only)" }, - { EM_S370 , "IBM System/370" }, - { EM_MIPS_RS3_LE , "MIPS R3000 little-endian (Oct 4 1999 Draft) Deprecated" }, - { EM_res011 , "Reserved" }, - { EM_res012 , "Reserved" }, - { EM_res013 , "Reserved" }, - { EM_res014 , "Reserved" }, - { EM_PARISC , "HPPA" }, - { EM_res016 , "Reserved" }, - { EM_VPP550 , "Fujitsu VPP500" }, - { EM_SPARC32PLUS , "Sun's v8plus" }, - { EM_960 , "Intel 80960" }, - { EM_PPC , "PowerPC" }, - { EM_PPC64 , "64-bit PowerPC" }, - { EM_S390 , "IBM S/390" }, - { EM_SPU , "Sony/Toshiba/IBM SPU" }, - { EM_res024 , "Reserved" }, - { EM_res025 , "Reserved" }, - { EM_res026 , "Reserved" }, - { EM_res027 , "Reserved" }, - { EM_res028 , "Reserved" }, - { EM_res029 , "Reserved" }, - { EM_res030 , "Reserved" }, - { EM_res031 , "Reserved" }, - { EM_res032 , "Reserved" }, - { EM_res033 , "Reserved" }, - { EM_res034 , "Reserved" }, - { EM_res035 , "Reserved" }, - { EM_V800 , "NEC V800 series" }, - { EM_FR20 , "Fujitsu FR20" }, - { EM_RH32 , "TRW RH32" }, - { EM_MCORE , "Motorola M*Core // May also be taken by Fujitsu MMA" }, - { EM_RCE , "Old name for MCore" }, - { EM_ARM , "ARM" }, - { EM_OLD_ALPHA , "Digital Alpha" }, - { EM_SH , "Renesas (formerly Hitachi) / SuperH SH" }, - { EM_SPARCV9 , "SPARC v9 64-bit" }, - { EM_TRICORE , "Siemens Tricore embedded processor" }, - { EM_ARC , "ARC Cores" }, - { EM_H8_300 , "Renesas (formerly Hitachi) H8/300" }, - { EM_H8_300H , "Renesas (formerly Hitachi) H8/300H" }, - { EM_H8S , "Renesas (formerly Hitachi) H8S" }, - { EM_H8_500 , "Renesas (formerly Hitachi) H8/500" }, - { EM_IA_64 , "Intel IA-64 Processor" }, - { EM_MIPS_X , "Stanford MIPS-X" }, - { EM_COLDFIRE , "Motorola Coldfire" }, - { EM_68HC12 , "Motorola M68HC12" }, - { EM_MMA , "Fujitsu Multimedia Accelerator" }, - { EM_PCP , "Siemens PCP" }, - { EM_NCPU , "Sony nCPU embedded RISC processor" }, - { EM_NDR1 , "Denso NDR1 microprocesspr" }, - { EM_STARCORE , "Motorola Star*Core processor" }, - { EM_ME16 , "Toyota ME16 processor" }, - { EM_ST100 , "STMicroelectronics ST100 processor" }, - { EM_TINYJ , "Advanced Logic Corp. TinyJ embedded processor" }, - { EM_X86_64 , "Advanced Micro Devices X86-64 processor" }, - { EM_PDSP , "Sony DSP Processor" }, - { EM_PDP10 , "Digital Equipment Corp. PDP-10" }, - { EM_PDP11 , "Digital Equipment Corp. PDP-11" }, - { EM_FX66 , "Siemens FX66 microcontroller" }, - { EM_ST9PLUS , "STMicroelectronics ST9+ 8/16 bit microcontroller" }, - { EM_ST7 , "STMicroelectronics ST7 8-bit microcontroller" }, - { EM_68HC16 , "Motorola MC68HC16 Microcontroller" }, - { EM_68HC11 , "Motorola MC68HC11 Microcontroller" }, - { EM_68HC08 , "Motorola MC68HC08 Microcontroller" }, - { EM_68HC05 , "Motorola MC68HC05 Microcontroller" }, - { EM_SVX , "Silicon Graphics SVx" }, - { EM_ST19 , "STMicroelectronics ST19 8-bit cpu" }, - { EM_VAX , "Digital VAX" }, - { EM_CRIS , "Axis Communications 32-bit embedded processor" }, - { EM_JAVELIN , "Infineon Technologies 32-bit embedded cpu" }, - { EM_FIREPATH , "Element 14 64-bit DSP processor" }, - { EM_ZSP , "LSI Logic's 16-bit DSP processor" }, - { EM_MMIX , "Donald Knuth's educational 64-bit processor" }, - { EM_HUANY , "Harvard's machine-independent format" }, - { EM_PRISM , "SiTera Prism" }, - { EM_AVR , "Atmel AVR 8-bit microcontroller" }, - { EM_FR30 , "Fujitsu FR30" }, - { EM_D10V , "Mitsubishi D10V" }, - { EM_D30V , "Mitsubishi D30V" }, - { EM_V850 , "NEC v850" }, - { EM_M32R , "Renesas M32R (formerly Mitsubishi M32R)" }, - { EM_MN10300 , "Matsushita MN10300" }, - { EM_MN10200 , "Matsushita MN10200" }, - { EM_PJ , "picoJava" }, - { EM_OPENRISC , "OpenRISC 32-bit embedded processor" }, - { EM_ARC_A5 , "ARC Cores Tangent-A5" }, - { EM_XTENSA , "Tensilica Xtensa Architecture" }, - { EM_VIDEOCORE , "Alphamosaic VideoCore processor" }, - { EM_TMM_GPP , "Thompson Multimedia General Purpose Processor" }, - { EM_NS32K , "National Semiconductor 32000 series" }, - { EM_TPC , "Tenor Network TPC processor" }, - { EM_SNP1K , "Trebia SNP 1000 processor" }, - { EM_ST200 , "STMicroelectronics ST200 microcontroller" }, - { EM_IP2K , "Ubicom IP2022 micro controller" }, - { EM_MAX , "MAX Processor" }, - { EM_CR , "National Semiconductor CompactRISC" }, - { EM_F2MC16 , "Fujitsu F2MC16" }, - { EM_MSP430 , "TI msp430 micro controller" }, - { EM_BLACKFIN , "ADI Blackfin" }, - { EM_SE_C33 , "S1C33 Family of Seiko Epson processors" }, - { EM_SEP , "Sharp embedded microprocessor" }, - { EM_ARCA , "Arca RISC Microprocessor" }, - { EM_UNICORE , "Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University" }, - { EM_EXCESS , "eXcess: 16/32/64-bit configurable embedded CPU" }, - { EM_DXP , "Icera Semiconductor Inc. Deep Execution Processor" }, - { EM_ALTERA_NIOS2 , "Altera Nios II soft-core processor" }, - { EM_CRX , "National Semiconductor CRX" }, - { EM_XGATE , "Motorola XGATE embedded processor" }, - { EM_C166 , "Infineon C16x/XC16x processor" }, - { EM_M16C , "Renesas M16C series microprocessors" }, - { EM_DSPIC30F , "Microchip Technology dsPIC30F Digital Signal Controller" }, - { EM_CE , "Freescale Communication Engine RISC core" }, - { EM_M32C , "Renesas M32C series microprocessors" }, - { EM_res121 , "Reserved" }, - { EM_res122 , "Reserved" }, - { EM_res123 , "Reserved" }, - { EM_res124 , "Reserved" }, - { EM_res125 , "Reserved" }, - { EM_res126 , "Reserved" }, - { EM_res127 , "Reserved" }, - { EM_res128 , "Reserved" }, - { EM_res129 , "Reserved" }, - { EM_res130 , "Reserved" }, - { EM_TSK3000 , "Altium TSK3000 core" }, - { EM_RS08 , "Freescale RS08 embedded processor" }, - { EM_res133 , "Reserved" }, - { EM_ECOG2 , "Cyan Technology eCOG2 microprocessor" }, - { EM_SCORE , "Sunplus Score" }, - { EM_SCORE7 , "Sunplus S+core7 RISC processor" }, - { EM_DSP24 , "New Japan Radio (NJR) 24-bit DSP Processor" }, - { EM_VIDEOCORE3 , "Broadcom VideoCore III processor" }, - { EM_LATTICEMICO32, "RISC processor for Lattice FPGA architecture" }, - { EM_SE_C17 , "Seiko Epson C17 family" }, - { EM_TI_C6000 , "Texas Instruments TMS320C6000 DSP family" }, - { EM_TI_C2000 , "Texas Instruments TMS320C2000 DSP family" }, - { EM_TI_C5500 , "Texas Instruments TMS320C55x DSP family" }, - { EM_res143 , "Reserved" }, - { EM_res144 , "Reserved" }, - { EM_res145 , "Reserved" }, - { EM_res146 , "Reserved" }, - { EM_res147 , "Reserved" }, - { EM_res148 , "Reserved" }, - { EM_res149 , "Reserved" }, - { EM_res150 , "Reserved" }, - { EM_res151 , "Reserved" }, - { EM_res152 , "Reserved" }, - { EM_res153 , "Reserved" }, - { EM_res154 , "Reserved" }, - { EM_res155 , "Reserved" }, - { EM_res156 , "Reserved" }, - { EM_res157 , "Reserved" }, - { EM_res158 , "Reserved" }, - { EM_res159 , "Reserved" }, - { EM_MMDSP_PLUS , "STMicroelectronics 64bit VLIW Data Signal Processor" }, - { EM_CYPRESS_M8C , "Cypress M8C microprocessor" }, - { EM_R32C , "Renesas R32C series microprocessors" }, - { EM_TRIMEDIA , "NXP Semiconductors TriMedia architecture family" }, - { EM_QDSP6 , "QUALCOMM DSP6 Processor" }, - { EM_8051 , "Intel 8051 and variants" }, - { EM_STXP7X , "STMicroelectronics STxP7x family" }, - { EM_NDS32 , "Andes Technology compact code size embedded RISC processor family" }, - { EM_ECOG1 , "Cyan Technology eCOG1X family" }, - { EM_ECOG1X , "Cyan Technology eCOG1X family" }, - { EM_MAXQ30 , "Dallas Semiconductor MAXQ30 Core Micro-controllers" }, - { EM_XIMO16 , "New Japan Radio (NJR) 16-bit DSP Processor" }, - { EM_MANIK , "M2000 Reconfigurable RISC Microprocessor" }, - { EM_CRAYNV2 , "Cray Inc. NV2 vector architecture" }, - { EM_RX , "Renesas RX family" }, - { EM_METAG , "Imagination Technologies META processor architecture" }, - { EM_MCST_ELBRUS , "MCST Elbrus general purpose hardware architecture" }, - { EM_ECOG16 , "Cyan Technology eCOG16 family" }, - { EM_CR16 , "National Semiconductor CompactRISC 16-bit processor" }, - { EM_ETPU , "Freescale Extended Time Processing Unit" }, - { EM_SLE9X , "Infineon Technologies SLE9X core" }, - { EM_L1OM , "Intel L1OM" }, - { EM_INTEL181 , "Reserved by Intel" }, - { EM_INTEL182 , "Reserved by Intel" }, - { EM_res183 , "Reserved by ARM" }, - { EM_res184 , "Reserved by ARM" }, - { EM_AVR32 , "Atmel Corporation 32-bit microprocessor family" }, - { EM_STM8 , "STMicroeletronics STM8 8-bit microcontroller" }, - { EM_TILE64 , "Tilera TILE64 multicore architecture family" }, - { EM_TILEPRO , "Tilera TILEPro multicore architecture family" }, - { EM_MICROBLAZE , "Xilinx MicroBlaze 32-bit RISC soft processor core" }, - { EM_CUDA , "NVIDIA CUDA architecture " }, -}; - - -static struct section_type_table_t { - const Elf64_Half key; - const char* str; -} section_type_table [] = -{ - { SHT_NULL , "NULL" }, - { SHT_PROGBITS , "PROGBITS" }, - { SHT_SYMTAB , "SYMTAB" }, - { SHT_STRTAB , "STRTAB" }, - { SHT_RELA , "RELA" }, - { SHT_HASH , "HASH" }, - { SHT_DYNAMIC , "DYNAMIC" }, - { SHT_NOTE , "NOTE" }, - { SHT_NOBITS , "NOBITS" }, - { SHT_REL , "REL" }, - { SHT_SHLIB , "SHLIB" }, - { SHT_DYNSYM , "DYNSYM" }, - { SHT_INIT_ARRAY , "INIT_ARRAY" }, - { SHT_FINI_ARRAY , "FINI_ARRAY" }, - { SHT_PREINIT_ARRAY, "PREINIT_ARRAY" }, - { SHT_GROUP , "GROUP" }, - { SHT_SYMTAB_SHNDX , "SYMTAB_SHNDX " }, -}; - - -static struct segment_type_table_t { - const Elf_Word key; - const char* str; -} segment_type_table [] = -{ - { PT_NULL , "NULL" }, - { PT_LOAD , "LOAD" }, - { PT_DYNAMIC, "DYNAMIC" }, - { PT_INTERP , "INTERP" }, - { PT_NOTE , "NOTE" }, - { PT_SHLIB , "SHLIB" }, - { PT_PHDR , "PHDR" }, - { PT_TLS , "TLS" }, -}; - - -static struct segment_flag_table_t { - const Elf_Word key; - const char* str; -} segment_flag_table [] = -{ - { 0, "" }, - { 1, "X" }, - { 2, "W" }, - { 3, "WX" }, - { 4, "R" }, - { 5, "RX" }, - { 6, "RW" }, - { 7, "RWX" }, -}; - - -static struct symbol_bind_t { - const Elf_Word key; - const char* str; -} symbol_bind_table [] = -{ - { STB_LOCAL , "LOCAL" }, - { STB_GLOBAL , "GLOBAL" }, - { STB_WEAK , "WEAK" }, - { STB_LOOS , "LOOS" }, - { STB_HIOS , "HIOS" }, - { STB_MULTIDEF, "MULTIDEF" }, - { STB_LOPROC , "LOPROC" }, - { STB_HIPROC , "HIPROC" }, -}; - - -static struct symbol_type_t { - const Elf_Word key; - const char* str; -} symbol_type_table [] = -{ - { STT_NOTYPE , "NOTYPE" }, - { STT_OBJECT , "OBJECT" }, - { STT_FUNC , "FUNC" }, - { STT_SECTION, "SECTION" }, - { STT_FILE , "FILE" }, - { STT_COMMON , "COMMON" }, - { STT_TLS , "TLS" }, - { STT_LOOS , "LOOS" }, - { STT_HIOS , "HIOS" }, - { STT_LOPROC , "LOPROC" }, - { STT_HIPROC , "HIPROC" }, -}; - - -//------------------------------------------------------------------------------ -class dump -{ -#define DUMP_DEC_FORMAT( width ) std::setw(width) << std::setfill( ' ' ) << \ - std::dec << std::right -#define DUMP_HEX_FORMAT( width ) std::setw(width) << std::setfill( '0' ) << \ - std::hex << std::right -#define DUMP_STR_FORMAT( width ) std::setw(width) << std::setfill( ' ' ) << \ - std::hex << std::left - - public: -//------------------------------------------------------------------------------ - static void - header( std::ostream& out, const elfio& reader ) - { - out << "ELF Header" << std::endl << std::endl - << " Class: " << str_class( reader.get_class() ) << std::endl - << " Encoding: " << str_endian( reader.get_encoding() ) << std::endl - << " ELFVersion: " << str_version( reader.get_elf_version() ) << std::endl - << " Type: " << str_type( reader.get_type() ) << std::endl - << " Machine: " << str_machine( reader.get_machine() ) << std::endl - << " Version: " << str_version( reader.get_version() ) << std::endl - << " Entry: " << "0x" << std::hex << reader.get_entry() << std::endl - << " Flags: " << "0x" << std::hex << reader.get_flags() << std::endl - << std::endl; - } - -//------------------------------------------------------------------------------ - static void - section_headers( std::ostream& out, const elfio& reader ) - { - Elf_Half n = reader.sections.size(); - - if ( n > 0 ) { - out - << "Section Headers:" << std::endl - << "[ Nr ] Type Addr Size ES Flg Lk Inf Al Name" << std::endl; - - for ( Elf_Half i = 0; i < n; ++i ) { // For all sections - section* sec = reader.sections[i]; - section_header( out, i, sec ); - } - - out << "Key to Flags: W (write), A (alloc), X (execute)\n\n" - << std::endl; - } - } - -//------------------------------------------------------------------------------ - static void - section_header( std::ostream& out, Elf_Half no, const section* sec ) - { - std::ios_base::fmtflags original_flags = out.flags(); - out << "[" - << DUMP_DEC_FORMAT( 5 ) << no - << "] " - << DUMP_STR_FORMAT( 17 ) << str_section_type( sec->get_type() ) << " " - << DUMP_HEX_FORMAT( 8 ) << sec->get_address() << " " - << DUMP_HEX_FORMAT( 8 ) << sec->get_size() << " " - << DUMP_HEX_FORMAT( 2 ) << sec->get_entry_size() << " " - << DUMP_STR_FORMAT( 3 ) << section_flags( sec->get_flags() ) << " " - << DUMP_DEC_FORMAT( 2 ) << sec->get_link() << " " - << DUMP_DEC_FORMAT( 3 ) << sec->get_info() << " " - << DUMP_DEC_FORMAT( 2 ) << sec->get_addr_align() << " " - << DUMP_STR_FORMAT( 17 ) << sec->get_name() << " " - << std::endl; - out.flags(original_flags); - - return; - } - -//------------------------------------------------------------------------------ - static void - segment_headers( std::ostream& out, const elfio& reader ) - { - Elf_Half n = reader.segments.size(); - if ( n > 0 ) { - out << "Segment headers:" << std::endl - << "[ Nr ] Type VirtAddr PhysAddr FileSize Mem.Size Flags Align" - << std::endl; - - for ( Elf_Half i = 0; i < n; ++i ) { - segment* seg = reader.segments[i]; - segment_header( out, i, seg ); - } - - out << std::endl; - } - } - -//------------------------------------------------------------------------------ - static void - segment_header( std::ostream& out, Elf_Half no, const segment* seg ) - { - std::ios_base::fmtflags original_flags = out.flags(); - out << "[" - << DUMP_DEC_FORMAT( 5 ) << no - << "] " - << DUMP_STR_FORMAT( 14 ) << str_segment_type( seg->get_type() ) << " " - << DUMP_HEX_FORMAT( 8 ) << seg->get_virtual_address() << " " - << DUMP_HEX_FORMAT( 8 ) << seg->get_physical_address() << " " - << DUMP_HEX_FORMAT( 8 ) << seg->get_file_size() << " " - << DUMP_HEX_FORMAT( 8 ) << seg->get_memory_size() << " " - << DUMP_STR_FORMAT( 8 ) << str_segment_flag( seg->get_flags() ) << " " - << DUMP_HEX_FORMAT( 8 ) << seg->get_align() << " " - << std::endl; - out.flags(original_flags); - } - -//------------------------------------------------------------------------------ - static void - symbol_tables( std::ostream& out, const elfio& reader ) - { - Elf_Half n = reader.sections.size(); - for ( Elf_Half i = 0; i < n; ++i ) { // For all sections - section* sec = reader.sections[i]; - if ( SHT_SYMTAB == sec->get_type() || SHT_DYNSYM == sec->get_type() ) { - symbol_section_accessor symbols( reader, sec ); - - Elf_Xword sym_no = symbols.get_symbols_num(); - if ( sym_no > 0 ) { - out << "Symbol table (" << sec->get_name() << ")" << std::endl - << "[ Nr ] Value Size Type Bind Sect Name" - << std::endl; - - for ( int i = 0; i < sym_no; ++i ) { - std::string name; - Elf64_Addr value; - Elf_Xword size; - unsigned char bind; - unsigned char type; - Elf_Half section; - unsigned char other; - symbols.get_symbol( i, name, value, size, bind, type, section, other ); - symbol_table( out, i, name, value, size, bind, type, section ); - } - - out << std::endl; - } - } - } - } - -//------------------------------------------------------------------------------ - static void - symbol_table( std::ostream& out, - Elf_Half no, - std::string& name, - Elf64_Addr value, - Elf_Xword size, - unsigned char bind, - unsigned char type, - Elf_Half section ) - { - std::ios_base::fmtflags original_flags = out.flags(); - out << "[" - << DUMP_DEC_FORMAT( 5 ) << no - << "] " - << DUMP_HEX_FORMAT( 8 ) << value << " " - << DUMP_HEX_FORMAT( 8 ) << size << " " - << DUMP_STR_FORMAT( 7 ) << str_symbol_type( type ) << " " - << DUMP_STR_FORMAT( 8 ) << str_symbol_bind( bind ) << " " - << DUMP_DEC_FORMAT( 5 ) << section << " " - << DUMP_STR_FORMAT( 1 ) << name << " " - << std::endl; - out.flags(original_flags); - } - -//------------------------------------------------------------------------------ - static void - notes( std::ostream& out, const elfio& reader ) - { - Elf_Half no = reader.sections.size(); - for ( Elf_Half i = 0; i < no; ++i ) { // For all sections - section* sec = reader.sections[i]; - if ( SHT_NOTE == sec->get_type() ) { // Look at notes - note_section_accessor notes( reader, sec ); - int no_notes = notes.get_notes_num(); - if ( no > 0 ) { - out << "Note section (" << sec->get_name() << ")" << std::endl - << " No Type Name" - << std::endl; - for ( int j = 0; j < no_notes; ++j ) { // For all notes - Elf_Word type; - std::string name; - void* desc; - Elf_Word descsz; - - notes.get_note( j, type, name, desc, descsz ); - // 'name' usually contains \0 at the end. Try to fix it - name = name.c_str(); - note( out, j, type, name ); - } - - out << std::endl; - } - } - } - } - -//------------------------------------------------------------------------------ - static void - note( std::ostream& out, - int no, - Elf_Word type, - const std::string& name ) - { - out << " [" - << DUMP_DEC_FORMAT( 2 ) << no - << "] " - << DUMP_HEX_FORMAT( 8 ) << type << " " - << DUMP_STR_FORMAT( 1 ) << name - << std::endl; - } - - - private: -//------------------------------------------------------------------------------ - template< typename T, typename K > - std::string - static - find_value_in_table( const T& table, const K& key ) - { - std::string res = "UNKNOWN"; - for ( unsigned int i = 0; i < sizeof( table )/sizeof( table[0] ); ++i ) { - if ( table[i].key == key ) { - res = table[i].str; - break; - } - } - - return res; - } - - -//------------------------------------------------------------------------------ - template< typename T, typename K > - static - std::string - format_assoc( const T& table, const K& key ) - { - std::string str = find_value_in_table( table, key ); - if ( str == "UNKNOWN" ) { - std::ostringstream oss; - oss << str << " (0x" << std::hex << key << ")"; - str = oss.str(); - } - - return str; - } - - -//------------------------------------------------------------------------------ - template< typename T > - static - std::string - format_assoc( const T& table, const char key ) - { - return format_assoc( table, (const int)key ); - } - - -//------------------------------------------------------------------------------ - static - std::string - section_flags( Elf_Xword flags ) - { - std::string ret = ""; - if ( flags & SHF_WRITE ) { - ret += "W"; - } - if ( flags & SHF_ALLOC ) { - ret += "A"; - } - if ( flags & SHF_EXECINSTR ) { - ret += "X"; - } - - return ret; - } - - -//------------------------------------------------------------------------------ -#define STR_FUNC_TABLE( name ) \ - template< typename T > \ - static \ - std::string \ - str_##name( const T key ) \ - { \ - return format_assoc( name##_table, key ); \ - } - - STR_FUNC_TABLE( class ); - STR_FUNC_TABLE( endian ); - STR_FUNC_TABLE( version ); - STR_FUNC_TABLE( type ); - STR_FUNC_TABLE( machine ); - STR_FUNC_TABLE( section_type ); - STR_FUNC_TABLE( segment_type ); - STR_FUNC_TABLE( segment_flag ); - STR_FUNC_TABLE( symbol_bind ); - STR_FUNC_TABLE( symbol_type ); - -#undef STR_FUNC_TABLE -#undef DUMP_DEC_FORMAT -#undef DUMP_HEX_FORMAT -#undef DUMP_STR_FORMAT -}; - - -}; // namespace ELFIO - -#endif // ELFIO_DUMP_HPP +/* +Copyright (C) 2001-2011 by Serge Lamikhov-Center + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef ELFIO_DUMP_HPP +#define ELFIO_DUMP_HPP + +#include <string> +#include <ostream> +#include <sstream> +#include <iomanip> +#include <elfio/elfio.hpp> + +namespace ELFIO { + + +static struct class_table_t { + const char key; + const char* str; +} class_table [] = +{ + { ELFCLASS32, "ELF32" }, + { ELFCLASS64, "ELF64" }, +}; + + +static struct endian_table_t { + const char key; + const char* str; +} endian_table [] = +{ + { ELFDATANONE, "None" }, + { ELFDATA2LSB, "Little endian" }, + { ELFDATA2MSB, "Big endian" }, +}; + + +static struct version_table_t { + const Elf64_Word key; + const char* str; +} version_table [] = +{ + { EV_NONE , "None" }, + { EV_CURRENT, "Current" }, +}; + + +static struct type_table_t { + const Elf32_Half key; + const char* str; +} type_table [] = +{ + { ET_NONE, "No file type" }, + { ET_REL , "Relocatable file" }, + { ET_EXEC, "Executable file" }, + { ET_DYN , "Shared object file" }, + { ET_CORE, "Core file" }, +}; + + +static struct machine_table_t { + const Elf64_Half key; + const char* str; +} machine_table [] = +{ + { EM_NONE , "No machine" }, + { EM_M32 , "AT&T WE 32100" }, + { EM_SPARC , "SUN SPARC" }, + { EM_386 , "Intel 80386" }, + { EM_68K , "Motorola m68k family" }, + { EM_88K , "Motorola m88k family" }, + { EM_486 , "Intel 80486// Reserved for future use" }, + { EM_860 , "Intel 80860" }, + { EM_MIPS , "MIPS R3000 (officially, big-endian only)" }, + { EM_S370 , "IBM System/370" }, + { EM_MIPS_RS3_LE , "MIPS R3000 little-endian (Oct 4 1999 Draft) Deprecated" }, + { EM_res011 , "Reserved" }, + { EM_res012 , "Reserved" }, + { EM_res013 , "Reserved" }, + { EM_res014 , "Reserved" }, + { EM_PARISC , "HPPA" }, + { EM_res016 , "Reserved" }, + { EM_VPP550 , "Fujitsu VPP500" }, + { EM_SPARC32PLUS , "Sun's v8plus" }, + { EM_960 , "Intel 80960" }, + { EM_PPC , "PowerPC" }, + { EM_PPC64 , "64-bit PowerPC" }, + { EM_S390 , "IBM S/390" }, + { EM_SPU , "Sony/Toshiba/IBM SPU" }, + { EM_res024 , "Reserved" }, + { EM_res025 , "Reserved" }, + { EM_res026 , "Reserved" }, + { EM_res027 , "Reserved" }, + { EM_res028 , "Reserved" }, + { EM_res029 , "Reserved" }, + { EM_res030 , "Reserved" }, + { EM_res031 , "Reserved" }, + { EM_res032 , "Reserved" }, + { EM_res033 , "Reserved" }, + { EM_res034 , "Reserved" }, + { EM_res035 , "Reserved" }, + { EM_V800 , "NEC V800 series" }, + { EM_FR20 , "Fujitsu FR20" }, + { EM_RH32 , "TRW RH32" }, + { EM_MCORE , "Motorola M*Core // May also be taken by Fujitsu MMA" }, + { EM_RCE , "Old name for MCore" }, + { EM_ARM , "ARM" }, + { EM_OLD_ALPHA , "Digital Alpha" }, + { EM_SH , "Renesas (formerly Hitachi) / SuperH SH" }, + { EM_SPARCV9 , "SPARC v9 64-bit" }, + { EM_TRICORE , "Siemens Tricore embedded processor" }, + { EM_ARC , "ARC Cores" }, + { EM_H8_300 , "Renesas (formerly Hitachi) H8/300" }, + { EM_H8_300H , "Renesas (formerly Hitachi) H8/300H" }, + { EM_H8S , "Renesas (formerly Hitachi) H8S" }, + { EM_H8_500 , "Renesas (formerly Hitachi) H8/500" }, + { EM_IA_64 , "Intel IA-64 Processor" }, + { EM_MIPS_X , "Stanford MIPS-X" }, + { EM_COLDFIRE , "Motorola Coldfire" }, + { EM_68HC12 , "Motorola M68HC12" }, + { EM_MMA , "Fujitsu Multimedia Accelerator" }, + { EM_PCP , "Siemens PCP" }, + { EM_NCPU , "Sony nCPU embedded RISC processor" }, + { EM_NDR1 , "Denso NDR1 microprocesspr" }, + { EM_STARCORE , "Motorola Star*Core processor" }, + { EM_ME16 , "Toyota ME16 processor" }, + { EM_ST100 , "STMicroelectronics ST100 processor" }, + { EM_TINYJ , "Advanced Logic Corp. TinyJ embedded processor" }, + { EM_X86_64 , "Advanced Micro Devices X86-64 processor" }, + { EM_PDSP , "Sony DSP Processor" }, + { EM_PDP10 , "Digital Equipment Corp. PDP-10" }, + { EM_PDP11 , "Digital Equipment Corp. PDP-11" }, + { EM_FX66 , "Siemens FX66 microcontroller" }, + { EM_ST9PLUS , "STMicroelectronics ST9+ 8/16 bit microcontroller" }, + { EM_ST7 , "STMicroelectronics ST7 8-bit microcontroller" }, + { EM_68HC16 , "Motorola MC68HC16 Microcontroller" }, + { EM_68HC11 , "Motorola MC68HC11 Microcontroller" }, + { EM_68HC08 , "Motorola MC68HC08 Microcontroller" }, + { EM_68HC05 , "Motorola MC68HC05 Microcontroller" }, + { EM_SVX , "Silicon Graphics SVx" }, + { EM_ST19 , "STMicroelectronics ST19 8-bit cpu" }, + { EM_VAX , "Digital VAX" }, + { EM_CRIS , "Axis Communications 32-bit embedded processor" }, + { EM_JAVELIN , "Infineon Technologies 32-bit embedded cpu" }, + { EM_FIREPATH , "Element 14 64-bit DSP processor" }, + { EM_ZSP , "LSI Logic's 16-bit DSP processor" }, + { EM_MMIX , "Donald Knuth's educational 64-bit processor" }, + { EM_HUANY , "Harvard's machine-independent format" }, + { EM_PRISM , "SiTera Prism" }, + { EM_AVR , "Atmel AVR 8-bit microcontroller" }, + { EM_FR30 , "Fujitsu FR30" }, + { EM_D10V , "Mitsubishi D10V" }, + { EM_D30V , "Mitsubishi D30V" }, + { EM_V850 , "NEC v850" }, + { EM_M32R , "Renesas M32R (formerly Mitsubishi M32R)" }, + { EM_MN10300 , "Matsushita MN10300" }, + { EM_MN10200 , "Matsushita MN10200" }, + { EM_PJ , "picoJava" }, + { EM_OPENRISC , "OpenRISC 32-bit embedded processor" }, + { EM_ARC_A5 , "ARC Cores Tangent-A5" }, + { EM_XTENSA , "Tensilica Xtensa Architecture" }, + { EM_VIDEOCORE , "Alphamosaic VideoCore processor" }, + { EM_TMM_GPP , "Thompson Multimedia General Purpose Processor" }, + { EM_NS32K , "National Semiconductor 32000 series" }, + { EM_TPC , "Tenor Network TPC processor" }, + { EM_SNP1K , "Trebia SNP 1000 processor" }, + { EM_ST200 , "STMicroelectronics ST200 microcontroller" }, + { EM_IP2K , "Ubicom IP2022 micro controller" }, + { EM_MAX , "MAX Processor" }, + { EM_CR , "National Semiconductor CompactRISC" }, + { EM_F2MC16 , "Fujitsu F2MC16" }, + { EM_MSP430 , "TI msp430 micro controller" }, + { EM_BLACKFIN , "ADI Blackfin" }, + { EM_SE_C33 , "S1C33 Family of Seiko Epson processors" }, + { EM_SEP , "Sharp embedded microprocessor" }, + { EM_ARCA , "Arca RISC Microprocessor" }, + { EM_UNICORE , "Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University" }, + { EM_EXCESS , "eXcess: 16/32/64-bit configurable embedded CPU" }, + { EM_DXP , "Icera Semiconductor Inc. Deep Execution Processor" }, + { EM_ALTERA_NIOS2 , "Altera Nios II soft-core processor" }, + { EM_CRX , "National Semiconductor CRX" }, + { EM_XGATE , "Motorola XGATE embedded processor" }, + { EM_C166 , "Infineon C16x/XC16x processor" }, + { EM_M16C , "Renesas M16C series microprocessors" }, + { EM_DSPIC30F , "Microchip Technology dsPIC30F Digital Signal Controller" }, + { EM_CE , "Freescale Communication Engine RISC core" }, + { EM_M32C , "Renesas M32C series microprocessors" }, + { EM_res121 , "Reserved" }, + { EM_res122 , "Reserved" }, + { EM_res123 , "Reserved" }, + { EM_res124 , "Reserved" }, + { EM_res125 , "Reserved" }, + { EM_res126 , "Reserved" }, + { EM_res127 , "Reserved" }, + { EM_res128 , "Reserved" }, + { EM_res129 , "Reserved" }, + { EM_res130 , "Reserved" }, + { EM_TSK3000 , "Altium TSK3000 core" }, + { EM_RS08 , "Freescale RS08 embedded processor" }, + { EM_res133 , "Reserved" }, + { EM_ECOG2 , "Cyan Technology eCOG2 microprocessor" }, + { EM_SCORE , "Sunplus Score" }, + { EM_SCORE7 , "Sunplus S+core7 RISC processor" }, + { EM_DSP24 , "New Japan Radio (NJR) 24-bit DSP Processor" }, + { EM_VIDEOCORE3 , "Broadcom VideoCore III processor" }, + { EM_LATTICEMICO32, "RISC processor for Lattice FPGA architecture" }, + { EM_SE_C17 , "Seiko Epson C17 family" }, + { EM_TI_C6000 , "Texas Instruments TMS320C6000 DSP family" }, + { EM_TI_C2000 , "Texas Instruments TMS320C2000 DSP family" }, + { EM_TI_C5500 , "Texas Instruments TMS320C55x DSP family" }, + { EM_res143 , "Reserved" }, + { EM_res144 , "Reserved" }, + { EM_res145 , "Reserved" }, + { EM_res146 , "Reserved" }, + { EM_res147 , "Reserved" }, + { EM_res148 , "Reserved" }, + { EM_res149 , "Reserved" }, + { EM_res150 , "Reserved" }, + { EM_res151 , "Reserved" }, + { EM_res152 , "Reserved" }, + { EM_res153 , "Reserved" }, + { EM_res154 , "Reserved" }, + { EM_res155 , "Reserved" }, + { EM_res156 , "Reserved" }, + { EM_res157 , "Reserved" }, + { EM_res158 , "Reserved" }, + { EM_res159 , "Reserved" }, + { EM_MMDSP_PLUS , "STMicroelectronics 64bit VLIW Data Signal Processor" }, + { EM_CYPRESS_M8C , "Cypress M8C microprocessor" }, + { EM_R32C , "Renesas R32C series microprocessors" }, + { EM_TRIMEDIA , "NXP Semiconductors TriMedia architecture family" }, + { EM_QDSP6 , "QUALCOMM DSP6 Processor" }, + { EM_8051 , "Intel 8051 and variants" }, + { EM_STXP7X , "STMicroelectronics STxP7x family" }, + { EM_NDS32 , "Andes Technology compact code size embedded RISC processor family" }, + { EM_ECOG1 , "Cyan Technology eCOG1X family" }, + { EM_ECOG1X , "Cyan Technology eCOG1X family" }, + { EM_MAXQ30 , "Dallas Semiconductor MAXQ30 Core Micro-controllers" }, + { EM_XIMO16 , "New Japan Radio (NJR) 16-bit DSP Processor" }, + { EM_MANIK , "M2000 Reconfigurable RISC Microprocessor" }, + { EM_CRAYNV2 , "Cray Inc. NV2 vector architecture" }, + { EM_RX , "Renesas RX family" }, + { EM_METAG , "Imagination Technologies META processor architecture" }, + { EM_MCST_ELBRUS , "MCST Elbrus general purpose hardware architecture" }, + { EM_ECOG16 , "Cyan Technology eCOG16 family" }, + { EM_CR16 , "National Semiconductor CompactRISC 16-bit processor" }, + { EM_ETPU , "Freescale Extended Time Processing Unit" }, + { EM_SLE9X , "Infineon Technologies SLE9X core" }, + { EM_L1OM , "Intel L1OM" }, + { EM_INTEL181 , "Reserved by Intel" }, + { EM_INTEL182 , "Reserved by Intel" }, + { EM_res183 , "Reserved by ARM" }, + { EM_res184 , "Reserved by ARM" }, + { EM_AVR32 , "Atmel Corporation 32-bit microprocessor family" }, + { EM_STM8 , "STMicroeletronics STM8 8-bit microcontroller" }, + { EM_TILE64 , "Tilera TILE64 multicore architecture family" }, + { EM_TILEPRO , "Tilera TILEPro multicore architecture family" }, + { EM_MICROBLAZE , "Xilinx MicroBlaze 32-bit RISC soft processor core" }, + { EM_CUDA , "NVIDIA CUDA architecture " }, +}; + + +static struct section_type_table_t { + const Elf64_Half key; + const char* str; +} section_type_table [] = +{ + { SHT_NULL , "NULL" }, + { SHT_PROGBITS , "PROGBITS" }, + { SHT_SYMTAB , "SYMTAB" }, + { SHT_STRTAB , "STRTAB" }, + { SHT_RELA , "RELA" }, + { SHT_HASH , "HASH" }, + { SHT_DYNAMIC , "DYNAMIC" }, + { SHT_NOTE , "NOTE" }, + { SHT_NOBITS , "NOBITS" }, + { SHT_REL , "REL" }, + { SHT_SHLIB , "SHLIB" }, + { SHT_DYNSYM , "DYNSYM" }, + { SHT_INIT_ARRAY , "INIT_ARRAY" }, + { SHT_FINI_ARRAY , "FINI_ARRAY" }, + { SHT_PREINIT_ARRAY, "PREINIT_ARRAY" }, + { SHT_GROUP , "GROUP" }, + { SHT_SYMTAB_SHNDX , "SYMTAB_SHNDX " }, +}; + + +static struct segment_type_table_t { + const Elf_Word key; + const char* str; +} segment_type_table [] = +{ + { PT_NULL , "NULL" }, + { PT_LOAD , "LOAD" }, + { PT_DYNAMIC, "DYNAMIC" }, + { PT_INTERP , "INTERP" }, + { PT_NOTE , "NOTE" }, + { PT_SHLIB , "SHLIB" }, + { PT_PHDR , "PHDR" }, + { PT_TLS , "TLS" }, +}; + + +static struct segment_flag_table_t { + const Elf_Word key; + const char* str; +} segment_flag_table [] = +{ + { 0, "" }, + { 1, "X" }, + { 2, "W" }, + { 3, "WX" }, + { 4, "R" }, + { 5, "RX" }, + { 6, "RW" }, + { 7, "RWX" }, +}; + + +static struct symbol_bind_t { + const Elf_Word key; + const char* str; +} symbol_bind_table [] = +{ + { STB_LOCAL , "LOCAL" }, + { STB_GLOBAL , "GLOBAL" }, + { STB_WEAK , "WEAK" }, + { STB_LOOS , "LOOS" }, + { STB_HIOS , "HIOS" }, + { STB_MULTIDEF, "MULTIDEF" }, + { STB_LOPROC , "LOPROC" }, + { STB_HIPROC , "HIPROC" }, +}; + + +static struct symbol_type_t { + const Elf_Word key; + const char* str; +} symbol_type_table [] = +{ + { STT_NOTYPE , "NOTYPE" }, + { STT_OBJECT , "OBJECT" }, + { STT_FUNC , "FUNC" }, + { STT_SECTION, "SECTION" }, + { STT_FILE , "FILE" }, + { STT_COMMON , "COMMON" }, + { STT_TLS , "TLS" }, + { STT_LOOS , "LOOS" }, + { STT_HIOS , "HIOS" }, + { STT_LOPROC , "LOPROC" }, + { STT_HIPROC , "HIPROC" }, +}; + + +//------------------------------------------------------------------------------ +class dump +{ +#define DUMP_DEC_FORMAT( width ) std::setw(width) << std::setfill( ' ' ) << \ + std::dec << std::right +#define DUMP_HEX_FORMAT( width ) std::setw(width) << std::setfill( '0' ) << \ + std::hex << std::right +#define DUMP_STR_FORMAT( width ) std::setw(width) << std::setfill( ' ' ) << \ + std::hex << std::left + + public: +//------------------------------------------------------------------------------ + static void + header( std::ostream& out, const elfio& reader ) + { + out << "ELF Header" << std::endl << std::endl + << " Class: " << str_class( reader.get_class() ) << std::endl + << " Encoding: " << str_endian( reader.get_encoding() ) << std::endl + << " ELFVersion: " << str_version( reader.get_elf_version() ) << std::endl + << " Type: " << str_type( reader.get_type() ) << std::endl + << " Machine: " << str_machine( reader.get_machine() ) << std::endl + << " Version: " << str_version( reader.get_version() ) << std::endl + << " Entry: " << "0x" << std::hex << reader.get_entry() << std::endl + << " Flags: " << "0x" << std::hex << reader.get_flags() << std::endl + << std::endl; + } + +//------------------------------------------------------------------------------ + static void + section_headers( std::ostream& out, const elfio& reader ) + { + Elf_Half n = reader.sections.size(); + + if ( n > 0 ) { + out + << "Section Headers:" << std::endl + << "[ Nr ] Type Addr Size ES Flg Lk Inf Al Name" << std::endl; + + for ( Elf_Half i = 0; i < n; ++i ) { // For all sections + section* sec = reader.sections[i]; + section_header( out, i, sec ); + } + + out << "Key to Flags: W (write), A (alloc), X (execute)\n\n" + << std::endl; + } + } + +//------------------------------------------------------------------------------ + static void + section_header( std::ostream& out, Elf_Half no, const section* sec ) + { + std::ios_base::fmtflags original_flags = out.flags(); + out << "[" + << DUMP_DEC_FORMAT( 5 ) << no + << "] " + << DUMP_STR_FORMAT( 17 ) << str_section_type( sec->get_type() ) << " " + << DUMP_HEX_FORMAT( 8 ) << sec->get_address() << " " + << DUMP_HEX_FORMAT( 8 ) << sec->get_size() << " " + << DUMP_HEX_FORMAT( 2 ) << sec->get_entry_size() << " " + << DUMP_STR_FORMAT( 3 ) << section_flags( sec->get_flags() ) << " " + << DUMP_DEC_FORMAT( 2 ) << sec->get_link() << " " + << DUMP_DEC_FORMAT( 3 ) << sec->get_info() << " " + << DUMP_DEC_FORMAT( 2 ) << sec->get_addr_align() << " " + << DUMP_STR_FORMAT( 17 ) << sec->get_name() << " " + << std::endl; + out.flags(original_flags); + + return; + } + +//------------------------------------------------------------------------------ + static void + segment_headers( std::ostream& out, const elfio& reader ) + { + Elf_Half n = reader.segments.size(); + if ( n > 0 ) { + out << "Segment headers:" << std::endl + << "[ Nr ] Type VirtAddr PhysAddr FileSize Mem.Size Flags Align" + << std::endl; + + for ( Elf_Half i = 0; i < n; ++i ) { + segment* seg = reader.segments[i]; + segment_header( out, i, seg ); + } + + out << std::endl; + } + } + +//------------------------------------------------------------------------------ + static void + segment_header( std::ostream& out, Elf_Half no, const segment* seg ) + { + std::ios_base::fmtflags original_flags = out.flags(); + out << "[" + << DUMP_DEC_FORMAT( 5 ) << no + << "] " + << DUMP_STR_FORMAT( 14 ) << str_segment_type( seg->get_type() ) << " " + << DUMP_HEX_FORMAT( 8 ) << seg->get_virtual_address() << " " + << DUMP_HEX_FORMAT( 8 ) << seg->get_physical_address() << " " + << DUMP_HEX_FORMAT( 8 ) << seg->get_file_size() << " " + << DUMP_HEX_FORMAT( 8 ) << seg->get_memory_size() << " " + << DUMP_STR_FORMAT( 8 ) << str_segment_flag( seg->get_flags() ) << " " + << DUMP_HEX_FORMAT( 8 ) << seg->get_align() << " " + << std::endl; + out.flags(original_flags); + } + +//------------------------------------------------------------------------------ + static void + symbol_tables( std::ostream& out, const elfio& reader ) + { + Elf_Half n = reader.sections.size(); + for ( Elf_Half i = 0; i < n; ++i ) { // For all sections + section* sec = reader.sections[i]; + if ( SHT_SYMTAB == sec->get_type() || SHT_DYNSYM == sec->get_type() ) { + symbol_section_accessor symbols( reader, sec ); + + Elf_Xword sym_no = symbols.get_symbols_num(); + if ( sym_no > 0 ) { + out << "Symbol table (" << sec->get_name() << ")" << std::endl + << "[ Nr ] Value Size Type Bind Sect Name" + << std::endl; + + for ( int i = 0; i < sym_no; ++i ) { + std::string name; + Elf64_Addr value; + Elf_Xword size; + unsigned char bind; + unsigned char type; + Elf_Half section; + unsigned char other; + symbols.get_symbol( i, name, value, size, bind, type, section, other ); + symbol_table( out, i, name, value, size, bind, type, section ); + } + + out << std::endl; + } + } + } + } + +//------------------------------------------------------------------------------ + static void + symbol_table( std::ostream& out, + Elf_Half no, + std::string& name, + Elf64_Addr value, + Elf_Xword size, + unsigned char bind, + unsigned char type, + Elf_Half section ) + { + std::ios_base::fmtflags original_flags = out.flags(); + out << "[" + << DUMP_DEC_FORMAT( 5 ) << no + << "] " + << DUMP_HEX_FORMAT( 8 ) << value << " " + << DUMP_HEX_FORMAT( 8 ) << size << " " + << DUMP_STR_FORMAT( 7 ) << str_symbol_type( type ) << " " + << DUMP_STR_FORMAT( 8 ) << str_symbol_bind( bind ) << " " + << DUMP_DEC_FORMAT( 5 ) << section << " " + << DUMP_STR_FORMAT( 1 ) << name << " " + << std::endl; + out.flags(original_flags); + } + +//------------------------------------------------------------------------------ + static void + notes( std::ostream& out, const elfio& reader ) + { + Elf_Half no = reader.sections.size(); + for ( Elf_Half i = 0; i < no; ++i ) { // For all sections + section* sec = reader.sections[i]; + if ( SHT_NOTE == sec->get_type() ) { // Look at notes + note_section_accessor notes( reader, sec ); + int no_notes = notes.get_notes_num(); + if ( no > 0 ) { + out << "Note section (" << sec->get_name() << ")" << std::endl + << " No Type Name" + << std::endl; + for ( int j = 0; j < no_notes; ++j ) { // For all notes + Elf_Word type; + std::string name; + void* desc; + Elf_Word descsz; + + notes.get_note( j, type, name, desc, descsz ); + // 'name' usually contains \0 at the end. Try to fix it + name = name.c_str(); + note( out, j, type, name ); + } + + out << std::endl; + } + } + } + } + +//------------------------------------------------------------------------------ + static void + note( std::ostream& out, + int no, + Elf_Word type, + const std::string& name ) + { + out << " [" + << DUMP_DEC_FORMAT( 2 ) << no + << "] " + << DUMP_HEX_FORMAT( 8 ) << type << " " + << DUMP_STR_FORMAT( 1 ) << name + << std::endl; + } + + + private: +//------------------------------------------------------------------------------ + template< typename T, typename K > + std::string + static + find_value_in_table( const T& table, const K& key ) + { + std::string res = "UNKNOWN"; + for ( unsigned int i = 0; i < sizeof( table )/sizeof( table[0] ); ++i ) { + if ( table[i].key == key ) { + res = table[i].str; + break; + } + } + + return res; + } + + +//------------------------------------------------------------------------------ + template< typename T, typename K > + static + std::string + format_assoc( const T& table, const K& key ) + { + std::string str = find_value_in_table( table, key ); + if ( str == "UNKNOWN" ) { + std::ostringstream oss; + oss << str << " (0x" << std::hex << key << ")"; + str = oss.str(); + } + + return str; + } + + +//------------------------------------------------------------------------------ + template< typename T > + static + std::string + format_assoc( const T& table, const char key ) + { + return format_assoc( table, (const int)key ); + } + + +//------------------------------------------------------------------------------ + static + std::string + section_flags( Elf_Xword flags ) + { + std::string ret = ""; + if ( flags & SHF_WRITE ) { + ret += "W"; + } + if ( flags & SHF_ALLOC ) { + ret += "A"; + } + if ( flags & SHF_EXECINSTR ) { + ret += "X"; + } + + return ret; + } + + +//------------------------------------------------------------------------------ +#define STR_FUNC_TABLE( name ) \ + template< typename T > \ + static \ + std::string \ + str_##name( const T key ) \ + { \ + return format_assoc( name##_table, key ); \ + } + + STR_FUNC_TABLE( class ); + STR_FUNC_TABLE( endian ); + STR_FUNC_TABLE( version ); + STR_FUNC_TABLE( type ); + STR_FUNC_TABLE( machine ); + STR_FUNC_TABLE( section_type ); + STR_FUNC_TABLE( segment_type ); + STR_FUNC_TABLE( segment_flag ); + STR_FUNC_TABLE( symbol_bind ); + STR_FUNC_TABLE( symbol_type ); + +#undef STR_FUNC_TABLE +#undef DUMP_DEC_FORMAT +#undef DUMP_HEX_FORMAT +#undef DUMP_STR_FORMAT +}; + + +}; // namespace ELFIO + +#endif // ELFIO_DUMP_HPP diff --git a/elfio/elfio_header.hpp b/elfio/elfio_header.hpp index c3a0a95c8a6c73c3089c97eeff50a5a6a74151b1..c4ad61f6fe508a8d5133c4dafae83c8dd0baaa1f 100644 --- a/elfio/elfio_header.hpp +++ b/elfio/elfio_header.hpp @@ -1,146 +1,146 @@ -/* -Copyright (C) 2001-2011 by Serge Lamikhov-Center - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef ELF_HEADER_HPP -#define ELF_HEADER_HPP - -#include <fstream> - -namespace ELFIO { - -class elf_header -{ - public: - virtual ~elf_header() {}; - virtual bool load( std::ifstream& stream ) = 0; - virtual bool save( std::ofstream& stream ) const = 0; - - // ELF header functions - ELFIO_GET_ACCESS_DECL( unsigned char, class ); - ELFIO_GET_ACCESS_DECL( unsigned char, elf_version ); - ELFIO_GET_ACCESS_DECL( unsigned char, encoding ); - ELFIO_GET_ACCESS_DECL( Elf_Word, version ); - ELFIO_GET_ACCESS_DECL( Elf_Half, header_size ); - ELFIO_GET_ACCESS_DECL( Elf_Half, section_entry_size ); - ELFIO_GET_ACCESS_DECL( Elf_Half, segment_entry_size ); - - ELFIO_GET_SET_ACCESS_DECL( unsigned char, os_abi ); - ELFIO_GET_SET_ACCESS_DECL( unsigned char, abi_version ); - ELFIO_GET_SET_ACCESS_DECL( Elf_Half, type ); - ELFIO_GET_SET_ACCESS_DECL( Elf_Half, machine ); - ELFIO_GET_SET_ACCESS_DECL( Elf_Word, flags ); - ELFIO_GET_SET_ACCESS_DECL( Elf64_Addr, entry ); - ELFIO_GET_SET_ACCESS_DECL( Elf_Half, sections_num ); - ELFIO_GET_SET_ACCESS_DECL( Elf64_Off, sections_offset ); - ELFIO_GET_SET_ACCESS_DECL( Elf_Half, segments_num ); - ELFIO_GET_SET_ACCESS_DECL( Elf64_Off, segments_offset ); - ELFIO_GET_SET_ACCESS_DECL( Elf_Half, section_name_str_index ); -}; - - -template< class T > struct elf_header_impl_types; -template<> struct elf_header_impl_types<Elf32_Ehdr> { - typedef Elf32_Phdr Phdr_type; - typedef Elf32_Shdr Shdr_type; - static const unsigned char file_class = ELFCLASS32; -}; -template<> struct elf_header_impl_types<Elf64_Ehdr> { - typedef Elf64_Phdr Phdr_type; - typedef Elf64_Shdr Shdr_type; - static const unsigned char file_class = ELFCLASS64; -}; - -template< class T > class elf_header_impl : public elf_header -{ - public: - elf_header_impl( endianess_convertor* convertor_, - unsigned char encoding ) - { - convertor = convertor_; - - std::fill_n( reinterpret_cast<char*>( &header ), sizeof( header ), '\0' ); - - header.e_ident[EI_MAG0] = ELFMAG0; - header.e_ident[EI_MAG1] = ELFMAG1; - header.e_ident[EI_MAG2] = ELFMAG2; - header.e_ident[EI_MAG3] = ELFMAG3; - header.e_ident[EI_CLASS] = elf_header_impl_types<T>::file_class; - header.e_ident[EI_DATA] = encoding; - header.e_ident[EI_VERSION] = EV_CURRENT; - header.e_version = EV_CURRENT; - header.e_version = (*convertor)( header.e_version ); - header.e_ehsize = ( sizeof( header ) ); - header.e_ehsize = (*convertor)( header.e_ehsize ); - header.e_shstrndx = (*convertor)( (Elf_Half)1 ); - header.e_phentsize = sizeof( typename elf_header_impl_types<T>::Phdr_type ); - header.e_shentsize = sizeof( typename elf_header_impl_types<T>::Shdr_type ); - header.e_phentsize = (*convertor)( header.e_phentsize ); - header.e_shentsize = (*convertor)( header.e_shentsize ); - } - - bool - load( std::ifstream& stream ) - { - stream.seekg( 0 ); - stream.read( reinterpret_cast<char*>( &header ), sizeof( header ) ); - - return (stream.gcount() == sizeof( header ) ); - } - - bool - save( std::ofstream& stream ) const - { - stream.seekp( 0 ); - stream.write( reinterpret_cast<const char*>( &header ), sizeof( header ) ); - - return stream.good(); - } - - // ELF header functions - ELFIO_GET_ACCESS( unsigned char, class, header.e_ident[EI_CLASS] ); - ELFIO_GET_ACCESS( unsigned char, elf_version, header.e_ident[EI_VERSION] ); - ELFIO_GET_ACCESS( unsigned char, encoding, header.e_ident[EI_DATA] ); - ELFIO_GET_ACCESS( Elf_Word, version, header.e_version ); - ELFIO_GET_ACCESS( Elf_Half, header_size, header.e_ehsize ); - ELFIO_GET_ACCESS( Elf_Half, section_entry_size, header.e_shentsize ); - ELFIO_GET_ACCESS( Elf_Half, segment_entry_size, header.e_phentsize ); - - ELFIO_GET_SET_ACCESS( unsigned char, os_abi, header.e_ident[EI_OSABI] ); - ELFIO_GET_SET_ACCESS( unsigned char, abi_version, header.e_ident[EI_ABIVERSION] ); - ELFIO_GET_SET_ACCESS( Elf_Half, type, header.e_type ); - ELFIO_GET_SET_ACCESS( Elf_Half, machine, header.e_machine ); - ELFIO_GET_SET_ACCESS( Elf_Word, flags, header.e_flags ); - ELFIO_GET_SET_ACCESS( Elf_Half, section_name_str_index, header.e_shstrndx ); - ELFIO_GET_SET_ACCESS( Elf64_Addr, entry, header.e_entry ); - ELFIO_GET_SET_ACCESS( Elf_Half, sections_num, header.e_shnum ); - ELFIO_GET_SET_ACCESS( Elf64_Off, sections_offset, header.e_shoff ); - ELFIO_GET_SET_ACCESS( Elf_Half, segments_num, header.e_phnum ); - ELFIO_GET_SET_ACCESS( Elf64_Off, segments_offset, header.e_phoff ); - - private: - T header; - endianess_convertor* convertor; -}; - -} // namespace ELFIO - -#endif // ELF_HEADER_HPP +/* +Copyright (C) 2001-2011 by Serge Lamikhov-Center + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef ELF_HEADER_HPP +#define ELF_HEADER_HPP + +#include <fstream> + +namespace ELFIO { + +class elf_header +{ + public: + virtual ~elf_header() {}; + virtual bool load( std::ifstream& stream ) = 0; + virtual bool save( std::ofstream& stream ) const = 0; + + // ELF header functions + ELFIO_GET_ACCESS_DECL( unsigned char, class ); + ELFIO_GET_ACCESS_DECL( unsigned char, elf_version ); + ELFIO_GET_ACCESS_DECL( unsigned char, encoding ); + ELFIO_GET_ACCESS_DECL( Elf_Word, version ); + ELFIO_GET_ACCESS_DECL( Elf_Half, header_size ); + ELFIO_GET_ACCESS_DECL( Elf_Half, section_entry_size ); + ELFIO_GET_ACCESS_DECL( Elf_Half, segment_entry_size ); + + ELFIO_GET_SET_ACCESS_DECL( unsigned char, os_abi ); + ELFIO_GET_SET_ACCESS_DECL( unsigned char, abi_version ); + ELFIO_GET_SET_ACCESS_DECL( Elf_Half, type ); + ELFIO_GET_SET_ACCESS_DECL( Elf_Half, machine ); + ELFIO_GET_SET_ACCESS_DECL( Elf_Word, flags ); + ELFIO_GET_SET_ACCESS_DECL( Elf64_Addr, entry ); + ELFIO_GET_SET_ACCESS_DECL( Elf_Half, sections_num ); + ELFIO_GET_SET_ACCESS_DECL( Elf64_Off, sections_offset ); + ELFIO_GET_SET_ACCESS_DECL( Elf_Half, segments_num ); + ELFIO_GET_SET_ACCESS_DECL( Elf64_Off, segments_offset ); + ELFIO_GET_SET_ACCESS_DECL( Elf_Half, section_name_str_index ); +}; + + +template< class T > struct elf_header_impl_types; +template<> struct elf_header_impl_types<Elf32_Ehdr> { + typedef Elf32_Phdr Phdr_type; + typedef Elf32_Shdr Shdr_type; + static const unsigned char file_class = ELFCLASS32; +}; +template<> struct elf_header_impl_types<Elf64_Ehdr> { + typedef Elf64_Phdr Phdr_type; + typedef Elf64_Shdr Shdr_type; + static const unsigned char file_class = ELFCLASS64; +}; + +template< class T > class elf_header_impl : public elf_header +{ + public: + elf_header_impl( endianess_convertor* convertor_, + unsigned char encoding ) + { + convertor = convertor_; + + std::fill_n( reinterpret_cast<char*>( &header ), sizeof( header ), '\0' ); + + header.e_ident[EI_MAG0] = ELFMAG0; + header.e_ident[EI_MAG1] = ELFMAG1; + header.e_ident[EI_MAG2] = ELFMAG2; + header.e_ident[EI_MAG3] = ELFMAG3; + header.e_ident[EI_CLASS] = elf_header_impl_types<T>::file_class; + header.e_ident[EI_DATA] = encoding; + header.e_ident[EI_VERSION] = EV_CURRENT; + header.e_version = EV_CURRENT; + header.e_version = (*convertor)( header.e_version ); + header.e_ehsize = ( sizeof( header ) ); + header.e_ehsize = (*convertor)( header.e_ehsize ); + header.e_shstrndx = (*convertor)( (Elf_Half)1 ); + header.e_phentsize = sizeof( typename elf_header_impl_types<T>::Phdr_type ); + header.e_shentsize = sizeof( typename elf_header_impl_types<T>::Shdr_type ); + header.e_phentsize = (*convertor)( header.e_phentsize ); + header.e_shentsize = (*convertor)( header.e_shentsize ); + } + + bool + load( std::ifstream& stream ) + { + stream.seekg( 0 ); + stream.read( reinterpret_cast<char*>( &header ), sizeof( header ) ); + + return (stream.gcount() == sizeof( header ) ); + } + + bool + save( std::ofstream& stream ) const + { + stream.seekp( 0 ); + stream.write( reinterpret_cast<const char*>( &header ), sizeof( header ) ); + + return stream.good(); + } + + // ELF header functions + ELFIO_GET_ACCESS( unsigned char, class, header.e_ident[EI_CLASS] ); + ELFIO_GET_ACCESS( unsigned char, elf_version, header.e_ident[EI_VERSION] ); + ELFIO_GET_ACCESS( unsigned char, encoding, header.e_ident[EI_DATA] ); + ELFIO_GET_ACCESS( Elf_Word, version, header.e_version ); + ELFIO_GET_ACCESS( Elf_Half, header_size, header.e_ehsize ); + ELFIO_GET_ACCESS( Elf_Half, section_entry_size, header.e_shentsize ); + ELFIO_GET_ACCESS( Elf_Half, segment_entry_size, header.e_phentsize ); + + ELFIO_GET_SET_ACCESS( unsigned char, os_abi, header.e_ident[EI_OSABI] ); + ELFIO_GET_SET_ACCESS( unsigned char, abi_version, header.e_ident[EI_ABIVERSION] ); + ELFIO_GET_SET_ACCESS( Elf_Half, type, header.e_type ); + ELFIO_GET_SET_ACCESS( Elf_Half, machine, header.e_machine ); + ELFIO_GET_SET_ACCESS( Elf_Word, flags, header.e_flags ); + ELFIO_GET_SET_ACCESS( Elf_Half, section_name_str_index, header.e_shstrndx ); + ELFIO_GET_SET_ACCESS( Elf64_Addr, entry, header.e_entry ); + ELFIO_GET_SET_ACCESS( Elf_Half, sections_num, header.e_shnum ); + ELFIO_GET_SET_ACCESS( Elf64_Off, sections_offset, header.e_shoff ); + ELFIO_GET_SET_ACCESS( Elf_Half, segments_num, header.e_phnum ); + ELFIO_GET_SET_ACCESS( Elf64_Off, segments_offset, header.e_phoff ); + + private: + T header; + endianess_convertor* convertor; +}; + +} // namespace ELFIO + +#endif // ELF_HEADER_HPP diff --git a/elfio/elfio_note.hpp b/elfio/elfio_note.hpp index 8c9de722373db8b255ed7c41f84c4d68cd7ddd9d..810008f581d1f776e39e664872dd2a7d1714cb61 100644 --- a/elfio/elfio_note.hpp +++ b/elfio/elfio_note.hpp @@ -1,157 +1,157 @@ -/* -Copyright (C) 2001-2011 by Serge Lamikhov-Center - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef ELFIO_NOTE_HPP -#define ELFIO_NOTE_HPP - -namespace ELFIO { - -//------------------------------------------------------------------------------ -class note_section_accessor -{ - public: -//------------------------------------------------------------------------------ - note_section_accessor( const elfio& elf_file_, section* section_ ) : - elf_file( elf_file_ ), note_section( section_ ) - { - process_section(); - } - -//------------------------------------------------------------------------------ - Elf_Word - get_notes_num() const - { - return (Elf_Word)note_start_positions.size(); - } - -//------------------------------------------------------------------------------ - bool - get_note( Elf_Word index, - Elf_Word& type, - std::string& name, - void*& desc, - Elf_Word& descSize ) const - { - if ( index >= note_section->get_size() ) { - return false; - } - - const char* pData = note_section->get_data() + note_start_positions[index]; - - const endianess_convertor& convertor = elf_file.get_convertor(); - type = convertor( *(Elf_Word*)( pData + 2*sizeof( Elf_Word ) ) ); - Elf_Word namesz = convertor( *(Elf_Word*)( pData ) ); - name.assign( pData + 3*sizeof( Elf_Word ), namesz ); - descSize = convertor( *(Elf_Word*)( pData + sizeof( namesz ) ) ); - if ( 0 == descSize ) { - desc = 0; - } - else { - int align = sizeof( Elf_Xword ); - if ( elf_file.get_class() == ELFCLASS32 ) { - align = sizeof( Elf_Word ); - } - desc = const_cast<char*> ( pData + 3*sizeof( Elf_Word ) + - ( ( namesz + align - 1 ) / align ) * align ); - } - - return true; - } - -//------------------------------------------------------------------------------ - void add_note( Elf_Word type, - const std::string& name, - const void* desc, - Elf_Word descSize ) - { - const endianess_convertor& convertor = elf_file.get_convertor(); - - Elf_Word nameLen = (Elf_Word)name.size() + 1; - Elf_Word nameLenConv = convertor( nameLen ); - std::string buffer( reinterpret_cast<char*>( &nameLenConv ), sizeof( nameLenConv ) ); - Elf_Word descSizeConv = convertor( descSize ); - buffer.append( reinterpret_cast<char*>( &descSizeConv ), sizeof( descSizeConv ) ); - type = convertor( type ); - buffer.append( reinterpret_cast<char*>( &type ), sizeof( type ) ); - buffer.append( name ); - buffer.append( 1, '\x00' ); - const char pad[] = { '\0', '\0', '\0', '\0' }; - if ( nameLen % sizeof( Elf_Word ) != 0 ) { - buffer.append( pad, sizeof( Elf_Word ) - - nameLen % sizeof( Elf_Word ) ); - } - if ( desc != 0 && descSize != 0 ) { - buffer.append( reinterpret_cast<const char*>( desc ), descSize ); - if ( descSize % sizeof( Elf_Word ) != 0 ) { - buffer.append( pad, sizeof( Elf_Word ) - - descSize % sizeof( Elf_Word ) ); - } - } - - note_start_positions.push_back( note_section->get_size() ); - note_section->append_data( buffer ); - } - - private: -//------------------------------------------------------------------------------ - void process_section() - { - const endianess_convertor& convertor = elf_file.get_convertor(); - const char* data = note_section->get_data(); - Elf_Xword size = note_section->get_size(); - Elf_Xword current = 0; - - note_start_positions.clear(); - - // Is it empty? - if ( 0 == data || 0 == size ) { - return; - } - - while ( current + 3*sizeof( Elf_Word ) <= size ) { - note_start_positions.push_back( current ); - Elf_Word namesz = convertor( - *(Elf_Word*)( data + current ) ); - Elf_Word descsz = convertor( - *(Elf_Word*)( data + current + sizeof( namesz ) ) ); - - int align = sizeof( Elf_Xword ); - if ( elf_file.get_class() == ELFCLASS32 ) { - align = sizeof( Elf_Word ); - } - - current += 3*sizeof( Elf_Word ) + - ( ( namesz + align - 1 ) / align ) * align + - ( ( descsz + align - 1 ) / align ) * align; - } - } - -//------------------------------------------------------------------------------ - private: - const elfio& elf_file; - section* note_section; - std::vector<Elf_Xword> note_start_positions; -}; - -} // namespace ELFIO - -#endif // ELFIO_NOTE_HPP +/* +Copyright (C) 2001-2011 by Serge Lamikhov-Center + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef ELFIO_NOTE_HPP +#define ELFIO_NOTE_HPP + +namespace ELFIO { + +//------------------------------------------------------------------------------ +class note_section_accessor +{ + public: +//------------------------------------------------------------------------------ + note_section_accessor( const elfio& elf_file_, section* section_ ) : + elf_file( elf_file_ ), note_section( section_ ) + { + process_section(); + } + +//------------------------------------------------------------------------------ + Elf_Word + get_notes_num() const + { + return (Elf_Word)note_start_positions.size(); + } + +//------------------------------------------------------------------------------ + bool + get_note( Elf_Word index, + Elf_Word& type, + std::string& name, + void*& desc, + Elf_Word& descSize ) const + { + if ( index >= note_section->get_size() ) { + return false; + } + + const char* pData = note_section->get_data() + note_start_positions[index]; + + const endianess_convertor& convertor = elf_file.get_convertor(); + type = convertor( *(Elf_Word*)( pData + 2*sizeof( Elf_Word ) ) ); + Elf_Word namesz = convertor( *(Elf_Word*)( pData ) ); + name.assign( pData + 3*sizeof( Elf_Word ), namesz ); + descSize = convertor( *(Elf_Word*)( pData + sizeof( namesz ) ) ); + if ( 0 == descSize ) { + desc = 0; + } + else { + int align = sizeof( Elf_Xword ); + if ( elf_file.get_class() == ELFCLASS32 ) { + align = sizeof( Elf_Word ); + } + desc = const_cast<char*> ( pData + 3*sizeof( Elf_Word ) + + ( ( namesz + align - 1 ) / align ) * align ); + } + + return true; + } + +//------------------------------------------------------------------------------ + void add_note( Elf_Word type, + const std::string& name, + const void* desc, + Elf_Word descSize ) + { + const endianess_convertor& convertor = elf_file.get_convertor(); + + Elf_Word nameLen = (Elf_Word)name.size() + 1; + Elf_Word nameLenConv = convertor( nameLen ); + std::string buffer( reinterpret_cast<char*>( &nameLenConv ), sizeof( nameLenConv ) ); + Elf_Word descSizeConv = convertor( descSize ); + buffer.append( reinterpret_cast<char*>( &descSizeConv ), sizeof( descSizeConv ) ); + type = convertor( type ); + buffer.append( reinterpret_cast<char*>( &type ), sizeof( type ) ); + buffer.append( name ); + buffer.append( 1, '\x00' ); + const char pad[] = { '\0', '\0', '\0', '\0' }; + if ( nameLen % sizeof( Elf_Word ) != 0 ) { + buffer.append( pad, sizeof( Elf_Word ) - + nameLen % sizeof( Elf_Word ) ); + } + if ( desc != 0 && descSize != 0 ) { + buffer.append( reinterpret_cast<const char*>( desc ), descSize ); + if ( descSize % sizeof( Elf_Word ) != 0 ) { + buffer.append( pad, sizeof( Elf_Word ) - + descSize % sizeof( Elf_Word ) ); + } + } + + note_start_positions.push_back( note_section->get_size() ); + note_section->append_data( buffer ); + } + + private: +//------------------------------------------------------------------------------ + void process_section() + { + const endianess_convertor& convertor = elf_file.get_convertor(); + const char* data = note_section->get_data(); + Elf_Xword size = note_section->get_size(); + Elf_Xword current = 0; + + note_start_positions.clear(); + + // Is it empty? + if ( 0 == data || 0 == size ) { + return; + } + + while ( current + 3*sizeof( Elf_Word ) <= size ) { + note_start_positions.push_back( current ); + Elf_Word namesz = convertor( + *(Elf_Word*)( data + current ) ); + Elf_Word descsz = convertor( + *(Elf_Word*)( data + current + sizeof( namesz ) ) ); + + int align = sizeof( Elf_Xword ); + if ( elf_file.get_class() == ELFCLASS32 ) { + align = sizeof( Elf_Word ); + } + + current += 3*sizeof( Elf_Word ) + + ( ( namesz + align - 1 ) / align ) * align + + ( ( descsz + align - 1 ) / align ) * align; + } + } + +//------------------------------------------------------------------------------ + private: + const elfio& elf_file; + section* note_section; + std::vector<Elf_Xword> note_start_positions; +}; + +} // namespace ELFIO + +#endif // ELFIO_NOTE_HPP diff --git a/elfio/elfio_relocation.hpp b/elfio/elfio_relocation.hpp index 6c00f7fe11da544c2fe7969855ac618ea1bfa42f..3d26adc4f5866771120b1a4a35f23bd2ac0e510b 100644 --- a/elfio/elfio_relocation.hpp +++ b/elfio/elfio_relocation.hpp @@ -1,374 +1,374 @@ -/* -Copyright (C) 2001-2011 by Serge Lamikhov-Center - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef ELFI_RELOCATION_HPP -#define ELFI_RELOCATION_HPP - -namespace ELFIO { - -template<typename T> struct get_sym_and_type; -template<> struct get_sym_and_type< Elf32_Rel > -{ - static int get_r_sym( Elf_Xword info ) - { - return ELF32_R_SYM( (Elf_Word)info ); - } - static int get_r_type( Elf_Xword info ) - { - return ELF32_R_TYPE( (Elf_Word)info ); - } -}; -template<> struct get_sym_and_type< Elf32_Rela > -{ - static int get_r_sym( Elf_Xword info ) - { - return ELF32_R_SYM( (Elf_Word)info ); - } - static int get_r_type( Elf_Xword info ) - { - return ELF32_R_TYPE( (Elf_Word)info ); - } -}; -template<> struct get_sym_and_type< Elf64_Rel > -{ - static int get_r_sym( Elf_Xword info ) - { - return ELF64_R_SYM( info ); - } - static int get_r_type( Elf_Xword info ) - { - return ELF64_R_TYPE( info ); - } -}; -template<> struct get_sym_and_type< Elf64_Rela > -{ - static int get_r_sym( Elf_Xword info ) - { - return ELF64_R_SYM( info ); - } - static int get_r_type( Elf_Xword info ) - { - return ELF64_R_TYPE( info ); - } -}; - - -//------------------------------------------------------------------------------ -class relocation_section_accessor -{ - public: -//------------------------------------------------------------------------------ - relocation_section_accessor( elfio& elf_file_, section* section_ ) : - elf_file( elf_file_ ), - relocation_section( section_ ) - { - } - -//------------------------------------------------------------------------------ - Elf_Xword - get_entries_num() const - { - Elf_Xword nRet = 0; - - if ( 0 != relocation_section->get_entry_size() ) { - nRet = relocation_section->get_size() / relocation_section->get_entry_size(); - } - - return nRet; - } - -//------------------------------------------------------------------------------ - bool - get_entry( Elf_Xword index, - Elf64_Addr& offset, - Elf_Word& symbol, - Elf_Word& type, - Elf_Sxword& addend ) const - { - if ( index >= get_entries_num() ) { // Is index valid - return false; - } - - if ( elf_file.get_class() == ELFCLASS32 ) { - if ( SHT_REL == relocation_section->get_type() ) { - generic_get_entry_rel< Elf32_Rel >( index, offset, symbol, - type, addend ); - } - else if ( SHT_RELA == relocation_section->get_type() ) { - generic_get_entry_rela< Elf32_Rela >( index, offset, symbol, - type, addend ); - } - } - else { - if ( SHT_REL == relocation_section->get_type() ) { - generic_get_entry_rel< Elf64_Rel >( index, offset, symbol, - type, addend ); - } - else if ( SHT_RELA == relocation_section->get_type() ) { - generic_get_entry_rela< Elf64_Rela >( index, offset, symbol, - type, addend ); - } - } - - return true; - } - -//------------------------------------------------------------------------------ - bool - get_entry( Elf_Xword index, - Elf64_Addr& offset, - Elf64_Addr& symbolValue, - std::string& symbolName, - Elf_Word& type, - Elf_Sxword& addend, - Elf_Sxword& calcValue ) const - { - // Do regular job - Elf_Word symbol; - bool ret = get_entry( index, offset, symbol, type, addend ); - - // Find the symbol - Elf_Xword size; - unsigned char bind; - unsigned char symbolType; - Elf_Half section; - unsigned char other; - - symbol_section_accessor symbols( elf_file, elf_file.sections[get_symbol_table_index()] ); - ret = symbols.get_symbol( symbol, symbolName, symbolValue, - size, bind, symbolType, section, other ); - - if ( ret ) { // Was it successful? - switch ( type ) { - case R_386_NONE: // none - calcValue = 0; - break; - case R_386_32: // S + A - calcValue = symbolValue + addend; - break; - case R_386_PC32: // S + A - P - calcValue = symbolValue + addend - offset; - break; - case R_386_GOT32: // G + A - P - calcValue = 0; - break; - case R_386_PLT32: // L + A - P - calcValue = 0; - break; - case R_386_COPY: // none - calcValue = 0; - break; - case R_386_GLOB_DAT: // S - case R_386_JMP_SLOT: // S - calcValue = symbolValue; - break; - case R_386_RELATIVE: // B + A - calcValue = addend; - break; - case R_386_GOTOFF: // S + A - GOT - calcValue = 0; - break; - case R_386_GOTPC: // GOT + A - P - calcValue = 0; - break; - default: // Not recognized symbol! - calcValue = 0; - break; - } - } - - return ret; - } - -//------------------------------------------------------------------------------ - void - add_entry( Elf64_Addr offset, Elf_Xword info ) - { - if ( elf_file.get_class() == ELFCLASS32 ) { - generic_add_entry< Elf32_Rel >( offset, info ); - } - else { - generic_add_entry< Elf64_Rel >( offset, info ); - } - } - -//------------------------------------------------------------------------------ - void - add_entry( Elf64_Addr offset, Elf_Word symbol, unsigned char type ) - { - Elf_Xword info; - if ( elf_file.get_class() == ELFCLASS32 ) { - info = ELF32_R_INFO( symbol, type ); - } - else { - info = ELF64_R_INFO( symbol, type ); - } - - add_entry( offset, info ); - } - -//------------------------------------------------------------------------------ - void - add_entry( Elf64_Addr offset, Elf_Xword info, Elf_Sxword addend ) - { - if ( elf_file.get_class() == ELFCLASS32 ) { - generic_add_entry< Elf32_Rela >( offset, info, addend ); - } - else { - generic_add_entry< Elf64_Rela >( offset, info, addend ); - } - } - -//------------------------------------------------------------------------------ - void - add_entry( Elf64_Addr offset, Elf_Word symbol, unsigned char type, - Elf_Sxword addend ) - { - Elf_Xword info; - if ( elf_file.get_class() == ELFCLASS32 ) { - info = ELF32_R_INFO( symbol, type ); - } - else { - info = ELF64_R_INFO( symbol, type ); - } - - add_entry( offset, info, addend ); - } - -//------------------------------------------------------------------------------ - void - add_entry( string_section_accessor str_writer, - const char* str, - symbol_section_accessor sym_writer, - Elf64_Addr value, - Elf_Word size, - unsigned char sym_info, - unsigned char other, - Elf_Half shndx, - Elf64_Addr offset, - unsigned char type ) - { - Elf_Word str_index = str_writer.add_string( str ); - Elf_Word sym_index = sym_writer.add_symbol( str_index, value, size, - sym_info, other, shndx ); - add_entry( offset, sym_index, type ); - } - -//------------------------------------------------------------------------------ - private: -//------------------------------------------------------------------------------ - Elf_Half - get_symbol_table_index() const - { - return (Elf_Half)relocation_section->get_link(); - } - -//------------------------------------------------------------------------------ - Elf_Half - getTargetSectionIndex() const - { - return (Elf_Half)relocation_section->get_info(); - } - -//------------------------------------------------------------------------------ - template< class T > - void - generic_get_entry_rel( Elf_Xword index, - Elf64_Addr& offset, - Elf_Word& symbol, - Elf_Word& type, - Elf_Sxword& addend ) const - { - const endianess_convertor& convertor = elf_file.get_convertor(); - - const T* pEntry = reinterpret_cast<const T*>( - relocation_section->get_data() + - index * relocation_section->get_entry_size() ); - offset = convertor( pEntry->r_offset ); - Elf_Xword tmp = convertor( pEntry->r_info ); - symbol = get_sym_and_type<T>::get_r_sym( tmp ); - type = get_sym_and_type<T>::get_r_type( tmp ); - addend = 0; - } - -//------------------------------------------------------------------------------ - template< class T > - void - generic_get_entry_rela( Elf_Xword index, - Elf64_Addr& offset, - Elf_Word& symbol, - Elf_Word& type, - Elf_Sxword& addend ) const - { - const endianess_convertor& convertor = elf_file.get_convertor(); - - const T* pEntry = reinterpret_cast<const T*>( - relocation_section->get_data() + - index * relocation_section->get_entry_size() ); - offset = convertor( pEntry->r_offset ); - Elf_Xword tmp = convertor( pEntry->r_info ); - symbol = get_sym_and_type<T>::get_r_sym( tmp ); - type = get_sym_and_type<T>::get_r_type( tmp ); - addend = convertor( pEntry->r_addend ); - } - -//------------------------------------------------------------------------------ - template< class T > - void - generic_add_entry( Elf64_Addr offset, Elf_Xword info ) - { - const endianess_convertor& convertor = elf_file.get_convertor(); - - T entry; - entry.r_offset = convertor( offset ); - entry.r_info = convertor( info ); - - relocation_section->append_data( reinterpret_cast<char*>( &entry ), sizeof( entry ) ); - } - -//------------------------------------------------------------------------------ - template< class T > - void - generic_add_entry( Elf64_Addr offset, Elf_Xword info, Elf_Sxword addend ) - { - const endianess_convertor& convertor = elf_file.get_convertor(); - - T entry; - entry.r_offset = offset; - entry.r_info = info; - entry.r_addend = addend; - entry.r_offset = convertor( entry.r_offset ); - entry.r_info = convertor( entry.r_info ); - entry.r_addend = convertor( entry.r_addend ); - - relocation_section->append_data( reinterpret_cast<char*>( &entry ), sizeof( entry ) ); - } - -//------------------------------------------------------------------------------ - private: - elfio& elf_file; - section* relocation_section; -}; - -} // namespace ELFIO - -#endif // ELFI_RELOCATION_HPP +/* +Copyright (C) 2001-2011 by Serge Lamikhov-Center + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef ELFI_RELOCATION_HPP +#define ELFI_RELOCATION_HPP + +namespace ELFIO { + +template<typename T> struct get_sym_and_type; +template<> struct get_sym_and_type< Elf32_Rel > +{ + static int get_r_sym( Elf_Xword info ) + { + return ELF32_R_SYM( (Elf_Word)info ); + } + static int get_r_type( Elf_Xword info ) + { + return ELF32_R_TYPE( (Elf_Word)info ); + } +}; +template<> struct get_sym_and_type< Elf32_Rela > +{ + static int get_r_sym( Elf_Xword info ) + { + return ELF32_R_SYM( (Elf_Word)info ); + } + static int get_r_type( Elf_Xword info ) + { + return ELF32_R_TYPE( (Elf_Word)info ); + } +}; +template<> struct get_sym_and_type< Elf64_Rel > +{ + static int get_r_sym( Elf_Xword info ) + { + return ELF64_R_SYM( info ); + } + static int get_r_type( Elf_Xword info ) + { + return ELF64_R_TYPE( info ); + } +}; +template<> struct get_sym_and_type< Elf64_Rela > +{ + static int get_r_sym( Elf_Xword info ) + { + return ELF64_R_SYM( info ); + } + static int get_r_type( Elf_Xword info ) + { + return ELF64_R_TYPE( info ); + } +}; + + +//------------------------------------------------------------------------------ +class relocation_section_accessor +{ + public: +//------------------------------------------------------------------------------ + relocation_section_accessor( elfio& elf_file_, section* section_ ) : + elf_file( elf_file_ ), + relocation_section( section_ ) + { + } + +//------------------------------------------------------------------------------ + Elf_Xword + get_entries_num() const + { + Elf_Xword nRet = 0; + + if ( 0 != relocation_section->get_entry_size() ) { + nRet = relocation_section->get_size() / relocation_section->get_entry_size(); + } + + return nRet; + } + +//------------------------------------------------------------------------------ + bool + get_entry( Elf_Xword index, + Elf64_Addr& offset, + Elf_Word& symbol, + Elf_Word& type, + Elf_Sxword& addend ) const + { + if ( index >= get_entries_num() ) { // Is index valid + return false; + } + + if ( elf_file.get_class() == ELFCLASS32 ) { + if ( SHT_REL == relocation_section->get_type() ) { + generic_get_entry_rel< Elf32_Rel >( index, offset, symbol, + type, addend ); + } + else if ( SHT_RELA == relocation_section->get_type() ) { + generic_get_entry_rela< Elf32_Rela >( index, offset, symbol, + type, addend ); + } + } + else { + if ( SHT_REL == relocation_section->get_type() ) { + generic_get_entry_rel< Elf64_Rel >( index, offset, symbol, + type, addend ); + } + else if ( SHT_RELA == relocation_section->get_type() ) { + generic_get_entry_rela< Elf64_Rela >( index, offset, symbol, + type, addend ); + } + } + + return true; + } + +//------------------------------------------------------------------------------ + bool + get_entry( Elf_Xword index, + Elf64_Addr& offset, + Elf64_Addr& symbolValue, + std::string& symbolName, + Elf_Word& type, + Elf_Sxword& addend, + Elf_Sxword& calcValue ) const + { + // Do regular job + Elf_Word symbol; + bool ret = get_entry( index, offset, symbol, type, addend ); + + // Find the symbol + Elf_Xword size; + unsigned char bind; + unsigned char symbolType; + Elf_Half section; + unsigned char other; + + symbol_section_accessor symbols( elf_file, elf_file.sections[get_symbol_table_index()] ); + ret = symbols.get_symbol( symbol, symbolName, symbolValue, + size, bind, symbolType, section, other ); + + if ( ret ) { // Was it successful? + switch ( type ) { + case R_386_NONE: // none + calcValue = 0; + break; + case R_386_32: // S + A + calcValue = symbolValue + addend; + break; + case R_386_PC32: // S + A - P + calcValue = symbolValue + addend - offset; + break; + case R_386_GOT32: // G + A - P + calcValue = 0; + break; + case R_386_PLT32: // L + A - P + calcValue = 0; + break; + case R_386_COPY: // none + calcValue = 0; + break; + case R_386_GLOB_DAT: // S + case R_386_JMP_SLOT: // S + calcValue = symbolValue; + break; + case R_386_RELATIVE: // B + A + calcValue = addend; + break; + case R_386_GOTOFF: // S + A - GOT + calcValue = 0; + break; + case R_386_GOTPC: // GOT + A - P + calcValue = 0; + break; + default: // Not recognized symbol! + calcValue = 0; + break; + } + } + + return ret; + } + +//------------------------------------------------------------------------------ + void + add_entry( Elf64_Addr offset, Elf_Xword info ) + { + if ( elf_file.get_class() == ELFCLASS32 ) { + generic_add_entry< Elf32_Rel >( offset, info ); + } + else { + generic_add_entry< Elf64_Rel >( offset, info ); + } + } + +//------------------------------------------------------------------------------ + void + add_entry( Elf64_Addr offset, Elf_Word symbol, unsigned char type ) + { + Elf_Xword info; + if ( elf_file.get_class() == ELFCLASS32 ) { + info = ELF32_R_INFO( symbol, type ); + } + else { + info = ELF64_R_INFO( symbol, type ); + } + + add_entry( offset, info ); + } + +//------------------------------------------------------------------------------ + void + add_entry( Elf64_Addr offset, Elf_Xword info, Elf_Sxword addend ) + { + if ( elf_file.get_class() == ELFCLASS32 ) { + generic_add_entry< Elf32_Rela >( offset, info, addend ); + } + else { + generic_add_entry< Elf64_Rela >( offset, info, addend ); + } + } + +//------------------------------------------------------------------------------ + void + add_entry( Elf64_Addr offset, Elf_Word symbol, unsigned char type, + Elf_Sxword addend ) + { + Elf_Xword info; + if ( elf_file.get_class() == ELFCLASS32 ) { + info = ELF32_R_INFO( symbol, type ); + } + else { + info = ELF64_R_INFO( symbol, type ); + } + + add_entry( offset, info, addend ); + } + +//------------------------------------------------------------------------------ + void + add_entry( string_section_accessor str_writer, + const char* str, + symbol_section_accessor sym_writer, + Elf64_Addr value, + Elf_Word size, + unsigned char sym_info, + unsigned char other, + Elf_Half shndx, + Elf64_Addr offset, + unsigned char type ) + { + Elf_Word str_index = str_writer.add_string( str ); + Elf_Word sym_index = sym_writer.add_symbol( str_index, value, size, + sym_info, other, shndx ); + add_entry( offset, sym_index, type ); + } + +//------------------------------------------------------------------------------ + private: +//------------------------------------------------------------------------------ + Elf_Half + get_symbol_table_index() const + { + return (Elf_Half)relocation_section->get_link(); + } + +//------------------------------------------------------------------------------ + Elf_Half + getTargetSectionIndex() const + { + return (Elf_Half)relocation_section->get_info(); + } + +//------------------------------------------------------------------------------ + template< class T > + void + generic_get_entry_rel( Elf_Xword index, + Elf64_Addr& offset, + Elf_Word& symbol, + Elf_Word& type, + Elf_Sxword& addend ) const + { + const endianess_convertor& convertor = elf_file.get_convertor(); + + const T* pEntry = reinterpret_cast<const T*>( + relocation_section->get_data() + + index * relocation_section->get_entry_size() ); + offset = convertor( pEntry->r_offset ); + Elf_Xword tmp = convertor( pEntry->r_info ); + symbol = get_sym_and_type<T>::get_r_sym( tmp ); + type = get_sym_and_type<T>::get_r_type( tmp ); + addend = 0; + } + +//------------------------------------------------------------------------------ + template< class T > + void + generic_get_entry_rela( Elf_Xword index, + Elf64_Addr& offset, + Elf_Word& symbol, + Elf_Word& type, + Elf_Sxword& addend ) const + { + const endianess_convertor& convertor = elf_file.get_convertor(); + + const T* pEntry = reinterpret_cast<const T*>( + relocation_section->get_data() + + index * relocation_section->get_entry_size() ); + offset = convertor( pEntry->r_offset ); + Elf_Xword tmp = convertor( pEntry->r_info ); + symbol = get_sym_and_type<T>::get_r_sym( tmp ); + type = get_sym_and_type<T>::get_r_type( tmp ); + addend = convertor( pEntry->r_addend ); + } + +//------------------------------------------------------------------------------ + template< class T > + void + generic_add_entry( Elf64_Addr offset, Elf_Xword info ) + { + const endianess_convertor& convertor = elf_file.get_convertor(); + + T entry; + entry.r_offset = convertor( offset ); + entry.r_info = convertor( info ); + + relocation_section->append_data( reinterpret_cast<char*>( &entry ), sizeof( entry ) ); + } + +//------------------------------------------------------------------------------ + template< class T > + void + generic_add_entry( Elf64_Addr offset, Elf_Xword info, Elf_Sxword addend ) + { + const endianess_convertor& convertor = elf_file.get_convertor(); + + T entry; + entry.r_offset = offset; + entry.r_info = info; + entry.r_addend = addend; + entry.r_offset = convertor( entry.r_offset ); + entry.r_info = convertor( entry.r_info ); + entry.r_addend = convertor( entry.r_addend ); + + relocation_section->append_data( reinterpret_cast<char*>( &entry ), sizeof( entry ) ); + } + +//------------------------------------------------------------------------------ + private: + elfio& elf_file; + section* relocation_section; +}; + +} // namespace ELFIO + +#endif // ELFI_RELOCATION_HPP diff --git a/elfio/elfio_section.hpp b/elfio/elfio_section.hpp index b85cd5dec54edc9dac16d01e03b0884247c4c9b5..73f1e31b66b3fe0cabe51946a52d81df6727958b 100644 --- a/elfio/elfio_section.hpp +++ b/elfio/elfio_section.hpp @@ -1,274 +1,274 @@ -/* -Copyright (C) 2001-2011 by Serge Lamikhov-Center - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef ELFI_SECTION_HPP -#define ELFI_SECTION_HPP - -#include <string> -#include <fstream> - -namespace ELFIO { - -class section -{ - friend class elfio; - public: - virtual ~section() {}; - - virtual Elf_Half get_index() const = 0; - - ELFIO_GET_SET_ACCESS_DECL( std::string, name ); - ELFIO_GET_SET_ACCESS_DECL( Elf_Word, type ); - ELFIO_GET_SET_ACCESS_DECL( Elf_Xword, flags ); - ELFIO_GET_SET_ACCESS_DECL( Elf_Word, info ); - ELFIO_GET_SET_ACCESS_DECL( Elf_Word, link ); - ELFIO_GET_SET_ACCESS_DECL( Elf_Xword, addr_align ); - ELFIO_GET_SET_ACCESS_DECL( Elf_Xword, entry_size ); - ELFIO_GET_SET_ACCESS_DECL( Elf64_Addr, address ); - ELFIO_GET_SET_ACCESS_DECL( Elf_Xword, size ); - ELFIO_GET_SET_ACCESS_DECL( Elf_Word, name_string_offset ); - - virtual const char* get_data() const = 0; - virtual void set_data( const char* pData, Elf_Word size ) = 0; - virtual void set_data( const std::string& data ) = 0; - virtual void append_data( const char* pData, Elf_Word size ) = 0; - virtual void append_data( const std::string& data ) = 0; - - protected: - virtual void set_index( Elf_Half ) = 0; - virtual void load( std::ifstream& f, - std::streampos header_offset ) = 0; - virtual void save( std::ofstream& f, - std::streampos header_offset, - std::streampos data_offset ) = 0; - virtual bool is_address_initialized() const = 0; -}; - - -template< class T > -class section_impl : public section -{ - public: -//------------------------------------------------------------------------------ - section_impl( const endianess_convertor* convertor_ ) : convertor( convertor_ ) - { - std::fill_n( reinterpret_cast<char*>( &header ), sizeof( header ), '\0' ); - is_address_set = false; - data = 0; - data_size = 0; - } - -//------------------------------------------------------------------------------ - ~section_impl() - { - delete [] data; - } - -//------------------------------------------------------------------------------ - // Section info functions - ELFIO_GET_SET_ACCESS( Elf_Word, type, header.sh_type ); - ELFIO_GET_SET_ACCESS( Elf_Xword, flags, header.sh_flags ); - ELFIO_GET_SET_ACCESS( Elf_Xword, size, header.sh_size ); - ELFIO_GET_SET_ACCESS( Elf_Word, link, header.sh_link ); - ELFIO_GET_SET_ACCESS( Elf_Word, info, header.sh_info ); - ELFIO_GET_SET_ACCESS( Elf_Xword, addr_align, header.sh_addralign ); - ELFIO_GET_SET_ACCESS( Elf_Xword, entry_size, header.sh_entsize ); - ELFIO_GET_SET_ACCESS( Elf_Word, name_string_offset, header.sh_name ); - ELFIO_GET_ACCESS ( Elf64_Addr, address, header.sh_addr ); - -//------------------------------------------------------------------------------ - Elf_Half - get_index() const - { - return index; - } - - -//------------------------------------------------------------------------------ - std::string - get_name() const - { - return name; - } - -//------------------------------------------------------------------------------ - void - set_name( std::string name_ ) - { - name = name_; - } - -//------------------------------------------------------------------------------ - void - set_address( Elf64_Addr value ) - { - header.sh_addr = value; - header.sh_addr = (*convertor)( header.sh_addr ); - is_address_set = true; - } - -//------------------------------------------------------------------------------ - bool - is_address_initialized() const - { - return is_address_set; - } - -//------------------------------------------------------------------------------ - const char* - get_data() const - { - return data; - } - -//------------------------------------------------------------------------------ - void - set_data( const char* raw_data, Elf_Word size ) - { - if ( get_type() != SHT_NOBITS ) { - delete [] data; - data = new char[size]; - if ( 0 != data && 0 != raw_data ) { - data_size = size; - std::copy( raw_data, raw_data + size, data ); - } - } - - set_size( size ); - } - -//------------------------------------------------------------------------------ - void - set_data( const std::string& str_data ) - { - return set_data( str_data.c_str(), (Elf_Word)str_data.size() ); - } - -//------------------------------------------------------------------------------ - void - append_data( const char* raw_data, Elf_Word size ) - { - if ( get_type() != SHT_NOBITS ) { - if ( get_size() + size < data_size ) { - std::copy( raw_data, raw_data + size, data + get_size() ); - } - else { - data_size = 2*( data_size + size); - char* new_data = new char[data_size]; - if ( 0 != new_data ) { - std::copy( data, data + get_size(), new_data ); - std::copy( raw_data, raw_data + size, new_data + get_size() ); - delete [] data; - data = new_data; - } - } - set_size( get_size() + size ); - } - } - -//------------------------------------------------------------------------------ - void - append_data( const std::string& str_data ) - { - return append_data( str_data.c_str(), (Elf_Word)str_data.size() ); - } - -//------------------------------------------------------------------------------ - protected: -//------------------------------------------------------------------------------ - void - set_index( Elf_Half value ) - { - index = value; - } - -//------------------------------------------------------------------------------ - void - load( std::ifstream& stream, - std::streampos header_offset ) - { - std::fill_n( reinterpret_cast<char*>( &header ), sizeof( header ), '\0' ); - stream.seekg( header_offset ); - stream.read( reinterpret_cast<char*>( &header ), sizeof( header ) ); - - Elf_Xword size = get_size(); - if ( 0 == data && SHT_NULL != get_type() && SHT_NOBITS != get_type() && - 0 != size ) { - data = new char[size]; - stream.seekg( (*convertor)( header.sh_offset ) ); - stream.read( data, size ); - data_size = size; - } - } - -//------------------------------------------------------------------------------ - void - save( std::ofstream& f, - std::streampos header_offset, - std::streampos data_offset ) - { - if ( 0 != get_index() ) { - header.sh_offset = data_offset; - header.sh_offset = (*convertor)( header.sh_offset ); - } - - save_header( f, header_offset ); - if ( get_type() != SHT_NOBITS && get_type() != SHT_NULL && - get_size() != 0 && data != 0 ) { - save_data( f, data_offset ); - } - } - -//------------------------------------------------------------------------------ - private: -//------------------------------------------------------------------------------ - void - save_header( std::ofstream& f, - std::streampos header_offset ) const - { - f.seekp( header_offset ); - f.write( reinterpret_cast<const char*>( &header ), sizeof( header ) ); - } - -//------------------------------------------------------------------------------ - void - save_data( std::ofstream& f, - std::streampos data_offset ) const - { - f.seekp( data_offset ); - f.write( get_data(), get_size() ); - } - -//------------------------------------------------------------------------------ - private: - mutable T header; - Elf_Half index; - std::string name; - char* data; - Elf_Word data_size; - const endianess_convertor* convertor; - bool is_address_set; -}; - -} // namespace ELFIO - -#endif // ELFI_SECTION_HPP +/* +Copyright (C) 2001-2011 by Serge Lamikhov-Center + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef ELFI_SECTION_HPP +#define ELFI_SECTION_HPP + +#include <string> +#include <fstream> + +namespace ELFIO { + +class section +{ + friend class elfio; + public: + virtual ~section() {}; + + virtual Elf_Half get_index() const = 0; + + ELFIO_GET_SET_ACCESS_DECL( std::string, name ); + ELFIO_GET_SET_ACCESS_DECL( Elf_Word, type ); + ELFIO_GET_SET_ACCESS_DECL( Elf_Xword, flags ); + ELFIO_GET_SET_ACCESS_DECL( Elf_Word, info ); + ELFIO_GET_SET_ACCESS_DECL( Elf_Word, link ); + ELFIO_GET_SET_ACCESS_DECL( Elf_Xword, addr_align ); + ELFIO_GET_SET_ACCESS_DECL( Elf_Xword, entry_size ); + ELFIO_GET_SET_ACCESS_DECL( Elf64_Addr, address ); + ELFIO_GET_SET_ACCESS_DECL( Elf_Xword, size ); + ELFIO_GET_SET_ACCESS_DECL( Elf_Word, name_string_offset ); + + virtual const char* get_data() const = 0; + virtual void set_data( const char* pData, Elf_Word size ) = 0; + virtual void set_data( const std::string& data ) = 0; + virtual void append_data( const char* pData, Elf_Word size ) = 0; + virtual void append_data( const std::string& data ) = 0; + + protected: + virtual void set_index( Elf_Half ) = 0; + virtual void load( std::ifstream& f, + std::streampos header_offset ) = 0; + virtual void save( std::ofstream& f, + std::streampos header_offset, + std::streampos data_offset ) = 0; + virtual bool is_address_initialized() const = 0; +}; + + +template< class T > +class section_impl : public section +{ + public: +//------------------------------------------------------------------------------ + section_impl( const endianess_convertor* convertor_ ) : convertor( convertor_ ) + { + std::fill_n( reinterpret_cast<char*>( &header ), sizeof( header ), '\0' ); + is_address_set = false; + data = 0; + data_size = 0; + } + +//------------------------------------------------------------------------------ + ~section_impl() + { + delete [] data; + } + +//------------------------------------------------------------------------------ + // Section info functions + ELFIO_GET_SET_ACCESS( Elf_Word, type, header.sh_type ); + ELFIO_GET_SET_ACCESS( Elf_Xword, flags, header.sh_flags ); + ELFIO_GET_SET_ACCESS( Elf_Xword, size, header.sh_size ); + ELFIO_GET_SET_ACCESS( Elf_Word, link, header.sh_link ); + ELFIO_GET_SET_ACCESS( Elf_Word, info, header.sh_info ); + ELFIO_GET_SET_ACCESS( Elf_Xword, addr_align, header.sh_addralign ); + ELFIO_GET_SET_ACCESS( Elf_Xword, entry_size, header.sh_entsize ); + ELFIO_GET_SET_ACCESS( Elf_Word, name_string_offset, header.sh_name ); + ELFIO_GET_ACCESS ( Elf64_Addr, address, header.sh_addr ); + +//------------------------------------------------------------------------------ + Elf_Half + get_index() const + { + return index; + } + + +//------------------------------------------------------------------------------ + std::string + get_name() const + { + return name; + } + +//------------------------------------------------------------------------------ + void + set_name( std::string name_ ) + { + name = name_; + } + +//------------------------------------------------------------------------------ + void + set_address( Elf64_Addr value ) + { + header.sh_addr = value; + header.sh_addr = (*convertor)( header.sh_addr ); + is_address_set = true; + } + +//------------------------------------------------------------------------------ + bool + is_address_initialized() const + { + return is_address_set; + } + +//------------------------------------------------------------------------------ + const char* + get_data() const + { + return data; + } + +//------------------------------------------------------------------------------ + void + set_data( const char* raw_data, Elf_Word size ) + { + if ( get_type() != SHT_NOBITS ) { + delete [] data; + data = new char[size]; + if ( 0 != data && 0 != raw_data ) { + data_size = size; + std::copy( raw_data, raw_data + size, data ); + } + } + + set_size( size ); + } + +//------------------------------------------------------------------------------ + void + set_data( const std::string& str_data ) + { + return set_data( str_data.c_str(), (Elf_Word)str_data.size() ); + } + +//------------------------------------------------------------------------------ + void + append_data( const char* raw_data, Elf_Word size ) + { + if ( get_type() != SHT_NOBITS ) { + if ( get_size() + size < data_size ) { + std::copy( raw_data, raw_data + size, data + get_size() ); + } + else { + data_size = 2*( data_size + size); + char* new_data = new char[data_size]; + if ( 0 != new_data ) { + std::copy( data, data + get_size(), new_data ); + std::copy( raw_data, raw_data + size, new_data + get_size() ); + delete [] data; + data = new_data; + } + } + set_size( get_size() + size ); + } + } + +//------------------------------------------------------------------------------ + void + append_data( const std::string& str_data ) + { + return append_data( str_data.c_str(), (Elf_Word)str_data.size() ); + } + +//------------------------------------------------------------------------------ + protected: +//------------------------------------------------------------------------------ + void + set_index( Elf_Half value ) + { + index = value; + } + +//------------------------------------------------------------------------------ + void + load( std::ifstream& stream, + std::streampos header_offset ) + { + std::fill_n( reinterpret_cast<char*>( &header ), sizeof( header ), '\0' ); + stream.seekg( header_offset ); + stream.read( reinterpret_cast<char*>( &header ), sizeof( header ) ); + + Elf_Xword size = get_size(); + if ( 0 == data && SHT_NULL != get_type() && SHT_NOBITS != get_type() && + 0 != size ) { + data = new char[size]; + stream.seekg( (*convertor)( header.sh_offset ) ); + stream.read( data, size ); + data_size = size; + } + } + +//------------------------------------------------------------------------------ + void + save( std::ofstream& f, + std::streampos header_offset, + std::streampos data_offset ) + { + if ( 0 != get_index() ) { + header.sh_offset = data_offset; + header.sh_offset = (*convertor)( header.sh_offset ); + } + + save_header( f, header_offset ); + if ( get_type() != SHT_NOBITS && get_type() != SHT_NULL && + get_size() != 0 && data != 0 ) { + save_data( f, data_offset ); + } + } + +//------------------------------------------------------------------------------ + private: +//------------------------------------------------------------------------------ + void + save_header( std::ofstream& f, + std::streampos header_offset ) const + { + f.seekp( header_offset ); + f.write( reinterpret_cast<const char*>( &header ), sizeof( header ) ); + } + +//------------------------------------------------------------------------------ + void + save_data( std::ofstream& f, + std::streampos data_offset ) const + { + f.seekp( data_offset ); + f.write( get_data(), get_size() ); + } + +//------------------------------------------------------------------------------ + private: + mutable T header; + Elf_Half index; + std::string name; + char* data; + Elf_Word data_size; + const endianess_convertor* convertor; + bool is_address_set; +}; + +} // namespace ELFIO + +#endif // ELFI_SECTION_HPP diff --git a/elfio/elfio_segment.hpp b/elfio/elfio_segment.hpp index 94d73f669bab228e3cb6aa9f899f823af3638bb0..78fc44969ca2b0fe38d0eaf597167083e56929be 100644 --- a/elfio/elfio_segment.hpp +++ b/elfio/elfio_segment.hpp @@ -1,182 +1,182 @@ -/* -Copyright (C) 2001-2011 by Serge Lamikhov-Center - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef ELFI_SEGMENT_HPP -#define ELFI_SEGMENT_HPP - -#include <fstream> -#include <vector> - -namespace ELFIO { - -class segment -{ - friend class elfio; - public: - virtual ~segment() {}; - - virtual Elf_Half get_index() const = 0; - - ELFIO_GET_SET_ACCESS_DECL( Elf_Word, type ); - ELFIO_GET_SET_ACCESS_DECL( Elf_Word, flags ); - ELFIO_GET_SET_ACCESS_DECL( Elf_Xword, align ); - ELFIO_GET_SET_ACCESS_DECL( Elf64_Addr, virtual_address ); - ELFIO_GET_SET_ACCESS_DECL( Elf64_Addr, physical_address ); - ELFIO_GET_SET_ACCESS_DECL( Elf_Xword, file_size ); - ELFIO_GET_SET_ACCESS_DECL( Elf_Xword, memory_size ); - - virtual const char* get_data() const = 0; - - virtual Elf_Half add_section_index( Elf_Half index, Elf_Xword addr_align ) = 0; - virtual Elf_Half get_sections_num() const = 0; - virtual Elf_Half get_section_index_at( Elf_Half num ) const = 0; - - protected: - virtual void set_index( Elf_Half ) = 0; - virtual void load( std::ifstream& stream, std::streampos header_offset ) const = 0; - virtual void save( std::ofstream& f, std::streampos header_offset, - std::streampos data_offset ) = 0; -}; - - -//------------------------------------------------------------------------------ -template< class T > -class segment_impl : public segment -{ - public: -//------------------------------------------------------------------------------ - segment_impl( endianess_convertor* convertor_ ) : - convertor( convertor_ ) - { - std::fill_n( reinterpret_cast<char*>( &ph ), sizeof( ph ), '\0' ); - data = 0; - } - -//------------------------------------------------------------------------------ - virtual ~segment_impl() - { - delete [] data; - } - -//------------------------------------------------------------------------------ - // Section info functions - ELFIO_GET_SET_ACCESS( Elf_Word, type, ph.p_type ); - ELFIO_GET_SET_ACCESS( Elf_Word, flags, ph.p_flags ); - ELFIO_GET_SET_ACCESS( Elf_Xword, align, ph.p_align ); - ELFIO_GET_SET_ACCESS( Elf64_Addr, virtual_address, ph.p_vaddr ); - ELFIO_GET_SET_ACCESS( Elf64_Addr, physical_address, ph.p_paddr ); - ELFIO_GET_SET_ACCESS( Elf_Xword, file_size, ph.p_filesz ); - ELFIO_GET_SET_ACCESS( Elf_Xword, memory_size, ph.p_memsz ); - -//------------------------------------------------------------------------------ - Elf_Half - get_index() const - { - return index; - } - -//------------------------------------------------------------------------------ - const char* - get_data() const - { - return data; - } - -//------------------------------------------------------------------------------ - Elf_Half - add_section_index( Elf_Half index, Elf_Xword addr_align ) - { - sections.push_back( index ); - if ( addr_align > get_align() ) { - set_align( addr_align ); - } - - return (Elf_Half)sections.size(); - } - -//------------------------------------------------------------------------------ - Elf_Half - get_sections_num() const - { - return (Elf_Half)sections.size(); - } - -//------------------------------------------------------------------------------ - Elf_Half - get_section_index_at( Elf_Half num ) const - { - if ( num < sections.size() ) { - return sections[num]; - } - - return -1; - } - -//------------------------------------------------------------------------------ - protected: -//------------------------------------------------------------------------------ - void - set_index( Elf_Half value ) - { - index = value; - } - -//------------------------------------------------------------------------------ - void - load( std::ifstream& stream, - std::streampos header_offset ) const - { - stream.seekg( header_offset ); - stream.read( reinterpret_cast<char*>( &ph ), sizeof( ph ) ); - - if ( PT_NULL != get_type() && 0 != get_file_size() ) { - stream.seekg( (*convertor)( ph.p_offset ) ); - Elf_Xword size = get_file_size(); - data = new char[size]; - if ( 0 != data ) { - stream.read( data, size ); - } - } - } - -//------------------------------------------------------------------------------ - void save( std::ofstream& f, - std::streampos header_offset, - std::streampos data_offset ) - { - ph.p_offset = data_offset; - f.seekp( header_offset ); - f.write( reinterpret_cast<const char*>( &ph ), sizeof( ph ) ); - } - -//------------------------------------------------------------------------------ - private: - mutable T ph; - Elf_Half index; - mutable char* data; - std::vector<Elf_Half> sections; - endianess_convertor* convertor; -}; - -} // namespace ELFIO - -#endif // ELFI_SEGMENT_HPP +/* +Copyright (C) 2001-2011 by Serge Lamikhov-Center + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef ELFI_SEGMENT_HPP +#define ELFI_SEGMENT_HPP + +#include <fstream> +#include <vector> + +namespace ELFIO { + +class segment +{ + friend class elfio; + public: + virtual ~segment() {}; + + virtual Elf_Half get_index() const = 0; + + ELFIO_GET_SET_ACCESS_DECL( Elf_Word, type ); + ELFIO_GET_SET_ACCESS_DECL( Elf_Word, flags ); + ELFIO_GET_SET_ACCESS_DECL( Elf_Xword, align ); + ELFIO_GET_SET_ACCESS_DECL( Elf64_Addr, virtual_address ); + ELFIO_GET_SET_ACCESS_DECL( Elf64_Addr, physical_address ); + ELFIO_GET_SET_ACCESS_DECL( Elf_Xword, file_size ); + ELFIO_GET_SET_ACCESS_DECL( Elf_Xword, memory_size ); + + virtual const char* get_data() const = 0; + + virtual Elf_Half add_section_index( Elf_Half index, Elf_Xword addr_align ) = 0; + virtual Elf_Half get_sections_num() const = 0; + virtual Elf_Half get_section_index_at( Elf_Half num ) const = 0; + + protected: + virtual void set_index( Elf_Half ) = 0; + virtual void load( std::ifstream& stream, std::streampos header_offset ) const = 0; + virtual void save( std::ofstream& f, std::streampos header_offset, + std::streampos data_offset ) = 0; +}; + + +//------------------------------------------------------------------------------ +template< class T > +class segment_impl : public segment +{ + public: +//------------------------------------------------------------------------------ + segment_impl( endianess_convertor* convertor_ ) : + convertor( convertor_ ) + { + std::fill_n( reinterpret_cast<char*>( &ph ), sizeof( ph ), '\0' ); + data = 0; + } + +//------------------------------------------------------------------------------ + virtual ~segment_impl() + { + delete [] data; + } + +//------------------------------------------------------------------------------ + // Section info functions + ELFIO_GET_SET_ACCESS( Elf_Word, type, ph.p_type ); + ELFIO_GET_SET_ACCESS( Elf_Word, flags, ph.p_flags ); + ELFIO_GET_SET_ACCESS( Elf_Xword, align, ph.p_align ); + ELFIO_GET_SET_ACCESS( Elf64_Addr, virtual_address, ph.p_vaddr ); + ELFIO_GET_SET_ACCESS( Elf64_Addr, physical_address, ph.p_paddr ); + ELFIO_GET_SET_ACCESS( Elf_Xword, file_size, ph.p_filesz ); + ELFIO_GET_SET_ACCESS( Elf_Xword, memory_size, ph.p_memsz ); + +//------------------------------------------------------------------------------ + Elf_Half + get_index() const + { + return index; + } + +//------------------------------------------------------------------------------ + const char* + get_data() const + { + return data; + } + +//------------------------------------------------------------------------------ + Elf_Half + add_section_index( Elf_Half index, Elf_Xword addr_align ) + { + sections.push_back( index ); + if ( addr_align > get_align() ) { + set_align( addr_align ); + } + + return (Elf_Half)sections.size(); + } + +//------------------------------------------------------------------------------ + Elf_Half + get_sections_num() const + { + return (Elf_Half)sections.size(); + } + +//------------------------------------------------------------------------------ + Elf_Half + get_section_index_at( Elf_Half num ) const + { + if ( num < sections.size() ) { + return sections[num]; + } + + return -1; + } + +//------------------------------------------------------------------------------ + protected: +//------------------------------------------------------------------------------ + void + set_index( Elf_Half value ) + { + index = value; + } + +//------------------------------------------------------------------------------ + void + load( std::ifstream& stream, + std::streampos header_offset ) const + { + stream.seekg( header_offset ); + stream.read( reinterpret_cast<char*>( &ph ), sizeof( ph ) ); + + if ( PT_NULL != get_type() && 0 != get_file_size() ) { + stream.seekg( (*convertor)( ph.p_offset ) ); + Elf_Xword size = get_file_size(); + data = new char[size]; + if ( 0 != data ) { + stream.read( data, size ); + } + } + } + +//------------------------------------------------------------------------------ + void save( std::ofstream& f, + std::streampos header_offset, + std::streampos data_offset ) + { + ph.p_offset = data_offset; + f.seekp( header_offset ); + f.write( reinterpret_cast<const char*>( &ph ), sizeof( ph ) ); + } + +//------------------------------------------------------------------------------ + private: + mutable T ph; + Elf_Half index; + mutable char* data; + std::vector<Elf_Half> sections; + endianess_convertor* convertor; +}; + +} // namespace ELFIO + +#endif // ELFI_SEGMENT_HPP diff --git a/elfio/elfio_strings.hpp b/elfio/elfio_strings.hpp index 4c688cf7957c9689febdca500199accdcd3a5ac4..e4b8b518ce7a26a8014849e0cd13258f6a17d73a 100644 --- a/elfio/elfio_strings.hpp +++ b/elfio/elfio_strings.hpp @@ -1,101 +1,101 @@ -/* -Copyright (C) 2001-2011 by Serge Lamikhov-Center - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef ELFIO_STRINGS_HPP -#define ELFIO_STRINGS_HPP - -#include <cstdlib> -#include <cstring> -#include <string> - -namespace ELFIO { - -//------------------------------------------------------------------------------ -class string_section_accessor -{ - public: -//------------------------------------------------------------------------------ - string_section_accessor( section* section_ ) : - string_section( section_ ) - { - } - - -//------------------------------------------------------------------------------ - const char* - get_string( Elf_Word index ) const - { - if ( index < string_section->get_size() ) { - const char* data = string_section->get_data(); - if ( 0 != data ) { - return data + index; - } - } - - return 0; - } - - -//------------------------------------------------------------------------------ - Elf_Word - add_string( const char* str ) - { - // Strings are addeded to the end of the current section data - Elf_Word current_position = (Elf_Word)string_section->get_size(); - - if ( current_position == 0 ) { - char empty_string[1] = {'\0'}; - string_section->append_data( empty_string, 1 ); - current_position++; - } - string_section->append_data( str, (Elf_Word)std::strlen( str ) + 1 ); - - return current_position; - } - - -//------------------------------------------------------------------------------ - Elf_Word - add_string( const std::string& str ) - { - // Strings are addeded to the end of the current section data - Elf_Word current_position = (Elf_Word)string_section->get_size(); - - char empty_string[1] = {'\0'}; - if ( current_position == 0 ) { - string_section->append_data( empty_string, 1 ); - current_position++; - } - string_section->append_data( str ); - string_section->append_data( empty_string, 1 ); - - return current_position; - } - -//------------------------------------------------------------------------------ - private: - section* string_section; -}; - -} // namespace ELFIO - -#endif // ELFIO_STRINGS_HPP +/* +Copyright (C) 2001-2011 by Serge Lamikhov-Center + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef ELFIO_STRINGS_HPP +#define ELFIO_STRINGS_HPP + +#include <cstdlib> +#include <cstring> +#include <string> + +namespace ELFIO { + +//------------------------------------------------------------------------------ +class string_section_accessor +{ + public: +//------------------------------------------------------------------------------ + string_section_accessor( section* section_ ) : + string_section( section_ ) + { + } + + +//------------------------------------------------------------------------------ + const char* + get_string( Elf_Word index ) const + { + if ( index < string_section->get_size() ) { + const char* data = string_section->get_data(); + if ( 0 != data ) { + return data + index; + } + } + + return 0; + } + + +//------------------------------------------------------------------------------ + Elf_Word + add_string( const char* str ) + { + // Strings are addeded to the end of the current section data + Elf_Word current_position = (Elf_Word)string_section->get_size(); + + if ( current_position == 0 ) { + char empty_string[1] = {'\0'}; + string_section->append_data( empty_string, 1 ); + current_position++; + } + string_section->append_data( str, (Elf_Word)std::strlen( str ) + 1 ); + + return current_position; + } + + +//------------------------------------------------------------------------------ + Elf_Word + add_string( const std::string& str ) + { + // Strings are addeded to the end of the current section data + Elf_Word current_position = (Elf_Word)string_section->get_size(); + + char empty_string[1] = {'\0'}; + if ( current_position == 0 ) { + string_section->append_data( empty_string, 1 ); + current_position++; + } + string_section->append_data( str ); + string_section->append_data( empty_string, 1 ); + + return current_position; + } + +//------------------------------------------------------------------------------ + private: + section* string_section; +}; + +} // namespace ELFIO + +#endif // ELFIO_STRINGS_HPP diff --git a/elfio/elfio_symbols.hpp b/elfio/elfio_symbols.hpp index 12999c84c6c460a2fa82a06de100261166467550..d498ca1cfcd25c5a8699e0b4265f8b960e99ec3c 100644 --- a/elfio/elfio_symbols.hpp +++ b/elfio/elfio_symbols.hpp @@ -1,276 +1,276 @@ -/* -Copyright (C) 2001-2011 by Serge Lamikhov-Center - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef ELFI_SYMBOLS_HPP -#define ELFI_SYMBOLS_HPP - -namespace ELFIO { - -//------------------------------------------------------------------------------ -class symbol_section_accessor -{ - public: -//------------------------------------------------------------------------------ - symbol_section_accessor( const elfio& elf_file_, section* symbol_section_ ) : - elf_file( elf_file_ ), - symbol_section( symbol_section_ ) - { - find_hash_section(); - } - -//------------------------------------------------------------------------------ - Elf_Xword - get_symbols_num() const - { - Elf_Xword nRet = 0; - if ( 0 != symbol_section->get_entry_size() ) { - nRet = symbol_section->get_size() / symbol_section->get_entry_size(); - } - - return nRet; - } - -//------------------------------------------------------------------------------ - bool - get_symbol( Elf_Xword index, - std::string& name, - Elf64_Addr& value, - Elf_Xword& size, - unsigned char& bind, - unsigned char& type, - Elf_Half& section_index, - unsigned char& other ) const - { - bool ret = false; - - if ( elf_file.get_class() == ELFCLASS32 ) { - ret = generic_get_symbol<Elf32_Sym>( index, name, value, size, bind, - type, section_index, other ); - } - else { - ret = generic_get_symbol<Elf64_Sym>( index, name, value, size, bind, - type, section_index, other ); - } - - return ret; - } - -//------------------------------------------------------------------------------ - bool - get_symbol( std::string& name, - Elf64_Addr& value, - Elf_Xword& size, - unsigned char& bind, - unsigned char& type, - Elf_Half& section_index, - unsigned char& other ) const - { - bool ret = false; - - if ( 0 != get_hash_table_index() ) { - Elf_Word nbucket = *(Elf_Word*)hash_section->get_data(); - Elf_Word val = elf_hash( (const unsigned char*)name.c_str() ); - - Elf_Word y = *(Elf_Word*)( hash_section->get_data() + - ( 2 + val % nbucket ) * sizeof( Elf_Word ) ); - std::string str; - get_symbol( y, str, value, size, bind, type, section_index, other ); - while ( str != name && STN_UNDEF != y ) { - y = *(Elf_Word*)( hash_section->get_data() + - ( 2 + nbucket + y ) * sizeof( Elf_Word ) ); - get_symbol( y, str, value, size, bind, type, section_index, other ); - } - if ( str == name ) { - ret = true; - } - } - - return ret; - } - -//------------------------------------------------------------------------------ - Elf_Word - add_symbol( Elf_Word name, Elf64_Addr value, Elf_Xword size, - unsigned char info, unsigned char other, - Elf_Half shndx ) - { - Elf_Word nRet; - - if ( symbol_section->get_size() == 0 ) { - if ( elf_file.get_class() == ELFCLASS32 ) { - nRet = generic_add_symbol<Elf32_Sym>( 0, 0, 0, 0, 0, 0 ); - } - else { - nRet = generic_add_symbol<Elf64_Sym>( 0, 0, 0, 0, 0, 0 ); - } - } - - if ( elf_file.get_class() == ELFCLASS32 ) { - nRet = generic_add_symbol<Elf32_Sym>( name, value, size, info, other, - shndx ); - } - else { - nRet = generic_add_symbol<Elf64_Sym>( name, value, size, info, other, - shndx ); - } - - return nRet; - } - -//------------------------------------------------------------------------------ - Elf_Word - add_symbol( Elf_Word name, Elf64_Addr value, Elf_Xword size, - unsigned char bind, unsigned char type, unsigned char other, - Elf_Half shndx ) - { - return add_symbol( name, value, size, ELF_ST_INFO( bind, type ), other, shndx ); - } - -//------------------------------------------------------------------------------ - Elf_Word - add_symbol( string_section_accessor& pStrWriter, const char* str, - Elf64_Addr value, Elf_Xword size, - unsigned char info, unsigned char other, - Elf_Half shndx ) - { - Elf_Word index = pStrWriter.add_string( str ); - return add_symbol( index, value, size, info, other, shndx ); - } - -//------------------------------------------------------------------------------ - Elf_Word - add_symbol( string_section_accessor& pStrWriter, const char* str, - Elf64_Addr value, Elf_Xword size, - unsigned char bind, unsigned char type, unsigned char other, - Elf_Half shndx ) - { - return add_symbol( pStrWriter, str, value, size, ELF_ST_INFO( bind, type ), other, shndx ); - } - -//------------------------------------------------------------------------------ - private: -//------------------------------------------------------------------------------ - void - find_hash_section() - { - hash_section = 0; - hash_section_index = 0; - Elf_Half nSecNo = elf_file.sections.size(); - for ( Elf_Half i = 0; i < nSecNo && 0 == hash_section_index; ++i ) { - const section* sec = elf_file.sections[i]; - if ( sec->get_link() == symbol_section->get_index() ) { - hash_section = sec; - hash_section_index = i; - } - } - } - -//------------------------------------------------------------------------------ - Elf_Half - get_string_table_index() const - { - return (Elf_Half)symbol_section->get_link(); - } - -//------------------------------------------------------------------------------ - Elf_Half - get_hash_table_index() const - { - return hash_section_index; - } - -//------------------------------------------------------------------------------ - template< class T > - bool - generic_get_symbol( Elf_Xword index, - std::string& name, Elf64_Addr& value, - Elf_Xword& size, - unsigned char& bind, unsigned char& type, - Elf_Half& section_index, - unsigned char& other ) const - { - bool ret = false; - - if ( index < get_symbols_num() ) { - const T* pSym = reinterpret_cast<const T*>( - symbol_section->get_data() + - index * symbol_section->get_entry_size() ); - - const endianess_convertor& convertor = elf_file.get_convertor(); - - section* string_section = elf_file.sections[get_string_table_index()]; - string_section_accessor str_reader( string_section ); - const char* pStr = str_reader.get_string( convertor( pSym->st_name ) ); - if ( 0 != pStr ) { - name = pStr; - } - value = convertor( pSym->st_value ); - size = convertor( pSym->st_size ); - bind = ELF_ST_BIND( pSym->st_info ); - type = ELF_ST_TYPE( pSym->st_info ); - section_index = convertor( pSym->st_shndx ); - other = pSym->st_other; - - ret = true; - } - - return ret; - } - -//------------------------------------------------------------------------------ - template< class T > - Elf_Word - generic_add_symbol( Elf_Word name, Elf64_Addr value, Elf_Xword size, - unsigned char info, unsigned char other, - Elf_Half shndx ) - { - const endianess_convertor& convertor = elf_file.get_convertor(); - - T entry; - entry.st_name = convertor( name ); - entry.st_value = value; - entry.st_value = convertor( entry.st_value ); - entry.st_size = size; - entry.st_size = convertor( entry.st_size ); - entry.st_info = convertor( info ); - entry.st_other = convertor( other ); - entry.st_shndx = convertor( shndx ); - - symbol_section->append_data( reinterpret_cast<char*>( &entry ), - sizeof( entry ) ); - - Elf_Word nRet = symbol_section->get_size() / sizeof( entry ) - 1; - - return nRet; - } - -//------------------------------------------------------------------------------ - private: - const elfio& elf_file; - section* symbol_section; - Elf_Half hash_section_index; - const section* hash_section; -}; - -} // namespace ELFIO - -#endif // ELFI_SYMBOLS_HPP +/* +Copyright (C) 2001-2011 by Serge Lamikhov-Center + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef ELFI_SYMBOLS_HPP +#define ELFI_SYMBOLS_HPP + +namespace ELFIO { + +//------------------------------------------------------------------------------ +class symbol_section_accessor +{ + public: +//------------------------------------------------------------------------------ + symbol_section_accessor( const elfio& elf_file_, section* symbol_section_ ) : + elf_file( elf_file_ ), + symbol_section( symbol_section_ ) + { + find_hash_section(); + } + +//------------------------------------------------------------------------------ + Elf_Xword + get_symbols_num() const + { + Elf_Xword nRet = 0; + if ( 0 != symbol_section->get_entry_size() ) { + nRet = symbol_section->get_size() / symbol_section->get_entry_size(); + } + + return nRet; + } + +//------------------------------------------------------------------------------ + bool + get_symbol( Elf_Xword index, + std::string& name, + Elf64_Addr& value, + Elf_Xword& size, + unsigned char& bind, + unsigned char& type, + Elf_Half& section_index, + unsigned char& other ) const + { + bool ret = false; + + if ( elf_file.get_class() == ELFCLASS32 ) { + ret = generic_get_symbol<Elf32_Sym>( index, name, value, size, bind, + type, section_index, other ); + } + else { + ret = generic_get_symbol<Elf64_Sym>( index, name, value, size, bind, + type, section_index, other ); + } + + return ret; + } + +//------------------------------------------------------------------------------ + bool + get_symbol( std::string& name, + Elf64_Addr& value, + Elf_Xword& size, + unsigned char& bind, + unsigned char& type, + Elf_Half& section_index, + unsigned char& other ) const + { + bool ret = false; + + if ( 0 != get_hash_table_index() ) { + Elf_Word nbucket = *(Elf_Word*)hash_section->get_data(); + Elf_Word val = elf_hash( (const unsigned char*)name.c_str() ); + + Elf_Word y = *(Elf_Word*)( hash_section->get_data() + + ( 2 + val % nbucket ) * sizeof( Elf_Word ) ); + std::string str; + get_symbol( y, str, value, size, bind, type, section_index, other ); + while ( str != name && STN_UNDEF != y ) { + y = *(Elf_Word*)( hash_section->get_data() + + ( 2 + nbucket + y ) * sizeof( Elf_Word ) ); + get_symbol( y, str, value, size, bind, type, section_index, other ); + } + if ( str == name ) { + ret = true; + } + } + + return ret; + } + +//------------------------------------------------------------------------------ + Elf_Word + add_symbol( Elf_Word name, Elf64_Addr value, Elf_Xword size, + unsigned char info, unsigned char other, + Elf_Half shndx ) + { + Elf_Word nRet; + + if ( symbol_section->get_size() == 0 ) { + if ( elf_file.get_class() == ELFCLASS32 ) { + nRet = generic_add_symbol<Elf32_Sym>( 0, 0, 0, 0, 0, 0 ); + } + else { + nRet = generic_add_symbol<Elf64_Sym>( 0, 0, 0, 0, 0, 0 ); + } + } + + if ( elf_file.get_class() == ELFCLASS32 ) { + nRet = generic_add_symbol<Elf32_Sym>( name, value, size, info, other, + shndx ); + } + else { + nRet = generic_add_symbol<Elf64_Sym>( name, value, size, info, other, + shndx ); + } + + return nRet; + } + +//------------------------------------------------------------------------------ + Elf_Word + add_symbol( Elf_Word name, Elf64_Addr value, Elf_Xword size, + unsigned char bind, unsigned char type, unsigned char other, + Elf_Half shndx ) + { + return add_symbol( name, value, size, ELF_ST_INFO( bind, type ), other, shndx ); + } + +//------------------------------------------------------------------------------ + Elf_Word + add_symbol( string_section_accessor& pStrWriter, const char* str, + Elf64_Addr value, Elf_Xword size, + unsigned char info, unsigned char other, + Elf_Half shndx ) + { + Elf_Word index = pStrWriter.add_string( str ); + return add_symbol( index, value, size, info, other, shndx ); + } + +//------------------------------------------------------------------------------ + Elf_Word + add_symbol( string_section_accessor& pStrWriter, const char* str, + Elf64_Addr value, Elf_Xword size, + unsigned char bind, unsigned char type, unsigned char other, + Elf_Half shndx ) + { + return add_symbol( pStrWriter, str, value, size, ELF_ST_INFO( bind, type ), other, shndx ); + } + +//------------------------------------------------------------------------------ + private: +//------------------------------------------------------------------------------ + void + find_hash_section() + { + hash_section = 0; + hash_section_index = 0; + Elf_Half nSecNo = elf_file.sections.size(); + for ( Elf_Half i = 0; i < nSecNo && 0 == hash_section_index; ++i ) { + const section* sec = elf_file.sections[i]; + if ( sec->get_link() == symbol_section->get_index() ) { + hash_section = sec; + hash_section_index = i; + } + } + } + +//------------------------------------------------------------------------------ + Elf_Half + get_string_table_index() const + { + return (Elf_Half)symbol_section->get_link(); + } + +//------------------------------------------------------------------------------ + Elf_Half + get_hash_table_index() const + { + return hash_section_index; + } + +//------------------------------------------------------------------------------ + template< class T > + bool + generic_get_symbol( Elf_Xword index, + std::string& name, Elf64_Addr& value, + Elf_Xword& size, + unsigned char& bind, unsigned char& type, + Elf_Half& section_index, + unsigned char& other ) const + { + bool ret = false; + + if ( index < get_symbols_num() ) { + const T* pSym = reinterpret_cast<const T*>( + symbol_section->get_data() + + index * symbol_section->get_entry_size() ); + + const endianess_convertor& convertor = elf_file.get_convertor(); + + section* string_section = elf_file.sections[get_string_table_index()]; + string_section_accessor str_reader( string_section ); + const char* pStr = str_reader.get_string( convertor( pSym->st_name ) ); + if ( 0 != pStr ) { + name = pStr; + } + value = convertor( pSym->st_value ); + size = convertor( pSym->st_size ); + bind = ELF_ST_BIND( pSym->st_info ); + type = ELF_ST_TYPE( pSym->st_info ); + section_index = convertor( pSym->st_shndx ); + other = pSym->st_other; + + ret = true; + } + + return ret; + } + +//------------------------------------------------------------------------------ + template< class T > + Elf_Word + generic_add_symbol( Elf_Word name, Elf64_Addr value, Elf_Xword size, + unsigned char info, unsigned char other, + Elf_Half shndx ) + { + const endianess_convertor& convertor = elf_file.get_convertor(); + + T entry; + entry.st_name = convertor( name ); + entry.st_value = value; + entry.st_value = convertor( entry.st_value ); + entry.st_size = size; + entry.st_size = convertor( entry.st_size ); + entry.st_info = convertor( info ); + entry.st_other = convertor( other ); + entry.st_shndx = convertor( shndx ); + + symbol_section->append_data( reinterpret_cast<char*>( &entry ), + sizeof( entry ) ); + + Elf_Word nRet = symbol_section->get_size() / sizeof( entry ) - 1; + + return nRet; + } + +//------------------------------------------------------------------------------ + private: + const elfio& elf_file; + section* symbol_section; + Elf_Half hash_section_index; + const section* hash_section; +}; + +} // namespace ELFIO + +#endif // ELFI_SYMBOLS_HPP diff --git a/elfio/elfio_utils.hpp b/elfio/elfio_utils.hpp index a61102292b4ec72267e1d8b6f6e41269fec9eec6..c1b77ff8a709985af2571f7595d32206f6b6b1cd 100644 --- a/elfio/elfio_utils.hpp +++ b/elfio/elfio_utils.hpp @@ -1,209 +1,209 @@ -/* -Copyright (C) 2001-2011 by Serge Lamikhov-Center - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifndef ELFIO_UTILS_HPP -#define ELFIO_UTILS_HPP - -#define ELFIO_GET_ACCESS( TYPE, NAME, FIELD ) \ - TYPE get_##NAME() const \ - { \ - return (*convertor)( FIELD ); \ - } -#define ELFIO_SET_ACCESS( TYPE, NAME, FIELD ) \ - void set_##NAME( TYPE value ) \ - { \ - FIELD = value; \ - FIELD = (*convertor)( FIELD ); \ - } -#define ELFIO_GET_SET_ACCESS( TYPE, NAME, FIELD ) \ - TYPE get_##NAME() const \ - { \ - return (*convertor)( FIELD ); \ - } \ - void set_##NAME( TYPE value ) \ - { \ - FIELD = value; \ - FIELD = (*convertor)( FIELD ); \ - } - -#define ELFIO_GET_ACCESS_DECL( TYPE, NAME ) \ - virtual TYPE get_##NAME() const = 0; - -#define ELFIO_SET_ACCESS_DECL( TYPE, NAME ) \ - virtual void set_##NAME( TYPE value ) = 0; - -#define ELFIO_GET_SET_ACCESS_DECL( TYPE, NAME ) \ - virtual TYPE get_##NAME() const = 0; \ - virtual void set_##NAME( TYPE value ) = 0; - -namespace ELFIO { - -//------------------------------------------------------------------------------ -class endianess_convertor { - public: -//------------------------------------------------------------------------------ - endianess_convertor() - { - need_conversion = false; - } - -//------------------------------------------------------------------------------ - void - setup( unsigned char elf_file_encoding ) - { - need_conversion = ( elf_file_encoding != get_host_encoding() ); - } - -//------------------------------------------------------------------------------ - uint64_t - operator()( uint64_t value ) const - { - if ( !need_conversion ) { - return value; - } - value = - ( ( value & 0x00000000000000FFull ) << 56 ) | - ( ( value & 0x000000000000FF00ull ) << 40 ) | - ( ( value & 0x0000000000FF0000ull ) << 24 ) | - ( ( value & 0x00000000FF000000ull ) << 8 ) | - ( ( value & 0x000000FF00000000ull ) >> 8 ) | - ( ( value & 0x0000FF0000000000ull ) >> 24 ) | - ( ( value & 0x00FF000000000000ull ) >> 40 ) | - ( ( value & 0xFF00000000000000ull ) >> 56 ); - - return value; - } - -//------------------------------------------------------------------------------ - int64_t - operator()( int64_t value ) const - { - if ( !need_conversion ) { - return value; - } - return (int64_t)(*this)( (uint64_t)value ); - } - -//------------------------------------------------------------------------------ - uint32_t - operator()( uint32_t value ) const - { - if ( !need_conversion ) { - return value; - } - value = - ( ( value & 0x000000FF ) << 24 ) | - ( ( value & 0x0000FF00 ) << 8 ) | - ( ( value & 0x00FF0000 ) >> 8 ) | - ( ( value & 0xFF000000 ) >> 24 ); - - return value; - } - -//------------------------------------------------------------------------------ - int32_t - operator()( int32_t value ) const - { - if ( !need_conversion ) { - return value; - } - return (int32_t)(*this)( (uint32_t)value ); - } - -//------------------------------------------------------------------------------ - uint16_t - operator()( uint16_t value ) const - { - if ( !need_conversion ) { - return value; - } - value = - ( ( value & 0x00FF ) << 8 ) | - ( ( value & 0xFF00 ) >> 8 ); - - return value; - } - -//------------------------------------------------------------------------------ - int16_t - operator()( int16_t value ) const - { - if ( !need_conversion ) { - return value; - } - return (int16_t)(*this)( (uint16_t)value ); - } - -//------------------------------------------------------------------------------ - int8_t - operator()( int8_t value ) const - { - return value; - } - -//------------------------------------------------------------------------------ - uint8_t - operator()( uint8_t value ) const - { - return value; - } - -//------------------------------------------------------------------------------ - private: -//------------------------------------------------------------------------------ - unsigned char - get_host_encoding() const - { - static const int tmp = 1; - if ( 1 == *(char*)&tmp ) { - return ELFDATA2LSB; - } - else { - return ELFDATA2MSB; - } - } - -//------------------------------------------------------------------------------ - private: - bool need_conversion; -}; - - -//------------------------------------------------------------------------------ -inline -uint32_t -elf_hash( const unsigned char *name ) -{ - uint32_t h = 0, g; - while ( *name ) { - h = (h << 4) + *name++; - g = h & 0xf0000000; - if ( g != 0 ) - h ^= g >> 24; - h &= ~g; - } - return h; -} - -} // namespace ELFIO - -#endif // ELFIO_UTILS_HPP +/* +Copyright (C) 2001-2011 by Serge Lamikhov-Center + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef ELFIO_UTILS_HPP +#define ELFIO_UTILS_HPP + +#define ELFIO_GET_ACCESS( TYPE, NAME, FIELD ) \ + TYPE get_##NAME() const \ + { \ + return (*convertor)( FIELD ); \ + } +#define ELFIO_SET_ACCESS( TYPE, NAME, FIELD ) \ + void set_##NAME( TYPE value ) \ + { \ + FIELD = value; \ + FIELD = (*convertor)( FIELD ); \ + } +#define ELFIO_GET_SET_ACCESS( TYPE, NAME, FIELD ) \ + TYPE get_##NAME() const \ + { \ + return (*convertor)( FIELD ); \ + } \ + void set_##NAME( TYPE value ) \ + { \ + FIELD = value; \ + FIELD = (*convertor)( FIELD ); \ + } + +#define ELFIO_GET_ACCESS_DECL( TYPE, NAME ) \ + virtual TYPE get_##NAME() const = 0; + +#define ELFIO_SET_ACCESS_DECL( TYPE, NAME ) \ + virtual void set_##NAME( TYPE value ) = 0; + +#define ELFIO_GET_SET_ACCESS_DECL( TYPE, NAME ) \ + virtual TYPE get_##NAME() const = 0; \ + virtual void set_##NAME( TYPE value ) = 0; + +namespace ELFIO { + +//------------------------------------------------------------------------------ +class endianess_convertor { + public: +//------------------------------------------------------------------------------ + endianess_convertor() + { + need_conversion = false; + } + +//------------------------------------------------------------------------------ + void + setup( unsigned char elf_file_encoding ) + { + need_conversion = ( elf_file_encoding != get_host_encoding() ); + } + +//------------------------------------------------------------------------------ + uint64_t + operator()( uint64_t value ) const + { + if ( !need_conversion ) { + return value; + } + value = + ( ( value & 0x00000000000000FFull ) << 56 ) | + ( ( value & 0x000000000000FF00ull ) << 40 ) | + ( ( value & 0x0000000000FF0000ull ) << 24 ) | + ( ( value & 0x00000000FF000000ull ) << 8 ) | + ( ( value & 0x000000FF00000000ull ) >> 8 ) | + ( ( value & 0x0000FF0000000000ull ) >> 24 ) | + ( ( value & 0x00FF000000000000ull ) >> 40 ) | + ( ( value & 0xFF00000000000000ull ) >> 56 ); + + return value; + } + +//------------------------------------------------------------------------------ + int64_t + operator()( int64_t value ) const + { + if ( !need_conversion ) { + return value; + } + return (int64_t)(*this)( (uint64_t)value ); + } + +//------------------------------------------------------------------------------ + uint32_t + operator()( uint32_t value ) const + { + if ( !need_conversion ) { + return value; + } + value = + ( ( value & 0x000000FF ) << 24 ) | + ( ( value & 0x0000FF00 ) << 8 ) | + ( ( value & 0x00FF0000 ) >> 8 ) | + ( ( value & 0xFF000000 ) >> 24 ); + + return value; + } + +//------------------------------------------------------------------------------ + int32_t + operator()( int32_t value ) const + { + if ( !need_conversion ) { + return value; + } + return (int32_t)(*this)( (uint32_t)value ); + } + +//------------------------------------------------------------------------------ + uint16_t + operator()( uint16_t value ) const + { + if ( !need_conversion ) { + return value; + } + value = + ( ( value & 0x00FF ) << 8 ) | + ( ( value & 0xFF00 ) >> 8 ); + + return value; + } + +//------------------------------------------------------------------------------ + int16_t + operator()( int16_t value ) const + { + if ( !need_conversion ) { + return value; + } + return (int16_t)(*this)( (uint16_t)value ); + } + +//------------------------------------------------------------------------------ + int8_t + operator()( int8_t value ) const + { + return value; + } + +//------------------------------------------------------------------------------ + uint8_t + operator()( uint8_t value ) const + { + return value; + } + +//------------------------------------------------------------------------------ + private: +//------------------------------------------------------------------------------ + unsigned char + get_host_encoding() const + { + static const int tmp = 1; + if ( 1 == *(char*)&tmp ) { + return ELFDATA2LSB; + } + else { + return ELFDATA2MSB; + } + } + +//------------------------------------------------------------------------------ + private: + bool need_conversion; +}; + + +//------------------------------------------------------------------------------ +inline +uint32_t +elf_hash( const unsigned char *name ) +{ + uint32_t h = 0, g; + while ( *name ) { + h = (h << 4) + *name++; + g = h & 0xf0000000; + if ( g != 0 ) + h ^= g >> 24; + h &= ~g; + } + return h; +} + +} // namespace ELFIO + +#endif // ELFIO_UTILS_HPP diff --git a/elfio/elfo_dynamic.hpp b/elfio/elfo_dynamic.hpp index a3c36358b45023e08896a2ffa3107e30bd245fee..f477a3552eed0b152e817873232a75430e2e87b3 100644 --- a/elfio/elfo_dynamic.hpp +++ b/elfio/elfo_dynamic.hpp @@ -1,75 +1,75 @@ -#ifndef ELFO_DYNAMIC_HPP -#define ELFO_DYNAMIC_HPP - -// Dynamic section producer -class ELFODynamicWriter : public IELFODynamicWriter -{ - public: - ELFODynamicWriter( IELFO* pIELFO, IELFOSection* pSection ); - ~ELFODynamicWriter(); - - virtual int addRef(); - virtual int release(); - - virtual ELFIO_Err addEntry( Elf_Sword tag, Elf_Word value ); - - private: - int m_nRefCnt; - IELFO* m_pIELFO; - IELFOSection* m_pSection; -}; - - -ELFODynamicWriter::ELFODynamicWriter( IELFO* pIELFO, IELFOSection* pSection ) : - m_nRefCnt( 1 ), - m_pIELFO( pIELFO ), - m_pSection( pSection ) -{ - m_pIELFO->addRef(); - m_pSection->addRef(); -} - - -ELFODynamicWriter::~ELFODynamicWriter() -{ -} - - -int -ELFODynamicWriter::addRef() -{ - m_pIELFO->addRef(); - m_pSection->addRef(); - return ++m_nRefCnt; -} - - -int -ELFODynamicWriter::release() -{ - int nRet = --m_nRefCnt; - IELFO* pIELFO = m_pIELFO; - IELFOSection* pSec = m_pSection; - - if ( 0 == m_nRefCnt ) { - delete this; - } - pSec->release(); - pIELFO->release(); - - return nRet; -} - - -ELFIO_Err -ELFODynamicWriter::addEntry( Elf_Sword tag, Elf_Word value ) -{ - Elf64_Dyn entry; - entry.d_tag = convert2host( tag, m_pIELFO->get_encoding() ); - entry.d_un.d_val = convert2host( value, m_pIELFO->get_encoding() ); - - return m_pSection->appendData( reinterpret_cast<const char*>( &entry ), - sizeof( entry ) ); -} - -#endif // ELFO_DYNAMIC_HPP +#ifndef ELFO_DYNAMIC_HPP +#define ELFO_DYNAMIC_HPP + +// Dynamic section producer +class ELFODynamicWriter : public IELFODynamicWriter +{ + public: + ELFODynamicWriter( IELFO* pIELFO, IELFOSection* pSection ); + ~ELFODynamicWriter(); + + virtual int addRef(); + virtual int release(); + + virtual ELFIO_Err addEntry( Elf_Sword tag, Elf_Word value ); + + private: + int m_nRefCnt; + IELFO* m_pIELFO; + IELFOSection* m_pSection; +}; + + +ELFODynamicWriter::ELFODynamicWriter( IELFO* pIELFO, IELFOSection* pSection ) : + m_nRefCnt( 1 ), + m_pIELFO( pIELFO ), + m_pSection( pSection ) +{ + m_pIELFO->addRef(); + m_pSection->addRef(); +} + + +ELFODynamicWriter::~ELFODynamicWriter() +{ +} + + +int +ELFODynamicWriter::addRef() +{ + m_pIELFO->addRef(); + m_pSection->addRef(); + return ++m_nRefCnt; +} + + +int +ELFODynamicWriter::release() +{ + int nRet = --m_nRefCnt; + IELFO* pIELFO = m_pIELFO; + IELFOSection* pSec = m_pSection; + + if ( 0 == m_nRefCnt ) { + delete this; + } + pSec->release(); + pIELFO->release(); + + return nRet; +} + + +ELFIO_Err +ELFODynamicWriter::addEntry( Elf_Sword tag, Elf_Word value ) +{ + Elf64_Dyn entry; + entry.d_tag = convert2host( tag, m_pIELFO->get_encoding() ); + entry.d_un.d_val = convert2host( value, m_pIELFO->get_encoding() ); + + return m_pSection->appendData( reinterpret_cast<const char*>( &entry ), + sizeof( entry ) ); +} + +#endif // ELFO_DYNAMIC_HPP diff --git a/examples/Makefile.am b/examples/Makefile.am index 26253a5d38c92f10d7c072f3bf8568389ca35cd5..2dbce667bd07317afa8dfba6d77460ba32945162 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1 +1 @@ -SUBDIRS = elfdump tutorial writer write_obj +SUBDIRS = elfdump tutorial writer write_obj diff --git a/examples/Makefile.in b/examples/Makefile.in index 8002ceb7067dff3d09103a16642208564cd6865e..9837be12a09ffa3f97e5324fe67f22018618b8b9 100644 --- a/examples/Makefile.in +++ b/examples/Makefile.in @@ -34,7 +34,7 @@ POST_UNINSTALL = : subdir = examples DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/configure.in +am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d @@ -179,9 +179,9 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) exit 1;; \ esac; \ done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu examples/Makefile'; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign examples/Makefile'; \ $(am__cd) $(top_srcdir) && \ - $(AUTOMAKE) --gnu examples/Makefile + $(AUTOMAKE) --foreign examples/Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ diff --git a/examples/RelocationTable/RelocationTable.cpp b/examples/RelocationTable/RelocationTable.cpp index bf07701e175a6c1663bff3ece49954818959b97c..52570780ada99cd093b5275691825871b1223427 100644 --- a/examples/RelocationTable/RelocationTable.cpp +++ b/examples/RelocationTable/RelocationTable.cpp @@ -1,56 +1,56 @@ -#include <cstdio> -#include <ELFIO.h> - -int main( int, char* argv[] ) -{ - // Create a ELFI reader - IELFI* pReader; - ELFIO::GetInstance()->CreateELFI( &pReader ); - - // Initialize it - char* filename = argv[1]; - pReader->Load( filename ); - - // Get .text relocation entry - // List all sections of the file - int i; - int nSecNo = pReader->GetSectionsNum(); - for ( i = 0; i < nSecNo; ++i ) { // For all sections - const IELFISection* pSec = pReader->GetSection( i ); - if ( SHT_REL != pSec->GetType() && SHT_RELA != pSec->GetType() ) { - pSec->Release(); - continue; - } - const IELFIRelocationTable* pRel = 0; - pReader->CreateSectionReader( IELFI::ELFI_RELOCATION, pSec, (void**)&pRel ); - - // Print all entries - Elf64_Addr offset; - Elf64_Addr symbolValue; - std::string symbolName; - unsigned char type; - Elf_Sxword addend; - Elf_Sxword calcValue; - Elf_Xword nNum = pRel->GetEntriesNum(); - if ( 0 < nNum ) { - std::printf( "\nSection name: %s\n", pSec->GetName().c_str() ); - std::printf( " Num Type Offset Addend Calc SymValue SymName\n" ); - for ( Elf_Xword i = 0; i < nNum; ++i ) { - pRel->GetEntry( i, offset, symbolValue, symbolName, - type, addend, calcValue ); - std::printf( "[%4llx] %02x %08llx %08llx %08llx %08llx %s\n", - i, type, offset, - addend, calcValue, - symbolValue, symbolName.c_str() ); - } - } - - pSec->Release(); - pRel->Release(); - } - - // Free resources - pReader->Release(); - - return 0; -} +#include <cstdio> +#include <ELFIO.h> + +int main( int, char* argv[] ) +{ + // Create a ELFI reader + IELFI* pReader; + ELFIO::GetInstance()->CreateELFI( &pReader ); + + // Initialize it + char* filename = argv[1]; + pReader->Load( filename ); + + // Get .text relocation entry + // List all sections of the file + int i; + int nSecNo = pReader->GetSectionsNum(); + for ( i = 0; i < nSecNo; ++i ) { // For all sections + const IELFISection* pSec = pReader->GetSection( i ); + if ( SHT_REL != pSec->GetType() && SHT_RELA != pSec->GetType() ) { + pSec->Release(); + continue; + } + const IELFIRelocationTable* pRel = 0; + pReader->CreateSectionReader( IELFI::ELFI_RELOCATION, pSec, (void**)&pRel ); + + // Print all entries + Elf64_Addr offset; + Elf64_Addr symbolValue; + std::string symbolName; + unsigned char type; + Elf_Sxword addend; + Elf_Sxword calcValue; + Elf_Xword nNum = pRel->GetEntriesNum(); + if ( 0 < nNum ) { + std::printf( "\nSection name: %s\n", pSec->GetName().c_str() ); + std::printf( " Num Type Offset Addend Calc SymValue SymName\n" ); + for ( Elf_Xword i = 0; i < nNum; ++i ) { + pRel->GetEntry( i, offset, symbolValue, symbolName, + type, addend, calcValue ); + std::printf( "[%4llx] %02x %08llx %08llx %08llx %08llx %s\n", + i, type, offset, + addend, calcValue, + symbolValue, symbolName.c_str() ); + } + } + + pSec->Release(); + pRel->Release(); + } + + // Free resources + pReader->Release(); + + return 0; +} diff --git a/examples/elfdump/Makefile.am b/examples/elfdump/Makefile.am index 8f85ad78c8ab097809e87789253e00f3d2ed0414..57a34706b1619d732826a4ac3ba230f8b7935834 100644 --- a/examples/elfdump/Makefile.am +++ b/examples/elfdump/Makefile.am @@ -1,7 +1,4 @@ -INCLUDES = -I$(top_srcdir) - -bin_PROGRAMS = elfdump - -elfdump_SOURCES = elfdump.cpp - -EXTRA_DIST = ELFDump.vcxproj +AM_CPPFLAGS = -I$(top_srcdir) +bin_PROGRAMS = elfdump +elfdump_SOURCES = elfdump.cpp +EXTRA_DIST = ELFDump.vcxproj diff --git a/examples/elfdump/Makefile.in b/examples/elfdump/Makefile.in index d21b2e04d99d45dd4b0122c22dc8161119d366f9..4dda5567c54e36885c29f5fad20fed1d6ceee844 100644 --- a/examples/elfdump/Makefile.in +++ b/examples/elfdump/Makefile.in @@ -36,7 +36,7 @@ bin_PROGRAMS = elfdump$(EXEEXT) subdir = examples/elfdump DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/configure.in +am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d @@ -144,7 +144,7 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -INCLUDES = -I$(top_srcdir) +AM_CPPFLAGS = -I$(top_srcdir) elfdump_SOURCES = elfdump.cpp EXTRA_DIST = ELFDump.vcxproj all: all-am @@ -160,9 +160,9 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) exit 1;; \ esac; \ done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu examples/elfdump/Makefile'; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign examples/elfdump/Makefile'; \ $(am__cd) $(top_srcdir) && \ - $(AUTOMAKE) --gnu examples/elfdump/Makefile + $(AUTOMAKE) --foreign examples/elfdump/Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ diff --git a/examples/elfdump/elfdump.cpp b/examples/elfdump/elfdump.cpp index 91565858b6df81b82fbcdb4ccbb8f1c8a96134a2..bf985ee4a53fe7211217960957d316d365628ac5 100644 --- a/examples/elfdump/elfdump.cpp +++ b/examples/elfdump/elfdump.cpp @@ -1,56 +1,56 @@ -/* -ELFDump.cpp - Dump ELF file using ELFIO library. - -Copyright (C) 2001-2011 by Serge Lamikhov-Center - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -#ifdef _MSC_VER - #define _SCL_SECURE_NO_WARNINGS - #define ELFIO_NO_INTTYPES -#endif - -#include <iostream> -#include <elfio/elfio_dump.hpp> - -using namespace ELFIO; - -int main( int argc, char** argv ) -{ - if ( argc != 2 ) { - printf( "Usage: ELFDump <file_name>\n" ); - return 1; - } - - elfio reader; - - if ( !reader.load( argv[1] ) ) { - printf( "File %s is not found or it is not an ELF file\n", argv[1] ); - return 1; - } - - dump::header ( std::cout, reader ); - dump::section_headers( std::cout, reader ); - dump::segment_headers( std::cout, reader ); - dump::symbol_tables ( std::cout, reader ); - dump::notes ( std::cout, reader ); - - return 0; -} +/* +ELFDump.cpp - Dump ELF file using ELFIO library. + +Copyright (C) 2001-2011 by Serge Lamikhov-Center + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifdef _MSC_VER + #define _SCL_SECURE_NO_WARNINGS + #define ELFIO_NO_INTTYPES +#endif + +#include <iostream> +#include <elfio/elfio_dump.hpp> + +using namespace ELFIO; + +int main( int argc, char** argv ) +{ + if ( argc != 2 ) { + printf( "Usage: ELFDump <file_name>\n" ); + return 1; + } + + elfio reader; + + if ( !reader.load( argv[1] ) ) { + printf( "File %s is not found or it is not an ELF file\n", argv[1] ); + return 1; + } + + dump::header ( std::cout, reader ); + dump::section_headers( std::cout, reader ); + dump::segment_headers( std::cout, reader ); + dump::symbol_tables ( std::cout, reader ); + dump::notes ( std::cout, reader ); + + return 0; +} diff --git a/examples/tutorial/Makefile.am b/examples/tutorial/Makefile.am index ee687329361f21c899a7ee25cf0dc5f6410fefa8..14bcceb7e545b1ccc90da0d348668821cd2f91c9 100644 --- a/examples/tutorial/Makefile.am +++ b/examples/tutorial/Makefile.am @@ -1,5 +1,3 @@ -INCLUDES = -I$(top_srcdir) - -bin_PROGRAMS = tutorial - -tutorial_SOURCES = tutorial.cpp +AM_CPPFLAGS = -I$(top_srcdir) +bin_PROGRAMS = tutorial +tutorial_SOURCES = tutorial.cpp diff --git a/examples/tutorial/Makefile.in b/examples/tutorial/Makefile.in index 460c653b4cb90578c20cfcf718f187e59b4bc7b3..1e9cc0cd0103b737a3e31378177df5b9b50680cf 100644 --- a/examples/tutorial/Makefile.in +++ b/examples/tutorial/Makefile.in @@ -36,7 +36,7 @@ bin_PROGRAMS = tutorial$(EXEEXT) subdir = examples/tutorial DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/configure.in +am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d @@ -144,7 +144,7 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -INCLUDES = -I$(top_srcdir) +AM_CPPFLAGS = -I$(top_srcdir) tutorial_SOURCES = tutorial.cpp all: all-am @@ -159,9 +159,9 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) exit 1;; \ esac; \ done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu examples/tutorial/Makefile'; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign examples/tutorial/Makefile'; \ $(am__cd) $(top_srcdir) && \ - $(AUTOMAKE) --gnu examples/tutorial/Makefile + $(AUTOMAKE) --foreign examples/tutorial/Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ diff --git a/examples/tutorial/tutorial.cpp b/examples/tutorial/tutorial.cpp index fecba467a7accf504f87d28da1d6dd1c88825333..1e62cde35f1fef0736542d83c7389398659fb7e8 100644 --- a/examples/tutorial/tutorial.cpp +++ b/examples/tutorial/tutorial.cpp @@ -1,90 +1,90 @@ -#include <iostream> -#include <elfio/elfio.hpp> - -using namespace ELFIO; - -int main( int argc, char** argv ) -{ - if ( argc != 2 ) { - std::cout << "Usage: tutorial <elf_file>" << std::endl; - return 1; - } - - // Create an elfio reader - elfio reader; - - // Load ELF data - if ( !reader.load( argv[1] ) ) { - std::cout << "Can't find or process ELF file " << argv[1] << std::endl; - return 2; - } - - // Print ELF file properties - std::cout << "ELF file class : "; - if ( reader.get_class() == ELFCLASS32 ) - std::cout << "ELF32" << std::endl; - else - std::cout << "ELF64" << std::endl; - - std::cout << "ELF file encoding : "; - if ( reader.get_encoding() == ELFDATA2LSB ) - std::cout << "Little endian" << std::endl; - else - std::cout << "Big endian" << std::endl; - - // Print ELF file sections info - Elf_Half sec_num = reader.sections.size(); - std::cout << "Number of sections: " << sec_num << std::endl; - for ( int i = 0; i < sec_num; ++i ) { - section* psec = reader.sections[i]; - std::cout << " [" << i << "] " - << psec->get_name() - << "\t" - << psec->get_size() - << std::endl; - // Access to section's data - // const char* p = reader.sections[i]->get_data() - } - - // Print ELF file segments info - Elf_Half seg_num = reader.segments.size(); - std::cout << "Number of segments: " << seg_num << std::endl; - for ( int i = 0; i < seg_num; ++i ) { - const segment* pseg = reader.segments[i]; - std::cout << " [" << i << "] 0x" << std::hex - << pseg->get_flags() - << "\t0x" - << pseg->get_virtual_address() - << "\t0x" - << pseg->get_file_size() - << "\t0x" - << pseg->get_memory_size() - << std::endl; - // Access to segments's data - // const char* p = reader.segments[i]->get_data() - } - - for ( int i = 0; i < sec_num; ++i ) { - section* psec = reader.sections[i]; - // Check section type - if ( psec->get_type() == SHT_SYMTAB ) { - const symbol_section_accessor symbols( reader, psec ); - for ( unsigned int j = 0; j < symbols.get_symbols_num(); ++j ) { - std::string name; - Elf64_Addr value; - Elf_Xword size; - unsigned char bind; - unsigned char type; - Elf_Half section_index; - unsigned char other; - - // Read symbol properties - symbols.get_symbol( j, name, value, size, bind, - type, section_index, other ); - std::cout << j << " " << name << " " << value << std::endl; - } - } - } - - return 0; -} +#include <iostream> +#include <elfio/elfio.hpp> + +using namespace ELFIO; + +int main( int argc, char** argv ) +{ + if ( argc != 2 ) { + std::cout << "Usage: tutorial <elf_file>" << std::endl; + return 1; + } + + // Create an elfio reader + elfio reader; + + // Load ELF data + if ( !reader.load( argv[1] ) ) { + std::cout << "Can't find or process ELF file " << argv[1] << std::endl; + return 2; + } + + // Print ELF file properties + std::cout << "ELF file class : "; + if ( reader.get_class() == ELFCLASS32 ) + std::cout << "ELF32" << std::endl; + else + std::cout << "ELF64" << std::endl; + + std::cout << "ELF file encoding : "; + if ( reader.get_encoding() == ELFDATA2LSB ) + std::cout << "Little endian" << std::endl; + else + std::cout << "Big endian" << std::endl; + + // Print ELF file sections info + Elf_Half sec_num = reader.sections.size(); + std::cout << "Number of sections: " << sec_num << std::endl; + for ( int i = 0; i < sec_num; ++i ) { + section* psec = reader.sections[i]; + std::cout << " [" << i << "] " + << psec->get_name() + << "\t" + << psec->get_size() + << std::endl; + // Access to section's data + // const char* p = reader.sections[i]->get_data() + } + + // Print ELF file segments info + Elf_Half seg_num = reader.segments.size(); + std::cout << "Number of segments: " << seg_num << std::endl; + for ( int i = 0; i < seg_num; ++i ) { + const segment* pseg = reader.segments[i]; + std::cout << " [" << i << "] 0x" << std::hex + << pseg->get_flags() + << "\t0x" + << pseg->get_virtual_address() + << "\t0x" + << pseg->get_file_size() + << "\t0x" + << pseg->get_memory_size() + << std::endl; + // Access to segments's data + // const char* p = reader.segments[i]->get_data() + } + + for ( int i = 0; i < sec_num; ++i ) { + section* psec = reader.sections[i]; + // Check section type + if ( psec->get_type() == SHT_SYMTAB ) { + const symbol_section_accessor symbols( reader, psec ); + for ( unsigned int j = 0; j < symbols.get_symbols_num(); ++j ) { + std::string name; + Elf64_Addr value; + Elf_Xword size; + unsigned char bind; + unsigned char type; + Elf_Half section_index; + unsigned char other; + + // Read symbol properties + symbols.get_symbol( j, name, value, size, bind, + type, section_index, other ); + std::cout << j << " " << name << " " << value << std::endl; + } + } + } + + return 0; +} diff --git a/examples/write_obj/Makefile.am b/examples/write_obj/Makefile.am index d78d378849f8326385b3c0dabc04c65e5725f841..eebfeee2f6e42f4008a29856e22f31c647e87865 100644 --- a/examples/write_obj/Makefile.am +++ b/examples/write_obj/Makefile.am @@ -1,5 +1,3 @@ -INCLUDES = -I$(top_srcdir) - -bin_PROGRAMS = write_obj - -write_obj_SOURCES = write_obj.cpp +AM_CPPFLAGS = -I$(top_srcdir) +bin_PROGRAMS = write_obj +write_obj_SOURCES = write_obj.cpp diff --git a/examples/write_obj/Makefile.in b/examples/write_obj/Makefile.in index 340cf49ec82480669e26fa0a9c03b4ec1e343045..ed855515fac12d09b54f553f7389e9c8a8ddc7bb 100644 --- a/examples/write_obj/Makefile.in +++ b/examples/write_obj/Makefile.in @@ -36,7 +36,7 @@ bin_PROGRAMS = write_obj$(EXEEXT) subdir = examples/write_obj DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/configure.in +am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d @@ -144,7 +144,7 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -INCLUDES = -I$(top_srcdir) +AM_CPPFLAGS = -I$(top_srcdir) write_obj_SOURCES = write_obj.cpp all: all-am @@ -159,9 +159,9 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) exit 1;; \ esac; \ done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu examples/write_obj/Makefile'; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign examples/write_obj/Makefile'; \ $(am__cd) $(top_srcdir) && \ - $(AUTOMAKE) --gnu examples/write_obj/Makefile + $(AUTOMAKE) --foreign examples/write_obj/Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ diff --git a/examples/writer/Makefile.am b/examples/writer/Makefile.am index 4e9b63948ee46a35029d5352c73b78fea64af6f7..19e519fbc53d54fe4300a804ccb2883f92ca2d4d 100644 --- a/examples/writer/Makefile.am +++ b/examples/writer/Makefile.am @@ -1,5 +1,3 @@ -INCLUDES = -I$(top_srcdir) - -bin_PROGRAMS = writer - -writer_SOURCES = writer.cpp +AM_CPPFLAGS = -I$(top_srcdir) +bin_PROGRAMS = writer +writer_SOURCES = writer.cpp diff --git a/examples/writer/Makefile.in b/examples/writer/Makefile.in index a129ace9fb4f4db667374be28241f092cf936066..039c69e0a6f9ff064e06e7039c7c6f08e5aef429 100644 --- a/examples/writer/Makefile.in +++ b/examples/writer/Makefile.in @@ -36,7 +36,7 @@ bin_PROGRAMS = writer$(EXEEXT) subdir = examples/writer DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/configure.in +am__aclocal_m4_deps = $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) mkinstalldirs = $(install_sh) -d @@ -144,7 +144,7 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -INCLUDES = -I$(top_srcdir) +AM_CPPFLAGS = -I$(top_srcdir) writer_SOURCES = writer.cpp all: all-am @@ -159,9 +159,9 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) exit 1;; \ esac; \ done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu examples/writer/Makefile'; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign examples/writer/Makefile'; \ $(am__cd) $(top_srcdir) && \ - $(AUTOMAKE) --gnu examples/writer/Makefile + $(AUTOMAKE) --foreign examples/writer/Makefile .PRECIOUS: Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ diff --git a/examples/writer/writer.cpp b/examples/writer/writer.cpp index 7dcee2c67213a5e859128689a43d3aa5178de177..e06adc4fc0644dfd5cec582019d9473a7cf0da4e 100644 --- a/examples/writer/writer.cpp +++ b/examples/writer/writer.cpp @@ -1,82 +1,82 @@ -#include <elfio/elfio.hpp> - -using namespace ELFIO; - -int main( void ) -{ - elfio writer; - - // You can't proceed without this function call! - writer.create( ELFCLASS32, ELFDATA2LSB ); - - writer.set_os_abi( ELFOSABI_LINUX ); - writer.set_type( ET_EXEC ); - writer.set_machine( EM_386 ); - - // Create code section - section* text_sec = writer.sections.add( ".text" ); - text_sec->set_type( SHT_PROGBITS ); - text_sec->set_flags( SHF_ALLOC | SHF_EXECINSTR ); - text_sec->set_addr_align( 0x10 ); - - // Add data into it - char text[] = { '\xB8', '\x04', '\x00', '\x00', '\x00', // mov eax, 4 - '\xBB', '\x01', '\x00', '\x00', '\x00', // mov ebx, 1 - '\xB9', '\x20', '\x80', '\x04', '\x08', // mov ecx, msg - '\xBA', '\x0E', '\x00', '\x00', '\x00', // mov edx, 14 - '\xCD', '\x80', // int 0x80 - '\xB8', '\x01', '\x00', '\x00', '\x00', // mov eax, 1 - '\xCD', '\x80' // int 0x80 - }; - text_sec->set_data( text, sizeof( text ) ); - - // Create a loadable segment - segment* text_seg = writer.segments.add(); - text_seg->set_type( PT_LOAD ); - text_seg->set_virtual_address( 0x08048000 ); - text_seg->set_physical_address( 0x08048000 ); - text_seg->set_flags( PF_X | PF_R ); - text_seg->set_align( 0x1000 ); - - // Add code section into program segment - text_seg->add_section_index( text_sec->get_index(), text_sec->get_addr_align() ); - - // Create data section* - section* data_sec = writer.sections.add( ".data" ); - data_sec->set_type( SHT_PROGBITS ); - data_sec->set_flags( SHF_ALLOC | SHF_WRITE ); - data_sec->set_addr_align( 0x4 ); - - char data[] = { '\x48', '\x65', '\x6C', '\x6C', '\x6F', // msg: db 'Hello, World!', 10 - '\x2C', '\x20', '\x57', '\x6F', '\x72', - '\x6C', '\x64', '\x21', '\x0A' - }; - data_sec->set_data( data, sizeof( data ) ); - - // Create a read/write segment - segment* data_seg = writer.segments.add(); - data_seg->set_type( PT_LOAD ); - data_seg->set_virtual_address( 0x08048020 ); - data_seg->set_physical_address( 0x08048020 ); - data_seg->set_flags( PF_W | PF_R ); - data_seg->set_align( 0x10 ); - - // Add code section into program segment - data_seg->add_section_index( data_sec->get_index(), data_sec->get_addr_align() ); - - section* note_sec = writer.sections.add( ".note" ); - note_sec->set_type( SHT_NOTE ); - note_sec->set_addr_align( 1 ); - note_section_accessor note_writer( writer, note_sec ); - note_writer.add_note( 0x01, "Created by ELFIO", 0, 0 ); - char descr[6] = {0x31, 0x32, 0x33, 0x34, 0x35, 0x36}; - note_writer.add_note( 0x01, "Never easier!", descr, sizeof( descr ) ); - - // Setup entry point - writer.set_entry( 0x08048000 ); - - // Create ELF file - writer.save( "hello_i386_32" ); - - return 0; -} +#include <elfio/elfio.hpp> + +using namespace ELFIO; + +int main( void ) +{ + elfio writer; + + // You can't proceed without this function call! + writer.create( ELFCLASS32, ELFDATA2LSB ); + + writer.set_os_abi( ELFOSABI_LINUX ); + writer.set_type( ET_EXEC ); + writer.set_machine( EM_386 ); + + // Create code section + section* text_sec = writer.sections.add( ".text" ); + text_sec->set_type( SHT_PROGBITS ); + text_sec->set_flags( SHF_ALLOC | SHF_EXECINSTR ); + text_sec->set_addr_align( 0x10 ); + + // Add data into it + char text[] = { '\xB8', '\x04', '\x00', '\x00', '\x00', // mov eax, 4 + '\xBB', '\x01', '\x00', '\x00', '\x00', // mov ebx, 1 + '\xB9', '\x20', '\x80', '\x04', '\x08', // mov ecx, msg + '\xBA', '\x0E', '\x00', '\x00', '\x00', // mov edx, 14 + '\xCD', '\x80', // int 0x80 + '\xB8', '\x01', '\x00', '\x00', '\x00', // mov eax, 1 + '\xCD', '\x80' // int 0x80 + }; + text_sec->set_data( text, sizeof( text ) ); + + // Create a loadable segment + segment* text_seg = writer.segments.add(); + text_seg->set_type( PT_LOAD ); + text_seg->set_virtual_address( 0x08048000 ); + text_seg->set_physical_address( 0x08048000 ); + text_seg->set_flags( PF_X | PF_R ); + text_seg->set_align( 0x1000 ); + + // Add code section into program segment + text_seg->add_section_index( text_sec->get_index(), text_sec->get_addr_align() ); + + // Create data section* + section* data_sec = writer.sections.add( ".data" ); + data_sec->set_type( SHT_PROGBITS ); + data_sec->set_flags( SHF_ALLOC | SHF_WRITE ); + data_sec->set_addr_align( 0x4 ); + + char data[] = { '\x48', '\x65', '\x6C', '\x6C', '\x6F', // msg: db 'Hello, World!', 10 + '\x2C', '\x20', '\x57', '\x6F', '\x72', + '\x6C', '\x64', '\x21', '\x0A' + }; + data_sec->set_data( data, sizeof( data ) ); + + // Create a read/write segment + segment* data_seg = writer.segments.add(); + data_seg->set_type( PT_LOAD ); + data_seg->set_virtual_address( 0x08048020 ); + data_seg->set_physical_address( 0x08048020 ); + data_seg->set_flags( PF_W | PF_R ); + data_seg->set_align( 0x10 ); + + // Add code section into program segment + data_seg->add_section_index( data_sec->get_index(), data_sec->get_addr_align() ); + + section* note_sec = writer.sections.add( ".note" ); + note_sec->set_type( SHT_NOTE ); + note_sec->set_addr_align( 1 ); + note_section_accessor note_writer( writer, note_sec ); + note_writer.add_note( 0x01, "Created by ELFIO", 0, 0 ); + char descr[6] = {0x31, 0x32, 0x33, 0x34, 0x35, 0x36}; + note_writer.add_note( 0x01, "Never easier!", descr, sizeof( descr ) ); + + // Setup entry point + writer.set_entry( 0x08048000 ); + + // Create ELF file + writer.save( "hello_i386_32" ); + + return 0; +} diff --git a/prepare_cygwin.sh b/prepare_cygwin.sh index bbd6234c3984c56c0a6ef976f43a95803c5da252..f4704316c80251e8467ef269a0811f38d6e41d99 100755 --- a/prepare_cygwin.sh +++ b/prepare_cygwin.sh @@ -1,20 +1,20 @@ -ELFIOVER='ELFIO-1.0.3' -BUILDVER='1' -FULLVER=${ELFIOVER}-${BUILDVER} - -mkdir $1 -cp ${ELFIOVER}.tar.gz $1 -cd $1 -tar -xzf ${ELFIOVER}.tar.gz -cp ../cygwin/${FULLVER}.sh . -mkdir ${ELFIOVER}/CYGWIN-PATCHES -cp ../cygwin/CYGWIN-PATCHES/* ${ELFIOVER}/CYGWIN-PATCHES -./${FULLVER}.sh mkdirs -./${FULLVER}.sh spkg - -cd .. -mkdir $2 -cp $1/${FULLVER}-src.tar.bz2 $2 -cd $2 -tar -xjf ${FULLVER}-src.tar.bz2 -./${FULLVER}.sh all +ELFIOVER='ELFIO-1.0.3' +BUILDVER='1' +FULLVER=${ELFIOVER}-${BUILDVER} + +mkdir $1 +cp ${ELFIOVER}.tar.gz $1 +cd $1 +tar -xzf ${ELFIOVER}.tar.gz +cp ../cygwin/${FULLVER}.sh . +mkdir ${ELFIOVER}/CYGWIN-PATCHES +cp ../cygwin/CYGWIN-PATCHES/* ${ELFIOVER}/CYGWIN-PATCHES +./${FULLVER}.sh mkdirs +./${FULLVER}.sh spkg + +cd .. +mkdir $2 +cp $1/${FULLVER}-src.tar.bz2 $2 +cd $2 +tar -xjf ${FULLVER}-src.tar.bz2 +./${FULLVER}.sh all