Bitdefender Hypervisor Memory Introspection
winagent.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Bitdefender
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 #ifndef _WIN_AGENT_H_
6 #define _WIN_AGENT_H_
7 
8 #include "aghcall.h"
9 #include "agent.h"
10 
12 #define MAX_BOOTSTRAP_SIZE 512u
13 
17 #define AG_OPT_INJECT_ON_RIP_POWSTATE_CHANGE 0x00000001
18 
19 
32 typedef INTSTATUS
34  _In_ QWORD GuestVirtualAddress,
35  _In_ DWORD AgentTag,
36  _In_opt_ void *Context
37  );
38 
39 
55 typedef INTSTATUS
57  _In_ QWORD GuestVirtualAddress,
58  _In_ DWORD ErrorCode,
59  _In_ DWORD AgentTag,
60  _In_opt_ void *Context
61  );
62 
63 
76 typedef QWORD
78  _In_ QWORD GuestVirtualAddress,
79  _In_ DWORD MaxSize,
80  _In_opt_ void *Context
81  );
82 
83 
87 typedef enum _AGENT_HCALL
88 {
91 } AGENT_HCALL;
92 
93 
94 
98 typedef struct _WIN_AGENT
99 {
101 
103  AGENT_HCALL HcallType;
104 
108  void *Context;
109 
110  // Bootstrap related.
113 
114  // Driver related.
118 
121 
125 
128 
133 
134  // Agent related.
140 
143  DWORD Pid;
147 
149 
152 
154 
156 
158 
159 
160 //
161 // API
162 //
163 BOOLEAN
165  _In_ QWORD Rip
166  );
167 
168 INTSTATUS
170  _In_ QWORD Rip
171  );
172 
173 INTSTATUS
175  _In_ QWORD Rip,
176  _In_ DWORD CpuNumber
177  );
178 
179 INTSTATUS
184  _In_opt_ void *Context,
188  _In_ DWORD AgentTag,
190  _In_opt_z_ const CHAR *Name,
192  _In_opt_ const CHAR *Args,
194  _Outptr_opt_ PWIN_AGENT *Agent
195  );
196 
197 INTSTATUS
200  _In_opt_ void *Context,
201  _Outptr_opt_ PWIN_AGENT *Agent
202  );
203 
204 INTSTATUS
206  void
207  );
208 
209 INTSTATUS
211  void
212  );
213 
214 void
216  _In_ CHAR *ImageName,
217  _Out_ BOOLEAN *IsAgent,
218  _Out_ DWORD *Tag
219  );
220 
221 void
223  _In_ CHAR *ImageName,
224  _Out_opt_ BOOLEAN *IsAgent,
225  _Out_opt_ DWORD *Tag,
226  _Out_opt_ BOOLEAN *Removed
227  );
228 
229 void
231  _In_ DWORD Counter,
232  _Out_opt_ DWORD *Tag
233  );
234 
235 void
237  void
238  );
239 
240 BOOLEAN
242  _In_ QWORD Ptr,
243  _In_ THS_PTR_TYPE Type
244  );
245 
248  _Out_opt_ DWORD *Tag
249  );
250 
251 INTSTATUS
253  void
254  );
255 
256 void
258  void
259  );
260 
261 INTSTATUS
263  void
264  );
265 
266 #endif // _WIN_AGENT_H_
INTSTATUS IntWinAgentUnInit(void)
Uninit the agents state.
Definition: winagent.c:3352
#define _In_opt_
Definition: intro_sal.h:16
struct _WIN_AGENT * PWIN_AGENT
AG_WAITSTATE IntWinAgentGetState(DWORD *Tag)
Gets the global agents state.
Definition: winagent.c:3245
#define _Out_
Definition: intro_sal.h:22
_Bool BOOLEAN
Definition: intro_types.h:58
INTSTATUS IntWinAgentHandleInt3(QWORD Rip, DWORD CpuNumber)
Handle a breakpoint that was initiated inside the guest.
Definition: winagent.c:2273
BOOLEAN InstructionRestored
True if the detours instruction has been restored.
Definition: winagent.h:131
uint8_t BYTE
Definition: intro_types.h:47
#define _In_
Definition: intro_sal.h:21
DWORD AgentTag
Agent tag.
Definition: winagent.h:119
uint16_t WORD
Definition: intro_types.h:48
INTSTATUS IntWinAgentEnableInjection(void)
enables agent injections.
Definition: winagent.c:3010
DWORD Options
Agent options.
Definition: winagent.h:155
BYTE BootStrap[MAX_BOOTSTRAP_SIZE]
The bootstrap code.
Definition: winagent.h:153
QWORD DriverAddress
Address of the boot driver.
Definition: winagent.h:115
void IntWinAgentDisablePendingAgents(void)
Disables all pending agents.
Definition: winagent.c:3291
void IntWinAgentInit(void)
Initialize the agents state.
Definition: winagent.c:3333
#define IG_MAX_AGENT_NAME_LENGTH
Definition: glueiface.h:1712
struct _WIN_AGENT WIN_AGENT
DWORD DriverEntryPoint
Entry point of the boot driver.
Definition: winagent.h:117
QWORD BootstrapAddress
Address where the bootstrap was allocated.
Definition: winagent.h:111
BYTE InstructionLen
Detoured instruction length.
Definition: winagent.h:130
PFUNC_AgentCompletion CompletionCallback
Completion callback.
Definition: winagent.h:107
#define _Outptr_opt_
Definition: intro_sal.h:39
int INTSTATUS
The status data type.
Definition: introstatus.h:24
enum _AGENT_HCALL AGENT_HCALL
QWORD Token2
Token used by the bootstrap code.
Definition: winagent.h:123
PBYTE AgentContent
Agent contents. Can be a file, process, driver, etc.
Definition: winagent.h:135
DWORD ErrorCode
Definition: winagent.h:142
DWORD Agid
Agent ID. Unique for each injected agent.
Definition: winagent.h:141
void IntWinAgentCheckIfProcessAgentAndIncrement(CHAR *ImageName, BOOLEAN *IsAgent, DWORD *Tag)
Checks if a process is an agent or not, and increments the ref count of that name.
Definition: winagent.c:3028
#define MAX_BOOTSTRAP_SIZE
Maximum size of the bootstrap code.
Definition: winagent.h:12
CHAR Name[IG_MAX_AGENT_NAME_LENGTH]
Agent name.
Definition: winagent.h:148
#define _Out_opt_
Definition: intro_sal.h:30
CHAR Args[IG_MAX_COMMAND_LINE_LENGTH]
Agent arguments.
Definition: winagent.h:146
uint8_t * PBYTE
Definition: intro_types.h:47
void * Context
Optional context. Passed along to the 3 callbacks above.
Definition: winagent.h:108
INTSTATUS(* PFUNC_AgentCompletion)(QWORD GuestVirtualAddress, DWORD ErrorCode, DWORD AgentTag, void *Context)
Completion callback.
Definition: winagent.h:56
unsigned long long QWORD
Definition: intro_types.h:53
#define IG_MAX_COMMAND_LINE_LENGTH
Definition: glueiface.h:1711
DWORD BootstrapSize
The size of the bootstrap.
Definition: winagent.h:112
This file contains the private, undocumented hypercalls. They are used only by the loaders and the ag...
INTSTATUS(* PFUNC_AgentInjection)(QWORD GuestVirtualAddress, DWORD AgentTag, void *Context)
Injection callback.
Definition: winagent.h:33
AGENT_HCALL HcallType
Hyper call type.
Definition: winagent.h:103
SIZE_T ArgsLen
Length of the arguments.
Definition: winagent.h:145
PFUNC_AgentDeliver DeliverCallback
Delivery callback.
Definition: winagent.h:106
QWORD Token3
Token used by the bootstrap code.
Definition: winagent.h:124
#define _In_opt_z_
Definition: intro_sal.h:18
INTSTATUS IntWinAgentInject(PFUNC_AgentInjection InjectionCallback, PFUNC_AgentCompletion CompletionCallback, PFUNC_AgentDeliver DeliverCallback, void *Context, PBYTE AgentContent, DWORD AgentSize, BOOLEAN AgentInternal, DWORD AgentTag, AGENT_TYPE AgentType, const CHAR *Name, DWORD Options, const CHAR *Args, DWORD Pid, PWIN_AGENT *Agent)
Schedule an agent injection inside the guest.
Definition: winagent.c:2608
Hyper call using INT3.
Definition: winagent.h:90
enum _AGENT_TYPE AGENT_TYPE
DWORD AgentPosition
Current pointer inside the agent, used to track which chunk must be injected inside the guest...
Definition: winagent.h:138
WORD OffsetJumpBack
Offset of the trampoline code which jumps back to the detoured instruction.
Definition: winagent.h:151
uint32_t DWORD
Definition: intro_types.h:49
Hyper call using VMCALL.
Definition: winagent.h:89
BOOLEAN AgentInternal
True if the agent is internal to Introcore.
Definition: winagent.h:139
BYTE InstructionBytes[16]
Detoured instruction bytes.
Definition: winagent.h:129
AGENT_TYPE AgentType
Agent type.
Definition: winagent.h:102
THS_PTR_TYPE
The type of pointer to be checked.
DWORD Flags
Agent flags & state.
Definition: winagent.h:120
void IntWinAgentCheckIfProcessAgentAndDecrement(CHAR *ImageName, BOOLEAN *IsAgent, DWORD *Tag, BOOLEAN *Removed)
Checks if a process is an agent or not, and decrements the ref count of that name.
Definition: winagent.c:3084
BOOLEAN IntWinAgentIsRipInsideCurrentAgent(QWORD Rip)
Return true if the given RIP points inside the currently active boot driver.
Definition: winagent.c:197
INTSTATUS IntWinAgentInjectBreakpoint(PFUNC_AgentInjection InjectionCallback, void *Context, PWIN_AGENT *Agent)
Injects a breakpoint agent inside the guest.
Definition: winagent.c:2921
DWORD Pid
PID of the process that will be the parent of the injected process.
Definition: winagent.h:144
void IntWinAgentRemoveEntryByAgid(DWORD Counter, DWORD *Tag)
Removes an agent name from the list of names, using the ID.
Definition: winagent.c:3171
LIST_ENTRY Link
List entry element.
Definition: winagent.h:100
INTSTATUS IntWinAgentHandleVmcall(QWORD Rip)
Handle a VMCALL that was executed inside the guest.
Definition: winagent.c:2397
DWORD AgentSize
Definition: winagent.h:136
QWORD(* PFUNC_AgentDeliver)(QWORD GuestVirtualAddress, DWORD MaxSize, void *Context)
Called for VE and PT initialization.
Definition: winagent.h:77
void * BootCloakRegion
Cloak handle used to hide the bootstrap code.
Definition: winagent.h:127
_AGENT_HCALL
Definition: winagent.h:87
enum _AG_WAITSTATE AG_WAITSTATE
BOOLEAN IntWinAgentIsPtrInTrampoline(QWORD Ptr, THS_PTR_TYPE Type)
Check if the provided address points inside the agent trampoline.
Definition: winagent.c:3219
char CHAR
Definition: intro_types.h:56
INTSTATUS IntWinAgentInjectTrampoline(void)
Inject the agent trampoline inside the guest.
Definition: winagent.c:364
QWORD Token1
Token used by the bootstrap code.
Definition: winagent.h:122
void * InsCloakRegion
Cloak handle used to hide the detoured instruction.
Definition: winagent.h:126
QWORD InstructionAddress
Address of the detoured instruction.
Definition: winagent.h:132
DWORD DriverSize
Size of the boot driver.
Definition: winagent.h:116
INTSTATUS IntWinAgentActivatePendingAgent(void)
Activates a pending agent that waits to be injected.
Definition: winagent.c:920
size_t SIZE_T
Definition: intro_types.h:60
PFUNC_AgentInjection InjectionCallback
Injection callback.
Definition: winagent.h:105