Subversion Repositories Kolibri OS

Rev

Rev 1539 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1539 Rev 1542
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2010. All rights reserved.         ;;
3
;; Copyright (C) KolibriOS team 2010. All rights reserved.         ;;
4
;; Distributed under terms of the GNU General Public License       ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
5
;;                                                                 ;;
6
;;  Synergyc.asm - Synergy client for KolibriOS                    ;;
6
;;  Synergyc.asm - Synergy client for KolibriOS                    ;;
7
;;                                                                 ;;
7
;;                                                                 ;;
8
;;  Written by hidnplayr@kolibrios.org                             ;;
8
;;  Written by hidnplayr@kolibrios.org                             ;;
9
;;                                                                 ;;
9
;;                                                                 ;;
10
;;          GNU GENERAL PUBLIC LICENSE                             ;;
10
;;          GNU GENERAL PUBLIC LICENSE                             ;;
11
;;             Version 2, June 1991                                ;;
11
;;             Version 2, June 1991                                ;;
12
;;                                                                 ;;
12
;;                                                                 ;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14
 
14
 
15
use32
15
use32
16
	org	0x0
16
	org	0x0
17
 
17
 
18
	db	'MENUET01'	; signature
18
	db	'MENUET01'	; signature
19
	dd	1		; header version
19
	dd	1		; header version
20
	dd	start		; entry point
20
	dd	start		; entry point
21
	dd	i_end		; initialized size
21
	dd	i_end		; initialized size
22
	dd	mem		; required memory
22
	dd	mem		; required memory
23
	dd	mem		; stack pointer
23
	dd	mem		; stack pointer
24
	dd	0		; parameters
24
	dd	0		; parameters
25
	dd	path		; path
25
	dd	path		; path
26
 
26
 
27
BUFFERSIZE	equ 1024
27
BUFFERSIZE	equ 1024
28
 
28
 
29
include '../proc32.inc'
29
include '../proc32.inc'
30
include '../macros.inc'
30
include '../macros.inc'
31
purge mov,add,sub
31
purge mov,add,sub
32
include '../dll.inc'
32
include '../dll.inc'
33
 
33
 
34
include '../network.inc'
34
include '../network.inc'
35
 
35
 
36
start:
36
start:
37
 
37
 
38
	cld
38
	cld
39
	mov	edi, path      ; Calculate the length of zero-terminated string
39
	mov	edi, path      ; Calculate the length of zero-terminated string
40
	xor	al , al
40
	xor	al , al
41
	mov	ecx, 1024
41
	mov	ecx, 1024
42
	repne	scasb
42
	repne	scasb
43
	dec	edi
43
	dec	edi
44
	mov	esi, filename
44
	mov	esi, filename
45
	movsd
45
	movsd
46
	movsb
46
	movsb
47
 
47
 
48
	mcall	68, 11
48
	mcall	68, 11
49
 
49
 
50
	stdcall dll.Load, @IMPORT
50
	stdcall dll.Load, @IMPORT
51
	test	eax, eax
51
	test	eax, eax
52
	jnz	exit
52
	jnz	exit
53
 
53
 
54
	push	1
54
	push	1
55
	call	[con_start]
55
	call	[con_start]
56
 
56
 
57
	push	title
57
	push	title
58
	push	25
58
	push	25
59
	push	80
59
	push	80
60
	push	25
60
	push	25
61
	push	80
61
	push	80
62
	call	[con_init]
62
	call	[con_init]
63
 
63
 
64
	push	path
64
	push	path
65
	call	[con_write_asciiz]
65
	call	[con_write_asciiz]
66
 
66
 
67
	push	newline
67
	push	newline
68
	call	[con_write_asciiz]
68
	call	[con_write_asciiz]
69
 
69
 
70
	push	newline
70
	push	newline
71
	call	[con_write_asciiz]
71
	call	[con_write_asciiz]
72
 
72
 
73
	invoke	ini.get_str, path, str_remote, str_ip, buffer_ptr, 16, 0
73
	invoke	ini.get_str, path, str_remote, str_ip, buffer_ptr, 16, 0
74
	test	eax, eax
74
	test	eax, eax
75
	jnz	error
75
	jnz	error
76
 
76
 
77
	invoke	ini.get_int, path, str_remote, str_port, 24800
77
	invoke	ini.get_int, path, str_remote, str_port, 24800
78
	mov	[sockaddr1.port], ax
78
	mov	[sockaddr1.port], ax
79
 
79
 
80
	push	str1
80
	push	str1
81
	call	[con_write_asciiz]
81
	call	[con_write_asciiz]
82
 
82
 
83
	push	buffer_ptr
83
	push	buffer_ptr
84
	call	[con_write_asciiz]
84
	call	[con_write_asciiz]
85
 
85
 
86
	push	newline
86
	push	newline
87
	call	[con_write_asciiz]
87
	call	[con_write_asciiz]
88
 
88
 
89
	mcall	socket, AF_INET4, IPPROTO_TCP, 0
89
	mcall	socket, AF_INET4, SOCK_STREAM, 0
90
	cmp	eax, -1
90
	cmp	eax, -1
91
	je	error
91
	je	error
92
 
92
 
93
	mov	[socketnum], eax
93
	mov	[socketnum], eax
94
 
94
 
95
	push	buffer_ptr	; hostname
95
	push	buffer_ptr	; hostname
96
	call	[inet_addr]
96
	call	[inet_addr]
97
	cmp	eax, -1
97
	cmp	eax, -1
98
	je	error
98
	je	error
99
	mov	[sockaddr1.ip], eax
99
	mov	[sockaddr1.ip], eax
100
 
100
 
101
	mcall	connect, [socketnum], sockaddr1, 18
101
	mcall	connect, [socketnum], sockaddr1, 18
102
 
102
 
103
	push	str7
103
	push	str7
104
	call	[con_write_asciiz]
104
	call	[con_write_asciiz]
105
 
105
 
106
	mcall	40, 1 shl 7;  + 7
106
	mcall	40, 1 shl 7;  + 7
107
 
107
 
108
login:
108
login:
109
	call	wait_for_data
109
	call	wait_for_data
110
 
110
 
111
	push	buffer_ptr + 4
111
	push	buffer_ptr + 4
112
	call	[con_write_asciiz]
112
	call	[con_write_asciiz]
113
 
113
 
114
	cmp	dword [buffer_ptr], 11 shl 24
114
	cmp	dword [buffer_ptr], 11 shl 24
115
	jne	login
115
	jne	login
116
	cmp	dword [buffer_ptr + 4], 'Syne'
116
	cmp	dword [buffer_ptr + 4], 'Syne'
117
	jne	login
117
	jne	login
118
	cmp	word [buffer_ptr + 8], 'rg'
118
	cmp	word [buffer_ptr + 8], 'rg'
119
	jne	login
119
	jne	login
120
	cmp	byte [buffer_ptr + 10], 'y'
120
	cmp	byte [buffer_ptr + 10], 'y'
121
	jne	login
121
	jne	login
122
 
122
 
123
	push	str2
123
	push	str2
124
	call	[con_write_asciiz]
124
	call	[con_write_asciiz]
125
 
125
 
126
	lea	edi, [buffer_ptr + 11 + 4 + 4]
126
	lea	edi, [buffer_ptr + 11 + 4 + 4]
127
	invoke	ini.get_str, path, str_local, str_name, edi, 255, 0
127
	invoke	ini.get_str, path, str_local, str_name, edi, 255, 0
128
	xor	al , al
128
	xor	al , al
129
	mov	ecx, 256
129
	mov	ecx, 256
130
	repne	scasb
130
	repne	scasb
131
	sub	edi, buffer_ptr + 1 + 4
131
	sub	edi, buffer_ptr + 1 + 4
132
	mov	esi, edi
132
	mov	esi, edi
133
	bswap	edi
133
	bswap	edi
134
	mov	dword [buffer_ptr], edi
134
	mov	dword [buffer_ptr], edi
135
	mov	edi, esi
135
	mov	edi, esi
136
	sub	edi, 11 + 4
136
	sub	edi, 11 + 4
137
	bswap	edi
137
	bswap	edi
138
	mov	dword [buffer_ptr + 11 + 4], edi
138
	mov	dword [buffer_ptr + 11 + 4], edi
139
	add	esi, 4
139
	add	esi, 4
140
 
140
 
141
	mcall	send, [socketnum], buffer_ptr, , 0
141
	mcall	send, [socketnum], buffer_ptr, , 0
142
 
142
 
143
mainloop:
143
mainloop:
144
	call	wait_for_data
144
	call	wait_for_data
145
	mov	edi, buffer_ptr
145
	mov	edi, buffer_ptr
146
 
146
 
147
  .command:
147
  .command:
148
	push	eax edi
148
	push	eax edi
149
 
149
 
150
	cmp	dword [edi + 4], 'QINF' ; query screen info
150
	cmp	dword [edi + 4], 'QINF' ; query screen info
151
	je	.qinf
151
	je	.qinf
152
 
152
 
153
	cmp	dword [edi + 4], 'CALV' ; alive ?
153
	cmp	dword [edi + 4], 'CALV' ; alive ?
154
	je	.calv
154
	je	.calv
155
 
155
 
156
	cmp	dword [edi + 4], 'CINN' ; mouse moved into screen
156
	cmp	dword [edi + 4], 'CINN' ; mouse moved into screen
157
	je	.cinn
157
	je	.cinn
158
 
158
 
159
	cmp	dword [edi + 4], 'DCLP' ; Clipboard event
159
	cmp	dword [edi + 4], 'DCLP' ; Clipboard event
160
	je	.dclp
160
	je	.dclp
161
 
161
 
162
	cmp	dword [edi + 4], 'DMMV' ; Mouse moved
162
	cmp	dword [edi + 4], 'DMMV' ; Mouse moved
163
	je	.dmmv
163
	je	.dmmv
164
 
164
 
165
	cmp	dword [edi + 4], 'COUT' ; leave screen
165
	cmp	dword [edi + 4], 'COUT' ; leave screen
166
	je	.cout
166
	je	.cout
167
 
167
 
168
	cmp	dword [edi + 4], 'DMDN' ; mouse button down
168
	cmp	dword [edi + 4], 'DMDN' ; mouse button down
169
	je	.dmdn
169
	je	.dmdn
170
 
170
 
171
	cmp	dword [edi + 4], 'DMUP' ; mouse button released
171
	cmp	dword [edi + 4], 'DMUP' ; mouse button released
172
	je	.dmup
172
	je	.dmup
173
 
173
 
174
	cmp	dword [edi + 4], 'CNOP' ; no operation
174
	cmp	dword [edi + 4], 'CNOP' ; no operation
175
	je	.next
175
	je	.next
176
 
176
 
177
	cmp	dword [edi + 4], 'CIAK' ; resolution changed?
177
	cmp	dword [edi + 4], 'CIAK' ; resolution changed?
178
	je	.ciak
178
	je	.ciak
179
 
179
 
180
	push	str3
180
	push	str3
181
	call	[con_write_asciiz]
181
	call	[con_write_asciiz]
182
 
182
 
183
	mov	byte[edi+8],0
183
	mov	byte[edi+8],0
184
	add	edi, 4
184
	add	edi, 4
185
	push	edi
185
	push	edi
186
	call	[con_write_asciiz]
186
	call	[con_write_asciiz]
187
 
187
 
188
	push	newline
188
	push	newline
189
	call	[con_write_asciiz]
189
	call	[con_write_asciiz]
190
 
190
 
191
  .next:
191
  .next:
192
	pop	edi eax
192
	pop	edi eax
193
 
193
 
194
	mov	ecx, dword [edi]
194
	mov	ecx, dword [edi]
195
	bswap	ecx
195
	bswap	ecx
196
	add	ecx, 4
196
	add	ecx, 4
197
	sub	eax, ecx
197
	sub	eax, ecx
198
	jle	mainloop
198
	jle	mainloop
199
	add	edi, ecx
199
	add	edi, ecx
200
	jmp	.command
200
	jmp	.command
201
 
201
 
202
 
202
 
203
  .qinf:
203
  .qinf:
204
	mcall	14	; get screen info
204
	mcall	14	; get screen info
205
	add	eax, 0x00010001
205
	add	eax, 0x00010001
206
	bswap	eax
206
	bswap	eax
207
	mov	dword [screeninfo.size], eax
207
	mov	dword [screeninfo.size], eax
208
	mcall	send, [socketnum], screeninfo, screeninfo.length, 0	; send client name
208
	mcall	send, [socketnum], screeninfo, screeninfo.length, 0	; send client name
209
	jmp	.next
209
	jmp	.next
210
 
210
 
211
 
211
 
212
  .calv:
212
  .calv:
213
	mcall	send, [socketnum], calv, calv.length, 0     ; looks like ping-pong event
213
	mcall	send, [socketnum], calv, calv.length, 0     ; looks like ping-pong event
214
	jmp	.next
214
	jmp	.next
215
 
215
 
216
 
216
 
217
  .cinn:
217
  .cinn:
218
	mov	edx, [edi + 8]
218
	mov	edx, [edi + 8]
219
	bswap	edx
219
	bswap	edx
220
	mcall	18, 19, 4
220
	mcall	18, 19, 4
221
	; ignore sequence number and modify key mask for now
221
	; ignore sequence number and modify key mask for now
222
	push	str6
222
	push	str6
223
	call	[con_write_asciiz]
223
	call	[con_write_asciiz]
224
	jmp	.next
224
	jmp	.next
225
 
225
 
226
  .dclp:
226
  .dclp:
227
 
227
 
228
	jmp	.next
228
	jmp	.next
229
 
229
 
230
  .dmmv:
230
  .dmmv:
231
	mov	edx, [edi + 8]
231
	mov	edx, [edi + 8]
232
	bswap	edx
232
	bswap	edx
233
	mcall	18, 19, 4
233
	mcall	18, 19, 4
234
	mcall	send, [socketnum], cnop, cnop.length, 0     ; reply with NOP
234
	mcall	send, [socketnum], cnop, cnop.length, 0     ; reply with NOP
235
	push	str4
235
	push	str4
236
	call	[con_write_asciiz]
236
	call	[con_write_asciiz]
237
	jmp	.next
237
	jmp	.next
238
 
238
 
239
  .cout:
239
  .cout:
240
	jmp	.next
240
	jmp	.next
241
 
241
 
242
  .dmdn:
242
  .dmdn:
243
	movzx	eax, byte [edi + 8]
243
	movzx	eax, byte [edi + 8]
244
	or	[mousestate], eax
244
	or	[mousestate], eax
245
	mcall	18, 19, 5, [mousestate]
245
	mcall	18, 19, 5, [mousestate]
246
	mcall	send, [socketnum], cnop, cnop.length, 0     ; reply with NOP
246
	mcall	send, [socketnum], cnop, cnop.length, 0     ; reply with NOP
247
	push	str5
247
	push	str5
248
	call	[con_write_asciiz]
248
	call	[con_write_asciiz]
249
	jmp	.next
249
	jmp	.next
250
 
250
 
251
  .dmup:
251
  .dmup:
252
	movzx	eax, byte [edi + 8]
252
	movzx	eax, byte [edi + 8]
253
	not	eax
253
	not	eax
254
	and	[mousestate], eax
254
	and	[mousestate], eax
255
	mcall	18, 19, 5, [mousestate]
255
	mcall	18, 19, 5, [mousestate]
256
	mcall	send, [socketnum], cnop, cnop.length, 0     ; reply with NOP
256
	mcall	send, [socketnum], cnop, cnop.length, 0     ; reply with NOP
257
	push	str5
257
	push	str5
258
	call	[con_write_asciiz]
258
	call	[con_write_asciiz]
259
	jmp	.next
259
	jmp	.next
260
 
260
 
261
  .ciak:
261
  .ciak:
262
	jmp	.next
262
	jmp	.next
263
 
263
 
264
error:
264
error:
265
	push	str_err
265
	push	str_err
266
	call	[con_write_asciiz]
266
	call	[con_write_asciiz]
267
 
267
 
268
	call	[con_gets]
268
	call	[con_gets]
269
 
269
 
270
	push	1
270
	push	1
271
	call	[con_exit]
271
	call	[con_exit]
272
 
272
 
273
	mcall	close, [socketnum]
273
	mcall	close, [socketnum]
274
exit:
274
exit:
275
 
275
 
276
	mcall	-1
276
	mcall	-1
277
 
277
 
278
 
278
 
279
wait_for_data:
279
wait_for_data:
280
	mcall	10		; wait for data
280
	mcall	10		; wait for data
281
 
281
 
282
	mcall	recv, [socketnum], buffer_ptr, BUFFERSIZE, 0
282
	mcall	recv, [socketnum], buffer_ptr, BUFFERSIZE, 0
283
	cmp	eax, -1
283
	cmp	eax, -1
284
	je	wait_for_data
284
	je	wait_for_data
285
 
285
 
286
	cmp	eax, 8
286
	cmp	eax, 8
287
	jl	wait_for_data
287
	jl	wait_for_data
288
 
288
 
289
	ret
289
	ret
290
 
290
 
291
 
291
 
292
 
292
 
293
; data
293
; data
294
title	db	'Synergy client',0
294
title	db	'Synergy client',0
295
str1	db	'Connecting to: ',0
295
str1	db	'Connecting to: ',0
296
str7	db	'Connected!',13,10,0
296
str7	db	'Connected!',13,10,0
297
str2	db	13,10,'Handshake received',13,10,0
297
str2	db	13,10,'Handshake received',13,10,0
298
str3	db	'Unsupported command: ',0
298
str3	db	'Unsupported command: ',0
299
newline db	13,10,0
299
newline db	13,10,0
300
str4	db	'mouse moved',13,10,0
300
str4	db	'mouse moved',13,10,0
301
str5	db	'mouse buttons changed',13,10,0
301
str5	db	'mouse buttons changed',13,10,0
302
str6	db	'Enter screen',13,10,0
302
str6	db	'Enter screen',13,10,0
303
str_err db	'Error occured !',13,10,'Press any key to quit',0
303
str_err db	'Error occured !',13,10,'Press any key to quit',0
304
 
304
 
305
screeninfo:
305
screeninfo:
306
	dd (screeninfo.length - 4) shl 24
306
	dd (screeninfo.length - 4) shl 24
307
	db 'DINF'
307
	db 'DINF'
308
	dw 0	; coordinate of leftmost pixel
308
	dw 0	; coordinate of leftmost pixel
309
	dw 0	; coordiante of topmost pixel
309
	dw 0	; coordiante of topmost pixel
310
  .size:
310
  .size:
311
	dw 0	; width
311
	dw 0	; width
312
	dw 0	; height
312
	dw 0	; height
313
 
313
 
314
	dw 0	; size of warp zone
314
	dw 0	; size of warp zone
315
 
315
 
316
	dw 0xb88b	 ; x position of the mouse on the secondary screen  (no idea what it means)
316
	dw 0xb88b	 ; x position of the mouse on the secondary screen  (no idea what it means)
317
	dw 0xbcfb	 ; y position of the mouse on the secondary screen
317
	dw 0xbcfb	 ; y position of the mouse on the secondary screen
318
  .length = $ - screeninfo
318
  .length = $ - screeninfo
319
 
319
 
320
calv:
320
calv:
321
	dd (4) shl 24
321
	dd (4) shl 24
322
	db 'CALV'
322
	db 'CALV'
323
  .length = $ - calv + 8 ; also send cnop
323
  .length = $ - calv + 8 ; also send cnop
324
 
324
 
325
cnop:
325
cnop:
326
	dd (4) shl 24
326
	dd (4) shl 24
327
	db 'CNOP'
327
	db 'CNOP'
328
  .length = $ - cnop
328
  .length = $ - cnop
329
 
329
 
330
mousestate	dd 0
330
mousestate	dd 0
331
 
331
 
332
 
332
 
333
sockaddr1:
333
sockaddr1:
334
	dw AF_INET4
334
	dw AF_INET4
335
.port	dw 24800
335
.port	dw 24800
336
.ip	dd 192 + 168 shl 8 + 1 shl 16 + 115 shl 24
336
.ip	dd 192 + 168 shl 8 + 1 shl 16 + 115 shl 24
337
	rb 10
337
	rb 10
338
 
338
 
339
filename	db	'.ini', 0
339
filename	db	'.ini', 0
340
str_local	db	'local', 0
340
str_local	db	'local', 0
341
str_name	db	'name', 0
341
str_name	db	'name', 0
342
str_remote	db	'remote', 0
342
str_remote	db	'remote', 0
343
str_port	db	'port', 0
343
str_port	db	'port', 0
344
str_ip		db	'ip', 0
344
str_ip		db	'ip', 0
345
 
345
 
346
; import
346
; import
347
align 16
347
align 16
348
@IMPORT:
348
@IMPORT:
349
 
349
 
350
library console,	'console.obj',\
350
library console,	'console.obj',\
351
	libini, 	'libini.obj',\
351
	libini, 	'libini.obj',\
352
	network,	'network.obj'
352
	network,	'network.obj'
353
 
353
 
354
import	network,\
354
import	network,\
355
	inet_addr,	'inet_addr'
355
	inet_addr,	'inet_addr'
356
 
356
 
357
import	console,		\
357
import	console,		\
358
	con_start,		'START',\
358
	con_start,		'START',\
359
	con_init,		'con_init',\
359
	con_init,		'con_init',\
360
	con_write_asciiz,	'con_write_asciiz',\
360
	con_write_asciiz,	'con_write_asciiz',\
361
	con_exit,		'con_exit',\
361
	con_exit,		'con_exit',\
362
	con_gets,		'con_gets',\
362
	con_gets,		'con_gets',\
363
	con_cls,		'con_cls',\
363
	con_cls,		'con_cls',\
364
	con_getch2,		'con_getch2',\
364
	con_getch2,		'con_getch2',\
365
	con_set_cursor_pos,	'con_set_cursor_pos'
365
	con_set_cursor_pos,	'con_set_cursor_pos'
366
 
366
 
367
import	libini,\
367
import	libini,\
368
	ini.get_str,	'ini_get_str',\
368
	ini.get_str,	'ini_get_str',\
369
	ini.get_int,	'ini_get_int'
369
	ini.get_int,	'ini_get_int'
370
 
370
 
371
align	4
371
align	4
372
i_end:
372
i_end:
373
socketnum	dd ?
373
socketnum	dd ?
374
buffer_ptr	rb BUFFERSIZE
374
buffer_ptr	rb BUFFERSIZE
375
path		rb 4096    ; stack
375
path		rb 4096    ; stack
376
mem:
376
mem: