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