Rev 485 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
31 | halyavin | 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' |
||
485 | heavyiron | 19 | include '..\..\..\macros.inc' |
31 | halyavin | 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 |
||
485 | heavyiron | 27 | mcall |
31 | halyavin | 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 |
||
485 | heavyiron | 41 | mcall |
31 | halyavin | 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 |
||
485 | heavyiron | 50 | mcall |
31 | halyavin | 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 |
||
485 | heavyiron | 97 | mcall |
31 | halyavin | 98 | |
99 | ; Read the IP address |
||
100 | mov eax, 53 |
||
101 | mov ebx, 255 |
||
102 | mov ecx, 203 |
||
485 | heavyiron | 103 | mcall |
31 | halyavin | 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 |
||
485 | heavyiron | 127 | mcall |
31 | halyavin | 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 |
||
485 | heavyiron | 182 | mcall |
31 | halyavin | 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 |
||
485 | heavyiron | 216 | mcall |
31 | halyavin | 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 |
||
485 | heavyiron | 250 | mcall |
31 | halyavin | 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 |
||
485 | heavyiron | 292 | mcall |
31 | halyavin | 293 | jmp still |
294 | |||
295 | button: ; button |
||
296 | mov eax,17 ; get id |
||
485 | heavyiron | 297 | mcall |
31 | halyavin | 298 | |
299 | cmp ah,1 ; button id=1 ? |
||
300 | jnz still |
||
301 | |||
302 | mov eax,0xffffffff ; close this program |
||
485 | heavyiron | 303 | mcall |
31 | halyavin | 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 |
||
485 | heavyiron | 342 | mcall |
31 | halyavin | 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] |
||
551 | spraid | 348 | mov edx,0x14224466 ; color of work area RRGGBB |
485 | heavyiron | 349 | mov edi,title ; WINDOW LABEL |
350 | mcall |
||
31 | halyavin | 351 | |
485 | heavyiron | 352 | |
31 | halyavin | 353 | ; Re-draw the screen text |
354 | cld |
||
485 | heavyiron | 355 | mov eax,4 |
31 | halyavin | 356 | mov ebx,25*65536+35 ; draw info text with function 4 |
357 | mov ecx,0xffffff |
||
358 | mov edx,text |
||
359 | mov esi,40 |
||
360 | newline: |
||
485 | heavyiron | 361 | mcall |
31 | halyavin | 362 | add ebx,16 |
363 | add edx,40 |
||
364 | cmp [edx],byte 'x' |
||
365 | jnz newline |
||
366 | |||
367 | |||
368 | mov eax,12 ; function 12:tell os about windowdraw |
||
369 | mov ebx,2 ; 2, end of draw |
||
485 | heavyiron | 370 | mcall |
31 | halyavin | 371 | |
372 | ret |
||
373 | |||
374 | ; Taken from PS.ASM |
||
375 | printhex: |
||
376 | ; number in eax |
||
377 | ; print to ebx |
||
378 | ; xlat from hextable |
||
379 | pusha |
||
380 | mov esi, ebx |
||
381 | add esi, 8 |
||
382 | mov ebx, hextable |
||
383 | mov ecx, 8 |
||
384 | phex_loop: |
||
385 | mov edx, eax |
||
386 | and eax, 15 |
||
387 | xlatb |
||
388 | mov [esi], al |
||
389 | mov eax, edx |
||
390 | shr eax, 4 |
||
391 | dec esi |
||
392 | loop phex_loop |
||
393 | popa |
||
394 | ret |
||
395 | |||
396 | |||
397 | ; DATA AREA |
||
398 | |||
399 | text: |
||
400 | db ' Number of ARP entries: xxxxxxxx ' |
||
401 | db ' Maximum # of entries : xxxxxxxx ' |
||
402 | db ' ' |
||
403 | db ' IP Address MAC Stat TTL ' |
||
404 | db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx ' |
||
405 | db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx ' |
||
406 | db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx ' |
||
407 | db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx ' |
||
408 | db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx ' |
||
409 | db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx ' |
||
410 | db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx ' |
||
411 | db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx ' |
||
412 | db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx ' |
||
413 | db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx ' |
||
414 | db 'x <- END MARKER, DONT DELETE ' |
||
415 | |||
416 | |||
417 | blank: |
||
418 | db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx ' |
||
419 | |||
420 | |||
485 | heavyiron | 421 | title db 'ARP Table ( First 10 Entries )',0 |
31 | halyavin | 422 | |
423 | hextable db '0123456789ABCDEF' |
||
424 | |||
425 | |||
426 | I_END:-> |
||
427 |