我正在使用ptrace(PTRACE_POKETEXT, pid, addr, (orig^flip_mask));
以更改實時進程的數據,但只要呼叫終止,所做的更改就會消失,是否可以保留PTRACE_POKETEXT
即使在終止ptrace
呼叫之後仍會永久更改?保存ptrace()的更改PTRACE_POKEDATA調用
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);
}
更改不應該消失。 – Barmar
它會消失的唯一原因是因爲您戳的過程重新分配了變量。你將不得不改變流程的代碼來防止這種情況發生。 – Barmar
你可以顯示你正在追蹤的過程的代碼以及你如何使用'ptrace'? – Barmar