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