VNC Viewer: accept server address through parameters, improved GUI, various bugfixes.

git-svn-id: svn://kolibrios.org@5720 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2015-08-13 19:20:59 +00:00
parent 01dcf2d4d4
commit 253b29a88f
3 changed files with 200 additions and 65 deletions

View File

@ -26,7 +26,7 @@ draw_gui:
mcall
cmp [status], STATUS_CONNECTING
ja @f
ja .login?
mov ebx, 25 shl 16 + 24
xor ecx, ecx
@ -36,7 +36,24 @@ draw_gui:
invoke edit_box_draw, URLbox ; Server textbox
cmp [status], STATUS_INITIAL
cmp [status], STATUS_CONNECTING
jne @f
mov ebx, 220 shl 16 + 85
mov ecx, 47 shl 16 + 16
mov edx, 4
mov esi, 0xCCCCCC
mcall 8 ; Cancel button
mov ebx, 240 shl 16 + 52
mov edx, cancelstr
mov esi, okstr-cancelstr
mcall 4 ; Cancel button text
jmp .redraw_done
@@:
cmp [status], STATUS_CONNECT
jne .redraw_done
mov ebx, 220 shl 16 + 85
@ -52,7 +69,7 @@ draw_gui:
jmp .redraw_done
@@:
.login?:
cmp [status], STATUS_LOGIN
ja @f
@ -81,22 +98,60 @@ draw_gui:
mov ebx, 240 shl 16 + 52
mov edx, loginstr
mov esi, loginstr_e-loginstr
mov esi, cancelstr-loginstr
mcall 4 ; Login button text
mov ebx, 120 shl 16 + 85
mov ecx, 47 shl 16 + 16
mov edx, 4
mov esi, 0xCCCCCC
mcall 8 ; Cancel button
mov ebx, 140 shl 16 + 52
mov edx, cancelstr
mov esi, okstr-cancelstr
mcall 4 ; Cancel button text
jmp .redraw_done
@@:
cmp [status], STATUS_DISCONNECTED
jb .redraw_done
mov ebx, 25 shl 16 + 15
mov ecx, 0x80ca0000 ; red ASCIIZ string
mov ebx, 15 shl 16 + 10
mov ecx, 0x00ca0000 ; red ASCIIZ string
mov edx, [status]
sub edx, 10
mov edx, [err_msg+4*edx]
.restart:
xor esi, esi
.pr_loop:
cmp byte[edx+esi], 0
je .last
cmp byte[edx+esi], 0x0a
je .print
inc esi
jmp .pr_loop
.print:
mcall 4
add edx, esi
inc edx
add ebx, 10
jmp .restart
.last:
mcall 4 ; print error message to window
mov ebx, 220 shl 16 + 85
mov ecx, 47 shl 16 + 16
mov edx, 5
mov esi, 0xCCCCCC
mcall 8 ; OK button
mov ebx, 256 shl 16 + 52
mov edx, okstr
mov esi, okstr_e-okstr
mcall 4 ; OK button text
.redraw_done:
mov [update_gui], 0
mcall 12, 2
@ -124,20 +179,27 @@ draw_gui:
.key: ; key event handler
mcall 2 ; read key
cmp [status], STATUS_INITIAL
cmp [status], STATUS_CONNECT
jne @f
test [URLbox.flags], ed_focus
jz mainloop
cmp ah, 13 ; enter (return) key
je .connect
invoke edit_box_key, URLbox
jmp .loop
@@:
cmp [status], STATUS_REQ_LOGIN
jne .loop
jne @f
cmp ah, 13 ; enter (return) key
je .login
invoke edit_box_key, USERbox
invoke edit_box_key, PASSbox
jmp .loop
@@:
cmp [status], STATUS_DISCONNECTED
jb @f
cmp ah, 13
je .ok
@@:
jmp .loop
@ -150,23 +212,17 @@ draw_gui:
je .connect
cmp ah, 3 ; login ?
je .login
cmp ah, 4
je .cancel
cmp ah, 5
je .ok
jmp .loop
.connect:
mov eax, [URLbox.pos]
mov byte[serveraddr+eax], 0
mov [status], STATUS_CONNECTING
inc [update_gui]
; Create network thread
mcall 51, 1, thread_start, thread_stack
cmp eax, -1
jne @f
mov [status], STATUS_THREAD_ERR
; inc [update_gui]
@@:
call open_connection
jmp .loop
.login:
@ -174,8 +230,16 @@ draw_gui:
inc [update_gui]
jmp .loop
.cancel:
mcall 18, 18, [thread_id] ; kill thread
.ok:
and [URLbox.flags], not ed_disabled
mov [status], STATUS_CONNECT
inc [update_gui]
jmp .loop
.mouse:
cmp [status], STATUS_INITIAL
cmp [status], STATUS_CONNECT
jne @f
invoke edit_box_mouse, URLbox
@@:
@ -188,4 +252,21 @@ draw_gui:
.close:
mov [status], STATUS_CLOSED
mcall -1
mcall -1
open_connection:
or [URLbox.flags], ed_disabled
mov [status], STATUS_CONNECTING
; Create network thread
mcall 51, 1, thread_start, thread_stack
cmp eax, -1
jne @f
mov [status], STATUS_THREAD_ERR
@@:
mov [thread_id], eax
inc [update_gui]
ret

View File

@ -70,26 +70,39 @@ thread_start:
cmp eax, -1
je err_connect
; Wait for handshake from server
; TODO: implement timeout
; Verify handshake from server
call wait_for_data
cmp dword[receive_buffer], "RFB "
jne err_proto
add esi, 12
; Did we get an error message already?
cmp eax, 16
jb @f
lodsd
test eax, eax
je err_handshake
@@:
; Reply to handshake
DEBUGF 1, "Sending handshake\n"
mcall send, [socketnum], HandShake, 12, 0
; VNC 3.3 protocol: server decides security type
call wait_for_data
cmp dword[receive_buffer], 0x01000000 ; no security
lodsd
cmp eax, 0x00000000
je err_handshake
cmp eax, 0x01000000 ; no security
je initialize
cmp dword[receive_buffer], 0x02000000 ; VNC security
cmp eax, 0x02000000 ; VNC security
je vnc_security
jmp err_security
jmp err_proto
vnc_security:
push esi ; pointer to message
mov dword[password], 0
mov dword[password+4], 0
@ -110,7 +123,6 @@ vnc_security:
DEBUGF 1, "VNC authentication\n"
; Bit reverse the password and create DES keys
mov ebx, dword[password]
mov edx, ebx
and ebx, 0xf0f0f0f0
@ -157,34 +169,36 @@ vnc_security:
call DES_create_keys
; Encrypt message with DES
mov ebx, dword[receive_buffer+4]
mov edx, dword[receive_buffer+8]
mov esi, [esp]
mov ebx, dword[esi+0]
mov edx, dword[esi+4]
call encrypt_DES
mov dword[receive_buffer+4], ebx
mov dword[receive_buffer+8], edx
mov esi, [esp]
mov dword[esi+0], ebx
mov dword[esi+4], edx
mov ebx, dword[receive_buffer+12]
mov edx, dword[receive_buffer+16]
mov ebx, dword[esi+8]
mov edx, dword[esi+12]
call encrypt_DES
mov dword[receive_buffer+12], ebx
mov dword[receive_buffer+16], edx
mov esi, [esp]
mov dword[esi+8], ebx
mov dword[esi+12], edx
; Blank out the password and key fields in RAM
mov edi, password
mov ecx, 384/4
xor eax, eax
rep stosd
; Send the authentication response to server
pop edx
mcall send, [socketnum], , 16, 0
mcall send, [socketnum], receive_buffer+4, 16, 0
securityresult:
; Wait for SecurityResult from server
call wait_for_data
cmp dword[receive_buffer], 0
cmp dword[receive_buffer], 0 ; OK
jne err_login
; jmp initialize
initialize:
DEBUGF 1, "Sending ClientInit\n"
@ -307,12 +321,10 @@ rectangle_loop:
je encoding_CopyRect
cmp eax, 2
je encoding_RRE
; cmp eax, 5
; je encoding_hextile
; cmp eax, 15
; je encoding_TRLE
; cmp eax, 16
; je encoding_ZRLE
cmp eax, 15
je encoding_TRLE
cmp eax, 16
je encoding_ZRLE
DEBUGF 2, "unknown encoding: %u\n", eax
jmp thread_loop
@ -416,6 +428,8 @@ read_data:
ret
.buffer_end_reached:
DEBUGF 1, "end of buffer reached, re-organizing\n"
pop edi esi edx ecx ebx
; Buffer is full, first needed data by program is pointed to by esi.
; Move all usefull data to begin of buffer
cmp esi, receive_buffer
@ -436,6 +450,7 @@ wait_for_data: ; FIXME: add timeout
je err_sock
test eax, eax
jz err_disconnected
mov esi, receive_buffer
ret
@ -466,8 +481,24 @@ err_proto:
mcall -1
ret
err_security:
err_handshake:
mov [status], STATUS_SECURITY_ERR
lodsd ; Custom message from server?
test eax, eax
jz .no_msg
bswap eax
mov ecx, eax
cmp ecx, 512
jb @f
mov ecx, 512
@@:
mov edi, sz_err_security_c
rep movsb
mov byte[edi], 0
mov [status], STATUS_SECURITY_ERR_C
.no_msg:
inc [update_gui]
mcall -1
ret

View File

@ -17,7 +17,8 @@ format binary as ""
__DEBUG__ = 1
__DEBUG_LEVEL__ = 2
BITS_PER_PIXEL = 8 ; 8, 16 24
BITS_PER_PIXEL = 8 ; 8, 16 24
SERVERADDRLEN = 4096
use32
@ -29,7 +30,7 @@ use32
dd I_END ; size of image
dd IM_END ; memory for app
dd IM_END ; esp
dd 0x0, 0x0 ; I_Param , I_Path
dd serveraddr, 0x0 ; I_Param , I_Path
include "../../macros.inc"
include "../../debug-fdo.inc"
@ -68,7 +69,7 @@ TIMEOUT = 5 ; timeout in seconds
RECEIVE_BUFFER_SIZE = 8*1024*1024 ; 8 Mib
STATUS_INITIAL = 0
STATUS_CONNECT = 0
STATUS_CONNECTING = 1
STATUS_REQ_LOGIN = 2
STATUS_LOGIN = 3
@ -84,6 +85,7 @@ STATUS_SECURITY_ERR = 15
STATUS_LIB_ERR = 16
STATUS_THREAD_ERR = 17
STATUS_LOGIN_FAILED = 18
STATUS_SECURITY_ERR_C = 19
BYTES_PER_PIXEL = (BITS_PER_PIXEL + 7) / 8
@ -108,6 +110,19 @@ START:
mov [status], STATUS_LIB_ERR
@@:
; Check if we got a server address through parameters
cmp byte[serveraddr], 0
je @f
xor al, al
mov edi, serveraddr
mov ecx, SERVERADDRLEN
repne scasb
sub edi, serveraddr+1
mov [URLbox.size], edi
mov [URLbox.pos], edi
call open_connection
@@:
; Present the user with the GUI and wait for network connection
call draw_gui
@ -140,6 +155,7 @@ redraw:
mcall 12, 2
draw_framebuffer:
DEBUGF 1, "Drawing framebuffer\n"
mcall 7, framebuffer_data, dword[screen], 0
mov [update_framebuffer], 0
@ -314,13 +330,12 @@ SetPixelFormat8 db 0 ; setPixelformat
SetEncodings db 2 ; setEncodings
db 0 ; padding
db 0, 3 ; number of encodings
db 0, 0, 0, 1 ; Copyrect encoding
db 0, 0, 0, 2 ; RRE
db 0, 0, 0, 0 ; raw encoding
; db 0, 0, 0, 5 ; HexTile
; db 0, 0, 0, 15 ; TRLE
db 0, 4 ; number of encodings
; db 0, 0, 0, 16 ; ZRLE
db 0, 0, 0, 15 ; TRLE
db 0, 0, 0, 2 ; RRE
db 0, 0, 0, 1 ; Copyrect encoding
db 0, 0, 0, 0 ; raw encoding
.length = $ - SetEncodings
FramebufferUpdateRequest db 3
@ -349,16 +364,17 @@ sockaddr1:
beep db 0x85, 0x25, 0x85, 0x40, 0
status dd STATUS_INITIAL
status dd STATUS_CONNECT
update_gui dd 0
mouse_dd dd 0
update_framebuffer dd 0
thread_id dd 0
deflate_buffer dd 0
deflate_length dd ?
deflate_str dd ?
URLbox edit_box 235, 70, 20, 0xffffff, 0x6f9480, 0, 0, 0, 65535, serveraddr, mouse_dd, ed_focus, 0, 0
URLbox edit_box 235, 70, 20, 0xffffff, 0x6f9480, 0, 0, 0, SERVERADDRLEN, serveraddr, mouse_dd, ed_focus, 0, 0
USERbox edit_box 215, 90, 10, 0xffffff, 0x6f9480, 0, 0, 0, 127, username, mouse_dd, ed_focus, 0, 0
PASSbox edit_box 215, 90, 30, 0xffffff, 0x6f9480, 0, 0, 0, 127, password, mouse_dd, ed_pass, 0, 0
@ -367,14 +383,16 @@ userstr db "username:"
passstr db "password:"
connectstr db "Connect"
loginstr db "Log in"
loginstr_e:
cancelstr db "Cancel"
okstr db "OK"
okstr_e:
sz_err_disconnected db "Server closed connection unexpectedly.", 0
sz_err_disconnected db "The server has closed the connection unexpectedly.", 0
sz_err_dns db "Could not resolve hostname.", 0
sz_err_sock db "Could not open socket.", 0
sz_err_connect db "Could not connect to the server.", 0
sz_err_proto db "A protocol error has occured.", 0
sz_err_security db "Server requested an unsupported security type.", 0
sz_err_security db "An authentication problem has occured.", 0
sz_err_library db "Could not load needed libraries.", 0
sz_err_thread db "Could not create thread.", 0
sz_err_login_failed db "Login failed.", 0
@ -388,6 +406,7 @@ err_msg dd sz_err_disconnected
dd sz_err_library
dd sz_err_thread
dd sz_err_login_failed
dd sz_err_security_c
; import
align 4
@ -421,6 +440,9 @@ I_END:
servername rb 64+1
serveraddr db 0
rb SERVERADDRLEN
socketnum dd ?
datapointer dd ?
@ -454,7 +476,8 @@ username rb 128
password rb 128
keys rd 32*2 ; DES keys for VNC authentication
serveraddr rb 65536
sz_err_security_c rb 512+1
receive_buffer rb RECEIVE_BUFFER_SIZE
framebuffer_data rb 1280*1024*3 ; framebuffer