static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { RIODesc *ret = NULL; RIOMach *riom; const char *pidfile; char *pidpath, *endptr; int pid; task_t task; if (!__plugin_open (io, file, 0)) { return NULL; } pidfile = file + (file[0] == 'a' ? 9 : 7); pid = (int)strtol (pidfile, &endptr, 10); if (endptr == pidfile || pid < 0) { return NULL; } task = pid_to_task (pid); if (task == -1) { return NULL; } if (!task) { if (pid > 0 && io->referer && !strncmp (io->referer, "dbg://", 6)) { eprintf ("Child killed\n"); kill (pid, 9); } switch (errno) { case EPERM: eprintf ("Operation not permitted\n"); break; case EINVAL: perror ("ptrace: Cannot attach"); eprintf ("Possibly unsigned r2. Please see doc/osx.md\n"); eprintf ("ERRNO: %d (EINVAL)\n", errno); break; default: eprintf ("unknown error in debug_attach\n"); break; } return NULL; } riom = R_NEW0 (RIOMach); riom->pid = pid; riom->task = task; // sleep 1s to get proper path (program name instead of ls) (racy) pidpath = pid ? r_sys_pid_to_path (pid) : strdup ("kernel"); ret = r_io_desc_new (&r_io_plugin_mach, riom->pid, pidpath, rw | R_IO_EXEC, mode, riom); free (pidpath); return ret; }
static RIODesc *__open(struct r_io_t *io, const char *file, int rw, int mode) { if (__plugin_open (io, file, 0)) { char *pidpath; RIOW32Dbg *dbg = R_NEW (RIOW32Dbg); if (dbg == NULL) return NULL; dbg->pid = atoi (file+9); if (__attach (dbg) == -1) { free (dbg); return NULL; } pidpath = r_sys_pid_to_path (dbg->pid); RETURN_IO_DESC_NEW (&r_io_plugin_w32dbg, -1, pidpath, rw | R_IO_EXEC, mode, dbg); } return NULL; }
static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { RIODesc *ret = NULL; RIOMach *riom; const char *pidfile; char *pidpath; int pid; task_t task; if (!__plugin_open (io, file, 0)) return NULL; pidfile = file+(file[0]=='a'?9:7); if (!strcmp (pidfile, "0")) { /* tfp0 */ pid = 0; } else { pid = atoi (pidfile); if (pid<1) return NULL; } task = debug_attach (pid); if ((int)task == -1) { switch (errno) { case EPERM: eprintf ("Operation not permitted\n"); break; case EINVAL: perror ("ptrace: Cannot attach"); eprintf ("ERRNO: %d (EINVAL)\n", errno); break; default: eprintf ("unknown error in debug_attach\n"); break; } return NULL; } riom = R_NEW0 (RIOMach); riom->pid = pid; riom->task = task; // sleep 1s to get proper path (program name instead of ls) (racy) pidpath = r_sys_pid_to_path (pid); ret = r_io_desc_new (&r_io_plugin_mach, riom->pid, pidpath, rw | R_IO_EXEC, mode, riom); free (pidpath); return ret; }
static RIODesc *__open(struct r_io_t *io, const char *file, int rw, int mode) { char *pidpath; int ret = -1; if (__plugin_open (io, file,0)) { int pid = atoi (file+9); ret = ptrace (PTRACE_ATTACH, pid, 0, 0); if (file[0]=='p') //ptrace ret = 0; else if (ret == -1) { #ifdef __ANDROID__ eprintf ("ptrace_attach: Operation not permitted\n"); #else switch (errno) { case EPERM: ret = pid; eprintf ("ptrace_attach: Operation not permitted\n"); break; case EINVAL: perror ("ptrace: Cannot attach"); eprintf ("ERRNO: %d (EINVAL)\n", errno); break; } #endif } else if (__waitpid (pid)) ret = pid; else eprintf ("Error in waitpid\n"); if (ret != -1) { RIODesc *desc; RIOPtrace *riop = R_NEW (RIOPtrace); riop->pid = riop->tid = pid; open_pidmem (riop); pidpath = r_sys_pid_to_path (pid); desc = r_io_desc_new (&r_io_plugin_ptrace, pid, pidpath, R_TRUE, mode, riop); free (pidpath); return desc; } } return NULL; }
static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { if (__plugin_open (io, file, 0)) { char *pidpath; RIODesc *ret; RIOW32Dbg *dbg = R_NEW0 (RIOW32Dbg); if (!dbg) { return NULL; } dbg->pid = atoi (file + 9); if (__open_proc (dbg, !strncmp (file, "attach://", 9)) == -1) { free (dbg); return NULL; } pidpath = r_sys_pid_to_path (dbg->pid); ret = r_io_desc_new (io, &r_io_plugin_w32dbg, file, rw | R_PERM_X, mode, dbg); ret->name = pidpath; return ret; } return NULL; }
static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { RIODesc *ret = NULL; RIOMach *riom = NULL; const char *pidfile; char *pidpath, *endptr; int pid; task_t task; if (!__plugin_open (io, file, false) && !__plugin_open (io, (const char *)&file[1], false)) { return NULL; } pidfile = file + (file[0] == 'a' ? 9 : (file[0] == 's' ? 8 : 7)); pid = (int)strtol (pidfile, &endptr, 10); if (endptr == pidfile || pid < 0) { return NULL; } task = pid_to_task (NULL, pid); if (task == -1) { return NULL; } if (!task) { if (pid > 0 && !strncmp (file, "smach://", 8)) { kill (pid, SIGKILL); eprintf ("Child killed\n"); } #if 0 /* this is broken, referer gets set in the riodesc after this function returns the riodesc * the pid > 0 check doesn't seem to be reasonable to me too * what was this intended to check anyway ? */ if (pid > 0 && io->referer && !strncmp (io->referer, "dbg://", 6)) { eprintf ("Child killed\n"); kill (pid, SIGKILL); } #endif switch (errno) { case EPERM: eprintf ("Operation not permitted\n"); break; case EINVAL: perror ("ptrace: Cannot attach"); eprintf ("Possibly unsigned r2. Please see doc/macos.md\n"); eprintf ("ERRNO: %d (EINVAL)\n", errno); break; default: eprintf ("unknown error in debug_attach\n"); break; } return NULL; } RIODescData *iodd = R_NEW0 (RIODescData); if (iodd) { iodd->pid = pid; iodd->tid = pid; iodd->data = NULL; } riom = R_NEW0 (RIOMach); if (!riom) { return NULL; } riom->task = task; iodd->magic = r_str_hash ("mach"); iodd->data = riom; // sleep 1s to get proper path (program name instead of ls) (racy) pidpath = pid ? r_sys_pid_to_path (pid) : strdup ("kernel"); if (!strncmp (file, "smach://", 8)) { ret = r_io_desc_new (io, &r_io_plugin_mach, &file[1], rw | R_PERM_X, mode, iodd); } else { ret = r_io_desc_new (io, &r_io_plugin_mach, file, rw | R_PERM_X, mode, iodd); } ret->name = pidpath; return ret; }