VirtualBox

source: vbox/trunk/src/VBox/RDP/client-1.8.3/orders.c@ 55121

最後變更 在這個檔案從55121是 55121,由 vboxsync 提交於 10 年 前

rdesktop 1.8.3 unmodified

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 31.3 KB
 
1/* -*- c-basic-offset: 8 -*-
2 rdesktop: A Remote Desktop Protocol client.
3 RDP order processing
4 Copyright (C) Matthew Chapman <matthewc.unsw.edu.au> 1999-2008
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 3 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, see <http://www.gnu.org/licenses/>.
18*/
19
20#include "rdesktop.h"
21#include "orders.h"
22
23extern uint8 *g_next_packet;
24static RDP_ORDER_STATE g_order_state;
25extern RDP_VERSION g_rdp_version;
26
27/* Read field indicating which parameters are present */
28static void
29rdp_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) */
56static void
57rdp_in_coord(STREAM s, sint16 * coord, RD_BOOL delta)
58{
59 sint8 change;
60
61 if (delta)
62 {
63 in_uint8(s, change);
64 *coord += change;
65 }
66 else
67 {
68 in_uint16_le(s, *coord);
69 }
70}
71
72/* Parse a delta co-ordinate in polyline/polygon order form */
73static int
74parse_delta(uint8 * buffer, int *offset)
75{
76 int value = buffer[(*offset)++];
77 int two_byte = value & 0x80;
78
79 if (value & 0x40) /* sign bit */
80 value |= ~0x3f;
81 else
82 value &= 0x3f;
83
84 if (two_byte)
85 value = (value << 8) | buffer[(*offset)++];
86
87 return value;
88}
89
90/* Read a colour entry */
91static void
92rdp_in_colour(STREAM s, uint32 * colour)
93{
94 uint32 i;
95 in_uint8(s, i);
96 *colour = i;
97 in_uint8(s, i);
98 *colour |= i << 8;
99 in_uint8(s, i);
100 *colour |= i << 16;
101}
102
103/* Parse bounds information */
104static RD_BOOL
105rdp_parse_bounds(STREAM s, BOUNDS * bounds)
106{
107 uint8 present;
108
109 in_uint8(s, present);
110
111 if (present & 1)
112 rdp_in_coord(s, &bounds->left, False);
113 else if (present & 16)
114 rdp_in_coord(s, &bounds->left, True);
115
116 if (present & 2)
117 rdp_in_coord(s, &bounds->top, False);
118 else if (present & 32)
119 rdp_in_coord(s, &bounds->top, True);
120
121 if (present & 4)
122 rdp_in_coord(s, &bounds->right, False);
123 else if (present & 64)
124 rdp_in_coord(s, &bounds->right, True);
125
126 if (present & 8)
127 rdp_in_coord(s, &bounds->bottom, False);
128 else if (present & 128)
129 rdp_in_coord(s, &bounds->bottom, True);
130
131 return s_check(s);
132}
133
134/* Parse a pen */
135static RD_BOOL
136rdp_parse_pen(STREAM s, PEN * pen, uint32 present)
137{
138 if (present & 1)
139 in_uint8(s, pen->style);
140
141 if (present & 2)
142 in_uint8(s, pen->width);
143
144 if (present & 4)
145 rdp_in_colour(s, &pen->colour);
146
147 return s_check(s);
148}
149
150static void
151setup_brush(BRUSH * out_brush, BRUSH * in_brush)
152{
153 BRUSHDATA *brush_data;
154 uint8 cache_idx;
155 uint8 colour_code;
156
157 memcpy(out_brush, in_brush, sizeof(BRUSH));
158 if (out_brush->style & 0x80)
159 {
160 colour_code = out_brush->style & 0x0f;
161 cache_idx = out_brush->pattern[0];
162 brush_data = cache_get_brush_data(colour_code, cache_idx);
163 if ((brush_data == NULL) || (brush_data->data == NULL))
164 {
165 error("error getting brush data, style %x\n", out_brush->style);
166 out_brush->bd = NULL;
167 memset(out_brush->pattern, 0, 8);
168 }
169 else
170 {
171 out_brush->bd = brush_data;
172 }
173 out_brush->style = 3;
174 }
175}
176
177/* Parse a brush */
178static RD_BOOL
179rdp_parse_brush(STREAM s, BRUSH * brush, uint32 present)
180{
181 if (present & 1)
182 in_uint8(s, brush->xorigin);
183
184 if (present & 2)
185 in_uint8(s, brush->yorigin);
186
187 if (present & 4)
188 in_uint8(s, brush->style);
189
190 if (present & 8)
191 in_uint8(s, brush->pattern[0]);
192
193 if (present & 16)
194 in_uint8a(s, &brush->pattern[1], 7);
195
196 return s_check(s);
197}
198
199/* Process a destination blt order */
200static void
201process_destblt(STREAM s, DESTBLT_ORDER * os, uint32 present, RD_BOOL delta)
202{
203 if (present & 0x01)
204 rdp_in_coord(s, &os->x, delta);
205
206 if (present & 0x02)
207 rdp_in_coord(s, &os->y, delta);
208
209 if (present & 0x04)
210 rdp_in_coord(s, &os->cx, delta);
211
212 if (present & 0x08)
213 rdp_in_coord(s, &os->cy, delta);
214
215 if (present & 0x10)
216 in_uint8(s, os->opcode);
217
218 DEBUG(("DESTBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d)\n",
219 os->opcode, os->x, os->y, os->cx, os->cy));
220
221 ui_destblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy);
222}
223
224/* Process a pattern blt order */
225static void
226process_patblt(STREAM s, PATBLT_ORDER * os, uint32 present, RD_BOOL delta)
227{
228 BRUSH brush;
229
230 if (present & 0x0001)
231 rdp_in_coord(s, &os->x, delta);
232
233 if (present & 0x0002)
234 rdp_in_coord(s, &os->y, delta);
235
236 if (present & 0x0004)
237 rdp_in_coord(s, &os->cx, delta);
238
239 if (present & 0x0008)
240 rdp_in_coord(s, &os->cy, delta);
241
242 if (present & 0x0010)
243 in_uint8(s, os->opcode);
244
245 if (present & 0x0020)
246 rdp_in_colour(s, &os->bgcolour);
247
248 if (present & 0x0040)
249 rdp_in_colour(s, &os->fgcolour);
250
251 rdp_parse_brush(s, &os->brush, present >> 7);
252
253 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,
254 os->y, os->cx, os->cy, os->brush.style, os->bgcolour, os->fgcolour));
255
256 setup_brush(&brush, &os->brush);
257
258 ui_patblt(ROP2_P(os->opcode), os->x, os->y, os->cx, os->cy,
259 &brush, os->bgcolour, os->fgcolour);
260}
261
262/* Process a screen blt order */
263static void
264process_screenblt(STREAM s, SCREENBLT_ORDER * os, uint32 present, RD_BOOL delta)
265{
266 if (present & 0x0001)
267 rdp_in_coord(s, &os->x, delta);
268
269 if (present & 0x0002)
270 rdp_in_coord(s, &os->y, delta);
271
272 if (present & 0x0004)
273 rdp_in_coord(s, &os->cx, delta);
274
275 if (present & 0x0008)
276 rdp_in_coord(s, &os->cy, delta);
277
278 if (present & 0x0010)
279 in_uint8(s, os->opcode);
280
281 if (present & 0x0020)
282 rdp_in_coord(s, &os->srcx, delta);
283
284 if (present & 0x0040)
285 rdp_in_coord(s, &os->srcy, delta);
286
287 DEBUG(("SCREENBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,srcx=%d,srcy=%d)\n",
288 os->opcode, os->x, os->y, os->cx, os->cy, os->srcx, os->srcy));
289
290 ui_screenblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy, os->srcx, os->srcy);
291}
292
293/* Process a line order */
294static void
295process_line(STREAM s, LINE_ORDER * os, uint32 present, RD_BOOL delta)
296{
297 if (present & 0x0001)
298 in_uint16_le(s, os->mixmode);
299
300 if (present & 0x0002)
301 rdp_in_coord(s, &os->startx, delta);
302
303 if (present & 0x0004)
304 rdp_in_coord(s, &os->starty, delta);
305
306 if (present & 0x0008)
307 rdp_in_coord(s, &os->endx, delta);
308
309 if (present & 0x0010)
310 rdp_in_coord(s, &os->endy, delta);
311
312 if (present & 0x0020)
313 rdp_in_colour(s, &os->bgcolour);
314
315 if (present & 0x0040)
316 in_uint8(s, os->opcode);
317
318 rdp_parse_pen(s, &os->pen, present >> 7);
319
320 DEBUG(("LINE(op=0x%x,sx=%d,sy=%d,dx=%d,dy=%d,fg=0x%x)\n",
321 os->opcode, os->startx, os->starty, os->endx, os->endy, os->pen.colour));
322
323 if (os->opcode < 0x01 || os->opcode > 0x10)
324 {
325 error("bad ROP2 0x%x\n", os->opcode);
326 return;
327 }
328
329 ui_line(os->opcode - 1, os->startx, os->starty, os->endx, os->endy, &os->pen);
330}
331
332/* Process an opaque rectangle order */
333static void
334process_rect(STREAM s, RECT_ORDER * os, uint32 present, RD_BOOL delta)
335{
336 uint32 i;
337 if (present & 0x01)
338 rdp_in_coord(s, &os->x, delta);
339
340 if (present & 0x02)
341 rdp_in_coord(s, &os->y, delta);
342
343 if (present & 0x04)
344 rdp_in_coord(s, &os->cx, delta);
345
346 if (present & 0x08)
347 rdp_in_coord(s, &os->cy, delta);
348
349 if (present & 0x10)
350 {
351 in_uint8(s, i);
352 os->colour = (os->colour & 0xffffff00) | i;
353 }
354
355 if (present & 0x20)
356 {
357 in_uint8(s, i);
358 os->colour = (os->colour & 0xffff00ff) | (i << 8);
359 }
360
361 if (present & 0x40)
362 {
363 in_uint8(s, i);
364 os->colour = (os->colour & 0xff00ffff) | (i << 16);
365 }
366
367 DEBUG(("RECT(x=%d,y=%d,cx=%d,cy=%d,fg=0x%x)\n", os->x, os->y, os->cx, os->cy, os->colour));
368
369 ui_rect(os->x, os->y, os->cx, os->cy, os->colour);
370}
371
372/* Process a desktop save order */
373static void
374process_desksave(STREAM s, DESKSAVE_ORDER * os, uint32 present, RD_BOOL delta)
375{
376 int width, height;
377
378 if (present & 0x01)
379 in_uint32_le(s, os->offset);
380
381 if (present & 0x02)
382 rdp_in_coord(s, &os->left, delta);
383
384 if (present & 0x04)
385 rdp_in_coord(s, &os->top, delta);
386
387 if (present & 0x08)
388 rdp_in_coord(s, &os->right, delta);
389
390 if (present & 0x10)
391 rdp_in_coord(s, &os->bottom, delta);
392
393 if (present & 0x20)
394 in_uint8(s, os->action);
395
396 DEBUG(("DESKSAVE(l=%d,t=%d,r=%d,b=%d,off=%d,op=%d)\n",
397 os->left, os->top, os->right, os->bottom, os->offset, os->action));
398
399 width = os->right - os->left + 1;
400 height = os->bottom - os->top + 1;
401
402 if (os->action == 0)
403 ui_desktop_save(os->offset, os->left, os->top, width, height);
404 else
405 ui_desktop_restore(os->offset, os->left, os->top, width, height);
406}
407
408/* Process a memory blt order */
409static void
410process_memblt(STREAM s, MEMBLT_ORDER * os, uint32 present, RD_BOOL delta)
411{
412 RD_HBITMAP bitmap;
413
414 if (present & 0x0001)
415 {
416 in_uint8(s, os->cache_id);
417 in_uint8(s, os->colour_table);
418 }
419
420 if (present & 0x0002)
421 rdp_in_coord(s, &os->x, delta);
422
423 if (present & 0x0004)
424 rdp_in_coord(s, &os->y, delta);
425
426 if (present & 0x0008)
427 rdp_in_coord(s, &os->cx, delta);
428
429 if (present & 0x0010)
430 rdp_in_coord(s, &os->cy, delta);
431
432 if (present & 0x0020)
433 in_uint8(s, os->opcode);
434
435 if (present & 0x0040)
436 rdp_in_coord(s, &os->srcx, delta);
437
438 if (present & 0x0080)
439 rdp_in_coord(s, &os->srcy, delta);
440
441 if (present & 0x0100)
442 in_uint16_le(s, os->cache_idx);
443
444 DEBUG(("MEMBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,id=%d,idx=%d)\n",
445 os->opcode, os->x, os->y, os->cx, os->cy, os->cache_id, os->cache_idx));
446
447 bitmap = cache_get_bitmap(os->cache_id, os->cache_idx);
448 if (bitmap == NULL)
449 return;
450
451 ui_memblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy, bitmap, os->srcx, os->srcy);
452}
453
454/* Process a 3-way blt order */
455static void
456process_triblt(STREAM s, TRIBLT_ORDER * os, uint32 present, RD_BOOL delta)
457{
458 RD_HBITMAP bitmap;
459 BRUSH brush;
460
461 if (present & 0x000001)
462 {
463 in_uint8(s, os->cache_id);
464 in_uint8(s, os->colour_table);
465 }
466
467 if (present & 0x000002)
468 rdp_in_coord(s, &os->x, delta);
469
470 if (present & 0x000004)
471 rdp_in_coord(s, &os->y, delta);
472
473 if (present & 0x000008)
474 rdp_in_coord(s, &os->cx, delta);
475
476 if (present & 0x000010)
477 rdp_in_coord(s, &os->cy, delta);
478
479 if (present & 0x000020)
480 in_uint8(s, os->opcode);
481
482 if (present & 0x000040)
483 rdp_in_coord(s, &os->srcx, delta);
484
485 if (present & 0x000080)
486 rdp_in_coord(s, &os->srcy, delta);
487
488 if (present & 0x000100)
489 rdp_in_colour(s, &os->bgcolour);
490
491 if (present & 0x000200)
492 rdp_in_colour(s, &os->fgcolour);
493
494 rdp_parse_brush(s, &os->brush, present >> 10);
495
496 if (present & 0x008000)
497 in_uint16_le(s, os->cache_idx);
498
499 if (present & 0x010000)
500 in_uint16_le(s, os->unknown);
501
502 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",
503 os->opcode, os->x, os->y, os->cx, os->cy, os->cache_id, os->cache_idx,
504 os->brush.style, os->bgcolour, os->fgcolour));
505
506 bitmap = cache_get_bitmap(os->cache_id, os->cache_idx);
507 if (bitmap == NULL)
508 return;
509
510 setup_brush(&brush, &os->brush);
511
512 ui_triblt(os->opcode, os->x, os->y, os->cx, os->cy,
513 bitmap, os->srcx, os->srcy, &brush, os->bgcolour, os->fgcolour);
514}
515
516/* Process a polygon order */
517static void
518process_polygon(STREAM s, POLYGON_ORDER * os, uint32 present, RD_BOOL delta)
519{
520 int index, data, next;
521 uint8 flags = 0;
522 RD_POINT *points;
523
524 if (present & 0x01)
525 rdp_in_coord(s, &os->x, delta);
526
527 if (present & 0x02)
528 rdp_in_coord(s, &os->y, delta);
529
530 if (present & 0x04)
531 in_uint8(s, os->opcode);
532
533 if (present & 0x08)
534 in_uint8(s, os->fillmode);
535
536 if (present & 0x10)
537 rdp_in_colour(s, &os->fgcolour);
538
539 if (present & 0x20)
540 in_uint8(s, os->npoints);
541
542 if (present & 0x40)
543 {
544 in_uint8(s, os->datasize);
545 in_uint8a(s, os->data, os->datasize);
546 }
547
548 DEBUG(("POLYGON(x=%d,y=%d,op=0x%x,fm=%d,fg=0x%x,n=%d,sz=%d)\n",
549 os->x, os->y, os->opcode, os->fillmode, os->fgcolour, os->npoints, os->datasize));
550
551 DEBUG(("Data: "));
552
553 for (index = 0; index < os->datasize; index++)
554 DEBUG(("%02x ", os->data[index]));
555
556 DEBUG(("\n"));
557
558 if (os->opcode < 0x01 || os->opcode > 0x10)
559 {
560 error("bad ROP2 0x%x\n", os->opcode);
561 return;
562 }
563
564 points = (RD_POINT *) xmalloc((os->npoints + 1) * sizeof(RD_POINT));
565 memset(points, 0, (os->npoints + 1) * sizeof(RD_POINT));
566
567 points[0].x = os->x;
568 points[0].y = os->y;
569
570 index = 0;
571 data = ((os->npoints - 1) / 4) + 1;
572 for (next = 1; (next <= os->npoints) && (next < 256) && (data < os->datasize); next++)
573 {
574 if ((next - 1) % 4 == 0)
575 flags = os->data[index++];
576
577 if (~flags & 0x80)
578 points[next].x = parse_delta(os->data, &data);
579
580 if (~flags & 0x40)
581 points[next].y = parse_delta(os->data, &data);
582
583 flags <<= 2;
584 }
585
586 if (next - 1 == os->npoints)
587 ui_polygon(os->opcode - 1, os->fillmode, points, os->npoints + 1, NULL, 0,
588 os->fgcolour);
589 else
590 error("polygon parse error\n");
591
592 xfree(points);
593}
594
595/* Process a polygon2 order */
596static void
597process_polygon2(STREAM s, POLYGON2_ORDER * os, uint32 present, RD_BOOL delta)
598{
599 int index, data, next;
600 uint8 flags = 0;
601 RD_POINT *points;
602 BRUSH brush;
603
604 if (present & 0x0001)
605 rdp_in_coord(s, &os->x, delta);
606
607 if (present & 0x0002)
608 rdp_in_coord(s, &os->y, delta);
609
610 if (present & 0x0004)
611 in_uint8(s, os->opcode);
612
613 if (present & 0x0008)
614 in_uint8(s, os->fillmode);
615
616 if (present & 0x0010)
617 rdp_in_colour(s, &os->bgcolour);
618
619 if (present & 0x0020)
620 rdp_in_colour(s, &os->fgcolour);
621
622 rdp_parse_brush(s, &os->brush, present >> 6);
623
624 if (present & 0x0800)
625 in_uint8(s, os->npoints);
626
627 if (present & 0x1000)
628 {
629 in_uint8(s, os->datasize);
630 in_uint8a(s, os->data, os->datasize);
631 }
632
633 DEBUG(("POLYGON2(x=%d,y=%d,op=0x%x,fm=%d,bs=%d,bg=0x%x,fg=0x%x,n=%d,sz=%d)\n",
634 os->x, os->y, os->opcode, os->fillmode, os->brush.style, os->bgcolour, os->fgcolour,
635 os->npoints, os->datasize));
636
637 DEBUG(("Data: "));
638
639 for (index = 0; index < os->datasize; index++)
640 DEBUG(("%02x ", os->data[index]));
641
642 DEBUG(("\n"));
643
644 if (os->opcode < 0x01 || os->opcode > 0x10)
645 {
646 error("bad ROP2 0x%x\n", os->opcode);
647 return;
648 }
649
650 setup_brush(&brush, &os->brush);
651
652 points = (RD_POINT *) xmalloc((os->npoints + 1) * sizeof(RD_POINT));
653 memset(points, 0, (os->npoints + 1) * sizeof(RD_POINT));
654
655 points[0].x = os->x;
656 points[0].y = os->y;
657
658 index = 0;
659 data = ((os->npoints - 1) / 4) + 1;
660 for (next = 1; (next <= os->npoints) && (next < 256) && (data < os->datasize); next++)
661 {
662 if ((next - 1) % 4 == 0)
663 flags = os->data[index++];
664
665 if (~flags & 0x80)
666 points[next].x = parse_delta(os->data, &data);
667
668 if (~flags & 0x40)
669 points[next].y = parse_delta(os->data, &data);
670
671 flags <<= 2;
672 }
673
674 if (next - 1 == os->npoints)
675 ui_polygon(os->opcode - 1, os->fillmode, points, os->npoints + 1,
676 &brush, os->bgcolour, os->fgcolour);
677 else
678 error("polygon2 parse error\n");
679
680 xfree(points);
681}
682
683/* Process a polyline order */
684static void
685process_polyline(STREAM s, POLYLINE_ORDER * os, uint32 present, RD_BOOL delta)
686{
687 int index, next, data;
688 uint8 flags = 0;
689 PEN pen;
690 RD_POINT *points;
691
692 if (present & 0x01)
693 rdp_in_coord(s, &os->x, delta);
694
695 if (present & 0x02)
696 rdp_in_coord(s, &os->y, delta);
697
698 if (present & 0x04)
699 in_uint8(s, os->opcode);
700
701 if (present & 0x10)
702 rdp_in_colour(s, &os->fgcolour);
703
704 if (present & 0x20)
705 in_uint8(s, os->lines);
706
707 if (present & 0x40)
708 {
709 in_uint8(s, os->datasize);
710 in_uint8a(s, os->data, os->datasize);
711 }
712
713 DEBUG(("POLYLINE(x=%d,y=%d,op=0x%x,fg=0x%x,n=%d,sz=%d)\n",
714 os->x, os->y, os->opcode, os->fgcolour, os->lines, os->datasize));
715
716 DEBUG(("Data: "));
717
718 for (index = 0; index < os->datasize; index++)
719 DEBUG(("%02x ", os->data[index]));
720
721 DEBUG(("\n"));
722
723 if (os->opcode < 0x01 || os->opcode > 0x10)
724 {
725 error("bad ROP2 0x%x\n", os->opcode);
726 return;
727 }
728
729 points = (RD_POINT *) xmalloc((os->lines + 1) * sizeof(RD_POINT));
730 memset(points, 0, (os->lines + 1) * sizeof(RD_POINT));
731
732 points[0].x = os->x;
733 points[0].y = os->y;
734 pen.style = pen.width = 0;
735 pen.colour = os->fgcolour;
736
737 index = 0;
738 data = ((os->lines - 1) / 4) + 1;
739 for (next = 1; (next <= os->lines) && (data < os->datasize); next++)
740 {
741 if ((next - 1) % 4 == 0)
742 flags = os->data[index++];
743
744 if (~flags & 0x80)
745 points[next].x = parse_delta(os->data, &data);
746
747 if (~flags & 0x40)
748 points[next].y = parse_delta(os->data, &data);
749
750 flags <<= 2;
751 }
752
753 if (next - 1 == os->lines)
754 ui_polyline(os->opcode - 1, points, os->lines + 1, &pen);
755 else
756 error("polyline parse error\n");
757
758 xfree(points);
759}
760
761/* Process an ellipse order */
762static void
763process_ellipse(STREAM s, ELLIPSE_ORDER * os, uint32 present, RD_BOOL delta)
764{
765 if (present & 0x01)
766 rdp_in_coord(s, &os->left, delta);
767
768 if (present & 0x02)
769 rdp_in_coord(s, &os->top, delta);
770
771 if (present & 0x04)
772 rdp_in_coord(s, &os->right, delta);
773
774 if (present & 0x08)
775 rdp_in_coord(s, &os->bottom, delta);
776
777 if (present & 0x10)
778 in_uint8(s, os->opcode);
779
780 if (present & 0x20)
781 in_uint8(s, os->fillmode);
782
783 if (present & 0x40)
784 rdp_in_colour(s, &os->fgcolour);
785
786 DEBUG(("ELLIPSE(l=%d,t=%d,r=%d,b=%d,op=0x%x,fm=%d,fg=0x%x)\n", os->left, os->top,
787 os->right, os->bottom, os->opcode, os->fillmode, os->fgcolour));
788
789 ui_ellipse(os->opcode - 1, os->fillmode, os->left, os->top, os->right - os->left,
790 os->bottom - os->top, NULL, 0, os->fgcolour);
791}
792
793/* Process an ellipse2 order */
794static void
795process_ellipse2(STREAM s, ELLIPSE2_ORDER * os, uint32 present, RD_BOOL delta)
796{
797 BRUSH brush;
798
799 if (present & 0x0001)
800 rdp_in_coord(s, &os->left, delta);
801
802 if (present & 0x0002)
803 rdp_in_coord(s, &os->top, delta);
804
805 if (present & 0x0004)
806 rdp_in_coord(s, &os->right, delta);
807
808 if (present & 0x0008)
809 rdp_in_coord(s, &os->bottom, delta);
810
811 if (present & 0x0010)
812 in_uint8(s, os->opcode);
813
814 if (present & 0x0020)
815 in_uint8(s, os->fillmode);
816
817 if (present & 0x0040)
818 rdp_in_colour(s, &os->bgcolour);
819
820 if (present & 0x0080)
821 rdp_in_colour(s, &os->fgcolour);
822
823 rdp_parse_brush(s, &os->brush, present >> 8);
824
825 DEBUG(("ELLIPSE2(l=%d,t=%d,r=%d,b=%d,op=0x%x,fm=%d,bs=%d,bg=0x%x,fg=0x%x)\n",
826 os->left, os->top, os->right, os->bottom, os->opcode, os->fillmode, os->brush.style,
827 os->bgcolour, os->fgcolour));
828
829 setup_brush(&brush, &os->brush);
830
831 ui_ellipse(os->opcode - 1, os->fillmode, os->left, os->top, os->right - os->left,
832 os->bottom - os->top, &brush, os->bgcolour, os->fgcolour);
833}
834
835/* Process a text order */
836static void
837process_text2(STREAM s, TEXT2_ORDER * os, uint32 present, RD_BOOL delta)
838{
839 int i;
840 BRUSH brush;
841
842 if (present & 0x000001)
843 in_uint8(s, os->font);
844
845 if (present & 0x000002)
846 in_uint8(s, os->flags);
847
848 if (present & 0x000004)
849 in_uint8(s, os->opcode);
850
851 if (present & 0x000008)
852 in_uint8(s, os->mixmode);
853
854 if (present & 0x000010)
855 rdp_in_colour(s, &os->fgcolour);
856
857 if (present & 0x000020)
858 rdp_in_colour(s, &os->bgcolour);
859
860 if (present & 0x000040)
861 in_uint16_le(s, os->clipleft);
862
863 if (present & 0x000080)
864 in_uint16_le(s, os->cliptop);
865
866 if (present & 0x000100)
867 in_uint16_le(s, os->clipright);
868
869 if (present & 0x000200)
870 in_uint16_le(s, os->clipbottom);
871
872 if (present & 0x000400)
873 in_uint16_le(s, os->boxleft);
874
875 if (present & 0x000800)
876 in_uint16_le(s, os->boxtop);
877
878 if (present & 0x001000)
879 in_uint16_le(s, os->boxright);
880
881 if (present & 0x002000)
882 in_uint16_le(s, os->boxbottom);
883
884 rdp_parse_brush(s, &os->brush, present >> 14);
885
886 if (present & 0x080000)
887 in_uint16_le(s, os->x);
888
889 if (present & 0x100000)
890 in_uint16_le(s, os->y);
891
892 if (present & 0x200000)
893 {
894 in_uint8(s, os->length);
895 in_uint8a(s, os->text, os->length);
896 }
897
898 DEBUG(("TEXT2(x=%d,y=%d,cl=%d,ct=%d,cr=%d,cb=%d,bl=%d,bt=%d,br=%d,bb=%d,bs=%d,bg=0x%x,fg=0x%x,font=%d,fl=0x%x,op=0x%x,mix=%d,n=%d)\n", os->x, os->y, os->clipleft, os->cliptop, os->clipright, os->clipbottom, os->boxleft, os->boxtop, os->boxright, os->boxbottom, os->brush.style, os->bgcolour, os->fgcolour, os->font, os->flags, os->opcode, os->mixmode, os->length));
899
900 DEBUG(("Text: "));
901
902 for (i = 0; i < os->length; i++)
903 DEBUG(("%02x ", os->text[i]));
904
905 DEBUG(("\n"));
906
907 setup_brush(&brush, &os->brush);
908
909 ui_draw_text(os->font, os->flags, os->opcode - 1, os->mixmode, os->x, os->y,
910 os->clipleft, os->cliptop, os->clipright - os->clipleft,
911 os->clipbottom - os->cliptop, os->boxleft, os->boxtop,
912 os->boxright - os->boxleft, os->boxbottom - os->boxtop,
913 &brush, os->bgcolour, os->fgcolour, os->text, os->length);
914}
915
916/* Process a raw bitmap cache order */
917static void
918process_raw_bmpcache(STREAM s)
919{
920 RD_HBITMAP bitmap;
921 uint16 cache_idx, bufsize;
922 uint8 cache_id, width, height, bpp, Bpp;
923 uint8 *data, *inverted;
924 int y;
925
926 in_uint8(s, cache_id);
927 in_uint8s(s, 1); /* pad */
928 in_uint8(s, width);
929 in_uint8(s, height);
930 in_uint8(s, bpp);
931 Bpp = (bpp + 7) / 8;
932 in_uint16_le(s, bufsize);
933 in_uint16_le(s, cache_idx);
934 in_uint8p(s, data, bufsize);
935
936 DEBUG(("RAW_BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d)\n", width, height, cache_id, cache_idx));
937 inverted = (uint8 *) xmalloc(width * height * Bpp);
938 for (y = 0; y < height; y++)
939 {
940 memcpy(&inverted[(height - y - 1) * (width * Bpp)], &data[y * (width * Bpp)],
941 width * Bpp);
942 }
943
944 bitmap = ui_create_bitmap(width, height, inverted);
945 xfree(inverted);
946 cache_put_bitmap(cache_id, cache_idx, bitmap);
947}
948
949/* Process a bitmap cache order */
950static void
951process_bmpcache(STREAM s)
952{
953 RD_HBITMAP bitmap;
954 uint16 cache_idx, size;
955 uint8 cache_id, width, height, bpp, Bpp;
956 uint8 *data, *bmpdata;
957 uint16 bufsize, pad2, row_size, final_size;
958 uint8 pad1;
959
960 pad2 = row_size = final_size = 0xffff; /* Shut the compiler up */
961
962 in_uint8(s, cache_id);
963 in_uint8(s, pad1); /* pad */
964 in_uint8(s, width);
965 in_uint8(s, height);
966 in_uint8(s, bpp);
967 Bpp = (bpp + 7) / 8;
968 in_uint16_le(s, bufsize); /* bufsize */
969 in_uint16_le(s, cache_idx);
970
971 if (g_rdp_version >= RDP_V5)
972 {
973 size = bufsize;
974 }
975 else
976 {
977
978 /* Begin compressedBitmapData */
979 in_uint16_le(s, pad2); /* pad */
980 in_uint16_le(s, size);
981 /* in_uint8s(s, 4); *//* row_size, final_size */
982 in_uint16_le(s, row_size);
983 in_uint16_le(s, final_size);
984
985 }
986 in_uint8p(s, data, size);
987
988 DEBUG(("BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d,bpp=%d,size=%d,pad1=%d,bufsize=%d,pad2=%d,rs=%d,fs=%d)\n", width, height, cache_id, cache_idx, bpp, size, pad1, bufsize, pad2, row_size, final_size));
989
990 bmpdata = (uint8 *) xmalloc(width * height * Bpp);
991
992 if (bitmap_decompress(bmpdata, width, height, data, size, Bpp))
993 {
994 bitmap = ui_create_bitmap(width, height, bmpdata);
995 cache_put_bitmap(cache_id, cache_idx, bitmap);
996 }
997 else
998 {
999 DEBUG(("Failed to decompress bitmap data\n"));
1000 }
1001
1002 xfree(bmpdata);
1003}
1004
1005/* Process a bitmap cache v2 order */
1006static void
1007process_bmpcache2(STREAM s, uint16 flags, RD_BOOL compressed)
1008{
1009 RD_HBITMAP bitmap;
1010 int y;
1011 uint8 cache_id, cache_idx_low, width, height, Bpp;
1012 uint16 cache_idx, bufsize;
1013 uint8 *data, *bmpdata, *bitmap_id;
1014
1015 bitmap_id = NULL; /* prevent compiler warning */
1016 cache_id = flags & ID_MASK;
1017 Bpp = ((flags & MODE_MASK) >> MODE_SHIFT) - 2;
1018
1019 if (flags & PERSIST)
1020 {
1021 in_uint8p(s, bitmap_id, 8);
1022 }
1023
1024 if (flags & SQUARE)
1025 {
1026 in_uint8(s, width);
1027 height = width;
1028 }
1029 else
1030 {
1031 in_uint8(s, width);
1032 in_uint8(s, height);
1033 }
1034
1035 in_uint16_be(s, bufsize);
1036 bufsize &= BUFSIZE_MASK;
1037 in_uint8(s, cache_idx);
1038
1039 if (cache_idx & LONG_FORMAT)
1040 {
1041 in_uint8(s, cache_idx_low);
1042 cache_idx = ((cache_idx ^ LONG_FORMAT) << 8) + cache_idx_low;
1043 }
1044
1045 in_uint8p(s, data, bufsize);
1046
1047 DEBUG(("BMPCACHE2(compr=%d,flags=%x,cx=%d,cy=%d,id=%d,idx=%d,Bpp=%d,bs=%d)\n",
1048 compressed, flags, width, height, cache_id, cache_idx, Bpp, bufsize));
1049
1050 bmpdata = (uint8 *) xmalloc(width * height * Bpp);
1051
1052 if (compressed)
1053 {
1054 if (!bitmap_decompress(bmpdata, width, height, data, bufsize, Bpp))
1055 {
1056 DEBUG(("Failed to decompress bitmap data\n"));
1057 xfree(bmpdata);
1058 return;
1059 }
1060 }
1061 else
1062 {
1063 for (y = 0; y < height; y++)
1064 memcpy(&bmpdata[(height - y - 1) * (width * Bpp)],
1065 &data[y * (width * Bpp)], width * Bpp);
1066 }
1067
1068 bitmap = ui_create_bitmap(width, height, bmpdata);
1069
1070 if (bitmap)
1071 {
1072 cache_put_bitmap(cache_id, cache_idx, bitmap);
1073 if (flags & PERSIST)
1074 pstcache_save_bitmap(cache_id, cache_idx, bitmap_id, width, height,
1075 width * height * Bpp, bmpdata);
1076 }
1077 else
1078 {
1079 DEBUG(("process_bmpcache2: ui_create_bitmap failed\n"));
1080 }
1081
1082 xfree(bmpdata);
1083}
1084
1085/* Process a colourmap cache order */
1086static void
1087process_colcache(STREAM s)
1088{
1089 COLOURENTRY *entry;
1090 COLOURMAP map;
1091 RD_HCOLOURMAP hmap;
1092 uint8 cache_id;
1093 int i;
1094
1095 in_uint8(s, cache_id);
1096 in_uint16_le(s, map.ncolours);
1097
1098 map.colours = (COLOURENTRY *) xmalloc(sizeof(COLOURENTRY) * map.ncolours);
1099
1100 for (i = 0; i < map.ncolours; i++)
1101 {
1102 entry = &map.colours[i];
1103 in_uint8(s, entry->blue);
1104 in_uint8(s, entry->green);
1105 in_uint8(s, entry->red);
1106 in_uint8s(s, 1); /* pad */
1107 }
1108
1109 DEBUG(("COLCACHE(id=%d,n=%d)\n", cache_id, map.ncolours));
1110
1111 hmap = ui_create_colourmap(&map);
1112
1113 if (cache_id)
1114 ui_set_colourmap(hmap);
1115
1116 xfree(map.colours);
1117}
1118
1119/* Process a font cache order */
1120static void
1121process_fontcache(STREAM s)
1122{
1123 RD_HGLYPH bitmap;
1124 uint8 font, nglyphs;
1125 uint16 character, offset, baseline, width, height;
1126 int i, datasize;
1127 uint8 *data;
1128
1129 in_uint8(s, font);
1130 in_uint8(s, nglyphs);
1131
1132 DEBUG(("FONTCACHE(font=%d,n=%d)\n", font, nglyphs));
1133
1134 for (i = 0; i < nglyphs; i++)
1135 {
1136 in_uint16_le(s, character);
1137 in_uint16_le(s, offset);
1138 in_uint16_le(s, baseline);
1139 in_uint16_le(s, width);
1140 in_uint16_le(s, height);
1141
1142 datasize = (height * ((width + 7) / 8) + 3) & ~3;
1143 in_uint8p(s, data, datasize);
1144
1145 bitmap = ui_create_glyph(width, height, data);
1146 cache_put_font(font, character, offset, baseline, width, height, bitmap);
1147 }
1148}
1149
1150static void
1151process_compressed_8x8_brush_data(uint8 * in, uint8 * out, int Bpp)
1152{
1153 int x, y, pal_index, in_index, shift, do2, i;
1154 uint8 *pal;
1155
1156 in_index = 0;
1157 pal = in + 16;
1158 /* read it bottom up */
1159 for (y = 7; y >= 0; y--)
1160 {
1161 /* 2 bytes per row */
1162 x = 0;
1163 for (do2 = 0; do2 < 2; do2++)
1164 {
1165 /* 4 pixels per byte */
1166 shift = 6;
1167 while (shift >= 0)
1168 {
1169 pal_index = (in[in_index] >> shift) & 3;
1170 /* size of palette entries depends on Bpp */
1171 for (i = 0; i < Bpp; i++)
1172 {
1173 out[(y * 8 + x) * Bpp + i] = pal[pal_index * Bpp + i];
1174 }
1175 x++;
1176 shift -= 2;
1177 }
1178 in_index++;
1179 }
1180 }
1181}
1182
1183/* Process a brush cache order */
1184static void
1185process_brushcache(STREAM s, uint16 flags)
1186{
1187 BRUSHDATA brush_data;
1188 uint8 cache_idx, colour_code, width, height, size, type;
1189 uint8 *comp_brush;
1190 int index;
1191 int Bpp;
1192
1193 in_uint8(s, cache_idx);
1194 in_uint8(s, colour_code);
1195 in_uint8(s, width);
1196 in_uint8(s, height);
1197 in_uint8(s, type); /* type, 0x8x = cached */
1198 in_uint8(s, size);
1199
1200 DEBUG(("BRUSHCACHE(idx=%d,wd=%d,ht=%d,sz=%d)\n", cache_idx, width, height, size));
1201
1202 if ((width == 8) && (height == 8))
1203 {
1204 if (colour_code == 1)
1205 {
1206 brush_data.colour_code = 1;
1207 brush_data.data_size = 8;
1208 brush_data.data = xmalloc(8);
1209 if (size == 8)
1210 {
1211 /* read it bottom up */
1212 for (index = 7; index >= 0; index--)
1213 {
1214 in_uint8(s, brush_data.data[index]);
1215 }
1216 }
1217 else
1218 {
1219 warning("incompatible brush, colour_code %d size %d\n", colour_code,
1220 size);
1221 }
1222 cache_put_brush_data(1, cache_idx, &brush_data);
1223 }
1224 else if ((colour_code >= 3) && (colour_code <= 6))
1225 {
1226 Bpp = colour_code - 2;
1227 brush_data.colour_code = colour_code;
1228 brush_data.data_size = 8 * 8 * Bpp;
1229 brush_data.data = xmalloc(8 * 8 * Bpp);
1230 if (size == 16 + 4 * Bpp)
1231 {
1232 in_uint8p(s, comp_brush, 16 + 4 * Bpp);
1233 process_compressed_8x8_brush_data(comp_brush, brush_data.data, Bpp);
1234 }
1235 else
1236 {
1237 in_uint8a(s, brush_data.data, 8 * 8 * Bpp);
1238 }
1239 cache_put_brush_data(colour_code, cache_idx, &brush_data);
1240 }
1241 else
1242 {
1243 warning("incompatible brush, colour_code %d size %d\n", colour_code, size);
1244 }
1245 }
1246 else
1247 {
1248 warning("incompatible brush, width height %d %d\n", width, height);
1249 }
1250}
1251
1252/* Process a secondary order */
1253static void
1254process_secondary_order(STREAM s)
1255{
1256 /* The length isn't calculated correctly by the server.
1257 * For very compact orders the length becomes negative
1258 * so a signed integer must be used. */
1259 uint16 length;
1260 uint16 flags;
1261 uint8 type;
1262 uint8 *next_order;
1263
1264 in_uint16_le(s, length);
1265 in_uint16_le(s, flags); /* used by bmpcache2 */
1266 in_uint8(s, type);
1267
1268 next_order = s->p + (sint16) length + 7;
1269
1270 switch (type)
1271 {
1272 case RDP_ORDER_RAW_BMPCACHE:
1273 process_raw_bmpcache(s);
1274 break;
1275
1276 case RDP_ORDER_COLCACHE:
1277 process_colcache(s);
1278 break;
1279
1280 case RDP_ORDER_BMPCACHE:
1281 process_bmpcache(s);
1282 break;
1283
1284 case RDP_ORDER_FONTCACHE:
1285 process_fontcache(s);
1286 break;
1287
1288 case RDP_ORDER_RAW_BMPCACHE2:
1289 process_bmpcache2(s, flags, False); /* uncompressed */
1290 break;
1291
1292 case RDP_ORDER_BMPCACHE2:
1293 process_bmpcache2(s, flags, True); /* compressed */
1294 break;
1295
1296 case RDP_ORDER_BRUSHCACHE:
1297 process_brushcache(s, flags);
1298 break;
1299
1300 default:
1301 unimpl("secondary order %d\n", type);
1302 }
1303
1304 s->p = next_order;
1305}
1306
1307/* Process an order PDU */
1308void
1309process_orders(STREAM s, uint16 num_orders)
1310{
1311 RDP_ORDER_STATE *os = &g_order_state;
1312 uint32 present;
1313 uint8 order_flags;
1314 int size, processed = 0;
1315 RD_BOOL delta;
1316
1317 while (processed < num_orders)
1318 {
1319 in_uint8(s, order_flags);
1320
1321 if (!(order_flags & RDP_ORDER_STANDARD))
1322 {
1323 error("order parsing failed\n");
1324 break;
1325 }
1326
1327 if (order_flags & RDP_ORDER_SECONDARY)
1328 {
1329 process_secondary_order(s);
1330 }
1331 else
1332 {
1333 if (order_flags & RDP_ORDER_CHANGE)
1334 {
1335 in_uint8(s, os->order_type);
1336 }
1337
1338 switch (os->order_type)
1339 {
1340 case RDP_ORDER_TRIBLT:
1341 case RDP_ORDER_TEXT2:
1342 size = 3;
1343 break;
1344
1345 case RDP_ORDER_PATBLT:
1346 case RDP_ORDER_MEMBLT:
1347 case RDP_ORDER_LINE:
1348 case RDP_ORDER_POLYGON2:
1349 case RDP_ORDER_ELLIPSE2:
1350 size = 2;
1351 break;
1352
1353 default:
1354 size = 1;
1355 }
1356
1357 rdp_in_present(s, &present, order_flags, size);
1358
1359 if (order_flags & RDP_ORDER_BOUNDS)
1360 {
1361 if (!(order_flags & RDP_ORDER_LASTBOUNDS))
1362 rdp_parse_bounds(s, &os->bounds);
1363
1364 ui_set_clip(os->bounds.left,
1365 os->bounds.top,
1366 os->bounds.right -
1367 os->bounds.left + 1,
1368 os->bounds.bottom - os->bounds.top + 1);
1369 }
1370
1371 delta = order_flags & RDP_ORDER_DELTA;
1372
1373 switch (os->order_type)
1374 {
1375 case RDP_ORDER_DESTBLT:
1376 process_destblt(s, &os->destblt, present, delta);
1377 break;
1378
1379 case RDP_ORDER_PATBLT:
1380 process_patblt(s, &os->patblt, present, delta);
1381 break;
1382
1383 case RDP_ORDER_SCREENBLT:
1384 process_screenblt(s, &os->screenblt, present, delta);
1385 break;
1386
1387 case RDP_ORDER_LINE:
1388 process_line(s, &os->line, present, delta);
1389 break;
1390
1391 case RDP_ORDER_RECT:
1392 process_rect(s, &os->rect, present, delta);
1393 break;
1394
1395 case RDP_ORDER_DESKSAVE:
1396 process_desksave(s, &os->desksave, present, delta);
1397 break;
1398
1399 case RDP_ORDER_MEMBLT:
1400 process_memblt(s, &os->memblt, present, delta);
1401 break;
1402
1403 case RDP_ORDER_TRIBLT:
1404 process_triblt(s, &os->triblt, present, delta);
1405 break;
1406
1407 case RDP_ORDER_POLYGON:
1408 process_polygon(s, &os->polygon, present, delta);
1409 break;
1410
1411 case RDP_ORDER_POLYGON2:
1412 process_polygon2(s, &os->polygon2, present, delta);
1413 break;
1414
1415 case RDP_ORDER_POLYLINE:
1416 process_polyline(s, &os->polyline, present, delta);
1417 break;
1418
1419 case RDP_ORDER_ELLIPSE:
1420 process_ellipse(s, &os->ellipse, present, delta);
1421 break;
1422
1423 case RDP_ORDER_ELLIPSE2:
1424 process_ellipse2(s, &os->ellipse2, present, delta);
1425 break;
1426
1427 case RDP_ORDER_TEXT2:
1428 process_text2(s, &os->text2, present, delta);
1429 break;
1430
1431 default:
1432 unimpl("order %d\n", os->order_type);
1433 return;
1434 }
1435
1436 if (order_flags & RDP_ORDER_BOUNDS)
1437 ui_reset_clip();
1438 }
1439
1440 processed++;
1441 }
1442#if 0
1443 /* not true when RDP_COMPRESSION is set */
1444 if (s->p != g_next_packet)
1445 error("%d bytes remaining\n", (int) (g_next_packet - s->p));
1446#endif
1447
1448}
1449
1450/* Reset order state */
1451void
1452reset_order_state(void)
1453{
1454 memset(&g_order_state, 0, sizeof(g_order_state));
1455 g_order_state.order_type = RDP_ORDER_PATBLT;
1456}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette