gpt4 book ai didi

c - 如何运行 KMDF 驱动程序?

转载 作者:可可西里 更新时间:2023-11-01 10:05:13 26 4
gpt4 key购买 nike

我已经为本地内核调试设置了我的系统,因为我只打算编写一个具有两个函数的简单驱动程序。我刚刚构建了一个简单的“hello world”类型的驱动程序,看看我是否能让我的驱动程序运行,目前我已经禁用了驱动程序签名验证并启用了内核 Debug模式,使用:

bcdedit /debug on

我还使用 Windows 测试商店的证书对我的驱动程序进行了测试签名?或者在 VS2015 中叫什么 :)

现在,我的问题是我在构建后通过右键单击 .inf 文件来安装我的驱动程序,但是我在我的驱动程序(下面的代码)中没有看到任何调试打印的输出,所以这让我相信我的驱动程序根本没有运行?或者是什么 ?

我在安装驱动程序的机器上更改了Component Filter Mask的值以进行调试。

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Debug Print Filter = 0xFFFFFFFF

所以,我不知道是什么导致我的驱动程序不运行/不输出任何东西。

驱动代码:

#include <ntddk.h>
#include <wdf.h>
DRIVER_INITIALIZE DriverEntry;
EVT_WDF_DRIVER_DEVICE_ADD KmdfHelloWorldEvtDeviceAdd;

void WinPrint(const char *message) {
KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, message));
}

NTSTATUS DriverEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath)
{
NTSTATUS status;
WDF_DRIVER_CONFIG config;

WinPrint("KmdfHelloWorld: DriverEntry\n");
KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "DriverEntry called!"));
KdPrintEx((DPFLTR_IHVDRIVER_ID, 0xFFFFFFFF, "DriverEntry called!"));
WinPrint("DriverEntry called!");

WDF_DRIVER_CONFIG_INIT(&config, KmdfHelloWorldEvtDeviceAdd);
status = WdfDriverCreate(DriverObject, RegistryPath, WDF_NO_OBJECT_ATTRIBUTES, &config, WDF_NO_HANDLE);

return status;
}

NTSTATUS KmdfHelloWorldEvtDeviceAdd(_In_ WDFDRIVER Driver, _Inout_ PWDFDEVICE_INIT DeviceInit)
{
NTSTATUS status;
WDFDEVICE hDevice;
UNREFERENCED_PARAMETER(Driver);

WinPrint("KmdfHelloWorld: KmdfHelloWorldEvtDeviceAdd\n");
WinPrint("Unloading driver!");

status = WdfDeviceCreate(&DeviceInit, WDF_NO_OBJECT_ATTRIBUTES, &hDevice);
return status;
}

我尝试从驱动程序创建和运行服务,我在提升的命令提示符下使用了以下命令,但我遇到了一些问题,我认为这不是运行内核驱动程序的正确方法(我不知道如何运行一个 :S)。

sc create poschamonitorv2 binPath="C:\x64\debug\poschamonitorv2.sys" DisplayName= "Poscha Monitor"

sc start poschamonitorv2

但这只会导致以下错误

ERROR_CHILD_NOT_COMPLETE
129 (0x81)
The %1 application cannot be run in Win32 mode.

所以我还是没弄明白:/哦,下面是 .INF 文件,它只是从 VS 自动生成的,我做了一些小改动。

;
; PoschaMonitorV2.inf
;

[Version]
Signature="$WINDOWS NT$"
Class=Sample ; TODO: edit Class
ClassGuid={78A1C341-4539-11d3-B88D-00C04FAD5171} ; TODO: edit ClassGuid
Provider=%ManufacturerName%
CatalogFile=PoschaMonitorV2.cat
DriverVer= ; TODO: set DriverVer in stampinf property pages

[DestinationDirs]
DefaultDestDir = 12

; ================= Class section =====================

[ClassInstall32]
Addreg=SampleClassReg

[SampleClassReg]
HKR,,,0,%ClassName%
HKR,,Icon,,-5

[SourceDisksNames]
1 = %DiskName%,,,""

[SourceDisksFiles]
PoschaMonitorV2.sys = 1,,

;*****************************************
; Install Section
;*****************************************

[Manufacturer]
%ManufacturerName%=Standard,NT$ARCH$

[Standard.NT$ARCH$]
%PoschaMonitorV2.DeviceDesc%=PoschaMonitorV2_Device, Root\PoschaMonitorV2 ; TODO: edit hw-id

[PoschaMonitorV2_Device.NT]
CopyFiles=Drivers_Dir

[Drivers_Dir]
PoschaMonitorV2.sys

;-------------- Service installation
[PoschaMonitorV2_Device.NT.Services]
AddService = PoschaMonitorV2,%SPSVCINST_ASSOCSERVICE%, PoschaMonitorV2_Service_Inst

; -------------- PoschaMonitorV2 driver install sections
[PoschaMonitorV2_Service_Inst]
DisplayName = %PoschaMonitorV2.SVCDESC%
ServiceType = 1 ; SERVICE_KERNEL_DRIVER
StartType = 3 ; SERVICE_AUTO_START
ErrorControl = 1 ; SERVICE_ERROR_NORMAL
ServiceBinary = %12%\PoschaMonitorV2.sys

;
;--- PoschaMonitorV2_Device Coinstaller installation ------
;

[DestinationDirs]
PoschaMonitorV2_Device_CoInstaller_CopyFiles = 11

[PoschaMonitorV2_Device.NT.CoInstallers]
AddReg=PoschaMonitorV2_Device_CoInstaller_AddReg
CopyFiles=PoschaMonitorV2_Device_CoInstaller_CopyFiles

[PoschaMonitorV2_Device_CoInstaller_AddReg]
HKR,,CoInstallers32,0x00010000, "WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll,WdfCoInstaller"

[PoschaMonitorV2_Device_CoInstaller_CopyFiles]
WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll

[SourceDisksFiles]
WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll=1 ; make sure the number matches with SourceDisksNames

[PoschaMonitorV2_Device.NT.Wdf]
KmdfService = PoschaMonitorV2, PoschaMonitorV2_wdfsect
[PoschaMonitorV2_wdfsect]
KmdfLibraryVersion = $KMDFVERSION$

[Strings]
SPSVCINST_ASSOCSERVICE= 0x00000002
ManufacturerName="<Your manufacturer name>" ;TODO: Replace with your manufacturer name
ClassName="Samples" ; TODO: edit ClassName
DiskName = "PoschaMonitorV2 Installation Disk"
PoschaMonitorV2.DeviceDesc = "PoschaMonitorV2 Device"
PoschaMonitorV2.SVCDESC = "PoschaMonitorV2 Service"

最佳答案

经过几个小时的纠缠,我终于解决了这个问题,问题是我没有在我的项目设置中为“KMDF Version Minor”和“KMDF Version Major”设置值。你可以在这里阅读更多相关信息:

https://msdn.microsoft.com/en-us/library/windows/hardware/hh825931(v=vs.85).aspx

希望有一天其他人会发现这个有用:)

关于c - 如何运行 KMDF 驱动程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32670819/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com