驱动过滤鼠标

驱动过滤鼠标, 附加到鼠标设备上

 

  
  
  
  
  1. VOID Attach(  
  2.         IN PDRIVER_OBJECT DriverObject  
  3.         )  
  4. {  
  5.     NTSTATUS status;  
  6.     PDRIVER_OBJECT targetDriverObject;  
  7.     PDEVICE_OBJECT curDeviceObject;  
  8.     PDEVICE_OBJECT lowerDeviceObject;  
  9.     PDEVICE_OBJECT filterDeviceObject;  
  10.     UNICODE_STRING kbdClassName;  
  11.     KdPrint(("Attach invoke\n"));  
  12.     RtlInitUnicodeString(&kbdClassName, L"\\Driver\\mouclass");  
  13.     status = ObReferenceObjectByName(&kbdClassName, OBJ_CASE_INSENSITIVE, NULL, 0,   
  14.             *IoDriverObjectType, KernelMode, NULL, &targetDriverObject);  
  15.     if (!NT_SUCCESS(status)) {  
  16.         KdPrint(("ObReferenceObjectByName failed\n"));  
  17.         KdPrint(("status %08x\n", status));  
  18.         return ;  
  19.     }  
  20.     g_old_adddevice = targetDriverObject->DriverExtension->AddDevice; 
  21.     if (g_new_adddevice) 
  22.     { 
  23.         KdPrint(("use new adddevice\r\n")); 
  24.         targetDriverObject->DriverExtension->AddDevice = g_new_adddevice; 
  25.     } 
  26.     ObDereferenceObject(targetDriverObject);  
  27.     curDeviceObject = targetDriverObject->DeviceObject;  
  28.     while (curDeviceObject != NULL) {  
  29.         status = IoCreateDevice(DriverObject, sizeof(FILTER_EXT), NULL, curDeviceObject->DeviceType,   
  30.                 curDeviceObject->Characteristics, FALSE, &filterDeviceObject);  
  31.         if (!NT_SUCCESS(status)) {  
  32.             KdPrint(("IoCreateDevice failed\n"));  
  33.         } else {  
  34.             lowerDeviceObject = IoAttachDeviceToDeviceStack(filterDeviceObject, curDeviceObject);  
  35.             if (lowerDeviceObject == NULL) {  
  36.                 KdPrint(("IoAttachDeviceToDeviceStack failed\n"));  
  37.                 IoDeleteDevice(filterDeviceObject);  
  38.             } else {  
  39.                 ((PFILTER_EXT)filterDeviceObject->DeviceExtension)->LowerDeviceObject = lowerDeviceObject;  
  40.                 filterDeviceObject->Flags |=   
  41.                     lowerDeviceObject->Flags & (DO_BUFFERED_IO | DO_DIRECT_IO | DO_POWER_PAGABLE);  
  42.                 filterDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;  
  43.             }  
  44.         }  
  45.         curDeviceObject = curDeviceObject->NextDevice;  
  46.     }  
  47. }   

 

你可能感兴趣的:(驱动,Attach)