From ea87ad3d8b54e4dc0adea8023b98b7b81f9993fb Mon Sep 17 00:00:00 2001 From: DisabledMallis Date: Thu, 11 Nov 2021 18:51:41 -0500 Subject: [PATCH 1/7] Add PolyHook2 support --- kiero.cpp | 38 ++++++++++++++++++++++++++++++++++++++ kiero.h | 3 ++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/kiero.cpp b/kiero.cpp index 73e87f0..1fa9b76 100644 --- a/kiero.cpp +++ b/kiero.cpp @@ -34,6 +34,19 @@ # include "minhook/include/MinHook.h" #endif +#if KIERO_USE_POLYHOOK +#include +#include "polyhook2/CapstoneDisassembler.hpp" +#if KIERO_ARCH_X64 +# include "polyhook2/Detour/x64Detour.hpp" +PLH::CapstoneDisassembler disassembler(PLH::Mode::x64); +#endif +#if KIERO_ARCH_X86 +# include "polyhook2/Detour/x86Detour.hpp" +PLH::CapstoneDisassembler disassembler(PLH::Mode::x86); +#endif +#endif + #ifdef _UNICODE # define KIERO_TEXT(text) L##text #else @@ -676,6 +689,9 @@ void kiero::shutdown() } } +#if KIERO_USE_POLYHOOK +std::map detours; +#endif kiero::Status::Enum kiero::bind(uint16_t _index, void** _original, void* _function) { // TODO: Need own detour function @@ -692,6 +708,23 @@ kiero::Status::Enum kiero::bind(uint16_t _index, void** _original, void* _functi } #endif +#if KIERO_USE_POLYHOOK + void* target = (void*)g_methodsTable[_index]; + + //The detour object needs to stay 'alive' since polyhook will unhook the function when the object is destroyed + //This is why here I heap allocate +#if KIERO_ARCH_X64 + detours[_index] = new PLH::x64Detour((char*)target, (char*)_function, (uint64_t*)_original, disassembler); +#endif +#if KIERO_ARCH_X86 + detours[_index] = new PLH::x86Detour((char*)target, (char*)_function, (uint64_t*)_original, disassembler); +#endif + + if(!detours[_index]->hook()) { + return Status::UnknownError; + } +#endif + return Status::Success; } @@ -705,6 +738,11 @@ void kiero::unbind(uint16_t _index) #if KIERO_USE_MINHOOK MH_DisableHook((void*)g_methodsTable[_index]); #endif + +#if KIERO_USE_POLYHOOK + detours[_index]->unHook(); + delete detours[_index]; +#endif } } diff --git a/kiero.h b/kiero.h index 4aba3d4..ff0f1d6 100644 --- a/kiero.h +++ b/kiero.h @@ -3,7 +3,7 @@ #include -#define KIERO_VERSION "1.2.12" +#define KIERO_VERSION "1.2.12-with-polyhook" #define KIERO_INCLUDE_D3D9 0 // 1 if you need D3D9 hook #define KIERO_INCLUDE_D3D10 0 // 1 if you need D3D10 hook @@ -12,6 +12,7 @@ #define KIERO_INCLUDE_OPENGL 0 // 1 if you need OpenGL hook #define KIERO_INCLUDE_VULKAN 0 // 1 if you need Vulkan hook #define KIERO_USE_MINHOOK 0 // 1 if you will use kiero::bind function +#define KIERO_USE_POLYHOOK 0 // 1 if you will use kiero::bind function #define KIERO_ARCH_X64 0 #define KIERO_ARCH_X86 0 From f4eb45a00d3813ee11528f6da9ba018c8eaf2048 Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 26 May 2022 18:30:50 -0400 Subject: [PATCH 2/7] Use CMake + removed dependencies (these can be provided by using CMake) --- .gitignore | 3 ++ .gitmodules | 6 --- CMakeLists.txt | 59 ++++++++++++++++++++++ examples/imgui/README.md | 10 ---- examples/imgui/imgui | 1 - examples/imgui/impl/d3d10_impl.cpp | 57 --------------------- examples/imgui/impl/d3d10_impl.h | 14 ------ examples/imgui/impl/d3d11_impl.cpp | 60 ---------------------- examples/imgui/impl/d3d11_impl.h | 14 ------ examples/imgui/impl/d3d9_impl.cpp | 67 ------------------------- examples/imgui/impl/d3d9_impl.h | 14 ------ examples/imgui/impl/shared.cpp | 19 ------- examples/imgui/impl/shared.h | 6 --- examples/imgui/impl/win32_impl.cpp | 28 ----------- examples/imgui/impl/win32_impl.h | 14 ------ examples/imgui/main.cpp | 80 ------------------------------ kiero.cpp | 8 +-- kiero.h | 11 +--- minhook | 1 - 19 files changed, 67 insertions(+), 405 deletions(-) delete mode 100644 .gitmodules create mode 100644 CMakeLists.txt delete mode 100644 examples/imgui/README.md delete mode 160000 examples/imgui/imgui delete mode 100644 examples/imgui/impl/d3d10_impl.cpp delete mode 100644 examples/imgui/impl/d3d10_impl.h delete mode 100644 examples/imgui/impl/d3d11_impl.cpp delete mode 100644 examples/imgui/impl/d3d11_impl.h delete mode 100644 examples/imgui/impl/d3d9_impl.cpp delete mode 100644 examples/imgui/impl/d3d9_impl.h delete mode 100644 examples/imgui/impl/shared.cpp delete mode 100644 examples/imgui/impl/shared.h delete mode 100644 examples/imgui/impl/win32_impl.cpp delete mode 100644 examples/imgui/impl/win32_impl.h delete mode 100644 examples/imgui/main.cpp delete mode 160000 minhook diff --git a/.gitignore b/.gitignore index 259148f..782232e 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ *.exe *.out *.app + +.vs/ +out/ \ No newline at end of file diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 7c5c20b..0000000 --- a/.gitmodules +++ /dev/null @@ -1,6 +0,0 @@ -[submodule "minhook"] - path = minhook - url = https://github.com/TsudaKageyu/minhook -[submodule "examples/imgui/imgui"] - path = examples/imgui/imgui - url = https://github.com/ocornut/imgui diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..33a11b5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,59 @@ +project(Kiero LANGUAGES CXX) + +option(DYNAMIC "If Kiero should be linked dynamically or not" OFF) +if(DYNAMIC) +add_library(Kiero SHARED) +else() +add_library(Kiero STATIC) +endif() + +option(KIERO_INCLUDE_D3D9 "if you need D3D9 hook" OFF) +if(KIERO_INCLUDE_D3D9) +add_compile_definitions(KIERO_INCLUDE_D3D9 1) +endif() + +option(KIERO_INCLUDE_D3D10 "if you need D3D10 hook" OFF) +if(KIERO_INCLUDE_D3D10) +add_compile_definitions(KIERO_INCLUDE_D3D10 1) +endif() + +option(KIERO_INCLUDE_D3D11 "if you need D3D11 hook" OFF) +if(KIERO_INCLUDE_D3D11) +add_compile_definitions(KIERO_INCLUDE_D3D11 1) +endif() + +option(KIERO_INCLUDE_D3D12 "if you need D3D12 hook" OFF) +if(KIERO_INCLUDE_D3D12) +add_compile_definitions(KIERO_INCLUDE_D3D12 1) +endif() + +option(KIERO_INCLUDE_OPENGL "if you need OpenGL hook" OFF) +if(KIERO_INCLUDE_OPENGL) +add_compile_definitions(KIERO_INCLUDE_OPENGL 1) +endif() + +option(KIERO_INCLUDE_VULKAN "if you need Vulkan hook" OFF) +if(KIERO_INCLUDE_VULKAN) +add_compile_definitions(KIERO_INCLUDE_VULKAN 1) +endif() + +option(KIERO_USE_MINHOOK "if you will use kiero::bind function" OFF) +if(KIERO_USE_MINHOOK) +add_compile_definitions(KIERO_USE_MINHOOK 1) +endif() + +option(KIERO_USE_POLYHOOK "if you will use kiero::bind function" OFF) +if(KIERO_USE_POLYHOOK) +add_compile_definitions(KIERO_USE_POLYHOOK 1) +endif() + +target_sources(Kiero PRIVATE + "${CMAKE_CURRENT_LIST_DIR}/kiero.cpp" +) + +target_include_directories(Kiero INTERFACE "${CMAKE_CURRENT_LIST_DIR}") +if(KIERO_USE_POLYHOOK) +target_link_libraries(Kiero PRIVATE PolyHook_2) +elseif(KIERO_USE_MINHOOK) +target_link_libraries(Kiero PRIVATE minhook) +endif() \ No newline at end of file diff --git a/examples/imgui/README.md b/examples/imgui/README.md deleted file mode 100644 index 6f2b8eb..0000000 --- a/examples/imgui/README.md +++ /dev/null @@ -1,10 +0,0 @@ -## Kiero ImGui Universal Example -### TODO: -- [x] D3D9 -- [x] D3D10 -- [x] D3D11 -- [ ] D3D12 -- [ ] OpenGL -- [ ] Vulkan - -Author(s): [Rebzzel](https://github.com/Rebzzel) \ No newline at end of file diff --git a/examples/imgui/imgui b/examples/imgui/imgui deleted file mode 160000 index 110f506..0000000 --- a/examples/imgui/imgui +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 110f506ec0dd10999ed685c87c609553cb162028 diff --git a/examples/imgui/impl/d3d10_impl.cpp b/examples/imgui/impl/d3d10_impl.cpp deleted file mode 100644 index b6867a6..0000000 --- a/examples/imgui/impl/d3d10_impl.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "../../../kiero.h" - -#if KIERO_INCLUDE_D3D10 - -#include "d3d10_impl.h" -#include -#include - -#include "win32_impl.h" - -#include "../imgui/imgui.h" -#include "../imgui/examples/imgui_impl_win32.h" -#include "../imgui/examples/imgui_impl_dx10.h" - -typedef long(__stdcall* Present)(IDXGISwapChain*, UINT, UINT); -static Present oPresent = NULL; - -long __stdcall hkPresent10(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags) -{ - static bool init = false; - - if (!init) - { - DXGI_SWAP_CHAIN_DESC desc; - pSwapChain->GetDesc(&desc); - - ID3D10Device* device; - pSwapChain->GetDevice(__uuidof(ID3D10Device), (void**)&device); - - impl::win32::init(desc.OutputWindow); - - ImGui::CreateContext(); - ImGui_ImplWin32_Init(desc.OutputWindow); - ImGui_ImplDX10_Init(device); - - init = true; - } - - ImGui_ImplDX10_NewFrame(); - ImGui_ImplWin32_NewFrame(); - ImGui::NewFrame(); - - impl::showExampleWindow("D3D10"); - - ImGui::EndFrame(); - ImGui::Render(); - ImGui_ImplDX10_RenderDrawData(ImGui::GetDrawData()); - - return oPresent(pSwapChain, SyncInterval, Flags); -} - -void impl::d3d10::init() -{ - assert(kiero::bind(8, (void**)&oPresent, hkPresent10) == kiero::Status::Success); -} - -#endif // KIERO_INCLUDE_D3D10 \ No newline at end of file diff --git a/examples/imgui/impl/d3d10_impl.h b/examples/imgui/impl/d3d10_impl.h deleted file mode 100644 index a8f87fe..0000000 --- a/examples/imgui/impl/d3d10_impl.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __D3D10_IMPL_H__ -#define __D3D10_IMPL_H__ - -#include "shared.h" - -namespace impl -{ - namespace d3d10 - { - void init(); - } -} - -#endif // __D3D10_IMPL_H__ \ No newline at end of file diff --git a/examples/imgui/impl/d3d11_impl.cpp b/examples/imgui/impl/d3d11_impl.cpp deleted file mode 100644 index 795504a..0000000 --- a/examples/imgui/impl/d3d11_impl.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "../../../kiero.h" - -#if KIERO_INCLUDE_D3D11 - -#include "d3d11_impl.h" -#include -#include - -#include "win32_impl.h" - -#include "../imgui/imgui.h" -#include "../imgui/examples/imgui_impl_win32.h" -#include "../imgui/examples/imgui_impl_dx11.h" - -typedef long(__stdcall* Present)(IDXGISwapChain*, UINT, UINT); -static Present oPresent = NULL; - -long __stdcall hkPresent11(IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags) -{ - static bool init = false; - - if (!init) - { - DXGI_SWAP_CHAIN_DESC desc; - pSwapChain->GetDesc(&desc); - - ID3D11Device* device; - pSwapChain->GetDevice(__uuidof(ID3D11Device), (void**)&device); - - ID3D11DeviceContext* context; - device->GetImmediateContext(&context); - - impl::win32::init(desc.OutputWindow); - - ImGui::CreateContext(); - ImGui_ImplWin32_Init(desc.OutputWindow); - ImGui_ImplDX11_Init(device, context); - - init = true; - } - - ImGui_ImplDX11_NewFrame(); - ImGui_ImplWin32_NewFrame(); - ImGui::NewFrame(); - - impl::showExampleWindow("D3D11"); - - ImGui::EndFrame(); - ImGui::Render(); - ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); - - return oPresent(pSwapChain, SyncInterval, Flags); -} - -void impl::d3d11::init() -{ - assert(kiero::bind(8, (void**)&oPresent, hkPresent11) == kiero::Status::Success); -} - -#endif // KIERO_INCLUDE_D3D11 \ No newline at end of file diff --git a/examples/imgui/impl/d3d11_impl.h b/examples/imgui/impl/d3d11_impl.h deleted file mode 100644 index 75c0fa8..0000000 --- a/examples/imgui/impl/d3d11_impl.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __D3D11_IMPL_H__ -#define __D3D11_IMPL_H__ - -#include "shared.h" - -namespace impl -{ - namespace d3d11 - { - void init(); - } -} - -#endif // __D3D11_IMPL_H__ \ No newline at end of file diff --git a/examples/imgui/impl/d3d9_impl.cpp b/examples/imgui/impl/d3d9_impl.cpp deleted file mode 100644 index 8a5ae16..0000000 --- a/examples/imgui/impl/d3d9_impl.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "../../../kiero.h" - -#if KIERO_INCLUDE_D3D9 - -#include "d3d9_impl.h" -#include -#include - -#include "win32_impl.h" - -#include "../imgui/imgui.h" -#include "../imgui/examples/imgui_impl_win32.h" -#include "../imgui/examples/imgui_impl_dx9.h" - -typedef long(__stdcall* Reset)(LPDIRECT3DDEVICE9, D3DPRESENT_PARAMETERS*); -static Reset oReset = NULL; - -typedef long(__stdcall* EndScene)(LPDIRECT3DDEVICE9); -static EndScene oEndScene = NULL; - -long __stdcall hkReset(LPDIRECT3DDEVICE9 pDevice, D3DPRESENT_PARAMETERS* pPresentationParameters) -{ - ImGui_ImplDX9_InvalidateDeviceObjects(); - long result = oReset(pDevice, pPresentationParameters); - ImGui_ImplDX9_CreateDeviceObjects(); - - return result; -} - -long __stdcall hkEndScene(LPDIRECT3DDEVICE9 pDevice) -{ - static bool init = false; - - if (!init) - { - D3DDEVICE_CREATION_PARAMETERS params; - pDevice->GetCreationParameters(¶ms); - - impl::win32::init(params.hFocusWindow); - - ImGui::CreateContext(); - ImGui_ImplWin32_Init(params.hFocusWindow); - ImGui_ImplDX9_Init(pDevice); - - init = true; - } - - ImGui_ImplDX9_NewFrame(); - ImGui_ImplWin32_NewFrame(); - ImGui::NewFrame(); - - impl::showExampleWindow("D3D9"); - - ImGui::EndFrame(); - ImGui::Render(); - ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData()); - - return oEndScene(pDevice); -} - -void impl::d3d9::init() -{ - assert(kiero::bind(16, (void**)&oReset, hkReset) == kiero::Status::Success); - assert(kiero::bind(42, (void**)&oEndScene, hkEndScene) == kiero::Status::Success); -} - -#endif // KIERO_INCLUDE_D3D9 \ No newline at end of file diff --git a/examples/imgui/impl/d3d9_impl.h b/examples/imgui/impl/d3d9_impl.h deleted file mode 100644 index 9118439..0000000 --- a/examples/imgui/impl/d3d9_impl.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __D3D9_IMPL_H__ -#define __D3D9_IMPL_H__ - -#include "shared.h" - -namespace impl -{ - namespace d3d9 - { - void init(); - } -} - -#endif // __D3D9_IMPL_H__ \ No newline at end of file diff --git a/examples/imgui/impl/shared.cpp b/examples/imgui/impl/shared.cpp deleted file mode 100644 index 2ee9b29..0000000 --- a/examples/imgui/impl/shared.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS - -#include "shared.h" -#include -#include "../imgui/imgui.h" - -void impl::showExampleWindow(const char* comment) -{ - char buffer[128]; - ::memset(buffer, 0, 128); - ::sprintf(buffer, "Kiero Dear ImGui Example (%s)", comment); - - ImGui::Begin(buffer); - - ImGui::Text("Hello"); - ImGui::Button("World!"); - - ImGui::End(); -} \ No newline at end of file diff --git a/examples/imgui/impl/shared.h b/examples/imgui/impl/shared.h deleted file mode 100644 index 2f2f1c3..0000000 --- a/examples/imgui/impl/shared.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -namespace impl -{ - void showExampleWindow(const char* comment); -} \ No newline at end of file diff --git a/examples/imgui/impl/win32_impl.cpp b/examples/imgui/impl/win32_impl.cpp deleted file mode 100644 index 7ef9381..0000000 --- a/examples/imgui/impl/win32_impl.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "../../../kiero.h" - -#include "win32_impl.h" -#include - -#include "../imgui/imgui.h" -#include "../imgui/examples/imgui_impl_win32.h" - -static WNDPROC oWndProc = NULL; - -extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); - -LRESULT CALLBACK hkWindowProc( - _In_ HWND hwnd, - _In_ UINT uMsg, - _In_ WPARAM wParam, - _In_ LPARAM lParam -) -{ - if (ImGui_ImplWin32_WndProcHandler(hwnd, uMsg, wParam, lParam) > 0) - return 1L; - return ::CallWindowProcA(oWndProc, hwnd, uMsg, wParam, lParam); -} - -void impl::win32::init(void* hwnd) -{ - oWndProc = (WNDPROC)::SetWindowLongPtr((HWND)hwnd, GWLP_WNDPROC, (LONG)hkWindowProc); -} \ No newline at end of file diff --git a/examples/imgui/impl/win32_impl.h b/examples/imgui/impl/win32_impl.h deleted file mode 100644 index d494ea0..0000000 --- a/examples/imgui/impl/win32_impl.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __WIN32_IMPL_H__ -#define __WIN32_IMPL_H__ - -#include "shared.h" - -namespace impl -{ - namespace win32 - { - void init(void* hwnd); - } -} - -#endif // __WIN32_IMPL_H__ \ No newline at end of file diff --git a/examples/imgui/main.cpp b/examples/imgui/main.cpp deleted file mode 100644 index f88444b..0000000 --- a/examples/imgui/main.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include "../../kiero.h" - -#if KIERO_INCLUDE_D3D9 -# include "impl/d3d9_impl.h" -#endif - -#if KIERO_INCLUDE_D3D10 -# include "impl/d3d10_impl.h" -#endif - -#if KIERO_INCLUDE_D3D11 -# include "impl/d3d11_impl.h" -#endif - -#if KIERO_INCLUDE_D3D12 -#endif - -#if KIERO_INCLUDE_OPENGL -#endif - -#if KIERO_INCLUDE_VULKAN -#endif - -#if !KIERO_USE_MINHOOK -# error "The example requires that minhook be enabled!" -#endif - -#include - -int kieroExampleThread() -{ - if (kiero::init(kiero::RenderType::Auto) == kiero::Status::Success) - { - switch (kiero::getRenderType()) - { -#if KIERO_INCLUDE_D3D9 - case kiero::RenderType::D3D9: - impl::d3d9::init(); - break; -#endif -#if KIERO_INCLUDE_D3D10 - case kiero::RenderType::D3D10: - impl::d3d10::init(); - break; -#endif -#if KIERO_INCLUDE_D3D11 - case kiero::RenderType::D3D11: - impl::d3d11::init(); - break; -#endif - case kiero::RenderType::D3D12: - // TODO: D3D12 implementation? - break; - case kiero::RenderType::OpenGL: - // TODO: OpenGL implementation? - break; - case kiero::RenderType::Vulkan: - // TODO: Vulkan implementation? - break; - } - - return 1; - } - - return 0; -} - -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, LPVOID) -{ - DisableThreadLibraryCalls(hInstance); - - switch (fdwReason) - { - case DLL_PROCESS_ATTACH: - CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)kieroExampleThread, NULL, 0, NULL); - break; - } - - return TRUE; -} \ No newline at end of file diff --git a/kiero.cpp b/kiero.cpp index 1fa9b76..e2651e2 100644 --- a/kiero.cpp +++ b/kiero.cpp @@ -31,18 +31,18 @@ #endif #if KIERO_USE_MINHOOK -# include "minhook/include/MinHook.h" +# include #endif #if KIERO_USE_POLYHOOK #include -#include "polyhook2/CapstoneDisassembler.hpp" +#include #if KIERO_ARCH_X64 -# include "polyhook2/Detour/x64Detour.hpp" +# include PLH::CapstoneDisassembler disassembler(PLH::Mode::x64); #endif #if KIERO_ARCH_X86 -# include "polyhook2/Detour/x86Detour.hpp" +# include PLH::CapstoneDisassembler disassembler(PLH::Mode::x86); #endif #endif diff --git a/kiero.h b/kiero.h index ff0f1d6..6eeb5ce 100644 --- a/kiero.h +++ b/kiero.h @@ -3,16 +3,7 @@ #include -#define KIERO_VERSION "1.2.12-with-polyhook" - -#define KIERO_INCLUDE_D3D9 0 // 1 if you need D3D9 hook -#define KIERO_INCLUDE_D3D10 0 // 1 if you need D3D10 hook -#define KIERO_INCLUDE_D3D11 0 // 1 if you need D3D11 hook -#define KIERO_INCLUDE_D3D12 0 // 1 if you need D3D12 hook -#define KIERO_INCLUDE_OPENGL 0 // 1 if you need OpenGL hook -#define KIERO_INCLUDE_VULKAN 0 // 1 if you need Vulkan hook -#define KIERO_USE_MINHOOK 0 // 1 if you will use kiero::bind function -#define KIERO_USE_POLYHOOK 0 // 1 if you will use kiero::bind function +#define KIERO_VERSION "1.2.12-extended" #define KIERO_ARCH_X64 0 #define KIERO_ARCH_X86 0 diff --git a/minhook b/minhook deleted file mode 160000 index 8fda4f5..0000000 --- a/minhook +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8fda4f5481fed5797dc2651cd91e238e9b3928c6 From df7be5b58d3499984a5b11565ceac55c98adfc65 Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 26 Aug 2022 13:59:35 -0400 Subject: [PATCH 3/7] Update polyhook --- kiero.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/kiero.cpp b/kiero.cpp index e2651e2..35441b1 100644 --- a/kiero.cpp +++ b/kiero.cpp @@ -36,14 +36,11 @@ #if KIERO_USE_POLYHOOK #include -#include #if KIERO_ARCH_X64 # include -PLH::CapstoneDisassembler disassembler(PLH::Mode::x64); #endif #if KIERO_ARCH_X86 # include -PLH::CapstoneDisassembler disassembler(PLH::Mode::x86); #endif #endif @@ -714,10 +711,10 @@ kiero::Status::Enum kiero::bind(uint16_t _index, void** _original, void* _functi //The detour object needs to stay 'alive' since polyhook will unhook the function when the object is destroyed //This is why here I heap allocate #if KIERO_ARCH_X64 - detours[_index] = new PLH::x64Detour((char*)target, (char*)_function, (uint64_t*)_original, disassembler); + detours[_index] = new PLH::x64Detour((char*)target, (char*)_function, (uint64_t*)_original); #endif #if KIERO_ARCH_X86 - detours[_index] = new PLH::x86Detour((char*)target, (char*)_function, (uint64_t*)_original, disassembler); + detours[_index] = new PLH::x86Detour((char*)target, (char*)_function, (uint64_t*)_original); #endif if(!detours[_index]->hook()) { From 1057a23aaa3d4eb9cd587ad404e8c2f1874e84df Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 26 Aug 2022 14:03:07 -0400 Subject: [PATCH 4/7] Fix detour --- kiero.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kiero.cpp b/kiero.cpp index 35441b1..60e56f8 100644 --- a/kiero.cpp +++ b/kiero.cpp @@ -711,10 +711,10 @@ kiero::Status::Enum kiero::bind(uint16_t _index, void** _original, void* _functi //The detour object needs to stay 'alive' since polyhook will unhook the function when the object is destroyed //This is why here I heap allocate #if KIERO_ARCH_X64 - detours[_index] = new PLH::x64Detour((char*)target, (char*)_function, (uint64_t*)_original); + detours[_index] = new PLH::x64Detour((uint64_t)target, (uint64_t)_function, (uint64_t*)_original); #endif #if KIERO_ARCH_X86 - detours[_index] = new PLH::x86Detour((char*)target, (char*)_function, (uint64_t*)_original); + detours[_index] = new PLH::x86Detour((uint64_t)target, (uint64_t)_function, (uint64_t*)_original); #endif if(!detours[_index]->hook()) { From aa468cb1063ef1ff3c0dc59a3e1e9567f3aa1d47 Mon Sep 17 00:00:00 2001 From: Mike Date: Sat, 12 Aug 2023 22:27:20 -0400 Subject: [PATCH 5/7] Update kiero.cpp --- kiero.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/kiero.cpp b/kiero.cpp index 60e56f8..f952fc9 100644 --- a/kiero.cpp +++ b/kiero.cpp @@ -680,6 +680,13 @@ void kiero::shutdown() MH_DisableHook(MH_ALL_HOOKS); #endif +#if KIERO_USE_POLYHOOK + for (const auto& [index, detour] : detours) + { + detour->unHook(); + } +#endif + ::free(g_methodsTable); g_methodsTable = NULL; g_renderType = RenderType::None; @@ -751,4 +758,4 @@ kiero::RenderType::Enum kiero::getRenderType() uint150_t* kiero::getMethodsTable() { return g_methodsTable; -} \ No newline at end of file +} From 960959b0101301d1132dc0674b1010d656cec1fb Mon Sep 17 00:00:00 2001 From: Mike Date: Sat, 12 Aug 2023 22:28:44 -0400 Subject: [PATCH 6/7] Update kiero.cpp --- kiero.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kiero.cpp b/kiero.cpp index f952fc9..788dcb2 100644 --- a/kiero.cpp +++ b/kiero.cpp @@ -672,6 +672,10 @@ kiero::Status::Enum kiero::init(RenderType::Enum _renderType) return Status::Success; } +#if KIERO_USE_POLYHOOK +std::map detours; +#endif + void kiero::shutdown() { if (g_renderType != RenderType::None) @@ -693,9 +697,6 @@ void kiero::shutdown() } } -#if KIERO_USE_POLYHOOK -std::map detours; -#endif kiero::Status::Enum kiero::bind(uint16_t _index, void** _original, void* _function) { // TODO: Need own detour function From 6d0cb52dd10d1c01d53dce23f2e2f11be0e5d502 Mon Sep 17 00:00:00 2001 From: Mike Date: Sat, 12 Aug 2023 22:39:41 -0400 Subject: [PATCH 7/7] Update kiero.cpp --- kiero.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kiero.cpp b/kiero.cpp index 788dcb2..f5bc17a 100644 --- a/kiero.cpp +++ b/kiero.cpp @@ -689,6 +689,7 @@ void kiero::shutdown() { detour->unHook(); } + detours.clear(); #endif ::free(g_methodsTable); @@ -747,6 +748,7 @@ void kiero::unbind(uint16_t _index) #if KIERO_USE_POLYHOOK detours[_index]->unHook(); delete detours[_index]; + detours.erase(_index); #endif } }