Rev 5668 | Rev 5677 | 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 | |
3545 | hidnplayr | 20 | use32 |
21 | |||
22 | org 0x0 |
||
23 | |||
5663 | hidnplayr | 24 | db "MENUET01" ; 8 byte id |
3618 | hidnplayr | 25 | dd 0x01 ; header version |
26 | dd START ; start of code |
||
27 | dd I_END ; size of image |
||
28 | dd IM_END ; memory for app |
||
29 | dd IM_END ; esp |
||
5668 | hidnplayr | 30 | dd 0x0, 0x0 ; I_Param , I_Path |
3545 | hidnplayr | 31 | |
5663 | hidnplayr | 32 | include "../../macros.inc" |
33 | include "../../debug-fdo.inc" |
||
34 | include "../../proc32.inc" |
||
35 | include "../../dll.inc" |
||
36 | include "../../struct.inc" |
||
37 | include "../../develop/libraries/box_lib/trunk/box_lib.mac" |
||
38 | include "../../network.inc" |
||
3545 | hidnplayr | 39 | |
5663 | hidnplayr | 40 | struct pixel_format |
41 | bpp db ? |
||
42 | depth db ? |
||
43 | big_endian db ? |
||
44 | true_color db ? |
||
45 | red_max dw ? |
||
46 | green_max dw ? |
||
47 | blue_max dw ? |
||
48 | red_shift db ? |
||
49 | green_shift db ? |
||
50 | blue_shift db ? |
||
51 | padding rb 3 |
||
52 | ends |
||
3545 | hidnplayr | 53 | |
5663 | hidnplayr | 54 | struct framebuffer |
55 | width dw ? |
||
56 | height dw ? |
||
57 | pixelformat pixel_format |
||
58 | name_length dd ? |
||
59 | name rb 256 |
||
60 | ends |
||
61 | |||
5668 | hidnplayr | 62 | xpos = 4 |
5670 | hidnplayr | 63 | ypos = 21 |
5668 | hidnplayr | 64 | |
65 | TIMEOUT = 5 ; timeout in seconds |
||
66 | |||
67 | RECEIVE_BUFFER_SIZE = 8*1024*1024 ; 8 Mib |
||
68 | |||
69 | STATUS_INITIAL = 0 |
||
70 | STATUS_CONNECTING = 1 |
||
5670 | hidnplayr | 71 | STATUS_REQ_LOGIN = 2 |
72 | STATUS_LOGIN = 3 |
||
73 | STATUS_CONNECTED = 4 |
||
5668 | hidnplayr | 74 | |
75 | STATUS_DISCONNECTED = 10 |
||
76 | STATUS_DNS_ERR = 11 |
||
77 | STATUS_SOCK_ERR = 12 |
||
78 | STATUS_CONNECT_ERR = 13 |
||
79 | STATUS_PROTO_ERR = 14 |
||
80 | STATUS_SECURITY_ERR = 15 |
||
81 | STATUS_LIB_ERR = 16 |
||
82 | STATUS_THREAD_ERR = 17 |
||
83 | |||
84 | include "gui.inc" |
||
85 | include "network.inc" |
||
5663 | hidnplayr | 86 | include "raw.inc" |
5666 | hidnplayr | 87 | include "copyrect.inc" |
5668 | hidnplayr | 88 | include "rre.inc" |
5663 | hidnplayr | 89 | |
3545 | hidnplayr | 90 | START: |
91 | |||
92 | mcall 68, 11 ; init heap |
||
93 | |||
5668 | hidnplayr | 94 | ; Load libraries |
3545 | hidnplayr | 95 | stdcall dll.Load, @IMPORT |
96 | test eax, eax |
||
5668 | hidnplayr | 97 | jz @f |
98 | mov [status], STATUS_LIB_ERR |
||
99 | @@: |
||
3545 | hidnplayr | 100 | |
5668 | hidnplayr | 101 | ; Present the user with the GUI and wait for network connection |
102 | call draw_gui |
||
3545 | hidnplayr | 103 | |
5668 | hidnplayr | 104 | ; Create main window |
105 | mcall 71, 1, name ; reset window caption (add server name) |
||
3545 | hidnplayr | 106 | |
5663 | hidnplayr | 107 | mov edx, dword[screen] |
3545 | hidnplayr | 108 | movzx esi, dx |
109 | shr edx, 16 |
||
110 | add edx, 2*xpos |
||
111 | add esi, ypos+xpos |
||
112 | mcall 67, 10, 10 ; resize the window |
||
113 | |||
5668 | hidnplayr | 114 | mcall 40, EVM_MOUSE + EVM_MOUSE_FILTER + EVM_KEY + EVM_REDRAW + EVM_BUTTON |
115 | |||
5670 | hidnplayr | 116 | mcall 66, 1, 1 ; Switch keyboard to scancode mode |
117 | mcall 26, 2, 1, keymap ; Read keymap |
||
118 | |||
5668 | hidnplayr | 119 | redraw: |
120 | mcall 12, 1 |
||
121 | |||
122 | mov ebx, dword[screen] |
||
123 | movzx ecx, bx |
||
124 | shr ebx, 16 |
||
125 | mov edx, 0x74ffffff |
||
126 | mov edi, name |
||
127 | mcall 0 ; draw window |
||
128 | |||
129 | mcall 12, 2 |
||
130 | |||
5670 | hidnplayr | 131 | draw_framebuffer: |
132 | mcall 7, framebuffer_data, dword[screen], 0 |
||
133 | mov [update_framebuffer], 0 |
||
134 | |||
3545 | hidnplayr | 135 | mainloop: |
5668 | hidnplayr | 136 | cmp [status], STATUS_CONNECTED |
137 | jne draw_gui |
||
5670 | hidnplayr | 138 | cmp [update_framebuffer], 0 |
139 | jne draw_framebuffer |
||
3545 | hidnplayr | 140 | |
5670 | hidnplayr | 141 | mcall 23, 10 ; Check for event with 0,1s timeout |
5668 | hidnplayr | 142 | |
3545 | hidnplayr | 143 | dec eax |
144 | jz redraw |
||
145 | dec eax |
||
146 | jz key |
||
147 | dec eax |
||
148 | jz button |
||
149 | sub eax, 3 |
||
150 | jz mouse |
||
151 | jmp mainloop |
||
152 | |||
153 | key: |
||
154 | mcall 2 |
||
5670 | hidnplayr | 155 | cmp ah, 224 ; ext |
156 | je mainloop ;; TODO |
||
3545 | hidnplayr | 157 | |
5670 | hidnplayr | 158 | xor al, al |
159 | test ah, 0x80 ; key up? |
||
160 | jnz @f |
||
161 | inc al |
||
162 | @@: |
||
163 | mov byte[KeyEvent.down], al |
||
164 | |||
165 | shr eax, 8 |
||
166 | and al, 0x7f |
||
167 | mov al, [keymap+eax] |
||
168 | mov byte[KeyEvent.key+3], al |
||
169 | |||
170 | DEBUGF 1, "Sending key: 0x%x\n", al |
||
171 | |||
5668 | hidnplayr | 172 | mcall send, [socketnum], KeyEvent, 8, 0 |
3545 | hidnplayr | 173 | jmp mainloop |
174 | |||
175 | mouse: |
||
5668 | hidnplayr | 176 | ; DEBUGF 1, "Sending mouse event\n" |
3545 | hidnplayr | 177 | |
178 | mcall 37, 1 ; get mouse pos |
||
179 | bswap eax |
||
5668 | hidnplayr | 180 | mov [PointerEvent.x], ax |
3545 | hidnplayr | 181 | shr eax, 16 |
5668 | hidnplayr | 182 | mov [PointerEvent.y], ax |
3545 | hidnplayr | 183 | |
184 | mcall 37, 2 ; get mouse buttons |
||
185 | test al, 00000010b ; test if right button was pressed (bit 1 in kolibri) |
||
186 | jz @f |
||
5663 | hidnplayr | 187 | 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 | 188 | @@: |
5668 | hidnplayr | 189 | mov [PointerEvent.mask], al |
3545 | hidnplayr | 190 | |
5668 | hidnplayr | 191 | mcall send, [socketnum], PointerEvent, 6, 0 |
3545 | hidnplayr | 192 | jmp mainloop |
193 | |||
194 | button: |
||
195 | mcall 17 ; get id |
||
196 | mcall -1 |
||
197 | |||
198 | |||
5668 | hidnplayr | 199 | ; DATA AREA |
3545 | hidnplayr | 200 | |
5668 | hidnplayr | 201 | include_debug_strings |
3545 | hidnplayr | 202 | |
5668 | hidnplayr | 203 | HandShake db "RFB 003.003", 10 |
3545 | hidnplayr | 204 | |
5668 | hidnplayr | 205 | ClientInit db 0 ; not shared |
3545 | hidnplayr | 206 | |
5668 | hidnplayr | 207 | SetPixelFormat32 db 0 ; setPixelformat |
208 | db 0, 0, 0 ; padding |
||
209 | .bpp db 32 ; bits per pixel |
||
210 | .depth db 32 ; depth |
||
211 | .big_endian db 0 ; big-endian flag |
||
212 | .true_color db 1 ; true-colour flag |
||
213 | .red_max db 0, 255 ; red-max |
||
214 | .green_max db 0, 255 ; green-max |
||
215 | .blue_max db 0, 255 ; blue-max |
||
216 | .red_shif db 0 ; red-shift |
||
217 | .green_shift db 8 ; green-shift |
||
218 | .blue_shift db 16 ; blue-shift |
||
219 | db 0, 0, 0 ; padding |
||
3545 | hidnplayr | 220 | |
5668 | hidnplayr | 221 | SetPixelFormat16 db 0 ; setPixelformat |
222 | db 0, 0, 0 ; padding |
||
223 | .bpp db 16 ; bits per pixel |
||
224 | .depth db 15 ; depth |
||
225 | .big_endian db 0 ; big-endian flag |
||
226 | .true_color db 1 ; true-colour flag |
||
227 | .red_max db 0, 31 ; red-max |
||
228 | .green_max db 0, 31 ; green-max |
||
229 | .blue_max db 0, 31 ; blue-max |
||
230 | .red_shif db 0 ; red-shift |
||
231 | .green_shift db 5 ; green-shift |
||
232 | .blue_shift db 10 ; blue-shift |
||
233 | db 0, 0, 0 ; padding |
||
3545 | hidnplayr | 234 | |
5668 | hidnplayr | 235 | SetPixelFormat8 db 0 ; setPixelformat |
236 | db 0, 0, 0 ; padding |
||
237 | .bpp db 8 ; bits per pixel |
||
238 | .depth db 6 ; depth |
||
239 | .big_endian db 0 ; big-endian flag |
||
240 | .true_color db 1 ; true-colour flag |
||
241 | .red_max db 0, 3 ; red-max |
||
242 | .green_max db 0, 3 ; green-max |
||
243 | .blue_max db 0, 3 ; blue-max |
||
244 | .red_shif db 0 ; red-shift |
||
245 | .green_shift db 2 ; green-shift |
||
246 | .blue_shift db 4 ; blue-shift |
||
247 | db 0, 0, 0 ; padding |
||
3545 | hidnplayr | 248 | |
5668 | hidnplayr | 249 | SetEncodings db 2 ; setEncodings |
250 | db 0 ; padding |
||
251 | db 0, 2 ; number of encodings |
||
252 | db 0, 0, 0, 0 ; raw encoding (DWORD, Big endian order) |
||
253 | db 0, 0, 0, 1 ; Copyrect encoding |
||
254 | ; db 0, 0, 0, 2 ; RRE |
||
255 | ; db 0, 0, 0, 5 ; HexTile |
||
256 | ; db 0, 0, 0, 15 ; TRLE |
||
257 | ; db 0, 0, 0, 16 ; ZRLE |
||
3545 | hidnplayr | 258 | |
5668 | hidnplayr | 259 | FramebufferUpdateRequest db 3 |
260 | .inc db 0 ; incremental |
||
261 | .x dw 0 |
||
262 | .y dw 0 |
||
263 | .width dw 0 |
||
264 | .height dw 0 |
||
3545 | hidnplayr | 265 | |
5668 | hidnplayr | 266 | KeyEvent db 4 ; keyevent |
267 | .down db 0 ; down-flag |
||
268 | dw 0 ; padding |
||
269 | .key dd 0 ; key |
||
3545 | hidnplayr | 270 | |
5668 | hidnplayr | 271 | PointerEvent db 5 ; pointerevent |
272 | .mask db 0 ; button-mask |
||
273 | .x dw 0 ; x-position |
||
274 | .y dw 0 ; y-position |
||
3545 | hidnplayr | 275 | |
276 | |||
277 | sockaddr1: |
||
5668 | hidnplayr | 278 | dw AF_INET4 |
279 | .port dw 0x0c17 ; 5900 |
||
280 | .ip dd 0 |
||
281 | rb 10 |
||
3545 | hidnplayr | 282 | |
5668 | hidnplayr | 283 | beep db 0x85, 0x25, 0x85, 0x40, 0 |
5663 | hidnplayr | 284 | |
5670 | hidnplayr | 285 | status dd STATUS_INITIAL |
286 | update_gui dd 0 |
||
287 | mouse_dd dd 0 |
||
288 | update_framebuffer dd 0 |
||
5668 | hidnplayr | 289 | |
5670 | hidnplayr | 290 | URLbox edit_box 235, 70, 10, 0xffffff, 0x6f9480, 0, 0, 0, 65535, serveraddr, mouse_dd, ed_focus, 0, 0 |
291 | USERbox edit_box 150, 70, 10, 0xffffff, 0x6f9480, 0, 0, 0, 127, username, mouse_dd, ed_focus, 0, 0 |
||
292 | PASSbox edit_box 150, 90, 10, 0xffffff, 0x6f9480, 0, 0, 0, 127, password, mouse_dd, 0, 0, 0 |
||
5663 | hidnplayr | 293 | |
5668 | hidnplayr | 294 | serverstr db "server:" |
295 | userstr db "username:" |
||
296 | passstr db "password:" |
||
5670 | hidnplayr | 297 | connectstr db "Connect" |
298 | loginstr db "Log in" |
||
5668 | hidnplayr | 299 | loginstr_e: |
300 | |||
301 | sz_err_disconnected db "Server closed connection unexpectedly.", 0 |
||
302 | sz_err_dns db "Could not resolve hostname.", 0 |
||
303 | sz_err_sock db "Could not open socket.", 0 |
||
304 | sz_err_connect db "Could not connect to the server.", 0 |
||
305 | sz_err_proto db "A protocol error has occured.", 0 |
||
306 | sz_err_security db "Server requested an unsupported security type.", 0 |
||
307 | sz_err_library db "Could not load needed libraries.", 0 |
||
308 | sz_err_thread db "Could not create thread.", 0 |
||
309 | |||
310 | err_msg dd sz_err_disconnected |
||
311 | dd sz_err_dns |
||
312 | dd sz_err_sock |
||
313 | dd sz_err_connect |
||
314 | dd sz_err_proto |
||
315 | dd sz_err_security |
||
316 | dd sz_err_library |
||
317 | dd sz_err_thread |
||
318 | |||
3545 | hidnplayr | 319 | ; import |
320 | align 4 |
||
321 | @IMPORT: |
||
322 | |||
5663 | hidnplayr | 323 | library network, "network.obj",\ |
324 | box_lib, "box_lib.obj",\ |
||
325 | archiver, "archiver.obj" |
||
3545 | hidnplayr | 326 | |
5663 | hidnplayr | 327 | import network,\ |
328 | getaddrinfo, "getaddrinfo", \ |
||
329 | freeaddrinfo, "freeaddrinfo", \ |
||
330 | inet_ntoa, "inet_ntoa" |
||
3545 | hidnplayr | 331 | |
5663 | hidnplayr | 332 | import box_lib,\ |
333 | edit_box_draw, "edit_box",\ |
||
334 | edit_box_key, "edit_box_key",\ |
||
335 | edit_box_mouse, "edit_box_mouse",\ |
||
336 | scrollbar_v_draw, "scrollbar_v_draw",\ |
||
337 | scrollbar_v_mouse, "scrollbar_v_mouse",\ |
||
338 | scrollbar_h_draw, "scrollbar_h_draw",\ |
||
339 | scrollbar_h_mouse, "scrollbar_h_mouse" |
||
340 | |||
341 | import archiver,\ |
||
342 | deflate_unpack, "deflate_unpack" |
||
343 | |||
5668 | hidnplayr | 344 | name db "VNC viewer " |
345 | .dash db 0, " " |
||
5663 | hidnplayr | 346 | |
3545 | hidnplayr | 347 | I_END: |
348 | |||
5663 | hidnplayr | 349 | servername rb 64+1 |
3545 | hidnplayr | 350 | |
5663 | hidnplayr | 351 | socketnum dd ? |
352 | datapointer dd ? |
||
5668 | hidnplayr | 353 | |
5663 | hidnplayr | 354 | rectangles dw ? |
3545 | hidnplayr | 355 | |
5663 | hidnplayr | 356 | rectangle: |
5668 | hidnplayr | 357 | .x dd ? |
358 | .y dd ? |
||
359 | .width dd ? |
||
360 | .height dd ? |
||
3545 | hidnplayr | 361 | |
5668 | hidnplayr | 362 | subrectangles dd ? |
363 | |||
364 | subrectangle: |
||
365 | .x dd ? |
||
366 | .y dd ? |
||
367 | .width dd ? |
||
368 | .height dd ? |
||
369 | |||
5663 | hidnplayr | 370 | screen: ; Remote screen resolution |
371 | .height dw ? |
||
372 | .width dw ? |
||
3545 | hidnplayr | 373 | |
5670 | hidnplayr | 374 | keymap rb 128 |
375 | username rb 128 |
||
376 | password rb 128 |
||
5663 | hidnplayr | 377 | serveraddr rb 65536 |
5668 | hidnplayr | 378 | receive_buffer rb RECEIVE_BUFFER_SIZE |
5663 | hidnplayr | 379 | framebuffer_data rb 1024*1024*3 ; framebuffer |
3545 | hidnplayr | 380 | |
5663 | hidnplayr | 381 | rb 0x1000 |
3545 | hidnplayr | 382 | thread_stack: |
5663 | hidnplayr | 383 | rb 0x1000 |
3545 | hidnplayr | 384 | IM_END: |
385 |