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 


Editing Memory in Delphi.
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Tue Jun 10, 2008 8:53 am    Post subject: Reply with quote

Moller wrote:
@oib111
I've tried this
Code:
function EditMemory(Address: Integer; Value: Integer): Boolean;
var
  ProcessId, WindowName, HandleWindow: Integer;
  Write: Cardinal;
  mbi: MEMORY_BASIC_INFORMATION;
  oldprotect: dword;
begin
  WindowName := FindWindow(nil, 'World of Warcraft');
  If WindowName = 0 then
  begin
  Result := False;
  Exit;
  end;
  GetWindowThreadProcessId(WindowName, @ProcessId);
  HandleWindow := OpenProcess(PROCESS_ALL_ACCESS, False, ProcessId);
  VirtualProtectEx(HandleWindow, mbi.BaseAddress, mbi.RegionSize, PAGE_READWRITE, @oldprotect);
  WriteProcessMemory(HandleWindow, Ptr(Address), @Value, 2, Write);
  CloseHandle(HandleWindow);
  Result := True;
end;


Code:
EditMemory($008D86F0, -100)


Still no success, any ideas?
Reakwon said it shouldn't be 4 byte, so I tried 2, but I have no idea what it should be.


First off, I would change WindowName to WindowHandle, and WindowHandle to hProcess. Also, the WindowName (in your code) should be a HWND type variable, and WindowHandle (in your code) should be a HANDLE type variable. I'm assuming delphi has those...and you should be writing 4 bytes, because your writing a signed integer, which is 4 bytes.

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
NothingToShow
Grandmaster Cheater Supreme
Reputation: 0

Joined: 11 Jul 2007
Posts: 1579

PostPosted: Tue Jun 10, 2008 8:56 am    Post subject: Reply with quote

First off, I would change WindowName to WindowHandle, and WindowHandle to hProcess. Also, the WindowName (in your code) should be a HWND type variable, and WindowHandle (in your code) should be a HANDLE type variable. I'm assuming delphi has those...and you should be writing 4 bytes, because your writing a signed integer, which is 4 bytes.[/quote]
That aren't my code. It's the topic starters, but yeah, I see some of the problems, I'll edit it, and tell you back.

EDIT:
Now the code looks like this
Code:
function EditMemory(Address: Integer; Value: Integer): Boolean;
var
  ProcessId: Integer;
  WindowName: hwnd;
  HandleWindow: hwnd;
  Write: Cardinal;
  mbi: MEMORY_BASIC_INFORMATION;
  oldprotect: dword;
begin
  WindowName := FindWindow(nil, 'World of Warcraft');
  If WindowName = 0 then
  begin
  Result := False;
  Exit;
  end;
  GetWindowThreadProcessId(WindowName, @ProcessId);
  HandleWindow := OpenProcess(PROCESS_ALL_ACCESS, False, ProcessId);
  VirtualProtectEx(HandleWindow, mbi.BaseAddress, mbi.RegionSize, PAGE_READWRITE, @oldprotect);
  WriteProcessMemory(HandleWindow, Ptr(Address), @Value, 4, Write);
  CloseHandle(HandleWindow);
  Result := True;
end;

Still, it doesn't work. (And there aren't any type called handle in Delphi, not what I know about).
Could it be VirtualProtectEx? Are there any errors in that.


Last edited by NothingToShow on Tue Jun 10, 2008 9:08 am; edited 2 times in total
Back to top
View user's profile Send private message
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Tue Jun 10, 2008 9:02 am    Post subject: Reply with quote

Quote:
008D86F0 is the address for the jump height of a character. When you add it to Cheat Engine, you use 8D86F0, but that doesn't work either.
I need to set the value of the address, to -100, but how do I do that?

If it doesn't work with CE, it definitely won't work with another app. Sounds like you just have the wrong address.

Make HandleWindow a global variable or pass it to the function and put findwindow-virtualprotectex in the main program and only call it once.
Also, to avoid confusion if you're multiclienting or something, I recommend doing
Code:
    SleepEx(3000, 0);
    HWND hwnd;
    hwnd = GetForegroundWindow();

get get the handle instead of using the window name or class.

_________________
Back to top
View user's profile Send private message
NothingToShow
Grandmaster Cheater Supreme
Reputation: 0

Joined: 11 Jul 2007
Posts: 1579

PostPosted: Tue Jun 10, 2008 9:05 am    Post subject: Reply with quote

HalfPrime wrote:
Quote:
008D86F0 is the address for the jump height of a character. When you add it to Cheat Engine, you use 8D86F0, but that doesn't work either.
I need to set the value of the address, to -100, but how do I do that?

If it doesn't work with CE, it definitely won't work with another app. Sounds like you just have the wrong address.

Make HandleWindow a global variable or pass it to the function and put findwindow-virtualprotectex in the main program and only call it once.
Also, to avoid confusion if you're multiclienting or something, I recommend doing
Code:
    SleepEx(3000, 0);
    HWND hwnd;
    hwnd = GetForegroundWindow();

get get the handle instead of using the window name or class.

I've tried with both 008D86F0 and 8D86F0. Didn't work.
Is it because I'm not running it in the main program, that it isn't working?
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Tue Jun 10, 2008 9:21 am    Post subject: Reply with quote

Try this.

Code:

function EditMemory(Address: Integer; Value: Integer): Boolean;
var
  ProcessId: Integer;
  WindowName: hwnd;
  HandleWindow: handle;
  Write: Cardinal;
  mbi: MEMORY_BASIC_INFORMATION;
  oldprotect: dword;
begin
  WindowName := FindWindow(nil, 'World of Warcraft');
  If WindowName = 0 then
  begin
  Result := False;
  Exit;
  end;
  GetWindowThreadProcessId(WindowName, @ProcessId);
  HandleWindow := OpenProcess(PROCESS_VM_WRITE, False, ProcessId);
  VirtualQueryEx(HandleWindow, @Address, @mbi, //sizeof operator here for mbi);
  VirtualProtectEx(HandleWindow, mbi.BaseAddress, mbi.RegionSize, PAGE_READWRITE, @oldprotect);
  WriteProcessMemory(HandleWindow, Ptr(Address), @Value, 4, Write);
  CloseHandle(HandleWindow);
  Result := True;
end;

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
NothingToShow
Grandmaster Cheater Supreme
Reputation: 0

Joined: 11 Jul 2007
Posts: 1579

PostPosted: Tue Jun 10, 2008 9:29 am    Post subject: Reply with quote

oib111 wrote:
Try this.

Code:

function EditMemory(Address: Integer; Value: Integer): Boolean;
var
  ProcessId: Integer;
  WindowName: hwnd;
  HandleWindow: handle;
  Write: Cardinal;
  mbi: MEMORY_BASIC_INFORMATION;
  oldprotect: dword;
begin
  WindowName := FindWindow(nil, 'World of Warcraft');
  If WindowName = 0 then
  begin
  Result := False;
  Exit;
  end;
  GetWindowThreadProcessId(WindowName, @ProcessId);
  HandleWindow := OpenProcess(PROCESS_VM_WRITE, False, ProcessId);
  VirtualQueryEx(HandleWindow, @Address, @mbi, //sizeof operator here for mbi);
  VirtualProtectEx(HandleWindow, mbi.BaseAddress, mbi.RegionSize, PAGE_READWRITE, @oldprotect);
  WriteProcessMemory(HandleWindow, Ptr(Address), @Value, 4, Write);
  CloseHandle(HandleWindow);
  Result := True;
end;

How would you do the
Code:
//sizeof operator here for mbi

in C++? So I know what to convert.
Back to top
View user's profile Send private message
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Tue Jun 10, 2008 9:30 am    Post subject: Reply with quote

Did it work with cheat engine, or not? If it didn't, you've got the wrong code.
When you call
Code:
EditMemory($008D86F0, -100)

does "$" in delphi tell the compiler that 008D86F0 is hex?

_________________
Back to top
View user's profile Send private message
NothingToShow
Grandmaster Cheater Supreme
Reputation: 0

Joined: 11 Jul 2007
Posts: 1579

PostPosted: Tue Jun 10, 2008 10:06 am    Post subject: Reply with quote

HalfPrime wrote:
Did it work with cheat engine, or not? If it didn't, you've got the wrong code.
When you call
Code:
EditMemory($008D86F0, -100)

does "$" in delphi tell the compiler that 008D86F0 is hex?

8D86F0 works with CE.
And yes, $ tells that it's a HEX. (I think ^^)
About.com - Delphi wrote:
Nevertheless, Delphi allows expressions with hexadecimal notation (using a $ prefix). So, here is a simple HexToInt function:
Code:
function HexToInt(HexNum: string): LongInt;
begin
   Result:=StrToInt('$' + HexNum) ;
end;
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Tue Jun 10, 2008 2:57 pm    Post subject: Reply with quote

Moller wrote:
oib111 wrote:
Try this.

Code:

function EditMemory(Address: Integer; Value: Integer): Boolean;
var
  ProcessId: Integer;
  WindowName: hwnd;
  HandleWindow: handle;
  Write: Cardinal;
  mbi: MEMORY_BASIC_INFORMATION;
  oldprotect: dword;
begin
  WindowName := FindWindow(nil, 'World of Warcraft');
  If WindowName = 0 then
  begin
  Result := False;
  Exit;
  end;
  GetWindowThreadProcessId(WindowName, @ProcessId);
  HandleWindow := OpenProcess(PROCESS_VM_WRITE, False, ProcessId);
  VirtualQueryEx(HandleWindow, @Address, @mbi, //sizeof operator here for mbi);
  VirtualProtectEx(HandleWindow, mbi.BaseAddress, mbi.RegionSize, PAGE_READWRITE, @oldprotect);
  WriteProcessMemory(HandleWindow, Ptr(Address), @Value, 4, Write);
  CloseHandle(HandleWindow);
  Result := True;
end;

How would you do the
Code:
//sizeof operator here for mbi

in C++? So I know what to convert.


You want to put 28 as the size. And if you want to freeze the value, just loop WPM.

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
NothingToShow
Grandmaster Cheater Supreme
Reputation: 0

Joined: 11 Jul 2007
Posts: 1579

PostPosted: Tue Jun 10, 2008 3:00 pm    Post subject: Reply with quote

@oib111
When I do that, and tests my app, it gives me this error:
Code:
Types of actual and formal var parameters must be identical.


Since you're not coding in Delphi, I don't expect you to know what to do.
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Tue Jun 10, 2008 3:09 pm    Post subject: Reply with quote

Try doing this.

Code:

function EditMemory(Address: Integer; Value: Integer): Boolean;
var
  ProcessId: Integer;
  WindowName: hwnd;
  HandleWindow: handle;
  Write: Cardinal;
  mbi: MEMORY_BASIC_INFORMATION;
  oldprotect: dword;
  size: SIZE_T;
begin
  size = 28;
  WindowName := FindWindow(nil, 'World of Warcraft');
  If WindowName = 0 then
  begin
  Result := False;
  Exit;
  end;
  GetWindowThreadProcessId(WindowName, @ProcessId);
  HandleWindow := OpenProcess(PROCESS_VM_WRITE, False, ProcessId);
  VirtualQueryEx(HandleWindow, @Address, @mbi, size);
  VirtualProtectEx(HandleWindow, mbi.BaseAddress, mbi.RegionSize, PAGE_READWRITE, @oldprotect);
  WriteProcessMemory(HandleWindow, Ptr(Address), @Value, 4, Write);
  CloseHandle(HandleWindow);
  Result := True;
end;


Not sure if SIZE_T is a valid varaible type.

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
NothingToShow
Grandmaster Cheater Supreme
Reputation: 0

Joined: 11 Jul 2007
Posts: 1579

PostPosted: Tue Jun 10, 2008 3:11 pm    Post subject: Reply with quote

No, it's not. What kind of variable type is it? If you know what I'm asking.
Or maybe I need to add something in uses, I'll search.
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Tue Jun 10, 2008 3:13 pm    Post subject: Reply with quote

SIZE_T is a ULONG_PTR, or unsigned long pointer.
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
NothingToShow
Grandmaster Cheater Supreme
Reputation: 0

Joined: 11 Jul 2007
Posts: 1579

PostPosted: Tue Jun 10, 2008 3:22 pm    Post subject: Reply with quote

oib111 wrote:
SIZE_T is a ULONG_PTR, or unsigned long pointer.

And unsigned pointer in Delphi, is (what the search has resulted) : Pointer, in this example.
Size: pointer;

But then it gives me another error, that when you're assigning the 28 to size, it tells me that the value is an integer, and not pointer.
Back to top
View user's profile Send private message
angerist
Grandmaster Cheater Supreme
Reputation: 0

Joined: 18 Jun 2007
Posts: 1011
Location: Australia.

PostPosted: Sat Jun 14, 2008 9:51 pm    Post subject: Reply with quote

@Moller,

You shouldn't base your project on my snippets. Since I'm very new to Delphi. And I coded that quickly. But I've been doing a fair bit of research on this. And it seems to be working. So I'll post snippets when I'm done.

_________________
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 programming All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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