Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Optimal memory reading/writing

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
dlpb
Advanced Cheater
Reputation: 0

Joined: 11 Dec 2013
Posts: 78

PostPosted: Sun Feb 28, 2016 2:29 pm    Post subject: Optimal memory reading/writing Reply with quote

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
View user's profile Send private message
dlpb
Advanced Cheater
Reputation: 0

Joined: 11 Dec 2013
Posts: 78

PostPosted: Tue Mar 01, 2016 6:08 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites