Linux ptrace() read whole memory page

假装没事ソ 提交于 2021-02-08 10:44:46

问题


Hello I try to dump the memory of a process in Android/Linux. Right now I read the memory maps to get a memory region's address space and then I read every single word like this:

ptrace(PTRACE_ATTACH, pid, NULL, NULL);
wait(NULL);

read each word in this memory region:
word = ptrace(PTRACE_PEEKDATA, pid, (void *)address, NULL);

ptrace(PTRACE_CONT, pid, NULL, NULL);
ptrace(PTRACE_DETACH, pid, NULL, NULL);

Isn't there a more efficient solution reading directly a whole memory page by specifying the start/end of a memory address space to read?


回答1:


There are two possible ways to read memory more efficiently from another process.

If your kernel supports it (I have no idea about Android kernels) you can use process_vm_readv.

Another way is to open the /proc/.../mem file of the target process and read from it. gdb uses this method, though I think only because process_vm_readv is "new" (in gdb's terms).



来源:https://stackoverflow.com/questions/34433451/linux-ptrace-read-whole-memory-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!