20 #include <freerdp/config.h>
24 #include <winpr/assert.h>
26 #include <freerdp/utils/pcap.h>
27 #include <freerdp/log.h>
29 #include "../cache/cache.h"
32 #define TAG FREERDP_TAG("core.surface")
39 if (!Stream_CheckAndLogRequiredLength(TAG, s, 24))
42 Stream_Read_UINT32(s, header->highUniqueId);
43 Stream_Read_UINT32(s, header->lowUniqueId);
44 Stream_Read_UINT64(s, header->tmMilliseconds);
45 Stream_Read_UINT64(s, header->tmSeconds);
54 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
57 Stream_Read_UINT8(s, bmp->bpp);
58 Stream_Read_UINT8(s, bmp->flags);
60 Stream_Read_UINT8(s, bmp->codecID);
61 Stream_Read_UINT16(s, bmp->width);
62 Stream_Read_UINT16(s, bmp->height);
63 Stream_Read_UINT32(s, bmp->bitmapDataLength);
65 if ((bmp->width == 0) || (bmp->height == 0))
67 WLog_ERR(TAG,
"invalid size value width=%" PRIu16
", height=%" PRIu16, bmp->width,
72 if ((bmp->bpp < 1) || (bmp->bpp > 32))
74 WLog_ERR(TAG,
"invalid bpp value %" PRIu32
"", bmp->bpp);
78 if (bmp->flags & EX_COMPRESSED_BITMAP_HEADER_PRESENT)
80 if (!update_recv_surfcmd_bitmap_header_ex(s, &bmp->exBitmapDataHeader))
84 bmp->bitmapData = Stream_Pointer(s);
85 if (!Stream_SafeSeek(s, bmp->bitmapDataLength))
87 WLog_ERR(TAG,
"expected bitmapDataLength %" PRIu32
", not enough data",
88 bmp->bitmapDataLength);
94 static BOOL update_recv_surfcmd_is_rect_valid(
const rdpContext* context,
97 WINPR_ASSERT(context);
98 WINPR_ASSERT(context->settings);
103 if ((cmd->destTop >= cmd->destBottom) || (cmd->destLeft >= cmd->destRight))
106 "Empty surface bits command rectangle: %" PRIu16
"x%" PRIu16
"-%" PRIu16
108 cmd->destLeft, cmd->destTop, cmd->destRight, cmd->destBottom);
113 if ((cmd->destRight > context->settings->DesktopWidth) ||
114 (cmd->destBottom > context->settings->DesktopHeight))
117 "Invalid surface bits command rectangle: %" PRIu16
"x%" PRIu16
"-%" PRIu16
118 "x%" PRIu16
" does not fit %" PRIu32
"x%" PRIu32,
119 cmd->destLeft, cmd->destTop, cmd->destRight, cmd->destBottom,
120 context->settings->DesktopWidth, context->settings->DesktopHeight);
127 static BOOL update_recv_surfcmd_surface_bits(rdpUpdate* update,
wStream* s, UINT16 cmdType)
132 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
135 cmd.cmdType = cmdType;
136 Stream_Read_UINT16(s, cmd.destLeft);
137 Stream_Read_UINT16(s, cmd.destTop);
138 Stream_Read_UINT16(s, cmd.destRight);
139 Stream_Read_UINT16(s, cmd.destBottom);
141 if (!update_recv_surfcmd_is_rect_valid(update->context, &cmd))
144 if (!update_recv_surfcmd_bitmap_ex(s, &cmd.bmp))
147 if (!IFCALLRESULT(TRUE, update->SurfaceBits, update->context, &cmd))
149 WLog_DBG(TAG,
"update->SurfaceBits implementation failed");
158 static BOOL update_recv_surfcmd_frame_marker(rdpUpdate* update,
wStream* s)
165 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
168 Stream_Read_UINT16(s, marker.frameAction);
169 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
171 "[SERVER-BUG]: got %" PRIuz
", expected %" PRIuz
172 " bytes. [MS-RDPBCGR] 2.2.9.2.3 Frame Marker Command (TS_FRAME_MARKER) is "
173 "missing frameId, ignoring",
174 Stream_GetRemainingLength(s), 4);
176 Stream_Read_UINT32(s, marker.frameId);
177 WLog_Print(up->log, WLOG_DEBUG,
"SurfaceFrameMarker: action: %s (%" PRIu32
") id: %" PRIu32
"",
178 (!marker.frameAction) ?
"Begin" :
"End", marker.frameAction, marker.frameId);
180 if (!update->SurfaceFrameMarker)
182 WINPR_ASSERT(update->context);
185 WLog_ERR(TAG,
"Missing callback update->SurfaceFrameMarker");
189 if (!update->SurfaceFrameMarker(update->context, &marker))
191 WLog_DBG(TAG,
"update->SurfaceFrameMarker implementation failed");
198 int update_recv_surfcmds(rdpUpdate* update,
wStream* s)
205 while (Stream_GetRemainingLength(s) >= 2)
207 const size_t start = Stream_GetPosition(s);
208 const BYTE* mark = Stream_ConstPointer(s);
210 Stream_Read_UINT16(s, cmdType);
214 case CMDTYPE_SET_SURFACE_BITS:
215 case CMDTYPE_STREAM_SURFACE_BITS:
216 if (!update_recv_surfcmd_surface_bits(update, s, cmdType))
221 case CMDTYPE_FRAME_MARKER:
222 if (!update_recv_surfcmd_frame_marker(update, s))
228 WLog_ERR(TAG,
"unknown cmdType 0x%04" PRIX16
"", cmdType);
234 const size_t size = Stream_GetPosition(s) - start;
236 pcap_add_record(up->pcap_rfx, mark, size);
237 pcap_flush(up->pcap_rfx);
244 static BOOL update_write_surfcmd_bitmap_header_ex(
wStream* s,
250 if (!Stream_EnsureRemainingCapacity(s, 24))
253 Stream_Write_UINT32(s, header->highUniqueId);
254 Stream_Write_UINT32(s, header->lowUniqueId);
255 Stream_Write_UINT64(s, header->tmMilliseconds);
256 Stream_Write_UINT64(s, header->tmSeconds);
265 if (!Stream_EnsureRemainingCapacity(s, 12))
268 if (bmp->codecID > UINT8_MAX)
270 WLog_ERR(TAG,
"Invalid TS_BITMAP_DATA_EX::codecID=0x%04" PRIx16
"", bmp->codecID);
273 Stream_Write_UINT8(s, bmp->bpp);
274 Stream_Write_UINT8(s, bmp->flags);
275 Stream_Write_UINT8(s, 0);
276 Stream_Write_UINT8(s, (UINT8)bmp->codecID);
277 Stream_Write_UINT16(s, bmp->width);
278 Stream_Write_UINT16(s, bmp->height);
279 Stream_Write_UINT32(s, bmp->bitmapDataLength);
281 if (bmp->flags & EX_COMPRESSED_BITMAP_HEADER_PRESENT)
283 if (!update_write_surfcmd_bitmap_header_ex(s, &bmp->exBitmapDataHeader))
287 if (!Stream_EnsureRemainingCapacity(s, bmp->bitmapDataLength))
290 Stream_Write(s, bmp->bitmapData, bmp->bitmapDataLength);
297 if (!Stream_EnsureRemainingCapacity(s, SURFCMD_SURFACE_BITS_HEADER_LENGTH))
300 cmdType = cmd->cmdType;
303 case CMDTYPE_SET_SURFACE_BITS:
304 case CMDTYPE_STREAM_SURFACE_BITS:
308 "SURFACE_BITS_COMMAND->cmdType 0x%04" PRIx16
309 " not allowed, correcting to 0x%04" PRIx16,
310 cmdType, CMDTYPE_STREAM_SURFACE_BITS);
311 cmdType = CMDTYPE_STREAM_SURFACE_BITS;
315 Stream_Write_UINT16(s, cmdType);
316 Stream_Write_UINT16(s, cmd->destLeft);
317 Stream_Write_UINT16(s, cmd->destTop);
318 Stream_Write_UINT16(s, cmd->destRight);
319 Stream_Write_UINT16(s, cmd->destBottom);
320 return update_write_surfcmd_bitmap_ex(s, &cmd->bmp);
323 BOOL update_write_surfcmd_frame_marker(
wStream* s, UINT16 frameAction, UINT32 frameId)
325 if (!Stream_EnsureRemainingCapacity(s, SURFCMD_FRAME_MARKER_LENGTH))
328 Stream_Write_UINT16(s, CMDTYPE_FRAME_MARKER);
329 Stream_Write_UINT16(s, frameAction);
330 Stream_Write_UINT32(s, frameId);
FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.