66
77#define IOCTL_POOL_MANAGER_ALLOCATE CTL_CODE (FILE_DEVICE_UNKNOWN, 0x900 , METHOD_BUFFERED, FILE_SPECIAL_ACCESS)
88
9- enum __vmcall_reason
9+ enum vm_call_reasons
1010{
1111 VMCALL_TEST,
1212 VMCALL_VMXOFF,
1313 VMCALL_EPT_HOOK_FUNCTION,
1414 VMCALL_EPT_UNHOOK_FUNCTION,
15- VMCALL_UNHOOK_ALL_PAGES,
1615 VMCALL_INVEPT_CONTEXT,
16+ VMCALL_DUMP_POOL_MANAGER,
17+ VMCALL_DUMP_VMCS_STATE,
18+ VMCALL_HIDE_HV_PRESENCE,
19+ VMCALL_UNHIDE_HV_PRESENCE
1720};
1821
1922enum invept_type
@@ -24,8 +27,6 @@ enum invept_type
2427
2528namespace hv
2629{
27- PDEVICE_OBJECT AirHvDeviceObject = NULL ;
28-
2930 void broadcast_vmoff (KDPC* Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2)
3031 {
3132 UNREFERENCED_PARAMETER (DeferredContext);
@@ -93,6 +94,18 @@ namespace hv
9394 else KeGenericCallDpc (broadcast_invept_single_context, NULL );
9495 }
9596
97+ // / <summary>
98+ // / Set/Unset presence of hypervisor
99+ // / </summary>
100+ // / <param name="value"> If false, hypervisor is not visible via cpuid interface, If true, it become visible</param>
101+ void hypervisor_visible (bool value)
102+ {
103+ if (value == true )
104+ __vm_call (VMCALL_UNHIDE_HV_PRESENCE, 0 , 0 , 0 );
105+ else
106+ __vm_call (VMCALL_HIDE_HV_PRESENCE, 0 , 0 , 0 );
107+ }
108+
96109 // / <summary>
97110 // / Hook function via ept and invalidate ept entries in tlb
98111 // / </summary>
@@ -111,7 +124,6 @@ namespace hv
111124 return status;
112125 }
113126
114-
115127 // / <summary>
116128 // / Hook function via ept and invalidate ept entries in tlb
117129 // / </summary>
@@ -136,62 +148,50 @@ namespace hv
136148 return __vm_call (VMCALL_TEST, 0 , 0 , 0 );
137149 }
138150
139- BOOLEAN PerformAllocation ()
151+ bool send_irp_perform_allocation ()
140152 {
141- NTSTATUS Status;
142- KEVENT Event;
143- PIRP Irp;
144- IO_STATUS_BLOCK ioStatus = { 0 };
153+ PDEVICE_OBJECT airhv_device_object;
154+ NTSTATUS status;
155+ KEVENT event;
156+ PIRP irp;
157+ IO_STATUS_BLOCK io_status = { 0 };
158+ UNICODE_STRING airhv_name;
159+ PFILE_OBJECT file_object;
145160
146- if (AirHvDeviceObject == NULL )
147- {
148- UNICODE_STRING AirHvName;
149- PFILE_OBJECT FileObject;
150- RtlInitUnicodeString (&AirHvName, L" \\ Device\\ airhv" );
161+ RtlInitUnicodeString (&airhv_name, L" \\ Device\\ airhv" );
151162
152- Status = IoGetDeviceObjectPointer (&AirHvName, NULL , &FileObject , &AirHvDeviceObject );
163+ status = IoGetDeviceObjectPointer (&airhv_name, 0 , &file_object , &airhv_device_object );
153164
154- if (NT_SUCCESS (Status) == FALSE )
155- {
156- LogError (" Couldn't get hypervisor device object pointer" );
157- return FALSE ;
158- }
159- }
165+ ObReferenceObjectByPointer (airhv_device_object, FILE_ALL_ACCESS, 0 , KernelMode);
160166
161- KeInitializeEvent (&Event, NotificationEvent, FALSE );
162- __try
163- {
164- Irp = IoBuildDeviceIoControlRequest (IOCTL_POOL_MANAGER_ALLOCATE, AirHvDeviceObject, NULL , NULL , NULL , NULL , FALSE , &Event, &ioStatus);
165- }
166- __except (EXCEPTION_EXECUTE_HANDLER)
167+ // We don't need this so we instantly dereference file object
168+ ObDereferenceObject (file_object);
169+
170+ if (NT_SUCCESS (status) == false )
167171 {
168- ASSERT ( FALSE );
169- return FALSE ;
172+ LogError ( " Couldn't get hypervisor device object pointer " );
173+ return false ;
170174 }
171175
176+ KeInitializeEvent (&event, NotificationEvent, 0 );
177+ irp = IoBuildDeviceIoControlRequest (IOCTL_POOL_MANAGER_ALLOCATE, airhv_device_object, 0 , 0 , 0 , 0 , 0 , &event, &io_status);
172178
173- if (Irp == NULL )
179+ if (irp == NULL )
174180 {
175181 LogError (" Couldn't create Irp" );
176- return FALSE ;
182+ ObDereferenceObject (airhv_device_object);
183+ return false ;
177184 }
178185
179186 else
180187 {
181- Status = IofCallDriver (AirHvDeviceObject, Irp );
188+ status = IofCallDriver (airhv_device_object, irp );
182189
183- if (Status == STATUS_PENDING)
184- {
185- KeWaitForSingleObject (&Event, Executive, KernelMode, FALSE , NULL );
186- Status = ioStatus.Status ;
187- }
190+ if (status == STATUS_PENDING)
191+ KeWaitForSingleObject (&event, Executive, KernelMode, 0 , 0 );
188192
189- return TRUE ;
193+ ObDereferenceObject (airhv_device_object);
194+ return true ;
190195 }
191196 }
192-
193- VOID CloseHandle ()
194- {
195- ObDereferenceObject (AirHvDeviceObject);
196- }
197197}
0 commit comments