ptrace(PTRACE_ATTACH, pid, 0, 0) error: cannot atttach to pid

1k views Asked by At

i am trying to inject a library in android using PTRACE but when i try to attach ptrace to specific pid for monitoring got an error/; "Cannot attach to pid"... Here is the code

// Attach 
    if (0 > ptrace(PTRACE_ATTACH, pid, 0, 0)) {
        printf("cannot attach to %d, error!\n", pid);
        exit(1);
    }
    waitpid(pid, NULL, 0);

i want to know why ptrace() is returning value less than zero causing error.... what should be returned by the ptrace() function to execute normally(error free)

1

There are 1 answers

0
Mark Segal On

In Android, to attach to a process which isn't your child and does not have the same UID as you do, you have to be root or have the appropriate capability.