C ++ ReadProcessMemory放入字节数组 [英] C++ ReadProcessMemory into byte array

查看:267
本文介绍了C ++ ReadProcessMemory放入字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ReadProcessMemory将动态量的字节读取到数组中,然后将其返回.我根本无法正常工作.我当前的代码是...

I'm attempting to use ReadProcessMemory to read a dynamic amount of bytes into an array and then return it. I simply can't get it to work properly. My current code is...

byte *Application::readMemory(DWORD address, int length) {
    byte *buffer = new byte[length];
    SIZE_T bytesRead;
    ReadProcessMemory(piProcessInfo.hProcess, (void *)address, &buffer, length, &bytesRead);
    return buffer;
}

任何帮助将不胜感激.

推荐答案

应该不是

   ReadProcessMemory(piProcessInfo.hProcess, (void *)address, buffer, length, &bytesRead);

?如果将缓冲区指针地址作为输入参数,则ReadProcessMemory会将其复制到缓冲区指针所在的位置(不是缓冲区,而是可变或超出缓冲区指针的位置)-并认为它在堆栈上,堆栈会损坏.

? If you give buffer-pointer address as input parameter, then ReadProcessMemory copies it where buffer pointer lies (not to the buffer but into buffer pointer vatiable and beyond) - and sice it is on the stack, stack gets corrupted.

这篇关于C ++ ReadProcessMemory放入字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆