<分区>
我知道以下事情:
/proc/$pid/mem (memory struct of this program)
/proc/$pid/maps
通常,我使用gdb,例如:
$ gdb --pid [pid]
(gdb) set {int}0x83040 = 4
起初,我猜可能是 gdb 打开了/proc/$pid/mem 文件并更新了它, 所以我做了一个测试...我使用具有 sudo 权限的 vim 打开这个文件,但我仍然无法更新/proc/$pid/men 文件。
谁能告诉我如何在 Linux 运行时更新另一个程序的内存?我可以更新系统的哪个文件?
我的 ptrace 代码:
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
int main()
{
int pid = 23587;
// int ret = ptrace(PTRACE_SEIZE, pid, NULL, NULL); // or PTRACE_SEIZE if you don't want to suspend the process
// printf("%d\n", ret);
int data = 100;
int res = ptrace(PTRACE_POKEDATA, pid, 999999, &data);
printf("%d\n", res);
printf("123\n");
perror("Error: ");
return 0;
}
但是我收到消息了
$ sudo ./aa
-1
123
Error: : No such process