1 |
/* -*- c-basic-offset: 8 -*- |
/* -*- c-basic-offset: 8 -*- |
2 |
rdesktop: A Remote Desktop Protocol client. |
rdesktop: A Remote Desktop Protocol client. |
3 |
RDP order processing |
RDP order processing |
4 |
Copyright (C) Matthew Chapman 1999-2005 |
Copyright (C) Matthew Chapman 1999-2007 |
5 |
|
|
6 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
7 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
23 |
|
|
24 |
extern uint8 *g_next_packet; |
extern uint8 *g_next_packet; |
25 |
static RDP_ORDER_STATE g_order_state; |
static RDP_ORDER_STATE g_order_state; |
26 |
extern BOOL g_use_rdp5; |
extern RD_BOOL g_use_rdp5; |
27 |
|
|
28 |
/* Read field indicating which parameters are present */ |
/* Read field indicating which parameters are present */ |
29 |
static void |
static void |
55 |
|
|
56 |
/* Read a co-ordinate (16-bit, or 8-bit delta) */ |
/* Read a co-ordinate (16-bit, or 8-bit delta) */ |
57 |
static void |
static void |
58 |
rdp_in_coord(STREAM s, sint16 * coord, BOOL delta) |
rdp_in_coord(STREAM s, sint16 * coord, RD_BOOL delta) |
59 |
{ |
{ |
60 |
sint8 change; |
sint8 change; |
61 |
|
|
102 |
} |
} |
103 |
|
|
104 |
/* Parse bounds information */ |
/* Parse bounds information */ |
105 |
static BOOL |
static RD_BOOL |
106 |
rdp_parse_bounds(STREAM s, BOUNDS * bounds) |
rdp_parse_bounds(STREAM s, BOUNDS * bounds) |
107 |
{ |
{ |
108 |
uint8 present; |
uint8 present; |
133 |
} |
} |
134 |
|
|
135 |
/* Parse a pen */ |
/* Parse a pen */ |
136 |
static BOOL |
static RD_BOOL |
137 |
rdp_parse_pen(STREAM s, PEN * pen, uint32 present) |
rdp_parse_pen(STREAM s, PEN * pen, uint32 present) |
138 |
{ |
{ |
139 |
if (present & 1) |
if (present & 1) |
148 |
return s_check(s); |
return s_check(s); |
149 |
} |
} |
150 |
|
|
151 |
|
static void |
152 |
|
setup_brush(BRUSH * out_brush, BRUSH * in_brush) |
153 |
|
{ |
154 |
|
BRUSHDATA * brush_data; |
155 |
|
uint16 cache_idx; |
156 |
|
uint8 brush_bpp; |
157 |
|
|
158 |
|
memcpy(out_brush, in_brush, sizeof(BRUSH)); |
159 |
|
if (out_brush->style & 0x80) |
160 |
|
{ |
161 |
|
brush_bpp = out_brush->style & 0x0f; |
162 |
|
if (brush_bpp == 1) /* 1 bpp */ |
163 |
|
{ |
164 |
|
cache_idx = out_brush->pattern[0]; |
165 |
|
brush_data = cache_get_brush_data(cache_idx); |
166 |
|
if (brush_data == NULL) |
167 |
|
{ |
168 |
|
error("error getting brush data, style %x\n", out_brush->style); |
169 |
|
} |
170 |
|
else |
171 |
|
{ |
172 |
|
memcpy(out_brush->pattern, brush_data->pattern, |
173 |
|
sizeof(out_brush->pattern)); |
174 |
|
} |
175 |
|
} |
176 |
|
else |
177 |
|
{ |
178 |
|
error("bad brush bpp %d\n", brush_bpp); |
179 |
|
} |
180 |
|
out_brush->style = 3; |
181 |
|
} |
182 |
|
} |
183 |
|
|
184 |
/* Parse a brush */ |
/* Parse a brush */ |
185 |
static BOOL |
static RD_BOOL |
186 |
rdp_parse_brush(STREAM s, BRUSH * brush, uint32 present) |
rdp_parse_brush(STREAM s, BRUSH * brush, uint32 present) |
187 |
{ |
{ |
188 |
if (present & 1) |
if (present & 1) |
205 |
|
|
206 |
/* Process a destination blt order */ |
/* Process a destination blt order */ |
207 |
static void |
static void |
208 |
process_destblt(STREAM s, DESTBLT_ORDER * os, uint32 present, BOOL delta) |
process_destblt(STREAM s, DESTBLT_ORDER * os, uint32 present, RD_BOOL delta) |
209 |
{ |
{ |
210 |
if (present & 0x01) |
if (present & 0x01) |
211 |
rdp_in_coord(s, &os->x, delta); |
rdp_in_coord(s, &os->x, delta); |
230 |
|
|
231 |
/* Process a pattern blt order */ |
/* Process a pattern blt order */ |
232 |
static void |
static void |
233 |
process_patblt(STREAM s, PATBLT_ORDER * os, uint32 present, BOOL delta) |
process_patblt(STREAM s, PATBLT_ORDER * os, uint32 present, RD_BOOL delta) |
234 |
{ |
{ |
235 |
|
BRUSH brush; |
236 |
|
|
237 |
if (present & 0x0001) |
if (present & 0x0001) |
238 |
rdp_in_coord(s, &os->x, delta); |
rdp_in_coord(s, &os->x, delta); |
239 |
|
|
260 |
DEBUG(("PATBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,bs=%d,bg=0x%x,fg=0x%x)\n", os->opcode, os->x, |
DEBUG(("PATBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,bs=%d,bg=0x%x,fg=0x%x)\n", os->opcode, os->x, |
261 |
os->y, os->cx, os->cy, os->brush.style, os->bgcolour, os->fgcolour)); |
os->y, os->cx, os->cy, os->brush.style, os->bgcolour, os->fgcolour)); |
262 |
|
|
263 |
|
setup_brush(&brush, &os->brush); |
264 |
|
|
265 |
ui_patblt(ROP2_P(os->opcode), os->x, os->y, os->cx, os->cy, |
ui_patblt(ROP2_P(os->opcode), os->x, os->y, os->cx, os->cy, |
266 |
&os->brush, os->bgcolour, os->fgcolour); |
&brush, os->bgcolour, os->fgcolour); |
267 |
} |
} |
268 |
|
|
269 |
/* Process a screen blt order */ |
/* Process a screen blt order */ |
270 |
static void |
static void |
271 |
process_screenblt(STREAM s, SCREENBLT_ORDER * os, uint32 present, BOOL delta) |
process_screenblt(STREAM s, SCREENBLT_ORDER * os, uint32 present, RD_BOOL delta) |
272 |
{ |
{ |
273 |
if (present & 0x0001) |
if (present & 0x0001) |
274 |
rdp_in_coord(s, &os->x, delta); |
rdp_in_coord(s, &os->x, delta); |
299 |
|
|
300 |
/* Process a line order */ |
/* Process a line order */ |
301 |
static void |
static void |
302 |
process_line(STREAM s, LINE_ORDER * os, uint32 present, BOOL delta) |
process_line(STREAM s, LINE_ORDER * os, uint32 present, RD_BOOL delta) |
303 |
{ |
{ |
304 |
if (present & 0x0001) |
if (present & 0x0001) |
305 |
in_uint16_le(s, os->mixmode); |
in_uint16_le(s, os->mixmode); |
338 |
|
|
339 |
/* Process an opaque rectangle order */ |
/* Process an opaque rectangle order */ |
340 |
static void |
static void |
341 |
process_rect(STREAM s, RECT_ORDER * os, uint32 present, BOOL delta) |
process_rect(STREAM s, RECT_ORDER * os, uint32 present, RD_BOOL delta) |
342 |
{ |
{ |
343 |
uint32 i; |
uint32 i; |
344 |
if (present & 0x01) |
if (present & 0x01) |
378 |
|
|
379 |
/* Process a desktop save order */ |
/* Process a desktop save order */ |
380 |
static void |
static void |
381 |
process_desksave(STREAM s, DESKSAVE_ORDER * os, uint32 present, BOOL delta) |
process_desksave(STREAM s, DESKSAVE_ORDER * os, uint32 present, RD_BOOL delta) |
382 |
{ |
{ |
383 |
int width, height; |
int width, height; |
384 |
|
|
414 |
|
|
415 |
/* Process a memory blt order */ |
/* Process a memory blt order */ |
416 |
static void |
static void |
417 |
process_memblt(STREAM s, MEMBLT_ORDER * os, uint32 present, BOOL delta) |
process_memblt(STREAM s, MEMBLT_ORDER * os, uint32 present, RD_BOOL delta) |
418 |
{ |
{ |
419 |
HBITMAP bitmap; |
RD_HBITMAP bitmap; |
420 |
|
|
421 |
if (present & 0x0001) |
if (present & 0x0001) |
422 |
{ |
{ |
460 |
|
|
461 |
/* Process a 3-way blt order */ |
/* Process a 3-way blt order */ |
462 |
static void |
static void |
463 |
process_triblt(STREAM s, TRIBLT_ORDER * os, uint32 present, BOOL delta) |
process_triblt(STREAM s, TRIBLT_ORDER * os, uint32 present, RD_BOOL delta) |
464 |
{ |
{ |
465 |
HBITMAP bitmap; |
RD_HBITMAP bitmap; |
466 |
|
BRUSH brush; |
467 |
|
|
468 |
if (present & 0x000001) |
if (present & 0x000001) |
469 |
{ |
{ |
514 |
if (bitmap == NULL) |
if (bitmap == NULL) |
515 |
return; |
return; |
516 |
|
|
517 |
|
setup_brush(&brush, &os->brush); |
518 |
|
|
519 |
ui_triblt(os->opcode, os->x, os->y, os->cx, os->cy, |
ui_triblt(os->opcode, os->x, os->y, os->cx, os->cy, |
520 |
bitmap, os->srcx, os->srcy, &os->brush, os->bgcolour, os->fgcolour); |
bitmap, os->srcx, os->srcy, &brush, os->bgcolour, os->fgcolour); |
521 |
} |
} |
522 |
|
|
523 |
/* Process a polygon order */ |
/* Process a polygon order */ |
524 |
static void |
static void |
525 |
process_polygon(STREAM s, POLYGON_ORDER * os, uint32 present, BOOL delta) |
process_polygon(STREAM s, POLYGON_ORDER * os, uint32 present, RD_BOOL delta) |
526 |
{ |
{ |
527 |
int index, data, next; |
int index, data, next; |
528 |
uint8 flags = 0; |
uint8 flags = 0; |
529 |
POINT *points; |
RD_POINT *points; |
530 |
|
|
531 |
if (present & 0x01) |
if (present & 0x01) |
532 |
rdp_in_coord(s, &os->x, delta); |
rdp_in_coord(s, &os->x, delta); |
568 |
return; |
return; |
569 |
} |
} |
570 |
|
|
571 |
points = (POINT *) xmalloc((os->npoints + 1) * sizeof(POINT)); |
points = (RD_POINT *) xmalloc((os->npoints + 1) * sizeof(RD_POINT)); |
572 |
memset(points, 0, (os->npoints + 1) * sizeof(POINT)); |
memset(points, 0, (os->npoints + 1) * sizeof(RD_POINT)); |
573 |
|
|
574 |
points[0].x = os->x; |
points[0].x = os->x; |
575 |
points[0].y = os->y; |
points[0].y = os->y; |
601 |
|
|
602 |
/* Process a polygon2 order */ |
/* Process a polygon2 order */ |
603 |
static void |
static void |
604 |
process_polygon2(STREAM s, POLYGON2_ORDER * os, uint32 present, BOOL delta) |
process_polygon2(STREAM s, POLYGON2_ORDER * os, uint32 present, RD_BOOL delta) |
605 |
{ |
{ |
606 |
int index, data, next; |
int index, data, next; |
607 |
uint8 flags = 0; |
uint8 flags = 0; |
608 |
POINT *points; |
RD_POINT *points; |
609 |
|
BRUSH brush; |
610 |
|
|
611 |
if (present & 0x0001) |
if (present & 0x0001) |
612 |
rdp_in_coord(s, &os->x, delta); |
rdp_in_coord(s, &os->x, delta); |
654 |
return; |
return; |
655 |
} |
} |
656 |
|
|
657 |
points = (POINT *) xmalloc((os->npoints + 1) * sizeof(POINT)); |
setup_brush(&brush, &os->brush); |
658 |
memset(points, 0, (os->npoints + 1) * sizeof(POINT)); |
|
659 |
|
points = (RD_POINT *) xmalloc((os->npoints + 1) * sizeof(RD_POINT)); |
660 |
|
memset(points, 0, (os->npoints + 1) * sizeof(RD_POINT)); |
661 |
|
|
662 |
points[0].x = os->x; |
points[0].x = os->x; |
663 |
points[0].y = os->y; |
points[0].y = os->y; |
680 |
|
|
681 |
if (next - 1 == os->npoints) |
if (next - 1 == os->npoints) |
682 |
ui_polygon(os->opcode - 1, os->fillmode, points, os->npoints + 1, |
ui_polygon(os->opcode - 1, os->fillmode, points, os->npoints + 1, |
683 |
&os->brush, os->bgcolour, os->fgcolour); |
&brush, os->bgcolour, os->fgcolour); |
684 |
else |
else |
685 |
error("polygon2 parse error\n"); |
error("polygon2 parse error\n"); |
686 |
|
|
689 |
|
|
690 |
/* Process a polyline order */ |
/* Process a polyline order */ |
691 |
static void |
static void |
692 |
process_polyline(STREAM s, POLYLINE_ORDER * os, uint32 present, BOOL delta) |
process_polyline(STREAM s, POLYLINE_ORDER * os, uint32 present, RD_BOOL delta) |
693 |
{ |
{ |
694 |
int index, next, data; |
int index, next, data; |
695 |
uint8 flags = 0; |
uint8 flags = 0; |
696 |
PEN pen; |
PEN pen; |
697 |
POINT *points; |
RD_POINT *points; |
698 |
|
|
699 |
if (present & 0x01) |
if (present & 0x01) |
700 |
rdp_in_coord(s, &os->x, delta); |
rdp_in_coord(s, &os->x, delta); |
733 |
return; |
return; |
734 |
} |
} |
735 |
|
|
736 |
points = (POINT *) xmalloc((os->lines + 1) * sizeof(POINT)); |
points = (RD_POINT *) xmalloc((os->lines + 1) * sizeof(RD_POINT)); |
737 |
memset(points, 0, (os->lines + 1) * sizeof(POINT)); |
memset(points, 0, (os->lines + 1) * sizeof(RD_POINT)); |
738 |
|
|
739 |
points[0].x = os->x; |
points[0].x = os->x; |
740 |
points[0].y = os->y; |
points[0].y = os->y; |
767 |
|
|
768 |
/* Process an ellipse order */ |
/* Process an ellipse order */ |
769 |
static void |
static void |
770 |
process_ellipse(STREAM s, ELLIPSE_ORDER * os, uint32 present, BOOL delta) |
process_ellipse(STREAM s, ELLIPSE_ORDER * os, uint32 present, RD_BOOL delta) |
771 |
{ |
{ |
772 |
if (present & 0x01) |
if (present & 0x01) |
773 |
rdp_in_coord(s, &os->left, delta); |
rdp_in_coord(s, &os->left, delta); |
799 |
|
|
800 |
/* Process an ellipse2 order */ |
/* Process an ellipse2 order */ |
801 |
static void |
static void |
802 |
process_ellipse2(STREAM s, ELLIPSE2_ORDER * os, uint32 present, BOOL delta) |
process_ellipse2(STREAM s, ELLIPSE2_ORDER * os, uint32 present, RD_BOOL delta) |
803 |
{ |
{ |
804 |
|
BRUSH brush; |
805 |
|
|
806 |
if (present & 0x0001) |
if (present & 0x0001) |
807 |
rdp_in_coord(s, &os->left, delta); |
rdp_in_coord(s, &os->left, delta); |
808 |
|
|
833 |
os->left, os->top, os->right, os->bottom, os->opcode, os->fillmode, os->brush.style, |
os->left, os->top, os->right, os->bottom, os->opcode, os->fillmode, os->brush.style, |
834 |
os->bgcolour, os->fgcolour)); |
os->bgcolour, os->fgcolour)); |
835 |
|
|
836 |
|
setup_brush(&brush, &os->brush); |
837 |
|
|
838 |
ui_ellipse(os->opcode - 1, os->fillmode, os->left, os->top, os->right - os->left, |
ui_ellipse(os->opcode - 1, os->fillmode, os->left, os->top, os->right - os->left, |
839 |
os->bottom - os->top, &os->brush, os->bgcolour, os->fgcolour); |
os->bottom - os->top, &brush, os->bgcolour, os->fgcolour); |
840 |
} |
} |
841 |
|
|
842 |
/* Process a text order */ |
/* Process a text order */ |
843 |
static void |
static void |
844 |
process_text2(STREAM s, TEXT2_ORDER * os, uint32 present, BOOL delta) |
process_text2(STREAM s, TEXT2_ORDER * os, uint32 present, RD_BOOL delta) |
845 |
{ |
{ |
846 |
int i; |
int i; |
847 |
|
BRUSH brush; |
848 |
|
|
849 |
if (present & 0x000001) |
if (present & 0x000001) |
850 |
in_uint8(s, os->font); |
in_uint8(s, os->font); |
911 |
|
|
912 |
DEBUG(("\n")); |
DEBUG(("\n")); |
913 |
|
|
914 |
|
setup_brush(&brush, &os->brush); |
915 |
|
|
916 |
ui_draw_text(os->font, os->flags, os->opcode - 1, os->mixmode, os->x, os->y, |
ui_draw_text(os->font, os->flags, os->opcode - 1, os->mixmode, os->x, os->y, |
917 |
os->clipleft, os->cliptop, os->clipright - os->clipleft, |
os->clipleft, os->cliptop, os->clipright - os->clipleft, |
918 |
os->clipbottom - os->cliptop, os->boxleft, os->boxtop, |
os->clipbottom - os->cliptop, os->boxleft, os->boxtop, |
919 |
os->boxright - os->boxleft, os->boxbottom - os->boxtop, |
os->boxright - os->boxleft, os->boxbottom - os->boxtop, |
920 |
&os->brush, os->bgcolour, os->fgcolour, os->text, os->length); |
&brush, os->bgcolour, os->fgcolour, os->text, os->length); |
921 |
} |
} |
922 |
|
|
923 |
/* Process a raw bitmap cache order */ |
/* Process a raw bitmap cache order */ |
924 |
static void |
static void |
925 |
process_raw_bmpcache(STREAM s) |
process_raw_bmpcache(STREAM s) |
926 |
{ |
{ |
927 |
HBITMAP bitmap; |
RD_HBITMAP bitmap; |
928 |
uint16 cache_idx, bufsize; |
uint16 cache_idx, bufsize; |
929 |
uint8 cache_id, width, height, bpp, Bpp; |
uint8 cache_id, width, height, bpp, Bpp; |
930 |
uint8 *data, *inverted; |
uint8 *data, *inverted; |
957 |
static void |
static void |
958 |
process_bmpcache(STREAM s) |
process_bmpcache(STREAM s) |
959 |
{ |
{ |
960 |
HBITMAP bitmap; |
RD_HBITMAP bitmap; |
961 |
uint16 cache_idx, size; |
uint16 cache_idx, size; |
962 |
uint8 cache_id, width, height, bpp, Bpp; |
uint8 cache_id, width, height, bpp, Bpp; |
963 |
uint8 *data, *bmpdata; |
uint8 *data, *bmpdata; |
1011 |
|
|
1012 |
/* Process a bitmap cache v2 order */ |
/* Process a bitmap cache v2 order */ |
1013 |
static void |
static void |
1014 |
process_bmpcache2(STREAM s, uint16 flags, BOOL compressed) |
process_bmpcache2(STREAM s, uint16 flags, RD_BOOL compressed) |
1015 |
{ |
{ |
1016 |
HBITMAP bitmap; |
RD_HBITMAP bitmap; |
1017 |
int y; |
int y; |
1018 |
uint8 cache_id, cache_idx_low, width, height, Bpp; |
uint8 cache_id, cache_idx_low, width, height, Bpp; |
1019 |
uint16 cache_idx, bufsize; |
uint16 cache_idx, bufsize; |
1095 |
{ |
{ |
1096 |
COLOURENTRY *entry; |
COLOURENTRY *entry; |
1097 |
COLOURMAP map; |
COLOURMAP map; |
1098 |
HCOLOURMAP hmap; |
RD_HCOLOURMAP hmap; |
1099 |
uint8 cache_id; |
uint8 cache_id; |
1100 |
int i; |
int i; |
1101 |
|
|
1127 |
static void |
static void |
1128 |
process_fontcache(STREAM s) |
process_fontcache(STREAM s) |
1129 |
{ |
{ |
1130 |
HGLYPH bitmap; |
RD_HGLYPH bitmap; |
1131 |
uint8 font, nglyphs; |
uint8 font, nglyphs; |
1132 |
uint16 character, offset, baseline, width, height; |
uint16 character, offset, baseline, width, height; |
1133 |
int i, datasize; |
int i, datasize; |
1154 |
} |
} |
1155 |
} |
} |
1156 |
|
|
1157 |
|
/* Process a brush cache order */ |
1158 |
|
static void |
1159 |
|
process_brushcache(STREAM s, uint16 flags) |
1160 |
|
{ |
1161 |
|
BRUSHDATA brush_data; |
1162 |
|
uint8 cache_idx, depth, width, height, size; |
1163 |
|
|
1164 |
|
in_uint8(s, cache_idx); |
1165 |
|
in_uint8(s, depth); |
1166 |
|
in_uint8(s, width); |
1167 |
|
in_uint8(s, height); |
1168 |
|
in_uint8s(s, 1); /* type, 0x80 = cached */ |
1169 |
|
in_uint8(s, size); |
1170 |
|
|
1171 |
|
DEBUG(("BRUSHCACHE(idx=%d,dp=%d,wd=%d,ht=%d,sz=%d)\n", cache_idx, depth, |
1172 |
|
width, height, size)); |
1173 |
|
|
1174 |
|
if ((depth == 1) && (width == 8) && (height == 8) && (size == 8)) |
1175 |
|
{ |
1176 |
|
in_uint8a(s, brush_data.pattern, sizeof(brush_data.pattern)); |
1177 |
|
cache_put_brush_data(cache_idx, &brush_data); |
1178 |
|
} |
1179 |
|
else |
1180 |
|
{ |
1181 |
|
warning("ignoring incompatible brush type. display may be incorrect\n"); |
1182 |
|
} |
1183 |
|
} |
1184 |
|
|
1185 |
/* Process a secondary order */ |
/* Process a secondary order */ |
1186 |
static void |
static void |
1187 |
process_secondary_order(STREAM s) |
process_secondary_order(STREAM s) |
1226 |
process_bmpcache2(s, flags, True); /* compressed */ |
process_bmpcache2(s, flags, True); /* compressed */ |
1227 |
break; |
break; |
1228 |
|
|
1229 |
|
case RDP_ORDER_BRUSHCACHE: |
1230 |
|
process_brushcache(s, flags); |
1231 |
|
break; |
1232 |
|
|
1233 |
default: |
default: |
1234 |
unimpl("secondary order %d\n", type); |
unimpl("secondary order %d\n", type); |
1235 |
} |
} |
1245 |
uint32 present; |
uint32 present; |
1246 |
uint8 order_flags; |
uint8 order_flags; |
1247 |
int size, processed = 0; |
int size, processed = 0; |
1248 |
BOOL delta; |
RD_BOOL delta; |
1249 |
|
|
1250 |
while (processed < num_orders) |
while (processed < num_orders) |
1251 |
{ |
{ |