IopQueryDeviceResources

VOID __fastcall IopQueryDeviceResources(
        _DEVICE_OBJECT *DeviceObject,
        UINT64 ResourceType,
        VOID **Resource,
        UINT64 *Length){
  int v5; 
  _IO_RESOURCE_REQUIREMENTS_LIST *v8; 
  void *DeviceNode; 
  NTSTATUS v10; 
  __int64 v11; 
  unsigned int *v12; 
  NTSTATUS DeviceResourcesFromRegistry; 
  VOID **PoolWithTag; 
  PVOID v15; 
  UINT64 v16; 
  VOID **v17; 
  PVOID v18; 
  int v19; 
  int v20; 
  UINT64 *Information; 
  UINT64 *Informationa; 
  UINT64 Create; 
  _UNICODE_STRING ValueName; 
  PVOID P; 
  _IO_RESOURCE_REQUIREMENTS_LIST *v26; 
  PVOID Src; 
  _IO_STACK_LOCATION TopStackLocation; 
  int v29; 
  ULONG v30; 
  _IO_RESOURCE_REQUIREMENTS_LIST *Requirements; 
  PVOID v32; 

  *Resource = 0i64;
  v5 = ResourceType;
  Requirements = 0i64;
  Src = 0i64;
  P = 0i64;
  v32 = 0i64;
  v26 = 0i64;
  v8 = 0i64;
  v29 = 0;
  *(_DWORD *)Length = 0;
  memset(&TopStackLocation, 0i64, sizeof(TopStackLocation));
  DeviceNode = DeviceObject->DeviceObjectExtension->DeviceNode;
  *(_QWORD *)&ValueName.Length = DeviceNode;
  if( !v5 )
  {
    if( (*((_DWORD *)DeviceNode + 99) & 1) != 0 )
    {
      PnpGetDeviceResourcesFromRegistry((__int64)DeviceObject, 0, 7, Resource, (ULONG *)Length);
    }
    else
    {
      *(_WORD *)&TopStackLocation.MajorFunction = 2587;
      v10 = IopSynchronousCall(DeviceObject, &TopStackLocation, 3221225659i64, 0i64, (UINT64 *)Resource);
      if( v10 == -1073741637 )
      {
        *Resource = 0i64;
        v10 = 0;
      }
      if( v10 >= 0 )
        *(_DWORD *)Length = PnpDetermineResourceListSize(*Resource);
    }
    return;
  }
  if( PnpGetDeviceResourcesFromRegistry((__int64)DeviceObject, 0, 2, Resource, &v30) != -1073741772 )
  {
    if( *Resource )
    {
      v8 = (_IO_RESOURCE_REQUIREMENTS_LIST *)PnpCmResourcesToIoResources(v11, *Resource, 0);
      ExFreePoolWithTag(*Resource, 0);
      if( !v8 )
      {
        *Resource = 0i64;
        *(_DWORD *)Length = 0;
        return;
      }
      *Resource = v8;
      *(_DWORD *)Length = v8->ListSize;
    }
    goto LABEL_17;
  }
  if( PnpGetDeviceResourcesFromRegistry((__int64)DeviceObject, 1, 1, (VOID **)&Requirements, &v30) != -1073741772 )
  {
    v8 = Requirements;
    goto LABEL_16;
  }
  if( (*((_DWORD *)DeviceNode + 99) & 1) != 0 )
  {
    DeviceResourcesFromRegistry = PnpGetDeviceResourcesFromRegistry(
                                    (__int64)DeviceObject,
                                    1,
                                    2,
                                    (VOID **)&Requirements,
                                    &v30);
    if( DeviceResourcesFromRegistry == -1073741772 )
      goto LABEL_14;
    goto LABEL_50;
  }
  v12 = (unsigned int *)*((_QWORD *)DeviceNode + 55);
  if( !v12 )
  {
    DeviceResourcesFromRegistry = PpIrpQueryResourceRequirements(DeviceObject, &Requirements);
    if( DeviceResourcesFromRegistry == -1073741637 )
    {
      v8 = 0i64;
LABEL_14:
      DeviceResourcesFromRegistry = 0;
      goto LABEL_15;
    }
LABEL_50:
    v8 = Requirements;
LABEL_15:
    if( DeviceResourcesFromRegistry < 0 )
      return;
    goto LABEL_16;
  }
  PoolWithTag = ExAllocatePoolWithTag(1ui64, *v12, 538996816i64);
  v8 = (_IO_RESOURCE_REQUIREMENTS_LIST *)PoolWithTag;
  if( !PoolWithTag )
    return;
  memmove(PoolWithTag, *((const VOID **)DeviceNode + 55), **((_DWORD **)DeviceNode + 55));
LABEL_16:
  if( PnpGetDeviceResourcesFromRegistry((__int64)DeviceObject, 0, 4, &P, &v30) >= 0 )
  {
    v18 = P;
    if( !P || !*(_DWORD *)P || *((_DWORD *)P + 1) != 5 )
    {
      v19 = PnpFilterResourceRequirementsList(v8, (unsigned int *)P, (char **)&v32, &v29);
      if( v18 )
        ExFreePoolWithTag(v18, 0);
      if( v19 < 0 )
      {
        if( v8 )
          ExFreePoolWithTag(v8, 0);
        return;
      }
      DeviceNode = *(void **)&ValueName.Length;
      if( (*(_DWORD *)(*(_QWORD *)&ValueName.Length + 396i64) & 1) != 0 || v29 && v8->AlternativeLists <= 1 )
      {
        if( v8 )
          ExFreePoolWithTag(v8, 0);
        v8 = (_IO_RESOURCE_REQUIREMENTS_LIST *)v32;
      }
      else
      {
        v20 = PnpMergeFilteredResourceRequirementsList(v32, v8, (unsigned int **)&v26);
        if( v8 )
          ExFreePoolWithTag(v8, 0);
        if( v32 )
          ExFreePoolWithTag(v32, 0);
        if( v20 < 0 )
          return;
        v8 = v26;
      }
    }
  }
LABEL_17:
  if( IopFilterResourceRequirementsCall(DeviceObject, v8, &Src) >= 0 )
  {
    v15 = Src;
    *(_DWORD *)(&ValueName.MaximumLength + 1) = 0;
    Requirements = 0i64;
    if( Src )
    {
      v16 = *(unsigned int *)Src;
      *(_DWORD *)Length = *(_DWORD *)Src;
      v17 = ExAllocatePoolWithTag(1ui64, v16, 538996816i64);
      *Resource = v17;
      if( !v17 )
      {
        ExFreePoolWithTag(v15, 0);
        return;
      }
      memmove(v17, v15, *(_DWORD *)Length);
      ExFreePoolWithTag(v15, 0);
    }
    else
    {
      *(_DWORD *)Length = 0;
      *Resource = 0i64;
    }
    LODWORD(Information) = 131097;
    if( CmOpenDeviceRegKey(
           *(&stru_140CF2E80 + 607),
           *((WCHAR **)DeviceNode + 6),
           CM_KEY_TYPE_DEVICE_CONTROL,
           0i64,
           (UINT64)Information,
           1u,
           (VOID **)&Requirements,
           0i64) >= 0 )
    {
      ValueName.Buffer = L"FilteredConfigVector";
      LODWORD(Create) = *(_DWORD *)Length;
      Informationa = (UINT64 *)*Resource;
      *(_DWORD *)&ValueName.Length = 2752552;
      ZwSetValueKey(Requirements, &ValueName, 0i64, 0xAui64, Informationa, Create);
      ZwClose((_HANDLE)Requirements);
    }
  }
  else
  {
    *Resource = v8;
    if( v8 )
      *(_DWORD *)Length = v8->ListSize;
    else
      *(_DWORD *)Length = 0;
  }
}

Referenced by:

IopReleaseDeviceResources
PiQueryAndAllocateBootResources
PnpGetResourceRequirementsForAssignTable