据说有新的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里面内容都差不都,,,,随便拿别人的修改修改就好了....
;--------- Version Section --------------------------------------------------- [Version] Signature="$CHICAGO$"; Provider=MemoryCat_Device DriverVer=11/1/2007,3.0.0.3 ; If device fits one of the standard classes, use the name and GUID here, ; otherwise create your own device class and GUID as this example shows. Class=MemoryCatDevice ClassGUID={D8477C35-5951-4eee-9592-88CCB549EEB4} ;--------- SourceDiskNames and SourceDiskFiles Section ----------------------- ; These sections identify source disks and files for installation. They are ; shown here as an example, but commented out. [SourceDisksNames] 1 = "HelloWDM",Disk1,, [SourceDisksFiles] DriverWdmTest.sys = 1,, ;--------- ClassInstall/ClassInstall32 Section ------------------------------- ; Not necessary if using a standard class ; 9X Style [ClassInstall] Addreg=Class_AddReg ; NT Style [ClassInstall32] Addreg=Class_AddReg [Class_AddReg] HKR,,,,%DeviceClassName% HKR,,Icon,,"-5" ;--------- DestinationDirs Section ------------------------------------------- [DestinationDirs] YouMark_Files_Driver = 10,System32\Drivers ;--------- Manufacturer and Models Sections ---------------------------------- [Manufacturer] %MfgName%=Mfg0 [Mfg0] ; PCI hardware Ids use the form ; PCI\VEN_aaaa&DEV_bbbb&SUBSYS_cccccccc&REV_ddt ;改成你自己的ID %DeviceDesc%=YouMark_DDI, PCI\VEN_1234&DEV_1234 ;---------- DDInstall Sections ----------------------------------------------- ; --------- Windows 9X ----------------- ; Experimentation has shown that DDInstall root names greater than 19 characters ; cause problems in Windows 98 [YouMark_DDI] CopyFiles=YouMark_Files_Driver AddReg=YouMark_9X_AddReg [YouMark_9X_AddReg] HKR,,DevLoader,,*ntkern HKR,,NTMPDriver,,DriverWdmTest.sys HKR, "Parameters", "BreakOnEntry", 0x00010001, 0 ; --------- Windows NT ----------------- [YouMark_DDI.NT] CopyFiles=YouMark_Files_Driver AddReg=YouMark_NT_AddReg [YouMark_DDI.NT.Services] Addservice = HelloWDM, 0x00000002, YouMark_AddService [YouMark_AddService] DisplayName = %SvcDesc% ServiceType = 1 ; SERVICE_KERNEL_DRIVER StartType = 3 ; SERVICE_DEMAND_START ErrorControl = 1 ; SERVICE_ERROR_NORMAL ServiceBinary = %10%\System32\Drivers\DriverWdmTest.sys [YouMark_NT_AddReg] HKLM, "System\CurrentControlSet\Services\HelloMemoryCatWDM\Parameters",\ "BreakOnEntry", 0x00010001, 0 ; --------- Files (common) ------------- [YouMark_Files_Driver] DriverWdmTest.sys ;--------- Strings Section --------------------------------------------------- [Strings] ProviderName="MemoryCat." MfgName="MemoryCat.com" DeviceDesc="MemoryCat test WDM!" DeviceClassName="MemoryCat_Device" SvcDesc="MemoryCat"