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.
Thanks
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
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.
How to I tell the function that I want to start with:
ADDR String + <an offset of 5 bytes>?
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
Kudos,
yes, this will work, too :)
yes, this will work, too :)
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.
It would be much faster if I could pass this value direct from the invoke command.
.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
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...
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...
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:
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?
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?
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
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. :)
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
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
invoke lstrcpyn, ADDR MemPointer, ADDR TestName+6, 256
Try this!!! :)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
);
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
);