Index: minhook/src/hook.c |
— | — | @@ -30,7 +30,8 @@ |
31 | 31 | #define _WIN32_WINNT 0x0501 |
32 | 32 | #include <windows.h> |
33 | 33 | #include <tlhelp32.h> |
34 | | -#include <limits.h> |
| 34 | +#include <limits.h>
|
| 35 | +#include <tchar.h> |
35 | 36 | |
36 | 37 | #include "../include/MinHook.h" |
37 | 38 | #include "buffer.h" |
— | — | @@ -304,6 +305,30 @@ |
305 | 306 | CloseHandle(hSnapshot); |
306 | 307 | } |
307 | 308 | } |
| 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 | +}
|
308 | 333 | |
309 | 334 | //------------------------------------------------------------------------- |
310 | 335 | static VOID Freeze(PFROZEN_THREADS pThreads, UINT pos, UINT action) |
— | — | @@ -318,7 +343,7 @@ |
319 | 344 | UINT i; |
320 | 345 | for (i = 0; i < pThreads->size; ++i) |
321 | 346 | { |
322 | | - HANDLE hThread = OpenThread(THREAD_ACCESS, FALSE, pThreads->pItems[i]); |
| 347 | + HANDLE hThread = _OpenThread(THREAD_ACCESS, FALSE, pThreads->pItems[i]); |
323 | 348 | if (hThread != NULL) |
324 | 349 | { |
325 | 350 | SuspendThread(hThread); |
— | — | @@ -337,7 +362,7 @@ |
338 | 363 | UINT i; |
339 | 364 | for (i = 0; i < pThreads->size; ++i) |
340 | 365 | { |
341 | | - HANDLE hThread = OpenThread(THREAD_ACCESS, FALSE, pThreads->pItems[i]); |
| 366 | + HANDLE hThread = _OpenThread(THREAD_ACCESS, FALSE, pThreads->pItems[i]); |
342 | 367 | if (hThread != NULL) |
343 | 368 | { |
344 | 369 | 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); |