【问题标题】:Read text from notepad process memory [closed]从记事本进程内存中读取文本[关闭]
【发布时间】: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


【解决方案1】:

你不能写这样的缓冲区。 C++ 假定它包含一个以 0 结尾的字符串。

试试

out.write(buffer, bytes_to_read);

同时打开带有标志的文件

ios::binary | ios::out

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-14
    • 2011-04-27
    • 1970-01-01
    • 1970-01-01
    • 2012-12-03
    • 2012-05-10
    • 2013-09-29
    相关资源
    最近更新 更多