PiDevCfgResolveVariable

INT64 __fastcall PiDevCfgResolveVariable(INT64 a1, const WCHAR *a2, CHAR **a3){
  INT64 v3; 
  unsigned int v4; 
  unsigned int *v5; 
  __int64(__fastcall *v6)(INT64, void *, _OWORD *); 
  int v7; 
  int v8; 
  unsigned int v9; 
  _QWORD *v10; 
  _QWORD *v11; 
  void *v12; 
  NTSTATUS v13; 
  NTSTATUS RegistryValue; 
  const wchar_t **v15; 
  const wchar_t *v16; 
  unsigned int v17; 
  const wchar_t **v18; 
  __int64 v19; 
  _OWORD *PoolWithTag; 
  _OWORD *v22; 
  _QWORD *v23; 
  int v24; 
  wchar_t **v25; 
  UINT8 *v26; 
  __int64 v27; 
  unsigned int v28; 
  UINT8 *v29; 
  _DWORD *v30; 
  __int64 v31; 
  _QWORD *v32; 
  UINT64 Value; 
  void *KeyHandle; 
  PVOID P; 
  void *Src; 
  struct _UNICODE_STRING DestinationString; 
  struct _OBJECT_ATTRIBUTES ObjectAttributes; 
  const wchar_t *HashValue; 
  v3 = a1;
  v4 = 0;
  v5 = 0i64;
  LODWORD(HashValue) = 0;
  v6 = 0i64;
  KeyHandle = 0i64;
  v7 = 0;
  P = 0i64;
  DestinationString = 0i64;
  Src = 0i64;
  LODWORD(Value) = 0;
  if( !*a2 )
    return(unsigned int)-1073741772;
  *a3 = 0i64;
  RtlInitUnicodeString(&DestinationString, a2, (WCHAR)a3);
  v8 = RtlHashUnicodeString(&DestinationString, 1u, 0i64, (UINT64 *)&HashValue);
  v9 = (unsigned int)HashValue;
  if( v8 < 0 )
    v9 = 0;
  v10 = (_QWORD *)(*(_QWORD *)(v3 + 24) + 16i64 * (v9 % 0x7F));
  v11 = (_QWORD *)*v10;
  if( (_QWORD *)*v10 != v10 )
  {
    do
    {
      v22 = v11;
      if( RtlEqualUnicodeString(&DestinationString, (UNICODE_STRING *)v11 + 1, 1u) )
        break;
      v11 = (_QWORD *)*v11;
      v22 = 0i64;
    }
    while( v11 != v10 );
    if( v22 )
    {
      if( *((_DWORD *)v22 + 8) == -1 )
        return(unsigned int)-1073741823;
      goto LABEL_27;
    }
    v3 = a1;
  }
  v12 = *(void **)(v3 + 16);
  *(&ObjectAttributes.Length + 1) = 0;
  memset(&ObjectAttributes.Attributes + 1, 0, 20);
  ObjectAttributes.RootDirectory = v12;
  ObjectAttributes.Length = 48;
  ObjectAttributes.ObjectName = &DestinationString;
  ObjectAttributes.Attributes = 576;
  v13 = ZwOpenKey(&KeyHandle, 0x20019u, &ObjectAttributes);
  v4 = v13;
  if( v13 >= 0 )
  {
    RegistryValue = IopGetRegistryValue(KeyHandle, (PWCHAR)&dword_14098BF74, 0i64, (KEY_VALUE_FULL_INFORMATION **)&P);
    v5 = (unsigned int *)P;
    v4 = RegistryValue;
    if( RegistryValue < 0 )
      goto LABEL_29;
    if( !PnpValidateRegistryString((KEY_VALUE_FULL_INFORMATION *)P) )
    {
      v4 = -1073741823;
      goto LABEL_29;
    }
    v15 = (const wchar_t **)&off_140985A70;
    v16 = (const wchar_t *)((char *)v5 + v5[2]);
    HashValue = v16;
    v17 = 0;
    while( wcsicmp(*v15, v16) )
    {
      v16 = HashValue;
      ++v17;
      v15 += 2;
      if( v17 >= 8 )
        goto LABEL_11;
    }
    v6 = (__int64(__fastcall *)(INT64, void *, _OWORD *))*(&funcs_140773296 + 2 * v17);
    if( !v6 )
    {
LABEL_11:
      v4 = -1073741772;
      goto LABEL_29;
    }
LABEL_22:
    PoolWithTag = ExAllocatePoolWithTag(PagedPool, 0x30ui64, 0x63647050ui64);
    v22 = PoolWithTag;
    if( !PoolWithTag )
    {
      v4 = -1073741670;
      goto LABEL_29;
    }
    *PoolWithTag = 0i64;
    PoolWithTag[1] = 0i64;
    PoolWithTag[2] = 0i64;
    v23 = (_QWORD *)v10[1];
    if( (_QWORD *)*v23 != v10 )
LABEL_57:
      __fastfail(3u);
    *(_QWORD *)v22 = v10;
    *((_QWORD *)v22 + 1) = v23;
    *v23 = v22;
    v10[1] = v22;
    if( RtlCreateUnicodeString((UNICODE_STRING *)v22 + 1, (PWCHAR)a2) )
    {
      if( v6 )
      {
        *((_DWORD *)v22 + 8) = -1;
        v24 = v6(a1, KeyHandle, v22);
        v4 = v24;
        if( v24 >= 0 )
        {
LABEL_27:
          *a3 = (CHAR *)v22;
          v22 = 0i64;
          goto LABEL_28;
        }
        if( v24 == -1073741772 )
          v4 = -1073741823;
LABEL_28:
        if( !v22 )
          goto LABEL_29;
        v31 = *(_QWORD *)v22;
        if( *(_OWORD **)(*(_QWORD *)v22 + 8i64) == v22 )
        {
          v32 = (_QWORD *)*((_QWORD *)v22 + 1);
          if( (_OWORD *)*v32 == v22 )
          {
            *v32 = v31;
            *(_QWORD *)(v31 + 8) = v32;
            ExFreePoolWithTag(v22, 0);
LABEL_29:
            if( v5 )
              ExFreePoolWithTag(v5, 0);
            goto LABEL_18;
          }
        }
        goto LABEL_57;
      }
      v26 = (UINT8 *)Src;
      if( Src )
      {
        *((_DWORD *)v22 + 8) = 1;
        v27 = -1i64;
        do
          ++v27;
        while( *(_WORD *)&v26[2 * v27] );
        v28 = 2 * v27 + 2;
        *((_DWORD *)v22 + 9) = v28;
        v29 = (UINT8 *)ExAllocatePoolWithTag(PagedPool, v28, 0x63647050ui64);
        *((_QWORD *)v22 + 5) = v29;
        if( v29 )
        {
          memmove(v29, v26, *((unsigned int *)v22 + 9));
          goto LABEL_27;
        }
      }
      else
      {
        *((_DWORD *)v22 + 8) = 4;
        *((_DWORD *)v22 + 9) = 4;
        v30 = ExAllocatePoolWithTag(PagedPool, 4ui64, 0x63647050ui64);
        *((_QWORD *)v22 + 5) = v30;
        if( v30 )
        {
          *v30 = v7;
          goto LABEL_27;
        }
      }
    }
    v4 = -1073741670;
    goto LABEL_28;
  }
  if( v13 == -1073741772 )
  {
    v4 = 0;
    v18 = (const wchar_t **)&off_1409854C0;
    v19 = 0i64;
    while( wcsicmp(*v18, a2) )
    {
      v19 = (unsigned int)(v19 + 1);
      v18 += 3;
      if( (unsigned int)v19 >= 4 )
        goto LABEL_16;
    }
    v25 = &(&off_1409854C0)[3 * v19];
    if( v25 )
    {
      v7 = *((_DWORD *)v25 + 4);
      Src = v25[1];
      goto LABEL_22;
    }
LABEL_16:
    if( PnpStringToDwordValue((PWCHAR)a2, &Value) )
    {
      v7 = Value;
      goto LABEL_22;
    }
    v4 = -1073741772;
  }
LABEL_18:
  if( KeyHandle )
    ZwClose(KeyHandle);
  return v4;
}

Referenced by:

PiDevCfgConfigureDeviceInterfaces
PiDevCfgCopyDeviceKey
PiDevCfgQueryResolveValue
PiDevCfgResolveVariableExpression
PiDevCfgResolveVariableFormatString
PiDevCfgResolveVariableKeyHandle
PiDevCfgResolveVariableKeyValue
PiDevCfgResolveVariableSwitchCase