 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
penpenpen Cheater
Reputation: 0
Joined: 23 Feb 2014 Posts: 39
|
Posted: Thu Oct 09, 2014 4:02 pm Post subject: [Delphi] Crash at "SetLength(...)" |
|
|
Hi,
I stumbled upon a problem while experimenting.
I hope we have some delphi experts here who can help .
So Basicly what I'm doing is this:
(The Code is executed within a DLL)
Declarations:
Code: |
var
POldCode:Pointer;
NewCode:TBytes;
OldCode:TBytes;
|
Code: |
setlength(oldcode,5);
Move(POldCode^, OldCode, sizeof(oldcode));
|
... Then this code is executed
Code: |
NewCode := CreateByteArrFromHex('C7 46 58 25 00 00 00 C7 46 54 25 00 00 00');
MeltByteArray(NewCode,OldCode);
|
And in the procedure MeltByteArray it crashes when setlength is called:
Code: |
procedure MeltByteArray(var a,b:TBytes);
var
Old: Integer;
begin
old := Length(a);
SetLength(a,old+Length(b)); //Crash
Move(b[0],a[old],Length(b)*SizeOf(b[0]));
end;
|
Not Important but this is my CreateByteArrayFromHex Function:
Code: | function CreateByteArrFromHex(ByteArr:String):TBytes;
var
i:integer;
begin
//Filter Leerzeichen
ByteArr:=StringReplace(ByteArr,' ','',[rfReplaceAll]);
i:=1; //String beginnt bei Index1
while i < length(ByteArr) do
begin
SetLength(Result,high(Result)+2);
Result[high(Result)] := HexToInt(Copy(ByteArr,i,2));
i:=i+2;
end;
end; |
I think it may have something to do with the Move Function which changes some references. But I'm not sure.
Hope you can help me  |
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25788 Location: The netherlands
|
Posted: Thu Oct 09, 2014 4:29 pm Post subject: |
|
|
Code: |
setlength(oldcode,5);
Move(POldCode^, OldCode, sizeof(oldcode));
|
you're never setting POldCode to @oldcode[0] after the setlength (setlength changes the location of the array) , so POldCode will be pointing to some random memory location(worst case scenario it points to the old array that has a length of 0). Causing the move to most likely overwrite random memory in the stack. (basically, anything weird can happen from this point) _________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
 |
penpenpen Cheater
Reputation: 0
Joined: 23 Feb 2014 Posts: 39
|
Posted: Thu Oct 09, 2014 4:37 pm Post subject: |
|
|
//Edit:
I got it working .
It was a problem with the move proc. I just replaced it by CopyMemory. And it works. I still dont really understand why though. But I will find out
Thanks DarkByte |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|