- 论坛徽章:
- 0
|
在/usr/include/asm/ptrace.h 中看到以下代码
- struct pt_regs {
- long uregs[18];
- };
- #define ARM_cpsr uregs[16]
- #define ARM_pc uregs[15]
- #define ARM_lr uregs[14]
- #define ARM_sp uregs[13]
- #define ARM_ip uregs[12]
- #define ARM_fp uregs[11]
- #define ARM_r10 uregs[10]
- #define ARM_r9 uregs[9]
- #define ARM_r8 uregs[8]
- #define ARM_r7 uregs[7]
- #define ARM_r6 uregs[6]
- #define ARM_r5 uregs[5]
- #define ARM_r4 uregs[4]
- #define ARM_r3 uregs[3]
- #define ARM_r2 uregs[2]
- #define ARM_r1 uregs[1]
- #define ARM_r0 uregs[0]
复制代码 然后我希望使用x86上的方式获得CPU寄存器值
- int main(int argc, char *argv[])
- {
- pid_t traced_process;
- struct pt_regs regs;
- long ins;
- if ( argc != 2 ) {
- printf("Usage: %s <pid to be traced>", argv[0]);
- exit(1);
- }
- traced_process = atoi(argv[1]);
- ptrace(PTRACE_ATTACH, traced_process, NULL, NULL);
- wait(NULL);
- ptrace(PTRACE_GETREGS, traced_process, NULL, ®s);
- ins = ptrace(PTRACE_PEEKTEXT, traced_process,
- regs.ARM_ip, NULL);
- printf("EIP: %lx Instructions executed: %lx\n", regs.ARM_ip, ins);
- ptrace(PTRACE_DETACH, traced_process, NULL, NULL);
- return 0;
- }
复制代码 但是实际执行的时候,输出
EIP: 0 Instructions executed: ffffffff
如何达到我想要的目的。谢谢指教 |
|