稍微了解了一些Windows平台外挂的相关知识,内存写出函数当然必不可少。
- void writeMemory(void* value, DWORD valueSize, ...) {
- if (g_process == nullptr)
- return;
- DWORD tempValue = 0;
-
- va_list addresses;
- va_start(addresses, valueSize);
- DWORD offset = 0;
- DWORD lastAddress = 0;
- while ((offset = va_arg(addresses, DWORD)) != -1) {
- lastAddress = tempValue + offset;
- ReadProcessMemory(g_process, (LPCVOID)lastAddress, &tempValue, sizeof(DWORD), NULL);
- }
- va_end(addresses);
- WriteProcessMemory(g_process, (LPVOID)lastAddress, value, valueSize, NULL);
- }
-
- void writeMemory(void* value, DWORD valueSize, DWORD address) {
- writeMemory(value, valueSize, address, -1);
- }
有两个重载函数,第一个可传入地址链,然后写目标地址写入(void*)字节数组。
第二个无需地址链,直接向绝对路径写字节数组。
调用示例:
- BYTE h[] = { 0x00, 0x01, 0x02 };
- writeMemory(h, sizeof(h), 0x205310F);