gpt4 book ai didi

c++ - WriteProcessMemory C++

转载 作者:行者123 更新时间:2023-11-28 02:59:53 29 4
gpt4 key购买 nike

只是粘贴了必要的内容,即使我的日志显示 WriteProcessMemory() 成功,内存地址也没有被写入。另外,我已经仔细检查了我是否也有正确的内存地址。谢谢你的帮助。

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。写入后需要恢复原来的保护。

另一件事是,您究竟如何知道这些地址始终相同?你能确认它永远不会改变吗?

注意:您可能还必须在写入后调用 FlushInstructionCache

关于c++ - WriteProcessMemory C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21083441/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com