From 757f6483855e491f8015756fa7faadffd50fda33 Mon Sep 17 00:00:00 2001 From: narzoul Date: Tue, 5 May 2020 20:36:49 +0200 Subject: [PATCH] Support injection via dciman32.dll --- DDrawCompat/Common/Hook.cpp | 13 -- DDrawCompat/Common/Log.cpp | 7 +- DDrawCompat/Common/Log.h | 9 +- DDrawCompat/DDraw/DirectDraw.cpp | 6 + DDrawCompat/DDraw/ScopedThreadLock.h | 2 +- .../DDraw/Surfaces/PrimarySurfaceImpl.cpp | 2 +- DDrawCompat/DDrawCompat.vcxproj | 11 +- DDrawCompat/DDrawCompat.vcxproj.filters | 24 +-- DDrawCompat/Dll/DDrawCompat.def | 25 --- DDrawCompat/Dll/Dll.cpp | 16 ++ DDrawCompat/Dll/{Procs.h => Dll.h} | 56 +++-- DDrawCompat/Dll/DllMain.cpp | 200 +++++++++++++----- DDrawCompat/Dll/Procs.cpp | 6 - DDrawCompat/Dll/UnmodifiedProcs.cpp | 9 - DDrawCompat/Gdi/Caret.cpp | 23 +- DDrawCompat/Gdi/WinProc.cpp | 9 +- DDrawCompat/Gdi/Window.cpp | 6 +- 17 files changed, 243 insertions(+), 181 deletions(-) delete mode 100644 DDrawCompat/Dll/DDrawCompat.def create mode 100644 DDrawCompat/Dll/Dll.cpp rename DDrawCompat/Dll/{Procs.h => Dll.h} (53%) delete mode 100644 DDrawCompat/Dll/Procs.cpp delete mode 100644 DDrawCompat/Dll/UnmodifiedProcs.cpp diff --git a/DDrawCompat/Common/Hook.cpp b/DDrawCompat/Common/Hook.cpp index 2b90452..dfe899f 100644 --- a/DDrawCompat/Common/Hook.cpp +++ b/DDrawCompat/Common/Hook.cpp @@ -5,11 +5,9 @@ #include #include #include -#include #include #include -#include #include #include @@ -92,17 +90,6 @@ namespace return oss.str(); } - std::vector getProcessModules(HANDLE process) - { - std::vector modules(10000); - DWORD bytesNeeded = 0; - if (EnumProcessModules(process, modules.data(), modules.size(), &bytesNeeded)) - { - modules.resize(bytesNeeded / sizeof(modules[0])); - } - return modules; - } - PIMAGE_NT_HEADERS getImageNtHeaders(HMODULE module) { PIMAGE_DOS_HEADER dosHeader = reinterpret_cast(module); diff --git a/DDrawCompat/Common/Log.cpp b/DDrawCompat/Common/Log.cpp index b3ff596..7cdb956 100644 --- a/DDrawCompat/Common/Log.cpp +++ b/DDrawCompat/Common/Log.cpp @@ -74,9 +74,14 @@ namespace Compat s_logFile << std::endl; } + void Log::initLogging() + { + s_logFile.open("ddraw.log"); + } + thread_local DWORD Log::s_indent = 0; thread_local DWORD Log::s_outParamDepth = 0; thread_local bool Log::s_isLeaveLog = false; - std::ofstream Log::s_logFile("ddraw.log"); + std::ofstream Log::s_logFile; } diff --git a/DDrawCompat/Common/Log.h b/DDrawCompat/Common/Log.h index 7a2a4f1..7a6cdd3 100644 --- a/DDrawCompat/Common/Log.h +++ b/DDrawCompat/Common/Log.h @@ -145,6 +145,7 @@ namespace Compat return *this; } + static void initLogging(); static bool isPointerDereferencingAllowed() { return s_isLeaveLog || 0 == s_outParamDepth; } protected: @@ -276,7 +277,7 @@ operator<<(std::ostream& os, T* t) return os << "null"; } - if (!Compat::Log::isPointerDereferencingAllowed()) + if (!Compat::Log::isPointerDereferencingAllowed() || reinterpret_cast(t) <= 0xFFFF) { return os << static_cast(t); } @@ -294,10 +295,10 @@ std::ostream& operator<<(std::ostream& os, T** t) os << static_cast(t); - if (Compat::Log::isPointerDereferencingAllowed()) + if (!Compat::Log::isPointerDereferencingAllowed() || reinterpret_cast(t) <= 0xFFFF) { - os << '=' << *t; + return os; } - return os; + return os << '=' << *t; } diff --git a/DDrawCompat/DDraw/DirectDraw.cpp b/DDrawCompat/DDraw/DirectDraw.cpp index 94cd1ad..056726b 100644 --- a/DDrawCompat/DDraw/DirectDraw.cpp +++ b/DDrawCompat/DDraw/DirectDraw.cpp @@ -51,6 +51,11 @@ namespace DDraw return pf; } + void logComInstantiation() + { + LOG_ONCE("COM instantiation of DirectDraw detected"); + } + void suppressEmulatedDirectDraw(GUID*& guid) { if (reinterpret_cast(DDCREATE_EMULATIONONLY) == guid) @@ -119,6 +124,7 @@ namespace DDraw template HRESULT STDMETHODCALLTYPE DirectDraw::Initialize(TDirectDraw* This, GUID* lpGUID) { + logComInstantiation(); suppressEmulatedDirectDraw(lpGUID); return s_origVtable.Initialize(This, lpGUID); } diff --git a/DDrawCompat/DDraw/ScopedThreadLock.h b/DDrawCompat/DDraw/ScopedThreadLock.h index 871b7ed..d2e9514 100644 --- a/DDrawCompat/DDraw/ScopedThreadLock.h +++ b/DDrawCompat/DDraw/ScopedThreadLock.h @@ -1,6 +1,6 @@ #pragma once -#include "Dll/Procs.h" +#include namespace DDraw { diff --git a/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.cpp b/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.cpp index 4b8a61e..2a9ed8a 100644 --- a/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.cpp +++ b/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/DDrawCompat/DDrawCompat.vcxproj b/DDrawCompat/DDrawCompat.vcxproj index f973d85..f1b4923 100644 --- a/DDrawCompat/DDrawCompat.vcxproj +++ b/DDrawCompat/DDrawCompat.vcxproj @@ -87,7 +87,6 @@ stdcpp17 - Dll/DDrawCompat.def dxguid.lib;detours.lib;msimg32.lib;oleacc.lib;psapi.lib;uxtheme.lib;dwmapi.lib;winmm.lib;%(AdditionalDependencies) DebugFull true @@ -106,7 +105,6 @@ stdcpp17 - Dll/DDrawCompat.def dxguid.lib;detours.lib;msimg32.lib;oleacc.lib;psapi.lib;uxtheme.lib;dwmapi.lib;winmm.lib;%(AdditionalDependencies) DebugFull true @@ -125,7 +123,6 @@ stdcpp17 - Dll/DDrawCompat.def dxguid.lib;detours.lib;msimg32.lib;oleacc.lib;psapi.lib;uxtheme.lib;dwmapi.lib;winmm.lib;%(AdditionalDependencies) DebugFull true @@ -211,7 +208,7 @@ - + @@ -279,9 +276,8 @@ - - + @@ -305,9 +301,6 @@ - - - diff --git a/DDrawCompat/DDrawCompat.vcxproj.filters b/DDrawCompat/DDrawCompat.vcxproj.filters index 1b8d844..3116275 100644 --- a/DDrawCompat/DDrawCompat.vcxproj.filters +++ b/DDrawCompat/DDrawCompat.vcxproj.filters @@ -231,9 +231,6 @@ Header Files\Config - - Header Files\Dll - Header Files\DDraw\Surfaces @@ -384,6 +381,9 @@ Header Files\Gdi + + Header Files\Dll + @@ -476,15 +476,6 @@ Source Files\Win32 - - Source Files\Dll - - - Source Files\Dll - - - Source Files\Dll - Source Files\DDraw\Surfaces @@ -590,10 +581,11 @@ Source Files\Gdi - - - + Source Files\Dll - + + + Source Files\Dll + \ No newline at end of file diff --git a/DDrawCompat/Dll/DDrawCompat.def b/DDrawCompat/Dll/DDrawCompat.def deleted file mode 100644 index b5df31a..0000000 --- a/DDrawCompat/Dll/DDrawCompat.def +++ /dev/null @@ -1,25 +0,0 @@ -LIBRARY ddraw - -EXPORTS - AcquireDDThreadLock - CompleteCreateSysmemSurface - D3DParseUnknownCommand - DDGetAttachedSurfaceLcl - DDInternalLock - DDInternalUnlock - DSoundHelp - DirectDrawCreate - DirectDrawCreateClipper - DirectDrawCreateEx - DirectDrawEnumerateA - DirectDrawEnumerateExA - DirectDrawEnumerateExW - DirectDrawEnumerateW - DllCanUnloadNow PRIVATE - DllGetClassObject PRIVATE - GetDDSurfaceLocal - GetOLEThunkData - GetSurfaceFromDC - RegisterSpecialCase - ReleaseDDThreadLock - SetAppCompatData diff --git a/DDrawCompat/Dll/Dll.cpp b/DDrawCompat/Dll/Dll.cpp new file mode 100644 index 0000000..c0e426f --- /dev/null +++ b/DDrawCompat/Dll/Dll.cpp @@ -0,0 +1,16 @@ +#include + +namespace Dll +{ + HMODULE g_currentModule = nullptr; + Procs g_origProcs = {}; + Procs g_jmpTargetProcs = {}; +} + +#define CREATE_PROC_STUB(procName) \ + extern "C" __declspec(dllexport, naked) void procName() \ + { \ + __asm jmp Dll::g_jmpTargetProcs.procName \ + } + +VISIT_ALL_PROCS(CREATE_PROC_STUB) diff --git a/DDrawCompat/Dll/Procs.h b/DDrawCompat/Dll/Dll.h similarity index 53% rename from DDrawCompat/Dll/Procs.h rename to DDrawCompat/Dll/Dll.h index 6b4b76c..93a04b8 100644 --- a/DDrawCompat/Dll/Procs.h +++ b/DDrawCompat/Dll/Dll.h @@ -2,7 +2,17 @@ #include -#define VISIT_UNMODIFIED_PROCS(visit) \ +#define VISIT_PUBLIC_DDRAW_PROCS(visit) \ + visit(DirectDrawCreate) \ + visit(DirectDrawCreateClipper) \ + visit(DirectDrawCreateEx) \ + visit(DirectDrawEnumerateA) \ + visit(DirectDrawEnumerateExA) \ + visit(DirectDrawEnumerateExW) \ + visit(DirectDrawEnumerateW) \ + visit(DllGetClassObject) + +#define VISIT_PRIVATE_DDRAW_PROCS(visit) \ visit(AcquireDDThreadLock) \ visit(CompleteCreateSysmemSurface) \ visit(D3DParseUnknownCommand) \ @@ -10,11 +20,6 @@ visit(DDInternalLock) \ visit(DDInternalUnlock) \ visit(DSoundHelp) \ - visit(DirectDrawCreateClipper) \ - visit(DirectDrawEnumerateA) \ - visit(DirectDrawEnumerateExA) \ - visit(DirectDrawEnumerateExW) \ - visit(DirectDrawEnumerateW) \ visit(DllCanUnloadNow) \ visit(GetDDSurfaceLocal) \ visit(GetOLEThunkData) \ @@ -23,25 +28,48 @@ visit(ReleaseDDThreadLock) \ visit(SetAppCompatData) -#define VISIT_MODIFIED_PROCS(visit) \ - visit(DirectDrawCreate) \ - visit(DirectDrawCreateEx) \ - visit(DllGetClassObject) +#define VISIT_DDRAW_PROCS(visit) \ + VISIT_PUBLIC_DDRAW_PROCS(visit) \ + VISIT_PRIVATE_DDRAW_PROCS(visit) + +#define VISIT_DCIMAN32_PROCS(visit) \ + visit(DCIBeginAccess) \ + visit(DCICloseProvider) \ + visit(DCICreateOffscreen) \ + visit(DCICreateOverlay) \ + visit(DCICreatePrimary) \ + visit(DCIDestroy) \ + visit(DCIDraw) \ + visit(DCIEndAccess) \ + visit(DCIEnum) \ + visit(DCIOpenProvider) \ + visit(DCISetClipList) \ + visit(DCISetDestination) \ + visit(DCISetSrcDestClip) \ + visit(GetDCRegionData) \ + visit(GetWindowRegionData) \ + visit(WinWatchClose) \ + visit(WinWatchDidStatusChange) \ + visit(WinWatchGetClipList) \ + visit(WinWatchNotify) \ + visit(WinWatchOpen) #define VISIT_ALL_PROCS(visit) \ - VISIT_UNMODIFIED_PROCS(visit) \ - VISIT_MODIFIED_PROCS(visit) - -#define ADD_FARPROC_MEMBER(memberName) FARPROC memberName; + VISIT_DDRAW_PROCS(visit) \ + VISIT_DCIMAN32_PROCS(visit) namespace Dll { struct Procs { +#define ADD_FARPROC_MEMBER(memberName) FARPROC memberName; VISIT_ALL_PROCS(ADD_FARPROC_MEMBER); +#undef ADD_FARPROC_MEMBER }; + extern HMODULE g_currentModule; extern Procs g_origProcs; + extern Procs g_jmpTargetProcs; } #undef ADD_FARPROC_MEMBER diff --git a/DDrawCompat/Dll/DllMain.cpp b/DDrawCompat/Dll/DllMain.cpp index a9694cb..be61963 100644 --- a/DDrawCompat/Dll/DllMain.cpp +++ b/DDrawCompat/Dll/DllMain.cpp @@ -1,6 +1,8 @@ #include +#include #include +#include #include #include @@ -11,7 +13,7 @@ #include #include #include -#include +#include #include #include #include @@ -24,7 +26,72 @@ HRESULT WINAPI SetAppCompatData(DWORD, DWORD); namespace { + template + using FuncPtr = Result(WINAPI*)(Params...); + HMODULE g_origDDrawModule = nullptr; + HMODULE g_origDciman32Module = nullptr; + + template + const char* getFuncName(); + +#define DEFINE_FUNC_NAME(func) template <> const char* getFuncName<&Dll::Procs::func>() { return #func; } + VISIT_PUBLIC_DDRAW_PROCS(DEFINE_FUNC_NAME) +#undef DEFINE_FUNC_NAME + + void installHooks(); + + template + Result WINAPI directDrawFunc(FirstParam firstParam, Params... params) + { + LOG_FUNC(getFuncName(), firstParam, params...); + installHooks(); + suppressEmulatedDirectDraw(firstParam); + return LOG_RESULT(reinterpret_cast>(Dll::g_origProcs.*origFunc)( + firstParam, params...)); + } + + template + FuncPtr getDirectDrawFuncPtr(FuncPtr) + { + return &directDrawFunc; + } + + std::string getDirName(const std::string& path) + { + return path.substr(0, path.find_last_of('\\')); + } + + std::string getFileName(const std::string& path) + { + auto lastSeparatorPos = path.find_last_of('\\'); + return std::string::npos == lastSeparatorPos ? path : path.substr(lastSeparatorPos + 1, std::string::npos); + } + + std::string getModulePath(HMODULE module) + { + char path[MAX_PATH] = {}; + GetModuleFileName(module, path, sizeof(path)); + return path; + } + + std::vector getProcessModules(HANDLE process) + { + std::vector modules(10000); + DWORD bytesNeeded = 0; + if (EnumProcessModules(process, modules.data(), modules.size(), &bytesNeeded)) + { + modules.resize(bytesNeeded / sizeof(modules[0])); + } + return modules; + } + + std::string getSystemDirectory() + { + char path[MAX_PATH] = {}; + GetSystemDirectory(path, sizeof(path)); + return path; + } void installHooks() { @@ -74,18 +141,28 @@ namespace } } - bool loadLibrary(const std::string& systemDirectory, const std::string& dllName, HMODULE& module) + bool isEqualPath(const std::string& p1, const std::string& p2) { - const std::string systemDllPath = systemDirectory + '\\' + dllName; + return 0 == _strcmpi(p1.c_str(), p2.c_str()); + } - module = LoadLibrary(systemDllPath.c_str()); - if (!module) + bool isOtherDDrawWrapperLoaded() + { + auto currentDllPath = getModulePath(Dll::g_currentModule); + auto systemDirectory = getSystemDirectory(); + auto processModules = getProcessModules(GetCurrentProcess()); + for (HMODULE module : processModules) { - Compat::Log() << "ERROR: Failed to load system " << dllName << " from " << systemDllPath; - return false; + auto path = getModulePath(module); + auto fileName = getFileName(path); + if ((isEqualPath(fileName, "ddraw.dll") || isEqualPath(fileName, "dciman32.dll")) && + !isEqualPath(path, currentDllPath) && + !isEqualPath(getDirName(path), systemDirectory)) + { + return true; + } } - - return true; + return false; } void printEnvironmentVariable(const char* var) @@ -99,42 +176,79 @@ namespace } Compat::Log() << "Environment variable " << var << " = \"" << value << '"'; } + + template + void suppressEmulatedDirectDraw(Param) + { + } + + void suppressEmulatedDirectDraw(GUID*& guid) + { + DDraw::suppressEmulatedDirectDraw(guid); + } } -#define LOAD_ORIGINAL_PROC(procName) \ - Dll::g_origProcs.procName = Compat::getProcAddress(g_origDDrawModule, #procName); +#define LOAD_ORIG_PROC(proc) \ + Dll::g_origProcs.proc = Compat::getProcAddress(origModule, #proc); + +#define HOOK_DDRAW_PROC(proc) \ + Compat::hookFunction( \ + reinterpret_cast(Dll::g_origProcs.proc), \ + getDirectDrawFuncPtr<&Dll::Procs::proc>(static_cast(nullptr)), \ + #proc); BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { + static bool skipDllMain = false; + if (skipDllMain) + { + return TRUE; + } + if (fdwReason == DLL_PROCESS_ATTACH) { - char currentProcessPath[MAX_PATH] = {}; - GetModuleFileName(nullptr, currentProcessPath, MAX_PATH); - Compat::Log() << "Process path: " << currentProcessPath; + Dll::g_currentModule = hinstDLL; + if (isOtherDDrawWrapperLoaded()) + { + skipDllMain = true; + return TRUE; + } + Compat::Log::initLogging(); + Compat::Log() << "Process path: " << getModulePath(nullptr); printEnvironmentVariable("__COMPAT_LAYER"); + auto currentDllPath = getModulePath(hinstDLL); + Compat::Log() << "Loading DDrawCompat " << (lpvReserved ? "statically" : "dynamically") << " from " << currentDllPath; - char currentDllPath[MAX_PATH] = {}; - GetModuleFileName(hinstDLL, currentDllPath, MAX_PATH); - Compat::Log() << "Loading DDrawCompat " << (lpvReserved ? "statically" : "dynamically") - << " from " << currentDllPath; - - char systemDirectory[MAX_PATH] = {}; - GetSystemDirectory(systemDirectory, MAX_PATH); - - std::string systemDDrawDllPath = std::string(systemDirectory) + "\\ddraw.dll"; - if (0 == _stricmp(currentDllPath, systemDDrawDllPath.c_str())) + auto systemDirectory = getSystemDirectory(); + if (isEqualPath(getDirName(currentDllPath), systemDirectory)) { - Compat::Log() << "DDrawCompat cannot be installed as the system ddraw.dll"; + Compat::Log() << "DDrawCompat cannot be installed in the Windows system directory"; return FALSE; } - if (!loadLibrary(systemDirectory, "ddraw.dll", g_origDDrawModule)) + auto systemDDrawDllPath = systemDirectory + "\\ddraw.dll"; + g_origDDrawModule = LoadLibrary(systemDDrawDllPath.c_str()); + if (!g_origDDrawModule) { + Compat::Log() << "ERROR: Failed to load system ddraw.dll from " << systemDDrawDllPath; return FALSE; } - VISIT_ALL_PROCS(LOAD_ORIGINAL_PROC); + HMODULE origModule = g_origDDrawModule; + VISIT_DDRAW_PROCS(LOAD_ORIG_PROC); + + auto systemDciman32DllPath = systemDirectory + "\\dciman32.dll"; + g_origDciman32Module = LoadLibrary(systemDciman32DllPath.c_str()); + if (g_origDciman32Module) + { + origModule = g_origDciman32Module; + VISIT_DCIMAN32_PROCS(LOAD_ORIG_PROC); + } + + Dll::g_jmpTargetProcs = Dll::g_origProcs; + + VISIT_PUBLIC_DDRAW_PROCS(HOOK_DDRAW_PROC) const BOOL disablePriorityBoost = TRUE; SetProcessPriorityBoost(GetCurrentProcess(), disablePriorityBoost); @@ -160,6 +274,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) D3dDdi::uninstallHooks(); Gdi::uninstallHooks(); Compat::unhookAllFunctions(); + FreeLibrary(g_origDciman32Module); FreeLibrary(g_origDDrawModule); } timeEndPeriod(1); @@ -172,34 +287,3 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) return TRUE; } - -extern "C" HRESULT WINAPI DirectDrawCreate( - GUID* lpGUID, - LPDIRECTDRAW* lplpDD, - IUnknown* pUnkOuter) -{ - LOG_FUNC(__func__, lpGUID, lplpDD, pUnkOuter); - installHooks(); - DDraw::suppressEmulatedDirectDraw(lpGUID); - return LOG_RESULT(CALL_ORIG_PROC(DirectDrawCreate)(lpGUID, lplpDD, pUnkOuter)); -} - -extern "C" HRESULT WINAPI DirectDrawCreateEx( - GUID* lpGUID, - LPVOID* lplpDD, - REFIID iid, - IUnknown* pUnkOuter) -{ - LOG_FUNC(__func__, lpGUID, lplpDD, iid, pUnkOuter); - installHooks(); - DDraw::suppressEmulatedDirectDraw(lpGUID); - return LOG_RESULT(CALL_ORIG_PROC(DirectDrawCreateEx)(lpGUID, lplpDD, iid, pUnkOuter)); -} - -extern "C" HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) -{ - LOG_FUNC(__func__, rclsid, riid, ppv); - LOG_ONCE("COM instantiation of DirectDraw detected"); - installHooks(); - return LOG_RESULT(CALL_ORIG_PROC(DllGetClassObject)(rclsid, riid, ppv)); -} diff --git a/DDrawCompat/Dll/Procs.cpp b/DDrawCompat/Dll/Procs.cpp deleted file mode 100644 index 3d7a6a7..0000000 --- a/DDrawCompat/Dll/Procs.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "Dll/Procs.h" - -namespace Dll -{ - Procs g_origProcs = {}; -} diff --git a/DDrawCompat/Dll/UnmodifiedProcs.cpp b/DDrawCompat/Dll/UnmodifiedProcs.cpp deleted file mode 100644 index 5e52803..0000000 --- a/DDrawCompat/Dll/UnmodifiedProcs.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "Dll/Procs.h" - -#define CREATE_PROC_STUB(procName) \ - extern "C" __declspec(naked) void __stdcall procName() \ - { \ - __asm jmp Dll::g_origProcs.procName \ - } - -VISIT_UNMODIFIED_PROCS(CREATE_PROC_STUB) diff --git a/DDrawCompat/Gdi/Caret.cpp b/DDrawCompat/Gdi/Caret.cpp index 91ff5e3..37e082d 100644 --- a/DDrawCompat/Gdi/Caret.cpp +++ b/DDrawCompat/Gdi/Caret.cpp @@ -1,11 +1,10 @@ #include -#include "Common/Hook.h" -#include "Common/Time.h" -#include "D3dDdi/ScopedCriticalSection.h" -#include "Gdi/Caret.h" - -extern "C" IMAGE_DOS_HEADER __ImageBase; +#include +#include +#include +#include +#include namespace { @@ -114,14 +113,10 @@ namespace Gdi void installHooks() { - g_caretGeneralEventHook = SetWinEventHook( - EVENT_OBJECT_SHOW, EVENT_OBJECT_HIDE, - reinterpret_cast(&__ImageBase), &caretEvent, - GetCurrentProcessId(), 0, WINEVENT_INCONTEXT); - g_caretLocationChangeEventHook = SetWinEventHook( - EVENT_OBJECT_LOCATIONCHANGE, EVENT_OBJECT_LOCATIONCHANGE, - reinterpret_cast(&__ImageBase), &caretEvent, - GetCurrentProcessId(), 0, WINEVENT_INCONTEXT); + g_caretGeneralEventHook = SetWinEventHook(EVENT_OBJECT_SHOW, EVENT_OBJECT_HIDE, + Dll::g_currentModule, &caretEvent, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT); + g_caretLocationChangeEventHook = SetWinEventHook(EVENT_OBJECT_LOCATIONCHANGE, EVENT_OBJECT_LOCATIONCHANGE, + Dll::g_currentModule, &caretEvent, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT); } void uninstallHooks() diff --git a/DDrawCompat/Gdi/WinProc.cpp b/DDrawCompat/Gdi/WinProc.cpp index 18afe75..4783325 100644 --- a/DDrawCompat/Gdi/WinProc.cpp +++ b/DDrawCompat/Gdi/WinProc.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -16,8 +17,6 @@ #include #include -extern "C" IMAGE_DOS_HEADER __ImageBase; - namespace { const char* PROP_DDRAWCOMPAT = "DDrawCompat"; @@ -316,11 +315,9 @@ namespace Gdi HOOK_FUNCTION(user32, SetWindowPos, setWindowPos); g_objectCreateEventHook = SetWinEventHook(EVENT_OBJECT_CREATE, EVENT_OBJECT_CREATE, - reinterpret_cast(&__ImageBase), &objectCreateEvent, - GetCurrentProcessId(), 0, WINEVENT_INCONTEXT); + Dll::g_currentModule, &objectCreateEvent, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT); g_objectStateChangeEventHook = SetWinEventHook(EVENT_OBJECT_STATECHANGE, EVENT_OBJECT_STATECHANGE, - reinterpret_cast(&__ImageBase), &objectStateChangeEvent, - GetCurrentProcessId(), 0, WINEVENT_INCONTEXT); + Dll::g_currentModule, &objectStateChangeEvent, GetCurrentProcessId(), 0, WINEVENT_INCONTEXT); EnumWindows(initTopLevelWindow, 0); Gdi::Window::updateAll(); diff --git a/DDrawCompat/Gdi/Window.cpp b/DDrawCompat/Gdi/Window.cpp index 56f4dd2..74297d5 100644 --- a/DDrawCompat/Gdi/Window.cpp +++ b/DDrawCompat/Gdi/Window.cpp @@ -7,8 +7,6 @@ #include #include -extern "C" IMAGE_DOS_HEADER __ImageBase; - namespace { const UINT WM_CREATEPRESENTATIONWINDOW = WM_USER; @@ -132,7 +130,7 @@ namespace WNDCLASS wc = {}; wc.lpfnWndProc = &messageWindowProc; - wc.hInstance = reinterpret_cast(&__ImageBase); + wc.hInstance = Dll::g_currentModule; wc.lpszClassName = "DDrawCompatMessageWindow"; RegisterClass(&wc); @@ -329,7 +327,7 @@ namespace Gdi WNDCLASS wc = {}; wc.lpfnWndProc = &presentationWindowProc; - wc.hInstance = reinterpret_cast(&__ImageBase); + wc.hInstance = Dll::g_currentModule; wc.lpszClassName = "DDrawCompatPresentationWindow"; RegisterClass(&wc);