使用WriteProcessMemory函数向指定进程写入数据
成功写入数据到进程 AA = 170 读取了1字节
源码
#include
#include
int main(int argc, PCHAR argv[]){
HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, 23548);
if (handle == NULL){
printf("打开进程失败\n");
}
printf("打开进程成功,句柄为:%p\n", handle);
LPSTR buffer = 0;
BYTE wb[5] = { 0xaa, 0xaa, 0xaa, 0xa1,0x00 };
BYTE cd[4] = { 0 };
DWORD i = 0;
DWORD newprot, oldprot;
VirtualProtectEx(handle, (LPVOID)0x0040008, 4, PAGE_EXECUTE_READWRITE, &oldprot);
if (!ReadProcessMemory(handle, (LPVOID)0x0040008, &buffer, 4, &i)){
printf("读取进程内存失败 %d %d\n", GetLastError(), i);
}
printf("读取到的进程内存信息为: %p 读取数量 %d\n", buffer, i);
if (!WriteProcessMemory(handle, (LPVOID)0x0040008, wb, 4, &i)){
printf("写入进程内存失败 %d %d\n", GetLastError(), i);
}
printf("写入到的进程内存信息为: %d 写入数量 %d\n", wb[0], i);
VirtualProtectEx(handle, (LPVOID)0x0040008, 4, oldprot, &newprot);
CloseHandle(handle);
getchar();
return 0;
}