问题描述
刚刚粘贴了必要的内容,即使我的日志显示 WriteProcessMemory() 成功,也没有写入内存地址.另外,我已经仔细检查过我也有正确的内存地址.感谢您的帮助.
Just pasted what was necessary, the memory addresses aren't being written to even though my logging shows that WriteProcessMemory() was successful. Also, I've double checked that i have the correct memory addresses as well. Thank You for help.
char* offsets[][3] = {
{ "0x3E264", "0", "char[1]" },
{ "0x45848", "Auto-Mine", "char[10]" },
{ "0x458C0", "Auto-Build", "char[10]" },
//to be continued...
};
HANDLE scHandle = OpenProcess(PROCESS_VM_WRITE | PROCESS_VM_OPERATION, FALSE, ID);
if (scHandle == NULL) {
log << "ERROR: OpenProcess() returned " << GetLastError() << endl;
return false;
}
DWORD bytesOut;
for (int a = 0; a < 9; a++) {
if (WriteProcessMemory(scHandle, (LPVOID)(wDetectorBaseAddress + (int)strtol(offsets[a][0], NULL, 0)), offsets[a][1], strlen(offsets[a][1]) + 1, &bytesOut))
{
log << "WriteProcessMemory() to address " << wDetectorBaseAddress << " + " << (int)strtol(offsets[a][0], NULL, 0) << " = " << wDetectorBaseAddress + (int)strtol(offsets[a][0], NULL, 0) << " with '" << offsets[a][1] << "'; " << bytesOut << " bytes were written" << endl;
}
else
{
log << "ERROR: WriteProcessMemory() returned " << GetLastError() << endl;
return false;
}
}
CloseHandle(scHandle);
推荐答案
在写入进程内存之前,您需要使用 PAGE_EXECUTE_READWRITE
调用 VirtualProtect
.写入后需要恢复原来的保护.
You need to call VirtualProtect
with PAGE_EXECUTE_READWRITE
before you can write to the process's memory. After writing, you need to restore the original protection.
另一件事是,您究竟是如何知道这些地址始终相同的?你能确认它永远不会改变吗?
Another thing is, how exactly do you know those addresses are always the same? Can you confirm that it never changes?
注意:您可能还必须在写入后调用 FlushInstructionCache
.
Note: You MIGHT also have to call FlushInstructionCache
after writing.
这篇关于写进程内存 C++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!