On November 4, 2020, the university has started for a month, right?
The c language I learned in this university (to be honest, it’s been useless for several years and I have forgotten almost, I have been learning it again these days)
The total code is at the bottom
I am going to introduce in detail the fruit ninja modifier made yesterday (c++) (novices can fully understand)
1. First, use CE to perform a simple and accurate search corresponding to the base address of the fruit directly
After all, it’s about C, so I won’t talk about the extra CE
2. Now that the exact address is found, go directly to the C language
The main way to write modifiers in C++ is to read memory and write memory (this is similar to modifying a large game). The following two functions are needed to read and write memory in C language.
ReadProcessMemory(HANDLE hProcess, LPCVOID lpBaseAddress, LPVOID lpBuffer, DWORD nSize, LPDWORD lpNumberOfBytesRead);
WriteProcessMemory(HANDLE hProcess,LPVOID lpBaseAddress,LPVOID lpBuffer,DWORD nSize,LPDWORD lpNumberOfBytesWritten);
And these two functions need to pass in a common parameter HANDLE type of data (you can use it as a license, only this license can read and write functions)
To obtain a license for this game (Fruit Ninja) requires a computer to find the PID of this game, and the PID can be obtained through the handle, so our idea
Handle-->PID-->License-->Then modify the game
1. Get the handle
The function to get the handle in C language is
FindWindow( LPCSTR lpClassName, LPCSTR lpWindowName );
The specific wording is
HWND hWnd;
hWnd=FindWindow(NULL,“这里填游戏名”);
Define a hWnd of type HWND to receive the handle
"Fill in the game name here" in c++ as "Fruit Ninja" (the process name of the fruit ninja), and then the obtained handle is stored in the hWnd variable
2. Get process PID
The function to get PID is
GetWindowThreadProcessId();
Specifically written here as
DWORD PID;
GetWindowThreadProcessId(hWnd,&PID);
Define a variable of DWORD type to store the PID. The first parameter of GetWindowThreadProcessId() passes in the handle obtained in the first step, and then returns the PID of the process, which we receive in parameter 2 <&PID>.
3. Get permission
Obtaining permission is written as
HANDLE lsProcess=0;
lsProcess=OpenProcess(PROCESS_ALL_ACCESS,FALSE,PID);
PROCESS_ALL_ACCESS means to get all the licenses, parameter 2 fill in the PID obtained in the previous step
Same lsProcess storage license
3. Modify the game
Modifying the game corresponds to these two functions
ReadProcessMemory(HANDLE hProcess, LPCVOID lpBaseAddress, LPVOID lpBuffer, DWORD nSize, LPDWORD lpNumberOfBytesRead);
WriteProcessMemory(HANDLE hProcess,LPVOID lpBaseAddress,LPVOID lpBuffer,DWORD nSize,LPDWORD lpNumberOfBytesWritten);
#include <iostream>
#include <windows.h>//需要引用这个头文件
DWORD s;//这个用来存放读取当前的分数
DWORD dizhi=0x0BF308C;//这个写游戏对应的分数地址
//FruitNinja.exe+1B308C
do{
ReadProcessMemory(lsProcess, (LPVOID)dizhi, &s, 4, NULL);
//参数一 填许可 参数二填地址 参数三存放的位置
printf("当前水果数量:");
cout<<s<<endl;
Sleep(300); //程序延迟300ms
system("cls");//清空控制台
} while(TRUE);
I want him to achieve a dynamic reading effect, so I made an endless loop to read the score and print it to the console
Look carefully at the comments of the above function, I believe you can understand
The running effect is as shown below
The above shows the reading score, of course, what we have to do is to modify the score and directly upload the code
DWORD ss=999;//这里填你要改的分数
WriteProcessMemory(lsProcess,(LPVOID)dizhi,&ss,4,NULL);
//参数一填许可 参数二填地址 参数三填要修改的值
Because I went to college, I have plenty of time, and more will be updated later
Hope novices will pay more attention and learn from each other
If you have any questions about the above case of cutting fruits, just send me a private message on this platform
#include <iostream>
#include <windows.h>
using namespace std;
HWND hq_HWND(char ming[]){//获取句柄 传入进程名(不加exe)传出HWND (失败返回0)
//cout<<ming<<endl;
HWND hWnd=FindWindow(NULL,ming);
return hWnd;
}
DWORD hq_PID(HWND hWnd){//传入句柄 传出pid(失败传出0)
DWORD PID;
GetWindowThreadProcessId(hWnd,&PID);
return PID;
}
HANDLE hq_Process(DWORD PID){ //获取一个许可 返回许可 传入 PID
HANDLE lsProcess=0;
lsProcess=OpenProcess(PROCESS_ALL_ACCESS,FALSE,PID);
return lsProcess;
}
int main(int argc, char** argv) {
//cout<<hq_HWND("Tutorial-i386")<<endl; //用于获取句柄
//cout<<hq_PID(hq_HWND("Tutorial-i386"))<<endl;//用于获取PID
HANDLE lsProcess;
lsProcess=hq_Process(hq_PID(hq_HWND("Fruit Ninja")));
DWORD ss=999;
DWORD dizhi=0x0BF308C;
//FruitNinja.exe+1B308C
DWORD s;
do{
ReadProcessMemory(lsProcess, (LPVOID)dizhi, &s, 4, NULL);
printf("当前水果数量:");
cout<<s<<endl;
Sleep(300);
system("cls");
} while(TRUE);
//WriteProcessMemory(lsProcess,(LPVOID)dizhi,&ss,4,NULL);
return 0;
}