PiDevCfgResolveMultiSzValue

NTSTATUS __stdcall PiDevCfgResolveMultiSzValue(
        UINT64 ValueType,
        UINT64 ValueSize,
        VOID *ValueData,
        UINT64 ValueModifiers,
        VOID *KeyHandle,
        WCHAR *ValueName,
        UINT64 *ValueSizeResult,
        VOID **ValueDataResult){
  VOID **v8; 
  size_t v9; 
  int v10; 
  _WORD *v11; 
  int v12; 
  _KEY_VALUE_FULL_INFORMATION *v13; 
  char v14; 
  NTSTATUS RegistryValue; 
  NTSTATUS v16; 
  size_t DataLength; 
  VOID **v18; 
  WCHAR v19; 
  size_t v20; 
  int v21; 
  WCHAR *v22; 
  __int64 v23; 
  size_t v24; 
  const wchar_t *v26; 
  unsigned int v27; 
  WCHAR v28; 
  bool v29; 
  size_t v30; 
  size_t v31; 
  VOID **PoolWithTag; 
  NTSTATUS v33; 
  size_t v34; 
  _KEY_VALUE_FULL_INFORMATION *Information; 
  VOID *Src[2]; 
  _UNICODE_STRING DestinationString; 
  int v38; 

  v38 = ValueType;
  v8 = 0i64;
  v9 = ValueSize;
  Information = 0i64;
  v10 = ValueModifiers;
  v11 = ValueData;
  *(_DWORD *)ValueSizeResult = 0;
  v12 = ValueType;
  v13 = 0i64;
  DestinationString = 0i64;
  *(_OWORD *)Src = 0i64;
  *ValueDataResult = 0i64;
  if( !(_DWORD)ValueType )
    goto LABEL_58;
  if( (unsigned int)ValueType <= 2 )
  {
    v14 = PnpValidateStringData((__int64)ValueData, ValueSize);
  }
  else
  {
    if( (_DWORD)ValueType != 7 )
      goto LABEL_58;
    v14 = PnpValidateMultiSzData(ValueData, ValueSize);
  }
  if( !v14 )
    return -1073741823;
  RegistryValue = IopGetRegistryValue(KeyHandle, ValueName, 0i64, &Information);
  v13 = Information;
  v16 = RegistryValue;
  v33 = RegistryValue;
  if( RegistryValue < 0 )
  {
    if( RegistryValue == -1073741772 )
    {
      v16 = 0;
      if( (v10 & 0x40000) == 0 )
      {
        DataLength = 0;
        goto LABEL_24;
      }
      v31 = v9 + 2;
      if( v12 == 7 )
        v31 = v9;
      DataLength = v31;
      PoolWithTag = ExAllocatePoolWithTag(1ui64, v31, 1667526736i64);
      v8 = PoolWithTag;
      if( PoolWithTag )
      {
        memmove(PoolWithTag, v11, v9);
        goto LABEL_24;
      }
      v13 = Information;
      v16 = -1073741670;
    }
    goto LABEL_27;
  }
  if( !PnpValidateRegistryMultiSz(Information) )
  {
LABEL_58:
    v16 = -1073741823;
    goto LABEL_27;
  }
  if( (v10 & 0x40000) != 0 )
  {
    DataLength = v13->DataLength;
    Src[0] = (char *)v13 + v13->DataOffset;
    if( !DataLength )
      DataLength = 2;
    v18 = ExAllocatePoolWithTag(1ui64, DataLength + v9, 1667526736i64);
    v20 = 0;
    v8 = v18;
    if( v18 )
    {
      if( DataLength > 2 )
      {
        memmove(v18, Src[0], DataLength);
        v20 = DataLength - 2;
      }
      v21 = v10 & 0x20000;
      v34 = v20;
      if( v38 != 7 )
      {
        if( v21 || DataLength == 2 || !PnpMultiSzContainsString((WCHAR *)Src[0], v11, v19) )
        {
          memmove((char *)v8 + v34, v11, v9);
          DataLength += v9;
        }
        goto LABEL_24;
      }
      if( v21 )
      {
        memmove((char *)v8 + v20, v11, v9);
        DataLength = DataLength + v9 - 2;
        goto LABEL_24;
      }
      if( !*v11 )
      {
LABEL_24:
        if( v8 )
          *((_WORD *)v8 + ((unsigned __int64)DataLength >> 1) - 1) = 0;
        *(_DWORD *)ValueSizeResult = DataLength;
        *ValueDataResult = v8;
        goto LABEL_27;
      }
      v22 = (WCHAR *)Src[0];
      do
      {
        v23 = -1i64;
        do
          ++v23;
        while( v11[v23] );
        v24 = 2 * v23 + 2;
        if( !PnpMultiSzContainsString(v22, v11, v19) )
        {
          memmove((char *)v8 + v34, v11, v24);
          v34 += v24;
          DataLength += v24;
        }
        v11 += (unsigned __int64)v24 >> 1;
      }
      while( *v11 );
LABEL_23:
      v13 = Information;
      goto LABEL_24;
    }
  }
  else
  {
    v8 = ExAllocatePoolWithTag(1ui64, v13->DataLength, 1667526736i64);
    if( v8 )
    {
      if( v12 != 7 )
        RtlInitUnicodeString(&DestinationString, v11);
      DataLength = 2;
      v26 = (const wchar_t *)((char *)v13 + v13->DataOffset);
      if( !*v26 )
        goto LABEL_24;
      v27 = 0;
      do
      {
        RtlInitUnicodeString((PUNICODE_STRING)Src, v26);
        if( v38 == 7 )
          v29 = PnpMultiSzContainsString(v11, (const WCHAR *)Src[1], v28) == 0i64;
        else
          v29 = (unsigned __int8)RtlEqualUnicodeString(&DestinationString, (PCUNICODE_STRING)Src, 1u) == 0;
        if( v29 )
        {
          v30 = LOWORD(Src[0]) + 2;
          memmove((char *)v8 + v27, Src[1], v30);
          v27 += v30;
          DataLength += v30;
        }
        v26 += ((unsigned __int64)LOWORD(Src[0]) >> 1) + 1;
      }
      while( *v26 );
      v16 = v33;
      goto LABEL_23;
    }
  }
  v16 = -1073741670;
LABEL_27:
  if( v13 )
    ExFreePoolWithTag(v13, 0);
  return v16;
}

Referenced by:

PiDevCfgCopyDeviceKey