C++ ReadProcessMemory into byte array

半城伤御伤魂 提交于 2019-12-25 02:19:53

问题


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;
}

Any help would be appreciated.


回答1:


Shouldn't it be

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

? 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.



来源:https://stackoverflow.com/questions/7688462/c-readprocessmemory-into-byte-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!