RtlStringCchCopyExW

NTSTATUS __stdcall RtlStringCchCopyExW(
        WCHAR *pszDest,
        UINT64 cchDest,
        WCHAR *pszSrc,
        WCHAR **ppszDestEnd,
        UINT64 *pcchRemaining,
        UINT64 dwFlags){
  NTSTATUS v9; 
  WCHAR *v10; 
  UINT64 v11; 
  WCHAR *v12; 
  NTSTATUS v13; 
  UINT64 v14; 
  size_t v16; 
  UINT64 v17; 
  size_t pcchNewDestLength[2]; 

  v9 = 0;
  if( (dwFlags & 0x100) != 0 )
  {
    if( !pszDest && cchDest || cchDest > 0x7FFFFFFF )
      v9 = -1073741811;
  }
  else if( cchDest - 1 > 0x7FFFFFFE )
  {
    v9 = -1073741811;
  }
  if( v9 < 0 )
  {
    if( cchDest )
      *pszDest = 0;
  }
  else
  {
    v17 = (UINT64)pszDest;
    v10 = pszDest;
    *(_QWORD *)pcchNewDestLength = cchDest;
    v11 = cchDest;
    if( (dwFlags & 0x100) != 0 )
    {
      v12 = (WCHAR *)&::ppszDestEnd;
      if( pszSrc )
        v12 = pszSrc;
      pszSrc = v12;
    }
    v9 = 0;
    if( (dwFlags & 0xFFFFE000) != 0 )
    {
      v9 = -1073741811;
      if( cchDest )
        *pszDest = 0;
    }
    else if( cchDest )
    {
      *(_QWORD *)pcchNewDestLength = 0i64;
      v13 = RtlStringCopyWorkerW((_NTSTRSAFE_PWSTR)pszDest, cchDest, pcchNewDestLength, pszSrc, v16);
      v14 = *(_QWORD *)pcchNewDestLength;
      v9 = v13;
      v11 = cchDest - *(_QWORD *)pcchNewDestLength;
      *(_QWORD *)pcchNewDestLength = cchDest - *(_QWORD *)pcchNewDestLength;
      v10 = &pszDest[v14];
      v17 = (UINT64)v10;
      if( v13 >= 0 )
      {
        if( (dwFlags & 0x200) != 0 && v11 > 1 && 2 * v11 > 2 )
          memset(v10 + 1, (unsigned __int8)dwFlags, 2 * v11 - 2);
        goto LABEL_13;
      }
    }
    else
    {
      if( !*pszSrc )
      {
LABEL_13:
        if( ppszDestEnd )
          *ppszDestEnd = v10;
        if( pcchRemaining )
          *pcchRemaining = v11;
        return v9;
      }
      v9 = pszDest != 0i64 ? -2147483643 : -1073741811;
    }
    if( (dwFlags & 0x1C00) != 0 && cchDest )
    {
      StringExHandleOtherFlagsW(pszDest, 2 * cchDest, (WCHAR **)pszSrc, &v17, (UINT64)pcchNewDestLength);
      v10 = (WCHAR *)v17;
      v11 = *(_QWORD *)pcchNewDestLength;
    }
    if( (int)(v9 + 0x80000000) < 0 || v9 == -2147483643 )
      goto LABEL_13;
  }
  return v9;
}

Referenced by:

CmClassSubkeyCallback
CmDeviceClassesSubkeyCallback
CmDevicePanelEnumSubkeyCallback
CmEnumSubkeyCallback
CmGetDeviceChildren
CmGetDeviceInterfaceName
CmGetDeviceInterfaceReferenceString
CmGetDeviceInterfaceSubkeyPath
CmGetDeviceParent
CmGetMatchingDeviceListForSubkey
CmGetMatchingFilteredDeviceInterfaceListWorker
CmIsDeviceSafeRemovalRequired
DrvDbBuildDeviceIdDriverInfMatch
DrvDbDeleteObjectSubKey
DrvDbGetDeviceIdDriverInfMatches
DrvDbGetDriverDatabaseList
DrvDbGetDriverPackageMappedProperty
DrvDbGetObjectSubKeyCallback
IopGetDeviceInterfaces
PiCMCreateDevice
PiCMGenerateDeviceInstance
PiDevCfgQueryPolicyStringList
PiDmGetObjectListCallback
PiPnpRtlGetFilteredDeviceList
PnpGetDeviceDependencyList
PnpGetGenericStorePropertyLocales
PnpObjectListCallback
RegRtlCreateTreeTransacted
RegRtlDeletePathInternal