Subversion Repositories Kolibri OS

Rev

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

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