VNC Viewer: Allow user to enter port number (address:port syntax). Fixed and enabled RRE.

git-svn-id: svn://kolibrios.org@5715 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2015-08-11 18:39:38 +00:00
parent d7b4570ef2
commit d39e3ce57e
3 changed files with 106 additions and 39 deletions

View File

@ -16,38 +16,67 @@ thread_start:
mcall 40, 0 ; disable all events for this thread mcall 40, 0 ; disable all events for this thread
; resolve name ; Extract port number from server address
mov esi, serveraddr
@@:
lodsb
test al, al
jz .port_done
cmp al, ':'
jne @r
mov byte[esi-1], 0 ; replace colon with 0 byte, we dont want to upset getaddrinfo
xor eax, eax
xor ebx, ebx ; port number
@@:
lodsb
test al, al
jz @f
sub al, '0'
jb err_dns
cmp al, 9
ja err_dns
lea ebx, [ebx*4+ebx]
lea ebx, [ebx*2+eax]
jmp @b
@@:
xchg bl, bh
mov [sockaddr1.port], bx
.port_done:
; Resolve hostname
push esp ; reserve stack place push esp ; reserve stack place
invoke getaddrinfo, serveraddr, 0, 0, esp invoke getaddrinfo, serveraddr, 0, 0, esp
pop esi pop esi
; test for error
test eax, eax test eax, eax
jnz err_dns jnz err_dns
mov eax, [esi+addrinfo.ai_addr] mov eax, [esi+addrinfo.ai_addr]
mov eax, [eax+sockaddr_in.sin_addr] mov eax, [eax+sockaddr_in.sin_addr]
mov [sockaddr1.ip], eax mov [sockaddr1.ip], eax
invoke freeaddrinfo, esi
DEBUGF 1, "Connecting to %u.%u.%u.%u:%u\n", \ DEBUGF 1, "Connecting to %u.%u.%u.%u:%u\n", \
[sockaddr1.ip]:1, [sockaddr1.ip+1]:1, [sockaddr1.ip+2]:1, [sockaddr1.ip+3]:1, \ [sockaddr1.ip]:1, [sockaddr1.ip+1]:1, [sockaddr1.ip+2]:1, [sockaddr1.ip+3]:1, \
[sockaddr1.port]:2 [sockaddr1.port]:2
invoke freeaddrinfo, esi ; Open socket
mcall socket, AF_INET4, SOCK_STREAM, 0 mcall socket, AF_INET4, SOCK_STREAM, 0
cmp eax, -1 cmp eax, -1
je err_sock je err_sock
mov [socketnum], eax mov [socketnum], eax
; Connect to the server
mcall connect, [socketnum], sockaddr1, 18 mcall connect, [socketnum], sockaddr1, 18
cmp eax, -1 cmp eax, -1
je err_connect je err_connect
; Wait for handshake from server
; TODO: implement timeout ; TODO: implement timeout
call wait_for_data call wait_for_data
cmp dword[receive_buffer], "RFB " cmp dword[receive_buffer], "RFB "
jne err_proto jne err_proto
; Reply to handshake
DEBUGF 1, "Sending handshake\n" DEBUGF 1, "Sending handshake\n"
mcall send, [socketnum], HandShake, 12, 0 mcall send, [socketnum], HandShake, 12, 0
call wait_for_data call wait_for_data
@ -203,7 +232,7 @@ end if
; Tell the main thread we are ready for business! ; Tell the main thread we are ready for business!
mov [status], STATUS_CONNECTED mov [status], STATUS_CONNECTED
; Request initial update ; Request initial framebuffer update from server
mov [FramebufferUpdateRequest.inc], 0 mov [FramebufferUpdateRequest.inc], 0
request_fbu: request_fbu:
@ -269,8 +298,8 @@ rectangle_loop:
lodsd ; encoding lodsd ; encoding
bswap eax bswap eax
DEBUGF 1, "rectangle: width=%u height=%u x=%u y=%u encoding: ",\ DEBUGF 1, "Rectangle: x=%u y=%u width=%u height=%u encoding: ",\
[rectangle.width]:2, [rectangle.height]:2, [rectangle.x]:2, [rectangle.y]:2 [rectangle.x]:2, [rectangle.y]:2, [rectangle.width]:2, [rectangle.height]:2
cmp eax, 0 cmp eax, 0
je encoding_raw je encoding_raw

View File

@ -12,54 +12,70 @@
;; ;; ;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pixel_to_24bpp: ; returns in ecx, destroys eax, ebx pixel_to_24bpp: ; returns in ecx
if BITS_PER_PIXEL = 8 if BITS_PER_PIXEL = 8
; Convert pixel to 24BPP
mov bl, 85 push eax ebx
mov al, [esi]
shr al, 6
and al, 3
mul bl
mov ch, al ; blue
mov bl, 36 mov bl, 36
mov al, [esi]
and al, 7
mul bl
mov ch, al ; red
mov al, [esi] mov al, [esi]
shr al, 3 shr al, 3
and al, 7 and al, 7
mul bl mul bl
mov cl, al ; green mov cl, al ; green
mov bl, 85
mov al, [esi] mov al, [esi]
and al, 7 shr al, 6
and al, 3
mul bl mul bl
shr ecx, 8 shl ecx, 8
mov cl, al ; red mov cl, al ; blue
inc esi inc esi
pop ebx eax
else if BITS_PER_PIXEL = 16 else if BITS_PER_PIXEL = 16
push eax
lodsw lodsw
mov cl, al mov cl, ah
shl cl, 3 and al, 0xf8 ; red
and cx, 0x00f8 ; blue
shl ecx, 16
mov cx, ax mov cx, ax
shl cx, 5 shl cx, 5
and ch, 0xfc ; green and ch, 0xfc ; green
mov cl, ah shl ecx, 8
and al, 0xf8 ; red
mov cl, al
shl cl, 3
and cx, 0x00f8 ; blue
pop eax
else else
xor ecx, ecx xor ecx, ecx
mov cx, [esi] mov cx, [esi]
shr ecx, 8 shl ecx, 8
mov cl, [esi+2] mov cl, [esi+2]
add esi, 3 add esi, 3
end if end if
ret ret
encoding_RRE: encoding_RRE:
DEBUGF 2,"RRE\n" DEBUGF 1,"RRE\n"
@@: @@:
lea eax, [esi+5] lea eax, [esi+4+BYTES_PER_PIXEL]
cmp [datapointer], eax cmp [datapointer], eax
jae @f jae @f
call read_data.more call read_data.more
@ -70,17 +86,23 @@ encoding_RRE:
bswap eax bswap eax
mov [subrectangles], eax mov [subrectangles], eax
DEBUGF 1, "%u subrectangles\n", eax
; Get background color
call pixel_to_24bpp call pixel_to_24bpp
; Calculate first pixel pos
movzx eax, [screen.width] movzx eax, [screen.width]
mul [rectangle.y] ; [screen.width]*[rectangle.y] mul [rectangle.y] ; [screen.width]*[rectangle.y]
add eax, [rectangle.x] ; [screen.width]*[rectangle.y]+[rectangle.x] add eax, [rectangle.x] ; [screen.width]*[rectangle.y]+[rectangle.x]
lea edi, [framebuffer_data+eax*3] ; edi = framebuffer_data+([screen.width]*[rectangle.y]+[rectangle.x])*3 lea edi, [framebuffer_data+eax*3] ; edi = framebuffer_data+([screen.width]*[rectangle.y]+[rectangle.x])*3
; Calculate offset between two rows of pixels
movzx eax, [screen.width] movzx eax, [screen.width]
sub eax, [rectangle.width] sub eax, [rectangle.width]
lea ebp, [eax*3] ; ebp = ([screen.width]-[rectangle.width])*3 lea ebp, [eax*3] ; ebp = ([screen.width]-[rectangle.width])*3
; Draw background rectangle
push edi push edi
mov eax, ecx mov eax, ecx
mov edx, [rectangle.height] mov edx, [rectangle.height]
@ -98,17 +120,23 @@ encoding_RRE:
jnz .lineloop jnz .lineloop
pop edi pop edi
; Any subrectangles at all?
cmp [subrectangles], 0
je next_rectangle
.subrectangle: .subrectangle:
@@: @@:
lea eax, [esi+9] lea eax, [esi+8+BYTES_PER_PIXEL]
cmp [datapointer], eax cmp [datapointer], eax
jae @f jae @f
call read_data.more call read_data.more
jmp @b jmp @b
@@: @@:
; Get subrectangle color
call pixel_to_24bpp call pixel_to_24bpp
; Get coordinates
xor eax, eax xor eax, eax
lodsw lodsw
xchg al, ah xchg al, ah
@ -118,17 +146,27 @@ encoding_RRE:
mov [subrectangle.y], eax mov [subrectangle.y], eax
lodsw lodsw
xchg al, ah xchg al, ah
mov [subrectangle.height], eax mov [subrectangle.width], eax
lodsw lodsw
xchg al, ah xchg al, ah
mov [subrectangle.width], eax mov [subrectangle.height], eax
DEBUGF 1, "Subrectangle: x=%u y=%u width=%u height=%u\n", \
[subrectangle.x], [subrectangle.y], [subrectangle.width], [subrectangle.height]
; Calculate pos of first pixel
push edi push edi
mov eax, [rectangle.width] movzx eax, [screen.width]
mul [subrectangle.y] mul [subrectangle.y]
add eax, [subrectangle.x] add eax, [subrectangle.x]
lea eax, [eax*3]
add edi, eax add edi, eax
; Calculate offset between two rows of pixels
movzx eax, [screen.width]
sub eax, [subrectangle.width]
lea ebp, [eax*3] ; ebp = ([screen.width]-[rectangle.width])*3
; Draw the subrectangle
mov eax, ecx mov eax, ecx
mov edx, [subrectangle.height] mov edx, [subrectangle.height]
.lineloop2: .lineloop2:
@ -143,9 +181,7 @@ encoding_RRE:
add edi, ebp add edi, ebp
dec edx dec edx
jnz .lineloop2 jnz .lineloop2
pop edi pop edi
dec [subrectangles] dec [subrectangles]
jnz .subrectangle jnz .subrectangle
jmp next_rectangle jmp next_rectangle

View File

@ -85,6 +85,8 @@ STATUS_LIB_ERR = 16
STATUS_THREAD_ERR = 17 STATUS_THREAD_ERR = 17
STATUS_LOGIN_FAILED = 18 STATUS_LOGIN_FAILED = 18
BYTES_PER_PIXEL = (BITS_PER_PIXEL + 7) / 8
include "keymap.inc" include "keymap.inc"
include "gui.inc" include "gui.inc"
include "network.inc" include "network.inc"
@ -310,10 +312,10 @@ SetPixelFormat8 db 0 ; setPixelformat
SetEncodings db 2 ; setEncodings SetEncodings db 2 ; setEncodings
db 0 ; padding db 0 ; padding
db 0, 2 ; number of encodings db 0, 3 ; number of encodings
db 0, 0, 0, 0 ; raw encoding (DWORD, Big endian order)
db 0, 0, 0, 1 ; Copyrect encoding db 0, 0, 0, 1 ; Copyrect encoding
; db 0, 0, 0, 2 ; RRE db 0, 0, 0, 2 ; RRE
db 0, 0, 0, 0 ; raw encoding
; db 0, 0, 0, 5 ; HexTile ; db 0, 0, 0, 5 ; HexTile
; db 0, 0, 0, 15 ; TRLE ; db 0, 0, 0, 15 ; TRLE
; db 0, 0, 0, 16 ; ZRLE ; db 0, 0, 0, 16 ; ZRLE