I am wondering if i got a string that is going to always be used in a program can i eliminate the MyString db LINE and write the string inline with the code.

This way there is only one copy of the string and it is in a buffer....

.............................................. THIS IS THE NORMAL WAY

MyString db "Text Text Text Text Text Text ",0
StringBuffer DD 0


mov esi, "offset MyString"
mov edi, offset StringBuffer
mov ecx, 128
rep movsd

:::::::::::::::::::::::::::::: Posted on 2002-01-21 22:32:38 by cmax

The register is not big enough to put the string directly into it, you must pass the eddress to the register. You can insert 4 bytes into a 32 bit register,

mov eax, "4321"

But once you string is longer than 4 bytes, you must work off the address of the buffer it is stored in.

You can directly store string data in the .CODE section but keep in mind that it is only READ ONLY data, you cannot write to it.

jmp @F
MyString db "This is a string",0

To copy either this string or any other to another buffer, you must get the address of both the source string and the destination buffer, then you can copy one to another.

mov esi, offset MyString
mov edi, offset MyBuffer
mov ecx, lengthof MyString
rep movsb

Just note that depending on how you allocate the buffer to write to, you may need to use,

lea edi, MyBuffer


Posted on 2002-01-21 22:47:43 by hutch--
I been tring to do this for the past 4 hours. Now I know why it did not work. This is the icing on the cake back when you explaned to me before about DWORDS...Now i think I really understand. Everything is feed in by pieces. What was i thinking...

"mov ecx, lengthof MyString" Posted on 2002-01-21 23:11:23 by cmax
Maybe I've overlooked something.. but I'm posting anyway..
I wonder why Hutch doesn't remember his own set of macros ???


; Hutch's SADD Macro
; Use: invoke MessageBox,hwnd,SADD("The Message"),SADD("The Title"),MB_OK
; Use: mov eax,CTXT("Whatever")
; ---------------------
; literal string MACRO
; ---------------------
literal MACRO quoted_text
LOCAL local_text
local_text db quoted_text,0
EXITM <local_text>
; --------------------------------
; string address in INVOKE format
; --------------------------------
SADD MACRO quoted_text
EXITM <ADDR literal(quoted_text)>
; --------------------------------
; string OFFSET for manual coding
; --------------------------------
CTXT MACRO quoted_text
EXITM <offset literal(quoted_text)>
Posted on 2002-01-21 23:59:45 by JimmyClif
Thanks JimmyClif, I'll go back and test this in a few minutes, but i am now posting a full example that f0dder requested that i do in an previous post:

cmax String to Buffer Copy Tute.. This will show you how to copy a string to a buffer without calling lstrcopy if i can ever get it working right...Test it and you will see the problem...as you go down the line 4 byte will be adding from previous...i don't want that to happen...What am i'm doing wrong.

.model flat,stdcall
option casemap:none

include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\gdi32.inc
include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc

includelib \MASM32\LIB\gdi32.lib
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib


wsprintf equ <wsprintfA>

szText MACRO Name, Text:VARARG
jmp lbl
Name db Text,0


BufferCaption1 db 'Here The Text to Test if Buffer 1 Has Anything In It',0
BufferCaption2 db 'Here The Text to Test if Buffer 2 Has Anything In It',0
BufferCaption3 db 'Here The Text to Test if Buffer 3 Has Anything In It',0
BufferCaption4 db 'Here The Text to Test if Buffer 4 Has Anything In It',0
BufferCaption5 db 'Here The Text to Test if Buffer 5 Has Anything In It',0
BufferCaption6 db 'Here The Text to Test if Buffer 6 Has Anything In It',0


Buffer1 DWORD ?
Buffer2 DWORD ?
Buffer3 DWORD ?
Buffer4 DWORD ?
Buffer5 DWORD ?
Buffer6 DWORD ?


szText String1, "String1", 0
szText String2, "String2", 0
szText String3, "String3", 0
szText String4, "String4", 0
szText String5, "String5", 0
szText String6, "String6", 0

;................................... ; Copy String To Buffer WITHOUT lstrcpy 01
mov esi, offset String1
mov edi, offset Buffer1
mov ecx, lengthof String1
rep movsd
;................................... ; Copy String To Buffer WITHOUT lstrcpy 02
mov esi, offset String2
mov edi, offset Buffer2
mov ecx, lengthof String2
rep movsd
;................................... ; Copy String To Buffer WITHOUT lstrcpy 03
mov esi, offset String3
mov edi, offset Buffer3
mov ecx, lengthof String3
rep movsd
;................................... ; Copy String To Buffer WITHOUT lstrcpy 04
mov esi, offset String4
mov edi, offset Buffer4
mov ecx, lengthof String4
rep movsd
;................................... ; Copy String To Buffer WITHOUT lstrcpy 05
mov esi, offset String5
mov edi, offset Buffer5
mov ecx, lengthof String5
rep movsd
;mov esi, offset String6
;mov edi, offset Buffer6
;mov ecx, lengthof String6
;rep movsd

invoke MessageBoxA, NULL, offset Buffer1, offset BufferCaption1, NULL
invoke MessageBoxA, NULL, offset Buffer2, offset BufferCaption2, NULL
invoke MessageBoxA, NULL, offset Buffer3, offset BufferCaption3, NULL
invoke MessageBoxA, NULL, offset Buffer4, offset BufferCaption4, NULL
invoke MessageBoxA, NULL, offset Buffer5, offset BufferCaption5, NULL
invoke MessageBoxA, NULL, offset Buffer6, offset BufferCaption6, NULL

invoke ExitProcess,0

end Main
Posted on 2002-01-22 11:12:57 by cmax
JimmyClif i read that when you use macro, is it true that it is best to call that macro only once during start up of a program because if you call it again it will expand your program in size.

The main thing that i am concerned about is would this continue to happen if you call that same macro again and again while the program is running. This is the real question...

If anyone know? What do they mean expand in size, and by how much ( in Size ) each time.....Double, Triple or what...
Posted on 2002-01-22 12:10:24 by cmax
Macro expansion is done at assemble-time. If you use a macro like
CTEXT three times, you get three strings. It doesn't matter if you
put it inside a loop or not (except of course if it's a macro loop).

Your code sample is pretty flawed. You try to copy a seven (or 8,
including the NUL character) byte string into a 4-byte DWORD...
this just will not work :). If you use HeapAlloc (or whatever dynamic
memory allocation function) to allocate memory for a buffer, you
should use "mov edi ", not "mov edi, offset buffer".

You will also want to remember that "rep movsd" copies dwords,
not bytes. You can either use "rep movsb", or do the copy in two
parts: first dwords, then the remaining bytes.

Anyway, what is this whole deal with buffers? I'm a bit confused
about your first post:

I am wondering if i got a string that is going to always be used in a program can i eliminate the MyString db LINE and write the string inline with the code.
This way there is only one copy of the string and it is in a buffer....

if you copy strings into buffers, there will obviously be *two* copies
of the string. One is the source, the other is in the buffer.
Posted on 2002-01-22 12:23:18 by f0dder
f0dder, i tried all that you said and it don't work or it don't make any sense. YOU TRY IT...

I thought a Buffer Was Memory...am i'm wrong....The string is in there is it not...

So no one know what cmax is taking about...
Now I post an FULL EXAMPLE.. ....

What you see here complys and execute with no problem other than what i posted it for....flawed or not it RUNS...

Comply it, Run it, Change it, Than tell me about it....

Strings and Buffers is all i usually ask about. This subject is very hot to me...You can also comply only one buffer and see how perfecly it works. The problem is when you do more than one... It make no since to me that it don't work when it should...I am to close to stop now....
Posted on 2002-01-22 20:27:54 by cmax
Hello cmax,
Try this, instead of:
Buffer1 DWORD ?
Buffer2 DWORD ?
Use this:
Buffer1 db 128 dup (?)
Buffer2 db 128 dup (?)

Using this, you are "allocating" 128 bytes. Now you can copy your strings into this buffers. Using DWORDs you only have 4 bytes.
I hope this helps.
Posted on 2002-01-22 21:22:32 by dilau
I forgot about that. See i knew it worked and have did that before, than days latter i forgot how i did it. Now I know what allocation means. It don't have to be as serious as HEAPS and all its friends.
Just a plain old db dup(128)

Plain Terninolgy is my main problem

Thanks dilau


"Anyway, what is this whole deal with buffers? I'm a bit confused "

I use to do everything with edit boxes. Than I got wise and wanted to do it like an real Assembler...with buffers and 32 bit register. Than i got serious about the M32LIB....
I figure that Assembler is all about calling codes that you created within YOUR program with less calls as possible OUTSIDE the program....If you can eliminate even a few calls to the API because ASM can do it on it's on...and you got time to work with it than DO THAT... I like Windows and the API but if I have my way with the help of the Board, M32LIB, and Will Power the only call outside my program would be EXIT PLEASE to the Kernel... I have gotten very greedy with what i think ASM can do

I don't plan to tell the whole secerte of my program, than the crakers will have nothing else to do in life, But crossing out some api calls and coding it within your own app are codes that I want to share with all coders so if their program is running on my machine I know it would be the best that it can be....ASM FOREVER Plus if you got data that you going to be using often its better to me that it live in a small buffer. No major work to get back to it when needed....Not required for all programs but maybe for some...The only thing it does is take up space, Soooooo i was hoping for a way not to write the string DIRECTLY to the 32bit Regesters than to buffer this way I not only got it in the buffer but now I only have ONE COPY,,,,,, Now Would'n that be the Greatest.....

That's the whole deal about Buffers. Can't wait to lay it all out so i can move on to the next HEAD BUSTER... All of this Did it for me....I'm sure now....and i read little artical where ever i find them....

Thanks f0dder
Thanks again dilau
Thanks Hutch

Hey JimmyClif, Will be Studying that Macro Tonight..Thanks
Posted on 2002-01-22 22:24:52 by cmax