PiDevCfgQueryIncludedDriverNode

INT64 __fastcall PiDevCfgQueryIncludedDriverNode(INT64 a1, const WCHAR *a2, const WCHAR *a3, INT64 a4, INT64 *a5){
  int v5; 
  WCHAR *v7; 
  KEY_VALUE_FULL_INFORMATION *v9; 
  NTSTATUS v10; 
  int v11; 
  NTSTATUS v12; 
  int v13; 
  int v14; 
  NTSTATUS v15; 
  UINT8 v16; 
  __int64 v17; 
  NTSTATUS DriverPackageId; 
  int v19; 
  NTSTATUS v20; 
  __int64 v21; 
  VOID *PoolWithTag; 
  INT64 v23; 
  NTSTATUS RegistryValue; 
  WCHAR *i; 
  int v26; 
  char v27; 
  int DriverConfigurationKeyScope; 
  int v29; 
  int v30; 
  __int64 v31; 
  WCHAR v32; 
  HANDLE KeyHandle; 
  KEY_VALUE_FULL_INFORMATION *Information; 
  struct _UNICODE_STRING UnicodeString; 
  HANDLE Handle; 
  v5 = a4;
  *(_QWORD *)&UnicodeString.Length = 0i64;
  UnicodeString.Buffer = 0i64;
  v7 = (WCHAR *)a2;
  Handle = 0i64;
  KeyHandle = 0i64;
  v9 = 0i64;
  Information = 0i64;
  if( !a2 )
  {
    v15 = PiDevCfgOpenDriverConfiguration(*(PVOID *)(a1 + 16), (PWCHAR)a3, &KeyHandle);
    v11 = v15;
    if( v15 == -1073741772 )
    {
      v11 = 0;
    }
    else if( v15 < 0 )
    {
      goto LABEL_73;
    }
    if( !KeyHandle )
    {
      v7 = *(WCHAR **)(a1 + 344);
      if( !v7 )
        goto LABEL_24;
      if( *v7 )
      {
        while( 1 )
        {
          DriverPackageId = PiDevCfgGetDriverPackageId(v7, &UnicodeString);
          v11 = DriverPackageId;
          if( DriverPackageId == -1073741772 )
            goto LABEL_41;
          if( DriverPackageId < 0 )
            goto LABEL_73;
          v19 = PnpOpenObjectRegKey(PiPnpRtlCtx, (__int64)UnicodeString.Buffer, 8u, 131097, 0, (__int64)&Handle);
          v11 = v19;
          if( v19 == -1073741772 )
            break;
          if( v19 < 0 )
            goto LABEL_73;
          v20 = PiDevCfgOpenDriverConfiguration(Handle, (PWCHAR)a3, &KeyHandle);
          v11 = v20;
          if( v20 < 0 )
          {
            if( v20 != -1073741772 )
              goto LABEL_37;
            ZwClose(Handle);
            Handle = 0i64;
            RtlFreeAnsiString(&UnicodeString);
            v21 = -1i64;
            do
              ++v21;
            while( v7[v21] );
            v7 += v21 + 1;
            if( *v7 )
              continue;
          }
          goto LABEL_38;
        }
        v11 = -1073740655;
      }
LABEL_37:
      if( v11 < 0 )
        goto LABEL_73;
LABEL_38:
      if( !KeyHandle )
      {
LABEL_24:
        v11 = -1073740654;
        goto LABEL_75;
      }
      goto LABEL_39;
    }
    v7 = *(WCHAR **)(a1 + 48);
    goto LABEL_17;
  }
  if( !wcsicmp(a2, *(const wchar_t **)(a1 + 48)) )
  {
    v10 = PiDevCfgOpenDriverConfiguration(*(PVOID *)(a1 + 16), (PWCHAR)a3, &KeyHandle);
    v11 = v10;
    if( v10 != -1073741772 )
    {
      if( v10 < 0 )
        goto LABEL_73;
LABEL_17:
      v16 = PnpDuplicateUnicodeString(&UnicodeString, (UNICODE_STRING *)(a1 + 56));
      v17 = 0i64;
      if( !v16 )
      {
LABEL_40:
        v11 = -1073741670;
        goto LABEL_73;
      }
      if( PiPnpRtlCtx )
        v17 = *(_QWORD *)(PiPnpRtlCtx + 224);
      v14 = SysCtxRegOpenKey(v17, *(char **)(a1 + 16), 0i64, 0, 0x20019u, &Handle);
      v11 = v14;
      goto LABEL_21;
    }
LABEL_11:
    v11 = -1073740654;
    goto LABEL_73;
  }
  v12 = PiDevCfgGetDriverPackageId(v7, &UnicodeString);
  v11 = v12;
  if( v12 != -1073741772 )
  {
    if( v12 < 0 )
      goto LABEL_73;
    v13 = PnpOpenObjectRegKey(PiPnpRtlCtx, (__int64)UnicodeString.Buffer, 8u, 131097, 0, (__int64)&Handle);
    v11 = v13;
    if( v13 != -1073741772 )
    {
      if( v13 < 0 )
        goto LABEL_73;
      v14 = PiDevCfgOpenDriverConfiguration(Handle, (PWCHAR)a3, &KeyHandle);
      v11 = v14;
      if( v14 != -1073741772 )
      {
LABEL_21:
        if( v14 < 0 )
          goto LABEL_73;
LABEL_39:
        PoolWithTag = ExAllocatePoolWithTag(PagedPool, 0x1A0ui64, 0x63647050ui64);
        v23 = (INT64)PoolWithTag;
        if( !PoolWithTag )
          goto LABEL_40;
        memset((INT64)PoolWithTag, 0i64);
        *(_DWORD *)(v23 + 184) = 32;
        *(_QWORD *)(v23 + 232) = v23 + 224;
        *(_QWORD *)(v23 + 224) = v23 + 224;
        *(_QWORD *)(v23 + 216) = v23 + 208;
        *(_QWORD *)(v23 + 208) = v23 + 208;
        *(_QWORD *)(v23 + 376) = v23 + 368;
        *(_QWORD *)(v23 + 368) = v23 + 368;
        if( RtlCreateUnicodeString((UNICODE_STRING *)(v23 + 40), v7)
          && PnpDuplicateUnicodeString((UNICODE_STRING *)(v23 + 56), &UnicodeString)
          && RtlCreateUnicodeString((UNICODE_STRING *)(v23 + 88), (PWCHAR)a3) )
        {
          *(_DWORD *)(v23 + 104) = v5;
          RegistryValue = IopGetRegistryValue(KeyHandle, (PWCHAR)L"IncludeScope", 0i64, &Information);
          v9 = Information;
          v11 = RegistryValue;
          if( RegistryValue == -1073741772 )
          {
            v11 = 0;
LABEL_68:
            *(_QWORD *)(v23 + 16) = Handle;
            *(_QWORD *)(v23 + 32) = KeyHandle;
            Handle = 0i64;
            KeyHandle = 0i64;
            *a5 = v23;
            v23 = 0i64;
            goto LABEL_69;
          }
          if( RegistryValue >= 0 )
          {
            if( !PnpValidateRegistryMultiSz(Information) )
            {
              v11 = -1073741823;
              goto LABEL_69;
            }
            for( i = (WCHAR *)((char *)v9 + v9->DataOffset); ; i += v31 + 1 )
            {
              v32 = *i;
              if( !*i )
                goto LABEL_68;
              v26 = *i - 42;
              if( *i == 42 )
                v26 = i[1];
              if( !v26 )
              {
                *(_DWORD *)(v23 + 104) = -1;
                goto LABEL_68;
              }
              v27 = 1;
              if( v32 != 43 )
              {
                if( v32 != 45 )
                  goto LABEL_59;
                v27 = 0;
              }
              ++i;
LABEL_59:
              DriverConfigurationKeyScope = PiDevCfgGetDriverConfigurationKeyScope(i);
              v29 = *(_DWORD *)(v23 + 104);
              if( v27 )
                v30 = DriverConfigurationKeyScope | v29;
              else
                v30 = ~DriverConfigurationKeyScope & v29;
              v31 = -1i64;
              *(_DWORD *)(v23 + 104) = v30;
              do
                ++v31;
              while( i[v31] );
            }
          }
        }
        else
        {
          v11 = -1073741670;
        }
LABEL_69:
        if( v23 )
          PiDevCfgFreeDriverNode(v23);
        if( v9 )
          ExFreePoolWithTag(v9, 0);
        goto LABEL_73;
      }
      goto LABEL_11;
    }
  }
LABEL_41:
  v11 = -1073740655;
LABEL_73:
  if( KeyHandle )
    ZwClose(KeyHandle);
LABEL_75:
  if( Handle )
    ZwClose(Handle);
  RtlFreeAnsiString(&UnicodeString);
  return(unsigned int)v11;
}

Referenced by:

PiDevCfgQueryIncludedDriverConfigurations