From 61516701398f95dae0bf0959ddb35e9ddbcfdbe8 Mon Sep 17 00:00:00 2001 From: Thierry Date: Sat, 1 Dec 2018 17:21:21 -0500 Subject: [PATCH 1/9] Add initial CMake files for building the detours lib Doesn't yet support building the corehook DLL but that is a work-in-progress. --- CMakeLists.txt | 15 +++++++++++++++ dll/CMakeLists.txt | 9 +++++++++ src/CMakeLists.txt | 31 +++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 dll/CMakeLists.txt create mode 100644 src/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..d2ba3a5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.2) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + +set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}) + +set(COREHOOK_INSTALL_INCLUDE_DIR ${PROJECT_SOURCE_DIR}) +set(COREHOOK_INSTALL_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin) +set(COREHOOK_INSTALL_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/lib) + + +include_directories(${COREHOOK_INSTALL_INCLUDE_DIR}) + +add_subdirectory(src) \ No newline at end of file diff --git a/dll/CMakeLists.txt b/dll/CMakeLists.txt new file mode 100644 index 0000000..65caac1 --- /dev/null +++ b/dll/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.2) +project(corehook) + +add_subdirectory(../src) +set(SOURCE_FILES main.cpp) + +add_executable(corehook ${SOURCE_FILES}) +target_link_libraries(corehook division) +install(TARGETS corehook DESTINATION ${DIVISIBLE_INSTALL_BIN_DIR}) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..4b3af81 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,31 @@ +cmake_minimum_required(VERSION 3.2) + +project(detours) +set(TARGET detours) + +enable_language(ASM_MASM) + if (CMAKE_ASM_MASM_COMPILER_WORKS) + if (NOT CMAKE_CL_64) + set(CMAKE_ASM_MASM_FLAGS ${CMAKE_ASM_MASM_FLAGS} /safeseh) + endif() + set_property(SOURCE trampolinex64.asm PROPERTY LANGUAGE ASM_MASM) + else() + message(WARNING "Could not find working MASM assebler\n${ASM_FAILURE_MSG}") + endif() +set(SOURCE_FILES + barrier.cpp + creatwth.cpp + detours.cpp + disasm.cpp + disolarm.cpp + disolarm64.cpp + disolia64.cpp + disolx64.cpp + disolx86.cpp + image.cpp + modules.cpp + ) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +add_library(detours STATIC ${SOURCE_FILES}) +install(TARGETS detours DESTINATION ${COREHOOK_INSTALL_BIN_DIR}) \ No newline at end of file From dafcbda258a266ca5480abae74f238c8d992b20e Mon Sep 17 00:00:00 2001 From: Thierry Date: Sat, 1 Dec 2018 18:21:35 -0500 Subject: [PATCH 2/9] Update cmake build to output corehook DLL Add support for building the corehook dll and the detours library at the same time --- CMakeLists.txt | 53 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d2ba3a5..3658e9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,58 @@ cmake_minimum_required(VERSION 3.2) -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") - set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}) set(COREHOOK_INSTALL_INCLUDE_DIR ${PROJECT_SOURCE_DIR}) set(COREHOOK_INSTALL_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin) set(COREHOOK_INSTALL_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/lib) - include_directories(${COREHOOK_INSTALL_INCLUDE_DIR}) -add_subdirectory(src) \ No newline at end of file +project(corehook) +set(TARGET detours) + +enable_language(ASM_MASM) +set(SOURCE_ASM + src/trampolinex64.asm + ) + +set(SOURCE_FILES + src/barrier.cpp + src/creatwth.cpp + src/detours.cpp + src/disasm.cpp + src/disolarm.cpp + src/disolarm64.cpp + src/disolia64.cpp + src/disolx64.cpp + src/disolx86.cpp + src/image.cpp + src/modules.cpp + ) + +set(COREHOOK_SOURCES + dll/corehook/corehook.cpp + ) + +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} + src + ) + +add_library(detours STATIC ${SOURCE_FILES} ${SOURCE_ASM}) + +add_library(corehook SHARED ${COREHOOK_SOURCES}) +target_link_libraries(corehook detours aux_ulib) + +if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32") + set_target_properties(corehook PROPERTIES OUTPUT_NAME corehook32) +elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64") + set_target_properties(corehook PROPERTIES OUTPUT_NAME corehook64) +elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "ARM") + set_target_properties(corehook PROPERTIES OUTPUT_NAME corehook32) +elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "ARM64") + set_target_properties(corehook PROPERTIES OUTPUT_NAME corehook64) +endif() + +install(TARGETS detours DESTINATION ${COREHOOK_INSTALL_BIN_DIR}) + From 53c174de0e96a637900b88919c5769a8a73e8353 Mon Sep 17 00:00:00 2001 From: Thierry Date: Sun, 2 Dec 2018 13:33:05 -0500 Subject: [PATCH 3/9] cmake: Add support for building the x86 Win32 corehook DLL --- CMakeLists.txt | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3658e9c..4a66273 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,11 +11,6 @@ include_directories(${COREHOOK_INSTALL_INCLUDE_DIR}) project(corehook) set(TARGET detours) -enable_language(ASM_MASM) -set(SOURCE_ASM - src/trampolinex64.asm - ) - set(SOURCE_FILES src/barrier.cpp src/creatwth.cpp @@ -39,20 +34,35 @@ include_directories( src ) -add_library(detours STATIC ${SOURCE_FILES} ${SOURCE_ASM}) - add_library(corehook SHARED ${COREHOOK_SOURCES}) -target_link_libraries(corehook detours aux_ulib) +enable_language(ASM_MASM) if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32") set_target_properties(corehook PROPERTIES OUTPUT_NAME corehook32) + set_target_properties(corehook PROPERTIES LINK_FLAGS "/SAFESEH:NO") + set(SOURCE_ASM + src/trampolinex86.asm + ) elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64") set_target_properties(corehook PROPERTIES OUTPUT_NAME corehook64) + set(SOURCE_ASM + src/trampolinex64.asm + ) elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "ARM") set_target_properties(corehook PROPERTIES OUTPUT_NAME corehook32) + set(SOURCE_ASM + src/trampolinearm.asm + ) elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "ARM64") - set_target_properties(corehook PROPERTIES OUTPUT_NAME corehook64) + set_target_properties(corehook PROPERTIES OUTPUT_NAME corehook64) + set(SOURCE_ASM + src/trampolinearm64.asm + ) endif() +add_library(detours STATIC ${SOURCE_FILES} ${SOURCE_ASM}) + +target_link_libraries(corehook detours aux_ulib) + install(TARGETS detours DESTINATION ${COREHOOK_INSTALL_BIN_DIR}) From 1d0c18533135621394f0bb81f6d8f4c3df82fedc Mon Sep 17 00:00:00 2001 From: Thierry Date: Sun, 2 Dec 2018 13:49:16 -0500 Subject: [PATCH 4/9] cmake: Add module export definitions to build --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a66273..904c623 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ set(SOURCE_FILES set(COREHOOK_SOURCES dll/corehook/corehook.cpp + dll/corehook/corehook.def ) include_directories( From 6c0e0fa8c2c216dcfd1623249c9a07571c092e99 Mon Sep 17 00:00:00 2001 From: Thierry Date: Sun, 2 Dec 2018 14:14:32 -0500 Subject: [PATCH 5/9] cmake: Update runtime library for the corehook DLL --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 904c623..0db8bf9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.2) set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}) +set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") set(COREHOOK_INSTALL_INCLUDE_DIR ${PROJECT_SOURCE_DIR}) set(COREHOOK_INSTALL_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin) From 0510613630e8e9eb1c967f882c02b836052d1d61 Mon Sep 17 00:00:00 2001 From: Thierry Date: Sun, 2 Dec 2018 14:56:48 -0500 Subject: [PATCH 6/9] cmake: Add Visual Studio 2017 CMake build script --- build/win-vs-2017.cmd | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 build/win-vs-2017.cmd diff --git a/build/win-vs-2017.cmd b/build/win-vs-2017.cmd new file mode 100644 index 0000000..763876b --- /dev/null +++ b/build/win-vs-2017.cmd @@ -0,0 +1,14 @@ +cd ../ +mkdir build32-vs2017 +mkdir build64-vs2017 +cd build32-vs2017 +cmake -G "Visual Studio 15 2017" ../ +cd ../ +cd build64-vs2017 +cmake -G "Visual Studio 15 2017 Win64" ../ +cd ../ +cmake --build build32-vs2017 --config Debug +cmake --build build32-vs2017 --config Release +cmake --build build64-vs2017 --config Debug +cmake --build build64-vs2017 --config Release +cd build \ No newline at end of file From cedd8d3a7567ebe7d09a06f92da2cd209faad505 Mon Sep 17 00:00:00 2001 From: Thierry Date: Sun, 2 Dec 2018 15:28:29 -0500 Subject: [PATCH 7/9] doc: Add CMake build instructions to readme --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c5b8f1d..57e667b 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,10 @@ For [CoreHook](https://github.com/unknownv2/CoreHook), the [Microsoft Detours](h ## Building -Building the DLL requires Visual Studio and there are two options: You can build the DLL by using the `Visual Studio IDE` or `msbuild` within the `Developer Command Prompt`, or `nmake` (it has been tested with `Visual Studio 2017` only). +Building the DLL requires Visual Studio and there are three options: You can build the DLL by using the `Visual Studio IDE` or `msbuild` within the `Developer Command Prompt`, `cmake`, or `nmake` (it has been tested with `Visual Studio 2017` only). ### Visual Studio + You can find the Visual Studio solution inside [the msvc folder](/msvc). You can choose a configuration (**Debug|Release**) and a platform (**X86|X64|ARM|ARM64**) and build. An example for building the X64 `corehook64.dll` in the Release configuration: @@ -32,6 +33,15 @@ nuget restore msvc/corehook.sln msbuild msvc/corehook.sln /p:Configuration=Release /p:Platform=x64 ``` +### CMake + +You can also build the library using CMake. You can run the `build/win-vs-2017.cmd` file to build for the `x86` and `x64` architectures. This also gives you the option to generate and build with an older version of `Visual Studio` such as `VS 2015` or `VS 2013`. + +You can build by running these commands from the root of the repository: +``` +cd scripts +win-vs-2017.cmd +``` ### NMAKE From d0ceb5be0c7f0a4eb9c1949ec5ecc5f2b9a0ae5a Mon Sep 17 00:00:00 2001 From: Thierry Date: Sun, 2 Dec 2018 15:29:37 -0500 Subject: [PATCH 8/9] doc: Fix CMake build instructions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 57e667b..f74edb1 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ You can also build the library using CMake. You can run the `build/win-vs-2017.c You can build by running these commands from the root of the repository: ``` -cd scripts +cd build win-vs-2017.cmd ``` From 5c97c94d3c1264e95ae26e6d1ca07fa5eb2f9052 Mon Sep 17 00:00:00 2001 From: Thierry Date: Sun, 2 Dec 2018 16:00:07 -0500 Subject: [PATCH 9/9] cmake: Remove uneeded cmake build files --- dll/CMakeLists.txt | 9 --------- src/CMakeLists.txt | 31 ------------------------------- 2 files changed, 40 deletions(-) delete mode 100644 dll/CMakeLists.txt delete mode 100644 src/CMakeLists.txt diff --git a/dll/CMakeLists.txt b/dll/CMakeLists.txt deleted file mode 100644 index 65caac1..0000000 --- a/dll/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -cmake_minimum_required(VERSION 3.2) -project(corehook) - -add_subdirectory(../src) -set(SOURCE_FILES main.cpp) - -add_executable(corehook ${SOURCE_FILES}) -target_link_libraries(corehook division) -install(TARGETS corehook DESTINATION ${DIVISIBLE_INSTALL_BIN_DIR}) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index 4b3af81..0000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -cmake_minimum_required(VERSION 3.2) - -project(detours) -set(TARGET detours) - -enable_language(ASM_MASM) - if (CMAKE_ASM_MASM_COMPILER_WORKS) - if (NOT CMAKE_CL_64) - set(CMAKE_ASM_MASM_FLAGS ${CMAKE_ASM_MASM_FLAGS} /safeseh) - endif() - set_property(SOURCE trampolinex64.asm PROPERTY LANGUAGE ASM_MASM) - else() - message(WARNING "Could not find working MASM assebler\n${ASM_FAILURE_MSG}") - endif() -set(SOURCE_FILES - barrier.cpp - creatwth.cpp - detours.cpp - disasm.cpp - disolarm.cpp - disolarm64.cpp - disolia64.cpp - disolx64.cpp - disolx86.cpp - image.cpp - modules.cpp - ) - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -add_library(detours STATIC ${SOURCE_FILES}) -install(TARGETS detours DESTINATION ${COREHOOK_INSTALL_BIN_DIR}) \ No newline at end of file