DXGL r870 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r869‎ | r870 | r871 >
Date:00:17, 28 September 2018
Author:admin
Status:new
Tags:
Comment:
Dynamically link OpenThread in libminhook. First of two changes to attempt Win9x compatibility.
Modified paths:
  • /minhook/src/hook.c (modified) (history)
  • /minhook/src/hook.c.diff (added) (history)

Diff [purge]

Index: minhook/src/hook.c
@@ -30,7 +30,8 @@
3131 #define _WIN32_WINNT 0x0501
3232 #include <windows.h>
3333 #include <tlhelp32.h>
34 -#include <limits.h>
 34+#include <limits.h>
 35+#include <tchar.h>
3536
3637 #include "../include/MinHook.h"
3738 #include "buffer.h"
@@ -304,6 +305,30 @@
305306 CloseHandle(hSnapshot);
306307 }
307308 }
 309+
 310+static HANDLE(WINAPI *__OpenThread)(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwThreadId) = NULL;
 311+static BOOL OpenThreadFail = FALSE;
 312+static HANDLE WINAPI _OpenThread(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwThreadId)
 313+{
 314+ HANDLE hKernel32;
 315+ if (!__OpenThread)
 316+ {
 317+ if (OpenThreadFail) return NULL;
 318+ hKernel32 = GetModuleHandle(_T("kernel32.dll"));
 319+ if (!hKernel32)
 320+ {
 321+ OpenThreadFail = TRUE;
 322+ return NULL;
 323+ }
 324+ __OpenThread = GetProcAddress(hKernel32, "OpenThread");
 325+ if (!__OpenThread)
 326+ {
 327+ OpenThreadFail = TRUE;
 328+ return NULL;
 329+ }
 330+ }
 331+ return __OpenThread(dwDesiredAccess, bInheritHandle, dwThreadId);
 332+}
308333
309334 //-------------------------------------------------------------------------
310335 static VOID Freeze(PFROZEN_THREADS pThreads, UINT pos, UINT action)
@@ -318,7 +343,7 @@
319344 UINT i;
320345 for (i = 0; i < pThreads->size; ++i)
321346 {
322 - HANDLE hThread = OpenThread(THREAD_ACCESS, FALSE, pThreads->pItems[i]);
 347+ HANDLE hThread = _OpenThread(THREAD_ACCESS, FALSE, pThreads->pItems[i]);
323348 if (hThread != NULL)
324349 {
325350 SuspendThread(hThread);
@@ -337,7 +362,7 @@
338363 UINT i;
339364 for (i = 0; i < pThreads->size; ++i)
340365 {
341 - HANDLE hThread = OpenThread(THREAD_ACCESS, FALSE, pThreads->pItems[i]);
 366+ HANDLE hThread = _OpenThread(THREAD_ACCESS, FALSE, pThreads->pItems[i]);
342367 if (hThread != NULL)
343368 {
344369 ResumeThread(hThread);
Index: minhook/src/hook.c.diff
@@ -0,0 +1,63 @@
 2+Index: hook.c
 3+===================================================================
 4+--- hook.c (revision 836)
 5+@@ -30,7 +30,8 @@
 6+ #define _WIN32_WINNT 0x0501
 7+ #include <windows.h>
 8+ #include <tlhelp32.h>
 9+-#include <limits.h>
 10++#include <limits.h>
 11++#include <tchar.h>
 12+
 13+ #include "../include/MinHook.h"
 14+ #include "buffer.h"
 15+@@ -304,6 +305,30 @@
 16+ CloseHandle(hSnapshot);
 17+ }
 18+ }
 19++
 20++static HANDLE(WINAPI *__OpenThread)(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwThreadId) = NULL;
 21++static BOOL OpenThreadFail = FALSE;
 22++static HANDLE WINAPI _OpenThread(DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwThreadId)
 23++{
 24++ HANDLE hKernel32;
 25++ if (!__OpenThread)
 26++ {
 27++ if (OpenThreadFail) return NULL;
 28++ hKernel32 = GetModuleHandle(_T("kernel32.dll"));
 29++ if (!hKernel32)
 30++ {
 31++ OpenThreadFail = TRUE;
 32++ return NULL;
 33++ }
 34++ __OpenThread = GetProcAddress(hKernel32, "OpenThread");
 35++ if (!__OpenThread)
 36++ {
 37++ OpenThreadFail = TRUE;
 38++ return NULL;
 39++ }
 40++ }
 41++ return __OpenThread(dwDesiredAccess, bInheritHandle, dwThreadId);
 42++}
 43+
 44+ //-------------------------------------------------------------------------
 45+ static VOID Freeze(PFROZEN_THREADS pThreads, UINT pos, UINT action)
 46+@@ -318,7 +343,7 @@
 47+ UINT i;
 48+ for (i = 0; i < pThreads->size; ++i)
 49+ {
 50+- HANDLE hThread = OpenThread(THREAD_ACCESS, FALSE, pThreads->pItems[i]);
 51++ HANDLE hThread = _OpenThread(THREAD_ACCESS, FALSE, pThreads->pItems[i]);
 52+ if (hThread != NULL)
 53+ {
 54+ SuspendThread(hThread);
 55+@@ -337,7 +362,7 @@
 56+ UINT i;
 57+ for (i = 0; i < pThreads->size; ++i)
 58+ {
 59+- HANDLE hThread = OpenThread(THREAD_ACCESS, FALSE, pThreads->pItems[i]);
 60++ HANDLE hThread = _OpenThread(THREAD_ACCESS, FALSE, pThreads->pItems[i]);
 61+ if (hThread != NULL)
 62+ {
 63+ ResumeThread(hThread);