CmGetDeviceMappedPropertyFromRegProp

__int64 __fastcall CmGetDeviceMappedPropertyFromRegProp(
        __int64 a1,
        const wchar_t *a2,
        __int64 a3,
        __int64 a4,
        int *a5,
        wchar_t *a6,
        unsigned int a7,
        unsigned int *a8,
        int a9){
  wchar_t *v9; 
  unsigned int v11; 
  int v12; 
  DEVPROPKEY **v13; 
  unsigned int i; 
  DEVPROPKEY *v15; 
  int *v16; 
  __int64 v17; 
  int v18; 
  __int64 v19; 
  const wchar_t *v20; 
  __int64 v21; 
  int v22; 
  int DeviceRegProp; 
  const wchar_t *v24; 
  __int64 v25; 
  int v27; 
  UINT64 v28; 
  void *PoolWithTag; 
  const wchar_t *v30; 
  int v31; 
  unsigned int Len; 
  int v33; 
  int v34; 
  int v35; 
  unsigned int v36; 
  int v37; 
  __int64 v38; 
  int v39; 
  const wchar_t *v40; 
  __int64 v41; 
  int v42; 
  HANDLE Handle; 
  PVOID P; 
  struct _UNICODE_STRING DestinationString; 
  GUID Guid; 
  WCHAR SourceString[40]; 
  v9 = a6;
  v41 = a3;
  v40 = a2;
  v38 = a1;
  v37 = 0;
  v42 = 0;
  v36 = 0;
  v39 = 0;
  P = 0i64;
  Handle = 0i64;
  DestinationString = 0i64;
  Guid = 0i64;
  if( (_WORD)a9 )
    return(unsigned int)-1073741811;
  *a5 = 0;
  *a8 = 0;
  if( a6 )
  {
    v11 = a7;
    v9 = (wchar_t *)(-(__int64)(a7 != 0) & (unsigned __int64)a6);
  }
  else
  {
    v11 = 0;
  }
  v12 = *(_DWORD *)(a4 + 16);
  v13 = &CmDeviceRegPropMap;
  for( i = 0; i < 0x21; ++i )
  {
    v15 = *v13;
    v16 = (int *)v13;
    if( v12 == (*v13)->pid )
    {
      v17 = *(_QWORD *)a4 - *(_QWORD *)&v15->fmtid.Data1;
      if( *(_QWORD *)a4 == *(_QWORD *)&v15->fmtid.Data1 )
        v17 = *(_QWORD *)(a4 + 8) - *(_QWORD *)v15->fmtid.Data4;
      if( !v17 )
        break;
    }
    v13 += 3;
    v16 = 0i64;
  }
  if( !v16 )
    return(unsigned int)-1073741802;
  v18 = v16[3];
  switch( v18 )
  {
    case 9:
      goto LABEL_40;
    case 25:
      return(unsigned int)-1073741637;
    case 27:
      v24 = v40;
      v36 = 4;
      DeviceRegProp = CmGetDeviceRegProp(v38, v40, v41, 27, (__int64)&v37, (__int64)&v39, (__int64)&v36, a9);
      if( DeviceRegProp < 0 )
        goto LABEL_20;
      if( v37 != v16[4] )
        return(unsigned int)-1073741811;
      *a8 = 1;
      *a5 = v16[2];
      if( v11 >= *a8 )
      {
        *(_BYTE *)v9 = -(v39 != 0);
        goto LABEL_20;
      }
      return(unsigned int)-1073741789;
    case 37:
LABEL_40:
      v33 = v16[3];
      v24 = v40;
      v36 = 78;
      DeviceRegProp = CmGetDeviceRegProp(v38, v40, v41, v33, (__int64)&v37, (__int64)SourceString, (__int64)&v36, a9);
      if( DeviceRegProp < 0 )
        goto LABEL_20;
      if( v37 != v16[4] )
        return(unsigned int)-1073741811;
      *a8 = 16;
      *a5 = v16[2];
      if( v11 >= *a8 )
      {
        SourceString[38] = 0;
        DeviceRegProp = RtlInitUnicodeStringEx(&DestinationString, SourceString);
        if( DeviceRegProp >= 0 )
        {
          DeviceRegProp = RtlGUIDFromString(&DestinationString, &Guid);
          if( DeviceRegProp >= 0 )
            *(GUID *)v9 = Guid;
        }
        goto LABEL_20;
      }
      return(unsigned int)-1073741789;
  }
  v19 = v41;
  v20 = v40;
  v21 = v38;
  *a8 = v11;
  v22 = CmGetDeviceRegProp(v21, v20, v19, v18, (__int64)&v37, (__int64)v9, (__int64)a8, a9);
  DeviceRegProp = v22;
  if( v22 && v22 != -1073741789 )
    goto LABEL_18;
  if( v37 != v16[4] )
    return(unsigned int)-1073741811;
  v27 = v16[2];
  *a5 = v27;
  if( v27 != 18 )
    goto LABEL_18;
  v28 = *a8;
  v36 = *a8;
  if( DeviceRegProp )
  {
    if( DeviceRegProp != -1073741789 )
      goto LABEL_18;
    PoolWithTag = ExAllocatePoolWithTag(PagedPool, v28, 0x52504E50ui64);
    if( !PoolWithTag )
      return(unsigned int)-1073741801;
    v34 = v18;
    v24 = v40;
    v25 = v38;
    v35 = CmGetDeviceRegProp(v38, v40, v41, v34, (__int64)&v42, (__int64)PoolWithTag, (__int64)&v36, a9);
    if( v35 < 0 )
    {
      DeviceRegProp = v35;
      ExFreePoolWithTag(PoolWithTag, 0);
      goto LABEL_21;
    }
    if( v36 < 2 )
      goto LABEL_31;
    v30 = (const wchar_t *)PoolWithTag;
  }
  else
  {
    if( v11 < 2 )
      goto LABEL_33;
    PoolWithTag = P;
    v30 = v9;
  }
  if( v30 && (PnpParseIndirectInfString(v30) || PnpParseIndirectResourceString((__int64)v30)) )
    *a5 = 25;
LABEL_31:
  if( PoolWithTag )
    ExFreePoolWithTag(PoolWithTag, 0);
LABEL_18:
  if( DeviceRegProp )
  {
    v24 = v40;
LABEL_20:
    v25 = v38;
LABEL_21:
    if( DeviceRegProp != -1073741810 )
      return(unsigned int)DeviceRegProp;
    DeviceRegProp = CmOpenDeviceRegKey(v25, v24, 16, 0, 1, 0, (__int64)&Handle, 0i64);
    if( !DeviceRegProp )
    {
      ZwClose(Handle);
      return(unsigned int)-1073741275;
    }
    if( DeviceRegProp != -1073741810 && DeviceRegProp != -1073741632 )
      return(unsigned int)-1073741823;
    return(unsigned int)DeviceRegProp;
  }
LABEL_33:
  v31 = *a5;
  if( *a5 == 8210 )
  {
    Len = PnpMultiSzGetLen(v9);
    if( 2 * (unsigned __int64)Len > *a8 )
    {
      DeviceRegProp = -1073741595;
      *a8 = 0;
      return(unsigned int)DeviceRegProp;
    }
    *a8 = 2 * Len;
    v31 = *a5;
  }
  if( v31 == 18 && !*a8 )
  {
    *a8 = 0;
    *a5 = 0;
    return(unsigned int)-1073741275;
  }
  return(unsigned int)DeviceRegProp;
}

Referenced by:

CmGetDeviceCompoundFilters
CmGetDeviceCompoundFiltersWorker
CmGetDeviceMappedProperty
CmGetDeviceMappedPropertyKeys