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 


C++ hacking question

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
TuxTheWise
How do I cheat?
Reputation: 0

Joined: 20 Jan 2011
Posts: 6

PostPosted: Thu Jan 20, 2011 8:06 am    Post subject: C++ hacking question Reply with quote

It's not a Cheat Engine question, but I thought you maybe could help me.

In C++, I can modify another process memory with:

Code:

HWND WindowsHandle = FindWindow(0,"BWMeter");
unsigned long int WindowsPID;
GetWindowThreadProcessId(WindowsHandle, &WindowsPID);
HANDLE WindowsProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, false, WindowsPID);

and using
Code:
WriteProcessMemory(...)
to change it.

However, the memory part I want to change depends on the base address of the process. Any idea of how I can get it? Cheat Engine can show it, but I wanted to automatically do it so my program could work in any situation.

Thanks.


Last edited by TuxTheWise on Fri Jan 21, 2011 6:06 pm; edited 2 times in total
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Thu Jan 20, 2011 2:18 pm    Post subject: Reply with quote

CreateToolhelp32Snapshot
Process32First
Process32Next
Module32First
Module32Next

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
TuxTheWise
How do I cheat?
Reputation: 0

Joined: 20 Jan 2011
Posts: 6

PostPosted: Thu Jan 20, 2011 7:30 pm    Post subject: Reply with quote

Okay, I can create a snapshot and get the info about the process/module. However, the data given by Process32... and Module32... (PROCESSENTRY32 and MODULEENTRY32) does not contain the base address (LPCVOID lpBuffer) I want to use with the WriteProcessMemory(...) function.

Can you explain how should I proceed to obtain it? Or there is another way to edit a memory value only with a offset, without the need of the base value?

Again, thanks for the help.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Thu Jan 20, 2011 7:45 pm    Post subject: Reply with quote

Module32First / Module32Next fill a MODULEENTRY32 struct which does contain the base address of each module.

You can read about each part of the structure here:
http://msdn.microsoft.com/en-us/library/ms886756.aspx

Edited for clarity..

_________________
- Retired.


Last edited by atom0s on Fri Jan 21, 2011 12:49 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
TuxTheWise
How do I cheat?
Reputation: 0

Joined: 20 Jan 2011
Posts: 6

PostPosted: Thu Jan 20, 2011 9:55 pm    Post subject: Reply with quote

I'm so dumb, for some reason I've missed it.

It worked EXACTLY like I wanted, thank you very much for the help!
Back to top
View user's profile Send private message
TuxTheWise
How do I cheat?
Reputation: 0

Joined: 20 Jan 2011
Posts: 6

PostPosted: Fri Jan 21, 2011 6:29 pm    Post subject: Reply with quote

Sorry for "closing" the topic before, new questions have appeared.

I think my question will get clearer if I show my results so far first.

The value of memory I want to modify (according to Cheat Engine) is 0x017B216C.

Seeing the process I want to modify with Module32... functions, I see that base address is 0x400000 (modBaseAddr) and the size of the module (modBaseSize) is 3579904 bytes long. It means that the place of memory I want to modify is not there.

My next step was looking at the Heaps. Making the iterations with Heap32... and Heap32List... I was able to construct this list: [sorry, I can't post urls yet T__T] (there is no real reason to see it if you don't want). The address I want is not here either.

What am I missing?


I was talking to a friend at work today, and he said a program are allocated in three parts: one is for code, other for static variables and another one for dynamic allocated memory. I think I reached the first one with the base address of the module and the last one looking at the heaps. Since what I want to do is changing a program's configuration, I believe the data I want is in the second area. I'm not sure if what I'm saying is correct though.

It seems like I'm progressing thanks to you Wiccaan.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri Jan 21, 2011 6:40 pm    Post subject: Reply with quote

Quote:

The value of memory I want to modify (according to Cheat Engine) is 0x017B216C.


Try seeing if the address is part of a DLL's memory, open Cheat Engine and attach to the application you are working on, then open the Memory Viewer in CE then go to:
View -> Enumerate DLL's and Symbols

Look for a module the address is in rage of. If the address looks like it could be part of one of the listed DLLs, use Module32First/Module32Next to get the base and size of that module to ensure its within that memory space.

If it is, then you can create an offset to it using:
Address - DLL Base = Offset

To which you can then refind it later with:
Offset + DLL Base = Address

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
TuxTheWise
How do I cheat?
Reputation: 0

Joined: 20 Jan 2011
Posts: 6

PostPosted: Fri Jan 21, 2011 8:22 pm    Post subject: Reply with quote

The memory piece I want to edit DOES NOT belong to any module in "Enumerate DLL's and Symbols" (I observed offset and size). It also does not belong to anything in the "View -> Heaplist".

Looking at the "View -> Memory Regions". I can find the region as:

Address - Allocation Protect - State - Protect - Type - Size
03070000 - Read+Write - Commit - Read+Write - Private - 125000
(in this OS the memory I want to modify is at 0x0310216C).

I wonder how Cheat Engine found this area, so I could find it the same way in my program.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri Jan 21, 2011 8:28 pm    Post subject: Reply with quote

Check out: VirutalQueryEx

Along with that since the memory is allocated, try debugging the address you are working with and see if you can locate a pointer. If you can find a pointer outside of the allocated memory you may be able to easily alter it each load.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
TuxTheWise
How do I cheat?
Reputation: 0

Joined: 20 Jan 2011
Posts: 6

PostPosted: Sat Jan 22, 2011 10:56 am    Post subject: Reply with quote

Wiccaan wrote:
Check out: VirtualQueryEx.


I made some tests and apparently I'll be able to find the memory region I want with this function.

Luckly I won't need to open this thread again. Thanks for the help.
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