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,42 @@
#include <bits/stdc++.h>
using namespace std;
struct Hero{
int life = 10000;
int attack = 10;
};
struct Monster{
int life = 10000;
int attack = 100;
};
int main(){
Hero h; Monster m;
cout << "Hero的血量内存地址为:" << &h.life << endl;
cout << "Hero的攻击力内存地址为:" << &h.attack << endl;
cout << "Monster的血量内存地址为:" << &m.life << endl;
cout << "Monster的攻击力内存地址为:" << &m.attack << endl;
system("pause");
int count = 0;
while(true){
if(m.life <= 0){
cout << "玩家打败了怪物!" << endl;
break;
}
if(h.life <= 0){
cout << "怪物打败了玩家!" << endl;
break;
}
h.life -= m.attack;
m.life -= h.attack;
cout << "--------第<< count << "次攻击-----------";
cout << "玩家对怪物造成了:" << h.attack << "点伤害" << endl;
cout << "怪物对玩家造成了:" << m.attack << "点伤害" << endl;
cout << "玩家血量:" << h.life << endl;
cout << "怪物血量:" << m.life << endl;
cout << endl;
_sleep(5000);
}
}
@@ -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;
}