문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top