From a46b62e220ef2f71ea835012091cbcb64da0c8ba Mon Sep 17 00:00:00 2001 From: alvarofe Date: Fri, 25 Aug 2017 14:33:14 +0200 Subject: [PATCH] Fix some regressions --- binr/radare2/radare2.c | 1 + libr/core/cmd_open.c | 15 ++++++++------- libr/core/file.c | 9 ++++++--- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/binr/radare2/radare2.c b/binr/radare2/radare2.c index cfcc6b217b..7b5be3d4d2 100644 --- a/binr/radare2/radare2.c +++ b/binr/radare2/radare2.c @@ -961,6 +961,7 @@ int main(int argc, char **argv, char **envp) { (void)r_core_bin_load (&r, filepath, baddr); } } else { + r_io_map_new (r.io, iod->fd, iod->flags, 0LL, 0LL, r_io_desc_size (iod)); if (run_anal < 0) { // PoC -- must move -rk functionalitiy into rcore // this may be used with caution (r2 -nn $FILE) diff --git a/libr/core/cmd_open.c b/libr/core/cmd_open.c index 8fcf2c5e1e..b44147833f 100644 --- a/libr/core/cmd_open.c +++ b/libr/core/cmd_open.c @@ -754,7 +754,6 @@ static int cmd_open(void *data, const char *input) { r_core_file_list (core, 'n'); break; } - /* fall through */ case ' ': { @@ -762,18 +761,17 @@ static int cmd_open(void *data, const char *input) { ut64 ma = 0L; char *fn = strdup (input + (isn? 2:1)); if (!fn || !*fn) { - eprintf ("Usage: on [file]\n"); + if (isn) { + eprintf ("Usage: on [file]\n"); + } else { + eprintf ("Usage: o [file] addr\n"); + } free (fn); break; } ptr = strchr (fn, ' '); if (ptr) { *ptr++ = '\0'; - char *ptr2 = strchr (ptr, ' '); - if (ptr2) { - *ptr2++ = 0; - ba = r_num_math (core->num, ptr2); - } ma = r_num_math (core->num, ptr); } int num = atoi (input + 1); @@ -785,6 +783,9 @@ static int cmd_open(void *data, const char *input) { // MUST CLEAN BEFORE LOADING if (!isn) { r_core_bin_load (core, fn, ba); + } else { + RIODesc *d = r_io_desc_get (core->io, file->fd); + r_io_map_new (core->io, d->fd, d->flags, 0LL, ma, r_io_desc_size (d)); } } else if (!nowarn) { eprintf ("Cannot open file '%s'\n", fn); diff --git a/libr/core/file.c b/libr/core/file.c index be0bcb9561..e6393337f3 100644 --- a/libr/core/file.c +++ b/libr/core/file.c @@ -521,6 +521,7 @@ R_API bool r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) { const char *suppress_warning = r_config_get (r->config, "file.nowarn"); RCoreFile *cf = r_core_file_cur (r); RIODesc *desc = cf ? r_io_desc_get (r->io, cf->fd) : NULL; + ut64 laddr = r_config_get_i (r->config, "bin.laddr"); RBinFile *binfile = NULL; RBinPlugin *plugin = NULL; int is_io_load; @@ -562,7 +563,6 @@ R_API bool r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) { if ((desc->plugin && desc->plugin->isdbg) || r_config_get_i (r->config, "cfg.debug")) { r_core_file_do_load_for_debug (r, baddr, filenameuri); } else { - ut64 laddr = r_config_get_i (r->config, "bin.laddr"); r_core_file_do_load_for_io_plugin (r, baddr, laddr); } // Restore original desc @@ -624,8 +624,8 @@ R_API bool r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) { } } //workaround to map correctly malloc:// and raw binaries - if (!plugin || !strcmp (plugin->name, "any") || !desc->plugin || !desc->plugin->isdbg) { - r_io_map_new (r->io, desc->fd, desc->flags, 0LL, 0LL, r_io_desc_size (desc)); + if (!plugin || !strcmp (plugin->name, "any") || r_io_desc_is_dbg (desc)) { + r_io_map_new (r->io, desc->fd, desc->flags, 0LL, laddr, r_io_desc_size (desc)); } return true; } @@ -812,6 +812,9 @@ R_API RCoreFile *r_core_file_open(RCore *r, const char *file, int flags, ut64 lo } r_config_set_i (r->config, "dbg.swstep", swstep); } + //used by r_core_bin_load otherwise won't load correctly + //this should be argument of r_core_bin_load + r_config_set_i (r->config, "bin.laddr", loadaddr); beach: r->times->file_open_time = r_sys_now () - prev; return fh;