What I want to do :

A parse function which extract a word following a key-word. This is for a configuration file.

Example :



;---------- config file -----------

car red
house yellow color
dog none

;-----------------------------------

If my key-word is "car", the parse function should return "red".
If my key-word is "house", the parse function should return "yellow".
If my key-word is "yellow", the parse function should return "color".
Etc.

This is what i wrote :

AdrBufferAParser is the address of the buffer to parse
AdrCmd is the address of the string containing the key-word
AdrBufferResultat is the address of the target buffer for the result.

;---code start

Parse PROC AdrBufferAParser:DWORD, AdrCmd:DWORD, AdrBufferResultat:DWORD

LOCAL TxtPos:DWORD

invoke InString, 1, AdrBufferAParser, AdrCmd
mov TxtPos, eax

.if eax != 0

invoke InString, TxtPos, AdrBufferAParser, addr espace
mov TxtPos, eax

.if eax != 0
mov eax, AdrBufferAParser
add eax, TxtPos
mov TxtPos, eax
;sub eax, 1

invoke lstrlen, eax
.if eax < 256
invoke lstrcpy, AdrBufferResultat, TxtPos
.else
invoke MemCopy, TxtPos, AdrBufferResultat, 255
.endif


mov eax, AdrBufferResultat
parselabel:
xor ebx,ebx
mov ebx,
.if bl == 13
mov byte ptr ,0
.elseif bl == 10
mov byte ptr ,0
.elseif bl == 32
mov byte ptr ,0
.elseif bl != 0
inc eax
jmp parselabel
.endif

.endif

.endif


ret
Parse endp

;---code end

When I call this function sometimes I get the good result, sometimes not. Can someone explain me why ? What is wrong here ?

:confused:
Posted on 2003-04-17 11:49:29 by Djizeus
Posted on 2003-04-17 17:20:15 by bitRAKE
This scanner seems to be very interesting, but i don't have the time to understand it and then to rewrite it to my own purpose...

Btw, I found a bug. Now it seems working... It's not optimized at all and may contain several other bugs (lol) => I don't know if this can help ! But here is the new version :

AdrBufferAParser is the address of the buffer to parse.
AdrCmd is the address of the string containing the key-word.
AdrBufferResultat is the address of the target buffer for the result.
szAdrBufferResultat is obviously the size of the previous buffer.


.data

espace db " ",0

.code

Parse PROC AdrBufferAParser:DWORD, AdrCmd:DWORD, AdrBufferResultat:DWORD, szAdrBufferResultat

LOCAL TxtPos:DWORD

invoke InString, 1, AdrBufferAParser, AdrCmd
mov TxtPos, eax

.if eax != 0

invoke InString, TxtPos, AdrBufferAParser, addr espace
mov TxtPos, eax

.if eax != 0
mov eax, AdrBufferAParser
add eax, TxtPos
mov TxtPos, eax
;sub eax, 1


invoke lstrlen, eax
.if eax < szAdrBufferResultat
invoke MemCopy, TxtPos, AdrBufferResultat, eax
.else
invoke MemCopy, TxtPos, AdrBufferResultat, szAdrBufferResultat
.endif


mov eax, AdrBufferResultat
parselabel:
xor ebx,ebx
mov ebx,
.if bl == 13
mov byte ptr ,0
.elseif bl == 10
mov byte ptr ,0
.elseif bl == 32
mov byte ptr ,0
.elseif bl != 0
inc eax
jmp parselabel
.endif

.endif

.endif


ret
Parse endp
Posted on 2003-04-18 12:39:58 by Djizeus

This scanner seems to be very interesting, but i don't have the time to understand it and then to rewrite it to my own purpose...
There is nothing to rewrite. Understanding it will make your work very little on this project and others.
Posted on 2003-04-18 14:30:00 by bitRAKE
Are you using the new InString, or the old one?
Posted on 2003-04-23 08:02:04 by Homer