2019-07-24 14:56:25 +02:00
|
|
|
cmake_minimum_required(VERSION 3.5)
|
2017-03-30 16:56:49 +02:00
|
|
|
|
2017-04-24 10:18:06 -04:00
|
|
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
|
|
|
|
2017-03-30 16:56:49 +02:00
|
|
|
# Modules
|
2017-04-16 13:49:44 +02:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
|
2020-11-10 17:21:13 +01:00
|
|
|
if(WIN32)
|
2018-07-27 10:27:20 +02:00
|
|
|
include(ChooseMSVCCRT)
|
|
|
|
endif()
|
2017-03-30 16:56:49 +02:00
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
include(CheckCCompilerFlag)
|
|
|
|
include(ExternalProject)
|
2020-11-26 13:17:50 -05:00
|
|
|
include(CMakePackageConfigHelpers)
|
2017-03-30 16:56:49 +02:00
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git"
|
|
|
|
AND IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
2018-10-31 12:26:53 +00:00
|
|
|
find_package(Git REQUIRED)
|
|
|
|
|
|
|
|
# Information from git
|
|
|
|
# ====================
|
|
|
|
include(LIEFGit)
|
|
|
|
else()
|
|
|
|
set(LIEF_VERSION_MAJOR "0")
|
2019-05-11 08:08:23 +02:00
|
|
|
set(LIEF_VERSION_MINOR "10")
|
2018-10-31 12:26:53 +00:00
|
|
|
set(LIEF_VERSION_PATCH "0")
|
|
|
|
endif()
|
2017-03-30 16:56:49 +02:00
|
|
|
|
2018-03-13 16:49:02 +01:00
|
|
|
# LIEF Project
|
|
|
|
# ============
|
2020-11-10 17:21:13 +01:00
|
|
|
project(
|
|
|
|
LIEF
|
|
|
|
VERSION ${LIEF_VERSION_MAJOR}.${LIEF_VERSION_MINOR}.${LIEF_VERSION_PATCH})
|
2017-03-30 16:56:49 +02:00
|
|
|
message(STATUS "${PROJECT_NAME} ${PROJECT_VERSION}")
|
|
|
|
|
2018-03-13 16:49:02 +01:00
|
|
|
# LIEF options
|
|
|
|
# =============
|
|
|
|
include(LIEFOptions)
|
Improve the ELF part of LIEF
Major changes (features):
* Enable adding multiple sections/segments - Executable (PIE or not), Library
* Enable adding multiple dynamic entries (DT_NEEDED, DT_INIT etc)
* Enable adding multiple relocations
* Enable adding multiple dynamic symbols
* Enable segment replacement
Major changes (API):
* Getters Binary::get_*name*() has been renamed to "name()"
* Binary::add(const DynamicEntry& entry) - To add an entry in the dynamic table
* Section& Binary::add(const Section& section, bool loaded = true) - To add a section(s)
* Segment& Binary::add(const Segment& segment, uint64_t base = 0) - To add segments
* Segment& replace(const Segment& new_segment, const Segment& original_segment, uint64_t base = 0)
* Binary's last_offset_section(), last_offset_segment(), next_virtual_address()
to have information about offset
* Binary's add_library(), get_library(), has_library() to handle
DT_NEEDED entries
Other changes:
* Binary::insert_content() - Use add(const Section&) or add(const Segment&) instead
* ELF's DataHandler has been cleaned
* Through LIEF::Section one can look for integers, strings, data
within the section (see LIEF::Section::search,
LIEF::Section::search_all)
* Through LIEF::Binary one can get *xref* of a number (or address)
see LIEF::Binary::xref function
* To access to the Abstract binary in Python, one can now use
the 'abstract' attribute. (e.g. binary.abstract.header.is_32)
Resolve: #83
Resolve: #66
Resolve: #48
2017-09-02 08:54:54 +02:00
|
|
|
|
2018-03-28 05:57:22 +02:00
|
|
|
# Compiler detection (C++14, C++17, ...)
|
|
|
|
include(LIEFCompilerDetection)
|
|
|
|
|
2017-03-30 16:56:49 +02:00
|
|
|
# CCACHE
|
|
|
|
# ======
|
2020-12-12 08:31:52 +01:00
|
|
|
message(STATUS "Caching: ${LIEF_USE_CCACHE}")
|
|
|
|
if(LIEF_USE_CCACHE)
|
|
|
|
find_program(CCACHE_FOUND ccache)
|
|
|
|
if(CCACHE_FOUND)
|
|
|
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
|
|
|
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
|
|
|
|
message(STATUS "Found ccache: ${CCACHE_FOUND}")
|
|
|
|
else()
|
|
|
|
find_program(SCCACHE_FOUND sccache)
|
|
|
|
if (SCCACHE_FOUND)
|
|
|
|
set(CMAKE_C_COMPILER_LAUNCHER ${SCCACHE_FOUND})
|
|
|
|
set(CMAKE_CXX_COMPILER_LAUNCHER ${SCCACHE_FOUND})
|
|
|
|
message(STATUS "Found sccache: ${SCCACHE_FOUND}")
|
|
|
|
else()
|
|
|
|
set(LIEF_USE_CCACHE OFF)
|
|
|
|
message(WARNING "Can't find cache solution")
|
|
|
|
endif()
|
|
|
|
endif()
|
2017-03-30 16:56:49 +02:00
|
|
|
endif()
|
|
|
|
|
2019-02-04 08:47:43 +01:00
|
|
|
# Dependencies
|
2017-03-30 16:56:49 +02:00
|
|
|
# ============
|
2017-10-31 18:21:21 +01:00
|
|
|
set(THIRD_PARTY_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/third-party/")
|
2018-03-13 16:49:02 +01:00
|
|
|
include(LIEFDependencies)
|
2017-03-30 16:56:49 +02:00
|
|
|
|
2021-01-03 17:52:44 +01:00
|
|
|
# iOS specific config
|
|
|
|
# ===================
|
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
|
|
|
|
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED NO)
|
|
|
|
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED NO)
|
|
|
|
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
message(STATUS "CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}")
|
|
|
|
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
|
|
|
|
message(STATUS "CMAKE_CXX_LINK_EXECUTABLE: ${CMAKE_CXX_LINK_EXECUTABLE}")
|
|
|
|
message(STATUS "CMAKE_CXX_LINK_FLAGS: ${CMAKE_CXX_LINK_FLAGS}")
|
|
|
|
message(STATUS "CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
|
|
|
|
message(STATUS "CMAKE_EXE_LINKER_FLAGS_RELEASE: ${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
|
|
|
|
message(STATUS "CMAKE_SHARED_LINKER_FLAGS: ${CMAKE_SHARED_LINKER_FLAGS}")
|
|
|
|
message(STATUS "CMAKE_SHARED_LINKER_FLAGS_RELEASE: ${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
|
|
|
|
message(STATUS "CMAKE_CXX_LINK_LIBRARY_FILE_FLAG: ${CMAKE_CXX_LINK_LIBRARY_FILE_FLAG}")
|
|
|
|
message(STATUS "CMAKE_LINK_LIBRARY_FILE_FLAG: ${CMAKE_LINK_LIBRARY_FILE_FLAG}")
|
|
|
|
message(STATUS "CMAKE_LINK_INTERFACE_LIBRARIES: ${CMAKE_LINK_INTERFACE_LIBRARIES}")
|
|
|
|
message(STATUS "CMAKE_CXX_IMPLICIT_LINK_LIBRARIES: ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES}")
|
|
|
|
message(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}")
|
|
|
|
|
2017-03-30 16:56:49 +02:00
|
|
|
# LIEF Source definition
|
|
|
|
# ======================
|
|
|
|
set_source_files_properties(${mbedtls_src_crypto} PROPERTIES GENERATED TRUE)
|
|
|
|
set_source_files_properties(${mbedtls_src_x509} PROPERTIES GENERATED TRUE)
|
|
|
|
set_source_files_properties(${mbedtls_src_tls} PROPERTIES GENERATED TRUE)
|
2018-03-13 16:49:02 +01:00
|
|
|
|
|
|
|
set(LIEF_PRIVATE_INCLUDE_DIR)
|
|
|
|
set(LIEF_PUBLIC_INCLUDE_DIR)
|
|
|
|
|
|
|
|
set(LIEF_PUBLIC_INCLUDE_FILES)
|
|
|
|
set(LIEF_PRIVATE_INCLUDE_FILES)
|
|
|
|
|
2017-09-05 22:00:31 +02:00
|
|
|
set(LIBLIEF_SOURCE_FILES
|
2020-11-10 17:21:13 +01:00
|
|
|
"${ELG_CC_PATH}"
|
|
|
|
"${mbedtls_src_crypto}"
|
|
|
|
"${mbedtls_src_x509}"
|
|
|
|
"${mbedtls_src_tls}"
|
|
|
|
"${LIBFUZZER_SRC_FILES}"
|
2021-01-05 19:26:10 +01:00
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/errors.cpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/hash_stream.cpp"
|
2020-11-10 17:21:13 +01:00
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/logging.cpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/exception.cpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/iostream.cpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/utils.cpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/Object.cpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/Object.tcc"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/Visitor.cpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/BinaryStream/BinaryStream.cpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/BinaryStream/VectorStream.cpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/BinaryStream/Convert.cpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/visitors/hash.cpp")
|
2017-03-30 16:56:49 +02:00
|
|
|
|
2017-04-24 10:18:06 -04:00
|
|
|
# Grouping basic headers together
|
|
|
|
# ===============================
|
|
|
|
set(LIEF_INC_FILES
|
2021-01-05 19:26:10 +01:00
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/errors.hpp"
|
2020-11-10 17:21:13 +01:00
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/ELF.hpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/Abstract.hpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/exception.hpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/iostream.hpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/iterators.hpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/LIEF.hpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/logging.hpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/MachO.hpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/PE.hpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/types.hpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/utils.hpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/visibility.h"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/Object.hpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/Visitor.hpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/visitor_macros.hpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/BinaryStream/BinaryStream.hpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/BinaryStream/VectorStream.hpp"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/BinaryStream/Convert.hpp"
|
2021-01-05 19:26:10 +01:00
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/hash_stream.hpp"
|
2020-11-10 17:21:13 +01:00
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/frozen.hpp")
|
2017-04-24 10:18:06 -04:00
|
|
|
|
|
|
|
set(LIEF_VISITOR_INCLUDE_FILES
|
2020-11-10 17:21:13 +01:00
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/hash.hpp")
|
2017-04-24 10:18:06 -04:00
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
set(LIEF_INCLUDE_FILES ${LIEF_INC_FILES} ${LIEF_VISITOR_INCLUDE_FILES})
|
2017-09-05 22:00:31 +02:00
|
|
|
|
2018-03-13 16:49:02 +01:00
|
|
|
set(LIEF_JSON_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src/visitors/json.cpp")
|
2020-11-10 17:21:13 +01:00
|
|
|
set(LIEF_JSON_HDR "${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/json.hpp"
|
2020-11-10 17:52:34 +01:00
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/third-party/json.hpp")
|
2017-09-28 10:54:37 +02:00
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
if(LIEF_ENABLE_JSON)
|
|
|
|
list(APPEND LIBLIEF_SOURCE_FILES "${LIEF_JSON_SRC}")
|
|
|
|
list(APPEND LIEF_INC_FILES "${LIEF_JSON_HDR}")
|
2018-03-13 16:49:02 +01:00
|
|
|
endif()
|
2017-09-28 10:54:37 +02:00
|
|
|
|
2017-09-05 22:00:31 +02:00
|
|
|
source_group("Header Files" FILES ${LIEF_INC_FILES})
|
|
|
|
source_group("Source Files" FILES ${LIBLIEF_SOURCE_FILES})
|
2017-04-24 10:18:06 -04:00
|
|
|
|
|
|
|
source_group("Header Files\\visitors" FILES ${LIEF_VISITOR_INCLUDE_FILES})
|
|
|
|
|
2018-07-27 10:27:20 +02:00
|
|
|
add_library(LIB_LIEF ${LIBLIEF_SOURCE_FILES} ${LIEF_INCLUDE_FILES})
|
2017-03-30 16:56:49 +02:00
|
|
|
|
2018-07-27 10:27:20 +02:00
|
|
|
if(WINDOWS AND BUILD_SHARED_LIBS)
|
|
|
|
target_link_libraries(LIB_LIEF ws2_32)
|
2018-04-15 15:11:54 +02:00
|
|
|
endif()
|
|
|
|
|
2018-10-31 12:27:26 +00:00
|
|
|
if(MSVC)
|
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /bigobj")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
|
2019-08-29 08:24:39 +02:00
|
|
|
endif()
|
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
if(CMAKE_BUILD_TYPE MATCHES Debug AND WINDOWS)
|
|
|
|
add_definitions(-D_ITERATOR_DEBUG_LEVEL=0 -D_SECURE_SCL=0
|
|
|
|
-D_HAS_ITERATOR_DEBUGGING=0)
|
2019-08-29 08:24:39 +02:00
|
|
|
endif()
|
2018-10-31 12:27:26 +00:00
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
if(CMAKE_BUILD_TYPE MATCHES Debug AND UNIX)
|
Authenticode-related bug fixes and improvements
Part of Authenticode verification consists of:
- Comparing the computed Authenticode hash to the digest
stored in the ContentInfo section
- Comparing hash(ContentInfo) to the digest stored in the
AuthenticatedAttributes section
- Verifying signed(hash(AuthenticatedAttributes)) using a
certificate identified by the issuer and serial number
specified in the SignerInfo section
This commit makes it so that the raw bytes needed to
calculate hash(ContentInfo) and hash(AuthenticatedAttributes)
are available for use.
============================================================
Allow missing [0] in SpcSpOpusInfo
Some executables have MoreInfo but not a ProgramName (and the documentation
lists both as OPTIONAL), so handle this case correctly.
Example:
```
01416b1730218454c99b13592650cb170402b86742b4bab971565903b841829b
SEQUENCE(2 elem)
OBJECT IDENTIFIER1.3.6.1.4.1.311.2.1.12spcSpOpusInfo(Microsoft code signing)
SET(1 elem)
SEQUENCE(1 elem)
[1](1 elem)
[0]http://www.mozilla.com
```
============================================================
Improve consistency of parsed serial numbers
When parsing the issuer serial number, call mbedtls_x509_get_serial instead of
parsing it as an integer directly with mbedtls_asn1_get_mpi. These two functions
differ in how they treat serial numbers prepended with '00' to prevent them from
being negative (the former preserves the '00', and the latter discards it). The
embedded certs are parsed via a call to mbedtls_x509_crt_parse_der, which uses
mbedtls_x509_get_serial behind the scenes, so there was an inconsistency between
lief_obj.signature.signer_info.issuer[1] and
lief_obj.signature.certificates[x].serial_number. Example:
8bf57d97dd917c4f823659266caaa33e7398406daf11ba8318e3f7414ee3fb24
============================================================
Handle SpcLink and SpcString CHOICEs in SpcSpOpusInfo
The Authenticode spec doc says that these can be CHOICES, so
handle the easy ones and safely skip the others.
============================================================
Allow Authenticode sig to be parsed even if cert parsing fails
By default, mbedtls doesn't support MD2 certs, which are fairly
common in older signed executables. Ex:
1cb16f94cebdcad7dd05c8537375a6ff6379fcdb08528fc83889f26efaa84e2a
============================================================
Enable mbed TLS MD2 and MD4 support; add Unix debug options
By default, mbedtls doesn't support MD2 certs, which are fairly
common in older signed executables. Ex:
1cb16f94cebdcad7dd05c8537375a6ff6379fcdb08528fc83889f26efaa84e2a
============================================================
Set MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION flag
Some older signed executables use certs with the SpcSpAgencyInfo
Critical Extension, which mbed TLS doesn't support, so set
MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION to have it
skip this extension. Example:
781ca31416ec708a587851dafd90c661b86f244ab8b8475c4185e958e54ff838
============================================================
Support accessing non-utf8 issuer names via Python
For a few signatures where the issuer name contained non-utf8
characters, accessing the issuer name field in Python would raise
a UnicodeDecodeError exception. Now this field is handled the
same way the names in the individual certs are (I'm not sure if
they get represented 100% correctly, but at least they are
consistent, which is good enough for me). Example:
048f91b9302c88380fc66adac1e314d82733089ef3a31eadca5f0cb4169b195f
2019-07-26 17:51:14 -04:00
|
|
|
target_compile_options(LIB_LIEF PRIVATE -g -O0)
|
|
|
|
endif()
|
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
if(BUILD_SHARED_LIBS)
|
2019-05-11 10:40:52 +02:00
|
|
|
target_compile_definitions(LIB_LIEF PRIVATE -DLIEF_EXPORTS)
|
|
|
|
else()
|
|
|
|
target_compile_definitions(LIB_LIEF PRIVATE -DLIEF_STATIC)
|
|
|
|
endif()
|
2020-11-10 17:21:13 +01:00
|
|
|
if(LIEF_SUPPORT_CXX14)
|
2018-07-27 10:27:20 +02:00
|
|
|
target_compile_features(LIB_LIEF PRIVATE cxx_std_14)
|
2018-03-28 05:57:22 +02:00
|
|
|
endif()
|
2018-03-13 16:49:02 +01:00
|
|
|
|
2017-09-05 22:00:31 +02:00
|
|
|
# Abstract part
|
|
|
|
include("${CMAKE_CURRENT_SOURCE_DIR}/src/Abstract/CMakeLists.txt")
|
2017-03-30 16:56:49 +02:00
|
|
|
|
2017-09-05 22:00:31 +02:00
|
|
|
# ELF Part
|
2017-11-18 16:37:40 +01:00
|
|
|
# ========
|
|
|
|
include("${CMAKE_CURRENT_SOURCE_DIR}/src/ELF/CMakeLists.txt")
|
2020-11-10 17:21:13 +01:00
|
|
|
if(LIEF_ELF)
|
2017-11-18 16:37:40 +01:00
|
|
|
set(ENABLE_ELF_SUPPORT 1)
|
|
|
|
else()
|
|
|
|
set(ENABLE_ELF_SUPPORT 0)
|
2017-03-30 16:56:49 +02:00
|
|
|
endif()
|
|
|
|
|
2017-09-05 22:00:31 +02:00
|
|
|
# PE Part
|
2017-11-18 16:37:40 +01:00
|
|
|
# =======
|
|
|
|
include("${CMAKE_CURRENT_SOURCE_DIR}/src/PE/CMakeLists.txt")
|
2020-11-10 17:21:13 +01:00
|
|
|
if(LIEF_PE)
|
2017-11-18 16:37:40 +01:00
|
|
|
set(ENABLE_PE_SUPPORT 1)
|
|
|
|
else()
|
|
|
|
set(ENABLE_PE_SUPPORT 0)
|
|
|
|
endif()
|
|
|
|
|
2017-09-05 22:00:31 +02:00
|
|
|
# MachO part
|
2017-11-18 16:37:40 +01:00
|
|
|
# ==========
|
|
|
|
include("${CMAKE_CURRENT_SOURCE_DIR}/src/MachO/CMakeLists.txt")
|
2020-11-10 17:21:13 +01:00
|
|
|
if(LIEF_MACHO)
|
2017-11-18 16:37:40 +01:00
|
|
|
set(ENABLE_MACHO_SUPPORT 1)
|
|
|
|
else()
|
|
|
|
set(ENABLE_MACHO_SUPPORT 0)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Logging Configuration
|
|
|
|
# =====================
|
2018-07-16 08:57:54 +02:00
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
target_compile_definitions(LIB_LIEF PRIVATE SPDLOG_DISABLE_DEFAULT_LOGGER
|
|
|
|
SPDLOG_FUNCTION=)
|
2017-03-30 16:56:49 +02:00
|
|
|
|
2018-03-28 05:57:22 +02:00
|
|
|
# Frozen Configuration
|
|
|
|
# ====================
|
2020-11-10 17:21:13 +01:00
|
|
|
if(LIEF_FROZEN_ENABLED)
|
2018-03-28 05:57:22 +02:00
|
|
|
list(APPEND LIEF_PRIVATE_INCLUDE_DIR "${FROZEN_INCLUDE_DIR}")
|
|
|
|
endif()
|
2017-03-30 16:56:49 +02:00
|
|
|
|
2018-05-04 12:46:28 +02:00
|
|
|
# OAT part
|
|
|
|
# ========
|
2020-11-10 17:21:13 +01:00
|
|
|
if(LIEF_OAT)
|
2018-05-04 12:46:28 +02:00
|
|
|
include(${CMAKE_CURRENT_SOURCE_DIR}/src/OAT/CMakeLists.txt)
|
|
|
|
set(ENABLE_OAT_SUPPORT 1)
|
|
|
|
else()
|
|
|
|
set(ENABLE_OAT_SUPPORT 0)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# DEX part
|
|
|
|
# ========
|
2020-11-10 17:21:13 +01:00
|
|
|
if(LIEF_DEX)
|
2018-05-04 12:46:28 +02:00
|
|
|
include(${CMAKE_CURRENT_SOURCE_DIR}/src/DEX/CMakeLists.txt)
|
|
|
|
set(ENABLE_DEX_SUPPORT 1)
|
|
|
|
else()
|
|
|
|
set(ENABLE_DEX_SUPPORT 0)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# VDEX part
|
Authenticode-related bug fixes and improvements
Part of Authenticode verification consists of:
- Comparing the computed Authenticode hash to the digest
stored in the ContentInfo section
- Comparing hash(ContentInfo) to the digest stored in the
AuthenticatedAttributes section
- Verifying signed(hash(AuthenticatedAttributes)) using a
certificate identified by the issuer and serial number
specified in the SignerInfo section
This commit makes it so that the raw bytes needed to
calculate hash(ContentInfo) and hash(AuthenticatedAttributes)
are available for use.
============================================================
Allow missing [0] in SpcSpOpusInfo
Some executables have MoreInfo but not a ProgramName (and the documentation
lists both as OPTIONAL), so handle this case correctly.
Example:
```
01416b1730218454c99b13592650cb170402b86742b4bab971565903b841829b
SEQUENCE(2 elem)
OBJECT IDENTIFIER1.3.6.1.4.1.311.2.1.12spcSpOpusInfo(Microsoft code signing)
SET(1 elem)
SEQUENCE(1 elem)
[1](1 elem)
[0]http://www.mozilla.com
```
============================================================
Improve consistency of parsed serial numbers
When parsing the issuer serial number, call mbedtls_x509_get_serial instead of
parsing it as an integer directly with mbedtls_asn1_get_mpi. These two functions
differ in how they treat serial numbers prepended with '00' to prevent them from
being negative (the former preserves the '00', and the latter discards it). The
embedded certs are parsed via a call to mbedtls_x509_crt_parse_der, which uses
mbedtls_x509_get_serial behind the scenes, so there was an inconsistency between
lief_obj.signature.signer_info.issuer[1] and
lief_obj.signature.certificates[x].serial_number. Example:
8bf57d97dd917c4f823659266caaa33e7398406daf11ba8318e3f7414ee3fb24
============================================================
Handle SpcLink and SpcString CHOICEs in SpcSpOpusInfo
The Authenticode spec doc says that these can be CHOICES, so
handle the easy ones and safely skip the others.
============================================================
Allow Authenticode sig to be parsed even if cert parsing fails
By default, mbedtls doesn't support MD2 certs, which are fairly
common in older signed executables. Ex:
1cb16f94cebdcad7dd05c8537375a6ff6379fcdb08528fc83889f26efaa84e2a
============================================================
Enable mbed TLS MD2 and MD4 support; add Unix debug options
By default, mbedtls doesn't support MD2 certs, which are fairly
common in older signed executables. Ex:
1cb16f94cebdcad7dd05c8537375a6ff6379fcdb08528fc83889f26efaa84e2a
============================================================
Set MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION flag
Some older signed executables use certs with the SpcSpAgencyInfo
Critical Extension, which mbed TLS doesn't support, so set
MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION to have it
skip this extension. Example:
781ca31416ec708a587851dafd90c661b86f244ab8b8475c4185e958e54ff838
============================================================
Support accessing non-utf8 issuer names via Python
For a few signatures where the issuer name contained non-utf8
characters, accessing the issuer name field in Python would raise
a UnicodeDecodeError exception. Now this field is handled the
same way the names in the individual certs are (I'm not sure if
they get represented 100% correctly, but at least they are
consistent, which is good enough for me). Example:
048f91b9302c88380fc66adac1e314d82733089ef3a31eadca5f0cb4169b195f
2019-07-26 17:51:14 -04:00
|
|
|
# =========
|
2020-11-10 17:21:13 +01:00
|
|
|
if(LIEF_VDEX)
|
2018-05-04 12:46:28 +02:00
|
|
|
include(${CMAKE_CURRENT_SOURCE_DIR}/src/VDEX/CMakeLists.txt)
|
|
|
|
set(ENABLE_VDEX_SUPPORT 1)
|
|
|
|
else()
|
|
|
|
set(ENABLE_VDEX_SUPPORT 0)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# ART part
|
Authenticode-related bug fixes and improvements
Part of Authenticode verification consists of:
- Comparing the computed Authenticode hash to the digest
stored in the ContentInfo section
- Comparing hash(ContentInfo) to the digest stored in the
AuthenticatedAttributes section
- Verifying signed(hash(AuthenticatedAttributes)) using a
certificate identified by the issuer and serial number
specified in the SignerInfo section
This commit makes it so that the raw bytes needed to
calculate hash(ContentInfo) and hash(AuthenticatedAttributes)
are available for use.
============================================================
Allow missing [0] in SpcSpOpusInfo
Some executables have MoreInfo but not a ProgramName (and the documentation
lists both as OPTIONAL), so handle this case correctly.
Example:
```
01416b1730218454c99b13592650cb170402b86742b4bab971565903b841829b
SEQUENCE(2 elem)
OBJECT IDENTIFIER1.3.6.1.4.1.311.2.1.12spcSpOpusInfo(Microsoft code signing)
SET(1 elem)
SEQUENCE(1 elem)
[1](1 elem)
[0]http://www.mozilla.com
```
============================================================
Improve consistency of parsed serial numbers
When parsing the issuer serial number, call mbedtls_x509_get_serial instead of
parsing it as an integer directly with mbedtls_asn1_get_mpi. These two functions
differ in how they treat serial numbers prepended with '00' to prevent them from
being negative (the former preserves the '00', and the latter discards it). The
embedded certs are parsed via a call to mbedtls_x509_crt_parse_der, which uses
mbedtls_x509_get_serial behind the scenes, so there was an inconsistency between
lief_obj.signature.signer_info.issuer[1] and
lief_obj.signature.certificates[x].serial_number. Example:
8bf57d97dd917c4f823659266caaa33e7398406daf11ba8318e3f7414ee3fb24
============================================================
Handle SpcLink and SpcString CHOICEs in SpcSpOpusInfo
The Authenticode spec doc says that these can be CHOICES, so
handle the easy ones and safely skip the others.
============================================================
Allow Authenticode sig to be parsed even if cert parsing fails
By default, mbedtls doesn't support MD2 certs, which are fairly
common in older signed executables. Ex:
1cb16f94cebdcad7dd05c8537375a6ff6379fcdb08528fc83889f26efaa84e2a
============================================================
Enable mbed TLS MD2 and MD4 support; add Unix debug options
By default, mbedtls doesn't support MD2 certs, which are fairly
common in older signed executables. Ex:
1cb16f94cebdcad7dd05c8537375a6ff6379fcdb08528fc83889f26efaa84e2a
============================================================
Set MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION flag
Some older signed executables use certs with the SpcSpAgencyInfo
Critical Extension, which mbed TLS doesn't support, so set
MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION to have it
skip this extension. Example:
781ca31416ec708a587851dafd90c661b86f244ab8b8475c4185e958e54ff838
============================================================
Support accessing non-utf8 issuer names via Python
For a few signatures where the issuer name contained non-utf8
characters, accessing the issuer name field in Python would raise
a UnicodeDecodeError exception. Now this field is handled the
same way the names in the individual certs are (I'm not sure if
they get represented 100% correctly, but at least they are
consistent, which is good enough for me). Example:
048f91b9302c88380fc66adac1e314d82733089ef3a31eadca5f0cb4169b195f
2019-07-26 17:51:14 -04:00
|
|
|
# ========
|
2020-11-10 17:21:13 +01:00
|
|
|
if(LIEF_ART)
|
2018-05-04 12:46:28 +02:00
|
|
|
include(${CMAKE_CURRENT_SOURCE_DIR}/src/ART/CMakeLists.txt)
|
|
|
|
set(ENABLE_ART_SUPPORT 1)
|
|
|
|
else()
|
|
|
|
set(ENABLE_ART_SUPPORT 0)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Platforms
|
|
|
|
# =========
|
|
|
|
include(${CMAKE_CURRENT_SOURCE_DIR}/src/platforms/CMakeLists.txt)
|
|
|
|
|
2017-03-30 16:56:49 +02:00
|
|
|
# LIEF includes
|
Authenticode-related bug fixes and improvements
Part of Authenticode verification consists of:
- Comparing the computed Authenticode hash to the digest
stored in the ContentInfo section
- Comparing hash(ContentInfo) to the digest stored in the
AuthenticatedAttributes section
- Verifying signed(hash(AuthenticatedAttributes)) using a
certificate identified by the issuer and serial number
specified in the SignerInfo section
This commit makes it so that the raw bytes needed to
calculate hash(ContentInfo) and hash(AuthenticatedAttributes)
are available for use.
============================================================
Allow missing [0] in SpcSpOpusInfo
Some executables have MoreInfo but not a ProgramName (and the documentation
lists both as OPTIONAL), so handle this case correctly.
Example:
```
01416b1730218454c99b13592650cb170402b86742b4bab971565903b841829b
SEQUENCE(2 elem)
OBJECT IDENTIFIER1.3.6.1.4.1.311.2.1.12spcSpOpusInfo(Microsoft code signing)
SET(1 elem)
SEQUENCE(1 elem)
[1](1 elem)
[0]http://www.mozilla.com
```
============================================================
Improve consistency of parsed serial numbers
When parsing the issuer serial number, call mbedtls_x509_get_serial instead of
parsing it as an integer directly with mbedtls_asn1_get_mpi. These two functions
differ in how they treat serial numbers prepended with '00' to prevent them from
being negative (the former preserves the '00', and the latter discards it). The
embedded certs are parsed via a call to mbedtls_x509_crt_parse_der, which uses
mbedtls_x509_get_serial behind the scenes, so there was an inconsistency between
lief_obj.signature.signer_info.issuer[1] and
lief_obj.signature.certificates[x].serial_number. Example:
8bf57d97dd917c4f823659266caaa33e7398406daf11ba8318e3f7414ee3fb24
============================================================
Handle SpcLink and SpcString CHOICEs in SpcSpOpusInfo
The Authenticode spec doc says that these can be CHOICES, so
handle the easy ones and safely skip the others.
============================================================
Allow Authenticode sig to be parsed even if cert parsing fails
By default, mbedtls doesn't support MD2 certs, which are fairly
common in older signed executables. Ex:
1cb16f94cebdcad7dd05c8537375a6ff6379fcdb08528fc83889f26efaa84e2a
============================================================
Enable mbed TLS MD2 and MD4 support; add Unix debug options
By default, mbedtls doesn't support MD2 certs, which are fairly
common in older signed executables. Ex:
1cb16f94cebdcad7dd05c8537375a6ff6379fcdb08528fc83889f26efaa84e2a
============================================================
Set MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION flag
Some older signed executables use certs with the SpcSpAgencyInfo
Critical Extension, which mbed TLS doesn't support, so set
MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION to have it
skip this extension. Example:
781ca31416ec708a587851dafd90c661b86f244ab8b8475c4185e958e54ff838
============================================================
Support accessing non-utf8 issuer names via Python
For a few signatures where the issuer name contained non-utf8
characters, accessing the issuer name field in Python would raise
a UnicodeDecodeError exception. Now this field is handled the
same way the names in the individual certs are (I'm not sure if
they get represented 100% correctly, but at least they are
consistent, which is good enough for me). Example:
048f91b9302c88380fc66adac1e314d82733089ef3a31eadca5f0cb4169b195f
2019-07-26 17:51:14 -04:00
|
|
|
# =============
|
2020-11-10 17:21:13 +01:00
|
|
|
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/version.h.in"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/version.h")
|
|
|
|
|
|
|
|
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/config.h.in"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/config.h" @ONLY)
|
|
|
|
|
|
|
|
list(APPEND LIEF_PUBLIC_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/api/c/include/"
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/include/")
|
|
|
|
|
2020-11-10 17:52:34 +01:00
|
|
|
list(APPEND LIEF_PRIVATE_INCLUDE_DIR "${LIEF_PUBLIC_INCLUDE_DIR}"
|
2021-01-05 19:26:10 +01:00
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/src" "${CMAKE_BINARY_DIR}")
|
2020-08-26 08:16:21 -05:00
|
|
|
|
2021-01-05 19:26:10 +01:00
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/LIEF.pc.in ${CMAKE_CURRENT_BINARY_DIR}/LIEF.pc
|
2020-11-10 17:21:13 +01:00
|
|
|
@ONLY)
|
2018-03-13 16:49:02 +01:00
|
|
|
|
2017-04-24 10:18:06 -04:00
|
|
|
# Grouping external projects
|
|
|
|
# ==========================
|
|
|
|
source_group("mbedtls\\crypto" FILES ${mbedtls_src_crypto})
|
2020-11-10 17:21:13 +01:00
|
|
|
source_group("mbedtls\\x509" FILES ${mbedtls_src_x509})
|
|
|
|
source_group("mbedtls\\tls" FILES ${mbedtls_src_tls})
|
2017-04-24 10:18:06 -04:00
|
|
|
|
2017-03-30 16:56:49 +02:00
|
|
|
# Library definition
|
|
|
|
# ==================
|
2020-11-10 17:21:13 +01:00
|
|
|
target_include_directories(
|
2020-11-10 17:52:34 +01:00
|
|
|
LIB_LIEF SYSTEM PRIVATE "${SPDLOG_SOURCE_DIR}/include"
|
2020-11-10 17:21:13 +01:00
|
|
|
"${MBEDTLS_INCLUDE_DIRS}")
|
|
|
|
|
|
|
|
target_include_directories(
|
|
|
|
LIB_LIEF
|
|
|
|
PUBLIC "${LIEF_PUBLIC_INCLUDE_DIR}"
|
2017-04-05 15:33:18 +02:00
|
|
|
PRIVATE "${LIEF_PRIVATE_INCLUDE_DIR}")
|
2017-03-30 16:56:49 +02:00
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
if(LIEF_ENABLE_JSON)
|
2020-12-23 07:37:39 +01:00
|
|
|
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/third-party/json.hpp
|
|
|
|
COMMAND
|
|
|
|
${CMAKE_COMMAND} -E copy_directory ${LIBJSON_SOURCE_DIR}/
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/third-party/
|
2020-11-11 07:13:55 +01:00
|
|
|
DEPENDS lief_libjson)
|
2020-12-23 07:37:39 +01:00
|
|
|
|
|
|
|
target_sources(LIB_LIEF PRIVATE
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/third-party/json.hpp)
|
2017-08-20 07:08:50 +02:00
|
|
|
endif()
|
2017-03-30 16:56:49 +02:00
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
if(LIEF_FROZEN_ENABLED)
|
2018-07-27 10:27:20 +02:00
|
|
|
add_dependencies(LIB_LIEF lief_frozen)
|
2018-03-28 05:57:22 +02:00
|
|
|
endif()
|
|
|
|
|
2021-01-12 20:44:23 +01:00
|
|
|
# =======================================
|
|
|
|
# Leaf
|
|
|
|
# =======================================
|
2021-01-05 19:26:10 +01:00
|
|
|
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/third-party/boost/leaf/all.hpp
|
|
|
|
COMMAND
|
|
|
|
${CMAKE_COMMAND} -E copy_directory ${LEAF_INCLUDE_DIR}/
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/third-party/
|
|
|
|
DEPENDS lief_leaf)
|
|
|
|
|
|
|
|
target_sources(LIB_LIEF PRIVATE
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/third-party/boost/leaf/all.hpp)
|
|
|
|
|
2021-01-12 20:44:23 +01:00
|
|
|
# =======================================
|
|
|
|
# utfcpp
|
|
|
|
# =======================================
|
2021-01-08 06:41:11 +01:00
|
|
|
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/third-party/utfcpp/utf8.h
|
|
|
|
COMMAND
|
|
|
|
${CMAKE_COMMAND} -E copy_directory ${UTFCPP_INCLUDE_DIR}/
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/third-party/utfcpp
|
|
|
|
DEPENDS lief_utfcpp)
|
|
|
|
|
|
|
|
target_sources(LIB_LIEF PRIVATE
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/third-party/utfcpp/utf8.h)
|
|
|
|
|
|
|
|
|
2020-12-23 07:37:39 +01:00
|
|
|
add_dependencies(LIB_LIEF lief_spdlog lief_mbed_tls)
|
2017-03-30 16:56:49 +02:00
|
|
|
|
|
|
|
# Flags definition
|
|
|
|
# ----------------
|
2020-11-09 21:02:50 +01:00
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
# cmake-format: off
|
|
|
|
set_target_properties(
|
|
|
|
LIB_LIEF
|
|
|
|
PROPERTIES POSITION_INDEPENDENT_CODE ON
|
|
|
|
CXX_STANDARD 11
|
|
|
|
CXX_STANDARD_REQUIRED ON
|
|
|
|
CXX_VISIBILITY_PRESET hidden
|
|
|
|
C_VISIBILITY_PRESET hidden)
|
|
|
|
# cmake-format: on
|
2019-05-04 07:17:03 +02:00
|
|
|
|
2021-01-03 17:52:44 +01:00
|
|
|
if(UNIX AND NOT APPLE)
|
|
|
|
set_property(
|
|
|
|
TARGET LIB_LIEF
|
|
|
|
APPEND
|
|
|
|
PROPERTY LINK_FLAGS "-Wl,--gc-sections -Wl,--exclude-libs,ALL")
|
|
|
|
endif()
|
|
|
|
|
2019-05-04 07:17:03 +02:00
|
|
|
target_compile_definitions(LIB_LIEF PUBLIC -D_GLIBCXX_USE_CXX11_ABI=1)
|
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
# Enable support for MD2 and MD4 for parsing the Authenticode sigs of older
|
|
|
|
# executables. Also, some older signed executables use certs with the
|
|
|
|
# SpcSpAgencyInfo Critical Extension, which mbed TLS doesn't support, so set
|
|
|
|
# MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION to have it skip this
|
|
|
|
# extension.
|
2021-01-05 19:26:10 +01:00
|
|
|
add_definitions(-DMBEDTLS_MD2_C -DMBEDTLS_MD4_C -DMBEDTLS_PEM_PARSE_C
|
|
|
|
-DMBEDTLS_X509_CRT_PARSE_C -DMBEDTLS_PEM_WRITE_C
|
2021-01-12 20:44:23 +01:00
|
|
|
-DMBEDTLS_PKCS1_V15 -DMBEDTLS_PKCS1_V21
|
2020-11-10 17:21:13 +01:00
|
|
|
-DMBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION)
|
2017-09-28 10:54:37 +02:00
|
|
|
|
|
|
|
# ASAN - LSAN - TSAN - USAN
|
2020-11-10 17:21:13 +01:00
|
|
|
# ~~~
|
2017-09-28 10:54:37 +02:00
|
|
|
set(SANITIZER_FLAGS -fno-omit-frame-pointer -g -O1)
|
2020-11-10 17:21:13 +01:00
|
|
|
if(LIEF_ASAN)
|
2017-09-28 08:54:40 +02:00
|
|
|
message(STATUS "Address sanitizer enabled")
|
|
|
|
list(APPEND SANITIZER_FLAGS -fsanitize=address)
|
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
set_property(
|
|
|
|
TARGET LIB_LIEF
|
|
|
|
APPEND
|
|
|
|
PROPERTY LINK_FLAGS -fsanitize=address)
|
2018-07-27 10:27:20 +02:00
|
|
|
target_link_libraries(LIB_LIEF INTERFACE asan)
|
2017-09-28 08:54:40 +02:00
|
|
|
endif()
|
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
if(LIEF_LSAN)
|
2017-09-28 08:54:40 +02:00
|
|
|
message(STATUS "Leak sanitizer enabled")
|
|
|
|
list(APPEND SANITIZER_FLAGS -fsanitize=leak)
|
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
set_property(
|
|
|
|
TARGET LIB_LIEF
|
|
|
|
APPEND
|
|
|
|
PROPERTY LINK_FLAGS -fsanitize=leak)
|
2017-09-28 10:54:37 +02:00
|
|
|
|
2018-07-27 10:27:20 +02:00
|
|
|
target_link_libraries(LIB_LIEF INTERFACE lsan)
|
2017-09-28 08:54:40 +02:00
|
|
|
endif()
|
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
if(LIEF_TSAN)
|
2017-09-28 08:54:40 +02:00
|
|
|
message(STATUS "Thread sanitizer enabled")
|
|
|
|
list(APPEND SANITIZER_FLAGS -fsanitize=thread)
|
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
set_property(
|
|
|
|
TARGET LIB_LIEF
|
|
|
|
APPEND
|
|
|
|
PROPERTY LINK_FLAGS -fsanitize=thread)
|
2017-09-28 10:54:37 +02:00
|
|
|
|
2018-07-27 10:27:20 +02:00
|
|
|
target_link_libraries(LIB_LIEF INTERFACE tsan)
|
2017-09-28 08:54:40 +02:00
|
|
|
endif()
|
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
if(LIEF_USAN)
|
2017-09-28 08:54:40 +02:00
|
|
|
message(STATUS "Undefined sanitizer enabled")
|
|
|
|
list(APPEND SANITIZER_FLAGS -fsanitize=undefined)
|
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
set_property(
|
|
|
|
TARGET LIB_LIEF
|
|
|
|
APPEND
|
|
|
|
PROPERTY LINK_FLAGS -fsanitize=undefined)
|
2017-09-28 10:54:37 +02:00
|
|
|
|
2018-07-27 10:27:20 +02:00
|
|
|
target_link_libraries(LIB_LIEF INTERFACE ubsan)
|
2017-09-28 08:54:40 +02:00
|
|
|
endif()
|
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
if(LIEF_ASAN
|
|
|
|
OR LIEF_LSAN
|
|
|
|
OR LIEF_TSAN
|
|
|
|
OR LIEF_USAN)
|
2018-07-27 10:27:20 +02:00
|
|
|
target_compile_options(LIB_LIEF PRIVATE ${SANITIZER_FLAGS})
|
2017-09-28 08:54:40 +02:00
|
|
|
endif()
|
2017-03-30 16:56:49 +02:00
|
|
|
|
2017-09-28 10:54:37 +02:00
|
|
|
# Fuzzing
|
2020-11-10 17:21:13 +01:00
|
|
|
# ~~~
|
|
|
|
if(LIEF_FUZZING)
|
|
|
|
set_property(
|
|
|
|
TARGET LIB_LIEF
|
|
|
|
APPEND
|
|
|
|
PROPERTY LINK_FLAGS ${FUZZING_LINKER_FLAGS})
|
2017-09-28 10:54:37 +02:00
|
|
|
|
2018-07-27 10:27:20 +02:00
|
|
|
target_compile_options(LIB_LIEF PRIVATE ${FUZZING_FLAGS})
|
2017-09-28 10:54:37 +02:00
|
|
|
|
2018-07-27 10:27:20 +02:00
|
|
|
target_link_libraries(LIB_LIEF asan pthread)
|
2017-09-28 10:54:37 +02:00
|
|
|
|
2018-07-27 10:27:20 +02:00
|
|
|
add_dependencies(LIB_LIEF lief_libfuzzer)
|
2017-09-28 10:54:37 +02:00
|
|
|
endif()
|
|
|
|
|
2018-03-13 16:49:02 +01:00
|
|
|
# Compile Flags
|
|
|
|
# =============
|
|
|
|
include(LIEFCompilerFlags)
|
2017-03-30 16:56:49 +02:00
|
|
|
|
2018-03-28 07:29:05 +02:00
|
|
|
# Profiling flags
|
|
|
|
# ---------------
|
2020-11-10 17:21:13 +01:00
|
|
|
if(LIEF_PROFILING)
|
2018-03-28 07:29:05 +02:00
|
|
|
set(PROFILING_FLAGS
|
2020-11-10 17:21:13 +01:00
|
|
|
-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc
|
|
|
|
-fno-builtin-free -fno-omit-frame-pointer -g)
|
2018-07-27 10:27:20 +02:00
|
|
|
target_compile_options(LIB_LIEF PUBLIC ${PROFILING_FLAGS})
|
2018-03-28 07:29:05 +02:00
|
|
|
|
|
|
|
add_executable(elf_profiler profiling/elf_profiler.cpp)
|
|
|
|
target_compile_options(elf_profiler PUBLIC ${PROFILING_FLAGS})
|
2018-07-27 10:27:20 +02:00
|
|
|
target_link_libraries(elf_profiler PRIVATE LIB_LIEF)
|
2018-03-28 07:29:05 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Coverage flags
|
|
|
|
# --------------
|
2017-03-30 16:56:49 +02:00
|
|
|
if(LIEF_COVERAGE)
|
2020-11-10 17:21:13 +01:00
|
|
|
target_compile_options(LIB_LIEF PRIVATE -g -O0 --coverage -fprofile-arcs
|
|
|
|
-ftest-coverage)
|
2018-07-27 10:27:20 +02:00
|
|
|
target_link_libraries(LIB_LIEF gcov)
|
2017-03-30 16:56:49 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
if(MSVC)
|
|
|
|
string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type)
|
|
|
|
if(build_type STREQUAL "debug")
|
|
|
|
set(CRT_OUTPUT_SUFFIX ${LIEF_USE_CRT_DEBUG})
|
|
|
|
else()
|
|
|
|
set(CRT_OUTPUT_SUFFIX ${LIEF_USE_CRT_RELEASE})
|
|
|
|
endif()
|
|
|
|
set_target_properties(LIB_LIEF PROPERTIES OUTPUT_NAME LIEF${CRT_OUTPUT_SUFFIX}
|
|
|
|
CLEAN_DIRECT_OUTPUT 1)
|
2020-11-05 09:37:16 -03:00
|
|
|
else()
|
2020-11-10 17:21:13 +01:00
|
|
|
set_target_properties(LIB_LIEF PROPERTIES OUTPUT_NAME LIEF CLEAN_DIRECT_OUTPUT
|
|
|
|
1)
|
2020-11-05 09:37:16 -03:00
|
|
|
endif()
|
2017-03-30 16:56:49 +02:00
|
|
|
|
|
|
|
# Set a default build type if none was specified
|
|
|
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
|
|
|
message(STATUS "Setting build type to 'Release' as none was specified.")
|
2020-11-10 17:21:13 +01:00
|
|
|
set(CMAKE_BUILD_TYPE
|
|
|
|
Release
|
|
|
|
CACHE STRING "Choose the type of build." FORCE)
|
2017-03-30 16:56:49 +02:00
|
|
|
# Set the possible values of build type for cmake-gui
|
|
|
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
|
2020-11-10 17:21:13 +01:00
|
|
|
"MinSizeRel" "RelWithDebInfo")
|
2017-03-30 16:56:49 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
message(STATUS "Configuration Types: ${CMAKE_CONFIGURATION_TYPES}")
|
|
|
|
message(STATUS "Build Types: ${CMAKE_BUILD_TYPE}")
|
|
|
|
|
|
|
|
if(APPLE)
|
2018-07-27 10:27:20 +02:00
|
|
|
set_target_properties(LIB_LIEF PROPERTIES MACOSX_RPATH ".")
|
2017-03-30 16:56:49 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# API
|
2020-11-10 17:21:13 +01:00
|
|
|
# ======================
|
2018-03-13 16:49:02 +01:00
|
|
|
include(LIEFApi)
|
2017-03-30 16:56:49 +02:00
|
|
|
|
|
|
|
# Examples
|
2020-11-10 17:21:13 +01:00
|
|
|
# ======================
|
2017-03-30 16:56:49 +02:00
|
|
|
if(LIEF_EXAMPLES)
|
2017-07-19 15:46:37 +02:00
|
|
|
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/examples")
|
2017-03-30 16:56:49 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Tests
|
2020-11-10 17:21:13 +01:00
|
|
|
# ======================
|
2021-01-05 19:26:10 +01:00
|
|
|
|
2017-03-30 16:56:49 +02:00
|
|
|
if(LIEF_TESTS)
|
2017-07-18 17:13:18 +02:00
|
|
|
enable_testing()
|
2017-04-05 15:33:18 +02:00
|
|
|
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/tests")
|
2017-03-30 16:56:49 +02:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Documentation
|
2020-11-10 17:21:13 +01:00
|
|
|
# ======================
|
|
|
|
if(LIEF_DOC)
|
2017-03-30 16:56:49 +02:00
|
|
|
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/doc)
|
|
|
|
endif()
|
|
|
|
|
2020-11-26 13:17:50 -05:00
|
|
|
# Find Package Config
|
|
|
|
# ======================
|
|
|
|
configure_package_config_file(
|
|
|
|
LIEFConfig.cmake.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/LIEFConfig.cmake
|
|
|
|
INSTALL_DESTINATION share/LIEF/cmake)
|
|
|
|
|
|
|
|
write_basic_package_version_file(
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/LIEFConfigVersion.cmake
|
|
|
|
VERSION ${PROJECT_VERSION}
|
|
|
|
COMPATIBILITY AnyNewerVersion)
|
|
|
|
|
2021-01-03 17:52:44 +01:00
|
|
|
# Post-build operations
|
|
|
|
# ======================
|
|
|
|
if (BUILD_SHARED_LIBS AND CMAKE_BUILD_TYPE MATCHES "Release")
|
|
|
|
if (UNIX AND NOT APPLE)
|
|
|
|
add_custom_command(
|
|
|
|
TARGET LIB_LIEF
|
|
|
|
COMMENT "Strip LIEF shared library"
|
|
|
|
POST_BUILD
|
|
|
|
COMMAND ${CMAKE_STRIP} --strip-all $<TARGET_FILE:LIB_LIEF>
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (APPLE)
|
|
|
|
add_custom_command(
|
|
|
|
TARGET LIB_LIEF
|
|
|
|
COMMENT "Strip LIEF shared library"
|
|
|
|
POST_BUILD
|
|
|
|
COMMAND ${CMAKE_STRIP} -x -S $<TARGET_FILE:LIB_LIEF>
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2017-03-30 16:56:49 +02:00
|
|
|
# Install Prefix
|
2020-11-10 17:21:13 +01:00
|
|
|
# ======================
|
2017-03-30 16:56:49 +02:00
|
|
|
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND UNIX)
|
2020-11-10 17:21:13 +01:00
|
|
|
if(UNIX AND NOT APPLE)
|
|
|
|
set(CMAKE_INSTALL_PREFIX
|
|
|
|
"/usr"
|
|
|
|
CACHE PATH "Install path prefix prepended on to install directories."
|
|
|
|
FORCE)
|
|
|
|
elseif(APPLE)
|
|
|
|
set(CMAKE_INSTALL_PREFIX
|
|
|
|
"/usr/local"
|
|
|
|
CACHE PATH "" FORCE)
|
2017-03-30 16:56:49 +02:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Installation
|
2020-11-10 17:21:13 +01:00
|
|
|
# ======================
|
2017-03-30 16:56:49 +02:00
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
install(
|
|
|
|
TARGETS LIB_LIEF
|
|
|
|
ARCHIVE DESTINATION lib
|
|
|
|
LIBRARY DESTINATION lib
|
|
|
|
RUNTIME DESTINATION lib COMPONENT libraries)
|
2017-03-30 16:56:49 +02:00
|
|
|
|
|
|
|
install(
|
|
|
|
DIRECTORY ${LIEF_PUBLIC_INCLUDE_DIR}
|
|
|
|
DESTINATION include
|
|
|
|
COMPONENT headers
|
2020-11-10 17:21:13 +01:00
|
|
|
FILES_MATCHING
|
|
|
|
REGEX "(.*).(hpp|h|def)$")
|
2017-03-30 16:56:49 +02:00
|
|
|
|
2017-07-19 15:46:37 +02:00
|
|
|
install(
|
|
|
|
FILES ${CMAKE_CURRENT_SOURCE_DIR}/scripts/FindLIEF.cmake
|
|
|
|
DESTINATION share/LIEF/cmake
|
2020-11-10 17:21:13 +01:00
|
|
|
COMPONENT CMakeScripts)
|
2017-07-19 15:46:37 +02:00
|
|
|
|
2020-11-26 13:17:50 -05:00
|
|
|
install(
|
|
|
|
FILES ${CMAKE_CURRENT_BINARY_DIR}/LIEFConfig.cmake
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/LIEFConfigVersion.cmake
|
|
|
|
DESTINATION share/LIEF/cmake
|
|
|
|
COMPONENT config)
|
|
|
|
|
2020-08-26 08:16:21 -05:00
|
|
|
install(
|
2021-01-05 19:26:10 +01:00
|
|
|
FILES ${CMAKE_BINARY_DIR}/LIEF.pc
|
2020-08-26 08:16:21 -05:00
|
|
|
DESTINATION lib/pkgconfig
|
2020-11-10 17:21:13 +01:00
|
|
|
COMPONENT libraries)
|
2020-08-26 08:16:21 -05:00
|
|
|
|
2020-11-10 17:21:13 +01:00
|
|
|
export(TARGETS LIB_LIEF FILE LIEFExport.cmake)
|
2019-02-18 17:23:33 +01:00
|
|
|
|
2017-03-30 16:56:49 +02:00
|
|
|
# Package
|
2020-11-10 17:21:13 +01:00
|
|
|
# ======================
|
2017-04-05 15:33:18 +02:00
|
|
|
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/package")
|