-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMiniVT.cpp
More file actions
executable file
·76 lines (63 loc) · 2.25 KB
/
MiniVT.cpp
File metadata and controls
executable file
·76 lines (63 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "stdafx.h"
#include "vtsystem.h"
void MiniVTUnload(IN PDRIVER_OBJECT DriverObject);
NTSTATUS MiniVTCreateClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
NTSTATUS MiniVTDefaultHandler(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
#ifdef __cplusplus
extern "C" NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath);
#endif
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
{
UNICODE_STRING DeviceName,Win32Device;
PDEVICE_OBJECT DeviceObject = NULL;
NTSTATUS status;
unsigned i;
RtlInitUnicodeString(&DeviceName,L"\\Device\\MiniVT0");
RtlInitUnicodeString(&Win32Device,L"\\DosDevices\\MiniVT0");
for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
DriverObject->MajorFunction[i] = MiniVTDefaultHandler;
DriverObject->MajorFunction[IRP_MJ_CREATE] = MiniVTCreateClose;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = MiniVTCreateClose;
DriverObject->DriverUnload = MiniVTUnload;
status = IoCreateDevice(DriverObject,
0,
&DeviceName,
FILE_DEVICE_UNKNOWN,
0,
FALSE,
&DeviceObject);
if (!NT_SUCCESS(status))
return status;
if (!DeviceObject)
return STATUS_UNEXPECTED_IO_ERROR;
DeviceObject->Flags |= DO_DIRECT_IO;
DeviceObject->AlignmentRequirement = FILE_WORD_ALIGNMENT;
status = IoCreateSymbolicLink(&Win32Device, &DeviceName);
DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
StartVirtualTechnology();
Log("驱动加载完毕.",0);
return STATUS_SUCCESS;
}
void MiniVTUnload(IN PDRIVER_OBJECT DriverObject)
{
UNICODE_STRING Win32Device;
StopVirtualTechnology();
RtlInitUnicodeString(&Win32Device,L"\\DosDevices\\MiniVT0");
IoDeleteSymbolicLink(&Win32Device);
IoDeleteDevice(DriverObject->DeviceObject);
Log("驱动卸载完毕.",0);
}
NTSTATUS MiniVTCreateClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
}
NTSTATUS MiniVTDefaultHandler(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return Irp->IoStatus.Status;
}