Subversion Repositories Kolibri OS

Rev

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