├── hypervisor-interactor ├── vmmintr.c ├── x86_64.h ├── vmmintr_asm.asm ├── types.h ├── hwstatus.h ├── utils.h ├── drvops.h ├── vmmintr.h ├── hwtypes.h ├── hypervisor-interactor.vcxproj.filters ├── drventry.c ├── hypervisor-interactor.inf ├── drvops.c └── hypervisor-interactor.vcxproj ├── .gitattributes ├── hypervisor-interactor.sln └── .gitignore /hypervisor-interactor/vmmintr.c: -------------------------------------------------------------------------------- 1 | #include "vmmintr.h" 2 | 3 | HWSTATUS ComSendSignal(IN DWORD64 CommunicationOffset) 4 | { 5 | return HyperWinVmCall(VMCALL_COMMUNICATION_BLOCK, CommunicationOffset); 6 | } -------------------------------------------------------------------------------- /hypervisor-interactor/x86_64.h: -------------------------------------------------------------------------------- 1 | #ifndef __HYPERWIN_X86_64_H_ 2 | #define __HYPERWIN_X86_64_H_ 3 | 4 | #define PAGE_SIZE 0x1000 5 | #define LARGE_PAGE_SIZE 0x200000 6 | #define LARGE_PAGE_MASK 0x1fffffULL 7 | 8 | #endif -------------------------------------------------------------------------------- /hypervisor-interactor/vmmintr_asm.asm: -------------------------------------------------------------------------------- 1 | PUBLIC HyperWinVmCall 2 | .code _text 3 | 4 | HyperWinVmCall PROC PUBLIC 5 | 6 | mov rax, rcx 7 | mov rbx, rdx 8 | 9 | vmcall 10 | 11 | ret 12 | HyperWinVmCall ENDP 13 | 14 | END -------------------------------------------------------------------------------- /hypervisor-interactor/types.h: -------------------------------------------------------------------------------- 1 | #ifndef __HV_TYPES_H_ 2 | #define __HV_TYPES_H_ 3 | 4 | typedef unsigned long long QWORD, *QWORD_PTR; 5 | /* typedef unsigned int DWORD, *DWORD_PTR; 6 | typedef unsigned short WORD, *DWORD_PTR; */ 7 | typedef unsigned char BYTE, *BYTE_PTR; 8 | 9 | #endif -------------------------------------------------------------------------------- /hypervisor-interactor/hwstatus.h: -------------------------------------------------------------------------------- 1 | #ifndef __HYPERWIN_STATUS_H_ 2 | #define __HYPERWIN_STATUS_H_ 3 | 4 | /* HyperWin OPERATION codes 5 | (The rest are defined in user-mode) */ 6 | #define OPERATION_COMPLETED 0x444f4e45 7 | 8 | 9 | /* HyperWin status codes */ 10 | 11 | #define HYPERWIN_STATUS_SUCCUESS 0 12 | #define HYPERWIN_INIT_FAILED 1 13 | 14 | #endif -------------------------------------------------------------------------------- /hypervisor-interactor/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef __HYPERWIN_UTILS_H_ 2 | #define __HYPERWINS_UTILS_H_ 3 | 4 | #include 5 | 6 | #define hvPrint(format, ...) DbgPrint("HyperWin :: " \ 7 | format, \ 8 | __VA_ARGS__) 9 | #define DEBUG_LEVEL_INFO 1 10 | #define DEBUG_LEVEL_WARNING 2 11 | #define DEBUG_LEVEL_DEBUG 3 12 | 13 | #define DEBUG_LEVEL DEBUG_LEVEL_DEBUG 14 | 15 | #endif -------------------------------------------------------------------------------- /hypervisor-interactor/drvops.h: -------------------------------------------------------------------------------- 1 | #ifndef __HYPERWIN_DRVOPS_H_ 2 | #define __HYPERWIN_DRVOPS_H_ 3 | 4 | #include 5 | 6 | NTSTATUS HyperWinCreate(IN PDEVICE_OBJECT pDeviceObj, IN PIRP Irp); 7 | NTSTATUS HyperWinDeviceIoControl(IN PDEVICE_OBJECT pDeviceObj, IN PIRP Irp); 8 | NTSTATUS HyperWinUnsupported(IN PDEVICE_OBJECT pDeviceObj, IN PIRP Irp); 9 | NTSTATUS HyperWinClose(IN PDEVICE_OBJECT pDeviceObj, IN PIRP Irp); 10 | 11 | #endif -------------------------------------------------------------------------------- /hypervisor-interactor/vmmintr.h: -------------------------------------------------------------------------------- 1 | #ifndef __HYPERVIN_VMMINTR_H_ 2 | #define __HYPERVIN_VMMINTR_H_ 3 | 4 | #include "hwtypes.h" 5 | 6 | // 7 | // These values are agreed values used to interact with the hypervisor 8 | // 9 | #define VMCALL_COMMUNICATION_BLOCK 0x487970657257696e 10 | 11 | extern HWSTATUS HyperWinVmCall(IN DWORD64 HyperwinRax, IN DWORD64 comminucationOffset); 12 | HWSTATUS ComSendSignal(IN DWORD64 CommunicationOffset); 13 | 14 | #endif -------------------------------------------------------------------------------- /hypervisor-interactor/hwtypes.h: -------------------------------------------------------------------------------- 1 | #ifndef __HYPERWIN_TYPES_H_ 2 | #define __HYPERWIN_TYPES_H_ 3 | 4 | #include 5 | 6 | #define HWSTATUS DWORD64 7 | 8 | typedef DWORD64 OPERATION, * POPERATION; 9 | typedef unsigned char BYTE, * BYTE_PTR; 10 | typedef DWORD64* DWORD64_PTR; 11 | 12 | typedef struct _HYPERWIN_MAIN_DATA 13 | { 14 | DWORD64 PhysicalWritePipe; 15 | BYTE_PTR VirtualWritePipe; 16 | DWORD64 WritePipeSize; 17 | DWORD64 PhysicalReadPipe; 18 | BYTE_PTR VirtualReadPipe; 19 | DWORD64 ReadPipeSize; 20 | DWORD64 CurrentWriteOffset; 21 | BOOLEAN IsMapped; 22 | KSPIN_LOCK WritePipeSpinlock; 23 | } HYPERWIN_MAIN_DATA, *PHYPERWIN_MAIN_DATA; 24 | 25 | #endif -------------------------------------------------------------------------------- /hypervisor-interactor/hypervisor-interactor.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {8E41214B-6785-4CFE-B992-037D68949A14} 18 | inf;inv;inx;mof;mc; 19 | 20 | 21 | 22 | 23 | Driver Files 24 | 25 | 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | 38 | 39 | Header Files 40 | 41 | 42 | Header Files 43 | 44 | 45 | Header Files 46 | 47 | 48 | Header Files 49 | 50 | 51 | Header Files 52 | 53 | 54 | Header Files 55 | 56 | 57 | 58 | 59 | Source Files 60 | 61 | 62 | -------------------------------------------------------------------------------- /hypervisor-interactor/drventry.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "utils.h" 3 | #include "hwtypes.h" 4 | #include "drvops.h" 5 | #include "x86_64.h" 6 | 7 | UNICODE_STRING deviceName, dosDeviceName; 8 | 9 | NTSTATUS DriverUnload(IN PDRIVER_OBJECT pDriverObj) 10 | { 11 | hvPrint("Unloading driver...\n"); 12 | // 13 | // Unmap memory used for communicating with HyperWin 14 | // 15 | if (((PHYPERWIN_MAIN_DATA)pDriverObj->DeviceObject->DeviceExtension)->IsMapped) 16 | { 17 | MmUnmapIoSpace(((PHYPERWIN_MAIN_DATA)pDriverObj->DeviceObject->DeviceExtension)->VirtualWritePipe, 18 | LARGE_PAGE_SIZE); 19 | MmUnmapIoSpace(((PHYPERWIN_MAIN_DATA)pDriverObj->DeviceObject->DeviceExtension)->VirtualReadPipe, 20 | LARGE_PAGE_SIZE); 21 | } 22 | IoDeleteSymbolicLink(&dosDeviceName); 23 | IoDeleteDevice(pDriverObj->DeviceObject); 24 | return STATUS_SUCCESS; 25 | } 26 | 27 | NTSTATUS DriverEntry(IN PDRIVER_OBJECT pDriverObj, IN PUNICODE_STRING RegPath) 28 | { 29 | UNREFERENCED_PARAMETER(RegPath); 30 | hvPrint("Loading driver...\n"); 31 | RtlInitUnicodeString(&deviceName, L"\\Device\\HyperWin"); 32 | RtlInitUnicodeString(&dosDeviceName, L"\\DosDevices\\HyperWin"); 33 | 34 | PDEVICE_OBJECT pDeviceObject; 35 | 36 | if (IoCreateDevice(pDriverObj, 37 | sizeof(HYPERWIN_MAIN_DATA), 38 | &deviceName, 39 | FILE_DEVICE_UNKNOWN, 40 | FILE_DEVICE_SECURE_OPEN, 41 | FALSE, 42 | &pDeviceObject) != STATUS_SUCCESS) 43 | { 44 | hvPrint("Could not create a device\n"); 45 | return STATUS_FAILED_DRIVER_ENTRY; 46 | } 47 | IoCreateSymbolicLink(&dosDeviceName, &deviceName); 48 | pDeviceObject->Flags &= (~DO_DEVICE_INITIALIZING); 49 | 50 | for (DWORD64 i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; i++) 51 | pDriverObj->MajorFunction[i] = HyperWinUnsupported; 52 | pDriverObj->MajorFunction[IRP_MJ_CREATE] = HyperWinCreate; 53 | pDriverObj->MajorFunction[IRP_MJ_DEVICE_CONTROL] = HyperWinDeviceIoControl; 54 | pDriverObj->MajorFunction[IRP_MJ_CLOSE] = HyperWinClose; 55 | pDriverObj->DriverUnload = DriverUnload; 56 | 57 | PHYPERWIN_MAIN_DATA pMainData = (PHYPERWIN_MAIN_DATA)pDeviceObject->DeviceExtension; 58 | pMainData->WritePipeSize = 0; 59 | pMainData->PhysicalWritePipe = 0; 60 | pMainData->IsMapped = FALSE; 61 | KeInitializeSpinLock(&(pMainData->WritePipeSpinlock)); 62 | 63 | hvPrint("Driver loaded successfully\n"); 64 | 65 | // 66 | // This section is here temporarly, for tests only 67 | // 68 | 69 | return STATUS_SUCCESS; 70 | } -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /hypervisor-interactor.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30330.147 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hypervisor-interactor", "hypervisor-interactor\hypervisor-interactor.vcxproj", "{A666C46C-610E-4FB5-86EF-B7BD832309A3}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|ARM = Debug|ARM 11 | Debug|ARM64 = Debug|ARM64 12 | Debug|x64 = Debug|x64 13 | Debug|x86 = Debug|x86 14 | Release|ARM = Release|ARM 15 | Release|ARM64 = Release|ARM64 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Debug|ARM.ActiveCfg = Debug|ARM 21 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Debug|ARM.Build.0 = Debug|ARM 22 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Debug|ARM.Deploy.0 = Debug|ARM 23 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Debug|ARM64.ActiveCfg = Debug|ARM64 24 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Debug|ARM64.Build.0 = Debug|ARM64 25 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Debug|ARM64.Deploy.0 = Debug|ARM64 26 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Debug|x64.ActiveCfg = Debug|x64 27 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Debug|x64.Build.0 = Debug|x64 28 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Debug|x86.ActiveCfg = Debug|Win32 29 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Debug|x86.Build.0 = Debug|Win32 30 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Debug|x86.Deploy.0 = Debug|Win32 31 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Release|ARM.ActiveCfg = Release|ARM 32 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Release|ARM.Build.0 = Release|ARM 33 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Release|ARM.Deploy.0 = Release|ARM 34 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Release|ARM64.ActiveCfg = Release|ARM64 35 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Release|ARM64.Build.0 = Release|ARM64 36 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Release|ARM64.Deploy.0 = Release|ARM64 37 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Release|x64.ActiveCfg = Release|x64 38 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Release|x64.Build.0 = Release|x64 39 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Release|x64.Deploy.0 = Release|x64 40 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Release|x86.ActiveCfg = Release|Win32 41 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Release|x86.Build.0 = Release|Win32 42 | {A666C46C-610E-4FB5-86EF-B7BD832309A3}.Release|x86.Deploy.0 = Release|Win32 43 | EndGlobalSection 44 | GlobalSection(SolutionProperties) = preSolution 45 | HideSolutionNode = FALSE 46 | EndGlobalSection 47 | GlobalSection(ExtensibilityGlobals) = postSolution 48 | SolutionGuid = {8F6C7A97-9B31-42E4-A5AD-D8453B292A53} 49 | EndGlobalSection 50 | EndGlobal 51 | -------------------------------------------------------------------------------- /hypervisor-interactor/hypervisor-interactor.inf: -------------------------------------------------------------------------------- 1 | ; 2 | ; hypervisor-interactor.inf 3 | ; 4 | 5 | [Version] 6 | Signature="$WINDOWS NT$" 7 | Class=Sample ; TODO: edit Class 8 | ClassGuid={78A1C341-4539-11d3-B88D-00C04FAD5171} ; TODO: edit ClassGuid 9 | Provider=%ManufacturerName% 10 | CatalogFile=hypervisor-interactor.cat 11 | DriverVer= ; TODO: set DriverVer in stampinf property pages 12 | PnpLockDown=1 13 | 14 | [DestinationDirs] 15 | DefaultDestDir = 13 16 | hypervisor-interactor_Device_CoInstaller_CopyFiles = 11 17 | 18 | ; ================= Class section ===================== 19 | 20 | [ClassInstall32] 21 | Addreg=SampleClassReg 22 | 23 | [SampleClassReg] 24 | HKR,,,0,%ClassName% 25 | HKR,,Icon,,-5 26 | 27 | [SourceDisksNames] 28 | 1 = %DiskName%,,,"" 29 | 30 | [SourceDisksFiles] 31 | hypervisor-interactor.sys = 1,, 32 | WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll=1 ; make sure the number matches with SourceDisksNames 33 | 34 | ;***************************************** 35 | ; Install Section 36 | ;***************************************** 37 | 38 | [Manufacturer] 39 | %ManufacturerName%=Standard,NT$ARCH$ 40 | 41 | [Standard.NT$ARCH$] 42 | %hypervisor-interactor.DeviceDesc%=hypervisor-interactor_Device, Root\hypervisor-interactor ; TODO: edit hw-id 43 | 44 | [hypervisor-interactor_Device.NT] 45 | CopyFiles=Drivers_Dir 46 | 47 | [Drivers_Dir] 48 | hypervisor-interactor.sys 49 | 50 | ;-------------- Service installation 51 | [hypervisor-interactor_Device.NT.Services] 52 | AddService = hypervisor-interactor,%SPSVCINST_ASSOCSERVICE%, hypervisor-interactor_Service_Inst 53 | 54 | ; -------------- hypervisor-interactor driver install sections 55 | [hypervisor-interactor_Service_Inst] 56 | DisplayName = %hypervisor-interactor.SVCDESC% 57 | ServiceType = 1 ; SERVICE_KERNEL_DRIVER 58 | StartType = 3 ; SERVICE_DEMAND_START 59 | ErrorControl = 1 ; SERVICE_ERROR_NORMAL 60 | ServiceBinary = %12%\hypervisor-interactor.sys 61 | 62 | ; 63 | ;--- hypervisor-interactor_Device Coinstaller installation ------ 64 | ; 65 | 66 | [hypervisor-interactor_Device.NT.CoInstallers] 67 | AddReg=hypervisor-interactor_Device_CoInstaller_AddReg 68 | CopyFiles=hypervisor-interactor_Device_CoInstaller_CopyFiles 69 | 70 | [hypervisor-interactor_Device_CoInstaller_AddReg] 71 | HKR,,CoInstallers32,0x00010000, "WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll,WdfCoInstaller" 72 | 73 | [hypervisor-interactor_Device_CoInstaller_CopyFiles] 74 | WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll 75 | 76 | [hypervisor-interactor_Device.NT.Wdf] 77 | KmdfService = hypervisor-interactor, hypervisor-interactor_wdfsect 78 | [hypervisor-interactor_wdfsect] 79 | KmdfLibraryVersion = $KMDFVERSION$ 80 | 81 | [Strings] 82 | SPSVCINST_ASSOCSERVICE= 0x00000002 83 | ManufacturerName="" ;TODO: Replace with your manufacturer name 84 | ClassName="Samples" ; TODO: edit ClassName 85 | DiskName = "hypervisor-interactor Installation Disk" 86 | hypervisor-interactor.DeviceDesc = "hypervisor-interactor Device" 87 | hypervisor-interactor.SVCDESC = "hypervisor-interactor Service" 88 | -------------------------------------------------------------------------------- /hypervisor-interactor/drvops.c: -------------------------------------------------------------------------------- 1 | #include "drvops.h" 2 | #include "hwtypes.h" 3 | #include "utils.h" 4 | #include "x86_64.h" 5 | #include "hwstatus.h" 6 | #include "vmmintr.h" 7 | 8 | NTSTATUS HyperWinCreate(IN PDEVICE_OBJECT pDeviceObj, IN PIRP Irp) 9 | { 10 | // 11 | // When a create call is being used, we need to make sure that the communication block 12 | // is mapped in to the kernel's virtual memory 13 | // 14 | UNREFERENCED_PARAMETER(Irp); 15 | PHYPERWIN_MAIN_DATA pData = (PHYPERWIN_MAIN_DATA)pDeviceObj->DeviceExtension; 16 | NTSTATUS NtStatus = STATUS_SUCCESS; 17 | if (!(pData->IsMapped)) 18 | { 19 | KIRQL OldIrql; 20 | KeAcquireSpinLock(&(pData->WritePipeSpinlock), &OldIrql); 21 | // 22 | // Double lock checking 23 | // 24 | if (pData->IsMapped) 25 | goto Mapped; 26 | pData->IsMapped = TRUE; 27 | int Values[4]; 28 | __cpuidex(Values, 0x40020020, 0); 29 | // 30 | // The hypervisor will store the result in EDX:EAX 31 | // 32 | #if DEBUG_LEVEL == 3 33 | hvPrint("CPUID result: %lx %lx %lx %lx\n", Values[0], Values[1], Values[2], Values[3]); 34 | #endif 35 | DWORD64 PhysicalAddress = ((DWORD64)Values[3] << 32) | (Values[0]); 36 | hvPrint("Got physical address: %llx\n", PhysicalAddress); 37 | pData->PhysicalWritePipe = PhysicalAddress; 38 | pData->WritePipeSize = LARGE_PAGE_SIZE; 39 | // 40 | // Map the memory to the kernel's virtual address 41 | // 42 | PHYSICAL_ADDRESS pa; 43 | pa.QuadPart = PhysicalAddress; 44 | pData->VirtualWritePipe = MmMapIoSpace(pa, LARGE_PAGE_SIZE, MmCached); 45 | pData->CurrentWriteOffset = 0; 46 | // 47 | // Get memory address for HyperWin responses 48 | // 49 | __cpuidex(Values, 0x40040040, 0); 50 | #if DEBUG_LEVEL == 3 51 | hvPrint("CPUID result: %lx %lx %lx %lx\n", Values[0], Values[1], Values[2], Values[3]); 52 | #endif 53 | PhysicalAddress = ((DWORD64)Values[3] << 32) | (Values[0]); 54 | hvPrint("Got physical address: %llx\n", PhysicalAddress); 55 | pData->PhysicalReadPipe = PhysicalAddress; 56 | pData->ReadPipeSize = LARGE_PAGE_SIZE; 57 | pa.QuadPart = PhysicalAddress; 58 | pData->VirtualReadPipe = MmMapIoSpace(pa, LARGE_PAGE_SIZE, MmCached); 59 | KeReleaseSpinLock(&(pData->WritePipeSpinlock), OldIrql); 60 | } 61 | Mapped: 62 | return NtStatus; 63 | } 64 | 65 | #define CTL_CODE_HW CTL_CODE(40000, 0x800, METHOD_BUFFERED, GENERIC_READ | GENERIC_WRITE) 66 | 67 | NTSTATUS HyperWinDeviceIoControl(IN PDEVICE_OBJECT pDeviceObj, IN PIRP Irp) 68 | { 69 | NTSTATUS NtStatus = STATUS_SUCCESS; 70 | PIO_STACK_LOCATION pStackLocation = IoGetCurrentIrpStackLocation(Irp); 71 | PHYPERWIN_MAIN_DATA pData = (PHYPERWIN_MAIN_DATA)pDeviceObj->DeviceExtension; 72 | PVOID SystemBuffer = Irp->AssociatedIrp.SystemBuffer; 73 | DWORD64 SavedWriteOffset, ReadOffset = 0, ReadLength; 74 | KIRQL Irql; 75 | HWSTATUS HwStatus; 76 | 77 | switch (pStackLocation->Parameters.DeviceIoControl.IoControlCode) 78 | { 79 | case CTL_CODE_HW: 80 | { 81 | hvPrint("Received ctl code: %xl\n", CTL_CODE_HW); 82 | KeAcquireSpinLock(&(pData->WritePipeSpinlock), &Irql); 83 | if (pData->CurrentWriteOffset + pStackLocation->Parameters.DeviceIoControl.InputBufferLength < 84 | pData->WritePipeSize) 85 | pData->CurrentWriteOffset += pStackLocation->Parameters.DeviceIoControl.InputBufferLength; 86 | else 87 | pData->CurrentWriteOffset = 0; 88 | SavedWriteOffset = pData->CurrentWriteOffset; 89 | KeReleaseSpinLock(&(pData->WritePipeSpinlock), Irql); 90 | 91 | RtlCopyMemory(pData->VirtualWritePipe + pData->CurrentWriteOffset, 92 | SystemBuffer, pStackLocation->Parameters.DeviceIoControl.InputBufferLength); 93 | HwStatus = ComSendSignal(pData->CurrentWriteOffset); 94 | *(DWORD64_PTR)(SystemBuffer) = HwStatus; 95 | Irp->IoStatus.Information = sizeof(HWSTATUS); 96 | hvPrint("Operation status: %lld\n", HwStatus); 97 | if(HwStatus != HYPERWIN_STATUS_SUCCUESS) 98 | goto DeviceIoControlExit; 99 | // 100 | // HypeWin sent a response? 101 | // 102 | if ((ReadOffset = *(DWORD64_PTR)(pData->VirtualWritePipe + SavedWriteOffset + 103 | sizeof(OPERATION))) != OPERATION_COMPLETED) 104 | { 105 | ReadLength = *(DWORD64_PTR)(pData->VirtualWritePipe + pData->CurrentWriteOffset 106 | + 2 * sizeof(DWORD64)); 107 | RtlCopyMemory(pData->VirtualReadPipe + ReadOffset, (BYTE_PTR)SystemBuffer + 108 | sizeof(HWSTATUS), ReadLength); 109 | Irp->IoStatus.Information += ReadLength; 110 | } 111 | 112 | break; 113 | } 114 | default: 115 | { 116 | hvPrint("Unkown IOCTL code was sent: %xl\n", pStackLocation->Parameters.DeviceIoControl.IoControlCode); 117 | } 118 | } 119 | 120 | DeviceIoControlExit: 121 | Irp->IoStatus.Status = NtStatus; 122 | if(NT_SUCCESS(NtStatus)) 123 | IoCompleteRequest(Irp, IO_NO_INCREMENT); 124 | return NtStatus; 125 | } 126 | 127 | NTSTATUS HyperWinUnsupported(IN PDEVICE_OBJECT pDeviceObj, IN PIRP Irp) 128 | { 129 | UNREFERENCED_PARAMETER(pDeviceObj); 130 | UNREFERENCED_PARAMETER(Irp); 131 | 132 | return STATUS_NOT_SUPPORTED; 133 | } 134 | 135 | NTSTATUS HyperWinClose(IN PDEVICE_OBJECT pDeviceObj, IN PIRP Irp) 136 | { 137 | UNREFERENCED_PARAMETER(pDeviceObj); 138 | UNREFERENCED_PARAMETER(Irp); 139 | 140 | return STATUS_SUCCESS; 141 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb -------------------------------------------------------------------------------- /hypervisor-interactor/hypervisor-interactor.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | Debug 22 | ARM 23 | 24 | 25 | Release 26 | ARM 27 | 28 | 29 | Debug 30 | ARM64 31 | 32 | 33 | Release 34 | ARM64 35 | 36 | 37 | 38 | {A666C46C-610E-4FB5-86EF-B7BD832309A3} 39 | {1bc93793-694f-48fe-9372-81e2b05556fd} 40 | v4.5 41 | 12.0 42 | Debug 43 | Win32 44 | hypervisor_interactor 45 | 46 | 47 | 48 | Windows10 49 | true 50 | WindowsKernelModeDriver10.0 51 | Driver 52 | KMDF 53 | Universal 54 | 55 | 56 | Windows10 57 | false 58 | WindowsKernelModeDriver10.0 59 | Driver 60 | KMDF 61 | Universal 62 | 63 | 64 | 65 | 66 | true 67 | WindowsKernelModeDriver10.0 68 | Driver 69 | KMDF 70 | Windows Driver 71 | Spectre 72 | 73 | 74 | Windows10 75 | false 76 | WindowsKernelModeDriver10.0 77 | Driver 78 | KMDF 79 | Universal 80 | 81 | 82 | Windows10 83 | true 84 | WindowsKernelModeDriver10.0 85 | Driver 86 | KMDF 87 | Universal 88 | 89 | 90 | Windows10 91 | false 92 | WindowsKernelModeDriver10.0 93 | Driver 94 | KMDF 95 | Universal 96 | 97 | 98 | Windows10 99 | true 100 | WindowsKernelModeDriver10.0 101 | Driver 102 | KMDF 103 | Universal 104 | 105 | 106 | Windows10 107 | false 108 | WindowsKernelModeDriver10.0 109 | Driver 110 | KMDF 111 | Universal 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | DbgengKernelDebugger 123 | 124 | 125 | DbgengKernelDebugger 126 | 127 | 128 | DbgengKernelDebugger 129 | 130 | 131 | DbgengKernelDebugger 132 | 133 | 134 | DbgengKernelDebugger 135 | 136 | 137 | DbgengKernelDebugger 138 | 139 | 140 | DbgengKernelDebugger 141 | 142 | 143 | DbgengKernelDebugger 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 | --------------------------------------------------------------------------------