A forum for reverse engineering, OS internals and malware analysis 

Forum for discussion about kernel-mode development.
 #15287  by Vrtule
 Tue Aug 21, 2012 9:02 pm
Hello,

I would like to determine the structure of device tree in the similar way DeviceTree utility does. For example, I would like to know what devices are connected to certain USB bus, or what volumes exist on certain hard disk.

When I found IRP_MN_QUERY_DEVICE_RELATIONS I thought the problem is no logner a problem. However, this is not true. When I query RemovalRelations, I get volumes present on given disk drive (I have not tested mirrored or stripped volumes yet). To determine what devices are connected to certain bus/ USB hub etc., BusRelations seems to be a reasonable idea. But it is not, because the operation is stateful (and strictly prohibited in the documentation).

Is tehere any safe altenrative to IRP_MN_QUERY_DEVICE_RELATIONS::BusRelations? Maybe I can do the following:
1) hook device chain of the target (bus) device
2) call IoInvalidateDeviceRelations(theTargetDevice, BusRelations);
3) Detect the IRP_MN_QUERY_RELATIONS IRP sent by the PNP Manager
4) Wait until the IRP is complete and get the information about the child devices in the completion routine
5) unhook the device chain

Has this approach a chance to work? Or is there any alternative?

Thanks in advance