阅读:1199回复:2
请问各位达人另一个 有关 键盘 的filter的问题(修改 Ctrl2cap)?
先在DriverEntry中添加
DriverObject->MajorFunction [IRP_MJ_CREATE] = DriverObject->MajorFunction [IRP_MJ_CLOSE] = MKFDDispatchCreateClose; 然后我在Ctrl2cap的AddDevice中用下面代码创建两个设备(我是菜鸟,错了请改正哦) NTSTATUS MKFDAddDevice( IN PDRIVER_OBJECT Driver, IN PDEVICE_OBJECT PDO ) { PDEVICE_EXTENSION devExt; IO_ERROR_LOG_PACKET errorLogEntry; PDEVICE_OBJECT device; PDEVICE_OBJECT deviceTHIS; NTSTATUS status = STATUS_SUCCESS; static WCHAR i=0; UNICODE_STRING devname,linkname; RtlInitUnicodeString(&devname, L"DeviceMKFD "); RtlInitUnicodeString(&linkname, L"DosDevicesSysKeyfilter "); devname.Buffer[(devname.Length/sizeof(WCHAR))-1]=L'0'+i; linkname.Buffer[(linkname.Length/sizeof(WCHAR))-1]=L'0'+i; i++; // // Create a filter device and attach it to the device stack. // status = IoCreateDevice(Driver, sizeof(DEVICE_EXTENSION),&devname,FILE_DEVICE_KEYBOARD, 0,FALSE,&device); if (!NT_SUCCESS(status)) { return (status); } RtlZeroMemory(device->DeviceExtension, sizeof(DEVICE_EXTENSION)); devExt = (PDEVICE_EXTENSION) device->DeviceExtension; status=IoCreateSymbolicLink(&linkname,&devname); if (!NT_SUCCESS(status)) { return (status); } IoInitializeRemoveLock(&devExt->RemoveLock, 0, 0, 0); devExt->TopOfStack = IoAttachDeviceToDeviceStack(device, PDO); ASSERT(devExt->TopOfStack); devExt->flags=MKFDFD; device->Flags |= (DO_BUFFERED_IO | DO_POWER_PAGABLE); device->Flags &= ~DO_DEVICE_INITIALIZING; // // Create a device FOR create/read/deviceiocontrol // status = IoCreateDevice(Driver, sizeof(DEVICE_EXTENSION),NULL,FILE_DEVICE_KEYBOARD, 0,FALSE,&deviceTHIS); if (!NT_SUCCESS(status)) { return (status); } RtlZeroMemory(deviceTHIS->DeviceExtension, sizeof(DEVICE_EXTENSION)); ((PDEVICE_EXTENSION)deviceTHIS->DeviceExtension)->flags=MKFDTD; deviceTHIS->Flags |= (DO_BUFFERED_IO | DO_POWER_PAGABLE); deviceTHIS->Flags &= ~DO_DEVICE_INITIALIZING; return status; } 然后用下面的代码处理不同的设备的create/close NTSTATUS MKFDDispatchCreateClose( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) { PIO_STACK_LOCATION irpStack; PDEVICE_EXTENSION devExt; irpStack = IoGetCurrentIrpStackLocation(Irp); devExt = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension; switch (irpStack->MajorFunction) { case IRP_MJ_CREATE: if (devExt->flags & MKFDTD) { return STATUS_SUCCESS; } break; case IRP_MJ_CLOSE: if (devExt->flags & MKFDTD) { return STATUS_SUCCESS; } break; } // // Pass on the create and the close // return MKFDDispatchGeneral(DeviceObject, Irp); } 请问各位,为何我CreateFile时总是只能写不能读呢? 其它的都没有修改,而且符号连接也已经建立成功了。 [编辑 - 6/18/04 by Deauty] |
|
沙发#
发布于:2004-06-18 21:28
头文件
// // MKFD.h // #define KEY_UP 1 #define KEY_DOWN 0 #define LCONTROL ((USHORT)0x1D) #define CAPS_LOCK ((USHORT)0x3A) // // Print macro that only turns on when checked builds are on // #if DBG #define DbgPrint(arg) DbgPrint arg #else #define DbgPrint(arg) #endif // // Undocumented NT 4 function to print to the startup screen // NTSYSAPI NTSTATUS NTAPI ZwDisplayString( PUNICODE_STRING String ); // // Our device extension definition // typedef struct _DEVICE_EXTENSION { // // The top of the stack before this filter was added. AKA the location // to which all IRPS should be directed. // ULONG flags; PDEVICE_OBJECT TopOfStack; UNICODE_STRING ifSymLinkName; IO_REMOVE_LOCK RemoveLock; } DEVICE_EXTENSION, *PDEVICE_EXTENSION; #define MKFDTD 0x00000001 #define MKFDFD 0x00000000 // // Forwards // NTSTATUS DriverEntry( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath ); NTSTATUS MKFDAddDevice( IN PDRIVER_OBJECT Driver, IN PDEVICE_OBJECT PDO ); NTSTATUS MKFDPnP( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ); NTSTATUS MKFDPower( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ); VOID MKFDUnload( IN PDRIVER_OBJECT Driver ); NTSTATUS MKFDInit( IN PDRIVER_OBJECT DriverObject ); NTSTATUS MKFDDispatchRead( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ); NTSTATUS MKFDDispatchCreateClose( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ); NTSTATUS MKFDDeviceControl( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ); NTSTATUS MKFDDispatchGeneral( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ); |
|
板凳#
发布于:2004-10-15 19:34
这个问题不知道你现在解决没有,如果没有可以留个联系方法讨论一下。。。。。
|
|