2011-08-01 20:19:39 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-08-01 20:19:39 +04:00
|
|
|
* Fast Path
|
|
|
|
*
|
|
|
|
* 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-01 20:19:39 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2012-11-22 05:21:08 +04:00
|
|
|
#include <winpr/crt.h>
|
2013-04-30 07:55:44 +04:00
|
|
|
#include <winpr/stream.h>
|
2012-11-22 05:21:08 +04:00
|
|
|
|
2011-08-31 12:35:50 +04:00
|
|
|
#include <freerdp/api.h>
|
2012-02-17 09:58:30 +04:00
|
|
|
#include <freerdp/crypto/per.h>
|
2011-08-01 20:19:39 +04:00
|
|
|
|
2011-08-16 11:04:57 +04:00
|
|
|
#include "orders.h"
|
|
|
|
#include "update.h"
|
2011-08-23 17:01:19 +04:00
|
|
|
#include "surface.h"
|
2011-08-01 20:19:39 +04:00
|
|
|
#include "fastpath.h"
|
2012-03-30 07:57:26 +04:00
|
|
|
#include "rdp.h"
|
2011-08-01 20:19:39 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fast-Path packet format is defined in [MS-RDPBCGR] 2.2.9.1.2, which revises
|
|
|
|
* server output packets from the first byte with the goal of improving
|
|
|
|
* bandwidth.
|
|
|
|
*
|
|
|
|
* Slow-Path packet always starts with TPKT header, which has the first
|
|
|
|
* byte 0x03, while Fast-Path packet starts with 2 zero bits in the first
|
|
|
|
* two less significant bits of the first byte.
|
|
|
|
*/
|
|
|
|
|
2011-08-26 17:18:07 +04:00
|
|
|
#define FASTPATH_MAX_PACKET_SIZE 0x3FFF
|
2011-08-23 19:28:28 +04:00
|
|
|
|
2012-07-24 01:01:23 +04:00
|
|
|
#ifdef WITH_DEBUG_RDP
|
|
|
|
static const char* const FASTPATH_UPDATETYPE_STRINGS[] =
|
|
|
|
{
|
|
|
|
"Orders", /* 0x0 */
|
|
|
|
"Bitmap", /* 0x1 */
|
|
|
|
"Palette", /* 0x2 */
|
|
|
|
"Synchronize", /* 0x3 */
|
|
|
|
"Surface Commands", /* 0x4 */
|
|
|
|
"System Pointer Hidden", /* 0x5 */
|
|
|
|
"System Pointer Default", /* 0x6 */
|
|
|
|
"???", /* 0x7 */
|
|
|
|
"Pointer Position", /* 0x8 */
|
|
|
|
"Color Pointer", /* 0x9 */
|
|
|
|
"Cached Pointer", /* 0xA */
|
|
|
|
"New Pointer", /* 0xB */
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2012-02-08 14:50:29 +04:00
|
|
|
/*
|
|
|
|
* The fastpath header may be two or three bytes long.
|
|
|
|
* This function assumes that at least two bytes are available in the stream
|
|
|
|
* and doesn't touch third byte.
|
|
|
|
*/
|
2013-03-21 23:19:33 +04:00
|
|
|
UINT16 fastpath_header_length(wStream* s)
|
2012-02-08 14:50:29 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE length1;
|
2012-02-08 14:50:29 +04:00
|
|
|
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_Seek_UINT8(s);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, length1);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Rewind(s, 2);
|
2012-02-08 14:50:29 +04:00
|
|
|
|
|
|
|
return ((length1 & 0x80) != 0 ? 3 : 2);
|
|
|
|
}
|
|
|
|
|
2012-02-08 15:46:53 +04:00
|
|
|
/**
|
|
|
|
* Read a Fast-Path packet header.\n
|
|
|
|
* @param s stream
|
|
|
|
* @param encryptionFlags
|
|
|
|
* @return length
|
|
|
|
*/
|
2013-03-21 23:19:33 +04:00
|
|
|
UINT16 fastpath_read_header(rdpFastPath* fastpath, wStream* s)
|
2011-08-01 20:19:39 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE header;
|
|
|
|
UINT16 length;
|
2011-08-01 20:19:39 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, header);
|
2011-09-15 06:09:33 +04:00
|
|
|
|
2013-05-02 02:15:55 +04:00
|
|
|
if (fastpath)
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
2011-08-09 19:28:02 +04:00
|
|
|
fastpath->encryptionFlags = (header & 0xC0) >> 6;
|
2011-08-23 11:51:51 +04:00
|
|
|
fastpath->numberEvents = (header & 0x3C) >> 2;
|
|
|
|
}
|
2011-08-01 20:19:39 +04:00
|
|
|
|
2012-02-07 14:15:32 +04:00
|
|
|
per_read_length(s, &length);
|
2011-08-01 20:19:39 +04:00
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
2011-08-09 19:28:02 +04:00
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static INLINE void fastpath_read_update_header(wStream* s, BYTE* updateCode, BYTE* fragmentation, BYTE* compression)
|
2011-08-28 21:36:56 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE updateHeader;
|
2011-08-28 21:36:56 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, updateHeader);
|
2011-08-28 21:36:56 +04:00
|
|
|
*updateCode = updateHeader & 0x0F;
|
|
|
|
*fragmentation = (updateHeader >> 4) & 0x03;
|
|
|
|
*compression = (updateHeader >> 6) & 0x03;
|
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static INLINE void fastpath_write_update_header(wStream* s, BYTE updateCode, BYTE fragmentation, BYTE compression)
|
2011-08-28 21:36:56 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE updateHeader = 0;
|
2011-08-28 21:36:56 +04:00
|
|
|
|
|
|
|
updateHeader |= updateCode & 0x0F;
|
2011-08-29 06:27:46 +04:00
|
|
|
updateHeader |= (fragmentation & 0x03) << 4;
|
|
|
|
updateHeader |= (compression & 0x03) << 6;
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(s, updateHeader);
|
2011-08-28 21:36:56 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL fastpath_read_header_rdp(rdpFastPath* fastpath, wStream* s, UINT16 *length)
|
2011-09-15 01:14:50 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE header;
|
2011-09-15 01:14:50 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, header);
|
2011-09-15 06:09:33 +04:00
|
|
|
|
2013-05-02 02:15:55 +04:00
|
|
|
if (fastpath)
|
2011-09-15 01:14:50 +04:00
|
|
|
{
|
|
|
|
fastpath->encryptionFlags = (header & 0xC0) >> 6;
|
|
|
|
fastpath->numberEvents = (header & 0x3C) >> 2;
|
|
|
|
}
|
|
|
|
|
2013-01-14 02:37:50 +04:00
|
|
|
if (!per_read_length(s, length))
|
|
|
|
return FALSE;
|
2011-09-15 01:14:50 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
*length = *length - Stream_GetPosition(s);
|
2013-01-14 02:37:50 +04:00
|
|
|
return TRUE;
|
2011-09-15 01:14:50 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL fastpath_recv_orders(rdpFastPath* fastpath, wStream* s)
|
2011-08-16 11:04:57 +04:00
|
|
|
{
|
|
|
|
rdpUpdate* update = fastpath->rdp->update;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 numberOrders;
|
2011-08-16 11:04:57 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, numberOrders); /* numberOrders (2 bytes) */
|
2011-08-16 11:04:57 +04:00
|
|
|
|
|
|
|
while (numberOrders > 0)
|
|
|
|
{
|
2012-02-11 17:30:09 +04:00
|
|
|
if (!update_recv_order(update, s))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2011-08-16 11:04:57 +04:00
|
|
|
numberOrders--;
|
|
|
|
}
|
2012-02-11 17:30:09 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-16 11:04:57 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL fastpath_recv_update_common(rdpFastPath* fastpath, wStream* s)
|
2011-08-16 11:04:57 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 updateType;
|
2011-11-22 04:41:49 +04:00
|
|
|
rdpUpdate* update = fastpath->rdp->update;
|
|
|
|
rdpContext* context = update->context;
|
2011-08-16 11:04:57 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 2)
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2013-04-13 01:05:42 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, updateType); /* updateType (2 bytes) */
|
2011-08-16 11:04:57 +04:00
|
|
|
|
|
|
|
switch (updateType)
|
|
|
|
{
|
|
|
|
case UPDATE_TYPE_BITMAP:
|
2013-08-08 05:47:03 +04:00
|
|
|
if (!update_read_bitmap_update(update, s, &update->bitmap_update))
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2011-11-22 04:41:49 +04:00
|
|
|
IFCALL(update->BitmapUpdate, context, &update->bitmap_update);
|
2011-08-16 11:04:57 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UPDATE_TYPE_PALETTE:
|
2013-04-13 01:05:42 +04:00
|
|
|
if (!update_read_palette(update, s, &update->palette_update))
|
2013-01-12 17:49:01 +04:00
|
|
|
return FALSE;
|
2011-11-22 04:41:49 +04:00
|
|
|
IFCALL(update->Palette, context, &update->palette_update);
|
2011-08-16 11:04:57 +04:00
|
|
|
break;
|
|
|
|
}
|
2013-01-12 17:49:01 +04:00
|
|
|
return TRUE;
|
2011-08-16 11:04:57 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL fastpath_recv_update_synchronize(rdpFastPath* fastpath, wStream* s)
|
2012-01-11 02:03:31 +04:00
|
|
|
{
|
2013-01-14 15:33:56 +04:00
|
|
|
/* server 2008 can send invalid synchronize packet with missing padding,
|
|
|
|
so don't return FALSE even if the packet is invalid */
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_SafeSeek(s, 2); /* size (2 bytes), MUST be set to zero */
|
2013-01-14 15:33:56 +04:00
|
|
|
return TRUE;
|
2012-01-11 02:03:31 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static int fastpath_recv_update(rdpFastPath* fastpath, BYTE updateCode, UINT32 size, wStream* s)
|
2011-08-09 19:28:02 +04:00
|
|
|
{
|
2013-01-17 03:01:10 +04:00
|
|
|
int status = 0;
|
2011-09-19 22:50:40 +04:00
|
|
|
rdpUpdate* update = fastpath->rdp->update;
|
2011-11-22 02:48:03 +04:00
|
|
|
rdpContext* context = fastpath->rdp->update->context;
|
|
|
|
rdpPointerUpdate* pointer = update->pointer;
|
2011-09-19 22:50:40 +04:00
|
|
|
|
2012-07-24 01:01:23 +04:00
|
|
|
#ifdef WITH_DEBUG_RDP
|
|
|
|
DEBUG_RDP("recv Fast-Path %s Update (0x%X), length:%d",
|
2013-07-07 10:44:38 +04:00
|
|
|
updateCode < ARRAYSIZE(FASTPATH_UPDATETYPE_STRINGS) ? FASTPATH_UPDATETYPE_STRINGS[updateCode] : "???", updateCode, size);
|
2012-07-24 01:01:23 +04:00
|
|
|
#endif
|
|
|
|
|
2011-08-09 19:28:02 +04:00
|
|
|
switch (updateCode)
|
|
|
|
{
|
|
|
|
case FASTPATH_UPDATETYPE_ORDERS:
|
2012-02-11 17:30:09 +04:00
|
|
|
if (!fastpath_recv_orders(fastpath, s))
|
2013-01-17 03:01:10 +04:00
|
|
|
return -1;
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_BITMAP:
|
|
|
|
case FASTPATH_UPDATETYPE_PALETTE:
|
2013-01-17 03:01:10 +04:00
|
|
|
if (!fastpath_recv_update_common(fastpath, s))
|
|
|
|
return -1;
|
2013-01-14 02:37:50 +04:00
|
|
|
break;
|
2011-08-09 19:28:02 +04:00
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_SYNCHRONIZE:
|
2013-01-12 17:49:01 +04:00
|
|
|
if (!fastpath_recv_update_synchronize(fastpath, s))
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "fastpath_recv_update_synchronize failure but we continue\n");
|
2013-01-14 13:13:29 +04:00
|
|
|
else
|
|
|
|
IFCALL(update->Synchronize, context);
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_SURFCMDS:
|
2013-01-17 03:01:10 +04:00
|
|
|
status = update_recv_surfcmds(update, size, s);
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_PTR_NULL:
|
2011-11-22 02:48:03 +04:00
|
|
|
pointer->pointer_system.type = SYSPTR_NULL;
|
|
|
|
IFCALL(pointer->PointerSystem, context, &pointer->pointer_system);
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_PTR_DEFAULT:
|
2011-11-22 02:48:03 +04:00
|
|
|
update->pointer->pointer_system.type = SYSPTR_DEFAULT;
|
|
|
|
IFCALL(pointer->PointerSystem, context, &pointer->pointer_system);
|
2013-04-15 14:14:09 +04:00
|
|
|
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_PTR_POSITION:
|
2013-01-12 17:49:01 +04:00
|
|
|
if (!update_read_pointer_position(s, &pointer->pointer_position))
|
2013-01-17 03:01:10 +04:00
|
|
|
return -1;
|
2011-11-22 02:48:03 +04:00
|
|
|
IFCALL(pointer->PointerPosition, context, &pointer->pointer_position);
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_COLOR:
|
2013-01-12 17:49:01 +04:00
|
|
|
if (!update_read_pointer_color(s, &pointer->pointer_color))
|
2013-01-17 03:01:10 +04:00
|
|
|
return -1;
|
2011-11-22 02:48:03 +04:00
|
|
|
IFCALL(pointer->PointerColor, context, &pointer->pointer_color);
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_CACHED:
|
2013-01-12 17:49:01 +04:00
|
|
|
if (!update_read_pointer_cached(s, &pointer->pointer_cached))
|
2013-01-17 03:01:10 +04:00
|
|
|
return -1;
|
2011-11-22 02:48:03 +04:00
|
|
|
IFCALL(pointer->PointerCached, context, &pointer->pointer_cached);
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_UPDATETYPE_POINTER:
|
2013-01-14 02:37:50 +04:00
|
|
|
if (!update_read_pointer_new(s, &pointer->pointer_new))
|
2013-01-17 03:01:10 +04:00
|
|
|
return -1;
|
2011-11-22 02:48:03 +04:00
|
|
|
IFCALL(pointer->PointerNew, context, &pointer->pointer_new);
|
2011-08-09 19:28:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DEBUG_WARN("unknown updateCode 0x%X", updateCode);
|
|
|
|
break;
|
|
|
|
}
|
2012-02-11 17:30:09 +04:00
|
|
|
|
2013-01-17 03:01:10 +04:00
|
|
|
return status;
|
2011-08-09 19:28:02 +04:00
|
|
|
}
|
|
|
|
|
2013-04-30 07:55:44 +04:00
|
|
|
const char* fastpath_get_fragmentation_string(BYTE fragmentation)
|
|
|
|
{
|
|
|
|
if (fragmentation == FASTPATH_FRAGMENT_SINGLE)
|
|
|
|
return "FASTPATH_FRAGMENT_SINGLE";
|
|
|
|
else if (fragmentation == FASTPATH_FRAGMENT_LAST)
|
|
|
|
return "FASTPATH_FRAGMENT_LAST";
|
|
|
|
else if (fragmentation == FASTPATH_FRAGMENT_FIRST)
|
|
|
|
return "FASTPATH_FRAGMENT_FIRST";
|
|
|
|
else if (fragmentation == FASTPATH_FRAGMENT_NEXT)
|
|
|
|
return "FASTPATH_FRAGMENT_NEXT";
|
|
|
|
|
|
|
|
return "FASTPATH_FRAGMENT_UNKNOWN";
|
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static int fastpath_recv_update_data(rdpFastPath* fastpath, wStream* s)
|
2011-08-09 19:28:02 +04:00
|
|
|
{
|
2013-01-17 03:01:10 +04:00
|
|
|
int status;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 size;
|
2013-04-30 07:55:44 +04:00
|
|
|
UINT32 roff;
|
|
|
|
UINT32 rlen;
|
|
|
|
rdpRdp* rdp;
|
2011-08-28 23:12:33 +04:00
|
|
|
int next_pos;
|
2013-04-30 19:26:33 +04:00
|
|
|
BYTE* buffer;
|
|
|
|
wStream* cs;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 totalSize;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE updateCode;
|
|
|
|
BYTE fragmentation;
|
|
|
|
BYTE compression;
|
|
|
|
BYTE compressionFlags;
|
2013-04-30 19:26:33 +04:00
|
|
|
rdpTransport* transport;
|
2011-09-08 09:17:58 +04:00
|
|
|
|
2013-01-17 03:01:10 +04:00
|
|
|
status = 0;
|
2011-09-08 09:17:58 +04:00
|
|
|
rdp = fastpath->rdp;
|
2013-04-30 19:26:33 +04:00
|
|
|
transport = fastpath->rdp->transport;
|
2011-08-09 19:28:02 +04:00
|
|
|
|
2011-08-28 21:36:56 +04:00
|
|
|
fastpath_read_update_header(s, &updateCode, &fragmentation, &compression);
|
2011-08-09 19:28:02 +04:00
|
|
|
|
|
|
|
if (compression == FASTPATH_OUTPUT_COMPRESSION_USED)
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, compressionFlags);
|
2011-08-09 19:28:02 +04:00
|
|
|
else
|
|
|
|
compressionFlags = 0;
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, size);
|
2013-01-17 03:01:10 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < size)
|
2013-01-17 03:01:10 +04:00
|
|
|
return -1;
|
|
|
|
|
2013-04-30 19:26:33 +04:00
|
|
|
cs = s;
|
2013-04-30 06:35:15 +04:00
|
|
|
next_pos = Stream_GetPosition(s) + size;
|
2011-08-09 19:28:02 +04:00
|
|
|
|
2011-09-11 22:08:15 +04:00
|
|
|
if (compressionFlags & PACKET_COMPRESSED)
|
2011-08-09 19:28:02 +04:00
|
|
|
{
|
2013-05-15 20:14:26 +04:00
|
|
|
if (decompress_rdp(rdp->mppc_dec, Stream_Pointer(s), size, compressionFlags, &roff, &rlen))
|
2011-09-08 09:17:58 +04:00
|
|
|
{
|
2013-04-30 19:26:33 +04:00
|
|
|
size = rlen;
|
|
|
|
buffer = rdp->mppc_dec->history_buf + roff;
|
|
|
|
|
|
|
|
cs = StreamPool_Take(transport->ReceivePool, size);
|
|
|
|
|
|
|
|
Stream_SetPosition(cs, 0);
|
|
|
|
Stream_Write(cs, buffer, size);
|
|
|
|
Stream_SealLength(cs);
|
|
|
|
Stream_SetPosition(cs, 0);
|
2011-09-08 09:17:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "decompress_rdp() failed\n");
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(s, size);
|
2011-09-08 09:17:58 +04:00
|
|
|
}
|
2011-08-09 19:28:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fragmentation == FASTPATH_FRAGMENT_SINGLE)
|
|
|
|
{
|
2013-04-30 07:55:44 +04:00
|
|
|
if (fastpath->fragmentation != -1)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Unexpected FASTPATH_FRAGMENT_SINGLE\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-08-28 23:12:33 +04:00
|
|
|
totalSize = size;
|
2013-04-30 19:26:33 +04:00
|
|
|
status = fastpath_recv_update(fastpath, updateCode, totalSize, cs);
|
2013-04-30 07:55:44 +04:00
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
return -1;
|
2011-08-09 19:28:02 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (fragmentation == FASTPATH_FRAGMENT_FIRST)
|
2013-04-30 07:55:44 +04:00
|
|
|
{
|
|
|
|
if (fastpath->fragmentation != -1)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Unexpected FASTPATH_FRAGMENT_FIRST\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2011-08-09 19:28:02 +04:00
|
|
|
|
2013-04-30 07:55:44 +04:00
|
|
|
fastpath->fragmentation = FASTPATH_FRAGMENT_FIRST;
|
2013-04-13 01:05:42 +04:00
|
|
|
|
2013-04-30 07:55:44 +04:00
|
|
|
totalSize = size;
|
|
|
|
|
|
|
|
if (totalSize > transport->settings->MultifragMaxRequestSize)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Total size (%d) exceeds MultifragMaxRequestSize (%d)\n",
|
|
|
|
totalSize, transport->settings->MultifragMaxRequestSize);
|
|
|
|
return -1;
|
|
|
|
}
|
2011-08-09 19:28:02 +04:00
|
|
|
|
2013-04-30 07:55:44 +04:00
|
|
|
fastpath->updateData = StreamPool_Take(transport->ReceivePool, size);
|
|
|
|
Stream_SetPosition(fastpath->updateData, 0);
|
|
|
|
|
2013-04-30 19:26:33 +04:00
|
|
|
Stream_Copy(fastpath->updateData, cs, size);
|
2013-04-30 07:55:44 +04:00
|
|
|
}
|
|
|
|
else if (fragmentation == FASTPATH_FRAGMENT_NEXT)
|
2011-08-09 19:28:02 +04:00
|
|
|
{
|
2013-04-30 07:55:44 +04:00
|
|
|
if ((fastpath->fragmentation != FASTPATH_FRAGMENT_FIRST) &&
|
|
|
|
(fastpath->fragmentation != FASTPATH_FRAGMENT_NEXT))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Unexpected FASTPATH_FRAGMENT_NEXT\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fastpath->fragmentation = FASTPATH_FRAGMENT_NEXT;
|
|
|
|
|
|
|
|
totalSize = Stream_GetPosition(fastpath->updateData) + size;
|
|
|
|
|
|
|
|
if (totalSize > transport->settings->MultifragMaxRequestSize)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Total size (%d) exceeds MultifragMaxRequestSize (%d)\n",
|
|
|
|
totalSize, transport->settings->MultifragMaxRequestSize);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stream_EnsureCapacity(fastpath->updateData, totalSize);
|
|
|
|
|
2013-04-30 19:26:33 +04:00
|
|
|
Stream_Copy(fastpath->updateData, cs, size);
|
2011-08-09 19:28:02 +04:00
|
|
|
}
|
2013-04-30 07:55:44 +04:00
|
|
|
else if (fragmentation == FASTPATH_FRAGMENT_LAST)
|
|
|
|
{
|
|
|
|
if ((fastpath->fragmentation != FASTPATH_FRAGMENT_FIRST) &&
|
|
|
|
(fastpath->fragmentation != FASTPATH_FRAGMENT_NEXT))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Unexpected FASTPATH_FRAGMENT_LAST\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2011-08-09 19:28:02 +04:00
|
|
|
|
2013-04-30 07:55:44 +04:00
|
|
|
fastpath->fragmentation = -1;
|
2013-01-17 03:01:10 +04:00
|
|
|
|
2013-04-30 07:55:44 +04:00
|
|
|
totalSize = Stream_GetPosition(fastpath->updateData) + size;
|
|
|
|
|
|
|
|
if (totalSize > transport->settings->MultifragMaxRequestSize)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Total size (%d) exceeds MultifragMaxRequestSize (%d)\n",
|
|
|
|
totalSize, transport->settings->MultifragMaxRequestSize);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Stream_EnsureCapacity(fastpath->updateData, totalSize);
|
|
|
|
|
2013-04-30 19:26:33 +04:00
|
|
|
Stream_Copy(fastpath->updateData, cs, size);
|
2013-04-30 07:55:44 +04:00
|
|
|
|
|
|
|
Stream_SealLength(fastpath->updateData);
|
|
|
|
Stream_SetPosition(fastpath->updateData, 0);
|
|
|
|
|
|
|
|
status = fastpath_recv_update(fastpath, updateCode, totalSize, fastpath->updateData);
|
|
|
|
|
|
|
|
Stream_Release(fastpath->updateData);
|
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
2012-02-11 17:30:09 +04:00
|
|
|
}
|
2011-08-09 19:28:02 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, next_pos);
|
2011-09-11 11:00:40 +04:00
|
|
|
|
2013-04-30 19:26:33 +04:00
|
|
|
if (cs != s)
|
|
|
|
Stream_Release(cs);
|
2012-02-11 17:30:09 +04:00
|
|
|
|
2013-01-17 03:01:10 +04:00
|
|
|
return status;
|
2011-08-09 19:28:02 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
int fastpath_recv_updates(rdpFastPath* fastpath, wStream* s)
|
2011-08-09 19:28:02 +04:00
|
|
|
{
|
2013-01-17 03:01:10 +04:00
|
|
|
int status = 0;
|
2011-08-10 19:55:47 +04:00
|
|
|
rdpUpdate* update = fastpath->rdp->update;
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
IFCALL(update->BeginPaint, update->context);
|
2011-08-10 19:55:47 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
while (Stream_GetRemainingLength(s) >= 3)
|
2011-08-09 19:28:02 +04:00
|
|
|
{
|
2013-01-17 03:01:10 +04:00
|
|
|
if (fastpath_recv_update_data(fastpath, s) < 0)
|
2013-01-09 02:18:10 +04:00
|
|
|
return -1;
|
2011-08-09 19:28:02 +04:00
|
|
|
}
|
2011-08-10 19:55:47 +04:00
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
IFCALL(update->EndPaint, update->context);
|
2011-08-23 08:58:10 +04:00
|
|
|
|
2013-01-17 03:01:10 +04:00
|
|
|
return status;
|
2011-08-23 08:58:10 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL fastpath_read_input_event_header(wStream* s, BYTE* eventFlags, BYTE* eventCode)
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE eventHeader;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 1)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, eventHeader); /* eventHeader (1 byte) */
|
2011-08-23 11:51:51 +04:00
|
|
|
|
|
|
|
*eventFlags = (eventHeader & 0x1F);
|
|
|
|
*eventCode = (eventHeader >> 5);
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL fastpath_recv_input_event_scancode(rdpFastPath* fastpath, wStream* s, BYTE eventFlags)
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 flags;
|
|
|
|
UINT16 code;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 1)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, code); /* keyCode (1 byte) */
|
2011-08-23 11:51:51 +04:00
|
|
|
|
|
|
|
flags = 0;
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2011-08-23 11:51:51 +04:00
|
|
|
if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_RELEASE))
|
|
|
|
flags |= KBD_FLAGS_RELEASE;
|
|
|
|
else
|
|
|
|
flags |= KBD_FLAGS_DOWN;
|
|
|
|
|
|
|
|
if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_EXTENDED))
|
|
|
|
flags |= KBD_FLAGS_EXTENDED;
|
|
|
|
|
|
|
|
IFCALL(fastpath->rdp->input->KeyboardEvent, fastpath->rdp->input, flags, code);
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL fastpath_recv_input_event_mouse(rdpFastPath* fastpath, wStream* s, BYTE eventFlags)
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 pointerFlags;
|
|
|
|
UINT16 xPos;
|
|
|
|
UINT16 yPos;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 6)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, pointerFlags); /* pointerFlags (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, xPos); /* xPos (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, yPos); /* yPos (2 bytes) */
|
2011-08-23 11:51:51 +04:00
|
|
|
|
|
|
|
IFCALL(fastpath->rdp->input->MouseEvent, fastpath->rdp->input, pointerFlags, xPos, yPos);
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL fastpath_recv_input_event_mousex(rdpFastPath* fastpath, wStream* s, BYTE eventFlags)
|
2011-08-23 08:58:10 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 pointerFlags;
|
|
|
|
UINT16 xPos;
|
|
|
|
UINT16 yPos;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 6)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, pointerFlags); /* pointerFlags (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, xPos); /* xPos (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, yPos); /* yPos (2 bytes) */
|
2011-08-23 11:51:51 +04:00
|
|
|
|
|
|
|
IFCALL(fastpath->rdp->input->ExtendedMouseEvent, fastpath->rdp->input, pointerFlags, xPos, yPos);
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL fastpath_recv_input_event_sync(rdpFastPath* fastpath, wStream* s, BYTE eventFlags)
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
|
|
|
IFCALL(fastpath->rdp->input->SynchronizeEvent, fastpath->rdp->input, eventFlags);
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL fastpath_recv_input_event_unicode(rdpFastPath* fastpath, wStream* s, BYTE eventFlags)
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 unicodeCode;
|
|
|
|
UINT16 flags;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 2)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, unicodeCode); /* unicodeCode (2 bytes) */
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2012-02-07 15:22:01 +04:00
|
|
|
flags = 0;
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2012-02-07 15:22:01 +04:00
|
|
|
if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_RELEASE))
|
|
|
|
flags |= KBD_FLAGS_RELEASE;
|
|
|
|
else
|
|
|
|
flags |= KBD_FLAGS_DOWN;
|
|
|
|
|
|
|
|
IFCALL(fastpath->rdp->input->UnicodeKeyboardEvent, fastpath->rdp->input, flags, unicodeCode);
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL fastpath_recv_input_event(rdpFastPath* fastpath, wStream* s)
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE eventFlags;
|
|
|
|
BYTE eventCode;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
|
|
|
if (!fastpath_read_input_event_header(s, &eventFlags, &eventCode))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
|
|
|
switch (eventCode)
|
|
|
|
{
|
|
|
|
case FASTPATH_INPUT_EVENT_SCANCODE:
|
|
|
|
if (!fastpath_recv_input_event_scancode(fastpath, s, eventFlags))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-23 11:51:51 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_INPUT_EVENT_MOUSE:
|
|
|
|
if (!fastpath_recv_input_event_mouse(fastpath, s, eventFlags))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-23 11:51:51 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_INPUT_EVENT_MOUSEX:
|
|
|
|
if (!fastpath_recv_input_event_mousex(fastpath, s, eventFlags))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-23 11:51:51 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_INPUT_EVENT_SYNC:
|
|
|
|
if (!fastpath_recv_input_event_sync(fastpath, s, eventFlags))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-23 11:51:51 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FASTPATH_INPUT_EVENT_UNICODE:
|
|
|
|
if (!fastpath_recv_input_event_unicode(fastpath, s, eventFlags))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-23 11:51:51 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Unknown eventCode %d\n", eventCode);
|
2011-08-23 11:51:51 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
int fastpath_recv_inputs(rdpFastPath* fastpath, wStream* s)
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE i;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
|
|
|
if (fastpath->numberEvents == 0)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* If numberEvents is not provided in fpInputHeader, it will be provided
|
2011-08-27 05:44:37 +04:00
|
|
|
* as one additional byte here.
|
2011-08-23 11:51:51 +04:00
|
|
|
*/
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 1)
|
2013-01-07 02:24:08 +04:00
|
|
|
return -1;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, fastpath->numberEvents); /* eventHeader (1 byte) */
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < fastpath->numberEvents; i++)
|
|
|
|
{
|
|
|
|
if (!fastpath_recv_input_event(fastpath, s))
|
2013-01-07 02:24:08 +04:00
|
|
|
return -1;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2013-01-07 02:24:08 +04:00
|
|
|
return 0;
|
2011-08-09 19:28:02 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
static UINT32 fastpath_get_sec_bytes(rdpRdp* rdp)
|
2012-01-25 19:08:14 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 sec_bytes;
|
2012-01-25 19:08:14 +04:00
|
|
|
|
2013-05-02 02:15:55 +04:00
|
|
|
sec_bytes = 0;
|
|
|
|
|
2012-01-25 19:08:14 +04:00
|
|
|
if (rdp->do_crypt)
|
|
|
|
{
|
|
|
|
sec_bytes = 8;
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2012-11-08 08:29:24 +04:00
|
|
|
if (rdp->settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS)
|
2012-01-25 19:08:14 +04:00
|
|
|
sec_bytes += 4;
|
|
|
|
}
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2012-01-25 19:08:14 +04:00
|
|
|
return sec_bytes;
|
|
|
|
}
|
|
|
|
|
2013-04-15 14:14:09 +04:00
|
|
|
wStream* fastpath_input_pdu_init_header(rdpFastPath* fastpath)
|
2011-08-16 10:37:11 +04:00
|
|
|
{
|
2012-01-25 19:08:14 +04:00
|
|
|
rdpRdp *rdp;
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2012-01-25 19:08:14 +04:00
|
|
|
|
|
|
|
rdp = fastpath->rdp;
|
|
|
|
|
|
|
|
s = transport_send_stream_init(rdp->transport, 256);
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(s, 3); /* fpInputHeader, length1 and length2 */
|
2013-05-02 02:15:55 +04:00
|
|
|
|
|
|
|
if (rdp->do_crypt)
|
|
|
|
{
|
2012-01-25 19:08:14 +04:00
|
|
|
rdp->sec_flags |= SEC_ENCRYPT;
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2012-01-25 19:08:14 +04:00
|
|
|
if (rdp->do_secure_checksum)
|
|
|
|
rdp->sec_flags |= SEC_SECURE_CHECKSUM;
|
|
|
|
}
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(s, fastpath_get_sec_bytes(rdp));
|
2013-04-15 14:14:09 +04:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
wStream* fastpath_input_pdu_init(rdpFastPath* fastpath, BYTE eventFlags, BYTE eventCode)
|
|
|
|
{
|
|
|
|
rdpRdp *rdp;
|
|
|
|
wStream* s;
|
|
|
|
|
|
|
|
rdp = fastpath->rdp;
|
|
|
|
|
|
|
|
s = fastpath_input_pdu_init_header(fastpath);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(s, eventFlags | (eventCode << 5)); /* eventHeader (1 byte) */
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2011-08-16 10:37:11 +04:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2013-04-15 14:14:09 +04:00
|
|
|
BOOL fastpath_send_multiple_input_pdu(rdpFastPath* fastpath, wStream* s, int iNumEvents)
|
2011-08-16 10:37:11 +04:00
|
|
|
{
|
2013-05-16 02:05:40 +04:00
|
|
|
rdpRdp* rdp;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 length;
|
|
|
|
BYTE eventHeader;
|
2012-01-25 19:08:14 +04:00
|
|
|
int sec_bytes;
|
|
|
|
|
2013-09-02 20:07:55 +04:00
|
|
|
/*
|
|
|
|
* A maximum of 15 events are allowed per request
|
|
|
|
* if the optional numEvents field isn't used
|
|
|
|
* see MS-RDPBCGR 2.2.8.1.2 for details
|
|
|
|
*/
|
|
|
|
if (iNumEvents > 15)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-01-25 19:08:14 +04:00
|
|
|
rdp = fastpath->rdp;
|
2011-08-16 10:37:11 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
length = Stream_GetPosition(s);
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2012-02-21 00:03:28 +04:00
|
|
|
if (length >= (2 << 14))
|
2011-08-16 10:37:11 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "Maximum FastPath PDU length is 32767\n");
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-16 10:37:11 +04:00
|
|
|
}
|
|
|
|
|
2012-01-25 19:08:14 +04:00
|
|
|
eventHeader = FASTPATH_INPUT_ACTION_FASTPATH;
|
2013-09-02 20:07:55 +04:00
|
|
|
eventHeader |= (iNumEvents << 2); /* numberEvents */
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2012-01-25 19:08:14 +04:00
|
|
|
if (rdp->sec_flags & SEC_ENCRYPT)
|
|
|
|
eventHeader |= (FASTPATH_INPUT_ENCRYPTED << 6);
|
|
|
|
if (rdp->sec_flags & SEC_SECURE_CHECKSUM)
|
|
|
|
eventHeader |= (FASTPATH_INPUT_SECURE_CHECKSUM << 6);
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, 0);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(s, eventHeader);
|
2012-01-25 19:08:14 +04:00
|
|
|
sec_bytes = fastpath_get_sec_bytes(fastpath->rdp);
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2012-01-25 19:08:14 +04:00
|
|
|
/*
|
2013-05-02 02:15:55 +04:00
|
|
|
* We always encode length in two bytes, even though we could use
|
2012-01-25 19:08:14 +04:00
|
|
|
* only one byte if length <= 0x7F. It is just easier that way,
|
|
|
|
* because we can leave room for fixed-length header, store all
|
|
|
|
* the data first and then store the header.
|
|
|
|
*/
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16_BE(s, 0x8000 | length);
|
2012-01-25 19:08:14 +04:00
|
|
|
|
|
|
|
if (sec_bytes > 0)
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* fpInputEvents;
|
|
|
|
UINT16 fpInputEvents_length;
|
2012-01-25 19:08:14 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
fpInputEvents = Stream_Pointer(s) + sec_bytes;
|
2012-02-21 00:03:31 +04:00
|
|
|
fpInputEvents_length = length - 3 - sec_bytes;
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2012-01-25 19:08:14 +04:00
|
|
|
if (rdp->sec_flags & SEC_SECURE_CHECKSUM)
|
2013-04-30 06:35:15 +04:00
|
|
|
security_salted_mac_signature(rdp, fpInputEvents, fpInputEvents_length, TRUE, Stream_Pointer(s));
|
2012-01-25 19:08:14 +04:00
|
|
|
else
|
2013-04-30 06:35:15 +04:00
|
|
|
security_mac_signature(rdp, fpInputEvents, fpInputEvents_length, Stream_Pointer(s));
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2012-02-21 00:03:31 +04:00
|
|
|
security_encrypt(fpInputEvents, fpInputEvents_length, rdp);
|
2012-01-25 19:08:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
rdp->sec_flags = 0;
|
2011-08-16 10:37:11 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, length);
|
2013-05-15 20:14:26 +04:00
|
|
|
Stream_SealLength(s);
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2011-08-23 11:51:51 +04:00
|
|
|
if (transport_write(fastpath->rdp->transport, s) < 0)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-23 11:51:51 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-23 11:51:51 +04:00
|
|
|
}
|
|
|
|
|
2013-04-15 14:14:09 +04:00
|
|
|
BOOL fastpath_send_input_pdu(rdpFastPath* fastpath, wStream* s)
|
|
|
|
{
|
|
|
|
return fastpath_send_multiple_input_pdu(fastpath, s, 1);
|
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* fastpath_update_pdu_init(rdpFastPath* fastpath)
|
2011-08-23 11:51:51 +04:00
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2011-08-23 19:28:28 +04:00
|
|
|
s = transport_send_stream_init(fastpath->rdp->transport, FASTPATH_MAX_PACKET_SIZE);
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(s, 3); /* fpOutputHeader, length1 and length2 */
|
|
|
|
Stream_Seek(s, fastpath_get_sec_bytes(fastpath->rdp));
|
|
|
|
Stream_Seek(s, 3); /* updateHeader, size */
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2011-08-23 11:51:51 +04:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2013-05-10 00:30:28 +04:00
|
|
|
wStream* fastpath_update_pdu_init_new(rdpFastPath* fastpath)
|
|
|
|
{
|
|
|
|
wStream* s;
|
|
|
|
|
|
|
|
s = Stream_New(NULL, FASTPATH_MAX_PACKET_SIZE);
|
|
|
|
|
|
|
|
Stream_Seek(s, 3); /* fpOutputHeader, length1 and length2 */
|
|
|
|
Stream_Seek(s, fastpath_get_sec_bytes(fastpath->rdp));
|
|
|
|
Stream_Seek(s, 3); /* updateHeader, size */
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s)
|
2011-08-27 05:44:37 +04:00
|
|
|
{
|
2012-03-20 21:03:36 +04:00
|
|
|
rdpRdp* rdp;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* bm;
|
|
|
|
BYTE* ptr_to_crypt;
|
|
|
|
BYTE* ptr_sig;
|
|
|
|
BYTE* holdp;
|
2011-08-28 01:11:20 +04:00
|
|
|
int fragment;
|
2012-01-25 19:08:14 +04:00
|
|
|
int sec_bytes;
|
2012-03-20 21:03:36 +04:00
|
|
|
int try_comp;
|
|
|
|
int comp_flags;
|
|
|
|
int header_bytes;
|
|
|
|
int cflags;
|
|
|
|
int pdu_data_bytes;
|
|
|
|
int dlen;
|
|
|
|
int bytes_to_crypt;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL result;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 pduLength;
|
|
|
|
UINT16 maxLength;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 totalLength;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE fragmentation;
|
|
|
|
BYTE header;
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* update;
|
|
|
|
wStream* comp_update;
|
|
|
|
wStream* ls;
|
2011-08-27 05:44:37 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
result = TRUE;
|
2012-01-25 19:08:14 +04:00
|
|
|
rdp = fastpath->rdp;
|
2013-05-09 01:48:30 +04:00
|
|
|
update = comp_update = ls = NULL;
|
|
|
|
try_comp = rdp->settings->CompressionEnabled;
|
|
|
|
|
2012-01-25 19:08:14 +04:00
|
|
|
sec_bytes = fastpath_get_sec_bytes(rdp);
|
2012-04-22 08:17:00 +04:00
|
|
|
maxLength = FASTPATH_MAX_PACKET_SIZE - (6 + sec_bytes);
|
2013-04-30 06:35:15 +04:00
|
|
|
totalLength = Stream_GetPosition(s) - (6 + sec_bytes);
|
|
|
|
Stream_SetPosition(s, 0);
|
2011-08-27 05:44:37 +04:00
|
|
|
|
2013-05-02 02:15:55 +04:00
|
|
|
for (fragment = 0; (totalLength > 0) || (fragment == 0); fragment++)
|
2011-08-27 05:44:37 +04:00
|
|
|
{
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_GetPointer(s, holdp);
|
2012-03-20 21:03:36 +04:00
|
|
|
ls = s;
|
|
|
|
dlen = MIN(maxLength, totalLength);
|
|
|
|
cflags = 0;
|
2012-04-22 08:17:00 +04:00
|
|
|
comp_flags = 0;
|
2012-03-20 21:03:36 +04:00
|
|
|
header_bytes = 6 + sec_bytes;
|
|
|
|
pdu_data_bytes = dlen;
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2012-03-20 21:03:36 +04:00
|
|
|
if (try_comp)
|
|
|
|
{
|
2013-05-15 20:14:26 +04:00
|
|
|
if (compress_rdp(rdp->mppc_enc, Stream_Pointer(ls) + header_bytes, dlen))
|
2012-03-20 21:03:36 +04:00
|
|
|
{
|
|
|
|
if (rdp->mppc_enc->flags & PACKET_COMPRESSED)
|
|
|
|
{
|
|
|
|
cflags = rdp->mppc_enc->flags;
|
|
|
|
pdu_data_bytes = rdp->mppc_enc->bytes_in_opb;
|
|
|
|
comp_flags = FASTPATH_OUTPUT_COMPRESSION_USED;
|
|
|
|
header_bytes = 7 + sec_bytes;
|
2012-10-09 11:01:37 +04:00
|
|
|
bm = (BYTE*) (rdp->mppc_enc->outputBuffer - header_bytes);
|
2013-08-04 13:23:32 +04:00
|
|
|
if (comp_update)
|
|
|
|
Stream_Free(comp_update, FALSE);
|
2013-05-09 01:48:30 +04:00
|
|
|
comp_update = Stream_New(bm, pdu_data_bytes + header_bytes);
|
2012-03-20 21:03:36 +04:00
|
|
|
ls = comp_update;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2013-05-02 02:15:55 +04:00
|
|
|
{
|
2013-03-29 02:06:34 +04:00
|
|
|
fprintf(stderr, "fastpath_send_update_pdu: mppc_encode failed\n");
|
2013-05-02 02:15:55 +04:00
|
|
|
}
|
2012-03-20 21:03:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
totalLength -= dlen;
|
|
|
|
pduLength = pdu_data_bytes + header_bytes;
|
2011-08-28 01:11:20 +04:00
|
|
|
|
2011-08-28 21:36:56 +04:00
|
|
|
if (totalLength == 0)
|
|
|
|
fragmentation = (fragment == 0) ? FASTPATH_FRAGMENT_SINGLE : FASTPATH_FRAGMENT_LAST;
|
2011-08-28 01:11:20 +04:00
|
|
|
else
|
2011-08-28 21:36:56 +04:00
|
|
|
fragmentation = (fragment == 0) ? FASTPATH_FRAGMENT_FIRST : FASTPATH_FRAGMENT_NEXT;
|
|
|
|
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_GetPointer(ls, bm);
|
2012-01-25 19:08:14 +04:00
|
|
|
header = 0;
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2012-01-25 19:08:14 +04:00
|
|
|
if (sec_bytes > 0)
|
|
|
|
header |= (FASTPATH_OUTPUT_ENCRYPTED << 6);
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(ls, header); /* fpOutputHeader (1 byte) */
|
|
|
|
Stream_Write_UINT8(ls, 0x80 | (pduLength >> 8)); /* length1 */
|
|
|
|
Stream_Write_UINT8(ls, pduLength & 0xFF); /* length2 */
|
2012-03-20 21:03:36 +04:00
|
|
|
|
2012-01-25 19:08:14 +04:00
|
|
|
if (sec_bytes > 0)
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(ls, sec_bytes);
|
2012-03-20 21:03:36 +04:00
|
|
|
|
|
|
|
fastpath_write_update_header(ls, updateCode, fragmentation, comp_flags);
|
|
|
|
|
|
|
|
/* extra byte if compressed */
|
|
|
|
if (ls == comp_update)
|
|
|
|
{
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(ls, cflags);
|
2012-03-20 21:03:36 +04:00
|
|
|
bytes_to_crypt = pdu_data_bytes + 4;
|
|
|
|
}
|
|
|
|
else
|
2013-05-02 02:15:55 +04:00
|
|
|
{
|
2012-03-20 21:03:36 +04:00
|
|
|
bytes_to_crypt = pdu_data_bytes + 3;
|
2013-05-02 02:15:55 +04:00
|
|
|
}
|
2012-03-20 21:03:36 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(ls, pdu_data_bytes);
|
2011-12-03 10:42:13 +04:00
|
|
|
|
2013-08-04 13:23:32 +04:00
|
|
|
if (update)
|
|
|
|
Stream_Free(update, FALSE);
|
2013-05-09 01:48:30 +04:00
|
|
|
update = Stream_New(bm, pduLength);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(update, pduLength);
|
2012-03-20 21:03:36 +04:00
|
|
|
|
2012-01-25 19:08:14 +04:00
|
|
|
if (sec_bytes > 0)
|
|
|
|
{
|
2012-03-20 21:03:36 +04:00
|
|
|
/* does this work ? */
|
|
|
|
ptr_to_crypt = bm + 3 + sec_bytes;
|
|
|
|
ptr_sig = bm + 3;
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2012-01-25 19:08:14 +04:00
|
|
|
if (rdp->sec_flags & SEC_SECURE_CHECKSUM)
|
2012-10-09 10:31:28 +04:00
|
|
|
security_salted_mac_signature(rdp, ptr_to_crypt, bytes_to_crypt, TRUE, ptr_sig);
|
2012-01-25 19:08:14 +04:00
|
|
|
else
|
2012-03-20 21:03:36 +04:00
|
|
|
security_mac_signature(rdp, ptr_to_crypt, bytes_to_crypt, ptr_sig);
|
2013-05-02 02:15:55 +04:00
|
|
|
|
2012-03-20 21:03:36 +04:00
|
|
|
security_encrypt(ptr_to_crypt, bytes_to_crypt, rdp);
|
2012-01-25 19:08:14 +04:00
|
|
|
}
|
2012-03-20 21:03:36 +04:00
|
|
|
|
2013-05-15 20:14:26 +04:00
|
|
|
Stream_SealLength(s);
|
|
|
|
|
2011-12-03 10:42:13 +04:00
|
|
|
if (transport_write(fastpath->rdp->transport, update) < 0)
|
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
result = FALSE;
|
2011-12-03 10:42:13 +04:00
|
|
|
break;
|
|
|
|
}
|
2011-08-28 01:11:20 +04:00
|
|
|
|
2012-03-20 21:03:36 +04:00
|
|
|
/* Reserve 6 + sec_bytes bytes for the next fragment header, if any. */
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_SetPointer(s, holdp + dlen);
|
2011-08-27 05:44:37 +04:00
|
|
|
}
|
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(update, FALSE);
|
|
|
|
Stream_Free(comp_update, FALSE);
|
2011-12-03 10:42:13 +04:00
|
|
|
|
|
|
|
return result;
|
2011-08-27 05:44:37 +04:00
|
|
|
}
|
|
|
|
|
2011-08-09 19:28:02 +04:00
|
|
|
rdpFastPath* fastpath_new(rdpRdp* rdp)
|
|
|
|
{
|
|
|
|
rdpFastPath* fastpath;
|
|
|
|
|
2012-11-22 05:21:08 +04:00
|
|
|
fastpath = (rdpFastPath*) malloc(sizeof(rdpFastPath));
|
|
|
|
|
2013-04-30 07:55:44 +04:00
|
|
|
if (fastpath)
|
|
|
|
{
|
|
|
|
ZeroMemory(fastpath, sizeof(rdpFastPath));
|
|
|
|
|
|
|
|
fastpath->rdp = rdp;
|
|
|
|
fastpath->fragmentation = -1;
|
|
|
|
}
|
2011-08-09 19:28:02 +04:00
|
|
|
|
|
|
|
return fastpath;
|
|
|
|
}
|
|
|
|
|
|
|
|
void fastpath_free(rdpFastPath* fastpath)
|
|
|
|
{
|
2013-04-30 07:55:44 +04:00
|
|
|
if (fastpath)
|
|
|
|
{
|
|
|
|
free(fastpath);
|
|
|
|
}
|
2011-08-09 19:28:02 +04:00
|
|
|
}
|