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