i want to avoid using memory and instead use a register.
.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
includelib user32.lib

.data
data db "dr-xr-xr-x hello",0

.data?
buffer0 dd ?

.code
start:
xor ecx,ecx
lea esi, offset data
lea edi,buffer0 ;instead of using a buffer can i use a register?
mov ecx,10
rep movsb
invoke MessageBox,0,addr buffer0,0,0
invoke ExitProcess,NULL
end start
Posted on 2002-02-02 10:43:38 by smurf
Hello smurf,
Is your code working?


.data?
buffer0 dd ?

With this, you only have a DWORD (4 bytes) to copy your string into. You have to declare an array of bytes big enough (at least the same size of your original string). If you use like this, you will fill your buffer0 (4 bytes) and will overwrite the memory after it.
Try using this:


.data?
buffer0 db 10 dup (?)

Let me know if it works.
Hope this helps you.
Posted on 2002-02-02 11:03:32 by dilau
Sorry smurf, I didn't answer your question about the registers.
You can't use a register to copy your string into because a register is also a DWORD. But I think you can put an address to a buffer (array of bytes big enough to receive your string). Like this:


.data?
buffer0 db 10 dup (?)

.code
start:
xor ecx,ecx
lea esi, offset data
mov eax, addr buffer0
mov edi, eax
mov ecx,10
rep movsb
invoke MessageBox,0,addr buffer0,0,0
invoke ExitProcess,NULL
end start
Posted on 2002-02-02 11:08:37 by dilau
ok i finally got this through my thick skull. for some reason i wasnt getting the concept that the memory was being overwritten mainly because my application still worked fine. thanks for the help.
Posted on 2002-02-02 11:14:18 by smurf
so i have this question for you then. why isnt the memory overwritten using this code?
data db "dr-xr-xr-x   1 owner    group       0 May 21  2001 deskapps",13,10,

"dr-xr-xr-x 1 owner group 0 Apr 20 2001 developr",0
Posted on 2002-02-02 11:48:39 by smurf
If your buffer is big enough to receive that string, the memory after it won't be overwritten. Otherwise, it will.
Posted on 2002-02-02 13:40:37 by dilau
i guess i wasnt clear enough.

data db "d",0

should this be the only way to use this since its defining a string as a byte? a byte can only hold one character so everthing after the d should be overwritting memory right? well i know it doesnt but i just dont understand why this is.
Posted on 2002-02-02 14:37:29 by smurf
Hi smurf,
I'll try to explain to you this overwritting thing I was talking about.


.data
data db "dr-xr-xr-x hello",0

.data?
buffer0 dd ?

.code
start:
xor ecx,ecx
lea esi, offset data
lea edi, buffer0
mov ecx,10
rep movsb
invoke MessageBox,0,addr buffer0,0,0
invoke ExitProcess,NULL
end start

Using the code above will overwrite the memory after the buffer because the buffer (DWORD = 4 bytes) isn't big enough to receive the string.
For example, this would be the same as if I declared the buffer this way:
buffer0 db 4 dup (?)
The size of the buffer is the same in both cases and they aren't big enough to receive the string (you copy 10 bytes on your code). If you did it this way:
buffer0 db 7 dup (?)
It wouldn't work either. Because the buffer needs to be at least 10 bytes. If you use this:
buffer0 db 10 dup (?)
It will work.
I am seeing another problem now in you code.
I realized that you wanna copy the first 10 bytes and the buffer will hold this string right? In your code, you didn't make the string in the buffer null-terminated. So you will have to make a buffer of 11 bytes (10 bytes of the string and another byte for the null character).
Use this code:


.data
data db "dr-xr-xr-x hello",0

.data?
buffer0 db 11 dup (?)

.code
start:
xor ecx,ecx
lea esi, offset data
lea edi, buffer0
mov ecx,10
rep movsb
lea edi, buffer0
add edi, 10
mov byte ptr [edi], 0
invoke MessageBox,0,addr buffer0,0,0
invoke ExitProcess,NULL
end start

The code above should work as you want.
Let me know if you understood.
Sorry for my english, it's really bad.
Posted on 2002-02-02 15:38:40 by dilau
how come when i do the code like this and not put in a null terminating character my code doesnt break?
.data

data db "dr-xr-xr-x hello",0

.data?
buffer0 dd 11 dup (?)

.code
start:
xor ecx,ecx
lea esi, offset data
lea edi, buffer0
mov ecx,10
rep movsb
invoke MessageBox,0,addr buffer0,0,0
invoke ExitProcess,NULL
Posted on 2002-02-02 16:41:23 by smurf
Most likely your address space is already zero filled. Grab a debugger called ollydbg if you want to see whats going on. Load the program, trace with f8, and right click on edi and select follow in dump once you reach that line.
Posted on 2002-02-02 20:43:50 by grv575
grv575 is right. The memory where your string was copied into is probably already filled with null characters. If you don't put the null character and the memory is not filled with null characters, Windows will consider all bytes after the string you copied to be in your string until it finds a null character. If this happens your string will contain some strange characters after the string you copied. Use the null character, it's safer. :)
Posted on 2002-02-02 23:32:53 by dilau