frida / frida-core

Frida core library intended for static linking into bindings
https://frida.re
Other
592 stars 187 forks source link

frida inject can't properly handle a program that is in the STOP state, even if the program resumes after injection. #493

Open nj00001 opened 7 months ago

nj00001 commented 7 months ago

Check out the code example below

#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <errno.h>

int main(){

    pid_t pid = getpid();

    printf("entry %d\n", pid);

    kill(pid, SIGSTOP);

    printf("leave\n");

}

When a process receives a SIGSTOP signal, it enters a suspended state, and if you use frida to inject into the process, the js code injected into the process does not seem to be executed. If you add a sleep function to the end of the above code, then you will receive Unexpectedly timed out while waiting for signal from process with PID 23551

xgloom commented 1 week ago

I ran into this as well. I wanted to suspend a program and attach Frida to it. Raising a SIGSTOP indeed didn't allow Frida to attach to it.

For my use case, I solved this by instead doing read from a fd (e.g. a FIFO file). This blocks the calling thread until it reads the input. This allowed me to attach Frida to the process and let it resume when I want by writing to that FIFO file (unblocking the thread).