PiFindDevInstMatch

INT64 __stdcall PiFindDevInstMatch(
        VOID *ServiceEnumHandle,
        UNICODE_STRING *DeviceInstanceName,
        UINT64 *Count,
        UNICODE_STRING *MatchingValueName,
        UINT64 *MatchingInstance){
  UINT64 *v5; 
  int v6; 
  ULONG v9; 
  unsigned int v10; 
  INT64 result; 
  PVOID v12; 
  unsigned __int16 *PoolWithTag; 
  void *v14; 
  __int64 v15; 
  NTSTATUS v16; 
  UINT64 v17; 
  wchar_t *v18; 
  struct _UNICODE_STRING v19; 
  unsigned __int16 *v20; 
  __int64 v21; 
  struct _UNICODE_STRING ValueName; 
  UNICODE_STRING String1; 
  ULONG ResultLength; 
  PVOID P; 
  v5 = MatchingInstance;
  v6 = 0;
  MatchingValueName->Length = 0;
  MatchingValueName->Buffer = 0i64;
  *(_DWORD *)v5 = -1;
  *(_DWORD *)Count = 0;
  ResultLength = 0;
  v9 = 256;
  P = 0i64;
  ValueName = 0i64;
  v10 = 0;
  String1 = 0i64;
  LODWORD(result) = IopGetRegistryValue(
                      ServiceEnumHandle,
                      (PWCHAR)&stru_1407D01E0.Xmm8,
                      0i64,
                      (KEY_VALUE_FULL_INFORMATION **)&P);
  if( (int)result < 0 )
  {
    if( (_DWORD)result != -1073741772 )
      return result;
    return 0i64;
  }
  v12 = P;
  if( *((_DWORD *)P + 1) == 4 && *((_DWORD *)P + 3) >= 4u )
  {
    v10 = *(_DWORD *)((char *)P + *((unsigned int *)P + 2));
    *(_DWORD *)Count = v10;
  }
  ExFreePoolWithTag(v12, 0);
  PoolWithTag = (unsigned __int16 *)ExAllocatePoolWithTag(PagedPool, 0x100ui64, 0x20207050ui64);
  if( !PoolWithTag )
    return 3221225626i64;
  v14 = ExAllocatePoolWithTag(PagedPool, 0x14ui64, 0x20207050ui64);
  if( !v14 )
  {
    v20 = PoolWithTag;
    goto LABEL_22;
  }
  if( !v10 )
  {
LABEL_15:
    ExFreePoolWithTag(PoolWithTag, 0);
    if( !MatchingValueName->Length )
      ExFreePoolWithTag(v14, 0);
    return 0i64;
  }
  while( 1 )
  {
    LODWORD(v21) = v6;
    MatchingInstance = (UINT64 *)v14;
    RtlStringCchPrintfExW((WCHAR *)v14, 0xAui64, (WCHAR **)&MatchingInstance, 0i64, 0i64, L"%u", v21);
    ValueName.MaximumLength = 20;
    v15 = ((char *)MatchingInstance - (_BYTE *)v14) >> 1;
    ValueName.Length = (_DWORD)v15 == -1 ? 20 : 2 * v15;
    ValueName.Buffer = (wchar_t *)v14;
    v16 = ZwQueryValueKey(ServiceEnumHandle, &ValueName, KeyValueFullInformation, PoolWithTag, v9, &ResultLength);
    if( v16 < 0 )
      break;
    if( *((_DWORD *)PoolWithTag + 1) == 1 )
    {
      v17 = *((unsigned int *)PoolWithTag + 3);
      if( (unsigned int)v17 > 2 )
      {
        LODWORD(MatchingInstance) = 0;
        PnpRegSzToString(
          (unsigned __int16 *)((char *)PoolWithTag + *((unsigned int *)PoolWithTag + 2)),
          v17,
          (UINT64 *)&MatchingInstance);
        String1.MaximumLength = PoolWithTag[6];
        v18 = (unsigned __int16 *)((char *)PoolWithTag + *((unsigned int *)PoolWithTag + 2));
        String1.Length = (unsigned __int16)MatchingInstance;
        String1.Buffer = v18;
        if( 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 = (unsigned __int16 *)ExAllocatePoolWithTag(PagedPool, ResultLength, 0x20207050ui64);
  if( PoolWithTag )
  {
    --v6;
    goto LABEL_14;
  }
  v20 = (unsigned __int16 *)v14;
LABEL_22:
  ExFreePoolWithTag(v20, 0);
  return 3221225626i64;
}

Referenced by:

PiProcessDriverInstance