diff --git a/libr/core/file.c b/libr/core/file.c index ce695ea3c6..c4b700f0a1 100644 --- a/libr/core/file.c +++ b/libr/core/file.c @@ -475,8 +475,9 @@ R_API RIOMap *r_core_file_get_next_map (RCore *core, RCoreFile * fh, int mode, u map = r_io_map_new (core->io, fh->desc->fd, mode, 0, loadaddr, r_io_desc_size (core->io, fh->desc)); if (!strcmp (loadmethod, "fail")) map = r_io_map_add (core->io, fh->desc->fd, mode, 0, loadaddr, r_io_desc_size (core->io, fh->desc)); - if (!strcmp (loadmethod, "append") && load_align) + if (!strcmp (loadmethod, "append") && load_align) { map = r_io_map_add_next_available (core->io, fh->desc->fd, mode, 0, loadaddr, r_io_desc_size (core->io, fh->desc), load_align); + } if (!strcmp (suppress_warning, "false")) { if (!map) eprintf ("r_core_file_get_next_map: Unable to load specified file to 0x%08"PFMT64x"\n", loadaddr); diff --git a/libr/core/rtr.c b/libr/core/rtr.c index 4a4fa4d669..a8efa5c92d 100644 --- a/libr/core/rtr.c +++ b/libr/core/rtr.c @@ -56,8 +56,11 @@ static int rtr_visual (RCore *core, TextLog T, const char *cmd) { if (cmd) { r_cons_break (NULL, NULL); for (;;) { + char *ret; r_cons_clear00 (); - r_cons_printf ("%s\n", rtrcmd (T, cmd)); + ret = rtrcmd (T, cmd); + r_cons_printf ("%s\n", ret); + free (ret); r_cons_flush (); if (r_cons_singleton ()->breaked) break; @@ -637,7 +640,7 @@ static int r_core_rtr_http_thread (RThread *th) { if (!th) return R_FALSE; ht = th->user; if (!ht || !ht->core) return R_FALSE; - return !r_core_rtr_http_run (ht->core, ht->launch, ht->path); + return r_core_rtr_http_run (ht->core, ht->launch, ht->path); } static RThread *httpthread = NULL; @@ -816,13 +819,19 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) { char uri[1024], prompt[64]; int len; char *str, *res, *ptr; - if (file[strlen (file)-1]=='/') { + int flen = strlen (file); + int is_visual = (file[flen-1]== 'V')?1:0; + int is_valid = (file[flen-(is_visual?2:1)] == '/')?1:0; + if (is_valid) { TextLog T = { host, port, file }; - rtr_visual (core, T, NULL); - for (;;) { + if (is_visual) { + file[flen-1] = 0; // remove V from url + rtr_visual (core, T, NULL); + } snprintf (prompt, sizeof (prompt), "[http://%s:%s/%s]> ", - host, port, file); - r_line_set_prompt (prompt); + host, port, file); + for (;;) { + r_line_set_prompt (prompt); str = r_line_readline (); if (!str || !*str) break; if (*str == 'q') break; @@ -832,26 +841,25 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) { } else { rtr_visual (core, T, NULL); } - } else - if (!strcmp (str, "TT")) { + } else if (!strcmp (str, "TT")) { rtr_textlog_chat (core, T); } else { - ptr = r_str_uri_encode (str); - if (ptr) str = ptr; - snprintf (uri, sizeof (uri), "http://%s:%s/%s%s", - host, port, file, str); - if (ptr == str) free (ptr); - str = r_socket_http_get (uri, NULL, &len); - if (str) { - str[len] = 0; - res = strstr (str, "\n\n"); - if (res) res = strstr (res+1, "\n\n"); - if (res) res += 2; else res = str; - printf ("%s%s", res, (res[strlen (res)-1]=='\n')?"":"\n"); - r_line_hist_add (str); - free (str); + ptr = r_str_uri_encode (str); + if (ptr) str = ptr; + snprintf (uri, sizeof (uri), "http://%s:%s/%s%s", + host, port, file, str); + if (ptr == str) free (ptr); + str = r_socket_http_get (uri, NULL, &len); + if (str) { + str[len] = 0; + res = strstr (str, "\n\n"); + if (res) res = strstr (res+1, "\n\n"); + if (res) res += 2; else res = str; + printf ("%s%s", res, (res[strlen (res)-1]=='\n')?"":"\n"); + r_line_hist_add (str); + free (str); + } } -} } r_socket_free (fd); return; diff --git a/libr/core/visual.c b/libr/core/visual.c index 565be73c28..c632102072 100644 --- a/libr/core/visual.c +++ b/libr/core/visual.c @@ -673,7 +673,7 @@ R_API int r_core_visual_cmd(RCore *core, int ch) { if (!r_core_rtr_http (core, '&', NULL)) { const char *xterm = r_config_get (core->config, "cmd.xterm"); // TODO: this must be configurable - r_sys_cmdf ("%s 'r2 -C http://localhost:%d/cmd/ || sleep 1' &", xterm, port); + r_sys_cmdf ("%s 'r2 -C http://localhost:%d/cmd/V;sleep 1' &", xterm, port); //xterm -bg black -fg gray -e 'r2 -C http://localhost:%d/cmd/;sleep 1' &", port); } else { r_cons_any_key (); diff --git a/libr/io/map.c b/libr/io/map.c index a3daed876a..2f80cb70db 100644 --- a/libr/io/map.c +++ b/libr/io/map.c @@ -208,11 +208,12 @@ R_API RIOMap *r_io_map_add_next_available(RIO *io, int fd, int flags, ut64 delta ut64 next_addr = addr, end_addr = next_addr + size; r_list_foreach (io->maps, iter, map) { + next_addr = R_MAX (next_addr, map->to+(load_align - (map->to % load_align))); // XXX - This does not handle when file overflow 0xFFFFFFFF000 -> 0x00000FFF // adding the check for the map's fd to see if this removes contention for // memory mapping with multiple files. - if ( map->fd == fd && ((map->from <= next_addr && next_addr < map->to) || + if (map->fd == fd && ((map->from <= next_addr && next_addr < map->to) || (map->from <= end_addr && end_addr < map->to)) ) { //return r_io_map_add(io, fd, flags, delta, map->to, size); next_addr = map->to + (load_align - (map->to % load_align));