quarkfc
驱动牛犊
驱动牛犊
  • 注册日期2001-07-13
  • 最后登录2006-07-26
  • 粉丝0
  • 关注0
  • 积分17分
  • 威望3点
  • 贡献值0点
  • 好评度1点
  • 原创分0分
  • 专家分0分
阅读:1109回复:0

如何将转WDM化为KDM?就是那个DebugPrint for 2000转为for NT

楼主#
更多 发布于:2002-05-28 11:48
就是《windows WDM设备驱动程序开发指南》中的debugPrint例子,没有与实际硬件交互,用于调试打印内核dbg信息,小弟想将其改造后在NT下使用
,我比较了一下,大部分函数,很类似,我
将wDM.h ->ntddk.h
并改动了很多编译没有通过的地方,
后来编译通过了,并且服务业可以启动(DriverEnrty顺利通过),

但是CreateFile时候,说是设备未就绪,
跟踪驱程,发现根本就没有进入到DbpCreate,
请问大侠,这是什么问题?
将WDM->KDM除了去掉PNP外,还要注意什么?


谢谢!
改动后代码如下:


NTSTATUS
DriverEntry(
    IN PDRIVER_OBJECT  DriverObject,
    IN PUNICODE_STRING RegistryPath
    )
{

    PDEVICE_OBJECT         fdo       = NULL;
    NTSTATUS               status;
    WCHAR                  deviceNameBuffer[]  = L\"\\\\Device\\\\InfoNT\";
    UNICODE_STRING         deviceNameUnicodeString;
    WCHAR                  deviceLinkBuffer[]  = L\"\\\\DosDevices\\\\InfoNT\";
    UNICODE_STRING         deviceLinkUnicodeString;
PDEBUGPRINT_DEVICE_EXTENSION dx ;
    SimplDrvKdPrint ((\"InfoNT.SYS: entering DriverEntry\\n\"));
    RtlInitUnicodeString (&deviceNameUnicodeString,
                          deviceNameBuffer
                          );
    status = IoCreateDevice (DriverObject,
                               sizeof (DEBUGPRINT_DEVICE_EXTENSION),
                               &deviceNameUnicodeString,
                               FILE_DEVICE_UNKNOWN,
                               0,
                               TRUE,
                               &fdo
                               );

if( !NT_SUCCESS(status)){
DbgPrint(\"IoCreateDeciceError!\");
return status;
}

dx = (PDEBUGPRINT_DEVICE_EXTENSION)fdo->DeviceExtension;
dx->fdo = fdo;
dx->UsageCount = 1;
KeInitializeEvent( &dx->StoppingEvent, NotificationEvent, FALSE);
dx->OpenHandleCount = 0;
dx->GotResources = false;
dx->Paused = false;
dx->IODisabled = true;
dx->Stopping = false;


// Initialise event list
KeInitializeSpinLock(&dx->EventListLock);
InitializeListHead(&dx->EventList);

// Initialise \"read queue\"
KeInitializeSpinLock(&dx->ReadIrpLock);
dx->ReadIrp = NULL;
    //
        // Create a symbolic link that Win32 apps can specify to gain access
        // to this driver/device
        //

     RtlInitUnicodeString (&deviceLinkUnicodeString,
                              deviceLinkBuffer
                              );

     status = IoCreateSymbolicLink (&deviceLinkUnicodeString,
                                         &deviceNameUnicodeString
                                         );


      if (!NT_SUCCESS(status)){
            SimplDrvKdPrint ((\"InfoNT.SYS: IoCreateSymbolicLink failed\\n\"));

        }


// Attach to the driver stack below us
//dx->NextStackDevice = IoAttachDeviceToDeviceStack(fdo,pdo);

// Set fdo flags appropriately
fdo->Flags |= DO_BUFFERED_IO;//|DO_POWER_PAGABLE;
fdo->Flags &= ~DO_DEVICE_INITIALIZING;


        //
        // Create dispatch points for device control, create, close.
        //
   //原来代码
  //      DriverObject->MajorFunction[IRP_MJ_CREATE]         =
 //       DriverObject->MajorFunction[IRP_MJ_CLOSE]          =
 //       DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = SimplDrvDispatch;
 //       DriverObject->DriverUnload                         = SimplDrvUnload;
    
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
DriverObject->DriverUnload =SimplDrvUnload;// DbpUnload;
    DriverObject->MajorFunction[IRP_MJ_CREATE] = DbpCreate;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = DbpClose;
    DriverObject->MajorFunction[IRP_MJ_READ] = DbpRead;
DriverObject->MajorFunction[IRP_MJ_WRITE] = DbpWrite;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DbpDeviceControl;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@



done_DriverEntry:

    if (!NT_SUCCESS(status))
    {
        //
        // Something went wrong, so clean up (free resources, etc.)
        //

        if (fdo)

            IoDeleteDevice (fdo);
    }
    DbgPrint(\"Entry SuccessfuL!\\n\"   );
    return status;
}


NTSTATUS DbpDeviceControl( IN PDEVICE_OBJECT fdo,
IN PIRP Irp)
{
PDEBUGPRINT_DEVICE_EXTENSION dx = (PDEBUGPRINT_DEVICE_EXTENSION)fdo->DeviceExtension;
DbgPrint(\"Into DbpDeviceControl!\");
if( dx->IODisabled){
DbgPrint(\"DbpDeviceControl 1!\\n\");
return CompleteIrp( Irp, STATUS_DEVICE_NOT_CONNECTED, 0);
}
// Complete successfully
DbgPrint(\"End DbpDeviceControl!\");
return CompleteIrp(Irp,STATUS_SUCCESS,0);
}


NTSTATUS DbpCreate( IN PDEVICE_OBJECT fdo,
IN PIRP Irp)
{

PDEBUGPRINT_DEVICE_EXTENSION dx = (PDEBUGPRINT_DEVICE_EXTENSION)fdo->DeviceExtension;
DbgPrint(\"Into DbpCreate!\");
if( dx->IODisabled){
DbgPrint(\"DbpCreate 1!\\n\");
return CompleteIrp( Irp, STATUS_DEVICE_NOT_CONNECTED, 0);
}

InterlockedIncrement(&dx->OpenHandleCount);
// Complete successfully
DbgPrint(\"End DbpCreate!\");
return CompleteIrp(Irp,STATUS_SUCCESS,0);
}

NTSTATUS DbpClose( IN PDEVICE_OBJECT fdo,
IN PIRP Irp)
{
PDEBUGPRINT_DEVICE_EXTENSION dx = (PDEBUGPRINT_DEVICE_EXTENSION)fdo->DeviceExtension;

InterlockedDecrement(&dx->OpenHandleCount);

// Complete successfully
return CompleteIrp(Irp,STATUS_SUCCESS,0);
}


VOID
SimplDrvUnload(
    IN PDRIVER_OBJECT DriverObject
    )
{
    WCHAR                  deviceLinkBuffer[]  = L\"\\\\DosDevices\\\\InfoNT\";
    UNICODE_STRING         deviceLinkUnicodeString;
    RtlInitUnicodeString (&deviceLinkUnicodeString,
                          deviceLinkBuffer
                          );

    IoDeleteSymbolicLink (&deviceLinkUnicodeString);

    //
    // Delete the device object
    //

    IoDeleteDevice (DriverObject->DeviceObject);

    SimplDrvKdPrint ((\"SIMPLDRV.SYS: unloading\\n\"));
}
 

最新喜欢:

mapoflmapofl
游客

返回顶部