I want to read a given number of bytes from a buffer, and then have these bytes in another buffer.

the reason i want to do this is that i want to check whether an smtp server accepts an email address as syntactically correct. if it does then the reply is something like:

250 <address@domain.com> is syntactically correct

as the message number is always 250 no matter what the email address is, or your ip address, the first 3 bytes will always be "250".

any help appreciated.
skud.
Posted on 2001-08-20 13:34:59 by skud


want to read a given number of bytes from a buffer, and then have these bytes in another buffer.







...


LEA ESI,SrcBuffer
LEA EDI,DestBuffer
MOV ECX,255 ; Replace the 255 with desired size
REP MOVSB


...




you could use the lstrcpy API too.

Hope that helps.


Latigo
Posted on 2001-08-20 13:52:25 by latigo
wow that was a quick response.

there isnt any way to copy a certain number of bytes using lstrcpy is there? just the whole string...

according to my codes.pdf, LEA means Load Effective Address...
and what i can see from it and your code it does the same as MOV, except with a buffer.

i have no idea what REP MOVSB does !!? ;(

i can't see at all how this does what you say it does !!
could you please explain what each line does?

skud.
Posted on 2001-08-20 14:10:22 by skud
irst a perfectly assembleable source code:




.386
.MODEL FLAT,STDCALL
option casemap:none

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

includelib user32.lib
includelib kernel32.lib


.DATA

SrcBuffer DB "Latigo",0


.DATA?

DestBuffer DB 7 DUP (?)

.CODE

Starts:

LEA ESI,SrcBuffer ; load in ESI the address of the source buffer
LEA EDI,DestBuffer ; load in EDI the address of the destination buffer
MOV ECX,7 ; set the counter to 7 (SrcBuffer's length)
REP MOVSB ; MOV all the Bytes from one buffer to another

INVOKE MessageBox,0,OFFSET DestBuffer,0,MB_OK

INVOKE ExitProcess,0

END Starts


As you know there are many Intel x86 instructions that are optimized for certain type of activities which use specific registers.
ECX is the counter, thus all LOOP and REP activities decrement it with each operation. REP is the short for REPetition and it will repeat the action you indicate after the REP mnemonic.
MOVSB transfers ONE BYTE from the address pointed by ESI to the address pointed by EDI. ESI is known as the source string buffer (for string operations that is) and EDI is known as the destination buffer. So MOVSB 'already' knows that it must take one byte from ESI and store it in EDI. That is why we load such registers before the MOVing operation.
If you wanted to transfer one WORD then instead of MOVSB it would be 'MOVSW' and if you wanted a DWORD then it'd be MOVSD.
I think that's all to it :).
If you still got any doubts let me know.


Latigo
Posted on 2001-08-20 15:18:12 by latigo
Yes, you were right, lstrcpy copies ALL the buffer. But lstrcpyn copies n bytes from one to another :)
Posted on 2001-08-20 15:23:39 by latigo
Skud, U could use a function MemCopy, it's in MASM32Lib (its with MASM32v6 package) but i does the same thing as latigo's code.

Here is a desciption of MemCopy funcyion from MASM32Lib help


MemCopy

MemCopy proc public uses esi edi Source:PTR BYTE,Dest:PTR BYTE,ln:DWORD

Note here that the source and destination parameters are DWORD size addresses of the respective source and destination buffers.

Example
invoke MemCopy,ADDR MySource,ADDR MyDest,ln

MemCopy copies the byte count of memory from a source buffer to a destination buffer.

Parameters
1. Source Source buffer address.

2. Dest Destination buffer address.

3. ln The number of bytes to copy.

Return Value
There is no return value.

Comments
The destination buffer must be at least the same size as the source buffer otherwise the procedure will write past the end of the destination buffer and cause a write page fault.
Posted on 2001-08-20 15:44:49 by NEMO