diff --git a/EnforceBindingDLL/EnforceBindings.cpp b/EnforceBindingDLL/EnforceBindings.cpp index 7f3cdd1..d1e3830 100644 --- a/EnforceBindingDLL/EnforceBindings.cpp +++ b/EnforceBindingDLL/EnforceBindings.cpp @@ -28,6 +28,34 @@ int32_t enforceBindingsID = 413080; std::string fun_prolog = "\x55\x8B\xEC\x83\xEC\x10"; + + + +typedef HWND (WINAPI *GETFOREGROUNDWINDOW)(); + +GETFOREGROUNDWINDOW fGetForegroundWindow = NULL; + +HWND WINAPI DetourGetForegroundWindow() +{ + HWND gloscHWND = FindWindow(nullptr, L"GloSC_OverlayWindow"); + return gloscHWND; +} + + +template +inline MH_STATUS MH_CreateHookEx(LPVOID pTarget, LPVOID pDetour, T** ppOriginal) +{ + return MH_CreateHook(pTarget, pDetour, reinterpret_cast(ppOriginal)); +} + +template +inline MH_STATUS MH_CreateHookApiEx( + LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, T** ppOriginal) +{ + return MH_CreateHookApi( + pszModule, pszProcName, pDetour, reinterpret_cast(ppOriginal)); +} + ////////////////////////////////// CODE /////////////////////////////////////////// __declspec(naked) void generalized_hookFn() { @@ -92,6 +120,30 @@ void EnforceBindings::Unpatch() } } +void EnforceBindings::patchLizard() +{ + // Initialize MinHook. + if (MH_Initialize() != MH_OK) + return; + + // Create a hook for GetActiveWindow, in disabled state. + if (MH_CreateHookApiEx(L"user32", "GetForegroundWindow", &DetourGetForegroundWindow, &fGetForegroundWindow) != MH_OK) + return; + + // Enable the hook for GetActiveWindow. + if (MH_EnableHook(&GetForegroundWindow) != MH_OK) + return; +} + +void EnforceBindings::unpatchLizard() +{ + if (MH_DisableHook(&GetForegroundWindow) != MH_OK) + return; + // Uninitialize MinHook. + if (MH_Uninitialize() != MH_OK) + return; +} + //places a jmp instruction to a __declspec(naked) function on a given adress //nops the rest of bytes to don't break any instructions diff --git a/EnforceBindingDLL/EnforceBindings.h b/EnforceBindingDLL/EnforceBindings.h index 1ce26d3..5ea56f0 100644 --- a/EnforceBindingDLL/EnforceBindings.h +++ b/EnforceBindingDLL/EnforceBindings.h @@ -21,6 +21,14 @@ limitations under the License. #include #include +#include "../packages/minhook.1.3.3/lib/native/include/MinHook.h" + +#if defined _M_X64 +#pragma comment(lib, "../packages/minhook.1.3.3/lib/native/lib/libMinHook-x64-v141-mt.lib") +#elif defined _M_IX86 +#pragma comment(lib, "../packages/minhook.1.3.3/lib/native/lib/libMinHook-x86-v141-mt.lib") +#endif + class EnforceBindings { @@ -29,6 +37,9 @@ public: static void patchBytes(); static void Unpatch(); + static void patchLizard(); + static void unpatchLizard(); + private: static void PlaceJMP(BYTE * Address, DWORD jumpTo, DWORD lenght); diff --git a/EnforceBindingDLL/dllmain.cpp b/EnforceBindingDLL/dllmain.cpp index cb1f21d..b2bf32d 100644 --- a/EnforceBindingDLL/dllmain.cpp +++ b/EnforceBindingDLL/dllmain.cpp @@ -29,8 +29,10 @@ int WINAPI DllMain(HINSTANCE hInst, DWORD reason, LPVOID reserved) if (reason == DLL_PROCESS_ATTACH) { EnforceBindings::patchBytes(); + EnforceBindings::patchLizard(); } else if (reason == DLL_PROCESS_DETACH) { EnforceBindings::Unpatch(); + EnforceBindings::unpatchLizard(); } return true; } \ No newline at end of file