[Tutorial] Basic C++ Game Hacking (Memory Editing)

Posts 1–15 of 18 · Page 1 of 2
[Tutorial] Basic C++ Game Hacking (Memory Editing)
Basic C++ Game Hacking (Memory Editing)
Hi All

Some simple basic C++ game hacking (egg: memory editing)
Ill start with one of the most simple codes:

Code:
#include <windows.h>

int main() 
{
	HWND hWnd = FindWindow(0, "Calculator");
  	if(hWnd == 0)
	{
    		MessageBox(0, "Error cannot find window.", "Error", MB_OK|MB_ICONERROR);
  	} 
	else 
	{
    		DWORD proccess_ID;
    		GetWindowThreadProcessId(hWnd, &proccess_ID);
    		HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proccess_ID);
    		if(!hProcess)
		{
      			MessageBox(0, "Could not open the process!", "Error!", MB_OK|MB_ICONERROR);
    		} 
		else 
		{
      			int newdata = 500;
     		 	DWORD newdatasize = sizeof(newdata);
      			if(WriteProcessMemory(hProcess, (LPVOID)0x57C2A4, &newdata, newdatasize, NULL))
			{
        				MessageBox(NULL, "WriteProcessMemory worked.", "Success", MB_OK + MB_ICONINFORMATION);
      			} 
			else 
			{
        				MessageBox(NULL, "Error cannot WriteProcessMemory!", "Error", MB_OK + MB_ICONERROR);
      			}
      			CloseHandle(hProcess);
    		}
  	}
  	return 0;
}
This will edit the following memory adress: 0x57C2A4
In the calculator window,


Code:
HWND hWnd = FindWindow(0, "Calculator");
  	if(hWnd == 0)
	{
    		MessageBox(0, "Error cannot find window.", "Error", MB_OK|MB_ICONERROR);
  	}
The lines above will search for a window (proccess) to edit.
In this case it is the calculator but if you want to edit the Cod4 Adresses it should be iw3mp!
The if statement checks if the window is opened and exists. If not you will get a message that
it can not be found.

Scroll down til you see this line:
Code:
if(WriteProcessMemory(hProcess, (LPVOID)0x57C2A4, &newdata, newdatasize, NULL))
0x57C2A4 is our adress, newdata is the value for our adressm and newdatasize is the bytes
that the adress is (Most 4)
So you could edit it to:

Code:
if(WriteProcessMemory(hProcess, (LPVOID)0x57C2A4, &567, 4, NULL))
Wich will change the value to 567 with 4 bytes.


Memory Adress freezing on request of Zyixc:

So there is not a real code to freeze (egg FreezeAdress() it just don't exsist>
But we can freeze it by using a infinite loop

So we take the code wich edits the adress value:

Code:
if(WriteProcessMemory(hProcess, (LPVOID)0x57C2A4, &newdata, newdatasize, NULL))
{
// Here should be the message box that the change has worked, but you need to remove it when using a loop otherwise you will get a infinite msgbox xD
}
and put it in a infinite loop:
Code:
while(1);
{
	if(WriteProcessMemory(hProcess, (LPVOID)0x57C2A4, &newdata, newdatasize, NULL))
	{
        				      			
	}
}
The code above will freeze youre code by using a simple loop. There is a second wat but you have maxium of numbers a signed interger can hold so it wil stop working after some time so just use the loop above.

Code:
for (int i = 0; i >= 0; i++)
{
// here the code
}

I will continue updating the topic with more info on howto start game hacking in C++.
A preview of how you can implent freezing adresses in the first code (on the top): http://pastebin.com/ATMUPjrq
thanks i was looking for this thnx\!
Howto freeze an adresss ?

ow it does automaticcaly
but if i change weapon its gone


sry for double post
First of all you can edit your post instead of double posting.
Freezing adresses is a little more complicated but i Will write a tutorial voor it.
Ill send you a message when its done.

Sorry for bad typing im on the iPhone xD

EDIT: For freeezing an adress isn't a code really. but if you put the following code:
(Wich is part of the coe in my first post)
Code:
                                            int newdata = 500;
     		 	DWORD newdatasize = sizeof(newdata);
      			if(WriteProcessMemory(hProcess, (LPVOID)0x57C2A4, &newdata, newdatasize, NULL))
			{
        				MessageBox(NULL, "WriteProcessMemory worked.", "Success", MB_OK + MB_ICONINFORMATION);
      			} 
			else 
			{
        				MessageBox(NULL, "Error cannot WriteProcessMemory!", "Error", MB_OK + MB_ICONERROR);
      			}
      			CloseHandle(hProcess);
Between:
Code:
for (int i = 0; i >= 0; i++)
{
// That code above here!
}
You get an infinite loop.. so the program will repeat the code between it.
So it basicly freezes the adress..

But i will add it to this tutorial.. be patient for a more extensive explaination..
Until i reaches the maximum number a signed integer can hold.

Use while(1) instead
I know, read the update on my first post
I already said that you can choose but you can use while(1);
Good work, but you should remove the For statement loop, and say you must use a while(1) loop... a for loop will end eventually...
Your'e right i'm not removing it completly.. but..just take a look :P
Quote Originally Posted by Tukjedude View Post
Your'e right i'm not removing it completly.. but..just take a look :P
Remove it or die...
Wtf why should i? Just shut up, and create your own tutorial if you don't like it..
If it was a joke.. then i will die
Very nice Tut Go ahead!
Code:
#include <windows.h>

int main() {
  HWND hWnd = FindWindow(0, "Calculator");
  if(hWnd == 0){
    MessageBox(0, "Error cannot find window.", "Error", MB_OK|MB_ICONERROR);
  } else {
    DWORD proccess_ID;
    GetWindowThreadProcessId(hWnd, &proccess_ID);
    HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proccess_ID);
    if(!hProcess){
      MessageBox(0, "Could not open the process!", "Error!", MB_OK|MB_ICONERROR);
    } else {
      int newdata = 500;
      DWORD newdatasize = sizeof(newdata);
      if(WriteProcessMemory(hProcess, (LPVOID)0x57C2A4, &newdata, newdatasize, NULL)){
        MessageBox(NULL, "WriteProcessMemory worked.", "Success", MB_OK + MB_ICONINFORMATION);
      } else {
        MessageBox(NULL, "Error cannot WriteProcessMemory!", "Error", MB_OK + MB_ICONERROR);
      }
      CloseHandle(hProcess);
    }
  }
  return 0;
}
That's also taken from another website, the code was originally posted February 14, 2009. I don't know how someone can claim to be a coder if they merely take source code from someone else, put their name on it, and claim it to be written by them. But I guess that's just how some people get by in life.
this is awesome thanks, hey can anyone give me an actual hack source code? (yes i will except a non working one) cuz i just want one for study
Quote Originally Posted by cruizrisner View Post
this is awesome thanks, hey can anyone give me an actual hack source code? (yes i will except a non working one) cuz i just want one for study
He isn't a coder, he is a leecher.
Quote Originally Posted by That0n3Guy View Post
He isn't a coder, he is a leecher.
my statement was addressed to everyone and i called nobody a coder
Posts 1–15 of 18 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?