Hi,

by now I try to write a PROC that parses a string for certain commands. Some commands have parameters which I want to extract.



Example: <Commandcode> <Param1> <Param2> ...
All Commandcodes and Parameters are 4 Bytes long

String db "IPRP USER <LoginName>",0

I want to extract the substring "USER". I wanted to do this using

invoke lstrcpyn, ADDR DestString, ?
How to I tell the function that I want to start with:
ADDR String + <an offset of 5 bytes>?


Thanks
Posted on 2002-06-21 04:36:56 by Compuholic
Off the top of my head:


.data
String db "IPRP USER <LoginName>",0

.data?
Buffer db 64 dup (?)

.code
lea edi, String
lea esi, Buffer
add edi, 5 ; skip first 5 byte
@@:
mov al, byte ptr [edi]
mov byte ptr [esi], al
inc edi
inc esi
or al, al ; zero?
jnz @B

; Buffer contains 'USER <LoginName>' now.
Posted on 2002-06-21 04:51:30 by bazik
How to I tell the function that I want to start with:
ADDR String + <an offset of 5 bytes>?

get the address in a register then add to it
lea esi, String
add esi, 5
invoke blah, esi
Posted on 2002-06-21 04:51:45 by Kudos
Kudos,

yes, this will work, too :)
Posted on 2002-06-21 04:53:21 by bazik
I thought of your solution too, bazik. But isn't there a possibility to do add 5 bytes to the offset directly?
It would be much faster if I could pass this value direct from the invoke command.
Posted on 2002-06-21 04:59:45 by Compuholic


.code
MyString db "Hi Woo!",0

start:
invoke MessageBox, NULL, ADDR MyString + 3, NULL, MB_OK
invoke ExitProcess, NULL
end start


Works for me... Could it be more difficult?

If you insist on using lea, then why not just use:


lea eax, String + 5
; end up being -
lea eax, [0x00b1ab1a + 5]
;which will end up being
lea eax, [0x00b1ab1f]

; or
lea eax, [esp + 50 + 5]
; which becomes
lea eax, [esp + 55]


Mirno
Posted on 2002-06-21 05:28:16 by Mirno
Hmm, I don't get it.

invoke MessageBox, NULL, ADDR MyString + 3, NULL, MB_OK

I tried this before posting my question and MASM said something like "invalid use of ADDR". And now it works.
Strange...
Posted on 2002-06-21 05:34:08 by Compuholic
Sorry that I have to bother you again. I don't want to flood this forum with threads, so I wrote it in here.

Just a simple question. How big is the stack on a Win2k machine. I'm asking this because I get a strange error that reminds me of a stack overflow. The program crashes just after the function call.

But I can't be a stack overflow, look at this:


ParseCommand PROC actualSocket:DWORD
LOCAL RecBuffer[67000d] : BYTE
LOCAL Command[5] : BYTE
LOCAL Param[5] : BYTE
LOCAL Filename[256] : BYTE
LOCAL BytesWritten : DWORD

mov BytesWritten, 0
invoke ioctlsocket, actualSocket, FIONREAD, ADDR RecBytes

I think 67 KB should not cause a stack overflow. There are also no big vars before the funktion call.

btw. Is it right that I can't receive more that about 65 KB per FD_READ Message because of the TCP-Packetsize limitation?
Posted on 2002-06-21 10:10:01 by Compuholic


I think 67 KB should not cause a stack overflow. There are also no big vars before the funktion call.


But they can :)
You should better dynamically alloc the needed memory via HeapAlloc / GlobalAlloc.

regards,
bAZiK
Posted on 2002-06-21 10:14:00 by bazik
by now I try to write a PROC that parses a string for certain commands. Some commands have parameters which I want to extract.
If the string to extract is undetermined in its position:
    [*]Use a string search algorithm to give you the position of the string.
    [*]use strlen on the search text
    [*]extract using a substring function:

    starting position == string search algorithm output
    ending position == string search algorithm output + strlen of the search text
    else just use what the other guys above told you to do. :)
Posted on 2002-06-21 10:30:57 by stryker
Hmm, hopefully my last question regarding this.

LOCAL MemPointer : DWORD

eax contains the number of bytes to alloc.

invoke LocalAlloc, LMEM_FIXED, eax
mov MemPointer, eax
[...]
invoke lstrcpyn, MemPointer + 6, ADDR TestName, 256

MemPointer + 6 points to an absolute wierd position. Does anyone has an explanation for this. I wanted to copy 256 bytes into the allocated memory with an offset of 6 bytes.

Thanks
Posted on 2002-06-21 11:45:03 by Compuholic
invoke lstrcpyn, ADDR MemPointer, ADDR TestName+6, 256 
Try this!!! :)
Posted on 2002-06-21 18:20:14 by stryker
LocalAlloc returns a handle not a pointer.

HLOCAL LocalAlloc(
UINT uFlags, // memory allocation attributes
SIZE_T uBytes // number of bytes to allocate
);

So you need to either use the LPTR flag or lock the returned handle with

LPVOID LocalLock(
HLOCAL hMem // handle to local memory object
);
Posted on 2002-06-24 03:37:04 by grv575