/[rdesktop]/sourceforge.net/trunk/rdesktop/rdp.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /sourceforge.net/trunk/rdesktop/rdp.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7 - (show annotations)
Fri Jul 7 09:40:03 2000 UTC (23 years, 11 months ago) by matty
File MIME type: text/plain
File size: 38339 byte(s)
Miscellaneous updates: implemented some more protocol features including
colour maps. Started on a new bitmap decompression engine which is not
completely working yet - however I am going back on the road so I am
committing now.

1 /*
2 rdesktop: A Remote Desktop Protocol client.
3 Protocol services - RDP layer
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 "includes.h"
22
23 /* Establish a connection up to the RDP layer */
24 HCONN rdp_connect(char *server)
25 {
26 HCONN conn;
27 RDP_ACTIVE_PDU active;
28 uint8 type;
29
30 if ((conn = mcs_connect(server)) == NULL)
31 return NULL;
32
33 rdp_establish_key(conn);
34 mcs_recv(conn, False); /* Server's licensing certificate */
35 rdp_send_cert(conn);
36 mcs_recv(conn, False);
37 mcs_recv(conn, False); /* Demand active */
38
39 if (!rdp_recv_pdu(conn, &type) || (type != RDP_PDU_DEMAND_ACTIVE))
40 {
41 fprintf(stderr, "RDP error, expected Demand Active\n");
42 mcs_disconnect(conn);
43 return NULL;
44 }
45
46 rdp_io_active_pdu(&conn->in, &active, RDP_PDU_DEMAND_ACTIVE);
47 rdp_send_confirm_active(conn);
48 rdp_send_synchronize(conn);
49 rdp_send_control(conn, RDP_CTL_COOPERATE);
50 rdp_send_control(conn, RDP_CTL_REQUEST_CONTROL);
51 rdp_recv_pdu(conn, &type); // RDP_PDU_SYNCHRONIZE
52 rdp_recv_pdu(conn, &type); // RDP_CTL_COOPERATE
53 rdp_recv_pdu(conn, &type); // RDP_CTL_GRANT_CONTROL
54 rdp_send_input(conn);
55 rdp_send_fonts(conn, 1);
56 rdp_send_fonts(conn, 2);
57 rdp_recv_pdu(conn, &type); // RDP_PDU_UNKNOWN 0x28
58
59 return conn;
60 }
61
62 void rdp_main_loop(HCONN conn)
63 {
64 RDP_DATA_HEADER hdr;
65 RDP_ORDER_STATE os;
66 uint8 type;
67
68 memset(&os, 0, sizeof(os));
69
70 while (rdp_recv_pdu(conn, &type))
71 {
72 if (type != RDP_PDU_DATA)
73 {
74 fprintf(stderr, "Unknown PDU 0x%x\n", type);
75 continue;
76 }
77
78 rdp_io_data_header(&conn->in, &hdr);
79
80 switch (hdr.data_pdu_type)
81 {
82 case RDP_DATA_PDU_UPDATE:
83 process_update(conn, &os);
84 break;
85
86 case RDP_DATA_PDU_POINTER:
87 process_pointer(conn);
88 break;
89
90 default:
91 fprintf(stderr, "Unknown data PDU 0x%x\n",
92 hdr.data_pdu_type);
93 }
94 }
95 }
96
97 void process_memblt(HCONN conn, RDP_ORDER_STATE *os, BOOL delta)
98 {
99 HBITMAP hbitmap;
100 uint16 present;
101 lsb_io_uint16(&conn->in, &present);
102
103 if (present & 1)
104 prs_io_uint8(&conn->in, &os->memblt.cache_id);
105
106 if (present & 2)
107 rdp_io_coord(&conn->in, &os->memblt.x, delta);
108
109 if (present & 4)
110 rdp_io_coord(&conn->in, &os->memblt.y, delta);
111
112 if (present & 8)
113 rdp_io_coord(&conn->in, &os->memblt.cx, delta);
114
115 if (present & 16)
116 rdp_io_coord(&conn->in, &os->memblt.cy, delta);
117
118 if (present & 32)
119 prs_io_uint8(&conn->in, &os->memblt.opcode);
120
121 if (present & 256)
122 lsb_io_uint16(&conn->in, &os->memblt.cache_idx);
123
124 if (os->memblt.opcode != 0xcc) /* SRCCOPY */
125 {
126 fprintf(stderr, "Unsupported raster operation 0x%x\n",
127 os->memblt.opcode);
128 return;
129 }
130
131 if ((os->memblt.cache_idx > NUM_ELEMENTS(conn->bmpcache))
132 || ((hbitmap = conn->bmpcache[os->memblt.cache_idx]) == NULL))
133 {
134 fprintf(stderr, "Bitmap %d not found\n", os->memblt.cache_idx);
135 return;
136 }
137
138 fprintf(stderr, "MEMBLT %d:%dx%d\n", os->memblt.cache_idx,
139 os->memblt.x, os->memblt.y);
140
141 ui_paint_bitmap(conn->wnd, hbitmap, os->memblt.x, os->memblt.y);
142 }
143
144 void process_opaque_rect(HCONN conn, RDP_ORDER_STATE *os, BOOL delta)
145 {
146 uint8 present;
147 prs_io_uint8(&conn->in, &present);
148
149 if (present & 1)
150 rdp_io_coord(&conn->in, &os->opaque_rect.x, delta);
151
152 if (present & 2)
153 rdp_io_coord(&conn->in, &os->opaque_rect.y, delta);
154
155 if (present & 4)
156 rdp_io_coord(&conn->in, &os->opaque_rect.cx, delta);
157
158 if (present & 8)
159 rdp_io_coord(&conn->in, &os->opaque_rect.cy, delta);
160
161 if (present & 16)
162 prs_io_uint8(&conn->in, &os->opaque_rect.colour);
163
164 fprintf(stderr, "Opaque rectangle at %d, %d\n", os->opaque_rect.x, os->opaque_rect.y);
165 ui_draw_rectangle(conn->wnd, os->opaque_rect.x, os->opaque_rect.y,
166 os->opaque_rect.cx, os->opaque_rect.cy);
167 }
168
169 void process_bmpcache(HCONN conn)
170 {
171 RDP_BITMAP_HEADER rbh;
172 HBITMAP *entry;
173 char *input, *bmpdata;
174
175 rdp_io_bitmap_header(&conn->in, &rbh);
176 fprintf(stderr, "BMPCACHE %d:%dx%d\n", rbh.cache_idx,
177 rbh.width, rbh.height);
178
179 input = conn->in.data + conn->in.offset;
180 conn->in.offset += rbh.size;
181 // dump_data(conn->in.data+conn->in.offset, conn->in.rdp_offset-conn->in.offset);
182
183 bmpdata = malloc(rbh.width * rbh.height);
184 if (!bitmap_decompress(bmpdata, rbh.width, rbh.height, input, rbh.size))
185 {
186 fprintf(stderr, "Decompression failed\n");
187 free(bmpdata);
188 return;
189 }
190
191 if (rbh.cache_idx > NUM_ELEMENTS(conn->bmpcache))
192 {
193 fprintf(stderr, "Attempted store past end of cache");
194 return;
195 }
196
197 entry = &conn->bmpcache[rbh.cache_idx];
198 // if (*entry != NULL)
199 // ui_destroy_bitmap(conn->wnd, *entry);
200
201 *entry = ui_create_bitmap(conn->wnd, rbh.width, rbh.height, bmpdata);
202 // ui_paint_bitmap(conn->wnd, bmp, x, 0);
203 // ui_destroy_bitmap(conn->wnd, bmp);
204 }
205
206 void process_orders(HCONN conn, RDP_ORDER_STATE *os)
207 {
208 uint16 num_orders;
209 int processed = 0;
210 BOOL res = True;
211 BOOL delta;
212 // unsigned char *p;
213
214 lsb_io_uint16(&conn->in, &num_orders);
215
216 conn->in.offset += 2;
217 // p = &conn->in.data[conn->in.offset];
218
219 // fprintf(stderr, "%02X %02X %02X %02X\n", p[0], p[1], p[2], p[3]);
220
221 while ((processed < num_orders) && res)
222 {
223 uint8 order_flags;
224
225 prs_io_uint8(&conn->in, &order_flags);
226 fprintf(stderr, "Order flags: 0x%x\n", order_flags);
227
228 if (order_flags == 0x51) /* ?? */
229 return;
230
231 if (!(order_flags & RDP_ORDER_STANDARD))
232 return;
233
234 if (order_flags & RDP_ORDER_SECONDARY)
235 {
236 RDP_SECONDARY_ORDER rso;
237
238 rdp_io_secondary_order(&conn->in, &rso);
239 switch (rso.type)
240 {
241 case RDP_ORDER_BMPCACHE:
242 process_bmpcache(conn);
243 break;
244 default:
245 fprintf(stderr, "Unknown secondary order %d\n",
246 rso.type);
247 return;
248 }
249 }
250 else
251 {
252 if (order_flags & RDP_ORDER_CHANGE)
253 prs_io_uint8(&conn->in, &os->order_type);
254
255 delta = order_flags & RDP_ORDER_DELTA;
256
257 switch (os->order_type)
258 {
259 case RDP_ORDER_OPAQUE_RECT:
260 process_opaque_rect(conn, os, delta);
261 break;
262
263 case RDP_ORDER_MEMBLT:
264 process_memblt(conn, os, delta);
265 break;
266
267 default:
268 fprintf(stderr, "Unknown order %d\n", os->order_type);
269 return;
270 }
271 }
272
273 processed++;
274 }
275 }
276
277 void process_palette(HCONN conn)
278 {
279 HCOLORMAP map;
280 COLORMAP colors;
281
282 rdp_io_colormap(&conn->in, &colors);
283 map = ui_create_colormap(conn->wnd, &colors);
284 ui_set_colormap(conn->wnd, map);
285 // ui_destroy_colormap(map);
286 }
287
288 void process_update(HCONN conn, RDP_ORDER_STATE *os)
289 {
290 RDP_UPDATE_PDU update;
291
292 rdp_io_update_pdu(&conn->in, &update);
293 switch (update.update_type)
294 {
295 case RDP_UPDATE_ORDERS:
296 process_orders(conn, os);
297 break;
298 case RDP_UPDATE_PALETTE:
299 process_palette(conn);
300 break;
301 case RDP_UPDATE_SYNCHRONIZE:
302 break;
303 default:
304 fprintf(stderr, "Unknown update 0x%x\n",
305 update.update_type);
306 }
307
308 }
309
310 void process_pointer(HCONN conn)
311 {
312 RDP_POINTER ptr;
313
314 rdp_io_pointer(&conn->in, &ptr);
315
316 switch (ptr.message)
317 {
318 case RDP_POINTER_MOVE:
319 ui_move_pointer(conn->wnd, ptr.x, ptr.y);
320 break;
321 default:
322 fprintf(stderr, "Unknown pointer message 0x%x\n",
323 ptr.message);
324 }
325 }
326
327 /* Work this out later. This is useless anyway when encryption is off. */
328 uint8 precanned_key_packet[] = {
329 0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x00,0x00,0x00,0x00,0x00,
330 0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6c,0x86,
331 0xf7,0x99,0xef,0x60,0xc4,0x49,0x52,0xd0,0xd8,0xea,0xb5,0x4f,0x58,0x19,
332 0x52,0x2a,0x93,0x83,0x57,0x4f,0x4e,0x04,0xde,0x96,0x51,0xab,0x13,0x20,
333 0xd8,0xe5,0x00,0x00,0x00,0x00,0x00,0x00
334 };
335
336 /* Create an RC4 key and transfer it to the server */
337 void rdp_establish_key(HCONN conn)
338 {
339 mcs_init_data(conn);
340 memcpy(conn->out.data + conn->out.offset, precanned_key_packet,
341 sizeof(precanned_key_packet));
342 conn->out.offset += sizeof(precanned_key_packet);
343 MARK_END(conn->out);
344 mcs_send_data(conn, MCS_GLOBAL_CHANNEL, True);
345 }
346
347 /* Horrible horrible certificate stuff. Work out later. */
348 uint8 precanned_cert_packet[] = {
349 0x80,0x00,0x00,0x00,0x12,0x02,0xb4,0x04,0x01,0x00,0x00,
350 0x00,0x00,0x00,0x01,0x02,0x9d,0xa3,0x7a,0x93,0x34,0x7b,0x28,0x37,0x24,0xa0,0x1f,
351 0x61,0x26,0xfd,0x96,0x3a,0x92,0x83,0xf3,0xe9,0x6a,0x2e,0x81,0x7c,0x2c,0xe4,0x72,//
352 0x01,0x18,0xe9,0xa1,0x0f,0x00,0x00,0x48,0x00,0x84,0x23,0x90,0xe6,0xd3,0xf8,0x20,
353 0xdb,0xa8,0x1b,0xb2,0xd0,0x78,0x2c,0x35,0xde,0xe3,0x0e,0x63,0x40,0xca,0xac,0x71,
354 0xc9,0x17,0x49,0x05,0x25,0xeb,0x9b,0xd0,0xa6,0x5c,0x90,0x3e,0x9d,0x4b,0x27,0x01,
355 0x79,0x1c,0x22,0xfb,0x3c,0x2c,0xb9,0x9f,0xf5,0x21,0xf3,0xee,0xd5,0x4d,0x47,0x1c,
356 0x85,0xbe,0x83,0x93,0xe8,0xed,0x8c,0x5c,0x82,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
357 0x00,0x01,0x00,0x10,0x04,0x30,0x82,0x04,0x0c,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,
358 0x0d,0x01,0x07,0x02,0xa0,0x82,0x03,0xfd,0x30,0x82,0x03,0xf9,0x02,0x01,0x01,0x31,
359 0x00,0x30,0x0b,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x07,0x01,0xa0,0x82,
360 0x03,0xe1,0x30,0x82,0x01,0x77,0x30,0x82,0x01,0x25,0xa0,0x03,0x02,0x01,0x02,0x02,
361 0x08,0x01,0xbf,0x06,0x84,0x9d,0xdb,0x2d,0xe0,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,
362 0x86,0xf7,0x0d,0x01,0x01,0x01,0x05,0x00,0x30,0x38,0x31,0x36,0x30,0x11,0x06,0x03,
363 0x55,0x04,0x03,0x1e,0x0a,0x00,0x4e,0x00,0x54,0x00,0x54,0x00,0x53,0x00,0x45,0x30,
364 0x21,0x06,0x03,0x55,0x04,0x07,0x1e,0x1a,0x00,0x4d,0x00,0x69,0x00,0x63,0x00,0x72,
365 0x00,0x6f,0x00,0x73,0x00,0x6f,0x00,0x66,0x00,0x74,0x00,0x2e,0x00,0x63,0x00,0x6f,
366 0x00,0x6d,0x30,0x1e,0x17,0x0d,0x39,0x39,0x30,0x39,0x32,0x34,0x31,0x32,0x30,0x32,
367 0x30,0x34,0x5a,0x17,0x0d,0x34,0x39,0x30,0x39,0x32,0x34,0x31,0x32,0x30,0x32,0x30,
368 0x34,0x5a,0x30,0x38,0x31,0x36,0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x1e,0x0a,0x00,
369 0x4e,0x00,0x54,0x00,0x54,0x00,0x53,0x00,0x45,0x30,0x21,0x06,0x03,0x55,0x04,0x07,
370 0x1e,0x1a,0x00,0x4d,0x00,0x69,0x00,0x63,0x00,0x72,0x00,0x6f,0x00,0x73,0x00,0x6f,
371 0x00,0x66,0x00,0x74,0x00,0x2e,0x00,0x63,0x00,0x6f,0x00,0x6d,0x30,0x5c,0x30,0x0d,
372 0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x01,0x05,0x00,0x03,0x4b,0x00,
373 0x30,0x48,0x02,0x41,0x00,0x91,0xb2,0x16,0x1c,0xae,0x4f,0x7f,0x7c,0xaf,0x57,0x2b,
374 0x23,0x4c,0x0c,0x25,0x3c,0x4f,0x66,0x9d,0x25,0xc3,0x4f,0x29,0xee,0x8b,0xda,0x4e,
375 0x95,0xe7,0x3b,0xaa,0xc0,0xa7,0xba,0xaf,0x99,0x8c,0x47,0x24,0x8b,0x09,0x77,0xbc,
376 0x2c,0xf4,0xe7,0x1a,0x07,0x58,0x7b,0x11,0x37,0x2a,0xa8,0x90,0xc3,0x50,0x92,0x80,
377 0x15,0xc5,0xda,0x51,0x8b,0x02,0x03,0x01,0x00,0x01,0xa3,0x13,0x30,0x11,0x30,0x0f,
378 0x06,0x03,0x55,0x1d,0x13,0x04,0x08,0x30,0x06,0x01,0x01,0xff,0x02,0x01,0x00,0x30,
379 0x09,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1d,0x05,0x00,0x03,0x41,0x00,0x14,0x04,0x67,
380 0x28,0xc8,0xd3,0x1f,0x13,0x14,0x2e,0x2c,0x93,0x09,0x25,0xbb,0xbe,0x86,0x6a,0xd3,
381 0x47,0x6f,0x44,0x16,0x7b,0x94,0x8c,0xb2,0xa2,0xd5,0xf7,0x4f,0xb1,0x8f,0x7f,0xde,
382 0x0b,0x88,0x34,0x4a,0x1d,0xdc,0xa1,0xfd,0x26,0xbd,0x43,0xbb,0x38,0xf1,0x87,0x34,
383 0xbb,0xe9,0x3b,0xfa,0x7f,0x1e,0xff,0xe1,0x10,0x7e,0xee,0x6e,0xd8,0x30,0x82,0x02,
384 0x62,0x30,0x82,0x02,0x10,0xa0,0x03,0x02,0x01,0x02,0x02,0x05,0x01,0x00,0x00,0x00,
385 0x01,0x30,0x09,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1d,0x05,0x00,0x30,0x38,0x31,0x36,
386 0x30,0x11,0x06,0x03,0x55,0x04,0x03,0x1e,0x0a,0x00,0x4e,0x00,0x54,0x00,0x54,0x00,
387 0x53,0x00,0x45,0x30,0x21,0x06,0x03,0x55,0x04,0x07,0x1e,0x1a,0x00,0x4d,0x00,0x69,
388 0x00,0x63,0x00,0x72,0x00,0x6f,0x00,0x73,0x00,0x6f,0x00,0x66,0x00,0x74,0x00,0x2e,
389 0x00,0x63,0x00,0x6f,0x00,0x6d,0x30,0x1e,0x17,0x0d,0x39,0x39,0x30,0x39,0x32,0x34,
390 0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x17,0x0d,0x34,0x39,0x30,0x39,0x32,0x34,0x30,
391 0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x79,0x31,0x77,0x30,0x17,0x06,0x03,0x55,0x04,
392 0x03,0x1e,0x10,0x00,0x52,0x00,0x45,0x00,0x53,0x00,0x37,0x00,0x2d,0x00,0x4e,0x00,
393 0x45,0x00,0x57,0x30,0x17,0x06,0x03,0x55,0x04,0x07,0x1e,0x10,0x00,0x7a,0x00,0x32,
394 0x00,0x32,0x00,0x33,0x00,0x32,0x00,0x32,0x00,0x30,0x00,0x33,0x30,0x43,0x06,0x03,
395 0x55,0x04,0x05,0x1e,0x3c,0x00,0x31,0x00,0x42,0x00,0x63,0x00,0x4b,0x00,0x65,0x00,
396 0x57,0x00,0x50,0x00,0x6c,0x00,0x37,0x00,0x58,0x00,0x47,0x00,0x61,0x00,0x73,0x00,
397 0x38,0x00,0x4a,0x00,0x79,0x00,0x50,0x00,0x34,0x00,0x30,0x00,0x7a,0x00,0x49,0x00,
398 0x6d,0x00,0x6e,0x00,0x6f,0x00,0x51,0x00,0x5a,0x00,0x59,0x00,0x3d,0x00,0x0d,0x00,
399 0x0a,0x30,0x5c,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x01,
400 0x05,0x00,0x03,0x4b,0x00,0x30,0x48,0x02,0x41,0x00,0x91,0xb2,0x16,0x1c,0xae,0x4f,
401 0x7f,0x7c,0xaf,0x57,0x2b,0x23,0x4c,0x0c,0x25,0x3c,0x4f,0x66,0x9d,0x25,0xc3,0x4f,
402 0x29,0xee,0x8b,0xda,0x4e,0x95,0xe7,0x3b,0xaa,0xc0,0xa7,0xba,0xaf,0x99,0x8c,0x47,
403 0x24,0x8b,0x09,0x77,0xbc,0x2c,0xf4,0xe7,0x1a,0x07,0x58,0x7b,0x11,0x37,0x2a,0xa8,
404 0x90,0xc3,0x50,0x92,0x80,0x15,0xc5,0xda,0x51,0x8b,0x02,0x03,0x01,0x00,0x01,0xa3,
405 0x81,0xc3,0x30,0x81,0xc0,0x30,0x14,0x06,0x09,0x2b,0x06,0x01,0x04,0x01,0x82,0x37,
406 0x12,0x04,0x01,0x01,0xff,0x04,0x04,0x01,0x00,0x01,0x00,0x30,0x3c,0x06,0x09,0x2b,
407 0x06,0x01,0x04,0x01,0x82,0x37,0x12,0x02,0x01,0x01,0xff,0x04,0x2c,0x4d,0x00,0x69,
408 0x00,0x63,0x00,0x72,0x00,0x6f,0x00,0x73,0x00,0x6f,0x00,0x66,0x00,0x74,0x00,0x20,
409 0x00,0x43,0x00,0x6f,0x00,0x72,0x00,0x70,0x00,0x6f,0x00,0x72,0x00,0x61,0x00,0x74,
410 0x00,0x69,0x00,0x6f,0x00,0x6e,0x00,0x00,0x00,0x30,0x4c,0x06,0x09,0x2b,0x06,0x01,
411 0x04,0x01,0x82,0x37,0x12,0x05,0x01,0x01,0xff,0x04,0x3c,0x00,0x10,0x00,0x00,0x01,
412 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x09,0x04,0x00,0x00,0x18,0x00,0x18,0x00,0x30,
413 0x00,0x01,0x00,0x32,0x00,0x33,0x00,0x36,0x00,0x2d,0x00,0x34,0x00,0x2e,0x00,0x30,
414 0x00,0x30,0x00,0x2d,0x00,0x45,0x00,0x58,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,
415 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x1c,0x06,0x03,0x55,0x1d,0x23,0x01,0x01,
416 0xff,0x04,0x12,0x30,0x10,0xa1,0x07,0x81,0x05,0x4e,0x54,0x54,0x53,0x45,0x82,0x05,
417 0x01,0x00,0x00,0x00,0x01,0x30,0x09,0x06,0x05,0x2b,0x0e,0x03,0x02,0x1d,0x05,0x00,
418 0x03,0x41,0x00,0x7b,0x1d,0xfd,0x24,0xea,0xf2,0xe8,0x17,0xdd,0x88,0x7e,0xfd,0xee,
419 0x28,0x61,0x7a,0x02,0xc3,0x73,0xcf,0x32,0x0f,0x7c,0x66,0x87,0x31,0xa7,0xbe,0x1b,
420 0x31,0xe2,0x20,0xa5,0x76,0x91,0x68,0x97,0x53,0x9e,0x80,0xcd,0x2b,0xd0,0x8e,0x8b,
421 0x7f,0x89,0x1b,0x62,0xa8,0xf8,0xee,0x5e,0x56,0xbd,0x9c,0x6b,0x80,0x06,0x54,0xd3,
422 0xf0,0xbf,0xb2,0x31,0x00,0x01,0x00,0x14,0x00,0xc7,0x32,0xf2,0x5b,0x98,0x0e,0x04,
423 0x49,0xa0,0x27,0x7e,0xf5,0xf6,0x0f,0xda,0x08,0x1d,0xe9,0x79,0xd1,0x31,0xc6,0x50,
424 0x90,0x4a,0xd3,0x1f,0x1d,0xf0,0x65,0x0d,0xb6,0x1f,0xaf,0xc9,0x1d
425 };
426
427 /* Send license certificate and related data to the server */
428 void rdp_send_cert(HCONN conn)
429 {
430 mcs_init_data(conn);
431 prs_io_uint8s(&conn->out, precanned_cert_packet, sizeof(precanned_cert_packet));
432 MARK_END(conn->out);
433 mcs_send_data(conn, MCS_GLOBAL_CHANNEL, True);
434 }
435
436 /* Initialise RDP transport packet */
437 void rdp_init(HCONN conn)
438 {
439 mcs_init_data(conn);
440 PUSH_LAYER(conn->out, rdp_offset, 6);
441 }
442
443 /* Transmit RDP transport packet */
444 void rdp_send(HCONN conn, uint16 pdu_type)
445 {
446 RDP_HEADER hdr;
447 int length;
448
449 POP_LAYER(conn->out, rdp_offset);
450 length = conn->out.end - conn->out.offset;
451 rdp_make_header(&hdr, length, pdu_type, conn->mcs_userid);
452 rdp_io_header(&conn->out, &hdr);
453 mcs_send_data(conn, MCS_GLOBAL_CHANNEL, True);
454 }
455
456 /* Initialise RDP transport data packet */
457 void rdp_init_data(HCONN conn)
458 {
459 mcs_init_data(conn);
460 PUSH_LAYER(conn->out, rdp_offset, 18);
461 }
462
463 /* Transmit RDP transport data packet */
464 void rdp_send_data(HCONN conn, uint16 data_pdu_type)
465 {
466 RDP_HEADER hdr;
467 RDP_DATA_HEADER datahdr;
468 int length = conn->out.end - conn->out.offset;
469
470 POP_LAYER(conn->out, rdp_offset);
471 length = conn->out.end - conn->out.offset;
472 rdp_make_header(&hdr, length, RDP_PDU_DATA, conn->mcs_userid);
473 rdp_io_header(&conn->out, &hdr);
474 rdp_make_data_header(&datahdr, 0x103ea, length, data_pdu_type);
475 rdp_io_data_header(&conn->out, &datahdr);
476 mcs_send_data(conn, MCS_GLOBAL_CHANNEL, True);
477 }
478
479 void rdp_send_confirm_active(HCONN conn)
480 {
481 RDP_ACTIVE_PDU active;
482
483 rdp_init(conn);
484 rdp_make_active_pdu(&active, 0x103ea, conn->mcs_userid);
485 rdp_io_active_pdu(&conn->out, &active, RDP_PDU_CONFIRM_ACTIVE);
486 MARK_END(conn->out);
487 rdp_send(conn, RDP_PDU_CONFIRM_ACTIVE);
488 }
489
490 void rdp_send_synchronize(HCONN conn)
491 {
492 RDP_SYNCHRONIZE_PDU sync;
493
494 rdp_init_data(conn);
495 rdp_make_synchronize_pdu(&sync, 1002);
496 rdp_io_synchronize_pdu(&conn->out, &sync);
497 MARK_END(conn->out);
498 rdp_send_data(conn, RDP_DATA_PDU_SYNCHRONIZE);
499 }
500
501 void rdp_send_control(HCONN conn, uint16 action)
502 {
503 RDP_CONTROL_PDU control;
504
505 rdp_init_data(conn);
506 rdp_make_control_pdu(&control, action);
507 rdp_io_control_pdu(&conn->out, &control);
508 MARK_END(conn->out);
509 rdp_send_data(conn, RDP_DATA_PDU_CONTROL);
510 }
511
512 void rdp_send_fonts(HCONN conn, uint16 seqno)
513 {
514 RDP_FONT_PDU fonts;
515
516 rdp_init_data(conn);
517 rdp_make_font_pdu(&fonts, seqno);
518 rdp_io_font_pdu(&conn->out, &fonts);
519 MARK_END(conn->out);
520 rdp_send_data(conn, RDP_DATA_PDU_FONT2);
521 }
522
523 void rdp_send_input(HCONN conn)
524 {
525 RDP_INPUT_PDU input;
526
527 rdp_init_data(conn);
528 rdp_make_input_pdu(&input);
529 rdp_io_input_pdu(&conn->out, &input);
530 MARK_END(conn->out);
531 rdp_send_data(conn, RDP_DATA_PDU_INPUT);
532 }
533
534 BOOL rdp_recv_pdu(HCONN conn, uint8 *type)
535 {
536 RDP_HEADER hdr;
537
538 conn->in.offset = conn->in.rdp_offset;
539
540 if (conn->in.offset >= conn->in.end)
541 {
542 if (!mcs_recv(conn, False))
543 return False;
544 }
545
546 if (!rdp_io_header(&conn->in, &hdr))
547 return False;
548
549 conn->in.rdp_offset += hdr.length;
550 *type = hdr.pdu_type & 0xf;
551
552 #if DEBUG
553 fprintf(stderr, "RDP packet (type %x):\n", *type);
554 dump_data(conn->in.data+conn->in.offset, conn->in.rdp_offset-conn->in.offset);
555 #endif
556
557 return True;
558 }
559
560 /* Disconnect from the RDP layer */
561 void rdp_disconnect(HCONN conn)
562 {
563 mcs_disconnect(conn);
564 }
565
566 void rdp_make_header(RDP_HEADER *hdr, uint16 length, uint16 pdu_type,
567 uint16 userid)
568 {
569 hdr->length = length;
570 hdr->pdu_type = pdu_type | 0x10; /* Version 1 */
571 hdr->userid = userid + 1001;
572 }
573
574 void rdp_make_data_header(RDP_DATA_HEADER *hdr, uint32 shareid,
575 uint16 length, uint16 data_pdu_type)
576 {
577 hdr->shareid = shareid;
578 hdr->pad = 0;
579 hdr->streamid = 1;
580 hdr->length = length - 14;
581 hdr->data_pdu_type = data_pdu_type;
582 hdr->compress_type = 0;
583 hdr->compress_len = 0;
584 }
585
586 void rdp_make_general_caps(RDP_GENERAL_CAPS *caps)
587 {
588 caps->os_major_type = 1;
589 caps->os_minor_type = 3;
590 caps->ver_protocol = 0x200;
591 }
592
593 void rdp_make_bitmap_caps(RDP_BITMAP_CAPS *caps)
594 {
595 caps->preferred_bpp = 8;
596 caps->receive1bpp = 1;
597 caps->receive4bpp = 1;
598 caps->receive8bpp = 1;
599 caps->width = 640;
600 caps->height = 480;
601 caps->compression = 1;
602 caps->unknown2 = 1;
603 }
604
605 void rdp_make_order_caps(RDP_ORDER_CAPS *caps)
606 {
607 caps->xgranularity = 1;
608 caps->ygranularity = 20;
609 caps->max_order_level = 1;
610 caps->num_fonts = 0x147;
611 caps->cap_flags = 0x2A;
612
613 // caps->cap_flags = ORDER_CAP_NEGOTIATE | ORDER_CAP_NOSUPPORT;
614
615 caps->support[0] = caps->support[1] = caps->support[2]
616 = caps->support[3] = caps->support[4] = caps->support[5]
617 = caps->support[6] = caps->support[8] = caps->support[11]
618 = caps->support[12] = caps->support[22] = caps->support[28]
619 = caps->support[29] = caps->support[30] = 1;
620 caps->text_cap_flags = 0x6A1;
621 caps->desk_save_size = 0x38400;
622 caps->unknown2 = 0x4E4;
623 }
624
625 void rdp_make_bmpcache_caps(RDP_BMPCACHE_CAPS *caps)
626 {
627 caps->caches[0].entries = 0x258;
628 caps->caches[0].max_cell_size = 0x100;
629 caps->caches[1].entries = 0x12c;
630 caps->caches[1].max_cell_size = 0x400;
631 caps->caches[2].entries = 0x106;
632 caps->caches[2].max_cell_size = 0x1000;
633 }
634
635 void rdp_make_control_caps(RDP_CONTROL_CAPS *caps)
636 {
637 caps->control_interest = 2;
638 caps->detach_interest = 2;
639 }
640
641 void rdp_make_activate_caps(RDP_ACTIVATE_CAPS *caps)
642 {
643 }
644
645 void rdp_make_pointer_caps(RDP_POINTER_CAPS *caps)
646 {
647 caps->colour_pointer = 0;
648 caps->cache_size = 20;
649 }
650
651 void rdp_make_share_caps(RDP_SHARE_CAPS *caps, uint16 userid)
652 {
653 }
654
655 void rdp_make_colcache_caps(RDP_COLCACHE_CAPS *caps)
656 {
657 caps->cache_size = 6;
658 }
659
660 void rdp_make_active_pdu(RDP_ACTIVE_PDU *pdu, uint32 shareid, uint16 userid)
661 {
662 memset(pdu, 0, sizeof(*pdu));
663 pdu->shareid = shareid;
664 pdu->userid = 1002;
665 pdu->source_len = sizeof(RDP_SOURCE);
666 memcpy(pdu->source, RDP_SOURCE, sizeof(RDP_SOURCE));
667
668 pdu->caps_len = RDP_CAPLEN_GENERAL + RDP_CAPLEN_BITMAP + RDP_CAPLEN_ORDER
669 + RDP_CAPLEN_BMPCACHE + RDP_CAPLEN_COLCACHE + RDP_CAPLEN_ACTIVATE
670 + RDP_CAPLEN_CONTROL + RDP_CAPLEN_POINTER + RDP_CAPLEN_SHARE
671 + RDP_CAPLEN_UNKNOWN;
672 pdu->num_caps = 0xD;
673
674 rdp_make_general_caps (&pdu->general_caps );
675 rdp_make_bitmap_caps (&pdu->bitmap_caps );
676 rdp_make_order_caps (&pdu->order_caps );
677 rdp_make_bmpcache_caps(&pdu->bmpcache_caps);
678 rdp_make_control_caps (&pdu->control_caps );
679 rdp_make_activate_caps(&pdu->activate_caps);
680 rdp_make_pointer_caps (&pdu->pointer_caps );
681 rdp_make_share_caps (&pdu->share_caps, userid);
682 rdp_make_colcache_caps(&pdu->colcache_caps);
683 }
684
685 void rdp_make_control_pdu(RDP_CONTROL_PDU *pdu, uint16 action)
686 {
687 pdu->action = action;
688 pdu->userid = 0;
689 pdu->controlid = 0;
690 }
691
692 void rdp_make_synchronize_pdu(RDP_SYNCHRONIZE_PDU *pdu, uint16 userid)
693 {
694 pdu->type = 1;
695 pdu->userid = userid;
696 }
697
698 void rdp_make_font_pdu(RDP_FONT_PDU *pdu, uint16 seqno)
699 {
700 pdu->num_fonts = 0;
701 pdu->unknown1 = 0x3e;
702 pdu->unknown2 = seqno;
703 pdu->entry_size = RDP_FONT_INFO_SIZE;
704 }
705
706 void rdp_make_input_pdu(RDP_INPUT_PDU *pdu)
707 {
708 uint32 now = time(NULL);
709
710 pdu->num_events = 3;
711 pdu->pad = 0;
712
713 pdu->event[0].event_time = now;
714 pdu->event[0].message_type = RDP_INPUT_SYNCHRONIZE;
715 pdu->event[0].device_flags = 0;
716 pdu->event[0].mouse_x = 0;
717 pdu->event[0].mouse_y = 0;
718
719 pdu->event[1].event_time = now;
720 pdu->event[1].message_type = RDP_INPUT_UNKNOWN;
721 pdu->event[1].device_flags = 0x8000;
722 pdu->event[1].mouse_x = 15;
723 pdu->event[1].mouse_y = 0;
724
725 pdu->event[2].event_time = now;
726 pdu->event[2].message_type = RDP_INPUT_MOUSE;
727 pdu->event[2].device_flags = MOUSE_FLAG_MOVE;
728 pdu->event[2].mouse_x = 425;
729 pdu->event[2].mouse_y = 493;
730 }
731
732 BOOL rdp_io_header(STREAM s, RDP_HEADER *hdr)
733 {
734 BOOL res = True;
735
736 res = res ? lsb_io_uint16(s, &hdr->length ) : False;
737 res = res ? lsb_io_uint16(s, &hdr->pdu_type) : False;
738 res = res ? lsb_io_uint16(s, &hdr->userid ) : False;
739
740 return res;
741 }
742
743 BOOL rdp_io_data_header(STREAM s, RDP_DATA_HEADER *hdr)
744 {
745 BOOL res = True;
746
747 res = res ? lsb_io_uint32(s, &hdr->shareid ) : False;
748 res = res ? prs_io_uint8 (s, &hdr->pad ) : False;
749 res = res ? prs_io_uint8 (s, &hdr->streamid ) : False;
750 res = res ? lsb_io_uint16(s, &hdr->length ) : False;
751 res = res ? prs_io_uint8 (s, &hdr->data_pdu_type) : False;
752 res = res ? prs_io_uint8 (s, &hdr->compress_type) : False;
753 res = res ? lsb_io_uint16(s, &hdr->compress_len ) : False;
754
755 return res;
756 }
757
758 BOOL rdp_io_coord(STREAM s, uint16 *coord, BOOL delta)
759 {
760 uint8 change;
761 BOOL res;
762
763 if (delta)
764 {
765 res = prs_io_uint8(s, &change);
766 *coord += change;
767 }
768 else
769 {
770 res = lsb_io_uint16(s, coord);
771 }
772
773 return res;
774 }
775
776 BOOL rdp_io_colormap(STREAM s, COLORMAP *colors)
777 {
778 int datasize;
779
780 lsb_io_uint16(s, &colors->ncolors);
781 datasize = colors->ncolors * 3;
782
783 if (datasize > sizeof(colors->colors))
784 return False;
785
786 memcpy(colors->colors, s->data + s->offset, datasize);
787 s->offset += datasize;
788 return True;
789 }
790
791 BOOL rdp_io_general_caps(STREAM s, RDP_GENERAL_CAPS *caps)
792 {
793 uint16 length = RDP_CAPLEN_GENERAL;
794 uint16 pkt_length = length;
795 BOOL res;
796
797 res = lsb_io_uint16(s, &pkt_length);
798 if (pkt_length != length)
799 {
800 fprintf(stderr, "Unrecognised capabilities size\n");
801 return False;
802 }
803
804 res = res ? lsb_io_uint16(s, &caps->os_major_type ) : False;
805 res = res ? lsb_io_uint16(s, &caps->os_minor_type ) : False;
806 res = res ? lsb_io_uint16(s, &caps->ver_protocol ) : False;
807 res = res ? lsb_io_uint16(s, &caps->pad1 ) : False;
808 res = res ? lsb_io_uint16(s, &caps->compress_types) : False;
809 res = res ? lsb_io_uint16(s, &caps->pad2 ) : False;
810 res = res ? lsb_io_uint16(s, &caps->cap_update ) : False;
811 res = res ? lsb_io_uint16(s, &caps->remote_unshare) : False;
812 res = res ? lsb_io_uint16(s, &caps->compress_level) : False;
813 res = res ? lsb_io_uint16(s, &caps->pad3 ) : False;
814
815 return res;
816 }
817
818 BOOL rdp_io_bitmap_caps(STREAM s, RDP_BITMAP_CAPS *caps)
819 {
820 uint16 length = RDP_CAPLEN_BITMAP;
821 uint16 pkt_length = length;
822 BOOL res;
823
824 res = lsb_io_uint16(s, &pkt_length);
825 if (pkt_length != length)
826 {
827 fprintf(stderr, "Unrecognised capabilities size\n");
828 return False;
829 }
830
831 res = res ? lsb_io_uint16(s, &caps->preferred_bpp) : False;
832 res = res ? lsb_io_uint16(s, &caps->receive1bpp ) : False;
833 res = res ? lsb_io_uint16(s, &caps->receive4bpp ) : False;
834 res = res ? lsb_io_uint16(s, &caps->receive8bpp ) : False;
835 res = res ? lsb_io_uint16(s, &caps->width ) : False;
836 res = res ? lsb_io_uint16(s, &caps->height ) : False;
837 res = res ? lsb_io_uint16(s, &caps->pad1 ) : False;
838 res = res ? lsb_io_uint16(s, &caps->allow_resize ) : False;
839 res = res ? lsb_io_uint16(s, &caps->compression ) : False;
840 res = res ? lsb_io_uint16(s, &caps->unknown1 ) : False;
841 res = res ? lsb_io_uint16(s, &caps->unknown2 ) : False;
842 res = res ? lsb_io_uint16(s, &caps->pad2 ) : False;
843
844 return res;
845 }
846
847 BOOL rdp_io_order_caps(STREAM s, RDP_ORDER_CAPS *caps)
848 {
849 uint16 length = RDP_CAPLEN_ORDER;
850 uint16 pkt_length = length;
851 BOOL res;
852
853 res = lsb_io_uint16(s, &pkt_length);
854 if (pkt_length != length)
855 {
856 fprintf(stderr, "Unrecognised capabilities size\n");
857 return False;
858 }
859
860 res = res ? prs_io_uint8s(s, caps->terminal_desc, 16) : False;
861 res = res ? lsb_io_uint32(s, &caps->pad1 ) : False;
862 res = res ? lsb_io_uint16(s, &caps->xgranularity ) : False;
863 res = res ? lsb_io_uint16(s, &caps->ygranularity ) : False;
864 res = res ? lsb_io_uint16(s, &caps->pad2 ) : False;
865 res = res ? lsb_io_uint16(s, &caps->max_order_level ) : False;
866 res = res ? lsb_io_uint16(s, &caps->num_fonts ) : False;
867 res = res ? lsb_io_uint16(s, &caps->cap_flags ) : False;
868 res = res ? prs_io_uint8s(s, caps->support , 32) : False;
869 res = res ? lsb_io_uint16(s, &caps->text_cap_flags ) : False;
870 res = res ? lsb_io_uint16(s, &caps->pad3 ) : False;
871 res = res ? lsb_io_uint32(s, &caps->pad4 ) : False;
872 res = res ? lsb_io_uint32(s, &caps->desk_save_size ) : False;
873 res = res ? lsb_io_uint32(s, &caps->unknown1 ) : False;
874 res = res ? lsb_io_uint32(s, &caps->unknown2 ) : False;
875
876 return res;
877 }
878
879 BOOL rdp_io_bmpcache_info(STREAM s, RDP_BMPCACHE_INFO *info)
880 {
881 if (!lsb_io_uint16(s, &info->entries ))
882 return False;
883
884 if (!lsb_io_uint16(s, &info->max_cell_size))
885 return False;
886
887 return True;
888 }
889
890 BOOL rdp_io_bmpcache_caps(STREAM s, RDP_BMPCACHE_CAPS *caps)
891 {
892 uint16 length = RDP_CAPLEN_BMPCACHE;
893 uint16 pkt_length = length;
894 BOOL res;
895 int i;
896
897 res = lsb_io_uint16(s, &pkt_length);
898 if (pkt_length != length)
899 {
900 fprintf(stderr, "Unrecognised capabilities size\n");
901 return False;
902 }
903
904 for (i = 0; i < 6; i++)
905 res = res ? lsb_io_uint32(s, &caps->unused[i]) : False;
906
907 for (i = 0; i < 3; i++)
908 res = res ? rdp_io_bmpcache_info(s, &caps->caches[i]) : False;
909
910 return res;
911 }
912
913 BOOL rdp_io_control_caps(STREAM s, RDP_CONTROL_CAPS *caps)
914 {
915 uint16 length = RDP_CAPLEN_CONTROL;
916 uint16 pkt_length = length;
917 BOOL res;
918
919 res = lsb_io_uint16(s, &pkt_length);
920 if (pkt_length != length)
921 {
922 fprintf(stderr, "Unrecognised capabilities size\n");
923 return False;
924 }
925
926 res = res ? lsb_io_uint16(s, &caps->control_caps ) : False;
927 res = res ? lsb_io_uint16(s, &caps->remote_detach ) : False;
928 res = res ? lsb_io_uint16(s, &caps->control_interest) : False;
929 res = res ? lsb_io_uint16(s, &caps->detach_interest ) : False;
930
931 return res;
932 }
933
934 BOOL rdp_io_activate_caps(STREAM s, RDP_ACTIVATE_CAPS *caps)
935 {
936 uint16 length = RDP_CAPLEN_ACTIVATE;
937 uint16 pkt_length = length;
938 BOOL res;
939
940 res = lsb_io_uint16(s, &pkt_length);
941 if (pkt_length != length)
942 {
943 fprintf(stderr, "Unrecognised capabilities size\n");
944 return False;
945 }
946
947 res = res ? lsb_io_uint16(s, &caps->help_key ) : False;
948 res = res ? lsb_io_uint16(s, &caps->help_index_key ) : False;
949 res = res ? lsb_io_uint16(s, &caps->help_extended_key) : False;
950 res = res ? lsb_io_uint16(s, &caps->window_activate ) : False;
951
952 return res;
953 }
954
955 BOOL rdp_io_pointer_caps(STREAM s, RDP_POINTER_CAPS *caps)
956 {
957 uint16 length = RDP_CAPLEN_POINTER;
958 uint16 pkt_length = length;
959 BOOL res;
960
961 res = lsb_io_uint16(s, &pkt_length);
962 if (pkt_length != length)
963 {
964 fprintf(stderr, "Unrecognised capabilities size\n");
965 return False;
966 }
967
968 res = res ? lsb_io_uint16(s, &caps->colour_pointer) : False;
969 res = res ? lsb_io_uint16(s, &caps->cache_size ) : False;
970
971 return res;
972 }
973
974 BOOL rdp_io_share_caps(STREAM s, RDP_SHARE_CAPS *caps)
975 {
976 uint16 length = RDP_CAPLEN_SHARE;
977 uint16 pkt_length = length;
978 BOOL res;
979
980 res = lsb_io_uint16(s, &pkt_length);
981 if (pkt_length != length)
982 {
983 fprintf(stderr, "Unrecognised capabilities size\n");
984 return False;
985 }
986
987 res = res ? lsb_io_uint16(s, &caps->userid) : False;
988 res = res ? lsb_io_uint16(s, &caps->pad ) : False;
989
990 return res;
991 }
992
993 BOOL rdp_io_colcache_caps(STREAM s, RDP_COLCACHE_CAPS *caps)
994 {
995 uint16 length = RDP_CAPLEN_COLCACHE;
996 uint16 pkt_length = length;
997 BOOL res;
998
999 res = lsb_io_uint16(s, &pkt_length);
1000 if (pkt_length != length)
1001 {
1002 fprintf(stderr, "Unrecognised capabilities size\n");
1003 return False;
1004 }
1005
1006 res = res ? lsb_io_uint16(s, &caps->cache_size) : False;
1007 res = res ? lsb_io_uint16(s, &caps->pad ) : False;
1008
1009 return res;
1010 }
1011
1012 uint8 canned_caps[] = {
1013 0x01,0x00,0x00,0x00,0x09,0x04,0x00,0x00,0x04,
1014 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1015 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1016 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1017 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1018 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x08,0x00,0x01,
1019 0x00,0x00,0x00,0x0E,0x00,0x08,0x00,0x01,0x00,0x00,0x00,0x10,0x00,0x34,0x00,0xFE,
1020 0x00,0x04,0x00,0xFE,0x00,0x04,0x00,0xFE,0x00,0x08,0x00,0xFE,0x00,0x08,0x00,0xFE,
1021 0x00,0x10,0x00,0xFE,0x00,0x20,0x00,0xFE,0x00,0x40,0x00,0xFE,0x00,0x80,0x00,0xFE,
1022 0x00,0x00,0x01,0x40,0x00,0x00,0x08,0x00,0x01,0x00,0x01,0x02,0x00,0x00,0x00
1023 };
1024
1025 BOOL rdp_io_unknown_caps(STREAM s, void *caps)
1026 {
1027 uint16 length = 0x58;
1028 uint16 pkt_length = length;
1029 BOOL res;
1030
1031 res = lsb_io_uint16(s, &pkt_length);
1032 if (pkt_length != length)
1033 {
1034 fprintf(stderr, "Unrecognised capabilities size\n");
1035 return False;
1036 }
1037
1038 res = res ? prs_io_uint8s(s, canned_caps, RDP_CAPLEN_UNKNOWN-4) : False;
1039
1040 return res;
1041 }
1042
1043 BOOL rdp_io_active_pdu(STREAM s, RDP_ACTIVE_PDU *pdu, int pdutype)
1044 {
1045 uint16 capset;
1046 uint16 length;
1047 BOOL res;
1048 int i;
1049
1050 res = lsb_io_uint32(s, &pdu->shareid);
1051
1052 if (pdutype == RDP_PDU_CONFIRM_ACTIVE)
1053 res = res ? lsb_io_uint16(s, &pdu->userid ) : False;
1054
1055 res = res ? lsb_io_uint16(s, &pdu->source_len) : False;
1056 res = res ? lsb_io_uint16(s, &pdu->caps_len ) : False;
1057
1058 if (pdu->source_len > 48)
1059 {
1060 fprintf(stderr, "RDP source descriptor too long\n");
1061 return False;
1062 }
1063
1064 res = res ? prs_io_uint8s(s, pdu->source, pdu->source_len) : False;
1065 res = res ? lsb_io_uint16(s, &pdu->num_caps ) : False;
1066 res = res ? lsb_io_uint16(s, &pdu->pad ) : False;
1067
1068 if (s->marshall)
1069 {
1070 capset = RDP_CAPSET_GENERAL;
1071 res = res ? lsb_io_uint16(s, &capset) : False;
1072 res = res ? rdp_io_general_caps(s, &pdu->general_caps) : False;
1073
1074 capset = RDP_CAPSET_BITMAP;
1075 res = res ? lsb_io_uint16(s, &capset) : False;
1076 res = res ? rdp_io_bitmap_caps (s, &pdu->bitmap_caps ) : False;
1077
1078 capset = RDP_CAPSET_ORDER;
1079 res = res ? lsb_io_uint16(s, &capset) : False;
1080 res = res ? rdp_io_order_caps (s, &pdu->order_caps ) : False;
1081
1082 capset = RDP_CAPSET_BMPCACHE;
1083 res = res ? lsb_io_uint16(s, &capset) : False;
1084 res = res ? rdp_io_bmpcache_caps(s, &pdu->bmpcache_caps) : False;
1085
1086 capset = RDP_CAPSET_COLCACHE;
1087 res = res ? lsb_io_uint16(s, &capset) : False;
1088 res = res ? rdp_io_colcache_caps(s, &pdu->colcache_caps) : False;
1089
1090 capset = RDP_CAPSET_ACTIVATE;
1091 res = res ? lsb_io_uint16(s, &capset) : False;
1092 res = res ? rdp_io_activate_caps(s, &pdu->activate_caps) : False;
1093
1094 capset = RDP_CAPSET_CONTROL;
1095 res = res ? lsb_io_uint16(s, &capset) : False;
1096 res = res ? rdp_io_control_caps(s, &pdu->control_caps) : False;
1097
1098 capset = RDP_CAPSET_POINTER;
1099 res = res ? lsb_io_uint16(s, &capset) : False;
1100 res = res ? rdp_io_pointer_caps(s, &pdu->pointer_caps) : False;
1101
1102 capset = RDP_CAPSET_SHARE;
1103 res = res ? lsb_io_uint16(s, &capset) : False;
1104 res = res ? rdp_io_share_caps (s, &pdu->share_caps ) : False;
1105
1106 capset = RDP_CAPSET_UNKNOWN;
1107 res = res ? lsb_io_uint16(s, &capset) : False;
1108 res = res ? rdp_io_unknown_caps(s, NULL) : False;
1109 }
1110 else
1111 {
1112 for (i = 0; i < pdu->num_caps; i++)
1113 {
1114 if (!res)
1115 return False;
1116
1117 if (!lsb_io_uint16(s, &capset))
1118 return False;
1119
1120 switch (capset)
1121 {
1122 case RDP_CAPSET_GENERAL:
1123 res = rdp_io_general_caps (s, &pdu->general_caps );
1124 break;
1125 case RDP_CAPSET_BITMAP:
1126 res = rdp_io_bitmap_caps (s, &pdu->bitmap_caps );
1127 break;
1128 case RDP_CAPSET_ORDER:
1129 res = rdp_io_order_caps (s, &pdu->order_caps );
1130 break;
1131 case RDP_CAPSET_BMPCACHE:
1132 res = rdp_io_bmpcache_caps(s, &pdu->bmpcache_caps);
1133 break;
1134 case RDP_CAPSET_CONTROL:
1135 res = rdp_io_control_caps (s, &pdu->control_caps );
1136 break;
1137 case RDP_CAPSET_ACTIVATE:
1138 res = rdp_io_activate_caps(s, &pdu->activate_caps);
1139 break;
1140 case RDP_CAPSET_POINTER:
1141 res = rdp_io_pointer_caps (s, &pdu->pointer_caps );
1142 break;
1143 case RDP_CAPSET_SHARE:
1144 res = rdp_io_share_caps (s, &pdu->share_caps );
1145 break;
1146 case RDP_CAPSET_COLCACHE:
1147 res = rdp_io_colcache_caps(s, &pdu->colcache_caps);
1148 break;
1149 default:
1150 fprintf(stderr, "Warning: Unrecognised capset %x\n",
1151 capset);
1152
1153 if (!lsb_io_uint16(s, &length))
1154 return False;
1155
1156 s->offset += (length - 4);
1157 }
1158 }
1159 }
1160
1161 return res;
1162 }
1163
1164 BOOL rdp_io_control_pdu(STREAM s, RDP_CONTROL_PDU *pdu)
1165 {
1166 BOOL res = True;
1167
1168 res = res ? lsb_io_uint16(s, &pdu->action ) : False;
1169 res = res ? lsb_io_uint16(s, &pdu->userid ) : False;
1170 res = res ? lsb_io_uint32(s, &pdu->controlid) : False;
1171
1172 return res;
1173 }
1174
1175 BOOL rdp_io_synchronize_pdu(STREAM s, RDP_SYNCHRONIZE_PDU *pdu)
1176 {
1177 BOOL res = True;
1178
1179 res = res ? lsb_io_uint16(s, &pdu->type ) : False;
1180 res = res ? lsb_io_uint16(s, &pdu->userid) : False;
1181
1182 return res;
1183 }
1184
1185 BOOL rdp_io_input_event(STREAM s, RDP_INPUT_EVENT *evt)
1186 {
1187 BOOL res = True;
1188
1189 res = res ? lsb_io_uint32(s, &evt->event_time) : False;
1190 res = res ? lsb_io_uint16(s, &evt->message_type) : False;
1191
1192 if (!res)
1193 return False;
1194
1195 switch (evt->message_type)
1196 {
1197 case RDP_INPUT_CODEPOINT:
1198 case RDP_INPUT_VIRTKEY:
1199 res = res ? lsb_io_uint16(s, &evt->device_flags) : False;
1200 res = res ? lsb_io_uint16(s, &evt->kbd_keycode ) : False;
1201 break;
1202 case RDP_INPUT_SYNCHRONIZE:
1203 case RDP_INPUT_UNKNOWN:
1204 case RDP_INPUT_MOUSE:
1205 res = res ? lsb_io_uint16(s, &evt->device_flags) : False;
1206 res = res ? lsb_io_uint16(s, &evt->mouse_x ) : False;
1207 res = res ? lsb_io_uint16(s, &evt->mouse_y ) : False;
1208 break;
1209 default:
1210 fprintf(stderr, "Unknown input type %d\n", evt->message_type);
1211 return False;
1212 }
1213
1214 return res;
1215 }
1216
1217 BOOL rdp_io_input_pdu(STREAM s, RDP_INPUT_PDU *pdu)
1218 {
1219 BOOL res = True;
1220 int i;
1221
1222 res = res ? lsb_io_uint16(s, &pdu->num_events) : False;
1223 res = res ? lsb_io_uint16(s, &pdu->pad ) : False;
1224
1225 if (pdu->num_events > RDP_MAX_EVENTS)
1226 {
1227 fprintf(stderr, "Too many events in one PDU\n");
1228 return False;
1229 }
1230
1231 for (i = 0; i < pdu->num_events; i++)
1232 {
1233 res = res ? rdp_io_input_event(s, &pdu->event[i]) : False;
1234 }
1235
1236 return res;
1237 }
1238
1239 BOOL rdp_io_font_info(STREAM s, RDP_FONT_INFO *font)
1240 {
1241 BOOL res = True;
1242
1243 res = res ? prs_io_uint8s(s, font->name, 32 ) : False;
1244 res = res ? lsb_io_uint16(s, &font->flags ) : False;
1245 res = res ? lsb_io_uint16(s, &font->width ) : False;
1246 res = res ? lsb_io_uint16(s, &font->height ) : False;
1247 res = res ? lsb_io_uint16(s, &font->xaspect ) : False;
1248 res = res ? lsb_io_uint16(s, &font->yaspect ) : False;
1249 res = res ? lsb_io_uint32(s, &font->signature) : False;
1250 res = res ? lsb_io_uint16(s, &font->codepage ) : False;
1251 res = res ? lsb_io_uint16(s, &font->ascent ) : False;
1252
1253 return res;
1254 }
1255
1256 BOOL rdp_io_font_pdu(STREAM s, RDP_FONT_PDU *pdu)
1257 {
1258 BOOL res = True;
1259 int i;
1260
1261 res = res ? lsb_io_uint16(s, &pdu->num_fonts ) : False;
1262 res = res ? lsb_io_uint16(s, &pdu->unknown1 ) : False;
1263 res = res ? lsb_io_uint16(s, &pdu->unknown2 ) : False;
1264 res = res ? lsb_io_uint16(s, &pdu->entry_size) : False;
1265
1266 if (pdu->num_fonts > RDP_MAX_FONTS)
1267 {
1268 fprintf(stderr, "Too many fonts in one PDU\n");
1269 return False;
1270 }
1271
1272 for (i = 0; i < pdu->num_fonts; i++)
1273 {
1274 res = res ? rdp_io_font_info(s, &pdu->font[i]) : False;
1275 }
1276
1277 return res;
1278 }
1279
1280 BOOL rdp_io_update_pdu(STREAM s, RDP_UPDATE_PDU *pdu)
1281 {
1282 BOOL res = True;
1283
1284 res = res ? lsb_io_uint16(s, &pdu->update_type) : False;
1285 res = res ? lsb_io_uint16(s, &pdu->pad ) : False;
1286
1287 return res;
1288 }
1289
1290 BOOL rdp_io_secondary_order(STREAM s, RDP_SECONDARY_ORDER *rso)
1291 {
1292 BOOL res = True;
1293
1294 res = res ? lsb_io_uint16(s, &rso->length) : False;
1295 res = res ? lsb_io_uint16(s, &rso->flags ) : False;
1296 res = res ? prs_io_uint8 (s, &rso->type ) : False;
1297
1298 return res;
1299 }
1300
1301 BOOL rdp_io_bitmap_header(STREAM s, RDP_BITMAP_HEADER *rdh)
1302 {
1303 BOOL res = True;
1304
1305 res = res ? prs_io_uint8 (s, &rdh->cache_id ) : False;
1306 res = res ? prs_io_uint8 (s, &rdh->pad1 ) : False;
1307 res = res ? prs_io_uint8 (s, &rdh->width ) : False;
1308 res = res ? prs_io_uint8 (s, &rdh->height ) : False;
1309 res = res ? prs_io_uint8 (s, &rdh->bpp ) : False;
1310 res = res ? lsb_io_uint16(s, &rdh->bufsize ) : False;
1311 res = res ? lsb_io_uint16(s, &rdh->cache_idx ) : False;
1312 res = res ? lsb_io_uint16(s, &rdh->pad2 ) : False;
1313 res = res ? lsb_io_uint16(s, &rdh->size ) : False;
1314 res = res ? lsb_io_uint16(s, &rdh->row_size ) : False;
1315 res = res ? lsb_io_uint16(s, &rdh->final_size) : False;
1316
1317 return res;
1318 }
1319
1320 BOOL rdp_io_pointer(STREAM s, RDP_POINTER *ptr)
1321 {
1322 BOOL res = True;
1323
1324 res = res ? lsb_io_uint16(s, &ptr->message) : False;
1325 res = res ? lsb_io_uint16(s, &ptr->pad ) : False;
1326 res = res ? lsb_io_uint16(s, &ptr->x ) : False;
1327 res = res ? lsb_io_uint16(s, &ptr->y ) : False;
1328
1329 return res;
1330 }

  ViewVC Help
Powered by ViewVC 1.1.26