Hi all I want to get deviceObject pointer from physical devicename ,for example \device\00000057. the \device\00000057 can be found from device manager. The following is my test code. The ZwOpenFile always fails(say device path can not be found). I knows the OSR tool DeviceTree.exe can show deviceobjcet from device name. Can someone tell me a method to open a physical device from driver. thanks in advance rech HANDLE fileHandle; OBJECT_ATTRIBUTES objectAttributes; WCHAR deviceName = L"\Device\00000057"; UNICODE_STRING pdoName; NTSTATUS status; IO_STATUS_BLOCK ioStatus; PDEVICE_OBJECT pDevObj; PFILE_OBJECT pFileObject; ACCESS_MASK access = FILE_READ_ACCESS; ACCESS_MASK access_write = FILE_WRITE_ACCESS; RtlInitUnicodeString (&pdoName,deviceName ); InitializeObjectAttributes( &objectAttributes, &pdoName, OBJ_KERNEL_HANDLE , (HANDLE) NULL, (PSECURITY_DESCRIPTOR) NULL ); // // Open it up, write access only! // status = ZwOpenFile( &fileHandle, access, &objectAttributes, &ioStatus, FILE_SHARE_WRITE | FILE_SHARE_READ, FILE_NON_DIRECTORY_FILE ); if (NT_SUCCESS(status)) { // // The open operation was successful. Dereference the file handle and // obtain a pointer to the device object for the handle. // status = ObReferenceObjectByHandle( fileHandle, 0, *IoFileObjectType, KernelMode, (PVOID *) &pFileObject, NULL ); ZwClose(fileHandle); } if (NT_SUCCESS(status)) { pDevObj = IoGetRelatedDeviceObject(pFileObject); if(pDevObj) { _asm int 3; } ObDereferenceObject(pFileObject); } return status;
Discover the new Windows Vista Learn more!
Explore the seven wonders of the world
http://search.msn.com/results.aspx?q=7+wonders+world&mkt=en-US&form=QBRE
I would say replacing first two words in the thread title with Io and merge the subsequent 3 (the last one should start with a capital), and to searching WDK help would be quite efficient way to go - it is really funny, but the title of this thread actually almost names the function that does something that you are trying to do (i. IoGetDeviceObjectPointer). ObOpenObjectByName() may help you as well - just keep in mind that the latter returns a pointer to the device object itself, while the former one returns a pointer to the top of its stack.
Anton Bassov
Thank you.
Yes ,it is funny.
I also try to use IoGetDeviceObjectPointer and ObOpenObjectByName ,but it still doesn’t work.
What I want to do is: There is a physical device object created by system in-box driver.The in-box driver doesn’t create any
device interface. The in-box driver name and the physical device instance path can be found from deivce manger UI.
Are those information enough to get the physical device object from a filter dirver?
thanks
rech
{ NTSTATUS status; WCHAR deviceName = L"\Device\00000055";
RtlInitUnicodeString (&deviceNameUnicodeString, deviceName); ntStatus = IoGetDeviceObjectPointer(&deviceNameUnicodeString, GENERIC_ALL, &pFileObject, &pDeviceObject); if (NT_SUCCESS(status)) { ObDereferenceObject(pFileObject); _asm int 3; } return status; }
{ NTSTATUS status; HANDLE fileHandle; OBJECT_ATTRIBUTES objectAttributes; WCHAR deviceName = L"\Device\00000055"; UNICODE_STRING pdoName; IO_STATUS_BLOCK ioStatus; PDEVICE_OBJECT pDevObj; PFILE_OBJECT pFileObject; ACCESS_MASK access = FILE_READ_ACCESS; ACCESS_MASK access_write = FILE_WRITE_ACCESS; RtlInitUnicodeString (&pdoName,deviceName ); InitializeObjectAttributes( &objectAttributes, &pdoName, OBJ_KERNEL_HANDLE , (HANDLE) NULL, (PSECURITY_DESCRIPTOR) NULL );
status = ObOpenObjectByName(&objectAttributes, NULL, KernelMode, NULL, GENERIC_ALL, NULL, &fileHandle ); if (NT_SUCCESS(status)) { ZwClose(fileHandle); _asm int 3; } return status; }> Date: Wed, 29 Oct 2008 03:09:02 -0400> From: xxxxx@hotmail.com> To: xxxxx@lists.osr.com> Subject: RE:[ntdev] How to Get DeviceObject pointer from Physical device name> > I would say replacing first two words in the thread title with Io and merge the subsequent 3 (the last one should start with a capital), and to searching WDK help would be quite efficient way to go - it is really funny, but the title of this thread actually almost names the function that does something that you are trying to do (i. IoGetDeviceObjectPointer). ObOpenObjectByName() may help you as well - just keep in mind that the latter returns a pointer to the device object itself, while the former one returns a pointer to the top of its stack.> > Anton Bassov > > —> NTDEV is sponsored by OSR> > For our schedule of WDF, WDM, debugging and other seminars visit: > http://www.osr.com/seminars\> > To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
Invite your mail contacts to join your friends list with Windows Live Spaces. It’s easy!
http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us