mirror of
https://github.com/serge1/ELFIO.git
synced 2025-03-29 19:20:41 +00:00
Make 'writer' examples to generate x86_64 files
This commit is contained in:
parent
64e6b2d774
commit
e6c59547e3
2
.gitignore
vendored
2
.gitignore
vendored
@ -44,6 +44,8 @@ tests/elf_examples/write_exe_i386_32_section_added
|
|||||||
tests/elf_examples/ppc-32bit-testcopy*.elf
|
tests/elf_examples/ppc-32bit-testcopy*.elf
|
||||||
tests/elf_examples/null_section_inside_segment*
|
tests/elf_examples/null_section_inside_segment*
|
||||||
tests/elf_examples/segment_containing_no_section*
|
tests/elf_examples/segment_containing_no_section*
|
||||||
|
examples/writer/hello_x86_64
|
||||||
|
examples/write_obj/hello
|
||||||
|
|
||||||
# various unwanted files (backups, objects, cmake artifacts)
|
# various unwanted files (backups, objects, cmake artifacts)
|
||||||
*~
|
*~
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* 2. Execute result file write_obj
|
* 2. Execute result file write_obj
|
||||||
* ./write_obj
|
* ./write_obj
|
||||||
* 3. Link output file hello.o:
|
* 3. Link output file hello.o:
|
||||||
* gcc -m32 -s -nostartfiles -nostdlib hello.o -o hello
|
* ld -m elf x64 -o hello hello.o
|
||||||
* 4. Run the result file:
|
* 4. Run the result file:
|
||||||
* ./hello
|
* ./hello
|
||||||
*/
|
*/
|
||||||
@ -21,11 +21,11 @@ int main( void )
|
|||||||
elfio writer;
|
elfio writer;
|
||||||
|
|
||||||
// You can't proceed before this function call!
|
// You can't proceed before this function call!
|
||||||
writer.create( ELFCLASS32, ELFDATA2LSB );
|
writer.create( ELFCLASS64, ELFDATA2LSB );
|
||||||
|
|
||||||
writer.set_os_abi( ELFOSABI_LINUX );
|
writer.set_os_abi( ELFOSABI_LINUX );
|
||||||
writer.set_type( ET_REL );
|
writer.set_type( ET_REL );
|
||||||
writer.set_machine( EM_386 );
|
writer.set_machine(EM_X86_64);
|
||||||
|
|
||||||
// This is our code
|
// This is our code
|
||||||
char text[] = { '\xB8', '\x04', '\x00', '\x00', '\x00', // mov eax, 4
|
char text[] = { '\xB8', '\x04', '\x00', '\x00', '\x00', // mov eax, 4
|
||||||
|
@ -7,11 +7,11 @@ int main( void )
|
|||||||
elfio writer;
|
elfio writer;
|
||||||
|
|
||||||
// You can't proceed without this function call!
|
// You can't proceed without this function call!
|
||||||
writer.create( ELFCLASS32, ELFDATA2LSB );
|
writer.create( ELFCLASS64, ELFDATA2LSB );
|
||||||
|
|
||||||
writer.set_os_abi( ELFOSABI_LINUX );
|
writer.set_os_abi( ELFOSABI_LINUX );
|
||||||
writer.set_type( ET_EXEC );
|
writer.set_type( ET_EXEC );
|
||||||
writer.set_machine( EM_386 );
|
writer.set_machine( EM_X86_64 );
|
||||||
|
|
||||||
// Create code section
|
// Create code section
|
||||||
section* text_sec = writer.sections.add( ".text" );
|
section* text_sec = writer.sections.add( ".text" );
|
||||||
@ -41,7 +41,7 @@ int main( void )
|
|||||||
// Add code section into program segment
|
// Add code section into program segment
|
||||||
text_seg->add_section_index( text_sec->get_index(), text_sec->get_addr_align() );
|
text_seg->add_section_index( text_sec->get_index(), text_sec->get_addr_align() );
|
||||||
|
|
||||||
// Create data section*
|
// Create data section
|
||||||
section* data_sec = writer.sections.add( ".data" );
|
section* data_sec = writer.sections.add( ".data" );
|
||||||
data_sec->set_type( SHT_PROGBITS );
|
data_sec->set_type( SHT_PROGBITS );
|
||||||
data_sec->set_flags( SHF_ALLOC | SHF_WRITE );
|
data_sec->set_flags( SHF_ALLOC | SHF_WRITE );
|
||||||
@ -77,7 +77,7 @@ int main( void )
|
|||||||
writer.set_entry( 0x08048000 );
|
writer.set_entry( 0x08048000 );
|
||||||
|
|
||||||
// Create ELF file
|
// Create ELF file
|
||||||
writer.save( "hello_i386_32" );
|
writer.save("hello_x86_64");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user