- use IopGetDeviceObjectFromDeviceInstance to retrieve PDO

svn path=/trunk/; revision=66545
This commit is contained in:
Johannes Anderwald 2015-03-02 19:14:16 +00:00
parent aa78e3fd93
commit 87b47bb64d

View file

@ -18,6 +18,9 @@
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
PDEVICE_OBJECT
IopGetDeviceObjectFromDeviceInstance(PUNICODE_STRING DeviceInstance);
static PWCHAR BaseKeyString = L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\DeviceClasses\\"; static PWCHAR BaseKeyString = L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\DeviceClasses\\";
static static
@ -1308,18 +1311,18 @@ IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName,
IN BOOLEAN Enable) IN BOOLEAN Enable)
{ {
PDEVICE_OBJECT PhysicalDeviceObject; PDEVICE_OBJECT PhysicalDeviceObject;
PFILE_OBJECT FileObject;
UNICODE_STRING GuidString; UNICODE_STRING GuidString;
PWCHAR StartPosition; PWCHAR StartPosition;
PWCHAR EndPosition; PWCHAR EndPosition;
NTSTATUS Status; NTSTATUS Status;
LPCGUID EventGuid; LPCGUID EventGuid;
HANDLE InstanceHandle, ControlHandle; HANDLE InstanceHandle, ControlHandle;
UNICODE_STRING KeyName; UNICODE_STRING KeyName, DeviceInstance;
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
ULONG LinkedValue; ULONG LinkedValue, Index;
GUID DeviceGuid; GUID DeviceGuid;
if (SymbolicLinkName == NULL) if (SymbolicLinkName == NULL)
return STATUS_INVALID_PARAMETER_1; return STATUS_INVALID_PARAMETER_1;
@ -1381,23 +1384,38 @@ IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName,
return Status; return Status;
} }
/* Get pointer to the PDO */ DeviceInstance.Buffer = ExAllocatePool(PagedPool, (ULONG_PTR)StartPosition - (ULONG_PTR)SymbolicLinkName->Buffer);
Status = IoGetDeviceObjectPointer( if (DeviceInstance.Buffer == NULL)
SymbolicLinkName,
0, /* DesiredAccess */
&FileObject,
&PhysicalDeviceObject);
if (!NT_SUCCESS(Status))
{ {
DPRINT1("IoGetDeviceObjectPointer() failed with status 0x%08lx\n", Status); /* no memory */
return Status; return STATUS_INSUFFICIENT_RESOURCES;
} }
DeviceInstance.MaximumLength = DeviceInstance.Length = ((ULONG_PTR)StartPosition - (ULONG_PTR)SymbolicLinkName->Buffer) - 5 * sizeof(WCHAR);
RtlCopyMemory(DeviceInstance.Buffer, &SymbolicLinkName->Buffer[4], DeviceInstance.Length);
for(Index = 0; Index < DeviceInstance.Length / sizeof(WCHAR); Index++)
{
if (DeviceInstance.Buffer[Index] == L'#')
{
DeviceInstance.Buffer[Index] = L'\\';
}
}
PhysicalDeviceObject = IopGetDeviceObjectFromDeviceInstance(&DeviceInstance);
if (!PhysicalDeviceObject)
{
DPRINT1("IopGetDeviceObjectFromDeviceInstance failed to find status %wZ\n", &DeviceInstance);
ExFreePool(DeviceInstance.Buffer);
return STATUS_NOT_FOUND;
}
ExFreePool(DeviceInstance.Buffer);
Status = RtlGUIDFromString(&GuidString, &DeviceGuid); Status = RtlGUIDFromString(&GuidString, &DeviceGuid);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("RtlGUIDFromString() failed with status 0x%08lx\n", Status); DPRINT1("RtlGUIDFromString() failed with status 0x%08lx\n", Status);
ObDereferenceObject(FileObject); ObDereferenceObject(PhysicalDeviceObject);
return Status; return Status;
} }
@ -1409,7 +1427,7 @@ IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName,
&DeviceGuid, &DeviceGuid,
(PVOID)SymbolicLinkName); (PVOID)SymbolicLinkName);
ObDereferenceObject(FileObject); ObDereferenceObject(PhysicalDeviceObject);
DPRINT("Status %x\n", Status); DPRINT("Status %x\n", Status);
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }