This repository was archived by the owner on Jul 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriver.c
More file actions
57 lines (44 loc) · 2.12 KB
/
Driver.c
File metadata and controls
57 lines (44 loc) · 2.12 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
#include <ntddk.h>
#include <wdf.h>
DRIVER_INITIALIZE DriverEntry;
EVT_WDF_DRIVER_DEVICE_ADD KmdfHelloWordDeviceAdd;
NTSTATUS
// Entry point of the Driver -> Main function
DriverEntry(
_In_ PDRIVER_OBJECT DriverObject,
_In_ PUNICODE_STRING RegistryPath
)
{
// Variable to record success or failure from Windows API
NTSTATUS status = STATUS_SUCCESS;
// Allocate driver config object
WDF_DRIVER_CONFIG config;
// KdPrintEx is a macgit ro that sends string to the Kernel Debugger
// DPFLTR_IHVDRIVER_ID -> Used to associate the print of Driver as a something not offical "Handmade Driver" (Thats help filter messages in Debuggers)
// DPFLTR_INFO_LEVEL -> Means we are printing something at the Info Level (Thats help filter messages in Debuggers)
KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "Hello Kernel World: DriverEntry\n"));
// Init the drivNew Computerer config allocated above
// Add the entry point of Event Device Add callback "KmdfHelloWordDeviceAdd"
WDF_DRIVER_CONFIG_INIT(&config, KmdfHelloWordDeviceAdd);
// WdfDriverCreate is used to create a Driver Object and Initialize it with specified attributes and configuration
status = WdfDriverCreate(DriverObject, RegistryPath, WDF_NO_OBJECT_ATTRIBUTES, &config, WDF_NO_HANDLE);
return (status);
}
NTSTATUS
KmdfHelloWordDeviceAdd(
_In_ WDFDRIVER Driver,
_Inout_ PWDFDEVICE_INIT DeviceInit
)
{
// Not using Driver object so we unreference it (void)
UNREFERENCED_PARAMETER(Driver);
NTSTATUS status;
// Allocated device object like we did with Driver config above
WDFDEVICE hDevice;
// KdPrintEx is a macro that sends string to the Kernel Debugger
// DPFLTR_IHVDRIVER_ID -> Used to associate the print of Driver as a something not offical "Handmade Driver" (Thats help filter messages in Debuggers)
// DPFLTR_INFO_LEVEL -> Means we are printing something at the Info Level (Thats help filter messages in Debuggers)
KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "Hello Kernel World: KmdfHelloWordDeviceAdd\n"));
status = WdfDeviceCreate(&DeviceInit, WDF_NO_OBJECT_ATTRIBUTES, &hDevice);
return (status);
}