在Linux上运行时,我可以修改程序的内存吗?

时间:2016-02-26 02:32:43

标签: linux memory

我知道以下事情:

/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

1 个答案:

答案 0 :(得分:1)

您可以使用ptrace()系统调用。

ObservableCollections
相关问题