pIoQueryBusDescription

NTSTATUS __stdcall pIoQueryBusDescription(
        _IO_QUERY_DESC *QueryDescription,
        _UNICODE_STRING *PathName,
        VOID *RootHandle,
        UINT64 *BusNum,
        UINT8 HighKey){
  int BusDescription; 
  NTSTATUS result; 
  _KEY_FULL_INFORMATION *v9; 
  ULONG MaxNameLen; 
  ULONG v11; 
  unsigned __int16 *PoolWithTag; 
  unsigned int v13; 
  _DWORD *v14; 
  UINT64 v15; 
  int v16; 
  _KEY_VALUE_FULL_INFORMATION *v17; 
  _DWORD *v18; 
  UINT64 v19; 
  _DWORD *v20; 
  NTSTATUS DeviceDescription; 
  _KEY_VALUE_FULL_INFORMATION **Length; 
  PVOID KeyHandle; 
  UINT64 ResultLength; 
  _KEY_FULL_INFORMATION *Information[2]; 
  _UNICODE_STRING Destination; 
  PVOID BaseHandle; 
  _UNICODE_STRING KeyName; 
  _UNICODE_STRING *v29; 
  _KEY_VALUE_FULL_INFORMATION *ValueList[2]; 
  PVOID P; 

  v29 = PathName;
  BaseHandle = RootHandle;
  P = 0i64;
  BusDescription = 0;
  KeyHandle = 0i64;
  Information[0] = 0i64;
  LODWORD(ResultLength) = 0;
  KeyName = 0i64;
  Destination = 0i64;
  *(_OWORD *)ValueList = 0i64;
  result = IopGetRegistryKeyInformation(RootHandle, Information);
  if( result >= 0 )
  {
    v9 = Information[0];
    MaxNameLen = Information[0]->MaxNameLen;
    v11 = MaxNameLen + 32;
    if( MaxNameLen + 32 < MaxNameLen )
    {
      return -1073741675;
    }
    else
    {
      PoolWithTag = (unsigned __int16 *)ExAllocatePoolWithTag(1ui64, v11, 1112239945i64);
      ExFreePoolWithTag(v9, 0);
      if( PoolWithTag )
      {
        v13 = 0;
        do
        {
          v14 = (_DWORD *)*((_QWORD *)QueryDescription + 1);
          if( v14 && *v14 == *(_DWORD *)BusNum )
            break;
          LODWORD(Length) = v11;
          BusDescription = ZwEnumerateKey(
                             BaseHandle,
                             v13,
                             KeyBasicInformation,
                             PoolWithTag,
                             (UINT64)Length,
                             &ResultLength);
          if( BusDescription < 0 )
            break;
          if( !HighKey
            || !wcsncmp(PoolWithTag + 8, L"MultifunctionAdapter", *((_DWORD *)PoolWithTag + 3) >> 1)
            || !wcsncmp(PoolWithTag + 8, L"EisaAdapter", *((_DWORD *)PoolWithTag + 3) >> 1)
            || !wcsncmp(PoolWithTag + 8, L"TcAdapter", *((_DWORD *)PoolWithTag + 3) >> 1) )
          {
            KeyName.Buffer = PoolWithTag + 8;
            KeyName.Length = PoolWithTag[6];
            KeyName.MaximumLength = PoolWithTag[6];
            if( IopOpenRegistryKey(&KeyHandle, BaseHandle, &KeyName, 0x20019ui64, 0) >= 0 )
            {
              Destination = *v29;
              RtlAppendUnicodeToString(&Destination, (WCHAR *)L"\\");
              RtlAppendUnicodeStringToString(&Destination, &KeyName);
              if( HighKey )
                goto LABEL_21;
              IopGetRegistryValues(KeyHandle, ValueList, v15);
              BusDescription = v16;
              if( v16 >= 0 )
              {
                v17 = ValueList[1];
                if( ValueList[1] )
                {
                  if( ValueList[1]->DataLength )
                  {
                    if( *(ULONG *)((char *)&ValueList[1]->TitleIndex + ValueList[1]->DataOffset) == **(_DWORD **)QueryDescription )
                    {
                      v19 = (unsigned int)(*(_DWORD *)BusNum + 1);
                      *(_DWORD *)BusNum = v19;
                      v20 = (_DWORD *)*((_QWORD *)QueryDescription + 1);
                      if( !v20 || *v20 == (_DWORD)v19 )
                      {
                        if( *((_QWORD *)QueryDescription + 2) )
                        {
                          *(_UNICODE_STRING *)Information = Destination;
                          DeviceDescription = pIoQueryDeviceDescription(
                                                QueryDescription,
                                                (_UNICODE_STRING *)Information,
                                                v17,
                                                v19,
                                                ValueList);
                        }
                        else
                        {
                          Length = ValueList;
                          DeviceDescription = (*((__int64(__fastcall **)(_QWORD, _UNICODE_STRING *, _QWORD))QueryDescription
                                               + 6))(
                                                *((_QWORD *)QueryDescription + 7),
                                                &Destination,
                                                **(unsigned int **)QueryDescription);
                        }
                        v17 = ValueList[1];
                        BusDescription = DeviceDescription;
                      }
                    }
                  }
                }
                if( ValueList[0] )
                {
                  ExFreePoolWithTag(ValueList[0], 0);
                  v17 = ValueList[1];
                  ValueList[0] = 0i64;
                }
                if( v17 )
                {
                  ExFreePoolWithTag(v17, 0);
                  ValueList[1] = 0i64;
                }
                if( P )
                {
                  ExFreePoolWithTag(P, 0);
                  P = 0i64;
                }
              }
              v18 = (_DWORD *)*((_QWORD *)QueryDescription + 1);
              if( !v18 || *v18 != *(_DWORD *)BusNum )
              {
LABEL_21:
                *(_UNICODE_STRING *)Information = Destination;
                BusDescription = pIoQueryBusDescription(
                                   QueryDescription,
                                   (_UNICODE_STRING *)Information,
                                   KeyHandle,
                                   BusNum,
                                   HighKey == 0);
                if( BusDescription == -2147483622 )
                  BusDescription = 0;
              }
              ZwClose((_HANDLE)KeyHandle);
              KeyHandle = 0i64;
            }
          }
          ++v13;
        }
        while( BusDescription >= 0 );
        ExFreePoolWithTag(PoolWithTag, 0);
        return BusDescription;
      }
      else
      {
        return -1073741670;
      }
    }
  }
  return result;
}

Referenced by:

IoQueryDeviceDescription
pIoQueryBusDescription