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!
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!
The lstrcpy function copies a string to a buffer.
LPTSTR lstrcpy(
LPTSTR lpString1, // address of buffer
LPCTSTR lpString2 // address of string to copy
);
LPTSTR lstrcpy(
LPTSTR lpString1, // address of buffer
LPCTSTR lpString2 // address of string to copy
);
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
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
thank,s but this will not work, cuz the the main string isn't writeable.
:alright:
But what now ?
:alright:
But what now ?
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..
it sounds like your not allocating right if you dont have access to something..
Is the string long enough?
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
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
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
Edit: Sorry Corrected the Macro I forgot MOVS Instructions auto update the ESI and EDI to the next byte/word/dword
.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
hi, the problem is cant write in my allocatet memory. Do i have to overgive some different parameters?
my current parameters are:
do i have to declare the allocated memory as writeable? - When, HOW?
Thanks for you asnwers!
Your BBB!
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!
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
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
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
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
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
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
And that
mov byte ptr,0
will never work as you wish - you have to make it:
mov eax,hHeap
mov byte ptr,0
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!
its not exactly the same why dont you check and see for your self lol.. dont be lazy..
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
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