Last active
August 29, 2015 14:08
-
-
Save Miliox/4dc18a89ac518bb0a1d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "DummyDriver.h" | |
| IMPLEMENT_EXTENSION(DUMMY_DEVICE_EXTENSION, | |
| { | |
| //TODO: Define Device Extension | |
| }); | |
| extern "C" | |
| NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) | |
| { | |
| UNREFERENCED_PARAMETER(RegistryPath); | |
| DriverObject->MajorFunction[IRP_MJ_CREATE] = DRIVER_ROUTINE(Create); | |
| DriverObject->MajorFunction[IRP_MJ_CLOSE] = DRIVER_ROUTINE(Close); | |
| DriverObject->MajorFunction[IRP_MJ_READ] = DRIVER_ROUTINE(Read); | |
| DriverObject->MajorFunction[IRP_MJ_WRITE] = DRIVER_ROUTINE(Write); | |
| DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DRIVER_ROUTINE(Ioctl); | |
| DriverObject->DriverUnload = DRIVER_ROUTINE(Unload); | |
| DriverObject->Flags |= DO_BUFFERED_IO; | |
| UNICODE_STRING DeviceName; | |
| RtlInitUnicodeString(&DeviceName, DEVICE_NAME); | |
| PDEVICE_OBJECT DeviceObject = NULL; | |
| NTSTATUS Status = IoCreateDevice( | |
| DriverObject, | |
| sizeof(DUMMY_DEVICE_EXTENSION), | |
| &DeviceName, | |
| FILE_DEVICE_UNKNOWN, | |
| FILE_DEVICE_SECURE_OPEN, | |
| FALSE, | |
| &DeviceObject); | |
| if (!NT_SUCCESS(Status)) | |
| { | |
| return Status; | |
| } | |
| UNICODE_STRING DosDeviceName; | |
| RtlInitUnicodeString(&DosDeviceName, DEVICE_SYMLINK); | |
| Status = IoCreateSymbolicLink(&DosDeviceName, &DeviceName); | |
| if (!NT_SUCCESS(Status)) | |
| { | |
| IoDeleteDevice(DeviceObject); | |
| return Status; | |
| } | |
| return STATUS_SUCCESS; | |
| } | |
| NTSTATUS DRIVER_ROUTINE(Create)(IN PDEVICE_OBJECT DeviceObject, PIRP Irp) | |
| { | |
| UNREFERENCED_PARAMETER(DeviceObject); | |
| Irp->IoStatus.Status = STATUS_SUCCESS; | |
| Irp->IoStatus.Information = 0; | |
| return STATUS_SUCCESS; | |
| } | |
| NTSTATUS DRIVER_ROUTINE(Close)(IN PDEVICE_OBJECT DeviceObject, PIRP Irp) | |
| { | |
| UNREFERENCED_PARAMETER(DeviceObject); | |
| Irp->IoStatus.Status = STATUS_SUCCESS; | |
| Irp->IoStatus.Information = 0; | |
| IoCompleteRequest(Irp, IO_NO_INCREMENT); | |
| return STATUS_SUCCESS; | |
| } | |
| NTSTATUS DRIVER_ROUTINE(Ioctl)(IN PDEVICE_OBJECT DeviceObject, PIRP Irp) | |
| { | |
| UNREFERENCED_PARAMETER(DeviceObject); | |
| Irp->IoStatus.Status = STATUS_SUCCESS; | |
| Irp->IoStatus.Information = 0; | |
| IoCompleteRequest(Irp, IO_NO_INCREMENT); | |
| return STATUS_SUCCESS; | |
| } | |
| NTSTATUS DRIVER_ROUTINE(Read)(IN PDEVICE_OBJECT DeviceObject, PIRP Irp) | |
| { | |
| UNREFERENCED_PARAMETER(DeviceObject); | |
| Irp->IoStatus.Status = STATUS_SUCCESS; | |
| Irp->IoStatus.Information = 0; | |
| IoCompleteRequest(Irp, IO_NO_INCREMENT); | |
| return STATUS_SUCCESS; | |
| } | |
| NTSTATUS DRIVER_ROUTINE(Write)(IN PDEVICE_OBJECT DeviceObject, PIRP Irp) | |
| { | |
| UNREFERENCED_PARAMETER(DeviceObject); | |
| Irp->IoStatus.Status = STATUS_SUCCESS; | |
| Irp->IoStatus.Information = 0; | |
| IoCompleteRequest(Irp, IO_NO_INCREMENT); | |
| return STATUS_SUCCESS; | |
| } | |
| VOID DRIVER_ROUTINE(Unload)(IN PDRIVER_OBJECT DriverObject) | |
| { | |
| UNICODE_STRING DosDeviceName; | |
| RtlInitUnicodeString(&DosDeviceName, DEVICE_SYMLINK); | |
| IoDeleteSymbolicLink(&DosDeviceName); | |
| IoDeleteDevice(DriverObject->DeviceObject); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #include <ntddk.h> | |
| #include <ntstatus.h> | |
| #define DRIVER_NAME DummyDriver | |
| #define DRIVER_ROUTINE(FUNCTION_NAME) DRIVER_NAME##FUNCTION_NAME | |
| #define DEVICE_NAME L"\\DummyDevice" | |
| #define DEVICE_SYMLINK L"\\Global??\\DummyDevice" | |
| #define DECLARE_EXTENSION(EXT) typedef struct _##EXT EXT, *P##EXT | |
| #define IMPLEMENT_EXTENSION(EXT, IMPL) struct _##EXT IMPL | |
| DECLARE_EXTENSION(DUMMY_DEVICE_EXTENSION); | |
| extern "C" | |
| NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath); | |
| NTSTATUS DRIVER_ROUTINE(Create)(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); | |
| NTSTATUS DRIVER_ROUTINE(Close)(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); | |
| NTSTATUS DRIVER_ROUTINE(Ioctl)(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); | |
| NTSTATUS DRIVER_ROUTINE(Read)(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); | |
| NTSTATUS DRIVER_ROUTINE(Write)(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); | |
| VOID DRIVER_ROUTINE(Unload)(IN PDRIVER_OBJECT DriverObject); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sc create dummy binPath= "system32\drivers\DummyDriver.sys" type= kernel start= demand error= normal DisplayName= DummyDriver |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment