DrvDbGetDeviceIdDriverInfMatches

NTSTATUS __stdcall DrvDbGetDeviceIdDriverInfMatches(
        VOID *ObjectBaseKey,
        WCHAR *DriverInfMatches,
        UINT64 DriverInfMatchesLen,
        UINT64 *RequiredLen,
        UINT8 IncludeMatchData){
  unsigned int *v5; 
  ULONG v6; 
  UINT64 v7; 
  NTSTATUS v8; 
  unsigned int v9; 
  unsigned int v10; 
  unsigned int v11; 
  __int64 v12; 
  VOID **PoolWithTag; 
  NTSTATUS v14; 
  const WCHAR *v15; 
  __int64 v16; 
  int v17; 
  unsigned int v18; 
  unsigned int v19; 
  UINT64 dwFlags; 
  _DRVDB_DRIVER_INF_MATCH_DATA DriverInfMatchData; 
  int v23; 
  unsigned int v24; 
  unsigned int v25; 
  unsigned int v26; 
  int v27; 
  WCHAR *v28; 
  UINT64 v29; 
  unsigned int v30; 
  char v31; 

  v30 = (unsigned int)RequiredLen;
  v29 = DriverInfMatchesLen;
  v28 = DriverInfMatches;
  v27 = HIDWORD(ObjectBaseKey);
  v5 = (unsigned int *)IncludeMatchData;
  v6 = 0;
  v7 = DriverInfMatchesLen;
  v24 = 0;
  v26 = 0;
  v23 = 0;
  DriverInfMatchData = 0;
  v25 = 0;
  *(_DWORD *)IncludeMatchData = 0;
  v8 = PnpCtxRegQueryInfoKey((__int64)&v24, DriverInfMatches, 0i64, 0i64, &v24, &v26, 0i64);
  if( v8 >= 0 )
  {
    v9 = v24;
    v10 = v26 + 1;
    if( v24 )
    {
      v11 = v26 + 1;
      if( v31 )
      {
        v11 = v26 + 17;
        v10 = v26 + 17;
      }
      PoolWithTag = ExAllocatePoolWithTag(1ui64, 2i64 * v11, 1111770192i64);
      if( PoolWithTag )
      {
        if( v9 )
        {
          do
          {
            v26 = v10;
            if( v31 )
            {
              *(_DWORD *)&IncludeMatchData = 4;
              v14 = PnpCtxRegEnumValue(
                      v12,
                      (_HANDLE)v28,
                      v6,
                      PoolWithTag,
                      (INT64)&v26,
                      &v23,
                      (INT64)&DriverInfMatchData);
              v8 = v14;
              if( v14 < 0 )
                goto LABEL_37;
              if( !v26 )
              {
LABEL_35:
                v8 = -1073741595;
                goto LABEL_26;
              }
              if( v23 == 3 )
              {
                if( IncludeMatchData != 4 )
                  goto LABEL_35;
              }
              else
              {
                DriverInfMatchData = 0;
              }
              v8 = DrvDbBuildDeviceIdDriverInfMatch(v15, &DriverInfMatchData, (WCHAR *)PoolWithTag + v26, v10 - v26);
              if( v8 < 0 )
                goto LABEL_26;
              v16 = -1i64;
              do
                ++v16;
              while( *((_WORD *)PoolWithTag + v16) );
              v17 = v16 + 1;
            }
            else
            {
              v14 = PnpCtxRegEnumValue(v12, (_HANDLE)v28, v6, PoolWithTag, (INT64)&v26, &v23, 0i64);
              v8 = v14;
              if( v14 < 0 )
              {
LABEL_37:
                if( v14 == -2147483622 )
                  v8 = 0;
                break;
              }
              v12 = v26;
              if( !v26 )
              {
                v8 = -1073741595;
                break;
              }
              *((_WORD *)PoolWithTag + v26) = 0;
              v17 = v12 + 1;
            }
            if( v7 )
            {
              v12 = v25;
              v18 = v17 + v25;
              if( v17 + v25 < v30 )
              {
                LODWORD(dwFlags) = 2304;
                RtlStringCchCopyExW((WCHAR *)(v29 + 2i64 * v25), v30 - v25, (WCHAR *)PoolWithTag, 0i64, 0i64, dwFlags);
                v25 = v18;
              }
              v7 = v29;
            }
            *v5 += v17;
            ++v6;
          }
          while( v6 < v24 );
        }
        if( v8 >= 0 )
        {
          if( *v5 )
          {
            v19 = *v5 + 1;
            *v5 = v19;
            if( v7 && v19 <= v30 )
              *(_WORD *)(v7 + 2i64 * (v19 - 1)) = 0;
            else
              v8 = -1073741789;
          }
          else
          {
            v8 = -1073741275;
          }
        }
LABEL_26:
        ExFreePoolWithTag(PoolWithTag, 0);
      }
      else
      {
        return -1073741801;
      }
    }
    else
    {
      return -1073741275;
    }
  }
  return v8;
}

Referenced by:

DrvDbGetDeviceIdMappedProperty