The concept of memory hacks is fairly easy to grasp especially with a demonstration. So the idea of a Memory hack is generally, to access the games process memory in order to change values therefore affecting the status of the player in game or to read values in order to gain an unfair advantage. Memory hacks can do things such as give health or ammo, change the players position, or give other players positions (depending on the game).
Things you need:
- Windows (vm or installed on a hardrive)
- An Installation of AssaultCube
- Cheat Engine >=6.4
- A text editor of some kind I use sublime text
- A C compiler mingw, lcc etc
Good to have:
- aadp4olly (for getting by anti debugging solutions that might be implemented on commercial games)
Before we get started I would also recommend adding this to your arguments inside the assaultcube.bat file "-t -w 800 -h 600", just because we are going to be messing around with a bunch of windows.
Things you should probably know (not completely necessary I suppose)
- Rudimentary understanding of ASM
- C Programming: Programming Languages For Hackers And Learn It From Most 6 Helpful Websites
- Memory Structure
- Programming with the Windows API
Hacking AssaultCube:
Cheat Engine makes finding this pointer relatively easy. Right click on the memory record and select find what access this address. There will be a couple of asm instructions in the debugger window but these are not what we are looking for these are just used for displaying the value. To find the value we want take a shot then return to the window. The decrement instruction is the one we are looking for. This instruction decrements your ammo when you take a shot double click on it. (As a side note record the address of the decrement instruction for later.) Cheat engine will find the value of a pointer to this address. So we search this value in Cheat Engine. Add the address manually and make sure to check the box designating it a pointer and add no offset because there is none in the instruction. Continue to repeat this process on the pointer until you reach a static address(green). Record the address and its offsets.
Now the process needs to be repeated for the health variable. Unfortunately assault cube dos not provide a command to hurt yourself so you have to hurt yourself by ingame means such as standing by a grenade. So do a first scan for 100 and then find a grenade on the map you were loaded into and hurt yourself with it. Do the next scan with your new health value. Continue to do this until you have two values once again add the top one and change the value.
Repeat the process of finding a static pointer.
Explained using pictures for visual learners:
First we search our starting value for ammo which if you are using the assault rifle is 20Programming the Hack:
The first thing we need to do to gain control of the game is to gain a handle linked to the process. To do this I wrote a method called getHandle.
Code: C
- /*
- * Returns a Handle for process matching pname
- */
- HANDLE getHandle(char pname[])
- {
- DWORD dwPid=0;
- HANDLE proc, hProc;
- PROCESSENTRY32 pe32 = {sizeof(PROCESSENTRY32)};
- while(!dwPid)
- {
- hProc=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
- if(Process32First(hProc, &pe32))//place process in pe32
- {
- do
- {
- {
- dwPid=pe32.th32ProcessID;//set pid to the pid of the process if the process names matched
- break;
- }
- }while(Process32Next(hProc,&pe32));//move to next process
- }
- sleep(10);
- }
- proc=OpenProcess (PROCESS_ALL_ACCESS,FALSE,dwPid);//open process Handle
- return proc;//return the Handle
- }
Code: C
- DWORD offCalc(DWORD b, DWORD offs[], int size, HANDLE proc)
- {
- DWORD base=b;
- DWORD ptemp;
- int i;
- for(i=0;i<size;i++)//loops through offsets
- {
- ReadProcessMemory(proc, (LPCVOID)base,&ptemp,sizeof(ptemp),NULL);//reads the next adress into ptemp
- base=ptemp+offs;//adds ptemp to the offset
- }
- return base;//return address
- }
Code: C
- int writeVal(HANDLE proc, DWORD addr,BYTE *val)
- {
- return WriteProcessMemory(proc,(BYTE*)addr,val,4,NULL);//write the value to the proc at addr
- }
This is all tied together in main.
Code: C
- int main()
- {
- BYTE setval[]={0x64,0x00,0x00,0x00};//100 in hex because of little endian
- HANDLE proc=NULL;//handle for the process
- DWORD health={0x00509B74};//static adress for health
- DWORD haddr;
- DWORD offh[]={0xF8};//offsets health
- DWORD ammo={0x0051E20C};//static adress for ammo
- DWORD aaddr;
- DWORD offa[]={0x374, 0x14, 0x00};//offsets for ammo
- char gameName[]="ac_client.exe";//name of the process
- proc=getHandle(gameName);//set proc to the Handle gained by get Handle
- if(proc!=0)//check if proc was retrieved
- {
- haddr=offCalc(health,offh,1,proc);//calculate the dynamic address and set haddrr
- aaddr=offCalc(ammo,offa,3,proc);//calculate the dynamic adress of and set aaddr
- int check1;//bool for write status
- int check2;//bool for write status
- while(1==1)//infinite loop cause im lazy
- {
- check1=writeVal(proc,haddr,setval);//write the val for health and place the status in check 1
- check2=writeVal(proc,aaddr,setval);//write the val for ammo and place the status in check 2
- if(!check1&&!check2)//print error adressess if write returns 0
- {
- if(!check1)
- if(!check2)
- }
- }
- }
- }
Code: C
- #include <windows.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <tlhelp32.h>
- //function prototypes
- DWORD offCalc(DWORD b, DWORD offs[], int size, HANDLE proc);
- HANDLE getHandle(char windowname[]);
- int writeVal(HANDLE proc, DWORD addr,BYTE *val);
- int main()
- {
- BYTE setval[]={0x64,0x00,0x00,0x00};//100 in hex because of little endian
- HANDLE proc=NULL;//handle for the process
- DWORD health={0x00509B74};//static adress for health
- DWORD haddr;
- DWORD offh[]={0xF8};//offsets health
- DWORD ammo={0x0051E20C};//static adress for ammo
- DWORD aaddr;
- DWORD offa[]={0x374, 0x14, 0x00};//offsets for ammo
- char gameName[]="ac_client.exe";//name of the process
- proc=getHandle(gameName);//set proc to the Handle gained by get Handle
- if(proc!=0)//check if proc was retrieved
- {
- haddr=offCalc(health,offh,1,proc);//calculate the dynamic address and set haddrr
- aaddr=offCalc(ammo,offa,3,proc);//calculate the dynamic adress of and set aaddr
- int check1;//bool for write status
- int check2;//bool for write status
- while(1==1)//infinite loop cause im lazy
- {
- check1=writeVal(proc,haddr,setval);//write the val for health and place the status in check 1
- check2=writeVal(proc,aaddr,setval);//write the val for ammo and place the status in check 2
- if(!check1&&!check2)//print error adressess if write returns 0
- {
- if(!check1)
- if(!check2)
- }
- }
- }
- }
- int writeVal(HANDLE proc, DWORD addr,BYTE *val)
- {
- return WriteProcessMemory(proc,(BYTE*)addr,val,4,NULL);//write the value to the proc at addr
- }
- /*
- * Returns a Handle for process matching pname
- */
- HANDLE getHandle(char pname[])
- {
- DWORD dwPid=0;
- HANDLE proc, hProc;
- PROCESSENTRY32 pe32 = {sizeof(PROCESSENTRY32)};
- while(!dwPid)
- {
- hProc=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
- if(Process32First(hProc, &pe32))//place process in pe32
- {
- do
- {
- {
- dwPid=pe32.th32ProcessID;//set pid to the pid of the process if the process names matched
- break;
- }
- }while(Process32Next(hProc,&pe32));//move to next process
- }
- sleep(10);
- }
- proc=OpenProcess (PROCESS_ALL_ACCESS,FALSE,dwPid);//open process Handle
- return proc;//return the Handle
- }
- /*
- * Returns the adress with calculated offsets
- */
- DWORD offCalc(DWORD b, DWORD offs[], int size, HANDLE proc)
- {
- DWORD base=b;
- DWORD ptemp;
- int i;
- for(i=0;i<size;i++)//loops through offsets
- {
- ReadProcessMemory(proc, (LPCVOID)base,&ptemp,sizeof(ptemp),NULL);//reads the next adress into ptemp
- base=ptemp+offs;//adds ptemp to the offset
- }
- return base;//return address
- }
You are done, Thanks for reading.
Recommended to read: How To Become A Hacker - Basic Guide For Beginners
No comments:
Post a Comment