PiFindDevInstMatch

NTSTATUS __stdcall PiFindDevInstMatch(
        VOID *ServiceEnumHandle,
        _UNICODE_STRING *DeviceInstanceName,
        UINT64 *Count,
        _UNICODE_STRING *MatchingValueName,
        UINT64 *MatchingInstance){
  UINT64 *v5; 
  int v6; 
  int v9; 
  unsigned int v10; 
  NTSTATUS result; 
  _KEY_VALUE_FULL_INFORMATION *v12; 
  VOID **PoolWithTag; 
  VOID **v14; 
  __int64 v15; 
  NTSTATUS v16; 
  unsigned int v17; 
  wchar_t *v18; 
  _UNICODE_STRING v19; 
  VOID **v20; 
  UINT64 dwFlags; 
  _UNICODE_STRING ValueName; 
  _UNICODE_STRING String1; 
  UINT64 ResultLength; 
  _KEY_VALUE_FULL_INFORMATION *Information; 

  v5 = MatchingInstance;
  v6 = 0;
  MatchingValueName->Length = 0;
  MatchingValueName->Buffer = 0i64;
  *(_DWORD *)v5 = -1;
  *(_DWORD *)Count = 0;
  LODWORD(ResultLength) = 0;
  v9 = 256;
  Information = 0i64;
  ValueName = 0i64;
  v10 = 0;
  String1 = 0i64;
  result = IopGetRegistryValue(ServiceEnumHandle, (PWCHAR)&stru_1407D01E0._Xmm8, 0i64, &Information);
  if( result < 0 )
  {
    if( result != -1073741772 )
      return result;
    return 0;
  }
  v12 = Information;
  if( Information->Type == 4 && Information->DataLength >= 4 )
  {
    v10 = *(ULONG *)((char *)&Information->TitleIndex + Information->DataOffset);
    *(_DWORD *)Count = v10;
  }
  ExFreePoolWithTag(v12, 0);
  PoolWithTag = ExAllocatePoolWithTag(1ui64, 0x100ui64, 538996816i64);
  if( !PoolWithTag )
    return -1073741670;
  v14 = ExAllocatePoolWithTag(1ui64, 0x14ui64, 538996816i64);
  if( !v14 )
  {
    v20 = PoolWithTag;
    goto LABEL_22;
  }
  if( !v10 )
  {
LABEL_15:
    ExFreePoolWithTag(PoolWithTag, 0);
    if( !MatchingValueName->Length )
      ExFreePoolWithTag(v14, 0);
    return 0;
  }
  while( 1 )
  {
    MatchingInstance = (UINT64 *)v14;
    RtlStringCchPrintfExW((WCHAR *)v14, 0xAui64, (WCHAR **)&MatchingInstance, 0i64, 0i64, (WCHAR *)L"%u");
    ValueName.MaximumLength = 20;
    v15 = ((char *)MatchingInstance - (char *)v14) >> 1;
    ValueName.Length = (_DWORD)v15 == -1 ? 20 : 2 * v15;
    LODWORD(dwFlags) = v9;
    ValueName.Buffer = (wchar_t *)v14;
    v16 = ZwQueryValueKey(ServiceEnumHandle, &ValueName, KeyValueFullInformation, PoolWithTag, dwFlags, &ResultLength);
    if( v16 < 0 )
      break;
    if( *((_DWORD *)PoolWithTag + 1) == 1 )
    {
      v17 = *((_DWORD *)PoolWithTag + 3);
      if( v17 > 2 )
      {
        LODWORD(MatchingInstance) = 0;
        PnpRegSzToString(
          (VOID **)((char *)PoolWithTag + *((unsigned int *)PoolWithTag + 2)),
          v17,
          (int *)&MatchingInstance);
        String1.MaximumLength = *((_WORD *)PoolWithTag + 6);
        v18 = (wchar_t *)((char *)PoolWithTag + *((unsigned int *)PoolWithTag + 2));
        String1.Length = (unsigned __int16)MatchingInstance;
        String1.Buffer = v18;
        if( (unsigned __int8)RtlEqualUnicodeString(&String1, DeviceInstanceName, 1u) )
        {
          v19 = ValueName;
          *(_DWORD *)v5 = v6;
          *MatchingValueName = v19;
          goto LABEL_15;
        }
      }
    }
LABEL_14:
    if( ++v6 >= v10 )
      goto LABEL_15;
  }
  if( v16 != -2147483643 && v16 != -1073741789 )
    goto LABEL_14;
  ExFreePoolWithTag(PoolWithTag, 0);
  v9 = ResultLength;
  PoolWithTag = ExAllocatePoolWithTag(1ui64, (unsigned int)ResultLength, 538996816i64);
  if( PoolWithTag )
  {
    --v6;
    goto LABEL_14;
  }
  v20 = v14;
LABEL_22:
  ExFreePoolWithTag(v20, 0);
  return -1073741670;
}

Referenced by:

PiProcessDriverInstance