Skip to content
Snippets Groups Projects
Commit 493549e0 authored by Serge Lamikhov-Center's avatar Serge Lamikhov-Center
Browse files

Initial

parents
No related branches found
No related tags found
No related merge requests found
Showing with 826 additions and 0 deletions
ELFIO library implemented by
Serge Lamikhov-Center <to_serge@users.sourceforge.net>
ELFIO tutorial - Serge Lamikhov-Center
Allan Finch
COPYING 0 → 100644
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.

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ELFDump", "Examples\ELFDump\ELFDump.vcxproj", "{CBAA735F-E237-4976-909F-2349920ED871}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ELFIOTest", "ELFIOTest\ELFIOTest.vcxproj", "{FC8A3379-B8AA-4C32-804F-F8C43AFBC2A1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CBAA735F-E237-4976-909F-2349920ED871}.Debug|Win32.ActiveCfg = Debug|Win32
{CBAA735F-E237-4976-909F-2349920ED871}.Debug|Win32.Build.0 = Debug|Win32
{CBAA735F-E237-4976-909F-2349920ED871}.Release|Win32.ActiveCfg = Release|Win32
{CBAA735F-E237-4976-909F-2349920ED871}.Release|Win32.Build.0 = Release|Win32
{FC8A3379-B8AA-4C32-804F-F8C43AFBC2A1}.Debug|Win32.ActiveCfg = Debug|Win32
{FC8A3379-B8AA-4C32-804F-F8C43AFBC2A1}.Debug|Win32.Build.0 = Debug|Win32
{FC8A3379-B8AA-4C32-804F-F8C43AFBC2A1}.Release|Win32.ActiveCfg = Release|Win32
{FC8A3379-B8AA-4C32-804F-F8C43AFBC2A1}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
ELFIO library implemented by
Serge Lamikhov-Center <to_serge@users.sourceforge.net>
ELFIO tutorial - Serge Lamikhov-Center
Allan Finch
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.

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ELFDump", "Examples\ELFDump\ELFDump.vcxproj", "{CBAA735F-E237-4976-909F-2349920ED871}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ELFIOTest", "ELFIOTest\ELFIOTest.vcxproj", "{FC8A3379-B8AA-4C32-804F-F8C43AFBC2A1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CBAA735F-E237-4976-909F-2349920ED871}.Debug|Win32.ActiveCfg = Debug|Win32
{CBAA735F-E237-4976-909F-2349920ED871}.Debug|Win32.Build.0 = Debug|Win32
{CBAA735F-E237-4976-909F-2349920ED871}.Release|Win32.ActiveCfg = Release|Win32
{CBAA735F-E237-4976-909F-2349920ED871}.Release|Win32.Build.0 = Release|Win32
{FC8A3379-B8AA-4C32-804F-F8C43AFBC2A1}.Debug|Win32.ActiveCfg = Debug|Win32
{FC8A3379-B8AA-4C32-804F-F8C43AFBC2A1}.Debug|Win32.Build.0 = Debug|Win32
{FC8A3379-B8AA-4C32-804F-F8C43AFBC2A1}.Release|Win32.ActiveCfg = Release|Win32
{FC8A3379-B8AA-4C32-804F-F8C43AFBC2A1}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
This diff is collapsed.
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{FC8A3379-B8AA-4C32-804F-F8C43AFBC2A1}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>ELFIOTest</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\elfio;d:\Developer\boost_1_48_0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>
</AdditionalDependencies>
<AdditionalLibraryDirectories>d:\Developer\boost_1_48_0\stage\lib</AdditionalLibraryDirectories>
</Link>
<PostBuildEvent>
<Command>"$(TargetDir)\$(TargetName).exe" --result_code=no --report_level=short </Command>
</PostBuildEvent>
<PostBuildEvent>
<Message>Auto run test</Message>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\ELFIO;d:\Developer\boost_1_46_1;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>$(SolutionDir)$(Configuration)\ELFIO.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>d:\Developer\boost_1_46_1\stage\lib</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="ELFIOTest.cpp">
<PreprocessToFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
</PreprocessToFile>
</ClCompile>
<ClCompile Include="ELFIOTest1.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ELFIOTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ELFIOTest1.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommandArguments>
</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
\ No newline at end of file
#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.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_entry( nStrIndex, 0, 0,
STB_LOCAL, STT_NOTYPE, 0,
data_sec->get_index() );
// Another way to add symbol
symbol_writer.add_entry( 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 )
{
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 );
// 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.add_section( ".note" );
note_sec->set_type( SHT_NOTE );
note_sec->set_addr_align( 1 );
note_section_accessor note_writer( writer, note_sec );
char descr[6] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
note_writer.add_note( 0x77, "Created by ELFIO", 0, 0 );
// Create note section*
IELFOSection* note_sec = pELFO->AddSection( ".note",
SHT_NOTE,
0,
0,
1,
0 );
// Create notes writer
IELFONotesWriter* pNoteWriter = 0;
pELFO->CreateSectionWriter( IELFO::ELFO_NOTE, note_sec, (void**)&pNoteWriter );
// Add new entry
pNoteWriter->AddNote( 0x77, "Created by ELFIO", 0, 0 );
pNoteWriter->release();
note_sec->release();
*/
// 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" );
}
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)
Copyright 1994, 1995, 1996, 1999, 2000, 2001 Free Software Foundation,
Inc.
This file is free documentation; the Free Software Foundation gives
unlimited permission to copy, distribute and modify it.
Basic Installation
==================
These are generic installation instructions.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses
those values to create a `Makefile' in each directory of the package.
It may also create one or more `.h' files containing system-dependent
definitions. Finally, it creates a shell script `config.status' that
you can run in the future to recreate the current configuration, and a
file `config.log' containing compiler output (useful mainly for
debugging `configure').
It can also use an optional file (typically called `config.cache'
and enabled with `--cache-file=config.cache' or simply `-C') that saves
the results of its tests to speed up reconfiguring. (Caching is
disabled by default to prevent problems with accidental use of stale
cache files.)
If you need to do unusual things to compile the package, please try
to figure out how `configure' could check whether to do them, and mail
diffs or instructions to the address given in the `README' so they can
be considered for the next release. If you are using the cache, and at
some point `config.cache' contains results you don't want to keep, you
may remove or edit it.
The file `configure.ac' (or `configure.in') is used to create
`configure' by a program called `autoconf'. You only need
`configure.ac' if you want to change it or regenerate `configure' using
a newer version of `autoconf'.
The simplest way to compile this package is:
1. `cd' to the directory containing the package's source code and type
`./configure' to configure the package for your system. If you're
using `csh' on an old version of System V, you might need to type
`sh ./configure' instead to prevent `csh' from trying to execute
`configure' itself.
Running `configure' takes awhile. While running, it prints some
messages telling which features it is checking for.
2. Type `make' to compile the package.
3. Optionally, type `make check' to run any self-tests that come with
the package.
4. Type `make install' to install the programs and any data files and
documentation.
5. You can remove the program binaries and object files from the
source code directory by typing `make clean'. To also remove the
files that `configure' created (so you can compile the package for
a different kind of computer), type `make distclean'. There is
also a `make maintainer-clean' target, but that is intended mainly
for the package's developers. If you use it, you may have to get
all sorts of other programs in order to regenerate files that came
with the distribution.
Compilers and Options
=====================
Some systems require unusual options for compilation or linking that
the `configure' script does not know about. Run `./configure --help'
for details on some of the pertinent environment variables.
You can give `configure' initial values for variables by setting
them in the environment. You can do that on the command line like this:
./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
*Note Defining Variables::, for more details.
Compiling For Multiple Architectures
====================================
You can compile the package for more than one kind of computer at the
same time, by placing the object files for each architecture in their
own directory. To do this, you must use a version of `make' that
supports the `VPATH' variable, such as GNU `make'. `cd' to the
directory where you want the object files and executables to go and run
the `configure' script. `configure' automatically checks for the
source code in the directory that `configure' is in and in `..'.
If you have to use a `make' that does not support the `VPATH'
variable, you have to compile the package for one architecture at a
time in the source code directory. After you have installed the
package for one architecture, use `make distclean' before reconfiguring
for another architecture.
Installation Names
==================
By default, `make install' will install the package's files in
`/usr/local/bin', `/usr/local/man', etc. You can specify an
installation prefix other than `/usr/local' by giving `configure' the
option `--prefix=PATH'.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
give `configure' the option `--exec-prefix=PATH', the package will use
PATH as the prefix for installing programs and libraries.
Documentation and other data files will still use the regular prefix.
In addition, if you use an unusual directory layout you can give
options like `--bindir=PATH' to specify different values for particular
kinds of files. Run `configure --help' for a list of the directories
you can set and what kinds of files go in them.
If the package supports it, you can cause programs to be installed
with an extra prefix or suffix on their names by giving `configure' the
option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
Optional Features
=================
Some packages pay attention to `--enable-FEATURE' options to
`configure', where FEATURE indicates an optional part of the package.
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
is something like `gnu-as' or `x' (for the X Window System). The
`README' should mention any `--enable-' and `--with-' options that the
package recognizes.
For packages that use the X Window System, `configure' can usually
find the X include and library files automatically, but if it doesn't,
you can use the `configure' options `--x-includes=DIR' and
`--x-libraries=DIR' to specify their locations.
Specifying the System Type
==========================
There may be some features `configure' cannot figure out
automatically, but needs to determine by the type of host the package
will run on. Usually `configure' can figure that out, but if it prints
a message saying it cannot guess the host type, give it the
`--build=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name which has the form:
CPU-COMPANY-SYSTEM
where SYSTEM can have one of these forms:
OS KERNEL-OS
See the file `config.sub' for the possible values of each field. If
`config.sub' isn't included in this package, then this package doesn't
need to know the host type.
If you are _building_ compiler tools for cross-compiling, you should
use the `--target=TYPE' option to select the type of system they will
produce code for.
If you want to _use_ a cross compiler, that generates code for a
platform different from the build platform, you should specify the host
platform (i.e., that on which the generated programs will eventually be
run) with `--host=TYPE'. In this case, you should also specify the
build platform with `--build=TYPE', because, in this case, it may not
be possible to guess the build platform (it sometimes involves
compiling and running simple test programs, and this can't be done if
the compiler is a cross compiler).
Sharing Defaults
================
If you want to set default values for `configure' scripts to share,
you can create a site shell script called `config.site' that gives
default values for variables like `CC', `cache_file', and `prefix'.
`configure' looks for `PREFIX/share/config.site' if it exists, then
`PREFIX/etc/config.site' if it exists. Or, you can set the
`CONFIG_SITE' environment variable to the location of the site script.
A warning: not all `configure' scripts look for a site script.
Defining Variables
==================
Variables not defined in a site shell script can be set in the
environment passed to `configure'. However, some packages may run
configure again during the build, and the customized values of these
variables may be lost. In order to avoid this problem, you should set
them in the `configure' command line, using `VAR=value'. For example:
./configure CC=/usr/local2/bin/gcc
will cause the specified gcc to be used as the C compiler (unless it is
overridden in the site shell script).
`configure' Invocation
======================
`configure' recognizes the following options to control how it
operates.
`--help'
`-h'
Print a summary of the options to `configure', and exit.
`--version'
`-V'
Print the version of Autoconf used to generate the `configure'
script, and exit.
`--cache-file=FILE'
Enable the cache: use and save the results of the tests in FILE,
traditionally `config.cache'. FILE defaults to `/dev/null' to
disable caching.
`--config-cache'
`-C'
Alias for `--cache-file=config.cache'.
`--quiet'
`--silent'
`-q'
Do not print messages saying which checks are being made. To
suppress all normal output, redirect it to `/dev/null' (any error
messages will still be shown).
`--srcdir=DIR'
Look for the package's source code in directory DIR. Usually
`configure' can determine that directory automatically.
`configure' also accepts some other, not widely useful, options. Run
`configure --help' for more details.
SUBDIRS = examples doc
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
This diff is collapsed.
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.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment