forked from x64dbg/ScyllaHide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHookMain.h
176 lines (144 loc) · 6.24 KB
/
HookMain.h
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#pragma once
#include <ntdll/ntdll.h>
typedef BOOL(WINAPI * t_DllMain)(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);
typedef void (WINAPI * t_GetSystemTime)(LPSYSTEMTIME lpSystemTime); //Kernel32.dll / kernelbase
typedef void (WINAPI * t_GetLocalTime)(LPSYSTEMTIME lpSystemTime); //Kernel32.dll / kernelbase
typedef DWORD(WINAPI * t_timeGetTime)(void); //Winmm.dll -> sometimes GetTickCount
typedef DWORD(WINAPI * t_GetTickCount)(void); //Kernel32.dll / kernelbase
typedef ULONGLONG(WINAPI * t_GetTickCount64)(void);
typedef BOOL(WINAPI * t_QueryPerformanceCounter)(LARGE_INTEGER *lpPerformanceCount); //Kernel32.dll -> ntdll.RtlQueryPerformanceCounter -> NO NATIVE CALL
typedef BOOL(WINAPI * t_QueryPerformanceFrequency)(LARGE_INTEGER *lpFrequency); //kernel32.dll -> ntdll.RtlQueryPerformanceFrequency -> ntdll.ZwQueryPerformanceCounter
typedef DWORD(WINAPI * t_OutputDebugStringA)(LPCSTR lpOutputString); //Kernel32.dll
typedef DWORD(WINAPI * t_OutputDebugStringW)(LPCWSTR lpOutputString); //Kernel32.dll
//WIN 7 X64: OutputDebugStringW -> OutputDebugStringA
#define MAX_NATIVE_HOOKS 32
#pragma pack(push, 1)
typedef struct _HOOK_NATIVE_CALL32 {
DWORD eaxValue;
DWORD ecxValue;
PVOID hookedFunction;
} HOOK_NATIVE_CALL32;
typedef struct _HOOK_DLL_DATA {
HMODULE hDllImage;
BOOLEAN EnablePebBeingDebugged;
BOOLEAN EnablePebHeapFlags;
BOOLEAN EnablePebNtGlobalFlag;
BOOLEAN EnablePebStartupInfo;
BOOLEAN EnablePebOsBuildNumber;
BOOLEAN EnableOutputDebugStringHook;
BOOLEAN EnableNtSetInformationThreadHook;
BOOLEAN EnableNtQuerySystemInformationHook;
BOOLEAN EnableNtQueryInformationProcessHook;
BOOLEAN EnableNtSetInformationProcessHook;
BOOLEAN EnableNtQueryObjectHook;
BOOLEAN EnableNtYieldExecutionHook;
BOOLEAN EnableNtCloseHook;
BOOLEAN EnablePreventThreadCreation;
BOOLEAN EnableNtCreateThreadExHook;
//Protect and Hide Hardware Breakpoints
BOOLEAN EnableNtGetContextThreadHook;
BOOLEAN EnableNtSetContextThreadHook;
BOOLEAN EnableNtContinueHook;
BOOLEAN EnableKiUserExceptionDispatcherHook;
//Native user32.dll/win32u.dll functions
ULONG_PTR NtUserBlockInputVA;
ULONG_PTR NtUserQueryWindowVA;
ULONG_PTR NtUserGetForegroundWindowVA;
ULONG_PTR NtUserBuildHwndListVA;
ULONG_PTR NtUserFindWindowExVA;
ULONG_PTR NtUserGetClassNameVA;
ULONG_PTR NtUserInternalGetWindowTextVA;
ULONG_PTR NtUserGetThreadStateVA;
BOOLEAN EnableNtUserBlockInputHook;
BOOLEAN EnableNtUserQueryWindowHook;
BOOLEAN EnableNtUserGetForegroundWindowHook;
BOOLEAN EnableNtUserBuildHwndListHook;
BOOLEAN EnableNtUserFindWindowExHook;
BOOLEAN EnableNtSetDebugFilterStateHook;
BOOLEAN EnableGetTickCountHook;
BOOLEAN EnableGetTickCount64Hook;
BOOLEAN EnableGetLocalTimeHook;
BOOLEAN EnableGetSystemTimeHook;
BOOLEAN EnableNtQuerySystemTimeHook;
BOOLEAN EnableNtQueryPerformanceCounterHook;
//special
BOOLEAN EnableMalwareRunPeUnpacker;
//t_NtWriteVirtualMemory dNtWriteVirtualMemory;
//DWORD NtWriteVirtualMemoryBackupSize;
t_NtResumeThread dNtResumeThread;
DWORD NtResumeThreadBackupSize;
t_NtSetDebugFilterState dNtSetDebugFilterState;
DWORD NtSetDebugFilterStateBackupSize;
t_NtSetInformationThread dNtSetInformationThread;
DWORD NtSetInformationThreadBackupSize;
t_NtQuerySystemInformation dNtQuerySystemInformation;
DWORD NtQuerySystemInformationBackupSize;
t_NtSetInformationProcess dNtSetInformationProcess;
DWORD NtSetInformationProcessBackupSize;
t_NtQueryInformationProcess dNtQueryInformationProcess;
DWORD NtQueryInformationProcessBackupSize;
t_NtQueryObject dNtQueryObject;
DWORD NtQueryObjectBackupSize;
t_NtYieldExecution dNtYieldExecution;
DWORD NtYieldExecutionBackupSize;
t_NtGetContextThread dNtGetContextThread;
DWORD NtGetContextThreadBackupSize;
t_NtSetContextThread dNtSetContextThread;
DWORD NtSetContextThreadBackupSize;
t_KiUserExceptionDispatcher dKiUserExceptionDispatcher;
DWORD KiUserExceptionDispatcherBackupSize;
t_NtContinue dNtContinue;
DWORD NtContinueBackupSize;
t_NtClose dNtClose;
DWORD NtCloseBackupSize;
t_NtDuplicateObject dNtDuplicateObject;
DWORD NtDuplicateObjectBackupSize;
t_NtCreateThreadEx dNtCreateThreadEx; //only since vista
DWORD NtCreateThreadExBackupSize;
t_NtCreateThread dNtCreateThread;
DWORD NtCreateThreadBackupSize;
/////////////////////////////////////////////////////////
t_GetTickCount dGetTickCount;
DWORD GetTickCountBackupSize;
t_GetTickCount64 dGetTickCount64;
DWORD GetTickCount64BackupSize;
t_GetLocalTime dGetLocalTime;
DWORD GetLocalTimeBackupSize;
t_GetSystemTime dGetSystemTime;
DWORD GetSystemTimeBackupSize;
t_NtQuerySystemTime dNtQuerySystemTime;
DWORD NtQuerySystemTimeBackupSize;
t_NtQueryPerformanceCounter dNtQueryPerformanceCounter;
DWORD NtQueryPerformanceCounterBackupSize;
/////////////////////////////////////////////////////////
t_OutputDebugStringA dOutputDebugStringA;
DWORD OutputDebugStringABackupSize;
t_NtUserBlockInput dNtUserBlockInput;
DWORD NtUserBlockInputBackupSize;
t_NtUserFindWindowEx dNtUserFindWindowEx;
DWORD NtUserFindWindowExBackupSize;
t_NtUserBuildHwndList /*or t_NtUserBuildHwndList_Eight*/ dNtUserBuildHwndList;
DWORD NtUserBuildHwndListBackupSize;
t_NtUserQueryWindow dNtUserQueryWindow;
DWORD NtUserQueryWindowBackupSize;
t_NtUserGetForegroundWindow dNtUserGetForegroundWindow;
DWORD NtUserGetForegroundWindowBackupSize;
t_NtUserQueryWindow NtUserQueryWindow;
t_NtUserGetClassName NtUserGetClassName;
t_NtUserInternalGetWindowText NtUserInternalGetWindowText;
t_NtUserGetThreadState NtUserGetThreadState;
DWORD dwProtectedProcessId;
BOOLEAN EnableProtectProcessId;
BOOLEAN isNtdllHooked;
BOOLEAN isKernel32Hooked;
BOOLEAN isUserDllHooked;
#ifndef _WIN64
HOOK_NATIVE_CALL32 HookNative[MAX_NATIVE_HOOKS];
PVOID NativeCallContinue;
#endif
} HOOK_DLL_DATA;
#pragma pack(pop)
#define HOOK_ERROR_SUCCESS 0
#define HOOK_ERROR_RESOLVE_IMPORT 1
#define HOOK_ERROR_DLLMAIN 2
#define HOOK_ERROR_PEHEADER 3