【发布时间】:2013-12-25 22:33:00
【问题描述】:
我想读取记事本的整个内存,并将输出写入文本文件。 如果我在记事本中输入内容,我在输出中找不到我输入的内容。 这是代码:
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID);
char* ptr = 0;
MEMORY_BASIC_INFORMATION info;
while(ptr<=(char*)0x7FFF0000)
{
VirtualQueryEx(hProcess,(LPCVOID)ptr,&info,sizeof(info));
if((info.AllocationProtect==0x04) || (info.AllocationProtect==0x10) ||
(info.AllocationProtect==0x20) || (info.AllocationProtect==0x40) ||
(info.AllocationProtect==0x80) || (info.AllocationProtect==0x02) ||
(info.AllocationProtect==0x08))
{
int bytes_to_read = (int)info.RegionSize;
char *buffer = NULL;
buffer = (char *)malloc(info.RegionSize);
ReadProcessMemory(hProcess,
info.BaseAddress,
&buffer,
bytes_to_read,
NULL);
ofstream out;
out.open("test.txt",ios_base::app);
out << buffer;
out.close();
}
ptr += info.RegionSize;
}
【问题讨论】:
-
AllocationProtect 是一个位掩码。这不适用于 64 位版本的 Windows。缓冲区不指向 C 字符串。解决这些问题似乎毫无意义。
标签: c++ windows memory notepad