0
请任何人告诉我,为什么下面的代码不能在64位linux上工作 父进程会改变tchild中的数据值,通过ptrace.initially子进程正常执行,并通过信号挂起进程并更改tchild程序中的数据。ptrace在64位不工作
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <sys/ptrace.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>
#include <wait.h>
#include <linux/user.h>
int main()
{
struct user_regs_struct regs;
int pid, status; /* process id & status */
pid = fork(); /* create new process */
int data;
if(pid == 0) {
ptrace(PTRACE_TRACEME, 0, 0, 0);
if(execl("/home/neeraj/neerajgit/ptrace/tchild", "tchild", 0) == -1)
{
fprintf(stderr, "exec err \n"); /* err msg */
exit(EXIT_FAILURE);
}
}
else if(pid < 0) {
fprintf(stderr, "fork err\n");
}
else {
wait(&status);
if(WIFSTOPPED(status)) { printf("child stopped \n"); }
printf("parent start\n");
kill(pid, SIGSTOP);
data = ptrace(PTRACE_GETREGS, pid, 0,®s); printf("%d\n", data);
data = 30;
ptrace(PTRACE_POKEDATA, pid, 201010 + 8 , &data);
ptrace(PTRACE_PEEKDATA, pid, 201010 + 8, NULL); printf("%d\n", data);
printf("child started\n");
printf("%ld \n", regs.rbx);
ptrace(PTRACE_CONT, pid, 0, 0);
sleep(5);
}
this is the tchild program
#include <stdio.h>
#include <sys/ptrace.h>
int data;
data = 20; /* tchild main */
int main()
{ printf("child started \n");
while(data != 30) ;
printf("child stopped %d\n", data);
}
(1)您如何知道变量'data'在子进程中的地址为'201010 + 8'? (2)编译'tchild'时,编译器有权假定'data'永远不会改变。我敢打赌,如果你将程序集转储为'tchild',你将会看到一个无条件的无限循环,甚至不会看'数据'。 – zwol
(3)与'ptrace'有关的一切都是[黑色艺术](http://www.jargon.net/jargonfile/b/blackart.html)。你有没有其他的方法来实现你的更大目标? – zwol