PiDrvDbResolveFilePathKeyValues

INT64 __stdcall PiDrvDbResolveFilePathKeyValues(INT64 rcx0, INT8 dl0, UNICODE_STRING *r8, UNICODE_STRING *a4){
  unsigned int v6; 
  void *v7; 
  UINT64 v8; 
  _WORD *v9; 
  UNICODE_STRING *v10; 
  WCHAR v11; 
  WCHAR v12; 
  int v13; 
  int appended; 
  WCHAR v15; 
  UINT8 v16; 
  __int64 v17; 
  __int64 v18; 
  ULONG v19; 
  int v20; 
  unsigned int v21; 
  unsigned __int64 v22; 
  const wchar_t *v23; 
  WCHAR *v24; 
  ULONG *v25; 
  unsigned int v26; 
  unsigned int v27; 
  const WCHAR *v28; 
  unsigned __int64 v29; 
  ULONG v30; 
  int v31; 
  int v32; 
  unsigned __int16 Length; 
  _UNICODE_STRING *p_UnicodeString; 
  wchar_t *Buffer; 
  const WCHAR *v36; 
  unsigned int v37; 
  const WCHAR *v38; 
  int v39; 
  __int64 v40; 
  SIZE_T v42; 
  unsigned int v43; 
  SIZE_T NumberOfBytes; 
  struct _UNICODE_STRING DestinationString; 
  int v46; 
  ULONG v47; 
  HANDLE Handle; 
  struct _UNICODE_STRING UnicodeString; 
  HANDLE v50; 
  _WORD *v51; 
  VOID *PoolWithTag; 
  struct _UNICODE_STRING StringAppend; 
  struct _UNICODE_STRING MultiSz; 
  void *P[10]; 
  v50 = 0i64;
  v42 = 0i64;
  LODWORD(NumberOfBytes) = 0;
  v43 = 0;
  PoolWithTag = 0i64;
  DestinationString = 0i64;
  v6 = 0;
  v7 = 0i64;
  v51 = 0i64;
  LODWORD(v8) = 0;
  Handle = 0i64;
  v9 = 0i64;
  P[0] = 0i64;
  StringAppend = 0i64;
  v46 = 0;
  v10 = r8;
  UnicodeString = 0i64;
  MultiSz = 0i64;
  RtlInitUnicodeString(&DestinationString, 0i64, (WCHAR)r8);
  RtlInitUnicodeString(&UnicodeString, 0i64, v11);
  RtlInitUnicodeString(&MultiSz, 0i64, v12);
  v13 = SysCtxRegOpenKey(0i64, (char *)rcx0, L"Setup\\ResolveFilePaths", 0, 0x20019u, &v50);
  appended = v13;
  if( v13 == -1073741772 )
  {
    appended = 0;
    goto LABEL_88;
  }
  if( v13 >= 0 )
  {
    appended = PiDrvDbQuerySystemPathWin32(v10, &DestinationString);
    if( appended < 0 )
    {
      appended = 0;
      RtlInitUnicodeString(&DestinationString, 0i64, v15);
    }
    if( (dl0 & 2) != 0 )
    {
      if( v10 )
      {
        v16 = RtlEqualUnicodeString(v10, (UNICODE_STRING *)&PiDrvDbSystemRootNt, 1u);
        v10 = 0i64;
        if( !v16 )
          goto LABEL_17;
      }
      if( (UNICODE_STRING *)DestinationString.Buffer != v10
        && !RtlEqualUnicodeString(&DestinationString, (UNICODE_STRING *)&PiDrvDbSystemRootWin32, 1u) )
      {
        goto LABEL_17;
      }
    }
    else
    {
      v10 = 0i64;
    }
    if( (dl0 & 1) == 0
      || !a4
      || (UNICODE_STRING *)DestinationString.Buffer == v10
      || RtlEqualUnicodeString(a4, &DestinationString, 1u) )
    {
      appended = (int)v10;
      goto LABEL_84;
    }
LABEL_17:
    if( (int)PnpCtxRegQueryInfoKey(v17, v50, 0i64, 0i64, v10, &v42, &NumberOfBytes) >= 0 )
    {
      v8 = (unsigned int)NumberOfBytes;
      HIDWORD(v42) = NumberOfBytes;
      v6 = 2 * v42 + 2;
      v43 = v6;
      if( 2 * (_DWORD)v42 != -2 )
      {
        PoolWithTag = ExAllocatePoolWithTag(PagedPool, v6, 0x62647050ui64);
        v7 = PoolWithTag;
        if( !PoolWithTag )
        {
          appended = -1073741670;
          goto LABEL_88;
        }
      }
      if( (_DWORD)v8 )
      {
        v51 = ExAllocatePoolWithTag(PagedPool, v8, 0x62647050ui64);
        v9 = v51;
        if( !v51 )
        {
LABEL_23:
          appended = -1073741670;
LABEL_84:
          if( v7 )
            ExFreePoolWithTag(v7, 0);
LABEL_86:
          if( v9 )
            ExFreePoolWithTag(v9, 0);
          goto LABEL_88;
        }
      }
    }
    v19 = (unsigned int)v10;
LABEL_25:
    v47 = v19;
    LODWORD(NumberOfBytes) = v6 >> 1;
    LODWORD(v42) = v8;
    v20 = PnpCtxRegEnumValue(v18, v50, v19, v7, &NumberOfBytes, (__int64)&v46, v9, (__int64)&v42);
    if( v20 == -2147483622 )
      goto LABEL_84;
    if( v20 == -1073741789 )
    {
      if( (unsigned int)NumberOfBytes > v6 >> 1 )
      {
        v21 = 2 * NumberOfBytes;
        v43 = 2 * NumberOfBytes;
        if( v7 )
          ExFreePoolWithTag(v7, 0);
        PoolWithTag = ExAllocatePoolWithTag(PagedPool, v21, 0x62647050ui64);
        v7 = PoolWithTag;
        if( !PoolWithTag )
        {
          appended = -1073741670;
          goto LABEL_86;
        }
      }
      if( (unsigned int)v42 <= (unsigned int)v8 )
        goto LABEL_35;
      v8 = (unsigned int)v42;
      HIDWORD(v42) = v42;
      if( v9 )
        ExFreePoolWithTag(v9, 0);
      v51 = ExAllocatePoolWithTag(PagedPool, v8, 0x62647050ui64);
      v9 = v51;
      if( v51 )
      {
LABEL_35:
        --v19;
        goto LABEL_80;
      }
      goto LABEL_23;
    }
    if( v20 < 0 )
      goto LABEL_82;
    if( v46 != 7 )
      goto LABEL_80;
    if( (unsigned int)v42 < 4 )
      goto LABEL_80;
    v22 = (unsigned __int64)(unsigned int)v42 >> 1;
    if( v9[v22 - 1] )
      goto LABEL_80;
    if( v9[v22 - 2] )
      goto LABEL_80;
    v20 = SysCtxRegOpenKey(0i64, (char *)rcx0, (const WCHAR *)v7, 0, 0x2001Fu, &Handle);
    if( v20 == -1073741772 )
      goto LABEL_80;
    if( v20 < 0 )
    {
LABEL_82:
      appended = v20;
      goto LABEL_84;
    }
    v23 = v9;
    if( !*v9 )
      goto LABEL_79;
    while( 1 )
    {
      v24 = (WCHAR *)&word_1407CF120;
      if( wcsicmp(v23, L" ") )
        v24 = (WCHAR *)v23;
      NumberOfBytes = (SIZE_T)v24;
      if( IopGetRegistryValue(Handle, v24, 0i64, (KEY_VALUE_FULL_INFORMATION **)P) >= 0 )
        break;
LABEL_75:
      v40 = -1i64;
      do
        ++v40;
      while( v23[v40] );
      v23 += v40 + 1;
      if( !*v23 )
      {
LABEL_78:
        v9 = v51;
        v7 = PoolWithTag;
        LODWORD(v8) = HIDWORD(v42);
        v19 = v47;
LABEL_79:
        ZwClose(Handle);
        if( appended < 0 )
          goto LABEL_84;
LABEL_80:
        v6 = v43;
        ++v19;
        goto LABEL_25;
      }
    }
    v25 = (ULONG *)P[0];
    v26 = *((_DWORD *)P[0] + 1);
    if( v26 )
    {
      if( v26 <= 2 )
      {
        v37 = *((_DWORD *)P[0] + 3);
        v38 = (const WCHAR *)((char *)P[0] + *((unsigned int *)P[0] + 2));
        if( v37 - 3 > 0xFFFB || v38[((unsigned __int64)v37 >> 1) - 1] )
          goto LABEL_74;
        RtlInitUnicodeString(&StringAppend, v38, 0);
        UnicodeString.Length = 0;
        v39 = PiDrvDbResolveSystemFilePath(
                (__m128i *)&StringAppend,
                dl0,
                r8,
                (UNICODE_STRING *)((unsigned __int64)&DestinationString & -(__int64)(DestinationString.Buffer != 0i64)),
                a4,
                &UnicodeString);
        appended = v39;
        if( v39 == -1073741275 || v39 == -1073741637 )
        {
          appended = 0;
          goto LABEL_74;
        }
        if( v39 < 0 )
          goto LABEL_74;
        v36 = v24;
        Buffer = UnicodeString.Buffer;
        v30 = UnicodeString.Length + 2;
      }
      else
      {
        if( v26 != 7 )
          goto LABEL_74;
        v27 = *((_DWORD *)P[0] + 3);
        v28 = (const WCHAR *)((char *)P[0] + *((unsigned int *)P[0] + 2));
        if( v27 - 4 > 0xFFFA )
          goto LABEL_74;
        v29 = (unsigned __int64)v27 >> 1;
        if( v28[v29 - 1] || v28[v29 - 2] )
          goto LABEL_74;
        LOWORD(v30) = 0;
        v31 = 0;
        MultiSz.Length = 0;
        if( *v28 )
        {
          while( 1 )
          {
            RtlInitUnicodeString(&StringAppend, v28, 0);
            UnicodeString.Length = 0;
            v32 = PiDrvDbResolveSystemFilePath(
                    (__m128i *)&StringAppend,
                    dl0,
                    r8,
                    (UNICODE_STRING *)((unsigned __int64)&DestinationString & -(__int64)(DestinationString.Buffer != 0i64)),
                    a4,
                    &UnicodeString);
            appended = v32;
            if( v32 == -1073741275 || v32 == -1073741637 )
            {
              Length = 0;
              UnicodeString.Length = 0;
            }
            else
            {
              if( v32 < 0 )
                goto LABEL_74;
              Length = UnicodeString.Length;
              ++v31;
            }
            p_UnicodeString = &UnicodeString;
            if( !Length )
              p_UnicodeString = &StringAppend;
            appended = PiDevCfgAppendMultiSz(&MultiSz, p_UnicodeString, 0i64, 1u);
            if( appended < 0 )
              goto LABEL_74;
            v28 += ((unsigned __int64)StringAppend.Length >> 1) + 1;
            if( !*v28 )
            {
              LOWORD(v30) = MultiSz.Length;
              break;
            }
          }
        }
        if( !v31 )
          goto LABEL_74;
        Buffer = MultiSz.Buffer;
        v36 = (const WCHAR *)NumberOfBytes;
        v30 = (unsigned __int16)v30;
      }
      appended = RegRtlSetValue(Handle, v36, v25[1], Buffer, v30);
    }
LABEL_74:
    ExFreePoolWithTag(v25, 0);
    if( appended < 0 )
      goto LABEL_78;
    goto LABEL_75;
  }
LABEL_88:
  RtlFreeAnsiString(&DestinationString);
  RtlFreeAnsiString(&UnicodeString);
  RtlFreeAnsiString(&MultiSz);
  if( v50 )
    ZwClose(v50);
  return(unsigned int)appended;
}

Referenced by:

PiDrvDbResolveKeyFilePaths
PiDrvDbResolveNodeFilePaths