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