mirror-ac/test/driver/main.cpp

67 lines
2 KiB
C++
Raw Normal View History

2024-01-11 10:16:55 +01:00
#include "driver.hpp"
UNICODE_STRING DRIVER_NAME = RTL_CONSTANT_STRING(L"donna-ac-test");
UNICODE_STRING DRIVER_LINK = RTL_CONSTANT_STRING(L"donna-ac-test-link");
#define IOCTL_RUN_NMI_CALLBACKS \
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x20001, METHOD_BUFFERED, FILE_ANY_ACCESS)
2024-01-11 10:16:55 +01:00
NTSTATUS
DeviceControl(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp) {
UNREFERENCED_PARAMETER(DeviceObject);
2024-01-11 10:16:55 +01:00
NTSTATUS status = STATUS_SUCCESS;
PIO_STACK_LOCATION stack_location = IoGetCurrentIrpStackLocation(Irp);
2024-01-11 10:16:55 +01:00
switch (stack_location->Parameters.DeviceIoControl.IoControlCode) {}
2024-01-11 10:16:55 +01:00
end:
Irp->IoStatus.Status = status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return status;
2024-01-11 10:16:55 +01:00
}
NTSTATUS
DeviceClose(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp) {
UNREFERENCED_PARAMETER(DeviceObject);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return Irp->IoStatus.Status;
2024-01-11 10:16:55 +01:00
}
NTSTATUS
DeviceCreate(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp) {
UNREFERENCED_PARAMETER(DeviceObject);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return Irp->IoStatus.Status;
2024-01-11 10:16:55 +01:00
}
STATIC
VOID DriverUnload(_In_ PDRIVER_OBJECT DriverObject) {
IoDeleteDevice(DriverObject->DeviceObject);
2024-01-11 10:16:55 +01:00
}
extern "C" NTSTATUS DriverEntry(_In_ PDRIVER_OBJECT DriverObject,
_In_ PUNICODE_STRING RegistryPath) {
NTSTATUS status;
2024-01-11 10:16:55 +01:00
status = IoCreateDevice(DriverObject, NULL, &DRIVER_NAME, FILE_DEVICE_UNKNOWN,
FILE_DEVICE_SECURE_OPEN, FALSE,
&DriverObject->DeviceObject);
2024-01-11 10:16:55 +01:00
if (!NT_SUCCESS(status)) {
return STATUS_FAILED_DRIVER_ENTRY;
}
2024-01-11 10:16:55 +01:00
status = IoCreateSymbolicLink(&DRIVER_LINK, &DRIVER_NAME);
2024-01-11 10:16:55 +01:00
if (!NT_SUCCESS(status)) {
IoDeleteDevice(DriverObject->DeviceObject);
return STATUS_FAILED_DRIVER_ENTRY;
}
2024-01-11 10:16:55 +01:00
DriverObject->MajorFunction[IRP_MJ_CREATE] = DeviceCreate;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = DeviceClose;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DeviceControl;
DriverObject->DriverUnload = DriverUnload;
2024-01-11 10:16:55 +01:00
return STATUS_SUCCESS;
2024-01-11 10:16:55 +01:00
}