Mega Code Archive

 
Categories / Delphi / Examples
 

Messing with other applications memory

Title: Messing with other applications memory Question: How can I edit data of my favorite game? Answer: First we will have to state some variables and define our constants. (i use "===" to show where the code you will put in the program begins. Please do not put this in your program, as neither you or Delphi will appreciate it) === Var Form1: TForm1; WindowName : integer; ProcessId : integer; ThreadId : integer; // defining variable's types ; buf : PChar; HandleWindow : Integer; write : cardinal ; Const WindowTitle = 'Game Window'; //!define the game's window name ; Address1 = $4ab3485f; //!define your address to poke ; PokeValue1 = $90; //!define what value to write ; NumberOfBytes1 = 1; //!define amount of bytes to write; === The Variables and Constants should be places just before the Implementation command. You needn't worry about the Var area unless you know delphi and want to do more than use a button to poke an address. Under Const there is: WindowTitle - make this equal to what the text on the menubar in windows for the game is. For delphi it says "Delphi 6," so type 'Delphi 6'. Address1 - This is the hex address for the first button to poke. Find your address using a memory scanner. Look to ArcheaHacking.com for tutorials on memory scanning. Do not include any trailing zero's, and include the "$" before the address. PokeValue1 - This is what you want your value to be equal to. Type in the hex equivalent of what the value will be, and make sure to include the "$" NumberOfBytes1 - This is for how many bytes to write. If you are writing "90" to an address that is 1 byte. If you are writing "9090" that is 2 bytes. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Now we must create a button for our trainer, so that the user may poke the address. To create a button for your form, double click "button" under the "Standard" components tab. From here you can modify the text in the button under "Caption" in your object inspector (make sure Button1 is selected in the drop box). To make the button do something, click the "events" tab in the object inspector. Now double click to the right of "OnClick" and you will be brought to your code. Here just enter: === begin WindowName := FindWindow(nil,WindowTitle); If WindowName = 0 then // check if the game is running; begin MessageDlg('The game must be running. Run it now, and then try again.', mtwarning,[mbOK],0); end; // the following will write our value; ThreadId := GetWindowThreadProcessId(WindowName,@ProcessId); HandleWindow := OpenProcess(PROCESS_ALL_ACCESS,False,ProcessId); GetMem(buf,1); buf^ := Chr(PokeValue1); WriteProcessMemory(HandleWindow,ptr(Address1),buf,NumberOfBytes1,write); FreeMem(buf); closehandle(HandleWindow); end; === And there we go, we have made a Trainer in Delphi6. Instructions are provided on adding more buttons inside the Project file. I included both the project file, and the pascal file, so that those without delphi6 can view the pas file.