Bitdefender Hypervisor Memory Introspection
winumcache.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Bitdefender
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #ifndef _WINUM_CACHE_H_
6 #define _WINUM_CACHE_H_
7 
8 #include "introcrt.h"
9 
11 
13 #define MAX_OFFSETS_PER_NAME 10
14 
15 
19 typedef struct _WINUM_CACHE_EXPORT
20 {
22 
28 
33 
34 
39 {
40  union
41  {
42  struct
43  {
49  };
50 
51  DWORD FuncArray[5];
52  };
54 
55 
59 typedef struct _WINUM_CACHE_EXPORTS
60 {
63 
66 
69 
71 
72 
76 typedef struct _WINUM_MODULE_CACHE
77 {
79 
81 
82  struct
83  {
86 
89 
92  } Info;
93 
96 
98 
100 
103 
107 
109 
110 
112 #define WINUMCACHE_MAX_EXPORTS 10000u
113 
114 
115 //
116 // API
117 //
118 INTSTATUS
120  _In_ WIN_PROCESS_MODULE *Module,
121  _In_reads_bytes_(4096) BYTE *Headers
122  );
123 
124 void
126  _In_ WIN_PROCESS_MODULE *Module
127  );
128 
129 void
131  _In_ WINUM_MODULE_CACHE *Cache
132  );
133 
134 void
136  void
137  );
138 
141  _In_ WIN_PROCESS_MODULE *Module,
142  _In_ DWORD Rva,
143  _In_ DWORD ErrorRange
144  );
145 
146 BOOLEAN
148  _In_ WIN_PROCESS_MODULE *Module
149  );
150 
153  _In_ WIN_PROCESS_MODULE *Module,
154  _In_ QWORD Gva,
155  _In_ DWORD Length
156  );
157 
158 #endif // _WINUM_CACHE_H_
BOOLEAN ExportDirRead
True if the exports directory has been read.
Definition: winumcache.h:101
RBTREE Tree
The RB tree containing all the exports (WINUM_CACHE_EXPORT entries).
Definition: winumcache.h:61
_Bool BOOLEAN
Definition: intro_types.h:58
uint8_t BYTE
Definition: intro_types.h:47
DWORD IatSize
Size of the imports table.
Definition: winumcache.h:88
#define _In_
Definition: intro_sal.h:21
BOOLEAN MemoryFuncsRead
True if the memory functions have been identified.
Definition: winumcache.h:102
struct _WINUM_CACHE_EXPORTS WINUM_CACHE_EXPORTS
struct _WINUM_CACHE_EXPORTS * PWINUM_CACHE_EXPORTS
void IntWinUmModCacheRelease(WINUM_MODULE_CACHE *Cache)
Removes a module cache, if it was written (it's dirty).
Definition: winumcache.c:1000
DWORD StartNames
First RVA pointing to the exported names.
Definition: winumcache.h:67
DWORD NumberOfOffsets
Number of symbols pointing to the exported RVA.
Definition: winumcache.h:27
Definition: rbtree.h:34
struct _WINUM_CACHE_MEMORY_FUNCS * PWINUM_CACHE_MEMORY_FUNCS
int INTSTATUS
The status data type.
Definition: introstatus.h:24
DWORD EatRva
RVA of the exports table.
Definition: winumcache.h:84
DWORD EndNames
Last RVA pointing to the exported names.
Definition: winumcache.h:68
WINUM_CACHE_EXPORT * IntWinUmModCacheExportFind(WIN_PROCESS_MODULE *Module, DWORD Rva, DWORD ErrorRange)
Tries to find an export in the range [Rva, Rva + ErrorRange].
Definition: winumcache.c:262
struct _WINUM_MODULE_CACHE WINUM_MODULE_CACHE
WINUM_CACHE_MEMORY_FUNCS MemFuncs
Memory related functions RVAs.
Definition: winumcache.h:95
WINUM_CACHE_EXPORT * Array
The array of WINUM_CACHE_EXPORT entries.
Definition: winumcache.h:62
struct _WINUM_MODULE_CACHE * PWINUM_MODULE_CACHE
BOOLEAN Wow64
True if this module is Wow64.
Definition: winumcache.h:99
unsigned long long QWORD
Definition: intro_types.h:53
DWORD MemmoveSRva
RVA of the memmoves function.
Definition: winumcache.h:47
struct _WINUM_CACHE_EXPORT * PWINUM_CACHE_EXPORT
LIST_ENTRY Link
Link inside the global list of module caches.
Definition: winumcache.h:78
DWORD MemmoveRva
RVA of the memmove function.
Definition: winumcache.h:46
DWORD MemcpyRva
RVA of the memcpy function.
Definition: winumcache.h:44
DWORD TimeDateStamp
Module time & date stamp.
Definition: winumcache.h:90
char * PCHAR
Definition: intro_types.h:56
struct _WINUM_CACHE_EXPORT WINUM_CACHE_EXPORT
DWORD NameOffsets[MAX_OFFSETS_PER_NAME]
Name RVAs pointing to this exported RVA.
Definition: winumcache.h:26
void IntWinUmModCacheGet(WIN_PROCESS_MODULE *Module)
Initializes the cache for the provided module.
Definition: winumcache.c:936
DWORD Rva
The RVA of this export.
Definition: winumcache.h:23
BOOLEAN IntWinUmCacheIsExportDirRead(WIN_PROCESS_MODULE *Module)
Checks if the exports directory of the given module has been read.
Definition: winumcache.c:1063
uint32_t DWORD
Definition: intro_types.h:49
DWORD MemcpySRva
RVA of the memcpys function.
Definition: winumcache.h:45
DWORD EatSize
Size of the exports table.
Definition: winumcache.h:85
DWORD NameHashes[MAX_OFFSETS_PER_NAME]
Hashes of the names pointing to this RVA.
Definition: winumcache.h:24
#define _In_reads_bytes_(expr)
Definition: intro_sal.h:25
DWORD SizeOfImage
Size of image.
Definition: winumcache.h:91
Definition: rbtree.h:84
DWORD NameLens[MAX_OFFSETS_PER_NAME]
Length of each name pointing to this RVA.
Definition: winumcache.h:25
DWORD MemsetRva
RVA of the memset function.
Definition: winumcache.h:48
#define MAX_OFFSETS_PER_NAME
We can have up to this many exports pointing to the same RVA.
Definition: winumcache.h:13
BOOLEAN Dirty
True if this caches was created for a module loaded by a statically detected process. Dirty caches are NOT reused by other loaded modules, and they will be destroyed when the module is unloaded.
Definition: winumcache.h:106
WINUM_CACHE_EXPORT * IntWinUmCacheGetExportFromRange(WIN_PROCESS_MODULE *Module, QWORD Gva, DWORD Length)
Tries to find an export in the range [Gva - Length, Gva].
Definition: winumcache.c:225
RBNODE RbNode
RB tree node entry.
Definition: winumcache.h:21
PCHAR Names[MAX_OFFSETS_PER_NAME]
The names pointing to this RVA. Each name will point inside the Names structure inside WINUM_CACHE_EX...
Definition: winumcache.h:31
void IntWinUmCacheUninit(void)
Uninit the module cache system. This will remove all cache entries. Use this during Introcore uninit...
Definition: winumcache.c:1082
struct _WINUM_CACHE_MEMORY_FUNCS WINUM_CACHE_MEMORY_FUNCS
INTSTATUS IntWinUmModCacheSetHeaders(WIN_PROCESS_MODULE *Module, BYTE *Headers)
Sets the MZ/PE headers in the cache of a given module.
Definition: winumcache.c:1025
DWORD IatRva
RVA of the imports table.
Definition: winumcache.h:87
BYTE * Headers
A buffer containing the MZ/PE headers of this module.
Definition: winumcache.h:97
WINUM_CACHE_EXPORTS Exports
The exports cache.
Definition: winumcache.h:94
DWORD ModuleNameHash
The hash on the name of the cached module.
Definition: winumcache.h:80
PCHAR Names
A pointer to a contiguous memory area containing all the exported names.
Definition: winumcache.h:65