From 6c3049c3dcc1f7e11af927e607c6176eeae0ef28 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sun, 1 Mar 2015 21:57:53 +0100 Subject: [PATCH] Added functions to disable/re-enable WOW64 filesystem redirection. --- include/MUtils/OSSupport.h | 5 +++ src/OSSupport_Win32.cpp | 72 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/include/MUtils/OSSupport.h b/include/MUtils/OSSupport.h index 696a065..f8eef72 100644 --- a/include/MUtils/OSSupport.h +++ b/include/MUtils/OSSupport.h @@ -163,8 +163,13 @@ namespace MUtils MUTILS_API bool setup_timer_resolution(const quint32 &interval = 1); MUTILS_API bool reset_timer_resolution(const quint32 &interval = 1); + //Keyboard support MUTILS_API bool check_key_state_esc(void); + //WOW64 redirection + MUTILS_API bool wow64fsredir_disable(void *oldValue); + MUTILS_API bool wow64fsredir_revert (void *oldValue); + //Check if debugger is present MUTILS_API void check_debugger(void); diff --git a/src/OSSupport_Win32.cpp b/src/OSSupport_Win32.cpp index 22843cb..e461034 100644 --- a/src/OSSupport_Win32.cpp +++ b/src/OSSupport_Win32.cpp @@ -1046,6 +1046,78 @@ bool MUtils::OS::check_key_state_esc(void) return (GetAsyncKeyState(VK_ESCAPE) & 0x0001) != 0; } +/////////////////////////////////////////////////////////////////////////////// +// WOW64 REDIRECTION +/////////////////////////////////////////////////////////////////////////////// + +typedef BOOL (_stdcall *Wow64DisableWow64FsRedirectionFun)(void *OldValue); +typedef BOOL (_stdcall *Wow64RevertWow64FsRedirectionFun )(void *OldValue); + +static QReadWriteLock g_wow64redir_lock; +static QScopedPointer g_wow64redir_kernel32; +static Wow64DisableWow64FsRedirectionFun g_wow64redir_disable = NULL; +static Wow64RevertWow64FsRedirectionFun g_wow64redir_revert = NULL; + +static bool wow64fsredir_init() +{ + QWriteLocker writeLock(&g_wow64redir_lock); + if(g_wow64redir_disable && g_wow64redir_revert) + { + return true; /*already initialized*/ + } + + if(g_wow64redir_kernel32.isNull()) + { + g_wow64redir_kernel32.reset(new QLibrary("kernel32.dll")); + } + + if(!g_wow64redir_kernel32->isLoaded()) + { + if(!g_wow64redir_kernel32->load()) + { + return false; /*faild to load kernel32.dll*/ + } + } + + g_wow64redir_disable = (Wow64DisableWow64FsRedirectionFun) g_wow64redir_kernel32->resolve("Wow64DisableWow64FsRedirection"); + g_wow64redir_revert = (Wow64RevertWow64FsRedirectionFun) g_wow64redir_kernel32->resolve("Wow64RevertWow64FsRedirection"); + + return (g_wow64redir_disable && g_wow64redir_revert); +} + +#define WOW64FSREDIR_INIT(RDLOCK) do \ +{ \ + while(!(g_wow64redir_disable && g_wow64redir_revert)) \ + { \ + (RDLOCK).unlock(); \ + if(!wow64fsredir_init()) return false; \ + (RDLOCK).relock(); \ + } \ +} \ +while(0) + +bool MUtils::OS::wow64fsredir_disable(void *oldValue) +{ + QReadLocker readLock(&g_wow64redir_lock); + WOW64FSREDIR_INIT(readLock); + if(g_wow64redir_disable(oldValue)) + { + return true; + } + return false; +} + +bool MUtils::OS::wow64fsredir_revert(void *oldValue) +{ + QReadLocker readLock(&g_wow64redir_lock); + WOW64FSREDIR_INIT(readLock); + if(g_wow64redir_revert(oldValue)) + { + return true; + } + return false; +} + /////////////////////////////////////////////////////////////////////////////// // DEBUGGER CHECK ///////////////////////////////////////////////////////////////////////////////