PiDevCfgConfigureDeviceInterfaces

__int64 __fastcall PiDevCfgConfigureDeviceInterfaces(wchar_t *a1, void *a2, __int64 a3){
  const WCHAR *v3; 
  NTSTATUS v6; 
  int MatchingFilteredDeviceInterfaceList; 
  NTSTATUS v9; 
  wchar_t *PoolWithTag; 
  unsigned int v11; 
  NTSTATUS i; 
  int v13; 
  WCHAR v14; 
  int v15; 
  unsigned __int16 v16; 
  __int64 v17; 
  UINT64 Length; 
  UINT64 Lengtha; 
  HANDLE Handle; 
  UINT64 ResultLength; 
  PVOID P; 
  void *KeyHandle; 
  UNICODE_STRING InterfaceKeyName; 
  UINT64 VariableModifiers; 
  WCHAR *ReferenceString; 
  struct _OBJECT_ATTRIBUTES ObjectAttributes; 
  UNICODE_STRING v28; 
  struct _UNICODE_STRING DestinationString; 
  __int128 v30; 
  __int64 v31; 
  _UNICODE_STRING VariableName; 
  GUID InterfaceClassGuid; 
  v3 = 0i64;
  ObjectAttributes.RootDirectory = a2;
  Handle = 0i64;
  *(_QWORD *)&InterfaceKeyName.Length = 1441812i64;
  v31 = 0i64;
  ReferenceString = 0i64;
  InterfaceKeyName.Buffer = L"Interfaces";
  P = 0i64;
  ObjectAttributes.ObjectName = &InterfaceKeyName;
  LODWORD(ResultLength) = 0;
  *(_QWORD *)&ObjectAttributes.Length = 48i64;
  *(_QWORD *)&ObjectAttributes.Attributes = 576i64;
  v30 = 0i64;
  KeyHandle = 0i64;
  DestinationString = 0i64;
  VariableName = 0i64;
  InterfaceClassGuid = 0i64;
  *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
  v6 = ZwOpenKey(&KeyHandle, 0x20019u, &ObjectAttributes);
  MatchingFilteredDeviceInterfaceList = v6;
  if( v6 == -1073741772 )
  {
    MatchingFilteredDeviceInterfaceList = 0;
    goto LABEL_3;
  }
  if( v6 < 0 )
    goto LABEL_3;
  *(_DWORD *)&InterfaceKeyName.Length = 262146;
  InterfaceKeyName.Buffer = (wchar_t *)L"*";
  ObjectAttributes.RootDirectory = KeyHandle;
  *(_QWORD *)&ObjectAttributes.Length = 48i64;
  ObjectAttributes.ObjectName = &InterfaceKeyName;
  *(_QWORD *)&ObjectAttributes.Attributes = 576i64;
  *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
  v9 = ZwOpenKey(&Handle, 0x20019u, &ObjectAttributes);
  MatchingFilteredDeviceInterfaceList = v9;
  if( v9 == -1073741772 )
    goto LABEL_13;
  if( v9 < 0 )
    goto LABEL_3;
  *(_QWORD *)&v30 = Handle;
  *((_QWORD *)&v30 + 1) = a3;
  LODWORD(v31) = 0;
  MatchingFilteredDeviceInterfaceList = CmGetMatchingFilteredDeviceInterfaceList(
                                          PiPnpRtlCtx,
                                          0i64,
                                          (__int64)a1,
                                          0,
                                          (__int64)PiDevCfgConfigureDeviceInterfaceCallback,
                                          (__int64)&v30,
                                          0i64,
                                          0,
                                          (__int64)&ResultLength,
                                          0);
  ZwClose(Handle);
  Handle = 0i64;
  if( MatchingFilteredDeviceInterfaceList >= 0 )
  {
    MatchingFilteredDeviceInterfaceList = v31;
    if( (int)v31 >= 0 )
    {
LABEL_13:
      PoolWithTag = (wchar_t *)ExAllocatePoolWithTag(PagedPool, 0x26Eui64, 0x63647050ui64);
      if( !PoolWithTag )
      {
        MatchingFilteredDeviceInterfaceList = -1073741670;
        goto LABEL_3;
      }
      v11 = 0;
      LODWORD(Length) = 622;
      for( i = ZwEnumerateKey(KeyHandle, 0i64, KeyBasicInformation, PoolWithTag, Length, &ResultLength);
            ;
            i = ZwEnumerateKey(KeyHandle, v11, KeyBasicInformation, PoolWithTag, Lengtha, &ResultLength) )
      {
        MatchingFilteredDeviceInterfaceList = i;
        if( i < 0 )
        {
          if( i == -2147483622 )
          {
            MatchingFilteredDeviceInterfaceList = 0;
          }
          else if( i == -2147483643 )
          {
            MatchingFilteredDeviceInterfaceList = -1073741773;
          }
          goto LABEL_51;
        }
        PoolWithTag[((unsigned __int64)*((unsigned int *)PoolWithTag + 3) >> 1) + 8] = 0;
        if( wcsicmp(PoolWithTag + 8, L"*") )
          break;
LABEL_45:
        ++v11;
        LODWORD(Lengtha) = 622;
      }
      MatchingFilteredDeviceInterfaceList = RtlInitUnicodeStringEx(&DestinationString, PoolWithTag + 8);
      if( MatchingFilteredDeviceInterfaceList < 0 )
        goto LABEL_51;
      v28 = DestinationString;
      ObjectAttributes.RootDirectory = KeyHandle;
      *(_QWORD *)&ObjectAttributes.Length = 48i64;
      ObjectAttributes.ObjectName = &DestinationString;
      *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
      *(_QWORD *)&ObjectAttributes.Attributes = 576i64;
      Handle = 0i64;
      MatchingFilteredDeviceInterfaceList = ZwOpenKey(&Handle, 0x20019u, &ObjectAttributes);
      if( MatchingFilteredDeviceInterfaceList < 0 )
        goto LABEL_51;
      LODWORD(VariableModifiers) = 0;
      if( !a3
        || !*(_QWORD *)(a3 + 16)
        || !PiDevCfgParseVariableName(DestinationString.Buffer, &VariableName, &VariableModifiers) )
      {
        goto LABEL_39;
      }
      VariableModifiers = 0i64;
      v13 = PiDevCfgResolveVariable(a3, VariableName.Buffer, (CHAR **)&VariableModifiers);
      v14 = 0;
      MatchingFilteredDeviceInterfaceList = v13;
      if( v13 < 0 )
      {
        if( v13 == -1073741772 )
        {
          v28 = VariableName;
          goto LABEL_39;
        }
      }
      else
      {
        v15 = *(_DWORD *)(VariableModifiers + 32);
        if( (unsigned int)(v15 - 1) <= 1 )
        {
          v16 = *(_WORD *)(VariableModifiers + 36);
          v28.Buffer = *(wchar_t **)(VariableModifiers + 40);
          v28.MaximumLength = v16;
          v28.Length = v16 - 2;
LABEL_28:
          if( v3 )
          {
            if( *v3 )
            {
              while( 1 )
              {
                RtlInitUnicodeString(&InterfaceKeyName, v3, v14);
                if( PiDevCfgParseInterfaceKeyName(&InterfaceKeyName, &InterfaceClassGuid, &ReferenceString) )
                {
                  MatchingFilteredDeviceInterfaceList = IopRegisterDeviceInterface(
                                                          a1,
                                                          &InterfaceClassGuid,
                                                          ReferenceString,
                                                          1u,
                                                          (WCHAR **)&P,
                                                          0i64);
                  if( MatchingFilteredDeviceInterfaceList < 0 )
                    break;
                  MatchingFilteredDeviceInterfaceList = PiDevCfgConfigureDeviceInterface((WCHAR *)P, Handle, a3);
                  ExFreePoolWithTag(P, 0);
                  if( MatchingFilteredDeviceInterfaceList < 0 )
                    break;
                }
                v17 = -1i64;
                do
                  ++v17;
                while( v3[v17] );
                v3 += v17 + 1;
                if( !*v3 )
                  goto LABEL_36;
              }
LABEL_51:
              ExFreePoolWithTag(PoolWithTag, 0);
LABEL_3:
              if( Handle )
                ZwClose(Handle);
              goto LABEL_5;
            }
LABEL_36:
            v3 = 0i64;
            goto LABEL_42;
          }
LABEL_39:
          v3 = 0i64;
          if( !PiDevCfgParseInterfaceKeyName(&v28, &InterfaceClassGuid, &ReferenceString) )
          {
LABEL_43:
            ZwClose(Handle);
            goto LABEL_44;
          }
          MatchingFilteredDeviceInterfaceList = IopRegisterDeviceInterface(
                                                  a1,
                                                  &InterfaceClassGuid,
                                                  ReferenceString,
                                                  1u,
                                                  (WCHAR **)&P,
                                                  0i64);
          if( MatchingFilteredDeviceInterfaceList < 0 )
            goto LABEL_51;
          MatchingFilteredDeviceInterfaceList = PiDevCfgConfigureDeviceInterface((WCHAR *)P, Handle, a3);
          ExFreePoolWithTag(P, 0);
LABEL_42:
          if( MatchingFilteredDeviceInterfaceList < 0 )
            goto LABEL_51;
          goto LABEL_43;
        }
        if( v15 == 7 )
        {
          v3 = *(const WCHAR **)(VariableModifiers + 40);
          goto LABEL_28;
        }
      }
      ZwClose(Handle);
      v3 = 0i64;
LABEL_44:
      Handle = 0i64;
      goto LABEL_45;
    }
  }
LABEL_5:
  if( KeyHandle )
    ZwClose(KeyHandle);
  return(unsigned int)MatchingFilteredDeviceInterfaceList;
}

Referenced by:

PiDevCfgConfigureDeviceKeys