如何接受常量的用户输入并使用writeprocessmemory?

时间:2017-06-08 06:26:52

标签: c++ memory garrys-mod

如何使用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 个答案:

答案 0 :(得分:0)

您使用读取权限打开进程:

HANDLE pHandle = OpenProcess(PROCESS_VM_READ, FALSE, pid);

尝试:

HANDLE pHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);