Subversion Repositories Kolibri OS

Rev

Rev 3618 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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