mirror of
https://github.com/serge1/ELFIO.git
synced 2025-02-28 16:11:47 +00:00
Use <elfio/> prefix for \#include files
This commit is contained in:
parent
647aa544be
commit
d3a0732983
BIN
doc/elfio.docx
BIN
doc/elfio.docx
Binary file not shown.
@ -37,11 +37,12 @@ THE SOFTWARE.
|
||||
#include <vector>
|
||||
#include <typeinfo>
|
||||
|
||||
#include "elf_types.hpp"
|
||||
#include "elfio_header.hpp"
|
||||
#include "elfio_section.hpp"
|
||||
#include "elfio_segment.hpp"
|
||||
#include "elfio_strings.hpp"
|
||||
#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 ) \
|
||||
|
@ -27,7 +27,7 @@ THE SOFTWARE.
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <elfio.hpp>
|
||||
#include <elfio/elfio.hpp>
|
||||
|
||||
namespace ELFIO {
|
||||
|
||||
|
@ -24,8 +24,6 @@ THE SOFTWARE.
|
||||
#define ELF_HEADER_HPP
|
||||
|
||||
#include <fstream>
|
||||
#include "elf_types.hpp"
|
||||
#include "elfio_utils.hpp"
|
||||
|
||||
namespace ELFIO {
|
||||
|
||||
|
@ -25,8 +25,6 @@ THE SOFTWARE.
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include "elf_types.hpp"
|
||||
#include "elfio_utils.hpp"
|
||||
|
||||
namespace ELFIO {
|
||||
|
||||
|
@ -25,8 +25,6 @@ THE SOFTWARE.
|
||||
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include "elf_types.hpp"
|
||||
#include "elfio_utils.hpp"
|
||||
|
||||
namespace ELFIO {
|
||||
|
||||
|
@ -23,9 +23,6 @@ THE SOFTWARE.
|
||||
#ifndef ELFIO_UTILS_HPP
|
||||
#define ELFIO_UTILS_HPP
|
||||
|
||||
#include "elf_types.hpp"
|
||||
|
||||
|
||||
#define ELFIO_GET_ACCESS( TYPE, NAME, FIELD ) \
|
||||
TYPE get_##NAME() const \
|
||||
{ \
|
||||
|
@ -28,7 +28,7 @@ THE SOFTWARE.
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <elfio_dump.hpp>
|
||||
#include <elfio/elfio_dump.hpp>
|
||||
|
||||
using namespace ELFIO;
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <iostream>
|
||||
#include <elfio.hpp>
|
||||
#include <elfio/elfio.hpp>
|
||||
|
||||
using namespace ELFIO;
|
||||
|
||||
|
@ -1,82 +1,82 @@
|
||||
#include <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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user