Is there a good way to check for the existence of a device outside of the current driver stack in a KMDF framework? Perhaps via something like the physical device object name. I want to know if \Device\MyDeviceXXX
exists from an unrelated driver. Also the device is a software-only device, no hardware involved.
Asked
Active
Viewed 65 times
0

James Parsons
- 6,097
- 12
- 68
- 108
-
dammit, thought there was a bug on my tv/monitor – ikegami Aug 07 '20 at 03:44
1 Answers
0
Depends on which IRQL you're running on. On PASSIVE_LEVEL you can try open the file, like:
UNICODE_STRING usname;
IO_STATUS_BLOCK iostatus;
OBJECT_ATTRIBUTES oa;
HANDLE hfile=NULL;
RtlInitUnicodeString(&usname, L"\\Device\\NDMP2"); // specify your device name here!!!
InitializeObjectAttributes(&oa, &usname, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
NTSTATUS status = ZwOpenFile(&hfile, GENERIC_READ, &oa, &iostatus, 0, 0);
if (status == 0 && hfile)
{
// opened OK - device exists
ZwClose(hfile);
}
else
{
// no such device and/or error
}

Kola73
- 134
- 1
- 7