i need to parse this string.

111 this is just a test (198.178.42.6.24.235)

111 this is just a test ( ; i dont need this text at all

198.178.42.6 ;i need this in a buffer

24 ;this in another buffer

235 ;and this in another buffer

) ;i dont need this
Posted on 2002-01-28 00:41:56 by smurf
Hey smurf,

I don't know parsing, but i know how to rig stuff up now ...If all of the strings coming is in that style of format....If it was me I would use StrLen or Lenght and divide it up erase or dump the stuff i don't need into a small buffer and divide the string up that way...
Something like something like a copare to get to the next dot....I be back I got get an example maybe that would help..
Posted on 2002-01-28 01:21:44 by cmax
use the Masm32.lib functions,
szLeft, szRight, szMid, and Instring. It makes string parsing very easy, it's almost like vb!

JP
Posted on 2002-01-28 01:41:37 by Asm_Freak
Another way of looking at the problem is like:
*(N.N.N.N.N.N)*
Where * means anything, and N means a number between 0-255 - everything else is interpreted literally. This representation helps lead us to an algorithm. First you need to write a procedure that reads a number from a string and returns a byte, or an error if the number is out of range. Then just find the "(" and loop six times insuring there is a "." between the numbers. Then check for a ")" at the end. You might want to start over if you encounter and error, or just abort altogether.

If you know the ")" comes at the end, then I'd start at the end. ;)
Posted on 2002-01-28 01:41:43 by bitRAKE
smurf,

You can use the szMid function from masm32.lib. For example,


.386
.model flat, stdcall
option casemap: none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\masm32.inc
include \masm32\include\debug.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\debug.lib

.data
szText byte "111 this is just a test (198.178.42.6.24.235)", 0
szBuff1 byte 13 dup(0)
szBuff2 byte 3 dup(0)
szBuff3 byte 4 dup(0)

.code

start:
invoke szMid, addr szText, addr szBuff1, 25, 12
PrintString szBuff1
invoke szMid, addr szText, addr szBuff2, 38, 2
PrintString szBuff2
invoke szMid, addr szText, addr szBuff3, 41, 3
PrintString szBuff3
ret
end start
Posted on 2002-01-28 01:48:30 by vkim
You can rig this up to your use i think..I combinded StrLen and SzCat from the M32lib so its a straight run...I don't know how to make Szmulcat work but that would be a plus...vKim got the easyest way if you want to use API...I use Write file for double checking because i like it tight. No Spaces

.386
.model flat,stdcall
option casemap:none
WinMain proto :DWORD,:DWORD,:DWORD,:SWORD

include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\gdi32.inc
include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc

includelib \MASM32\LIB\gdi32.lib
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib


MessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORD
StrLen PROTO :DWORD
CatString11 PROTO :DWORD
wsprintfA PROTO C :DWORD,:VARARG
wsprintf equ <wsprintfA>

szText MACRO Name, Text:VARARG
LOCAL lbl
jmp lbl
Name db Text,0
lbl:
ENDM

.data
MyText db "C:\What is Really in This Buffer.txt",0

Caption1 db 'Buffer 1',0
Caption2 db 'Buffer 2',0
Caption3 db 'Buffer 3',0

.data?

Buffer1 db 12 dup(?)
Buffer2 db 12 dup(?)
Buffer3 db 5 dup(?)

hFile dd ?
NumBytesWritten dd ?
Bytes dd ?
.code
Main:

szText String1, "12345678900"
szText String2, "abcdefghijk"
szText String3, "0123456789"

; ..................................................................................................


;................................... ; Copy String To Buffer WITHOUT lstrcpy 01
mov esi, offset String1
mov edi, offset Buffer1
mov ecx, 3
rep movsb

mov esi, offset String2
mov edi, offset Buffer2
mov ecx, 11
rep movsb


mov eax, offset String3
add eax, lengthof String3
sub eax, 4
invoke lstrcpyA, offset Buffer3, eax

invoke CatString11, offset Buffer1




invoke MessageBoxA, NULL, offset Buffer1, offset Caption1, NULL

invoke MessageBoxA, NULL, offset Buffer2, offset Caption2, NULL

invoke MessageBoxA, NULL, offset Buffer3, offset Caption2, NULL



invoke CreateFileA,offset MyText,GENERIC_WRITE,NULL,NULL,CREATE_ALWAYS,NULL,NULL
mov hFile, eax
invoke WriteFile, hFile, addr Buffer1, 22, offset NumBytesWritten, 0
invoke CloseHandle, hFile

invoke ExitProcess,0
; ################################
; #################################

CatString11 proc item:DWORD

push ebx
mov eax,item ; get pointer to string
lea edx, ; pointer+3 used in the end
@@:
mov ebx, ; read first 4 bytes
add eax,11 ; increment pointer
lea ecx, ; subtract 1 from each byte
not ebx ; invert all bytes
and ecx,ebx ; and these two
and ecx,80808080h
; jz @B ; no zero bytes, continue loop
test ecx,00008080h ; test first two bytes
jnz @F
shr ecx,16 ; not in the first 2 bytes
@@:
shl cl,1 ; use carry flag to avoid branch
sbb eax,edx ; compute length
pop ebx
; ...............................................................
mov edx, item
mov ecx, offset Buffer2
add edx, eax
@@:
mov al,
mov , al
inc ecx
inc edx
test al, al ; test for zero
jne @B

XOR ECX,ECX
XOR EDX,EDX


invoke MessageBoxA, NULL, edx, offset Caption3, NULL

ret

CatString11 endp

; ###############################

;end


end Main
Posted on 2002-01-28 02:00:20 by cmax
ive came up with some code to do what parsing i needed done. vkim code worked well on a static string but the probelm is my string wont be the same and will change often so using that method wouldnt work well. so now im wondering how inefficient my code is.

.586

.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib kernel32.lib
include \masm32\include\user32.inc
include \masm32\include\masm32.inc
includelib user32.lib
includelib \masm32\lib\masm32.lib

.data
info db "227 Entering Passive Mode (205,164,98,136,18,166).",0
SetFlag db 0

.data?
StartPos dd ?
EndPos dd ?
EndPos1 dd ?
PeriodPos4 dd ?
PeriodBytes4 dd ?
PeriodPos5 dd ?
PeriodBytes5 dd ?
buffer dd 32 dup (?)
buffer1 dd 32 dup (?)
buffer2 dd 32 dup (?)
buffer3 dd 32 dup (?)

.code
start:

xor ecx,ecx
lea esi, info
MyLoop:
xor eax,eax
lodsb
push ecx
.if al == 0
jmp StringEnd
.elseif al == 28h
mov StartPos,ecx
.elseif al == 29h
mov EndPos,ecx
mov EndPos1,ecx
.elseif al == 2ch
mov byte ptr [info + ecx],2eh
inc SetFlag
.if SetFlag == 4
mov PeriodPos4,ecx
mov PeriodBytes4,ecx
mov edi,StartPos
sub PeriodBytes4,edi
dec PeriodBytes4

.elseif SetFlag == 5
inc PeriodPos4
mov PeriodPos5,ecx
mov PeriodBytes5,ecx
mov edi,PeriodPos4
sub PeriodBytes5,edi
.endif

.endif
pop ecx
inc ecx
jmp MyLoop
StringEnd:
inc PeriodPos5
mov edi,PeriodPos5
sub EndPos1,edi

mov edi,StartPos
sub EndPos,edi
inc StartPos
dec EndPos
invoke szMid, addr info, addr buffer,StartPos,EndPos
invoke szMid, addr info, addr buffer1,StartPos,PeriodBytes4
invoke szMid, addr info, addr buffer2,PeriodPos4,PeriodBytes5
invoke szMid, addr info, addr buffer3,PeriodPos5,EndPos1
invoke MessageBox,0,addr buffer,0,0
invoke MessageBox,0,addr buffer1,0,0
invoke MessageBox,0,addr buffer2,0,0
invoke MessageBox,0,addr buffer3,0,0

invoke ExitProcess,NULL
end start


aslo thanks cmax for the code.. just alittle bit hard for me to follow right now.
Posted on 2002-01-28 16:12:54 by smurf
smurf,
please take a look at my (not optimized :) ) code. Looks a bit clearer than yours, and gives the same result :cool:



; #################################################

.486
.model flat, stdcall
option casemap :none

; #################################################

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

; #################################################



; #################################################

.data

szInfo db "227 Entering Passive Mode (205,164,98,136,18,166)", 0


; #################################################

.data?
szBuffer1 db 128 dup (?)
szBuffer2 db 128 dup (?)
szBuffer3 db 128 dup (?)


; #################################################

.code

start:

lea esi, szInfo

@@:
mov al, byte ptr [esi]
inc esi
cmp al, "("
jne @B

lea edi, szBuffer1
xor ecx, ecx
@@:
mov al, byte ptr [esi]
mov byte ptr [edi], al
inc esi
inc edi

.if al == ","
mov byte ptr [edi-1], "." ; comment out to use comma instead of dots
inc ecx
.endif

cmp ecx, 4
jne @B

mov byte ptr [edi-1], 0

lea edi, szBuffer2
@@:
mov al, byte ptr [esi]
mov byte ptr [edi], al
inc esi
inc edi

cmp al, ","
jne @B

mov byte ptr [edi-1], 0

lea edi, szBuffer3
@@:
mov al, byte ptr [esi]
mov byte ptr [edi], al
inc esi
inc edi

cmp al, ")"
jne @B

mov byte ptr [edi-1], 0

invoke MessageBox, 0, addr szBuffer1, 0, 0
invoke MessageBox, 0, addr szBuffer2, 0, 0
invoke MessageBox, 0, addr szBuffer3, 0, 0
invoke ExitProcess, eax

end start

; #################################################
Posted on 2002-01-28 19:04:13 by bazik
Sounds like exactly what you need is strtok(), but that's in C and I don't think its in the MASM32 library.
Posted on 2002-01-28 21:35:16 by peterverstappen
thanks everyone for the help. bazik thanks for the code its alot better using all the registers instead of all the varables i was using not only that your code is simply better.
Posted on 2002-01-28 22:06:51 by smurf