1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
|
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
xrdp: A Remote Desktop Protocol server.
Copyright (C) Jay Sorg 2005
librdp main header file
*/
/* include other h files */
#include "arch.h"
#include "parse.h"
#include "os_calls.h"
#include "ssl_calls.h"
#include "xrdp_constants.h"
#include "defines.h"
struct rdp_brush
{
int xorigin;
int yorigin;
int style;
char pattern[8];
};
struct rdp_pen
{
int style;
int width;
int color;
};
struct rdp_colormap
{
int ncolors;
int colors[256];
};
struct rdp_bitmap
{
int width;
int height;
int bpp;
char* data;
};
struct rdp_cursor
{
int x;
int y;
int width;
int height;
char mask[(32 * 32) / 8];
char data[(32 * 32) * 3];
};
/* tcp */
struct rdp_tcp
{
int sck;
int sck_closed;
struct rdp_iso* iso_layer; /* owner */
};
/* iso */
struct rdp_iso
{
struct rdp_mcs* mcs_layer; /* owner */
struct rdp_tcp* tcp_layer;
};
/* mcs */
struct rdp_mcs
{
struct rdp_sec* sec_layer; /* owner */
struct rdp_iso* iso_layer;
int userid;
struct stream* client_mcs_data;
struct stream* server_mcs_data;
};
/* sec */
struct rdp_sec
{
struct rdp_rdp* rdp_layer; /* owner */
struct rdp_mcs* mcs_layer;
struct rdp_lic* lic_layer;
char server_random[32];
char client_random[64];
char client_crypt_random[72];
struct stream* client_mcs_data;
struct stream* server_mcs_data;
int decrypt_use_count;
int encrypt_use_count;
char decrypt_key[16];
char encrypt_key[16];
char decrypt_update_key[16];
char encrypt_update_key[16];
int rc4_key_size; /* 1 = 40-bit, 2 = 128-bit */
int rc4_key_len; /* 8 or 16 */
int crypt_level; /* 1 = low, 2 = medium, 3 = high */
char sign_key[16];
void* decrypt_rc4_info;
void* encrypt_rc4_info;
};
/* licence */
struct rdp_lic
{
struct rdp_sec* sec_layer; /* owner */
char licence_key[16];
char licence_sign_key[16];
int licence_issued;
};
/* rdp */
struct rdp_rdp
{
struct mod* mod;
struct rdp_sec* sec_layer;
struct rdp_orders* orders;
int share_id;
int use_rdp5;
int bitmap_compression;
int bitmap_cache;
int desktop_save;
int polygon_ellipse_orders;
int rec_mode;
int rec_fd;
/* cache */
struct rdp_colormap colormap;
struct rdp_cursor cursors[32];
};
struct rdp_orders_state
{
/* order stuff */
int order_type;
/* clip state */
int clip_left;
int clip_top;
int clip_right;
int clip_bottom;
/* text order state */
int text_font;
int text_flags;
int text_opcode;
int text_mixmode;
int text_fgcolor;
int text_bgcolor;
int text_clipleft;
int text_cliptop;
int text_clipright;
int text_clipbottom;
int text_boxleft;
int text_boxtop;
int text_boxright;
int text_boxbottom;
struct rdp_brush text_brush;
int text_x;
int text_y;
int text_length;
char text_text[256];
/* destblt order state */
int dest_x;
int dest_y;
int dest_cx;
int dest_cy;
int dest_opcode;
/* patblt order state */
int pat_x;
int pat_y;
int pat_cx;
int pat_cy;
int pat_opcode;
int pat_bgcolor;
int pat_fgcolor;
struct rdp_brush pat_brush;
/* screenblt order state */
int screenblt_x;
int screenblt_y;
int screenblt_cx;
int screenblt_cy;
int screenblt_opcode;
int screenblt_srcx;
int screenblt_srcy;
/* line order state */
int line_mixmode;
int line_startx;
int line_starty;
int line_endx;
int line_endy;
int line_bgcolor;
int line_opcode;
struct rdp_pen line_pen;
/* rect order state */
int rect_x;
int rect_y;
int rect_cx;
int rect_cy;
int rect_color;
/* desksave order state */
int desksave_offset;
int desksave_left;
int desksave_top;
int desksave_right;
int desksave_bottom;
int desksave_action;
/* memblt order state */
int memblt_cache_id;
int memblt_color_table;
int memblt_x;
int memblt_y;
int memblt_cx;
int memblt_cy;
int memblt_opcode;
int memblt_srcx;
int memblt_srcy;
int memblt_cache_idx;
/* polyline order state */
int polyline_x;
int polyline_y;
int polyline_opcode;
int polyline_fgcolor;
int polyline_lines;
int polyline_datasize;
char polyline_data[256];
};
/* orders */
struct rdp_orders
{
struct rdp_rdp* rdp_layer;
/* order state */
struct rdp_orders_state state;
/* cache */
struct rdp_colormap* cache_colormap[6];
struct rdp_bitmap* cache_bitmap[3][600];
};
struct mod
{
int size; /* size of this struct */
/* client functions */
int (*mod_start)(struct mod* v, int w, int h, int bpp);
int (*mod_connect)(struct mod* v);
int (*mod_event)(struct mod* v, int msg, long param1, long param2,
long param3, long param4);
int (*mod_signal)(struct mod* v);
int (*mod_end)(struct mod* v);
int (*mod_set_param)(struct mod* v, char* name, char* value);
/* server functions */
int (*server_begin_update)(struct mod* v);
int (*server_end_update)(struct mod* v);
int (*server_fill_rect)(struct mod* v, int x, int y, int cx, int cy);
int (*server_screen_blt)(struct mod* v, int x, int y, int cx, int cy,
int srcx, int srcy);
int (*server_paint_rect)(struct mod* v, int x, int y, int cx, int cy,
char* data, int width, int height, int srcx, int srcy);
int (*server_set_cursor)(struct mod* v, int x, int y, char* data, char* mask);
int (*server_palette)(struct mod* v, int* palette);
int (*server_msg)(struct mod* v, char* msg, int code);
int (*server_is_term)(struct mod* v);
int (*server_set_clip)(struct mod* v, int x, int y, int cx, int cy);
int (*server_reset_clip)(struct mod* v);
int (*server_set_fgcolor)(struct mod* v, int fgcolor);
int (*server_set_bgcolor)(struct mod* v, int bgcolor);
int (*server_set_opcode)(struct mod* v, int opcode);
int (*server_set_mixmode)(struct mod* v, int mixmode);
int (*server_set_brush)(struct mod* v, int x_orgin, int y_orgin,
int style, char* pattern);
int (*server_set_pen)(struct mod* v, int style,
int width);
int (*server_draw_line)(struct mod* v, int x1, int y1, int x2, int y2);
int (*server_add_char)(struct mod* v, int font, int charactor,
int offset, int baseline,
int width, int height, char* data);
int (*server_draw_text)(struct mod* v, int font,
int flags, int mixmode, int clip_left, int clip_top,
int clip_right, int clip_bottom,
int box_left, int box_top,
int box_right, int box_bottom,
int x, int y, char* data, int data_len);
int (*server_reset)(struct mod* v, int width, int height, int bpp);
/* common */
long handle; /* pointer to self as long */
long wm;
long painter;
int sck;
/* mod data */
struct rdp_rdp* rdp_layer;
int width;
int height;
int rdp_bpp;
int xrdp_bpp;
char ip[256];
char port[256];
char username[256];
char password[256];
char hostname[256];
char domain[256];
char program[256];
char directory[256];
int keylayout;
int up_and_running;
struct stream* in_s;
};
/* rdp_tcp.c */
struct rdp_tcp* APP_CC
rdp_tcp_create(struct rdp_iso* owner);
void APP_CC
rdp_tcp_delete(struct rdp_tcp* self);
int APP_CC
rdp_tcp_init(struct rdp_tcp* self, struct stream* s);
int APP_CC
rdp_tcp_recv(struct rdp_tcp* self, struct stream* s, int len);
int APP_CC
rdp_tcp_send(struct rdp_tcp* self, struct stream* s);
int APP_CC
rdp_tcp_connect(struct rdp_tcp* self, char* ip, char* port);
int APP_CC
rdp_tcp_disconnect(struct rdp_tcp* self);
/* rdp_ico.c */
struct rdp_iso* APP_CC
rdp_iso_create(struct rdp_mcs* owner);
void APP_CC
rdp_iso_delete(struct rdp_iso* self);
int APP_CC
rdp_iso_recv(struct rdp_iso* self, struct stream* s);
int APP_CC
rdp_iso_init(struct rdp_iso* self, struct stream* s);
int APP_CC
rdp_iso_send(struct rdp_iso* self, struct stream* s);
int APP_CC
rdp_iso_connect(struct rdp_iso* self, char* ip, char* port);
int APP_CC
rdp_iso_disconnect(struct rdp_iso* self);
/* rdp_mcs.c */
struct rdp_mcs* APP_CC
rdp_mcs_create(struct rdp_sec* owner,
struct stream* client_mcs_data,
struct stream* server_mcs_data);
void APP_CC
rdp_mcs_delete(struct rdp_mcs* self);
int APP_CC
rdp_mcs_init(struct rdp_mcs* self, struct stream* s);
int APP_CC
rdp_mcs_send(struct rdp_mcs* self, struct stream* s);
int APP_CC
rdp_mcs_connect(struct rdp_mcs* self, char* ip, char* port);
int APP_CC
rdp_mcs_recv(struct rdp_mcs* self, struct stream* s, int* chan);
/* rdp_sec.c */
struct rdp_sec* APP_CC
rdp_sec_create(struct rdp_rdp* owner);
void APP_CC
rdp_sec_delete(struct rdp_sec* self);
int APP_CC
rdp_sec_init(struct rdp_sec* self, struct stream* s, int flags);
int APP_CC
rdp_sec_send(struct rdp_sec* self, struct stream* s, int flags);
int APP_CC
rdp_sec_recv(struct rdp_sec* self, struct stream* s, int* chan);
int APP_CC
rdp_sec_connect(struct rdp_sec* self, char* ip, char* port);
void APP_CC
rdp_sec_buf_out_uint32(char* buffer, int value);
void APP_CC
rdp_sec_hash_16(char* out, char* in, char* salt1, char* salt2);
void APP_CC
rdp_sec_hash_48(char* out, char* in, char* salt1, char* salt2, int salt);
void APP_CC
rdp_sec_sign(char* signature, int siglen, char* session_key, int keylen,
char* data, int datalen);
/* rdp_rdp.c */
struct rdp_rdp* APP_CC
rdp_rdp_create(struct mod* owner);
void APP_CC
rdp_rdp_delete(struct rdp_rdp* self);
int APP_CC
rdp_rdp_connect(struct rdp_rdp* self, char* ip, char* port);
int APP_CC
rdp_rdp_send_input(struct rdp_rdp* self, struct stream* s,
int time, int message_type,
int device_flags, int param1, int param2);
int APP_CC
rdp_rdp_send_invalidate(struct rdp_rdp* self, struct stream* s,
int left, int top, int width, int height);
int APP_CC
rdp_rdp_recv(struct rdp_rdp* self, struct stream* s, int* type);
int APP_CC
rdp_rdp_process_data_pdu(struct rdp_rdp* self, struct stream* s);
int APP_CC
rdp_rdp_process_demand_active(struct rdp_rdp* self, struct stream* s);
void APP_CC
rdp_rdp_out_unistr(struct stream* s, char* text);
int APP_CC
rdp_rec_check_file(struct rdp_rdp* self);
int APP_CC
rdp_rec_write_item(struct rdp_rdp* self, struct stream* s);
/* rdp_bitmap.c */
int APP_CC
rdp_bitmap_decompress(char* output, int width, int height, char* input,
int size, int Bpp);
/* rdp_orders.c */
struct rdp_orders* APP_CC
rdp_orders_create(struct rdp_rdp* owner);
void APP_CC
rdp_orders_delete(struct rdp_orders* self);
void APP_CC
rdp_orders_reset_state(struct rdp_orders* self);
int APP_CC
rdp_orders_process_orders(struct rdp_orders* self, struct stream* s,
int num_orders);
char* APP_CC
rdp_orders_convert_bitmap(int in_bpp, int out_bpp, char* bmpdata,
int width, int height, int* palette);
int APP_CC
rdp_orders_convert_color(int in_bpp, int out_bpp, int in_color, int* palette);
/* rdp_lic.c */
struct rdp_lic* APP_CC
rdp_lic_create(struct rdp_sec* owner);
void APP_CC
rdp_lic_delete(struct rdp_lic* self);
void APP_CC
rdp_lic_process(struct rdp_lic* self, struct stream* s);
|