Hello Coding-Friends.

I use HeapReAlloc and stored about 100KB data.
But when I want to write in it, the programm crashes.
I can append data, but cant manipulate it.
when it's not possible to write in in(but i hope it is),

is there a function that allows to coppy a range of a string into another?
something like this:

INVOKE CopyRange, Tstring, mainstring, 50, 100

an then Tstring retieves the data from mainstring at the pos 50 till 100.

I hope you understant me well.

Greets!
Posted on 2003-09-30 00:40:30 by Bubu-Boy
The lstrcpy function copies a string to a buffer.

LPTSTR lstrcpy(

LPTSTR lpString1, // address of buffer
LPCTSTR lpString2 // address of string to copy
);
Posted on 2003-09-30 01:50:24 by devilsclaw
you could try a macro also

StrCpy MACRO Src, Dest
mov ebx,Src
mov ecx,Dest
xor eax,eax
StartCpy:
cmp byte ptr ,00h
je EndCpy
mov dl, byte ptr
mov byte ptr , dl
inc eax
inc ebx
inc ecx
jmp StartCpy
EndCpy:
ENDM
Posted on 2003-09-30 02:02:20 by devilsclaw
thank,s but this will not work, cuz the the main string isn't writeable.

:alright:

But what now ?
Posted on 2003-09-30 02:16:41 by Bubu-Boy
the main string does not have to be write able to copy from it and both of these do that..

it sounds like your not allocating right if you dont have access to something..
Posted on 2003-09-30 02:30:22 by devilsclaw
Is the string long enough?
Posted on 2003-09-30 05:02:15 by roticv
StrCpy MACRO Src, Dest
mov esi,Src
mov edi,Dest
xor eax,eax
StartCpy:
cmp byte ptr ,00h
je EndCpy
movsb
inc eax
jmp StartCpy
EndCpy:
mov byte ptr ,00h
ENDM

There Optimized it a bit and also made it put a null terminated byte at the end..

I guess it might be a good idea for it to save edi and esi

StrCpy MACRO Src, Dest
push edi
push esi
mov esi,Src
mov edi,Dest
xor eax,eax
StartCpy:
cmp byte ptr ,00h
je EndCpy
movsb
inc eax
jmp StartCpy
EndCpy:
mov byte ptr ,00h
pop esi
pop edi
ENDM
Posted on 2003-09-30 11:43:21 by devilsclaw
im looking are your copy memory invoke up there and it might be because you need to put offset in front of the string addresses here is a code example of using my macro but should be the same concept for the lstrcpy and the copy mem



.386
.model flat,stdcall
option casemap:none

INCLUDE \MASM32\INCLUDE\WINDOWS.INC
INCLUDE \MASM32\INCLUDE\KERNEL32.INC
INCLUDE \MASM32\INCLUDE\USER32.INC

INCLUDELIB \MASM32\LIB\KERNEL32.LIB
INCLUDELIB \MASM32\LIB\USER32.LIB

StrCpy MACRO Src, Dest
push esi
push edi
mov esi,Src
mov edi,Dest
xor eax,eax
StartCpy:
cmp byte ptr [esi],00h
je EndCpy
movsb
inc eax
jmp StartCpy
EndCpy:
mov byte ptr [edi],00h
pop edi
pop esi
ENDM

.data
Test1 DB "Hello World How Are You",0

.data?
Test2 db 00FFFFh dup (?)

.code
start:
StrCpy offset Test1,offset Test2
invoke MessageBoxA,NULL,addr Test1,addr Test2,MB_OK
INVOKE ExitProcess,NULL


Edit: Sorry Corrected the Macro I forgot MOVS Instructions auto update the ESI and EDI to the next byte/word/dword
Posted on 2003-09-30 12:18:45 by devilsclaw
hi, the problem is cant write in my allocatet memory. Do i have to overgive some different parameters?
my current parameters are:



INVOKE GetProcessHeap
MOV Heap,EAX
INVOKE HeapAlloc,Heap,0, SIZEEE
MOV tHeap,EAX
invoke lstrcat, tHeap, stringveryong
mov byte ptr[theap+55], 0 ;<<<-then it crashes. the string is aobut 30000 bytes long





do i have to declare the allocated memory as writeable? - When, HOW?

Thanks for you asnwers!

Your BBB!
Posted on 2003-09-30 13:49:50 by Bubu-Boy
try

invoke lstrcat,offset tHeap, offset stringveryong

or try

invoke lstrcat,tHeap, offset stringveryong

not sure right now since the whole code is not there..

also lstrcat addess a string to an already existing string and from what i can tell your copying you should be using lstrcpy
Posted on 2003-09-30 13:52:37 by devilsclaw
hi, i want to write in the string.

MOV BYTE PTR, 0

but then in crashes i can append something, but not replace, or write in it.

Thats the problem.

Sorry, when I couldn't expressionate clear.

Greets BBB
Posted on 2003-09-30 14:10:54 by Bubu-Boy
ok First off you forgot to ZERO INIT the memory..




.386
.model flat,stdcall
option casemap:none

INCLUDE \MASM32\INCLUDE\WINDOWS.INC
INCLUDE \MASM32\INCLUDE\KERNEL32.INC
INCLUDE \MASM32\INCLUDE\USER32.INC

INCLUDELIB \MASM32\LIB\KERNEL32.LIB
INCLUDELIB \MASM32\LIB\USER32.LIB

INCLUDE .\LIB\MIXLIB.INC
INCLUDELIB .\LIB\MIXLIB.LIB

.data
stringveryong DB "Hello World How Are You",0

.data?
Heap dd ?
hHeap dd ?
.code
start:
INVOKE GetProcessHeap
MOV Heap,EAX
INVOKE HeapAlloc,Heap,HEAP_ZERO_MEMORY, 100h
MOV hHeap,EAX
;If normally stringveryong is a memory pointer then you had the it correct
invoke lstrcat,hHeap, offset stringveryong
mov eax,hHeap
mov byte ptr[eax+55],00h

INVOKE ExitProcess,NULL
end start
Posted on 2003-09-30 14:32:05 by devilsclaw
huh. Maybe you're using the old pointer to the data. Reallocating almost always changes the pointer! Make sure you always use the new pointer, returned by HeapReAlloc !!

And that
mov byte ptr,0
will never work as you wish - you have to make it:
mov eax,hHeap
mov byte ptr,0
Posted on 2003-09-30 14:41:47 by Ultrano
hHeap,EAX


Yes I did. - CAn you write in you allocatet memory ?

IS your Code the same as mine ??? - Or do i have to overgive a parameter like ACCESS_WRITE ?


Greets! - We see us later, i will go to bed now.

Greets!
Posted on 2003-09-30 14:45:46 by Bubu-Boy
its not exactly the same why dont you check and see for your self lol.. dont be lazy..
Posted on 2003-09-30 14:47:11 by devilsclaw
Hi devilsclaw I think we speak in different direction ?

How I can check the code from Ultrano, and compare it with my own.

I'm not lazy, despair perhaps.

when I call Realoc it will return the new handke, which i save in tHeap.

...

bye
Posted on 2003-09-30 14:52:49 by Bubu-Boy