我写了这段代码来更改选定进程的十六进制转储,这是代码:
#include <windows.h>
int main(int argc, char *argv[])
{
unsigned char buffer[5];
int i;
unsigned char patchbytes[5] = { 0xCC, 0xCC, 0xCC, 0xCC, 0xCC};
DWORD pid = atoi(argv[1]);
HANDLE hproc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if (!hproc)
{
printf("open failed\n");
return -1;
}
ReadProcessMemory(hproc, (void*)0x77992FF5, buffer, 5, NULL);
printf("Before:\n");
for (i = 0; i < sizeof(patchbytes); i++) {
printf("%02x \t", buffer[i]);
}
printf("\n");
WriteProcessMemory(hproc, (void*)0x77992FF5, patchbytes, 5, NULL);
printf("After:\n");
for (i = 0; i < sizeof(patchbytes); i++) {
printf("%02x \t", buffer[i]);
}
FlushInstructionCache(hproc, NULL, 0);
CloseHandle(hproc);
return 0;
}
因此,我读取了前五个字节,然后将其覆盖,在覆盖它们之前和之后检查字节的值。但这给了我相同的东西,所以字节没有变化。我在做什么错了?
答案 0 :(得分:2)
您只需将最初读取的缓冲区打印两次。
在ReadProcessMemory(hproc, (void*)0x77992FF5, buffer, 5, NULL);
之后再掷另一个WriteProcessMemory
。