Fix the r2 -d oo issue with more referer fields

This commit is contained in:
pancake 2014-11-04 10:30:28 +01:00
parent 83ad35e39a
commit 1eccc191e0
4 changed files with 25 additions and 11 deletions

View File

@ -415,6 +415,7 @@ static RBinReloc *reloc_convert(struct Elf_(r_bin_elf_obj_t) *bin, RBinElfReloc
case R_X86_64_8: ADD(8, 0);
case R_X86_64_PC8: ADD(8, -P);
case R_X86_64_GOTPCREL: ADD(64, GOT-P);
case R_X86_64_COPY: ADD(64, 0); // XXX: copy symbol at runtime
default: eprintf("TODO(eddyb): uninmplemented ELF/x64 reloc type %i\n", rel->type);
}
break;

View File

@ -118,6 +118,7 @@ typedef struct r_io_t {
int raised;
int va;
int raw;
char *referer;
char *redirect;
/* write mask */
void (*printf)(const char *str, ...);

View File

@ -5,7 +5,9 @@
#include <r_util.h>
#include <r_debug.h> /* only used for BSD PTRACE redefinitions */
static void my_io_redirect (RIO *io, const char *file) {
static void my_io_redirect (RIO *io, const char *ref, const char *file) {
free (io->referer);
io->referer = ref? strdup (ref): NULL;
free (io->redirect);
io->redirect = file? strdup (file): NULL;
}
@ -262,14 +264,14 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
// TODO: use io_procpid here? faster or what?
sprintf (uri, "ptrace://%d", pid);
#endif
my_io_redirect (io, uri);
my_io_redirect (io, file, uri);
} else {
sprintf (uri, "attach://%d", pid);
my_io_redirect (io, uri);
my_io_redirect (io, file, uri);
}
return NULL;
}
my_io_redirect (io, NULL);
my_io_redirect (io, file, NULL);
return NULL;
}

View File

@ -158,7 +158,6 @@ static int __plugin_open(RIO *io, const char *file, ut8 many) {
}
static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
char *pidpath;
int ret = -1;
if (__plugin_open (io, file,0)) {
int pid = atoi (file+9);
@ -188,12 +187,23 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
RIOPtrace *riop = R_NEW0 (RIOPtrace);
riop->pid = riop->tid = pid;
open_pidmem (riop);
pidpath = r_sys_pid_to_path (pid);
// sleep 1s to get proper path (racy)
//r_sys_sleep (1);
desc = r_io_desc_new (&r_io_plugin_ptrace, pid,
pidpath, rw | R_IO_EXEC, mode, riop);
free (pidpath);
{
char *pidpath = NULL;
if (io->referer && !strncmp (io->referer, "dbg://", 6)) {
// if it's a pid attach try to resolve real path
if (atoi (io->referer+6)) {
pidpath = r_sys_pid_to_path (pid);
eprintf ("PIDPATH: %s\n", pidpath);
}
}
if (!pidpath) {
pidpath = strdup (file);
}
desc = r_io_desc_new (&r_io_plugin_ptrace, pid,
pidpath, rw | R_IO_EXEC, mode, riop);
free (pidpath);
}
return desc;
}
}