【问题标题】:Accessing and editing multiple addresses in memory访问和编辑内存中的多个地址
【发布时间】:2017-07-08 08:26:38
【问题描述】:

我想访问和编辑内存中的多个地址。 如果它含糊不清,问题是:如果我使用内存扫描器并且结果是地址列表,我将如何访问和编辑它们? 我已经被告知尝试将所有地址放入一个数组中,我该怎么做?

这是目前为止的代码:

//

#include "stdafx.h"
#include "iostream"
#include "Windows.h"
#include <cstdint>
#include <stdint.h>

using namespace std;
int main()
{
    int newValue = 0;
    int* p;
    p = (int*)0x4F6DCFE3DC; // now p points to address 0x220202

    HWND hwnd = FindWindowA(NULL, "Call of Duty®: Modern Warfare® 3 Multiplayer");// Finds Window
    if (hwnd == NULL) {// Tests for success
        cout << "The window is not open" << endl;
        Sleep(3000);
        exit(-1);
    }
    else {
        cout << "It's open boss!";
    }
    else {// If Successful Begins the following
        DWORD procID;
        GetWindowThreadProcessId(hwnd, &procID);
        HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID);//Gets handle on process
        if (procID == NULL) {
            cout << "Cannot obtain process." << endl;
            Sleep(3000);
            exit(-1);
        }
        else {//Begins writing to memory
            while (newValue == 0) {
                 /*This Writes*/WriteProcessMemory(handle, (LPVOID)0x04F6DCFE3DC, &newValue, sizeof(newValue), 0);
                 cout << p;
                 Sleep(3000);

            }
        }
    }
}

【问题讨论】:

  • 请使用tour,尤其是How to Ask。不发文字图片,发文字。制作minimal reproducible example。描述你想要达到的目标。描述地址列表的含义。为什么要编辑它们?描述您如何访问地址列表,代码图片显示通过常量进行的访问。编辑问题以获取更多信息,不要将信息写入问题的答案。
  • p = (int*)0x4F6DCFE3DC; // now p points to address 0x220202 嗯!?这就是为什么 cmets 不应该描述明显的代码。代码经常更改,而 cmets 不会。然后它只是引起了人们的注意。
  • @StoryTeller 你的问题是评论说的很明显吗?
  • if {...} else {...} else {...} 错了。
  • 我投了反对票,因为这个问题一团糟。不想劝阻新用户,但如果你要粗鲁......

标签: c++ memory memory-address


【解决方案1】:

这相当容易。只需使用std::vector&lt;std::pair&lt;int*,int&gt;&gt; 来包含您要修改的所有这些地址以及它们应该达到的值:

std::vector<std::pair<int*,int>> changeMap = {
    { (int*)0x4F6DCFE3DC , 0 }
    // more address value pairs ...
};

然后你可以循环处理它们:

for(auto it = std::begin(changeMap); it != std::end(changeMap); ++it)
{
    WriteProcessMemory(handle, (LPVOID)it->first, &(it->second),
                       sizeof(it->second), 0);
}

你想用它实现什么1


我已经被告知尝试将所有地址放入一个数组中,我该怎么做?

如果您想将所有地址内容设置为0,您可以使用更简单的构造:

int newValue = 0;
std::vector<int*> changeAddrList = {
    (int*)0x4F6DCFE3DC ,
    // more addresses to change ...
};

// ...

for(auto addr : changeAddrList)
{
    WriteProcessMemory(handle, (LPVOID)addr , &newValue ,
                       sizeof(newValue), 0);
}

1在另一个进程中摆弄内存很容易出错,并可能导致各种意外行为!
您的代码可能会在该程序的较新版本中失败,您正在尝试应用您的作弊代码。

【讨论】:

  • 自 C++11 起您可以使用 for(auto&amp; it : changeMap) 作为语法糖
  • @Garmekain 当然!我不想过分强调这一点。我很确定 OP 足以消化我的答案;-)。
  • 你给出的答案并不难“消化”或任何你想称之为的。
  • @LEXERA.EXE 好吧,如果这能解决您的问题,那么您可以简单地接受它。还是我误解了你的问题?
  • 误会*。希望它确实解决了我的问题。干活。
猜你喜欢
  • 2010-11-01
  • 1970-01-01
  • 2012-01-05
  • 2010-09-12
  • 2021-10-28
  • 2013-12-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多