【发布时间】:2017-04-09 00:52:00
【问题描述】:
我正在使用ptrace(PTRACE_POKETEXT, pid, addr, (orig ^ flip_mask)); 来更改实时进程的数据,但是一旦调用终止,所做的更改就会消失,即使在终止之后也可以永久保留PTRACE_POKETEXT 更改ptrace 电话?
void run_pro1 (pid_t child_pid) {
srand(time(0));
int wait_status;
unsigned icounter = 0;
procmsg("debugger started\n");
wait(&wait_status);
while (WIFSTOPPED(wait_status)) {
icounter++;
struct user_regs_struct regs;
ptrace(PTRACE_GETREGS, child_pid, 0, ®s);
unsigned instr = ptrace(PTRACE_PEEKTEXT, child_pid, regs.rax , 0);
unsigned *instr3 ;
instr3 = &instr;
unsigned instr2 = instr ^ (1UL << (1 << (rand()%32)));
ptrace(PTRACE_POKETEXT, child_pid, instr, instr2);
unsigned *instr4 ;
instr4 = &instr2;
cout<<"addrctn="<< *instr3 <<endl;
cout<<"addrctn="<< *instr4 <<endl;
if (ptrace(PTRACE_SINGLESTEP, child_pid, 0, 0) < 0) {
perror("ptrace");
return;
} /* Wait for child to stop on its next instruction */
ptrace(PTRACE_CONT, child_pid, 0, 0);
wait(&wait_status); //break;
}
procmsg("the child executed %u instructions\n", icounter);
}
【问题讨论】:
-
更改不应消失。
-
它消失的唯一原因是您戳的过程重新分配了变量。您必须更改该过程的代码以防止这种情况发生。
-
您能否展示您正在跟踪的进程的代码以及您如何使用
ptrace? -
亲爱的 Barmar,非常感谢您的回复,我刚刚发布了跟踪子 pid 的跟踪器进程的代码
-
“永久”是什么意思?
标签: c++ operating-system ptrace