PiDevCfgBuildIndirectString

NTSTATUS __stdcall PiDevCfgBuildIndirectString(
        PI_DEVCFG_DRIVER_NODE *DriverNode,
        _UNICODE_STRING *StringToken,
        _UNICODE_STRING *IndirectString,
        _UNICODE_STRING *StringValue){
  unsigned __int64 Length; 
  int v9; 
  _KEY_VALUE_FULL_INFORMATION *v10; 
  wchar_t *Buffer; 
  __int64 v12; 
  unsigned __int64 v13; 
  wchar_t *StringRoutine; 
  wchar_t *v15; 
  NTSTATUS RegistryValue; 
  unsigned int DataLength; 
  _WORD *v18; 
  unsigned int v19; 
  unsigned __int16 v20; 
  int v21; 
  __int64 v22; 
  _UNICODE_STRING v23; 
  INT64 v25; 
  INT64 v26; 
  VOID *KeyHandle; 
  _UNICODE_STRING DestinationString; 
  __int128 v29; 
  _UNICODE_STRING RemainingString; 
  _UNICODE_STRING UnicodeString; 
  _OBJECT_ATTRIBUTES ObjectAttributes; 
  _KEY_VALUE_FULL_INFORMATION *Information; 

  Length = StringToken->Length;
  KeyHandle = 0i64;
  Information = 0i64;
  *(_QWORD *)&DestinationString.Length = 0i64;
  DestinationString.Buffer = 0i64;
  v9 = 0;
  v10 = 0i64;
  RemainingString = 0i64;
  v29 = 0i64;
  UnicodeString = 0i64;
  if( (unsigned int)Length <= 4 || (Buffer = StringToken->Buffer, *Buffer != 37) || Buffer[(Length >> 1) - 1] != 37 )
  {
    if( PnpDuplicateUnicodeString((__int64)IndirectString, (__int64)StringToken) )
    {
      if( StringValue )
        *StringValue = *IndirectString;
      goto LABEL_19;
    }
    goto LABEL_24;
  }
  *(_DWORD *)&RemainingString.Length = 1048590;
  RemainingString.Buffer = L"Strings";
  ObjectAttributes.RootDirectory = (void *)*((_QWORD *)DriverNode + 2);
  *(_QWORD *)&ObjectAttributes.Length = 48i64;
  ObjectAttributes.ObjectName = &RemainingString;
  *(_QWORD *)&ObjectAttributes.Attributes = 576i64;
  *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
  if( ZwOpenKey(
         &KeyHandle,
         0x20019ui64,
         &ObjectAttributes,
         (INT64)StringValue,
         v25,
         v26,
         (INT64)KeyHandle,
         *(INT64 *)&DestinationString.Length) >= 0 )
  {
    v12 = (unsigned __int16)(StringToken->Length - 4);
    v13 = (unsigned __int16)v12;
    UnicodeString.Length = StringToken->Length - 4;
    UnicodeString.MaximumLength = v12 + 2;
    StringRoutine = (wchar_t *)ExpAllocateStringRoutine((unsigned __int16)(v12 + 2));
    UnicodeString.Buffer = StringRoutine;
    v15 = StringRoutine;
    if( !StringRoutine )
      goto LABEL_24;
    memmove(StringRoutine, StringToken->Buffer + 1, v13);
    v15[v13 >> 1] = 0;
    RegistryValue = IopGetRegistryValue(KeyHandle, v15, 0i64, &Information);
    RtlFreeAnsiString(&UnicodeString);
    if( RegistryValue >= 0 )
    {
      v10 = Information;
      if( PnpValidateRegistryString(Information) )
      {
        DataLength = v10->DataLength;
        v18 = (_WORD *)((char *)v10 + v10->DataOffset);
        LODWORD(Information) = 0;
        PnpRegSzToString(v18, DataLength, (int *)&Information);
        LOWORD(v29) = (_WORD)Information;
        WORD1(v29) = v10->DataLength;
        *((_QWORD *)&v29 + 1) = (char *)v10 + v10->DataOffset;
      }
      else
      {
        ExFreePoolWithTag(v10, 0);
        v10 = 0i64;
      }
    }
  }
  v19 = *((unsigned __int16 *)DriverNode + 20) + StringToken->Length + 4;
  if( *((_QWORD *)&v29 + 1) )
    v19 += (unsigned __int16)v29 + 2;
  if( (unsigned __int64)v19 + 2 > 0xFFFE )
  {
    v9 = -1073741562;
    goto LABEL_19;
  }
  DestinationString.Length = v19;
  DestinationString.MaximumLength = v19 + 2;
  DestinationString.Buffer = (wchar_t *)ExpAllocateStringRoutine((unsigned __int16)(v19 + 2));
  if( !DestinationString.Buffer )
  {
LABEL_24:
    v9 = -1073741670;
    goto LABEL_19;
  }
  v9 = RtlUnicodeStringPrintfEx(&DestinationString, &RemainingString, 0x800ui64, (WCHAR *)L"@%wZ,%wZ");
  if( v9 < 0 )
    goto LABEL_19;
  v20 = DestinationString.Length;
  v21 = DestinationString.Length >> 1;
  if( *((_QWORD *)&v29 + 1) )
  {
    v9 = RtlUnicodeStringPrintf(&RemainingString, (WCHAR *)L";%wZ");
    if( v9 < 0 )
      goto LABEL_19;
    DestinationString.Length = RemainingString.Length + v20;
    v22 = (unsigned int)(v21 + 1);
  }
  else
  {
    v22 = v21 - (StringToken->Length >> 1);
  }
  v23 = DestinationString;
  DestinationString = 0i64;
  *IndirectString = v23;
  if( StringValue )
    RtlInitUnicodeString(StringValue, &IndirectString->Buffer[v22]);
LABEL_19:
  RtlFreeAnsiString(&DestinationString);
  if( v10 )
    ExFreePoolWithTag(v10, 0);
  if( KeyHandle )
    ZwClose((_HANDLE)KeyHandle);
  return v9;
}

Referenced by:

PiDevCfgConfigureDevice