HalpQueryDeviceRelations

NTSTATUS __stdcall HalpQueryDeviceRelations(
        _DEVICE_OBJECT *DeviceObject,
        _DEVICE_RELATION_TYPE RelationType,
        _DEVICE_RELATIONS **DeviceRelations){
  _QWORD *DeviceExtension; 
  __int64 v6; 
  unsigned int v7; 
  __int64 v9; 
  VOID **v10; 
  _DEVICE_RELATIONS *v11; 
  __int64 v12; 
  _DEVICE_OBJECT *v13; 
  VOID **PoolWithTag; 
  _DEVICE_RELATIONS *v15; 

  DeviceExtension = DeviceObject->DeviceExtension;
  if( *(_DWORD *)DeviceExtension == 193 )
    v6 = DeviceExtension[1];
  else
    v6 = 0i64;
  v7 = 0;
  if( RelationType )
  {
    if( RelationType != TargetDeviceRelation || !v6 )
      return -1073741637;
    PoolWithTag = ExAllocatePoolWithTag(1ui64, 0x10ui64, 543973704i64);
    v15 = (_DEVICE_RELATIONS *)PoolWithTag;
    if( PoolWithTag )
    {
      *(_DWORD *)PoolWithTag = 1;
      PoolWithTag[1] = DeviceObject;
      ObfReferenceObject(DeviceObject);
      *DeviceRelations = v15;
      return 0;
    }
  }
  else
  {
    if( !v6 )
      return -1073741637;
    v9 = v6;
    do
    {
      v9 = *(_QWORD *)(v9 + 8);
      ++v7;
    }
    while( v9 );
    v10 = ExAllocatePoolWithTag(1ui64, 16i64 * v7, 543973704i64);
    v11 = (_DEVICE_RELATIONS *)v10;
    if( v10 )
    {
      *(_DWORD *)v10 = v7;
      v12 = 0i64;
      do
      {
        v13 = *(_DEVICE_OBJECT **)(v6 + 16);
        v11->Objects[v12] = v13;
        ObfReferenceObject(v13);
        v6 = *(_QWORD *)(v6 + 8);
        v12 = (unsigned int)(v12 + 1);
      }
      while( v6 );
      *DeviceRelations = v11;
      return 0;
    }
  }
  return -1073741670;
}

Referenced by:

HalpDispatchPnp