2015-08-03 15:32:28 +03: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 21:34:26 +04:00
|
|
|
|
|
|
|
thread_start:
|
|
|
|
|
2015-08-03 21:07:56 +03:00
|
|
|
mcall 40, 0 ; disable all events for this thread
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2015-08-11 21:39:38 +03:00
|
|
|
; 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
|
2015-08-03 21:07:56 +03:00
|
|
|
push esp ; reserve stack place
|
2015-08-03 15:32:28 +03:00
|
|
|
invoke getaddrinfo, serveraddr, 0, 0, esp
|
2013-05-28 21:34:26 +04:00
|
|
|
pop esi
|
|
|
|
test eax, eax
|
2015-08-03 21:07:56 +03:00
|
|
|
jnz err_dns
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
mov eax, [esi+addrinfo.ai_addr]
|
|
|
|
mov eax, [eax+sockaddr_in.sin_addr]
|
|
|
|
mov [sockaddr1.ip], eax
|
2015-08-11 21:39:38 +03:00
|
|
|
invoke freeaddrinfo, esi
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2015-08-03 15:32:28 +03:00
|
|
|
DEBUGF 1, "Connecting to %u.%u.%u.%u:%u\n", \
|
2015-08-05 12:37:00 +03:00
|
|
|
[sockaddr1.ip]:1, [sockaddr1.ip+1]:1, [sockaddr1.ip+2]:1, [sockaddr1.ip+3]:1, \
|
|
|
|
[sockaddr1.port]:2
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2015-08-11 21:39:38 +03:00
|
|
|
; Open socket
|
2013-05-28 21:34:26 +04:00
|
|
|
mcall socket, AF_INET4, SOCK_STREAM, 0
|
2015-08-03 21:07:56 +03:00
|
|
|
cmp eax, -1
|
|
|
|
je err_sock
|
2013-05-28 21:34:26 +04:00
|
|
|
mov [socketnum], eax
|
2015-08-11 21:39:38 +03:00
|
|
|
|
|
|
|
; Connect to the server
|
2013-05-28 21:34:26 +04:00
|
|
|
mcall connect, [socketnum], sockaddr1, 18
|
2015-08-03 21:07:56 +03:00
|
|
|
cmp eax, -1
|
|
|
|
je err_connect
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2015-08-13 22:20:59 +03:00
|
|
|
; Verify handshake from server
|
2013-05-28 21:34:26 +04:00
|
|
|
call wait_for_data
|
2015-08-03 15:32:28 +03:00
|
|
|
cmp dword[receive_buffer], "RFB "
|
2015-08-03 21:07:56 +03:00
|
|
|
jne err_proto
|
2015-08-13 22:20:59 +03:00
|
|
|
add esi, 12
|
|
|
|
|
|
|
|
; Did we get an error message already?
|
|
|
|
cmp eax, 16
|
|
|
|
jb @f
|
|
|
|
lodsd
|
|
|
|
test eax, eax
|
|
|
|
je err_handshake
|
|
|
|
@@:
|
2015-08-11 21:39:38 +03:00
|
|
|
|
|
|
|
; Reply to handshake
|
2015-08-05 12:37:00 +03:00
|
|
|
DEBUGF 1, "Sending handshake\n"
|
2015-08-03 21:07:56 +03:00
|
|
|
mcall send, [socketnum], HandShake, 12, 0
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2015-08-13 22:20:59 +03:00
|
|
|
; VNC 3.3 protocol: server decides security type
|
|
|
|
call wait_for_data
|
|
|
|
lodsd
|
|
|
|
cmp eax, 0x00000000
|
|
|
|
je err_handshake
|
|
|
|
cmp eax, 0x01000000 ; no security
|
2015-08-05 12:37:00 +03:00
|
|
|
je initialize
|
2015-08-13 22:20:59 +03:00
|
|
|
cmp eax, 0x02000000 ; VNC security
|
2013-05-28 21:34:26 +04:00
|
|
|
je vnc_security
|
2015-08-13 22:20:59 +03:00
|
|
|
jmp err_proto
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
vnc_security:
|
|
|
|
|
2015-08-13 22:20:59 +03:00
|
|
|
push esi ; pointer to message
|
|
|
|
|
2015-08-05 12:37:00 +03:00
|
|
|
mov dword[password], 0
|
|
|
|
mov dword[password+4], 0
|
|
|
|
|
|
|
|
and [USERbox.flags], not ed_focus
|
|
|
|
or [USERbox.flags], ed_disabled
|
|
|
|
or [PASSbox.flags], ed_focus
|
|
|
|
|
|
|
|
mov [status], STATUS_REQ_LOGIN
|
|
|
|
inc [update_gui]
|
|
|
|
@@:
|
|
|
|
mcall 5, 10
|
|
|
|
cmp [status], STATUS_LOGIN
|
|
|
|
je @f
|
|
|
|
cmp [status], STATUS_REQ_LOGIN
|
|
|
|
je @r
|
|
|
|
mcall -1
|
|
|
|
@@:
|
|
|
|
DEBUGF 1, "VNC authentication\n"
|
|
|
|
|
|
|
|
; Bit reverse the password and create DES keys
|
|
|
|
mov ebx, dword[password]
|
|
|
|
mov edx, ebx
|
|
|
|
and ebx, 0xf0f0f0f0
|
|
|
|
shr ebx, 4
|
|
|
|
and edx, 0x0f0f0f0f
|
|
|
|
shl edx, 4
|
|
|
|
or ebx, edx
|
|
|
|
mov edx, ebx
|
|
|
|
and ebx, 0xCCCCCCCC
|
|
|
|
shr ebx, 2
|
|
|
|
and edx, 0x33333333
|
|
|
|
shl edx, 2
|
|
|
|
or ebx, edx
|
|
|
|
mov edx, ebx
|
|
|
|
and ebx, 0xAAAAAAAA
|
|
|
|
shr ebx, 1
|
|
|
|
and edx, 0x55555555
|
|
|
|
shl edx, 1
|
|
|
|
or ebx, edx
|
|
|
|
bswap ebx
|
|
|
|
|
|
|
|
mov eax, dword[password+4]
|
|
|
|
mov edx, eax
|
|
|
|
and eax, 0xf0f0f0f0
|
|
|
|
shr eax, 4
|
|
|
|
and edx, 0x0f0f0f0f
|
|
|
|
shl edx, 4
|
|
|
|
or eax, edx
|
|
|
|
mov edx, eax
|
|
|
|
and eax, 0xCCCCCCCC
|
|
|
|
shr eax, 2
|
|
|
|
and edx, 0x33333333
|
|
|
|
shl edx, 2
|
|
|
|
or eax, edx
|
|
|
|
mov edx, eax
|
|
|
|
and eax, 0xAAAAAAAA
|
|
|
|
shr eax, 1
|
|
|
|
and edx, 0x55555555
|
|
|
|
shl edx, 1
|
|
|
|
or edx, eax
|
|
|
|
bswap edx
|
|
|
|
|
|
|
|
mov edi, keys
|
|
|
|
call DES_create_keys
|
|
|
|
|
|
|
|
; Encrypt message with DES
|
2015-08-13 22:20:59 +03:00
|
|
|
mov esi, [esp]
|
|
|
|
mov ebx, dword[esi+0]
|
|
|
|
mov edx, dword[esi+4]
|
2015-08-05 12:37:00 +03:00
|
|
|
call encrypt_DES
|
2015-08-13 22:20:59 +03:00
|
|
|
mov esi, [esp]
|
|
|
|
mov dword[esi+0], ebx
|
|
|
|
mov dword[esi+4], edx
|
2015-08-05 12:37:00 +03:00
|
|
|
|
2015-08-13 22:20:59 +03:00
|
|
|
mov ebx, dword[esi+8]
|
|
|
|
mov edx, dword[esi+12]
|
2015-08-05 12:37:00 +03:00
|
|
|
call encrypt_DES
|
2015-08-13 22:20:59 +03:00
|
|
|
mov esi, [esp]
|
|
|
|
mov dword[esi+8], ebx
|
|
|
|
mov dword[esi+12], edx
|
2015-08-05 12:37:00 +03:00
|
|
|
|
|
|
|
; 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
|
2015-08-13 22:20:59 +03:00
|
|
|
pop edx
|
|
|
|
mcall send, [socketnum], , 16, 0
|
2015-08-05 12:37:00 +03:00
|
|
|
|
2015-08-13 22:20:59 +03:00
|
|
|
securityresult:
|
|
|
|
; Wait for SecurityResult from server
|
2015-08-05 12:37:00 +03:00
|
|
|
call wait_for_data
|
2015-08-13 22:20:59 +03:00
|
|
|
cmp dword[receive_buffer], 0 ; OK
|
2015-08-05 12:37:00 +03:00
|
|
|
jne err_login
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
DEBUGF 1, "Sending ClientInit\n"
|
2015-08-03 15:32:28 +03:00
|
|
|
mcall send, [socketnum], ClientInit, 1, 0
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
call wait_for_data ; now the server should send init message
|
|
|
|
|
2015-08-03 15:32:28 +03: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 21:34:26 +04:00
|
|
|
|
2015-08-03 15:32:28 +03:00
|
|
|
mov eax, dword[receive_buffer+framebuffer.width]
|
2015-08-03 21:07:56 +03:00
|
|
|
mov dword[FramebufferUpdateRequest.width], eax
|
2013-05-28 21:34:26 +04:00
|
|
|
bswap eax
|
2015-08-03 15:32:28 +03:00
|
|
|
mov dword[screen], eax
|
|
|
|
DEBUGF 1, "Screen width=%u, height=%u\n", [screen.width]:2, [screen.height]:2
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2015-08-03 15:32:28 +03:00
|
|
|
DEBUGF 1, "Sending pixel format\n"
|
2015-08-04 19:29:37 +03:00
|
|
|
if BITS_PER_PIXEL = 8
|
|
|
|
mcall send, [socketnum], SetPixelFormat8, 20, 0
|
|
|
|
else if BITS_PER_PIXEL = 16
|
|
|
|
mcall send, [socketnum], SetPixelFormat16, 20, 0
|
|
|
|
else
|
|
|
|
mcall send, [socketnum], SetPixelFormat24, 20, 0
|
|
|
|
end if
|
2015-08-03 15:32:28 +03:00
|
|
|
|
|
|
|
DEBUGF 1, "Sending encoding info\n"
|
2015-08-10 14:09:36 +03:00
|
|
|
mcall send, [socketnum], SetEncodings, SetEncodings.length, 0
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2015-08-03 21:07:56 +03:00
|
|
|
; Set main window caption to servername
|
|
|
|
mov ecx, dword[receive_buffer+framebuffer.name_length]
|
|
|
|
bswap ecx
|
|
|
|
cmp ecx, 64
|
|
|
|
jbe @f
|
|
|
|
mov ecx, 64
|
|
|
|
@@:
|
|
|
|
lea esi, [receive_buffer+framebuffer.name]
|
|
|
|
mov edi, servername
|
|
|
|
rep movsb
|
|
|
|
mov byte[edi], 0
|
|
|
|
mov [name.dash], "-"
|
|
|
|
|
|
|
|
; Tell the main thread we are ready for business!
|
|
|
|
mov [status], STATUS_CONNECTED
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2015-08-11 21:39:38 +03:00
|
|
|
; Request initial framebuffer update from server
|
2015-08-03 21:07:56 +03:00
|
|
|
mov [FramebufferUpdateRequest.inc], 0
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2015-08-03 15:32:28 +03:00
|
|
|
request_fbu:
|
|
|
|
DEBUGF 1, "Requesting framebuffer update\n"
|
2015-08-03 21:07:56 +03:00
|
|
|
mcall send, [socketnum], FramebufferUpdateRequest, 10, 0
|
|
|
|
mov [FramebufferUpdateRequest.inc], 1
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
thread_loop:
|
|
|
|
call read_data ; Read the data into the buffer
|
|
|
|
|
2015-08-03 15:32:28 +03:00
|
|
|
lodsb
|
|
|
|
cmp al, 0
|
2013-05-28 21:34:26 +04:00
|
|
|
je framebufferupdate
|
2015-08-03 15:32:28 +03:00
|
|
|
cmp al, 1
|
2013-05-28 21:34:26 +04:00
|
|
|
je setcolourmapentries
|
2015-08-03 15:32:28 +03:00
|
|
|
cmp al, 2
|
2013-05-28 21:34:26 +04:00
|
|
|
je bell
|
2015-08-03 15:32:28 +03:00
|
|
|
cmp al, 3
|
2013-05-28 21:34:26 +04:00
|
|
|
je servercuttext
|
|
|
|
|
2015-08-04 11:59:09 +03:00
|
|
|
DEBUGF 2, "Unknown server command: %u\n", al
|
2013-05-28 21:34:26 +04:00
|
|
|
jmp thread_loop
|
|
|
|
|
|
|
|
framebufferupdate:
|
|
|
|
|
2015-08-03 15:32:28 +03:00
|
|
|
@@:
|
|
|
|
lea eax, [esi+6]
|
|
|
|
cmp [datapointer], eax
|
|
|
|
jae @f
|
|
|
|
call read_data.more
|
|
|
|
jmp @b
|
|
|
|
@@:
|
|
|
|
|
|
|
|
inc esi ; padding
|
|
|
|
lodsw
|
2013-05-28 21:34:26 +04:00
|
|
|
xchg al, ah
|
2015-08-03 15:32:28 +03:00
|
|
|
mov [rectangles], ax
|
|
|
|
DEBUGF 1, "Framebufferupdate: %u rectangles\n", ax
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2015-08-03 15:32:28 +03:00
|
|
|
rectangle_loop:
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2015-08-03 15:32:28 +03:00
|
|
|
@@:
|
|
|
|
lea eax, [esi+12]
|
|
|
|
cmp [datapointer], eax
|
|
|
|
jae @f
|
|
|
|
call read_data.more
|
|
|
|
jmp @b
|
|
|
|
@@:
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2015-08-03 21:07:56 +03:00
|
|
|
xor eax, eax
|
|
|
|
lodsw
|
|
|
|
xchg al, ah
|
|
|
|
mov [rectangle.x], eax
|
|
|
|
lodsw
|
|
|
|
xchg al, ah
|
|
|
|
mov [rectangle.y], eax
|
|
|
|
lodsw
|
|
|
|
xchg al, ah
|
|
|
|
mov [rectangle.width], eax
|
|
|
|
lodsw
|
|
|
|
xchg al, ah
|
|
|
|
mov [rectangle.height], eax
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2015-08-03 15:32:28 +03:00
|
|
|
lodsd ; encoding
|
2015-08-10 14:09:36 +03:00
|
|
|
bswap eax
|
2015-08-11 21:39:38 +03:00
|
|
|
DEBUGF 1, "Rectangle: x=%u y=%u width=%u height=%u encoding: ",\
|
|
|
|
[rectangle.x]:2, [rectangle.y]:2, [rectangle.width]:2, [rectangle.height]:2
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
cmp eax, 0
|
|
|
|
je encoding_raw
|
2015-08-03 16:13:09 +03:00
|
|
|
cmp eax, 1
|
2015-08-03 21:07:56 +03:00
|
|
|
je encoding_CopyRect
|
|
|
|
cmp eax, 2
|
|
|
|
je encoding_RRE
|
2015-08-13 22:20:59 +03:00
|
|
|
cmp eax, 15
|
|
|
|
je encoding_TRLE
|
|
|
|
cmp eax, 16
|
|
|
|
je encoding_ZRLE
|
2015-08-03 15:32:28 +03:00
|
|
|
|
2015-08-04 11:59:09 +03:00
|
|
|
DEBUGF 2, "unknown encoding: %u\n", eax
|
2013-05-28 21:34:26 +04:00
|
|
|
jmp thread_loop
|
|
|
|
|
2015-08-03 15:32:28 +03:00
|
|
|
next_rectangle:
|
2015-08-04 11:59:09 +03:00
|
|
|
inc [update_framebuffer]
|
2015-08-03 15:32:28 +03:00
|
|
|
dec [rectangles]
|
|
|
|
jnz rectangle_loop
|
|
|
|
jmp request_fbu
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
|
|
|
|
setcolourmapentries:
|
|
|
|
|
2015-08-03 15:32:28 +03:00
|
|
|
DEBUGF 1, "Server sent SetColourMapEntries message\n"
|
|
|
|
|
2015-08-04 19:29:37 +03:00
|
|
|
@@:
|
|
|
|
lea eax, [esi+5]
|
|
|
|
cmp [datapointer], eax
|
|
|
|
jae @f
|
|
|
|
call read_data.more
|
|
|
|
jmp @b
|
|
|
|
@@:
|
|
|
|
|
|
|
|
inc esi ; padding
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
lodsw ; first color (just ignore for now)
|
|
|
|
|
|
|
|
lodsw ; number of colors (use to find end of message)
|
|
|
|
xchg al, ah
|
|
|
|
lea eax, [eax*2+eax]
|
|
|
|
shl eax, 1
|
|
|
|
@@:
|
|
|
|
push eax
|
|
|
|
add eax, esi
|
|
|
|
cmp [datapointer], eax
|
|
|
|
jae @f
|
|
|
|
call read_data.more
|
|
|
|
pop eax
|
|
|
|
jmp @b
|
|
|
|
@@:
|
|
|
|
pop eax
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2015-08-04 19:29:37 +03:00
|
|
|
add esi, eax ; Just skip it for now.
|
2013-05-28 21:34:26 +04:00
|
|
|
jmp thread_loop
|
|
|
|
|
|
|
|
|
|
|
|
bell:
|
|
|
|
mcall 55, 55, , , beep
|
|
|
|
jmp thread_loop
|
|
|
|
|
|
|
|
|
|
|
|
servercuttext:
|
|
|
|
|
2015-08-03 15:32:28 +03: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 21:34:26 +04:00
|
|
|
|
2015-08-03 15:32:28 +03: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 21:34:26 +04:00
|
|
|
jmp thread_loop
|
|
|
|
|
|
|
|
|
|
|
|
read_data:
|
|
|
|
mov [datapointer], receive_buffer
|
2015-08-03 15:32:28 +03:00
|
|
|
mov esi, receive_buffer
|
|
|
|
.more:
|
|
|
|
push ebx ecx edx esi edi
|
2015-08-04 19:29:37 +03:00
|
|
|
neg esi
|
|
|
|
add esi, receive_buffer + RECEIVE_BUFFER_SIZE
|
|
|
|
jz .buffer_end_reached
|
|
|
|
xor edi, edi
|
|
|
|
mcall recv, [socketnum], [datapointer]
|
2015-08-03 15:32:28 +03:00
|
|
|
pop edi esi edx ecx ebx
|
2013-05-28 21:34:26 +04:00
|
|
|
cmp eax, -1
|
2015-08-04 19:29:37 +03:00
|
|
|
je err_sock
|
|
|
|
test eax, eax
|
|
|
|
jz err_disconnected
|
2015-08-03 21:07:56 +03:00
|
|
|
add [datapointer], eax
|
2015-08-04 19:29:37 +03:00
|
|
|
ret
|
|
|
|
|
|
|
|
.buffer_end_reached:
|
2015-08-13 22:20:59 +03:00
|
|
|
DEBUGF 1, "end of buffer reached, re-organizing\n"
|
|
|
|
pop edi esi edx ecx ebx
|
2015-08-03 21:07:56 +03:00
|
|
|
; Buffer is full, first needed data by program is pointed to by esi.
|
2015-08-04 19:29:37 +03:00
|
|
|
; Move all usefull data to begin of buffer
|
2015-08-03 21:07:56 +03:00
|
|
|
cmp esi, receive_buffer
|
|
|
|
je err_proto
|
|
|
|
mov ecx, [datapointer]
|
|
|
|
sub ecx, esi
|
|
|
|
mov edi, receive_buffer
|
|
|
|
rep movsb
|
2015-08-04 19:29:37 +03:00
|
|
|
mov [datapointer], edi ; new end of data
|
|
|
|
mov esi, receive_buffer ; new start of data
|
|
|
|
jmp .more
|
|
|
|
|
2013-05-28 21:34:26 +04:00
|
|
|
|
|
|
|
|
2015-08-03 15:32:28 +03:00
|
|
|
wait_for_data: ; FIXME: add timeout
|
2015-08-04 19:29:37 +03:00
|
|
|
mcall recv, [socketnum], receive_buffer, 4096, 0 ; MSG_DONTWAIT
|
2013-05-28 21:34:26 +04:00
|
|
|
cmp eax, -1
|
2015-08-04 19:29:37 +03:00
|
|
|
je err_sock
|
2013-05-28 21:34:26 +04:00
|
|
|
test eax, eax
|
2015-08-04 19:29:37 +03:00
|
|
|
jz err_disconnected
|
2015-08-13 22:20:59 +03:00
|
|
|
mov esi, receive_buffer
|
2015-08-03 21:07:56 +03:00
|
|
|
ret
|
2013-05-28 21:34:26 +04:00
|
|
|
|
2015-08-03 21:07:56 +03:00
|
|
|
|
|
|
|
err_disconnected:
|
|
|
|
mov [status], STATUS_DISCONNECTED
|
|
|
|
inc [update_gui]
|
|
|
|
mcall -1
|
|
|
|
|
|
|
|
err_dns:
|
|
|
|
mov [status], STATUS_DNS_ERR
|
|
|
|
inc [update_gui]
|
|
|
|
mcall -1
|
|
|
|
|
|
|
|
err_sock:
|
|
|
|
mov [status], STATUS_SOCK_ERR
|
|
|
|
inc [update_gui]
|
|
|
|
mcall -1
|
|
|
|
|
|
|
|
err_connect:
|
|
|
|
mov [status], STATUS_CONNECT_ERR
|
|
|
|
inc [update_gui]
|
|
|
|
mcall -1
|
2013-05-28 21:34:26 +04:00
|
|
|
ret
|
|
|
|
|
2015-08-03 21:07:56 +03:00
|
|
|
err_proto:
|
|
|
|
mov [status], STATUS_PROTO_ERR
|
|
|
|
inc [update_gui]
|
2015-08-03 15:32:28 +03:00
|
|
|
mcall -1
|
|
|
|
ret
|
|
|
|
|
2015-08-13 22:20:59 +03:00
|
|
|
err_handshake:
|
2015-08-03 21:07:56 +03:00
|
|
|
mov [status], STATUS_SECURITY_ERR
|
2015-08-13 22:20:59 +03:00
|
|
|
|
|
|
|
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:
|
|
|
|
|
2015-08-03 21:07:56 +03:00
|
|
|
inc [update_gui]
|
|
|
|
mcall -1
|
|
|
|
ret
|
2015-08-05 12:37:00 +03:00
|
|
|
|
|
|
|
err_login:
|
|
|
|
mov [status], STATUS_LOGIN_FAILED
|
|
|
|
inc [update_gui]
|
|
|
|
mcall -1
|
|
|
|
ret
|