diff --git a/libr/debug/debug.c b/libr/debug/debug.c index ca2823531d..f80464b26a 100644 --- a/libr/debug/debug.c +++ b/libr/debug/debug.c @@ -1530,7 +1530,8 @@ R_API ut64 r_debug_get_baddr(RDebug *dbg, const char *file) { return 0LL; } #if __WINDOWS__ - return r_io_desc_get_base (dbg->iob.io->desc); + ut64 base; + return r_io_desc_get_base (dbg->iob.io->desc, &base), base; #else r_debug_select (dbg, pid, tid); r_debug_map_sync (dbg); diff --git a/libr/include/r_io.h b/libr/include/r_io.h index f8172d4120..cf9940ad56 100644 --- a/libr/include/r_io.h +++ b/libr/include/r_io.h @@ -138,7 +138,7 @@ typedef struct r_io_plugin_t { bool (*is_blockdevice)(RIODesc *desc); int (*getpid)(RIODesc *desc); int (*gettid)(RIODesc *desc); - ut64 (*getbase)(RIODesc *desc); + bool (*getbase)(RIODesc *desc, ut64 *base); bool (*resize)(RIO *io, RIODesc *fd, ut64 size); int (*extend)(RIO *io, RIODesc *fd, ut64 size); bool (*accept)(RIO *io, RIODesc *desc, int fd); @@ -387,7 +387,7 @@ R_API bool r_io_desc_exchange (RIO *io, int fd, int fdx); //this should get 2 de R_API bool r_io_desc_is_dbg (RIODesc *desc); R_API int r_io_desc_get_pid (RIODesc *desc); R_API int r_io_desc_get_tid (RIODesc *desc); -R_API ut64 r_io_desc_get_base (RIODesc *desc); +R_API bool r_io_desc_get_base (RIODesc *desc, ut64 *base); R_API int r_io_desc_read_at (RIODesc *desc, ut64 addr, ut8 *buf, int len); R_API int r_io_desc_write_at (RIODesc *desc, ut64 addr, const ut8 *buf, int len); R_API bool r_io_desc_fini (RIO *io); @@ -458,7 +458,7 @@ R_API int r_io_fd_write_at (RIO *io, int fd, ut64 addr, const ut8 *buf, int len) R_API bool r_io_fd_is_dbg (RIO *io, int fd); R_API int r_io_fd_get_pid (RIO *io, int fd); R_API int r_io_fd_get_tid (RIO *io, int fd); -R_API int r_io_fd_get_base (RIO *io, int fd); +R_API bool r_io_fd_get_base (RIO *io, int fd, ut64 *base); R_API const char *r_io_fd_get_name (RIO *io, int fd); R_API int r_io_fd_get_current(RIO *io); R_API bool r_io_use_fd (RIO *io, int fd); diff --git a/libr/io/desc.c b/libr/io/desc.c index 92f3556bde..f81c081ca0 100644 --- a/libr/io/desc.c +++ b/libr/io/desc.c @@ -287,21 +287,11 @@ R_API int r_io_desc_get_tid(RIODesc *desc) { return desc->plugin->gettid (desc); } -R_API ut64 r_io_desc_get_base (RIODesc *desc) { - //-1 and -2 are reserved - if (!desc) { - return -3; +R_API bool r_io_desc_get_base (RIODesc *desc, ut64 *base) { + if (!base || !desc || !desc->plugin || !desc->plugin->isdbg || !desc->plugin->getbase) { + return false; } - if (!desc->plugin) { - return -4; - } - if (!desc->plugin->isdbg) { - return -5; - } - if (!desc->plugin->getbase) { - return -6; - } - return desc->plugin->getbase (desc); + return desc->plugin->getbase (desc, base); } R_API int r_io_desc_read_at(RIODesc *desc, ut64 addr, ut8 *buf, int len) { diff --git a/libr/io/fd.c b/libr/io/fd.c index 72259dce7e..b5fd0b0335 100644 --- a/libr/io/fd.c +++ b/libr/io/fd.c @@ -92,14 +92,15 @@ R_API int r_io_fd_get_tid(RIO *io, int fd) { return r_io_desc_get_tid (desc); } -R_API int r_io_fd_get_base (RIO *io, int fd) { +R_API bool r_io_fd_get_base (RIO *io, int fd, ut64 *base) { RIODesc *desc; - if (!io || !io->files) { - return -2; + if (!io || !io->files || !base) { + return false; } desc = r_io_desc_get (io, fd); - return r_io_desc_get_base (desc); + return r_io_desc_get_base (desc, base); } + R_API const char *r_io_fd_get_name(RIO *io, int fd) { RIODesc *desc; if (!io || !io->files || !(desc = r_io_desc_get (io, fd))) { diff --git a/libr/io/p/io_w32dbg.c b/libr/io/p/io_w32dbg.c index ca894b99ed..63550f989c 100644 --- a/libr/io/p/io_w32dbg.c +++ b/libr/io/p/io_w32dbg.c @@ -143,9 +143,13 @@ static int __gettid (RIODesc *fd) { return iow? iow->tid: -1; } -static int __getbase (RIODesc *fd) { +static bool __getbase (RIODesc *fd, ut64 *base) { RIOW32Dbg *iow = (RIOW32Dbg *)(fd ? fd->data : NULL); - return iow ? iow->winbase: -1; + if (base && iow) { + *base = iow->winbase; + return true; + } + return false; } RIOPlugin r_io_plugin_w32dbg = {