Subversion Repositories Kolibri OS

Rev

Rev 1542 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  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. BUFFERSIZE      equ 1024
  33.  
  34. include '../macros.inc'
  35. purge mov,add,sub
  36. include '../debug-fdo.inc'
  37. include '../proc32.inc'
  38. include '../dll.inc'
  39.  
  40. include '../network.inc'
  41.  
  42. start:
  43.  
  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
  53.  
  54.         mcall   68, 11
  55.  
  56.         stdcall dll.Load, @IMPORT
  57.         test    eax, eax
  58.         jnz     exit
  59.  
  60.         push    1
  61.         call    [con_start]
  62.  
  63.         push    title
  64.         push    25
  65.         push    80
  66.         push    25
  67.         push    80
  68.         call    [con_init]
  69.  
  70.         push    path
  71.         call    [con_write_asciiz]
  72.  
  73.         push    newline
  74.         call    [con_write_asciiz]
  75.  
  76.         push    newline
  77.         call    [con_write_asciiz]
  78.  
  79.         invoke  ini.get_str, path, str_remote, str_ip, buffer_ptr, 16, 0
  80.         test    eax, eax
  81.         jnz     error
  82.  
  83.         invoke  ini.get_int, path, str_remote, str_port, 24800
  84.         mov     [sockaddr1.port], ax
  85.  
  86.         push    str1
  87.         call    [con_write_asciiz]
  88.  
  89.         push    buffer_ptr
  90.         call    [con_write_asciiz]
  91.  
  92.         push    newline
  93.         call    [con_write_asciiz]
  94.  
  95.         mcall   socket, AF_INET4, SOCK_STREAM, 0
  96.         cmp     eax, -1
  97.         je      error
  98.  
  99.         mov     [socketnum], eax
  100.  
  101.         push    buffer_ptr      ; hostname
  102.         call    [inet_addr]
  103.         cmp     eax, -1
  104.         je      error
  105.         mov     [sockaddr1.ip], eax
  106.  
  107.         mcall   connect, [socketnum], sockaddr1, 18
  108.  
  109.         push    str7
  110.         call    [con_write_asciiz]
  111.  
  112.         mcall   40, 1 shl 7;  + 7
  113.  
  114. login:
  115.         call    wait_for_data
  116.  
  117.         push    buffer_ptr + 4
  118.         call    [con_write_asciiz]
  119.  
  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
  128.  
  129.         push    str2
  130.         call    [con_write_asciiz]
  131.  
  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
  146.  
  147.         mcall   send, [socketnum], buffer_ptr, , 0
  148.  
  149. mainloop:
  150.         call    wait_for_data
  151.         mov     edi, buffer_ptr
  152.  
  153.   .command:
  154.         push    eax edi
  155.  
  156.         cmp     dword [edi + 4], 'QINF' ; query screen info
  157.         je      .qinf
  158.  
  159.         cmp     dword [edi + 4], 'CALV' ; alive ?
  160.         je      .calv
  161.  
  162.         cmp     dword [edi + 4], 'CINN' ; mouse moved into screen
  163.         je      .cinn
  164.  
  165.         cmp     dword [edi + 4], 'DCLP' ; Clipboard event
  166.         je      .dclp
  167.  
  168.         cmp     dword [edi + 4], 'DMMV' ; Mouse moved
  169.         je      .dmmv
  170.  
  171.         cmp     dword [edi + 4], 'COUT' ; leave screen
  172.         je      .cout
  173.  
  174.         cmp     dword [edi + 4], 'DMDN' ; mouse button down
  175.         je      .dmdn
  176.  
  177.         cmp     dword [edi + 4], 'DMUP' ; mouse button released
  178.         je      .dmup
  179.  
  180.         cmp     dword [edi + 4], 'CNOP' ; no operation
  181.         je      .next
  182.  
  183.         cmp     dword [edi + 4], 'CIAK' ; resolution changed?
  184.         je      .ciak
  185.  
  186.         push    str3
  187.         call    [con_write_asciiz]
  188.  
  189.         mov     byte[edi+8],0
  190.         add     edi, 4
  191.         push    edi
  192.         call    [con_write_asciiz]
  193.  
  194.         push    newline
  195.         call    [con_write_asciiz]
  196.  
  197.   .next:
  198.         pop     edi eax
  199.  
  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
  207.  
  208.  
  209.   .qinf:
  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
  216.  
  217.  
  218.   .calv:
  219.         mcall   send, [socketnum], calv, calv.length, 0     ; looks like ping-pong event
  220.         jmp     .next
  221.  
  222.  
  223.   .cinn:
  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
  231.  
  232.   .dclp:
  233.  
  234.         jmp     .next
  235.  
  236.   .dmmv:
  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
  244.  
  245.   .cout:
  246.         jmp     .next
  247.  
  248.   .dmdn:
  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
  256.  
  257.   .dmup:
  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
  266.  
  267.   .ciak:
  268.         jmp     .next
  269.  
  270. error:
  271.         push    str_err
  272.         call    [con_write_asciiz]
  273.  
  274.         call    [con_gets]
  275.  
  276.         push    1
  277.         call    [con_exit]
  278.  
  279.         mcall   close, [socketnum]
  280. exit:
  281.  
  282.         mcall   -1
  283.  
  284.  
  285. wait_for_data:
  286.         mcall   10              ; wait for data
  287.  
  288.         mcall   recv, [socketnum], buffer_ptr, BUFFERSIZE, 0
  289.         cmp     eax, -1
  290.         je      wait_for_data
  291.  
  292.         cmp     eax, 8
  293.         jl      wait_for_data
  294.  
  295.         ret
  296.  
  297.  
  298.  
  299. ; data
  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
  310.  
  311. screeninfo:
  312.         dd (screeninfo.length - 4) shl 24
  313.         db 'DINF'
  314.         dw 0    ; coordinate of leftmost pixel
  315.         dw 0    ; coordiante of topmost pixel
  316.   .size:
  317.         dw 0    ; width
  318.         dw 0    ; height
  319.  
  320.         dw 0    ; size of warp zone
  321.  
  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
  324.   .length = $ - screeninfo
  325.  
  326. calv:
  327.         dd (4) shl 24
  328.         db 'CALV'
  329.   .length = $ - calv + 8 ; also send cnop
  330.  
  331. cnop:
  332.         dd (4) shl 24
  333.         db 'CNOP'
  334.   .length = $ - cnop
  335.  
  336. mousestate      dd 0
  337.  
  338.  
  339. sockaddr1:
  340.         dw AF_INET4
  341. .port   dw 24800
  342. .ip     dd 192 + 168 shl 8 + 1 shl 16 + 115 shl 24
  343.         rb 10
  344.  
  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
  351.  
  352. ; import
  353. align 16
  354. @IMPORT:
  355.  
  356. library console,        'console.obj',\
  357.         network,        'network.obj',\
  358.         libini,         'libini.obj'
  359.  
  360. import  network,\
  361.         inet_addr,      'inet_addr'
  362.  
  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'
  372.  
  373. import  libini,\
  374.         ini.get_str,    'ini_get_str',\
  375.         ini.get_int,    'ini_get_int'
  376.  
  377. include_debug_strings
  378.  
  379. align   4
  380. i_end:
  381. socketnum       dd ?
  382. buffer_ptr      rb BUFFERSIZE
  383. path            rb 4096    ; stack
  384. mem: