PiDevCfgQueryPolicyStringList

INT64 __stdcall PiDevCfgQueryPolicyStringList(PVOID PolicyKeyHandle, WCHAR *PolicyName, WCHAR **PolicyStringList){
  unsigned int v3; 
  int v4; 
  void *v5; 
  int RegistryValue; 
  unsigned int *v9; 
  WCHAR v10; 
  unsigned int v11; 
  KEY_VALUE_FULL_INFORMATION *PoolWithTag; 
  unsigned int v13; 
  unsigned int v14; 
  unsigned int v15; 
  unsigned int v16; 
  NTSTATUS i; 
  unsigned int v18; 
  PULONG ResultLength; 
  UINT64 dwFlags; 
  UINT64 v22; 
  size_t *pcchRemaining; 
  void *KeyHandle; 
  struct _UNICODE_STRING DestinationString; 
  WCHAR **v26; 
  struct _OBJECT_ATTRIBUTES ObjectAttributes; 
  __int128 KeyInformation; 
  __int128 v29; 
  __int64 v30; 
  v3 = 0;
  v26 = PolicyStringList;
  KeyHandle = 0i64;
  pcchRemaining = 0i64;
  v30 = 0i64;
  LODWORD(v22) = 0;
  DestinationString = 0i64;
  v4 = 0;
  v5 = 0i64;
  KeyInformation = 0i64;
  v29 = 0i64;
  RegistryValue = IopGetRegistryValue(PolicyKeyHandle, PolicyName, 0i64, (KEY_VALUE_FULL_INFORMATION **)&pcchRemaining);
  if( RegistryValue < 0 )
  {
    PoolWithTag = (KEY_VALUE_FULL_INFORMATION *)pcchRemaining;
LABEL_36:
    if( PoolWithTag )
      ExFreePoolWithTag(PoolWithTag, 0);
    goto LABEL_38;
  }
  if( PnpValidateRegistryDword((KEY_VALUE_FULL_INFORMATION *)pcchRemaining) )
    v4 = *(unsigned int *)((char *)v9 + v9[2]);
  ExFreePoolWithTag(v9, 0);
  if( v4 != 1 )
    goto LABEL_5;
  RtlInitUnicodeString(&DestinationString, PolicyName, v10);
  *(_QWORD *)&ObjectAttributes.Length = 48i64;
  ObjectAttributes.ObjectName = &DestinationString;
  *(_QWORD *)&ObjectAttributes.Attributes = 576i64;
  ObjectAttributes.RootDirectory = PolicyKeyHandle;
  *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
  RegistryValue = ZwOpenKey(&KeyHandle, 0x20019u, &ObjectAttributes);
  if( RegistryValue >= 0 )
  {
    RegistryValue = NtQueryKey(KeyHandle, KeyCachedInformation, &KeyInformation, 0x28ui64, &v22);
    if( RegistryValue >= 0 )
    {
      if( !DWORD1(v29) )
      {
LABEL_5:
        RegistryValue = -1073741275;
        goto LABEL_38;
      }
      v11 = HIDWORD(v29) + 2 * (DWORD2(v29) + 12);
      LODWORD(pcchRemaining) = v11;
      PoolWithTag = (KEY_VALUE_FULL_INFORMATION *)ExAllocatePoolWithTag(PagedPool, v11, 0x63647050ui64);
      if( !PoolWithTag )
      {
        RegistryValue = -1073741670;
        goto LABEL_38;
      }
      v13 = DWORD1(v29) * HIDWORD(v29) + 2;
      while( 2 )
      {
        if( v5 )
          ExFreePoolWithTag(v5, 0);
        v5 = ExAllocatePoolWithTag(PagedPool, v13, 0x63647050ui64);
        if( v5 )
        {
          v14 = v13 >> 1;
          v15 = 0;
          LODWORD(ResultLength) = v11;
          v16 = 0;
          for( i = ZwEnumerateValueKey(
                      KeyHandle,
                      0i64,
                      KeyValueFullInformation,
                      PoolWithTag,
                      (UINT64)ResultLength,
                      &v22);
                ;
                i = ZwEnumerateValueKey(KeyHandle, v3, KeyValueFullInformation, PoolWithTag, (UINT64)ResultLength, &v22) )
          {
            RegistryValue = i;
            if( i == -2147483622 )
              break;
            if( i == -2147483643 )
            {
              ExFreePoolWithTag(PoolWithTag, 0);
              LODWORD(pcchRemaining) = v22;
              PoolWithTag = (KEY_VALUE_FULL_INFORMATION *)ExAllocatePoolWithTag(
                                                            PagedPool,
                                                            (unsigned int)v22,
                                                            0x63647050ui64);
              if( !PoolWithTag )
              {
                RegistryValue = -1073741670;
                goto LABEL_32;
              }
              --v3;
            }
            else
            {
              if( i < 0 )
                goto LABEL_32;
              if( PnpValidateRegistryString(PoolWithTag) )
              {
                RegistryValue = RtlInitUnicodeStringEx(
                                  &DestinationString,
                                  (WCHAR *)((char *)PoolWithTag + PoolWithTag->DataOffset));
                if( RegistryValue < 0 )
                  goto LABEL_32;
                v15 += DestinationString.MaximumLength >> 1;
                if( v14 > v15 )
                {
                  LODWORD(dwFlags) = 2304;
                  RtlStringCchCopyExW((WCHAR *)v5 + v16, v14 - v16, DestinationString.Buffer, 0i64, 0i64, dwFlags);
                  v16 += DestinationString.MaximumLength >> 1;
                }
              }
            }
            ++v3;
            LODWORD(ResultLength) = (_DWORD)pcchRemaining;
          }
          v3 = 0;
          RegistryValue = 0;
          if( v15 )
          {
            v18 = v15 + 1;
            if( v14 < v18 )
            {
              v11 = (unsigned int)pcchRemaining;
              v13 = 2 * v18;
              continue;
            }
            *((_WORD *)v5 + v16) = 0;
            *v26 = (WCHAR *)v5;
            v5 = 0i64;
          }
          else
          {
            RegistryValue = -1073741275;
          }
LABEL_32:
          if( v5 )
            ExFreePoolWithTag(v5, 0);
        }
        else
        {
          RegistryValue = -1073741670;
        }
        goto LABEL_36;
      }
    }
  }
LABEL_38:
  if( KeyHandle )
    ZwClose(KeyHandle);
  return(unsigned int)RegistryValue;
}

Referenced by:

PiDevCfgEnforceDevicePolicy