Rev 5715 | Rev 5717 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3618 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
5663 | hidnplayr | 3 | ;; Copyright (C) KolibriOS team 2010-2015. All rights reserved. ;; |
3618 | hidnplayr | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
5668 | hidnplayr | 6 | ;; VNC client for KolibriOS ;; |
3618 | hidnplayr | 7 | ;; ;; |
8 | ;; Written by hidnplayr@kolibrios.org ;; |
||
9 | ;; ;; |
||
10 | ;; GNU GENERAL PUBLIC LICENSE ;; |
||
11 | ;; Version 2, June 1991 ;; |
||
12 | ;; ;; |
||
13 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
3545 | hidnplayr | 14 | |
15 | format binary as "" |
||
16 | |||
3618 | hidnplayr | 17 | __DEBUG__ = 1 |
5670 | hidnplayr | 18 | __DEBUG_LEVEL__ = 2 |
3618 | hidnplayr | 19 | |
5715 | hidnplayr | 20 | BITS_PER_PIXEL = 8 ; 8, 16 24 |
5677 | hidnplayr | 21 | |
3545 | hidnplayr | 22 | use32 |
23 | |||
24 | org 0x0 |
||
25 | |||
5663 | hidnplayr | 26 | db "MENUET01" ; 8 byte id |
3618 | hidnplayr | 27 | dd 0x01 ; header version |
28 | dd START ; start of code |
||
29 | dd I_END ; size of image |
||
30 | dd IM_END ; memory for app |
||
31 | dd IM_END ; esp |
||
5668 | hidnplayr | 32 | dd 0x0, 0x0 ; I_Param , I_Path |
3545 | hidnplayr | 33 | |
5663 | hidnplayr | 34 | include "../../macros.inc" |
35 | include "../../debug-fdo.inc" |
||
36 | include "../../proc32.inc" |
||
37 | include "../../dll.inc" |
||
38 | include "../../struct.inc" |
||
39 | include "../../develop/libraries/box_lib/trunk/box_lib.mac" |
||
40 | include "../../network.inc" |
||
3545 | hidnplayr | 41 | |
5663 | hidnplayr | 42 | struct pixel_format |
43 | bpp db ? |
||
44 | depth db ? |
||
45 | big_endian db ? |
||
46 | true_color db ? |
||
47 | red_max dw ? |
||
48 | green_max dw ? |
||
49 | blue_max dw ? |
||
50 | red_shift db ? |
||
51 | green_shift db ? |
||
52 | blue_shift db ? |
||
53 | padding rb 3 |
||
54 | ends |
||
3545 | hidnplayr | 55 | |
5663 | hidnplayr | 56 | struct framebuffer |
57 | width dw ? |
||
58 | height dw ? |
||
59 | pixelformat pixel_format |
||
60 | name_length dd ? |
||
61 | name rb 256 |
||
62 | ends |
||
63 | |||
5668 | hidnplayr | 64 | xpos = 4 |
5670 | hidnplayr | 65 | ypos = 21 |
5668 | hidnplayr | 66 | |
67 | TIMEOUT = 5 ; timeout in seconds |
||
68 | |||
69 | RECEIVE_BUFFER_SIZE = 8*1024*1024 ; 8 Mib |
||
70 | |||
71 | STATUS_INITIAL = 0 |
||
72 | STATUS_CONNECTING = 1 |
||
5670 | hidnplayr | 73 | STATUS_REQ_LOGIN = 2 |
74 | STATUS_LOGIN = 3 |
||
75 | STATUS_CONNECTED = 4 |
||
5680 | hidnplayr | 76 | STATUS_CLOSED = 5 |
5668 | hidnplayr | 77 | |
78 | STATUS_DISCONNECTED = 10 |
||
79 | STATUS_DNS_ERR = 11 |
||
80 | STATUS_SOCK_ERR = 12 |
||
81 | STATUS_CONNECT_ERR = 13 |
||
82 | STATUS_PROTO_ERR = 14 |
||
83 | STATUS_SECURITY_ERR = 15 |
||
84 | STATUS_LIB_ERR = 16 |
||
85 | STATUS_THREAD_ERR = 17 |
||
5680 | hidnplayr | 86 | STATUS_LOGIN_FAILED = 18 |
5668 | hidnplayr | 87 | |
5715 | hidnplayr | 88 | BYTES_PER_PIXEL = (BITS_PER_PIXEL + 7) / 8 |
89 | |||
5677 | hidnplayr | 90 | include "keymap.inc" |
5668 | hidnplayr | 91 | include "gui.inc" |
92 | include "network.inc" |
||
5663 | hidnplayr | 93 | include "raw.inc" |
5666 | hidnplayr | 94 | include "copyrect.inc" |
5668 | hidnplayr | 95 | include "rre.inc" |
5716 | hidnplayr | 96 | include "trle.inc" |
5680 | hidnplayr | 97 | include "des.inc" |
5663 | hidnplayr | 98 | |
3545 | hidnplayr | 99 | START: |
100 | |||
101 | mcall 68, 11 ; init heap |
||
102 | |||
5668 | hidnplayr | 103 | ; Load libraries |
3545 | hidnplayr | 104 | stdcall dll.Load, @IMPORT |
105 | test eax, eax |
||
5668 | hidnplayr | 106 | jz @f |
107 | mov [status], STATUS_LIB_ERR |
||
108 | @@: |
||
3545 | hidnplayr | 109 | |
5668 | hidnplayr | 110 | ; Present the user with the GUI and wait for network connection |
111 | call draw_gui |
||
3545 | hidnplayr | 112 | |
5668 | hidnplayr | 113 | ; Create main window |
114 | mcall 71, 1, name ; reset window caption (add server name) |
||
3545 | hidnplayr | 115 | |
5663 | hidnplayr | 116 | mov edx, dword[screen] |
3545 | hidnplayr | 117 | movzx esi, dx |
118 | shr edx, 16 |
||
119 | add edx, 2*xpos |
||
120 | add esi, ypos+xpos |
||
121 | mcall 67, 10, 10 ; resize the window |
||
122 | |||
5668 | hidnplayr | 123 | mcall 40, EVM_MOUSE + EVM_MOUSE_FILTER + EVM_KEY + EVM_REDRAW + EVM_BUTTON |
124 | |||
5670 | hidnplayr | 125 | mcall 66, 1, 1 ; Switch keyboard to scancode mode |
126 | |||
5677 | hidnplayr | 127 | call generate_keymap |
128 | |||
5668 | hidnplayr | 129 | redraw: |
130 | mcall 12, 1 |
||
131 | |||
132 | mov ebx, dword[screen] |
||
133 | movzx ecx, bx |
||
134 | shr ebx, 16 |
||
135 | mov edx, 0x74ffffff |
||
136 | mov edi, name |
||
137 | mcall 0 ; draw window |
||
138 | |||
139 | mcall 12, 2 |
||
140 | |||
5670 | hidnplayr | 141 | draw_framebuffer: |
142 | mcall 7, framebuffer_data, dword[screen], 0 |
||
143 | mov [update_framebuffer], 0 |
||
144 | |||
3545 | hidnplayr | 145 | mainloop: |
5668 | hidnplayr | 146 | cmp [status], STATUS_CONNECTED |
147 | jne draw_gui |
||
5670 | hidnplayr | 148 | cmp [update_framebuffer], 0 |
149 | jne draw_framebuffer |
||
3545 | hidnplayr | 150 | |
5670 | hidnplayr | 151 | mcall 23, 10 ; Check for event with 0,1s timeout |
5668 | hidnplayr | 152 | |
3545 | hidnplayr | 153 | dec eax |
154 | jz redraw |
||
155 | dec eax |
||
156 | jz key |
||
157 | dec eax |
||
158 | jz button |
||
159 | sub eax, 3 |
||
160 | jz mouse |
||
161 | jmp mainloop |
||
162 | |||
163 | key: |
||
5677 | hidnplayr | 164 | mcall 66, 3 |
5693 | hidnplayr | 165 | mov ebx, eax ; get modifier keys |
5677 | hidnplayr | 166 | |
5693 | hidnplayr | 167 | mcall 2 ; get key scancode |
168 | cmp ah, 224 ; extended keycode? |
||
169 | je .extended |
||
3545 | hidnplayr | 170 | |
5670 | hidnplayr | 171 | xor al, al |
172 | test ah, 0x80 ; key up? |
||
173 | jnz @f |
||
174 | inc al |
||
175 | @@: |
||
176 | mov byte[KeyEvent.down], al |
||
177 | |||
5693 | hidnplayr | 178 | movzx eax, ah |
5670 | hidnplayr | 179 | |
5677 | hidnplayr | 180 | test ebx, 100000b ; alt? |
5693 | hidnplayr | 181 | jz .no_alt |
182 | mov ax, [keymap_alt+eax*2] |
||
5677 | hidnplayr | 183 | jmp .key |
5693 | hidnplayr | 184 | .no_alt: |
185 | |||
5677 | hidnplayr | 186 | test ebx, 11b ; shift? |
5693 | hidnplayr | 187 | jz .no_shift |
188 | mov ax, [keymap_shift+eax*2] |
||
189 | jmp .key |
||
190 | .no_shift: |
||
191 | |||
192 | test ebx, 10000000b ; numlock ? |
||
193 | jz .no_numlock |
||
194 | cmp al, 71 |
||
195 | jb .no_numlock |
||
196 | cmp al, 83 |
||
197 | ja .no_numlock |
||
198 | mov ah, [keymap_numlock+eax-71] |
||
199 | xor al, al |
||
200 | jmp .key |
||
201 | |||
202 | .extended: ; extended keys always use regular keymap |
||
203 | mcall 2 |
||
204 | shr eax, 8 |
||
205 | jz mainloop |
||
206 | .no_numlock: |
||
207 | mov ax, [keymap+eax*2] |
||
5677 | hidnplayr | 208 | .key: |
5693 | hidnplayr | 209 | test ax, ax |
210 | jz mainloop |
||
5677 | hidnplayr | 211 | mov word[KeyEvent.key+2], ax |
212 | DEBUGF 1, "Sending key: 0x%x\n", ax |
||
5668 | hidnplayr | 213 | mcall send, [socketnum], KeyEvent, 8, 0 |
3545 | hidnplayr | 214 | jmp mainloop |
215 | |||
5677 | hidnplayr | 216 | |
5693 | hidnplayr | 217 | |
3545 | hidnplayr | 218 | mouse: |
5677 | hidnplayr | 219 | ; DEBUGF 1, "Sending pointer event\n" |
3545 | hidnplayr | 220 | |
221 | mcall 37, 1 ; get mouse pos |
||
222 | bswap eax |
||
5668 | hidnplayr | 223 | mov [PointerEvent.x], ax |
3545 | hidnplayr | 224 | shr eax, 16 |
5668 | hidnplayr | 225 | mov [PointerEvent.y], ax |
3545 | hidnplayr | 226 | |
227 | mcall 37, 2 ; get mouse buttons |
||
228 | test al, 00000010b ; test if right button was pressed (bit 1 in kolibri) |
||
229 | jz @f |
||
5663 | hidnplayr | 230 | add al, 00000010b ; in RFB protocol it is bit 2, so if we add bit 2 again, we"ll get bit 3 and bit 1 will remain the same |
3545 | hidnplayr | 231 | @@: |
5668 | hidnplayr | 232 | mov [PointerEvent.mask], al |
3545 | hidnplayr | 233 | |
5668 | hidnplayr | 234 | mcall send, [socketnum], PointerEvent, 6, 0 |
3545 | hidnplayr | 235 | jmp mainloop |
236 | |||
237 | button: |
||
238 | mcall 17 ; get id |
||
5680 | hidnplayr | 239 | mov [status], STATUS_CLOSED |
5677 | hidnplayr | 240 | mcall close, [socketnum] |
3545 | hidnplayr | 241 | mcall -1 |
242 | |||
243 | |||
5668 | hidnplayr | 244 | ; DATA AREA |
3545 | hidnplayr | 245 | |
5668 | hidnplayr | 246 | include_debug_strings |
3545 | hidnplayr | 247 | |
5693 | hidnplayr | 248 | keymap_numlock: |
249 | db '7', '8', '9', '-' |
||
250 | db '4', '5', '6', '+' |
||
251 | db '1', '2', '3' |
||
252 | db '0', '.' |
||
253 | |||
5668 | hidnplayr | 254 | HandShake db "RFB 003.003", 10 |
3545 | hidnplayr | 255 | |
5668 | hidnplayr | 256 | ClientInit db 0 ; not shared |
3545 | hidnplayr | 257 | |
5668 | hidnplayr | 258 | SetPixelFormat32 db 0 ; setPixelformat |
259 | db 0, 0, 0 ; padding |
||
260 | .bpp db 32 ; bits per pixel |
||
261 | .depth db 32 ; depth |
||
262 | .big_endian db 0 ; big-endian flag |
||
263 | .true_color db 1 ; true-colour flag |
||
264 | .red_max db 0, 255 ; red-max |
||
265 | .green_max db 0, 255 ; green-max |
||
266 | .blue_max db 0, 255 ; blue-max |
||
267 | .red_shif db 0 ; red-shift |
||
268 | .green_shift db 8 ; green-shift |
||
269 | .blue_shift db 16 ; blue-shift |
||
270 | db 0, 0, 0 ; padding |
||
3545 | hidnplayr | 271 | |
5677 | hidnplayr | 272 | SetPixelFormat24 db 0 ; setPixelformat |
273 | db 0, 0, 0 ; padding |
||
274 | .bpp db 24 ; bits per pixel |
||
275 | .depth db 24 ; depth |
||
276 | .big_endian db 0 ; big-endian flag |
||
277 | .true_color db 1 ; true-colour flag |
||
278 | .red_max db 0, 255 ; red-max |
||
279 | .green_max db 0, 255 ; green-max |
||
280 | .blue_max db 0, 255 ; blue-max |
||
281 | .red_shift db 16 ; red-shift |
||
282 | .green_shift db 8 ; green-shift |
||
283 | .blue_shift db 0 ; blue-shift |
||
284 | db 0, 0, 0 ; padding |
||
285 | |||
5668 | hidnplayr | 286 | SetPixelFormat16 db 0 ; setPixelformat |
287 | db 0, 0, 0 ; padding |
||
288 | .bpp db 16 ; bits per pixel |
||
5677 | hidnplayr | 289 | .depth db 16 ; depth |
5668 | hidnplayr | 290 | .big_endian db 0 ; big-endian flag |
291 | .true_color db 1 ; true-colour flag |
||
292 | .red_max db 0, 31 ; red-max |
||
5677 | hidnplayr | 293 | .green_max db 0, 63 ; green-max |
5668 | hidnplayr | 294 | .blue_max db 0, 31 ; blue-max |
5677 | hidnplayr | 295 | .red_shift db 11 ; red-shift |
5668 | hidnplayr | 296 | .green_shift db 5 ; green-shift |
5677 | hidnplayr | 297 | .blue_shift db 0 ; blue-shift |
5668 | hidnplayr | 298 | db 0, 0, 0 ; padding |
3545 | hidnplayr | 299 | |
5668 | hidnplayr | 300 | SetPixelFormat8 db 0 ; setPixelformat |
301 | db 0, 0, 0 ; padding |
||
302 | .bpp db 8 ; bits per pixel |
||
5677 | hidnplayr | 303 | .depth db 8 ; depth |
5668 | hidnplayr | 304 | .big_endian db 0 ; big-endian flag |
305 | .true_color db 1 ; true-colour flag |
||
5677 | hidnplayr | 306 | .red_max db 0, 7 ; red-max |
307 | .green_max db 0, 7 ; green-max |
||
5668 | hidnplayr | 308 | .blue_max db 0, 3 ; blue-max |
5677 | hidnplayr | 309 | .red_shift db 0 ; red-shift |
310 | .green_shift db 3 ; green-shift |
||
311 | .blue_shift db 6 ; blue-shift |
||
5668 | hidnplayr | 312 | db 0, 0, 0 ; padding |
3545 | hidnplayr | 313 | |
5668 | hidnplayr | 314 | SetEncodings db 2 ; setEncodings |
315 | db 0 ; padding |
||
5715 | hidnplayr | 316 | db 0, 3 ; number of encodings |
5668 | hidnplayr | 317 | db 0, 0, 0, 1 ; Copyrect encoding |
5715 | hidnplayr | 318 | db 0, 0, 0, 2 ; RRE |
319 | db 0, 0, 0, 0 ; raw encoding |
||
5668 | hidnplayr | 320 | ; db 0, 0, 0, 5 ; HexTile |
321 | ; db 0, 0, 0, 15 ; TRLE |
||
322 | ; db 0, 0, 0, 16 ; ZRLE |
||
5708 | hidnplayr | 323 | .length = $ - SetEncodings |
3545 | hidnplayr | 324 | |
5668 | hidnplayr | 325 | FramebufferUpdateRequest db 3 |
326 | .inc db 0 ; incremental |
||
327 | .x dw 0 |
||
328 | .y dw 0 |
||
329 | .width dw 0 |
||
330 | .height dw 0 |
||
3545 | hidnplayr | 331 | |
5668 | hidnplayr | 332 | KeyEvent db 4 ; keyevent |
333 | .down db 0 ; down-flag |
||
334 | dw 0 ; padding |
||
335 | .key dd 0 ; key |
||
3545 | hidnplayr | 336 | |
5668 | hidnplayr | 337 | PointerEvent db 5 ; pointerevent |
338 | .mask db 0 ; button-mask |
||
339 | .x dw 0 ; x-position |
||
340 | .y dw 0 ; y-position |
||
3545 | hidnplayr | 341 | |
342 | |||
343 | sockaddr1: |
||
5668 | hidnplayr | 344 | dw AF_INET4 |
345 | .port dw 0x0c17 ; 5900 |
||
346 | .ip dd 0 |
||
347 | rb 10 |
||
3545 | hidnplayr | 348 | |
5668 | hidnplayr | 349 | beep db 0x85, 0x25, 0x85, 0x40, 0 |
5663 | hidnplayr | 350 | |
5670 | hidnplayr | 351 | status dd STATUS_INITIAL |
352 | update_gui dd 0 |
||
353 | mouse_dd dd 0 |
||
354 | update_framebuffer dd 0 |
||
5668 | hidnplayr | 355 | |
5693 | hidnplayr | 356 | URLbox edit_box 235, 70, 20, 0xffffff, 0x6f9480, 0, 0, 0, 65535, serveraddr, mouse_dd, ed_focus, 0, 0 |
357 | USERbox edit_box 215, 90, 10, 0xffffff, 0x6f9480, 0, 0, 0, 127, username, mouse_dd, ed_focus, 0, 0 |
||
358 | PASSbox edit_box 215, 90, 30, 0xffffff, 0x6f9480, 0, 0, 0, 127, password, mouse_dd, ed_pass, 0, 0 |
||
5663 | hidnplayr | 359 | |
5668 | hidnplayr | 360 | serverstr db "server:" |
361 | userstr db "username:" |
||
362 | passstr db "password:" |
||
5670 | hidnplayr | 363 | connectstr db "Connect" |
364 | loginstr db "Log in" |
||
5668 | hidnplayr | 365 | loginstr_e: |
366 | |||
367 | sz_err_disconnected db "Server closed connection unexpectedly.", 0 |
||
368 | sz_err_dns db "Could not resolve hostname.", 0 |
||
369 | sz_err_sock db "Could not open socket.", 0 |
||
370 | sz_err_connect db "Could not connect to the server.", 0 |
||
371 | sz_err_proto db "A protocol error has occured.", 0 |
||
372 | sz_err_security db "Server requested an unsupported security type.", 0 |
||
373 | sz_err_library db "Could not load needed libraries.", 0 |
||
374 | sz_err_thread db "Could not create thread.", 0 |
||
5680 | hidnplayr | 375 | sz_err_login_failed db "Login failed.", 0 |
5668 | hidnplayr | 376 | |
377 | err_msg dd sz_err_disconnected |
||
378 | dd sz_err_dns |
||
379 | dd sz_err_sock |
||
380 | dd sz_err_connect |
||
381 | dd sz_err_proto |
||
382 | dd sz_err_security |
||
383 | dd sz_err_library |
||
384 | dd sz_err_thread |
||
5680 | hidnplayr | 385 | dd sz_err_login_failed |
5668 | hidnplayr | 386 | |
3545 | hidnplayr | 387 | ; import |
388 | align 4 |
||
389 | @IMPORT: |
||
390 | |||
5663 | hidnplayr | 391 | library network, "network.obj",\ |
392 | box_lib, "box_lib.obj",\ |
||
393 | archiver, "archiver.obj" |
||
3545 | hidnplayr | 394 | |
5663 | hidnplayr | 395 | import network,\ |
396 | getaddrinfo, "getaddrinfo", \ |
||
397 | freeaddrinfo, "freeaddrinfo", \ |
||
398 | inet_ntoa, "inet_ntoa" |
||
3545 | hidnplayr | 399 | |
5663 | hidnplayr | 400 | import box_lib,\ |
401 | edit_box_draw, "edit_box",\ |
||
402 | edit_box_key, "edit_box_key",\ |
||
403 | edit_box_mouse, "edit_box_mouse",\ |
||
404 | scrollbar_v_draw, "scrollbar_v_draw",\ |
||
405 | scrollbar_v_mouse, "scrollbar_v_mouse",\ |
||
406 | scrollbar_h_draw, "scrollbar_h_draw",\ |
||
407 | scrollbar_h_mouse, "scrollbar_h_mouse" |
||
408 | |||
409 | import archiver,\ |
||
410 | deflate_unpack, "deflate_unpack" |
||
411 | |||
5668 | hidnplayr | 412 | name db "VNC viewer " |
413 | .dash db 0, " " |
||
5663 | hidnplayr | 414 | |
3545 | hidnplayr | 415 | I_END: |
416 | |||
5663 | hidnplayr | 417 | servername rb 64+1 |
3545 | hidnplayr | 418 | |
5663 | hidnplayr | 419 | socketnum dd ? |
420 | datapointer dd ? |
||
5668 | hidnplayr | 421 | |
5663 | hidnplayr | 422 | rectangles dw ? |
3545 | hidnplayr | 423 | |
5663 | hidnplayr | 424 | rectangle: |
5668 | hidnplayr | 425 | .x dd ? |
426 | .y dd ? |
||
427 | .width dd ? |
||
428 | .height dd ? |
||
3545 | hidnplayr | 429 | |
5668 | hidnplayr | 430 | subrectangles dd ? |
431 | |||
432 | subrectangle: |
||
433 | .x dd ? |
||
434 | .y dd ? |
||
435 | .width dd ? |
||
436 | .height dd ? |
||
437 | |||
5663 | hidnplayr | 438 | screen: ; Remote screen resolution |
439 | .height dw ? |
||
440 | .width dw ? |
||
3545 | hidnplayr | 441 | |
5716 | hidnplayr | 442 | palette rd 128 ; TRLE/ZRLE |
443 | palettesize db ? ; TRLE/ZRLE |
||
444 | |||
5677 | hidnplayr | 445 | keymap rw 128 |
446 | keymap_shift rw 128 |
||
447 | keymap_alt rw 128 |
||
5670 | hidnplayr | 448 | username rb 128 |
449 | password rb 128 |
||
5680 | hidnplayr | 450 | keys rd 32*2 ; DES keys for VNC authentication |
451 | |||
5663 | hidnplayr | 452 | serveraddr rb 65536 |
5668 | hidnplayr | 453 | receive_buffer rb RECEIVE_BUFFER_SIZE |
5677 | hidnplayr | 454 | framebuffer_data rb 1280*1024*3 ; framebuffer |
3545 | hidnplayr | 455 | |
5663 | hidnplayr | 456 | rb 0x1000 |
3545 | hidnplayr | 457 | thread_stack: |
5663 | hidnplayr | 458 | rb 0x1000 |
3545 | hidnplayr | 459 | IM_END: |
460 |