Subversion Repositories Kolibri OS

Rev

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

  1. ;
  2. ; Netstat for KolibriOS v0.1  (still alpha version)
  3. ;
  4. ; hidnplayr@gmail.com
  5. ;
  6.  
  7. use32
  8.  
  9.     org     0x0
  10.  
  11.     db     'MENUET01'        ; 8 byte id
  12.     dd     0x01              ; header version
  13.     dd     START             ; start of code
  14.     dd     IM_END            ; size of image
  15.     dd     (I_END+0x100)     ; memory for app
  16.     dd     (I_END+0x100)     ; esp
  17.     dd     I_PARAM , 0x0     ; I_Param , I_Icon
  18.  
  19. __DEBUG__ equ 1
  20. __DEBUG_LEVEL__ equ 1
  21.  
  22. include '..\macros.inc'
  23. include '..\debug-fdo.inc'
  24.  
  25. START:                                 ; start of execution
  26.     ; TODO: check Parameters
  27.  
  28.     DEBUGF 1, 'Hello!\n'
  29.  
  30.  
  31.   redraw:
  32.  
  33.     mcall   12, 1
  34.  
  35.     mcall   0, 100 shl 16 + 520, 100 shl 16 + 240, 0x34bcbcbc, ,name
  36.  
  37.     mov     edx, 101
  38.     mov     esi, 0x00aaaaff
  39.     mov     edi, 0x00aaffff
  40.  
  41.     cmp     dl, [mode]
  42.     cmove   esi, edi
  43.     mcall   8, 25 shl 16 + 65, 25 shl 16 + 20
  44.  
  45.    @@:
  46.     inc     edx
  47.     add     ebx, 75 shl 16
  48.     mov     esi, 0x00aaaaff
  49.  
  50.     cmp     dl, [mode]
  51.     cmove   esi, edi
  52.     mcall
  53.  
  54.     cmp     edx, 105
  55.     jle     @r
  56.  
  57.     mcall   4, 28 shl 16 + 31, 0x80000000, modes
  58.  
  59.     cmp     [mode], 101
  60.     jne     @f
  61.  
  62.     mcall   4, 20 shl 16 + 75, 0x80000000, str_packets_tx
  63.     add     ebx, 18
  64.     mov     edx, str_packets_rx
  65.     mcall
  66.     add     ebx, 18
  67.     mov     edx, str_bytes_tx
  68.     mcall
  69.     add     ebx, 18
  70.     mov     edx, str_bytes_rx
  71.     mcall
  72.     add     ebx, 18
  73.     mov     edx, str_MAC
  74.     mcall
  75.     add     ebx, 18
  76.     mov     edx, str_queue_in
  77.     mcall
  78.     add     ebx, 18
  79.     mov     edx, str_queue_out
  80.     mcall
  81.  
  82.     mov     ebx,1337 shl 16 + 4
  83.     mov     bh, [device]
  84.     mcall   75
  85.     push    eax
  86.     push    bx
  87.  
  88.     mov     edx, 135 shl 16 + 75 + 4*18
  89.     call    draw_mac
  90.     jmp     end_of_draw
  91.  
  92.  @@:
  93.  
  94.     cmp     [mode], 102
  95.     jne     @f
  96.  
  97.     mcall   4, 20 shl 16 + 75, 0x80000000, str_packets_tx
  98.     add     ebx, 18
  99.     mov     edx, str_packets_rx
  100.     mcall
  101.     add     ebx, 18
  102.     mov     edx, str_ip
  103.     mcall
  104.     add     ebx, 18
  105.     mov     edx, str_dns
  106.     mcall
  107.     add     ebx, 18
  108.     mov     edx, str_subnet
  109.     mcall
  110.     add     ebx, 18
  111.     mov     edx, str_gateway
  112.     mcall
  113.  
  114.  
  115.     mov     ebx, 0 shl 16 + 8
  116.     mov     bh, [device]
  117.     mcall   75
  118.     push    eax
  119.  
  120.     dec     bl
  121.     dec     bl
  122.     mcall   75
  123.     push    eax
  124.  
  125.     dec     bl
  126.     dec     bl
  127.     mcall   75
  128.     push    eax
  129.  
  130.     dec     bl
  131.     dec     bl
  132.     mcall   75
  133.     push    eax
  134.  
  135.     mov     edx, 135 shl 16 + 75 + 2*18
  136.     call    draw_ip
  137.  
  138.     add     edx, 18
  139.     call    draw_ip
  140.  
  141.     add     edx, 18
  142.     call    draw_ip
  143.  
  144.     add     edx, 18
  145.     call    draw_ip
  146.  
  147.     jmp     end_of_draw
  148.  
  149.  @@:
  150.  
  151.     cmp     [mode], 103
  152.     jne     @f
  153.  
  154.     mcall   4, 20 shl 16 + 75, 0x80000000, str_packets_tx
  155.     add     ebx, 18
  156.     mov     edx, str_packets_rx
  157.     mcall
  158.     add     ebx, 18
  159.     mov     edx, str_arp
  160.     mcall
  161.  
  162.     jmp     end_of_draw
  163.  
  164.  @@:
  165.  
  166.     mcall   4, 20 shl 16 + 75, 0x80000000, str_packets_tx
  167.     add     ebx, 18
  168.     mov     edx, str_packets_rx
  169.     mcall
  170.  
  171.  end_of_draw:
  172.  
  173.     mcall   12, 2
  174.  
  175.     jmp     draw_stats
  176.  
  177.   mainloop:
  178.  
  179.     mcall   23,50                  ; wait for event with timeout    (0,5 s)
  180.  
  181.     cmp     eax, 1
  182.     je      redraw
  183.     cmp     eax, 2
  184.     je      key
  185.     cmp     eax, 3
  186.     je      button
  187.  
  188.  
  189.  
  190.  
  191. ;-------------------------------
  192. ;
  193. ;------------------------------
  194.  
  195.   draw_stats:
  196.  
  197.     cmp     [mode], 101
  198.     jne     not_101
  199.  
  200.     mov     ebx, 1337 shl 16 + 0
  201.     mov     bh, [device]
  202.    @@:
  203.     push    ebx
  204.     mcall   75
  205.     pop     ebx
  206.     push    eax
  207.     inc     bl
  208.     cmp     bl, 3
  209.     jle     @r
  210.  
  211.     inc     bl   ;5
  212.     inc     bl   ;6
  213.  
  214.    @@:
  215.     push    ebx
  216.     mcall   75
  217.     pop     ebx
  218.     push    eax
  219.     inc     bl
  220.     cmp     bl, 7
  221.     jle     @r
  222.  
  223.     mov     eax, 47
  224.     mov     ebx, 0x000a0000
  225.     mov     esi, 0x40000000
  226.     mov     edi, 0x00bcbcbc
  227.     mov     edx, 135 shl 16 + 75 + 6*18
  228.     pop     ecx
  229.     mcall
  230.     sub     edx, 18
  231.     pop     ecx
  232.     mcall
  233.     sub     edx, 2*18
  234.     pop     ecx
  235.     mcall
  236.     sub     edx, 18
  237.     pop     ecx
  238.     mcall
  239.     sub     edx, 18
  240.     pop     ecx
  241.     mcall
  242.     sub     edx, 18
  243.     pop     ecx
  244.     mcall
  245.  
  246.     jmp     mainloop
  247.  
  248.  
  249.  not_101:
  250.  
  251.     cmp     [mode], 102
  252.     jne     not_102
  253.  
  254.     mov     ebx, 0 shl 16
  255.     mov     bh, [device]
  256.     push    ebx
  257.     mcall   75
  258.     pop     ebx
  259.     push    eax
  260.     inc     bl
  261.     push    ebx
  262.     mcall   75
  263.     pop     ebx
  264.     push    eax
  265.     inc     bl
  266.  
  267.     mov     eax, 47
  268.     mov     ebx, 0x000a0000
  269.     mov     esi, 0x40000000
  270.     mov     edi, 0x00bcbcbc
  271.     mov     edx, 135 shl 16 + 75 + 18
  272.     pop     ecx
  273.     mcall
  274.     sub     edx, 18
  275.     pop     ecx
  276.     mcall
  277.  
  278.     jmp     mainloop
  279.  
  280.  
  281.  not_102:
  282.  
  283.     cmp     [mode], 103
  284.     jne     not_103
  285.  
  286.     mov     ebx, 0x0608 shl 16 + 0
  287.     mov     bh, [device]
  288.     push    ebx
  289.     mcall   75
  290.     pop     ebx
  291.     push    eax
  292.     inc     bl
  293.     push    ebx
  294.     mcall   75
  295.     pop     ebx
  296.     push    eax
  297.     inc     bl
  298.     push    ebx
  299.     mcall   75
  300.     pop     ebx
  301.     push    eax
  302.     inc     bl
  303.  
  304.     mov     eax, 47
  305.     mov     ebx, 0x000a0000
  306.     mov     esi, 0x40000000
  307.     mov     edi, 0x00bcbcbc
  308.     mov     edx, 135 shl 16 + 75 + 2*18
  309.     pop     ecx
  310.     mcall
  311.     sub     edx, 18
  312.     pop     ecx
  313.     mcall
  314.     sub     edx, 18
  315.     pop     ecx
  316.     mcall
  317.  
  318.     jmp     mainloop
  319.  
  320. not_103:
  321.  
  322.     cmp     [mode], 104
  323.     jne     not_104
  324.  
  325.     mov     ebx, 1 shl 16 + 0
  326.     mov     bh, [device]
  327.     push    ebx
  328.     mcall   75
  329.     pop     ebx
  330.     push    eax
  331.     inc     bl
  332.     push    ebx
  333.     mcall   75
  334.     pop     ebx
  335.     push    eax
  336.     inc     bl
  337.  
  338.     mov     eax, 47
  339.     mov     ebx, 0x000a0000
  340.     mov     esi, 0x40000000
  341.     mov     edi, 0x00bcbcbc
  342.     mov     edx, 135 shl 16 + 75 + 18
  343.     pop     ecx
  344.     mcall
  345.     sub     edx, 18
  346.     pop     ecx
  347.     mcall
  348.  
  349.     jmp     mainloop
  350.  
  351. not_104:
  352.  
  353.     cmp     [mode], 105
  354.     jne     not_105
  355.  
  356.     mov     ebx, 17 shl 16 + 0
  357.     mov     bh, [device]
  358.     push    ebx
  359.     mcall   75
  360.     pop     ebx
  361.     push    eax
  362.     inc     bl
  363.     push    ebx
  364.     mcall   75
  365.     pop     ebx
  366.     push    eax
  367.     inc     bl
  368.  
  369.     mov     eax, 47
  370.     mov     ebx, 0x000a0000
  371.     mov     esi, 0x40000000
  372.     mov     edi, 0x00bcbcbc
  373.     mov     edx, 135 shl 16 + 75 + 18
  374.     pop     ecx
  375.     mcall
  376.     sub     edx, 18
  377.     pop     ecx
  378.     mcall
  379.  
  380.     jmp     mainloop
  381.  
  382. not_105:
  383.  
  384.     cmp     [mode], 106
  385.     jne     not_106
  386.  
  387.     mov     ebx, 6 shl 16 + 0
  388.     mov     bh, [device]
  389.     push    ebx
  390.     mcall   75
  391.     pop     ebx
  392.     push    eax
  393.     inc     bl
  394.     push    ebx
  395.     mcall   75
  396.     pop     ebx
  397.     push    eax
  398.     inc     bl
  399.  
  400.     mov     eax, 47
  401.     mov     ebx, 0x000a0000
  402.     mov     esi, 0x40000000
  403.     mov     edi, 0x00bcbcbc
  404.     mov     edx, 135 shl 16 + 75 + 18
  405.     pop     ecx
  406.     mcall
  407.     sub     edx, 18
  408.     pop     ecx
  409.     mcall
  410.  
  411.     jmp     mainloop
  412.  
  413. not_106:
  414.  
  415.     jmp     mainloop
  416.  
  417.   key:
  418.     mcall   2
  419.     jmp     mainloop
  420.  
  421.  
  422.   button:                         ; button
  423.     mcall   17                    ; get id
  424.     cmp     ah, 1
  425.     je      close
  426.     mov     [mode], ah
  427.     jmp     redraw
  428.  
  429.   close:
  430.     mcall   -1
  431.  
  432.  
  433.  
  434. draw_mac:
  435.  
  436.         mov     eax, 47
  437.         mov     ebx, 0x00020100
  438.         mov     esi, 0x40000000
  439.         mov     edi, 0x00bcbcbc
  440.  
  441.         mov     cl, [esp+4]
  442.         mcall
  443.  
  444.         mov     cl, [esp+4+1]
  445.         add     edx, 15 shl 16
  446.         mcall
  447.  
  448.         mov     cl, [esp+4+2]
  449.         add     edx, 15 shl 16
  450.         mcall
  451.  
  452.         mov     cl, [esp+4+3]
  453.         add     edx, 15 shl 16
  454.         mcall
  455.  
  456.         mov     cl, [esp+4+4]
  457.         add     edx, 15 shl 16
  458.         mcall
  459.  
  460.         mov     cl, [esp+4+5]
  461.         add     edx, 15 shl 16
  462.         mcall
  463.  
  464.         mov     eax, [esp]
  465.         add     esp, 6+4
  466.         sub     edx, 5*15 shl 16
  467.  
  468.         jmp     eax
  469.  
  470.  
  471. draw_ip:
  472.  
  473.         mov     eax, 47
  474.         mov     ebx, 0x00030000
  475.         mov     esi, 0x40000000
  476.         mov     edi, 0x00bcbcbc
  477.  
  478.         xor     ecx, ecx
  479.  
  480.         mov     cl, [esp+4]
  481.         mcall
  482.  
  483.         mov     cl, [esp+4+1]
  484.         add     edx, 30 shl 16
  485.         mcall
  486.  
  487.         mov     cl, [esp+4+2]
  488.         add     edx, 30 shl 16
  489.         mcall
  490.  
  491.         mov     cl, [esp+4+3]
  492.         add     edx, 30 shl 16
  493.         mcall
  494.  
  495.         sub     edx, 3*30 shl 16
  496.         mov     eax, [esp]
  497.         add     esp, 8
  498.         jmp     eax
  499.  
  500.  
  501. ; DATA AREA
  502.  
  503. IM_END:
  504.  
  505. name    db 'Netstat',0
  506. mode    db 101
  507. device  db 0
  508. modes   db 'Ethernet        IPv4        ARP         ICMP         UDP         TCP',0
  509.  
  510. str_packets_tx db 'Packets sent:',0
  511. str_packets_rx db 'Packets received:',0
  512. str_bytes_tx   db 'Bytes sent:',0
  513. str_bytes_rx   db 'Bytes received:',0
  514. str_MAC        db 'MAC address:',0
  515. str_queue_in   db 'IN-queue size:',0
  516. str_queue_out  db 'OUT-queue size:',0
  517. str_ip         db 'IP address:',0
  518. str_dns        db 'DNS address:',0
  519. str_subnet     db 'Subnet mask:',0
  520. str_gateway    db 'Standard gateway:',0
  521. str_arp        db 'ARP entrys:',0
  522.  
  523. include_debug_strings    ; ALWAYS present in data section
  524.  
  525. I_PARAM rb 1024
  526.  
  527. I_END:
  528.  
  529.  
  530.