View previous topic :: View next topic |
Author |
Message |
kot1990 Expert Cheater
Reputation: 1
Joined: 06 Sep 2009 Posts: 131 Location: Greece
|
Posted: Sun Sep 06, 2009 9:29 am Post subject: Please explain someone. |
|
|
I just created a small program in C that creates an integer x and assigns the value 998 to it and prints its address which is 0022FF74 and the value 998. Then it waits to press a key and it prints the value of x again. This time I go to cheat engine and set the value 998 to something else. Ok, it prints the new value that I set in CE.
Here's the code of my program:
Code: | #include <stdio.h>
int main()
{
int x =998;
printf("x is %d and the address of x is %p\n",x,&x);
system("pause");
printf("Now x is %d\n",x);
system("pause");
} |
My question is: How can the program save the integer x in the same location 0022FF74 everytime I run the program?
If I run another instance of the program at the same time, the same memory location 0022FF74 is used in both instances and contains different values. For example I run the program for the first time and it displays
"x is 998 and the address of x is 0022FF74". I change the 998 to 1500 with CE. Now memory 0022FF74 contains 1500. Then I run a second instance of the program. I switch with CE to the other executable and it contains the value 998 in the same location 0022FF74. I change it to 1850. Now I go to the first instance and press a key to see the value. It prints 1500 from location 0022FF74. Now I go to the second one and it prints 1850 from the same memory location .. That's weird. Please help!!!![/code]
|
|
Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sun Sep 06, 2009 10:02 am Post subject: |
|
|
Your programs don't share the same virtual memory, so if you change one value in one instance, it won't change in the second instance and vice-versa.
_________________
|
|
Back to top |
|
 |
kot1990 Expert Cheater
Reputation: 1
Joined: 06 Sep 2009 Posts: 131 Location: Greece
|
Posted: Sun Sep 06, 2009 10:05 am Post subject: |
|
|
yea, I just figured this out. What I want to do is to create an application that will change the value in memory, but 0022FF74 doesn't seem to be the real memory location, because both use the same one. How can I manage the real one to change it, like CE does.
|
|
Back to top |
|
 |
Chaosis13 Master Cheater
Reputation: 0
Joined: 14 Aug 2007 Posts: 372
|
Posted: Sun Sep 06, 2009 10:16 am Post subject: |
|
|
Space is allocated when you run a program. Location x is relative to the allocated space. The absolute address is irrelevant to what you want.
So both programs use the same relative address, but the absolute address is different.
To make a program to edit the value use WriteProcessMemory(), VirtualProtectEx() also might be useful.
|
|
Back to top |
|
 |
kot1990 Expert Cheater
Reputation: 1
Joined: 06 Sep 2009 Posts: 131 Location: Greece
|
Posted: Sun Sep 06, 2009 10:24 am Post subject: |
|
|
Than you! I will try
|
|
Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Sun Sep 06, 2009 10:29 am Post subject: |
|
|
it is the real memory location. or at least the correct virtual one. windows gives the user the impression of thread and process concurrency which is a huge topic in itself. each program sees a usermode space for itself of 0x00000000-0x7fffffff which works by virtual memory and swapping pages in and out of various places
so if you want to change the virtual memory for one particular process, there are two ways
1 ) edit the memory from within that same process
2 ) edit it externally by some other means ( easiest is winapi )
to edit the memory from within that same process one way would be to inject a dll
second way might use something like writeprocessmemory. for that you need to specify a handle to the process which is like an identifier to the system of which process you want to edit the memory of
that is how the system knows which process' memory to edit, by the specified handle
if you're interested you can read up on concurrency, if you just want to make it work learn how to get a specific process' handle and then once you have it you can use writeprocessmemory
i wouldn't advise touching winapi until you have a good grasp of the language itself though
|
|
Back to top |
|
 |
Chaosis13 Master Cheater
Reputation: 0
Joined: 14 Aug 2007 Posts: 372
|
Posted: Sun Sep 06, 2009 10:41 am Post subject: |
|
|
I think he wants the English version. From his code he is obviously a beginner, but wants to learn. Lets not scare him away.
|
|
Back to top |
|
 |
kot1990 Expert Cheater
Reputation: 1
Joined: 06 Sep 2009 Posts: 131 Location: Greece
|
Posted: Sun Sep 06, 2009 10:44 am Post subject: |
|
|
I am a newbie and I don't know many things in languages but I am learning. Thx for all your advise
|
|
Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Sun Sep 06, 2009 12:18 pm Post subject: |
|
|
Chaosis13 wrote: | I think he wants the English version. From his code he is obviously a beginner, but wants to learn. Lets not scare him away. |
hence i wrote a confusing paragraph then appended :
Quote: | i wouldn't advise touching winapi until you have a good grasp of the language itself though |
hopefully it should prevent another void spawning
|
|
Back to top |
|
 |
kot1990 Expert Cheater
Reputation: 1
Joined: 06 Sep 2009 Posts: 131 Location: Greece
|
Posted: Sun Sep 06, 2009 7:45 pm Post subject: |
|
|
After a lot of searching I found (as you said) than every proccess has its own virtual memory and I need to target the specified proccess under windows to make changes to its memory. And I don't have to worry about absolute addresses, it seems that windows will do it for me ,, the only thing I need now is the proccess id and WriteProcessMemory. I got confused in the beggining, but CE also needs a targeted application to make changes to its memory, that helped me a lot to understand!!!! Special thanks to everyone who helped me.
|
|
Back to top |
|
 |
Chaosis13 Master Cheater
Reputation: 0
Joined: 14 Aug 2007 Posts: 372
|
Posted: Mon Sep 07, 2009 6:27 am Post subject: |
|
|
You need to do this:
Code: | HANDLE hProc;
HWND Game;
int PID;
int base_address = 0x400000;
int pointer;
//Handles
Game = FindWindow(NULL, "WINDOW NAME");
if (!Game) {
cout << "Failed to get handle.\n";
Sleep(10000);
return true;
}
GetWindowThreadProcessId(Game,(LPDWORD)&PID);
hProc = OpenProcess(PROCESS_ALL_ACCESS,FALSE,PID);
// Get Base Pointer
ReadProcessMemory(hProc, (LPCVOID)base_address, &pointer, 0x4, NULL); |
This is edited from a program of mine. Read over it, and Google the functions. (FindWindow, OpenProcess)
|
|
Back to top |
|
 |
kot1990 Expert Cheater
Reputation: 1
Joined: 06 Sep 2009 Posts: 131 Location: Greece
|
Posted: Tue Sep 08, 2009 8:40 am Post subject: |
|
|
Well, this is my first program in C++. Till now I knew only C (types, variables, loops , pointers, structures), but it seems to be the same in C++. Now I 've got a problem with accessing the process. Look at my code:
Code: | #include <iostream>
#include <windows.h>
using namespace std;
bool main()
{
HWND Game;
int pointer;
int PID;
int base_address = 0x100579C;
Game = FindWindow(NULL, L"Minesweeper");
if (!Game)
{
cout << "Failed to get handle.\n";
return true;
}
GetWindowThreadProcessId(Game,(LPDWORD)&PID);
cout << PID;
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS,false,PID);
if(hProc == NULL)
MessageBox(NULL, L"Cannot open process!", L"Error!", MB_OK + MB_ICONERROR);
//ReadProcessMemory(hProc, (LPCVOID)base_address, &pointer, 0x4, NULL);
if (WriteProcessMemory(hProc, (LPVOID)base_address, &pointer, 0x4,NULL))
MessageBox(NULL, L"WriteProcessMemory is a success!", L"Success!", MB_OK + MB_ICONINFORMATION);
} |
The problem is on OpenProcess
hProc = OpenProcess(PROCESS_ALL_ACCESS,false,PID);
The error message will always display . I tried other methods accessing. Ok I got PROCESS_VM_WRITE working but I think then WriteProcessMemory fails for some reason. I couldn't write to memory. And another thing is that all text in MessageBox and FindWindow needed an L in front, otherwise I was getting an error like "can't convert from constant char to LPCWSTR". And what is the base address. I thought is was the address I'm gonna write to. So I changed it. I need to write 4 bytes from 0x100579C - 0x100579F with all 4 bytes to be 0. (00 00 00 00). On that address minesweeper keeps the time running. The PID is displayed correctly like 2125 on "cout << PID"; , that means that FindWindow and GetWindowThreadProcessId worked correctly.
|
|
Back to top |
|
 |
Chaosis13 Master Cheater
Reputation: 0
Joined: 14 Aug 2007 Posts: 372
|
Posted: Tue Sep 08, 2009 5:45 pm Post subject: |
|
|
Prototype from MSDN: Code: | BOOL WINAPI WriteProcessMemory(
__in HANDLE hProcess,
__in LPVOID lpBaseAddress,
__in LPCVOID lpBuffer,
__in SIZE_T nSize,
__out SIZE_T *lpNumberOfBytesWritten
); |
You are using the parameters from ReadProcessMemory()...
This might work: Code: | WriteProcessMemory(hProc, 0x100579C, 90, 4, NULL); |
This looks like what you want to do.
|
|
Back to top |
|
 |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Tue Sep 08, 2009 6:01 pm Post subject: |
|
|
I am bored in class, so I thought I made you something quick.
Code: | #include <iostream>
#include <tchar.h>
#include <windows.h>
int main()
{
HWND hWnd;
DWORD dwPID, dwBaseAddr = 0x100579C;
HANDLE hProc;
BYTE byWrite[] = { 0x90, 0x90 };
std::cout << "Hello" << std::endl << "Searching for Minesweeper...";
while((hWnd = FindWindow(NULL, _T("Minesweeper"))) == NULL)
std::cout << "."; Sleep(100);
std::cout << std::endl << "Found MineSweeper!" << std::endl;
GetWindowThreadProcessId(hWnd, &dwPID);
if((hProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE, false, dwPID)) != INVALID_HANDLE_VALUE)
if(WriteProcessMemory(hProc, &dwBaseAddr, byWrite, sizeof(byWrite), NULL))
std::cout << "Success!" << std::endl;
else
std::cout << "Could not write process memory!" << std::endl;
else
std::cout << "Could not open process!";
if(hProc != INVALID_HANDLE_VALUE)
CloseHandle(hProc);
std::cin;
} |
Not sure if it'll work, never tested it.
|
|
Back to top |
|
 |
hacksign23 Master Cheater
Reputation: 0
Joined: 26 Nov 2006 Posts: 404
|
Posted: Tue Sep 08, 2009 6:05 pm Post subject: |
|
|
this probably won't help
but try making it static?
_________________
|
|
Back to top |
|
 |
|