how to get PDEVICE_OBJECT name

Home Forums Discussions General Discussion how to get PDEVICE_OBJECT name

This topic contains 1 reply, has 1 voice, and was last updated by  fedotov 8 years, 9 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #5218

    fedotov
    Participant

    I need to enumerate names of devices objects belongs to not my DriverObject.
    I get DriverObject that i need by ObReferenceObjectByName, next i successfully enumerating Device Objects, but all the names are “(null)”. I see by DeviceTree.exe that all the Device Objects are not unnamed.

    Help me please, i need to do it as fast as i can , but i haven’t any idea what to do

    All the names getting from this code are =”(null)”;


    RtlInitUnicodeString( &nameUsbStor, L"\Driver\USBSTOR" );
    status = ObReferenceObjectByName(&nameUsbStor,OBJ_CASE_INSENSITIVE,NULL,(ACCESS_MASK)0L,*IoDriverObjectType,KernelMode,NULL,&DriverObject);
    if (NT_SUCCESS( status ))
    {
    // request to know number of devices in USBSTOR
    status = (gFuncTbl.EnumerateDeviceObjectList)(DriverObject,NULL,0,&numDevices);

    DbgPrint("USBSTOR has devices num = %d rn",numDevices);

    if(status != STATUS_BUFFER_TOO_SMALL) goto func_exit_deref;

    numDevices += 8;//for some bad case

    devList = SDalloc(numDevices * sizeof(PDEVICE_OBJECT));

    if (NULL == devList) goto func_exit_deref;

    status = (gFuncTbl.EnumerateDeviceObjectList)(DriverObject,devList,(numDevices * sizeof(PDEVICE_OBJECT)),&numDevices);
    if (!NT_SUCCESS( status ))
    {
    SDfree(devList);
    goto func_exit_deref;
    }
    // Walk the given list of devices into USBSTOR
    for (i=0; i < numDevices; i++)
    {
    try
    {
    SDGetObjectName( devList, &name );
    DbgPrint("device object of USBSTOR name = %wZ rn", &name);

    baseDeviceObject = (gFuncTbl.GetDeviceAttachmentBaseRef)( devList
    );
    SDGetObjectName( baseDeviceObject, &name )
    ObDereferenceObject( baseDeviceObject );

    DbgPrint("baseDeviceObject name = %wZ rn",&name);

    currentDevObj = (gFuncTbl.GetAttachedDeviceReference)( devList
    );
    do
    {
    SDGetObjectName( currentDevObj, &name );
    DbgPrint("device object of USBSTOR name = %wZ rn", &name);
    nextDevObj = (gFuncTbl.GetLowerDeviceObject)( currentDevObj );
    ObDereferenceObject( currentDevObj );
    currentDevObj = nextDevObj;

    } while (NULL != currentDevObj);

    }
    finally
    {
    ObDereferenceObject( devList
    );
    }
    }
    ObDereferenceObject( DriverObject );
    }

    [/code]

    #6651

    fedotov
    Participant

    I found error, thanks to all who wans to help me.
    My code above is absolutely workable, i’m in a hurry now and i did foolish error (commenting some line of code bofere this code snippet).
    Thanks once more

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.