2015-08-03 14:32:28 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
|
|
|
;; Copyright (C) KolibriOS team 2010-2015. All rights reserved. ;;
|
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;; VNC client for KolibriOS ;;
|
|
|
|
;; ;;
|
|
|
|
;; Written by hidnplayr@kolibrios.org ;;
|
|
|
|
;; ;;
|
|
|
|
;; GNU GENERAL PUBLIC LICENSE ;;
|
|
|
|
;; Version 2, June 1991 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
thread_start:
|
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
DEBUGF 1, "I am the thread!\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
mcall 40, 0 ; disable all events
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
; resolve name
|
|
|
|
push esp ; reserve stack place
|
2015-08-03 14:32:28 +02:00
|
|
|
invoke getaddrinfo, serveraddr, 0, 0, esp
|
2013-05-28 19:34:26 +02:00
|
|
|
pop esi
|
|
|
|
; test for error
|
|
|
|
test eax, eax
|
|
|
|
jnz exit
|
|
|
|
|
|
|
|
mov eax, [esi+addrinfo.ai_addr]
|
|
|
|
mov eax, [eax+sockaddr_in.sin_addr]
|
|
|
|
mov [sockaddr1.ip], eax
|
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
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.port]:2
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
mcall socket, AF_INET4, SOCK_STREAM, 0
|
2015-08-03 14:32:28 +02:00
|
|
|
test eax, eax
|
|
|
|
jz exit
|
|
|
|
;;; invoke freeaddrinfo, ??
|
2013-05-28 19:34:26 +02:00
|
|
|
mov [socketnum], eax
|
|
|
|
mcall connect, [socketnum], sockaddr1, 18
|
2015-08-03 14:32:28 +02:00
|
|
|
;;; test eax, eax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
; TODO: implement timeout
|
2013-05-28 19:34:26 +02:00
|
|
|
call wait_for_data
|
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
cmp dword[receive_buffer], "RFB "
|
2013-05-28 19:34:26 +02:00
|
|
|
jne no_rfb
|
2015-08-03 14:32:28 +02:00
|
|
|
DEBUGF 1, "received: %s\n", receive_buffer
|
2013-05-28 19:34:26 +02:00
|
|
|
mcall send, [socketnum], handshake, 12, 0
|
2015-08-03 14:32:28 +02:00
|
|
|
DEBUGF 1, "Sending handshake: protocol version\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
call wait_for_data
|
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
cmp dword[receive_buffer], 0x00000000
|
2013-05-28 19:34:26 +02:00
|
|
|
je invalid_security
|
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
cmp dword[receive_buffer], 0x01000000
|
2013-05-28 19:34:26 +02:00
|
|
|
je no_security
|
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
cmp dword[receive_buffer], 0x02000000
|
2013-05-28 19:34:26 +02:00
|
|
|
je vnc_security
|
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
DEBUGF 1, "Unknown security type\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
jmp exit
|
|
|
|
|
|
|
|
vnc_security:
|
|
|
|
mov byte[mode], 1
|
2015-08-03 14:32:28 +02:00
|
|
|
call logon
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
no_security:
|
2015-08-03 14:32:28 +02:00
|
|
|
mcall send, [socketnum], ClientInit, 1, 0
|
|
|
|
DEBUGF 1, "ClientInit sent\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
call wait_for_data ; now the server should send init message
|
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
DEBUGF 1, "Serverinit: bpp: %u depth: %u bigendian: %u truecolor: %u\n", \
|
|
|
|
[receive_buffer+framebuffer.pixelformat.bpp]:1, \
|
|
|
|
[receive_buffer+framebuffer.pixelformat.depth]:1, \
|
|
|
|
[receive_buffer+framebuffer.pixelformat.big_endian]:1, \
|
|
|
|
[receive_buffer+framebuffer.pixelformat.true_color]:1
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
mov eax, dword[receive_buffer+framebuffer.width]
|
|
|
|
mov dword[fbur.width], eax
|
2013-05-28 19:34:26 +02:00
|
|
|
bswap eax
|
2015-08-03 14:32:28 +02:00
|
|
|
mov dword[screen], eax
|
|
|
|
DEBUGF 1, "Screen width=%u, height=%u\n", [screen.width]:2, [screen.height]:2
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
mcall send, [socketnum], pixel_format8, 20, 0
|
2015-08-03 14:32:28 +02:00
|
|
|
DEBUGF 1, "Sending pixel format\n"
|
|
|
|
|
2015-08-03 15:13:09 +02:00
|
|
|
mcall send, [socketnum], encodings, 12, 0
|
2015-08-03 14:32:28 +02:00
|
|
|
DEBUGF 1, "Sending encoding info\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
mov [thread_ready], 1
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
; Request initial update
|
|
|
|
mov [fbur.inc], 0
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
request_fbu:
|
|
|
|
DEBUGF 1, "Requesting framebuffer update\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
mcall send, [socketnum], fbur, 10, 0
|
2015-08-03 14:32:28 +02:00
|
|
|
mov [fbur.inc], 1
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
thread_loop:
|
|
|
|
call read_data ; Read the data into the buffer
|
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
lodsb
|
|
|
|
cmp al, 0
|
2013-05-28 19:34:26 +02:00
|
|
|
je framebufferupdate
|
2015-08-03 14:32:28 +02:00
|
|
|
cmp al, 1
|
2013-05-28 19:34:26 +02:00
|
|
|
je setcolourmapentries
|
2015-08-03 14:32:28 +02:00
|
|
|
cmp al, 2
|
2013-05-28 19:34:26 +02:00
|
|
|
je bell
|
2015-08-03 14:32:28 +02:00
|
|
|
cmp al, 3
|
2013-05-28 19:34:26 +02:00
|
|
|
je servercuttext
|
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
|
|
|
|
DEBUGF 1, "Unknown server command: %u\n", al
|
2013-05-28 19:34:26 +02:00
|
|
|
jmp thread_loop
|
|
|
|
|
|
|
|
framebufferupdate:
|
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
@@:
|
|
|
|
lea eax, [esi+6]
|
|
|
|
cmp [datapointer], eax
|
|
|
|
jae @f
|
|
|
|
call read_data.more
|
|
|
|
jmp @b
|
|
|
|
@@:
|
|
|
|
|
|
|
|
inc esi ; padding
|
|
|
|
lodsw
|
2013-05-28 19:34:26 +02:00
|
|
|
xchg al, ah
|
2015-08-03 14:32:28 +02:00
|
|
|
mov [rectangles], ax
|
|
|
|
DEBUGF 1, "Framebufferupdate: %u rectangles\n", ax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
rectangle_loop:
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
@@:
|
|
|
|
lea eax, [esi+12]
|
|
|
|
cmp [datapointer], eax
|
|
|
|
jae @f
|
|
|
|
call read_data.more
|
|
|
|
jmp @b
|
|
|
|
@@:
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
lodsd ; position
|
|
|
|
bswap eax
|
|
|
|
mov [rectangle.y], ax
|
|
|
|
shr eax, 16
|
|
|
|
mov [rectangle.x], ax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
lodsd ; size
|
|
|
|
bswap eax
|
|
|
|
mov [rectangle.height], ax
|
|
|
|
shr eax, 16
|
|
|
|
mov [rectangle.width], ax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
lodsd ; encoding
|
|
|
|
DEBUGF 1, "rectangle: width=%u height=%u x=%u y=%u encoding: ",\
|
|
|
|
[rectangle.width]:2, [rectangle.height]:2, [rectangle.x]:2, [rectangle.y]:2
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
cmp eax, 0
|
|
|
|
je encoding_raw
|
2015-08-03 15:13:09 +02:00
|
|
|
cmp eax, 1
|
|
|
|
je encoding_copyrect
|
2015-08-03 14:32:28 +02:00
|
|
|
; cmp eax, 2
|
|
|
|
; je encoding_RRE
|
|
|
|
; cmp eax, 5
|
|
|
|
; je encoding_hextile
|
|
|
|
; cmp eax, 15
|
|
|
|
; je encoding_TRLE
|
|
|
|
; cmp eax, 16
|
|
|
|
; je encoding_ZRLE
|
|
|
|
|
|
|
|
DEBUGF 1, "\nunknown encoding: %u\n", eax
|
2013-05-28 19:34:26 +02:00
|
|
|
jmp thread_loop
|
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
;; jmp rectangle_loop
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
next_rectangle:
|
|
|
|
push esi
|
|
|
|
call drawbuffer
|
|
|
|
pop esi
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
dec [rectangles]
|
|
|
|
jnz rectangle_loop
|
|
|
|
jmp request_fbu
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
setcolourmapentries:
|
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
DEBUGF 1, "Server sent SetColourMapEntries message\n"
|
|
|
|
|
|
|
|
; TODO
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
jmp thread_loop
|
|
|
|
|
|
|
|
|
|
|
|
bell:
|
|
|
|
mcall 55, 55, , , beep
|
|
|
|
jmp thread_loop
|
|
|
|
|
|
|
|
|
|
|
|
servercuttext:
|
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
DEBUGF 1, "Server cut text\n"
|
|
|
|
|
|
|
|
@@:
|
|
|
|
lea eax, [esi+7]
|
|
|
|
cmp [datapointer], eax
|
|
|
|
jae @f
|
|
|
|
call read_data.more
|
|
|
|
jmp @b
|
|
|
|
@@:
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
add esi, 3
|
|
|
|
lodsd
|
|
|
|
bswap eax
|
|
|
|
mov ecx, eax
|
|
|
|
|
|
|
|
@@:
|
|
|
|
lea eax, [esi+ecx]
|
|
|
|
cmp [datapointer], eax
|
|
|
|
jae @f
|
|
|
|
call read_data.more
|
|
|
|
jmp @b
|
|
|
|
@@:
|
|
|
|
|
|
|
|
; TODO: paste text to clipboard
|
|
|
|
|
|
|
|
DEBUGF 1, "%u bytes of text\n", ecx
|
|
|
|
add esi, ecx
|
2013-05-28 19:34:26 +02:00
|
|
|
jmp thread_loop
|
|
|
|
|
|
|
|
|
|
|
|
read_data:
|
|
|
|
mov [datapointer], receive_buffer
|
2015-08-03 14:32:28 +02:00
|
|
|
mov esi, receive_buffer
|
|
|
|
.more:
|
|
|
|
push ebx ecx edx esi edi
|
2013-05-28 19:34:26 +02:00
|
|
|
mcall recv, [socketnum], [datapointer], 4096, 0
|
2015-08-03 14:32:28 +02:00
|
|
|
pop edi esi edx ecx ebx
|
2013-05-28 19:34:26 +02:00
|
|
|
cmp eax, -1
|
2015-08-03 14:32:28 +02:00
|
|
|
je .error
|
|
|
|
add [datapointer], eax ; TODO: check for buffer overflow
|
2013-05-28 19:34:26 +02:00
|
|
|
cmp eax, 4096
|
2015-08-03 14:32:28 +02:00
|
|
|
je .more
|
|
|
|
ret
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
.error:
|
|
|
|
DEBUGF 1, "Socket error!\n"
|
|
|
|
mcall -1
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
wait_for_data: ; FIXME: add timeout
|
2013-05-28 19:34:26 +02:00
|
|
|
mcall recv, [socketnum], receive_buffer, 4096, 0
|
|
|
|
cmp eax, -1
|
2015-08-03 14:32:28 +02:00
|
|
|
je .error
|
2013-05-28 19:34:26 +02:00
|
|
|
test eax, eax
|
|
|
|
jz wait_for_data
|
|
|
|
|
|
|
|
ret
|
|
|
|
|
2015-08-03 14:32:28 +02:00
|
|
|
.error:
|
|
|
|
DEBUGF 1, "Socket error!\n"
|
|
|
|
mcall -1
|
|
|
|
ret
|
|
|
|
|