Sweet. The purpose of the code is to copy a string from one location to another, including the terminating 0, lets look at the code:
lpstrcpy:
pop ebx ;The function call puts the addresses on the stack
pop eax ;this retrieves them and lets me use them
mov edx,eax ;copy them over into other registers
mov ecx,ebx ;
@@: ; do{}
mov byte ptr[ecx],byte ptr[edx] ;move the byte at offset edx
inc ecx ;to offset edx
inc edx ;and increment both offsets
cmp byte ptr[edx],0 ;if our next byte=0 (end of string)
jne @B ; while(char != 0)
mov byte ptr[ecx],byte ptr[edx] ;copy the zero over
xchg edx,eax ;swap eax & ecx around
sub eax,edx ;subtract to see how many bytes we've copied
ret ; return (# of bytes)
So that's what the code does, I'll also give you a literal translation as to what all the code means
invoke lstrcpy, offset first, offset second
lstrcpy(&first,&second);
This isnt part of the code, but it calls the code. What it does is pushes the offsets onto the stack in reverse order, so both codes do this:
push offset second
push offset first
call lstrcpy
This is where the code comes in:
lstrcpy:
pop ebx
pop eax
Do you know how the stack works? Like a stack of paper, you can only put on/take off from the top. So everything comes off in reverse order, so ebx=offset first & eax==offset second. We'll use eax & ebx to save the offsets, and copy them elsewhere:
mov edx,eax
mov ecx,ebx
Now edx=offset second and ecx=offset first
@@:
That's a lazy mans label, i couldn't think of a name for it
mov byte ptr[ecx],byte ptr[edx]
inc ecx
inc edx
Moves the byte at offset edx to .....ecx and increments both of them
cmp byte ptr[edx],0
jne @B
do{} until(byte ptr[edx]==0)
Basically it compares the byte at edx to 0, and (jne Jump if Not Equal) loops if it isnt (@B is go Back to the last @@:, @F is Forward)
mov byte ptr[ecx],byte ptr[edx]
Copy the zero over to terminate the string
xchg edx,eax
sub eax,edx
Swaps edx with eax, (edx is now start of string, eax is end) and subtracts edx from eax (end-start=length)
ret
Eax is the return value, so basically this means return strlength.
There we go, have a nice day
NoFriLLz