Subversion Repositories Kolibri OS

Rev

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