Well, the subject says it all.

I coded a real small app, which adds numbers in front of ips in a file (e.g. '' becomes '01)')

For now it only is able to put numbers at a max of 99 (due to the use of aam) and it uses a bytescan. Why? just for its simplicity.

What it does is scan for a number. If one found then it checks if the character before the number is a chr(10). If so, this number is at the beginning of the line and ASSUMED to be an ip (as I assumer only IPs are listed and they start at the beginning of a new line).

This works fine for now and more than 99 IPs I don't thing I will need. But it that could be possible.

Now i'm wondering if it can be adjusted to make it work faster (Geez, I want speed baby, speed:grin:) or how to add more numbers into this. I guess it is kinda self-explanatory with the comments. If not feel free to tell me so.

I too think the loop (bytescan) is rather lame and crappy, but can't clear my head to make up a better one...

; ecx = contains number to add (100 is max)
; ebh = contains 2 chars after number (high word of ebx)
; edi = ptr to address to insert number
;return values
; ebx = ' )YX' Where X is first digit and Y is last digit (display = 'XY) ')
; ecx = next number
PutNrInText proc
inc ecx
mov eax, ecx
aam ;adjust chars ax (ONLY FOR: numbers between 0-99)
add ax, 3030h
mov bl, ah
mov bh, al
mov dword ptr [edi], ebx
add edi, 4
PutNrInText endp

; edi = address of memory block to add numbers to
; esi = address of empty block which will contain new data with numbers
; ecx = size of 'edi' memory block
;return values
; ecx = NULL if function fails.
AddNumbers proc
xor edx, edx ;edx = size counter
or ecx, ecx ;is size NULL
jz @ReturnNow ;if so leave proc

mov ebp, ecx ;ebp = size of memory bloack for comparison
xor ecx, ecx ;ecx = counter of added numbers
cld ;clear direction flag for increment
mov ebx, ' )00' ;set initial value

;test first char for number
mov al, byte ptr [esi]
sub al, 30h
js @loop1
sub al, 9
jns @loop1

call PutNrInText
;Do the rest (including the first char! =] Add it to the destination !!!!
mov al, byte ptr [esi]
sub al, 30h
js @NoNum
sub al, 9
jns @NoNum
cmp byte ptr [esi-1], 10 ;see if this is the BOL
jne @NoNum ;if not then get out

call PutNrInText
movsb ;copy byte to new address block in edi
inc edx ;increase counter
cmp edx, ebp ;have we reached the end?
jne @loop1 ;if not continue with data parse
AddNumbers endp
Posted on 2002-04-19 02:44:54 by the_anomaly