Subversion Repositories Kolibri OS

Rev

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

  1. ;
  2. ;    ARP Status Monitor
  3. ;
  4. ;    Compile with FASM for Menuet
  5. ;
  6. ;  This program displays the ARP table, and it's settings
  7.    
  8. use32
  9.    
  10.                 org     0x0
  11.    
  12.                 db      'MENUET00'              ; 8 byte id
  13.                 dd      38                      ; required os
  14.                 dd      START                   ; program start
  15.                 dd      I_END                   ; program image size
  16.                 dd      0x100000                ; required amount of memory
  17.                 dd      0x00000000              ; reserved=no extended header
  18.    include 'lang.inc'
  19.    include 'macros.inc'
  20.    
  21. START:                          ; start of execution
  22.     call draw_window            ; at first, draw the window
  23.    
  24. still:
  25.     mov  eax,23                 ; wait here for event
  26.     mov  ebx,200                                ; Time out after 2s
  27.     int  0x40
  28.    
  29.     cmp  eax,1                  ; redraw request ?
  30.     jz   red
  31.     cmp  eax,2                  ; key in buffer ?
  32.     jz   key
  33.     cmp  eax,3                  ; button in buffer ?
  34.     jz   button
  35.    
  36.         ; read the stack status data, and write it to the screen buffer
  37.  
  38.         mov             eax, 53
  39.         mov             ebx, 255
  40.         mov             ecx, 200
  41.         int             0x40
  42.  
  43.         push    eax            
  44.         mov             ebx, text + 24
  45.         call    printhex
  46.  
  47.         mov             eax, 53
  48.         mov             ebx, 255
  49.         mov             ecx, 201
  50.         int             0x40
  51.                
  52.         mov             ebx, text + 64
  53.         call    printhex
  54.        
  55.        
  56.         ; Fill the table with blanks
  57.         mov             edx, text + 160
  58. doBlank:
  59.         mov             esi, blank
  60.         mov             edi, edx
  61.         mov             ecx, 40
  62.         rep             movsb
  63.         add             edx, 40
  64.  
  65.         cmp             edx, text + 560
  66.         jne             doBlank
  67.        
  68.         pop             ecx                                     ; The number of entries
  69.        
  70.         mov             ebx, text+ 160  +1      ; the position for the first IP address line
  71.        
  72.         xor             edx, edx                        ; edx is index into the ARP table
  73.  
  74.         cmp             ecx, 10
  75.         jle             show_entries
  76.         mov             ecx, 10
  77.        
  78.        
  79. ; The following code is not very efficient; Sorry about that.
  80. ; ARPSTAT is a debugging tool, so I didn't want to put much effort in
  81. show_entries:
  82.         ; Ecx now holds the number of entries to populate.
  83.         ; Ebx holds the place to put the data
  84.         ; edx is a counter
  85.         cmp             ecx, 0
  86.         je              red
  87.        
  88.         push    ecx
  89.         push    edx
  90.         push    ebx
  91.        
  92.  
  93.         ; select the arp table entry (in edx)
  94.         mov             eax, 53
  95.         mov             ebx, 255
  96.         mov             ecx, 202
  97.         int             0x40
  98.        
  99.         ; Read the IP address
  100.         mov             eax, 53
  101.         mov             ebx, 255
  102.         mov             ecx, 203
  103.         int             0x40
  104.        
  105.         ; IP in eax. Get the address to put it back
  106.         pop             ebx
  107.         push            ebx
  108.        
  109.         call            writeDecimal                    ; Extract 1 byte from eax, store it in string  
  110.         add             ebx, 4
  111.         shr             eax, 8
  112.         call            writeDecimal                    ; Extract 1 byte from eax, store it in string  
  113.         add             ebx, 4
  114.         shr             eax, 8
  115.         call            writeDecimal                    ; Extract 1 byte from eax, store it in string  
  116.         add             ebx, 4
  117.         shr             eax, 8
  118.         call            writeDecimal                    ; Extract 1 byte from eax, store it in string  
  119.  
  120.         add             ebx, 4
  121.        
  122.         ; Now display the 6 byte MAC
  123.         push            ebx
  124.         mov             eax, 53
  125.         mov             ebx, 255
  126.         mov             ecx, 204
  127.         int             0x40
  128.         pop             ebx
  129.                
  130.         mov             ecx, eax
  131.  
  132.         shr             eax, 4
  133.         and             eax, 0x0f
  134.         mov             al, [eax + hextable]
  135.         mov             [ebx], al
  136.         inc             ebx
  137.         mov             eax, ecx
  138.         and             eax, 0x0f
  139.         mov             al, [eax + hextable]
  140.         mov             [ebx], al
  141.         inc             ebx
  142.         mov             eax, ecx
  143.         shr             eax, 12
  144.         and             eax, 0x0f
  145.         mov             al, [eax + hextable]
  146.         mov             [ebx], al
  147.         inc             ebx
  148.         mov             eax, ecx
  149.         shr             eax, 8
  150.         and             eax, 0x0f
  151.         mov             al, [eax + hextable]
  152.         mov             [ebx], al
  153.         inc             ebx
  154.         mov             eax, ecx
  155.         shr             eax, 20
  156.         and             eax, 0x0f
  157.         mov             al, [eax + hextable]
  158.         mov             [ebx], al
  159.         inc             ebx
  160.         mov             eax, ecx
  161.         shr             eax, 16
  162.         and             eax, 0x0f
  163.         mov             al, [eax + hextable]
  164.         mov             [ebx], al
  165.         inc             ebx
  166.         mov             eax, ecx
  167.         shr             eax, 28
  168.         mov             al, [eax + hextable]
  169.         mov             [ebx], al
  170.         inc             ebx
  171.         mov             eax, ecx
  172.         shr             eax, 24
  173.         and             eax, 0x0f
  174.         mov             al, [eax + hextable]
  175.         mov             [ebx], al
  176.         inc             ebx
  177.  
  178.         push            ebx
  179.         mov             eax, 53
  180.         mov             ebx, 255
  181.         mov             ecx, 205
  182.         int             0x40
  183.         pop             ebx
  184.        
  185.         mov             ecx, eax
  186.  
  187.         shr             eax, 4
  188.         and             eax, 0x0f
  189.         mov             al, [eax + hextable]
  190.         mov             [ebx], al
  191.         inc             ebx
  192.         mov             eax, ecx
  193.         and             eax, 0x0f
  194.         mov             al, [eax + hextable]
  195.         mov             [ebx], al
  196.         inc             ebx
  197.         mov             eax, ecx
  198.         shr             eax, 12
  199.         and             eax, 0x0f
  200.         mov             al, [eax + hextable]
  201.         mov             [ebx], al
  202.         inc             ebx
  203.         mov             eax, ecx
  204.         shr             eax, 8
  205.         and             eax, 0x0f
  206.         mov             al, [eax + hextable]
  207.         mov             [ebx], al
  208.  
  209.         ; Now display the stat field
  210.         inc             ebx
  211.         inc             ebx
  212.         push            ebx
  213.         mov             eax, 53
  214.         mov             ebx, 255
  215.         mov             ecx, 206
  216.         int             0x40
  217.         pop             ebx
  218.        
  219.         mov             ecx, eax
  220.  
  221.         shr             eax, 4
  222.         and             eax, 0x0f
  223.         mov             al, [eax + hextable]
  224.         mov             [ebx], al
  225.         inc             ebx
  226.         mov             eax, ecx
  227.         and             eax, 0x0f
  228.         mov             al, [eax + hextable]
  229.         mov             [ebx], al
  230.         inc             ebx
  231.         mov             eax, ecx
  232.         shr             eax, 12
  233.         and             eax, 0x0f
  234.         mov             al, [eax + hextable]
  235.         mov             [ebx], al
  236.         inc             ebx
  237.         mov             eax, ecx
  238.         shr             eax, 8
  239.         and             eax, 0x0f
  240.         mov             al, [eax + hextable]
  241.         mov             [ebx], al
  242.        
  243.         ; Now display the TTL field (this is intel word format)
  244.         inc             ebx
  245.         inc             ebx
  246.         push            ebx
  247.         mov             eax, 53
  248.         mov             ebx, 255
  249.         mov             ecx, 207
  250.         int             0x40
  251.         pop             ebx
  252.        
  253.         mov             ecx, eax
  254.  
  255.         shr             eax, 12
  256.         and             eax, 0x0f
  257.         mov             al, [eax + hextable]
  258.         mov             [ebx], al
  259.         inc             ebx
  260.         mov             eax, ecx
  261.         shr             eax, 8
  262.         and             eax, 0x0f
  263.         mov             al, [eax + hextable]
  264.         mov             [ebx], al
  265.         inc             ebx
  266.         mov             eax, ecx
  267.         shr             eax, 4
  268.         and             eax, 0x0f
  269.         mov             al, [eax + hextable]
  270.         mov             [ebx], al
  271.         inc             ebx
  272.         mov             eax, ecx
  273.         and             eax, 0x0f
  274.         mov             al, [eax + hextable]
  275.         mov             [ebx], al
  276.  
  277.        
  278.         pop             ebx
  279.         add             ebx, 40
  280.         pop             edx
  281.         inc             edx
  282.         pop             ecx
  283.         dec             ecx
  284.         jmp             show_entries
  285.  
  286. red:                            ; redraw
  287.     call draw_window
  288.     jmp  still
  289.    
  290. key:                            ; Keys are not valid at this part of the
  291.     mov  eax,2                  ; loop. Just read it and ignore
  292.     int  0x40
  293.     jmp  still
  294.    
  295. button:                         ; button
  296.     mov  eax,17                 ; get id
  297.     int  0x40
  298.    
  299.     cmp  ah,1                   ; button id=1 ?
  300.     jnz  still
  301.  
  302.     mov  eax,0xffffffff         ; close this program
  303.     int  0x40
  304.  
  305.     jmp  still
  306.  
  307.  
  308.  
  309. writeDecimal:
  310.         pusha
  311.         and     eax, 0xff
  312.         mov     ecx, eax
  313.         mov     dl, 100
  314.         div     dl
  315.         mov     cl, ah
  316.         add     al, '0'
  317.         mov     [ebx], al
  318.         inc     ebx
  319.         mov     eax, ecx
  320.         mov     dl, 10
  321.         div     dl
  322.         mov     cl, ah
  323.         add     al, '0'
  324.         mov     [ebx], al
  325.         inc     ebx
  326.         mov     al, ah
  327.         add     al, '0'
  328.         mov     [ebx], al
  329.         popa
  330.         ret
  331.    
  332.    
  333. ;   *********************************************
  334. ;   *******  WINDOW DEFINITIONS AND DRAW ********
  335. ;   *********************************************
  336.    
  337.    
  338. draw_window:
  339.    
  340.     mov  eax,12                    ; function 12:tell os about windowdraw
  341.     mov  ebx,1                     ; 1, start of draw
  342.     int  0x40
  343.    
  344.                                    ; DRAW WINDOW
  345.     mov  eax,0                     ; function 0 : define and draw window
  346.     mov  ebx,100*65536+280         ; [x start] *65536 + [x size]
  347.     mov  ecx,100*65536+270         ; [y start] *65536 + [y size]
  348.     mov  edx,0x03224466            ; color of work area RRGGBB
  349.     mov  esi,0x00334455            ; color of grab bar  RRGGBB,8->color gl
  350.     mov  edi,0x00ddeeff            ; color of frames    RRGGBB
  351.     int  0x40
  352.    
  353.                                    ; WINDOW LABEL
  354.     mov  eax,4                     ; function 4 : write text to window
  355.     mov  ebx,8*65536+8             ; [x start] *65536 + [y start]
  356.     mov  ecx,0x00ffffff            ; color of text RRGGBB
  357.     mov  edx,labelt                ; pointer to text beginning
  358.     mov  esi,labellen-labelt       ; text length
  359.     int  0x40
  360.    
  361.         ; Re-draw the screen text
  362.     cld
  363.     mov  ebx,25*65536+35           ; draw info text with function 4
  364.     mov  ecx,0xffffff
  365.     mov  edx,text
  366.     mov  esi,40
  367.   newline:
  368.     mov  eax,4
  369.     int  0x40
  370.     add  ebx,16
  371.     add  edx,40
  372.     cmp  [edx],byte 'x'
  373.     jnz  newline
  374.    
  375.    
  376.     mov  eax,12                    ; function 12:tell os about windowdraw
  377.     mov  ebx,2                     ; 2, end of draw
  378.     int  0x40
  379.    
  380.     ret
  381.  
  382. ; Taken from PS.ASM  
  383. printhex:
  384. ; number in eax
  385. ; print to ebx
  386. ; xlat from hextable
  387.  pusha
  388.  mov esi, ebx
  389.  add esi, 8
  390.  mov ebx, hextable
  391.  mov ecx, 8
  392. phex_loop:
  393.  mov edx, eax
  394.  and eax, 15
  395.  xlatb
  396.  mov [esi], al
  397.  mov eax, edx
  398.  shr eax, 4
  399.  dec esi
  400.  loop phex_loop
  401.  popa
  402.  ret
  403.  
  404.    
  405. ; DATA AREA
  406.    
  407. text:
  408.     db ' Number of ARP entries: xxxxxxxx        '
  409.     db ' Maximum # of entries : xxxxxxxx        '
  410.     db '                                        '
  411.     db ' IP Address      MAC          Stat TTL  '
  412.     db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
  413.     db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
  414.     db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
  415.     db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
  416.     db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
  417.     db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
  418.     db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
  419.     db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
  420.     db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
  421.     db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
  422.     db 'x <- END MARKER, DONT DELETE            '
  423.  
  424.  
  425. blank:
  426.           db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
  427.  
  428.  
  429. labelt:
  430.     db   'ARP Table ( First 10 Entries )'
  431. labellen:
  432.    
  433. hextable db '0123456789ABCDEF'
  434.  
  435.  
  436. I_END:
  437.    
  438.    
  439.    
  440.    
  441.  
  442.  
  443.