-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathHideThreadFromDebugger.cpp
More file actions
29 lines (21 loc) · 1.01 KB
/
Copy pathHideThreadFromDebugger.cpp
File metadata and controls
29 lines (21 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "HideThreadFromDebugger.h"
typedef BOOL (WINAPI *ZWSETINFORMATIONTHREAD)(HANDLE, THREAD_INFORMATION_CLASS, PVOID, ULONG);
// Pointer for calling original function
ZWSETINFORMATIONTHREAD fpZwSetInformationThread = NULL;
// Detour function
INT WINAPI tZwSetInformationThread(HANDLE threadHandle, THREAD_INFORMATION_CLASS threadInfoClass, PVOID threadInfo, ULONG threadInfoLength)
{
if (threadInfoClass == 0x11) // ThreadHideFromDebugger
{
return 0x1; // return STATUS_SUCCESS as if we set the ThreadHideFromDebugger flag
}
return fpZwSetInformationThread(threadHandle, threadInfoClass, threadInfo, threadInfoLength); // return the original function if any other info class
}
BOOL BypassHideThreadFromDebugger()
{
if (MH_CreateHookApi(L"ntdll", "NtSetInformationThread", &tZwSetInformationThread, reinterpret_cast<LPVOID*>(&fpZwSetInformationThread)) != MH_OK)
return false;
if (MH_EnableHook((LPVOID)GetProcAddress(GetModuleHandleW(L"ntdll"), "NtSetInformationThread")) != MH_OK)
return false;
return true;
}