DrvDbSetDeviceIdDriverInfMatches

__int64 __fastcall DrvDbSetDeviceIdDriverInfMatches(__int64 a1, void *a2, __int64 a3){
  const wchar_t *v3; 
  int inited; 
  unsigned int v6; 
  WCHAR *v7; 
  WCHAR *v8; 
  __int64 v9; 
  unsigned int v10; 
  __int64 v11; 
  void *PoolWithTag; 
  ULONG v13; 
  int v14; 
  const WCHAR *v15; 
  size_t v16; 
  __int64 v17; 
  WCHAR v18; 
  __int64 v20; 
  ULONG v21; 
  int *v22; 
  ULONG v23; 
  unsigned int v24; 
  ULONG v25; 
  int v26; 
  int v27; 
  int v28; 
  unsigned int v29; 
  int v30; 
  struct _UNICODE_STRING DestinationString; 
  unsigned int MaxCount; 
  int MaxCount_4; 
  HANDLE KeyHandle; 
  const wchar_t *v35; 
  unsigned int v36; 
  v35 = (const wchar_t *)a3;
  KeyHandle = a2;
  MaxCount_4 = HIDWORD(a1);
  v3 = (const wchar_t *)a3;
  v36 = 0;
  MaxCount = 0;
  v28 = 0;
  v27 = 0;
  v30 = PnpCtxRegQueryInfoKey(a1, a2, 0i64, 0i64, &v36, &MaxCount, 0i64);
  inited = v30;
  if( v30 >= 0 )
  {
    v6 = MaxCount + 1;
    v29 = MaxCount + 1;
    if( v3 )
    {
      v7 = (WCHAR *)v3;
      if( *v3 )
      {
        do
        {
          v8 = wcschr(v7, 0x5Cu);
          if( v8 )
          {
            v9 = v8 - v7;
          }
          else
          {
            v9 = -1i64;
            do
              ++v9;
            while( v7[v9] );
          }
          v10 = v9 + 1;
          if( v10 > v6 )
            v6 = v10;
          v11 = -1i64;
          do
            ++v11;
          while( v7[v11] );
          v7 += v11 + 1;
        }
        while( *v7 );
        inited = v30;
        v29 = v6;
      }
      PoolWithTag = ExAllocatePoolWithTag(PagedPool, 2i64 * v6, 0x42444450ui64);
      if( PoolWithTag )
      {
        v13 = 0;
        if( v36 )
        {
          while( 1 )
          {
            MaxCount = v6;
            v14 = PnpCtxRegEnumValue(0i64, KeyHandle, v13, PoolWithTag, &MaxCount, (__int64)&v28, 0i64, 0i64);
            inited = v14;
            if( v14 < 0 )
              break;
            if( v28 == 3 || !v28 )
            {
              v15 = v3;
              if( *v3 )
              {
                v16 = MaxCount;
                do
                {
                  if( !(unsigned int)wcsncmp(v15, (const WCHAR *)PoolWithTag, v16) )
                  {
                    v18 = v15[v16];
                    if( v18 == 92 || !v18 )
                      break;
                  }
                  v17 = -1i64;
                  do
                    ++v17;
                  while( v15[v17] );
                  v15 += v17 + 1;
                }
                while( *v15 );
                v3 = v35;
                v6 = v29;
              }
              if( !*v15 )
              {
                DestinationString = 0i64;
                inited = RtlInitUnicodeStringEx(&DestinationString, (WCHAR *)PoolWithTag);
                if( inited >= 0 )
                  inited = ZwDeleteValueKey(KeyHandle, &DestinationString);
                if( inited == -1073741772 )
                {
                  inited = 0;
                }
                else if( inited < 0 )
                {
                  goto LABEL_28;
                }
              }
            }
            if( ++v13 >= v36 )
              goto LABEL_27;
          }
          if( v14 == -2147483622 )
            inited = 0;
        }
LABEL_27:
        if( inited >= 0 )
        {
          while( *v3 )
          {
            inited = DrvDbSplitDeviceIdDriverInfMatch(v3, (NTSTRSAFE_PWSTR)PoolWithTag, v6, (__int64)&v27);
            if( inited < 0 )
              break;
            if( (_BYTE)v27 )
            {
              v21 = 3;
              v22 = &v27;
              v23 = 4;
            }
            else
            {
              v21 = 0;
              v22 = 0i64;
              v23 = 0;
            }
            inited = RegRtlSetValue(KeyHandle, (const WCHAR *)PoolWithTag, v21, v22, v23);
            if( inited < 0 )
              break;
            v20 = -1i64;
            do
              ++v20;
            while( v3[v20] );
            v3 += v20 + 1;
          }
        }
LABEL_28:
        ExFreePoolWithTag(PoolWithTag, 0);
        return(unsigned int)inited;
      }
    }
    else
    {
      v24 = v36;
      if( !v36 )
        return 0;
      PoolWithTag = ExAllocatePoolWithTag(PagedPool, 2i64 * v6, 0x42444450ui64);
      if( PoolWithTag )
      {
        v25 = 0;
        if( v24 )
        {
          while( 1 )
          {
            MaxCount = v6;
            inited = PnpCtxRegEnumValue(0i64, a2, v25, PoolWithTag, &MaxCount, 0i64, 0i64, 0i64);
            if( inited < 0 )
              break;
            DestinationString = 0i64;
            inited = RtlInitUnicodeStringEx(&DestinationString, (WCHAR *)PoolWithTag);
            if( inited >= 0 )
              inited = ZwDeleteValueKey(a2, &DestinationString);
            if( (int)(inited + 0x80000000) < 0 || inited == -1073741772 )
            {
              v26 = 0;
              if( inited != -1073741772 )
                v26 = inited;
              ++v25;
              inited = v26;
              if( v25 < v24 )
                continue;
            }
            goto LABEL_28;
          }
          if( inited == -2147483622 )
            inited = 0;
        }
        goto LABEL_28;
      }
    }
    return(unsigned int)-1073741801;
  }
  return(unsigned int)inited;
}

Referenced by:

DrvDbSetDeviceIdMappedProperty