Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add x86HotpatchDetour #204

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 30 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ if(POLYHOOK_FEATURE_DETOURS AND NOT POLYHOOK_USE_EXTERNAL_ASMTK)
if(NOT POLYHOOK_USE_EXTERNAL_ASMJIT)
set(ASMJIT_DIR "${PROJECT_SOURCE_DIR}/asmjit")
endif()

# asmjit and asmtk do not use `option`
if(POLYHOOK_BUILD_SHARED_ASMTK)
set(ASMTK_STATIC OFF CACHE BOOL "")
set(ASMJIT_STATIC OFF CACHE BOOL "")
set(ASMTK_STATIC OFF)
set(ASMJIT_STATIC OFF)
else()
set(ASMTK_STATIC ON CACHE BOOL "")
set(ASMJIT_STATIC ON CACHE BOOL "")
set(ASMTK_STATIC ON)
set(ASMJIT_STATIC ON)
endif()

add_subdirectory(asmtk)
Expand All @@ -88,10 +88,11 @@ endif()
if(POLYHOOK_FEATURE_INLINENTD AND NOT POLYHOOK_USE_EXTERNAL_ASMJIT)
# Avoid including asmjit again if it was already included
if(NOT TARGET asmjit)
# asmjit doesn't use `option`
if(POLYHOOK_BUILD_SHARED_ASMJIT)
set(ASMJIT_STATIC OFF CACHE BOOL "")
set(ASMJIT_STATIC OFF)
else()
set(ASMJIT_STATIC ON CACHE BOOL "")
set(ASMJIT_STATIC ON)
endif()

add_subdirectory(asmjit)
Expand All @@ -103,13 +104,23 @@ endif()
# Zydis
#

if(NOT POLYHOOK_USE_EXTERNAL_ZYDIS)
set(ZYDIS_BUILD_SHARED_LIB ${POLYHOOK_BUILD_SHARED_ZYDIS} CACHE BOOL "")
set(ZYCORE_BUILD_SHARED_LIB ${POLYHOOK_BUILD_SHARED_ZYDIS} CACHE BOOL "")
set(ZYDIS_BUILD_TOOLS OFF CACHE BOOL "")
set(ZYDIS_BUILD_EXAMPLES OFF CACHE BOOL "")
function(set_zycore_options)
set(ZYCORE_BUILD_SHARED_LIB ${POLYHOOK_BUILD_SHARED_ZYDIS} CACHE BOOL "" FORCE)
set(ZYCORE_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(ZYCORE_BUILD_TESTS OFF CACHE BOOL "" FORCE)
endfunction()

function(set_zydis_options)
set(ZYDIS_BUILD_SHARED_LIB ${POLYHOOK_BUILD_SHARED_ZYDIS} CACHE BOOL "" FORCE)
set(ZYDIS_BUILD_TOOLS OFF CACHE BOOL "" FORCE)
set(ZYDIS_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(ZYDIS_BUILD_DOXYGEN OFF CACHE BOOL "" FORCE)
endfunction()

if(NOT POLYHOOK_USE_EXTERNAL_ZYDIS)
set_zycore_options()
add_subdirectory(zydis/dependencies/zycore)
set_zydis_options()
add_subdirectory(zydis)

if(MSVC)
Expand Down Expand Up @@ -263,14 +274,16 @@ if(POLYHOOK_FEATURE_DETOURS)
${PROJECT_SOURCE_DIR}/polyhook2/Detour/ADetour.hpp
${PROJECT_SOURCE_DIR}/polyhook2/Detour/NatDetour.hpp
${PROJECT_SOURCE_DIR}/polyhook2/Detour/x64Detour.hpp
${PROJECT_SOURCE_DIR}/polyhook2/Detour/x86Detour.hpp)
${PROJECT_SOURCE_DIR}/polyhook2/Detour/x86Detour.hpp
${PROJECT_SOURCE_DIR}/polyhook2/Detour/x86HotpatchDetour.hpp)

install(FILES ${POLYHOOK_DETOUR_HEADERS} DESTINATION include/polyhook2/Detour)

target_sources(${PROJECT_NAME} PRIVATE
${PROJECT_SOURCE_DIR}/sources/ADetour.cpp
${PROJECT_SOURCE_DIR}/sources/x64Detour.cpp
${PROJECT_SOURCE_DIR}/sources/x86Detour.cpp)
${PROJECT_SOURCE_DIR}/sources/x86Detour.cpp
${PROJECT_SOURCE_DIR}/sources/x86HotpatchDetour.cpp)

# only build tests if making exe
if(NOT POLYHOOK_BUILD_DLL)
Expand All @@ -280,7 +293,9 @@ if(POLYHOOK_FEATURE_DETOURS)
${PROJECT_SOURCE_DIR}/UnitTests/${POLYHOOK_OS}/TestDetourTranslationx64.cpp
${PROJECT_SOURCE_DIR}/UnitTests/${POLYHOOK_OS}/TestDetourSchemex64.cpp)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) #32-bit
target_sources(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/UnitTests/${POLYHOOK_OS}/TestDetourx86.cpp)
target_sources(${PROJECT_NAME} PRIVATE
${PROJECT_SOURCE_DIR}/UnitTests/${POLYHOOK_OS}/TestDetourx86.cpp
${PROJECT_SOURCE_DIR}/UnitTests/${POLYHOOK_OS}/TestDetourx86hotpatch.cpp)
endif()
endif()
endif()
Expand Down
Loading