[英]Simple ReadProcessMemory not working
I googled a bit but can't seem to make this work.我用谷歌搜索了一下,但似乎无法完成这项工作。
privileges();
int pid = getPid("test.exe");
cout << "Process ID :" << pid << endl;
const char* prename;
HANDLE pHandle = OpenProcess(PROCESS_VM_READ , FALSE, pid);
if (pHandle)
{
cout << "Handle Open Success" << endl;
//SIZE_T bytesRead;
if (ReadProcessMemory(pHandle, (void*)0x013831BC, &prename, strlen(prename), NULL))
{
cout << "Read Success" << endl;
cout << prename << endl;
}
else
cout << GetLastError() << endl;
}
return 0;
It prints "Read Success" but does not print the variable just blank.它打印“读取成功”,但不会将变量打印为空白。 The address(address of a string in another process) I got is from ollydbg and verified it using a function as well.我得到的地址(另一个进程中字符串的地址)来自 ollydbg 并使用函数对其进行了验证。
I also wanted to replace the string using writeprocessmemory but before i get to that i needed to make sure reading is correct.我还想使用 writeprocessmemory 替换字符串,但在此之前我需要确保读取正确。
Any idea?任何的想法?
Your problem lies here:你的问题在这里:
const char* prename;
ReadProcessMemory(pHandle, (void*)0x013831BC, &prename, strlen(prename), NULL)
Your char pointer is not initialized and neither is the random memory it points to.您的 char 指针未初始化,它指向的随机内存也未初始化。 When you call strlen on it, it's trying to get the length of a random memory location.当您对其调用 strlen 时,它会尝试获取随机内存位置的长度。
Secondly you're using the address of the pointer &prename
, that's the address of the pointer not the char array it should point to.其次,您使用的是指针的地址&prename
,这是指针的地址,而不是它应该指向的字符数组。
To fix do it like this:要修复这样做:
char prename[100];
ReadProcessMemory(pHandle, (void*)0x013831BC, &prename, sizeof(prename), NULL)
sizeof() will return 100, so you will be reading 100 bytes of memory sizeof() 将返回 100,因此您将读取 100 字节的内存
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.