2014-10-18 02:23:07 +04:00
|
|
|
/**
|
|
|
|
* WinPR: Windows Portable Runtime
|
|
|
|
* Clipboard Functions
|
|
|
|
*
|
|
|
|
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 12:08:00 +03:00
|
|
|
#include <winpr/config.h>
|
2014-10-18 02:23:07 +04:00
|
|
|
|
2017-11-14 18:10:52 +03:00
|
|
|
#include <errno.h>
|
2014-10-18 02:23:07 +04:00
|
|
|
#include <winpr/crt.h>
|
2016-02-06 00:28:45 +03:00
|
|
|
#include <winpr/user.h>
|
2014-10-18 02:23:07 +04:00
|
|
|
|
|
|
|
#include "clipboard.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Standard Clipboard Formats:
|
|
|
|
* http://msdn.microsoft.com/en-us/library/windows/desktop/ff729168/
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "CF_TEXT":
|
|
|
|
*
|
|
|
|
* Null-terminated ANSI text with CR/LF line endings.
|
|
|
|
*/
|
|
|
|
|
2017-11-14 18:10:52 +03:00
|
|
|
static void* clipboard_synthesize_cf_text(wClipboard* clipboard, UINT32 formatId, const void* data,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT32* pSize)
|
2014-10-18 02:23:07 +04:00
|
|
|
{
|
2022-10-28 09:09:27 +03:00
|
|
|
size_t size;
|
2014-10-18 02:23:07 +04:00
|
|
|
char* pDstData = NULL;
|
|
|
|
|
|
|
|
if (formatId == CF_UNICODETEXT)
|
|
|
|
{
|
2022-10-28 09:09:27 +03:00
|
|
|
char* str = ConvertWCharNToUtf8Alloc(data, *pSize / sizeof(WCHAR), &size);
|
2014-10-18 02:23:07 +04:00
|
|
|
|
|
|
|
if (!str)
|
|
|
|
return NULL;
|
|
|
|
|
2022-10-28 09:09:27 +03:00
|
|
|
pDstData = ConvertLineEndingToCRLF(str, &size);
|
2014-10-18 02:23:07 +04:00
|
|
|
free(str);
|
|
|
|
*pSize = size;
|
|
|
|
return pDstData;
|
|
|
|
}
|
|
|
|
else if ((formatId == CF_TEXT) || (formatId == CF_OEMTEXT) ||
|
2023-02-21 17:13:07 +03:00
|
|
|
(formatId == ClipboardGetFormatId(clipboard, mime_text_plain)))
|
2014-10-18 02:23:07 +04:00
|
|
|
{
|
2022-10-28 09:09:27 +03:00
|
|
|
size = *pSize;
|
|
|
|
pDstData = ConvertLineEndingToCRLF(data, &size);
|
2014-10-18 02:23:07 +04:00
|
|
|
|
|
|
|
if (!pDstData)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
*pSize = size;
|
|
|
|
return pDstData;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "CF_OEMTEXT":
|
|
|
|
*
|
|
|
|
* Null-terminated OEM text with CR/LF line endings.
|
|
|
|
*/
|
|
|
|
|
2017-11-14 18:10:52 +03:00
|
|
|
static void* clipboard_synthesize_cf_oemtext(wClipboard* clipboard, UINT32 formatId,
|
2019-11-06 17:24:51 +03:00
|
|
|
const void* data, UINT32* pSize)
|
2014-10-18 02:23:07 +04:00
|
|
|
{
|
|
|
|
return clipboard_synthesize_cf_text(clipboard, formatId, data, pSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "CF_LOCALE":
|
|
|
|
*
|
|
|
|
* System locale identifier associated with CF_TEXT
|
|
|
|
*/
|
|
|
|
|
2017-11-14 18:10:52 +03:00
|
|
|
static void* clipboard_synthesize_cf_locale(wClipboard* clipboard, UINT32 formatId,
|
2019-11-06 17:24:51 +03:00
|
|
|
const void* data, UINT32* pSize)
|
2014-10-18 02:23:07 +04:00
|
|
|
{
|
|
|
|
UINT32* pDstData = NULL;
|
2019-11-06 17:24:51 +03:00
|
|
|
pDstData = (UINT32*)malloc(sizeof(UINT32));
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2015-04-03 17:21:01 +03:00
|
|
|
if (!pDstData)
|
|
|
|
return NULL;
|
2014-10-18 02:23:07 +04:00
|
|
|
|
2017-11-14 18:10:52 +03:00
|
|
|
*pDstData = 0x0409; /* English - United States */
|
2019-11-06 17:24:51 +03:00
|
|
|
return (void*)pDstData;
|
2014-10-18 02:23:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "CF_UNICODETEXT":
|
|
|
|
*
|
|
|
|
* Null-terminated UTF-16 text with CR/LF line endings.
|
|
|
|
*/
|
|
|
|
|
2017-11-14 18:10:52 +03:00
|
|
|
static void* clipboard_synthesize_cf_unicodetext(wClipboard* clipboard, UINT32 formatId,
|
2019-11-06 17:24:51 +03:00
|
|
|
const void* data, UINT32* pSize)
|
2014-10-18 02:23:07 +04:00
|
|
|
{
|
2022-10-28 09:09:27 +03:00
|
|
|
size_t size;
|
2014-10-18 02:23:07 +04:00
|
|
|
char* crlfStr = NULL;
|
|
|
|
WCHAR* pDstData = NULL;
|
|
|
|
|
|
|
|
if ((formatId == CF_TEXT) || (formatId == CF_OEMTEXT) ||
|
2023-02-21 17:13:07 +03:00
|
|
|
(formatId == ClipboardGetFormatId(clipboard, mime_text_plain)))
|
2014-10-18 02:23:07 +04:00
|
|
|
{
|
2022-10-28 09:09:27 +03:00
|
|
|
size_t len = 0;
|
2017-11-14 18:10:52 +03:00
|
|
|
if (!pSize || (*pSize > INT32_MAX))
|
|
|
|
return NULL;
|
|
|
|
|
2022-10-28 09:09:27 +03:00
|
|
|
size = *pSize;
|
2021-08-02 13:13:34 +03:00
|
|
|
crlfStr = ConvertLineEndingToCRLF((const char*)data, &size);
|
2014-10-18 02:23:07 +04:00
|
|
|
|
|
|
|
if (!crlfStr)
|
|
|
|
return NULL;
|
|
|
|
|
2022-10-28 09:09:27 +03:00
|
|
|
pDstData = ConvertUtf8NToWCharAlloc(crlfStr, size, &len);
|
2014-10-18 02:23:07 +04:00
|
|
|
free(crlfStr);
|
|
|
|
|
2022-10-28 09:09:27 +03:00
|
|
|
if ((len < 1) || (len > UINT32_MAX / sizeof(WCHAR)))
|
|
|
|
{
|
|
|
|
free(pDstData);
|
2014-10-18 02:23:07 +04:00
|
|
|
return NULL;
|
2022-10-28 09:09:27 +03:00
|
|
|
}
|
2014-10-18 02:23:07 +04:00
|
|
|
|
2023-02-22 09:13:38 +03:00
|
|
|
*pSize = (len + 1) * sizeof(WCHAR);
|
2014-10-18 02:23:07 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
return (void*)pDstData;
|
2014-10-18 02:23:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-13 13:08:46 +03:00
|
|
|
* mime_utf8_string:
|
2014-10-18 02:23:07 +04:00
|
|
|
*
|
|
|
|
* Null-terminated UTF-8 string with LF line endings.
|
|
|
|
*/
|
|
|
|
|
2017-11-14 18:10:52 +03:00
|
|
|
static void* clipboard_synthesize_utf8_string(wClipboard* clipboard, UINT32 formatId,
|
2019-11-06 17:24:51 +03:00
|
|
|
const void* data, UINT32* pSize)
|
2014-10-18 02:23:07 +04:00
|
|
|
{
|
2022-10-28 09:09:27 +03:00
|
|
|
size_t size;
|
2014-10-18 02:23:07 +04:00
|
|
|
char* pDstData = NULL;
|
|
|
|
|
|
|
|
if (formatId == CF_UNICODETEXT)
|
|
|
|
{
|
2022-10-28 09:09:27 +03:00
|
|
|
pDstData = ConvertWCharNToUtf8Alloc(data, *pSize / sizeof(WCHAR), &size);
|
2014-10-18 02:23:07 +04:00
|
|
|
|
|
|
|
if (!pDstData)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
size = ConvertLineEndingToLF(pDstData, size);
|
2021-06-16 15:43:07 +03:00
|
|
|
*pSize = (UINT32)size;
|
2014-10-18 02:23:07 +04:00
|
|
|
return pDstData;
|
|
|
|
}
|
|
|
|
else if ((formatId == CF_TEXT) || (formatId == CF_OEMTEXT) ||
|
2023-02-21 17:13:07 +03:00
|
|
|
(formatId == ClipboardGetFormatId(clipboard, mime_text_plain)))
|
2014-10-18 02:23:07 +04:00
|
|
|
{
|
2021-06-16 15:43:07 +03:00
|
|
|
int rc;
|
2022-10-28 09:09:27 +03:00
|
|
|
size = *pSize;
|
2019-11-06 17:24:51 +03:00
|
|
|
pDstData = (char*)malloc(size);
|
2014-10-18 02:23:07 +04:00
|
|
|
|
|
|
|
if (!pDstData)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
CopyMemory(pDstData, data, size);
|
2022-10-28 09:09:27 +03:00
|
|
|
rc = ConvertLineEndingToLF(pDstData, size);
|
2021-06-16 15:43:07 +03:00
|
|
|
if (rc < 0)
|
|
|
|
{
|
|
|
|
free(pDstData);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*pSize = (UINT32)rc;
|
2014-10-18 02:23:07 +04:00
|
|
|
return pDstData;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "CF_DIB":
|
|
|
|
*
|
|
|
|
* BITMAPINFO structure followed by the bitmap bits.
|
|
|
|
*/
|
|
|
|
|
2017-11-14 18:10:52 +03:00
|
|
|
static void* clipboard_synthesize_cf_dib(wClipboard* clipboard, UINT32 formatId, const void* data,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT32* pSize)
|
2014-10-18 02:23:07 +04:00
|
|
|
{
|
2014-10-18 03:14:54 +04:00
|
|
|
UINT32 SrcSize;
|
|
|
|
UINT32 DstSize;
|
|
|
|
BYTE* pDstData;
|
|
|
|
SrcSize = *pSize;
|
|
|
|
|
|
|
|
if (formatId == CF_DIBV5)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else if (formatId == ClipboardGetFormatId(clipboard, "image/bmp"))
|
|
|
|
{
|
2021-08-26 12:23:32 +03:00
|
|
|
const BITMAPFILEHEADER* pFileHeader;
|
2014-10-18 03:14:54 +04:00
|
|
|
|
|
|
|
if (SrcSize < (sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)))
|
|
|
|
return NULL;
|
|
|
|
|
2021-08-02 13:13:34 +03:00
|
|
|
pFileHeader = (const BITMAPFILEHEADER*)data;
|
2014-10-18 03:14:54 +04:00
|
|
|
|
|
|
|
if (pFileHeader->bfType != 0x4D42)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
DstSize = SrcSize - sizeof(BITMAPFILEHEADER);
|
2019-11-06 17:24:51 +03:00
|
|
|
pDstData = (BYTE*)malloc(DstSize);
|
2014-10-18 03:14:54 +04:00
|
|
|
|
|
|
|
if (!pDstData)
|
|
|
|
return NULL;
|
|
|
|
|
2021-08-02 13:13:34 +03:00
|
|
|
data = (const void*)&((const BYTE*)data)[sizeof(BITMAPFILEHEADER)];
|
2014-10-18 03:14:54 +04:00
|
|
|
CopyMemory(pDstData, data, DstSize);
|
|
|
|
*pSize = DstSize;
|
|
|
|
return pDstData;
|
|
|
|
}
|
2014-10-18 02:23:07 +04:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "CF_DIBV5":
|
|
|
|
*
|
|
|
|
* BITMAPV5HEADER structure followed by the bitmap color space information and the bitmap bits.
|
|
|
|
*/
|
|
|
|
|
2017-11-14 18:10:52 +03:00
|
|
|
static void* clipboard_synthesize_cf_dibv5(wClipboard* clipboard, UINT32 formatId, const void* data,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT32* pSize)
|
2014-10-18 02:23:07 +04:00
|
|
|
{
|
2014-10-18 03:14:54 +04:00
|
|
|
if (formatId == CF_DIB)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else if (formatId == ClipboardGetFormatId(clipboard, "image/bmp"))
|
|
|
|
{
|
|
|
|
}
|
2014-10-18 02:23:07 +04:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "image/bmp":
|
|
|
|
*
|
|
|
|
* Bitmap file format.
|
|
|
|
*/
|
|
|
|
|
2017-11-14 18:10:52 +03:00
|
|
|
static void* clipboard_synthesize_image_bmp(wClipboard* clipboard, UINT32 formatId,
|
2019-11-06 17:24:51 +03:00
|
|
|
const void* data, UINT32* pSize)
|
2014-10-18 02:23:07 +04:00
|
|
|
{
|
2014-10-18 03:14:54 +04:00
|
|
|
UINT32 SrcSize;
|
|
|
|
UINT32 DstSize;
|
|
|
|
BYTE* pDstData;
|
|
|
|
SrcSize = *pSize;
|
|
|
|
|
|
|
|
if (formatId == CF_DIB)
|
|
|
|
{
|
|
|
|
BYTE* pDst;
|
2021-08-26 12:23:32 +03:00
|
|
|
const BITMAPINFOHEADER* pInfoHeader;
|
2014-10-18 03:14:54 +04:00
|
|
|
BITMAPFILEHEADER* pFileHeader;
|
|
|
|
|
2014-10-18 04:40:11 +04:00
|
|
|
if (SrcSize < sizeof(BITMAPINFOHEADER))
|
|
|
|
return NULL;
|
|
|
|
|
2021-08-02 13:13:34 +03:00
|
|
|
pInfoHeader = (const BITMAPINFOHEADER*)data;
|
2014-10-18 03:14:54 +04:00
|
|
|
|
|
|
|
if ((pInfoHeader->biBitCount < 1) || (pInfoHeader->biBitCount > 32))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
DstSize = sizeof(BITMAPFILEHEADER) + SrcSize;
|
2019-11-06 17:24:51 +03:00
|
|
|
pDstData = (BYTE*)malloc(DstSize);
|
2014-10-18 03:14:54 +04:00
|
|
|
|
|
|
|
if (!pDstData)
|
|
|
|
return NULL;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
pFileHeader = (BITMAPFILEHEADER*)pDstData;
|
2014-10-18 03:14:54 +04:00
|
|
|
pFileHeader->bfType = 0x4D42;
|
|
|
|
pFileHeader->bfSize = DstSize;
|
|
|
|
pFileHeader->bfReserved1 = 0;
|
|
|
|
pFileHeader->bfReserved2 = 0;
|
|
|
|
pFileHeader->bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
|
|
|
|
pDst = &pDstData[sizeof(BITMAPFILEHEADER)];
|
|
|
|
CopyMemory(pDst, data, SrcSize);
|
|
|
|
*pSize = DstSize;
|
|
|
|
return pDstData;
|
|
|
|
}
|
|
|
|
else if (formatId == CF_DIBV5)
|
|
|
|
{
|
|
|
|
}
|
2014-10-18 02:23:07 +04:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "HTML Format":
|
|
|
|
*
|
|
|
|
* HTML clipboard format: msdn.microsoft.com/en-us/library/windows/desktop/ms649015/
|
|
|
|
*/
|
|
|
|
|
2017-11-14 18:10:52 +03:00
|
|
|
static void* clipboard_synthesize_html_format(wClipboard* clipboard, UINT32 formatId,
|
2022-04-27 22:02:18 +03:00
|
|
|
const void* pData, UINT32* pSize)
|
2014-10-18 02:23:07 +04:00
|
|
|
{
|
2022-04-27 22:02:18 +03:00
|
|
|
union
|
|
|
|
{
|
|
|
|
const void* cpv;
|
|
|
|
const char* cpc;
|
|
|
|
const BYTE* cpb;
|
|
|
|
WCHAR* pv;
|
|
|
|
} pSrcData;
|
2014-10-18 03:14:54 +04:00
|
|
|
char* pDstData = NULL;
|
2022-04-27 22:02:18 +03:00
|
|
|
|
|
|
|
pSrcData.cpv = NULL;
|
|
|
|
|
|
|
|
WINPR_ASSERT(clipboard);
|
|
|
|
WINPR_ASSERT(pSize);
|
2014-10-18 02:23:07 +04:00
|
|
|
|
2014-10-18 03:14:54 +04:00
|
|
|
if (formatId == ClipboardGetFormatId(clipboard, "text/html"))
|
|
|
|
{
|
2022-06-03 11:25:30 +03:00
|
|
|
const INT64 SrcSize = (INT64)*pSize;
|
|
|
|
const size_t DstSize = SrcSize + 200;
|
2014-10-18 03:14:54 +04:00
|
|
|
char* body;
|
2022-04-27 22:02:18 +03:00
|
|
|
char num[20] = { 0 };
|
|
|
|
|
|
|
|
/* Create a copy, we modify the input data */
|
|
|
|
pSrcData.pv = calloc(1, SrcSize + 1);
|
|
|
|
if (!pSrcData.pv)
|
|
|
|
goto fail;
|
|
|
|
memcpy(pSrcData.pv, pData, SrcSize);
|
2014-10-18 03:14:54 +04:00
|
|
|
|
|
|
|
if (SrcSize > 2)
|
|
|
|
{
|
2021-06-16 15:43:07 +03:00
|
|
|
if (SrcSize > INT_MAX)
|
|
|
|
return NULL;
|
2014-10-18 03:14:54 +04:00
|
|
|
|
2022-04-27 22:02:18 +03:00
|
|
|
/* Check the BOM (Byte Order Mark) */
|
|
|
|
if ((pSrcData.cpb[0] == 0xFE) && (pSrcData.cpb[1] == 0xFF))
|
2023-12-12 13:06:52 +03:00
|
|
|
ByteSwapUnicode(pSrcData.pv, (SrcSize / 2));
|
2014-10-18 03:14:54 +04:00
|
|
|
|
2022-04-27 22:02:18 +03:00
|
|
|
/* Check if we have WCHAR, convert to UTF-8 */
|
|
|
|
if ((pSrcData.cpb[0] == 0xFF) && (pSrcData.cpb[1] == 0xFE))
|
2014-10-18 03:14:54 +04:00
|
|
|
{
|
2022-10-28 09:09:27 +03:00
|
|
|
char* utfString =
|
|
|
|
ConvertWCharNToUtf8Alloc(&pSrcData.pv[1], SrcSize / sizeof(WCHAR), NULL);
|
2022-04-27 22:02:18 +03:00
|
|
|
free(pSrcData.pv);
|
2024-01-19 11:22:09 +03:00
|
|
|
pSrcData.cpc = utfString;
|
2022-10-28 09:09:27 +03:00
|
|
|
if (!utfString)
|
|
|
|
goto fail;
|
2014-10-18 03:14:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-03 11:25:30 +03:00
|
|
|
pDstData = (char*)calloc(1, DstSize);
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2015-04-03 17:21:01 +03:00
|
|
|
if (!pDstData)
|
2022-04-27 22:02:18 +03:00
|
|
|
goto fail;
|
2014-10-18 03:14:54 +04:00
|
|
|
|
2022-06-03 11:25:30 +03:00
|
|
|
sprintf_s(pDstData, DstSize,
|
2018-08-24 10:54:25 +03:00
|
|
|
"Version:0.9\r\n"
|
|
|
|
"StartHTML:0000000000\r\n"
|
|
|
|
"EndHTML:0000000000\r\n"
|
|
|
|
"StartFragment:0000000000\r\n"
|
|
|
|
"EndFragment:0000000000\r\n");
|
2022-04-27 22:02:18 +03:00
|
|
|
body = strstr(pSrcData.cpc, "<body");
|
2014-10-18 03:14:54 +04:00
|
|
|
|
|
|
|
if (!body)
|
2022-04-27 22:02:18 +03:00
|
|
|
body = strstr(pSrcData.cpc, "<BODY");
|
2014-10-18 03:14:54 +04:00
|
|
|
|
|
|
|
/* StartHTML */
|
2022-06-03 11:25:30 +03:00
|
|
|
sprintf_s(num, sizeof(num), "%010" PRIuz "", strnlen(pDstData, DstSize));
|
2014-10-18 03:14:54 +04:00
|
|
|
CopyMemory(&pDstData[23], num, 10);
|
|
|
|
|
|
|
|
if (!body)
|
2022-06-03 11:25:30 +03:00
|
|
|
{
|
|
|
|
if (!winpr_str_append("<HTML><BODY>", pDstData, DstSize, NULL))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!winpr_str_append("<!--StartFragment-->", pDstData, DstSize, NULL))
|
|
|
|
goto fail;
|
2014-10-18 03:14:54 +04:00
|
|
|
|
|
|
|
/* StartFragment */
|
2019-11-06 17:24:51 +03:00
|
|
|
sprintf_s(num, sizeof(num), "%010" PRIuz "", strnlen(pDstData, SrcSize + 200));
|
2014-10-18 03:14:54 +04:00
|
|
|
CopyMemory(&pDstData[69], num, 10);
|
2022-06-03 11:25:30 +03:00
|
|
|
|
|
|
|
if (!winpr_str_append(pSrcData.cpc, pDstData, DstSize, NULL))
|
|
|
|
goto fail;
|
|
|
|
|
2014-10-18 03:14:54 +04:00
|
|
|
/* EndFragment */
|
2019-11-06 17:24:51 +03:00
|
|
|
sprintf_s(num, sizeof(num), "%010" PRIuz "", strnlen(pDstData, SrcSize + 200));
|
2014-10-18 03:14:54 +04:00
|
|
|
CopyMemory(&pDstData[93], num, 10);
|
2022-06-03 11:25:30 +03:00
|
|
|
|
|
|
|
if (!winpr_str_append("<!--EndFragment-->", pDstData, DstSize, NULL))
|
|
|
|
goto fail;
|
2014-10-18 03:14:54 +04:00
|
|
|
|
|
|
|
if (!body)
|
2022-06-03 11:25:30 +03:00
|
|
|
{
|
|
|
|
if (!winpr_str_append("</BODY></HTML>", pDstData, DstSize, NULL))
|
|
|
|
goto fail;
|
|
|
|
}
|
2014-10-18 03:14:54 +04:00
|
|
|
|
|
|
|
/* EndHTML */
|
2022-06-03 11:25:30 +03:00
|
|
|
sprintf_s(num, sizeof(num), "%010" PRIuz "", strnlen(pDstData, DstSize));
|
2014-10-18 03:14:54 +04:00
|
|
|
CopyMemory(&pDstData[43], num, 10);
|
2022-06-03 11:25:30 +03:00
|
|
|
*pSize = (UINT32)strnlen(pDstData, DstSize) + 1;
|
2014-10-18 03:14:54 +04:00
|
|
|
}
|
2022-04-27 22:02:18 +03:00
|
|
|
fail:
|
|
|
|
free(pSrcData.pv);
|
2014-10-18 03:14:54 +04:00
|
|
|
return pDstData;
|
2014-10-18 02:23:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "text/html":
|
|
|
|
*
|
|
|
|
* HTML text format.
|
|
|
|
*/
|
|
|
|
|
2017-11-14 18:10:52 +03:00
|
|
|
static void* clipboard_synthesize_text_html(wClipboard* clipboard, UINT32 formatId,
|
2019-11-06 17:24:51 +03:00
|
|
|
const void* data, UINT32* pSize)
|
2014-10-18 02:23:07 +04:00
|
|
|
{
|
2017-11-14 18:10:52 +03:00
|
|
|
long beg;
|
|
|
|
long end;
|
2021-08-02 13:13:34 +03:00
|
|
|
const char* str;
|
2014-10-18 03:14:54 +04:00
|
|
|
char* begStr;
|
|
|
|
char* endStr;
|
2017-11-14 18:10:52 +03:00
|
|
|
long DstSize = -1;
|
2014-10-18 03:14:54 +04:00
|
|
|
BYTE* pDstData = NULL;
|
|
|
|
|
|
|
|
if (formatId == ClipboardGetFormatId(clipboard, "HTML Format"))
|
|
|
|
{
|
2021-06-16 15:43:07 +03:00
|
|
|
INT64 SrcSize;
|
2021-08-02 13:13:34 +03:00
|
|
|
str = (const char*)data;
|
2019-11-06 17:24:51 +03:00
|
|
|
SrcSize = (INT64)*pSize;
|
2014-10-18 03:14:54 +04:00
|
|
|
begStr = strstr(str, "StartHTML:");
|
|
|
|
endStr = strstr(str, "EndHTML:");
|
|
|
|
|
|
|
|
if (!begStr || !endStr)
|
|
|
|
return NULL;
|
|
|
|
|
2017-11-14 18:10:52 +03:00
|
|
|
errno = 0;
|
2018-01-07 05:45:22 +03:00
|
|
|
beg = strtol(&begStr[10], NULL, 10);
|
2017-11-14 18:10:52 +03:00
|
|
|
|
|
|
|
if (errno != 0)
|
|
|
|
return NULL;
|
|
|
|
|
2018-01-07 05:45:22 +03:00
|
|
|
end = strtol(&endStr[8], NULL, 10);
|
2014-10-18 03:14:54 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (beg < 0 || end < 0 || (beg > SrcSize) || (end > SrcSize) || (beg >= end) ||
|
|
|
|
(errno != 0))
|
2014-10-18 03:14:54 +04:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
DstSize = end - beg;
|
2021-06-16 15:43:07 +03:00
|
|
|
pDstData = (BYTE*)malloc((size_t)(SrcSize - beg + 1));
|
2014-10-18 03:14:54 +04:00
|
|
|
|
|
|
|
if (!pDstData)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
CopyMemory(pDstData, &str[beg], DstSize);
|
2019-11-06 17:24:51 +03:00
|
|
|
DstSize = ConvertLineEndingToLF((char*)pDstData, DstSize);
|
|
|
|
*pSize = (UINT32)DstSize;
|
2014-10-18 03:14:54 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
return (void*)pDstData;
|
2014-10-18 02:23:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL ClipboardInitSynthesizers(wClipboard* clipboard)
|
|
|
|
{
|
|
|
|
UINT32 formatId;
|
|
|
|
UINT32 altFormatId;
|
|
|
|
/**
|
|
|
|
* CF_TEXT
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, CF_TEXT, CF_OEMTEXT, clipboard_synthesize_cf_oemtext);
|
2014-10-18 02:23:07 +04:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, CF_TEXT, CF_UNICODETEXT,
|
2017-11-14 18:10:52 +03:00
|
|
|
clipboard_synthesize_cf_unicodetext);
|
2019-11-06 17:24:51 +03:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, CF_TEXT, CF_LOCALE, clipboard_synthesize_cf_locale);
|
2023-02-21 17:13:07 +03:00
|
|
|
altFormatId = ClipboardRegisterFormat(clipboard, mime_text_plain);
|
2019-11-06 17:24:51 +03:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, CF_TEXT, altFormatId, clipboard_synthesize_utf8_string);
|
2014-10-18 02:23:07 +04:00
|
|
|
/**
|
|
|
|
* CF_OEMTEXT
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, CF_TEXT, clipboard_synthesize_cf_text);
|
2014-10-18 02:23:07 +04:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, CF_UNICODETEXT,
|
2017-11-14 18:10:52 +03:00
|
|
|
clipboard_synthesize_cf_unicodetext);
|
2019-11-06 17:24:51 +03:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, CF_LOCALE, clipboard_synthesize_cf_locale);
|
2023-02-21 17:13:07 +03:00
|
|
|
altFormatId = ClipboardRegisterFormat(clipboard, mime_text_plain);
|
2014-10-18 02:23:07 +04:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, CF_OEMTEXT, altFormatId,
|
2017-11-14 18:10:52 +03:00
|
|
|
clipboard_synthesize_utf8_string);
|
2014-10-18 02:23:07 +04:00
|
|
|
/**
|
|
|
|
* CF_UNICODETEXT
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, CF_TEXT, clipboard_synthesize_cf_text);
|
2014-10-18 02:23:07 +04:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, CF_OEMTEXT,
|
2017-11-14 18:10:52 +03:00
|
|
|
clipboard_synthesize_cf_oemtext);
|
2014-10-18 02:23:07 +04:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, CF_LOCALE,
|
2017-11-14 18:10:52 +03:00
|
|
|
clipboard_synthesize_cf_locale);
|
2023-02-21 17:13:07 +03:00
|
|
|
altFormatId = ClipboardRegisterFormat(clipboard, mime_text_plain);
|
2014-10-18 02:23:07 +04:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, CF_UNICODETEXT, altFormatId,
|
2017-11-14 18:10:52 +03:00
|
|
|
clipboard_synthesize_utf8_string);
|
2014-10-18 02:23:07 +04:00
|
|
|
/**
|
|
|
|
* UTF8_STRING
|
|
|
|
*/
|
2023-02-21 17:13:07 +03:00
|
|
|
formatId = ClipboardRegisterFormat(clipboard, mime_text_plain);
|
2014-10-18 02:23:07 +04:00
|
|
|
|
|
|
|
if (formatId)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, formatId, CF_TEXT, clipboard_synthesize_cf_text);
|
2014-10-18 02:23:07 +04:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, formatId, CF_OEMTEXT,
|
2017-11-14 18:10:52 +03:00
|
|
|
clipboard_synthesize_cf_oemtext);
|
2014-10-18 02:23:07 +04:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, formatId, CF_UNICODETEXT,
|
2017-11-14 18:10:52 +03:00
|
|
|
clipboard_synthesize_cf_unicodetext);
|
2014-10-18 02:23:07 +04:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, formatId, CF_LOCALE,
|
2017-11-14 18:10:52 +03:00
|
|
|
clipboard_synthesize_cf_locale);
|
2014-10-18 02:23:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* text/plain
|
|
|
|
*/
|
2023-02-21 17:13:07 +03:00
|
|
|
formatId = ClipboardRegisterFormat(clipboard, mime_text_plain);
|
2014-10-18 02:23:07 +04:00
|
|
|
|
|
|
|
if (formatId)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, formatId, CF_TEXT, clipboard_synthesize_cf_text);
|
2014-10-18 02:23:07 +04:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, formatId, CF_OEMTEXT,
|
2017-11-14 18:10:52 +03:00
|
|
|
clipboard_synthesize_cf_oemtext);
|
2014-10-18 02:23:07 +04:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, formatId, CF_UNICODETEXT,
|
2017-11-14 18:10:52 +03:00
|
|
|
clipboard_synthesize_cf_unicodetext);
|
2014-10-18 02:23:07 +04:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, formatId, CF_LOCALE,
|
2017-11-14 18:10:52 +03:00
|
|
|
clipboard_synthesize_cf_locale);
|
2014-10-18 02:23:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CF_DIB
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (formatId)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, CF_DIB, CF_DIBV5, clipboard_synthesize_cf_dibv5);
|
2014-10-18 02:23:07 +04:00
|
|
|
altFormatId = ClipboardRegisterFormat(clipboard, "image/bmp");
|
|
|
|
ClipboardRegisterSynthesizer(clipboard, CF_DIB, altFormatId,
|
2017-11-14 18:10:52 +03:00
|
|
|
clipboard_synthesize_image_bmp);
|
2014-10-18 02:23:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CF_DIBV5
|
|
|
|
*/
|
|
|
|
|
2014-10-18 03:14:54 +04:00
|
|
|
if (formatId && 0)
|
2014-10-18 02:23:07 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, CF_DIB, clipboard_synthesize_cf_dib);
|
2014-10-18 02:23:07 +04:00
|
|
|
altFormatId = ClipboardRegisterFormat(clipboard, "image/bmp");
|
|
|
|
ClipboardRegisterSynthesizer(clipboard, CF_DIBV5, altFormatId,
|
2017-11-14 18:10:52 +03:00
|
|
|
clipboard_synthesize_image_bmp);
|
2014-10-18 02:23:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* image/bmp
|
|
|
|
*/
|
|
|
|
formatId = ClipboardRegisterFormat(clipboard, "image/bmp");
|
|
|
|
|
|
|
|
if (formatId)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
ClipboardRegisterSynthesizer(clipboard, formatId, CF_DIB, clipboard_synthesize_cf_dib);
|
|
|
|
ClipboardRegisterSynthesizer(clipboard, formatId, CF_DIBV5, clipboard_synthesize_cf_dibv5);
|
2014-10-18 02:23:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* HTML Format
|
|
|
|
*/
|
|
|
|
formatId = ClipboardRegisterFormat(clipboard, "HTML Format");
|
|
|
|
|
|
|
|
if (formatId)
|
|
|
|
{
|
|
|
|
altFormatId = ClipboardRegisterFormat(clipboard, "text/html");
|
|
|
|
ClipboardRegisterSynthesizer(clipboard, formatId, altFormatId,
|
2017-11-14 18:10:52 +03:00
|
|
|
clipboard_synthesize_text_html);
|
2014-10-18 02:23:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* text/html
|
|
|
|
*/
|
|
|
|
formatId = ClipboardRegisterFormat(clipboard, "text/html");
|
|
|
|
|
|
|
|
if (formatId)
|
|
|
|
{
|
|
|
|
altFormatId = ClipboardRegisterFormat(clipboard, "HTML Format");
|
|
|
|
ClipboardRegisterSynthesizer(clipboard, formatId, altFormatId,
|
2017-11-14 18:10:52 +03:00
|
|
|
clipboard_synthesize_html_format);
|
2014-10-18 02:23:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|