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