CmGetDeviceInterfaceSubkeyPath

NTSTATUS __stdcall CmGetDeviceInterfaceSubkeyPath(
        WCHAR *DeviceInterfaceName,
        UINT8 InstanceKey,
        WCHAR *ClassGuid,
        WCHAR *SubkeyPath,
        UINT64 SubkeyPathLength){
  char v6; 
  WCHAR *v7; 
  NTSTATUS result; 
  WORD *v9; 
  __int64 v10; 
  WCHAR *v11; 
  unsigned __int64 v12; 
  unsigned __int64 v13; 
  UINT64 *pcchRemaining; 
  UINT64 *pcchRemaininga; 
  UINT64 dwFlags; 
  UINT64 v17; 
  _NTSTRSAFE_PWSTR pszDest[2]; 
  _UNICODE_STRING DestinationString; 
  _GUID Guid; 
  unsigned int cchDest; 

  *(_QWORD *)pszDest = 0i64;
  v17 = 0i64;
  Guid = 0i64;
  v6 = (char)ClassGuid;
  DestinationString = 0i64;
  v7 = (WCHAR *)InstanceKey;
  result = CmValidateDeviceInterfaceName(DeviceInterfaceName);
  if( result >= 0 )
  {
    v9 = wcschr(v7 + 4, 92);
    v10 = -1i64;
    if( v9 )
    {
      v11 = v9 + 1;
      v12 = v9 - v7;
    }
    else
    {
      v11 = 0i64;
      v12 = -1i64;
      do
        ++v12;
      while( v7[v12] );
    }
    if( v12 > 0xFFFFFFFF )
      return -1073741675;
    if( (unsigned int)v12 < 0x30 )
      return -1073741773;
    v13 = (unsigned int)(v12 + 1);
    if( v6 )
    {
      v13 += 2i64;
      if( v11 )
      {
        do
          ++v10;
        while( v11[v10] );
        v13 += v10;
      }
    }
    if( v13 > 0xFFFFFFFF )
      return -1073741675;
    if( !SubkeyPath
      || (LODWORD(dwFlags) = 2048,
          result = RtlStringCchCopyNExW(
                     SubkeyPath,
                     0x27ui64,
                     &v7[(unsigned int)v12 - 38],
                     0x26ui64,
                     0i64,
                     0i64,
                     dwFlags),
          result >= 0)
      && (result = RtlInitUnicodeStringEx(&DestinationString, SubkeyPath), result >= 0)
      && (result = RtlGUIDFromString(&DestinationString, &Guid), result >= 0) )
    {
      if( (unsigned int)v13 > cchDest )
      {
        return -1073741789;
      }
      else
      {
        LODWORD(dwFlags) = 2048;
        result = RtlStringCchCopyNExW(
                   (WCHAR *)SubkeyPathLength,
                   cchDest,
                   v7,
                   (unsigned int)v12,
                   (WCHAR **)pszDest,
                   &v17,
                   dwFlags);
        if( result >= 0 )
        {
          *(_QWORD *)SubkeyPathLength = 0x23003F00230023i64;
          if( v6 )
          {
            LODWORD(pcchRemaining) = 2048;
            result = RtlStringCchCopyExW(
                       *(WCHAR **)pszDest,
                       v17,
                       (WCHAR **)pszDest,
                       &v17,
                       (UINT64)pcchRemaining);
            if( result >= 0 )
            {
              if( v11 )
              {
                LODWORD(pcchRemaininga) = 2048;
                return RtlStringCchCopyExW(
                         *(WCHAR **)pszDest,
                         v17,
                         v11,
                         (WCHAR **)pszDest,
                         &v17,
                         (UINT64)pcchRemaininga);
              }
            }
          }
        }
      }
    }
  }
  return result;
}

Referenced by:

CmGetDeviceInterfaceClassGuidString
CmGetDeviceInterfaceRegKeyPath