error: ‘struct pt_regs’ has no member named ‘ARM_sp’

1.4k Views Asked by At

I wrote codes below and included asm/ptrace.h, compiled codes with GCC in linux, the compiler told

‘struct pt_regs’ has no member named ‘ARM_sp’

What can I do to solve this problem?

#include <asm/ptrace.h>
extern struct pt_regs saved_regs;
//...
uint32_t * inject_so_of(pid_t pid,const char *so_path)
{
    struct pt_regs regs;
    memcpy(&regs,&saved_regs,sizeof(regs));
    ptrace_readdata(pid,(void *)regs.ARM_sp,(void *)sbuf, sizeof(sbuf));
    ptrace_writedata(pid,(void *)regs.ARM_sp,(void *)so_path,strlen(so_path));
    uint32_t parameters[2];
    parameters[0] = regs.ARM_sp;
    parameters[1] = RTLD_NOW;
    if(ptrace_call(pid,find_dlopen_addr(pid),parameters,2,&regs) == -1)
    {
        DPRINTF("dlopen_error");
    }
    ptrace_getregs(pid,&regs);
    uint32_t r0 = regs.ARM_r0;
    DPRINTF("[+2]\t");
    ptrace_setregs(pid,&saved_regs);
    ptrace_writedata(pid,(uint8_t *)saved_regs.ARM_sp,(uint8_t *) sbuf,sizeof(sbuf));
    ptrace_detach(pid);
    return (uint32_t *) r0;
}
//...

The definition of pt_regs in asm/ptrace.h is:

struct pt_regs
{
    long uregs[18];
};

#define ARM_cpsr uregs[16]
#define ARM_pc uregs[15]
#define ARM_lr uregs[14]
/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
#define ARM_sp uregs[13]
#define ARM_ip uregs[12]
#define ARM_fp uregs[11]
#define ARM_r10 uregs[10]

I am getting the following errors:

AndroidInjectSo.c:149:38: error: ‘struct pt_regs’ has no member named ‘ARM_sp’
 ptrace_writedata(pid,(void *)regs.ARM_sp,(void *)so_path,strlen(so_path));
                                  ^
AndroidInjectSo.c:151:25: error: ‘struct pt_regs’ has no member named ‘ARM_sp’
 parameters[0] = regs.ARM_sp;
                     ^
AndroidInjectSo.c:158:23: error: ‘struct pt_regs’ has no member named ‘ARM_r0’
 uint32_t r0 = regs.ARM_r0;
                   ^
AndroidInjectSo.c:161:47: error: ‘struct pt_regs’ has no member named ‘ARM_sp’
 ptrace_writedata(pid,(uint8_t *)saved_regs.ARM_sp,(uint8_t *) sbuf,sizeof(sbuf));
0

There are 0 best solutions below