Initial commit: C++ courseware

This commit is contained in:
xiaolinquan committed 2026-11-05 22:51:02 +08:00
commit 4a4ee7c287
1789 files changed
+373489

No files matched your search

@@ -0,0 +1,34 @@
#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;
}