Log in

View Full Version : Delphi programming help...


ModelingMan
25-05-2004, 16:08
Hi, I'm new to these forums.

I need some help, I am making a game trainer in Delphi and having a problem writing the correct value to a processes memory.

Here is some souce:

var
Form1: TForm1;
WindowName : integer;
ProcessId : integer;
ThreadId : integer;
buf : PChar;
HandleWindow : Integer;
write : cardinal;

implementation

{$R WindowsXP.RES}

uses colors, aboutbox;

Const
WindowTitle = 'GTA: Vice City';
Address = 8223480;
NumberOfBytes = 2;
Banshee = 159;

{$R *.dfm}

procedure TForm1.ListBox1Click(Sender: TObject);
begin
If ListBox1.Selected [0] then
begin
WindowName := FindWindow(nil,WindowTitle);
If WindowName = 0 then
begin
MessageDlg('Vice City must be running. Run it now, and then try again.', mtwarning,[mbOK],0)
end
else
ThreadId := GetWindowThreadProcessId(WindowName,@ProcessId);
HandleWindow := OpenProcess(PROCESS_ALL_ACCESS,False,ProcessId);

GetMem(buf,1);
buf^ := Chr(Banshee);
WriteProcessMemory(HandleWindow,ptr(Address),buf,N umberOfBytes,write);
FreeMem(buf);
closehandle(HandleWindow);
end;

What this program will be doing is editing which car is in a garage in game, in that source the car value is 159 but when I run the program it writes the value 22943 which causes the game to crash. I have the NumberOfBytes correct. I think it's something to do with
WriteProcessMemory(HandleWindow,ptr(Address),buf,N umberOfBytes,write);
I would like to get it to write the correct values.

Any help is greatly appreciated.

Brandon Martus
25-05-2004, 16:27
This forum isn't really for Delphi programming. We (ChiefDelphi) are a FIRST Robotics (http://www.usfirst.org) team, sponsored by Delphi (http://www.delphi.com/). These forums are here for discussion of the FIRST Robotics competition. Someone here may be able to help you out, but you may want to look elsewhere for more comprehensive Delphi programming help.

Alan Anderson
25-05-2004, 16:29
I'm not really sure what this is doing in this thread, but here's the problem:

Const
NumberOfBytes = 2;
Banshee = 159;

GetMem(buf,1);
buf^ := Chr(Banshee);
WriteProcessMemory(HandleWindow,ptr(Address),buf,N umberOfBytes,write);
FreeMem(buf);

You're putting a single byte in the buffer, but you're writing two bytes. It looks like the second byte of the buffer has a random (but consistent?) 89 in it. Thus the two bytes written are 159:89, or hexadecimal 9F:59. On a "little-endian" processor, that's the decimal 22943 you're getting.

The solution is to set the second byte of the buffer to zero before writing it. That means you'll have to make your buffer two bytes long, too.

ModelingMan
25-05-2004, 16:56
Thank you for the help Alan.

And I am sorry for the misunderstanding of what these forums are for.