1 |
matty |
10 |
/* |
2 |
|
|
rdesktop: A Remote Desktop Protocol client. |
3 |
|
|
RDP order processing |
4 |
matty |
30 |
Copyright (C) Matthew Chapman 1999-2001 |
5 |
matty |
10 |
|
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 |
matty |
28 |
extern uint8 *next_packet; |
25 |
matty |
10 |
static RDP_ORDER_STATE order_state; |
26 |
|
|
|
27 |
|
|
/* Read field indicating which parameters are present */ |
28 |
matty |
25 |
static void |
29 |
|
|
rdp_in_present(STREAM s, uint32 *present, uint8 flags, int size) |
30 |
matty |
10 |
{ |
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 |
matty |
25 |
static void |
57 |
|
|
rdp_in_coord(STREAM s, uint16 *coord, BOOL delta) |
58 |
matty |
10 |
{ |
59 |
|
|
uint8 change; |
60 |
|
|
|
61 |
|
|
if (delta) |
62 |
|
|
{ |
63 |
|
|
in_uint8(s, change); |
64 |
matty |
37 |
*coord += (signed char) change; |
65 |
matty |
10 |
} |
66 |
|
|
else |
67 |
|
|
{ |
68 |
|
|
in_uint16_le(s, *coord); |
69 |
|
|
} |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
/* Read a colour entry */ |
73 |
matty |
25 |
static void |
74 |
|
|
rdp_in_colour(STREAM s, uint8 *colour) |
75 |
matty |
10 |
{ |
76 |
|
|
in_uint8(s, *colour); |
77 |
|
|
s->p += 2; |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
/* Parse bounds information */ |
81 |
matty |
25 |
static BOOL |
82 |
|
|
rdp_parse_bounds(STREAM s, BOUNDS *bounds) |
83 |
matty |
10 |
{ |
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 |
matty |
25 |
static BOOL |
113 |
|
|
rdp_parse_pen(STREAM s, PEN *pen, uint32 present) |
114 |
matty |
10 |
{ |
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 |
matty |
25 |
static BOOL |
129 |
|
|
rdp_parse_brush(STREAM s, BRUSH *brush, uint32 present) |
130 |
matty |
10 |
{ |
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 |
matty |
25 |
static void |
151 |
|
|
process_destblt(STREAM s, DESTBLT_ORDER *os, uint32 present, BOOL delta) |
152 |
matty |
10 |
{ |
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 |
matty |
30 |
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 |
matty |
10 |
|
171 |
|
|
ui_destblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy); |
172 |
|
|
} |
173 |
|
|
|
174 |
|
|
/* Process a pattern blt order */ |
175 |
matty |
25 |
static void |
176 |
|
|
process_patblt(STREAM s, PATBLT_ORDER *os, uint32 present, BOOL delta) |
177 |
matty |
10 |
{ |
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 |
matty |
30 |
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 |
matty |
10 |
|
205 |
|
|
ui_patblt(ROP2_P(os->opcode), os->x, os->y, os->cx, os->cy, |
206 |
matty |
24 |
&os->brush, os->bgcolour, os->fgcolour); |
207 |
matty |
10 |
} |
208 |
|
|
|
209 |
|
|
/* Process a screen blt order */ |
210 |
matty |
25 |
static void |
211 |
|
|
process_screenblt(STREAM s, SCREENBLT_ORDER *os, uint32 present, BOOL delta) |
212 |
matty |
10 |
{ |
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 |
matty |
30 |
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 |
matty |
10 |
|
237 |
|
|
ui_screenblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy, |
238 |
matty |
24 |
os->srcx, os->srcy); |
239 |
matty |
10 |
} |
240 |
|
|
|
241 |
|
|
/* Process a line order */ |
242 |
matty |
25 |
static void |
243 |
|
|
process_line(STREAM s, LINE_ORDER *os, uint32 present, BOOL delta) |
244 |
matty |
10 |
{ |
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 |
matty |
30 |
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 |
matty |
10 |
|
272 |
|
|
if (os->opcode < 0x01 || os->opcode > 0x10) |
273 |
|
|
{ |
274 |
matty |
30 |
error("bad ROP2 0x%x\n", os->opcode); |
275 |
matty |
10 |
return; |
276 |
|
|
} |
277 |
|
|
|
278 |
matty |
24 |
ui_line(os->opcode - 1, os->startx, os->starty, |
279 |
|
|
os->endx, os->endy, &os->pen); |
280 |
matty |
10 |
} |
281 |
|
|
|
282 |
|
|
/* Process an opaque rectangle order */ |
283 |
matty |
25 |
static void |
284 |
|
|
process_rect(STREAM s, RECT_ORDER *os, uint32 present, BOOL delta) |
285 |
matty |
10 |
{ |
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 |
matty |
30 |
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 |
matty |
10 |
|
304 |
|
|
ui_rect(os->x, os->y, os->cx, os->cy, os->colour); |
305 |
|
|
} |
306 |
|
|
|
307 |
|
|
/* Process a desktop save order */ |
308 |
matty |
25 |
static void |
309 |
|
|
process_desksave(STREAM s, DESKSAVE_ORDER *os, uint32 present, BOOL delta) |
310 |
matty |
10 |
{ |
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 |
matty |
30 |
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 |
matty |
10 |
|
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 |
matty |
24 |
ui_desktop_restore(os->offset, os->left, os->top, width, |
342 |
|
|
height); |
343 |
matty |
10 |
} |
344 |
|
|
|
345 |
|
|
/* Process a memory blt order */ |
346 |
matty |
25 |
static void |
347 |
|
|
process_memblt(STREAM s, MEMBLT_ORDER *os, uint32 present, BOOL delta) |
348 |
matty |
10 |
{ |
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 |
matty |
30 |
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 |
matty |
10 |
|
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 |
matty |
24 |
bitmap, os->srcx, os->srcy); |
391 |
matty |
10 |
} |
392 |
|
|
|
393 |
|
|
/* Process a 3-way blt order */ |
394 |
matty |
25 |
static void |
395 |
|
|
process_triblt(STREAM s, TRIBLT_ORDER *os, uint32 present, BOOL delta) |
396 |
matty |
10 |
{ |
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 |
matty |
30 |
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", |
441 |
|
|
os->opcode, os->x, os->y, os->cx, os->cy, os->cache_id, |
442 |
|
|
os->cache_idx, os->brush.style, os->bgcolour, os->fgcolour)); |
443 |
matty |
10 |
|
444 |
|
|
bitmap = cache_get_bitmap(os->cache_id, os->cache_idx); |
445 |
|
|
if (bitmap == NULL) |
446 |
|
|
return; |
447 |
|
|
|
448 |
|
|
ui_triblt(os->opcode, os->x, os->y, os->cx, os->cy, |
449 |
matty |
24 |
bitmap, os->srcx, os->srcy, |
450 |
|
|
&os->brush, os->bgcolour, os->fgcolour); |
451 |
matty |
10 |
} |
452 |
|
|
|
453 |
matty |
15 |
/* Parse a delta co-ordinate in polyline order form */ |
454 |
matty |
25 |
static int |
455 |
|
|
parse_delta(uint8 *buffer, int *offset) |
456 |
matty |
15 |
{ |
457 |
|
|
int value = buffer[(*offset)++]; |
458 |
|
|
int two_byte = value & 0x80; |
459 |
|
|
|
460 |
matty |
24 |
if (value & 0x40) /* sign bit */ |
461 |
matty |
15 |
value |= ~0x3f; |
462 |
|
|
else |
463 |
|
|
value &= 0x3f; |
464 |
|
|
|
465 |
|
|
if (two_byte) |
466 |
|
|
value = (value << 8) | buffer[(*offset)++]; |
467 |
|
|
|
468 |
|
|
return value; |
469 |
|
|
} |
470 |
|
|
|
471 |
|
|
/* Process a polyline order */ |
472 |
matty |
25 |
static void |
473 |
|
|
process_polyline(STREAM s, POLYLINE_ORDER *os, uint32 present, BOOL delta) |
474 |
matty |
15 |
{ |
475 |
|
|
int index, line, data; |
476 |
|
|
int x, y, xfrom, yfrom; |
477 |
|
|
uint8 flags = 0; |
478 |
|
|
PEN pen; |
479 |
jsorg71 |
55 |
uint8 opcode; |
480 |
matty |
15 |
|
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 |
jsorg71 |
55 |
if (os->flags & 1) |
502 |
|
|
opcode = ROP2_COPY; |
503 |
|
|
else |
504 |
|
|
opcode = ROP2_NXOR; |
505 |
matty |
15 |
|
506 |
matty |
30 |
DEBUG(("POLYLINE(x=%d,y=%d,fl=0x%x,fg=0x%x,n=%d,sz=%d)\n", |
507 |
|
|
os->x, os->y, os->flags, os->fgcolour, os->lines, os->datasize)); |
508 |
matty |
15 |
|
509 |
matty |
30 |
DEBUG(("Data: ")); |
510 |
matty |
15 |
|
511 |
|
|
for (index = 0; index < os->datasize; index++) |
512 |
matty |
30 |
DEBUG(("%02x ", os->data[index])); |
513 |
matty |
15 |
|
514 |
matty |
30 |
DEBUG(("\n")); |
515 |
matty |
15 |
|
516 |
|
|
x = os->x; |
517 |
|
|
y = os->y; |
518 |
|
|
pen.style = pen.width = 0; |
519 |
|
|
pen.colour = os->fgcolour; |
520 |
|
|
|
521 |
|
|
index = 0; |
522 |
|
|
data = ((os->lines - 1) / 4) + 1; |
523 |
|
|
for (line = 0; (line < os->lines) && (data < os->datasize); line++) |
524 |
|
|
{ |
525 |
|
|
xfrom = x; |
526 |
|
|
yfrom = y; |
527 |
|
|
|
528 |
|
|
if (line % 4 == 0) |
529 |
|
|
flags = os->data[index++]; |
530 |
|
|
|
531 |
|
|
if ((flags & 0xc0) == 0) |
532 |
matty |
24 |
flags |= 0xc0; /* none = both */ |
533 |
matty |
15 |
|
534 |
|
|
if (flags & 0x40) |
535 |
|
|
x += parse_delta(os->data, &data); |
536 |
|
|
|
537 |
|
|
if (flags & 0x80) |
538 |
|
|
y += parse_delta(os->data, &data); |
539 |
|
|
|
540 |
jsorg71 |
55 |
ui_line(opcode, xfrom, yfrom, x, y, &pen); |
541 |
matty |
15 |
|
542 |
|
|
flags <<= 2; |
543 |
|
|
} |
544 |
|
|
} |
545 |
|
|
|
546 |
matty |
10 |
/* Process a text order */ |
547 |
matty |
25 |
static void |
548 |
|
|
process_text2(STREAM s, TEXT2_ORDER *os, uint32 present, BOOL delta) |
549 |
matty |
10 |
{ |
550 |
|
|
int i; |
551 |
|
|
|
552 |
|
|
if (present & 0x000001) |
553 |
|
|
in_uint8(s, os->font); |
554 |
|
|
|
555 |
|
|
if (present & 0x000002) |
556 |
|
|
in_uint8(s, os->flags); |
557 |
|
|
|
558 |
|
|
if (present & 0x000004) |
559 |
|
|
in_uint8(s, os->unknown); |
560 |
|
|
|
561 |
|
|
if (present & 0x000008) |
562 |
|
|
in_uint8(s, os->mixmode); |
563 |
|
|
|
564 |
|
|
if (present & 0x000010) |
565 |
|
|
rdp_in_colour(s, &os->fgcolour); |
566 |
|
|
|
567 |
|
|
if (present & 0x000020) |
568 |
|
|
rdp_in_colour(s, &os->bgcolour); |
569 |
|
|
|
570 |
|
|
if (present & 0x000040) |
571 |
|
|
in_uint16_le(s, os->clipleft); |
572 |
|
|
|
573 |
|
|
if (present & 0x000080) |
574 |
|
|
in_uint16_le(s, os->cliptop); |
575 |
|
|
|
576 |
|
|
if (present & 0x000100) |
577 |
|
|
in_uint16_le(s, os->clipright); |
578 |
|
|
|
579 |
|
|
if (present & 0x000200) |
580 |
|
|
in_uint16_le(s, os->clipbottom); |
581 |
|
|
|
582 |
|
|
if (present & 0x000400) |
583 |
|
|
in_uint16_le(s, os->boxleft); |
584 |
|
|
|
585 |
|
|
if (present & 0x000800) |
586 |
|
|
in_uint16_le(s, os->boxtop); |
587 |
|
|
|
588 |
|
|
if (present & 0x001000) |
589 |
|
|
in_uint16_le(s, os->boxright); |
590 |
|
|
|
591 |
|
|
if (present & 0x002000) |
592 |
|
|
in_uint16_le(s, os->boxbottom); |
593 |
|
|
|
594 |
|
|
if (present & 0x080000) |
595 |
|
|
in_uint16_le(s, os->x); |
596 |
|
|
|
597 |
|
|
if (present & 0x100000) |
598 |
|
|
in_uint16_le(s, os->y); |
599 |
|
|
|
600 |
|
|
if (present & 0x200000) |
601 |
|
|
{ |
602 |
|
|
in_uint8(s, os->length); |
603 |
|
|
in_uint8a(s, os->text, os->length); |
604 |
|
|
} |
605 |
|
|
|
606 |
matty |
30 |
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", |
607 |
|
|
os->x, os->y, os->clipleft, os->cliptop, os->clipright, |
608 |
|
|
os->clipbottom, os->boxleft, os->boxtop, os->boxright, |
609 |
|
|
os->boxbottom, os->fgcolour, os->bgcolour, os->font, |
610 |
|
|
os->flags, os->mixmode, os->unknown, os->length)); |
611 |
matty |
10 |
|
612 |
matty |
30 |
DEBUG(("Text: ")); |
613 |
matty |
10 |
|
614 |
|
|
for (i = 0; i < os->length; i++) |
615 |
matty |
30 |
DEBUG(("%02x ", os->text[i])); |
616 |
matty |
10 |
|
617 |
matty |
30 |
DEBUG(("\n")); |
618 |
matty |
10 |
|
619 |
matty |
17 |
ui_draw_text(os->font, os->flags, os->mixmode, os->x, os->y, |
620 |
matty |
24 |
os->clipleft, os->cliptop, |
621 |
|
|
os->clipright - os->clipleft, |
622 |
|
|
os->clipbottom - os->cliptop, |
623 |
|
|
os->boxleft, os->boxtop, |
624 |
|
|
os->boxright - os->boxleft, |
625 |
|
|
os->boxbottom - os->boxtop, |
626 |
|
|
os->bgcolour, os->fgcolour, os->text, os->length); |
627 |
matty |
10 |
} |
628 |
|
|
|
629 |
|
|
/* Process a raw bitmap cache order */ |
630 |
matty |
25 |
static void |
631 |
|
|
process_raw_bmpcache(STREAM s) |
632 |
matty |
10 |
{ |
633 |
|
|
HBITMAP bitmap; |
634 |
|
|
uint16 cache_idx, bufsize; |
635 |
|
|
uint8 cache_id, width, height, bpp; |
636 |
matty |
28 |
uint8 *data, *inverted; |
637 |
|
|
int y; |
638 |
matty |
10 |
|
639 |
|
|
in_uint8(s, cache_id); |
640 |
matty |
24 |
in_uint8s(s, 1); /* pad */ |
641 |
matty |
10 |
in_uint8(s, width); |
642 |
|
|
in_uint8(s, height); |
643 |
|
|
in_uint8(s, bpp); |
644 |
|
|
in_uint16_le(s, bufsize); |
645 |
|
|
in_uint16_le(s, cache_idx); |
646 |
|
|
in_uint8p(s, data, bufsize); |
647 |
|
|
|
648 |
matty |
30 |
DEBUG(("RAW_BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d)\n", |
649 |
|
|
width, height, cache_id, cache_idx)); |
650 |
matty |
28 |
inverted = xmalloc(width * height); |
651 |
|
|
for (y = 0; y < height; y++) |
652 |
|
|
{ |
653 |
|
|
memcpy(&inverted[(height - y - 1) * width], &data[y * width], |
654 |
|
|
width); |
655 |
|
|
} |
656 |
matty |
10 |
|
657 |
matty |
28 |
bitmap = ui_create_bitmap(width, height, inverted); |
658 |
|
|
xfree(inverted); |
659 |
matty |
10 |
cache_put_bitmap(cache_id, cache_idx, bitmap); |
660 |
|
|
} |
661 |
|
|
|
662 |
|
|
/* Process a bitmap cache order */ |
663 |
matty |
25 |
static void |
664 |
|
|
process_bmpcache(STREAM s) |
665 |
matty |
10 |
{ |
666 |
|
|
HBITMAP bitmap; |
667 |
|
|
uint16 cache_idx, size; |
668 |
|
|
uint8 cache_id, width, height, bpp; |
669 |
|
|
uint8 *data, *bmpdata; |
670 |
|
|
|
671 |
|
|
in_uint8(s, cache_id); |
672 |
matty |
24 |
in_uint8s(s, 1); /* pad */ |
673 |
matty |
10 |
in_uint8(s, width); |
674 |
|
|
in_uint8(s, height); |
675 |
|
|
in_uint8(s, bpp); |
676 |
matty |
24 |
in_uint8s(s, 2); /* bufsize */ |
677 |
matty |
10 |
in_uint16_le(s, cache_idx); |
678 |
matty |
24 |
in_uint8s(s, 2); /* pad */ |
679 |
matty |
10 |
in_uint16_le(s, size); |
680 |
matty |
24 |
in_uint8s(s, 4); /* row_size, final_size */ |
681 |
matty |
10 |
in_uint8p(s, data, size); |
682 |
|
|
|
683 |
matty |
30 |
DEBUG(("BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d)\n", |
684 |
|
|
width, height, cache_id, cache_idx)); |
685 |
matty |
10 |
|
686 |
|
|
bmpdata = xmalloc(width * height); |
687 |
|
|
|
688 |
|
|
if (bitmap_decompress(bmpdata, width, height, data, size)) |
689 |
|
|
{ |
690 |
|
|
bitmap = ui_create_bitmap(width, height, bmpdata); |
691 |
|
|
cache_put_bitmap(cache_id, cache_idx, bitmap); |
692 |
|
|
} |
693 |
|
|
|
694 |
|
|
xfree(bmpdata); |
695 |
|
|
} |
696 |
|
|
|
697 |
|
|
/* Process a colourmap cache order */ |
698 |
matty |
25 |
static void |
699 |
|
|
process_colcache(STREAM s) |
700 |
matty |
10 |
{ |
701 |
|
|
COLOURENTRY *entry; |
702 |
|
|
COLOURMAP map; |
703 |
|
|
HCOLOURMAP hmap; |
704 |
|
|
uint8 cache_id; |
705 |
|
|
int i; |
706 |
|
|
|
707 |
|
|
in_uint8(s, cache_id); |
708 |
|
|
in_uint16_le(s, map.ncolours); |
709 |
|
|
|
710 |
|
|
map.colours = xmalloc(3 * map.ncolours); |
711 |
|
|
|
712 |
|
|
for (i = 0; i < map.ncolours; i++) |
713 |
|
|
{ |
714 |
|
|
entry = &map.colours[i]; |
715 |
|
|
in_uint8(s, entry->blue); |
716 |
|
|
in_uint8(s, entry->green); |
717 |
|
|
in_uint8(s, entry->red); |
718 |
matty |
24 |
in_uint8s(s, 1); /* pad */ |
719 |
matty |
10 |
} |
720 |
|
|
|
721 |
matty |
30 |
DEBUG(("COLCACHE(id=%d,n=%d)\n", cache_id, map.ncolours)); |
722 |
matty |
10 |
|
723 |
|
|
hmap = ui_create_colourmap(&map); |
724 |
|
|
ui_set_colourmap(hmap); |
725 |
|
|
|
726 |
|
|
xfree(map.colours); |
727 |
|
|
} |
728 |
|
|
|
729 |
|
|
/* Process a font cache order */ |
730 |
matty |
25 |
static void |
731 |
|
|
process_fontcache(STREAM s) |
732 |
matty |
10 |
{ |
733 |
|
|
HGLYPH bitmap; |
734 |
|
|
uint8 font, nglyphs; |
735 |
matty |
20 |
uint16 character, offset, baseline, width, height; |
736 |
matty |
24 |
int i, datasize; |
737 |
|
|
uint8 *data; |
738 |
matty |
10 |
|
739 |
|
|
in_uint8(s, font); |
740 |
|
|
in_uint8(s, nglyphs); |
741 |
|
|
|
742 |
matty |
30 |
DEBUG(("FONTCACHE(font=%d,n=%d)\n", font, nglyphs)); |
743 |
matty |
10 |
|
744 |
|
|
for (i = 0; i < nglyphs; i++) |
745 |
|
|
{ |
746 |
|
|
in_uint16_le(s, character); |
747 |
matty |
20 |
in_uint16_le(s, offset); |
748 |
matty |
10 |
in_uint16_le(s, baseline); |
749 |
|
|
in_uint16_le(s, width); |
750 |
|
|
in_uint16_le(s, height); |
751 |
|
|
|
752 |
|
|
datasize = (height * ((width + 7) / 8) + 3) & ~3; |
753 |
|
|
in_uint8p(s, data, datasize); |
754 |
|
|
|
755 |
matty |
23 |
bitmap = ui_create_glyph(width, height, data); |
756 |
matty |
20 |
cache_put_font(font, character, offset, baseline, |
757 |
matty |
24 |
width, height, bitmap); |
758 |
matty |
10 |
} |
759 |
|
|
} |
760 |
|
|
|
761 |
|
|
/* Process a secondary order */ |
762 |
matty |
25 |
static void |
763 |
|
|
process_secondary_order(STREAM s) |
764 |
matty |
10 |
{ |
765 |
|
|
uint16 length; |
766 |
|
|
uint8 type; |
767 |
|
|
uint8 *next_order; |
768 |
|
|
|
769 |
|
|
in_uint16_le(s, length); |
770 |
matty |
24 |
in_uint8s(s, 2); /* flags */ |
771 |
matty |
10 |
in_uint8(s, type); |
772 |
|
|
|
773 |
|
|
next_order = s->p + length + 7; |
774 |
|
|
|
775 |
|
|
switch (type) |
776 |
|
|
{ |
777 |
|
|
case RDP_ORDER_RAW_BMPCACHE: |
778 |
|
|
process_raw_bmpcache(s); |
779 |
|
|
break; |
780 |
|
|
|
781 |
|
|
case RDP_ORDER_COLCACHE: |
782 |
|
|
process_colcache(s); |
783 |
|
|
break; |
784 |
|
|
|
785 |
|
|
case RDP_ORDER_BMPCACHE: |
786 |
|
|
process_bmpcache(s); |
787 |
|
|
break; |
788 |
|
|
|
789 |
|
|
case RDP_ORDER_FONTCACHE: |
790 |
|
|
process_fontcache(s); |
791 |
|
|
break; |
792 |
|
|
|
793 |
|
|
default: |
794 |
matty |
30 |
unimpl("secondary order %d\n", type); |
795 |
matty |
10 |
} |
796 |
|
|
|
797 |
|
|
s->p = next_order; |
798 |
|
|
} |
799 |
|
|
|
800 |
|
|
/* Process an order PDU */ |
801 |
matty |
25 |
void |
802 |
|
|
process_orders(STREAM s) |
803 |
matty |
10 |
{ |
804 |
|
|
RDP_ORDER_STATE *os = &order_state; |
805 |
|
|
uint32 present; |
806 |
|
|
uint16 num_orders; |
807 |
|
|
uint8 order_flags; |
808 |
|
|
int size, processed = 0; |
809 |
|
|
BOOL delta; |
810 |
|
|
|
811 |
matty |
24 |
in_uint8s(s, 2); /* pad */ |
812 |
matty |
10 |
in_uint16_le(s, num_orders); |
813 |
matty |
24 |
in_uint8s(s, 2); /* pad */ |
814 |
matty |
10 |
|
815 |
|
|
while (processed < num_orders) |
816 |
|
|
{ |
817 |
|
|
in_uint8(s, order_flags); |
818 |
|
|
|
819 |
|
|
if (!(order_flags & RDP_ORDER_STANDARD)) |
820 |
|
|
{ |
821 |
matty |
30 |
error("order parsing failed\n"); |
822 |
matty |
10 |
break; |
823 |
|
|
} |
824 |
|
|
|
825 |
|
|
if (order_flags & RDP_ORDER_SECONDARY) |
826 |
|
|
{ |
827 |
|
|
process_secondary_order(s); |
828 |
|
|
} |
829 |
|
|
else |
830 |
|
|
{ |
831 |
|
|
if (order_flags & RDP_ORDER_CHANGE) |
832 |
|
|
{ |
833 |
|
|
in_uint8(s, os->order_type); |
834 |
|
|
} |
835 |
|
|
|
836 |
|
|
switch (os->order_type) |
837 |
|
|
{ |
838 |
|
|
case RDP_ORDER_TRIBLT: |
839 |
|
|
case RDP_ORDER_TEXT2: |
840 |
|
|
size = 3; |
841 |
|
|
break; |
842 |
|
|
|
843 |
|
|
case RDP_ORDER_PATBLT: |
844 |
|
|
case RDP_ORDER_MEMBLT: |
845 |
|
|
case RDP_ORDER_LINE: |
846 |
|
|
size = 2; |
847 |
|
|
break; |
848 |
|
|
|
849 |
|
|
default: |
850 |
|
|
size = 1; |
851 |
|
|
} |
852 |
|
|
|
853 |
|
|
rdp_in_present(s, &present, order_flags, size); |
854 |
|
|
|
855 |
|
|
if (order_flags & RDP_ORDER_BOUNDS) |
856 |
|
|
{ |
857 |
|
|
if (!(order_flags & RDP_ORDER_LASTBOUNDS)) |
858 |
|
|
rdp_parse_bounds(s, &os->bounds); |
859 |
|
|
|
860 |
|
|
ui_set_clip(os->bounds.left, |
861 |
matty |
24 |
os->bounds.top, |
862 |
|
|
os->bounds.right - |
863 |
|
|
os->bounds.left + 1, |
864 |
|
|
os->bounds.bottom - |
865 |
|
|
os->bounds.top + 1); |
866 |
matty |
10 |
} |
867 |
|
|
|
868 |
|
|
delta = order_flags & RDP_ORDER_DELTA; |
869 |
|
|
|
870 |
|
|
switch (os->order_type) |
871 |
|
|
{ |
872 |
|
|
case RDP_ORDER_DESTBLT: |
873 |
|
|
process_destblt(s, &os->destblt, |
874 |
|
|
present, delta); |
875 |
|
|
break; |
876 |
|
|
|
877 |
|
|
case RDP_ORDER_PATBLT: |
878 |
|
|
process_patblt(s, &os->patblt, |
879 |
|
|
present, delta); |
880 |
|
|
break; |
881 |
|
|
|
882 |
|
|
case RDP_ORDER_SCREENBLT: |
883 |
|
|
process_screenblt(s, &os->screenblt, |
884 |
|
|
present, delta); |
885 |
|
|
break; |
886 |
|
|
|
887 |
|
|
case RDP_ORDER_LINE: |
888 |
|
|
process_line(s, &os->line, |
889 |
matty |
24 |
present, delta); |
890 |
matty |
10 |
break; |
891 |
|
|
|
892 |
|
|
case RDP_ORDER_RECT: |
893 |
|
|
process_rect(s, &os->rect, |
894 |
|
|
present, delta); |
895 |
|
|
break; |
896 |
|
|
|
897 |
|
|
case RDP_ORDER_DESKSAVE: |
898 |
|
|
process_desksave(s, &os->desksave, |
899 |
|
|
present, delta); |
900 |
|
|
break; |
901 |
|
|
|
902 |
|
|
case RDP_ORDER_MEMBLT: |
903 |
|
|
process_memblt(s, &os->memblt, |
904 |
|
|
present, delta); |
905 |
|
|
break; |
906 |
|
|
|
907 |
|
|
case RDP_ORDER_TRIBLT: |
908 |
|
|
process_triblt(s, &os->triblt, |
909 |
|
|
present, delta); |
910 |
|
|
break; |
911 |
|
|
|
912 |
matty |
15 |
case RDP_ORDER_POLYLINE: |
913 |
|
|
process_polyline(s, &os->polyline, |
914 |
|
|
present, delta); |
915 |
|
|
break; |
916 |
|
|
|
917 |
matty |
10 |
case RDP_ORDER_TEXT2: |
918 |
|
|
process_text2(s, &os->text2, |
919 |
|
|
present, delta); |
920 |
|
|
break; |
921 |
|
|
|
922 |
|
|
default: |
923 |
matty |
30 |
unimpl("order %d\n", os->order_type); |
924 |
matty |
10 |
return; |
925 |
|
|
} |
926 |
|
|
|
927 |
|
|
if (order_flags & RDP_ORDER_BOUNDS) |
928 |
|
|
ui_reset_clip(); |
929 |
|
|
} |
930 |
|
|
|
931 |
|
|
processed++; |
932 |
|
|
} |
933 |
|
|
|
934 |
|
|
if (s->p != next_packet) |
935 |
matty |
30 |
error("%d bytes remaining\n", (int) (next_packet - s->p)); |
936 |
matty |
10 |
} |
937 |
|
|
|
938 |
|
|
/* Reset order state */ |
939 |
matty |
25 |
void |
940 |
|
|
reset_order_state() |
941 |
matty |
10 |
{ |
942 |
|
|
memset(&order_state, 0, sizeof(order_state)); |
943 |
matty |
28 |
order_state.order_type = RDP_ORDER_PATBLT; |
944 |
matty |
10 |
} |