diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..c9310a2 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "texthook/minhook"] + path = texthook/minhook + url = https://github.com/TsudaKageyu/minhook.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c601c0..6973450 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,11 +18,11 @@ add_compile_options( ) if(${CMAKE_SIZEOF_VOID_P} EQUAL 8) - set(CMAKE_FINAL_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/builds/${CMAKE_BUILD_TYPE}_x64) - link_directories(x64libs) + set(CMAKE_FINAL_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/builds/${CMAKE_BUILD_TYPE}_x64) + link_directories(x64libs) else() - set(CMAKE_FINAL_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/builds/${CMAKE_BUILD_TYPE}_x86) - link_directories(x86libs) + set(CMAKE_FINAL_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/builds/${CMAKE_BUILD_TYPE}_x86) + link_directories(x86libs) endif() set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY $<1:${CMAKE_FINAL_OUTPUT_DIRECTORY}>) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY $<1:${CMAKE_FINAL_OUTPUT_DIRECTORY}>) @@ -44,6 +44,6 @@ add_subdirectory(texthook) add_subdirectory(extensions) add_subdirectory(test) if (DEFINED VERSION) - add_subdirectory(GUI/host) + add_subdirectory(GUI/host) endif() #add_subdirectory(GUI/host) diff --git a/texthook/CMakeLists.txt b/texthook/CMakeLists.txt index 0952dbf..8bfdbcd 100644 --- a/texthook/CMakeLists.txt +++ b/texthook/CMakeLists.txt @@ -1,32 +1,50 @@ -include_directories(. util) +include_directories(. util minhook/include) if(${CMAKE_SIZEOF_VOID_P} EQUAL 8) -set(texthook_src - main.cc - texthook.cc - hookfinder.cc - engine/match.cc - engine/match64.cc - engine/native/pchooks.cc - util/ithsys/ithsys.cc - util/util.cc -) + set(minhook_src + minhook/src/buffer.c + minhook/src/hook.c + minhook/src/trampoline.c + minhook/src/hde/hde64.c + ) + set(texthook_src + main.cc + texthook.cc + hookfinder.cc + engine/match.cc + engine/match64.cc + engine/native/pchooks.cc + util/ithsys/ithsys.cc + util/util.cc + ) else() -set(texthook_src - main.cc - texthook.cc - hookfinder.cc - engine/engine.cc - engine/match.cc - engine/match32.cc - engine/native/pchooks.cc - util/util.cc - util/ithsys/ithsys.cc - util/disasm/disasm.cc - util/memdbg/memsearch.cc -) + set(minhook_src + minhook/src/buffer.c + minhook/src/hook.c + minhook/src/trampoline.c + minhook/src/hde/hde32.c + ) + set(texthook_src + main.cc + texthook.cc + hookfinder.cc + engine/engine.cc + engine/match.cc + engine/match32.cc + engine/native/pchooks.cc + util/util.cc + util/ithsys/ithsys.cc + util/disasm/disasm.cc + util/memdbg/memsearch.cc + ) endif() +add_library(minhook ${minhook_src}) add_library(texthook MODULE ${texthook_src}) -target_precompile_headers(texthook REUSE_FROM pch) +target_precompile_headers(texthook PRIVATE ../include/common.h) +if(NOT CMAKE_BUILD_TYPE MATCHES DEBUG) + target_compile_options(minhook PRIVATE /MT) + target_compile_options(texthook PRIVATE /MT) + target_link_options(texthook PRIVATE /NODEFAULTLIB:MSVCRT) +endif() target_link_libraries(texthook minhook) diff --git a/texthook/hookfinder.cc b/texthook/hookfinder.cc index 608a73b..cb88aeb 100644 --- a/texthook/hookfinder.cc +++ b/texthook/hookfinder.cc @@ -2,6 +2,7 @@ #include "defs.h" #include "main.h" #include "util.h" +#include "MinHook.h" extern const char* HOOK_SEARCH_STARTING; extern const char* HOOK_SEARCH_INITIALIZING; diff --git a/texthook/main.cc b/texthook/main.cc index 91f159a..317c41e 100644 --- a/texthook/main.cc +++ b/texthook/main.cc @@ -9,6 +9,7 @@ #include "texthook.h" #include "hookfinder.h" #include "util.h" +#include "MinHook.h" extern const char* PIPE_CONNECTED; extern const char* INSERTING_HOOK; diff --git a/texthook/main.h b/texthook/main.h index f801a52..3e4bea7 100644 --- a/texthook/main.h +++ b/texthook/main.h @@ -15,49 +15,6 @@ void RemoveHook(uint64_t addr, int maxOffset = 9); inline SearchParam spDefault; -extern "C" // minhook library -{ - enum MH_STATUS - { - MH_OK, - MH_ERROR_ALREADY_INITIALIZED, - MH_ERROR_NOT_INITIALIZED, - MH_ERROR_ALREADY_CREATED, - MH_ERROR_NOT_CREATED, - MH_ERROR_ENABLED, - MH_ERROR_DISABLED, - MH_ERROR_NOT_EXECUTABLE, - MH_ERROR_UNSUPPORTED_FUNCTION, - MH_ERROR_MEMORY_ALLOC, - MH_ERROR_MEMORY_PROTECT, - MH_ERROR_MODULE_NOT_FOUND, - MH_ERROR_FUNCTION_NOT_FOUND - }; - - MH_STATUS WINAPI MH_Initialize(VOID); - MH_STATUS WINAPI MH_Uninitialize(VOID); - - // Creates a Hook for the specified target function, in disabled state. - // Parameters: - // pTarget [in] A pointer to the target function, which will be - // overridden by the detour function. - // pDetour [in] A pointer to the detour function, which will override - // the target function. - // ppOriginal [out] A pointer to the trampoline function, which will be - // used to call the original target function. - // This parameter can be NULL. - MH_STATUS WINAPI MH_CreateHook(LPVOID pTarget, LPVOID pDetour, LPVOID *ppOriginal); - MH_STATUS WINAPI MH_EnableHook(LPVOID pTarget); - MH_STATUS WINAPI MH_DisableHook(LPVOID pTarget); - MH_STATUS WINAPI MH_RemoveHook(LPVOID pTarget); - MH_STATUS WINAPI MH_QueueEnableHook(LPVOID pTarget); - MH_STATUS WINAPI MH_QueueDisableHook(LPVOID pTarget); - MH_STATUS WINAPI MH_ApplyQueued(VOID); - const char* WINAPI MH_StatusToString(MH_STATUS status); -} - -#define MH_ALL_HOOKS NULL - #define ITH_RAISE (*(int*)0 = 0) // raise C000005, for debugging only #define ITH_TRY __try #define ITH_EXCEPT __except(EXCEPTION_EXECUTE_HANDLER) diff --git a/texthook/minhook b/texthook/minhook new file mode 160000 index 0000000..8fda4f5 --- /dev/null +++ b/texthook/minhook @@ -0,0 +1 @@ +Subproject commit 8fda4f5481fed5797dc2651cd91e238e9b3928c6 diff --git a/texthook/texthook.cc b/texthook/texthook.cc index 53cecd3..a99c91b 100644 --- a/texthook/texthook.cc +++ b/texthook/texthook.cc @@ -6,6 +6,7 @@ #include "texthook.h" #include "main.h" #include "ithsys/ithsys.h" +#include "MinHook.h" extern const char* FUNC_MISSING; extern const char* MODULE_MISSING; diff --git a/x64libs/minhook.lib b/x64libs/minhook.lib deleted file mode 100644 index 1ae7f03..0000000 Binary files a/x64libs/minhook.lib and /dev/null differ diff --git a/x86libs/minhook.lib b/x86libs/minhook.lib deleted file mode 100644 index 5add6f9..0000000 Binary files a/x86libs/minhook.lib and /dev/null differ