20 #include <freerdp/config.h>
24 #include <winpr/assert.h>
25 #include <winpr/cast.h>
27 #include <freerdp/utils/pcap.h>
28 #include <freerdp/log.h>
30 #include "../cache/cache.h"
33 #define TAG FREERDP_TAG("core.surface")
40 if (!Stream_CheckAndLogRequiredLength(TAG, s, 24))
43 Stream_Read_UINT32(s, header->highUniqueId);
44 Stream_Read_UINT32(s, header->lowUniqueId);
45 Stream_Read_UINT64(s, header->tmMilliseconds);
46 Stream_Read_UINT64(s, header->tmSeconds);
55 if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
58 Stream_Read_UINT8(s, bmp->bpp);
59 Stream_Read_UINT8(s, bmp->flags);
61 Stream_Read_UINT8(s, bmp->codecID);
62 Stream_Read_UINT16(s, bmp->width);
63 Stream_Read_UINT16(s, bmp->height);
64 Stream_Read_UINT32(s, bmp->bitmapDataLength);
66 if ((bmp->width == 0) || (bmp->height == 0))
68 WLog_ERR(TAG,
"invalid size value width=%" PRIu16
", height=%" PRIu16, bmp->width,
73 if ((bmp->bpp < 1) || (bmp->bpp > 32))
75 WLog_ERR(TAG,
"invalid bpp value %" PRIu32
"", bmp->bpp);
79 if (bmp->flags & EX_COMPRESSED_BITMAP_HEADER_PRESENT)
81 if (!update_recv_surfcmd_bitmap_header_ex(s, &bmp->exBitmapDataHeader))
85 bmp->bitmapData = Stream_Pointer(s);
86 if (!Stream_SafeSeek(s, bmp->bitmapDataLength))
88 WLog_ERR(TAG,
"expected bitmapDataLength %" PRIu32
", not enough data",
89 bmp->bitmapDataLength);
95 static BOOL update_recv_surfcmd_is_rect_valid(
const rdpContext* context,
98 WINPR_ASSERT(context);
99 WINPR_ASSERT(context->settings);
104 if ((cmd->destTop >= cmd->destBottom) || (cmd->destLeft >= cmd->destRight))
107 "Empty surface bits command rectangle: %" PRIu16
"x%" PRIu16
"-%" PRIu16
109 cmd->destLeft, cmd->destTop, cmd->destRight, cmd->destBottom);
114 if ((cmd->destRight > context->settings->DesktopWidth) ||
115 (cmd->destBottom > context->settings->DesktopHeight))
118 "Invalid surface bits command rectangle: %" PRIu16
"x%" PRIu16
"-%" PRIu16
119 "x%" PRIu16
" does not fit %" PRIu32
"x%" PRIu32,
120 cmd->destLeft, cmd->destTop, cmd->destRight, cmd->destBottom,
121 context->settings->DesktopWidth, context->settings->DesktopHeight);
128 static BOOL update_recv_surfcmd_surface_bits(rdpUpdate* update,
wStream* s, UINT16 cmdType)
133 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
136 cmd.cmdType = cmdType;
137 Stream_Read_UINT16(s, cmd.destLeft);
138 Stream_Read_UINT16(s, cmd.destTop);
139 Stream_Read_UINT16(s, cmd.destRight);
140 Stream_Read_UINT16(s, cmd.destBottom);
142 if (!update_recv_surfcmd_is_rect_valid(update->context, &cmd))
145 if (!update_recv_surfcmd_bitmap_ex(s, &cmd.bmp))
148 if (!IFCALLRESULT(TRUE, update->SurfaceBits, update->context, &cmd))
150 WLog_DBG(TAG,
"update->SurfaceBits implementation failed");
159 static BOOL update_recv_surfcmd_frame_marker(rdpUpdate* update,
wStream* s)
166 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
169 Stream_Read_UINT16(s, marker.frameAction);
170 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
172 "[SERVER-BUG]: got %" PRIuz
", expected %" PRIuz
173 " bytes. [MS-RDPBCGR] 2.2.9.2.3 Frame Marker Command (TS_FRAME_MARKER) is "
174 "missing frameId, ignoring",
175 Stream_GetRemainingLength(s), 4);
177 Stream_Read_UINT32(s, marker.frameId);
178 WLog_Print(up->log, WLOG_DEBUG,
"SurfaceFrameMarker: action: %s (%" PRIu32
") id: %" PRIu32
"",
179 (!marker.frameAction) ?
"Begin" :
"End", marker.frameAction, marker.frameId);
181 if (!update->SurfaceFrameMarker)
183 WINPR_ASSERT(update->context);
186 WLog_ERR(TAG,
"Missing callback update->SurfaceFrameMarker");
190 if (!update->SurfaceFrameMarker(update->context, &marker))
192 WLog_DBG(TAG,
"update->SurfaceFrameMarker implementation failed");
199 int update_recv_surfcmds(rdpUpdate* update,
wStream* s)
206 while (Stream_GetRemainingLength(s) >= 2)
208 const size_t start = Stream_GetPosition(s);
209 const BYTE* mark = Stream_ConstPointer(s);
211 Stream_Read_UINT16(s, cmdType);
215 case CMDTYPE_SET_SURFACE_BITS:
216 case CMDTYPE_STREAM_SURFACE_BITS:
217 if (!update_recv_surfcmd_surface_bits(update, s, cmdType))
222 case CMDTYPE_FRAME_MARKER:
223 if (!update_recv_surfcmd_frame_marker(update, s))
229 WLog_ERR(TAG,
"unknown cmdType 0x%04" PRIX16
"", cmdType);
235 const size_t size = Stream_GetPosition(s) - start;
237 pcap_add_record(up->pcap_rfx, mark, size);
238 pcap_flush(up->pcap_rfx);
245 static BOOL update_write_surfcmd_bitmap_header_ex(
wStream* s,
251 if (!Stream_EnsureRemainingCapacity(s, 24))
254 Stream_Write_UINT32(s, header->highUniqueId);
255 Stream_Write_UINT32(s, header->lowUniqueId);
256 Stream_Write_UINT64(s, header->tmMilliseconds);
257 Stream_Write_UINT64(s, header->tmSeconds);
266 if (!Stream_EnsureRemainingCapacity(s, 12))
269 if (bmp->codecID > UINT8_MAX)
271 WLog_ERR(TAG,
"Invalid TS_BITMAP_DATA_EX::codecID=0x%04" PRIx16
"", bmp->codecID);
274 Stream_Write_UINT8(s, bmp->bpp);
275 Stream_Write_UINT8(s, bmp->flags);
276 Stream_Write_UINT8(s, 0);
277 Stream_Write_UINT8(s, (UINT8)bmp->codecID);
278 Stream_Write_UINT16(s, bmp->width);
279 Stream_Write_UINT16(s, bmp->height);
280 Stream_Write_UINT32(s, bmp->bitmapDataLength);
282 if (bmp->flags & EX_COMPRESSED_BITMAP_HEADER_PRESENT)
284 if (!update_write_surfcmd_bitmap_header_ex(s, &bmp->exBitmapDataHeader))
288 if (!Stream_EnsureRemainingCapacity(s, bmp->bitmapDataLength))
291 Stream_Write(s, bmp->bitmapData, bmp->bitmapDataLength);
297 if (!Stream_EnsureRemainingCapacity(s, SURFCMD_SURFACE_BITS_HEADER_LENGTH))
300 WINPR_ASSERT(cmd->cmdType <= UINT16_MAX);
301 UINT16 cmdType = (UINT16)cmd->cmdType;
304 case CMDTYPE_SET_SURFACE_BITS:
305 case CMDTYPE_STREAM_SURFACE_BITS:
309 "SURFACE_BITS_COMMAND->cmdType 0x%04" PRIx16
310 " not allowed, correcting to 0x%04" PRIx16,
311 cmdType, CMDTYPE_STREAM_SURFACE_BITS);
312 cmdType = CMDTYPE_STREAM_SURFACE_BITS;
316 Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, cmdType));
317 Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, cmd->destLeft));
318 Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, cmd->destTop));
319 Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, cmd->destRight));
320 Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, cmd->destBottom));
321 return update_write_surfcmd_bitmap_ex(s, &cmd->bmp);
324 BOOL update_write_surfcmd_frame_marker(
wStream* s, UINT16 frameAction, UINT32 frameId)
326 if (!Stream_EnsureRemainingCapacity(s, SURFCMD_FRAME_MARKER_LENGTH))
329 Stream_Write_UINT16(s, CMDTYPE_FRAME_MARKER);
330 Stream_Write_UINT16(s, frameAction);
331 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.