 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
dlpb Advanced Cheater
Reputation: 0
Joined: 11 Dec 2013 Posts: 78
|
Posted: Sun Feb 28, 2016 2:29 pm Post subject: Optimal memory reading/writing |
|
|
Hi. I have recently been looking at my read / write functions in Delphi 7 and wondering if there is a smarter way to do things using pointers and so on. Here is how I managed to do the READ function:
Code: | Function NewerReadValue(TheAddress: Pointer): Pointer;
var
BytesCopied: array [0..7] of byte;
begin
Fillchar(bytescopied,8,0);
//my pidhandle is global.
if PidHandle <> 0 then
ReadProcessMemory(Pidhandle, pointer(TheAddress), @BytesCopied, 8, Readed);
Result:= @BytesCopied;
end; |
In other words, 8 bytes are always copied and then the address pointed to as the function result. Always using 8 is me being lazy - you could just as easily add a manual size parameter.
Then to call function:
Code: | pbyte(NewerReadValue (pointer($CC1EF0) ) )^; |
This way, you can change pbyte to plongint, pdouble, or any type and acquire the correct read value.
But all my attempts to be equally smart with a one-size-fits-all approach to Write have failed. Is it true to say the only way is to just add a "type" parameter or just make multiple write functions for each type?
|
|
Back to top |
|
 |
dlpb Advanced Cheater
Reputation: 0
Joined: 11 Dec 2013 Posts: 78
|
Posted: Tue Mar 01, 2016 6:08 pm Post subject: |
|
|
OK, so, from what I can gather, with Delphi 7, I am stuck with writing a function for each write. Example:
Code: | {Writes a byte to memory}
Function WByte(TheAddress: LongInt;
TheValue: Byte): Cardinal;
Var
OldProtection : DWORD;
Begin
Result:= 0;
if PidHandle=0 then
exit;
if(VirtualProtectEx(PidHandle, Pointer(TheAddress),1, PAGE_EXECUTE_READWRITE, @OldProtection))then
begin
WriteProcessMemory(PidHandle, Pointer(TheAddress), @TheValue, 1, Result);
VirtualProtectEx(PidHandle, Pointer(TheAddress), 1, OldProtection, @OldProtection);
FlushInstructionCache(PidHandle,Pointer(TheAddress),1);
end;
End; |
|
|
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
|
|