Bitdefender Hypervisor Memory Introspection
winummodule.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Bitdefender
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #ifndef _WINUMMODULE_H_
6 #define _WINUMMODULE_H_
7 
8 #include "winumcache.h"
9 #include "winvad.h"
10 
11 #define NAMEHASH_NTDLL 0xbe9d4ec5
12 #define NAMEHASH_KERNEL32 0x72f47653
13 #define NAMEHASH_KERNELBASE 0x2945f399
14 #define NAMEHASH_USER32 0xb8d0fd42
15 
16 #define NAMEHASH_WOW64 0xb29d7275
17 #define NAMEHASH_WOW64WIN 0xb3ad9cbb
18 #define NAMEHASH_WOW64CPU 0x824c82be
19 
20 #define NAMEHASH_WS2_32 0x3d20b35c
21 #define NAMEHASH_WININET 0x7350cbf8
22 
23 #define NAMEHASH_VERIFIER 0x3608e61f
24 #define NAMEHASH_APISETSCHEMA 0x6b8a8a45
25 
26 
30 typedef struct _WIN_PROCESS_MODULE
31 {
33 
36 
37  union
38  {
40  struct
41  {
53  DWORD StaticScan: 1;
57  };
58  };
59 
61 
64 
67 
68  void *HookObject;
71 
73 
83 
87 
88  const VAD *Vad;
89 
91 
92 
96 typedef struct _PROTECTED_DLL_INFO
97 {
101 
102 
103 #define MODULE_MATCH(m, p) ((((m)->Path->NameHash == (p)->NameHash)) && \
104  (0 == memcmp((m)->Path->Name, (p)->Name, (m)->Path->NameSize)))
105 
106 
107 //
108 // API
109 //
110 INTSTATUS
112  _In_ WIN_PROCESS_OBJECT *Process,
113  _In_ const VAD *Vad
114  );
115 
116 INTSTATUS
118  _In_ PWIN_PROCESS_OBJECT Process,
119  _In_ PVAD Vad
120  );
121 
122 INTSTATUS
124  _In_opt_ void *Context,
125  _In_ void *Hook,
126  _In_ QWORD Address,
127  _Out_ INTRO_ACTION *Action
128  );
129 
130 INTSTATUS
132  _In_ QWORD Cr3,
133  _In_ QWORD VirtualAddress,
134  _In_ PINSTRUX Instrux,
135  _In_ void *Context
136  );
137 
138 INTSTATUS
140  _In_ PWIN_PROCESS_MODULE Module
141  );
142 
143 INTSTATUS
145  _In_ PWIN_PROCESS_MODULE Module
146  );
147 
148 void
151  );
152 
153 PWIN_PROCESS_MODULE
155  _In_ PWIN_PROCESS_OBJECT Process,
156  _In_ QWORD Gva
157  );
158 
159 INTSTATUS
161  _In_ void *Context,
162  _In_ QWORD Cr3,
163  _In_ QWORD VirtualAddress
164  );
165 
166 INTSTATUS
168  _In_ PWIN_PROCESS_OBJECT Process
169  );
170 
171 #endif // _WINUMMODULE_H_
WINUM_PATH * Path
Module path.
Definition: winummodule.h:62
DWORD Is64BitModule
TRUE if the module is 64 bit.
Definition: winummodule.h:45
#define _In_opt_
Definition: intro_sal.h:16
PBYTE IATBitmap
A bitmap indicating which IAT entries have been initialized.
Definition: winummodule.h:66
#define _Out_
Definition: intro_sal.h:22
_Bool BOOLEAN
Definition: intro_types.h:58
WCHAR * Name
Name.
Definition: winummodule.h:98
#define _In_
Definition: intro_sal.h:21
const VAD * Vad
The VAD which describes this module.
Definition: winummodule.h:88
DWORD ShouldProtHooks
TRUE if the module should be protected against hooks.
Definition: winummodule.h:42
DWORD ShouldGetCache
TRUE if the module headers should be cached.
Definition: winummodule.h:55
INTSTATUS IntWinModHandlePreInjection(void *Context, QWORD Cr3, QWORD VirtualAddress)
Module base page-fault pre-injection callback.
Definition: winummodule.c:1265
DWORD IsSuspicious
TRUE if the module is suspicious.
Definition: winummodule.h:51
Windows process subsystem.
Definition: winprocess.h:54
int INTSTATUS
The status data type.
Definition: introstatus.h:24
DWORD IsProtected
TRUE if the module is actually hooked.
Definition: winummodule.h:46
struct _WIN_PROCESS_MODULE * PWIN_PROCESS_MODULE
BOOLEAN FirstDoubleAgentExecDone
A flag which is set in order to verify if the first execution (for init phase) is done on double agen...
Definition: winummodule.h:80
QWORD VirtualBase
Guest virtual address of the loaded module.
Definition: winummodule.h:34
struct _PROTECTED_DLL_INFO PROTECTED_DLL_INFO
struct _PROTECTED_DLL_INFO * PPROTECTED_DLL_INFO
QWORD SlackSpaceForVerifier
The address between sections on which we put the needed verifier structure on double agent...
Definition: winummodule.h:75
PWIN_PROCESS_MODULE IntWinUmModFindByAddress(PWIN_PROCESS_OBJECT Process, QWORD Gva)
Searches for a user-mode module which contains the indicated guest virtual address.
Definition: winummodule.c:2304
void IntWinModulesChangeProtectionFlags(PWIN_PROCESS_SUBSYSTEM Subsystem)
Change the protection flags applied to the process modules that are currently loaded.
Definition: winummodule.c:2138
DWORD Flags
Raw flags.
Definition: winummodule.h:39
DWORD LoadEventSent
TRUE if the load event has been sent.
Definition: winummodule.h:49
uint8_t * PBYTE
Definition: intro_types.h:47
DWORD DoubleAgentAlertSent
TRUE if a DoubleAgent alert has been sent on this module.
Definition: winummodule.h:56
unsigned long long QWORD
Definition: intro_types.h:53
struct _WIN_PROCESS_MODULE WIN_PROCESS_MODULE
DWORD ShouldProtUnpack
TRUE if the module should be protected against unpack.
Definition: winummodule.h:43
void * SlackSpaceSwapHandle
Swap handle for the slack space page where we put verifier structures.
Definition: winummodule.h:82
void * MainModHeadersSwapHandle
Needed for verifying if the process main module is from the Native subsystem or not (e...
Definition: winummodule.h:86
void * HookObject
Module hook object.
Definition: winummodule.h:68
DWORD UnloadEventSent
TRUE if the unload event has been sent.
Definition: winummodule.h:50
INTSTATUS IntWinModHandleWrite(void *Context, void *Hook, QWORD Address, INTRO_ACTION *Action)
Handle writes inside a protected user-mode module wrapper. Will dispatch appropriately to either the ...
Definition: winummodule.c:1036
void * ModBlockObject
Module load block handle.
Definition: winummodule.h:72
uint16_t WCHAR
Definition: intro_types.h:63
uint32_t DWORD
Definition: intro_types.h:49
INTSTATUS IntWinModPolyHandler(QWORD Cr3, QWORD VirtualAddress, PINSTRUX Instrux, void *Context)
Handle an unpack event for the indicated address.
Definition: winummodule.c:1940
INTSTATUS IntWinModHandleLoadFromVad(WIN_PROCESS_OBJECT *Process, const VAD *Vad)
Handle a module load from a VAD.
Definition: winummodule.c:1587
LIST_ENTRY Link
List entry element.
Definition: winummodule.h:32
enum _INTRO_ACTION INTRO_ACTION
Event actions.
INTSTATUS IntWinProcSendAllDllEventsForProcess(PWIN_PROCESS_OBJECT Process)
Send DLL load events for all modules loaded in all subsystems of a process.
Definition: winummodule.c:198
DWORD UnpackAlertSent
TRUE if unpack alerts have been sent.
Definition: winummodule.h:44
DWORD NameHash
Name hash.
Definition: winummodule.h:99
void * HeadersSwapHandle
Swap handle for the headers.
Definition: winummodule.h:69
WINUM_MODULE_CACHE * Cache
Module headers cache.
Definition: winummodule.h:63
DWORD IATEntries
Number of IAT entries.
Definition: winummodule.h:65
DWORD StaticScan
TRUE if the module was found by statically enumerating process modules.
Definition: winummodule.h:54
INTSTATUS IntWinModRemoveModule(PWIN_PROCESS_MODULE Module)
Removes a Windows module.
Definition: winummodule.c:2043
void * ExportsSwapHandle
Swap handle for the exports.
Definition: winummodule.h:70
PWIN_PROCESS_SUBSYSTEM Subsystem
Module subsystem.
Definition: winummodule.h:60
QWORD AddressOfVerifierData
The address received by DllMain where the pointer to verifier structure should be put...
Definition: winummodule.h:77
INTSTATUS IntWinModUnHookModule(PWIN_PROCESS_MODULE Module)
Remove the protection from the indicated module.
Definition: winummodule.c:1205
A representation of a Windows VAD structure.
Definition: winvad.h:80
DWORD IsMainModule
TRUE if this is the main module.
Definition: winummodule.h:47
DWORD IsSystemModule
TRUE if this is a system module (loaded from system32 or syswow64).
Definition: winummodule.h:48
DWORD Size
Virtual size of the module.
Definition: winummodule.h:35
INTSTATUS IntWinModHandleUnloadFromVad(PWIN_PROCESS_OBJECT Process, PVAD Vad)
Handle a module unload.
Definition: winummodule.c:1762
This structure describes a running process inside the guest.
Definition: winprocess.h:83