RegRtlEnumKey

NTSTATUS __stdcall RegRtlEnumKey(
        VOID *hKey,
        UINT64 KeyIndex,
        WCHAR *KeyName,
        UINT64 *lpKeyNameLength,
        INT64 a5,
        INT64 a6,
        INT64 a7,
        INT64 a8){
  size_t *v11; 
  unsigned __int64 v12; 
  unsigned int v13; 
  WCHAR *p_KeyInformation; 
  NTSTATUS v15; 
  NTSTATUS v16; 
  size_t *v17; 
  unsigned int v18; 
  unsigned int v19; 
  VOID **PoolWithTag; 
  NTSTATUS v22; 
  unsigned int v23; 
  unsigned int v24; 
  UINT64 Length; 
  UINT64 Lengtha; 
  UINT64 Index; 
  char KeyInformation; 

  HIDWORD(Index) = KeyIndex;
  LODWORD(Index) = 0;
  v11 = 0i64;
  if( KeyName )
  {
    v12 = 2i64 * *(unsigned int *)lpKeyNameLength;
    if( v12 > 0xFFFFFFFF )
      return -1073741675;
  }
  else
  {
    LODWORD(v12) = 0;
  }
  v13 = 96;
  if( (unsigned int)v12 > 0x60 )
  {
    p_KeyInformation = KeyName;
    v13 = v12;
  }
  else
  {
    p_KeyInformation = (WCHAR *)&KeyInformation;
  }
  LODWORD(Length) = v13;
  v15 = ZwEnumerateKey(hKey, KeyIndex, KeyBasicInformation, p_KeyInformation, Length, &Index);
  v16 = v15;
  if( !v15 || v15 == -2147483643 )
  {
    v17 = (size_t *)(p_KeyInformation + 6);
    v18 = *((_DWORD *)p_KeyInformation + 3);
    v19 = v18 + 2;
    if( v18 + 2 >= v18 )
    {
      *(_DWORD *)lpKeyNameLength = v19 >> 1;
      if( v19 > (unsigned int)v12 )
        return -1073741789;
      if( (unsigned int)Index <= v13 )
        goto LABEL_9;
      if( (unsigned int)v12 < 0xFFFFFFF0 )
      {
        PoolWithTag = ExAllocatePoolWithTag(1ui64, (unsigned int)(v12 + 16), 1279739218i64);
        v11 = (size_t *)PoolWithTag;
        if( !PoolWithTag )
          return -1073741801;
        p_KeyInformation = (WCHAR *)PoolWithTag;
        LODWORD(Lengtha) = v12 + 16;
        v22 = ZwEnumerateKey(hKey, HIDWORD(Index), KeyBasicInformation, PoolWithTag, Lengtha, &Index);
        v16 = v22;
        if( v22 && v22 != -2147483643 )
          goto LABEL_10;
        v17 = v11 + 3;
        v23 = v11[3];
        v24 = v23 + 2;
        if( v23 + 2 < v23 )
        {
          v16 = -1073741675;
        }
        else
        {
          *(_DWORD *)lpKeyNameLength = v24 >> 1;
          if( v24 <= (unsigned int)v12 )
          {
LABEL_9:
            memmove(KeyName, p_KeyInformation + 8, *v17);
            v16 = 0;
            KeyName[*(_DWORD *)lpKeyNameLength - 1] = 0;
            goto LABEL_10;
          }
          v16 = -1073741789;
        }
LABEL_10:
        if( v11 )
          ExFreePoolWithTag(v11, 0);
        return v16;
      }
    }
    return -1073741675;
  }
  return v16;
}

Referenced by:

CmEnumDevicesInContainerWithCallbackWorker
CmGetDeviceContainerIdFromBase
PiCMDeleteDeviceKey
PiCMEnumerateSubKeys
PiDqDeleteUserObjectFromLoadedHives
PiDrvDbOverlayCopyKeys
PiDrvDbOverlayNodeHive
PnpGetGenericStorePropertyKeys
RegRtlCopyTreeInternal
RegRtlDeleteTreeInternal
RegRtlEnumKeyWithCallback