据说有新的wdf 比 wdm 好.....不过我还是地学一学
写了一个最简单的wdm...
WDM比NT式加载有点麻烦..需要个.inf配置文件,,而且有时还要重启系统(可能是我菜吧..不知道其它办法 = =).
这提供那加载工具,,自己下载好了EzDriverInstaller.zip
首先,先定义,其中那个guid由guid.exe工具生成,,,在VC或VS的工具那里有.
#include// {D8477C35-5951-4eee-9592-88CCB549EEB4} DEFINE_GUID(Ternsoft_WDM_DEVICE,0xd8477c35, 0x5951, 0x4eee, 0x95, 0x92, 0x88, 0xcc, 0xb5, 0x49, 0xee, 0xb4); typedef struct{ DEVICE_OBJECT *pStackNextDeviceObject; UNICODE_STRING ustrSymbolicLinkName; }DEVICE_EXTENSION;
wdm设备的生成不再在DriverEntry了,
#ifdef __cplusplus extern "C" { #endif NTSTATUS DriverEntry( IN OUT PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath ) { KdPrint(("DriverEntry")); DriverObject->MajorFunction[IRP_MJ_CREATE] = DriverObject->MajorFunction[IRP_MJ_CLOSE] = DRIVERWDMTEST_DispatchCreateClose; DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DRIVERWDMTEST_DispatchDeviceControl; DriverObject->MajorFunction[IRP_MJ_PNP]=DRIVERWDMTEST_DispatchPnp; DriverObject->DriverUnload = DRIVERWDMTEST_DriverUnload; DriverObject->DriverExtension->AddDevice=DRIVERWDMTEST_AddDevice; KdPrint(("DriverEntry finished")); return STATUS_SUCCESS; } #ifdef __cplusplus }; // extern "C" #endif
而是 DriverObject->DriverExtension->AddDevice=DRIVERWDMTEST_AddDevice 指定在一个方法里.
NTSTATUS DRIVERWDMTEST_AddDevice ( __in struct _DRIVER_OBJECT *DriverObject, __in struct _DEVICE_OBJECT *PhysicalDeviceObject ) { KdPrint(("DRIVERWDMTEST_AddDevice test wdm haha ternsoft.com")); DEVICE_OBJECT *pFunDeviceObject; NTSTATUS status=IoCreateDevice(DriverObject,sizeof(DEVICE_EXTENSION),NULL,//木有指定设备名 FILE_DEVICE_UNKNOWN,0,FALSE,&pFunDeviceObject); if (!NT_SUCCESS(status)) { KdPrint(("IoCreateDevice failed")); return status; } DEVICE_EXTENSION *pDEX=(DEVICE_EXTENSION*)pFunDeviceObject->DeviceExtension; pDEX->pStackNextDeviceObject=IoAttachDeviceToDeviceStack(pFunDeviceObject,PhysicalDeviceObject); status=IoRegisterDeviceInterface(PhysicalDeviceObject,&Ternsoft_WDM_DEVICE,NULL,&pDEX->ustrSymbolicLinkName); if (!NT_SUCCESS(status)) { KdPrint(("IoRegisterDeviceInterface failed")); return status; } KdPrint(("IoRegisterDeviceInterface %wZ",&pDEX->ustrSymbolicLinkName)); IoSetDeviceInterfaceState(&pDEX->ustrSymbolicLinkName,true); pFunDeviceObject->Flags |= DO_BUFFERED_IO | DO_POWER_PAGABLE; pFunDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING; KdPrint(("DRIVERWDMTEST_AddDevice finished!")); return STATUS_SUCCESS; }
另外我的pnp派遣函数灰常简单...啥事也没做,直接交给下层处理
NTSTATUS DRIVERWDMTEST_DispatchPnp( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) { KdPrint(("DRIVERWDMTEST_DispatchPnp")); DEVICE_EXTENSION *pDEX=(DEVICE_EXTENSION*)DeviceObject->DeviceExtension; /* NTSTATUS status = STATUS_SUCCESS; Irp->IoStatus.Status = status; Irp->IoStatus.Information = 0; IoCompleteRequest(Irp, IO_NO_INCREMENT); return status; */ IoSkipCurrentIrpStackLocation(Irp); return IoCallDriver(pDEX->pStackNextDeviceObject, Irp); }
饿..还有那个2.inf ...其实inf里面内容都差不都,,,,随便拿别人的修改修改就好了....