ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Hi, I'm developing an application that access the procfs and then
read/write /proc/<PID>/mem of a process to change the content of a file
owned by that process.
The sequential steps performed by the application are the followings:
1) catch, by using ptrace, of the "read" system call
2) read the file content directly on /proc/PID/mem
3) modify this content
4) write back the modified content on /proc/PD/mem
The problem is that it returns "Error 22 Invalid argument" every time
it tries to read (or write) on procfs.
(I've already patched the kernel to allow read/write operation on
/proc/<pid>/mem and I've tried the pread/pwrite functions, but they
have the same behavior).
// traced_proc is the pid_t of the traced process
// get number of bytes to read
eax_reg = ptrace(PTRACE_PEEKUSER, traced_proc, 4*EAX, NULL);
// get traced process space buffer
ecx_reg = ptrace(PTRACE_PEEKUSER, traced_proc, 4*ECX, NULL);
eax_reg is initialized to 0 before the "char orig_buf[eax_reg+1];" line (the code that I reported here is only an extract of the actual application, sorry for the misunderstanding...).
eax_reg is initialized to 0 before the "char orig_buf[eax_reg+1];" line (the code that I reported here is only an extract of the actual application, sorry for the misunderstanding...).
You are still probably smashing your stack variables with the memset, because the value of eax_reg is non-zero in the memset.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.