Projects STRLCPY LIEF Commits 306a191a
🤬
Showing first 76 files as there are too many
  • ■ ■ ■ ■ ■ ■
    .appveyor.yml
     1 +version: 0.4.{build}
     2 +image: Visual Studio 2015
     3 +clone_folder: c:\projects\lief
     4 + 
     5 +configuration: Release
     6 + 
     7 +clone_depth: 5
     8 + 
     9 +platform:
     10 +- x86
     11 +- x64
     12 + 
     13 +environment:
     14 + matrix:
     15 + # Python 2.7
     16 + - PYTHON_VERSION: "2.7"
     17 + PYTHON32_PATH: "C:\\Python27"
     18 + PYTHON32_INCLUDE: "C:\\Python27\\include"
     19 + PYTHON32_BINARY: "C:\\Python27\\python.exe"
     20 + PYTHON32_LIBRARY: "C:\\Python27\\libs\\python27.lib"
     21 + PYTHON64_PATH: "C:\\Python27-x64"
     22 + PYTHON64_INCLUDE: "C:\\Python27-x64\\include"
     23 + PYTHON64_BINARY: "C:\\Python27-x64\\python.exe"
     24 + PYTHON64_LIBRARY: "C:\\Python27-x64\\libs\\python27.lib"
     25 + 
     26 + 
     27 + # Python 3.5
     28 + - PYTHON_VERSION: "3.5"
     29 + PYTHON32_PATH: "C:\\Python35"
     30 + PYTHON32_INCLUDE: "C:\\Python35\\include"
     31 + PYTHON32_BINARY: "C:\\Python35\\python.exe"
     32 + PYTHON32_LIBRARY: "C:\\Python35\\libs\\python35.lib"
     33 + PYTHON64_PATH: "C:\\Python35-x64"
     34 + PYTHON64_INCLUDE: "C:\\Python35-x64\\include"
     35 + PYTHON64_BINARY: "C:\\Python35-x64\\python.exe"
     36 + PYTHON64_LIBRARY: "C:\\Python35-x64\\libs\\python35.lib"
     37 + 
     38 + 
     39 + # Python 3.6
     40 + - PYTHON_VERSION: "3.6"
     41 + PYTHON32_PATH: "C:\\Python36"
     42 + PYTHON32_INCLUDE: "C:\\Python36\\include"
     43 + PYTHON32_BINARY: "C:\\Python36\\python.exe"
     44 + PYTHON32_LIBRARY: "C:\\Python36\\libs\\python36.lib"
     45 + PYTHON64_PATH: "C:\\Python36-x64"
     46 + PYTHON64_INCLUDE: "C:\\Python36-x64\\include"
     47 + PYTHON64_BINARY: "C:\\Python36-x64\\python.exe"
     48 + PYTHON64_LIBRARY: "C:\\Python36-x64\\libs\\python36.lib"
     49 + 
     50 +matrix:
     51 + fast_finish: true # set this flag to immediately finish build once one of the jobs fails.
     52 + allow_failures:
     53 + - platform: x86
     54 + configuration: Release
     55 + - platform: x64
     56 + configuration: Release
     57 + 
     58 +install:
     59 + - ps: if ($env:PLATFORM -eq "x64") { $env:CMAKE_ARCH = "x64" }
     60 + 
     61 + - ps: if ($env:PLATFORM -eq "x64") { $env:PYTHON_PATH = $env:PYTHON64_PATH }
     62 + - ps: if ($env:PLATFORM -eq "x64") { $env:PYTHON_INCLUDE = $env:PYTHON64_INCLUDE }
     63 + - ps: if ($env:PLATFORM -eq "x64") { $env:PYTHON_BINARY = $env:PYTHON64_BINARY }
     64 + - ps: if ($env:PLATFORM -eq "x64") { $env:PYTHON_LIBRARY = $env:PYTHON64_LIBRARY }
     65 + 
     66 + - ps: if ($env:PLATFORM -eq "x86") { $env:PYTHON_PATH = $env:PYTHON32_PATH }
     67 + - ps: if ($env:PLATFORM -eq "x86") { $env:PYTHON_INCLUDE = $env:PYTHON32_INCLUDE }
     68 + - ps: if ($env:PLATFORM -eq "x86") { $env:PYTHON_BINARY = $env:PYTHON32_BINARY }
     69 + - ps: if ($env:PLATFORM -eq "x86") { $env:PYTHON_LIBRARY = $env:PYTHON32_LIBRARY }
     70 + 
     71 + - set PATH=%PYTHON_PATH%;%PATH%
     72 + 
     73 +build_script:
     74 + - 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%
     75 + - set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
     76 + - cmake --build . --config Release --target ALL_BUILD -- /v:m /logger:%MSBuildLogger%
     77 + 
     78 +test_script:
     79 + - cmake --build . --config Release --target RUN_TESTS -- /v:m /logger:%MSBuildLogger%
     80 + 
     81 +after_test:
     82 + - cd api\python
     83 + - python.exe .\setup.py sdist --formats=zip && exit 0 # Ignore warnings...
     84 + - ps: gci dist\*.zip | % { rename-item –path $_.Fullname –Newname ( "windows_" + $env:PLATFORM + "_" + $_.basename + "_py" + $env:PYTHON_VERSION + $_.extension) }
     85 + 
     86 +#artifacts:
     87 +# - path: 'api\python\dist\*.zip'
     88 + 
     89 + 
     90 + 
  • ■ ■ ■ ■ ■ ■
    .dockerignore
     1 +*
     2 +!src
     3 +!doc
     4 +!tests
     5 +!include
     6 +!examples
     7 +!api
     8 +!CMakeLists.txt
     9 +!CMakeModules
     10 +!package
     11 + 
  • ■ ■ ■ ■ ■ ■
    .travis.yml
     1 +language: cpp
     2 + 
     3 + 
     4 +matrix:
     5 + include:
     6 + # Linux gcc 5.0 - Python 2.7
     7 + - os: linux
     8 + dist: trusty
     9 + compiler: gcc
     10 + addons:
     11 + apt:
     12 + sources: ['ubuntu-toolchain-r-test']
     13 + packages: ['g++-5', 'ccache', 'libpython2.7']
     14 + 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 ]
     15 + 
     16 + 
     17 + ## Linux gcc 5.0 - Python 3.5
     18 + - os: linux
     19 + dist: trusty
     20 + compiler: gcc
     21 + addons:
     22 + apt:
     23 + sources: ['ubuntu-toolchain-r-test', 'deadsnakes']
     24 + packages: ['g++-5', 'gcc-5', 'ccache', 'python3.5-dev']
     25 + 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]
     26 + 
     27 + 
     28 + # Linux gcc 6 - Python 3.6
     29 + - os: linux
     30 + dist: trusty
     31 + compiler: gcc
     32 + addons:
     33 + apt:
     34 + sources: ['ubuntu-toolchain-r-test', 'deadsnakes']
     35 + packages: ['g++-6', 'gcc-6', 'ccache', 'python3.6-dev', 'python-sphinx']
     36 + 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]
     37 + 
     38 + # OSX 10.11 - xcode 7.3 - Python 2.7
     39 + - os: osx
     40 + osx_image: xcode7.3
     41 + compiler: clang
     42 + env: [CXX_COMPILER=clang++, C_COMPILER=clang, PYTHON_VERSION=2.7]
     43 + 
     44 + # OSX 10.12 - xcode 8.2 - Python 3.5
     45 + - os: osx
     46 + osx_image: xcode8.2
     47 + compiler: clang
     48 + env: [ CXX_COMPILER=clang++, C_COMPILER=clang, PYTHON_VERSION=3.5]
     49 + 
     50 + 
     51 + ## OSX 10.12 - xcode 8.2 - Python 3.6
     52 + - os: osx
     53 + osx_image: xcode8.2
     54 + compiler: clang
     55 + env: [CXX_COMPILER=clang++, C_COMPILER=clang, PYTHON_VERSION=3.6]
     56 + 
     57 +#branches:
     58 +# only:
     59 +# - master
     60 + 
     61 + 
     62 +notifications:
     63 + email: false
     64 + 
     65 +sudo: required
     66 + 
     67 +cache:
     68 + - apt
     69 + - ccache
     70 + 
     71 +before_install:
     72 + - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get update -q; fi
     73 + - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install python-setuptools; fi
     74 + - export CC="$C_COMPILER"
     75 + - export CXX="$CXX_COMPILER"
     76 + - if [ "$TRAVIS_OS_NAME" == "osx" ]; then export PREFIX="/usr/local"; fi
     77 + - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew update; fi
     78 + 
     79 + - if [ "$TRAVIS_OS_NAME" == "osx" ]; then export PYTHON_CONFIGURE_OPTS="--enable-shared"; fi
     80 + - if [ "$TRAVIS_OS_NAME" == "osx" ]; then pyenv root; fi
     81 + - if [ "$TRAVIS_OS_NAME" == "osx" ]; then pyenv install --list ;fi
     82 + 
     83 + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then pyenv install 2.7.10; fi
     84 + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.5" ]]; then pyenv install 3.5.0; fi
     85 + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.6" ]]; then pyenv install 3.6.0b4; fi
     86 + 
     87 + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then export PYTHON_INCLUDE_DIR=$(pyenv root)/versions/2.7.10/include/python2.7 ;fi
     88 + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then export PYTHON_LIBRARY=$(pyenv root)/versions/2.7.10/lib/libpython2.7.dylib ;fi
     89 + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/2.7.10/bin/python2.7 ;fi
     90 + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then $PYTHON_BINARY -m pip install --upgrade pip ;fi
     91 + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then $PYTHON_BINARY -m pip install --upgrade setuptools ;fi
     92 + 
     93 + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.5" ]]; then export PYTHON_INCLUDE_DIR=$(pyenv root)/versions/3.5.0/include/python3.5m ;fi
     94 + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.5" ]]; then export PYTHON_LIBRARY=$(pyenv root)/versions/3.5.0/lib/libpython3.dylib ;fi
     95 + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.5" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/3.5.0/bin/python3.5 ;fi
     96 + 
     97 + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.6" ]]; then export PYTHON_INCLUDE_DIR=$(pyenv root)/versions/3.6.0b4/include/python3.6m ;fi
     98 + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.6" ]]; then export PYTHON_LIBRARY=$(pyenv root)/versions/3.6.0b4/lib/libpython3.dylib ;fi
     99 + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.6" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/3.6.0b4/bin/python3.6 ;fi
     100 + 
     101 +install:
     102 + - if [ "$GCOV" == "ON" ]; then sudo ln -sf /usr/bin/gcov-5 /usr/bin/gcov; fi
     103 + - if [ "$GCOV" == "ON" ]; then wget http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.13.orig.tar.gz; fi
     104 + - if [ "$GCOV" == "ON" ]; then tar xf lcov_1.13.orig.tar.gz; fi
     105 + - if [ "$GCOV" == "ON" ]; then sudo make -C lcov-1.13/ install; fi
     106 + 
     107 + - 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
     108 + - if [[ "$LIEF_DOC" == "ON" ]]; then tar -xzf doxygen-1.8.10.linux.bin.tar.gz; fi
     109 + - if [[ "$LIEF_DOC" == "ON" ]]; then cd doxygen-1.8.10; fi
     110 + - if [[ "$LIEF_DOC" == "ON" ]]; then ./configure --prefix /usr; fi
     111 + - if [[ "$LIEF_DOC" == "ON" ]]; then sudo make install; fi
     112 + - if [[ "$LIEF_DOC" == "ON" ]]; then cd ..; fi
     113 + 
     114 + # Setup CMake 3.1 for Linux
     115 + - 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
     116 + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then tar -xzf cmake-3.7.2-Linux-x86_64.tar.gz ;fi
     117 + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export PATH=$PWD/cmake-3.7.2-Linux-x86_64/bin:$PATH ;fi
     118 + 
     119 + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py ;fi
     120 + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo $PYTHON_BINARY ./get-pip.py ;fi
     121 + - if [[ "$TRAVIS_OS_NAME" == "linux" && "$LIEF_DOC" == "ON" ]]; then sudo $PYTHON_BINARY -m pip install breathe ;fi
     122 + - if [[ "$TRAVIS_OS_NAME" == "linux" && "$LIEF_DOC" == "ON" ]]; then sudo $PYTHON_BINARY -m pip install sphinx_rtd_theme ;fi
     123 + 
     124 + # Prepare build
     125 + - mkdir build
     126 + - cd build
     127 + 
     128 + 
     129 +script:
     130 + - 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} ..
     131 + - make -j2
     132 + - sudo make check-lief
     133 + 
     134 +after_success:
     135 + - make package
     136 + - sudo $PYTHON_BINARY -m pip install setuptools
     137 + - sudo $PYTHON_BINARY -m pip install --upgrade setuptools
     138 + - cd api/python
     139 + - $PYTHON_BINARY setup.py sdist
     140 + - 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
     141 + - 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
     142 + 
     143 + 
     144 +deploy:
     145 + provider: releases
     146 + api-key:
     147 + - 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="
     148 + file_glob: true
     149 + file:
     150 + - ${TRAVIS_BUILD_DIR}/build/api/python/dist/*.tar.gz
     151 + - ${TRAVIS_BUILD_DIR}/build/*.tar.gz
     152 + skip_cleanup: true
     153 + on:
     154 + #branch: master
     155 + tags: true
     156 + 
     157 + 
  • ■ ■ ■ ■ ■ ■
    AUTHORS
     1 +Authors:
     2 + 
     3 + Romain Thomas <[email protected]>
     4 + 
  • ■ ■ ■ ■ ■ ■
    Acknowledgements
     1 +Acknowledgements
     2 +----------------
     3 + 
     4 +LIEF makes use of the following open source projects:
     5 + 
     6 + - mbedTLS - https://tls.mbed.org/
     7 + - pybind11 - https://github.com/pybind/pybind11
     8 + - json - https://nlohmann.github.io/json/
     9 + - rang - https://agauniyal.github.io/rang/
     10 + - easyloggingpp - https://github.com/muflihun/easyloggingpp
     11 + - Catch - https://github.com/philsquared/Catch
     12 + - yamlcpp - https://github.com/jbeder/yaml-cpp
     13 + - filesystem - https://github.com/wjakob/filesystem
     14 + - utf8-cpp - https://sourceforge.net/projects/utfcpp/
     15 + 
     16 +The logo is designed by Freepik
     17 + 
  • ■ ■ ■ ■ ■ ■
    CHANGELOG
     1 +Changelog
     2 +=========
     3 + 
     4 +v0.6:
     5 + * First public release
     6 + 
     7 + 
     8 + 
  • ■ ■ ■ ■ ■ ■
    CMakeLists.txt
     1 +cmake_minimum_required(VERSION 3.1)
     2 + 
     3 +# Modules
     4 +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/")
     5 +include(CheckCXXCompilerFlag)
     6 +include(CheckCCompilerFlag)
     7 +include(Findcppcheck)
     8 +include(CppcheckTargets)
     9 +include(ExternalProject)
     10 + 
     11 +# LIEF version
     12 +set(LIEF_VERSION_MAJOR 0)
     13 +set(LIEF_VERSION_MINOR 6)
     14 +set(LIEF_VERSION_PATCH 0)
     15 + 
     16 +project(LIEF VERSION ${LIEF_VERSION_MAJOR}.${LIEF_VERSION_MINOR}.${LIEF_VERSION_PATCH})
     17 +message(STATUS "${PROJECT_NAME} ${PROJECT_VERSION}")
     18 + 
     19 +# options
     20 +option(LIEF_TESTS "Enable tests" OFF)
     21 +option(LIEF_DOC "Enable documentation" OFF)
     22 +option(LIEF_PYTHON_API "Enable Python API" ON)
     23 +option(LIEF_INSTALL_PYTHON "Install Python bindings" OFF)
     24 +option(LIEF_C_API "C API" ON)
     25 +option(LIEF_EXAMPLES "Build LIEF C++ examples" ON)
     26 +option(LIEF_FORCE32 "Force build LIEF 32 bits version" OFF)
     27 +option(LIEF_COVERAGE "Perform code coverage" OFF)
     28 +option(LIEF_USE_CCACHE "Use ccache to speed up compilation" ON)
     29 +option(LIEF_EXTRA_WARNINGS "Enable extra warning from the compiler" OFF)
     30 +option(LIEF_LOGGING "Enable logging" ON)
     31 + 
     32 +option(LIEF_ELF "Build LIEF with ELF module" ON)
     33 +option(LIEF_PE "Build LIEF with PE module" ON)
     34 +option(LIEF_MACHO "Build LIEF with MachO module" ON)
     35 + 
     36 +# CCACHE
     37 +# ======
     38 +find_program(CCACHE_FOUND ccache)
     39 +message(STATUS "ccache: ${LIEF_USE_CCACHE}")
     40 +if(CCACHE_FOUND AND LIEF_USE_CCACHE)
     41 + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
     42 + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
     43 +endif()
     44 + 
     45 + 
     46 +# Dependencies
     47 +# ============
     48 +find_package(Git REQUIRED)
     49 + 
     50 +# Json
     51 +# ----
     52 +set(LIBJSON_GIT_URL "https://github.com/nlohmann/json.git" CACHE STRING "URL to the JSON lib repo")
     53 +ExternalProject_Add(libjson
     54 + GIT_REPOSITORY ${LIBJSON_GIT_URL}
     55 + GIT_TAG v2.0.8
     56 + CONFIGURE_COMMAND ""
     57 + BUILD_COMMAND ""
     58 + INSTALL_COMMAND "")
     59 + 
     60 +ExternalProject_get_property(libjson SOURCE_DIR)
     61 +set(LIBJSON_SOURCE_DIR ${SOURCE_DIR})
     62 + 
     63 + 
     64 +# Rang
     65 +# ----
     66 +set(LIBRANG_GIT_URL "https://github.com/agauniyal/rang.git" CACHE STRING "URL to the Rang lib repo")
     67 +ExternalProject_Add(rang_cpp_color
     68 + GIT_REPOSITORY ${LIBRANG_GIT_URL}
     69 + GIT_TAG master
     70 + CONFIGURE_COMMAND ""
     71 + BUILD_COMMAND ""
     72 + INSTALL_COMMAND "")
     73 + 
     74 +ExternalProject_get_property(rang_cpp_color SOURCE_DIR)
     75 +set(LIBRANG_SOURCE_DIR ${SOURCE_DIR})
     76 + 
     77 + 
     78 +# mbed TLS
     79 +# --------
     80 +set(MBED_TLS_TAG mbedtls-2.4.0)
     81 +set(MBED_TLS_GIT_URL "https://github.com/ARMmbed/mbedtls.git" CACHE STRING "URL to MbedTLS")
     82 +set(MBED_TLS_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/mbed_tls)
     83 + 
     84 + 
     85 +ExternalProject_Add(mbed_tls
     86 + PREFIX ${MBED_TLS_PREFIX}
     87 + CONFIGURE_COMMAND ""
     88 + BUILD_COMMAND ""
     89 + INSTALL_COMMAND ""
     90 + GIT_REPOSITORY ${MBED_TLS_GIT_URL}
     91 + GIT_TAG ${MBED_TLS_TAG}
     92 + UPDATE_COMMAND "" # repetitive update are a pain
     93 + BUILD_BYPRODUCTS ${MBED_TLS_PREFIX})
     94 + 
     95 +ExternalProject_get_property(mbed_tls SOURCE_DIR)
     96 +set(MBEDTLS_SOURCE_DIR ${SOURCE_DIR})
     97 +set(MBEDTLS_INCLUDE_DIRS "${MBEDTLS_SOURCE_DIR}/include")
     98 + 
     99 +set(mbedtls_src_crypto
     100 + ${MBEDTLS_SOURCE_DIR}/library/aes.c
     101 + ${MBEDTLS_SOURCE_DIR}/library/aesni.c
     102 + ${MBEDTLS_SOURCE_DIR}/library/arc4.c
     103 + ${MBEDTLS_SOURCE_DIR}/library/asn1parse.c
     104 + ${MBEDTLS_SOURCE_DIR}/library/asn1write.c
     105 + ${MBEDTLS_SOURCE_DIR}/library/base64.c
     106 + ${MBEDTLS_SOURCE_DIR}/library/bignum.c
     107 + ${MBEDTLS_SOURCE_DIR}/library/blowfish.c
     108 + ${MBEDTLS_SOURCE_DIR}/library/camellia.c
     109 + ${MBEDTLS_SOURCE_DIR}/library/ccm.c
     110 + ${MBEDTLS_SOURCE_DIR}/library/cipher.c
     111 + ${MBEDTLS_SOURCE_DIR}/library/cipher_wrap.c
     112 + ${MBEDTLS_SOURCE_DIR}/library/cmac.c
     113 + ${MBEDTLS_SOURCE_DIR}/library/ctr_drbg.c
     114 + ${MBEDTLS_SOURCE_DIR}/library/des.c
     115 + ${MBEDTLS_SOURCE_DIR}/library/dhm.c
     116 + ${MBEDTLS_SOURCE_DIR}/library/ecdh.c
     117 + ${MBEDTLS_SOURCE_DIR}/library/ecdsa.c
     118 + ${MBEDTLS_SOURCE_DIR}/library/ecjpake.c
     119 + ${MBEDTLS_SOURCE_DIR}/library/ecp.c
     120 + ${MBEDTLS_SOURCE_DIR}/library/ecp_curves.c
     121 + ${MBEDTLS_SOURCE_DIR}/library/entropy.c
     122 + ${MBEDTLS_SOURCE_DIR}/library/entropy_poll.c
     123 + ${MBEDTLS_SOURCE_DIR}/library/error.c
     124 + ${MBEDTLS_SOURCE_DIR}/library/gcm.c
     125 + ${MBEDTLS_SOURCE_DIR}/library/havege.c
     126 + ${MBEDTLS_SOURCE_DIR}/library/hmac_drbg.c
     127 + ${MBEDTLS_SOURCE_DIR}/library/md.c
     128 + ${MBEDTLS_SOURCE_DIR}/library/md2.c
     129 + ${MBEDTLS_SOURCE_DIR}/library/md4.c
     130 + ${MBEDTLS_SOURCE_DIR}/library/md5.c
     131 + ${MBEDTLS_SOURCE_DIR}/library/md_wrap.c
     132 + ${MBEDTLS_SOURCE_DIR}/library/memory_buffer_alloc.c
     133 + ${MBEDTLS_SOURCE_DIR}/library/oid.c
     134 + ${MBEDTLS_SOURCE_DIR}/library/padlock.c
     135 + ${MBEDTLS_SOURCE_DIR}/library/pem.c
     136 + ${MBEDTLS_SOURCE_DIR}/library/pk.c
     137 + ${MBEDTLS_SOURCE_DIR}/library/pk_wrap.c
     138 + ${MBEDTLS_SOURCE_DIR}/library/pkcs12.c
     139 + ${MBEDTLS_SOURCE_DIR}/library/pkcs5.c
     140 + ${MBEDTLS_SOURCE_DIR}/library/pkparse.c
     141 + ${MBEDTLS_SOURCE_DIR}/library/pkwrite.c
     142 + ${MBEDTLS_SOURCE_DIR}/library/platform.c
     143 + ${MBEDTLS_SOURCE_DIR}/library/ripemd160.c
     144 + ${MBEDTLS_SOURCE_DIR}/library/rsa.c
     145 + ${MBEDTLS_SOURCE_DIR}/library/sha1.c
     146 + ${MBEDTLS_SOURCE_DIR}/library/sha256.c
     147 + ${MBEDTLS_SOURCE_DIR}/library/sha512.c
     148 + ${MBEDTLS_SOURCE_DIR}/library/threading.c
     149 + ${MBEDTLS_SOURCE_DIR}/library/timing.c
     150 + ${MBEDTLS_SOURCE_DIR}/library/version.c
     151 + ${MBEDTLS_SOURCE_DIR}/library/version_features.c
     152 + ${MBEDTLS_SOURCE_DIR}/library/xtea.c
     153 +)
     154 + 
     155 +set(mbedtls_src_x509
     156 + ${MBEDTLS_SOURCE_DIR}/library/certs.c
     157 + ${MBEDTLS_SOURCE_DIR}/library/pkcs11.c
     158 + ${MBEDTLS_SOURCE_DIR}/library/x509.c
     159 + ${MBEDTLS_SOURCE_DIR}/library/x509_create.c
     160 + ${MBEDTLS_SOURCE_DIR}/library/x509_crl.c
     161 + ${MBEDTLS_SOURCE_DIR}/library/x509_crt.c
     162 + ${MBEDTLS_SOURCE_DIR}/library/x509_csr.c
     163 + ${MBEDTLS_SOURCE_DIR}/library/x509write_crt.c
     164 + ${MBEDTLS_SOURCE_DIR}/library/x509write_csr.c
     165 +)
     166 + 
     167 +set(mbedtls_src_tls
     168 + ${MBEDTLS_SOURCE_DIR}/library/debug.c
     169 + ${MBEDTLS_SOURCE_DIR}/library/net_sockets.c
     170 + ${MBEDTLS_SOURCE_DIR}/library/ssl_cache.c
     171 + ${MBEDTLS_SOURCE_DIR}/library/ssl_ciphersuites.c
     172 + ${MBEDTLS_SOURCE_DIR}/library/ssl_cli.c
     173 + ${MBEDTLS_SOURCE_DIR}/library/ssl_cookie.c
     174 + ${MBEDTLS_SOURCE_DIR}/library/ssl_srv.c
     175 + ${MBEDTLS_SOURCE_DIR}/library/ssl_ticket.c
     176 + ${MBEDTLS_SOURCE_DIR}/library/ssl_tls.c
     177 +)
     178 + 
     179 + 
     180 +# easyloggingpp
     181 +# -------------
     182 +set(ELG_GIT_URL "https://github.com/easylogging/easyloggingpp.git" CACHE STRING "URL to the easyloggingpp lib repo")
     183 +ExternalProject_Add(easyloggingpp
     184 + GIT_REPOSITORY ${ELG_GIT_URL}
     185 + #GIT_TAG "v9.83"
     186 + GIT_TAG "master"
     187 + CONFIGURE_COMMAND ""
     188 + BUILD_COMMAND ""
     189 + INSTALL_COMMAND "")
     190 + 
     191 +ExternalProject_get_property(easyloggingpp SOURCE_DIR)
     192 +set(ELG_SOURCE_DIR ${SOURCE_DIR}/src)
     193 + 
     194 + 
     195 + 
     196 +# LIEF Source definition
     197 +# ======================
     198 +set_source_files_properties(${mbedtls_src_crypto} PROPERTIES GENERATED TRUE)
     199 +set_source_files_properties(${mbedtls_src_x509} PROPERTIES GENERATED TRUE)
     200 +set_source_files_properties(${mbedtls_src_tls} PROPERTIES GENERATED TRUE)
     201 +set_source_files_properties(${ELG_SOURCE_DIR}/easylogging++.cc PROPERTIES GENERATED TRUE)
     202 + 
     203 +set(LIEF_SRC
     204 + ${ELG_SOURCE_DIR}/easylogging++.cc
     205 + ${mbedtls_src_crypto}
     206 + ${mbedtls_src_x509}
     207 + ${mbedtls_src_tls}
     208 + ${CMAKE_CURRENT_SOURCE_DIR}/src/logging.cpp
     209 + ${CMAKE_CURRENT_SOURCE_DIR}/src/exception.cpp
     210 + ${CMAKE_CURRENT_SOURCE_DIR}/src/iostream.cpp
     211 + ${CMAKE_CURRENT_SOURCE_DIR}/src/utils.cpp
     212 + ${CMAKE_CURRENT_SOURCE_DIR}/src/Visitable.cpp
     213 + ${CMAKE_CURRENT_SOURCE_DIR}/src/Visitor.cpp
     214 + ${CMAKE_CURRENT_SOURCE_DIR}/src/BinaryStream/BinaryStream.cpp
     215 + ${CMAKE_CURRENT_SOURCE_DIR}/src/BinaryStream/VectorStream.cpp
     216 + ${CMAKE_CURRENT_SOURCE_DIR}/src/visitors/elf_json.cpp
     217 + ${CMAKE_CURRENT_SOURCE_DIR}/src/visitors/json.cpp
     218 + ${CMAKE_CURRENT_SOURCE_DIR}/src/visitors/hash.cpp)
     219 + 
     220 +set(LIEF_ABSTRACT_SRC
     221 + ${CMAKE_CURRENT_SOURCE_DIR}/src/Abstract/Binary.cpp
     222 + ${CMAKE_CURRENT_SOURCE_DIR}/src/Abstract/Symbol.cpp
     223 + ${CMAKE_CURRENT_SOURCE_DIR}/src/Abstract/EnumToString.cpp
     224 + ${CMAKE_CURRENT_SOURCE_DIR}/src/Abstract/Header.cpp
     225 + ${CMAKE_CURRENT_SOURCE_DIR}/src/Abstract/Section.cpp
     226 + ${CMAKE_CURRENT_SOURCE_DIR}/src/Abstract/Parser.cpp)
     227 + 
     228 + 
     229 + 
     230 +set(LIBLIEF_SOURCE_FILES
     231 + ${LIEF_SRC}
     232 + ${LIEF_ABSTRACT_SRC})
     233 + 
     234 +add_library(LIB_LIEF_STATIC STATIC ${LIBLIEF_SOURCE_FILES}) # Static one
     235 +add_library(LIB_LIEF_SHARED SHARED ${LIBLIEF_SOURCE_FILES}) # Shared one
     236 + 
     237 + 
     238 +if (LIEF_ELF)
     239 + include(${CMAKE_CURRENT_SOURCE_DIR}/src/ELF/CMakeLists.txt)
     240 +endif()
     241 + 
     242 +if (LIEF_PE)
     243 + include(${CMAKE_CURRENT_SOURCE_DIR}/src/PE/CMakeLists.txt)
     244 +endif()
     245 + 
     246 +if (LIEF_MACHO)
     247 + include(${CMAKE_CURRENT_SOURCE_DIR}/src/MachO/CMakeLists.txt)
     248 +endif()
     249 + 
     250 + 
     251 +# LIEF includes
     252 +# =============
     253 + 
     254 +configure_file(
     255 + ${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/version.h.in
     256 + ${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/version.h
     257 +)
     258 + 
     259 +set (LIEF_PUBLIC_INCLUDE_DIR
     260 + ${CMAKE_CURRENT_SOURCE_DIR}/include/
     261 + ${CMAKE_CURRENT_BINARY_DIR}/include/
     262 + ${LIBJSON_SOURCE_DIR}/src/)
     263 + 
     264 +set(LIEF_PRIVATE_INCLUDE_DIR
     265 + ${LIEF_PUBLIC_INCLUDE_DIR}
     266 + ${LIBRANG_SOURCE_DIR}/include
     267 + ${ELG_SOURCE_DIR}/
     268 + ${MBEDTLS_INCLUDE_DIRS})
     269 + 
     270 +# Library definition
     271 +# ==================
     272 +add_definitions(-DELPP_NO_DEFAULT_LOG_FILE)
     273 +if (LIEF_ELF)
     274 + add_definitions(-DLIEF_ELF_MODULE)
     275 +endif()
     276 + 
     277 +if (LIEF_PE)
     278 + add_definitions(-DLIEF_PE_MODULE)
     279 +endif()
     280 + 
     281 +if (LIEF_MACHO)
     282 + add_definitions(-DLIEF_MACHO_MODULE)
     283 +endif()
     284 + 
     285 +target_include_directories(LIB_LIEF_STATIC
     286 + PUBLIC ${LIEF_PUBLIC_INCLUDE_DIR}
     287 + PRIVATE ${LIEF_PRIVATE_INCLUDE_DIR})
     288 + 
     289 +target_include_directories(LIB_LIEF_SHARED
     290 + PUBLIC ${LIEF_PUBLIC_INCLUDE_DIR}
     291 + PRIVATE ${LIEF_PRIVATE_INCLUDE_DIR})
     292 + 
     293 + 
     294 +add_dependencies(LIB_LIEF_STATIC libjson)
     295 +add_dependencies(LIB_LIEF_SHARED libjson)
     296 + 
     297 +add_dependencies(LIB_LIEF_STATIC easyloggingpp)
     298 +add_dependencies(LIB_LIEF_SHARED easyloggingpp)
     299 + 
     300 +add_dependencies(LIB_LIEF_STATIC rang_cpp_color)
     301 +add_dependencies(LIB_LIEF_SHARED rang_cpp_color)
     302 + 
     303 +add_dependencies(LIB_LIEF_STATIC mbed_tls)
     304 +add_dependencies(LIB_LIEF_SHARED mbed_tls)
     305 + 
     306 +# Flags definition
     307 +# ----------------
     308 +set_property(TARGET LIB_LIEF_STATIC LIB_LIEF_SHARED PROPERTY CXX_STANDARD 11)
     309 +set_property(TARGET LIB_LIEF_STATIC LIB_LIEF_SHARED PROPERTY CXX_STANDARD_REQUIRED ON)
     310 +set_property(TARGET LIB_LIEF_STATIC LIB_LIEF_SHARED PROPERTY POSITION_INDEPENDENT_CODE ON)
     311 +#set_property(TARGET LIB_LIEF_STATIC LIB_LIEF_SHARED PROPERTY CXX_VISIBILITY_PRESET hidden)
     312 + 
     313 + 
     314 +CHECK_CXX_COMPILER_FLAG("-Weverything" HAS_WARN_EVERY)
     315 + 
     316 +if (LIEF_EXTRA_WARNINGS AND HAS_WARN_EVERY)
     317 + set(EXTRA_FLAGS
     318 + -Weverything
     319 + -Wno-c++98-compat
     320 + -Wno-c++98-compat-pedantic
     321 + -Wno-padded
     322 + -Wno-unused-exception-parameter
     323 + -Wno-weak-vtables
     324 + -Wno-exit-time-destructors
     325 + -Wno-global-constructors
     326 + -Wno-documentation
     327 + -Wno-documentation-unknown-command
     328 + -Wno-sign-conversion)
     329 + 
     330 + target_compile_options(LIB_LIEF_STATIC PRIVATE ${EXTRA_FLAGS})
     331 + target_compile_options(LIB_LIEF_SHARED PRIVATE ${EXTRA_FLAGS})
     332 +endif()
     333 + 
     334 +if (MSVC)
     335 + add_definitions(-DNOMINMAX)
     336 + target_compile_options(LIB_LIEF_STATIC PUBLIC /FIiso646.h)
     337 + target_compile_options(LIB_LIEF_SHARED PUBLIC /FIiso646.h)
     338 + 
     339 + target_compile_options(LIB_LIEF_STATIC PUBLIC /MT)
     340 + 
     341 +endif()
     342 + 
     343 +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
     344 + if (UNIX)
     345 + if (LIEF_FORCE32)
     346 + target_compile_options(LIB_LIEF_STATIC PRIVATE -m32)
     347 + target_compile_options(LIB_LIEF_SHARED PRIVATE -m32)
     348 + 
     349 + set_property(TARGET LIB_LIEF_STATIC LIB_LIEF_SHARED PROPERTY LINK_FLAGS -m32)
     350 + endif()
     351 + 
     352 + set(LIB_LIEF_COMPILE_FLAGS
     353 + -Wall -Wextra -Wpedantic
     354 + -Wno-expansion-to-defined
     355 + -fno-stack-protector
     356 + -fomit-frame-pointer -fno-strict-aliasing
     357 + -fexceptions
     358 + -fvisibility=hidden)
     359 + target_compile_options(LIB_LIEF_STATIC PRIVATE ${LIB_LIEF_COMPILE_FLAGS})
     360 + target_compile_options(LIB_LIEF_SHARED PRIVATE ${LIB_LIEF_COMPILE_FLAGS})
     361 + endif()
     362 +endif()
     363 + 
     364 + 
     365 +if(CROSS_COMPILE_WINDOWS)
     366 + target_link_libraries(LIB_LIEF_STATIC -static -static-libgcc -static-libstdc++)
     367 +endif()
     368 + 
     369 +if(LIEF_COVERAGE)
     370 + target_compile_options(LIB_LIEF_STATIC PRIVATE -g -O0 --coverage -fprofile-arcs -ftest-coverage)
     371 + target_compile_options(LIB_LIEF_SHARED PRIVATE -g -O0 --coverage -fprofile-arcs -ftest-coverage)
     372 + target_link_libraries(LIB_LIEF_STATIC gcov)
     373 + target_link_libraries(LIB_LIEF_SHARED gcov)
     374 +endif()
     375 + 
     376 +find_package(cppcheck)
     377 + 
     378 +set_target_properties(
     379 + LIB_LIEF_STATIC
     380 + PROPERTIES OUTPUT_NAME LIEF
     381 + CLEAN_DIRECT_OUTPUT 1)
     382 + 
     383 +set_target_properties(
     384 + LIB_LIEF_SHARED
     385 + PROPERTIES OUTPUT_NAME LIEF
     386 + CLEAN_DIRECT_OUTPUT 1)
     387 + 
     388 + 
     389 + 
     390 +# Set a default build type if none was specified
     391 +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
     392 + message(STATUS "Setting build type to 'Release' as none was specified.")
     393 + set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
     394 + # Set the possible values of build type for cmake-gui
     395 + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
     396 + "MinSizeRel" "RelWithDebInfo")
     397 +endif()
     398 + 
     399 +message(STATUS "Configuration Types: ${CMAKE_CONFIGURATION_TYPES}")
     400 +message(STATUS "Build Types: ${CMAKE_BUILD_TYPE}")
     401 + 
     402 + 
     403 +if(APPLE)
     404 + set_target_properties(LIB_LIEF_STATIC PROPERTIES MACOSX_RPATH ".")
     405 + set_target_properties(LIB_LIEF_SHARED PROPERTIES MACOSX_RPATH ".")
     406 +endif()
     407 + 
     408 + 
     409 +# API
     410 +# ===
     411 + 
     412 +# Python
     413 +# ------
     414 + 
     415 +if (LIEF_PYTHON_API)
     416 + if(WIN32)
     417 + set(PYTHON_BUILD_LIEF_DIRECTORY "${CMAKE_BINARY_DIR}/api/python/Release")
     418 + else()
     419 + set(PYTHON_BUILD_LIEF_DIRECTORY "${CMAKE_BINARY_DIR}/api/python")
     420 + endif()
     421 + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/api/python)
     422 +endif()
     423 + 
     424 +# C API
     425 +# -----
     426 +if(LIEF_C_API)
     427 + 
     428 + # ELF
     429 + configure_file(
     430 + ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include/LIEF/ELF/enums.h.in
     431 + ${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/ELF/enums.h
     432 + @ONLY
     433 + )
     434 + 
     435 + configure_file(
     436 + ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include/LIEF/ELF/structures.h.in
     437 + ${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/ELF/structures.h
     438 + @ONLY
     439 + )
     440 + 
     441 + # PE
     442 + configure_file(
     443 + ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include/LIEF/PE/enums.h.in
     444 + ${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/PE/enums.h
     445 + @ONLY
     446 + )
     447 + 
     448 + configure_file(
     449 + ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include/LIEF/PE/structures.h.in
     450 + ${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/PE/structures.h
     451 + @ONLY
     452 + )
     453 + 
     454 + 
     455 + # MachO
     456 + configure_file(
     457 + ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include/LIEF/MachO/enums.h.in
     458 + ${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/MachO/enums.h
     459 + @ONLY
     460 + )
     461 + 
     462 + configure_file(
     463 + ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include/LIEF/MachO/structures.h.in
     464 + ${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/MachO/structures.h
     465 + @ONLY
     466 + )
     467 + 
     468 + target_include_directories(LIB_LIEF_STATIC
     469 + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include
     470 + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include)
     471 + 
     472 + target_include_directories(LIB_LIEF_SHARED
     473 + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include
     474 + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include)
     475 + 
     476 + include(${CMAKE_CURRENT_SOURCE_DIR}/api/c/CMakeLists.txt)
     477 +endif()
     478 + 
     479 + 
     480 + 
     481 +# Examples
     482 +# ========
     483 +if(LIEF_EXAMPLES)
     484 + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples/cpp)
     485 + 
     486 + if (LIEF_C_API)
     487 + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples/c)
     488 + endif()
     489 +endif()
     490 + 
     491 +# Tests
     492 +# =====
     493 +if(LIEF_TESTS)
     494 + enable_testing()
     495 + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests)
     496 + add_custom_target(check-lief COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)
     497 +endif()
     498 + 
     499 +# CPP Check
     500 +# =========
     501 +set(CPPCHECK_TEMPLATE_ARG "[{severity}][{id}] {message} {callstack} \(On {file}:{line}\)")
     502 +set(_cppcheck_args "--enable=warning,performance,portability,information")
     503 +#add_cppcheck(LIB_LIEF_STATIC FORCE)
     504 + 
     505 + 
     506 +# Documentation
     507 +# =============
     508 +if (LIEF_DOC)
     509 + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/doc)
     510 +endif()
     511 + 
     512 + 
     513 +# Install Prefix
     514 +# ==============
     515 +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND UNIX)
     516 + if (UNIX AND NOT APPLE)
     517 + set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Install path prefix prepended on to install directories." FORCE)
     518 + elseif (APPLE)
     519 + set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "" FORCE)
     520 + endif()
     521 +endif()
     522 + 
     523 +# Installation
     524 +# ============
     525 + 
     526 +install(TARGETS LIB_LIEF_STATIC
     527 + ARCHIVE
     528 + DESTINATION lib
     529 + LIBRARY
     530 + DESTINATION lib
     531 + COMPONENT libraries)
     532 + 
     533 +install(TARGETS LIB_LIEF_SHARED
     534 + ARCHIVE
     535 + DESTINATION lib
     536 + LIBRARY
     537 + DESTINATION lib
     538 + COMPONENT libraries)
     539 + 
     540 +install(
     541 + DIRECTORY ${LIEF_PUBLIC_INCLUDE_DIR}
     542 + DESTINATION include
     543 + COMPONENT headers
     544 + FILES_MATCHING REGEX "(.*).(hpp|h|def)$")
     545 + 
     546 +# Package
     547 +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/package)
     548 + 
     549 + 
     550 + 
     551 + 
     552 + 
     553 + 
  • ■ ■ ■ ■ ■ ■
    CMakeModules/CodeCoverage.cmake
     1 +# Copyright (c) 2012 - 2015, Lars Bilke
     2 +# All rights reserved.
     3 +#
     4 +# Redistribution and use in source and binary forms, with or without modification,
     5 +# are permitted provided that the following conditions are met:
     6 +#
     7 +# 1. Redistributions of source code must retain the above copyright notice, this
     8 +# list of conditions and the following disclaimer.
     9 +#
     10 +# 2. Redistributions in binary form must reproduce the above copyright notice,
     11 +# this list of conditions and the following disclaimer in the documentation
     12 +# and/or other materials provided with the distribution.
     13 +#
     14 +# 3. Neither the name of the copyright holder nor the names of its contributors
     15 +# may be used to endorse or promote products derived from this software without
     16 +# specific prior written permission.
     17 +#
     18 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
     19 +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     20 +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     21 +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
     22 +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     23 +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24 +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
     25 +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26 +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     27 +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28 +#
     29 +#
     30 +#
     31 +# 2012-01-31, Lars Bilke
     32 +# - Enable Code Coverage
     33 +#
     34 +# 2013-09-17, Joakim Söderberg
     35 +# - Added support for Clang.
     36 +# - Some additional usage instructions.
     37 +#
     38 +# USAGE:
     39 + 
     40 +# 0. (Mac only) If you use Xcode 5.1 make sure to patch geninfo as described here:
     41 +# http://stackoverflow.com/a/22404544/80480
     42 +#
     43 +# 1. Copy this file into your cmake modules path.
     44 +#
     45 +# 2. Add the following line to your CMakeLists.txt:
     46 +# INCLUDE(CodeCoverage)
     47 +#
     48 +# 3. Set compiler flags to turn off optimization and enable coverage:
     49 +# SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
     50 +# SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
     51 +#
     52 +# 3. Use the function SETUP_TARGET_FOR_COVERAGE to create a custom make target
     53 +# which runs your test executable and produces a lcov code coverage report:
     54 +# Example:
     55 +# SETUP_TARGET_FOR_COVERAGE(
     56 +# my_coverage_target # Name for custom target.
     57 +# test_driver # Name of the test driver executable that runs the tests.
     58 +# # NOTE! This should always have a ZERO as exit code
     59 +# # otherwise the coverage generation will not complete.
     60 +# coverage # Name of output directory.
     61 +# )
     62 +#
     63 +# 4. Build a Debug build:
     64 +# cmake -DCMAKE_BUILD_TYPE=Debug ..
     65 +# make
     66 +# make my_coverage_target
     67 +#
     68 +#
     69 + 
     70 +# Check prereqs
     71 +FIND_PROGRAM( GCOV_PATH gcov )
     72 +FIND_PROGRAM( LCOV_PATH lcov )
     73 +FIND_PROGRAM( GENHTML_PATH genhtml )
     74 +FIND_PROGRAM( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/tests)
     75 + 
     76 +IF(NOT GCOV_PATH)
     77 + MESSAGE(FATAL_ERROR "gcov not found! Aborting...")
     78 +ENDIF() # NOT GCOV_PATH
     79 + 
     80 +IF("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
     81 + IF("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 3)
     82 + MESSAGE(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...")
     83 + ENDIF()
     84 +ELSEIF(NOT CMAKE_COMPILER_IS_GNUCXX)
     85 + MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...")
     86 +ENDIF() # CHECK VALID COMPILER
     87 + 
     88 +SET(CMAKE_CXX_FLAGS_COVERAGE
     89 + "-g -O0 --coverage -fprofile-arcs -ftest-coverage"
     90 + CACHE STRING "Flags used by the C++ compiler during coverage builds."
     91 + FORCE )
     92 +SET(CMAKE_C_FLAGS_COVERAGE
     93 + "-g -O0 --coverage -fprofile-arcs -ftest-coverage"
     94 + CACHE STRING "Flags used by the C compiler during coverage builds."
     95 + FORCE )
     96 +SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE
     97 + ""
     98 + CACHE STRING "Flags used for linking binaries during coverage builds."
     99 + FORCE )
     100 +SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
     101 + ""
     102 + CACHE STRING "Flags used by the shared libraries linker during coverage builds."
     103 + FORCE )
     104 +MARK_AS_ADVANCED(
     105 + CMAKE_CXX_FLAGS_COVERAGE
     106 + CMAKE_C_FLAGS_COVERAGE
     107 + CMAKE_EXE_LINKER_FLAGS_COVERAGE
     108 + CMAKE_SHARED_LINKER_FLAGS_COVERAGE )
     109 + 
     110 +IF ( NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "Coverage"))
     111 + MESSAGE( WARNING "Code coverage results with an optimized (non-Debug) build may be misleading" )
     112 +ENDIF() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug"
     113 + 
     114 + 
     115 +# Param _targetname The name of new the custom make target
     116 +# Param _testrunner The name of the target which runs the tests.
     117 +# MUST return ZERO always, even on errors.
     118 +# If not, no coverage report will be created!
     119 +# Param _outputname lcov output is generated as _outputname.info
     120 +# HTML report is generated in _outputname/index.html
     121 +# Optional fourth parameter is passed as arguments to _testrunner
     122 +# Pass them in list form, e.g.: "-j;2" for -j 2
     123 +FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname)
     124 + 
     125 + IF(NOT LCOV_PATH)
     126 + MESSAGE(FATAL_ERROR "lcov not found! Aborting...")
     127 + ENDIF() # NOT LCOV_PATH
     128 + 
     129 + IF(NOT GENHTML_PATH)
     130 + MESSAGE(FATAL_ERROR "genhtml not found! Aborting...")
     131 + ENDIF() # NOT GENHTML_PATH
     132 + 
     133 + SET(coverage_info "${CMAKE_BINARY_DIR}/${_outputname}.info")
     134 + SET(coverage_cleaned "${coverage_info}.cleaned")
     135 + 
     136 + SEPARATE_ARGUMENTS(test_command UNIX_COMMAND "${_testrunner}")
     137 + 
     138 + # Setup target
     139 + ADD_CUSTOM_TARGET(${_targetname}
     140 + 
     141 + # Cleanup lcov
     142 + ${LCOV_PATH} --directory . --zerocounters
     143 + 
     144 + # Run tests
     145 + COMMAND ${test_command} ${ARGV3}
     146 + 
     147 + # Capturing lcov counters and generating report
     148 + COMMAND ${LCOV_PATH} --directory . --capture --output-file ${coverage_info}
     149 + COMMAND ${LCOV_PATH} --remove ${coverage_info} 'tests/*' '/usr/*' --output-file ${coverage_cleaned}
     150 + COMMAND ${GENHTML_PATH} -o ${_outputname} ${coverage_cleaned}
     151 + COMMAND ${CMAKE_COMMAND} -E remove ${coverage_info} ${coverage_cleaned}
     152 + 
     153 + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
     154 + COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
     155 + )
     156 + 
     157 + # Show info where to find the report
     158 + ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
     159 + COMMAND ;
     160 + COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report."
     161 + )
     162 + 
     163 +ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE
     164 + 
     165 +# Param _targetname The name of new the custom make target
     166 +# Param _testrunner The name of the target which runs the tests
     167 +# Param _outputname cobertura output is generated as _outputname.xml
     168 +# Optional fourth parameter is passed as arguments to _testrunner
     169 +# Pass them in list form, e.g.: "-j;2" for -j 2
     170 +FUNCTION(SETUP_TARGET_FOR_COVERAGE_COBERTURA _targetname _testrunner _outputname)
     171 + 
     172 + IF(NOT PYTHON_EXECUTABLE)
     173 + MESSAGE(FATAL_ERROR "Python not found! Aborting...")
     174 + ENDIF() # NOT PYTHON_EXECUTABLE
     175 + 
     176 + IF(NOT GCOVR_PATH)
     177 + MESSAGE(FATAL_ERROR "gcovr not found! Aborting...")
     178 + ENDIF() # NOT GCOVR_PATH
     179 + 
     180 + ADD_CUSTOM_TARGET(${_targetname}
     181 + 
     182 + # Run tests
     183 + ${_testrunner} ${ARGV3}
     184 + 
     185 + # Running gcovr
     186 + COMMAND ${GCOVR_PATH} -x -r ${CMAKE_SOURCE_DIR} -e '${CMAKE_SOURCE_DIR}/tests/' -o ${_outputname}.xml
     187 + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
     188 + COMMENT "Running gcovr to produce Cobertura code coverage report."
     189 + )
     190 + 
     191 + # Show info where to find the report
     192 + ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
     193 + COMMAND ;
     194 + COMMENT "Cobertura code coverage report saved in ${_outputname}.xml."
     195 + )
     196 + 
     197 +ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE_COBERTURA
     198 + 
  • ■ ■ ■ ■ ■ ■
    CMakeModules/CppcheckTargets.cmake
     1 +# - Run cppcheck on c++ source files as a custom target and a test
     2 +#
     3 +# include(CppcheckTargets)
     4 +# add_cppcheck(<target-name> [UNUSED_FUNCTIONS] [STYLE] [POSSIBLE_ERROR] [FORCE] [FAIL_ON_WARNINGS]) -
     5 +# Create a target to check a target's sources with cppcheck and the indicated options
     6 +# add_cppcheck_sources(<target-name> [UNUSED_FUNCTIONS] [STYLE] [POSSIBLE_ERROR] [FORCE] [FAIL_ON_WARNINGS]) -
     7 +# Create a target to check standalone sources with cppcheck and the indicated options
     8 +#
     9 +# Requires these CMake modules:
     10 +# Findcppcheck
     11 +#
     12 +# Requires CMake 2.6 or newer (uses the 'function' command)
     13 +#
     14 +# Original Author:
     15 +# 2009-2010 Ryan Pavlik <[email protected]> <[email protected]>
     16 +# http://academic.cleardefinition.com
     17 +# Iowa State University HCI Graduate Program/VRAC
     18 +#
     19 +# Copyright Iowa State University 2009-2010.
     20 +# Distributed under the Boost Software License, Version 1.0.
     21 +# (See accompanying file LICENSE_1_0.txt or copy at
     22 +# http://www.boost.org/LICENSE_1_0.txt)
     23 + 
     24 +if(__add_cppcheck)
     25 + return()
     26 +endif()
     27 +set(__add_cppcheck YES)
     28 + 
     29 +if(NOT CPPCHECK_FOUND)
     30 + find_package(cppcheck QUIET)
     31 +endif()
     32 + 
     33 +if(CPPCHECK_FOUND)
     34 + if(NOT TARGET all_cppcheck)
     35 + add_custom_target(all_cppcheck)
     36 + set_target_properties(all_cppcheck PROPERTIES EXCLUDE_FROM_ALL TRUE)
     37 + endif()
     38 +endif()
     39 + 
     40 +function(add_cppcheck_sources _targetname)
     41 + if(CPPCHECK_FOUND)
     42 + set(_cppcheck_args)
     43 + set(_input ${ARGN})
     44 + list(FIND _input UNUSED_FUNCTIONS _unused_func)
     45 + if("${_unused_func}" GREATER "-1")
     46 + list(APPEND _cppcheck_args ${CPPCHECK_UNUSEDFUNC_ARG})
     47 + list(REMOVE_AT _input ${_unused_func})
     48 + endif()
     49 + 
     50 + list(FIND _input STYLE _style)
     51 + if("${_style}" GREATER "-1")
     52 + list(APPEND _cppcheck_args ${CPPCHECK_STYLE_ARG})
     53 + list(REMOVE_AT _input ${_style})
     54 + endif()
     55 + 
     56 + list(FIND _input POSSIBLE_ERROR _poss_err)
     57 + if("${_poss_err}" GREATER "-1")
     58 + list(APPEND _cppcheck_args ${CPPCHECK_POSSIBLEERROR_ARG})
     59 + list(REMOVE_AT _input ${_poss_err})
     60 + endif()
     61 + 
     62 + list(FIND _input FORCE _force)
     63 + if("${_force}" GREATER "-1")
     64 + list(APPEND _cppcheck_args "--force")
     65 + list(REMOVE_AT _input ${_force})
     66 + endif()
     67 + 
     68 + list(FIND _input FAIL_ON_WARNINGS _fail_on_warn)
     69 + if("${_fail_on_warn}" GREATER "-1")
     70 + list(APPEND
     71 + CPPCHECK_FAIL_REGULAR_EXPRESSION
     72 + ${CPPCHECK_WARN_REGULAR_EXPRESSION})
     73 + list(REMOVE_AT _input ${_fail_on_warn})
     74 + endif()
     75 + 
     76 + set(_files)
     77 + foreach(_source ${_input})
     78 + get_source_file_property(_cppcheck_loc "${_source}" LOCATION)
     79 + if(_cppcheck_loc)
     80 + # This file has a source file property, carry on.
     81 + get_source_file_property(_cppcheck_lang "${_source}" LANGUAGE)
     82 + if("${_cppcheck_lang}" MATCHES "CXX")
     83 + list(APPEND _files "${_cppcheck_loc}")
     84 + endif()
     85 + else()
     86 + # This file doesn't have source file properties - figure it out.
     87 + get_filename_component(_cppcheck_loc "${_source}" ABSOLUTE)
     88 + if(EXISTS "${_cppcheck_loc}")
     89 + list(APPEND _files "${_cppcheck_loc}")
     90 + else()
     91 + message(FATAL_ERROR
     92 + "Adding CPPCHECK for file target ${_targetname}: "
     93 + "File ${_source} does not exist or needs a corrected path location "
     94 + "since we think its absolute path is ${_cppcheck_loc}")
     95 + endif()
     96 + endif()
     97 + endforeach()
     98 + 
     99 + if("1.${CMAKE_VERSION}" VERSION_LESS "1.2.8.0")
     100 + # Older than CMake 2.8.0
     101 + add_test(${_targetname}_cppcheck_test
     102 + "${CPPCHECK_EXECUTABLE}"
     103 + ${CPPCHECK_TEMPLATE_ARG}
     104 + ${_cppcheck_args} "--inline-suppr"
     105 + ${_files})
     106 + else()
     107 + # CMake 2.8.0 and newer
     108 + add_test(NAME
     109 + ${_targetname}_cppcheck_test
     110 + COMMAND
     111 + "${CPPCHECK_EXECUTABLE}"
     112 + ${CPPCHECK_TEMPLATE_ARG}
     113 + ${_cppcheck_args} "--inline-suppr"
     114 + ${_files})
     115 + endif()
     116 + 
     117 + set_tests_properties(${_targetname}_cppcheck_test
     118 + PROPERTIES
     119 + FAIL_REGULAR_EXPRESSION
     120 + "${CPPCHECK_FAIL_REGULAR_EXPRESSION}")
     121 + 
     122 + add_custom_command(TARGET
     123 + all_cppcheck
     124 + PRE_BUILD
     125 + COMMAND
     126 + ${CPPCHECK_EXECUTABLE}
     127 + ${CPPCHECK_QUIET_ARG}
     128 + ${CPPCHECK_TEMPLATE_ARG}
     129 + ${_cppcheck_args} "--inline-suppr"
     130 + ${_files}
     131 + WORKING_DIRECTORY
     132 + "${CMAKE_CURRENT_SOURCE_DIR}"
     133 + COMMENT
     134 + "${_targetname}_cppcheck: Running cppcheck on target ${_targetname}..."
     135 + VERBATIM)
     136 + endif()
     137 +endfunction()
     138 + 
     139 +function(add_cppcheck _name)
     140 + if(NOT TARGET ${_name})
     141 + message(FATAL_ERROR
     142 + "add_cppcheck given a target name that does not exist: '${_name}' !")
     143 + endif()
     144 + if(CPPCHECK_FOUND)
     145 + set(_cppcheck_args CACHE STRING "${_cppcheck_args} ")
     146 + #set(_cppcheck_args "${_cppcheck_args} ")
     147 + list(FIND ARGN UNUSED_FUNCTIONS _unused_func)
     148 + if("${_unused_func}" GREATER "-1")
     149 + list(APPEND _cppcheck_args ${CPPCHECK_UNUSEDFUNC_ARG})
     150 + endif()
     151 + 
     152 + list(FIND ARGN STYLE _style)
     153 + if("${_style}" GREATER "-1")
     154 + list(APPEND _cppcheck_args ${CPPCHECK_STYLE_ARG})
     155 + endif()
     156 + 
     157 + list(FIND ARGN POSSIBLE_ERROR _poss_err)
     158 + if("${_poss_err}" GREATER "-1")
     159 + list(APPEND _cppcheck_args ${CPPCHECK_POSSIBLEERROR_ARG})
     160 + endif()
     161 + 
     162 + list(FIND ARGN FORCE _force)
     163 + if("${_force}" GREATER "-1")
     164 + list(APPEND _cppcheck_args "--force")
     165 + endif()
     166 + 
     167 + list(FIND _input FAIL_ON_WARNINGS _fail_on_warn)
     168 + if("${_fail_on_warn}" GREATER "-1")
     169 + list(APPEND
     170 + CPPCHECK_FAIL_REGULAR_EXPRESSION
     171 + ${CPPCHECK_WARN_REGULAR_EXPRESSION})
     172 + list(REMOVE_AT _input ${_unused_func})
     173 + endif()
     174 + 
     175 + get_target_property(_cppcheck_includes "${_name}" INCLUDE_DIRECTORIES)
     176 + set(_includes)
     177 + foreach(_include ${_cppcheck_includes})
     178 + list(APPEND _includes "-I${_include}")
     179 + endforeach()
     180 + 
     181 + get_target_property(_cppcheck_sources "${_name}" SOURCES)
     182 + set(_files)
     183 + foreach(_source ${_cppcheck_sources})
     184 + get_source_file_property(_cppcheck_lang "${_source}" LANGUAGE)
     185 + get_source_file_property(_cppcheck_loc "${_source}" LOCATION)
     186 + if("${_cppcheck_lang}" MATCHES "CXX")
     187 + list(APPEND _files "${_cppcheck_loc}")
     188 + endif()
     189 + endforeach()
     190 + 
     191 + if("1.${CMAKE_VERSION}" VERSION_LESS "1.2.8.0")
     192 + # Older than CMake 2.8.0
     193 + add_test(${_name}_cppcheck_test
     194 + "${CPPCHECK_EXECUTABLE}"
     195 + ${CPPCHECK_TEMPLATE_ARG}
     196 + ${_cppcheck_args} "--inline-suppr"
     197 + ${_files})
     198 + else()
     199 + # CMake 2.8.0 and newer
     200 + add_test(NAME
     201 + ${_name}_cppcheck_test
     202 + COMMAND
     203 + "${CPPCHECK_EXECUTABLE}"
     204 + ${CPPCHECK_TEMPLATE_ARG}
     205 + ${_cppcheck_args} "--inline-suppr"
     206 + ${_files})
     207 + endif()
     208 + 
     209 + set_tests_properties(${_name}_cppcheck_test
     210 + PROPERTIES
     211 + FAIL_REGULAR_EXPRESSION
     212 + "${CPPCHECK_FAIL_REGULAR_EXPRESSION}")
     213 + MESSAGE(STATUS "CPPCHECKargs: ${_cppcheck_args}")
     214 + add_custom_command(TARGET
     215 + all_cppcheck
     216 + PRE_BUILD
     217 + COMMAND
     218 + ${CPPCHECK_EXECUTABLE}
     219 + ${CPPCHECK_QUIET_ARG}
     220 + ${CPPCHECK_TEMPLATE_ARG}
     221 + ${_cppcheck_args} "--inline-suppr"
     222 + ${_includes}
     223 + ${_files}
     224 + WORKING_DIRECTORY
     225 + "${CMAKE_CURRENT_SOURCE_DIR}"
     226 + COMMENT
     227 + "${_name}_cppcheck: Running cppcheck on target ${_name}..."
     228 + VERBATIM)
     229 + endif()
     230 + 
     231 +endfunction()
     232 + 
  • ■ ■ ■ ■ ■ ■
    CMakeModules/FindYamlCpp.cmake
     1 +# Locate yaml-cpp
     2 +#
     3 +# This module defines
     4 +# YAMLCPP_FOUND, if false, do not try to link to yaml-cpp
     5 +# YAMLCPP_LIBNAME, name of yaml library
     6 +# YAMLCPP_LIBRARY, where to find yaml-cpp
     7 +# YAMLCPP_LIBRARY_RELEASE, where to find Release or RelWithDebInfo yaml-cpp
     8 +# YAMLCPP_LIBRARY_DEBUG, where to find Debug yaml-cpp
     9 +# YAMLCPP_INCLUDE_DIR, where to find yaml.h
     10 +# YAMLCPP_LIBRARY_DIR, the directories to find YAMLCPP_LIBRARY
     11 +#
     12 +# By default, the dynamic libraries of yaml-cpp will be found. To find the static ones instead,
     13 +# you must set the YAMLCPP_USE_STATIC_LIBS variable to TRUE before calling find_package(YamlCpp ...)
     14 + 
     15 +# attempt to find static library first if this is set
     16 +if(YAMLCPP_USE_STATIC_LIBS)
     17 + set(YAMLCPP_STATIC libyaml-cpp.a)
     18 + set(YAMLCPP_STATIC_DEBUG libyaml-cpp-dbg.a)
     19 +endif()
     20 + 
     21 +if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") ### Set Yaml libary name for Windows
     22 + set(YAMLCPP_LIBNAME "libyaml-cppmd" CACHE STRING "Name of YAML library")
     23 + set(YAMLCPP_LIBNAME optimized ${YAMLCPP_LIBNAME} debug ${YAMLCPP_LIBNAME}d)
     24 +else() ### Set Yaml libary name for Unix, Linux, OS X, etc
     25 + set(YAMLCPP_LIBNAME "yaml-cpp" CACHE STRING "Name of YAML library")
     26 +endif()
     27 + 
     28 +# find the yaml-cpp include directory
     29 +find_path(YAMLCPP_INCLUDE_DIR
     30 + NAMES yaml-cpp/yaml.h
     31 + PATH_SUFFIXES include
     32 + PATHS
     33 + ${PROJECT_SOURCE_DIR}/dependencies/yaml-cpp-0.5.1/include
     34 + ~/Library/Frameworks/yaml-cpp/include/
     35 + /Library/Frameworks/yaml-cpp/include/
     36 + /usr/local/include/
     37 + /usr/include/
     38 + /sw/yaml-cpp/ # Fink
     39 + /opt/local/yaml-cpp/ # DarwinPorts
     40 + /opt/csw/yaml-cpp/ # Blastwave
     41 + /opt/yaml-cpp/)
     42 + 
     43 +# find the release yaml-cpp library
     44 +find_library(YAMLCPP_LIBRARY_RELEASE
     45 + NAMES ${YAMLCPP_STATIC} yaml-cpp libyaml-cppmd.lib
     46 + PATH_SUFFIXES lib64 lib Release RelWithDebInfo
     47 + PATHS
     48 + ${PROJECT_SOURCE_DIR}/dependencies/yaml-cpp-0.5.1/
     49 + ${PROJECT_SOURCE_DIR}/dependencies/yaml-cpp-0.5.1/build
     50 + ~/Library/Frameworks
     51 + /Library/Frameworks
     52 + /usr/local
     53 + /usr
     54 + /sw
     55 + /opt/local
     56 + /opt/csw
     57 + /opt)
     58 + 
     59 +# find the debug yaml-cpp library
     60 +find_library(YAMLCPP_LIBRARY_DEBUG
     61 + NAMES ${YAMLCPP_STATIC_DEBUG} yaml-cpp-dbg libyaml-cppmdd.lib
     62 + PATH_SUFFIXES lib64 lib Debug
     63 + PATHS
     64 + ${PROJECT_SOURCE_DIR}/dependencies/yaml-cpp-0.5.1/
     65 + ${PROJECT_SOURCE_DIR}/dependencies/yaml-cpp-0.5.1/build
     66 + ~/Library/Frameworks
     67 + /Library/Frameworks
     68 + /usr/local
     69 + /usr
     70 + /sw
     71 + /opt/local
     72 + /opt/csw
     73 + /opt)
     74 + 
     75 +# set library vars
     76 +set(YAMLCPP_LIBRARY ${YAMLCPP_LIBRARY_RELEASE})
     77 +if(CMAKE_BUILD_TYPE MATCHES Debug AND EXISTS ${YAMLCPP_LIBRARY_DEBUG})
     78 + set(YAMLCPP_LIBRARY ${YAMLCPP_LIBRARY_DEBUG})
     79 +endif()
     80 + 
     81 +get_filename_component(YAMLCPP_LIBRARY_RELEASE_DIR ${YAMLCPP_LIBRARY_RELEASE} PATH)
     82 +get_filename_component(YAMLCPP_LIBRARY_DEBUG_DIR ${YAMLCPP_LIBRARY_DEBUG} PATH)
     83 +set(YAMLCPP_LIBRARY_DIR ${YAMLCPP_LIBRARY_RELEASE_DIR} ${YAMLCPP_LIBRARY_DEBUG_DIR})
     84 + 
     85 +# handle the QUIETLY and REQUIRED arguments and set YAMLCPP_FOUND to TRUE if all listed variables are TRUE
     86 +include(FindPackageHandleStandardArgs)
     87 +FIND_PACKAGE_HANDLE_STANDARD_ARGS(YamlCpp DEFAULT_MSG
     88 + YAMLCPP_INCLUDE_DIR
     89 + YAMLCPP_LIBRARY
     90 + YAMLCPP_LIBRARY_DIR)
     91 +mark_as_advanced(
     92 + YAMLCPP_INCLUDE_DIR
     93 + YAMLCPP_LIBRARY_DIR
     94 + YAMLCPP_LIBRARY
     95 + YAMLCPP_LIBRARY_RELEASE
     96 + YAMLCPP_LIBRARY_RELEASE_DIR
     97 + YAMLCPP_LIBRARY_DEBUG
     98 + YAMLCPP_LIBRARY_DEBUG_DIR)
     99 + 
  • ■ ■ ■ ■ ■ ■
    CMakeModules/Findcppcheck.cmake
     1 +# - try to find cppcheck tool
     2 +#
     3 +# Cache Variables:
     4 +# CPPCHECK_EXECUTABLE
     5 +#
     6 +# Non-cache variables you might use in your CMakeLists.txt:
     7 +# CPPCHECK_FOUND
     8 +# CPPCHECK_POSSIBLEERROR_ARG
     9 +# CPPCHECK_UNUSEDFUNC_ARG
     10 +# CPPCHECK_STYLE_ARG
     11 +# CPPCHECK_QUIET_ARG
     12 +# CPPCHECK_INCLUDEPATH_ARG
     13 +# CPPCHECK_FAIL_REGULAR_EXPRESSION
     14 +# CPPCHECK_WARN_REGULAR_EXPRESSION
     15 +# CPPCHECK_MARK_AS_ADVANCED - whether to mark our vars as advanced even
     16 +# if we don't find this program.
     17 +#
     18 +# Requires these CMake modules:
     19 +# FindPackageHandleStandardArgs (known included with CMake >=2.6.2)
     20 +#
     21 +# Original Author:
     22 +# 2009-2010 Ryan Pavlik <[email protected]> <[email protected]>
     23 +# http://academic.cleardefinition.com
     24 +# Iowa State University HCI Graduate Program/VRAC
     25 +#
     26 +# Copyright Iowa State University 2009-2010.
     27 +# Distributed under the Boost Software License, Version 1.0.
     28 +# (See accompanying file LICENSE_1_0.txt or copy at
     29 +# http://www.boost.org/LICENSE_1_0.txt)
     30 + 
     31 +file(TO_CMAKE_PATH "${CPPCHECK_ROOT_DIR}" CPPCHECK_ROOT_DIR)
     32 +set(CPPCHECK_ROOT_DIR
     33 + "${CPPCHECK_ROOT_DIR}"
     34 + CACHE
     35 + PATH
     36 + "Path to search for cppcheck")
     37 + 
     38 +# cppcheck app bundles on Mac OS X are GUI, we want command line only
     39 +set(_oldappbundlesetting ${CMAKE_FIND_APPBUNDLE})
     40 +set(CMAKE_FIND_APPBUNDLE NEVER)
     41 + 
     42 +if(CPPCHECK_EXECUTABLE AND NOT EXISTS "${CPPCHECK_EXECUTABLE}")
     43 + set(CPPCHECK_EXECUTABLE "notfound" CACHE PATH FORCE "")
     44 +endif()
     45 + 
     46 +# If we have a custom path, look there first.
     47 +if(CPPCHECK_ROOT_DIR)
     48 + find_program(CPPCHECK_EXECUTABLE
     49 + NAMES
     50 + cppcheck
     51 + cli
     52 + PATHS
     53 + "${CPPCHECK_ROOT_DIR}"
     54 + PATH_SUFFIXES
     55 + cli
     56 + NO_DEFAULT_PATH)
     57 +endif()
     58 + 
     59 +find_program(CPPCHECK_EXECUTABLE NAMES cppcheck)
     60 + 
     61 +# Restore original setting for appbundle finding
     62 +set(CMAKE_FIND_APPBUNDLE ${_oldappbundlesetting})
     63 + 
     64 +# Find out where our test file is
     65 +get_filename_component(_cppcheckmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
     66 +set(_cppcheckdummyfile "${_cppcheckmoddir}/Findcppcheck.cpp")
     67 +if(NOT EXISTS "${_cppcheckdummyfile}")
     68 + message(FATAL_ERROR
     69 + "Missing file ${_cppcheckdummyfile} - should be alongside Findcppcheck.cmake, can be found at https://github.com/rpavlik/cmake-modules")
     70 +endif()
     71 + 
     72 +function(_cppcheck_test_arg _resultvar _arg)
     73 + if(NOT CPPCHECK_EXECUTABLE)
     74 + set(${_resultvar} NO)
     75 + return()
     76 + endif()
     77 + execute_process(COMMAND
     78 + "${CPPCHECK_EXECUTABLE}"
     79 + "${_arg}"
     80 + "--quiet"
     81 + "${_cppcheckdummyfile}"
     82 + RESULT_VARIABLE
     83 + _cppcheck_result
     84 + OUTPUT_QUIET
     85 + ERROR_QUIET)
     86 + if("${_cppcheck_result}" EQUAL 0)
     87 + set(${_resultvar} YES PARENT_SCOPE)
     88 + else()
     89 + set(${_resultvar} NO PARENT_SCOPE)
     90 + endif()
     91 +endfunction()
     92 + 
     93 +function(_cppcheck_set_arg_var _argvar _arg)
     94 + if("${${_argvar}}" STREQUAL "")
     95 + _cppcheck_test_arg(_cppcheck_arg "${_arg}")
     96 + if(_cppcheck_arg)
     97 + set(${_argvar} "${_arg}" PARENT_SCOPE)
     98 + endif()
     99 + endif()
     100 +endfunction()
     101 + 
     102 +if(CPPCHECK_EXECUTABLE)
     103 + 
     104 + # Check for the two types of command line arguments by just trying them
     105 + _cppcheck_set_arg_var(CPPCHECK_STYLE_ARG "--enable=style")
     106 + _cppcheck_set_arg_var(CPPCHECK_STYLE_ARG "--style")
     107 + if("${CPPCHECK_STYLE_ARG}" STREQUAL "--enable=style")
     108 + 
     109 + _cppcheck_set_arg_var(CPPCHECK_UNUSEDFUNC_ARG
     110 + "--enable=unusedFunction")
     111 + _cppcheck_set_arg_var(CPPCHECK_INFORMATION_ARG "--enable=information")
     112 + _cppcheck_set_arg_var(CPPCHECK_MISSINGINCLUDE_ARG
     113 + "--enable=missingInclude")
     114 + _cppcheck_set_arg_var(CPPCHECK_POSIX_ARG "--enable=posix")
     115 + _cppcheck_set_arg_var(CPPCHECK_POSSIBLEERROR_ARG
     116 + "--enable=possibleError")
     117 + _cppcheck_set_arg_var(CPPCHECK_POSSIBLEERROR_ARG "--enable=all")
     118 + 
     119 + if(MSVC)
     120 + set(CPPCHECK_TEMPLATE_ARG --template vs)
     121 + set(CPPCHECK_FAIL_REGULAR_EXPRESSION "[(]error[)]")
     122 + set(CPPCHECK_WARN_REGULAR_EXPRESSION "[(]style[)]")
     123 + elseif(CMAKE_COMPILER_IS_GNUCXX)
     124 + set(CPPCHECK_TEMPLATE_ARG --template gcc)
     125 + set(CPPCHECK_FAIL_REGULAR_EXPRESSION " error: ")
     126 + set(CPPCHECK_WARN_REGULAR_EXPRESSION " style: ")
     127 + else()
     128 + set(CPPCHECK_TEMPLATE_ARG --template gcc)
     129 + set(CPPCHECK_FAIL_REGULAR_EXPRESSION " error: ")
     130 + set(CPPCHECK_WARN_REGULAR_EXPRESSION " style: ")
     131 + endif()
     132 + elseif("${CPPCHECK_STYLE_ARG}" STREQUAL "--style")
     133 + # Old arguments
     134 + _cppcheck_set_arg_var(CPPCHECK_UNUSEDFUNC_ARG "--unused-functions")
     135 + _cppcheck_set_arg_var(CPPCHECK_POSSIBLEERROR_ARG "--all")
     136 + set(CPPCHECK_FAIL_REGULAR_EXPRESSION "error:")
     137 + set(CPPCHECK_WARN_REGULAR_EXPRESSION "[(]style[)]")
     138 + else()
     139 + # No idea - some other issue must be getting in the way
     140 + message(STATUS
     141 + "WARNING: Can't detect whether CPPCHECK wants new or old-style arguments!")
     142 + endif()
     143 + 
     144 + set(CPPCHECK_QUIET_ARG "--quiet")
     145 + set(CPPCHECK_INCLUDEPATH_ARG "-I")
     146 + 
     147 +endif()
     148 + 
     149 +set(CPPCHECK_ALL
     150 + "${CPPCHECK_EXECUTABLE} ${CPPCHECK_POSSIBLEERROR_ARG} ${CPPCHECK_UNUSEDFUNC_ARG} ${CPPCHECK_STYLE_ARG} ${CPPCHECK_QUIET_ARG} ${CPPCHECK_INCLUDEPATH_ARG} some/include/path")
     151 + 
     152 +include(FindPackageHandleStandardArgs)
     153 +find_package_handle_standard_args(cppcheck
     154 + DEFAULT_MSG
     155 + CPPCHECK_ALL
     156 + CPPCHECK_EXECUTABLE
     157 + CPPCHECK_POSSIBLEERROR_ARG
     158 + CPPCHECK_UNUSEDFUNC_ARG
     159 + CPPCHECK_STYLE_ARG
     160 + CPPCHECK_INCLUDEPATH_ARG
     161 + CPPCHECK_QUIET_ARG)
     162 + 
     163 +if(CPPCHECK_FOUND OR CPPCHECK_MARK_AS_ADVANCED)
     164 + mark_as_advanced(CPPCHECK_ROOT_DIR)
     165 +endif()
     166 + 
     167 +mark_as_advanced(CPPCHECK_EXECUTABLE)
     168 + 
  • ■ ■ ■ ■ ■ ■
    CMakeModules/Findcppcheck.cpp
     1 +/**
     2 + * \file Findcppcheck.cpp
     3 + * \brief Dummy C++ source file used by CMake module Findcppcheck.cmake
     4 + *
     5 + * \author
     6 + * Ryan Pavlik, 2009-2010
     7 + * <[email protected]>
     8 + * http://academic.cleardefinition.com/
     9 + *
     10 + */
     11 + 
     12 + 
     13 + 
     14 +int main(int argc, char* argv[]) {
     15 + return 0;
     16 +}
     17 + 
  • ■ ■ ■ ■ ■ ■
    CMakeModules/Toolchain-mingw32.cmake
     1 +SET(CROSS_COMPILE_WINDOWS ON)
     2 + 
     3 +# the name of the target operating system
     4 +SET(CMAKE_SYSTEM_NAME Windows)
     5 + 
     6 +# which compilers to use for C and C++
     7 +SET(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
     8 +SET(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
     9 +SET(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
     10 + 
     11 +# here is the target environment located
     12 +SET(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
     13 + 
     14 +# adjust the default behaviour of the FIND_XXX() commands:
     15 +# search headers and libraries in the target environment, search
     16 +# programs in the host environment
     17 +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
     18 +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
     19 +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
     20 + 
  • ■ ■ ■ ■ ■ ■
    LICENSE
     1 + Apache License
     2 + Version 2.0, January 2004
     3 + http://www.apache.org/licenses/
     4 + 
     5 + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
     6 + 
     7 + 1. Definitions.
     8 + 
     9 + "License" shall mean the terms and conditions for use, reproduction,
     10 + and distribution as defined by Sections 1 through 9 of this document.
     11 + 
     12 + "Licensor" shall mean the copyright owner or entity authorized by
     13 + the copyright owner that is granting the License.
     14 + 
     15 + "Legal Entity" shall mean the union of the acting entity and all
     16 + other entities that control, are controlled by, or are under common
     17 + control with that entity. For the purposes of this definition,
     18 + "control" means (i) the power, direct or indirect, to cause the
     19 + direction or management of such entity, whether by contract or
     20 + otherwise, or (ii) ownership of fifty percent (50%) or more of the
     21 + outstanding shares, or (iii) beneficial ownership of such entity.
     22 + 
     23 + "You" (or "Your") shall mean an individual or Legal Entity
     24 + exercising permissions granted by this License.
     25 + 
     26 + "Source" form shall mean the preferred form for making modifications,
     27 + including but not limited to software source code, documentation
     28 + source, and configuration files.
     29 + 
     30 + "Object" form shall mean any form resulting from mechanical
     31 + transformation or translation of a Source form, including but
     32 + not limited to compiled object code, generated documentation,
     33 + and conversions to other media types.
     34 + 
     35 + "Work" shall mean the work of authorship, whether in Source or
     36 + Object form, made available under the License, as indicated by a
     37 + copyright notice that is included in or attached to the work
     38 + (an example is provided in the Appendix below).
     39 + 
     40 + "Derivative Works" shall mean any work, whether in Source or Object
     41 + form, that is based on (or derived from) the Work and for which the
     42 + editorial revisions, annotations, elaborations, or other modifications
     43 + represent, as a whole, an original work of authorship. For the purposes
     44 + of this License, Derivative Works shall not include works that remain
     45 + separable from, or merely link (or bind by name) to the interfaces of,
     46 + the Work and Derivative Works thereof.
     47 + 
     48 + "Contribution" shall mean any work of authorship, including
     49 + the original version of the Work and any modifications or additions
     50 + to that Work or Derivative Works thereof, that is intentionally
     51 + submitted to Licensor for inclusion in the Work by the copyright owner
     52 + or by an individual or Legal Entity authorized to submit on behalf of
     53 + the copyright owner. For the purposes of this definition, "submitted"
     54 + means any form of electronic, verbal, or written communication sent
     55 + to the Licensor or its representatives, including but not limited to
     56 + communication on electronic mailing lists, source code control systems,
     57 + and issue tracking systems that are managed by, or on behalf of, the
     58 + Licensor for the purpose of discussing and improving the Work, but
     59 + excluding communication that is conspicuously marked or otherwise
     60 + designated in writing by the copyright owner as "Not a Contribution."
     61 + 
     62 + "Contributor" shall mean Licensor and any individual or Legal Entity
     63 + on behalf of whom a Contribution has been received by Licensor and
     64 + subsequently incorporated within the Work.
     65 + 
     66 + 2. Grant of Copyright License. Subject to the terms and conditions of
     67 + this License, each Contributor hereby grants to You a perpetual,
     68 + worldwide, non-exclusive, no-charge, royalty-free, irrevocable
     69 + copyright license to reproduce, prepare Derivative Works of,
     70 + publicly display, publicly perform, sublicense, and distribute the
     71 + Work and such Derivative Works in Source or Object form.
     72 + 
     73 + 3. Grant of Patent License. Subject to the terms and conditions of
     74 + this License, each Contributor hereby grants to You a perpetual,
     75 + worldwide, non-exclusive, no-charge, royalty-free, irrevocable
     76 + (except as stated in this section) patent license to make, have made,
     77 + use, offer to sell, sell, import, and otherwise transfer the Work,
     78 + where such license applies only to those patent claims licensable
     79 + by such Contributor that are necessarily infringed by their
     80 + Contribution(s) alone or by combination of their Contribution(s)
     81 + with the Work to which such Contribution(s) was submitted. If You
     82 + institute patent litigation against any entity (including a
     83 + cross-claim or counterclaim in a lawsuit) alleging that the Work
     84 + or a Contribution incorporated within the Work constitutes direct
     85 + or contributory patent infringement, then any patent licenses
     86 + granted to You under this License for that Work shall terminate
     87 + as of the date such litigation is filed.
     88 + 
     89 + 4. Redistribution. You may reproduce and distribute copies of the
     90 + Work or Derivative Works thereof in any medium, with or without
     91 + modifications, and in Source or Object form, provided that You
     92 + meet the following conditions:
     93 + 
     94 + (a) You must give any other recipients of the Work or
     95 + Derivative Works a copy of this License; and
     96 + 
     97 + (b) You must cause any modified files to carry prominent notices
     98 + stating that You changed the files; and
     99 + 
     100 + (c) You must retain, in the Source form of any Derivative Works
     101 + that You distribute, all copyright, patent, trademark, and
     102 + attribution notices from the Source form of the Work,
     103 + excluding those notices that do not pertain to any part of
     104 + the Derivative Works; and
     105 + 
     106 + (d) If the Work includes a "NOTICE" text file as part of its
     107 + distribution, then any Derivative Works that You distribute must
     108 + include a readable copy of the attribution notices contained
     109 + within such NOTICE file, excluding those notices that do not
     110 + pertain to any part of the Derivative Works, in at least one
     111 + of the following places: within a NOTICE text file distributed
     112 + as part of the Derivative Works; within the Source form or
     113 + documentation, if provided along with the Derivative Works; or,
     114 + within a display generated by the Derivative Works, if and
     115 + wherever such third-party notices normally appear. The contents
     116 + of the NOTICE file are for informational purposes only and
     117 + do not modify the License. You may add Your own attribution
     118 + notices within Derivative Works that You distribute, alongside
     119 + or as an addendum to the NOTICE text from the Work, provided
     120 + that such additional attribution notices cannot be construed
     121 + as modifying the License.
     122 + 
     123 + You may add Your own copyright statement to Your modifications and
     124 + may provide additional or different license terms and conditions
     125 + for use, reproduction, or distribution of Your modifications, or
     126 + for any such Derivative Works as a whole, provided Your use,
     127 + reproduction, and distribution of the Work otherwise complies with
     128 + the conditions stated in this License.
     129 + 
     130 + 5. Submission of Contributions. Unless You explicitly state otherwise,
     131 + any Contribution intentionally submitted for inclusion in the Work
     132 + by You to the Licensor shall be under the terms and conditions of
     133 + this License, without any additional terms or conditions.
     134 + Notwithstanding the above, nothing herein shall supersede or modify
     135 + the terms of any separate license agreement you may have executed
     136 + with Licensor regarding such Contributions.
     137 + 
     138 + 6. Trademarks. This License does not grant permission to use the trade
     139 + names, trademarks, service marks, or product names of the Licensor,
     140 + except as required for reasonable and customary use in describing the
     141 + origin of the Work and reproducing the content of the NOTICE file.
     142 + 
     143 + 7. Disclaimer of Warranty. Unless required by applicable law or
     144 + agreed to in writing, Licensor provides the Work (and each
     145 + Contributor provides its Contributions) on an "AS IS" BASIS,
     146 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
     147 + implied, including, without limitation, any warranties or conditions
     148 + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
     149 + PARTICULAR PURPOSE. You are solely responsible for determining the
     150 + appropriateness of using or redistributing the Work and assume any
     151 + risks associated with Your exercise of permissions under this License.
     152 + 
     153 + 8. Limitation of Liability. In no event and under no legal theory,
     154 + whether in tort (including negligence), contract, or otherwise,
     155 + unless required by applicable law (such as deliberate and grossly
     156 + negligent acts) or agreed to in writing, shall any Contributor be
     157 + liable to You for damages, including any direct, indirect, special,
     158 + incidental, or consequential damages of any character arising as a
     159 + result of this License or out of the use or inability to use the
     160 + Work (including but not limited to damages for loss of goodwill,
     161 + work stoppage, computer failure or malfunction, or any and all
     162 + other commercial damages or losses), even if such Contributor
     163 + has been advised of the possibility of such damages.
     164 + 
     165 + 9. Accepting Warranty or Additional Liability. While redistributing
     166 + the Work or Derivative Works thereof, You may choose to offer,
     167 + and charge a fee for, acceptance of support, warranty, indemnity,
     168 + or other liability obligations and/or rights consistent with this
     169 + License. However, in accepting such obligations, You may act only
     170 + on Your own behalf and on Your sole responsibility, not on behalf
     171 + of any other Contributor, and only if You agree to indemnify,
     172 + defend, and hold each Contributor harmless for any liability
     173 + incurred by, or claims asserted against, such Contributor by reason
     174 + of your accepting any such warranty or additional liability.
     175 + 
     176 + END OF TERMS AND CONDITIONS
     177 + 
     178 + APPENDIX: How to apply the Apache License to your work.
     179 + 
     180 + To apply the Apache License to your work, attach the following
     181 + boilerplate notice, with the fields enclosed by brackets "{}"
     182 + replaced with your own identifying information. (Don't include
     183 + the brackets!) The text should be enclosed in the appropriate
     184 + comment syntax for the file format. We also recommend that a
     185 + file or class name and description of purpose be included on the
     186 + same "printed page" as the copyright notice for easier
     187 + identification within third-party archives.
     188 + 
     189 + Copyright 2017 R. Thomas
     190 + Copyright 2017 Quarkslab
     191 + 
     192 + Licensed under the Apache License, Version 2.0 (the "License");
     193 + you may not use this file except in compliance with the License.
     194 + You may obtain a copy of the License at
     195 + 
     196 + http://www.apache.org/licenses/LICENSE-2.0
     197 + 
     198 + Unless required by applicable law or agreed to in writing, software
     199 + distributed under the License is distributed on an "AS IS" BASIS,
     200 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     201 + See the License for the specific language governing permissions and
     202 + limitations under the License.
     203 + 
  • ■ ■ ■ ■ ■ ■
    README.md
     1 +<p align="center" >
     2 +<img width="40%" src="http://romainthomas.fr/logo_blue_with_name_500.png"/><br />
     3 +</p>
     4 +<hr>
     5 +<p>
     6 + <a href="https://gitter.im/lief-project">
     7 + <img src="https://img.shields.io/gitter/room/gitterHQ/gitter.svg">
     8 + </a>
     9 + 
     10 +</p>
     11 + 
     12 +The purpose of this project is to provide a cross platform library which can parse, modify and abstract ELF, PE and MachO formats.
     13 + 
     14 +Main features:
     15 + 
     16 + * **Parsing**: LIEF can parse ELF, PE, MachO and provides an user-friendly API to access to format internals.
     17 + * **Modify**: LIEF enables to modify some parts of these formats
     18 + * **Abstract**: Three formats have common features like sections, symbols, entry point... LIEF factors them.
     19 + * **API**: LIEF can be used in C, C++ and Python
     20 + 
     21 +## Getting started
     22 + 
     23 +### Python
     24 + 
     25 +```python
     26 +import lief
     27 +# ELF
     28 +binary = lief.parse("/usr/bin/ls")
     29 +print(binary)
     30 + 
     31 +# PE
     32 +binary = lief.parse("C:\\Windows\\explorer.exe")
     33 +print(binary)
     34 + 
     35 +# Mach-O
     36 +binary = lief.parse("/usr/bin/ls")
     37 +print(binary)
     38 + 
     39 +```
     40 + 
     41 +### C++
     42 + 
     43 +```cpp
     44 +#include <LIEF/LIEF.hpp>
     45 +int main(int argc, const char** argv) {
     46 + LIEF::ELF::Binary* elf = LIEF::ELF::Parser::parse("/usr/bin/ls");
     47 + LIEF::PE::Binary* pe = LIEF::PE::Parser::parse("C:\\Windows\\explorer.exe");
     48 + LIEF::MachO::Binary* macho = LIEF::MachO::Parser::parse("/usr/bin/ls");
     49 + 
     50 + std::cout << *elf << std::endl;
     51 + std::cout << *pe << std::endl;
     52 + std::cout << *macho << std::endl;
     53 + 
     54 + delete elf;
     55 + delete pe;
     56 + delete macho;
     57 +}
     58 +```
     59 + 
     60 +### C
     61 + 
     62 +```cpp
     63 +#include <LIEF/LIEF.h>
     64 +int main(int argc, const char** argv) {
     65 + 
     66 + Elf_Binary_t* elf_binary = elf_parse("/usr/bin/ls");
     67 + Pe_Binary_t* pe_binary = pe_parse("C:\\Windows\\explorer.exe");
     68 + Macho_Binary_t** macho_binaries = macho_parse("/usr/bin/ls");
     69 + 
     70 + Pe_Section_t** pe_sections = pe_binary->sections;
     71 + Elf_Section_t** elf_sections = elf_binary->sections;
     72 + Macho_Section_t** macho_sections = macho_binaries[0]->sections;
     73 + 
     74 + for (size_t i = 0; pe_sections[i] != NULL; ++i) {
     75 + printf("%s\n", pe_sections[i]->name)
     76 + }
     77 + 
     78 + for (size_t i = 0; elf_sections[i] != NULL; ++i) {
     79 + printf("%s\n", elf_sections[i]->name)
     80 + }
     81 + 
     82 + for (size_t i = 0; macho_sections[i] != NULL; ++i) {
     83 + printf("%s\n", macho_sections[i]->name)
     84 + }
     85 + 
     86 + elf_binary_destroy(elf_binary);
     87 + pe_binary_destroy(pe_binary);
     88 + macho_binaries_destroy(macho_binaries);
     89 +}
     90 + 
     91 +```
     92 +## Documentation
     93 + 
     94 +* [Tutorial](http://lief.quarkslab.com/doc)
     95 +* [API](http://lief.quarkslab.com/doc)
     96 +* [Doxygen](http://lief.quarkslab.com/doc)
     97 + 
     98 +## Support
     99 + 
     100 +* **Mail**: lief at quarkslab com
     101 +* **Gitter**: [lief-project](https://gitter.im/lief-project)
     102 + 
     103 +## Authors
     104 + 
     105 +Romain Thomas - [Quarkslab](https://www.quarkslab.com)
     106 + 
     107 + 
     108 + 
  • ■ ■ ■ ■ ■ ■
    api/c/CMakeLists.txt
     1 +include_directories(
     2 + ${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF
     3 + ${CMAKE_CURRENT_SOURCE_DIR}/include
     4 +)
     5 + 
     6 +set(LIEF_C_ELF_SRC
     7 + ${CMAKE_CURRENT_LIST_DIR}/ELF/Symbol.cpp
     8 + ${CMAKE_CURRENT_LIST_DIR}/ELF/Section.cpp
     9 + ${CMAKE_CURRENT_LIST_DIR}/ELF/Segment.cpp
     10 + ${CMAKE_CURRENT_LIST_DIR}/ELF/DynamicEntry.cpp
     11 + ${CMAKE_CURRENT_LIST_DIR}/ELF/Header.cpp
     12 + ${CMAKE_CURRENT_LIST_DIR}/ELF/Binary.cpp
     13 + ${CMAKE_CURRENT_LIST_DIR}/ELF/EnumToString.cpp)
     14 + 
     15 + 
     16 +set(LIEF_C_PE_SRC
     17 + ${CMAKE_CURRENT_LIST_DIR}/PE/Binary.cpp
     18 + ${CMAKE_CURRENT_LIST_DIR}/PE/DosHeader.cpp
     19 + ${CMAKE_CURRENT_LIST_DIR}/PE/Header.cpp
     20 + ${CMAKE_CURRENT_LIST_DIR}/PE/OptionalHeader.cpp
     21 + ${CMAKE_CURRENT_LIST_DIR}/PE/Section.cpp
     22 + ${CMAKE_CURRENT_LIST_DIR}/PE/DataDirectory.cpp
     23 + ${CMAKE_CURRENT_LIST_DIR}/PE/EnumToString.cpp)
     24 + 
     25 + 
     26 +set(LIEF_C_MACHO_SRC
     27 + ${CMAKE_CURRENT_LIST_DIR}/MachO/Parser.cpp
     28 + ${CMAKE_CURRENT_LIST_DIR}/MachO/LoadCommand.cpp
     29 + ${CMAKE_CURRENT_LIST_DIR}/MachO/Segment.cpp
     30 + ${CMAKE_CURRENT_LIST_DIR}/MachO/Symbol.cpp
     31 + ${CMAKE_CURRENT_LIST_DIR}/MachO/Section.cpp
     32 + ${CMAKE_CURRENT_LIST_DIR}/MachO/Header.cpp
     33 + ${CMAKE_CURRENT_LIST_DIR}/MachO/Binary.cpp
     34 + ${CMAKE_CURRENT_LIST_DIR}/MachO/EnumToString.cpp)
     35 + 
     36 +set(LIEF_C_SRC)
     37 + 
     38 +if (LIEF_ELF)
     39 + set(LIEF_C_SRC ${LIEF_C_SRC} ${LIEF_C_ELF_SRC})
     40 +endif()
     41 + 
     42 +if (LIEF_PE)
     43 + set(LIEF_C_SRC ${LIEF_C_SRC} ${LIEF_C_PE_SRC})
     44 +endif()
     45 + 
     46 +if (LIEF_MACHO)
     47 + set(LIEF_C_SRC ${LIEF_C_SRC} ${LIEF_C_MACHO_SRC})
     48 +endif()
     49 + 
     50 +target_sources(LIB_LIEF_STATIC PRIVATE ${LIEF_C_SRC})
     51 +target_sources(LIB_LIEF_SHARED PRIVATE ${LIEF_C_SRC})
     52 + 
     53 + 
  • ■ ■ ■ ■ ■ ■
    api/c/ELF/Binary.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include "LIEF/ELF/Binary.h"
     17 +#include "LIEF/ELF/Section.h"
     18 +#include "LIEF/ELF/Segment.h"
     19 +#include "LIEF/ELF/Header.h"
     20 +#include "LIEF/ELF/Symbol.h"
     21 + 
     22 +#include "LIEF/ELF/Parser.hpp"
     23 +#include "LIEF/ELF/Binary.hpp"
     24 + 
     25 +#include "Section.hpp"
     26 +#include "Segment.hpp"
     27 +#include "DynamicEntry.hpp"
     28 +#include "Symbol.hpp"
     29 +#include "Header.hpp"
     30 +#include "Binary.hpp"
     31 + 
     32 +using namespace LIEF::ELF;
     33 + 
     34 +namespace LIEF {
     35 +namespace ELF {
     36 +void init_c_binary(Elf_Binary_t* c_binary, Binary* binary) {
     37 + c_binary->handler = reinterpret_cast<void*>(binary);
     38 + c_binary->name = binary->name().c_str();
     39 + c_binary->type = static_cast<enum ::ELF_CLASS>(binary->type());
     40 + c_binary->interpreter = nullptr;
     41 + if (binary->has_interpreter()) {
     42 + std::string interp = binary->get_interpreter();
     43 + c_binary->interpreter = static_cast<char*>(malloc(interp.size() * sizeof(char)));
     44 + std::memcpy(
     45 + reinterpret_cast<void*>(const_cast<char*>(c_binary->interpreter)),
     46 + reinterpret_cast<const void*>(interp.data()),
     47 + interp.size());
     48 + }
     49 + 
     50 + 
     51 + init_c_header(c_binary, binary);
     52 + init_c_sections(c_binary, binary);
     53 + init_c_segments(c_binary, binary);
     54 + init_c_dynamic_symbols(c_binary, binary);
     55 + init_c_static_symbols(c_binary, binary);
     56 + init_c_dynamic_entries(c_binary, binary);
     57 + 
     58 + 
     59 +}
     60 + 
     61 +}
     62 +}
     63 + 
     64 +Elf_Binary_t* elf_parse(const char *file) {
     65 + Binary* binary = Parser::parse(file);
     66 + Elf_Binary_t* c_binary = static_cast<Elf_Binary_t*>(malloc(sizeof(Elf_Binary_t)));
     67 + memset(c_binary, 0, sizeof(Elf_Binary_t));
     68 + init_c_binary(c_binary, binary);
     69 + return c_binary;
     70 +}
     71 + 
     72 +// Binary Methods
     73 +// ==============
     74 + 
     75 +int elf_binary_save_header(Elf_Binary_t* binary) {
     76 + Header& hdr = reinterpret_cast<Binary*>(binary->handler)->get_header();
     77 + 
     78 + hdr.file_type(static_cast<LIEF::ELF::E_TYPE>(binary->header.file_type));
     79 + hdr.machine_type(static_cast<LIEF::ELF::ARCH>(binary->header.machine_type));
     80 + hdr.object_file_version(static_cast<LIEF::ELF::VERSION>(binary->header.object_file_version));
     81 + hdr.program_headers_offset(binary->header.program_headers_offset);
     82 + hdr.section_headers_offset(binary->header.section_headers_offset);
     83 + hdr.processor_flag(binary->header.processor_flags);
     84 + hdr.header_size(binary->header.header_size);
     85 + hdr.program_header_size(binary->header.program_header_size);
     86 + hdr.numberof_segments(binary->header.numberof_segments);
     87 + hdr.sizeof_section_header(binary->header.sizeof_section_header);
     88 + hdr.numberof_sections(binary->header.numberof_sections);
     89 + hdr.section_name_table_idx(binary->header.name_string_table_idx);
     90 + hdr.entrypoint(binary->header.entrypoint);
     91 + 
     92 + //TODO: identity
     93 + return true;
     94 +}
     95 + 
     96 + 
     97 +void elf_binary_destroy(Elf_Binary_t* binary) {
     98 + destroy_sections(binary);
     99 + destroy_segments(binary);
     100 + destroy_dynamic_symbols(binary);
     101 + destroy_static_symbols(binary);
     102 + destroy_dynamic_entries(binary);
     103 + 
     104 + if (binary->interpreter != nullptr) {
     105 + free(const_cast<char*>(binary->interpreter));
     106 + }
     107 + 
     108 + delete reinterpret_cast<Binary*>(binary->handler);
     109 + free(binary);
     110 + 
     111 +}
     112 +//}
     113 + 
  • ■ ■ ■ ■ ■ ■
    api/c/ELF/Binary.hpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef LIEF_ELF_BINARY_CPP_C_API_
     17 +#define LIEF_ELF_BINARY_CPP_C_API_
     18 + 
     19 +#include "LIEF/ELF/Binary.h"
     20 +#include "LIEF/ELF/Binary.hpp"
     21 + 
     22 +namespace LIEF {
     23 +namespace ELF {
     24 + 
     25 +void init_c_binary(Elf_Binary_t* c_binary, Binary* binary);
     26 + 
     27 +}
     28 +}
     29 + 
     30 +#endif
     31 + 
  • ■ ■ ■ ■ ■ ■
    api/c/ELF/DynamicEntry.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include "DynamicEntry.hpp"
     17 + 
     18 +namespace LIEF {
     19 +namespace ELF {
     20 + 
     21 +void init_c_dynamic_entries(Elf_Binary_t* c_binary, Binary* binary) {
     22 + 
     23 + it_dynamic_entries dyn_entries = binary->get_dynamic_entries();
     24 + c_binary->dynamic_entries = static_cast<Elf_DynamicEntry_t**>(
     25 + malloc((dyn_entries.size() + 1) * sizeof(Elf_DynamicEntry_t**)));
     26 + 
     27 + for (size_t i = 0; i < dyn_entries.size(); ++i) {
     28 + DynamicEntry& entry = dyn_entries[i];
     29 + switch(entry.tag()) {
     30 + case DYNAMIC_TAGS::DT_NEEDED:
     31 + {
     32 + 
     33 + Elf_DynamicEntry_Library_t* e = static_cast<Elf_DynamicEntry_Library_t*>(
     34 + malloc(sizeof(Elf_DynamicEntry_Library_t)));
     35 + 
     36 + e->tag = static_cast<enum ::DYNAMIC_TAGS>(entry.tag());
     37 + e->value = entry.value();
     38 + e->name = dynamic_cast<DynamicEntryLibrary*>(&entry)->name().c_str();
     39 + 
     40 + c_binary->dynamic_entries[i] = reinterpret_cast<Elf_DynamicEntry_t*>(e);
     41 + break;
     42 + // cppcheck-suppress memleak
     43 + }
     44 + 
     45 + case DYNAMIC_TAGS::DT_SONAME:
     46 + {
     47 + Elf_DynamicEntry_SharedObject_t* e = static_cast<Elf_DynamicEntry_SharedObject_t*>(
     48 + malloc(sizeof(Elf_DynamicEntry_SharedObject_t)));
     49 + 
     50 + e->tag = static_cast<enum ::DYNAMIC_TAGS>(entry.tag());
     51 + e->value = entry.value();
     52 + e->name = dynamic_cast<DynamicSharedObject*>(&entry)->name().c_str();
     53 + 
     54 + c_binary->dynamic_entries[i] = reinterpret_cast<Elf_DynamicEntry_t*>(e);
     55 + break;
     56 + }
     57 + 
     58 + case DYNAMIC_TAGS::DT_RPATH:
     59 + {
     60 + Elf_DynamicEntry_Rpath_t* e = static_cast<Elf_DynamicEntry_Rpath_t*>(
     61 + malloc(sizeof(Elf_DynamicEntry_Rpath_t)));
     62 + 
     63 + e->tag = static_cast<enum ::DYNAMIC_TAGS>(entry.tag());
     64 + e->value = entry.value();
     65 + e->rpath = dynamic_cast<DynamicEntryRpath*>(&entry)->name().c_str();
     66 + 
     67 + c_binary->dynamic_entries[i] = reinterpret_cast<Elf_DynamicEntry_t*>(e);
     68 + 
     69 + break;
     70 + }
     71 + 
     72 + case DYNAMIC_TAGS::DT_RUNPATH:
     73 + {
     74 + Elf_DynamicEntry_RunPath_t* e = static_cast<Elf_DynamicEntry_RunPath_t*>(
     75 + malloc(sizeof(Elf_DynamicEntry_RunPath_t)));
     76 + 
     77 + e->tag = static_cast<enum ::DYNAMIC_TAGS>(entry.tag());
     78 + e->value = entry.value();
     79 + e->runpath = dynamic_cast<DynamicEntryRunPath*>(&entry)->name().c_str();
     80 + 
     81 + c_binary->dynamic_entries[i] = reinterpret_cast<Elf_DynamicEntry_t*>(e);
     82 + 
     83 + break;
     84 + }
     85 + 
     86 + case DYNAMIC_TAGS::DT_INIT_ARRAY:
     87 + case DYNAMIC_TAGS::DT_FINI_ARRAY:
     88 + case DYNAMIC_TAGS::DT_PREINIT_ARRAY:
     89 + {
     90 + Elf_DynamicEntry_Array_t* e = static_cast<Elf_DynamicEntry_Array_t*>(
     91 + malloc(sizeof(Elf_DynamicEntry_Array_t)));
     92 + 
     93 + e->tag = static_cast<enum ::DYNAMIC_TAGS>(entry.tag());
     94 + e->value = entry.value();
     95 + const std::vector<uint64_t>& array = dynamic_cast<DynamicEntryArray*>(&entry)->array();
     96 + e->array = static_cast<uint64_t*>(malloc((array.size() + 1) * sizeof(uint64_t)));
     97 + for (size_t i = 0; i < array.size(); ++i) {
     98 + e->array[i] = array[i];
     99 + }
     100 + e->array[array.size()] = 0;
     101 + c_binary->dynamic_entries[i] = reinterpret_cast<Elf_DynamicEntry_t*>(e);
     102 + 
     103 + break;
     104 + }
     105 + default:
     106 + {
     107 + c_binary->dynamic_entries[i] =
     108 + static_cast<Elf_DynamicEntry_t*>(malloc(sizeof(Elf_DynamicEntry_t)));
     109 + c_binary->dynamic_entries[i]->tag = static_cast<enum ::DYNAMIC_TAGS>(entry.tag());
     110 + c_binary->dynamic_entries[i]->value = entry.value();
     111 + 
     112 + }
     113 + }
     114 + }
     115 + 
     116 + c_binary->dynamic_entries[dyn_entries.size()] = nullptr;
     117 + 
     118 +}
     119 + 
     120 + 
     121 + 
     122 +void destroy_dynamic_entries(Elf_Binary_t* c_binary) {
     123 + 
     124 + Elf_DynamicEntry_t **dynamic_entries = c_binary->dynamic_entries;
     125 + for (size_t idx = 0; dynamic_entries[idx] != NULL; ++idx) {
     126 + switch(dynamic_entries[idx]->tag) {
     127 + case DYNAMIC_TAGS::DT_NEEDED:
     128 + {
     129 + free(reinterpret_cast<Elf_DynamicEntry_Library_t*>(dynamic_entries[idx]));
     130 + break;
     131 + }
     132 + 
     133 + case DYNAMIC_TAGS::DT_SONAME:
     134 + {
     135 + free(reinterpret_cast<Elf_DynamicEntry_SharedObject_t*>(dynamic_entries[idx]));
     136 + break;
     137 + }
     138 + 
     139 + case DYNAMIC_TAGS::DT_RPATH:
     140 + {
     141 + free(reinterpret_cast<Elf_DynamicEntry_Rpath_t*>(dynamic_entries[idx]));
     142 + break;
     143 + }
     144 + 
     145 + case DYNAMIC_TAGS::DT_RUNPATH:
     146 + {
     147 + free(reinterpret_cast<Elf_DynamicEntry_RunPath_t*>(dynamic_entries[idx]));
     148 + break;
     149 + }
     150 + 
     151 + case DYNAMIC_TAGS::DT_INIT_ARRAY:
     152 + case DYNAMIC_TAGS::DT_FINI_ARRAY:
     153 + case DYNAMIC_TAGS::DT_PREINIT_ARRAY:
     154 + {
     155 + free(reinterpret_cast<Elf_DynamicEntry_Array_t*>(dynamic_entries[idx]));
     156 + break;
     157 + }
     158 + default:
     159 + {
     160 + 
     161 + free(dynamic_entries[idx]);
     162 + }
     163 + 
     164 + 
     165 + }
     166 + }
     167 + free(c_binary->dynamic_entries);
     168 + 
     169 +}
     170 + 
     171 +}
     172 +}
     173 + 
     174 + 
     175 + 
  • ■ ■ ■ ■ ■ ■
    api/c/ELF/DynamicEntry.hpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef LIEF_ELF_DYNAMIC_ENTRY_CPP_C_API_
     17 +#define LIEF_ELF_DYNAMIC_ENTRY_CPP_C_API_
     18 + 
     19 +#include "LIEF/ELF/Binary.h"
     20 +#include "LIEF/ELF/Binary.hpp"
     21 + 
     22 +#include "LIEF/ELF/DynamicEntry.h"
     23 +#include "LIEF/ELF/DynamicEntry.hpp"
     24 + 
     25 +namespace LIEF {
     26 +namespace ELF {
     27 + 
     28 +void init_c_dynamic_entries(Elf_Binary_t* c_binary, Binary* binary);
     29 +void destroy_dynamic_entries(Elf_Binary_t* c_binary);
     30 + 
     31 +}
     32 +}
     33 + 
     34 +#endif
     35 + 
  • ■ ■ ■ ■ ■ ■
    api/c/ELF/EnumToString.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include "LIEF/ELF/EnumToString.h"
     17 +#include "LIEF/ELF/EnumToString.hpp"
     18 + 
     19 +#include "LIEF/ELF/Structures.hpp"
     20 +#include "LIEF/ELF/structures.h"
     21 + 
     22 + 
     23 +extern "C"
     24 +{
     25 + const char* E_TYPE_to_string(enum E_TYPE e) {
     26 + return LIEF::ELF::to_string(static_cast<LIEF::ELF::E_TYPE>(e));
     27 + }
     28 + 
     29 + const char* SYMBOL_BINDINGS_to_string(enum SYMBOL_BINDINGS e) {
     30 + return LIEF::ELF::to_string(static_cast<LIEF::ELF::SYMBOL_BINDINGS>(e));
     31 + }
     32 + 
     33 + const char* VERSION_to_string(enum VERSION e) {
     34 + return LIEF::ELF::to_string(static_cast<LIEF::ELF::VERSION>(e));
     35 + }
     36 + 
     37 + const char* ARCH_to_string(enum ARCH e) {
     38 + return LIEF::ELF::to_string(static_cast<LIEF::ELF::ARCH>(e));
     39 + }
     40 + 
     41 + const char* SEGMENT_TYPES_to_string(enum SEGMENT_TYPES e) {
     42 + return LIEF::ELF::to_string(static_cast<LIEF::ELF::SEGMENT_TYPES>(e));
     43 + }
     44 + 
     45 + const char* DYNAMIC_TAGS_to_string(enum DYNAMIC_TAGS e) {
     46 + return LIEF::ELF::to_string(static_cast<LIEF::ELF::DYNAMIC_TAGS>(e));
     47 + }
     48 + 
     49 + const char* SECTION_TYPES_to_string(enum SECTION_TYPES e) {
     50 + return LIEF::ELF::to_string(static_cast<LIEF::ELF::SECTION_TYPES>(e));
     51 + }
     52 + 
     53 + const char* SECTION_FLAGS_to_string(enum SECTION_FLAGS e) {
     54 + return LIEF::ELF::to_string(static_cast<LIEF::ELF::SECTION_FLAGS>(e));
     55 + }
     56 + 
     57 + const char* SYMBOL_TYPES_to_string(enum SYMBOL_TYPES e) {
     58 + return LIEF::ELF::to_string(static_cast<LIEF::ELF::SYMBOL_TYPES>(e));
     59 + }
     60 + 
     61 + const char* ELF_CLASS_to_string(enum ELF_CLASS e) {
     62 + return LIEF::ELF::to_string(static_cast<LIEF::ELF::ELF_CLASS>(e));
     63 + }
     64 + 
     65 + const char* ELF_DATA_to_string(enum ELF_DATA e) {
     66 + return LIEF::ELF::to_string(static_cast<LIEF::ELF::ELF_DATA>(e));
     67 + }
     68 + 
     69 + const char* OS_ABI_to_string(enum OS_ABI e) {
     70 + return LIEF::ELF::to_string(static_cast<LIEF::ELF::OS_ABI>(e));
     71 + }
     72 + 
     73 +}
     74 + 
  • ■ ■ ■ ■ ■ ■
    api/c/ELF/Header.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include "Header.hpp"
     17 + 
     18 +namespace LIEF {
     19 +namespace ELF {
     20 + 
     21 +void init_c_header(Elf_Binary_t* c_binary, Binary* binary) {
     22 + 
     23 + const Header& hdr = binary->get_header();
     24 + c_binary->header.file_type = static_cast<enum ::E_TYPE>(hdr.file_type());
     25 + c_binary->header.machine_type = static_cast<enum ::ARCH>(hdr.machine_type());
     26 + c_binary->header.object_file_version = static_cast<enum ::VERSION>(hdr.object_file_version());
     27 + c_binary->header.program_headers_offset = hdr.program_headers_offset();
     28 + c_binary->header.section_headers_offset = hdr.section_headers_offset();
     29 + c_binary->header.processor_flags = hdr.processor_flag();
     30 + c_binary->header.header_size = hdr.header_size();
     31 + c_binary->header.program_header_size = hdr.program_header_size();
     32 + c_binary->header.numberof_segments = hdr.numberof_segments();
     33 + c_binary->header.sizeof_section_header = hdr.sizeof_section_header();
     34 + c_binary->header.numberof_sections = hdr.numberof_sections();
     35 + c_binary->header.name_string_table_idx = hdr.section_name_table_idx();
     36 + c_binary->header.entrypoint = hdr.entrypoint();
     37 + const Header::identity_t& ident = hdr.identity();
     38 + std::copy(
     39 + std::begin(ident),
     40 + std::end(ident),
     41 + c_binary->header.identity);
     42 + 
     43 +}
     44 + 
     45 +}
     46 +}
     47 + 
  • ■ ■ ■ ■ ■ ■
    api/c/ELF/Header.hpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef LIEF_ELF_HEADER_CPP_C_API_
     17 +#define LIEF_ELF_HEADER_CPP_C_API_
     18 + 
     19 +#include "LIEF/ELF/Binary.h"
     20 +#include "LIEF/ELF/Binary.hpp"
     21 + 
     22 +#include "LIEF/ELF/Header.h"
     23 +#include "LIEF/ELF/Header.hpp"
     24 + 
     25 +namespace LIEF {
     26 +namespace ELF {
     27 + 
     28 +void init_c_header(Elf_Binary_t* c_binary, Binary* binary);
     29 + 
     30 +}
     31 +}
     32 + 
     33 +#endif
     34 + 
  • ■ ■ ■ ■ ■ ■
    api/c/ELF/Section.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include "Section.hpp"
     17 + 
     18 +namespace LIEF {
     19 +namespace ELF {
     20 +void init_c_sections(Elf_Binary_t* c_binary, Binary* binary) {
     21 + 
     22 + it_sections sections = binary->get_sections();
     23 + 
     24 + c_binary->sections = static_cast<Elf_Section_t**>(
     25 + malloc((sections.size() + 1) * sizeof(Elf_Section_t**)));
     26 + 
     27 + for (size_t i = 0; i < sections.size(); ++i) {
     28 + Section& b_section = sections[i];
     29 + c_binary->sections[i] = static_cast<Elf_Section_t*>(malloc(sizeof(Elf_Section_t)));
     30 + const std::vector<uint8_t>& section_content = b_section.content();
     31 + uint8_t* content = static_cast<uint8_t*>(malloc(section_content.size() * sizeof(uint8_t)));
     32 + std::copy(
     33 + std::begin(section_content),
     34 + std::end(section_content),
     35 + content);
     36 + 
     37 + c_binary->sections[i]->name = b_section.name().c_str();
     38 + c_binary->sections[i]->flags = b_section.flags();
     39 + c_binary->sections[i]->type = static_cast<enum ::SECTION_TYPES>(b_section.type());
     40 + c_binary->sections[i]->virtual_address = b_section.virtual_address();
     41 + c_binary->sections[i]->offset = b_section.file_offset();
     42 + c_binary->sections[i]->original_size = b_section.original_size();
     43 + c_binary->sections[i]->link = b_section.link();
     44 + c_binary->sections[i]->info = b_section.information();
     45 + c_binary->sections[i]->alignment = b_section.alignment();
     46 + c_binary->sections[i]->entry_size = b_section.entry_size();
     47 + c_binary->sections[i]->content = content;
     48 + c_binary->sections[i]->size = section_content.size();
     49 + c_binary->sections[i]->entropy = b_section.entropy();
     50 + }
     51 + c_binary->sections[sections.size()] = nullptr;
     52 + 
     53 +}
     54 + 
     55 + 
     56 + 
     57 +void destroy_sections(Elf_Binary_t* c_binary) {
     58 + 
     59 + Elf_Section_t **sections = c_binary->sections;
     60 + for (size_t idx = 0; sections[idx] != nullptr; ++idx) {
     61 + free(sections[idx]->content);
     62 + free(sections[idx]);
     63 + }
     64 + free(c_binary->sections);
     65 + 
     66 +}
     67 + 
     68 +}
     69 +}
     70 + 
     71 + 
     72 + 
  • ■ ■ ■ ■ ■ ■
    api/c/ELF/Section.hpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef LIEF_ELF_SECTION_CPP_C_API_
     17 +#define LIEF_ELF_SECTION_CPP_C_API_
     18 + 
     19 +#include "LIEF/ELF/Binary.h"
     20 +#include "LIEF/ELF/Binary.hpp"
     21 + 
     22 +#include "LIEF/ELF/Section.h"
     23 +#include "LIEF/ELF/Section.hpp"
     24 + 
     25 +namespace LIEF {
     26 +namespace ELF {
     27 + 
     28 +void init_c_sections(Elf_Binary_t* c_binary, Binary* binary);
     29 +void destroy_sections(Elf_Binary_t* c_binary);
     30 + 
     31 +}
     32 +}
     33 + 
     34 +#endif
     35 + 
  • ■ ■ ■ ■ ■ ■
    api/c/ELF/Segment.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include "Segment.hpp"
     17 + 
     18 +namespace LIEF {
     19 +namespace ELF {
     20 + 
     21 +void init_c_segments(Elf_Binary_t* c_binary, Binary* binary) {
     22 + 
     23 + it_segments segments = binary->get_segments();
     24 + c_binary->segments = static_cast<Elf_Segment_t**>(
     25 + malloc((segments.size() + 1) * sizeof(Elf_Segment_t**)));
     26 + for (size_t i = 0; i < segments.size(); ++i) {
     27 + Segment& segment = segments[i];
     28 + 
     29 + const std::vector<uint8_t>& segment_content = segment.content();
     30 + uint8_t* content = static_cast<uint8_t*>(malloc(segment_content.size() * sizeof(uint8_t)));
     31 + std::copy(
     32 + std::begin(segment_content),
     33 + std::end(segment_content),
     34 + content);
     35 + 
     36 + c_binary->segments[i] = static_cast<Elf_Segment_t*>(malloc(sizeof(Elf_Segment_t)));
     37 + c_binary->segments[i]->type = static_cast<enum ::SEGMENT_TYPES>(segment.type());
     38 + c_binary->segments[i]->flags = segment.flag();
     39 + c_binary->segments[i]->virtual_address = segment.virtual_address();
     40 + c_binary->segments[i]->virtual_size = segment.virtual_size();
     41 + c_binary->segments[i]->offset = segment.file_offset();
     42 + c_binary->segments[i]->alignment = segment.alignment();
     43 + c_binary->segments[i]->size = segment_content.size();
     44 + c_binary->segments[i]->content = content;
     45 + }
     46 + 
     47 + c_binary->segments[segments.size()] = nullptr;
     48 + 
     49 +}
     50 + 
     51 + 
     52 + 
     53 +void destroy_segments(Elf_Binary_t* c_binary) {
     54 + 
     55 + Elf_Segment_t **segments = c_binary->segments;
     56 + for (size_t idx = 0; segments[idx] != nullptr; ++idx) {
     57 + free(segments[idx]->content);
     58 + free(segments[idx]);
     59 + }
     60 + free(c_binary->segments);
     61 + 
     62 +}
     63 + 
     64 +}
     65 +}
     66 + 
     67 + 
     68 + 
  • ■ ■ ■ ■ ■ ■
    api/c/ELF/Segment.hpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef LIEF_ELF_SEGMENT_CPP_C_API_
     17 +#define LIEF_ELF_SEGMENT_CPP_C_API_
     18 + 
     19 +#include "LIEF/ELF/Binary.h"
     20 +#include "LIEF/ELF/Binary.hpp"
     21 + 
     22 +#include "LIEF/ELF/Segment.h"
     23 +#include "LIEF/ELF/Segment.hpp"
     24 + 
     25 +namespace LIEF {
     26 +namespace ELF {
     27 + 
     28 +void init_c_segments(Elf_Binary_t* c_binary, Binary* binary);
     29 +void destroy_segments(Elf_Binary_t* c_binary);
     30 + 
     31 +}
     32 +}
     33 + 
     34 +#endif
     35 + 
  • ■ ■ ■ ■ ■ ■
    api/c/ELF/Symbol.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include "Symbol.hpp"
     17 + 
     18 +namespace LIEF {
     19 +namespace ELF {
     20 + 
     21 +void init_c_dynamic_symbols(Elf_Binary_t* c_binary, Binary* binary) {
     22 + it_symbols dyn_symb = binary->get_dynamic_symbols();
     23 + 
     24 + c_binary->dynamic_symbols = static_cast<Elf_Symbol_t**>(
     25 + malloc((dyn_symb.size() + 1) * sizeof(Elf_Symbol_t**)));
     26 + 
     27 + for (size_t i = 0; i < dyn_symb.size(); ++i) {
     28 + Symbol& b_sym = dyn_symb[i];
     29 + c_binary->dynamic_symbols[i] = static_cast<Elf_Symbol_t*>(malloc(sizeof(Elf_Symbol_t)));
     30 + c_binary->dynamic_symbols[i]->name = b_sym.name().c_str();
     31 + c_binary->dynamic_symbols[i]->type = static_cast<enum ::SYMBOL_TYPES>(b_sym.type());
     32 + c_binary->dynamic_symbols[i]->binding = static_cast<enum ::SYMBOL_BINDINGS>(b_sym.binding());
     33 + c_binary->dynamic_symbols[i]->other = b_sym.other();
     34 + c_binary->dynamic_symbols[i]->shndx = b_sym.shndx();
     35 + c_binary->dynamic_symbols[i]->value = b_sym.value();
     36 + c_binary->dynamic_symbols[i]->size = b_sym.size();
     37 + c_binary->dynamic_symbols[i]->information = b_sym.information();
     38 + }
     39 + c_binary->dynamic_symbols[dyn_symb.size()] = nullptr;
     40 + 
     41 + 
     42 + 
     43 +}
     44 + 
     45 + 
     46 +void init_c_static_symbols(Elf_Binary_t* c_binary, Binary* binary) {
     47 + it_symbols static_symb = binary->get_static_symbols();
     48 + 
     49 + c_binary->static_symbols = static_cast<Elf_Symbol_t**>(
     50 + malloc((static_symb.size() + 1) * sizeof(Elf_Symbol_t**)));
     51 + 
     52 + for (size_t i = 0; i < static_symb.size(); ++i) {
     53 + Symbol& b_sym = static_symb[i];
     54 + c_binary->static_symbols[i] = static_cast<Elf_Symbol_t*>(malloc(sizeof(Elf_Symbol_t)));
     55 + c_binary->static_symbols[i]->name = b_sym.name().c_str();
     56 + c_binary->static_symbols[i]->type = static_cast<enum ::SYMBOL_TYPES>(b_sym.type());
     57 + c_binary->static_symbols[i]->binding = static_cast<enum ::SYMBOL_BINDINGS>(b_sym.binding());
     58 + c_binary->static_symbols[i]->other = b_sym.other();
     59 + c_binary->static_symbols[i]->shndx = b_sym.shndx();
     60 + c_binary->static_symbols[i]->value = b_sym.value();
     61 + c_binary->static_symbols[i]->size = b_sym.size();
     62 + c_binary->static_symbols[i]->information = b_sym.information();
     63 + }
     64 + c_binary->static_symbols[static_symb.size()] = nullptr;
     65 + 
     66 +}
     67 + 
     68 + 
     69 + 
     70 +void destroy_dynamic_symbols(Elf_Binary_t* c_binary) {
     71 + Elf_Symbol_t **dynamic_symbols = c_binary->dynamic_symbols;
     72 + for (size_t idx = 0; dynamic_symbols[idx] != nullptr; ++idx) {
     73 + free(dynamic_symbols[idx]);
     74 + }
     75 + free(c_binary->dynamic_symbols);
     76 +}
     77 + 
     78 + 
     79 +void destroy_static_symbols(Elf_Binary_t* c_binary) {
     80 + Elf_Symbol_t **static_symbols = c_binary->static_symbols;
     81 + for (size_t idx = 0; static_symbols[idx] != nullptr; ++idx) {
     82 + free(static_symbols[idx]);
     83 + }
     84 + free(c_binary->static_symbols);
     85 +}
     86 + 
     87 +}
     88 +}
     89 + 
     90 + 
     91 + 
  • ■ ■ ■ ■ ■ ■
    api/c/ELF/Symbol.hpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef LIEF_ELF_SYMBOL_CPP_C_API_
     17 +#define LIEF_ELF_SYMBOL_CPP_C_API_
     18 + 
     19 +#include "LIEF/ELF/Binary.h"
     20 +#include "LIEF/ELF/Binary.hpp"
     21 + 
     22 +#include "LIEF/ELF/Symbol.h"
     23 +#include "LIEF/ELF/Symbol.hpp"
     24 + 
     25 +namespace LIEF {
     26 +namespace ELF {
     27 + 
     28 +void init_c_dynamic_symbols(Elf_Binary_t* c_binary, Binary* binary);
     29 +void init_c_static_symbols(Elf_Binary_t* c_binary, Binary* binary);
     30 + 
     31 +void destroy_dynamic_symbols(Elf_Binary_t* c_binary);
     32 +void destroy_static_symbols(Elf_Binary_t* c_binary);
     33 + 
     34 +}
     35 +}
     36 + 
     37 +#endif
     38 + 
  • ■ ■ ■ ■ ■ ■
    api/c/MachO/Binary.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include "LIEF/MachO/Binary.h"
     17 + 
     18 +#include "LIEF/MachO/Binary.hpp"
     19 + 
     20 +#include "Binary.hpp"
     21 +#include "Section.hpp"
     22 +#include "Header.hpp"
     23 +#include "Symbol.hpp"
     24 +#include "Segment.hpp"
     25 +#include "LoadCommand.hpp"
     26 + 
     27 + 
     28 +using namespace LIEF::MachO;
     29 + 
     30 +namespace LIEF {
     31 +namespace MachO {
     32 +void init_c_binary(Macho_Binary_t* c_binary, Binary* binary) {
     33 + 
     34 + c_binary->handler = reinterpret_cast<void*>(binary);
     35 + c_binary->name = binary->name().c_str();
     36 + c_binary->imagebase = binary->imagebase();
     37 + init_c_header(c_binary, binary);
     38 + init_c_commands(c_binary, binary);
     39 + init_c_symbols(c_binary, binary);
     40 + init_c_sections(c_binary, binary);
     41 + init_c_segments(c_binary, binary);
     42 +}
     43 +}
     44 +}
     45 + 
     46 +void macho_binaries_destroy(Macho_Binary_t** binaries) {
     47 + for (size_t i = 0; binaries[i] != nullptr; ++i) {
     48 + destroy_sections(binaries[i]);
     49 + destroy_commands(binaries[i]);
     50 + destroy_symbols(binaries[i]);
     51 + destroy_segments(binaries[i]);
     52 + 
     53 + delete reinterpret_cast<Binary*>(binaries[i]->handler);
     54 + free(binaries[i]);
     55 + }
     56 + free(binaries);
     57 + 
     58 +}
     59 + 
  • ■ ■ ■ ■ ■ ■
    api/c/MachO/Binary.hpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef LIEF_MACHO_BINARY_CPP_C_API_
     17 +#define LIEF_MACHO_BINARY_CPP_C_API_
     18 + 
     19 +#include "LIEF/MachO/Binary.h"
     20 +#include "LIEF/MachO/Binary.hpp"
     21 + 
     22 +namespace LIEF {
     23 +namespace MachO {
     24 + 
     25 +void init_c_binary(Macho_Binary_t* c_binary, Binary* binary);
     26 + 
     27 +}
     28 +}
     29 + 
     30 +#endif
     31 + 
  • ■ ■ ■ ■ ■ ■
    api/c/MachO/EnumToString.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include "LIEF/MachO/EnumToString.h"
     17 +#include "LIEF/MachO/EnumToString.hpp"
     18 + 
     19 +#include "LIEF/MachO/enums.hpp"
     20 +#include "LIEF/MachO/enums.h"
     21 + 
     22 + 
     23 +extern "C"
     24 +{
     25 + 
     26 +const char* LOAD_COMMAND_TYPES_to_string(enum LOAD_COMMAND_TYPES e) {
     27 + return LIEF::MachO::to_string(static_cast<LIEF::MachO::LOAD_COMMAND_TYPES>(e));
     28 +}
     29 + 
     30 + 
     31 +const char* MACHO_TYPES_to_string(enum MACHO_TYPES e) {
     32 + return LIEF::MachO::to_string(static_cast<LIEF::MachO::MACHO_TYPES>(e));
     33 +}
     34 + 
     35 + 
     36 +const char* FILE_TYPES_to_string(enum FILE_TYPES e) {
     37 + return LIEF::MachO::to_string(static_cast<LIEF::MachO::FILE_TYPES>(e));
     38 +}
     39 + 
     40 + 
     41 +const char* CPU_TYPES_to_string(enum CPU_TYPES e) {
     42 + return LIEF::MachO::to_string(static_cast<LIEF::MachO::CPU_TYPES>(e));
     43 +}
     44 + 
     45 + 
     46 +const char* HEADER_FLAGS_to_string(enum HEADER_FLAGS e) {
     47 + return LIEF::MachO::to_string(static_cast<LIEF::MachO::HEADER_FLAGS>(e));
     48 +}
     49 + 
     50 + 
     51 +const char* MachO_SECTION_TYPES_to_string(enum SECTION_TYPES e) {
     52 + return LIEF::MachO::to_string(static_cast<LIEF::MachO::SECTION_TYPES>(e));
     53 +}
     54 + 
     55 + 
     56 +const char* MachO_SYMBOL_TYPES_to_string(enum SYMBOL_TYPES e) {
     57 + return LIEF::MachO::to_string(static_cast<LIEF::MachO::SYMBOL_TYPES>(e));
     58 +}
     59 + 
     60 + 
     61 +const char* N_LIST_TYPES_to_string(enum N_LIST_TYPES e) {
     62 + return LIEF::MachO::to_string(static_cast<LIEF::MachO::N_LIST_TYPES>(e));
     63 +}
     64 + 
     65 + 
     66 +const char* SYMBOL_DESCRIPTIONS_to_string(enum SYMBOL_DESCRIPTIONS e) {
     67 + return LIEF::MachO::to_string(static_cast<LIEF::MachO::SYMBOL_DESCRIPTIONS>(e));
     68 +}
     69 + 
     70 + 
     71 + 
     72 + 
     73 + 
     74 + 
     75 + 
     76 +}
     77 + 
  • ■ ■ ■ ■ ■ ■
    api/c/MachO/Header.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include "Header.hpp"
     17 + 
     18 +namespace LIEF {
     19 +namespace MachO {
     20 +void init_c_header(Macho_Binary_t* c_binary, Binary* binary) {
     21 + Header& header = binary->header();
     22 + c_binary->header.magic = header.magic();
     23 + c_binary->header.cpu_type = static_cast<enum ::CPU_TYPES>(header.cpu_type());
     24 + c_binary->header.cpu_subtype = header.cpu_subtype();
     25 + c_binary->header.file_type = static_cast<enum ::FILE_TYPES>(header.file_type());
     26 + c_binary->header.nb_cmds = header.nb_cmds();
     27 + c_binary->header.sizeof_cmds = header.sizeof_cmds();
     28 + c_binary->header.flags = header.flags();
     29 + c_binary->header.reserved = header.reserved();
     30 +}
     31 + 
     32 +}
     33 +}
     34 + 
  • ■ ■ ■ ■ ■ ■
    api/c/MachO/Header.hpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef LIEF_MACHO_HEADER_CPP_C_API_
     17 +#define LIEF_MACHO_HEADER_CPP_C_API_
     18 + 
     19 +#include "LIEF/MachO/Binary.h"
     20 +#include "LIEF/MachO/Binary.hpp"
     21 + 
     22 +#include "LIEF/MachO/Header.h"
     23 +#include "LIEF/MachO/Header.hpp"
     24 + 
     25 +namespace LIEF {
     26 +namespace MachO {
     27 + 
     28 +void init_c_header(Macho_Binary_t* c_binary, Binary* binary);
     29 + 
     30 +}
     31 +}
     32 + 
     33 +#endif
     34 + 
  • ■ ■ ■ ■ ■ ■
    api/c/MachO/LoadCommand.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include "LoadCommand.hpp"
     17 + 
     18 +namespace LIEF {
     19 +namespace MachO {
     20 +void init_c_commands(Macho_Binary_t* c_binary, Binary* binary) {
     21 + it_commands commands = binary->commands();
     22 + 
     23 + c_binary->commands = static_cast<Macho_Command_t**>(
     24 + malloc((commands.size() + 1) * sizeof(Macho_Command_t**)));
     25 + 
     26 + for (size_t i = 0; i < commands.size(); ++i) {
     27 + LoadCommand& cmd = commands[i];
     28 + 
     29 + c_binary->commands[i] = static_cast<Macho_Command_t*>(malloc(sizeof(Macho_Command_t)));
     30 + const std::vector<uint8_t>& cmd_content = cmd.data();
     31 + uint8_t* content = static_cast<uint8_t*>(malloc(cmd_content.size() * sizeof(uint8_t)));
     32 + std::copy(
     33 + std::begin(cmd_content),
     34 + std::end(cmd_content),
     35 + content);
     36 + 
     37 + c_binary->commands[i]->command = static_cast<enum ::LOAD_COMMAND_TYPES>(cmd.command());
     38 + c_binary->commands[i]->size = cmd.size();
     39 + c_binary->commands[i]->data = content;
     40 + c_binary->commands[i]->offset = cmd.command_offset();
     41 + }
     42 + 
     43 + c_binary->commands[commands.size()] = nullptr;
     44 + 
     45 +}
     46 + 
     47 + 
     48 + 
     49 +void destroy_commands(Macho_Binary_t* c_binary) {
     50 + Macho_Command_t **commands = c_binary->commands;
     51 + for (size_t idx = 0; commands[idx] != nullptr; ++idx) {
     52 + free(commands[idx]->data);
     53 + free(commands[idx]);
     54 + }
     55 + free(c_binary->commands);
     56 + 
     57 +}
     58 + 
     59 +}
     60 +}
     61 + 
     62 + 
     63 + 
  • ■ ■ ■ ■ ■ ■
    api/c/MachO/LoadCommand.hpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef LIEF_MACHO_LOAD_COMMAND_CPP_C_API_
     17 +#define LIEF_MACHO_LOAD_COMMAND_CPP_C_API_
     18 + 
     19 +#include "LIEF/MachO/Binary.h"
     20 +#include "LIEF/MachO/Binary.hpp"
     21 + 
     22 +#include "LIEF/MachO/LoadCommand.h"
     23 +#include "LIEF/MachO/LoadCommand.hpp"
     24 + 
     25 +namespace LIEF {
     26 +namespace MachO {
     27 + 
     28 +void init_c_commands(Macho_Binary_t* c_binary, Binary* binary);
     29 +void destroy_commands(Macho_Binary_t* c_binary);
     30 + 
     31 +}
     32 +}
     33 + 
     34 +#endif
     35 + 
  • ■ ■ ■ ■ ■ ■
    api/c/MachO/Parser.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include <cstring>
     17 + 
     18 +#include "LIEF/MachO/Binary.h"
     19 +#include "LIEF/MachO/Parser.hpp"
     20 + 
     21 +#include "Binary.hpp"
     22 + 
     23 +using namespace LIEF::MachO;
     24 + 
     25 +Macho_Binary_t** macho_parse(const char *file) {
     26 + std::vector<Binary*> macho_binaries{Parser::parse(file)};
     27 + 
     28 + Macho_Binary_t** c_macho_binaries = static_cast<Macho_Binary_t**>(
     29 + malloc((macho_binaries.size() + 1) * sizeof(Macho_Binary_t**)));
     30 + 
     31 + for (size_t i = 0; i < macho_binaries.size(); ++i) {
     32 + Binary* binary = macho_binaries [i];
     33 + c_macho_binaries[i] = static_cast<Macho_Binary_t*>(malloc(sizeof(Macho_Binary_t)));
     34 + init_c_binary(c_macho_binaries[i], binary);
     35 + }
     36 + 
     37 + c_macho_binaries[macho_binaries.size()] = nullptr;
     38 + 
     39 + return c_macho_binaries;
     40 +}
     41 + 
     42 + 
  • ■ ■ ■ ■ ■ ■
    api/c/MachO/Section.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include "Section.hpp"
     17 + 
     18 +namespace LIEF {
     19 +namespace MachO {
     20 +void init_c_sections(Macho_Binary_t* c_binary, Binary* binary) {
     21 + it_sections sections = binary->sections();
     22 + 
     23 + c_binary->sections = static_cast<Macho_Section_t**>(
     24 + malloc((sections.size() + 1) * sizeof(Macho_Section_t**)));
     25 + 
     26 + for (size_t i = 0; i < sections.size(); ++i) {
     27 + Section& section = sections[i];
     28 + 
     29 + c_binary->sections[i] = static_cast<Macho_Section_t*>(malloc(sizeof(Macho_Section_t)));
     30 + const std::vector<uint8_t>& section_content = section.content();
     31 + uint8_t* content = static_cast<uint8_t*>(malloc(section_content.size() * sizeof(uint8_t)));
     32 + std::copy(
     33 + std::begin(section_content),
     34 + std::end(section_content),
     35 + content);
     36 + 
     37 + c_binary->sections[i]->name = section.name().c_str();
     38 + c_binary->sections[i]->alignment = section.alignment();
     39 + c_binary->sections[i]->relocation_offset = section.relocation_offset();
     40 + c_binary->sections[i]->numberof_relocations = section.numberof_relocations();
     41 + c_binary->sections[i]->flags = section.flags();
     42 + c_binary->sections[i]->type = static_cast<enum ::SECTION_TYPES>(section.type());
     43 + c_binary->sections[i]->reserved1 = section.reserved1();
     44 + c_binary->sections[i]->reserved2 = section.reserved2();
     45 + c_binary->sections[i]->reserved3 = section.reserved3();
     46 + c_binary->sections[i]->virtual_address = section.virtual_address();
     47 + c_binary->sections[i]->offset = section.offset();
     48 + c_binary->sections[i]->size = section.size();
     49 + c_binary->sections[i]->content = content;
     50 + c_binary->sections[i]->entropy = section.entropy();
     51 + }
     52 + 
     53 + c_binary->sections[sections.size()] = nullptr;
     54 + 
     55 +}
     56 + 
     57 + 
     58 + 
     59 +void destroy_sections(Macho_Binary_t* c_binary) {
     60 + Macho_Section_t **sections = c_binary->sections;
     61 + for (size_t idx = 0; sections[idx] != nullptr; ++idx) {
     62 + free(sections[idx]->content);
     63 + free(sections[idx]);
     64 + }
     65 + free(c_binary->sections);
     66 + 
     67 +}
     68 + 
     69 +}
     70 +}
     71 + 
     72 + 
     73 + 
  • ■ ■ ■ ■ ■ ■
    api/c/MachO/Section.hpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef LIEF_MACHO_SECTION_CPP_C_API_
     17 +#define LIEF_MACHO_SECTION_CPP_C_API_
     18 + 
     19 +#include "LIEF/MachO/Binary.h"
     20 +#include "LIEF/MachO/Binary.hpp"
     21 + 
     22 +#include "LIEF/MachO/Section.h"
     23 +#include "LIEF/MachO/Section.hpp"
     24 + 
     25 +namespace LIEF {
     26 +namespace MachO {
     27 + 
     28 +void init_c_sections(Macho_Binary_t* c_binary, Binary* binary);
     29 +void destroy_sections(Macho_Binary_t* c_binary);
     30 + 
     31 +}
     32 +}
     33 + 
     34 +#endif
     35 + 
  • ■ ■ ■ ■ ■ ■
    api/c/MachO/Segment.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include "Segment.hpp"
     17 + 
     18 +namespace LIEF {
     19 +namespace MachO {
     20 +void init_c_segments(Macho_Binary_t* c_binary, Binary* binary) {
     21 + it_segments segments = binary->segments();
     22 + 
     23 + c_binary->segments = static_cast<Macho_Segment_t**>(
     24 + malloc((segments.size() + 1) * sizeof(Macho_Segment_t**)));
     25 + 
     26 + for (size_t i = 0; i < segments.size(); ++i) {
     27 + SegmentCommand& segment = segments[i];
     28 + 
     29 + c_binary->segments[i] = static_cast<Macho_Segment_t*>(malloc(sizeof(Macho_Segment_t)));
     30 + const std::vector<uint8_t>& segment_content = segment.content();
     31 + uint8_t* content = static_cast<uint8_t*>(malloc(segment_content.size() * sizeof(uint8_t)));
     32 + std::copy(
     33 + std::begin(segment_content),
     34 + std::end(segment_content),
     35 + content);
     36 + 
     37 + c_binary->segments[i]->name = segment.name().c_str();
     38 + c_binary->segments[i]->virtual_address = segment.virtual_address();
     39 + c_binary->segments[i]->virtual_size = segment.virtual_size();
     40 + c_binary->segments[i]->file_size = segment.file_size();
     41 + c_binary->segments[i]->file_offset = segment.file_offset();
     42 + c_binary->segments[i]->max_protection = segment.max_protection();
     43 + c_binary->segments[i]->init_protection = segment.init_protection();
     44 + c_binary->segments[i]->numberof_sections = segment.numberof_sections();
     45 + c_binary->segments[i]->flags = segment.flags();
     46 + c_binary->segments[i]->content = content;
     47 + c_binary->segments[i]->sections = nullptr; //TODO
     48 + }
     49 + 
     50 + c_binary->segments[segments.size()] = nullptr;
     51 + 
     52 +}
     53 + 
     54 + 
     55 + 
     56 +void destroy_segments(Macho_Binary_t* c_binary) {
     57 + Macho_Segment_t **segments = c_binary->segments;
     58 + for (size_t idx = 0; segments[idx] != nullptr; ++idx) {
     59 + free(segments[idx]->content);
     60 + free(segments[idx]);
     61 + }
     62 + free(c_binary->segments);
     63 + 
     64 +}
     65 + 
     66 +}
     67 +}
     68 + 
     69 + 
     70 + 
  • ■ ■ ■ ■ ■ ■
    api/c/MachO/Segment.hpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef LIEF_MACHO_SEGMENT_CPP_C_API_
     17 +#define LIEF_MACHO_SEGMENT_CPP_C_API_
     18 + 
     19 +#include "LIEF/MachO/Binary.h"
     20 +#include "LIEF/MachO/Binary.hpp"
     21 + 
     22 +#include "LIEF/MachO/Segment.h"
     23 +#include "LIEF/MachO/SegmentCommand.hpp"
     24 + 
     25 +namespace LIEF {
     26 +namespace MachO {
     27 + 
     28 +void init_c_segments(Macho_Binary_t* c_binary, Binary* binary);
     29 +void destroy_segments(Macho_Binary_t* c_binary);
     30 + 
     31 +}
     32 +}
     33 + 
     34 +#endif
     35 + 
  • ■ ■ ■ ■ ■ ■
    api/c/MachO/Symbol.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include "Symbol.hpp"
     17 + 
     18 +namespace LIEF {
     19 +namespace MachO {
     20 +void init_c_symbols(Macho_Binary_t* c_binary, Binary* binary) {
     21 + it_symbols symbols = binary->symbols();
     22 + 
     23 + c_binary->symbols = static_cast<Macho_Symbol_t**>(
     24 + malloc((symbols.size() + 1) * sizeof(Macho_Symbol_t**)));
     25 + 
     26 + for (size_t i = 0; i < symbols.size(); ++i) {
     27 + Symbol& symbol = symbols[i];
     28 + 
     29 + c_binary->symbols[i] = static_cast<Macho_Symbol_t*>(malloc(sizeof(Macho_Symbol_t)));
     30 + 
     31 + c_binary->symbols[i]->name = symbol.name().c_str();
     32 + c_binary->symbols[i]->type = symbol.type();
     33 + c_binary->symbols[i]->numberof_sections = symbol.numberof_sections();
     34 + c_binary->symbols[i]->description = symbol.description();
     35 + c_binary->symbols[i]->value = symbol.value();
     36 + }
     37 + 
     38 + c_binary->symbols[symbols.size()] = nullptr;
     39 + 
     40 +}
     41 + 
     42 + 
     43 + 
     44 +void destroy_symbols(Macho_Binary_t* c_binary) {
     45 + Macho_Symbol_t **symbols = c_binary->symbols;
     46 + for (size_t idx = 0; symbols[idx] != nullptr; ++idx) {
     47 + free(symbols[idx]);
     48 + }
     49 + free(c_binary->symbols);
     50 + 
     51 +}
     52 + 
     53 +}
     54 +}
     55 + 
     56 + 
     57 + 
  • ■ ■ ■ ■ ■ ■
    api/c/MachO/Symbol.hpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef LIEF_MACHO_SYMBOL_CPP_C_API_
     17 +#define LIEF_MACHO_SYMBOL_CPP_C_API_
     18 + 
     19 +#include "LIEF/MachO/Binary.h"
     20 +#include "LIEF/MachO/Binary.hpp"
     21 + 
     22 +#include "LIEF/MachO/Symbol.h"
     23 +#include "LIEF/MachO/Symbol.hpp"
     24 + 
     25 +namespace LIEF {
     26 +namespace MachO {
     27 + 
     28 +void init_c_symbols(Macho_Binary_t* c_binary, Binary* binary);
     29 +void destroy_symbols(Macho_Binary_t* c_binary);
     30 + 
     31 +}
     32 +}
     33 + 
     34 +#endif
     35 + 
  • ■ ■ ■ ■ ■ ■
    api/c/PE/Binary.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include <cstring>
     17 + 
     18 +#include "LIEF/PE/Binary.h"
     19 + 
     20 +#include "LIEF/PE/Parser.hpp"
     21 +#include "LIEF/PE/Binary.hpp"
     22 + 
     23 +#include "Binary.hpp"
     24 +#include "DosHeader.hpp"
     25 +#include "Header.hpp"
     26 +#include "OptionalHeader.hpp"
     27 +#include "Section.hpp"
     28 +#include "DataDirectory.hpp"
     29 + 
     30 +using namespace LIEF::PE;
     31 + 
     32 +namespace LIEF {
     33 +namespace PE {
     34 + 
     35 +void init_c_binary(Pe_Binary_t* c_binary, Binary* binary) {
     36 + c_binary->name = binary->name().c_str();
     37 + c_binary->handler = reinterpret_cast<void*>(binary);
     38 + 
     39 + init_c_dos_header(c_binary, binary);
     40 + init_c_header(c_binary, binary);
     41 + init_c_optional_header(c_binary, binary);
     42 + init_c_sections(c_binary, binary);
     43 + init_c_data_directories(c_binary, binary);
     44 + 
     45 +}
     46 + 
     47 +}
     48 +}
     49 + 
     50 +Pe_Binary_t* pe_parse(const char *file) {
     51 + Binary* binary = Parser::parse(file);
     52 + Pe_Binary_t* c_binary = static_cast<Pe_Binary_t*>(malloc(sizeof(Pe_Binary_t)));
     53 + std::memset(c_binary, 0, sizeof(Pe_Binary_t));
     54 + init_c_binary(c_binary, binary);
     55 + 
     56 + return c_binary;
     57 +}
     58 + 
     59 +void pe_binary_destroy(Pe_Binary_t* binary) {
     60 + destroy_sections(binary);
     61 + destroy_data_directories(binary);
     62 + delete reinterpret_cast<Binary*>(binary->handler);
     63 + free(binary);
     64 +}
     65 + 
  • ■ ■ ■ ■ ■ ■
    api/c/PE/Binary.hpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef LIEF_PE_BINARY_CPP_C_API_
     17 +#define LIEF_PE_BINARY_CPP_C_API_
     18 + 
     19 +#include "LIEF/PE/Binary.h"
     20 +#include "LIEF/PE/Binary.hpp"
     21 + 
     22 +namespace LIEF {
     23 +namespace PE {
     24 + 
     25 +void init_c_binary(Pe_Binary_t* c_binary, Binary* binary);
     26 + 
     27 +}
     28 +}
     29 + 
     30 +#endif
     31 + 
  • ■ ■ ■ ■ ■ ■
    api/c/PE/DataDirectory.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include "DataDirectory.hpp"
     17 + 
     18 +namespace LIEF {
     19 +namespace PE {
     20 +void init_c_data_directories(Pe_Binary_t* c_binary, Binary* binary) {
     21 + 
     22 + it_data_directories data_directories = binary->data_directories();
     23 + 
     24 + c_binary->data_directories = static_cast<Pe_DataDirectory_t**>(
     25 + malloc((data_directories.size() + 1) * sizeof(Pe_DataDirectory_t**)));
     26 + 
     27 + for (size_t i = 0; i < data_directories.size(); ++i) {
     28 + 
     29 + c_binary->data_directories[i] = static_cast<Pe_DataDirectory_t*>(malloc(sizeof(Pe_DataDirectory_t)));
     30 + c_binary->data_directories[i]->rva = data_directories[i].RVA();
     31 + c_binary->data_directories[i]->size = data_directories[i].size();
     32 + }
     33 + c_binary->data_directories[data_directories.size()] = nullptr;
     34 + 
     35 + 
     36 + 
     37 +}
     38 + 
     39 + 
     40 + 
     41 +void destroy_data_directories(Pe_Binary_t* c_binary) {
     42 + 
     43 + Pe_DataDirectory_t **data_directories = c_binary->data_directories;
     44 + for (size_t idx = 0; data_directories[idx] != nullptr; ++idx) {
     45 + free(data_directories[idx]);
     46 + }
     47 + free(c_binary->data_directories);
     48 + 
     49 +}
     50 + 
     51 +}
     52 +}
     53 + 
     54 + 
     55 + 
  • ■ ■ ■ ■ ■ ■
    api/c/PE/DataDirectory.hpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef LIEF_PE_DATA_DIRECTORY_CPP_C_API_
     17 +#define LIEF_PE_DATA_DIRECTORY_CPP_C_API_
     18 + 
     19 +#include "LIEF/PE/Binary.h"
     20 +#include "LIEF/PE/Binary.hpp"
     21 + 
     22 +#include "LIEF/PE/DataDirectory.h"
     23 +#include "LIEF/PE/DataDirectory.hpp"
     24 + 
     25 +namespace LIEF {
     26 +namespace PE {
     27 + 
     28 +void init_c_data_directories(Pe_Binary_t* c_binary, Binary* binary);
     29 +void destroy_data_directories(Pe_Binary_t* c_binary);
     30 + 
     31 +}
     32 +}
     33 + 
     34 +#endif
     35 + 
  • ■ ■ ■ ■ ■ ■
    api/c/PE/DosHeader.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include "DosHeader.hpp"
     17 + 
     18 +namespace LIEF {
     19 +namespace PE {
     20 +void init_c_dos_header(Pe_Binary_t* c_binary, Binary* binary) {
     21 + const DosHeader& dos_header = binary->dos_header();
     22 + c_binary->dos_header.magic = dos_header.magic();
     23 + c_binary->dos_header.used_bytes_in_the_last_page = dos_header.used_bytes_in_the_last_page();
     24 + c_binary->dos_header.file_size_in_pages = dos_header.file_size_in_pages();
     25 + c_binary->dos_header.numberof_relocation = dos_header.numberof_relocation();
     26 + c_binary->dos_header.header_size_in_paragraphs = dos_header.header_size_in_paragraphs();
     27 + c_binary->dos_header.minimum_extra_paragraphs = dos_header.minimum_extra_paragraphs();
     28 + c_binary->dos_header.maximum_extra_paragraphs = dos_header.maximum_extra_paragraphs();
     29 + c_binary->dos_header.initial_relative_ss = dos_header.initial_relative_ss();
     30 + c_binary->dos_header.initial_sp = dos_header.initial_sp();
     31 + c_binary->dos_header.checksum = dos_header.checksum();
     32 + c_binary->dos_header.initial_ip = dos_header.initial_ip();
     33 + c_binary->dos_header.initial_relative_cs = dos_header.initial_relative_cs();
     34 + c_binary->dos_header.addressof_relocation_table = dos_header.addressof_relocation_table();
     35 + c_binary->dos_header.overlay_number = dos_header.overlay_number();
     36 + c_binary->dos_header.oem_id = dos_header.oem_id();
     37 + c_binary->dos_header.oem_info = dos_header.oem_info();
     38 + c_binary->dos_header.addressof_new_exeheader = dos_header.addressof_new_exeheader();
     39 + 
     40 + const DosHeader::reserved_t& reserved = dos_header.reserved();
     41 + std::copy(
     42 + std::begin(reserved),
     43 + std::end(reserved),
     44 + c_binary->dos_header.reserved);
     45 + 
     46 + 
     47 + const DosHeader::reserved2_t& reserved2 = dos_header.reserved2();
     48 + std::copy(
     49 + std::begin(reserved2),
     50 + std::end(reserved2),
     51 + c_binary->dos_header.reserved2);
     52 +}
     53 + 
     54 +}
     55 +}
     56 + 
  • ■ ■ ■ ■ ■ ■
    api/c/PE/DosHeader.hpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef LIEF_PE_DOS_HEADER_CPP_C_API_
     17 +#define LIEF_PE_DOS_HEADER_CPP_C_API_
     18 + 
     19 +#include "LIEF/PE/Binary.h"
     20 +#include "LIEF/PE/Binary.hpp"
     21 + 
     22 +#include "LIEF/PE/DosHeader.h"
     23 +#include "LIEF/PE/DosHeader.hpp"
     24 + 
     25 +namespace LIEF {
     26 +namespace PE {
     27 + 
     28 +void init_c_dos_header(Pe_Binary_t* c_binary, Binary* binary);
     29 + 
     30 +}
     31 +}
     32 + 
     33 +#endif
     34 + 
  • ■ ■ ■ ■ ■ ■
    api/c/PE/EnumToString.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include "LIEF/PE/EnumToString.h"
     17 +#include "LIEF/PE/EnumToString.hpp"
     18 + 
     19 +#include "LIEF/PE/enums.hpp"
     20 +#include "LIEF/PE/enums.h"
     21 + 
     22 + 
     23 +extern "C"
     24 +{
     25 + 
     26 +const char* PE_TYPES_to_string(enum PE_TYPES e) {
     27 + return LIEF::PE::to_string(static_cast<LIEF::PE::PE_TYPE>(e));
     28 +}
     29 + 
     30 + 
     31 +const char* MACHINE_TYPES_to_string(enum MACHINE_TYPES e) {
     32 + return LIEF::PE::to_string(static_cast<LIEF::PE::MACHINE_TYPES>(e));
     33 +}
     34 + 
     35 + 
     36 +const char* SUBSYSTEM_to_string(enum SUBSYSTEM e) {
     37 + return LIEF::PE::to_string(static_cast<LIEF::PE::SUBSYSTEM>(e));
     38 +}
     39 + 
     40 +}
     41 + 
  • ■ ■ ■ ■ ■ ■
    api/c/PE/Header.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include "Header.hpp"
     17 + 
     18 +namespace LIEF {
     19 +namespace PE {
     20 + 
     21 +void init_c_header(Pe_Binary_t* c_binary, Binary* binary) {
     22 + 
     23 + const Header& header = binary->header();
     24 + 
     25 + const Header::signature_t& signature = header.signature();
     26 + 
     27 + c_binary->header.machine = static_cast<enum ::MACHINE_TYPES>(header.machine());
     28 + c_binary->header.numberof_sections = header.numberof_sections();
     29 + c_binary->header.time_date_stamp = header.time_date_stamp();
     30 + c_binary->header.pointerto_symbol_table = header.pointerto_symbol_table();
     31 + c_binary->header.numberof_symbols = header.numberof_symbols();
     32 + c_binary->header.sizeof_optional_header = header.sizeof_optional_header();
     33 + c_binary->header.characteristics = header.characteristics();
     34 + 
     35 + std::copy(
     36 + std::begin(signature),
     37 + std::end(signature),
     38 + c_binary->header.signature);
     39 +}
     40 + 
     41 +}
     42 +}
     43 + 
  • ■ ■ ■ ■ ■ ■
    api/c/PE/Header.hpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef LIEF_PE_HEADER_CPP_C_API_
     17 +#define LIEF_PE_HEADER_CPP_C_API_
     18 + 
     19 +#include "LIEF/PE/Binary.h"
     20 +#include "LIEF/PE/Binary.hpp"
     21 + 
     22 +#include "LIEF/PE/Header.h"
     23 +#include "LIEF/PE/Header.hpp"
     24 + 
     25 +namespace LIEF {
     26 +namespace PE {
     27 + 
     28 +void init_c_header(Pe_Binary_t* c_binary, Binary* binary);
     29 + 
     30 +}
     31 +}
     32 + 
     33 +#endif
     34 + 
  • ■ ■ ■ ■ ■ ■
    api/c/PE/OptionalHeader.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include "OptionalHeader.hpp"
     17 + 
     18 +namespace LIEF {
     19 +namespace PE {
     20 + 
     21 +void init_c_optional_header(Pe_Binary_t* c_binary, Binary* binary) {
     22 + 
     23 + const OptionalHeader& optional_header = binary->optional_header();
     24 + c_binary->optional_header.magic = static_cast<enum PE_TYPES>(optional_header.magic());
     25 + c_binary->optional_header.major_linker_version = optional_header.major_linker_version();
     26 + c_binary->optional_header.minor_linker_version = optional_header.minor_linker_version();
     27 + c_binary->optional_header.sizeof_code = optional_header.sizeof_code();
     28 + c_binary->optional_header.sizeof_initialized_data = optional_header.sizeof_initialized_data();
     29 + c_binary->optional_header.sizeof_uninitialized_data = optional_header.sizeof_uninitialized_data();
     30 + c_binary->optional_header.addressof_entrypoint = optional_header.addressof_entrypoint();
     31 + c_binary->optional_header.baseof_code = optional_header.baseof_code();
     32 + if (optional_header.magic() == PE_TYPE::PE32) {
     33 + c_binary->optional_header.baseof_data = optional_header.baseof_data();
     34 + } else {
     35 + c_binary->optional_header.baseof_data = 0;
     36 + }
     37 + c_binary->optional_header.imagebase = optional_header.imagebase();
     38 + c_binary->optional_header.section_alignment = optional_header.section_alignment();
     39 + c_binary->optional_header.file_alignment = optional_header.file_alignment();
     40 + c_binary->optional_header.major_operating_system_version = optional_header.major_operating_system_version();
     41 + c_binary->optional_header.minor_operating_system_version = optional_header.minor_operating_system_version();
     42 + c_binary->optional_header.major_image_version = optional_header.major_image_version();
     43 + c_binary->optional_header.minor_image_version = optional_header.minor_image_version();
     44 + c_binary->optional_header.major_subsystem_version = optional_header.major_subsystem_version();
     45 + c_binary->optional_header.minor_subsystem_version = optional_header.minor_subsystem_version();
     46 + c_binary->optional_header.win32_version_value = optional_header.win32_version_value();
     47 + c_binary->optional_header.sizeof_image = optional_header.sizeof_image();
     48 + c_binary->optional_header.sizeof_headers = optional_header.sizeof_headers();
     49 + c_binary->optional_header.checksum = optional_header.checksum();
     50 + c_binary->optional_header.subsystem = static_cast<enum ::SUBSYSTEM>(optional_header.subsystem());
     51 + c_binary->optional_header.dll_characteristics = optional_header.dll_characteristics();
     52 + c_binary->optional_header.sizeof_stack_reserve = optional_header.sizeof_stack_reserve();
     53 + c_binary->optional_header.sizeof_stack_commit = optional_header.sizeof_stack_commit();
     54 + c_binary->optional_header.sizeof_heap_reserve = optional_header.sizeof_heap_reserve();
     55 + c_binary->optional_header.sizeof_heap_commit = optional_header.sizeof_heap_commit();
     56 + c_binary->optional_header.loader_flags = optional_header.loader_flags();
     57 + c_binary->optional_header.numberof_rva_and_size = optional_header.numberof_rva_and_size();
     58 +}
     59 + 
     60 +}
     61 +}
     62 + 
  • ■ ■ ■ ■ ■ ■
    api/c/PE/OptionalHeader.hpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef LIEF_PE_OPTIONAL_HEADER_CPP_C_API_
     17 +#define LIEF_PE_OPTIONAL_HEADER_CPP_C_API_
     18 + 
     19 +#include "LIEF/PE/Binary.h"
     20 +#include "LIEF/PE/Binary.hpp"
     21 + 
     22 +#include "LIEF/PE/OptionalHeader.h"
     23 +#include "LIEF/PE/OptionalHeader.hpp"
     24 + 
     25 +namespace LIEF {
     26 +namespace PE {
     27 + 
     28 +void init_c_optional_header(Pe_Binary_t* c_binary, Binary* binary);
     29 + 
     30 +}
     31 +}
     32 + 
     33 +#endif
     34 + 
  • ■ ■ ■ ■ ■ ■
    api/c/PE/Section.cpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#include "Section.hpp"
     17 + 
     18 +namespace LIEF {
     19 +namespace PE {
     20 +void init_c_sections(Pe_Binary_t* c_binary, Binary* binary) {
     21 + 
     22 + it_sections sections = binary->get_sections();
     23 + 
     24 + c_binary->sections = static_cast<Pe_Section_t**>(
     25 + malloc((sections.size() + 1) * sizeof(Pe_Section_t**)));
     26 + 
     27 + for (size_t i = 0; i < sections.size(); ++i) {
     28 + Section& b_section = sections[i];
     29 + c_binary->sections[i] = static_cast<Pe_Section_t*>(malloc(sizeof(Pe_Section_t)));
     30 + const std::vector<uint8_t>& section_content = b_section.content();
     31 + uint8_t* content = static_cast<uint8_t*>(malloc(section_content.size() * sizeof(uint8_t)));
     32 + std::copy(
     33 + std::begin(section_content),
     34 + std::end(section_content),
     35 + content);
     36 + 
     37 + c_binary->sections[i]->name = b_section.name().c_str();
     38 + c_binary->sections[i]->virtual_address = b_section.virtual_address();
     39 + c_binary->sections[i]->size = b_section.size();
     40 + c_binary->sections[i]->offset = b_section.offset();
     41 + c_binary->sections[i]->virtual_size = b_section.virtual_size();
     42 + c_binary->sections[i]->pointerto_relocation = b_section.pointerto_relocation();
     43 + c_binary->sections[i]->pointerto_line_numbers = b_section.pointerto_line_numbers();
     44 + c_binary->sections[i]->characteristics = b_section.characteristics();
     45 + c_binary->sections[i]->content = content;
     46 + c_binary->sections[i]->entropy = b_section.entropy();
     47 + }
     48 + c_binary->sections[sections.size()] = nullptr;
     49 + 
     50 +}
     51 + 
     52 + 
     53 + 
     54 +void destroy_sections(Pe_Binary_t* c_binary) {
     55 + 
     56 + Pe_Section_t **sections = c_binary->sections;
     57 + for (size_t idx = 0; sections[idx] != nullptr; ++idx) {
     58 + free(sections[idx]->content);
     59 + free(sections[idx]);
     60 + }
     61 + free(c_binary->sections);
     62 + 
     63 +}
     64 + 
     65 +}
     66 +}
     67 + 
     68 + 
     69 + 
  • ■ ■ ■ ■ ■ ■
    api/c/PE/Section.hpp
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef LIEF_PE_SECTION_CPP_C_API_
     17 +#define LIEF_PE_SECTION_CPP_C_API_
     18 + 
     19 +#include "LIEF/PE/Binary.h"
     20 +#include "LIEF/PE/Binary.hpp"
     21 + 
     22 +#include "LIEF/PE/Section.h"
     23 +#include "LIEF/PE/Section.hpp"
     24 + 
     25 +namespace LIEF {
     26 +namespace PE {
     27 + 
     28 +void init_c_sections(Pe_Binary_t* c_binary, Binary* binary);
     29 +void destroy_sections(Pe_Binary_t* c_binary);
     30 + 
     31 +}
     32 +}
     33 + 
     34 +#endif
     35 + 
  • ■ ■ ■ ■ ■ ■
    api/c/include/LIEF/ELF/Binary.h
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef C_LIEF_ELF_BINARY_H_
     17 +#define C_LIEF_ELF_BINARY_H_
     18 + 
     19 +/** @defgroup elf_binary_c_api Binary
     20 + * @ingroup elf_c_api
     21 + * @addtogroup elf_binary_c_api
     22 + * @brief Binary C API
     23 + *
     24 + * @{
     25 + */
     26 + 
     27 +#include <stddef.h>
     28 + 
     29 +#include "LIEF/visibility.h"
     30 + 
     31 +#include "LIEF/ELF/enums.h"
     32 + 
     33 +#include "LIEF/ELF/Section.h"
     34 +#include "LIEF/ELF/Segment.h"
     35 +#include "LIEF/ELF/Header.h"
     36 +#include "LIEF/ELF/DynamicEntry.h"
     37 +#include "LIEF/ELF/Symbol.h"
     38 + 
     39 +#ifdef __cplusplus
     40 +extern "C" {
     41 +#endif
     42 + 
     43 +/** @brief LIEF::ELF::Binary C Handler */
     44 +struct Elf_Binary_t {
     45 + void* handler;
     46 + const char* name;
     47 + const char* interpreter;
     48 + enum ELF_CLASS type;
     49 + Elf_Header_t header;
     50 + Elf_Section_t **sections;
     51 + Elf_Segment_t **segments;
     52 + Elf_DynamicEntry_t **dynamic_entries;
     53 + Elf_Symbol_t **dynamic_symbols;
     54 + Elf_Symbol_t **static_symbols;
     55 +};
     56 + 
     57 +typedef struct Elf_Binary_t Elf_Binary_t;
     58 + 
     59 +/** @brief Wrapper for LIEF::ELF::Parser::parse */
     60 +DLL_PUBLIC Elf_Binary_t* elf_parse(const char *file);
     61 + 
     62 +DLL_PUBLIC void elf_binary_destroy(Elf_Binary_t* binary);
     63 + 
     64 +/* ELF::Binary methods
     65 + * ==================
     66 + */
     67 + 
     68 +/** @brief Update LIEF::ELF::Header object */
     69 +DLL_PUBLIC int elf_binary_save_header(Elf_Binary_t* binary);
     70 + 
     71 + 
     72 + 
     73 +#ifdef __cplusplus
     74 +}
     75 +#endif
     76 + 
     77 + 
     78 +/** @} */
     79 +#endif
     80 + 
  • ■ ■ ■ ■ ■ ■
    api/c/include/LIEF/ELF/DynamicEntry.h
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef C_LIEF_ELF_DYNAMIC_ENTRY_H_
     17 +#define C_LIEF_ELF_DYNAMIC_ENTRY_H_
     18 + 
     19 +#include <stdint.h>
     20 + 
     21 +#include "LIEF/ELF/enums.h"
     22 + 
     23 +/** @defgroup elf_dynamic_entry_c_api Dynamic Entry
     24 + * @ingroup elf_c_api
     25 + * @addtogroup elf_dynamic_entry_c_api
     26 + * @brief Dynamic Entry C API
     27 + *
     28 + * @{
     29 + */
     30 + 
     31 + 
     32 +#ifdef __cplusplus
     33 +extern "C" {
     34 +#endif
     35 + 
     36 +struct Elf_DynamicEntry_t {
     37 + enum DYNAMIC_TAGS tag;
     38 + uint64_t value;
     39 +};
     40 + 
     41 +struct Elf_DynamicEntry_Library_t {
     42 + enum DYNAMIC_TAGS tag;
     43 + uint64_t value;
     44 + const char* name;
     45 +};
     46 + 
     47 +struct Elf_DynamicEntry_SharedObject_t {
     48 + enum DYNAMIC_TAGS tag;
     49 + uint64_t value;
     50 + const char* name;
     51 +};
     52 + 
     53 +struct Elf_DynamicEntry_Array_t {
     54 + enum DYNAMIC_TAGS tag;
     55 + uint64_t value;
     56 + uint64_t* array;
     57 +};
     58 + 
     59 +struct Elf_DynamicEntry_Rpath_t {
     60 + enum DYNAMIC_TAGS tag;
     61 + uint64_t value;
     62 + const char* rpath;
     63 +};
     64 + 
     65 +struct Elf_DynamicEntry_RunPath_t {
     66 + enum DYNAMIC_TAGS tag;
     67 + uint64_t value;
     68 + const char* runpath;
     69 +};
     70 + 
     71 +typedef struct Elf_DynamicEntry_t Elf_DynamicEntry_t;
     72 +typedef struct Elf_DynamicEntry_Library_t Elf_DynamicEntry_Library_t;
     73 +typedef struct Elf_DynamicEntry_SharedObject_t Elf_DynamicEntry_SharedObject_t;
     74 +typedef struct Elf_DynamicEntry_Array_t Elf_DynamicEntry_Array_t;
     75 +typedef struct Elf_DynamicEntry_Rpath_t Elf_DynamicEntry_Rpath_t;
     76 +typedef struct Elf_DynamicEntry_RunPath_t Elf_DynamicEntry_RunPath_t;
     77 + 
     78 +#ifdef __cplusplus
     79 +}
     80 +#endif
     81 + 
     82 +/** @} */
     83 +#endif
     84 + 
  • ■ ■ ■ ■ ■ ■
    api/c/include/LIEF/ELF/EnumToString.h
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef C_LIEF_ELF_ENUM_TO_STRING_H_
     17 +#define C_LIEF_ELF_ENUM_TO_STRING_H_
     18 + 
     19 +#include "LIEF/visibility.h"
     20 + 
     21 +#include "LIEF/ELF/enums.h"
     22 + 
     23 +#ifdef __cplusplus
     24 +extern "C" {
     25 +#endif
     26 + 
     27 +DLL_PUBLIC const char* SYMBOL_BINDINGS_to_string(enum SYMBOL_BINDINGS e);
     28 +DLL_PUBLIC const char* E_TYPE_to_string(enum E_TYPE e);
     29 +DLL_PUBLIC const char* VERSION_to_string(enum VERSION e);
     30 +DLL_PUBLIC const char* ARCH_to_string(enum ARCH e);
     31 +DLL_PUBLIC const char* SEGMENT_TYPES_to_string(enum SEGMENT_TYPES e);
     32 +DLL_PUBLIC const char* DYNAMIC_TAGS_to_string(enum DYNAMIC_TAGS e);
     33 +DLL_PUBLIC const char* SECTION_TYPES_to_string(enum SECTION_TYPES e);
     34 +DLL_PUBLIC const char* SECTION_FLAGS_to_string(enum SECTION_FLAGS e);
     35 +DLL_PUBLIC const char* SYMBOL_TYPES_to_string(enum SYMBOL_TYPES e);
     36 +DLL_PUBLIC const char* ELF_CLASS_to_string(enum ELF_CLASS e);
     37 +DLL_PUBLIC const char* ELF_DATA_to_string(enum ELF_DATA e);
     38 +DLL_PUBLIC const char* OS_ABI_to_string(enum OS_ABI e);
     39 + 
     40 +#ifdef __cplusplus
     41 +}
     42 +#endif
     43 + 
     44 + 
     45 +#endif
     46 + 
  • ■ ■ ■ ■ ■ ■
    api/c/include/LIEF/ELF/Header.h
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef C_LIEF_ELF_HEADER_H_
     17 +#define C_LIEF_ELF_HEADER_H_
     18 +#include <inttypes.h>
     19 + 
     20 +#include "LIEF/ELF/enums.h"
     21 +/** @defgroup elf_header_c_api Header
     22 + * @ingroup elf_c_api
     23 + * @addtogroup elf_header_c_api
     24 + * @brief Header C API
     25 + *
     26 + * @{
     27 + */
     28 + 
     29 +#ifdef __cplusplus
     30 +extern "C" {
     31 +#endif
     32 + 
     33 +struct Elf_Header_t {
     34 + uint8_t identity[EI_NIDENT];
     35 + enum E_TYPE file_type;
     36 + enum ARCH machine_type;
     37 + enum VERSION object_file_version;
     38 + uint64_t entrypoint;
     39 + uint64_t program_headers_offset;
     40 + uint64_t section_headers_offset;
     41 + uint32_t processor_flags;
     42 + uint32_t header_size;
     43 + uint32_t program_header_size;
     44 + uint32_t numberof_segments;
     45 + uint32_t sizeof_section_header;
     46 + uint32_t numberof_sections;
     47 + uint32_t name_string_table_idx;
     48 +};
     49 + 
     50 +typedef struct Elf_Header_t Elf_Header_t;
     51 + 
     52 + 
     53 +#ifdef __cplusplus
     54 +}
     55 +#endif
     56 + 
     57 +/** @} */
     58 +#endif
     59 + 
  • ■ ■ ■ ■ ■ ■
    api/c/include/LIEF/ELF/Section.h
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef C_LIEF_ELF_SECTION_H_
     17 +#define C_LIEF_ELF_SECTION_H_
     18 + 
     19 +#include <stdint.h>
     20 + 
     21 +#include "LIEF/ELF/enums.h"
     22 + 
     23 +/** @defgroup elf_section_c_api Section
     24 + * @ingroup elf_c_api
     25 + * @addtogroup elf_section_c_api
     26 + * @brief Section C API
     27 + *
     28 + * @{
     29 + */
     30 + 
     31 +#ifdef __cplusplus
     32 +extern "C" {
     33 +#endif
     34 + 
     35 +struct Elf_Section_t {
     36 + const char* name;
     37 + uint32_t flags;
     38 + enum SECTION_TYPES type;
     39 + uint64_t virtual_address;
     40 + uint64_t offset;
     41 + uint64_t original_size;
     42 + uint32_t link;
     43 + uint32_t info;
     44 + uint64_t alignment;
     45 + uint64_t entry_size;
     46 + uint64_t size;
     47 + uint8_t* content;
     48 + double entropy;
     49 +};
     50 + 
     51 +typedef struct Elf_Section_t Elf_Section_t;
     52 + 
     53 +#ifdef __cplusplus
     54 +}
     55 +#endif
     56 + 
     57 +/** @} */
     58 +#endif
     59 + 
  • ■ ■ ■ ■ ■ ■
    api/c/include/LIEF/ELF/Segment.h
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef C_LIEF_ELF_SEGMENT_H_
     17 +#define C_LIEF_ELF_SEGMENT_H_
     18 + 
     19 +#include <stdint.h>
     20 +#include "LIEF/ELF/enums.h"
     21 + 
     22 +/** @defgroup elf_segment_c_api Segment
     23 + * @ingroup elf_c_api
     24 + * @addtogroup elf_segment_c_api
     25 + * @brief Segment C API
     26 + *
     27 + * @{
     28 + */
     29 + 
     30 +#ifdef __cplusplus
     31 +extern "C" {
     32 +#endif
     33 + 
     34 +struct Elf_Segment_t {
     35 + enum SEGMENT_TYPES type;
     36 + uint32_t flags;
     37 + uint64_t virtual_address;
     38 + uint64_t virtual_size;
     39 + uint64_t offset;
     40 + uint64_t alignment;
     41 + uint64_t size;
     42 + uint8_t* content;
     43 +};
     44 + 
     45 +typedef struct Elf_Segment_t Elf_Segment_t;
     46 + 
     47 +#ifdef __cplusplus
     48 +}
     49 +#endif
     50 + 
     51 +/** @} */
     52 +#endif
     53 + 
  • ■ ■ ■ ■ ■ ■
    api/c/include/LIEF/ELF/Symbol.h
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef C_LIEF_ELF_SYMBOL_H_
     17 +#define C_LIEF_ELF_SYMBOL_H_
     18 + 
     19 +#include <stdint.h>
     20 + 
     21 +#include "LIEF/ELF/enums.h"
     22 +/* @defgroup elf_symbol_c_api Symbol
     23 + * @ingroup elf_c_api
     24 + * @addtogroup elf_symbol_c_api
     25 + * @brief Symbol C API
     26 + *
     27 + * @{
     28 + */
     29 + 
     30 +#ifdef __cplusplus
     31 +extern "C" {
     32 +#endif
     33 + 
     34 +struct Elf_Symbol_t {
     35 + const char* name;
     36 + enum SYMBOL_TYPES type;
     37 + enum SYMBOL_BINDINGS binding;
     38 + uint8_t information;
     39 + uint8_t other;
     40 + uint16_t shndx;
     41 + uint64_t value;
     42 + uint64_t size;
     43 +};
     44 + 
     45 +typedef struct Elf_Symbol_t Elf_Symbol_t;
     46 + 
     47 +#ifdef __cplusplus
     48 +}
     49 +#endif
     50 + 
     51 +/** @} */
     52 +#endif
     53 + 
  • ■ ■ ■ ■ ■ ■
    api/c/include/LIEF/ELF/enums.h.in
     1 +#ifndef LIEF_ELF_C_ENUMS_H_
     2 +#define LIEF_ELF_C_ENUMS_H_
     3 +#ifdef __cplusplus
     4 +extern "C" {
     5 +#endif
     6 + 
     7 +@LIEF_ELF_ENUMS@
     8 + 
     9 +#ifdef __cplusplus
     10 +}
     11 +#endif
     12 + 
     13 + 
     14 +#endif
     15 + 
  • ■ ■ ■ ■ ■ ■
    api/c/include/LIEF/ELF/structures.h.in
     1 +#ifndef LIEF_ELF_C_STRUCTURES_H_
     2 +#define LIEF_ELF_C_STRUCTURES_H_
     3 +#ifdef __cplusplus
     4 +extern "C" {
     5 +#endif
     6 + 
     7 +@LIEF_ELF_STRUCTURES@
     8 + 
     9 +#ifdef __cplusplus
     10 +}
     11 +#endif
     12 + 
     13 + 
     14 +#endif
     15 + 
  • ■ ■ ■ ■ ■ ■
    api/c/include/LIEF/ELF.h
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef C_LIEF_ELF_H_
     17 +#define C_LIEF_ELF_H_
     18 + 
     19 +//! @defgroup elf_c_api ELF C API
     20 + 
     21 +#include "LIEF/ELF/Binary.h"
     22 +#include "LIEF/ELF/Symbol.h"
     23 +#include "LIEF/ELF/Section.h"
     24 +#include "LIEF/ELF/Header.h"
     25 +#include "LIEF/ELF/DynamicEntry.h"
     26 +#include "LIEF/ELF/EnumToString.h"
     27 +#endif
     28 + 
  • ■ ■ ■ ■ ■ ■
    api/c/include/LIEF/LIEF.h
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef C_LIEF_H_
     17 +#define C_LIEF_H_
     18 + 
     19 +#include <LIEF/MachO.h>
     20 +#include <LIEF/PE.h>
     21 +#include <LIEF/ELF.h>
     22 + 
     23 +#endif
     24 + 
  • ■ ■ ■ ■ ■ ■
    api/c/include/LIEF/MachO/Binary.h
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef C_LIEF_MACHO_BINARY_H_
     17 +#define C_LIEF_MACHO_BINARY_H_
     18 + 
     19 +/** @defgroup macho_binary_c_api Binary
     20 + * @ingroup macho_c_api
     21 + * @addtogroup macho_binary_c_api
     22 + * @brief Binary C API
     23 + *
     24 + * @{
     25 + */
     26 + 
     27 +#include <stddef.h>
     28 + 
     29 +#include "LIEF/visibility.h"
     30 + 
     31 +#include "LIEF/MachO/Header.h"
     32 +#include "LIEF/MachO/LoadCommand.h"
     33 +#include "LIEF/MachO/Symbol.h"
     34 +#include "LIEF/MachO/Section.h"
     35 +#include "LIEF/MachO/Segment.h"
     36 +#include "LIEF/MachO/enums.h"
     37 + 
     38 +#ifdef __cplusplus
     39 +extern "C" {
     40 +#endif
     41 + 
     42 +/** @brief LIEF::MachO::Binary C Handler */
     43 +struct Macho_Binary_t {
     44 + void* handler;
     45 + const char* name;
     46 + uint64_t imagebase;
     47 + Macho_Header_t header;
     48 + Macho_Command_t** commands;
     49 + Macho_Symbol_t** symbols;
     50 + Macho_Section_t** sections;
     51 + Macho_Segment_t** segments;
     52 + 
     53 +};
     54 + 
     55 +typedef struct Macho_Binary_t Macho_Binary_t;
     56 + 
     57 +/** @brief Wrapper on LIEF::MachO::Parser::parse */
     58 +DLL_PUBLIC Macho_Binary_t** macho_parse(const char *file);
     59 + 
     60 +DLL_PUBLIC void macho_binaries_destroy(Macho_Binary_t** binaries);
     61 + 
     62 +#ifdef __cplusplus
     63 +}
     64 +#endif
     65 + 
     66 + 
     67 +/** @} */
     68 +#endif
     69 + 
  • ■ ■ ■ ■ ■ ■
    api/c/include/LIEF/MachO/EnumToString.h
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef C_LIEF_MACHO_ENUM_TO_STRING_H_
     17 +#define C_LIEF_MACHO_ENUM_TO_STRING_H_
     18 + 
     19 +#include "LIEF/visibility.h"
     20 +#include "LIEF/MachO/enums.h"
     21 + 
     22 +#ifdef __cplusplus
     23 +extern "C" {
     24 +#endif
     25 + 
     26 +DLL_PUBLIC const char* LOAD_COMMAND_TYPES_to_string(enum LOAD_COMMAND_TYPES e);
     27 +DLL_PUBLIC const char* MACHO_TYPES_to_string(enum MACHO_TYPES e);
     28 +DLL_PUBLIC const char* FILE_TYPES_to_string(enum FILE_TYPES e);
     29 +DLL_PUBLIC const char* CPU_TYPES_to_string(enum CPU_TYPES e);
     30 +DLL_PUBLIC const char* HEADER_FLAGS_to_string(enum HEADER_FLAGS e);
     31 +DLL_PUBLIC const char* MachO_SECTION_TYPES_to_string(enum SECTION_TYPES e);
     32 +DLL_PUBLIC const char* MachO_SYMBOL_TYPES_to_string(enum SYMBOL_TYPES e);
     33 +DLL_PUBLIC const char* N_LIST_TYPES_to_string(enum N_LIST_TYPES e);
     34 +DLL_PUBLIC const char* SYMBOL_DESCRIPTIONS_to_string(enum SYMBOL_DESCRIPTIONS e);
     35 + 
     36 +#ifdef __cplusplus
     37 +}
     38 +#endif
     39 + 
     40 + 
     41 +#endif
     42 + 
  • ■ ■ ■ ■ ■ ■
    api/c/include/LIEF/MachO/Header.h
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef C_LIEF_MACHO_HEADER_H_
     17 +#define C_LIEF_MACHO_HEADER_H_
     18 +#include <inttypes.h>
     19 + 
     20 +#include "LIEF/MachO/enums.h"
     21 +/** @defgroup macho_header_c_api Header
     22 + * @ingroup macho_c_api
     23 + * @addtogroup macho_header_c_api
     24 + * @brief Header C API
     25 + *
     26 + * @{
     27 + */
     28 + 
     29 +#ifdef __cplusplus
     30 +extern "C" {
     31 +#endif
     32 + 
     33 +struct Macho_Header_t {
     34 + uint32_t magic;
     35 + enum CPU_TYPES cpu_type;
     36 + uint32_t cpu_subtype;
     37 + enum FILE_TYPES file_type;
     38 + uint32_t nb_cmds;
     39 + uint32_t sizeof_cmds;
     40 + uint32_t flags;
     41 + uint32_t reserved;
     42 +};
     43 + 
     44 +typedef struct Macho_Header_t Macho_Header_t;
     45 + 
     46 + 
     47 +#ifdef __cplusplus
     48 +}
     49 +#endif
     50 + 
     51 +/** @} */
     52 +#endif
     53 + 
  • ■ ■ ■ ■ ■ ■
    api/c/include/LIEF/MachO/LoadCommand.h
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef C_LIEF_MACHO_LOAD_COMMAND_H_
     17 +#define C_LIEF_MACHO_LOAD_COMMAND_H_
     18 +#include <inttypes.h>
     19 + 
     20 +#include "LIEF/MachO/enums.h"
     21 +/** @defgroup macho_load_command_c_api Header
     22 + * @ingroup macho_c_api
     23 + * @addtogroup macho_load_command_c_api
     24 + * @brief Load Command C API
     25 + *
     26 + * @{
     27 + */
     28 + 
     29 +#ifdef __cplusplus
     30 +extern "C" {
     31 +#endif
     32 + 
     33 +struct Macho_Command_t {
     34 + enum LOAD_COMMAND_TYPES command;
     35 + uint32_t size;
     36 + uint8_t* data;
     37 + uint32_t offset;
     38 +};
     39 + 
     40 +typedef struct Macho_Command_t Macho_Command_t;
     41 + 
     42 + 
     43 +#ifdef __cplusplus
     44 +}
     45 +#endif
     46 + 
     47 +/** @} */
     48 +#endif
     49 + 
  • ■ ■ ■ ■ ■ ■
    api/c/include/LIEF/MachO/Section.h
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef C_LIEF_MACHO_SECTION_H_
     17 +#define C_LIEF_MACHO_SECTION_H_
     18 +#include <inttypes.h>
     19 + 
     20 +#include "LIEF/MachO/enums.h"
     21 +/** @defgroup macho_section_c_api Header
     22 + * @ingroup macho_c_api
     23 + * @addtogroup macho_section_c_api
     24 + * @brief Section C API
     25 + *
     26 + * @{
     27 + */
     28 + 
     29 +#ifdef __cplusplus
     30 +extern "C" {
     31 +#endif
     32 + 
     33 +struct Macho_Section_t {
     34 + 
     35 + const char* name;
     36 + uint32_t alignment;
     37 + uint32_t relocation_offset;
     38 + uint32_t numberof_relocations;
     39 + uint32_t flags;
     40 + enum SECTION_TYPES type;
     41 + uint32_t reserved1;
     42 + uint32_t reserved2;
     43 + uint32_t reserved3;
     44 + uint64_t virtual_address;
     45 + uint64_t offset;
     46 + uint64_t size;
     47 + uint8_t* content;
     48 + double entropy;
     49 +};
     50 + 
     51 +typedef struct Macho_Section_t Macho_Section_t;
     52 + 
     53 + 
     54 +#ifdef __cplusplus
     55 +}
     56 +#endif
     57 + 
     58 +/** @} */
     59 +#endif
     60 + 
  • ■ ■ ■ ■ ■ ■
    api/c/include/LIEF/MachO/Segment.h
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef C_LIEF_MACHO_SEGMENT_H_
     17 +#define C_LIEF_MACHO_SEGMENT_H_
     18 +#include <inttypes.h>
     19 + 
     20 +#include "LIEF/MachO/enums.h"
     21 +/** @defgroup macho_segment_c_api Header
     22 + * @ingroup macho_c_api
     23 + * @addtogroup macho_segment_c_api
     24 + * @brief Segment C API
     25 + *
     26 + * @{
     27 + */
     28 + 
     29 +#ifdef __cplusplus
     30 +extern "C" {
     31 +#endif
     32 + 
     33 +struct Macho_Segment_t {
     34 + const char* name;
     35 + uint64_t virtual_address;
     36 + uint64_t virtual_size;
     37 + uint64_t file_size;
     38 + uint64_t file_offset;
     39 + uint32_t max_protection;
     40 + uint32_t init_protection;
     41 + uint32_t numberof_sections;
     42 + uint32_t flags;
     43 + uint8_t* content;
     44 + Macho_Section_t** sections;
     45 +};
     46 + 
     47 +typedef struct Macho_Segment_t Macho_Segment_t;
     48 + 
     49 + 
     50 +#ifdef __cplusplus
     51 +}
     52 +#endif
     53 + 
     54 +/** @} */
     55 +#endif
     56 + 
  • ■ ■ ■ ■ ■ ■
    api/c/include/LIEF/MachO/Symbol.h
     1 +/* Copyright 2017 R. Thomas
     2 + * Copyright 2017 Quarkslab
     3 + *
     4 + * Licensed under the Apache License, Version 2.0 (the "License");
     5 + * you may not use this file except in compliance with the License.
     6 + * You may obtain a copy of the License at
     7 + *
     8 + * http://www.apache.org/licenses/LICENSE-2.0
     9 + *
     10 + * Unless required by applicable law or agreed to in writing, software
     11 + * distributed under the License is distributed on an "AS IS" BASIS,
     12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 + * See the License for the specific language governing permissions and
     14 + * limitations under the License.
     15 + */
     16 +#ifndef C_LIEF_MACHO_SYMBOL_H_
     17 +#define C_LIEF_MACHO_SYMBOL_H_
     18 +#include <inttypes.h>
     19 + 
     20 +#include "LIEF/MachO/enums.h"
     21 +/** @defgroup macho_symbol_c_api Header
     22 + * @ingroup macho_c_api
     23 + * @addtogroup macho_symbol_c_api
     24 + * @brief Symbol C API
     25 + *
     26 + * @{
     27 + */
     28 + 
     29 +#ifdef __cplusplus
     30 +extern "C" {
     31 +#endif
     32 + 
     33 +struct Macho_Symbol_t {
     34 + const char* name;
     35 + uint8_t type;
     36 + uint8_t numberof_sections;
     37 + uint16_t description;
     38 + uint64_t value;
     39 +};
     40 + 
     41 +typedef struct Macho_Symbol_t Macho_Symbol_t;
     42 + 
     43 + 
     44 +#ifdef __cplusplus
     45 +}
     46 +#endif
     47 + 
     48 +/** @} */
     49 +#endif
     50 + 
  • ■ ■ ■ ■ ■ ■
    api/c/include/LIEF/MachO/enums.h.in
     1 +#ifndef LIEF_MACHO_C_ENUMS_H_
     2 +#define LIEF_MACHO_C_ENUMS_H_
     3 +#ifdef __cplusplus
     4 +extern "C" {
     5 +#endif
     6 + 
     7 +@LIEF_MACHO_ENUMS@
     8 + 
     9 +#ifdef __cplusplus
     10 +}
     11 +#endif
     12 + 
     13 + 
     14 +#endif
     15 + 
  • ■ ■ ■ ■ ■ ■
    api/c/include/LIEF/MachO/structures.h.in
     1 +#ifndef LIEF_MACHO_C_STRUCTURES_H_
     2 +#define LIEF_MACHO_C_STRUCTURES_H_
     3 +#ifdef __cplusplus
     4 +extern "C" {
     5 +#endif
     6 + 
     7 +@LIEF_MACHO_STRUCTURES@
     8 + 
     9 +#ifdef __cplusplus
     10 +}
     11 +#endif
     12 + 
     13 + 
     14 +#endif
     15 + 
Please wait...
Page is in error, reload to recover