Files

35 lines
994 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <windows.h>
#include <iostream>
using namespace std;
int main() {
int pid;
cout << "请输入目标进程 PID:" << endl;
cin >> pid;
// 使用 OpenProcess 打开目标进程,可以通过 hProcess 去访问这个程序内的所有内存数据
// PROCESS_ALL_ACCESS 表示请求所有权限
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
if(hProcess == nullptr){
cout << "无效进程";
return 0;
}
// 要写入的内存地址以字符串形式输入
string addr;
cin >> addr;
// 将字符串转换为无符号长整型 (unsigned long long),然后转换为 int* 指针
// stoull 可以将字符串解转为 unsigned long long
int* address = (int*)stoull(addr);
// 你想要修改的值
int newLife;
cin >> newLife;
// 将 newLife 的值写入到目标进程的指定内存地址
WriteProcessMemory(hProcess, address, &newLife, sizeof(newLife), 0);
CloseHandle(hProcess);
return 0;
}