Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • third-party-mirrors/ELFIO
1 result
Show changes
Commits on Source (375)
Showing with 716 additions and 1575 deletions
BasedOnStyle : LLVM
AccessModifierOffset : -2
AlignAfterOpenBracket : true
AlignConsecutiveAssignments : true
AlignConsecutiveDeclarations : true
AlignConsecutiveMacros : true
AlignEscapedNewlines : true
AlignOperands : true
AlignTrailingComments : true
BinPackParameters : false
BraceWrapping:
AfterCaseLabel : true
AfterClass : true
AfterEnum : true
AfterFunction : true
AfterNamespace : false
AfterStruct : true
AfterExternBlock : true
BeforeCatch : true
BeforeElse : true
BreakBeforeBraces : Custom
ColumnLimit : 80
FixNamespaceComments : true
IndentCaseLabels : false
IndentWidth : 4
NamespaceIndentation : Inner
PointerAlignment : Left
ReflowComments : false
SortIncludes : false
SpacesInConditionalStatement : true
SpacesInParentheses : true
TabWidth : 4
UseTab : Never
name: C/C++ CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
BUILD_TYPE: Release
jobs:
build_cmake:
name: CMake Build & Test
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
build_type: [Release]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Configure CMake
run: cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DELFIO_BUILD_EXAMPLES=YES -DELFIO_BUILD_TESTS=YES
- name: Build
run: cmake --build build --config ${{ matrix.build_type }}
- name: Test
run: |
cd build
ctest -C ${{ matrix.build_type }}
cd ..
name: "CodeQL"
on:
push:
branches: [main]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
schedule:
- cron: '0 15 * * 5'
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Override automatic language detection by changing the below list
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
language: ['cpp']
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2
# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
#- run: git checkout HEAD^2
# if: ${{ github.event_name == 'pull_request' }}
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
#- name: Autobuild
# uses: github/codeql-action/autobuild@v1
# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
- run: |
cmake -B build -D ELFIO_BUILD_EXAMPLES=ON
cmake --build build
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
autom4te.cache
Debug
Release
ELFIO.sdf
ELFIO.v11.suo
ELFIO.opensdf
.vs
ELFIOTest/Debug
ELFIOTest/ELFIOTest.vcxproj.user
examples/ELFDump/Debug
# generated elf files
elf_examples/*_copy
elf_examples/*_copy.elf
elf_examples/elf_dummy_header_i386_32.elf
elf_examples/elf_dummy_header_i386_64.elf
elf_examples/elf_dummy_header_ppc_32.elf
elf_examples/elf_dummy_header_ppc_64.elf
elf_examples/write_exe_i386_32
/ELFIO.v12.suo
ELFIOTest/ELFIOTest
# various unwanted files (backups, objects, cmake artifacts)
*~
*.o
*.kate-swp
*.swp
.#*
\#*#
CMakeCache.txt
Makefile
CMakeFiles
/build*/
*.res
# autotools artifacts
.deps
config.status
# eclipse project files
.settings
.project
.cproject
.cdtproject
.cdtbuild
# netbeans project files
/dist/
Makefile
.dep.inc
nbproject
# QtCreator project files
CMakeLists.txt.user
# ignore all _ prefixed directories (usually used for generated directories)
_*/
# Latex build output
*.pdf
*.log
*.out
*.aux
*.bbl
*.toc
*.blg
/examples/elfdump/ELFDump.vcxproj.user
autom4te.cache
Debug
Release
.vs
tmp/
docs
tests/Debug
tests/Release
tests/ELFIOTest
tests/ELFIOTest.exe
tests/runELFtests.trs
examples/ELFDump/Debug
examples/anonymizer/anonymizer
examples/anonymizer/anonymizer.exe
examples/elfdump/elfdump
examples/elfdump/elfdump.exe
examples/tutorial/tutorial
examples/tutorial/tutorial.exe
examples/write_obj/write_obj
examples/write_obj/write_obj.exe
examples/writer/writer
examples/writer/writer.exe
# generated elf files
tests/elf_examples/*_copy
tests/elf_examples/*_copy.elf
tests/elf_examples/elf_dummy_header_i386_32.elf
tests/elf_examples/elf_dummy_header_i386_64.elf
tests/elf_examples/elf_dummy_header_ppc_32.elf
tests/elf_examples/elf_dummy_header_ppc_64.elf
tests/elf_examples/write_exe_i386_32
tests/elf_examples/write_exe_i386_32_w_addr
tests/elf_examples/write_exe_i386_32_wo_addr
tests/elf_examples/write_exe_i386_32_section_added
tests/elf_examples/ppc-32bit-testcopy*.elf
tests/elf_examples/null_section_inside_segment*
tests/elf_examples/segment_containing_no_section*
tests/elf_examples/test_symbols_order.elf
tests/elf_examples/zavl_gen.ko
tests/elfio_fuzzer
tests/corpus
examples/writer/hello_x86_64
examples/write_obj/hello
examples/c_wrapper/c_example
examples/add_section/add_section
examples/elfdump/elfdump.trs
# various unwanted files (backups, objects, cmake artifacts)
*~
*.o
*.kate-swp
*.swp
.#*
\#*#
CMakeCache.txt
CMakeSettings.json
Makefile
CMakeFiles
/build*/
out
*.res
# autotools artifacts
.deps
config.status
ELFIOTest/runELFtests.trs
# eclipse project files
.settings
.project
.cproject
.cdtproject
.cdtbuild
# netbeans project files
/dist/
Makefile
.dep.inc
nbproject
# QtCreator project files
CMakeLists.txt.user
# ignore all _ prefixed directories (usually used for generated directories)
_*/
# Latex build output
*.pdf
*.log
*.out
*.aux
*.bbl
*.toc
*.blg
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}",
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/g++",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
\ No newline at end of file
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Run ELFIO Tests",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/tests/ELFIOTest",
"args": [
"--gtest_filter=ELFIOTest.load32",
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build/tests",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "ELFIO Test build",
"miDebuggerPath": "/usr/bin/gdb"
},
{
"name": "Run ELF Dump",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/examples/elfdump/elfdump",
"args": [
"build/tests/crash-de896e9e31bf6f4c540e7462ccc0440018e4f0de"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "ELF Dump Build",
"miDebuggerPath": "/usr/bin/gdb"
},
{
"name": "Run proc_mem",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/examples/proc_mem/proc_mem",
"args": [
"11706",
"/usr/bin/bash"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"miDebuggerPath": "/home/user/ELFIO/examples/sudo_gdb.sh"
},
{
"name": "Run dump for /proc/kcore",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/examples/elfdump/elfdump",
"args": [
"/proc/kcore"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"miDebuggerPath": "/home/user/ELFIO/examples/sudo_gdb.sh"
},
{
"name": "Fuzzer",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/build/tests/elfio_fuzzer",
"args": [
"crash-7143f5e49745dc6ce8909e642f9351d9d6496020"
],
"cwd": "${workspaceFolder}/build/tests",
}
]
}
\ No newline at end of file
{
"files.associations": {
"copyright": "json",
"*.ipp": "cpp",
"strstream": "cpp",
"cerrno": "cpp",
"csetjmp": "cpp",
"cstdarg": "cpp",
"rope": "cpp",
"iostream": "cpp",
"streambuf": "cpp",
"*.tcc": "cpp",
"regex": "cpp",
"algorithm": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"bitset": "cpp",
"cassert": "cpp",
"cctype": "cpp",
"cfloat": "cpp",
"chrono": "cpp",
"ciso646": "cpp",
"climits": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"complex": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"locale": "cpp",
"new": "cpp",
"ostream": "cpp",
"queue": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"thread": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"variant": "cpp",
"compare": "cpp"
},
"svn.ignoreMissingSvnWarning": true,
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "googletest.failed",
"settings": {
"foreground": "#f00"
}
},
{
"scope": "googletest.passed",
"settings": {
"foreground": "#0f0"
}
},
{
"scope": "googletest.run",
"settings": {
"foreground": "#0f0"
}
}
]
},
"gtest-adapter.debugConfig": "Run ELFIO Tests",
"gtest-adapter.supportLocation": true,
"sonarlint.pathToCompileCommands": "${workspaceFolder}/build/compile_commands.json"
}
\ No newline at end of file
{
"tasks": [
{
"type": "shell",
"label": "ELFIO Test build",
"command": "make",
"args": [
"INCLUDES=-I..",
"CXXFLAGS='-g -O0'"
],
"options": {
"cwd": "${workspaceRoot}/build/tests"
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
},
{
"type": "shell",
"label": "ELF Dump Build",
"command": "make",
"args": [
"INCLUDES=-I..",
"CXXFLAGS='-g -O0'"
],
"options": {
"cwd": "${workspaceRoot}/build"
},
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "clang-tidy",
"command": "clang-tidy",
"args": [
"--checks=*,-modernize-use-trailing-return-type,-modernize-avoid-c-arrays,-llvm*,-fuchsia-*,-altera-*",
"-header-filter=./*",
"examples/elfdump/elfdump.cpp",
"--",
"-I.",
],
"options": {
"cwd": "${workspaceRoot}"
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
},
{
"type": "shell",
"label": "Fuzzer",
"command": "clang",
"args": [
"-g",
"-O0",
"-fsanitize=fuzzer,address",
"-I..",
"elfio_fuzzer.cpp",
"-o",
"elfio_fuzzer",
],
"options": {
"cwd": "${workspaceRoot}/tests"
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
},
{
"type": "shell",
"label": "Fuzzer Tests",
"command": "./elfio_fuzzer",
"args": [
"-jobs=8",
"corpus"
],
"options": {
"cwd": "${workspaceRoot}/tests"
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
}
],
"version": "2.0.0"
}
\ No newline at end of file
ELFIO library implemented by
Serge Lamikhov-Center <to_serge@users.sourceforge.net>
cmake_minimum_required(VERSION 3.10)
# Detect if we are the top level CMakeLists.txt or are we included in some
# other project
if(NOT DEFINED PROJECT_NAME)
set(IS_TOP_PROJECT TRUE)
endif()
if(IS_TOP_PROJECT)
# Turn this on in order to build elfio examples
option(ELFIO_BUILD_EXAMPLES "Build ELFIO examples" ON)
# Turns this on in order to build tests
option(ELFIO_BUILD_TESTS "Build ELFIO tests" OFF)
# Generate output of compile commands during generation
set(CMAKE_EXPORT_COMPILE_COMMANDS, ON)
endif()
# Read version from header file
set(version_header "elfio/elfio_version.hpp")
file(READ ${version_header} ver)
string(REGEX MATCH "#define ELFIO_VERSION \"([0-9\.]+)\"" _ ${ver})
if(NOT CMAKE_MATCH_1)
message(FATAL_ERROR "Unable to parse version from ${version_header}")
endif()
set(version ${CMAKE_MATCH_1})
# Use configure_file to make configure step depend on elfio_version.hpp
configure_file(${version_header} ${CMAKE_CURRENT_BINARY_DIR}/elfio_version.hpp.copy COPYONLY)
project(elfio VERSION ${version} LANGUAGES C CXX)
include(GNUInstallDirs)
# Create a header only CMake target for elfio
add_library(elfio INTERFACE)
add_library(elfio::elfio ALIAS elfio)
target_include_directories(
elfio
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
# If this is the top level project, add in logic to install elfio
if(IS_TOP_PROJECT)
# Enable C++14 for examples and tests
if(ELFIO_BUILD_EXAMPLES OR ELFIO_BUILD_TESTS)
set(CMAKE_CXX_STANDARD 14)
endif()
if(ELFIO_BUILD_EXAMPLES)
# set (CMAKE_CXX_FLAGS "-Wall")
add_subdirectory(examples)
endif()
if(ELFIO_BUILD_TESTS)
# set (CMAKE_CXX_FLAGS "-Wall")
enable_testing()
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} USES_TERMINAL)
add_subdirectory(tests)
endif()
include(CMakePackageConfigHelpers)
# Create a file that includes the current project version. This will be
# installed with the elfio CMake package.
write_basic_package_version_file(
"${PROJECT_NAME}ConfigVersion.cmake"
VERSION
${PROJECT_VERSION}
COMPATIBILITY
SameMajorVersion)
# Create the default ${PROJECT_NAME}Config.cmake file which will be
# installed and found by calls to `find_package(elfio)`.
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
# Install the previously generated "config" and "version" files
install(
FILES
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
# Install the entire local `elfio` directory to the include directory
install(
DIRECTORY
elfio
DESTINATION
${CMAKE_INSTALL_INCLUDEDIR})
# Create a ${PROJECT_NAME}Targets.cmake file that is referenced by the
# ${PROJECT_NAME}Config.cmake file and includes the target information
# needed to compile/link against all targets exported under the
# ${PROJECT_NAME}_Targets export
install(
EXPORT
${PROJECT_NAME}_Targets
FILE
${PROJECT_NAME}Targets.cmake
NAMESPACE
${PROJECT_NAME}::
DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
# Add the elfio target to the ${PROJECT_NAME}_Targets export
install(
TARGETS
elfio
EXPORT
${PROJECT_NAME}_Targets)
# cmake -B build; cmake --build build; cpack --config build/CPackSourceConfig.cmake
# cmake -B build -D ELFIO_BUILD_EXAMPLES=ON -DELFIO_BUILD_TESTS=ON -G Ninja; cmake --build build; cpack --config build/CPackSourceConfig.cmake
set(_fmt TGZ)
if(WIN32)
set(_fmt ZIP)
endif()
set(CPACK_GENERATOR ${_fmt})
set(CPACK_SOURCE_GENERATOR ${_fmt})
set(CPACK_PACKAGE_VENDOR "ELFIO")
set(CPACK_PACKAGE_CONTACT "Serge Lamikhov-Center")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/package")
set(CPACK_PACKAGE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
string(TOLOWER ${CMAKE_SYSTEM_NAME} _sys)
string(TOLOWER ${PROJECT_NAME} _project_lower)
set(CPACK_PACKAGE_FILE_NAME "${_project_lower}-${_sys}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${_project_lower}-${PROJECT_VERSION}")
set(CPACK_SOURCE_IGNORE_FILES "/.git/;/.github/;/.vscode/;/build;/.clang-format;/.gitignore;/.travis.yml;/doc/images/;/doc/site;/doc/elfio.docx;/examples/sudo_gdb.sh;/tests")
install(FILES ${CPACK_RESOURCE_FILE_README} ${CPACK_RESOURCE_FILE_LICENSE}
DESTINATION share/docs/${PROJECT_NAME})
include(CPack)
endif()

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
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
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "writer", "examples\writer\writer.vcxproj", "{4E5A96DB-F6E9-4EEE-90BE-67B722DA8C84}"
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
{4E5A96DB-F6E9-4EEE-90BE-67B722DA8C84}.Debug|Win32.ActiveCfg = Debug|Win32
{4E5A96DB-F6E9-4EEE-90BE-67B722DA8C84}.Debug|Win32.Build.0 = Debug|Win32
{4E5A96DB-F6E9-4EEE-90BE-67B722DA8C84}.Release|Win32.ActiveCfg = Release|Win32
{4E5A96DB-F6E9-4EEE-90BE-67B722DA8C84}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.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>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</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>
<RunCodeAnalysis>false</RunCodeAnalysis>
</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>..;c:\Developer\boost_1_59_0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<EnablePREfast>false</EnablePREfast>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>
</AdditionalDependencies>
<AdditionalLibraryDirectories>c:\Developer\boost_1_59_0\stage\lib</AdditionalLibraryDirectories>
<Profile>false</Profile>
</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>..;c:\Developer\boost_1_59_0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>
</AdditionalDependencies>
<AdditionalLibraryDirectories>c:\Developer\boost_1_59_0\stage\lib</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="ELFIOTest.cpp">
<PreprocessToFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
</PreprocessToFile>
</ClCompile>
<ClCompile Include="ELFIOTest1.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\elfio\elfio.hpp" />
<ClInclude Include="..\elfio\elfio_dynamic.hpp" />
<ClInclude Include="..\elfio\elfio_header.hpp" />
<ClInclude Include="..\elfio\elfio_note.hpp" />
<ClInclude Include="..\elfio\elfio_relocation.hpp" />
<ClInclude Include="..\elfio\elfio_section.hpp" />
<ClInclude Include="..\elfio\elfio_segment.hpp" />
<ClInclude Include="..\elfio\elfio_strings.hpp" />
<ClInclude Include="..\elfio\elfio_symbols.hpp" />
<ClInclude Include="..\elfio\elfio_utils.hpp" />
<ClInclude Include="..\elfio\elf_types.hpp" />
</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>
<ItemGroup>
<ClInclude Include="..\elfio\elf_types.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\elfio\elfio.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\elfio\elfio_header.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\elfio\elfio_note.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\elfio\elfio_relocation.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\elfio\elfio_section.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\elfio\elfio_segment.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\elfio\elfio_strings.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\elfio\elfio_symbols.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\elfio\elfio_utils.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\elfio\elfio_dynamic.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</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/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( file1.load( file_name1 ), true );
BOOST_REQUIRE_EQUAL( file2.load( file_name2 ), true );
for (int i = 0; i < file1.sections.size(); ++i ) {
BOOST_CHECK_EQUAL( file1.sections[i]->get_address(),
file2.sections[i]->get_address() );
BOOST_CHECK_EQUAL( file1.sections[i]->get_addr_align(),
file2.sections[i]->get_addr_align() );
BOOST_CHECK_EQUAL( file1.sections[i]->get_entry_size(),
file2.sections[i]->get_entry_size() );
BOOST_CHECK_EQUAL( file1.sections[i]->get_flags(),
file2.sections[i]->get_flags() );
BOOST_CHECK_EQUAL( file1.sections[i]->get_index(),
file2.sections[i]->get_index() );
BOOST_CHECK_EQUAL( file1.sections[i]->get_info(),
file2.sections[i]->get_info() );
BOOST_CHECK_EQUAL( file1.sections[i]->get_link(),
file2.sections[i]->get_link() );
BOOST_CHECK_EQUAL( file1.sections[i]->get_name(),
file2.sections[i]->get_name() );
BOOST_CHECK_EQUAL( file1.sections[i]->get_name_string_offset(),
file2.sections[i]->get_name_string_offset() );
BOOST_CHECK_EQUAL( file1.sections[i]->get_size(),
file2.sections[i]->get_size() );
BOOST_CHECK_EQUAL( file1.sections[i]->get_type(),
file2.sections[i]->get_type() );
if ( file1.sections[i]->get_type() == SHT_NULL ||
file1.sections[i]->get_type() == SHT_NOBITS ) {
continue;
}
BOOST_REQUIRE_NE( file1.sections[i]->get_data(), (const char*)0 );
BOOST_REQUIRE_NE( file2.sections[i]->get_data(), (const char*)0 );
std::string pdata1( file1.sections[i]->get_data(),
file1.sections[i]->get_data() +
file1.sections[i]->get_size() );
std::string pdata2( file2.sections[i]->get_data(),
file2.sections[i]->get_data() +
file2.sections[i]->get_size() );
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.begin(), pdata1.end(),
pdata2.begin(), pdata2.end() );
}
}
}
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_REQUIRE_EQUAL( file2.load( file_name2 ), true );
for (int i = 0; i < file1.segments.size(); ++i ) {
BOOST_CHECK_EQUAL( file1.segments[i]->get_align(),
file2.segments[i]->get_align() );
BOOST_CHECK_EQUAL( file1.segments[i]->get_file_size(),
file2.segments[i]->get_file_size() );
BOOST_CHECK_EQUAL( file1.segments[i]->get_memory_size(),
file2.segments[i]->get_memory_size() );
BOOST_CHECK_EQUAL( file1.segments[i]->get_type(),
file2.segments[i]->get_type() );
// skip data comparisons of the program header and of empty segments
if( file1.segments[i]->get_type() == PT_PHDR || !file1.segments[i]->get_file_size() )
continue;
BOOST_REQUIRE_NE( file1.segments[i]->get_data(), (const char*)0 );
BOOST_REQUIRE_NE( file2.segments[i]->get_data(), (const char*)0 );
std::string pdata1( file1.segments[i]->get_data(),
file1.segments[i]->get_data() +
file1.segments[i]->get_file_size() );
std::string pdata2( file2.segments[i]->get_data(),
file2.segments[i]->get_data() +
file2.segments[i]->get_file_size() );
// truncate the data if the header and the segment table is
// part of the segment
Elf64_Off afterPHDR = file1.get_segments_offset() +
file1.get_segment_entry_size() * file1.segments.size();
if( file1.segments[i]->get_offset() < afterPHDR ) {
pdata1 = pdata1.substr( (unsigned int)afterPHDR );
pdata2 = pdata2.substr( (unsigned int)afterPHDR );
}
BOOST_CHECK_EQUAL_COLLECTIONS( pdata1.begin(), pdata1.end(),
pdata2.begin(), pdata2.end() );
}
}
////////////////////////////////////////////////////////////////////////////////
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( section_header_address_update )
{
elfio reader;
write_exe_i386( false, true, 0x08048100 );
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(), 0x08048100 );
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, 0x08048100 );
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() );
}
////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( elf_exe_copy_64 )
{
checkExeAreEqual( "../elf_examples/64bitLOAD.elf",
"../elf_examples/64bitLOAD_copy.elf" );
checkExeAreEqual( "../elf_examples/asm64",
"../elf_examples/asm64_copy" );
checkExeAreEqual( "../elf_examples/hello_64",
"../elf_examples/hello_64_copy" );
// The last segment (GNU_RELRO) is bigger than necessary.
// I don't see why but it contains a few bits of the .got.plt section.
// -> load, store, compare cycle fails
// checkExeAreEqual( "../elf_examples/main",
// "../elf_examples/main_copy" );
// checkExeAreEqual( "../elf_examples/ls",
// "../elf_examples/ls_copy" );
}
////////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE( elf_exe_copy_32 )
{
checkExeAreEqual( "../elf_examples/asm",
"../elf_examples/asm_copy" );
checkExeAreEqual( "../elf_examples/arm_v7m_test_debug.elf",
"../elf_examples/arm_v7m_test_debug_copy.elf" );
checkExeAreEqual( "../elf_examples/arm_v7m_test_release.elf",
"../elf_examples/arm_v7m_test_release_copy.elf" );
checkExeAreEqual( "../elf_examples/hello_32",
"../elf_examples/hello_32_copy" );
checkExeAreEqual( "../elf_examples/hello_arm",
"../elf_examples/hello_arm_copy" );
checkExeAreEqual( "../elf_examples/hello_arm_stripped",
"../elf_examples/hello_arm_stripped_copy" );
checkExeAreEqual( "../elf_examples/read_write_arm_elf32_input",
"../elf_examples/read_write_arm_elf32_input_copy" );
checkExeAreEqual( "../elf_examples/test_ppc",
"../elf_examples/test_ppc_copy" );
}
CXX=g++
CPPFLAGS=-c -Wall -std=c++0x -I..
LDLIBS=-lboost_unit_test_framework
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)
ELFIO is a header-only C++ library - installation does not require any
(pre)compilation step. Just copy 'elfio' folder into standard include directory.
For example:
cp -R elfio /usr/include
Alternatively, it is possible to modify compiler's include search path -
'-I<dir>' option in GCC; '/I<dir>' in MSVC.
Makefile(s) that come with the distribution package are provided for
example files compilation only.
To compile the examples, use the commands below:
./configure
make
MIT License
Copyright (C) 2001-2011 by Serge Lamikhov-Center
Copyright (C) 2001-present 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
......
SUBDIRS = examples
nobase_include_HEADERS = elfio/elf_types.hpp elfio/elfio_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/elfio_dump.hpp
EXTRA_DIST = doc/site/elfio.pdf
dist-hook:
mv $(distdir)/doc/site/elfio.pdf $(distdir)/doc
rm -Rf $(distdir)/doc/site
This diff is collapsed.