如何接受用户输入的常量并使用 writeprocessmemory?
Posted
技术标签:
【中文标题】如何接受用户输入的常量并使用 writeprocessmemory?【英文标题】:How to accept user input for a constant and use writeprocessmemory? 【发布时间】:2017-06-08 06:26:51 【问题描述】:如何使用WriteProcessMemory
更改我当前弹药地址的弹药?我知道怎么读,只是不知道怎么写。是 SetAmmo 。我以为我做的一切都是正确的?
代码:
#include <iostream>
#include <math.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <Windows.h>
using namespace std;
DWORD pid;
DWORD Ammo = 0x07823C5EC;
int MyAmmo;
int SetAmmo = 1;
int main()
HWND hwnd = FindWindowA(0, ("Garry's Mod"));
GetWindowThreadProcessId(hwnd, &pid);
HANDLE pHandle = OpenProcess(PROCESS_VM_READ, FALSE, pid);
ReadProcessMemory(pHandle, (LPVOID)Ammo, &MyAmmo, sizeof(MyAmmo), 0);
cout<<"Current Ammo = "<<MyAmmo<<endl;
WriteProcessMemory(pHandle, (LPVOID)Ammo, &SetAmmo, sizeof(SetAmmo), 0);
system("Pause");
return 0;
【问题讨论】:
为什么这看起来像是在尝试破解? 【参考方案1】:您以读取权限打开进程:
HANDLE pHandle = OpenProcess(PROCESS_VM_READ, FALSE, pid);
尝试:
HANDLE pHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
【讨论】:
不要使用PROCESS_ALL_ACCESS
。仅请求您实际需要的最低权限。要使用ReadProcessMemory
,您只需要PROCESS_VM_READ
权限即可。要使用WriteProcessMemory
,您只需要PROCESS_VM_WRITE
和PROCESS_VM_OPERATION
权限。这在文档中有详细说明。所以改用这个:HANDLE pHandle = OpenProcess(PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION, FALSE, pid);
以上是关于如何接受用户输入的常量并使用 writeprocessmemory?的主要内容,如果未能解决你的问题,请参考以下文章