Go to Post ... we are really in FIRST to develop a love and appreciation for Math, Science, and Technology. This is our goal. Every team can do this effectively regardless of how well they do in competitions. - tennispro9911 [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 25-05-2004, 16:08
ModelingMan's Avatar
ModelingMan ModelingMan is offline
Registered User
no team
 
Join Date: May 2004
Location: Scotland
Posts: 2
ModelingMan is an unknown quantity at this point
Delphi programming help...

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:

Code:
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,NumberOfBytes,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
Code:
WriteProcessMemory(HandleWindow,ptr(Address),buf,NumberOfBytes,write);
I would like to get it to write the correct values.

Any help is greatly appreciated.
__________________

Last edited by ModelingMan : 25-05-2004 at 16:15.
  #2   Spotlight this post!  
Unread 25-05-2004, 16:27
Brandon Martus's Avatar Unsung FIRST Hero
Brandon Martus Brandon Martus is offline
busy.
AKA: B. Slash Kamen
no team
 
Join Date: May 2001
Rookie Year: 1998
Location: Nevada, TX USA
Posts: 5,271
Brandon Martus has a reputation beyond reputeBrandon Martus has a reputation beyond reputeBrandon Martus has a reputation beyond reputeBrandon Martus has a reputation beyond reputeBrandon Martus has a reputation beyond reputeBrandon Martus has a reputation beyond reputeBrandon Martus has a reputation beyond reputeBrandon Martus has a reputation beyond reputeBrandon Martus has a reputation beyond reputeBrandon Martus has a reputation beyond reputeBrandon Martus has a reputation beyond repute
Send a message via ICQ to Brandon Martus Send a message via AIM to Brandon Martus Send a message via Yahoo to Brandon Martus
Re: Need Help? Call us!

This forum isn't really for Delphi programming. We (ChiefDelphi) are a FIRST Robotics team, sponsored by Delphi. 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.
__________________
Brandon Martus
e-mail
  #3   Spotlight this post!  
Unread 25-05-2004, 16:29
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Need Help? Call us!

I'm not really sure what this is doing in this thread, but here's the problem:

Code:
Const 
NumberOfBytes = 2;
Banshee = 159;

GetMem(buf,1);
buf^ := Chr(Banshee);
WriteProcessMemory(HandleWindow,ptr(Address),buf,NumberOfBytes,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.
  #4   Spotlight this post!  
Unread 25-05-2004, 16:56
ModelingMan's Avatar
ModelingMan ModelingMan is offline
Registered User
no team
 
Join Date: May 2004
Location: Scotland
Posts: 2
ModelingMan is an unknown quantity at this point
Re: Delphi programming help...

Thank you for the help Alan.

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


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Robot Programming Education phrontist Programming 11 03-05-2004 07:32
Thank you to Brandon and Chief Delphi Ken Leung Thanks and/or Congrats 19 15-12-2003 22:24
Chief Delphi Institute for Better High School Robotics archiver 2000 0 24-06-2002 00:17
Chief Delphi Institute for Better High School Robotics archiver 2000 2 24-06-2002 00:17
Delphi Automotive Systems is now just Delphi... Joe Johnson General Forum 10 21-03-2002 22:23


All times are GMT -5. The time now is 03:10.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi