|
打开vs2022,新建项目,选择Kernel Mode Driver, Empty(KMDF)
添加文件Driver.c(微软提供的示例程序),代码如下
#include <ntddk.h>
#include <wdf.h>
DRIVER_INITIALIZE DriverEntry;
EVT_WDF_DRIVER_DEVICE_ADD KmdfHelloWorldEvtDeviceAdd;
NTSTATUS
DriverEntry(
_In_ PDRIVER_OBJECT DriverObject,
_In_ PUNICODE_STRING RegistryPath
)
{
// NTSTATUS variable to record success or failure
NTSTATUS status = STATUS_SUCCESS;
// Allocate the driver configuration object
WDF_DRIVER_CONFIG config;
// Print &#34;Hello World&#34; for DriverEntry
KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, &#34;KmdfHelloWorld: DriverEntry\n&#34;));
// Initialize the driver configuration object to register the
// entry point for the EvtDeviceAdd callback, KmdfHelloWorldEvtDeviceAdd
WDF_DRIVER_CONFIG_INIT(&config,
KmdfHelloWorldEvtDeviceAdd
);
// Finally, create the driver object
status = WdfDriverCreate(DriverObject,
RegistryPath,
WDF_NO_OBJECT_ATTRIBUTES,
&config,
WDF_NO_HANDLE
);
return status;
}
NTSTATUS
KmdfHelloWorldEvtDeviceAdd(
_In_ WDFDRIVER Driver,
_Inout_ PWDFDEVICE_INIT DeviceInit
)
{
// We&#39;re not using the driver object,
// so we need to mark it as unreferenced
UNREFERENCED_PARAMETER(Driver);
NTSTATUS status;
// Allocate the device object
WDFDEVICE hDevice;
// Print &#34;Hello World&#34;
KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, &#34;KmdfHelloWorld: KmdfHelloWorldEvtDeviceAdd\n&#34;));
// Create the device object
status = WdfDeviceCreate(&DeviceInit,
WDF_NO_OBJECT_ATTRIBUTES,
&hDevice
);
return status;
}编译出错,提示error MSB8040: 此项目需要缓解了 Spectre 漏洞的库,安装Spectre 漏洞的库
获取工具和功能
这边看右上角msvc是最新版本,再单个组件里面搜索最新
勾选上Spectre相关得,点击修改(点击之前先关闭其他vs进程)
安装完成后重新打开vs2022,编译,如下所示,编译成功
- KmdfHello.sys - 内核模式驱动程序文件
- KmdfHello.inf - 在安装驱动程序时 Windows 使用的信息文件
- KmdfHello.cat - 安装程序验证驱动程序的测试签名所使用的目录文件
|
|