gpt4 book ai didi

c++ - 如何找到数据在内存中的地址?

转载 作者:太空宇宙 更新时间:2023-11-03 10:21:45 24 4
gpt4 key购买 nike

我需要找到一种方法来找到另一个程序的地址值。我事先找到了地址,但我不知道如何在关闭并重新打开程序后再次找到它们而无需再次搜索它们(我需要程序自己找到它们)。任何人都知道我该怎么做(对不起,如果我不清楚我真的不知道如何解释)如果你感到困惑,就问我,我会尽量弄清楚

我正在使用 C++

最佳答案

假设您的平台是 Windows,我发现将您自己的 DLL 注入(inject)目标进程很方便。从那里,您可以进行堆遍历并寻找值(value)。在你得到它之后,通过 IPC 将它发送回你的进程(例如,使用 Boost 的 message_queue)。

编辑

Blood,正如您所要求的,这里有一些代码和一个值得深思的地方。 DLL 本身非常简单,例如如下所示:


#include <Windows.h>

/** You can use this one to examine the given memory blocks.
* However, since you're inside another process, you cannot use
* std::cout. But you'll get the idea (just an example). The code
* is from my another project.
*/
void MyDump(const void *m, unsigned int n)
{
const unsigned char *p = reinterpret_cast<const unsigned char *>(m);
char buffer[16];
unsigned int mod = 1;

memset(&buffer, 0, sizeof(buffer));

std::cout << "------------------------------------------------------------------------------------\nOffset | Hex | ASCII |\n------------------------------------------------------------------------------------\n0x" << std::setfill('0') << std::setw(8) << std::hex << (long)m << " |";

for (unsigned int i = 0; i < n; ++i, ++mod) {
buffer[i % 16] = p[i];

--mod;

if (mod % 4 == 0)
std::cout << " ";

++mod;

std::cout << std::setw(2) << std::hex << static_cast<unsigned int>(p[i]) << " ";

if ((mod == 16 && i != 0) || i == n - 1) {
if (i == n - 1) {
for (unsigned int j = 0; j < (16 - mod) * 3; ++j)
std::cout << " ";

if (mod <= 4)
std::cout << " ";

if (mod <= 8)
std::cout << " ";

if (mod <= 12)
std::cout << " ";
}

mod = 0;

std::cout << "| ";

for (unsigned short j = 0; j < 16; ++j) {
switch (buffer[j]) {
case 0x7:
case 0x8:
case 0x9:
case 0xa:
case 0xb:
case 0xd:
case 0xe:
case 0xf:
std::cout << " ";

break;

default: std::cout << buffer[j];
}
}

std::cout << " |";

if (i == n - 1) {
std::cout << "\n------------------------------------------------------------------------------------\n";

return;
}

memset(&buffer, 0, sizeof(buffer));

std::cout << "\n0x" << std::setfill('0') << std::setw(8) << std::hex << (long)m + i << " |";
}
}
}

BOOL APIENTRY DllMain(HANDLE h_module, DWORD ul_reason_for_call, LPVOID)
{
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
/** Do the heap walk here, please see
* http://msdn.microsoft.com/en-us/library/ee175819%28v=VS.85%29.aspx
* for enumerating the heap.
*/

break;

case DLL_THREAD_ATTACH: break;

case DLL_THREAD_DETACH: break;

case DLL_PROCESS_DETACH:
}
}

既然您已经有了 DLL,您仍然需要将它注入(inject)到所需的进程中。这可以通过 EasyHook 轻松完成。应用程序接口(interface)。下载库并查看非托管 Hook 的示例。

关于c++ - 如何找到数据在内存中的地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2612304/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com