IopBuildFullDriverPath

NTSTATUS __stdcall IopBuildFullDriverPath(_UNICODE_STRING *KeyName, PVOID KeyHandle, _UNICODE_STRING *FullPath){
  int appended; 
  NTSTATUS RegistryValue; 
  _KEY_VALUE_FULL_INFORMATION *v8; 
  ULONG DataLength; 
  wchar_t *v10; 
  unsigned __int16 Length; 
  unsigned int v12; 
  VOID **Pool_1; 
  _UNICODE_STRING v15; 
  _UNICODE_STRING String2; 
  _UNICODE_STRING Source; 
  _UNICODE_STRING DestinationString; 
  _UNICODE_STRING String1; 
  _UNICODE_STRING v20; 
  _UNICODE_STRING v21; 
  _UNICODE_STRING v22; 
  _KEY_VALUE_FULL_INFORMATION *Information; 

  *(_QWORD *)&String1.Length = 1703960i64;
  *(_QWORD *)&v20.Length = 2359330i64;
  String1.Buffer = L"\\SystemRoot\\";
  v20.Buffer = L"System32\\Drivers\\";
  DestinationString = 0i64;
  Source = 0i64;
  v21 = 0i64;
  String2 = 0i64;
  v22 = 0i64;
  RtlInitUnicodeString(FullPath, 0i64);
  RtlInitUnicodeString(&DestinationString, 0i64);
  RtlInitUnicodeString(&Source, 0i64);
  RtlInitUnicodeString(&v21, 0i64);
  RtlInitUnicodeString(&String2, 0i64);
  RtlInitUnicodeString(&v22, 0i64);
  Information = 0i64;
  appended = IopQueryRegistryKeySystemPath((_HANDLE)KeyHandle, &DestinationString);
  if( appended < 0 )
    goto LABEL_16;
  RegistryValue = IopGetRegistryValue(KeyHandle, (PWCHAR)L"ImagePath", 0x100ui64, &Information);
  v8 = Information;
  if( RegistryValue < 0 || (DataLength = Information->DataLength, DataLength < 2) )
  {
    Source = DestinationString;
    v15 = *KeyName;
    v21 = v20;
    String2 = v15;
    RtlInitUnicodeString(&v22, L".SYS");
    Length = String2.Length;
  }
  else
  {
    if( DataLength > 0xFFFF )
      goto LABEL_20;
    v10 = (wchar_t *)((char *)Information + Information->DataOffset);
    String2.MaximumLength = Information->DataLength;
    Length = DataLength - 2;
    String2.Buffer = v10;
    String2.Length = DataLength - 2;
    if( *v10 == 92 )
    {
      if( (unsigned __int8)RtlPrefixUnicodeString(&String1, &String2, 1u) )
      {
        Length -= 24;
        Source = DestinationString;
        String2.Length = Length;
        String2.Buffer = v10 + 12;
      }
      else
      {
        RtlInitUnicodeString(&Source, 0i64);
      }
    }
    else
    {
      Source = DestinationString;
    }
  }
  v12 = Source.Length + 2 + v21.Length + v22.Length + Length;
  if( v12 <= 0xFFFF )
  {
    FullPath->MaximumLength = v12;
    FullPath->Length = 0;
    Pool_1 = IopVerifierExAllocatePool_1(1ui64, (unsigned __int16)v12);
    FullPath->Buffer = (wchar_t *)Pool_1;
    if( Pool_1 )
    {
      appended = RtlAppendUnicodeStringToString(FullPath, &Source);
      if( appended >= 0 )
      {
        appended = RtlAppendUnicodeStringToString(FullPath, &v21);
        if( appended >= 0 )
        {
          appended = RtlAppendUnicodeStringToString(FullPath, &String2);
          if( appended >= 0 )
          {
            appended = RtlAppendUnicodeStringToString(FullPath, &v22);
            if( appended >= 0 )
              FullPath->Buffer[(unsigned __int64)FullPath->Length >> 1] = 0;
          }
        }
      }
    }
    else
    {
      appended = -1073741670;
    }
    goto LABEL_14;
  }
LABEL_20:
  appended = -2147483643;
LABEL_14:
  if( v8 )
    ExFreePoolWithTag(v8, 0);
LABEL_16:
  RtlFreeAnsiString(&DestinationString);
  return appended;
}

Referenced by:

IopLoadDriver
PiNormalizeDeviceText
PpCheckInDriverDatabase