xtxb1652
驱动牛犊
驱动牛犊
  • 注册日期2005-04-24
  • 最后登录2005-10-13
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望1点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1078回复:2

请帮忙看看,为什么调用时会出现997的错误号呢

楼主#
更多 发布于:2005-06-16 12:23
请各位仔细分析一下,看问题出在哪?谢谢!
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath )
{
    NTSTATUS                ntStatus;
    WCHAR                   deviceNameBuffer[128]  = L\"\\\\Device\";
    UNICODE_STRING          deviceNameUnicodeString;
    WCHAR                   deviceLinkBuffer[128]  = L\"\\\\DosDevices\";
    UNICODE_STRING          deviceLinkUnicodeString;    
    WCHAR                   startValueBuffer[] = L\"Start\";
    UNICODE_STRING          startValueUnicodeString;
    UNICODE_STRING          registryPath;
    HANDLE                  driverKey;
    ULONG                   startType, demandStart;
    RTL_QUERY_REGISTRY_TABLE paramTable[2];
    OBJECT_ATTRIBUTES       objectAttributes;

int c = \'\\\\\';
WCHAR *pwcCh = wcsrchr(DriverObject->DriverName.Buffer,c);

if (pwcCh)
{
wcscpy(wcDriverName,pwcCh);
wcscat(deviceNameBuffer,wcDriverName);
wcscat(deviceLinkBuffer,wcDriverName);
}
    // Query our start type to see if we are supposed to monitor starting
    // at boot time
    registryPath.Buffer = ExAllocatePool( PagedPool,
                                          RegistryPath->Length + sizeof(UNICODE_NULL));
    if (!registryPath.Buffer)
{
        return STATUS_INSUFFICIENT_RESOURCES;
    }
 
chHideRegName = ExAllocatePool( PagedPool, MAXVALLEN );

    registryPath.Length = RegistryPath->Length + sizeof(UNICODE_NULL);
    registryPath.MaximumLength = registryPath.Length;

    RtlZeroMemory( registryPath.Buffer, registryPath.Length );
 
    RtlMoveMemory( registryPath.Buffer,  RegistryPath->Buffer,
                   RegistryPath->Length  );

    RtlZeroMemory( &paramTable[0], sizeof(paramTable));
    paramTable[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
    paramTable[0].Name = L\"Start\";
    paramTable[0].EntryContext = &startType;
    paramTable[0].DefaultType = REG_DWORD;
    paramTable[0].DefaultData = &startType;
    paramTable[0].DefaultLength = sizeof(ULONG);

    RtlQueryRegistryValues( RTL_REGISTRY_ABSOLUTE,
                            registryPath.Buffer, &paramTable[0],
                            NULL, NULL  );

    // Set start type to demand start so that boot logging
    // only happens this boot (unless the user reconfigures it in
    // the GUI)
    InitializeObjectAttributes( &objectAttributes, RegistryPath,
                                OBJ_CASE_INSENSITIVE, NULL, NULL );
    ntStatus = ZwOpenKey( &driverKey, KEY_WRITE, &objectAttributes );
    if( NT_SUCCESS( ntStatus ))
{
        demandStart = SERVICE_DEMAND_START;
        RtlInitUnicodeString( &startValueUnicodeString, startValueBuffer );
        ZwSetValueKey( driverKey, &startValueUnicodeString, 0, REG_DWORD,
                       &demandStart, sizeof(demandStart ));
        ZwClose( driverKey );
    }

    // Setup our name and symbolic link
    RtlInitUnicodeString (&deviceNameUnicodeString,
                          deviceNameBuffer );

    RtlInitUnicodeString (&deviceLinkUnicodeString,
                          deviceLinkBuffer );

    // Set up the device used for GUI communications
    ntStatus = IoCreateDevice ( DriverObject,
                                0,
                                &deviceNameUnicodeString,
                                FILE_DEVICE_HIDEME,
                                0,
                                TRUE,
                                &GUIDevice );
    if (NT_SUCCESS(ntStatus))
{
        // Create a symbolic link that the GUI can specify to gain access
        // to this driver/device
        ntStatus = IoCreateSymbolicLink (&deviceLinkUnicodeString,
                                         &deviceNameUnicodeString );

        // Create dispatch points for all routines that must be handled
        DriverObject->MajorFunction[IRP_MJ_SHUTDOWN]        =
        DriverObject->MajorFunction[IRP_MJ_CREATE]          =
        DriverObject->MajorFunction[IRP_MJ_CLOSE]           =
        DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL]  = DriverDispatch;
#if DBG
        DriverObject->DriverUnload                          = DriverUnload;
#endif
    }
    if (!NT_SUCCESS(ntStatus))
{
        DbgPrint((\"IPCNC: Failed to create our device!\\n\"));

        // Something went wrong, so clean up (free resources etc)
        if( GUIDevice )
IoDeleteDevice( GUIDevice );
        IoDeleteSymbolicLink( &deviceLinkUnicodeString );
DbgPrint((\"NOT STATUS_SUCCESS!\\n\"));
        return ntStatus;
    }

    // Pointer to system table data structure is an NTOSKRNL export
    ServiceTable = KeServiceDescriptorTable;
    DbgPrint((\"HookDriverSysFunc: Servicetable: %x\\n\", ServiceTable ));

    // Allocate the initial output buffer
    Store   = ExAllocatePool( PagedPool, sizeof(*Store) );
    if ( !Store )
{
        IoDeleteDevice( GUIDevice );
        IoDeleteSymbolicLink( &deviceLinkUnicodeString );
DbgPrint((\"STATUS_INSUFFICIENT_RESOURCES!\\n\"));
        return STATUS_INSUFFICIENT_RESOURCES;
    }
    Store->Len  = 0;
    Store->Next = NULL;

    // If we\'re a boot driver start logging now
    if( startType != SERVICE_DEMAND_START )
{
        HookDriverSysFunc();

        // Register for shutdown notification
        IoRegisterShutdownNotification( GUIDevice );
    }
DbgPrint((\"STATUS_SUCCESS!\\n\"));
    return STATUS_SUCCESS;
}

xtxb1652
驱动牛犊
驱动牛犊
  • 注册日期2005-04-24
  • 最后登录2005-10-13
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望1点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2005-06-17 14:42
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath )
{
...
int c = \'\\\\\';
WCHAR *pwcCh = wcsrchr(DriverObject->DriverName.Buffer,c);

if (pwcCh)
{
wcscpy(wcDriverName,pwcCh);
wcscat(deviceNameBuffer,wcDriverName);
wcscat(deviceLinkBuffer,wcDriverName);
}
...
}
为什么应用程序启动驱动时会出现997错误呢?很急,帮帮忙呀,谢谢啦!
xtxb1652
驱动牛犊
驱动牛犊
  • 注册日期2005-04-24
  • 最后登录2005-10-13
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望1点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2005-06-19 14:20
问题已经解决,不过希望驱动论坛上的同志们多相互帮助呀!:)
游客

返回顶部