1 |
/* |
2 |
rdesktop: A Remote Desktop Protocol client. |
3 |
RDP order processing |
4 |
Copyright (C) Matthew Chapman 1999-2000 |
5 |
|
6 |
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 |
8 |
the Free Software Foundation; either version 2 of the License, or |
9 |
(at your option) any later version. |
10 |
|
11 |
This program is distributed in the hope that it will be useful, |
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
GNU General Public License for more details. |
15 |
|
16 |
You should have received a copy of the GNU General Public License |
17 |
along with this program; if not, write to the Free Software |
18 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 |
*/ |
20 |
|
21 |
#include "rdesktop.h" |
22 |
#include "orders.h" |
23 |
|
24 |
extern uint8 *next_packet; |
25 |
static RDP_ORDER_STATE order_state; |
26 |
|
27 |
/* Read field indicating which parameters are present */ |
28 |
static void |
29 |
rdp_in_present(STREAM s, uint32 *present, uint8 flags, int size) |
30 |
{ |
31 |
uint8 bits; |
32 |
int i; |
33 |
|
34 |
if (flags & RDP_ORDER_SMALL) |
35 |
{ |
36 |
size--; |
37 |
} |
38 |
|
39 |
if (flags & RDP_ORDER_TINY) |
40 |
{ |
41 |
if (size < 2) |
42 |
size = 0; |
43 |
else |
44 |
size -= 2; |
45 |
} |
46 |
|
47 |
*present = 0; |
48 |
for (i = 0; i < size; i++) |
49 |
{ |
50 |
in_uint8(s, bits); |
51 |
*present |= bits << (i * 8); |
52 |
} |
53 |
} |
54 |
|
55 |
/* Read a co-ordinate (16-bit, or 8-bit delta) */ |
56 |
static void |
57 |
rdp_in_coord(STREAM s, uint16 *coord, BOOL delta) |
58 |
{ |
59 |
uint8 change; |
60 |
|
61 |
if (delta) |
62 |
{ |
63 |
in_uint8(s, change); |
64 |
*coord += (char) change; |
65 |
} |
66 |
else |
67 |
{ |
68 |
in_uint16_le(s, *coord); |
69 |
} |
70 |
} |
71 |
|
72 |
/* Read a colour entry */ |
73 |
static void |
74 |
rdp_in_colour(STREAM s, uint8 *colour) |
75 |
{ |
76 |
in_uint8(s, *colour); |
77 |
s->p += 2; |
78 |
} |
79 |
|
80 |
/* Parse bounds information */ |
81 |
static BOOL |
82 |
rdp_parse_bounds(STREAM s, BOUNDS *bounds) |
83 |
{ |
84 |
uint8 present; |
85 |
|
86 |
in_uint8(s, present); |
87 |
|
88 |
if (present & 1) |
89 |
rdp_in_coord(s, &bounds->left, False); |
90 |
else if (present & 16) |
91 |
rdp_in_coord(s, &bounds->left, True); |
92 |
|
93 |
if (present & 2) |
94 |
rdp_in_coord(s, &bounds->top, False); |
95 |
else if (present & 32) |
96 |
rdp_in_coord(s, &bounds->top, True); |
97 |
|
98 |
if (present & 4) |
99 |
rdp_in_coord(s, &bounds->right, False); |
100 |
else if (present & 64) |
101 |
rdp_in_coord(s, &bounds->right, True); |
102 |
|
103 |
if (present & 8) |
104 |
rdp_in_coord(s, &bounds->bottom, False); |
105 |
else if (present & 128) |
106 |
rdp_in_coord(s, &bounds->bottom, True); |
107 |
|
108 |
return s_check(s); |
109 |
} |
110 |
|
111 |
/* Parse a pen */ |
112 |
static BOOL |
113 |
rdp_parse_pen(STREAM s, PEN *pen, uint32 present) |
114 |
{ |
115 |
if (present & 1) |
116 |
in_uint8(s, pen->style); |
117 |
|
118 |
if (present & 2) |
119 |
in_uint8(s, pen->width); |
120 |
|
121 |
if (present & 4) |
122 |
rdp_in_colour(s, &pen->colour); |
123 |
|
124 |
return s_check(s); |
125 |
} |
126 |
|
127 |
/* Parse a brush */ |
128 |
static BOOL |
129 |
rdp_parse_brush(STREAM s, BRUSH *brush, uint32 present) |
130 |
{ |
131 |
if (present & 1) |
132 |
in_uint8(s, brush->xorigin); |
133 |
|
134 |
if (present & 2) |
135 |
in_uint8(s, brush->yorigin); |
136 |
|
137 |
if (present & 4) |
138 |
in_uint8(s, brush->style); |
139 |
|
140 |
if (present & 8) |
141 |
in_uint8(s, brush->pattern[0]); |
142 |
|
143 |
if (present & 16) |
144 |
in_uint8a(s, &brush->pattern[1], 7); |
145 |
|
146 |
return s_check(s); |
147 |
} |
148 |
|
149 |
/* Process a destination blt order */ |
150 |
static void |
151 |
process_destblt(STREAM s, DESTBLT_ORDER *os, uint32 present, BOOL delta) |
152 |
{ |
153 |
if (present & 0x01) |
154 |
rdp_in_coord(s, &os->x, delta); |
155 |
|
156 |
if (present & 0x02) |
157 |
rdp_in_coord(s, &os->y, delta); |
158 |
|
159 |
if (present & 0x04) |
160 |
rdp_in_coord(s, &os->cx, delta); |
161 |
|
162 |
if (present & 0x08) |
163 |
rdp_in_coord(s, &os->cy, delta); |
164 |
|
165 |
if (present & 0x10) |
166 |
in_uint8(s, os->opcode); |
167 |
|
168 |
DEBUG("DESTBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d)\n", |
169 |
os->opcode, os->x, os->y, os->cx, os->cy); |
170 |
|
171 |
ui_destblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy); |
172 |
} |
173 |
|
174 |
/* Process a pattern blt order */ |
175 |
static void |
176 |
process_patblt(STREAM s, PATBLT_ORDER *os, uint32 present, BOOL delta) |
177 |
{ |
178 |
if (present & 0x0001) |
179 |
rdp_in_coord(s, &os->x, delta); |
180 |
|
181 |
if (present & 0x0002) |
182 |
rdp_in_coord(s, &os->y, delta); |
183 |
|
184 |
if (present & 0x0004) |
185 |
rdp_in_coord(s, &os->cx, delta); |
186 |
|
187 |
if (present & 0x0008) |
188 |
rdp_in_coord(s, &os->cy, delta); |
189 |
|
190 |
if (present & 0x0010) |
191 |
in_uint8(s, os->opcode); |
192 |
|
193 |
if (present & 0x0020) |
194 |
rdp_in_colour(s, &os->bgcolour); |
195 |
|
196 |
if (present & 0x0040) |
197 |
rdp_in_colour(s, &os->fgcolour); |
198 |
|
199 |
rdp_parse_brush(s, &os->brush, present >> 7); |
200 |
|
201 |
DEBUG("PATBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,bs=%d,bg=0x%x,fg=0x%x)\n", |
202 |
os->opcode, os->x, os->y, os->cx, os->cy, |
203 |
os->brush.style, os->bgcolour, os->fgcolour); |
204 |
|
205 |
ui_patblt(ROP2_P(os->opcode), os->x, os->y, os->cx, os->cy, |
206 |
&os->brush, os->bgcolour, os->fgcolour); |
207 |
} |
208 |
|
209 |
/* Process a screen blt order */ |
210 |
static void |
211 |
process_screenblt(STREAM s, SCREENBLT_ORDER *os, uint32 present, BOOL delta) |
212 |
{ |
213 |
if (present & 0x0001) |
214 |
rdp_in_coord(s, &os->x, delta); |
215 |
|
216 |
if (present & 0x0002) |
217 |
rdp_in_coord(s, &os->y, delta); |
218 |
|
219 |
if (present & 0x0004) |
220 |
rdp_in_coord(s, &os->cx, delta); |
221 |
|
222 |
if (present & 0x0008) |
223 |
rdp_in_coord(s, &os->cy, delta); |
224 |
|
225 |
if (present & 0x0010) |
226 |
in_uint8(s, os->opcode); |
227 |
|
228 |
if (present & 0x0020) |
229 |
rdp_in_coord(s, &os->srcx, delta); |
230 |
|
231 |
if (present & 0x0040) |
232 |
rdp_in_coord(s, &os->srcy, delta); |
233 |
|
234 |
DEBUG("SCREENBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,srcx=%d,srcy=%d)\n", |
235 |
os->opcode, os->x, os->y, os->cx, os->cy, os->srcx, os->srcy); |
236 |
|
237 |
ui_screenblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy, |
238 |
os->srcx, os->srcy); |
239 |
} |
240 |
|
241 |
/* Process a line order */ |
242 |
static void |
243 |
process_line(STREAM s, LINE_ORDER *os, uint32 present, BOOL delta) |
244 |
{ |
245 |
if (present & 0x0001) |
246 |
in_uint16_le(s, os->mixmode); |
247 |
|
248 |
if (present & 0x0002) |
249 |
rdp_in_coord(s, &os->startx, delta); |
250 |
|
251 |
if (present & 0x0004) |
252 |
rdp_in_coord(s, &os->starty, delta); |
253 |
|
254 |
if (present & 0x0008) |
255 |
rdp_in_coord(s, &os->endx, delta); |
256 |
|
257 |
if (present & 0x0010) |
258 |
rdp_in_coord(s, &os->endy, delta); |
259 |
|
260 |
if (present & 0x0020) |
261 |
rdp_in_colour(s, &os->bgcolour); |
262 |
|
263 |
if (present & 0x0040) |
264 |
in_uint8(s, os->opcode); |
265 |
|
266 |
rdp_parse_pen(s, &os->pen, present >> 7); |
267 |
|
268 |
DEBUG("LINE(op=0x%x,sx=%d,sy=%d,dx=%d,dx=%d,fg=0x%x)\n", |
269 |
os->opcode, os->startx, os->starty, os->endx, os->endy, |
270 |
os->pen.colour); |
271 |
|
272 |
if (os->opcode < 0x01 || os->opcode > 0x10) |
273 |
{ |
274 |
ERROR("bad ROP2 0x%x\n", os->opcode); |
275 |
return; |
276 |
} |
277 |
|
278 |
ui_line(os->opcode - 1, os->startx, os->starty, |
279 |
os->endx, os->endy, &os->pen); |
280 |
} |
281 |
|
282 |
/* Process an opaque rectangle order */ |
283 |
static void |
284 |
process_rect(STREAM s, RECT_ORDER *os, uint32 present, BOOL delta) |
285 |
{ |
286 |
if (present & 0x01) |
287 |
rdp_in_coord(s, &os->x, delta); |
288 |
|
289 |
if (present & 0x02) |
290 |
rdp_in_coord(s, &os->y, delta); |
291 |
|
292 |
if (present & 0x04) |
293 |
rdp_in_coord(s, &os->cx, delta); |
294 |
|
295 |
if (present & 0x08) |
296 |
rdp_in_coord(s, &os->cy, delta); |
297 |
|
298 |
if (present & 0x10) |
299 |
in_uint8(s, os->colour); |
300 |
|
301 |
DEBUG("RECT(x=%d,y=%d,cx=%d,cy=%d,fg=0x%x)\n", |
302 |
os->x, os->y, os->cx, os->cy, os->colour); |
303 |
|
304 |
ui_rect(os->x, os->y, os->cx, os->cy, os->colour); |
305 |
} |
306 |
|
307 |
/* Process a desktop save order */ |
308 |
static void |
309 |
process_desksave(STREAM s, DESKSAVE_ORDER *os, uint32 present, BOOL delta) |
310 |
{ |
311 |
int width, height; |
312 |
|
313 |
if (present & 0x01) |
314 |
in_uint32_le(s, os->offset); |
315 |
|
316 |
if (present & 0x02) |
317 |
rdp_in_coord(s, &os->left, delta); |
318 |
|
319 |
if (present & 0x04) |
320 |
rdp_in_coord(s, &os->top, delta); |
321 |
|
322 |
if (present & 0x08) |
323 |
rdp_in_coord(s, &os->right, delta); |
324 |
|
325 |
if (present & 0x10) |
326 |
rdp_in_coord(s, &os->bottom, delta); |
327 |
|
328 |
if (present & 0x20) |
329 |
in_uint8(s, os->action); |
330 |
|
331 |
DEBUG("DESKSAVE(l=%d,t=%d,r=%d,b=%d,off=%d,op=%d)\n", |
332 |
os->left, os->top, os->right, os->bottom, os->offset, |
333 |
os->action); |
334 |
|
335 |
width = os->right - os->left + 1; |
336 |
height = os->bottom - os->top + 1; |
337 |
|
338 |
if (os->action == 0) |
339 |
ui_desktop_save(os->offset, os->left, os->top, width, height); |
340 |
else |
341 |
ui_desktop_restore(os->offset, os->left, os->top, width, |
342 |
height); |
343 |
} |
344 |
|
345 |
/* Process a memory blt order */ |
346 |
static void |
347 |
process_memblt(STREAM s, MEMBLT_ORDER *os, uint32 present, BOOL delta) |
348 |
{ |
349 |
HBITMAP bitmap; |
350 |
|
351 |
if (present & 0x0001) |
352 |
{ |
353 |
in_uint8(s, os->cache_id); |
354 |
in_uint8(s, os->colour_table); |
355 |
} |
356 |
|
357 |
if (present & 0x0002) |
358 |
rdp_in_coord(s, &os->x, delta); |
359 |
|
360 |
if (present & 0x0004) |
361 |
rdp_in_coord(s, &os->y, delta); |
362 |
|
363 |
if (present & 0x0008) |
364 |
rdp_in_coord(s, &os->cx, delta); |
365 |
|
366 |
if (present & 0x0010) |
367 |
rdp_in_coord(s, &os->cy, delta); |
368 |
|
369 |
if (present & 0x0020) |
370 |
in_uint8(s, os->opcode); |
371 |
|
372 |
if (present & 0x0040) |
373 |
rdp_in_coord(s, &os->srcx, delta); |
374 |
|
375 |
if (present & 0x0080) |
376 |
rdp_in_coord(s, &os->srcy, delta); |
377 |
|
378 |
if (present & 0x0100) |
379 |
in_uint16_le(s, os->cache_idx); |
380 |
|
381 |
DEBUG("MEMBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,id=%d,idx=%d)\n", |
382 |
os->opcode, os->x, os->y, os->cx, os->cy, os->cache_id, |
383 |
os->cache_idx); |
384 |
|
385 |
bitmap = cache_get_bitmap(os->cache_id, os->cache_idx); |
386 |
if (bitmap == NULL) |
387 |
return; |
388 |
|
389 |
ui_memblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy, |
390 |
bitmap, os->srcx, os->srcy); |
391 |
} |
392 |
|
393 |
/* Process a 3-way blt order */ |
394 |
static void |
395 |
process_triblt(STREAM s, TRIBLT_ORDER *os, uint32 present, BOOL delta) |
396 |
{ |
397 |
HBITMAP bitmap; |
398 |
|
399 |
if (present & 0x000001) |
400 |
{ |
401 |
in_uint8(s, os->cache_id); |
402 |
in_uint8(s, os->colour_table); |
403 |
} |
404 |
|
405 |
if (present & 0x000002) |
406 |
rdp_in_coord(s, &os->x, delta); |
407 |
|
408 |
if (present & 0x000004) |
409 |
rdp_in_coord(s, &os->y, delta); |
410 |
|
411 |
if (present & 0x000008) |
412 |
rdp_in_coord(s, &os->cx, delta); |
413 |
|
414 |
if (present & 0x000010) |
415 |
rdp_in_coord(s, &os->cy, delta); |
416 |
|
417 |
if (present & 0x000020) |
418 |
in_uint8(s, os->opcode); |
419 |
|
420 |
if (present & 0x000040) |
421 |
rdp_in_coord(s, &os->srcx, delta); |
422 |
|
423 |
if (present & 0x000080) |
424 |
rdp_in_coord(s, &os->srcy, delta); |
425 |
|
426 |
if (present & 0x000100) |
427 |
rdp_in_colour(s, &os->bgcolour); |
428 |
|
429 |
if (present & 0x000200) |
430 |
rdp_in_colour(s, &os->fgcolour); |
431 |
|
432 |
rdp_parse_brush(s, &os->brush, present >> 10); |
433 |
|
434 |
if (present & 0x008000) |
435 |
in_uint16_le(s, os->cache_idx); |
436 |
|
437 |
if (present & 0x010000) |
438 |
in_uint16_le(s, os->unknown); |
439 |
|
440 |
DEBUG |
441 |
("TRIBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,id=%d,idx=%d,bs=%d,bg=0x%x,fg=0x%x)\n", |
442 |
os->opcode, os->x, os->y, os->cx, os->cy, os->cache_id, |
443 |
os->cache_idx, os->brush.style, os->bgcolour, os->fgcolour); |
444 |
|
445 |
bitmap = cache_get_bitmap(os->cache_id, os->cache_idx); |
446 |
if (bitmap == NULL) |
447 |
return; |
448 |
|
449 |
ui_triblt(os->opcode, os->x, os->y, os->cx, os->cy, |
450 |
bitmap, os->srcx, os->srcy, |
451 |
&os->brush, os->bgcolour, os->fgcolour); |
452 |
} |
453 |
|
454 |
/* Parse a delta co-ordinate in polyline order form */ |
455 |
static int |
456 |
parse_delta(uint8 *buffer, int *offset) |
457 |
{ |
458 |
int value = buffer[(*offset)++]; |
459 |
int two_byte = value & 0x80; |
460 |
|
461 |
if (value & 0x40) /* sign bit */ |
462 |
value |= ~0x3f; |
463 |
else |
464 |
value &= 0x3f; |
465 |
|
466 |
if (two_byte) |
467 |
value = (value << 8) | buffer[(*offset)++]; |
468 |
|
469 |
return value; |
470 |
} |
471 |
|
472 |
/* Process a polyline order */ |
473 |
static void |
474 |
process_polyline(STREAM s, POLYLINE_ORDER *os, uint32 present, BOOL delta) |
475 |
{ |
476 |
int index, line, data; |
477 |
int x, y, xfrom, yfrom; |
478 |
uint8 flags = 0; |
479 |
PEN pen; |
480 |
|
481 |
if (present & 0x01) |
482 |
rdp_in_coord(s, &os->x, delta); |
483 |
|
484 |
if (present & 0x02) |
485 |
rdp_in_coord(s, &os->y, delta); |
486 |
|
487 |
if (present & 0x04) |
488 |
in_uint8(s, os->flags); |
489 |
|
490 |
if (present & 0x10) |
491 |
rdp_in_colour(s, &os->fgcolour); |
492 |
|
493 |
if (present & 0x20) |
494 |
in_uint8(s, os->lines); |
495 |
|
496 |
if (present & 0x40) |
497 |
{ |
498 |
in_uint8(s, os->datasize); |
499 |
in_uint8a(s, os->data, os->datasize); |
500 |
} |
501 |
|
502 |
DEBUG("POLYLINE(x=%d,y=%d,fl=0x%x,fg=0x%x,n=%d,sz=%d)\n", |
503 |
os->x, os->y, os->flags, os->fgcolour, os->lines, os->datasize); |
504 |
|
505 |
DEBUG("Data: "); |
506 |
|
507 |
for (index = 0; index < os->datasize; index++) |
508 |
DEBUG("%02x ", os->data[index]); |
509 |
|
510 |
DEBUG("\n"); |
511 |
|
512 |
x = os->x; |
513 |
y = os->y; |
514 |
pen.style = pen.width = 0; |
515 |
pen.colour = os->fgcolour; |
516 |
|
517 |
index = 0; |
518 |
data = ((os->lines - 1) / 4) + 1; |
519 |
for (line = 0; (line < os->lines) && (data < os->datasize); line++) |
520 |
{ |
521 |
xfrom = x; |
522 |
yfrom = y; |
523 |
|
524 |
if (line % 4 == 0) |
525 |
flags = os->data[index++]; |
526 |
|
527 |
if ((flags & 0xc0) == 0) |
528 |
flags |= 0xc0; /* none = both */ |
529 |
|
530 |
if (flags & 0x40) |
531 |
x += parse_delta(os->data, &data); |
532 |
|
533 |
if (flags & 0x80) |
534 |
y += parse_delta(os->data, &data); |
535 |
|
536 |
ui_line(ROP2_NXOR, xfrom, yfrom, x, y, &pen); |
537 |
|
538 |
flags <<= 2; |
539 |
} |
540 |
} |
541 |
|
542 |
/* Process a text order */ |
543 |
static void |
544 |
process_text2(STREAM s, TEXT2_ORDER *os, uint32 present, BOOL delta) |
545 |
{ |
546 |
DATABLOB *entry; |
547 |
int i; |
548 |
|
549 |
if (present & 0x000001) |
550 |
in_uint8(s, os->font); |
551 |
|
552 |
if (present & 0x000002) |
553 |
in_uint8(s, os->flags); |
554 |
|
555 |
if (present & 0x000004) |
556 |
in_uint8(s, os->unknown); |
557 |
|
558 |
if (present & 0x000008) |
559 |
in_uint8(s, os->mixmode); |
560 |
|
561 |
if (present & 0x000010) |
562 |
rdp_in_colour(s, &os->fgcolour); |
563 |
|
564 |
if (present & 0x000020) |
565 |
rdp_in_colour(s, &os->bgcolour); |
566 |
|
567 |
if (present & 0x000040) |
568 |
in_uint16_le(s, os->clipleft); |
569 |
|
570 |
if (present & 0x000080) |
571 |
in_uint16_le(s, os->cliptop); |
572 |
|
573 |
if (present & 0x000100) |
574 |
in_uint16_le(s, os->clipright); |
575 |
|
576 |
if (present & 0x000200) |
577 |
in_uint16_le(s, os->clipbottom); |
578 |
|
579 |
if (present & 0x000400) |
580 |
in_uint16_le(s, os->boxleft); |
581 |
|
582 |
if (present & 0x000800) |
583 |
in_uint16_le(s, os->boxtop); |
584 |
|
585 |
if (present & 0x001000) |
586 |
in_uint16_le(s, os->boxright); |
587 |
|
588 |
if (present & 0x002000) |
589 |
in_uint16_le(s, os->boxbottom); |
590 |
|
591 |
if (present & 0x080000) |
592 |
in_uint16_le(s, os->x); |
593 |
|
594 |
if (present & 0x100000) |
595 |
in_uint16_le(s, os->y); |
596 |
|
597 |
if (present & 0x200000) |
598 |
{ |
599 |
in_uint8(s, os->length); |
600 |
in_uint8a(s, os->text, os->length); |
601 |
} |
602 |
|
603 |
DEBUG |
604 |
("TEXT2(x=%d,y=%d,cl=%d,ct=%d,cr=%d,cb=%d,bl=%d,bt=%d,bb=%d,br=%d,fg=0x%x,bg=0x%x,font=%d,fl=0x%x,mix=%d,unk=0x%x,n=%d)\n", |
605 |
os->x, os->y, os->clipleft, os->cliptop, os->clipright, |
606 |
os->clipbottom, os->boxleft, os->boxtop, os->boxright, |
607 |
os->boxbottom, os->fgcolour, os->bgcolour, os->font, |
608 |
os->flags, os->mixmode, os->unknown, os->length); |
609 |
|
610 |
DEBUG("Text: "); |
611 |
|
612 |
for (i = 0; i < os->length; i++) |
613 |
DEBUG("%02x ", os->text[i]); |
614 |
|
615 |
DEBUG("\n"); |
616 |
|
617 |
/* Process special cache strings */ |
618 |
if ((os->length >= 2) && (os->text[0] == 0xfe)) |
619 |
{ |
620 |
entry = cache_get_text(os->text[1]); |
621 |
|
622 |
if (entry == NULL) |
623 |
return; |
624 |
|
625 |
memcpy(os->text, entry->data, entry->size); |
626 |
os->length = entry->size; |
627 |
} |
628 |
else if ((os->length >= 3) && (os->text[os->length - 3] == 0xff)) |
629 |
{ |
630 |
os->length -= 3; |
631 |
cache_put_text(os->text[os->length + 1], os->text, |
632 |
os->length); |
633 |
} |
634 |
|
635 |
ui_draw_text(os->font, os->flags, os->mixmode, os->x, os->y, |
636 |
os->clipleft, os->cliptop, |
637 |
os->clipright - os->clipleft, |
638 |
os->clipbottom - os->cliptop, |
639 |
os->boxleft, os->boxtop, |
640 |
os->boxright - os->boxleft, |
641 |
os->boxbottom - os->boxtop, |
642 |
os->bgcolour, os->fgcolour, os->text, os->length); |
643 |
} |
644 |
|
645 |
/* Process a raw bitmap cache order */ |
646 |
static void |
647 |
process_raw_bmpcache(STREAM s) |
648 |
{ |
649 |
HBITMAP bitmap; |
650 |
uint16 cache_idx, bufsize; |
651 |
uint8 cache_id, width, height, bpp; |
652 |
uint8 *data, *inverted; |
653 |
int y; |
654 |
|
655 |
in_uint8(s, cache_id); |
656 |
in_uint8s(s, 1); /* pad */ |
657 |
in_uint8(s, width); |
658 |
in_uint8(s, height); |
659 |
in_uint8(s, bpp); |
660 |
in_uint16_le(s, bufsize); |
661 |
in_uint16_le(s, cache_idx); |
662 |
in_uint8p(s, data, bufsize); |
663 |
|
664 |
DEBUG("RAW_BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d)\n", |
665 |
width, height, cache_id, cache_idx); |
666 |
inverted = xmalloc(width * height); |
667 |
for (y = 0; y < height; y++) |
668 |
{ |
669 |
memcpy(&inverted[(height - y - 1) * width], &data[y * width], |
670 |
width); |
671 |
} |
672 |
|
673 |
bitmap = ui_create_bitmap(width, height, inverted); |
674 |
xfree(inverted); |
675 |
cache_put_bitmap(cache_id, cache_idx, bitmap); |
676 |
} |
677 |
|
678 |
/* Process a bitmap cache order */ |
679 |
static void |
680 |
process_bmpcache(STREAM s) |
681 |
{ |
682 |
HBITMAP bitmap; |
683 |
uint16 cache_idx, size; |
684 |
uint8 cache_id, width, height, bpp; |
685 |
uint8 *data, *bmpdata; |
686 |
|
687 |
in_uint8(s, cache_id); |
688 |
in_uint8s(s, 1); /* pad */ |
689 |
in_uint8(s, width); |
690 |
in_uint8(s, height); |
691 |
in_uint8(s, bpp); |
692 |
in_uint8s(s, 2); /* bufsize */ |
693 |
in_uint16_le(s, cache_idx); |
694 |
in_uint8s(s, 2); /* pad */ |
695 |
in_uint16_le(s, size); |
696 |
in_uint8s(s, 4); /* row_size, final_size */ |
697 |
in_uint8p(s, data, size); |
698 |
|
699 |
DEBUG("BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d)\n", |
700 |
width, height, cache_id, cache_idx); |
701 |
|
702 |
bmpdata = xmalloc(width * height); |
703 |
|
704 |
if (bitmap_decompress(bmpdata, width, height, data, size)) |
705 |
{ |
706 |
bitmap = ui_create_bitmap(width, height, bmpdata); |
707 |
cache_put_bitmap(cache_id, cache_idx, bitmap); |
708 |
} |
709 |
|
710 |
xfree(bmpdata); |
711 |
} |
712 |
|
713 |
/* Process a colourmap cache order */ |
714 |
static void |
715 |
process_colcache(STREAM s) |
716 |
{ |
717 |
COLOURENTRY *entry; |
718 |
COLOURMAP map; |
719 |
HCOLOURMAP hmap; |
720 |
uint8 cache_id; |
721 |
int i; |
722 |
|
723 |
in_uint8(s, cache_id); |
724 |
in_uint16_le(s, map.ncolours); |
725 |
|
726 |
map.colours = xmalloc(3 * map.ncolours); |
727 |
|
728 |
for (i = 0; i < map.ncolours; i++) |
729 |
{ |
730 |
entry = &map.colours[i]; |
731 |
in_uint8(s, entry->blue); |
732 |
in_uint8(s, entry->green); |
733 |
in_uint8(s, entry->red); |
734 |
in_uint8s(s, 1); /* pad */ |
735 |
} |
736 |
|
737 |
DEBUG("COLCACHE(id=%d,n=%d)\n", cache_id, map.ncolours); |
738 |
|
739 |
hmap = ui_create_colourmap(&map); |
740 |
ui_set_colourmap(hmap); |
741 |
|
742 |
xfree(map.colours); |
743 |
} |
744 |
|
745 |
/* Process a font cache order */ |
746 |
static void |
747 |
process_fontcache(STREAM s) |
748 |
{ |
749 |
HGLYPH bitmap; |
750 |
uint8 font, nglyphs; |
751 |
uint16 character, offset, baseline, width, height; |
752 |
int i, datasize; |
753 |
uint8 *data; |
754 |
|
755 |
in_uint8(s, font); |
756 |
in_uint8(s, nglyphs); |
757 |
|
758 |
DEBUG("FONTCACHE(font=%d,n=%d)\n", font, nglyphs); |
759 |
|
760 |
for (i = 0; i < nglyphs; i++) |
761 |
{ |
762 |
in_uint16_le(s, character); |
763 |
in_uint16_le(s, offset); |
764 |
in_uint16_le(s, baseline); |
765 |
in_uint16_le(s, width); |
766 |
in_uint16_le(s, height); |
767 |
|
768 |
datasize = (height * ((width + 7) / 8) + 3) & ~3; |
769 |
in_uint8p(s, data, datasize); |
770 |
|
771 |
bitmap = ui_create_glyph(width, height, data); |
772 |
cache_put_font(font, character, offset, baseline, |
773 |
width, height, bitmap); |
774 |
} |
775 |
} |
776 |
|
777 |
/* Process a secondary order */ |
778 |
static void |
779 |
process_secondary_order(STREAM s) |
780 |
{ |
781 |
uint16 length; |
782 |
uint8 type; |
783 |
uint8 *next_order; |
784 |
|
785 |
in_uint16_le(s, length); |
786 |
in_uint8s(s, 2); /* flags */ |
787 |
in_uint8(s, type); |
788 |
|
789 |
next_order = s->p + length + 7; |
790 |
|
791 |
switch (type) |
792 |
{ |
793 |
case RDP_ORDER_RAW_BMPCACHE: |
794 |
process_raw_bmpcache(s); |
795 |
break; |
796 |
|
797 |
case RDP_ORDER_COLCACHE: |
798 |
process_colcache(s); |
799 |
break; |
800 |
|
801 |
case RDP_ORDER_BMPCACHE: |
802 |
process_bmpcache(s); |
803 |
break; |
804 |
|
805 |
case RDP_ORDER_FONTCACHE: |
806 |
process_fontcache(s); |
807 |
break; |
808 |
|
809 |
default: |
810 |
NOTIMP("secondary order %d\n", type); |
811 |
} |
812 |
|
813 |
s->p = next_order; |
814 |
} |
815 |
|
816 |
/* Process an order PDU */ |
817 |
void |
818 |
process_orders(STREAM s) |
819 |
{ |
820 |
RDP_ORDER_STATE *os = &order_state; |
821 |
uint32 present; |
822 |
uint16 num_orders; |
823 |
uint8 order_flags; |
824 |
int size, processed = 0; |
825 |
BOOL delta; |
826 |
|
827 |
in_uint8s(s, 2); /* pad */ |
828 |
in_uint16_le(s, num_orders); |
829 |
in_uint8s(s, 2); /* pad */ |
830 |
|
831 |
while (processed < num_orders) |
832 |
{ |
833 |
in_uint8(s, order_flags); |
834 |
|
835 |
if (!(order_flags & RDP_ORDER_STANDARD)) |
836 |
{ |
837 |
ERROR("order parsing failed\n"); |
838 |
break; |
839 |
} |
840 |
|
841 |
if (order_flags & RDP_ORDER_SECONDARY) |
842 |
{ |
843 |
process_secondary_order(s); |
844 |
} |
845 |
else |
846 |
{ |
847 |
if (order_flags & RDP_ORDER_CHANGE) |
848 |
{ |
849 |
in_uint8(s, os->order_type); |
850 |
} |
851 |
|
852 |
switch (os->order_type) |
853 |
{ |
854 |
case RDP_ORDER_TRIBLT: |
855 |
case RDP_ORDER_TEXT2: |
856 |
size = 3; |
857 |
break; |
858 |
|
859 |
case RDP_ORDER_PATBLT: |
860 |
case RDP_ORDER_MEMBLT: |
861 |
case RDP_ORDER_LINE: |
862 |
size = 2; |
863 |
break; |
864 |
|
865 |
default: |
866 |
size = 1; |
867 |
} |
868 |
|
869 |
rdp_in_present(s, &present, order_flags, size); |
870 |
|
871 |
if (order_flags & RDP_ORDER_BOUNDS) |
872 |
{ |
873 |
if (!(order_flags & RDP_ORDER_LASTBOUNDS)) |
874 |
rdp_parse_bounds(s, &os->bounds); |
875 |
|
876 |
ui_set_clip(os->bounds.left, |
877 |
os->bounds.top, |
878 |
os->bounds.right - |
879 |
os->bounds.left + 1, |
880 |
os->bounds.bottom - |
881 |
os->bounds.top + 1); |
882 |
} |
883 |
|
884 |
delta = order_flags & RDP_ORDER_DELTA; |
885 |
|
886 |
switch (os->order_type) |
887 |
{ |
888 |
case RDP_ORDER_DESTBLT: |
889 |
process_destblt(s, &os->destblt, |
890 |
present, delta); |
891 |
break; |
892 |
|
893 |
case RDP_ORDER_PATBLT: |
894 |
process_patblt(s, &os->patblt, |
895 |
present, delta); |
896 |
break; |
897 |
|
898 |
case RDP_ORDER_SCREENBLT: |
899 |
process_screenblt(s, &os->screenblt, |
900 |
present, delta); |
901 |
break; |
902 |
|
903 |
case RDP_ORDER_LINE: |
904 |
process_line(s, &os->line, |
905 |
present, delta); |
906 |
break; |
907 |
|
908 |
case RDP_ORDER_RECT: |
909 |
process_rect(s, &os->rect, |
910 |
present, delta); |
911 |
break; |
912 |
|
913 |
case RDP_ORDER_DESKSAVE: |
914 |
process_desksave(s, &os->desksave, |
915 |
present, delta); |
916 |
break; |
917 |
|
918 |
case RDP_ORDER_MEMBLT: |
919 |
process_memblt(s, &os->memblt, |
920 |
present, delta); |
921 |
break; |
922 |
|
923 |
case RDP_ORDER_TRIBLT: |
924 |
process_triblt(s, &os->triblt, |
925 |
present, delta); |
926 |
break; |
927 |
|
928 |
case RDP_ORDER_POLYLINE: |
929 |
process_polyline(s, &os->polyline, |
930 |
present, delta); |
931 |
break; |
932 |
|
933 |
case RDP_ORDER_TEXT2: |
934 |
process_text2(s, &os->text2, |
935 |
present, delta); |
936 |
break; |
937 |
|
938 |
default: |
939 |
NOTIMP("order %d\n", os->order_type); |
940 |
return; |
941 |
} |
942 |
|
943 |
if (order_flags & RDP_ORDER_BOUNDS) |
944 |
ui_reset_clip(); |
945 |
} |
946 |
|
947 |
processed++; |
948 |
} |
949 |
|
950 |
if (s->p != next_packet) |
951 |
WARN("%d bytes remaining\n", (int) (next_packet - s->p)); |
952 |
} |
953 |
|
954 |
/* Reset order state */ |
955 |
void |
956 |
reset_order_state() |
957 |
{ |
958 |
memset(&order_state, 0, sizeof(order_state)); |
959 |
order_state.order_type = RDP_ORDER_PATBLT; |
960 |
} |