-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
156 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,171 +1,116 @@ | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -1,6 +1,6 @@ | ||
cmake_minimum_required(VERSION 3.22.1) | ||
|
||
-include(ExternalProject) | ||
+ | ||
|
||
project(libmem | ||
LANGUAGES | ||
@@ -23,13 +23,23 @@ option(LIBMEM_DEEP_TESTS | ||
OFF | ||
) | ||
|
||
+set(CMAKE_CXX_STANDARD 17) | ||
+set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
+set(targets_export_name libmem-target) | ||
+ | ||
+if (MSVC AND NOT(BUILD_SHARED_LIBS)) | ||
+ add_definitions(/DLM_EXPORT) | ||
+elseif(NOT(MSVC) AND BUILD_SHARED_LIBS) | ||
+ add_definitions(-DLM_EXPORT) | ||
+endif() | ||
+if(0) | ||
option(LIBMEM_BUILD_STATIC | ||
"Build a static library" | ||
OFF | ||
) | ||
- | ||
+endif() | ||
set(LIBMEM_ARCH ${CMAKE_SYSTEM_PROCESSOR} CACHE STRING "Force a specific architecture") | ||
- | ||
+if(0) | ||
message(STATUS | ||
"[*] Architecture: ${LIBMEM_ARCH}" | ||
) | ||
@@ -65,13 +75,17 @@ add_library(capstone STATIC IMPORTED) | ||
set_target_properties(capstone PROPERTIES IMPORTED_LOCATION ${CAPSTONE_IMPORT_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}capstone${CMAKE_STATIC_LIBRARY_SUFFIX}) | ||
add_library(keystone STATIC IMPORTED) | ||
set_target_properties(keystone PROPERTIES IMPORTED_LOCATION ${KEYSTONE_IMPORT_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}keystone${CMAKE_STATIC_LIBRARY_SUFFIX}) | ||
+endif() | ||
+find_package(PkgConfig) | ||
+pkg_check_modules(keystone REQUIRED keystone) | ||
+find_package(capstone CONFIG REQUIRED) | ||
# End of external dependencies | ||
- | ||
set(LIBMEM_DIR "${PROJECT_SOURCE_DIR}") | ||
+set(LLVM_DEM_DIR "${LIBMEM_DIR}/external/llvm") | ||
set(LIBMEM_INC "${LIBMEM_DIR}/include") | ||
set(INTERNAL_DIR "${LIBMEM_DIR}/internal") | ||
set(COMMON_DIR "${LIBMEM_DIR}/src/common") | ||
- | ||
+file(GLOB_RECURSE LLVM_DEM_SRC "${LLVM_DEM_DIR}/lib/*.cpp") | ||
if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN) | ||
file(GLOB_RECURSE LIBMEM_SRC "${LIBMEM_DIR}/src/win/*.c" "${LIBMEM_DIR}/src/common/*.c" "${LIBMEM_DIR}/src/common/*.cpp" "${INTERNAL_DIR}/winutils/*.c" "${INTERNAL_DIR}/demangler/*.cpp") | ||
elseif(${CMAKE_SYSTEM_NAME} STREQUAL Linux) | ||
@@ -89,16 +103,13 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD) | ||
endif() | ||
file(GLOB LIBMEM_SRC ${LIBMEM_ARCH_SRC} "${LIBMEM_DIR}/src/freebsd/*.c" "${LIBMEM_DIR}/src/freebsd/ptrace/*.c" "${LIBMEM_DIR}/src/common/*.c" "${LIBMEM_DIR}/src/common/*.cpp" "${INTERNAL_DIR}/posixutils/*.c" "${INTERNAL_DIR}/elfutils/*.c" "${INTERNAL_DIR}/demangler/*.cpp") | ||
endif() | ||
-set(LIBMEM_DEPS | ||
- capstone | ||
- keystone | ||
- llvm | ||
-) | ||
|
||
-if (LIBMEM_BUILD_STATIC) | ||
+file(GLOB_RECURSE LIBMEM_PUBLIC_HEADERS "${LIBMEM_INC}/libmem/*.h" "${LIBMEM_INC}/libmem/*.hpp") | ||
+ | ||
+if (0) | ||
add_library(libmem STATIC ${LIBMEM_SRC}) | ||
else() | ||
- add_library(libmem SHARED ${LIBMEM_SRC}) | ||
+ add_library(libmem ${LIBMEM_SRC} ${LLVM_DEM_SRC}) | ||
endif() | ||
target_include_directories(libmem PRIVATE "${LIBMEM_DIR}/src" "${INTERNAL_DIR}" "${COMMON_DIR}") | ||
|
||
@@ -109,17 +120,16 @@ include_directories(${PROJECT_SOURCE_DIR} | ||
${LLVM_INC} | ||
) | ||
|
||
-if (LIBMEM_BUILD_TESTS) | ||
+if (0) | ||
set(TESTS_DIR "${PROJECT_SOURCE_DIR}/tests") | ||
add_subdirectory(${TESTS_DIR}) | ||
endif() | ||
|
||
-set_target_properties(libmem PROPERTIES POSITION_INDEPENDENT_CODE True INCLUDES ${LIBMEM_INC}) | ||
+set_target_properties(libmem PROPERTIES POSITION_INDEPENDENT_CODE True PUBLIC_HEADER "${LIBMEM_PUBLIC_HEADERS}") | ||
+target_compile_features(libmem PUBLIC cxx_std_17) | ||
+target_compile_definitions(libmem PUBLIC LM_EXPORT) | ||
+target_include_directories(libmem PRIVATE "${LLVM_DEM_DIR}/include" "${LIBMEM_DIR}/src" "${INTERNAL_DIR}" "${COMMON_DIR}" "${LIBMEM_INC}" INTERFACE $<INSTALL_INTERFACE:include>) | ||
target_compile_definitions(libmem PUBLIC LM_EXPORT) | ||
-add_dependencies(libmem | ||
- capstone-engine | ||
- keystone-engine | ||
-) | ||
|
||
if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN) | ||
set(LIBMEM_DEPS | ||
@@ -151,8 +161,8 @@ else() | ||
message(FATAL_ERROR "[!] Unsupported platform") | ||
endif() | ||
|
||
-target_link_libraries(libmem ${LIBMEM_DEPS}) | ||
-if(LIBMEM_BUILD_STATIC) | ||
+target_link_libraries(libmem PRIVATE ${LIBMEM_DEPS} ${keystone_LINK_LIBRARIES} capstone::capstone) | ||
+if(0) | ||
# Create a bundled static library containing all dependencies (to mimic the shared library behavior) | ||
set_target_properties(libmem PROPERTIES OUTPUT_NAME "libmem_partial") | ||
set(libmem_bundle_files "$<TARGET_FILE:libmem>") | ||
@@ -193,7 +203,7 @@ if(LIBMEM_BUILD_STATIC) | ||
endif() | ||
endif() | ||
|
||
-if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN) | ||
+if(0) | ||
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN) | ||
cmake_path(SET CMAKE_INSTALL_PREFIX "$ENV{ProgramFiles}") | ||
else() | ||
@@ -202,14 +212,44 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN | ||
endif() | ||
set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/libmem") | ||
execute_process(COMMAND mkdir "${CMAKE_INSTALL_PREFIX}") | ||
-else() | ||
+elseif(0) | ||
set(CMAKE_INSTALL_PREFIX "/usr") | ||
endif() | ||
- | ||
install(TARGETS libmem | ||
- LIBRARY DESTINATION lib) | ||
+ EXPORT ${targets_export_name} | ||
+ LIBRARY DESTINATION lib | ||
+ ARCHIVE DESTINATION lib | ||
+ PUBLIC_HEADER DESTINATION include/libmem | ||
+ RUNTIME DESTINATION bin | ||
+) | ||
|
||
-install(TARGETS libmem | ||
- RUNTIME DESTINATION lib) | ||
+# Install the export file, which allows users to find the target | ||
+install( | ||
+ EXPORT ${targets_export_name} | ||
+ NAMESPACE libmem:: | ||
+ FILE ${targets_export_name}.cmake | ||
+ DESTINATION share/libmem | ||
+) | ||
|
||
-install(DIRECTORY ${LIBMEM_INC}/libmem DESTINATION include) | ||
+# Config and version files for the package | ||
+include(CMakePackageConfigHelpers) | ||
+ | ||
+configure_package_config_file( | ||
+ ${CMAKE_CURRENT_SOURCE_DIR}/libmem-config.cmake.in | ||
+ ${CMAKE_CURRENT_BINARY_DIR}/libmem-config.cmake | ||
+ INSTALL_DESTINATION share/libmem | ||
+) | ||
+ | ||
+write_basic_package_version_file( | ||
+ "${CMAKE_CURRENT_BINARY_DIR}/libmem-config-version.cmake" | ||
+ VERSION 5.0.2 | ||
+ COMPATIBILITY SameMajorVersion | ||
+) | ||
+ | ||
+# Install the config and version files | ||
+install( | ||
+ FILES | ||
+ ${CMAKE_CURRENT_BINARY_DIR}/libmem-config.cmake | ||
+ ${CMAKE_CURRENT_BINARY_DIR}/libmem-config-version.cmake | ||
+ DESTINATION share/libmem | ||
+) | ||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
index 534057a..049805a 100644 | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -1,6 +1,6 @@ | ||
cmake_minimum_required(VERSION 3.22.1) | ||
|
||
-include(ExternalProject) | ||
+set(CMAKE_CXX_STANDARD 17) | ||
|
||
project(libmem | ||
LANGUAGES | ||
@@ -49,6 +49,7 @@ message(STATUS | ||
message(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}") | ||
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") | ||
|
||
+if(0) | ||
# External dependencies | ||
set(EXTERNAL_DEPENDENCIES_DIR "${PROJECT_SOURCE_DIR}/external") | ||
set(CAPSTONE_DIR "${EXTERNAL_DEPENDENCIES_DIR}/capstone") | ||
@@ -67,6 +68,7 @@ add_library(keystone STATIC IMPORTED) | ||
set_target_properties(keystone PROPERTIES IMPORTED_LOCATION ${KEYSTONE_IMPORT_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}keystone${CMAKE_STATIC_LIBRARY_SUFFIX}) | ||
# End of external dependencies | ||
|
||
+endif() | ||
set(LIBMEM_DIR "${PROJECT_SOURCE_DIR}") | ||
set(LIBMEM_INC "${LIBMEM_DIR}/include") | ||
set(INTERNAL_DIR "${LIBMEM_DIR}/internal") | ||
@@ -89,24 +91,21 @@ elseif(${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD) | ||
endif() | ||
file(GLOB LIBMEM_SRC ${LIBMEM_ARCH_SRC} "${LIBMEM_DIR}/src/freebsd/*.c" "${LIBMEM_DIR}/src/freebsd/ptrace/*.c" "${LIBMEM_DIR}/src/common/*.c" "${LIBMEM_DIR}/src/common/*.cpp" "${INTERNAL_DIR}/posixutils/*.c" "${INTERNAL_DIR}/elfutils/*.c" "${INTERNAL_DIR}/demangler/*.cpp") | ||
endif() | ||
+find_package(PkgConfig) | ||
+pkg_check_modules(keystone REQUIRED keystone) | ||
+find_package(capstone CONFIG REQUIRED) | ||
set(LIBMEM_DEPS | ||
- capstone | ||
- keystone | ||
- llvm | ||
+ capstone::capstone | ||
+ "${keystone_LINK_LIBRARIES}" | ||
) | ||
- | ||
-if (LIBMEM_BUILD_STATIC) | ||
- add_library(libmem STATIC ${LIBMEM_SRC}) | ||
-else() | ||
- add_library(libmem SHARED ${LIBMEM_SRC}) | ||
-endif() | ||
+file(GLOB_RECURSE LLVM_DEM_SRC "${LIBMEM_DIR}/external/llvm/lib/*.cpp") | ||
+add_library(libmem ${LIBMEM_SRC} ${LLVM_DEM_SRC}) | ||
target_include_directories(libmem PRIVATE "${LIBMEM_DIR}/src" "${INTERNAL_DIR}" "${COMMON_DIR}") | ||
|
||
include_directories(${PROJECT_SOURCE_DIR} | ||
${LIBMEM_INC} | ||
- ${CAPSTONE_INC} | ||
- ${KEYSTONE_INC} | ||
- ${LLVM_INC} | ||
+ "${keystone_INCLUDE_DIRS}" | ||
+ "${LIBMEM_DIR}/external/llvm/include" | ||
) | ||
|
||
if (LIBMEM_BUILD_TESTS) | ||
@@ -116,10 +115,6 @@ endif() | ||
|
||
set_target_properties(libmem PROPERTIES POSITION_INDEPENDENT_CODE True INCLUDES ${LIBMEM_INC}) | ||
target_compile_definitions(libmem PUBLIC LM_EXPORT) | ||
-add_dependencies(libmem | ||
- capstone-engine | ||
- keystone-engine | ||
-) | ||
|
||
if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN) | ||
set(LIBMEM_DEPS | ||
@@ -152,7 +147,7 @@ else() | ||
endif() | ||
|
||
target_link_libraries(libmem ${LIBMEM_DEPS}) | ||
-if(LIBMEM_BUILD_STATIC) | ||
+if(0) | ||
# Create a bundled static library containing all dependencies (to mimic the shared library behavior) | ||
set_target_properties(libmem PROPERTIES OUTPUT_NAME "libmem_partial") | ||
set(libmem_bundle_files "$<TARGET_FILE:libmem>") | ||
@@ -193,7 +188,7 @@ if(LIBMEM_BUILD_STATIC) | ||
endif() | ||
endif() | ||
|
||
-if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN) | ||
+if(0) | ||
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN) | ||
cmake_path(SET CMAKE_INSTALL_PREFIX "$ENV{ProgramFiles}") | ||
else() | ||
@@ -202,14 +197,17 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN | ||
endif() | ||
set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/libmem") | ||
execute_process(COMMAND mkdir "${CMAKE_INSTALL_PREFIX}") | ||
-else() | ||
set(CMAKE_INSTALL_PREFIX "/usr") | ||
endif() | ||
|
||
-install(TARGETS libmem | ||
- LIBRARY DESTINATION lib) | ||
- | ||
-install(TARGETS libmem | ||
- RUNTIME DESTINATION lib) | ||
- | ||
install(DIRECTORY ${LIBMEM_INC}/libmem DESTINATION include) | ||
+install(TARGETS libmem EXPORT libmem-target | ||
+ LIBRARY DESTINATION lib | ||
+ ARCHIVE DESTINATION lib | ||
+ RUNTIME DESTINATION bin | ||
+) | ||
+install(EXPORT libmem-target NAMESPACE libmem:: DESTINATION "share/libmem") | ||
+include(CMakePackageConfigHelpers) | ||
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libmem-config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/libmem-config.cmake" @ONLY) | ||
+write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/libmem-config-version.cmake" VERSION 5.0.4 COMPATIBILITY SameMajorVersion) | ||
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libmem-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/libmem-config-version.cmake" DESTINATION "share/libmem") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
@PACKAGE_INIT@ | ||
|
||
include(CMakeFindDependencyMacro) | ||
find_dependency(capstone CONFIG) | ||
|
||
include("${CMAKE_CURRENT_LIST_DIR}/libmem-target.cmake") | ||
check_required_components(libmem) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,22 @@ | ||
vcpkg_download_distfile( | ||
EXPORT_SURFACE_PATCH | ||
URLS https://github.com/rdbo/libmem/commit/04830fb5a6dd6c81843c1b54bd61dac5bd202b9a.patch?full_index=1 | ||
FILENAME libmem-export-surface-04830fb5a6dd6c81843c1b54bd61dac5bd202b9a.patch | ||
SHA512 9060f86514f866a24a61b6cd51ee524f169b23781969b5f47f6fa5d2144369e7648658848fb2e00e9f0aed72119c4ab20842ba5afe9b0a485eea15ff63934596 | ||
) | ||
|
||
vcpkg_from_github( | ||
OUT_SOURCE_PATH SOURCE_PATH | ||
REPO rdbo/libmem | ||
REF ${VERSION} | ||
SHA512 d7c5a1a42d65a00ed3aa8ba8f6974650801d3436ae90e072fea29d4dcb32a3963e2610c89a16b87d94a9613c8f2f0e8deb83b673a1771a9cd1eb716a56106a16 | ||
REF "${VERSION}" | ||
SHA512 a3245fedb0447133a674dc39b3f9dc0bce86cb8ed775cb50bc3b58ee410632653cfc340d17c2ca0a914e51ade9b62f393e23feb5f3d0459b1a1a8ce690a0d025 | ||
HEAD_REF master | ||
PATCHES | ||
0001-CMakeLists.patch | ||
"${EXPORT_SURFACE_PATCH}" | ||
) | ||
|
||
message(WARNING "Removing PreLoad.cmake") | ||
file(REMOVE "${SOURCE_PATH}/PreLoad.cmake") | ||
|
||
file(MAKE_DIRECTORY "${SOURCE_PATH}/cmake") | ||
|
||
file(COPY "${CMAKE_CURRENT_LIST_DIR}/libmem-config.cmake.in" | ||
DESTINATION "${SOURCE_PATH}" | ||
) | ||
|
||
file(COPY "${CMAKE_CURRENT_LIST_DIR}/libmem-config.cmake.in" DESTINATION "${SOURCE_PATH}") | ||
vcpkg_find_acquire_program(PKGCONFIG) | ||
vcpkg_cmake_configure( | ||
SOURCE_PATH "${SOURCE_PATH}" | ||
OPTIONS | ||
"-DPKG_CONFIG_EXECUTABLE=${PKGCONFIG}" | ||
) | ||
|
||
vcpkg_cmake_install() | ||
vcpkg_cmake_config_fixup() | ||
vcpkg_copy_pdbs() | ||
|
||
file(REMOVE_RECURSE | ||
"${CURRENT_PACKAGES_DIR}/debug/include" | ||
"${CURRENT_PACKAGES_DIR}/debug/share" | ||
) | ||
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") | ||
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include" "${CURRENT_PACKAGES_DIR}/debug/share") | ||
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
set(VCPKG_POLICY_EMPTY_PACKAGE enabled) | ||
|
||
vcpkg_cmake_configure(SOURCE_PATH "${CURRENT_PORT_DIR}/project") | ||
vcpkg_cmake_build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
project(libmem-test) | ||
set(CMAKE_CXX_STANDARD 17) | ||
find_package(libmem CONFIG REQUIRED) | ||
add_executable(main main.cpp) | ||
target_link_libraries(main PRIVATE libmem::libmem) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <libmem/libmem.h> | ||
int main() | ||
{ | ||
lm_module_t moduled; | ||
LM_FindModule("user32.dll", &moduled); | ||
return 0; | ||
} |
Oops, something went wrong.