Subversion Repositories Kolibri OS

Rev

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