IopGetRootDevices

NTSTATUS __stdcall IopGetRootDevices(DEVICE_RELATIONS **DeviceRelations){
  _WORD *PoolWithTag; 
  _ETHREAD *CurrentThread; 
  NTSTATUS inited; 
  unsigned int v5; 
  int MatchingFilteredDeviceList; 
  wchar_t *v7; 
  __int64 v8; 
  __int64 v9; 
  VOID *v10; 
  DEVICE_RELATIONS *v11; 
  UINT8 *v12; 
  PADAPTER_OBJECT *v14; 
  struct _UNICODE_STRING DestinationString; 
  __int128 Context; 
  void *Src; 
  unsigned int v18; 
  HANDLE Handle; 
  *DeviceRelations = 0i64;
  Handle = 0i64;
  PoolWithTag = 0i64;
  Context = 0i64;
  DestinationString = 0i64;
  Src = ExAllocatePoolWithTag(PagedPool, 0x400ui64, 0x64647050ui64);
  if( !Src )
    return -1073741670;
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  *(_QWORD *)((char *)&Context + 4) = 128i64;
  --*((_WORD *)CurrentThread + 242);
  ExAcquireResourceExclusiveLite(&PnpRegistryDeviceResource, 1u);
  v18 = 2048;
  inited = -1073741789;
  v5 = 0;
  while( v5 < 5 )
  {
    if( PoolWithTag )
      ExFreePoolWithTag(PoolWithTag, 0);
    PoolWithTag = ExAllocatePoolWithTag(PagedPool, 2i64 * v18, 0x64647050ui64);
    if( !PoolWithTag )
    {
      inited = -1073741670;
      break;
    }
    MatchingFilteredDeviceList = CmGetMatchingFilteredDeviceList(
                                   PiPnpRtlCtx,
                                   (__int64)L"Root",
                                   1,
                                   0i64,
                                   0i64,
                                   (__int64)PoolWithTag,
                                   v18,
                                   (__int64)&v18);
    ++v5;
    inited = MatchingFilteredDeviceList;
    if( MatchingFilteredDeviceList != -1073741789 )
    {
      if( MatchingFilteredDeviceList < 0 )
        break;
      v7 = PoolWithTag;
      LODWORD(Context) = 0;
      if( *PoolWithTag )
      {
        while( 1 )
        {
          inited = CmOpenDeviceRegKey(PiPnpRtlCtx, v7, 16, 0, 983103, 0, (__int64)&Handle, 0i64);
          if( inited < 0 )
            break;
          inited = RtlInitUnicodeStringEx(&DestinationString, v7);
          if( inited >= 0 && !(unsigned int)IopInitializeDeviceInstanceKey(Handle, &DestinationString, &Context) )
          {
            ZwClose(Handle);
            goto LABEL_17;
          }
          ZwClose(Handle);
          if( inited < 0 )
            break;
          v8 = -1i64;
          do
            ++v8;
          while( v7[v8] );
          v7 += v8 + 1;
          if( !*v7 )
            goto LABEL_17;
        }
LABEL_31:
        v9 = DWORD2(Context);
        if( !DWORD2(Context) )
          goto LABEL_32;
LABEL_21:
        if( inited >= 0 )
          break;
      }
      else
      {
LABEL_17:
        inited = Context;
        if( (int)Context < 0 )
          goto LABEL_31;
        v9 = DWORD2(Context);
        if( !DWORD2(Context) )
        {
LABEL_32:
          inited = -1073741823;
          goto LABEL_21;
        }
        v10 = ExAllocatePoolWithTag(PagedPool, 8i64 * DWORD2(Context) + 16, 0x64647050ui64);
        v11 = (DEVICE_RELATIONS *)v10;
        if( v10 )
        {
          v12 = (UINT8 *)Src;
          *(_DWORD *)v10 = v9;
          memmove((UINT8 *)v10 + 8, v12, 8i64 * (unsigned int)v9);
          *DeviceRelations = v11;
          goto LABEL_21;
        }
        inited = -1073741670;
      }
      if( (_DWORD)v9 )
      {
        v14 = (PADAPTER_OBJECT *)Src;
        do
        {
          HalPutDmaAdapter(*v14++);
          --v9;
        }
        while( v9 );
      }
      break;
    }
  }
  ExReleaseResourceLite(&PnpRegistryDeviceResource);
  KeLeaveCriticalRegionThread((__int64)KeGetCurrentThread());
  ExFreePoolWithTag(Src, 0);
  if( PoolWithTag )
    ExFreePoolWithTag(PoolWithTag, 0);
  return inited;
}

Referenced by:

IopPnPDispatch