how to get PDEVICE_OBJECT name

Home Forums Discussions General how to get PDEVICE_OBJECT name

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

      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
      Anonymous

        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.