CmGetDeviceSoftwareKeyPath

NTSTATUS __stdcall CmGetDeviceSoftwareKeyPath(
        HPNPCTX *hPnpCtx,
        const WCHAR *DeviceInstanceId,
        _CM_KEY_TYPE CmKeyTypeFlags,
        UINT64 HardwareProfileId,
        UINT8 Create,
        WCHAR *BaseKeyPath,
        UINT64 BaseKeyLength,
        UINT64 *RequiredLength){
  int v8; 
  __int16 v9; 
  NTSTATUS result; 
  __int64 v11; 
  unsigned __int64 v12; 
  __int64 v13; 
  unsigned __int64 v14; 
  __int64 v15; 
  unsigned __int64 v16; 
  char *pszFormat; 
  __int64 v18; 
  unsigned __int64 v19; 
  __int64 v20; 
  unsigned __int64 v21; 
  __int64 v22; 
  unsigned __int64 v23; 
  INT64 v24; 
  __int16 SoftwareKeyPath[48]; 

  v8 = HardwareProfileId;
  v9 = CmKeyTypeFlags;
  if( *((_BYTE *)hPnpCtx + 4) )
  {
    if( (CmKeyTypeFlags & 0x200) == 0 )
    {
      v20 = -1i64;
      do
        ++v20;
      while( DeviceInstanceId[v20] );
      v21 = v20 + 49;
      if( v21 > 0xFFFFFFFF )
        return -1073741675;
      if( RequiredLength )
        *(_DWORD *)RequiredLength = v21;
      if( (unsigned int)v21 > (unsigned int)BaseKeyLength )
        return -1073741789;
      goto LABEL_20;
    }
    if( !(_DWORD)HardwareProfileId )
    {
      v15 = -1i64;
      do
        ++v15;
      while( DeviceInstanceId[v15] );
      v16 = v15 + 100;
      if( v16 > 0xFFFFFFFF )
        return -1073741675;
      if( RequiredLength )
        *(_DWORD *)RequiredLength = v16;
      if( (unsigned int)v16 > (unsigned int)BaseKeyLength )
        return -1073741789;
      pszFormat = (char *)L"%s\\%s\\%s\\%s";
      goto LABEL_31;
    }
    if( (_DWORD)HardwareProfileId != -1 )
    {
      v18 = -1i64;
      do
        ++v18;
      while( DeviceInstanceId[v18] );
      v19 = v18 + 97;
      if( v19 <= 0xFFFFFFFF )
      {
        if( RequiredLength )
          *(_DWORD *)RequiredLength = v19;
        if( (unsigned int)v19 <= (unsigned int)BaseKeyLength )
        {
          LODWORD(v24) = 2048;
          return RtlStringCchPrintfExW(
                   BaseKeyPath,
                   (unsigned int)BaseKeyLength,
                   0i64,
                   0i64,
                   v24,
                   (WCHAR *)L"%s\\%04u\\%s\\%s\\%s");
        }
        return -1073741789;
      }
      return -1073741675;
    }
    return -1073741811;
  }
  LOBYTE(v24) = Create;
  result = CmGetDeviceSoftwareKey(hPnpCtx, DeviceInstanceId, (WCHAR *)SoftwareKeyPath, (UINT64)DeviceInstanceId, v24);
  if( result < 0 )
    return result;
  if( (v9 & 0x200) != 0 )
  {
    if( !v8 )
    {
      v13 = -1i64;
      do
        ++v13;
      while( SoftwareKeyPath[v13] );
      v14 = v13 + 91;
      if( v14 > 0xFFFFFFFF )
        return -1073741675;
      if( RequiredLength )
        *(_DWORD *)RequiredLength = v14;
      if( (unsigned int)v14 > (unsigned int)BaseKeyLength )
        return -1073741789;
LABEL_20:
      LODWORD(v24) = 2048;
      return RtlStringCchPrintfExW(BaseKeyPath, (unsigned int)BaseKeyLength, 0i64, 0i64, v24, (WCHAR *)L"%s\\%s\\%s");
    }
    if( v8 != -1 )
    {
      v22 = -1i64;
      do
        ++v22;
      while( SoftwareKeyPath[v22] );
      v23 = v22 + 88;
      if( v23 > 0xFFFFFFFF )
        return -1073741675;
      if( RequiredLength )
        *(_DWORD *)RequiredLength = v23;
      if( (unsigned int)v23 > (unsigned int)BaseKeyLength )
        return -1073741789;
      pszFormat = (char *)L"%s\\%04u\\%s\\%s";
LABEL_31:
      LODWORD(v24) = 2048;
      return RtlStringCchPrintfExW(BaseKeyPath, (unsigned int)BaseKeyLength, 0i64, 0i64, v24, (WCHAR *)pszFormat);
    }
    return -1073741811;
  }
  v11 = -1i64;
  do
    ++v11;
  while( SoftwareKeyPath[v11] );
  v12 = v11 + 40;
  if( v12 > 0xFFFFFFFF )
    return -1073741675;
  if( RequiredLength )
    *(_DWORD *)RequiredLength = v12;
  if( (unsigned int)v12 > (unsigned int)BaseKeyLength )
    return -1073741789;
  LODWORD(v24) = 2048;
  return RtlStringCchPrintfExW(BaseKeyPath, (unsigned int)BaseKeyLength, 0i64, 0i64, v24, (WCHAR *)L"%s\\%s");
}

Referenced by:

CmGetDeviceRegKeyPath