2011-08-23 17:01:19 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-08-23 17:01:19 +04:00
|
|
|
* Surface Commands
|
|
|
|
*
|
|
|
|
* Copyright 2011 Vic Lee
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-08-27 04:26:40 +04:00
|
|
|
#include <freerdp/utils/pcap.h>
|
2014-09-12 16:36:29 +04:00
|
|
|
#include <freerdp/log.h>
|
2011-08-27 04:26:40 +04:00
|
|
|
|
2011-08-23 17:01:19 +04:00
|
|
|
#include "surface.h"
|
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#define TAG FREERDP_TAG("core.surface")
|
|
|
|
|
2018-02-28 12:10:09 +03:00
|
|
|
static BOOL update_recv_surfcmd_bitmap_header_ex(wStream* s, TS_COMPRESSED_BITMAP_HEADER_EX* header)
|
|
|
|
{
|
|
|
|
if (!s || !header)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 24)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, header->highUniqueId);
|
|
|
|
Stream_Read_UINT32(s, header->lowUniqueId);
|
|
|
|
Stream_Read_UINT64(s, header->tmMilliseconds);
|
|
|
|
Stream_Read_UINT64(s, header->tmSeconds);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL update_recv_surfcmd_bitmap_ex(wStream* s, TS_BITMAP_DATA_EX* bmp)
|
2011-08-23 17:01:19 +04:00
|
|
|
{
|
2017-12-11 12:25:21 +03:00
|
|
|
size_t pos;
|
2018-02-28 12:10:09 +03:00
|
|
|
if (!s || !bmp)
|
|
|
|
return FALSE;
|
2011-08-23 17:01:19 +04:00
|
|
|
|
2018-02-28 12:10:09 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
2017-11-23 17:10:42 +03:00
|
|
|
return FALSE;
|
2013-01-17 03:01:10 +04:00
|
|
|
|
2018-02-28 12:10:09 +03:00
|
|
|
Stream_Read_UINT8(s, bmp->bpp);
|
|
|
|
Stream_Read_UINT8(s, bmp->flags);
|
|
|
|
Stream_Seek(s, 1); /* reserved */
|
|
|
|
Stream_Read_UINT8(s, bmp->codecID);
|
|
|
|
Stream_Read_UINT16(s, bmp->width);
|
|
|
|
Stream_Read_UINT16(s, bmp->height);
|
|
|
|
Stream_Read_UINT32(s, bmp->bitmapDataLength);
|
2017-11-23 17:10:42 +03:00
|
|
|
|
2018-02-28 12:10:09 +03:00
|
|
|
if ((bmp->bpp < 1) || (bmp->bpp > 32))
|
2014-05-29 12:12:02 +04:00
|
|
|
{
|
2018-02-28 12:10:09 +03:00
|
|
|
WLog_ERR(TAG, "invalid bpp value %"PRIu32"", bmp->bpp);
|
2014-05-29 12:12:02 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-02-28 12:10:09 +03:00
|
|
|
memset(&bmp->exBitmapDataHeader, 0, sizeof(TS_COMPRESSED_BITMAP_HEADER_EX));
|
|
|
|
if (bmp->flags & EX_COMPRESSED_BITMAP_HEADER_PRESENT)
|
|
|
|
{
|
|
|
|
if (!update_recv_surfcmd_bitmap_header_ex(s, &bmp->exBitmapDataHeader))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-01-17 03:01:10 +04:00
|
|
|
|
2018-02-28 12:10:09 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < bmp->bitmapDataLength)
|
2017-11-23 17:10:42 +03:00
|
|
|
return FALSE;
|
2013-01-17 03:01:10 +04:00
|
|
|
|
2018-02-28 12:10:09 +03:00
|
|
|
pos = Stream_GetPosition(s) + bmp->bitmapDataLength;
|
|
|
|
bmp->bitmapData = Stream_Pointer(s);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, pos);
|
2018-02-28 12:10:09 +03:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL update_recv_surfcmd_surface_bits(rdpUpdate* update, wStream* s)
|
|
|
|
{
|
|
|
|
SURFACE_BITS_COMMAND* cmd = &update->surface_bits_command;
|
|
|
|
|
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Read_UINT16(s, cmd->destLeft);
|
|
|
|
Stream_Read_UINT16(s, cmd->destTop);
|
|
|
|
Stream_Read_UINT16(s, cmd->destRight);
|
|
|
|
Stream_Read_UINT16(s, cmd->destBottom);
|
|
|
|
if (!update_recv_surfcmd_bitmap_ex(s, &cmd->bmp))
|
|
|
|
return FALSE;
|
2013-01-17 03:01:10 +04:00
|
|
|
|
2017-11-23 17:10:42 +03:00
|
|
|
if (!update->SurfaceBits)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Missing callback update->SurfaceBits");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-04-13 01:05:42 +04:00
|
|
|
|
2017-11-23 17:10:42 +03:00
|
|
|
return update->SurfaceBits(update->context, cmd);
|
2011-08-23 17:01:19 +04:00
|
|
|
}
|
|
|
|
|
2018-02-28 12:10:09 +03:00
|
|
|
static BOOL update_recv_surfcmd_frame_marker(rdpUpdate* update, wStream* s)
|
2011-08-23 17:01:19 +04:00
|
|
|
{
|
2011-11-25 20:30:15 +04:00
|
|
|
SURFACE_FRAME_MARKER* marker = &update->surface_frame_marker;
|
2011-08-23 17:01:19 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 6)
|
2017-11-23 17:10:42 +03:00
|
|
|
return FALSE;
|
2013-01-17 03:01:10 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, marker->frameAction);
|
|
|
|
Stream_Read_UINT32(s, marker->frameId);
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_Print(update->log, WLOG_DEBUG, "SurfaceFrameMarker: action: %s (%"PRIu32") id: %"PRIu32"",
|
2017-11-23 17:10:42 +03:00
|
|
|
(!marker->frameAction) ? "Begin" : "End",
|
|
|
|
marker->frameAction, marker->frameId);
|
2013-10-09 04:40:58 +04:00
|
|
|
|
2017-11-23 17:10:42 +03:00
|
|
|
if (!update->SurfaceFrameMarker)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Missing callback update->SurfaceFrameMarker");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-11-25 14:48:51 +04:00
|
|
|
|
2017-11-23 17:10:42 +03:00
|
|
|
return update->SurfaceFrameMarker(update->context, marker);
|
2011-08-23 17:01:19 +04:00
|
|
|
}
|
|
|
|
|
2018-02-28 12:10:09 +03:00
|
|
|
int update_recv_surfcmds(rdpUpdate* update, wStream* s)
|
2011-08-23 17:01:19 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* mark;
|
|
|
|
UINT16 cmdType;
|
2011-08-27 04:26:40 +04:00
|
|
|
|
2018-02-28 12:10:09 +03:00
|
|
|
while (Stream_GetRemainingLength(s) >= 2)
|
2011-08-27 05:44:37 +04:00
|
|
|
{
|
2018-02-28 12:10:09 +03:00
|
|
|
const size_t start = Stream_GetPosition(s);
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_GetPointer(s, mark);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, cmdType);
|
2011-08-23 17:01:19 +04:00
|
|
|
|
|
|
|
switch (cmdType)
|
|
|
|
{
|
|
|
|
case CMDTYPE_SET_SURFACE_BITS:
|
|
|
|
case CMDTYPE_STREAM_SURFACE_BITS:
|
2018-02-28 12:10:09 +03:00
|
|
|
if (!update_recv_surfcmd_surface_bits(update, s))
|
2013-01-14 02:37:50 +04:00
|
|
|
return -1;
|
2017-11-23 17:10:42 +03:00
|
|
|
|
2011-08-23 17:01:19 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CMDTYPE_FRAME_MARKER:
|
2018-02-28 12:10:09 +03:00
|
|
|
if (!update_recv_surfcmd_frame_marker(update, s))
|
2013-01-14 02:37:50 +04:00
|
|
|
return -1;
|
2017-11-23 17:10:42 +03:00
|
|
|
|
2011-08-23 17:01:19 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "unknown cmdType 0x%04"PRIX16"", cmdType);
|
2013-01-09 02:18:10 +04:00
|
|
|
return -1;
|
2011-08-23 17:01:19 +04:00
|
|
|
}
|
2011-08-28 01:11:20 +04:00
|
|
|
|
|
|
|
if (update->dump_rfx)
|
|
|
|
{
|
2018-02-28 12:10:09 +03:00
|
|
|
const size_t size = Stream_GetPosition(s) - start;
|
2015-06-16 16:42:07 +03:00
|
|
|
/* TODO: treat return values */
|
2018-02-28 12:10:09 +03:00
|
|
|
pcap_add_record(update->pcap_rfx, mark, size);
|
2011-08-28 01:11:20 +04:00
|
|
|
pcap_flush(update->pcap_rfx);
|
|
|
|
}
|
2011-08-23 17:01:19 +04:00
|
|
|
}
|
2013-01-09 02:18:10 +04:00
|
|
|
|
|
|
|
return 0;
|
2011-08-23 17:01:19 +04:00
|
|
|
}
|
|
|
|
|
2018-02-28 12:10:09 +03:00
|
|
|
static BOOL update_write_surfcmd_bitmap_header_ex(wStream* s, const TS_COMPRESSED_BITMAP_HEADER_EX* header)
|
|
|
|
{
|
|
|
|
if (!s || !header)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 24))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Write_UINT32(s, header->highUniqueId);
|
|
|
|
Stream_Write_UINT32(s, header->lowUniqueId);
|
|
|
|
Stream_Write_UINT64(s, header->tmMilliseconds);
|
|
|
|
Stream_Write_UINT64(s, header->tmSeconds);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL update_write_surfcmd_bitmap_ex(wStream* s, const TS_BITMAP_DATA_EX* bmp)
|
|
|
|
{
|
|
|
|
if (!s || !bmp)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 12))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Write_UINT8(s, bmp->bpp);
|
|
|
|
Stream_Write_UINT8(s, bmp->flags);
|
|
|
|
Stream_Write_UINT8(s, 0); /* reserved1, reserved2 */
|
|
|
|
Stream_Write_UINT8(s, bmp->codecID);
|
|
|
|
Stream_Write_UINT16(s, bmp->width);
|
|
|
|
Stream_Write_UINT16(s, bmp->height);
|
|
|
|
Stream_Write_UINT32(s, bmp->bitmapDataLength);
|
|
|
|
|
|
|
|
if (bmp->flags & EX_COMPRESSED_BITMAP_HEADER_PRESENT)
|
|
|
|
{
|
|
|
|
if (!update_write_surfcmd_bitmap_header_ex(s, &bmp->exBitmapDataHeader))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, bmp->bitmapDataLength))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Write(s, bmp->bitmapData, bmp->bitmapDataLength);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL update_write_surfcmd_surface_bits(wStream* s, const SURFACE_BITS_COMMAND* cmd)
|
2011-08-23 19:28:28 +04:00
|
|
|
{
|
2015-04-14 11:14:23 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, SURFCMD_SURFACE_BITS_HEADER_LENGTH))
|
|
|
|
return FALSE;
|
2011-08-23 19:28:28 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, CMDTYPE_STREAM_SURFACE_BITS);
|
|
|
|
Stream_Write_UINT16(s, cmd->destLeft);
|
|
|
|
Stream_Write_UINT16(s, cmd->destTop);
|
|
|
|
Stream_Write_UINT16(s, cmd->destRight);
|
|
|
|
Stream_Write_UINT16(s, cmd->destBottom);
|
2018-02-28 12:10:09 +03:00
|
|
|
|
|
|
|
return update_write_surfcmd_bitmap_ex(s, &cmd->bmp);
|
2011-08-23 19:28:28 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
BOOL update_write_surfcmd_frame_marker(wStream* s, UINT16 frameAction, UINT32 frameId)
|
2011-08-23 19:28:28 +04:00
|
|
|
{
|
2015-04-14 11:14:23 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, SURFCMD_FRAME_MARKER_LENGTH))
|
|
|
|
return FALSE;
|
2011-08-23 19:28:28 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, CMDTYPE_FRAME_MARKER);
|
|
|
|
Stream_Write_UINT16(s, frameAction);
|
|
|
|
Stream_Write_UINT32(s, frameId);
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2011-08-23 19:28:28 +04:00
|
|
|
}
|