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:
This will edit the following memory adress: 0x57C2A4Code:#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; }
In the calculator window,
The lines above will search for a window (proccess) to edit.Code:HWND hWnd = FindWindow(0, "Calculator"); if(hWnd == 0) { MessageBox(0, "Error cannot find window.", "Error", MB_OK|MB_ICONERROR); }
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:0x57C2A4 is our adress, newdata is the value for our adressm and newdatasize is the bytesCode:if(WriteProcessMemory(hProcess, (LPVOID)0x57C2A4, &newdata, newdatasize, NULL))
that the adress is (Most 4)
So you could edit it to:
Wich will change the value to 567 with 4 bytes.Code:if(WriteProcessMemory(hProcess, (LPVOID)0x57C2A4, &567, 4, NULL))
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:
and put it in a infinite loop: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 }
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:while(1); { if(WriteProcessMemory(hProcess, (LPVOID)0x57C2A4, &newdata, newdatasize, NULL)) { } }
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): https://pastebin.com/ATMUPjrq
Last edited by Tukjedude; 05-31-2010 at 12:31 PM.
thanks i was looking for this thnx\!
[IMG]https://www.mpgh.net/forum/members/560509-zyixc-albums-d/picture2910-******.png[/IMG]
The stars that once lit my way have dimmed, the sky turned gray.
The path, once so clear, faded away.
Howto freeze an adresss ?
ow it does automaticcaly
but if i change weapon its gone
sry for double post
Last edited by Zyixc; 05-31-2010 at 10:29 AM.
[IMG]https://www.mpgh.net/forum/members/560509-zyixc-albums-d/picture2910-******.png[/IMG]
The stars that once lit my way have dimmed, the sky turned gray.
The path, once so clear, faded away.
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)
Between: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);
You get an infinite loop.. so the program will repeat the code between it.Code:for (int i = 0; i >= 0; i++) { // That code above here! }
So it basicly freezes the adress..
But i will add it to this tutorial.. be patient for a more extensive explaination..
Last edited by Tukjedude; 05-31-2010 at 10:37 AM.
Zyixc (05-31-2010)
Until i reaches the maximum number a signed integer can hold.
Use while(1) instead
Ah we-a blaze the fyah, make it bun dem!
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
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
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.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 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
Very nice Tut Go ahead!