问题
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