mirror of
https://github.com/QuasarApp/LIEF.git
synced 2025-04-26 04:14:33 +00:00
First public release
This commit is contained in:
commit
306a191a03
89
.appveyor.yml
Normal file
89
.appveyor.yml
Normal file
@ -0,0 +1,89 @@
|
||||
version: 0.4.{build}
|
||||
image: Visual Studio 2015
|
||||
clone_folder: c:\projects\lief
|
||||
|
||||
configuration: Release
|
||||
|
||||
clone_depth: 5
|
||||
|
||||
platform:
|
||||
- x86
|
||||
- x64
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
# Python 2.7
|
||||
- PYTHON_VERSION: "2.7"
|
||||
PYTHON32_PATH: "C:\\Python27"
|
||||
PYTHON32_INCLUDE: "C:\\Python27\\include"
|
||||
PYTHON32_BINARY: "C:\\Python27\\python.exe"
|
||||
PYTHON32_LIBRARY: "C:\\Python27\\libs\\python27.lib"
|
||||
PYTHON64_PATH: "C:\\Python27-x64"
|
||||
PYTHON64_INCLUDE: "C:\\Python27-x64\\include"
|
||||
PYTHON64_BINARY: "C:\\Python27-x64\\python.exe"
|
||||
PYTHON64_LIBRARY: "C:\\Python27-x64\\libs\\python27.lib"
|
||||
|
||||
|
||||
# Python 3.5
|
||||
- PYTHON_VERSION: "3.5"
|
||||
PYTHON32_PATH: "C:\\Python35"
|
||||
PYTHON32_INCLUDE: "C:\\Python35\\include"
|
||||
PYTHON32_BINARY: "C:\\Python35\\python.exe"
|
||||
PYTHON32_LIBRARY: "C:\\Python35\\libs\\python35.lib"
|
||||
PYTHON64_PATH: "C:\\Python35-x64"
|
||||
PYTHON64_INCLUDE: "C:\\Python35-x64\\include"
|
||||
PYTHON64_BINARY: "C:\\Python35-x64\\python.exe"
|
||||
PYTHON64_LIBRARY: "C:\\Python35-x64\\libs\\python35.lib"
|
||||
|
||||
|
||||
# Python 3.6
|
||||
- PYTHON_VERSION: "3.6"
|
||||
PYTHON32_PATH: "C:\\Python36"
|
||||
PYTHON32_INCLUDE: "C:\\Python36\\include"
|
||||
PYTHON32_BINARY: "C:\\Python36\\python.exe"
|
||||
PYTHON32_LIBRARY: "C:\\Python36\\libs\\python36.lib"
|
||||
PYTHON64_PATH: "C:\\Python36-x64"
|
||||
PYTHON64_INCLUDE: "C:\\Python36-x64\\include"
|
||||
PYTHON64_BINARY: "C:\\Python36-x64\\python.exe"
|
||||
PYTHON64_LIBRARY: "C:\\Python36-x64\\libs\\python36.lib"
|
||||
|
||||
matrix:
|
||||
fast_finish: true # set this flag to immediately finish build once one of the jobs fails.
|
||||
allow_failures:
|
||||
- platform: x86
|
||||
configuration: Release
|
||||
- platform: x64
|
||||
configuration: Release
|
||||
|
||||
install:
|
||||
- ps: if ($env:PLATFORM -eq "x64") { $env:CMAKE_ARCH = "x64" }
|
||||
|
||||
- ps: if ($env:PLATFORM -eq "x64") { $env:PYTHON_PATH = $env:PYTHON64_PATH }
|
||||
- ps: if ($env:PLATFORM -eq "x64") { $env:PYTHON_INCLUDE = $env:PYTHON64_INCLUDE }
|
||||
- ps: if ($env:PLATFORM -eq "x64") { $env:PYTHON_BINARY = $env:PYTHON64_BINARY }
|
||||
- ps: if ($env:PLATFORM -eq "x64") { $env:PYTHON_LIBRARY = $env:PYTHON64_LIBRARY }
|
||||
|
||||
- ps: if ($env:PLATFORM -eq "x86") { $env:PYTHON_PATH = $env:PYTHON32_PATH }
|
||||
- ps: if ($env:PLATFORM -eq "x86") { $env:PYTHON_INCLUDE = $env:PYTHON32_INCLUDE }
|
||||
- ps: if ($env:PLATFORM -eq "x86") { $env:PYTHON_BINARY = $env:PYTHON32_BINARY }
|
||||
- ps: if ($env:PLATFORM -eq "x86") { $env:PYTHON_LIBRARY = $env:PYTHON32_LIBRARY }
|
||||
|
||||
- set PATH=%PYTHON_PATH%;%PATH%
|
||||
|
||||
build_script:
|
||||
- cmake -A "%CMAKE_ARCH%" -DLIEF_TESTS=on -DLIEF_PYTHON_API=on -DPYTHON_VERSION=%PYTHON_VERSION% -DPYTHON_INCLUDE_DIR=%PYTHON_INCLUDE% -DPYTHON_EXECUTABLE=%PYTHON_BINARY% -DPYTHON_LIBRARY=%PYTHON_LIBRARY%
|
||||
- set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
|
||||
- cmake --build . --config Release --target ALL_BUILD -- /v:m /logger:%MSBuildLogger%
|
||||
|
||||
test_script:
|
||||
- cmake --build . --config Release --target RUN_TESTS -- /v:m /logger:%MSBuildLogger%
|
||||
|
||||
after_test:
|
||||
- cd api\python
|
||||
- python.exe .\setup.py sdist --formats=zip && exit 0 # Ignore warnings...
|
||||
- ps: gci dist\*.zip | % { rename-item –path $_.Fullname –Newname ( "windows_" + $env:PLATFORM + "_" + $_.basename + "_py" + $env:PYTHON_VERSION + $_.extension) }
|
||||
|
||||
#artifacts:
|
||||
# - path: 'api\python\dist\*.zip'
|
||||
|
||||
|
10
.dockerignore
Normal file
10
.dockerignore
Normal file
@ -0,0 +1,10 @@
|
||||
*
|
||||
!src
|
||||
!doc
|
||||
!tests
|
||||
!include
|
||||
!examples
|
||||
!api
|
||||
!CMakeLists.txt
|
||||
!CMakeModules
|
||||
!package
|
156
.travis.yml
Normal file
156
.travis.yml
Normal file
@ -0,0 +1,156 @@
|
||||
language: cpp
|
||||
|
||||
|
||||
matrix:
|
||||
include:
|
||||
# Linux gcc 5.0 - Python 2.7
|
||||
- os: linux
|
||||
dist: trusty
|
||||
compiler: gcc
|
||||
addons:
|
||||
apt:
|
||||
sources: ['ubuntu-toolchain-r-test']
|
||||
packages: ['g++-5', 'ccache', 'libpython2.7']
|
||||
env: [ CXX_COMPILER=g++-5, C_COMPILER=gcc-5, PYTHON_VERSION=2.7, PYTHON_INCLUDE_DIR=/usr/include/python2.7, PYTHON_LIBRARY=/usr/lib/libpython2.7.so, PYTHON_BINARY=/usr/bin/python2.7 ]
|
||||
|
||||
|
||||
## Linux gcc 5.0 - Python 3.5
|
||||
- os: linux
|
||||
dist: trusty
|
||||
compiler: gcc
|
||||
addons:
|
||||
apt:
|
||||
sources: ['ubuntu-toolchain-r-test', 'deadsnakes']
|
||||
packages: ['g++-5', 'gcc-5', 'ccache', 'python3.5-dev']
|
||||
env: [ CXX_COMPILER=g++-5, C_COMPILER=gcc-5, PYTHON_VERSION=3.5, PYTHON_INCLUDE_DIR=/usr/include/python3.5m, PYTHON_LIBRARY=/usr/lib/libpython3.5m.so, PYTHON_BINARY=/usr/bin/python3.5]
|
||||
|
||||
|
||||
# Linux gcc 6 - Python 3.6
|
||||
- os: linux
|
||||
dist: trusty
|
||||
compiler: gcc
|
||||
addons:
|
||||
apt:
|
||||
sources: ['ubuntu-toolchain-r-test', 'deadsnakes']
|
||||
packages: ['g++-6', 'gcc-6', 'ccache', 'python3.6-dev', 'python-sphinx']
|
||||
env: [ CXX_COMPILER=g++-6, C_COMPILER=gcc-6, PYTHON_VERSION=3.6, PYTHON_INCLUDE_DIR=/usr/include/python3.6m, PYTHON_LIBRARY=/usr/lib/libpython3.6m.so, PYTHON_BINARY=/usr/bin/python3.6, LIEF_DOC=OFF]
|
||||
|
||||
# OSX 10.11 - xcode 7.3 - Python 2.7
|
||||
- os: osx
|
||||
osx_image: xcode7.3
|
||||
compiler: clang
|
||||
env: [CXX_COMPILER=clang++, C_COMPILER=clang, PYTHON_VERSION=2.7]
|
||||
|
||||
# OSX 10.12 - xcode 8.2 - Python 3.5
|
||||
- os: osx
|
||||
osx_image: xcode8.2
|
||||
compiler: clang
|
||||
env: [ CXX_COMPILER=clang++, C_COMPILER=clang, PYTHON_VERSION=3.5]
|
||||
|
||||
|
||||
## OSX 10.12 - xcode 8.2 - Python 3.6
|
||||
- os: osx
|
||||
osx_image: xcode8.2
|
||||
compiler: clang
|
||||
env: [CXX_COMPILER=clang++, C_COMPILER=clang, PYTHON_VERSION=3.6]
|
||||
|
||||
#branches:
|
||||
# only:
|
||||
# - master
|
||||
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
|
||||
sudo: required
|
||||
|
||||
cache:
|
||||
- apt
|
||||
- ccache
|
||||
|
||||
before_install:
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get update -q; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install python-setuptools; fi
|
||||
- export CC="$C_COMPILER"
|
||||
- export CXX="$CXX_COMPILER"
|
||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then export PREFIX="/usr/local"; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew update; fi
|
||||
|
||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then export PYTHON_CONFIGURE_OPTS="--enable-shared"; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then pyenv root; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then pyenv install --list ;fi
|
||||
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then pyenv install 2.7.10; fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.5" ]]; then pyenv install 3.5.0; fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.6" ]]; then pyenv install 3.6.0b4; fi
|
||||
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then export PYTHON_INCLUDE_DIR=$(pyenv root)/versions/2.7.10/include/python2.7 ;fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then export PYTHON_LIBRARY=$(pyenv root)/versions/2.7.10/lib/libpython2.7.dylib ;fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/2.7.10/bin/python2.7 ;fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then $PYTHON_BINARY -m pip install --upgrade pip ;fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then $PYTHON_BINARY -m pip install --upgrade setuptools ;fi
|
||||
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.5" ]]; then export PYTHON_INCLUDE_DIR=$(pyenv root)/versions/3.5.0/include/python3.5m ;fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.5" ]]; then export PYTHON_LIBRARY=$(pyenv root)/versions/3.5.0/lib/libpython3.dylib ;fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.5" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/3.5.0/bin/python3.5 ;fi
|
||||
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.6" ]]; then export PYTHON_INCLUDE_DIR=$(pyenv root)/versions/3.6.0b4/include/python3.6m ;fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.6" ]]; then export PYTHON_LIBRARY=$(pyenv root)/versions/3.6.0b4/lib/libpython3.dylib ;fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.6" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/3.6.0b4/bin/python3.6 ;fi
|
||||
|
||||
install:
|
||||
- if [ "$GCOV" == "ON" ]; then sudo ln -sf /usr/bin/gcov-5 /usr/bin/gcov; fi
|
||||
- if [ "$GCOV" == "ON" ]; then wget http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.13.orig.tar.gz; fi
|
||||
- if [ "$GCOV" == "ON" ]; then tar xf lcov_1.13.orig.tar.gz; fi
|
||||
- if [ "$GCOV" == "ON" ]; then sudo make -C lcov-1.13/ install; fi
|
||||
|
||||
- if [[ "$LIEF_DOC" == "ON" ]]; then wget --no-check-certificate ftp://ftp.stack.nl/pub/users/dimitri/doxygen-1.8.10.linux.bin.tar.gz; fi
|
||||
- if [[ "$LIEF_DOC" == "ON" ]]; then tar -xzf doxygen-1.8.10.linux.bin.tar.gz; fi
|
||||
- if [[ "$LIEF_DOC" == "ON" ]]; then cd doxygen-1.8.10; fi
|
||||
- if [[ "$LIEF_DOC" == "ON" ]]; then ./configure --prefix /usr; fi
|
||||
- if [[ "$LIEF_DOC" == "ON" ]]; then sudo make install; fi
|
||||
- if [[ "$LIEF_DOC" == "ON" ]]; then cd ..; fi
|
||||
|
||||
# Setup CMake 3.1 for Linux
|
||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then wget --no-check-certificate http://cmake.org/files/v3.7/cmake-3.7.2-Linux-x86_64.tar.gz ;fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then tar -xzf cmake-3.7.2-Linux-x86_64.tar.gz ;fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export PATH=$PWD/cmake-3.7.2-Linux-x86_64/bin:$PATH ;fi
|
||||
|
||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py ;fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo $PYTHON_BINARY ./get-pip.py ;fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "linux" && "$LIEF_DOC" == "ON" ]]; then sudo $PYTHON_BINARY -m pip install breathe ;fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "linux" && "$LIEF_DOC" == "ON" ]]; then sudo $PYTHON_BINARY -m pip install sphinx_rtd_theme ;fi
|
||||
|
||||
# Prepare build
|
||||
- mkdir build
|
||||
- cd build
|
||||
|
||||
|
||||
script:
|
||||
- cmake -DCMAKE_C_COMPILER=$C_COMPILER -DCMAKE_CXX_COMPILER=$CXX_COMPILER -DPYTHON_VERSION=$PYTHON_VERSION -DPYTHON_INCLUDE_DIR=$PYTHON_INCLUDE_DIR -DPYTHON_LIBRARY=$PYTHON_LIBRARY -DPYTHON_EXECUTABLE=$PYTHON_BINARY -DLIEF_TESTS=on -DLIEF_DOC=${LIEF_DOC:-OFF} ..
|
||||
- make -j2
|
||||
- sudo make check-lief
|
||||
|
||||
after_success:
|
||||
- make package
|
||||
- sudo $PYTHON_BINARY -m pip install setuptools
|
||||
- sudo $PYTHON_BINARY -m pip install --upgrade setuptools
|
||||
- cd api/python
|
||||
- $PYTHON_BINARY setup.py sdist
|
||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then bash -c 'cd dist && for f in *.tar.gz; do mv $f "linux_${f%.tar.gz}_py${PYTHON_VERSION}.tar.gz"; done' ;fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then bash -c 'cd dist && for f in *.tar.gz; do mv $f "osx_${f%.tar.gz}_py$PYTHON_VERSION.tar.gz"; done' ;fi
|
||||
|
||||
|
||||
deploy:
|
||||
provider: releases
|
||||
api-key:
|
||||
- secure: "E+rseEB8MX81WvdM8HS/mOwGNS1kSMzaitOqVl0KA09Ir1I/gtyzli3p5M3rVRws7uYsEWqOAVEGrBeH3LhuX4D5aS5i5+IKKmlHLMhd+XT3Nmg+VsWgiHm4PVpdKLegN78CVcZs3NsbUYvEvEzmPGiNqHjUp0+EvuE1jsSXuXdDaYK3aLn2YRkQpFrMOZcHzItsbD/XXqQoupA99SdsNLVLi2UbCFh2qULi2Y/yOGGoK1PYJxuLd1H4Z992MFqcCbHFHGWRH6OTA/oPcDjluPSChj+YPJ4Logl+NpaLEH5FCbKFdpIi7b6ay5cyQ4m4BxGGmTn/qEPmp/3ouzAQY+yGKONpdMmAb8nKLcs2F+jCNLx/hCem+52yElFF4iTcCP6Xca/Ntj+D447GwZOWOlSGpBygPePVzXmj3PnI/KnRhRNHqLntkNe98Qz7QC9Sla+0e1TJJuegsTANJ0DM2iHtlCOxqRK8WskqeTkrxX4zYK3qTyouG8VxJg23qeRk5I1tNtiaZqsEfiqFVw25DWdLz6B3nDarCMS6hQhEzkQptXLNtPDWNmtvr/CFGjpZFJxACd1tgPGSARhPdhAfcRZUUyPPfptKHp5oxqTGrW8UKzOEhF+cwIg3BCMWsAGzrpuRTXKSfwMeqrVddXzgyhhyD3ywFkXwc1/wLIIEfAE="
|
||||
file_glob: true
|
||||
file:
|
||||
- ${TRAVIS_BUILD_DIR}/build/api/python/dist/*.tar.gz
|
||||
- ${TRAVIS_BUILD_DIR}/build/*.tar.gz
|
||||
skip_cleanup: true
|
||||
on:
|
||||
#branch: master
|
||||
tags: true
|
||||
|
16
Acknowledgements
Normal file
16
Acknowledgements
Normal file
@ -0,0 +1,16 @@
|
||||
Acknowledgements
|
||||
----------------
|
||||
|
||||
LIEF makes use of the following open source projects:
|
||||
|
||||
- mbedTLS - https://tls.mbed.org/
|
||||
- pybind11 - https://github.com/pybind/pybind11
|
||||
- json - https://nlohmann.github.io/json/
|
||||
- rang - https://agauniyal.github.io/rang/
|
||||
- easyloggingpp - https://github.com/muflihun/easyloggingpp
|
||||
- Catch - https://github.com/philsquared/Catch
|
||||
- yamlcpp - https://github.com/jbeder/yaml-cpp
|
||||
- filesystem - https://github.com/wjakob/filesystem
|
||||
- utf8-cpp - https://sourceforge.net/projects/utfcpp/
|
||||
|
||||
The logo is designed by Freepik
|
552
CMakeLists.txt
Normal file
552
CMakeLists.txt
Normal file
@ -0,0 +1,552 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
|
||||
# Modules
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/")
|
||||
include(CheckCXXCompilerFlag)
|
||||
include(CheckCCompilerFlag)
|
||||
include(Findcppcheck)
|
||||
include(CppcheckTargets)
|
||||
include(ExternalProject)
|
||||
|
||||
# LIEF version
|
||||
set(LIEF_VERSION_MAJOR 0)
|
||||
set(LIEF_VERSION_MINOR 6)
|
||||
set(LIEF_VERSION_PATCH 0)
|
||||
|
||||
project(LIEF VERSION ${LIEF_VERSION_MAJOR}.${LIEF_VERSION_MINOR}.${LIEF_VERSION_PATCH})
|
||||
message(STATUS "${PROJECT_NAME} ${PROJECT_VERSION}")
|
||||
|
||||
# options
|
||||
option(LIEF_TESTS "Enable tests" OFF)
|
||||
option(LIEF_DOC "Enable documentation" OFF)
|
||||
option(LIEF_PYTHON_API "Enable Python API" ON)
|
||||
option(LIEF_INSTALL_PYTHON "Install Python bindings" OFF)
|
||||
option(LIEF_C_API "C API" ON)
|
||||
option(LIEF_EXAMPLES "Build LIEF C++ examples" ON)
|
||||
option(LIEF_FORCE32 "Force build LIEF 32 bits version" OFF)
|
||||
option(LIEF_COVERAGE "Perform code coverage" OFF)
|
||||
option(LIEF_USE_CCACHE "Use ccache to speed up compilation" ON)
|
||||
option(LIEF_EXTRA_WARNINGS "Enable extra warning from the compiler" OFF)
|
||||
option(LIEF_LOGGING "Enable logging" ON)
|
||||
|
||||
option(LIEF_ELF "Build LIEF with ELF module" ON)
|
||||
option(LIEF_PE "Build LIEF with PE module" ON)
|
||||
option(LIEF_MACHO "Build LIEF with MachO module" ON)
|
||||
|
||||
# CCACHE
|
||||
# ======
|
||||
find_program(CCACHE_FOUND ccache)
|
||||
message(STATUS "ccache: ${LIEF_USE_CCACHE}")
|
||||
if(CCACHE_FOUND AND LIEF_USE_CCACHE)
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
|
||||
endif()
|
||||
|
||||
|
||||
# Dependencies
|
||||
# ============
|
||||
find_package(Git REQUIRED)
|
||||
|
||||
# Json
|
||||
# ----
|
||||
set(LIBJSON_GIT_URL "https://github.com/nlohmann/json.git" CACHE STRING "URL to the JSON lib repo")
|
||||
ExternalProject_Add(libjson
|
||||
GIT_REPOSITORY ${LIBJSON_GIT_URL}
|
||||
GIT_TAG v2.0.8
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND "")
|
||||
|
||||
ExternalProject_get_property(libjson SOURCE_DIR)
|
||||
set(LIBJSON_SOURCE_DIR ${SOURCE_DIR})
|
||||
|
||||
|
||||
# Rang
|
||||
# ----
|
||||
set(LIBRANG_GIT_URL "https://github.com/agauniyal/rang.git" CACHE STRING "URL to the Rang lib repo")
|
||||
ExternalProject_Add(rang_cpp_color
|
||||
GIT_REPOSITORY ${LIBRANG_GIT_URL}
|
||||
GIT_TAG master
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND "")
|
||||
|
||||
ExternalProject_get_property(rang_cpp_color SOURCE_DIR)
|
||||
set(LIBRANG_SOURCE_DIR ${SOURCE_DIR})
|
||||
|
||||
|
||||
# mbed TLS
|
||||
# --------
|
||||
set(MBED_TLS_TAG mbedtls-2.4.0)
|
||||
set(MBED_TLS_GIT_URL "https://github.com/ARMmbed/mbedtls.git" CACHE STRING "URL to MbedTLS")
|
||||
set(MBED_TLS_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/mbed_tls)
|
||||
|
||||
|
||||
ExternalProject_Add(mbed_tls
|
||||
PREFIX ${MBED_TLS_PREFIX}
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
GIT_REPOSITORY ${MBED_TLS_GIT_URL}
|
||||
GIT_TAG ${MBED_TLS_TAG}
|
||||
UPDATE_COMMAND "" # repetitive update are a pain
|
||||
BUILD_BYPRODUCTS ${MBED_TLS_PREFIX})
|
||||
|
||||
ExternalProject_get_property(mbed_tls SOURCE_DIR)
|
||||
set(MBEDTLS_SOURCE_DIR ${SOURCE_DIR})
|
||||
set(MBEDTLS_INCLUDE_DIRS "${MBEDTLS_SOURCE_DIR}/include")
|
||||
|
||||
set(mbedtls_src_crypto
|
||||
${MBEDTLS_SOURCE_DIR}/library/aes.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/aesni.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/arc4.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/asn1parse.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/asn1write.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/base64.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/bignum.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/blowfish.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/camellia.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/ccm.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/cipher.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/cipher_wrap.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/cmac.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/ctr_drbg.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/des.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/dhm.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/ecdh.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/ecdsa.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/ecjpake.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/ecp.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/ecp_curves.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/entropy.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/entropy_poll.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/error.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/gcm.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/havege.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/hmac_drbg.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/md.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/md2.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/md4.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/md5.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/md_wrap.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/memory_buffer_alloc.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/oid.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/padlock.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/pem.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/pk.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/pk_wrap.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/pkcs12.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/pkcs5.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/pkparse.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/pkwrite.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/platform.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/ripemd160.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/rsa.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/sha1.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/sha256.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/sha512.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/threading.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/timing.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/version.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/version_features.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/xtea.c
|
||||
)
|
||||
|
||||
set(mbedtls_src_x509
|
||||
${MBEDTLS_SOURCE_DIR}/library/certs.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/pkcs11.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/x509.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/x509_create.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/x509_crl.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/x509_crt.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/x509_csr.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/x509write_crt.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/x509write_csr.c
|
||||
)
|
||||
|
||||
set(mbedtls_src_tls
|
||||
${MBEDTLS_SOURCE_DIR}/library/debug.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/net_sockets.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/ssl_cache.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/ssl_ciphersuites.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/ssl_cli.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/ssl_cookie.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/ssl_srv.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/ssl_ticket.c
|
||||
${MBEDTLS_SOURCE_DIR}/library/ssl_tls.c
|
||||
)
|
||||
|
||||
|
||||
# easyloggingpp
|
||||
# -------------
|
||||
set(ELG_GIT_URL "https://github.com/easylogging/easyloggingpp.git" CACHE STRING "URL to the easyloggingpp lib repo")
|
||||
ExternalProject_Add(easyloggingpp
|
||||
GIT_REPOSITORY ${ELG_GIT_URL}
|
||||
#GIT_TAG "v9.83"
|
||||
GIT_TAG "master"
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND "")
|
||||
|
||||
ExternalProject_get_property(easyloggingpp SOURCE_DIR)
|
||||
set(ELG_SOURCE_DIR ${SOURCE_DIR}/src)
|
||||
|
||||
|
||||
|
||||
# LIEF Source definition
|
||||
# ======================
|
||||
set_source_files_properties(${mbedtls_src_crypto} PROPERTIES GENERATED TRUE)
|
||||
set_source_files_properties(${mbedtls_src_x509} PROPERTIES GENERATED TRUE)
|
||||
set_source_files_properties(${mbedtls_src_tls} PROPERTIES GENERATED TRUE)
|
||||
set_source_files_properties(${ELG_SOURCE_DIR}/easylogging++.cc PROPERTIES GENERATED TRUE)
|
||||
|
||||
set(LIEF_SRC
|
||||
${ELG_SOURCE_DIR}/easylogging++.cc
|
||||
${mbedtls_src_crypto}
|
||||
${mbedtls_src_x509}
|
||||
${mbedtls_src_tls}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/logging.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/exception.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/iostream.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/utils.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Visitable.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Visitor.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/BinaryStream/BinaryStream.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/BinaryStream/VectorStream.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/visitors/elf_json.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/visitors/json.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/visitors/hash.cpp)
|
||||
|
||||
set(LIEF_ABSTRACT_SRC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Abstract/Binary.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Abstract/Symbol.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Abstract/EnumToString.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Abstract/Header.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Abstract/Section.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Abstract/Parser.cpp)
|
||||
|
||||
|
||||
|
||||
set(LIBLIEF_SOURCE_FILES
|
||||
${LIEF_SRC}
|
||||
${LIEF_ABSTRACT_SRC})
|
||||
|
||||
add_library(LIB_LIEF_STATIC STATIC ${LIBLIEF_SOURCE_FILES}) # Static one
|
||||
add_library(LIB_LIEF_SHARED SHARED ${LIBLIEF_SOURCE_FILES}) # Shared one
|
||||
|
||||
|
||||
if (LIEF_ELF)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/src/ELF/CMakeLists.txt)
|
||||
endif()
|
||||
|
||||
if (LIEF_PE)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/src/PE/CMakeLists.txt)
|
||||
endif()
|
||||
|
||||
if (LIEF_MACHO)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/src/MachO/CMakeLists.txt)
|
||||
endif()
|
||||
|
||||
|
||||
# LIEF includes
|
||||
# =============
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/version.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/version.h
|
||||
)
|
||||
|
||||
set (LIEF_PUBLIC_INCLUDE_DIR
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/
|
||||
${CMAKE_CURRENT_BINARY_DIR}/include/
|
||||
${LIBJSON_SOURCE_DIR}/src/)
|
||||
|
||||
set(LIEF_PRIVATE_INCLUDE_DIR
|
||||
${LIEF_PUBLIC_INCLUDE_DIR}
|
||||
${LIBRANG_SOURCE_DIR}/include
|
||||
${ELG_SOURCE_DIR}/
|
||||
${MBEDTLS_INCLUDE_DIRS})
|
||||
|
||||
# Library definition
|
||||
# ==================
|
||||
add_definitions(-DELPP_NO_DEFAULT_LOG_FILE)
|
||||
if (LIEF_ELF)
|
||||
add_definitions(-DLIEF_ELF_MODULE)
|
||||
endif()
|
||||
|
||||
if (LIEF_PE)
|
||||
add_definitions(-DLIEF_PE_MODULE)
|
||||
endif()
|
||||
|
||||
if (LIEF_MACHO)
|
||||
add_definitions(-DLIEF_MACHO_MODULE)
|
||||
endif()
|
||||
|
||||
target_include_directories(LIB_LIEF_STATIC
|
||||
PUBLIC ${LIEF_PUBLIC_INCLUDE_DIR}
|
||||
PRIVATE ${LIEF_PRIVATE_INCLUDE_DIR})
|
||||
|
||||
target_include_directories(LIB_LIEF_SHARED
|
||||
PUBLIC ${LIEF_PUBLIC_INCLUDE_DIR}
|
||||
PRIVATE ${LIEF_PRIVATE_INCLUDE_DIR})
|
||||
|
||||
|
||||
add_dependencies(LIB_LIEF_STATIC libjson)
|
||||
add_dependencies(LIB_LIEF_SHARED libjson)
|
||||
|
||||
add_dependencies(LIB_LIEF_STATIC easyloggingpp)
|
||||
add_dependencies(LIB_LIEF_SHARED easyloggingpp)
|
||||
|
||||
add_dependencies(LIB_LIEF_STATIC rang_cpp_color)
|
||||
add_dependencies(LIB_LIEF_SHARED rang_cpp_color)
|
||||
|
||||
add_dependencies(LIB_LIEF_STATIC mbed_tls)
|
||||
add_dependencies(LIB_LIEF_SHARED mbed_tls)
|
||||
|
||||
# Flags definition
|
||||
# ----------------
|
||||
set_property(TARGET LIB_LIEF_STATIC LIB_LIEF_SHARED PROPERTY CXX_STANDARD 11)
|
||||
set_property(TARGET LIB_LIEF_STATIC LIB_LIEF_SHARED PROPERTY CXX_STANDARD_REQUIRED ON)
|
||||
set_property(TARGET LIB_LIEF_STATIC LIB_LIEF_SHARED PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
#set_property(TARGET LIB_LIEF_STATIC LIB_LIEF_SHARED PROPERTY CXX_VISIBILITY_PRESET hidden)
|
||||
|
||||
|
||||
CHECK_CXX_COMPILER_FLAG("-Weverything" HAS_WARN_EVERY)
|
||||
|
||||
if (LIEF_EXTRA_WARNINGS AND HAS_WARN_EVERY)
|
||||
set(EXTRA_FLAGS
|
||||
-Weverything
|
||||
-Wno-c++98-compat
|
||||
-Wno-c++98-compat-pedantic
|
||||
-Wno-padded
|
||||
-Wno-unused-exception-parameter
|
||||
-Wno-weak-vtables
|
||||
-Wno-exit-time-destructors
|
||||
-Wno-global-constructors
|
||||
-Wno-documentation
|
||||
-Wno-documentation-unknown-command
|
||||
-Wno-sign-conversion)
|
||||
|
||||
target_compile_options(LIB_LIEF_STATIC PRIVATE ${EXTRA_FLAGS})
|
||||
target_compile_options(LIB_LIEF_SHARED PRIVATE ${EXTRA_FLAGS})
|
||||
endif()
|
||||
|
||||
if (MSVC)
|
||||
add_definitions(-DNOMINMAX)
|
||||
target_compile_options(LIB_LIEF_STATIC PUBLIC /FIiso646.h)
|
||||
target_compile_options(LIB_LIEF_SHARED PUBLIC /FIiso646.h)
|
||||
|
||||
target_compile_options(LIB_LIEF_STATIC PUBLIC /MT)
|
||||
|
||||
endif()
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
if (UNIX)
|
||||
if (LIEF_FORCE32)
|
||||
target_compile_options(LIB_LIEF_STATIC PRIVATE -m32)
|
||||
target_compile_options(LIB_LIEF_SHARED PRIVATE -m32)
|
||||
|
||||
set_property(TARGET LIB_LIEF_STATIC LIB_LIEF_SHARED PROPERTY LINK_FLAGS -m32)
|
||||
endif()
|
||||
|
||||
set(LIB_LIEF_COMPILE_FLAGS
|
||||
-Wall -Wextra -Wpedantic
|
||||
-Wno-expansion-to-defined
|
||||
-fno-stack-protector
|
||||
-fomit-frame-pointer -fno-strict-aliasing
|
||||
-fexceptions
|
||||
-fvisibility=hidden)
|
||||
target_compile_options(LIB_LIEF_STATIC PRIVATE ${LIB_LIEF_COMPILE_FLAGS})
|
||||
target_compile_options(LIB_LIEF_SHARED PRIVATE ${LIB_LIEF_COMPILE_FLAGS})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
if(CROSS_COMPILE_WINDOWS)
|
||||
target_link_libraries(LIB_LIEF_STATIC -static -static-libgcc -static-libstdc++)
|
||||
endif()
|
||||
|
||||
if(LIEF_COVERAGE)
|
||||
target_compile_options(LIB_LIEF_STATIC PRIVATE -g -O0 --coverage -fprofile-arcs -ftest-coverage)
|
||||
target_compile_options(LIB_LIEF_SHARED PRIVATE -g -O0 --coverage -fprofile-arcs -ftest-coverage)
|
||||
target_link_libraries(LIB_LIEF_STATIC gcov)
|
||||
target_link_libraries(LIB_LIEF_SHARED gcov)
|
||||
endif()
|
||||
|
||||
find_package(cppcheck)
|
||||
|
||||
set_target_properties(
|
||||
LIB_LIEF_STATIC
|
||||
PROPERTIES OUTPUT_NAME LIEF
|
||||
CLEAN_DIRECT_OUTPUT 1)
|
||||
|
||||
set_target_properties(
|
||||
LIB_LIEF_SHARED
|
||||
PROPERTIES OUTPUT_NAME LIEF
|
||||
CLEAN_DIRECT_OUTPUT 1)
|
||||
|
||||
|
||||
|
||||
# Set a default build type if none was specified
|
||||
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
||||
message(STATUS "Setting build type to 'Release' as none was specified.")
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
|
||||
# Set the possible values of build type for cmake-gui
|
||||
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
|
||||
"MinSizeRel" "RelWithDebInfo")
|
||||
endif()
|
||||
|
||||
message(STATUS "Configuration Types: ${CMAKE_CONFIGURATION_TYPES}")
|
||||
message(STATUS "Build Types: ${CMAKE_BUILD_TYPE}")
|
||||
|
||||
|
||||
if(APPLE)
|
||||
set_target_properties(LIB_LIEF_STATIC PROPERTIES MACOSX_RPATH ".")
|
||||
set_target_properties(LIB_LIEF_SHARED PROPERTIES MACOSX_RPATH ".")
|
||||
endif()
|
||||
|
||||
|
||||
# API
|
||||
# ===
|
||||
|
||||
# Python
|
||||
# ------
|
||||
|
||||
if (LIEF_PYTHON_API)
|
||||
if(WIN32)
|
||||
set(PYTHON_BUILD_LIEF_DIRECTORY "${CMAKE_BINARY_DIR}/api/python/Release")
|
||||
else()
|
||||
set(PYTHON_BUILD_LIEF_DIRECTORY "${CMAKE_BINARY_DIR}/api/python")
|
||||
endif()
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/api/python)
|
||||
endif()
|
||||
|
||||
# C API
|
||||
# -----
|
||||
if(LIEF_C_API)
|
||||
|
||||
# ELF
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/api/c/include/LIEF/ELF/enums.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/ELF/enums.h
|
||||
@ONLY
|
||||
)
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/api/c/include/LIEF/ELF/structures.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/ELF/structures.h
|
||||
@ONLY
|
||||
)
|
||||
|
||||
# PE
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/api/c/include/LIEF/PE/enums.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/PE/enums.h
|
||||
@ONLY
|
||||
)
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/api/c/include/LIEF/PE/structures.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/PE/structures.h
|
||||
@ONLY
|
||||
)
|
||||
|
||||
|
||||
# MachO
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/api/c/include/LIEF/MachO/enums.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/MachO/enums.h
|
||||
@ONLY
|
||||
)
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/api/c/include/LIEF/MachO/structures.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/MachO/structures.h
|
||||
@ONLY
|
||||
)
|
||||
|
||||
target_include_directories(LIB_LIEF_STATIC
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include
|
||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include)
|
||||
|
||||
target_include_directories(LIB_LIEF_SHARED
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include
|
||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include)
|
||||
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/api/c/CMakeLists.txt)
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
# Examples
|
||||
# ========
|
||||
if(LIEF_EXAMPLES)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples/cpp)
|
||||
|
||||
if (LIEF_C_API)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples/c)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Tests
|
||||
# =====
|
||||
if(LIEF_TESTS)
|
||||
enable_testing()
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
||||
add_custom_target(check-lief COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)
|
||||
endif()
|
||||
|
||||
# CPP Check
|
||||
# =========
|
||||
set(CPPCHECK_TEMPLATE_ARG "[{severity}][{id}] {message} {callstack} \(On {file}:{line}\)")
|
||||
set(_cppcheck_args "--enable=warning,performance,portability,information")
|
||||
#add_cppcheck(LIB_LIEF_STATIC FORCE)
|
||||
|
||||
|
||||
# Documentation
|
||||
# =============
|
||||
if (LIEF_DOC)
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/doc)
|
||||
endif()
|
||||
|
||||
|
||||
# Install Prefix
|
||||
# ==============
|
||||
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND UNIX)
|
||||
if (UNIX AND NOT APPLE)
|
||||
set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Install path prefix prepended on to install directories." FORCE)
|
||||
elseif (APPLE)
|
||||
set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "" FORCE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Installation
|
||||
# ============
|
||||
|
||||
install(TARGETS LIB_LIEF_STATIC
|
||||
ARCHIVE
|
||||
DESTINATION lib
|
||||
LIBRARY
|
||||
DESTINATION lib
|
||||
COMPONENT libraries)
|
||||
|
||||
install(TARGETS LIB_LIEF_SHARED
|
||||
ARCHIVE
|
||||
DESTINATION lib
|
||||
LIBRARY
|
||||
DESTINATION lib
|
||||
COMPONENT libraries)
|
||||
|
||||
install(
|
||||
DIRECTORY ${LIEF_PUBLIC_INCLUDE_DIR}
|
||||
DESTINATION include
|
||||
COMPONENT headers
|
||||
FILES_MATCHING REGEX "(.*).(hpp|h|def)$")
|
||||
|
||||
# Package
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/package)
|
||||
|
||||
|
||||
|
||||
|
||||
|
197
CMakeModules/CodeCoverage.cmake
Normal file
197
CMakeModules/CodeCoverage.cmake
Normal file
@ -0,0 +1,197 @@
|
||||
# Copyright (c) 2012 - 2015, Lars Bilke
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this
|
||||
# list of conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software without
|
||||
# specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
#
|
||||
#
|
||||
# 2012-01-31, Lars Bilke
|
||||
# - Enable Code Coverage
|
||||
#
|
||||
# 2013-09-17, Joakim Söderberg
|
||||
# - Added support for Clang.
|
||||
# - Some additional usage instructions.
|
||||
#
|
||||
# USAGE:
|
||||
|
||||
# 0. (Mac only) If you use Xcode 5.1 make sure to patch geninfo as described here:
|
||||
# http://stackoverflow.com/a/22404544/80480
|
||||
#
|
||||
# 1. Copy this file into your cmake modules path.
|
||||
#
|
||||
# 2. Add the following line to your CMakeLists.txt:
|
||||
# INCLUDE(CodeCoverage)
|
||||
#
|
||||
# 3. Set compiler flags to turn off optimization and enable coverage:
|
||||
# SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
|
||||
# SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
|
||||
#
|
||||
# 3. Use the function SETUP_TARGET_FOR_COVERAGE to create a custom make target
|
||||
# which runs your test executable and produces a lcov code coverage report:
|
||||
# Example:
|
||||
# SETUP_TARGET_FOR_COVERAGE(
|
||||
# my_coverage_target # Name for custom target.
|
||||
# test_driver # Name of the test driver executable that runs the tests.
|
||||
# # NOTE! This should always have a ZERO as exit code
|
||||
# # otherwise the coverage generation will not complete.
|
||||
# coverage # Name of output directory.
|
||||
# )
|
||||
#
|
||||
# 4. Build a Debug build:
|
||||
# cmake -DCMAKE_BUILD_TYPE=Debug ..
|
||||
# make
|
||||
# make my_coverage_target
|
||||
#
|
||||
#
|
||||
|
||||
# Check prereqs
|
||||
FIND_PROGRAM( GCOV_PATH gcov )
|
||||
FIND_PROGRAM( LCOV_PATH lcov )
|
||||
FIND_PROGRAM( GENHTML_PATH genhtml )
|
||||
FIND_PROGRAM( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/tests)
|
||||
|
||||
IF(NOT GCOV_PATH)
|
||||
MESSAGE(FATAL_ERROR "gcov not found! Aborting...")
|
||||
ENDIF() # NOT GCOV_PATH
|
||||
|
||||
IF("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
|
||||
IF("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 3)
|
||||
MESSAGE(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...")
|
||||
ENDIF()
|
||||
ELSEIF(NOT CMAKE_COMPILER_IS_GNUCXX)
|
||||
MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...")
|
||||
ENDIF() # CHECK VALID COMPILER
|
||||
|
||||
SET(CMAKE_CXX_FLAGS_COVERAGE
|
||||
"-g -O0 --coverage -fprofile-arcs -ftest-coverage"
|
||||
CACHE STRING "Flags used by the C++ compiler during coverage builds."
|
||||
FORCE )
|
||||
SET(CMAKE_C_FLAGS_COVERAGE
|
||||
"-g -O0 --coverage -fprofile-arcs -ftest-coverage"
|
||||
CACHE STRING "Flags used by the C compiler during coverage builds."
|
||||
FORCE )
|
||||
SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE
|
||||
""
|
||||
CACHE STRING "Flags used for linking binaries during coverage builds."
|
||||
FORCE )
|
||||
SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
|
||||
""
|
||||
CACHE STRING "Flags used by the shared libraries linker during coverage builds."
|
||||
FORCE )
|
||||
MARK_AS_ADVANCED(
|
||||
CMAKE_CXX_FLAGS_COVERAGE
|
||||
CMAKE_C_FLAGS_COVERAGE
|
||||
CMAKE_EXE_LINKER_FLAGS_COVERAGE
|
||||
CMAKE_SHARED_LINKER_FLAGS_COVERAGE )
|
||||
|
||||
IF ( NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "Coverage"))
|
||||
MESSAGE( WARNING "Code coverage results with an optimized (non-Debug) build may be misleading" )
|
||||
ENDIF() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug"
|
||||
|
||||
|
||||
# Param _targetname The name of new the custom make target
|
||||
# Param _testrunner The name of the target which runs the tests.
|
||||
# MUST return ZERO always, even on errors.
|
||||
# If not, no coverage report will be created!
|
||||
# Param _outputname lcov output is generated as _outputname.info
|
||||
# HTML report is generated in _outputname/index.html
|
||||
# Optional fourth parameter is passed as arguments to _testrunner
|
||||
# Pass them in list form, e.g.: "-j;2" for -j 2
|
||||
FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname)
|
||||
|
||||
IF(NOT LCOV_PATH)
|
||||
MESSAGE(FATAL_ERROR "lcov not found! Aborting...")
|
||||
ENDIF() # NOT LCOV_PATH
|
||||
|
||||
IF(NOT GENHTML_PATH)
|
||||
MESSAGE(FATAL_ERROR "genhtml not found! Aborting...")
|
||||
ENDIF() # NOT GENHTML_PATH
|
||||
|
||||
SET(coverage_info "${CMAKE_BINARY_DIR}/${_outputname}.info")
|
||||
SET(coverage_cleaned "${coverage_info}.cleaned")
|
||||
|
||||
SEPARATE_ARGUMENTS(test_command UNIX_COMMAND "${_testrunner}")
|
||||
|
||||
# Setup target
|
||||
ADD_CUSTOM_TARGET(${_targetname}
|
||||
|
||||
# Cleanup lcov
|
||||
${LCOV_PATH} --directory . --zerocounters
|
||||
|
||||
# Run tests
|
||||
COMMAND ${test_command} ${ARGV3}
|
||||
|
||||
# Capturing lcov counters and generating report
|
||||
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${coverage_info}
|
||||
COMMAND ${LCOV_PATH} --remove ${coverage_info} 'tests/*' '/usr/*' --output-file ${coverage_cleaned}
|
||||
COMMAND ${GENHTML_PATH} -o ${_outputname} ${coverage_cleaned}
|
||||
COMMAND ${CMAKE_COMMAND} -E remove ${coverage_info} ${coverage_cleaned}
|
||||
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
|
||||
)
|
||||
|
||||
# Show info where to find the report
|
||||
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
|
||||
COMMAND ;
|
||||
COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report."
|
||||
)
|
||||
|
||||
ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE
|
||||
|
||||
# Param _targetname The name of new the custom make target
|
||||
# Param _testrunner The name of the target which runs the tests
|
||||
# Param _outputname cobertura output is generated as _outputname.xml
|
||||
# Optional fourth parameter is passed as arguments to _testrunner
|
||||
# Pass them in list form, e.g.: "-j;2" for -j 2
|
||||
FUNCTION(SETUP_TARGET_FOR_COVERAGE_COBERTURA _targetname _testrunner _outputname)
|
||||
|
||||
IF(NOT PYTHON_EXECUTABLE)
|
||||
MESSAGE(FATAL_ERROR "Python not found! Aborting...")
|
||||
ENDIF() # NOT PYTHON_EXECUTABLE
|
||||
|
||||
IF(NOT GCOVR_PATH)
|
||||
MESSAGE(FATAL_ERROR "gcovr not found! Aborting...")
|
||||
ENDIF() # NOT GCOVR_PATH
|
||||
|
||||
ADD_CUSTOM_TARGET(${_targetname}
|
||||
|
||||
# Run tests
|
||||
${_testrunner} ${ARGV3}
|
||||
|
||||
# Running gcovr
|
||||
COMMAND ${GCOVR_PATH} -x -r ${CMAKE_SOURCE_DIR} -e '${CMAKE_SOURCE_DIR}/tests/' -o ${_outputname}.xml
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
COMMENT "Running gcovr to produce Cobertura code coverage report."
|
||||
)
|
||||
|
||||
# Show info where to find the report
|
||||
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
|
||||
COMMAND ;
|
||||
COMMENT "Cobertura code coverage report saved in ${_outputname}.xml."
|
||||
)
|
||||
|
||||
ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE_COBERTURA
|
231
CMakeModules/CppcheckTargets.cmake
Normal file
231
CMakeModules/CppcheckTargets.cmake
Normal file
@ -0,0 +1,231 @@
|
||||
# - Run cppcheck on c++ source files as a custom target and a test
|
||||
#
|
||||
# include(CppcheckTargets)
|
||||
# add_cppcheck(<target-name> [UNUSED_FUNCTIONS] [STYLE] [POSSIBLE_ERROR] [FORCE] [FAIL_ON_WARNINGS]) -
|
||||
# Create a target to check a target's sources with cppcheck and the indicated options
|
||||
# add_cppcheck_sources(<target-name> [UNUSED_FUNCTIONS] [STYLE] [POSSIBLE_ERROR] [FORCE] [FAIL_ON_WARNINGS]) -
|
||||
# Create a target to check standalone sources with cppcheck and the indicated options
|
||||
#
|
||||
# Requires these CMake modules:
|
||||
# Findcppcheck
|
||||
#
|
||||
# Requires CMake 2.6 or newer (uses the 'function' command)
|
||||
#
|
||||
# Original Author:
|
||||
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright Iowa State University 2009-2010.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
if(__add_cppcheck)
|
||||
return()
|
||||
endif()
|
||||
set(__add_cppcheck YES)
|
||||
|
||||
if(NOT CPPCHECK_FOUND)
|
||||
find_package(cppcheck QUIET)
|
||||
endif()
|
||||
|
||||
if(CPPCHECK_FOUND)
|
||||
if(NOT TARGET all_cppcheck)
|
||||
add_custom_target(all_cppcheck)
|
||||
set_target_properties(all_cppcheck PROPERTIES EXCLUDE_FROM_ALL TRUE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
function(add_cppcheck_sources _targetname)
|
||||
if(CPPCHECK_FOUND)
|
||||
set(_cppcheck_args)
|
||||
set(_input ${ARGN})
|
||||
list(FIND _input UNUSED_FUNCTIONS _unused_func)
|
||||
if("${_unused_func}" GREATER "-1")
|
||||
list(APPEND _cppcheck_args ${CPPCHECK_UNUSEDFUNC_ARG})
|
||||
list(REMOVE_AT _input ${_unused_func})
|
||||
endif()
|
||||
|
||||
list(FIND _input STYLE _style)
|
||||
if("${_style}" GREATER "-1")
|
||||
list(APPEND _cppcheck_args ${CPPCHECK_STYLE_ARG})
|
||||
list(REMOVE_AT _input ${_style})
|
||||
endif()
|
||||
|
||||
list(FIND _input POSSIBLE_ERROR _poss_err)
|
||||
if("${_poss_err}" GREATER "-1")
|
||||
list(APPEND _cppcheck_args ${CPPCHECK_POSSIBLEERROR_ARG})
|
||||
list(REMOVE_AT _input ${_poss_err})
|
||||
endif()
|
||||
|
||||
list(FIND _input FORCE _force)
|
||||
if("${_force}" GREATER "-1")
|
||||
list(APPEND _cppcheck_args "--force")
|
||||
list(REMOVE_AT _input ${_force})
|
||||
endif()
|
||||
|
||||
list(FIND _input FAIL_ON_WARNINGS _fail_on_warn)
|
||||
if("${_fail_on_warn}" GREATER "-1")
|
||||
list(APPEND
|
||||
CPPCHECK_FAIL_REGULAR_EXPRESSION
|
||||
${CPPCHECK_WARN_REGULAR_EXPRESSION})
|
||||
list(REMOVE_AT _input ${_fail_on_warn})
|
||||
endif()
|
||||
|
||||
set(_files)
|
||||
foreach(_source ${_input})
|
||||
get_source_file_property(_cppcheck_loc "${_source}" LOCATION)
|
||||
if(_cppcheck_loc)
|
||||
# This file has a source file property, carry on.
|
||||
get_source_file_property(_cppcheck_lang "${_source}" LANGUAGE)
|
||||
if("${_cppcheck_lang}" MATCHES "CXX")
|
||||
list(APPEND _files "${_cppcheck_loc}")
|
||||
endif()
|
||||
else()
|
||||
# This file doesn't have source file properties - figure it out.
|
||||
get_filename_component(_cppcheck_loc "${_source}" ABSOLUTE)
|
||||
if(EXISTS "${_cppcheck_loc}")
|
||||
list(APPEND _files "${_cppcheck_loc}")
|
||||
else()
|
||||
message(FATAL_ERROR
|
||||
"Adding CPPCHECK for file target ${_targetname}: "
|
||||
"File ${_source} does not exist or needs a corrected path location "
|
||||
"since we think its absolute path is ${_cppcheck_loc}")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if("1.${CMAKE_VERSION}" VERSION_LESS "1.2.8.0")
|
||||
# Older than CMake 2.8.0
|
||||
add_test(${_targetname}_cppcheck_test
|
||||
"${CPPCHECK_EXECUTABLE}"
|
||||
${CPPCHECK_TEMPLATE_ARG}
|
||||
${_cppcheck_args} "--inline-suppr"
|
||||
${_files})
|
||||
else()
|
||||
# CMake 2.8.0 and newer
|
||||
add_test(NAME
|
||||
${_targetname}_cppcheck_test
|
||||
COMMAND
|
||||
"${CPPCHECK_EXECUTABLE}"
|
||||
${CPPCHECK_TEMPLATE_ARG}
|
||||
${_cppcheck_args} "--inline-suppr"
|
||||
${_files})
|
||||
endif()
|
||||
|
||||
set_tests_properties(${_targetname}_cppcheck_test
|
||||
PROPERTIES
|
||||
FAIL_REGULAR_EXPRESSION
|
||||
"${CPPCHECK_FAIL_REGULAR_EXPRESSION}")
|
||||
|
||||
add_custom_command(TARGET
|
||||
all_cppcheck
|
||||
PRE_BUILD
|
||||
COMMAND
|
||||
${CPPCHECK_EXECUTABLE}
|
||||
${CPPCHECK_QUIET_ARG}
|
||||
${CPPCHECK_TEMPLATE_ARG}
|
||||
${_cppcheck_args} "--inline-suppr"
|
||||
${_files}
|
||||
WORKING_DIRECTORY
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
COMMENT
|
||||
"${_targetname}_cppcheck: Running cppcheck on target ${_targetname}..."
|
||||
VERBATIM)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(add_cppcheck _name)
|
||||
if(NOT TARGET ${_name})
|
||||
message(FATAL_ERROR
|
||||
"add_cppcheck given a target name that does not exist: '${_name}' !")
|
||||
endif()
|
||||
if(CPPCHECK_FOUND)
|
||||
set(_cppcheck_args CACHE STRING "${_cppcheck_args} ")
|
||||
#set(_cppcheck_args "${_cppcheck_args} ")
|
||||
list(FIND ARGN UNUSED_FUNCTIONS _unused_func)
|
||||
if("${_unused_func}" GREATER "-1")
|
||||
list(APPEND _cppcheck_args ${CPPCHECK_UNUSEDFUNC_ARG})
|
||||
endif()
|
||||
|
||||
list(FIND ARGN STYLE _style)
|
||||
if("${_style}" GREATER "-1")
|
||||
list(APPEND _cppcheck_args ${CPPCHECK_STYLE_ARG})
|
||||
endif()
|
||||
|
||||
list(FIND ARGN POSSIBLE_ERROR _poss_err)
|
||||
if("${_poss_err}" GREATER "-1")
|
||||
list(APPEND _cppcheck_args ${CPPCHECK_POSSIBLEERROR_ARG})
|
||||
endif()
|
||||
|
||||
list(FIND ARGN FORCE _force)
|
||||
if("${_force}" GREATER "-1")
|
||||
list(APPEND _cppcheck_args "--force")
|
||||
endif()
|
||||
|
||||
list(FIND _input FAIL_ON_WARNINGS _fail_on_warn)
|
||||
if("${_fail_on_warn}" GREATER "-1")
|
||||
list(APPEND
|
||||
CPPCHECK_FAIL_REGULAR_EXPRESSION
|
||||
${CPPCHECK_WARN_REGULAR_EXPRESSION})
|
||||
list(REMOVE_AT _input ${_unused_func})
|
||||
endif()
|
||||
|
||||
get_target_property(_cppcheck_includes "${_name}" INCLUDE_DIRECTORIES)
|
||||
set(_includes)
|
||||
foreach(_include ${_cppcheck_includes})
|
||||
list(APPEND _includes "-I${_include}")
|
||||
endforeach()
|
||||
|
||||
get_target_property(_cppcheck_sources "${_name}" SOURCES)
|
||||
set(_files)
|
||||
foreach(_source ${_cppcheck_sources})
|
||||
get_source_file_property(_cppcheck_lang "${_source}" LANGUAGE)
|
||||
get_source_file_property(_cppcheck_loc "${_source}" LOCATION)
|
||||
if("${_cppcheck_lang}" MATCHES "CXX")
|
||||
list(APPEND _files "${_cppcheck_loc}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if("1.${CMAKE_VERSION}" VERSION_LESS "1.2.8.0")
|
||||
# Older than CMake 2.8.0
|
||||
add_test(${_name}_cppcheck_test
|
||||
"${CPPCHECK_EXECUTABLE}"
|
||||
${CPPCHECK_TEMPLATE_ARG}
|
||||
${_cppcheck_args} "--inline-suppr"
|
||||
${_files})
|
||||
else()
|
||||
# CMake 2.8.0 and newer
|
||||
add_test(NAME
|
||||
${_name}_cppcheck_test
|
||||
COMMAND
|
||||
"${CPPCHECK_EXECUTABLE}"
|
||||
${CPPCHECK_TEMPLATE_ARG}
|
||||
${_cppcheck_args} "--inline-suppr"
|
||||
${_files})
|
||||
endif()
|
||||
|
||||
set_tests_properties(${_name}_cppcheck_test
|
||||
PROPERTIES
|
||||
FAIL_REGULAR_EXPRESSION
|
||||
"${CPPCHECK_FAIL_REGULAR_EXPRESSION}")
|
||||
MESSAGE(STATUS "CPPCHECKargs: ${_cppcheck_args}")
|
||||
add_custom_command(TARGET
|
||||
all_cppcheck
|
||||
PRE_BUILD
|
||||
COMMAND
|
||||
${CPPCHECK_EXECUTABLE}
|
||||
${CPPCHECK_QUIET_ARG}
|
||||
${CPPCHECK_TEMPLATE_ARG}
|
||||
${_cppcheck_args} "--inline-suppr"
|
||||
${_includes}
|
||||
${_files}
|
||||
WORKING_DIRECTORY
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
COMMENT
|
||||
"${_name}_cppcheck: Running cppcheck on target ${_name}..."
|
||||
VERBATIM)
|
||||
endif()
|
||||
|
||||
endfunction()
|
98
CMakeModules/FindYamlCpp.cmake
Normal file
98
CMakeModules/FindYamlCpp.cmake
Normal file
@ -0,0 +1,98 @@
|
||||
# Locate yaml-cpp
|
||||
#
|
||||
# This module defines
|
||||
# YAMLCPP_FOUND, if false, do not try to link to yaml-cpp
|
||||
# YAMLCPP_LIBNAME, name of yaml library
|
||||
# YAMLCPP_LIBRARY, where to find yaml-cpp
|
||||
# YAMLCPP_LIBRARY_RELEASE, where to find Release or RelWithDebInfo yaml-cpp
|
||||
# YAMLCPP_LIBRARY_DEBUG, where to find Debug yaml-cpp
|
||||
# YAMLCPP_INCLUDE_DIR, where to find yaml.h
|
||||
# YAMLCPP_LIBRARY_DIR, the directories to find YAMLCPP_LIBRARY
|
||||
#
|
||||
# By default, the dynamic libraries of yaml-cpp will be found. To find the static ones instead,
|
||||
# you must set the YAMLCPP_USE_STATIC_LIBS variable to TRUE before calling find_package(YamlCpp ...)
|
||||
|
||||
# attempt to find static library first if this is set
|
||||
if(YAMLCPP_USE_STATIC_LIBS)
|
||||
set(YAMLCPP_STATIC libyaml-cpp.a)
|
||||
set(YAMLCPP_STATIC_DEBUG libyaml-cpp-dbg.a)
|
||||
endif()
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") ### Set Yaml libary name for Windows
|
||||
set(YAMLCPP_LIBNAME "libyaml-cppmd" CACHE STRING "Name of YAML library")
|
||||
set(YAMLCPP_LIBNAME optimized ${YAMLCPP_LIBNAME} debug ${YAMLCPP_LIBNAME}d)
|
||||
else() ### Set Yaml libary name for Unix, Linux, OS X, etc
|
||||
set(YAMLCPP_LIBNAME "yaml-cpp" CACHE STRING "Name of YAML library")
|
||||
endif()
|
||||
|
||||
# find the yaml-cpp include directory
|
||||
find_path(YAMLCPP_INCLUDE_DIR
|
||||
NAMES yaml-cpp/yaml.h
|
||||
PATH_SUFFIXES include
|
||||
PATHS
|
||||
${PROJECT_SOURCE_DIR}/dependencies/yaml-cpp-0.5.1/include
|
||||
~/Library/Frameworks/yaml-cpp/include/
|
||||
/Library/Frameworks/yaml-cpp/include/
|
||||
/usr/local/include/
|
||||
/usr/include/
|
||||
/sw/yaml-cpp/ # Fink
|
||||
/opt/local/yaml-cpp/ # DarwinPorts
|
||||
/opt/csw/yaml-cpp/ # Blastwave
|
||||
/opt/yaml-cpp/)
|
||||
|
||||
# find the release yaml-cpp library
|
||||
find_library(YAMLCPP_LIBRARY_RELEASE
|
||||
NAMES ${YAMLCPP_STATIC} yaml-cpp libyaml-cppmd.lib
|
||||
PATH_SUFFIXES lib64 lib Release RelWithDebInfo
|
||||
PATHS
|
||||
${PROJECT_SOURCE_DIR}/dependencies/yaml-cpp-0.5.1/
|
||||
${PROJECT_SOURCE_DIR}/dependencies/yaml-cpp-0.5.1/build
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw
|
||||
/opt/local
|
||||
/opt/csw
|
||||
/opt)
|
||||
|
||||
# find the debug yaml-cpp library
|
||||
find_library(YAMLCPP_LIBRARY_DEBUG
|
||||
NAMES ${YAMLCPP_STATIC_DEBUG} yaml-cpp-dbg libyaml-cppmdd.lib
|
||||
PATH_SUFFIXES lib64 lib Debug
|
||||
PATHS
|
||||
${PROJECT_SOURCE_DIR}/dependencies/yaml-cpp-0.5.1/
|
||||
${PROJECT_SOURCE_DIR}/dependencies/yaml-cpp-0.5.1/build
|
||||
~/Library/Frameworks
|
||||
/Library/Frameworks
|
||||
/usr/local
|
||||
/usr
|
||||
/sw
|
||||
/opt/local
|
||||
/opt/csw
|
||||
/opt)
|
||||
|
||||
# set library vars
|
||||
set(YAMLCPP_LIBRARY ${YAMLCPP_LIBRARY_RELEASE})
|
||||
if(CMAKE_BUILD_TYPE MATCHES Debug AND EXISTS ${YAMLCPP_LIBRARY_DEBUG})
|
||||
set(YAMLCPP_LIBRARY ${YAMLCPP_LIBRARY_DEBUG})
|
||||
endif()
|
||||
|
||||
get_filename_component(YAMLCPP_LIBRARY_RELEASE_DIR ${YAMLCPP_LIBRARY_RELEASE} PATH)
|
||||
get_filename_component(YAMLCPP_LIBRARY_DEBUG_DIR ${YAMLCPP_LIBRARY_DEBUG} PATH)
|
||||
set(YAMLCPP_LIBRARY_DIR ${YAMLCPP_LIBRARY_RELEASE_DIR} ${YAMLCPP_LIBRARY_DEBUG_DIR})
|
||||
|
||||
# handle the QUIETLY and REQUIRED arguments and set YAMLCPP_FOUND to TRUE if all listed variables are TRUE
|
||||
include(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(YamlCpp DEFAULT_MSG
|
||||
YAMLCPP_INCLUDE_DIR
|
||||
YAMLCPP_LIBRARY
|
||||
YAMLCPP_LIBRARY_DIR)
|
||||
mark_as_advanced(
|
||||
YAMLCPP_INCLUDE_DIR
|
||||
YAMLCPP_LIBRARY_DIR
|
||||
YAMLCPP_LIBRARY
|
||||
YAMLCPP_LIBRARY_RELEASE
|
||||
YAMLCPP_LIBRARY_RELEASE_DIR
|
||||
YAMLCPP_LIBRARY_DEBUG
|
||||
YAMLCPP_LIBRARY_DEBUG_DIR)
|
167
CMakeModules/Findcppcheck.cmake
Normal file
167
CMakeModules/Findcppcheck.cmake
Normal file
@ -0,0 +1,167 @@
|
||||
# - try to find cppcheck tool
|
||||
#
|
||||
# Cache Variables:
|
||||
# CPPCHECK_EXECUTABLE
|
||||
#
|
||||
# Non-cache variables you might use in your CMakeLists.txt:
|
||||
# CPPCHECK_FOUND
|
||||
# CPPCHECK_POSSIBLEERROR_ARG
|
||||
# CPPCHECK_UNUSEDFUNC_ARG
|
||||
# CPPCHECK_STYLE_ARG
|
||||
# CPPCHECK_QUIET_ARG
|
||||
# CPPCHECK_INCLUDEPATH_ARG
|
||||
# CPPCHECK_FAIL_REGULAR_EXPRESSION
|
||||
# CPPCHECK_WARN_REGULAR_EXPRESSION
|
||||
# CPPCHECK_MARK_AS_ADVANCED - whether to mark our vars as advanced even
|
||||
# if we don't find this program.
|
||||
#
|
||||
# Requires these CMake modules:
|
||||
# FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
|
||||
#
|
||||
# Original Author:
|
||||
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright Iowa State University 2009-2010.
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
file(TO_CMAKE_PATH "${CPPCHECK_ROOT_DIR}" CPPCHECK_ROOT_DIR)
|
||||
set(CPPCHECK_ROOT_DIR
|
||||
"${CPPCHECK_ROOT_DIR}"
|
||||
CACHE
|
||||
PATH
|
||||
"Path to search for cppcheck")
|
||||
|
||||
# cppcheck app bundles on Mac OS X are GUI, we want command line only
|
||||
set(_oldappbundlesetting ${CMAKE_FIND_APPBUNDLE})
|
||||
set(CMAKE_FIND_APPBUNDLE NEVER)
|
||||
|
||||
if(CPPCHECK_EXECUTABLE AND NOT EXISTS "${CPPCHECK_EXECUTABLE}")
|
||||
set(CPPCHECK_EXECUTABLE "notfound" CACHE PATH FORCE "")
|
||||
endif()
|
||||
|
||||
# If we have a custom path, look there first.
|
||||
if(CPPCHECK_ROOT_DIR)
|
||||
find_program(CPPCHECK_EXECUTABLE
|
||||
NAMES
|
||||
cppcheck
|
||||
cli
|
||||
PATHS
|
||||
"${CPPCHECK_ROOT_DIR}"
|
||||
PATH_SUFFIXES
|
||||
cli
|
||||
NO_DEFAULT_PATH)
|
||||
endif()
|
||||
|
||||
find_program(CPPCHECK_EXECUTABLE NAMES cppcheck)
|
||||
|
||||
# Restore original setting for appbundle finding
|
||||
set(CMAKE_FIND_APPBUNDLE ${_oldappbundlesetting})
|
||||
|
||||
# Find out where our test file is
|
||||
get_filename_component(_cppcheckmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
|
||||
set(_cppcheckdummyfile "${_cppcheckmoddir}/Findcppcheck.cpp")
|
||||
if(NOT EXISTS "${_cppcheckdummyfile}")
|
||||
message(FATAL_ERROR
|
||||
"Missing file ${_cppcheckdummyfile} - should be alongside Findcppcheck.cmake, can be found at https://github.com/rpavlik/cmake-modules")
|
||||
endif()
|
||||
|
||||
function(_cppcheck_test_arg _resultvar _arg)
|
||||
if(NOT CPPCHECK_EXECUTABLE)
|
||||
set(${_resultvar} NO)
|
||||
return()
|
||||
endif()
|
||||
execute_process(COMMAND
|
||||
"${CPPCHECK_EXECUTABLE}"
|
||||
"${_arg}"
|
||||
"--quiet"
|
||||
"${_cppcheckdummyfile}"
|
||||
RESULT_VARIABLE
|
||||
_cppcheck_result
|
||||
OUTPUT_QUIET
|
||||
ERROR_QUIET)
|
||||
if("${_cppcheck_result}" EQUAL 0)
|
||||
set(${_resultvar} YES PARENT_SCOPE)
|
||||
else()
|
||||
set(${_resultvar} NO PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(_cppcheck_set_arg_var _argvar _arg)
|
||||
if("${${_argvar}}" STREQUAL "")
|
||||
_cppcheck_test_arg(_cppcheck_arg "${_arg}")
|
||||
if(_cppcheck_arg)
|
||||
set(${_argvar} "${_arg}" PARENT_SCOPE)
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
if(CPPCHECK_EXECUTABLE)
|
||||
|
||||
# Check for the two types of command line arguments by just trying them
|
||||
_cppcheck_set_arg_var(CPPCHECK_STYLE_ARG "--enable=style")
|
||||
_cppcheck_set_arg_var(CPPCHECK_STYLE_ARG "--style")
|
||||
if("${CPPCHECK_STYLE_ARG}" STREQUAL "--enable=style")
|
||||
|
||||
_cppcheck_set_arg_var(CPPCHECK_UNUSEDFUNC_ARG
|
||||
"--enable=unusedFunction")
|
||||
_cppcheck_set_arg_var(CPPCHECK_INFORMATION_ARG "--enable=information")
|
||||
_cppcheck_set_arg_var(CPPCHECK_MISSINGINCLUDE_ARG
|
||||
"--enable=missingInclude")
|
||||
_cppcheck_set_arg_var(CPPCHECK_POSIX_ARG "--enable=posix")
|
||||
_cppcheck_set_arg_var(CPPCHECK_POSSIBLEERROR_ARG
|
||||
"--enable=possibleError")
|
||||
_cppcheck_set_arg_var(CPPCHECK_POSSIBLEERROR_ARG "--enable=all")
|
||||
|
||||
if(MSVC)
|
||||
set(CPPCHECK_TEMPLATE_ARG --template vs)
|
||||
set(CPPCHECK_FAIL_REGULAR_EXPRESSION "[(]error[)]")
|
||||
set(CPPCHECK_WARN_REGULAR_EXPRESSION "[(]style[)]")
|
||||
elseif(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CPPCHECK_TEMPLATE_ARG --template gcc)
|
||||
set(CPPCHECK_FAIL_REGULAR_EXPRESSION " error: ")
|
||||
set(CPPCHECK_WARN_REGULAR_EXPRESSION " style: ")
|
||||
else()
|
||||
set(CPPCHECK_TEMPLATE_ARG --template gcc)
|
||||
set(CPPCHECK_FAIL_REGULAR_EXPRESSION " error: ")
|
||||
set(CPPCHECK_WARN_REGULAR_EXPRESSION " style: ")
|
||||
endif()
|
||||
elseif("${CPPCHECK_STYLE_ARG}" STREQUAL "--style")
|
||||
# Old arguments
|
||||
_cppcheck_set_arg_var(CPPCHECK_UNUSEDFUNC_ARG "--unused-functions")
|
||||
_cppcheck_set_arg_var(CPPCHECK_POSSIBLEERROR_ARG "--all")
|
||||
set(CPPCHECK_FAIL_REGULAR_EXPRESSION "error:")
|
||||
set(CPPCHECK_WARN_REGULAR_EXPRESSION "[(]style[)]")
|
||||
else()
|
||||
# No idea - some other issue must be getting in the way
|
||||
message(STATUS
|
||||
"WARNING: Can't detect whether CPPCHECK wants new or old-style arguments!")
|
||||
endif()
|
||||
|
||||
set(CPPCHECK_QUIET_ARG "--quiet")
|
||||
set(CPPCHECK_INCLUDEPATH_ARG "-I")
|
||||
|
||||
endif()
|
||||
|
||||
set(CPPCHECK_ALL
|
||||
"${CPPCHECK_EXECUTABLE} ${CPPCHECK_POSSIBLEERROR_ARG} ${CPPCHECK_UNUSEDFUNC_ARG} ${CPPCHECK_STYLE_ARG} ${CPPCHECK_QUIET_ARG} ${CPPCHECK_INCLUDEPATH_ARG} some/include/path")
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(cppcheck
|
||||
DEFAULT_MSG
|
||||
CPPCHECK_ALL
|
||||
CPPCHECK_EXECUTABLE
|
||||
CPPCHECK_POSSIBLEERROR_ARG
|
||||
CPPCHECK_UNUSEDFUNC_ARG
|
||||
CPPCHECK_STYLE_ARG
|
||||
CPPCHECK_INCLUDEPATH_ARG
|
||||
CPPCHECK_QUIET_ARG)
|
||||
|
||||
if(CPPCHECK_FOUND OR CPPCHECK_MARK_AS_ADVANCED)
|
||||
mark_as_advanced(CPPCHECK_ROOT_DIR)
|
||||
endif()
|
||||
|
||||
mark_as_advanced(CPPCHECK_EXECUTABLE)
|
16
CMakeModules/Findcppcheck.cpp
Normal file
16
CMakeModules/Findcppcheck.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
/**
|
||||
* \file Findcppcheck.cpp
|
||||
* \brief Dummy C++ source file used by CMake module Findcppcheck.cmake
|
||||
*
|
||||
* \author
|
||||
* Ryan Pavlik, 2009-2010
|
||||
* <rpavlik@iastate.edu>
|
||||
* http://academic.cleardefinition.com/
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
return 0;
|
||||
}
|
19
CMakeModules/Toolchain-mingw32.cmake
Normal file
19
CMakeModules/Toolchain-mingw32.cmake
Normal file
@ -0,0 +1,19 @@
|
||||
SET(CROSS_COMPILE_WINDOWS ON)
|
||||
|
||||
# the name of the target operating system
|
||||
SET(CMAKE_SYSTEM_NAME Windows)
|
||||
|
||||
# which compilers to use for C and C++
|
||||
SET(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
|
||||
SET(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
|
||||
SET(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
|
||||
|
||||
# here is the target environment located
|
||||
SET(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
|
||||
|
||||
# adjust the default behaviour of the FIND_XXX() commands:
|
||||
# search headers and libraries in the target environment, search
|
||||
# programs in the host environment
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
202
LICENSE
Normal file
202
LICENSE
Normal file
@ -0,0 +1,202 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2017 R. Thomas
|
||||
Copyright 2017 Quarkslab
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
107
README.md
Normal file
107
README.md
Normal file
@ -0,0 +1,107 @@
|
||||
<p align="center" >
|
||||
<img width="40%" src="http://romainthomas.fr/logo_blue_with_name_500.png"/><br />
|
||||
</p>
|
||||
<hr>
|
||||
<p>
|
||||
<a href="https://gitter.im/lief-project">
|
||||
<img src="https://img.shields.io/gitter/room/gitterHQ/gitter.svg">
|
||||
</a>
|
||||
|
||||
</p>
|
||||
|
||||
The purpose of this project is to provide a cross platform library which can parse, modify and abstract ELF, PE and MachO formats.
|
||||
|
||||
Main features:
|
||||
|
||||
* **Parsing**: LIEF can parse ELF, PE, MachO and provides an user-friendly API to access to format internals.
|
||||
* **Modify**: LIEF enables to modify some parts of these formats
|
||||
* **Abstract**: Three formats have common features like sections, symbols, entry point... LIEF factors them.
|
||||
* **API**: LIEF can be used in C, C++ and Python
|
||||
|
||||
## Getting started
|
||||
|
||||
### Python
|
||||
|
||||
```python
|
||||
import lief
|
||||
# ELF
|
||||
binary = lief.parse("/usr/bin/ls")
|
||||
print(binary)
|
||||
|
||||
# PE
|
||||
binary = lief.parse("C:\\Windows\\explorer.exe")
|
||||
print(binary)
|
||||
|
||||
# Mach-O
|
||||
binary = lief.parse("/usr/bin/ls")
|
||||
print(binary)
|
||||
|
||||
```
|
||||
|
||||
### C++
|
||||
|
||||
```cpp
|
||||
#include <LIEF/LIEF.hpp>
|
||||
int main(int argc, const char** argv) {
|
||||
LIEF::ELF::Binary* elf = LIEF::ELF::Parser::parse("/usr/bin/ls");
|
||||
LIEF::PE::Binary* pe = LIEF::PE::Parser::parse("C:\\Windows\\explorer.exe");
|
||||
LIEF::MachO::Binary* macho = LIEF::MachO::Parser::parse("/usr/bin/ls");
|
||||
|
||||
std::cout << *elf << std::endl;
|
||||
std::cout << *pe << std::endl;
|
||||
std::cout << *macho << std::endl;
|
||||
|
||||
delete elf;
|
||||
delete pe;
|
||||
delete macho;
|
||||
}
|
||||
```
|
||||
|
||||
### C
|
||||
|
||||
```cpp
|
||||
#include <LIEF/LIEF.h>
|
||||
int main(int argc, const char** argv) {
|
||||
|
||||
Elf_Binary_t* elf_binary = elf_parse("/usr/bin/ls");
|
||||
Pe_Binary_t* pe_binary = pe_parse("C:\\Windows\\explorer.exe");
|
||||
Macho_Binary_t** macho_binaries = macho_parse("/usr/bin/ls");
|
||||
|
||||
Pe_Section_t** pe_sections = pe_binary->sections;
|
||||
Elf_Section_t** elf_sections = elf_binary->sections;
|
||||
Macho_Section_t** macho_sections = macho_binaries[0]->sections;
|
||||
|
||||
for (size_t i = 0; pe_sections[i] != NULL; ++i) {
|
||||
printf("%s\n", pe_sections[i]->name)
|
||||
}
|
||||
|
||||
for (size_t i = 0; elf_sections[i] != NULL; ++i) {
|
||||
printf("%s\n", elf_sections[i]->name)
|
||||
}
|
||||
|
||||
for (size_t i = 0; macho_sections[i] != NULL; ++i) {
|
||||
printf("%s\n", macho_sections[i]->name)
|
||||
}
|
||||
|
||||
elf_binary_destroy(elf_binary);
|
||||
pe_binary_destroy(pe_binary);
|
||||
macho_binaries_destroy(macho_binaries);
|
||||
}
|
||||
|
||||
```
|
||||
## Documentation
|
||||
|
||||
* [Tutorial](http://lief.quarkslab.com/doc)
|
||||
* [API](http://lief.quarkslab.com/doc)
|
||||
* [Doxygen](http://lief.quarkslab.com/doc)
|
||||
|
||||
## Support
|
||||
|
||||
* **Mail**: lief at quarkslab com
|
||||
* **Gitter**: [lief-project](https://gitter.im/lief-project)
|
||||
|
||||
## Authors
|
||||
|
||||
Romain Thomas - [Quarkslab](https://www.quarkslab.com)
|
||||
|
||||
|
52
api/c/CMakeLists.txt
Normal file
52
api/c/CMakeLists.txt
Normal file
@ -0,0 +1,52 @@
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
)
|
||||
|
||||
set(LIEF_C_ELF_SRC
|
||||
${CMAKE_CURRENT_LIST_DIR}/ELF/Symbol.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/ELF/Section.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/ELF/Segment.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/ELF/DynamicEntry.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/ELF/Header.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/ELF/Binary.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/ELF/EnumToString.cpp)
|
||||
|
||||
|
||||
set(LIEF_C_PE_SRC
|
||||
${CMAKE_CURRENT_LIST_DIR}/PE/Binary.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/PE/DosHeader.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/PE/Header.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/PE/OptionalHeader.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/PE/Section.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/PE/DataDirectory.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/PE/EnumToString.cpp)
|
||||
|
||||
|
||||
set(LIEF_C_MACHO_SRC
|
||||
${CMAKE_CURRENT_LIST_DIR}/MachO/Parser.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/MachO/LoadCommand.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/MachO/Segment.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/MachO/Symbol.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/MachO/Section.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/MachO/Header.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/MachO/Binary.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/MachO/EnumToString.cpp)
|
||||
|
||||
set(LIEF_C_SRC)
|
||||
|
||||
if (LIEF_ELF)
|
||||
set(LIEF_C_SRC ${LIEF_C_SRC} ${LIEF_C_ELF_SRC})
|
||||
endif()
|
||||
|
||||
if (LIEF_PE)
|
||||
set(LIEF_C_SRC ${LIEF_C_SRC} ${LIEF_C_PE_SRC})
|
||||
endif()
|
||||
|
||||
if (LIEF_MACHO)
|
||||
set(LIEF_C_SRC ${LIEF_C_SRC} ${LIEF_C_MACHO_SRC})
|
||||
endif()
|
||||
|
||||
target_sources(LIB_LIEF_STATIC PRIVATE ${LIEF_C_SRC})
|
||||
target_sources(LIB_LIEF_SHARED PRIVATE ${LIEF_C_SRC})
|
||||
|
112
api/c/ELF/Binary.cpp
Normal file
112
api/c/ELF/Binary.cpp
Normal file
@ -0,0 +1,112 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "LIEF/ELF/Binary.h"
|
||||
#include "LIEF/ELF/Section.h"
|
||||
#include "LIEF/ELF/Segment.h"
|
||||
#include "LIEF/ELF/Header.h"
|
||||
#include "LIEF/ELF/Symbol.h"
|
||||
|
||||
#include "LIEF/ELF/Parser.hpp"
|
||||
#include "LIEF/ELF/Binary.hpp"
|
||||
|
||||
#include "Section.hpp"
|
||||
#include "Segment.hpp"
|
||||
#include "DynamicEntry.hpp"
|
||||
#include "Symbol.hpp"
|
||||
#include "Header.hpp"
|
||||
#include "Binary.hpp"
|
||||
|
||||
using namespace LIEF::ELF;
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
void init_c_binary(Elf_Binary_t* c_binary, Binary* binary) {
|
||||
c_binary->handler = reinterpret_cast<void*>(binary);
|
||||
c_binary->name = binary->name().c_str();
|
||||
c_binary->type = static_cast<enum ::ELF_CLASS>(binary->type());
|
||||
c_binary->interpreter = nullptr;
|
||||
if (binary->has_interpreter()) {
|
||||
std::string interp = binary->get_interpreter();
|
||||
c_binary->interpreter = static_cast<char*>(malloc(interp.size() * sizeof(char)));
|
||||
std::memcpy(
|
||||
reinterpret_cast<void*>(const_cast<char*>(c_binary->interpreter)),
|
||||
reinterpret_cast<const void*>(interp.data()),
|
||||
interp.size());
|
||||
}
|
||||
|
||||
|
||||
init_c_header(c_binary, binary);
|
||||
init_c_sections(c_binary, binary);
|
||||
init_c_segments(c_binary, binary);
|
||||
init_c_dynamic_symbols(c_binary, binary);
|
||||
init_c_static_symbols(c_binary, binary);
|
||||
init_c_dynamic_entries(c_binary, binary);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Elf_Binary_t* elf_parse(const char *file) {
|
||||
Binary* binary = Parser::parse(file);
|
||||
Elf_Binary_t* c_binary = static_cast<Elf_Binary_t*>(malloc(sizeof(Elf_Binary_t)));
|
||||
memset(c_binary, 0, sizeof(Elf_Binary_t));
|
||||
init_c_binary(c_binary, binary);
|
||||
return c_binary;
|
||||
}
|
||||
|
||||
// Binary Methods
|
||||
// ==============
|
||||
|
||||
int elf_binary_save_header(Elf_Binary_t* binary) {
|
||||
Header& hdr = reinterpret_cast<Binary*>(binary->handler)->get_header();
|
||||
|
||||
hdr.file_type(static_cast<LIEF::ELF::E_TYPE>(binary->header.file_type));
|
||||
hdr.machine_type(static_cast<LIEF::ELF::ARCH>(binary->header.machine_type));
|
||||
hdr.object_file_version(static_cast<LIEF::ELF::VERSION>(binary->header.object_file_version));
|
||||
hdr.program_headers_offset(binary->header.program_headers_offset);
|
||||
hdr.section_headers_offset(binary->header.section_headers_offset);
|
||||
hdr.processor_flag(binary->header.processor_flags);
|
||||
hdr.header_size(binary->header.header_size);
|
||||
hdr.program_header_size(binary->header.program_header_size);
|
||||
hdr.numberof_segments(binary->header.numberof_segments);
|
||||
hdr.sizeof_section_header(binary->header.sizeof_section_header);
|
||||
hdr.numberof_sections(binary->header.numberof_sections);
|
||||
hdr.section_name_table_idx(binary->header.name_string_table_idx);
|
||||
hdr.entrypoint(binary->header.entrypoint);
|
||||
|
||||
//TODO: identity
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void elf_binary_destroy(Elf_Binary_t* binary) {
|
||||
destroy_sections(binary);
|
||||
destroy_segments(binary);
|
||||
destroy_dynamic_symbols(binary);
|
||||
destroy_static_symbols(binary);
|
||||
destroy_dynamic_entries(binary);
|
||||
|
||||
if (binary->interpreter != nullptr) {
|
||||
free(const_cast<char*>(binary->interpreter));
|
||||
}
|
||||
|
||||
delete reinterpret_cast<Binary*>(binary->handler);
|
||||
free(binary);
|
||||
|
||||
}
|
||||
//}
|
30
api/c/ELF/Binary.hpp
Normal file
30
api/c/ELF/Binary.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef LIEF_ELF_BINARY_CPP_C_API_
|
||||
#define LIEF_ELF_BINARY_CPP_C_API_
|
||||
|
||||
#include "LIEF/ELF/Binary.h"
|
||||
#include "LIEF/ELF/Binary.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
void init_c_binary(Elf_Binary_t* c_binary, Binary* binary);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
174
api/c/ELF/DynamicEntry.cpp
Normal file
174
api/c/ELF/DynamicEntry.cpp
Normal file
@ -0,0 +1,174 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "DynamicEntry.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
void init_c_dynamic_entries(Elf_Binary_t* c_binary, Binary* binary) {
|
||||
|
||||
it_dynamic_entries dyn_entries = binary->get_dynamic_entries();
|
||||
c_binary->dynamic_entries = static_cast<Elf_DynamicEntry_t**>(
|
||||
malloc((dyn_entries.size() + 1) * sizeof(Elf_DynamicEntry_t**)));
|
||||
|
||||
for (size_t i = 0; i < dyn_entries.size(); ++i) {
|
||||
DynamicEntry& entry = dyn_entries[i];
|
||||
switch(entry.tag()) {
|
||||
case DYNAMIC_TAGS::DT_NEEDED:
|
||||
{
|
||||
|
||||
Elf_DynamicEntry_Library_t* e = static_cast<Elf_DynamicEntry_Library_t*>(
|
||||
malloc(sizeof(Elf_DynamicEntry_Library_t)));
|
||||
|
||||
e->tag = static_cast<enum ::DYNAMIC_TAGS>(entry.tag());
|
||||
e->value = entry.value();
|
||||
e->name = dynamic_cast<DynamicEntryLibrary*>(&entry)->name().c_str();
|
||||
|
||||
c_binary->dynamic_entries[i] = reinterpret_cast<Elf_DynamicEntry_t*>(e);
|
||||
break;
|
||||
// cppcheck-suppress memleak
|
||||
}
|
||||
|
||||
case DYNAMIC_TAGS::DT_SONAME:
|
||||
{
|
||||
Elf_DynamicEntry_SharedObject_t* e = static_cast<Elf_DynamicEntry_SharedObject_t*>(
|
||||
malloc(sizeof(Elf_DynamicEntry_SharedObject_t)));
|
||||
|
||||
e->tag = static_cast<enum ::DYNAMIC_TAGS>(entry.tag());
|
||||
e->value = entry.value();
|
||||
e->name = dynamic_cast<DynamicSharedObject*>(&entry)->name().c_str();
|
||||
|
||||
c_binary->dynamic_entries[i] = reinterpret_cast<Elf_DynamicEntry_t*>(e);
|
||||
break;
|
||||
}
|
||||
|
||||
case DYNAMIC_TAGS::DT_RPATH:
|
||||
{
|
||||
Elf_DynamicEntry_Rpath_t* e = static_cast<Elf_DynamicEntry_Rpath_t*>(
|
||||
malloc(sizeof(Elf_DynamicEntry_Rpath_t)));
|
||||
|
||||
e->tag = static_cast<enum ::DYNAMIC_TAGS>(entry.tag());
|
||||
e->value = entry.value();
|
||||
e->rpath = dynamic_cast<DynamicEntryRpath*>(&entry)->name().c_str();
|
||||
|
||||
c_binary->dynamic_entries[i] = reinterpret_cast<Elf_DynamicEntry_t*>(e);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case DYNAMIC_TAGS::DT_RUNPATH:
|
||||
{
|
||||
Elf_DynamicEntry_RunPath_t* e = static_cast<Elf_DynamicEntry_RunPath_t*>(
|
||||
malloc(sizeof(Elf_DynamicEntry_RunPath_t)));
|
||||
|
||||
e->tag = static_cast<enum ::DYNAMIC_TAGS>(entry.tag());
|
||||
e->value = entry.value();
|
||||
e->runpath = dynamic_cast<DynamicEntryRunPath*>(&entry)->name().c_str();
|
||||
|
||||
c_binary->dynamic_entries[i] = reinterpret_cast<Elf_DynamicEntry_t*>(e);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case DYNAMIC_TAGS::DT_INIT_ARRAY:
|
||||
case DYNAMIC_TAGS::DT_FINI_ARRAY:
|
||||
case DYNAMIC_TAGS::DT_PREINIT_ARRAY:
|
||||
{
|
||||
Elf_DynamicEntry_Array_t* e = static_cast<Elf_DynamicEntry_Array_t*>(
|
||||
malloc(sizeof(Elf_DynamicEntry_Array_t)));
|
||||
|
||||
e->tag = static_cast<enum ::DYNAMIC_TAGS>(entry.tag());
|
||||
e->value = entry.value();
|
||||
const std::vector<uint64_t>& array = dynamic_cast<DynamicEntryArray*>(&entry)->array();
|
||||
e->array = static_cast<uint64_t*>(malloc((array.size() + 1) * sizeof(uint64_t)));
|
||||
for (size_t i = 0; i < array.size(); ++i) {
|
||||
e->array[i] = array[i];
|
||||
}
|
||||
e->array[array.size()] = 0;
|
||||
c_binary->dynamic_entries[i] = reinterpret_cast<Elf_DynamicEntry_t*>(e);
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
c_binary->dynamic_entries[i] =
|
||||
static_cast<Elf_DynamicEntry_t*>(malloc(sizeof(Elf_DynamicEntry_t)));
|
||||
c_binary->dynamic_entries[i]->tag = static_cast<enum ::DYNAMIC_TAGS>(entry.tag());
|
||||
c_binary->dynamic_entries[i]->value = entry.value();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c_binary->dynamic_entries[dyn_entries.size()] = nullptr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void destroy_dynamic_entries(Elf_Binary_t* c_binary) {
|
||||
|
||||
Elf_DynamicEntry_t **dynamic_entries = c_binary->dynamic_entries;
|
||||
for (size_t idx = 0; dynamic_entries[idx] != NULL; ++idx) {
|
||||
switch(dynamic_entries[idx]->tag) {
|
||||
case DYNAMIC_TAGS::DT_NEEDED:
|
||||
{
|
||||
free(reinterpret_cast<Elf_DynamicEntry_Library_t*>(dynamic_entries[idx]));
|
||||
break;
|
||||
}
|
||||
|
||||
case DYNAMIC_TAGS::DT_SONAME:
|
||||
{
|
||||
free(reinterpret_cast<Elf_DynamicEntry_SharedObject_t*>(dynamic_entries[idx]));
|
||||
break;
|
||||
}
|
||||
|
||||
case DYNAMIC_TAGS::DT_RPATH:
|
||||
{
|
||||
free(reinterpret_cast<Elf_DynamicEntry_Rpath_t*>(dynamic_entries[idx]));
|
||||
break;
|
||||
}
|
||||
|
||||
case DYNAMIC_TAGS::DT_RUNPATH:
|
||||
{
|
||||
free(reinterpret_cast<Elf_DynamicEntry_RunPath_t*>(dynamic_entries[idx]));
|
||||
break;
|
||||
}
|
||||
|
||||
case DYNAMIC_TAGS::DT_INIT_ARRAY:
|
||||
case DYNAMIC_TAGS::DT_FINI_ARRAY:
|
||||
case DYNAMIC_TAGS::DT_PREINIT_ARRAY:
|
||||
{
|
||||
free(reinterpret_cast<Elf_DynamicEntry_Array_t*>(dynamic_entries[idx]));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
|
||||
free(dynamic_entries[idx]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
free(c_binary->dynamic_entries);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
34
api/c/ELF/DynamicEntry.hpp
Normal file
34
api/c/ELF/DynamicEntry.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef LIEF_ELF_DYNAMIC_ENTRY_CPP_C_API_
|
||||
#define LIEF_ELF_DYNAMIC_ENTRY_CPP_C_API_
|
||||
|
||||
#include "LIEF/ELF/Binary.h"
|
||||
#include "LIEF/ELF/Binary.hpp"
|
||||
|
||||
#include "LIEF/ELF/DynamicEntry.h"
|
||||
#include "LIEF/ELF/DynamicEntry.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
void init_c_dynamic_entries(Elf_Binary_t* c_binary, Binary* binary);
|
||||
void destroy_dynamic_entries(Elf_Binary_t* c_binary);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
73
api/c/ELF/EnumToString.cpp
Normal file
73
api/c/ELF/EnumToString.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "LIEF/ELF/EnumToString.h"
|
||||
#include "LIEF/ELF/EnumToString.hpp"
|
||||
|
||||
#include "LIEF/ELF/Structures.hpp"
|
||||
#include "LIEF/ELF/structures.h"
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
const char* E_TYPE_to_string(enum E_TYPE e) {
|
||||
return LIEF::ELF::to_string(static_cast<LIEF::ELF::E_TYPE>(e));
|
||||
}
|
||||
|
||||
const char* SYMBOL_BINDINGS_to_string(enum SYMBOL_BINDINGS e) {
|
||||
return LIEF::ELF::to_string(static_cast<LIEF::ELF::SYMBOL_BINDINGS>(e));
|
||||
}
|
||||
|
||||
const char* VERSION_to_string(enum VERSION e) {
|
||||
return LIEF::ELF::to_string(static_cast<LIEF::ELF::VERSION>(e));
|
||||
}
|
||||
|
||||
const char* ARCH_to_string(enum ARCH e) {
|
||||
return LIEF::ELF::to_string(static_cast<LIEF::ELF::ARCH>(e));
|
||||
}
|
||||
|
||||
const char* SEGMENT_TYPES_to_string(enum SEGMENT_TYPES e) {
|
||||
return LIEF::ELF::to_string(static_cast<LIEF::ELF::SEGMENT_TYPES>(e));
|
||||
}
|
||||
|
||||
const char* DYNAMIC_TAGS_to_string(enum DYNAMIC_TAGS e) {
|
||||
return LIEF::ELF::to_string(static_cast<LIEF::ELF::DYNAMIC_TAGS>(e));
|
||||
}
|
||||
|
||||
const char* SECTION_TYPES_to_string(enum SECTION_TYPES e) {
|
||||
return LIEF::ELF::to_string(static_cast<LIEF::ELF::SECTION_TYPES>(e));
|
||||
}
|
||||
|
||||
const char* SECTION_FLAGS_to_string(enum SECTION_FLAGS e) {
|
||||
return LIEF::ELF::to_string(static_cast<LIEF::ELF::SECTION_FLAGS>(e));
|
||||
}
|
||||
|
||||
const char* SYMBOL_TYPES_to_string(enum SYMBOL_TYPES e) {
|
||||
return LIEF::ELF::to_string(static_cast<LIEF::ELF::SYMBOL_TYPES>(e));
|
||||
}
|
||||
|
||||
const char* ELF_CLASS_to_string(enum ELF_CLASS e) {
|
||||
return LIEF::ELF::to_string(static_cast<LIEF::ELF::ELF_CLASS>(e));
|
||||
}
|
||||
|
||||
const char* ELF_DATA_to_string(enum ELF_DATA e) {
|
||||
return LIEF::ELF::to_string(static_cast<LIEF::ELF::ELF_DATA>(e));
|
||||
}
|
||||
|
||||
const char* OS_ABI_to_string(enum OS_ABI e) {
|
||||
return LIEF::ELF::to_string(static_cast<LIEF::ELF::OS_ABI>(e));
|
||||
}
|
||||
|
||||
}
|
46
api/c/ELF/Header.cpp
Normal file
46
api/c/ELF/Header.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "Header.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
void init_c_header(Elf_Binary_t* c_binary, Binary* binary) {
|
||||
|
||||
const Header& hdr = binary->get_header();
|
||||
c_binary->header.file_type = static_cast<enum ::E_TYPE>(hdr.file_type());
|
||||
c_binary->header.machine_type = static_cast<enum ::ARCH>(hdr.machine_type());
|
||||
c_binary->header.object_file_version = static_cast<enum ::VERSION>(hdr.object_file_version());
|
||||
c_binary->header.program_headers_offset = hdr.program_headers_offset();
|
||||
c_binary->header.section_headers_offset = hdr.section_headers_offset();
|
||||
c_binary->header.processor_flags = hdr.processor_flag();
|
||||
c_binary->header.header_size = hdr.header_size();
|
||||
c_binary->header.program_header_size = hdr.program_header_size();
|
||||
c_binary->header.numberof_segments = hdr.numberof_segments();
|
||||
c_binary->header.sizeof_section_header = hdr.sizeof_section_header();
|
||||
c_binary->header.numberof_sections = hdr.numberof_sections();
|
||||
c_binary->header.name_string_table_idx = hdr.section_name_table_idx();
|
||||
c_binary->header.entrypoint = hdr.entrypoint();
|
||||
const Header::identity_t& ident = hdr.identity();
|
||||
std::copy(
|
||||
std::begin(ident),
|
||||
std::end(ident),
|
||||
c_binary->header.identity);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
33
api/c/ELF/Header.hpp
Normal file
33
api/c/ELF/Header.hpp
Normal file
@ -0,0 +1,33 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef LIEF_ELF_HEADER_CPP_C_API_
|
||||
#define LIEF_ELF_HEADER_CPP_C_API_
|
||||
|
||||
#include "LIEF/ELF/Binary.h"
|
||||
#include "LIEF/ELF/Binary.hpp"
|
||||
|
||||
#include "LIEF/ELF/Header.h"
|
||||
#include "LIEF/ELF/Header.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
void init_c_header(Elf_Binary_t* c_binary, Binary* binary);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
71
api/c/ELF/Section.cpp
Normal file
71
api/c/ELF/Section.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "Section.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
void init_c_sections(Elf_Binary_t* c_binary, Binary* binary) {
|
||||
|
||||
it_sections sections = binary->get_sections();
|
||||
|
||||
c_binary->sections = static_cast<Elf_Section_t**>(
|
||||
malloc((sections.size() + 1) * sizeof(Elf_Section_t**)));
|
||||
|
||||
for (size_t i = 0; i < sections.size(); ++i) {
|
||||
Section& b_section = sections[i];
|
||||
c_binary->sections[i] = static_cast<Elf_Section_t*>(malloc(sizeof(Elf_Section_t)));
|
||||
const std::vector<uint8_t>& section_content = b_section.content();
|
||||
uint8_t* content = static_cast<uint8_t*>(malloc(section_content.size() * sizeof(uint8_t)));
|
||||
std::copy(
|
||||
std::begin(section_content),
|
||||
std::end(section_content),
|
||||
content);
|
||||
|
||||
c_binary->sections[i]->name = b_section.name().c_str();
|
||||
c_binary->sections[i]->flags = b_section.flags();
|
||||
c_binary->sections[i]->type = static_cast<enum ::SECTION_TYPES>(b_section.type());
|
||||
c_binary->sections[i]->virtual_address = b_section.virtual_address();
|
||||
c_binary->sections[i]->offset = b_section.file_offset();
|
||||
c_binary->sections[i]->original_size = b_section.original_size();
|
||||
c_binary->sections[i]->link = b_section.link();
|
||||
c_binary->sections[i]->info = b_section.information();
|
||||
c_binary->sections[i]->alignment = b_section.alignment();
|
||||
c_binary->sections[i]->entry_size = b_section.entry_size();
|
||||
c_binary->sections[i]->content = content;
|
||||
c_binary->sections[i]->size = section_content.size();
|
||||
c_binary->sections[i]->entropy = b_section.entropy();
|
||||
}
|
||||
c_binary->sections[sections.size()] = nullptr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void destroy_sections(Elf_Binary_t* c_binary) {
|
||||
|
||||
Elf_Section_t **sections = c_binary->sections;
|
||||
for (size_t idx = 0; sections[idx] != nullptr; ++idx) {
|
||||
free(sections[idx]->content);
|
||||
free(sections[idx]);
|
||||
}
|
||||
free(c_binary->sections);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
34
api/c/ELF/Section.hpp
Normal file
34
api/c/ELF/Section.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef LIEF_ELF_SECTION_CPP_C_API_
|
||||
#define LIEF_ELF_SECTION_CPP_C_API_
|
||||
|
||||
#include "LIEF/ELF/Binary.h"
|
||||
#include "LIEF/ELF/Binary.hpp"
|
||||
|
||||
#include "LIEF/ELF/Section.h"
|
||||
#include "LIEF/ELF/Section.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
void init_c_sections(Elf_Binary_t* c_binary, Binary* binary);
|
||||
void destroy_sections(Elf_Binary_t* c_binary);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
67
api/c/ELF/Segment.cpp
Normal file
67
api/c/ELF/Segment.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "Segment.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
void init_c_segments(Elf_Binary_t* c_binary, Binary* binary) {
|
||||
|
||||
it_segments segments = binary->get_segments();
|
||||
c_binary->segments = static_cast<Elf_Segment_t**>(
|
||||
malloc((segments.size() + 1) * sizeof(Elf_Segment_t**)));
|
||||
for (size_t i = 0; i < segments.size(); ++i) {
|
||||
Segment& segment = segments[i];
|
||||
|
||||
const std::vector<uint8_t>& segment_content = segment.content();
|
||||
uint8_t* content = static_cast<uint8_t*>(malloc(segment_content.size() * sizeof(uint8_t)));
|
||||
std::copy(
|
||||
std::begin(segment_content),
|
||||
std::end(segment_content),
|
||||
content);
|
||||
|
||||
c_binary->segments[i] = static_cast<Elf_Segment_t*>(malloc(sizeof(Elf_Segment_t)));
|
||||
c_binary->segments[i]->type = static_cast<enum ::SEGMENT_TYPES>(segment.type());
|
||||
c_binary->segments[i]->flags = segment.flag();
|
||||
c_binary->segments[i]->virtual_address = segment.virtual_address();
|
||||
c_binary->segments[i]->virtual_size = segment.virtual_size();
|
||||
c_binary->segments[i]->offset = segment.file_offset();
|
||||
c_binary->segments[i]->alignment = segment.alignment();
|
||||
c_binary->segments[i]->size = segment_content.size();
|
||||
c_binary->segments[i]->content = content;
|
||||
}
|
||||
|
||||
c_binary->segments[segments.size()] = nullptr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void destroy_segments(Elf_Binary_t* c_binary) {
|
||||
|
||||
Elf_Segment_t **segments = c_binary->segments;
|
||||
for (size_t idx = 0; segments[idx] != nullptr; ++idx) {
|
||||
free(segments[idx]->content);
|
||||
free(segments[idx]);
|
||||
}
|
||||
free(c_binary->segments);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
34
api/c/ELF/Segment.hpp
Normal file
34
api/c/ELF/Segment.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef LIEF_ELF_SEGMENT_CPP_C_API_
|
||||
#define LIEF_ELF_SEGMENT_CPP_C_API_
|
||||
|
||||
#include "LIEF/ELF/Binary.h"
|
||||
#include "LIEF/ELF/Binary.hpp"
|
||||
|
||||
#include "LIEF/ELF/Segment.h"
|
||||
#include "LIEF/ELF/Segment.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
void init_c_segments(Elf_Binary_t* c_binary, Binary* binary);
|
||||
void destroy_segments(Elf_Binary_t* c_binary);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
90
api/c/ELF/Symbol.cpp
Normal file
90
api/c/ELF/Symbol.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "Symbol.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
void init_c_dynamic_symbols(Elf_Binary_t* c_binary, Binary* binary) {
|
||||
it_symbols dyn_symb = binary->get_dynamic_symbols();
|
||||
|
||||
c_binary->dynamic_symbols = static_cast<Elf_Symbol_t**>(
|
||||
malloc((dyn_symb.size() + 1) * sizeof(Elf_Symbol_t**)));
|
||||
|
||||
for (size_t i = 0; i < dyn_symb.size(); ++i) {
|
||||
Symbol& b_sym = dyn_symb[i];
|
||||
c_binary->dynamic_symbols[i] = static_cast<Elf_Symbol_t*>(malloc(sizeof(Elf_Symbol_t)));
|
||||
c_binary->dynamic_symbols[i]->name = b_sym.name().c_str();
|
||||
c_binary->dynamic_symbols[i]->type = static_cast<enum ::SYMBOL_TYPES>(b_sym.type());
|
||||
c_binary->dynamic_symbols[i]->binding = static_cast<enum ::SYMBOL_BINDINGS>(b_sym.binding());
|
||||
c_binary->dynamic_symbols[i]->other = b_sym.other();
|
||||
c_binary->dynamic_symbols[i]->shndx = b_sym.shndx();
|
||||
c_binary->dynamic_symbols[i]->value = b_sym.value();
|
||||
c_binary->dynamic_symbols[i]->size = b_sym.size();
|
||||
c_binary->dynamic_symbols[i]->information = b_sym.information();
|
||||
}
|
||||
c_binary->dynamic_symbols[dyn_symb.size()] = nullptr;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void init_c_static_symbols(Elf_Binary_t* c_binary, Binary* binary) {
|
||||
it_symbols static_symb = binary->get_static_symbols();
|
||||
|
||||
c_binary->static_symbols = static_cast<Elf_Symbol_t**>(
|
||||
malloc((static_symb.size() + 1) * sizeof(Elf_Symbol_t**)));
|
||||
|
||||
for (size_t i = 0; i < static_symb.size(); ++i) {
|
||||
Symbol& b_sym = static_symb[i];
|
||||
c_binary->static_symbols[i] = static_cast<Elf_Symbol_t*>(malloc(sizeof(Elf_Symbol_t)));
|
||||
c_binary->static_symbols[i]->name = b_sym.name().c_str();
|
||||
c_binary->static_symbols[i]->type = static_cast<enum ::SYMBOL_TYPES>(b_sym.type());
|
||||
c_binary->static_symbols[i]->binding = static_cast<enum ::SYMBOL_BINDINGS>(b_sym.binding());
|
||||
c_binary->static_symbols[i]->other = b_sym.other();
|
||||
c_binary->static_symbols[i]->shndx = b_sym.shndx();
|
||||
c_binary->static_symbols[i]->value = b_sym.value();
|
||||
c_binary->static_symbols[i]->size = b_sym.size();
|
||||
c_binary->static_symbols[i]->information = b_sym.information();
|
||||
}
|
||||
c_binary->static_symbols[static_symb.size()] = nullptr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void destroy_dynamic_symbols(Elf_Binary_t* c_binary) {
|
||||
Elf_Symbol_t **dynamic_symbols = c_binary->dynamic_symbols;
|
||||
for (size_t idx = 0; dynamic_symbols[idx] != nullptr; ++idx) {
|
||||
free(dynamic_symbols[idx]);
|
||||
}
|
||||
free(c_binary->dynamic_symbols);
|
||||
}
|
||||
|
||||
|
||||
void destroy_static_symbols(Elf_Binary_t* c_binary) {
|
||||
Elf_Symbol_t **static_symbols = c_binary->static_symbols;
|
||||
for (size_t idx = 0; static_symbols[idx] != nullptr; ++idx) {
|
||||
free(static_symbols[idx]);
|
||||
}
|
||||
free(c_binary->static_symbols);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
37
api/c/ELF/Symbol.hpp
Normal file
37
api/c/ELF/Symbol.hpp
Normal file
@ -0,0 +1,37 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef LIEF_ELF_SYMBOL_CPP_C_API_
|
||||
#define LIEF_ELF_SYMBOL_CPP_C_API_
|
||||
|
||||
#include "LIEF/ELF/Binary.h"
|
||||
#include "LIEF/ELF/Binary.hpp"
|
||||
|
||||
#include "LIEF/ELF/Symbol.h"
|
||||
#include "LIEF/ELF/Symbol.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace ELF {
|
||||
|
||||
void init_c_dynamic_symbols(Elf_Binary_t* c_binary, Binary* binary);
|
||||
void init_c_static_symbols(Elf_Binary_t* c_binary, Binary* binary);
|
||||
|
||||
void destroy_dynamic_symbols(Elf_Binary_t* c_binary);
|
||||
void destroy_static_symbols(Elf_Binary_t* c_binary);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
58
api/c/MachO/Binary.cpp
Normal file
58
api/c/MachO/Binary.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "LIEF/MachO/Binary.h"
|
||||
|
||||
#include "LIEF/MachO/Binary.hpp"
|
||||
|
||||
#include "Binary.hpp"
|
||||
#include "Section.hpp"
|
||||
#include "Header.hpp"
|
||||
#include "Symbol.hpp"
|
||||
#include "Segment.hpp"
|
||||
#include "LoadCommand.hpp"
|
||||
|
||||
|
||||
using namespace LIEF::MachO;
|
||||
|
||||
namespace LIEF {
|
||||
namespace MachO {
|
||||
void init_c_binary(Macho_Binary_t* c_binary, Binary* binary) {
|
||||
|
||||
c_binary->handler = reinterpret_cast<void*>(binary);
|
||||
c_binary->name = binary->name().c_str();
|
||||
c_binary->imagebase = binary->imagebase();
|
||||
init_c_header(c_binary, binary);
|
||||
init_c_commands(c_binary, binary);
|
||||
init_c_symbols(c_binary, binary);
|
||||
init_c_sections(c_binary, binary);
|
||||
init_c_segments(c_binary, binary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void macho_binaries_destroy(Macho_Binary_t** binaries) {
|
||||
for (size_t i = 0; binaries[i] != nullptr; ++i) {
|
||||
destroy_sections(binaries[i]);
|
||||
destroy_commands(binaries[i]);
|
||||
destroy_symbols(binaries[i]);
|
||||
destroy_segments(binaries[i]);
|
||||
|
||||
delete reinterpret_cast<Binary*>(binaries[i]->handler);
|
||||
free(binaries[i]);
|
||||
}
|
||||
free(binaries);
|
||||
|
||||
}
|
30
api/c/MachO/Binary.hpp
Normal file
30
api/c/MachO/Binary.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef LIEF_MACHO_BINARY_CPP_C_API_
|
||||
#define LIEF_MACHO_BINARY_CPP_C_API_
|
||||
|
||||
#include "LIEF/MachO/Binary.h"
|
||||
#include "LIEF/MachO/Binary.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace MachO {
|
||||
|
||||
void init_c_binary(Macho_Binary_t* c_binary, Binary* binary);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
76
api/c/MachO/EnumToString.cpp
Normal file
76
api/c/MachO/EnumToString.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "LIEF/MachO/EnumToString.h"
|
||||
#include "LIEF/MachO/EnumToString.hpp"
|
||||
|
||||
#include "LIEF/MachO/enums.hpp"
|
||||
#include "LIEF/MachO/enums.h"
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
const char* LOAD_COMMAND_TYPES_to_string(enum LOAD_COMMAND_TYPES e) {
|
||||
return LIEF::MachO::to_string(static_cast<LIEF::MachO::LOAD_COMMAND_TYPES>(e));
|
||||
}
|
||||
|
||||
|
||||
const char* MACHO_TYPES_to_string(enum MACHO_TYPES e) {
|
||||
return LIEF::MachO::to_string(static_cast<LIEF::MachO::MACHO_TYPES>(e));
|
||||
}
|
||||
|
||||
|
||||
const char* FILE_TYPES_to_string(enum FILE_TYPES e) {
|
||||
return LIEF::MachO::to_string(static_cast<LIEF::MachO::FILE_TYPES>(e));
|
||||
}
|
||||
|
||||
|
||||
const char* CPU_TYPES_to_string(enum CPU_TYPES e) {
|
||||
return LIEF::MachO::to_string(static_cast<LIEF::MachO::CPU_TYPES>(e));
|
||||
}
|
||||
|
||||
|
||||
const char* HEADER_FLAGS_to_string(enum HEADER_FLAGS e) {
|
||||
return LIEF::MachO::to_string(static_cast<LIEF::MachO::HEADER_FLAGS>(e));
|
||||
}
|
||||
|
||||
|
||||
const char* MachO_SECTION_TYPES_to_string(enum SECTION_TYPES e) {
|
||||
return LIEF::MachO::to_string(static_cast<LIEF::MachO::SECTION_TYPES>(e));
|
||||
}
|
||||
|
||||
|
||||
const char* MachO_SYMBOL_TYPES_to_string(enum SYMBOL_TYPES e) {
|
||||
return LIEF::MachO::to_string(static_cast<LIEF::MachO::SYMBOL_TYPES>(e));
|
||||
}
|
||||
|
||||
|
||||
const char* N_LIST_TYPES_to_string(enum N_LIST_TYPES e) {
|
||||
return LIEF::MachO::to_string(static_cast<LIEF::MachO::N_LIST_TYPES>(e));
|
||||
}
|
||||
|
||||
|
||||
const char* SYMBOL_DESCRIPTIONS_to_string(enum SYMBOL_DESCRIPTIONS e) {
|
||||
return LIEF::MachO::to_string(static_cast<LIEF::MachO::SYMBOL_DESCRIPTIONS>(e));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
33
api/c/MachO/Header.cpp
Normal file
33
api/c/MachO/Header.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "Header.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace MachO {
|
||||
void init_c_header(Macho_Binary_t* c_binary, Binary* binary) {
|
||||
Header& header = binary->header();
|
||||
c_binary->header.magic = header.magic();
|
||||
c_binary->header.cpu_type = static_cast<enum ::CPU_TYPES>(header.cpu_type());
|
||||
c_binary->header.cpu_subtype = header.cpu_subtype();
|
||||
c_binary->header.file_type = static_cast<enum ::FILE_TYPES>(header.file_type());
|
||||
c_binary->header.nb_cmds = header.nb_cmds();
|
||||
c_binary->header.sizeof_cmds = header.sizeof_cmds();
|
||||
c_binary->header.flags = header.flags();
|
||||
c_binary->header.reserved = header.reserved();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
33
api/c/MachO/Header.hpp
Normal file
33
api/c/MachO/Header.hpp
Normal file
@ -0,0 +1,33 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef LIEF_MACHO_HEADER_CPP_C_API_
|
||||
#define LIEF_MACHO_HEADER_CPP_C_API_
|
||||
|
||||
#include "LIEF/MachO/Binary.h"
|
||||
#include "LIEF/MachO/Binary.hpp"
|
||||
|
||||
#include "LIEF/MachO/Header.h"
|
||||
#include "LIEF/MachO/Header.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace MachO {
|
||||
|
||||
void init_c_header(Macho_Binary_t* c_binary, Binary* binary);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
62
api/c/MachO/LoadCommand.cpp
Normal file
62
api/c/MachO/LoadCommand.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "LoadCommand.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace MachO {
|
||||
void init_c_commands(Macho_Binary_t* c_binary, Binary* binary) {
|
||||
it_commands commands = binary->commands();
|
||||
|
||||
c_binary->commands = static_cast<Macho_Command_t**>(
|
||||
malloc((commands.size() + 1) * sizeof(Macho_Command_t**)));
|
||||
|
||||
for (size_t i = 0; i < commands.size(); ++i) {
|
||||
LoadCommand& cmd = commands[i];
|
||||
|
||||
c_binary->commands[i] = static_cast<Macho_Command_t*>(malloc(sizeof(Macho_Command_t)));
|
||||
const std::vector<uint8_t>& cmd_content = cmd.data();
|
||||
uint8_t* content = static_cast<uint8_t*>(malloc(cmd_content.size() * sizeof(uint8_t)));
|
||||
std::copy(
|
||||
std::begin(cmd_content),
|
||||
std::end(cmd_content),
|
||||
content);
|
||||
|
||||
c_binary->commands[i]->command = static_cast<enum ::LOAD_COMMAND_TYPES>(cmd.command());
|
||||
c_binary->commands[i]->size = cmd.size();
|
||||
c_binary->commands[i]->data = content;
|
||||
c_binary->commands[i]->offset = cmd.command_offset();
|
||||
}
|
||||
|
||||
c_binary->commands[commands.size()] = nullptr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void destroy_commands(Macho_Binary_t* c_binary) {
|
||||
Macho_Command_t **commands = c_binary->commands;
|
||||
for (size_t idx = 0; commands[idx] != nullptr; ++idx) {
|
||||
free(commands[idx]->data);
|
||||
free(commands[idx]);
|
||||
}
|
||||
free(c_binary->commands);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
34
api/c/MachO/LoadCommand.hpp
Normal file
34
api/c/MachO/LoadCommand.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef LIEF_MACHO_LOAD_COMMAND_CPP_C_API_
|
||||
#define LIEF_MACHO_LOAD_COMMAND_CPP_C_API_
|
||||
|
||||
#include "LIEF/MachO/Binary.h"
|
||||
#include "LIEF/MachO/Binary.hpp"
|
||||
|
||||
#include "LIEF/MachO/LoadCommand.h"
|
||||
#include "LIEF/MachO/LoadCommand.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace MachO {
|
||||
|
||||
void init_c_commands(Macho_Binary_t* c_binary, Binary* binary);
|
||||
void destroy_commands(Macho_Binary_t* c_binary);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
41
api/c/MachO/Parser.cpp
Normal file
41
api/c/MachO/Parser.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <cstring>
|
||||
|
||||
#include "LIEF/MachO/Binary.h"
|
||||
#include "LIEF/MachO/Parser.hpp"
|
||||
|
||||
#include "Binary.hpp"
|
||||
|
||||
using namespace LIEF::MachO;
|
||||
|
||||
Macho_Binary_t** macho_parse(const char *file) {
|
||||
std::vector<Binary*> macho_binaries{Parser::parse(file)};
|
||||
|
||||
Macho_Binary_t** c_macho_binaries = static_cast<Macho_Binary_t**>(
|
||||
malloc((macho_binaries.size() + 1) * sizeof(Macho_Binary_t**)));
|
||||
|
||||
for (size_t i = 0; i < macho_binaries.size(); ++i) {
|
||||
Binary* binary = macho_binaries [i];
|
||||
c_macho_binaries[i] = static_cast<Macho_Binary_t*>(malloc(sizeof(Macho_Binary_t)));
|
||||
init_c_binary(c_macho_binaries[i], binary);
|
||||
}
|
||||
|
||||
c_macho_binaries[macho_binaries.size()] = nullptr;
|
||||
|
||||
return c_macho_binaries;
|
||||
}
|
||||
|
72
api/c/MachO/Section.cpp
Normal file
72
api/c/MachO/Section.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "Section.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace MachO {
|
||||
void init_c_sections(Macho_Binary_t* c_binary, Binary* binary) {
|
||||
it_sections sections = binary->sections();
|
||||
|
||||
c_binary->sections = static_cast<Macho_Section_t**>(
|
||||
malloc((sections.size() + 1) * sizeof(Macho_Section_t**)));
|
||||
|
||||
for (size_t i = 0; i < sections.size(); ++i) {
|
||||
Section& section = sections[i];
|
||||
|
||||
c_binary->sections[i] = static_cast<Macho_Section_t*>(malloc(sizeof(Macho_Section_t)));
|
||||
const std::vector<uint8_t>& section_content = section.content();
|
||||
uint8_t* content = static_cast<uint8_t*>(malloc(section_content.size() * sizeof(uint8_t)));
|
||||
std::copy(
|
||||
std::begin(section_content),
|
||||
std::end(section_content),
|
||||
content);
|
||||
|
||||
c_binary->sections[i]->name = section.name().c_str();
|
||||
c_binary->sections[i]->alignment = section.alignment();
|
||||
c_binary->sections[i]->relocation_offset = section.relocation_offset();
|
||||
c_binary->sections[i]->numberof_relocations = section.numberof_relocations();
|
||||
c_binary->sections[i]->flags = section.flags();
|
||||
c_binary->sections[i]->type = static_cast<enum ::SECTION_TYPES>(section.type());
|
||||
c_binary->sections[i]->reserved1 = section.reserved1();
|
||||
c_binary->sections[i]->reserved2 = section.reserved2();
|
||||
c_binary->sections[i]->reserved3 = section.reserved3();
|
||||
c_binary->sections[i]->virtual_address = section.virtual_address();
|
||||
c_binary->sections[i]->offset = section.offset();
|
||||
c_binary->sections[i]->size = section.size();
|
||||
c_binary->sections[i]->content = content;
|
||||
c_binary->sections[i]->entropy = section.entropy();
|
||||
}
|
||||
|
||||
c_binary->sections[sections.size()] = nullptr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void destroy_sections(Macho_Binary_t* c_binary) {
|
||||
Macho_Section_t **sections = c_binary->sections;
|
||||
for (size_t idx = 0; sections[idx] != nullptr; ++idx) {
|
||||
free(sections[idx]->content);
|
||||
free(sections[idx]);
|
||||
}
|
||||
free(c_binary->sections);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
34
api/c/MachO/Section.hpp
Normal file
34
api/c/MachO/Section.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef LIEF_MACHO_SECTION_CPP_C_API_
|
||||
#define LIEF_MACHO_SECTION_CPP_C_API_
|
||||
|
||||
#include "LIEF/MachO/Binary.h"
|
||||
#include "LIEF/MachO/Binary.hpp"
|
||||
|
||||
#include "LIEF/MachO/Section.h"
|
||||
#include "LIEF/MachO/Section.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace MachO {
|
||||
|
||||
void init_c_sections(Macho_Binary_t* c_binary, Binary* binary);
|
||||
void destroy_sections(Macho_Binary_t* c_binary);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
69
api/c/MachO/Segment.cpp
Normal file
69
api/c/MachO/Segment.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "Segment.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace MachO {
|
||||
void init_c_segments(Macho_Binary_t* c_binary, Binary* binary) {
|
||||
it_segments segments = binary->segments();
|
||||
|
||||
c_binary->segments = static_cast<Macho_Segment_t**>(
|
||||
malloc((segments.size() + 1) * sizeof(Macho_Segment_t**)));
|
||||
|
||||
for (size_t i = 0; i < segments.size(); ++i) {
|
||||
SegmentCommand& segment = segments[i];
|
||||
|
||||
c_binary->segments[i] = static_cast<Macho_Segment_t*>(malloc(sizeof(Macho_Segment_t)));
|
||||
const std::vector<uint8_t>& segment_content = segment.content();
|
||||
uint8_t* content = static_cast<uint8_t*>(malloc(segment_content.size() * sizeof(uint8_t)));
|
||||
std::copy(
|
||||
std::begin(segment_content),
|
||||
std::end(segment_content),
|
||||
content);
|
||||
|
||||
c_binary->segments[i]->name = segment.name().c_str();
|
||||
c_binary->segments[i]->virtual_address = segment.virtual_address();
|
||||
c_binary->segments[i]->virtual_size = segment.virtual_size();
|
||||
c_binary->segments[i]->file_size = segment.file_size();
|
||||
c_binary->segments[i]->file_offset = segment.file_offset();
|
||||
c_binary->segments[i]->max_protection = segment.max_protection();
|
||||
c_binary->segments[i]->init_protection = segment.init_protection();
|
||||
c_binary->segments[i]->numberof_sections = segment.numberof_sections();
|
||||
c_binary->segments[i]->flags = segment.flags();
|
||||
c_binary->segments[i]->content = content;
|
||||
c_binary->segments[i]->sections = nullptr; //TODO
|
||||
}
|
||||
|
||||
c_binary->segments[segments.size()] = nullptr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void destroy_segments(Macho_Binary_t* c_binary) {
|
||||
Macho_Segment_t **segments = c_binary->segments;
|
||||
for (size_t idx = 0; segments[idx] != nullptr; ++idx) {
|
||||
free(segments[idx]->content);
|
||||
free(segments[idx]);
|
||||
}
|
||||
free(c_binary->segments);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
34
api/c/MachO/Segment.hpp
Normal file
34
api/c/MachO/Segment.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef LIEF_MACHO_SEGMENT_CPP_C_API_
|
||||
#define LIEF_MACHO_SEGMENT_CPP_C_API_
|
||||
|
||||
#include "LIEF/MachO/Binary.h"
|
||||
#include "LIEF/MachO/Binary.hpp"
|
||||
|
||||
#include "LIEF/MachO/Segment.h"
|
||||
#include "LIEF/MachO/SegmentCommand.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace MachO {
|
||||
|
||||
void init_c_segments(Macho_Binary_t* c_binary, Binary* binary);
|
||||
void destroy_segments(Macho_Binary_t* c_binary);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
56
api/c/MachO/Symbol.cpp
Normal file
56
api/c/MachO/Symbol.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "Symbol.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace MachO {
|
||||
void init_c_symbols(Macho_Binary_t* c_binary, Binary* binary) {
|
||||
it_symbols symbols = binary->symbols();
|
||||
|
||||
c_binary->symbols = static_cast<Macho_Symbol_t**>(
|
||||
malloc((symbols.size() + 1) * sizeof(Macho_Symbol_t**)));
|
||||
|
||||
for (size_t i = 0; i < symbols.size(); ++i) {
|
||||
Symbol& symbol = symbols[i];
|
||||
|
||||
c_binary->symbols[i] = static_cast<Macho_Symbol_t*>(malloc(sizeof(Macho_Symbol_t)));
|
||||
|
||||
c_binary->symbols[i]->name = symbol.name().c_str();
|
||||
c_binary->symbols[i]->type = symbol.type();
|
||||
c_binary->symbols[i]->numberof_sections = symbol.numberof_sections();
|
||||
c_binary->symbols[i]->description = symbol.description();
|
||||
c_binary->symbols[i]->value = symbol.value();
|
||||
}
|
||||
|
||||
c_binary->symbols[symbols.size()] = nullptr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void destroy_symbols(Macho_Binary_t* c_binary) {
|
||||
Macho_Symbol_t **symbols = c_binary->symbols;
|
||||
for (size_t idx = 0; symbols[idx] != nullptr; ++idx) {
|
||||
free(symbols[idx]);
|
||||
}
|
||||
free(c_binary->symbols);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
34
api/c/MachO/Symbol.hpp
Normal file
34
api/c/MachO/Symbol.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef LIEF_MACHO_SYMBOL_CPP_C_API_
|
||||
#define LIEF_MACHO_SYMBOL_CPP_C_API_
|
||||
|
||||
#include "LIEF/MachO/Binary.h"
|
||||
#include "LIEF/MachO/Binary.hpp"
|
||||
|
||||
#include "LIEF/MachO/Symbol.h"
|
||||
#include "LIEF/MachO/Symbol.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace MachO {
|
||||
|
||||
void init_c_symbols(Macho_Binary_t* c_binary, Binary* binary);
|
||||
void destroy_symbols(Macho_Binary_t* c_binary);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
64
api/c/PE/Binary.cpp
Normal file
64
api/c/PE/Binary.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <cstring>
|
||||
|
||||
#include "LIEF/PE/Binary.h"
|
||||
|
||||
#include "LIEF/PE/Parser.hpp"
|
||||
#include "LIEF/PE/Binary.hpp"
|
||||
|
||||
#include "Binary.hpp"
|
||||
#include "DosHeader.hpp"
|
||||
#include "Header.hpp"
|
||||
#include "OptionalHeader.hpp"
|
||||
#include "Section.hpp"
|
||||
#include "DataDirectory.hpp"
|
||||
|
||||
using namespace LIEF::PE;
|
||||
|
||||
namespace LIEF {
|
||||
namespace PE {
|
||||
|
||||
void init_c_binary(Pe_Binary_t* c_binary, Binary* binary) {
|
||||
c_binary->name = binary->name().c_str();
|
||||
c_binary->handler = reinterpret_cast<void*>(binary);
|
||||
|
||||
init_c_dos_header(c_binary, binary);
|
||||
init_c_header(c_binary, binary);
|
||||
init_c_optional_header(c_binary, binary);
|
||||
init_c_sections(c_binary, binary);
|
||||
init_c_data_directories(c_binary, binary);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Pe_Binary_t* pe_parse(const char *file) {
|
||||
Binary* binary = Parser::parse(file);
|
||||
Pe_Binary_t* c_binary = static_cast<Pe_Binary_t*>(malloc(sizeof(Pe_Binary_t)));
|
||||
std::memset(c_binary, 0, sizeof(Pe_Binary_t));
|
||||
init_c_binary(c_binary, binary);
|
||||
|
||||
return c_binary;
|
||||
}
|
||||
|
||||
void pe_binary_destroy(Pe_Binary_t* binary) {
|
||||
destroy_sections(binary);
|
||||
destroy_data_directories(binary);
|
||||
delete reinterpret_cast<Binary*>(binary->handler);
|
||||
free(binary);
|
||||
}
|
30
api/c/PE/Binary.hpp
Normal file
30
api/c/PE/Binary.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef LIEF_PE_BINARY_CPP_C_API_
|
||||
#define LIEF_PE_BINARY_CPP_C_API_
|
||||
|
||||
#include "LIEF/PE/Binary.h"
|
||||
#include "LIEF/PE/Binary.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace PE {
|
||||
|
||||
void init_c_binary(Pe_Binary_t* c_binary, Binary* binary);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
54
api/c/PE/DataDirectory.cpp
Normal file
54
api/c/PE/DataDirectory.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "DataDirectory.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace PE {
|
||||
void init_c_data_directories(Pe_Binary_t* c_binary, Binary* binary) {
|
||||
|
||||
it_data_directories data_directories = binary->data_directories();
|
||||
|
||||
c_binary->data_directories = static_cast<Pe_DataDirectory_t**>(
|
||||
malloc((data_directories.size() + 1) * sizeof(Pe_DataDirectory_t**)));
|
||||
|
||||
for (size_t i = 0; i < data_directories.size(); ++i) {
|
||||
|
||||
c_binary->data_directories[i] = static_cast<Pe_DataDirectory_t*>(malloc(sizeof(Pe_DataDirectory_t)));
|
||||
c_binary->data_directories[i]->rva = data_directories[i].RVA();
|
||||
c_binary->data_directories[i]->size = data_directories[i].size();
|
||||
}
|
||||
c_binary->data_directories[data_directories.size()] = nullptr;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void destroy_data_directories(Pe_Binary_t* c_binary) {
|
||||
|
||||
Pe_DataDirectory_t **data_directories = c_binary->data_directories;
|
||||
for (size_t idx = 0; data_directories[idx] != nullptr; ++idx) {
|
||||
free(data_directories[idx]);
|
||||
}
|
||||
free(c_binary->data_directories);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
34
api/c/PE/DataDirectory.hpp
Normal file
34
api/c/PE/DataDirectory.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef LIEF_PE_DATA_DIRECTORY_CPP_C_API_
|
||||
#define LIEF_PE_DATA_DIRECTORY_CPP_C_API_
|
||||
|
||||
#include "LIEF/PE/Binary.h"
|
||||
#include "LIEF/PE/Binary.hpp"
|
||||
|
||||
#include "LIEF/PE/DataDirectory.h"
|
||||
#include "LIEF/PE/DataDirectory.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace PE {
|
||||
|
||||
void init_c_data_directories(Pe_Binary_t* c_binary, Binary* binary);
|
||||
void destroy_data_directories(Pe_Binary_t* c_binary);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
55
api/c/PE/DosHeader.cpp
Normal file
55
api/c/PE/DosHeader.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "DosHeader.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace PE {
|
||||
void init_c_dos_header(Pe_Binary_t* c_binary, Binary* binary) {
|
||||
const DosHeader& dos_header = binary->dos_header();
|
||||
c_binary->dos_header.magic = dos_header.magic();
|
||||
c_binary->dos_header.used_bytes_in_the_last_page = dos_header.used_bytes_in_the_last_page();
|
||||
c_binary->dos_header.file_size_in_pages = dos_header.file_size_in_pages();
|
||||
c_binary->dos_header.numberof_relocation = dos_header.numberof_relocation();
|
||||
c_binary->dos_header.header_size_in_paragraphs = dos_header.header_size_in_paragraphs();
|
||||
c_binary->dos_header.minimum_extra_paragraphs = dos_header.minimum_extra_paragraphs();
|
||||
c_binary->dos_header.maximum_extra_paragraphs = dos_header.maximum_extra_paragraphs();
|
||||
c_binary->dos_header.initial_relative_ss = dos_header.initial_relative_ss();
|
||||
c_binary->dos_header.initial_sp = dos_header.initial_sp();
|
||||
c_binary->dos_header.checksum = dos_header.checksum();
|
||||
c_binary->dos_header.initial_ip = dos_header.initial_ip();
|
||||
c_binary->dos_header.initial_relative_cs = dos_header.initial_relative_cs();
|
||||
c_binary->dos_header.addressof_relocation_table = dos_header.addressof_relocation_table();
|
||||
c_binary->dos_header.overlay_number = dos_header.overlay_number();
|
||||
c_binary->dos_header.oem_id = dos_header.oem_id();
|
||||
c_binary->dos_header.oem_info = dos_header.oem_info();
|
||||
c_binary->dos_header.addressof_new_exeheader = dos_header.addressof_new_exeheader();
|
||||
|
||||
const DosHeader::reserved_t& reserved = dos_header.reserved();
|
||||
std::copy(
|
||||
std::begin(reserved),
|
||||
std::end(reserved),
|
||||
c_binary->dos_header.reserved);
|
||||
|
||||
|
||||
const DosHeader::reserved2_t& reserved2 = dos_header.reserved2();
|
||||
std::copy(
|
||||
std::begin(reserved2),
|
||||
std::end(reserved2),
|
||||
c_binary->dos_header.reserved2);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
33
api/c/PE/DosHeader.hpp
Normal file
33
api/c/PE/DosHeader.hpp
Normal file
@ -0,0 +1,33 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef LIEF_PE_DOS_HEADER_CPP_C_API_
|
||||
#define LIEF_PE_DOS_HEADER_CPP_C_API_
|
||||
|
||||
#include "LIEF/PE/Binary.h"
|
||||
#include "LIEF/PE/Binary.hpp"
|
||||
|
||||
#include "LIEF/PE/DosHeader.h"
|
||||
#include "LIEF/PE/DosHeader.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace PE {
|
||||
|
||||
void init_c_dos_header(Pe_Binary_t* c_binary, Binary* binary);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
40
api/c/PE/EnumToString.cpp
Normal file
40
api/c/PE/EnumToString.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "LIEF/PE/EnumToString.h"
|
||||
#include "LIEF/PE/EnumToString.hpp"
|
||||
|
||||
#include "LIEF/PE/enums.hpp"
|
||||
#include "LIEF/PE/enums.h"
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
const char* PE_TYPES_to_string(enum PE_TYPES e) {
|
||||
return LIEF::PE::to_string(static_cast<LIEF::PE::PE_TYPE>(e));
|
||||
}
|
||||
|
||||
|
||||
const char* MACHINE_TYPES_to_string(enum MACHINE_TYPES e) {
|
||||
return LIEF::PE::to_string(static_cast<LIEF::PE::MACHINE_TYPES>(e));
|
||||
}
|
||||
|
||||
|
||||
const char* SUBSYSTEM_to_string(enum SUBSYSTEM e) {
|
||||
return LIEF::PE::to_string(static_cast<LIEF::PE::SUBSYSTEM>(e));
|
||||
}
|
||||
|
||||
}
|
42
api/c/PE/Header.cpp
Normal file
42
api/c/PE/Header.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "Header.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace PE {
|
||||
|
||||
void init_c_header(Pe_Binary_t* c_binary, Binary* binary) {
|
||||
|
||||
const Header& header = binary->header();
|
||||
|
||||
const Header::signature_t& signature = header.signature();
|
||||
|
||||
c_binary->header.machine = static_cast<enum ::MACHINE_TYPES>(header.machine());
|
||||
c_binary->header.numberof_sections = header.numberof_sections();
|
||||
c_binary->header.time_date_stamp = header.time_date_stamp();
|
||||
c_binary->header.pointerto_symbol_table = header.pointerto_symbol_table();
|
||||
c_binary->header.numberof_symbols = header.numberof_symbols();
|
||||
c_binary->header.sizeof_optional_header = header.sizeof_optional_header();
|
||||
c_binary->header.characteristics = header.characteristics();
|
||||
|
||||
std::copy(
|
||||
std::begin(signature),
|
||||
std::end(signature),
|
||||
c_binary->header.signature);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
33
api/c/PE/Header.hpp
Normal file
33
api/c/PE/Header.hpp
Normal file
@ -0,0 +1,33 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef LIEF_PE_HEADER_CPP_C_API_
|
||||
#define LIEF_PE_HEADER_CPP_C_API_
|
||||
|
||||
#include "LIEF/PE/Binary.h"
|
||||
#include "LIEF/PE/Binary.hpp"
|
||||
|
||||
#include "LIEF/PE/Header.h"
|
||||
#include "LIEF/PE/Header.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace PE {
|
||||
|
||||
void init_c_header(Pe_Binary_t* c_binary, Binary* binary);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
61
api/c/PE/OptionalHeader.cpp
Normal file
61
api/c/PE/OptionalHeader.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "OptionalHeader.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace PE {
|
||||
|
||||
void init_c_optional_header(Pe_Binary_t* c_binary, Binary* binary) {
|
||||
|
||||
const OptionalHeader& optional_header = binary->optional_header();
|
||||
c_binary->optional_header.magic = static_cast<enum PE_TYPES>(optional_header.magic());
|
||||
c_binary->optional_header.major_linker_version = optional_header.major_linker_version();
|
||||
c_binary->optional_header.minor_linker_version = optional_header.minor_linker_version();
|
||||
c_binary->optional_header.sizeof_code = optional_header.sizeof_code();
|
||||
c_binary->optional_header.sizeof_initialized_data = optional_header.sizeof_initialized_data();
|
||||
c_binary->optional_header.sizeof_uninitialized_data = optional_header.sizeof_uninitialized_data();
|
||||
c_binary->optional_header.addressof_entrypoint = optional_header.addressof_entrypoint();
|
||||
c_binary->optional_header.baseof_code = optional_header.baseof_code();
|
||||
if (optional_header.magic() == PE_TYPE::PE32) {
|
||||
c_binary->optional_header.baseof_data = optional_header.baseof_data();
|
||||
} else {
|
||||
c_binary->optional_header.baseof_data = 0;
|
||||
}
|
||||
c_binary->optional_header.imagebase = optional_header.imagebase();
|
||||
c_binary->optional_header.section_alignment = optional_header.section_alignment();
|
||||
c_binary->optional_header.file_alignment = optional_header.file_alignment();
|
||||
c_binary->optional_header.major_operating_system_version = optional_header.major_operating_system_version();
|
||||
c_binary->optional_header.minor_operating_system_version = optional_header.minor_operating_system_version();
|
||||
c_binary->optional_header.major_image_version = optional_header.major_image_version();
|
||||
c_binary->optional_header.minor_image_version = optional_header.minor_image_version();
|
||||
c_binary->optional_header.major_subsystem_version = optional_header.major_subsystem_version();
|
||||
c_binary->optional_header.minor_subsystem_version = optional_header.minor_subsystem_version();
|
||||
c_binary->optional_header.win32_version_value = optional_header.win32_version_value();
|
||||
c_binary->optional_header.sizeof_image = optional_header.sizeof_image();
|
||||
c_binary->optional_header.sizeof_headers = optional_header.sizeof_headers();
|
||||
c_binary->optional_header.checksum = optional_header.checksum();
|
||||
c_binary->optional_header.subsystem = static_cast<enum ::SUBSYSTEM>(optional_header.subsystem());
|
||||
c_binary->optional_header.dll_characteristics = optional_header.dll_characteristics();
|
||||
c_binary->optional_header.sizeof_stack_reserve = optional_header.sizeof_stack_reserve();
|
||||
c_binary->optional_header.sizeof_stack_commit = optional_header.sizeof_stack_commit();
|
||||
c_binary->optional_header.sizeof_heap_reserve = optional_header.sizeof_heap_reserve();
|
||||
c_binary->optional_header.sizeof_heap_commit = optional_header.sizeof_heap_commit();
|
||||
c_binary->optional_header.loader_flags = optional_header.loader_flags();
|
||||
c_binary->optional_header.numberof_rva_and_size = optional_header.numberof_rva_and_size();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
33
api/c/PE/OptionalHeader.hpp
Normal file
33
api/c/PE/OptionalHeader.hpp
Normal file
@ -0,0 +1,33 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef LIEF_PE_OPTIONAL_HEADER_CPP_C_API_
|
||||
#define LIEF_PE_OPTIONAL_HEADER_CPP_C_API_
|
||||
|
||||
#include "LIEF/PE/Binary.h"
|
||||
#include "LIEF/PE/Binary.hpp"
|
||||
|
||||
#include "LIEF/PE/OptionalHeader.h"
|
||||
#include "LIEF/PE/OptionalHeader.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace PE {
|
||||
|
||||
void init_c_optional_header(Pe_Binary_t* c_binary, Binary* binary);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
68
api/c/PE/Section.cpp
Normal file
68
api/c/PE/Section.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "Section.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace PE {
|
||||
void init_c_sections(Pe_Binary_t* c_binary, Binary* binary) {
|
||||
|
||||
it_sections sections = binary->get_sections();
|
||||
|
||||
c_binary->sections = static_cast<Pe_Section_t**>(
|
||||
malloc((sections.size() + 1) * sizeof(Pe_Section_t**)));
|
||||
|
||||
for (size_t i = 0; i < sections.size(); ++i) {
|
||||
Section& b_section = sections[i];
|
||||
c_binary->sections[i] = static_cast<Pe_Section_t*>(malloc(sizeof(Pe_Section_t)));
|
||||
const std::vector<uint8_t>& section_content = b_section.content();
|
||||
uint8_t* content = static_cast<uint8_t*>(malloc(section_content.size() * sizeof(uint8_t)));
|
||||
std::copy(
|
||||
std::begin(section_content),
|
||||
std::end(section_content),
|
||||
content);
|
||||
|
||||
c_binary->sections[i]->name = b_section.name().c_str();
|
||||
c_binary->sections[i]->virtual_address = b_section.virtual_address();
|
||||
c_binary->sections[i]->size = b_section.size();
|
||||
c_binary->sections[i]->offset = b_section.offset();
|
||||
c_binary->sections[i]->virtual_size = b_section.virtual_size();
|
||||
c_binary->sections[i]->pointerto_relocation = b_section.pointerto_relocation();
|
||||
c_binary->sections[i]->pointerto_line_numbers = b_section.pointerto_line_numbers();
|
||||
c_binary->sections[i]->characteristics = b_section.characteristics();
|
||||
c_binary->sections[i]->content = content;
|
||||
c_binary->sections[i]->entropy = b_section.entropy();
|
||||
}
|
||||
c_binary->sections[sections.size()] = nullptr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void destroy_sections(Pe_Binary_t* c_binary) {
|
||||
|
||||
Pe_Section_t **sections = c_binary->sections;
|
||||
for (size_t idx = 0; sections[idx] != nullptr; ++idx) {
|
||||
free(sections[idx]->content);
|
||||
free(sections[idx]);
|
||||
}
|
||||
free(c_binary->sections);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
34
api/c/PE/Section.hpp
Normal file
34
api/c/PE/Section.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef LIEF_PE_SECTION_CPP_C_API_
|
||||
#define LIEF_PE_SECTION_CPP_C_API_
|
||||
|
||||
#include "LIEF/PE/Binary.h"
|
||||
#include "LIEF/PE/Binary.hpp"
|
||||
|
||||
#include "LIEF/PE/Section.h"
|
||||
#include "LIEF/PE/Section.hpp"
|
||||
|
||||
namespace LIEF {
|
||||
namespace PE {
|
||||
|
||||
void init_c_sections(Pe_Binary_t* c_binary, Binary* binary);
|
||||
void destroy_sections(Pe_Binary_t* c_binary);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
27
api/c/include/LIEF/ELF.h
Normal file
27
api/c/include/LIEF/ELF.h
Normal file
@ -0,0 +1,27 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_ELF_H_
|
||||
#define C_LIEF_ELF_H_
|
||||
|
||||
//! @defgroup elf_c_api ELF C API
|
||||
|
||||
#include "LIEF/ELF/Binary.h"
|
||||
#include "LIEF/ELF/Symbol.h"
|
||||
#include "LIEF/ELF/Section.h"
|
||||
#include "LIEF/ELF/Header.h"
|
||||
#include "LIEF/ELF/DynamicEntry.h"
|
||||
#include "LIEF/ELF/EnumToString.h"
|
||||
#endif
|
79
api/c/include/LIEF/ELF/Binary.h
Normal file
79
api/c/include/LIEF/ELF/Binary.h
Normal file
@ -0,0 +1,79 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_ELF_BINARY_H_
|
||||
#define C_LIEF_ELF_BINARY_H_
|
||||
|
||||
/** @defgroup elf_binary_c_api Binary
|
||||
* @ingroup elf_c_api
|
||||
* @addtogroup elf_binary_c_api
|
||||
* @brief Binary C API
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "LIEF/visibility.h"
|
||||
|
||||
#include "LIEF/ELF/enums.h"
|
||||
|
||||
#include "LIEF/ELF/Section.h"
|
||||
#include "LIEF/ELF/Segment.h"
|
||||
#include "LIEF/ELF/Header.h"
|
||||
#include "LIEF/ELF/DynamicEntry.h"
|
||||
#include "LIEF/ELF/Symbol.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @brief LIEF::ELF::Binary C Handler */
|
||||
struct Elf_Binary_t {
|
||||
void* handler;
|
||||
const char* name;
|
||||
const char* interpreter;
|
||||
enum ELF_CLASS type;
|
||||
Elf_Header_t header;
|
||||
Elf_Section_t **sections;
|
||||
Elf_Segment_t **segments;
|
||||
Elf_DynamicEntry_t **dynamic_entries;
|
||||
Elf_Symbol_t **dynamic_symbols;
|
||||
Elf_Symbol_t **static_symbols;
|
||||
};
|
||||
|
||||
typedef struct Elf_Binary_t Elf_Binary_t;
|
||||
|
||||
/** @brief Wrapper for LIEF::ELF::Parser::parse */
|
||||
DLL_PUBLIC Elf_Binary_t* elf_parse(const char *file);
|
||||
|
||||
DLL_PUBLIC void elf_binary_destroy(Elf_Binary_t* binary);
|
||||
|
||||
/* ELF::Binary methods
|
||||
* ==================
|
||||
*/
|
||||
|
||||
/** @brief Update LIEF::ELF::Header object */
|
||||
DLL_PUBLIC int elf_binary_save_header(Elf_Binary_t* binary);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/** @} */
|
||||
#endif
|
83
api/c/include/LIEF/ELF/DynamicEntry.h
Normal file
83
api/c/include/LIEF/ELF/DynamicEntry.h
Normal file
@ -0,0 +1,83 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_ELF_DYNAMIC_ENTRY_H_
|
||||
#define C_LIEF_ELF_DYNAMIC_ENTRY_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "LIEF/ELF/enums.h"
|
||||
|
||||
/** @defgroup elf_dynamic_entry_c_api Dynamic Entry
|
||||
* @ingroup elf_c_api
|
||||
* @addtogroup elf_dynamic_entry_c_api
|
||||
* @brief Dynamic Entry C API
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Elf_DynamicEntry_t {
|
||||
enum DYNAMIC_TAGS tag;
|
||||
uint64_t value;
|
||||
};
|
||||
|
||||
struct Elf_DynamicEntry_Library_t {
|
||||
enum DYNAMIC_TAGS tag;
|
||||
uint64_t value;
|
||||
const char* name;
|
||||
};
|
||||
|
||||
struct Elf_DynamicEntry_SharedObject_t {
|
||||
enum DYNAMIC_TAGS tag;
|
||||
uint64_t value;
|
||||
const char* name;
|
||||
};
|
||||
|
||||
struct Elf_DynamicEntry_Array_t {
|
||||
enum DYNAMIC_TAGS tag;
|
||||
uint64_t value;
|
||||
uint64_t* array;
|
||||
};
|
||||
|
||||
struct Elf_DynamicEntry_Rpath_t {
|
||||
enum DYNAMIC_TAGS tag;
|
||||
uint64_t value;
|
||||
const char* rpath;
|
||||
};
|
||||
|
||||
struct Elf_DynamicEntry_RunPath_t {
|
||||
enum DYNAMIC_TAGS tag;
|
||||
uint64_t value;
|
||||
const char* runpath;
|
||||
};
|
||||
|
||||
typedef struct Elf_DynamicEntry_t Elf_DynamicEntry_t;
|
||||
typedef struct Elf_DynamicEntry_Library_t Elf_DynamicEntry_Library_t;
|
||||
typedef struct Elf_DynamicEntry_SharedObject_t Elf_DynamicEntry_SharedObject_t;
|
||||
typedef struct Elf_DynamicEntry_Array_t Elf_DynamicEntry_Array_t;
|
||||
typedef struct Elf_DynamicEntry_Rpath_t Elf_DynamicEntry_Rpath_t;
|
||||
typedef struct Elf_DynamicEntry_RunPath_t Elf_DynamicEntry_RunPath_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif
|
45
api/c/include/LIEF/ELF/EnumToString.h
Normal file
45
api/c/include/LIEF/ELF/EnumToString.h
Normal file
@ -0,0 +1,45 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_ELF_ENUM_TO_STRING_H_
|
||||
#define C_LIEF_ELF_ENUM_TO_STRING_H_
|
||||
|
||||
#include "LIEF/visibility.h"
|
||||
|
||||
#include "LIEF/ELF/enums.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
DLL_PUBLIC const char* SYMBOL_BINDINGS_to_string(enum SYMBOL_BINDINGS e);
|
||||
DLL_PUBLIC const char* E_TYPE_to_string(enum E_TYPE e);
|
||||
DLL_PUBLIC const char* VERSION_to_string(enum VERSION e);
|
||||
DLL_PUBLIC const char* ARCH_to_string(enum ARCH e);
|
||||
DLL_PUBLIC const char* SEGMENT_TYPES_to_string(enum SEGMENT_TYPES e);
|
||||
DLL_PUBLIC const char* DYNAMIC_TAGS_to_string(enum DYNAMIC_TAGS e);
|
||||
DLL_PUBLIC const char* SECTION_TYPES_to_string(enum SECTION_TYPES e);
|
||||
DLL_PUBLIC const char* SECTION_FLAGS_to_string(enum SECTION_FLAGS e);
|
||||
DLL_PUBLIC const char* SYMBOL_TYPES_to_string(enum SYMBOL_TYPES e);
|
||||
DLL_PUBLIC const char* ELF_CLASS_to_string(enum ELF_CLASS e);
|
||||
DLL_PUBLIC const char* ELF_DATA_to_string(enum ELF_DATA e);
|
||||
DLL_PUBLIC const char* OS_ABI_to_string(enum OS_ABI e);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
58
api/c/include/LIEF/ELF/Header.h
Normal file
58
api/c/include/LIEF/ELF/Header.h
Normal file
@ -0,0 +1,58 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_ELF_HEADER_H_
|
||||
#define C_LIEF_ELF_HEADER_H_
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "LIEF/ELF/enums.h"
|
||||
/** @defgroup elf_header_c_api Header
|
||||
* @ingroup elf_c_api
|
||||
* @addtogroup elf_header_c_api
|
||||
* @brief Header C API
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Elf_Header_t {
|
||||
uint8_t identity[EI_NIDENT];
|
||||
enum E_TYPE file_type;
|
||||
enum ARCH machine_type;
|
||||
enum VERSION object_file_version;
|
||||
uint64_t entrypoint;
|
||||
uint64_t program_headers_offset;
|
||||
uint64_t section_headers_offset;
|
||||
uint32_t processor_flags;
|
||||
uint32_t header_size;
|
||||
uint32_t program_header_size;
|
||||
uint32_t numberof_segments;
|
||||
uint32_t sizeof_section_header;
|
||||
uint32_t numberof_sections;
|
||||
uint32_t name_string_table_idx;
|
||||
};
|
||||
|
||||
typedef struct Elf_Header_t Elf_Header_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif
|
58
api/c/include/LIEF/ELF/Section.h
Normal file
58
api/c/include/LIEF/ELF/Section.h
Normal file
@ -0,0 +1,58 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_ELF_SECTION_H_
|
||||
#define C_LIEF_ELF_SECTION_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "LIEF/ELF/enums.h"
|
||||
|
||||
/** @defgroup elf_section_c_api Section
|
||||
* @ingroup elf_c_api
|
||||
* @addtogroup elf_section_c_api
|
||||
* @brief Section C API
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Elf_Section_t {
|
||||
const char* name;
|
||||
uint32_t flags;
|
||||
enum SECTION_TYPES type;
|
||||
uint64_t virtual_address;
|
||||
uint64_t offset;
|
||||
uint64_t original_size;
|
||||
uint32_t link;
|
||||
uint32_t info;
|
||||
uint64_t alignment;
|
||||
uint64_t entry_size;
|
||||
uint64_t size;
|
||||
uint8_t* content;
|
||||
double entropy;
|
||||
};
|
||||
|
||||
typedef struct Elf_Section_t Elf_Section_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif
|
52
api/c/include/LIEF/ELF/Segment.h
Normal file
52
api/c/include/LIEF/ELF/Segment.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_ELF_SEGMENT_H_
|
||||
#define C_LIEF_ELF_SEGMENT_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "LIEF/ELF/enums.h"
|
||||
|
||||
/** @defgroup elf_segment_c_api Segment
|
||||
* @ingroup elf_c_api
|
||||
* @addtogroup elf_segment_c_api
|
||||
* @brief Segment C API
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Elf_Segment_t {
|
||||
enum SEGMENT_TYPES type;
|
||||
uint32_t flags;
|
||||
uint64_t virtual_address;
|
||||
uint64_t virtual_size;
|
||||
uint64_t offset;
|
||||
uint64_t alignment;
|
||||
uint64_t size;
|
||||
uint8_t* content;
|
||||
};
|
||||
|
||||
typedef struct Elf_Segment_t Elf_Segment_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif
|
52
api/c/include/LIEF/ELF/Symbol.h
Normal file
52
api/c/include/LIEF/ELF/Symbol.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_ELF_SYMBOL_H_
|
||||
#define C_LIEF_ELF_SYMBOL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "LIEF/ELF/enums.h"
|
||||
/* @defgroup elf_symbol_c_api Symbol
|
||||
* @ingroup elf_c_api
|
||||
* @addtogroup elf_symbol_c_api
|
||||
* @brief Symbol C API
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Elf_Symbol_t {
|
||||
const char* name;
|
||||
enum SYMBOL_TYPES type;
|
||||
enum SYMBOL_BINDINGS binding;
|
||||
uint8_t information;
|
||||
uint8_t other;
|
||||
uint16_t shndx;
|
||||
uint64_t value;
|
||||
uint64_t size;
|
||||
};
|
||||
|
||||
typedef struct Elf_Symbol_t Elf_Symbol_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif
|
14
api/c/include/LIEF/ELF/enums.h.in
Normal file
14
api/c/include/LIEF/ELF/enums.h.in
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef LIEF_ELF_C_ENUMS_H_
|
||||
#define LIEF_ELF_C_ENUMS_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@LIEF_ELF_ENUMS@
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
14
api/c/include/LIEF/ELF/structures.h.in
Normal file
14
api/c/include/LIEF/ELF/structures.h.in
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef LIEF_ELF_C_STRUCTURES_H_
|
||||
#define LIEF_ELF_C_STRUCTURES_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@LIEF_ELF_STRUCTURES@
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
23
api/c/include/LIEF/LIEF.h
Normal file
23
api/c/include/LIEF/LIEF.h
Normal file
@ -0,0 +1,23 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_H_
|
||||
#define C_LIEF_H_
|
||||
|
||||
#include <LIEF/MachO.h>
|
||||
#include <LIEF/PE.h>
|
||||
#include <LIEF/ELF.h>
|
||||
|
||||
#endif
|
28
api/c/include/LIEF/MachO.h
Normal file
28
api/c/include/LIEF/MachO.h
Normal file
@ -0,0 +1,28 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_MACHO_H_
|
||||
#define C_LIEF_MACHO_H_
|
||||
|
||||
//! @defgroup macho_c_api MachO C API
|
||||
|
||||
#include "LIEF/MachO/Binary.h"
|
||||
#include "LIEF/MachO/Symbol.h"
|
||||
#include "LIEF/MachO/Segment.h"
|
||||
#include "LIEF/MachO/Section.h"
|
||||
#include "LIEF/MachO/LoadCommand.h"
|
||||
#include "LIEF/MachO/Header.h"
|
||||
#include "LIEF/MachO/EnumToString.h"
|
||||
#endif
|
68
api/c/include/LIEF/MachO/Binary.h
Normal file
68
api/c/include/LIEF/MachO/Binary.h
Normal file
@ -0,0 +1,68 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_MACHO_BINARY_H_
|
||||
#define C_LIEF_MACHO_BINARY_H_
|
||||
|
||||
/** @defgroup macho_binary_c_api Binary
|
||||
* @ingroup macho_c_api
|
||||
* @addtogroup macho_binary_c_api
|
||||
* @brief Binary C API
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "LIEF/visibility.h"
|
||||
|
||||
#include "LIEF/MachO/Header.h"
|
||||
#include "LIEF/MachO/LoadCommand.h"
|
||||
#include "LIEF/MachO/Symbol.h"
|
||||
#include "LIEF/MachO/Section.h"
|
||||
#include "LIEF/MachO/Segment.h"
|
||||
#include "LIEF/MachO/enums.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @brief LIEF::MachO::Binary C Handler */
|
||||
struct Macho_Binary_t {
|
||||
void* handler;
|
||||
const char* name;
|
||||
uint64_t imagebase;
|
||||
Macho_Header_t header;
|
||||
Macho_Command_t** commands;
|
||||
Macho_Symbol_t** symbols;
|
||||
Macho_Section_t** sections;
|
||||
Macho_Segment_t** segments;
|
||||
|
||||
};
|
||||
|
||||
typedef struct Macho_Binary_t Macho_Binary_t;
|
||||
|
||||
/** @brief Wrapper on LIEF::MachO::Parser::parse */
|
||||
DLL_PUBLIC Macho_Binary_t** macho_parse(const char *file);
|
||||
|
||||
DLL_PUBLIC void macho_binaries_destroy(Macho_Binary_t** binaries);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/** @} */
|
||||
#endif
|
41
api/c/include/LIEF/MachO/EnumToString.h
Normal file
41
api/c/include/LIEF/MachO/EnumToString.h
Normal file
@ -0,0 +1,41 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_MACHO_ENUM_TO_STRING_H_
|
||||
#define C_LIEF_MACHO_ENUM_TO_STRING_H_
|
||||
|
||||
#include "LIEF/visibility.h"
|
||||
#include "LIEF/MachO/enums.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
DLL_PUBLIC const char* LOAD_COMMAND_TYPES_to_string(enum LOAD_COMMAND_TYPES e);
|
||||
DLL_PUBLIC const char* MACHO_TYPES_to_string(enum MACHO_TYPES e);
|
||||
DLL_PUBLIC const char* FILE_TYPES_to_string(enum FILE_TYPES e);
|
||||
DLL_PUBLIC const char* CPU_TYPES_to_string(enum CPU_TYPES e);
|
||||
DLL_PUBLIC const char* HEADER_FLAGS_to_string(enum HEADER_FLAGS e);
|
||||
DLL_PUBLIC const char* MachO_SECTION_TYPES_to_string(enum SECTION_TYPES e);
|
||||
DLL_PUBLIC const char* MachO_SYMBOL_TYPES_to_string(enum SYMBOL_TYPES e);
|
||||
DLL_PUBLIC const char* N_LIST_TYPES_to_string(enum N_LIST_TYPES e);
|
||||
DLL_PUBLIC const char* SYMBOL_DESCRIPTIONS_to_string(enum SYMBOL_DESCRIPTIONS e);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
52
api/c/include/LIEF/MachO/Header.h
Normal file
52
api/c/include/LIEF/MachO/Header.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_MACHO_HEADER_H_
|
||||
#define C_LIEF_MACHO_HEADER_H_
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "LIEF/MachO/enums.h"
|
||||
/** @defgroup macho_header_c_api Header
|
||||
* @ingroup macho_c_api
|
||||
* @addtogroup macho_header_c_api
|
||||
* @brief Header C API
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Macho_Header_t {
|
||||
uint32_t magic;
|
||||
enum CPU_TYPES cpu_type;
|
||||
uint32_t cpu_subtype;
|
||||
enum FILE_TYPES file_type;
|
||||
uint32_t nb_cmds;
|
||||
uint32_t sizeof_cmds;
|
||||
uint32_t flags;
|
||||
uint32_t reserved;
|
||||
};
|
||||
|
||||
typedef struct Macho_Header_t Macho_Header_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif
|
48
api/c/include/LIEF/MachO/LoadCommand.h
Normal file
48
api/c/include/LIEF/MachO/LoadCommand.h
Normal file
@ -0,0 +1,48 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_MACHO_LOAD_COMMAND_H_
|
||||
#define C_LIEF_MACHO_LOAD_COMMAND_H_
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "LIEF/MachO/enums.h"
|
||||
/** @defgroup macho_load_command_c_api Header
|
||||
* @ingroup macho_c_api
|
||||
* @addtogroup macho_load_command_c_api
|
||||
* @brief Load Command C API
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Macho_Command_t {
|
||||
enum LOAD_COMMAND_TYPES command;
|
||||
uint32_t size;
|
||||
uint8_t* data;
|
||||
uint32_t offset;
|
||||
};
|
||||
|
||||
typedef struct Macho_Command_t Macho_Command_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif
|
59
api/c/include/LIEF/MachO/Section.h
Normal file
59
api/c/include/LIEF/MachO/Section.h
Normal file
@ -0,0 +1,59 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_MACHO_SECTION_H_
|
||||
#define C_LIEF_MACHO_SECTION_H_
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "LIEF/MachO/enums.h"
|
||||
/** @defgroup macho_section_c_api Header
|
||||
* @ingroup macho_c_api
|
||||
* @addtogroup macho_section_c_api
|
||||
* @brief Section C API
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Macho_Section_t {
|
||||
|
||||
const char* name;
|
||||
uint32_t alignment;
|
||||
uint32_t relocation_offset;
|
||||
uint32_t numberof_relocations;
|
||||
uint32_t flags;
|
||||
enum SECTION_TYPES type;
|
||||
uint32_t reserved1;
|
||||
uint32_t reserved2;
|
||||
uint32_t reserved3;
|
||||
uint64_t virtual_address;
|
||||
uint64_t offset;
|
||||
uint64_t size;
|
||||
uint8_t* content;
|
||||
double entropy;
|
||||
};
|
||||
|
||||
typedef struct Macho_Section_t Macho_Section_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif
|
55
api/c/include/LIEF/MachO/Segment.h
Normal file
55
api/c/include/LIEF/MachO/Segment.h
Normal file
@ -0,0 +1,55 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_MACHO_SEGMENT_H_
|
||||
#define C_LIEF_MACHO_SEGMENT_H_
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "LIEF/MachO/enums.h"
|
||||
/** @defgroup macho_segment_c_api Header
|
||||
* @ingroup macho_c_api
|
||||
* @addtogroup macho_segment_c_api
|
||||
* @brief Segment C API
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Macho_Segment_t {
|
||||
const char* name;
|
||||
uint64_t virtual_address;
|
||||
uint64_t virtual_size;
|
||||
uint64_t file_size;
|
||||
uint64_t file_offset;
|
||||
uint32_t max_protection;
|
||||
uint32_t init_protection;
|
||||
uint32_t numberof_sections;
|
||||
uint32_t flags;
|
||||
uint8_t* content;
|
||||
Macho_Section_t** sections;
|
||||
};
|
||||
|
||||
typedef struct Macho_Segment_t Macho_Segment_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif
|
49
api/c/include/LIEF/MachO/Symbol.h
Normal file
49
api/c/include/LIEF/MachO/Symbol.h
Normal file
@ -0,0 +1,49 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_MACHO_SYMBOL_H_
|
||||
#define C_LIEF_MACHO_SYMBOL_H_
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "LIEF/MachO/enums.h"
|
||||
/** @defgroup macho_symbol_c_api Header
|
||||
* @ingroup macho_c_api
|
||||
* @addtogroup macho_symbol_c_api
|
||||
* @brief Symbol C API
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Macho_Symbol_t {
|
||||
const char* name;
|
||||
uint8_t type;
|
||||
uint8_t numberof_sections;
|
||||
uint16_t description;
|
||||
uint64_t value;
|
||||
};
|
||||
|
||||
typedef struct Macho_Symbol_t Macho_Symbol_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif
|
14
api/c/include/LIEF/MachO/enums.h.in
Normal file
14
api/c/include/LIEF/MachO/enums.h.in
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef LIEF_MACHO_C_ENUMS_H_
|
||||
#define LIEF_MACHO_C_ENUMS_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@LIEF_MACHO_ENUMS@
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
14
api/c/include/LIEF/MachO/structures.h.in
Normal file
14
api/c/include/LIEF/MachO/structures.h.in
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef LIEF_MACHO_C_STRUCTURES_H_
|
||||
#define LIEF_MACHO_C_STRUCTURES_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@LIEF_MACHO_STRUCTURES@
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
23
api/c/include/LIEF/PE.h
Normal file
23
api/c/include/LIEF/PE.h
Normal file
@ -0,0 +1,23 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_PE_H_
|
||||
#define C_LIEF_PE_H_
|
||||
|
||||
//! @defgroup pe_c_api PE C API
|
||||
|
||||
#include "LIEF/PE/Binary.h"
|
||||
#include "LIEF/PE/EnumToString.h"
|
||||
#endif
|
67
api/c/include/LIEF/PE/Binary.h
Normal file
67
api/c/include/LIEF/PE/Binary.h
Normal file
@ -0,0 +1,67 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_PE_BINARY_H_
|
||||
#define C_LIEF_PE_BINARY_H_
|
||||
|
||||
/** @defgroup pe_binary_c_api Binary
|
||||
* @ingroup pe_c_api
|
||||
* @addtogroup pe_binary_c_api
|
||||
* @brief Binary C API
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "LIEF/visibility.h"
|
||||
|
||||
#include "LIEF/PE/enums.h"
|
||||
|
||||
#include "LIEF/PE/DosHeader.h"
|
||||
#include "LIEF/PE/Header.h"
|
||||
#include "LIEF/PE/OptionalHeader.h"
|
||||
#include "LIEF/PE/DataDirectory.h"
|
||||
#include "LIEF/PE/Section.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @brief LIEF::PE::Binary C Handler */
|
||||
struct Pe_Binary_t {
|
||||
void* handler;
|
||||
const char* name;
|
||||
Pe_DosHeader_t dos_header;
|
||||
Pe_Header_t header;
|
||||
Pe_OptionalHeader_t optional_header;
|
||||
Pe_DataDirectory_t** data_directories;
|
||||
Pe_Section_t** sections;
|
||||
};
|
||||
|
||||
typedef struct Pe_Binary_t Pe_Binary_t;
|
||||
|
||||
/** @brief Wrapper on LIEF::PE::Parser::parse */
|
||||
DLL_PUBLIC Pe_Binary_t* pe_parse(const char *file);
|
||||
|
||||
DLL_PUBLIC void pe_binary_destroy(Pe_Binary_t* binary);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/** @} */
|
||||
#endif
|
47
api/c/include/LIEF/PE/DataDirectory.h
Normal file
47
api/c/include/LIEF/PE/DataDirectory.h
Normal file
@ -0,0 +1,47 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_PE_DATA_DIRECTORY_H_
|
||||
#define C_LIEF_PE_DATA_DIRECTORY_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "LIEF/PE/enums.h"
|
||||
/** @defgroup pe_data_directory_c_api Section
|
||||
* @ingroup pe_c_api
|
||||
* @addtogroup pe_data_directory_c_api
|
||||
* @brief Data directory C API
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Pe_DataDirectory_t {
|
||||
uint32_t rva;
|
||||
uint32_t size;
|
||||
};
|
||||
|
||||
typedef struct Pe_DataDirectory_t Pe_DataDirectory_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif
|
63
api/c/include/LIEF/PE/DosHeader.h
Normal file
63
api/c/include/LIEF/PE/DosHeader.h
Normal file
@ -0,0 +1,63 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_PE_DOS_HEADER_H_
|
||||
#define C_LIEF_PE_DOS_HEADER_H_
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "LIEF/ELF/enums.h"
|
||||
/** @defgroup pe_dos_header_c_api DosHeader
|
||||
* @ingroup pe_c_api
|
||||
* @addtogroup pe_dos_header_c_api
|
||||
* @brief Dos Header C API
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Pe_DosHeader_t {
|
||||
uint16_t magic ;
|
||||
uint16_t used_bytes_in_the_last_page;
|
||||
uint16_t file_size_in_pages;
|
||||
uint16_t numberof_relocation;
|
||||
uint16_t header_size_in_paragraphs;
|
||||
uint16_t minimum_extra_paragraphs;
|
||||
uint16_t maximum_extra_paragraphs;
|
||||
uint16_t initial_relative_ss;
|
||||
uint16_t initial_sp;
|
||||
uint16_t checksum;
|
||||
uint16_t initial_ip;
|
||||
uint16_t initial_relative_cs;
|
||||
uint16_t addressof_relocation_table;
|
||||
uint16_t overlay_number;
|
||||
uint16_t reserved[4];
|
||||
uint16_t oem_id;
|
||||
uint16_t oem_info;
|
||||
uint16_t reserved2[10];
|
||||
uint32_t addressof_new_exeheader;
|
||||
};
|
||||
|
||||
typedef struct Pe_DosHeader_t Pe_DosHeader_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif
|
37
api/c/include/LIEF/PE/EnumToString.h
Normal file
37
api/c/include/LIEF/PE/EnumToString.h
Normal file
@ -0,0 +1,37 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_PE_ENUM_TO_STRING_H_
|
||||
#define C_LIEF_PE_ENUM_TO_STRING_H_
|
||||
|
||||
#include "LIEF/visibility.h"
|
||||
|
||||
#include "LIEF/PE/enums.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
DLL_PUBLIC const char* PE_TYPES_to_string(enum PE_TYPES e);
|
||||
DLL_PUBLIC const char* MACHINE_TYPES_to_string(enum MACHINE_TYPES e);
|
||||
DLL_PUBLIC const char* SUBSYSTEM_to_string(enum SUBSYSTEM e);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
53
api/c/include/LIEF/PE/Header.h
Normal file
53
api/c/include/LIEF/PE/Header.h
Normal file
@ -0,0 +1,53 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_PE_HEADER_H_
|
||||
#define C_LIEF_PE_HEADER_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "LIEF/PE/enums.h"
|
||||
/** @defgroup pe_header_c_api Header
|
||||
* @ingroup pe_c_api
|
||||
* @addtogroup pe_header_c_api
|
||||
* @brief Header C API
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Pe_Header_t {
|
||||
uint8_t signature[4];
|
||||
enum MACHINE_TYPES machine;
|
||||
uint16_t numberof_sections;
|
||||
uint32_t time_date_stamp;
|
||||
uint32_t pointerto_symbol_table;
|
||||
uint32_t numberof_symbols;
|
||||
uint16_t sizeof_optional_header;
|
||||
uint16_t characteristics;
|
||||
};
|
||||
|
||||
typedef struct Pe_Header_t Pe_Header_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif
|
74
api/c/include/LIEF/PE/OptionalHeader.h
Normal file
74
api/c/include/LIEF/PE/OptionalHeader.h
Normal file
@ -0,0 +1,74 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_PE_OPTIONAL_HEADER_H_
|
||||
#define C_LIEF_PE_OPTIONAL_HEADER_H_
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "LIEF/PE/enums.h"
|
||||
/** @defgroup pe_optional_header_c_api OptionalHeader
|
||||
* @ingroup pe_c_api
|
||||
* @addtogroup pe_optional_header_c_api
|
||||
* @brief OptionalHeader C API
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Pe_OptionalHeader_t {
|
||||
enum PE_TYPES magic;
|
||||
uint8_t major_linker_version;
|
||||
uint8_t minor_linker_version;
|
||||
uint32_t sizeof_code;
|
||||
uint32_t sizeof_initialized_data;
|
||||
uint32_t sizeof_uninitialized_data;
|
||||
uint32_t addressof_entrypoint;
|
||||
uint32_t baseof_code;
|
||||
uint32_t baseof_data;
|
||||
uint64_t imagebase;
|
||||
uint32_t section_alignment;
|
||||
uint32_t file_alignment;
|
||||
uint16_t major_operating_system_version;
|
||||
uint16_t minor_operating_system_version;
|
||||
uint16_t major_image_version;
|
||||
uint16_t minor_image_version;
|
||||
uint16_t major_subsystem_version;
|
||||
uint16_t minor_subsystem_version;
|
||||
uint32_t win32_version_value;
|
||||
uint32_t sizeof_image;
|
||||
uint32_t sizeof_headers;
|
||||
uint32_t checksum;
|
||||
enum SUBSYSTEM subsystem;
|
||||
uint32_t dll_characteristics;
|
||||
uint64_t sizeof_stack_reserve;
|
||||
uint64_t sizeof_stack_commit;
|
||||
uint64_t sizeof_heap_reserve;
|
||||
uint64_t sizeof_heap_commit;
|
||||
uint32_t loader_flags;
|
||||
uint32_t numberof_rva_and_size;
|
||||
};
|
||||
|
||||
typedef struct Pe_OptionalHeader_t Pe_OptionalHeader_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif
|
58
api/c/include/LIEF/PE/Section.h
Normal file
58
api/c/include/LIEF/PE/Section.h
Normal file
@ -0,0 +1,58 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef C_LIEF_PE_SECTION_H_
|
||||
#define C_LIEF_PE_SECTION_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "LIEF/PE/enums.h"
|
||||
/** @defgroup pe_section_c_api Section
|
||||
* @ingroup pe_c_api
|
||||
* @addtogroup pe_section_c_api
|
||||
* @brief Section C API
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Pe_Section_t {
|
||||
const char* name;
|
||||
uint64_t virtual_address;
|
||||
uint64_t size;
|
||||
uint64_t offset;
|
||||
|
||||
uint32_t virtual_size;
|
||||
uint32_t pointerto_relocation;
|
||||
uint32_t pointerto_line_numbers;
|
||||
uint32_t characteristics;
|
||||
|
||||
uint8_t* content;
|
||||
double entropy;
|
||||
|
||||
};
|
||||
|
||||
typedef struct Pe_Section_t Pe_Section_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif
|
20
api/c/include/LIEF/PE/enums.h.in
Normal file
20
api/c/include/LIEF/PE/enums.h.in
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef LIEF_PE_C_ENUMS_H_
|
||||
#define LIEF_PE_C_ENUMS_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@LIEF_PE_ENUMS@
|
||||
|
||||
|
||||
enum PE_TYPES {
|
||||
PE32 = 0x10b, /** 32bits */
|
||||
PE32_PLUS = 0x20b /** 64 bits */
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
14
api/c/include/LIEF/PE/structures.h.in
Normal file
14
api/c/include/LIEF/PE/structures.h.in
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef LIEF_PE_C_STRUCTURES_H_
|
||||
#define LIEF_PE_C_STRUCTURES_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@LIEF_PE_STRUCTURES@
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
26
api/python/Abstract/init.cpp
Normal file
26
api/python/Abstract/init.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "pyLIEF.hpp"
|
||||
#include "init.hpp"
|
||||
|
||||
void init_LIEF_module(py::module& m) {
|
||||
init_LIEF_Enum(m);
|
||||
init_LIEF_Header_class(m);
|
||||
init_LIEF_Binary_class(m);
|
||||
init_LIEF_Section_class(m);
|
||||
init_LIEF_Symbol_class(m);
|
||||
init_LIEF_Parser_class(m);
|
||||
}
|
28
api/python/Abstract/init.hpp
Normal file
28
api/python/Abstract/init.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef PY_LIEF_INIT_H_
|
||||
#define PY_LIEF_INIT_H_
|
||||
|
||||
#include "pyLIEF.hpp"
|
||||
|
||||
void init_LIEF_Enum(py::module&);
|
||||
void init_LIEF_Header_class(py::module&);
|
||||
void init_LIEF_Binary_class(py::module&);
|
||||
void init_LIEF_Section_class(py::module&);
|
||||
void init_LIEF_Symbol_class(py::module&);
|
||||
void init_LIEF_Parser_class(py::module&);
|
||||
|
||||
#endif
|
102
api/python/Abstract/objects/pyBinary.cpp
Normal file
102
api/python/Abstract/objects/pyBinary.cpp
Normal file
@ -0,0 +1,102 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "init.hpp"
|
||||
#include "LIEF/Abstract/Binary.hpp"
|
||||
#include "LIEF/ELF/Binary.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using namespace LIEF;
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (Binary::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (Binary::*)(T);
|
||||
|
||||
template<class T>
|
||||
using it_t = T (Binary::*)(void);
|
||||
|
||||
void init_LIEF_Binary_class(py::module& m) {
|
||||
py::class_<Binary>(m, "Binary")
|
||||
.def_property("name",
|
||||
static_cast<getter_t<const std::string&>>(&Binary::name),
|
||||
static_cast<setter_t<const std::string&>>(&Binary::name),
|
||||
"Binary's name")
|
||||
|
||||
.def_property_readonly("header",
|
||||
&Binary::get_header,
|
||||
"Binary's header")
|
||||
|
||||
.def_property_readonly("entrypoint",
|
||||
&Binary::entrypoint,
|
||||
"Binary's entrypoint")
|
||||
|
||||
.def_property_readonly("sections",
|
||||
static_cast<it_t<it_sections>>(&Binary::get_sections),
|
||||
"Return a list in **read only** of binary's abstract " RST_CLASS_REF(lief.Section) "",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
.def_property_readonly("exported_functions",
|
||||
&Binary::get_exported_functions,
|
||||
"Return binary's exported functions (name)")
|
||||
|
||||
.def_property_readonly("imported_functions",
|
||||
&Binary::get_imported_functions,
|
||||
"Return binary's imported functions (name)")
|
||||
|
||||
.def_property_readonly("libraries",
|
||||
&Binary::get_imported_libraries,
|
||||
"Return binary's imported libraries (name)")
|
||||
|
||||
.def_property_readonly("symbols",
|
||||
static_cast<it_t<it_symbols>>(&Binary::get_symbols),
|
||||
"Return a list in **read only** of binary's abstract " RST_CLASS_REF(lief.Symbol) "",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
.def("get_function_address",
|
||||
&Binary::get_function_address,
|
||||
"Return the address of the given function name")
|
||||
|
||||
.def("patch_address",
|
||||
static_cast<void (Binary::*) (uint64_t, const std::vector<uint8_t>&)>(&Binary::patch_address),
|
||||
"Patch the address with the given value",
|
||||
py::arg("address"), py::arg("patch_value"))
|
||||
|
||||
.def("patch_address",
|
||||
static_cast<void (Binary::*) (uint64_t, uint64_t, size_t)>(&Binary::patch_address),
|
||||
"Patch the address with the given value",
|
||||
py::arg("address"), py::arg("patch_value"), py::arg_v("size", 8))
|
||||
|
||||
|
||||
.def("get_content_from_virtual_address",
|
||||
&Binary::get_content_from_virtual_address,
|
||||
"Return the content located at virtual address")
|
||||
|
||||
|
||||
.def("__str__",
|
||||
[] (const Binary& binary)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << binary;
|
||||
std::string str = stream.str();
|
||||
return str;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
51
api/python/Abstract/objects/pyHeader.cpp
Normal file
51
api/python/Abstract/objects/pyHeader.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <sstream>
|
||||
|
||||
#include "init.hpp"
|
||||
#include "LIEF/Abstract/Header.hpp"
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (LIEF::Header::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (LIEF::Header::*)(T);
|
||||
|
||||
void init_LIEF_Header_class(py::module& m) {
|
||||
py::class_<LIEF::Header>(m, "Header")
|
||||
.def(py::init())
|
||||
|
||||
.def_property("architecture",
|
||||
static_cast<getter_t<LIEF::ARCHITECTURES>>(&LIEF::Header::architecture),
|
||||
static_cast<setter_t<LIEF::ARCHITECTURES>>(&LIEF::Header::architecture),
|
||||
"Target's architecture")
|
||||
|
||||
|
||||
.def_property("entrypoint",
|
||||
static_cast<getter_t<uint64_t>>(&LIEF::Header::entrypoint),
|
||||
static_cast<setter_t<uint64_t>>(&LIEF::Header::entrypoint),
|
||||
"Binary's entrypoint")
|
||||
|
||||
|
||||
.def("__str__",
|
||||
[] (const LIEF::Header& header)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << header;
|
||||
std::string str = stream.str();
|
||||
return str;
|
||||
});
|
||||
}
|
28
api/python/Abstract/objects/pyParser.cpp
Normal file
28
api/python/Abstract/objects/pyParser.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "init.hpp"
|
||||
|
||||
#include "LIEF/Abstract/Parser.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
void init_LIEF_Parser_class(py::module& m) {
|
||||
|
||||
m.def("parse",
|
||||
&LIEF::Parser::parse,
|
||||
"Parse the given binary and return a " RST_CLASS_REF(lief.Binary) " object",
|
||||
py::return_value_policy::take_ownership);
|
||||
}
|
57
api/python/Abstract/objects/pySection.cpp
Normal file
57
api/python/Abstract/objects/pySection.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "init.hpp"
|
||||
#include "LIEF/Abstract/Section.hpp"
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (LIEF::Section::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (LIEF::Section::*)(T);
|
||||
|
||||
void init_LIEF_Section_class(py::module& m) {
|
||||
py::class_<LIEF::Section>(m, "Section")
|
||||
.def(py::init())
|
||||
|
||||
.def_property("name",
|
||||
static_cast<getter_t<const std::string&>>(&LIEF::Section::name),
|
||||
static_cast<setter_t<const std::string&>>(&LIEF::Section::name),
|
||||
"Section's name")
|
||||
|
||||
.def_property("size",
|
||||
static_cast<getter_t<uint64_t>>(&LIEF::Section::size),
|
||||
static_cast<setter_t<uint64_t>>(&LIEF::Section::size),
|
||||
"Section's size")
|
||||
|
||||
.def_property("offset",
|
||||
static_cast<getter_t<uint64_t>>(&LIEF::Section::offset),
|
||||
static_cast<setter_t<uint64_t>>(&LIEF::Section::offset),
|
||||
"Section's offset")
|
||||
|
||||
.def_property("virtual_address",
|
||||
static_cast<getter_t<uint64_t>>(&LIEF::Section::virtual_address),
|
||||
static_cast<setter_t<uint64_t>>(&LIEF::Section::virtual_address),
|
||||
"Section's size")
|
||||
|
||||
.def_property("content",
|
||||
static_cast<getter_t<std::vector<uint8_t>>>(&LIEF::Section::content),
|
||||
static_cast<setter_t<const std::vector<uint8_t>&>>(&LIEF::Section::content),
|
||||
"section's content")
|
||||
|
||||
.def_property_readonly("entropy",
|
||||
&LIEF::Section::entropy,
|
||||
"Section's entropy");
|
||||
}
|
61
api/python/Abstract/objects/pySymbol.cpp
Normal file
61
api/python/Abstract/objects/pySymbol.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "init.hpp"
|
||||
#include "LIEF/Abstract/Symbol.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
template<class T>
|
||||
using getter_t = const T& (LIEF::Symbol::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (LIEF::Symbol::*)(const T&);
|
||||
|
||||
|
||||
class PySymbol : public LIEF::Symbol {
|
||||
public:
|
||||
using LIEF::Symbol::Symbol;
|
||||
|
||||
virtual const std::string& name(void) const override {
|
||||
PYBIND11_OVERLOAD(const std::string&, LIEF::Symbol, name,);
|
||||
};
|
||||
|
||||
virtual void name(const std::string& name) override {
|
||||
PYBIND11_OVERLOAD(void, LIEF::Symbol, name, name);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
void init_LIEF_Symbol_class(py::module& m) {
|
||||
|
||||
py::class_<LIEF::Symbol, PySymbol>(m, "Symbol")
|
||||
.def(py::init())
|
||||
|
||||
.def_property("name",
|
||||
static_cast<getter_t<std::string>>(&LIEF::Symbol::name),
|
||||
static_cast<setter_t<std::string>>(&LIEF::Symbol::name),
|
||||
"Symbol's name")
|
||||
|
||||
.def("__str__",
|
||||
[] (const LIEF::Symbol& symbol)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << symbol;
|
||||
std::string str = stream.str();
|
||||
return str;
|
||||
});
|
||||
}
|
28
api/python/Abstract/pyEnums.cpp
Normal file
28
api/python/Abstract/pyEnums.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "init.hpp"
|
||||
#include "LIEF/Abstract/enums.hpp"
|
||||
#include "LIEF/Abstract/EnumToString.hpp"
|
||||
|
||||
#define PY_ENUM(x) LIEF::to_string(x), x
|
||||
|
||||
void init_LIEF_Enum(py::module& m) {
|
||||
py::enum_<LIEF::FILE_FORMATS>(m, "FILE_FORMATS")
|
||||
.value(PY_ENUM(LIEF::FILE_FORMATS::FORMAT_ELF))
|
||||
.value(PY_ENUM(LIEF::FILE_FORMATS::FORMAT_PE))
|
||||
.value(PY_ENUM(LIEF::FILE_FORMATS::FORMAT_MACHO))
|
||||
.export_values();
|
||||
}
|
164
api/python/CMakeLists.txt
Normal file
164
api/python/CMakeLists.txt
Normal file
@ -0,0 +1,164 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
include(ExternalProject)
|
||||
|
||||
|
||||
set(Python_ADDITIONAL_VERSIONS 2.7 2.7.6 3.4 3.5 3.6 3.7)
|
||||
if (NOT ${PYTHON_VERSION} STREQUAL "")
|
||||
find_package(PythonLibs ${PYTHON_VERSION} EXACT)
|
||||
|
||||
if (NOT PythonLibs_FOUND)
|
||||
find_package(PythonLibs ${PYTHON_VERSION})
|
||||
endif()
|
||||
|
||||
set(PYTHONLIBS_VERSION_STRING "${PYTHON_VERSION}")
|
||||
if (NOT PythonLibs_FOUND)
|
||||
# WARNING: DIRTY HACK
|
||||
# ^^^^^^^^^^^^^^^^^^^
|
||||
if ((${PYTHON_VERSION} VERSION_GREATER "3") OR (${PYTHON_VERSION} VERSION_EQUAL "3"))
|
||||
if (UNIX)
|
||||
set(PYTHON_LIBRARY /usr/lib/libpython${PYTHON_VERSION}.so)
|
||||
if(EXISTS "/usr/include/python${PYTHON_VERSION}" AND IS_DIRECTORY "/usr/include/python${PYTHON_VERSION}")
|
||||
set(PYTHON_INCLUDE_DIR /usr/include/python${PYTHON_VERSION})
|
||||
set(PYTHONLIBS_VERSION_STRING "${PYTHON_VERSION}")
|
||||
elseif(EXISTS "/usr/include/python${PYTHON_VERSION}m" AND IS_DIRECTORY "/usr/include/python${PYTHON_VERSION}m")
|
||||
set(PYTHON_INCLUDE_DIR /usr/include/python${PYTHON_VERSION}m)
|
||||
set(PYTHONLIBS_VERSION_STRING "${PYTHON_VERSION}m")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
find_package(PythonLibs REQUIRED)
|
||||
endif()
|
||||
|
||||
|
||||
message(STATUS "Python version: ${PYTHONLIBS_VERSION_STRING}")
|
||||
message(STATUS "Python lib: ${PYTHON_LIBRARY}")
|
||||
message(STATUS "Python include: ${PYTHON_INCLUDE_DIR}")
|
||||
|
||||
|
||||
set(PYBIND11_GIT_URL "https://github.com/pybind/pybind11.git" CACHE STRING "URL to the Pybind11 repo")
|
||||
ExternalProject_Add(pybind11
|
||||
GIT_REPOSITORY ${PYBIND11_GIT_URL}
|
||||
GIT_TAG v2.0.1
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND "")
|
||||
ExternalProject_get_property(pybind11 SOURCE_DIR)
|
||||
set(PYBIND11_SOURCE_DIR ${SOURCE_DIR})
|
||||
|
||||
|
||||
# Define source files
|
||||
set(LIEF_PYTHON_SRC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/pyLIEF.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/pyUtils.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/pyJson.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/pyIterators.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/pyExceptions.cpp
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Abstract/init.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects/pyBinary.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects/pyHeader.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects/pySection.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects/pyParser.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects/pySymbol.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Abstract/pyEnums.cpp
|
||||
)
|
||||
|
||||
|
||||
add_library(pyLIEF SHARED ${LIEF_PYTHON_SRC})
|
||||
|
||||
|
||||
target_include_directories(pyLIEF PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Abstract
|
||||
${PYTHON_INCLUDE_DIR}
|
||||
${PYBIND11_SOURCE_DIR}/include)
|
||||
|
||||
add_definitions(-DELPP_NO_DEFAULT_LOG_FILE)
|
||||
|
||||
if(LIEF_ELF)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/ELF/CMakeLists.txt)
|
||||
endif()
|
||||
|
||||
if(LIEF_PE)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/PE/CMakeLists.txt)
|
||||
endif()
|
||||
|
||||
if(LIEF_MACHO)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/MachO/CMakeLists.txt)
|
||||
endif()
|
||||
|
||||
|
||||
target_compile_features(pyLIEF PRIVATE cxx_attribute_deprecated)
|
||||
|
||||
set_property(TARGET pyLIEF PROPERTY CXX_STANDARD 11)
|
||||
set_property(TARGET pyLIEF PROPERTY CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
if (MSVC)
|
||||
target_compile_options(pyLIEF PUBLIC /FIiso646.h)
|
||||
set_property(TARGET pyLIEF PROPERTY LINK_FLAGS /NODEFAULTLIB:MSVCRT)
|
||||
endif()
|
||||
|
||||
set_target_properties(pyLIEF PROPERTIES PYTHON_VERSION ${PYTHONLIBS_VERSION_STRING})
|
||||
set(PYLIEF_DEPS_LIBRARIES LIB_LIEF_STATIC)
|
||||
|
||||
if(LIEF_COVERAGE)
|
||||
target_compile_options(pyLIEF PRIVATE -g -O0 --coverage -fprofile-arcs -ftest-coverage)
|
||||
set(PYLIEF_DEPS_LIBRARIES ${PYLIEF_DEPS_LIBRARIES} gcov)
|
||||
endif()
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
target_compile_options(pyLIEF PRIVATE -Wall -Wextra -Wpedantic -Wno-macro-redefined)
|
||||
endif()
|
||||
|
||||
set_target_properties(pyLIEF PROPERTIES PREFIX "" OUTPUT_NAME "lief")
|
||||
add_dependencies(pyLIEF pybind11)
|
||||
|
||||
if(APPLE)
|
||||
set_target_properties(pyLIEF PROPERTIES MACOSX_RPATH ".")
|
||||
set_target_properties(pyLIEF PROPERTIES LINK_FLAGS "-undefined dynamic_lookup ")
|
||||
endif()
|
||||
|
||||
set_target_properties(pyLIEF PROPERTIES PREFIX "")
|
||||
if (UNIX)
|
||||
set_target_properties(pyLIEF PROPERTIES SUFFIX ".so")
|
||||
elseif(WIN32)
|
||||
set_target_properties(pyLIEF PROPERTIES SUFFIX ".pyd")
|
||||
endif()
|
||||
|
||||
get_target_property(suffix pyLIEF SUFFIX)
|
||||
set(LIEF_LIBRARY_NAME "lief${suffix}")
|
||||
|
||||
if (WIN32)
|
||||
set(PYLIEF_DEPS_LIBRARIES ${PYLIEF_DEPS_LIBRARIES} ${PYTHON_LIBRARIES})
|
||||
endif()
|
||||
|
||||
target_link_libraries(pyLIEF PUBLIC ${PYLIEF_DEPS_LIBRARIES})
|
||||
|
||||
add_custom_command(TARGET pyLIEF POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:pyLIEF> ${PROJECT_BINARY_DIR}/api/python/
|
||||
)
|
||||
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in" "${CMAKE_CURRENT_BINARY_DIR}/setup.py")
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.in" "${CMAKE_CURRENT_BINARY_DIR}/__init__.py")
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/README.in" "${CMAKE_CURRENT_BINARY_DIR}/README")
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/MANIFEST.in.in" "${CMAKE_CURRENT_BINARY_DIR}/MANIFEST.in")
|
||||
|
||||
MESSAGE(STATUS "OS: ${CMAKE_HOST_SYSTEM}")
|
||||
|
||||
find_program(ENV_BINARY "env")
|
||||
|
||||
if (UNIX AND ENV_BINARY AND LIEF_INSTALL_PYTHON)
|
||||
if ((${PYTHONLIBS_VERSION_STRING} VERSION_GREATER "3") OR (${PYTHONLIBS_VERSION_STRING} VERSION_EQUAL "3"))
|
||||
install(CODE "execute_process(COMMAND ${ENV_BINARY} python3 ${CMAKE_CURRENT_BINARY_DIR}/setup.py install)"
|
||||
COMPONENT python)
|
||||
else()
|
||||
install(
|
||||
CODE "execute_process(COMMAND ${ENV_BINARY} python2 ${CMAKE_CURRENT_BINARY_DIR}/setup.py install)"
|
||||
COMPONENT python)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
29
api/python/ELF/CMakeLists.txt
Normal file
29
api/python/ELF/CMakeLists.txt
Normal file
@ -0,0 +1,29 @@
|
||||
set(LIEF_PYTHON_ELF_SRC
|
||||
${CMAKE_CURRENT_LIST_DIR}/pyELF.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/objects/pyDynamicEntry.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/objects/pySymbolVersionAuxRequirement.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/objects/pySymbolVersion.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/objects/pyDynamicEntryRunPath.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/objects/pySymbolVersionRequirement.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/objects/pyBinary.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/objects/pySymbolVersionDefinition.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/objects/pyHeader.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/objects/pySymbolVersionAux.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/objects/pyDynamicEntryArray.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/objects/pySegment.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/objects/pySection.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/objects/pyDynamicEntryRpath.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/objects/pyRelocation.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/objects/pyDynamicSharedObject.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/objects/pyParser.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/objects/pyDynamicEntryLibrary.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/objects/pySymbol.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/objects/pyGnuHash.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/objects/pyBuilder.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/pyELFStructures.cpp
|
||||
)
|
||||
|
||||
target_sources(pyLIEF PRIVATE ${LIEF_PYTHON_ELF_SRC})
|
||||
target_include_directories(pyLIEF PUBLIC ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
|
215
api/python/ELF/objects/pyBinary.cpp
Normal file
215
api/python/ELF/objects/pyBinary.cpp
Normal file
@ -0,0 +1,215 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <algorithm>
|
||||
|
||||
#include "LIEF/ELF/Binary.hpp"
|
||||
#include "LIEF/Abstract/Binary.hpp"
|
||||
|
||||
#include "pyELF.hpp"
|
||||
|
||||
template<class T>
|
||||
using no_const_getter = T (Binary::*)(void);
|
||||
|
||||
template<class T, class P>
|
||||
using no_const_func = T (Binary::*)(P);
|
||||
|
||||
void init_ELF_Binary_class(py::module& m) {
|
||||
|
||||
// Binary object
|
||||
py::class_<Binary, LIEF::Binary>(m, "Binary", "ELF binary representation")
|
||||
.def(py::init<const std::string &, ELF_CLASS>())
|
||||
|
||||
.def_property_readonly("type",
|
||||
&Binary::type)
|
||||
|
||||
.def_property_readonly("header",
|
||||
static_cast<no_const_getter<Header&>>(&Binary::get_header),
|
||||
"Return " RST_CLASS_REF(lief.ELF.Header) " object",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
.def_property_readonly("sections",
|
||||
static_cast<no_const_getter<it_sections>>(&Binary::get_sections),
|
||||
"Return binary's " RST_CLASS_REF(lief.ELF.Section) "",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
.def_property_readonly("segments",
|
||||
static_cast<no_const_getter<it_segments>>(&Binary::get_segments),
|
||||
"Return binary's " RST_CLASS_REF(lief.ELF.Segment) "",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
.def_property_readonly("dynamic_entries",
|
||||
static_cast<no_const_getter<it_dynamic_entries>>(&Binary::get_dynamic_entries),
|
||||
"Return " RST_CLASS_REF(lief.ELF.DynamicEntry) " entries as a list",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
.def_property_readonly("static_symbols",
|
||||
static_cast<no_const_getter<it_symbols>>(&Binary::get_static_symbols),
|
||||
"Return static's " RST_CLASS_REF(lief.ELF.Symbol) "",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
.def_property_readonly("dynamic_symbols",
|
||||
static_cast<no_const_getter<it_symbols>>(&Binary::get_dynamic_symbols),
|
||||
"Return dynamic's " RST_CLASS_REF(lief.ELF.Symbol) "",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
.def_property_readonly("exported_symbols",
|
||||
static_cast<no_const_getter<it_exported_symbols>>(&Binary::get_exported_symbols),
|
||||
"Return dynamic's " RST_CLASS_REF(lief.ELF.Symbol) " which are exported",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
.def_property_readonly("imported_symbols",
|
||||
static_cast<no_const_getter<it_imported_symbols>>(&Binary::get_imported_symbols),
|
||||
"Return dynamic's " RST_CLASS_REF(lief.ELF.Symbol) " which are imported",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
.def_property_readonly("dynamic_relocations",
|
||||
static_cast<no_const_getter<it_relocations>>(&Binary::get_dynamic_relocations),
|
||||
"Return PLT/GOT " RST_CLASS_REF(lief.ELF.Relocation) "",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
.def_property_readonly("pltgot_relocations",
|
||||
static_cast<no_const_getter<it_relocations>>(&Binary::get_pltgot_relocations),
|
||||
"Return dynamics " RST_CLASS_REF(lief.ELF.Relocation) "",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
.def_property_readonly("symbols_version",
|
||||
static_cast<no_const_getter<it_symbols_version>>(&Binary::get_symbols_version),
|
||||
"Return " RST_CLASS_REF(lief.ELF.SymbolVersion) "",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
.def_property_readonly("symbols_version_requirement",
|
||||
static_cast<no_const_getter<it_symbols_version_requirement>>(&Binary::get_symbols_version_requirement),
|
||||
"Return " RST_CLASS_REF(lief.ELF.SymbolVersionRequirement) "",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
.def_property_readonly("symbols_version_definition",
|
||||
static_cast<no_const_getter<it_symbols_version_definition>>(&Binary::get_symbols_version_definition),
|
||||
"Return " RST_CLASS_REF(lief.ELF.SymbolVersionDefinition) "",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
.def_property_readonly("gnu_hash",
|
||||
&Binary::get_gnu_hash,
|
||||
"Return " RST_CLASS_REF(lief.ELF.GnuHash) " object",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
.def_property_readonly("imagebase",
|
||||
&Binary::get_imagebase,
|
||||
"Return the program image base. (e.g. 0x400000)")
|
||||
|
||||
.def_property_readonly("virtual_size",
|
||||
&Binary::get_virtual_size,
|
||||
"Return the binary's size when mapped in memory")
|
||||
|
||||
.def_property_readonly("is_pie",
|
||||
&Binary::is_pie,
|
||||
"Check if the binary is a ``pie`` one")
|
||||
|
||||
.def_property_readonly("has_interpreter",
|
||||
&Binary::has_interpreter,
|
||||
"Check if the binary uses a loader")
|
||||
|
||||
.def_property_readonly("interpreter",
|
||||
&Binary::get_interpreter,
|
||||
"Return ELF interprer if any. (e.g. ``/lib64/ld-linux-x86-64.so.2``)")
|
||||
|
||||
.def("section_from_offset",
|
||||
static_cast<no_const_func<Section&, uint64_t>>(&Binary::section_from_offset),
|
||||
"Return binary's " RST_CLASS_REF(lief.ELF.Section) " which holds the offset",
|
||||
"address"_a,
|
||||
py::return_value_policy::reference)
|
||||
|
||||
.def("section_from_virtual_address",
|
||||
static_cast<no_const_func<Section&, uint64_t>>(&Binary::section_from_virtual_address),
|
||||
"Return binary's " RST_CLASS_REF(lief.ELF.Section) " which holds the given virtual address",
|
||||
py::return_value_policy::reference)
|
||||
|
||||
.def("segment_from_virtual_address",
|
||||
static_cast<no_const_func<Segment&, uint64_t>>(&Binary::segment_from_virtual_address),
|
||||
"Return binary's " RST_CLASS_REF(lief.ELF.Segment) " which holds the address",
|
||||
py::return_value_policy::reference)
|
||||
|
||||
.def("segment_from_offset",
|
||||
static_cast<no_const_func<Segment&, uint64_t>>(&Binary::segment_from_offset),
|
||||
"Return binary's " RST_CLASS_REF(lief.ELF.Segment) " which holds the offset",
|
||||
py::return_value_policy::reference)
|
||||
|
||||
.def("dynamic_entry_from_tag",
|
||||
static_cast<no_const_func<DynamicEntry&, DYNAMIC_TAGS>>(&Binary::dynamic_entry_from_tag),
|
||||
"Return first binary's " RST_CLASS_REF(lief.ELF.DynamicEntry) " given its tag",
|
||||
py::return_value_policy::reference)
|
||||
|
||||
.def("has_dynamic_entry",
|
||||
&Binary::has_dynamic_entry,
|
||||
"Check if the " RST_CLASS_REF(lief.ELF.DynamicEntry) " associated with the given tag exists")
|
||||
|
||||
.def("patch_pltgot",
|
||||
static_cast<void (Binary::*) (const std::string&, uint64_t)>(&Binary::patch_pltgot),
|
||||
"Patch the imported symbol's name with the ``address``")
|
||||
|
||||
.def("patch_pltgot",
|
||||
static_cast<void (Binary::*) (const Symbol&, uint64_t)>(&Binary::patch_pltgot),
|
||||
"Patch the imported symbol's name with the ``address``")
|
||||
|
||||
.def("has_section",
|
||||
&Binary::has_section,
|
||||
"Check if a section with the given name exists in the binary")
|
||||
|
||||
.def("get_section",
|
||||
static_cast<no_const_func<Section&, const std::string&>>(&Binary::get_section),
|
||||
py::return_value_policy::reference)
|
||||
|
||||
.def("add_static_symbol",
|
||||
&Binary::add_static_symbol,
|
||||
py::return_value_policy::reference)
|
||||
|
||||
.def("virtual_address_to_offset",
|
||||
&Binary::virtual_address_to_offset,
|
||||
"Convert the virtual address to an offset in the binary")
|
||||
|
||||
.def("add_section",
|
||||
&Binary::add_section,
|
||||
"Add a section in the binary",
|
||||
py::return_value_policy::reference)
|
||||
|
||||
.def("add_segment",
|
||||
&Binary::add_segment,
|
||||
"Add a segment in the binary",
|
||||
py::arg("segment"), py::arg_v("base", 0x400000), py::arg_v("force_note", false),
|
||||
py::return_value_policy::reference)
|
||||
|
||||
.def("insert_content",
|
||||
&Binary::insert_content,
|
||||
"Add some datas in the binary")
|
||||
|
||||
.def("strip",
|
||||
&Binary::strip,
|
||||
"Strip the binary")
|
||||
|
||||
.def("write",
|
||||
&Binary::write,
|
||||
"Rebuild the binary and write it in a file",
|
||||
py::return_value_policy::reference_internal)
|
||||
|
||||
|
||||
.def("__str__",
|
||||
[] (const Binary& binary)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << binary;
|
||||
std::string str = stream.str();
|
||||
return str;
|
||||
});
|
||||
}
|
41
api/python/ELF/objects/pyBuilder.cpp
Normal file
41
api/python/ELF/objects/pyBuilder.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "pyELF.hpp"
|
||||
|
||||
#include "LIEF/ELF/Builder.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
void init_ELF_Builder_class(py::module& m) {
|
||||
py::class_<Builder>(m, "Builder")
|
||||
.def(py::init<Binary*>())
|
||||
|
||||
.def("build", static_cast<void (Builder::*)(void)>(&Builder::build))
|
||||
|
||||
.def("empties_gnuhash",
|
||||
&Builder::empties_gnuhash,
|
||||
py::return_value_policy::reference)
|
||||
|
||||
.def("write",
|
||||
&Builder::write)
|
||||
|
||||
.def("get_build",
|
||||
&Builder::get_build,
|
||||
py::return_value_policy::reference_internal);
|
||||
|
||||
}
|
66
api/python/ELF/objects/pyDynamicEntry.cpp
Normal file
66
api/python/ELF/objects/pyDynamicEntry.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
/* Copyright 2017 R. Thomas
|
||||
* Copyright 2017 Quarkslab
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "pyELF.hpp"
|
||||
|
||||
#include "LIEF/ELF/DynamicEntry.hpp"
|
||||
#include "LIEF/visitors/Hash.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
template<class T>
|
||||
using getter_t = T (DynamicEntry::*)(void) const;
|
||||
|
||||
template<class T>
|
||||
using setter_t = void (DynamicEntry::*)(T);
|
||||
|
||||
void init_ELF_DynamicEntry_class(py::module& m) {
|
||||
|
||||
// DynamicEntry object
|
||||
py::class_<DynamicEntry>(m, "DynamicEntry")
|
||||
.def_property("tag",
|
||||
static_cast<getter_t<DYNAMIC_TAGS>>(&DynamicEntry::tag),
|
||||
static_cast<setter_t<DYNAMIC_TAGS>>(&DynamicEntry::tag),
|
||||
"Return the entry's " RST_CLASS_REF(lief.ELF.DYNAMIC_TAGS) " which represent the entry type")
|
||||
|
||||
|
||||
.def_property("value",
|
||||
static_cast<getter_t<uint64_t>>(&DynamicEntry::value),
|
||||
static_cast<setter_t<uint64_t>>(&DynamicEntry::value),
|
||||
"Return the entry's value.")
|
||||
|
||||
.def_property("name",
|
||||
static_cast<getter_t<const std::string&>>(&DynamicEntry::name),
|
||||
static_cast<setter_t<const std::string&>>(&DynamicEntry::name),
|
||||
"Depending on the entry type, it return a name. For instance for a `DT_SONAME`\
|
||||
entry it returns the library name")
|
||||
|
||||
.def("__eq__", &DynamicEntry::operator==)
|
||||
.def("__ne__", &DynamicEntry::operator!=)
|
||||
.def("__hash__",
|
||||
[] (const DynamicEntry& entry) {
|
||||
return LIEF::Hash::hash(entry);
|
||||
})
|
||||
|
||||
.def("__str__",
|
||||
[] (const DynamicEntry& dynamicEntry)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << dynamicEntry;
|
||||
std::string str = stream.str();
|
||||
return str;
|
||||
});
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user