Implement omj and om [fd]

This commit is contained in:
pancake 2017-08-23 12:18:29 +02:00
parent 941c48a477
commit d71f2a5843

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2016 - pancake */
/* radare - LGPL - Copyright 2009-2017 - pancake */
#include "r_list.h"
#include "r_config.h"
@ -67,6 +67,9 @@ static const char *help_msg_oj[] = {
static const char *help_msg_om[] = {
"Usage:", "om[-] [arg]", " # map opened files",
"om", "", "list all defined IO maps",
"om*", "", "list all maps in r2 commands format",
"omj", "", "list all maps in json format",
"om", " [fd]", "list all defined IO maps for a specific fd",
"om", "-mapid", "remove the map with corresponding id",
"om", " fd addr [size] [delta]", "create new io map",
"om.", "", "show map, that is mapped to current offset",
@ -269,15 +272,34 @@ static void cmd_open_bin(RCore *core, const char *input) {
}
}
static void map_list(RIO *io, int mode, RPrint *print) { //TODO: discuss the output format
// TODO: discuss the output format
static void map_list(RIO *io, int mode, RPrint *print, int fd) {
SdbListIter *iter;
RIOMap *map;
if (!io || !io->maps || !print || !print->cb_printf) {
return;
}
if (mode == 'j') {
print->cb_printf ("[");
}
bool first = true;
ls_foreach_prev (io->maps, iter, map) {
if (fd != -1 && map->fd != fd) {
continue;
}
if (!first) {
print->cb_printf (",");
}
first = false;
switch (mode) {
case 'j':
print->cb_printf ("{\"map\":%i,\"fd\":%d,\"delta\":%"PFMT64d",\"from\":%"PFMT64d
",\"to\":%"PFMT64d",\"flags\":\"%s\",\"name\":\"%s\"}", map->id, map->fd,
map->delta, map->from, map->to,
r_str_rwx_i (map->flags), (map->name ? map->name : ""));
break;
case 1:
case '*':
case 'r':
print->cb_printf ("om %d 0x%"PFMT64x" 0x%"PFMT64x" 0x%"PFMT64x"\n", map->fd,
map->from, map->to - map->from, map->delta);
@ -287,8 +309,12 @@ static void map_list(RIO *io, int mode, RPrint *print) { //TODO: discuss the out
" - 0x%"PFMT64x" ; %s : %s\n", map->id, map->fd,
map->delta, map->from, map->to,
r_str_rwx_i (map->flags), (map->name ? map->name : ""));
break;
}
}
if (mode == 'j') {
print->cb_printf ("]\n");
}
}
static void cmd_open_map (RCore *core, const char *input) {
@ -398,10 +424,12 @@ static void cmd_open_map (RCore *core, const char *input) {
}
} else {
size = r_io_desc_size (desc);
}
r_io_map_add (core->io, fd, desc->flags, delta, addr, size); //TODO:user should be able to set these
} else {
eprintf ("Invalid use of om . See om? for help.");
map_list (core->io, 0, core->print, r_num_math (core->num, s));
// eprintf ("Invalid use of om . See om? for help.");
}
free (s);
break;
@ -409,10 +437,9 @@ static void cmd_open_map (RCore *core, const char *input) {
r_io_map_del (core->io, r_num_math (core->num, input+2));
break;
case '\0':
map_list (core->io, 0, core->print);
break;
case 'j':
case '*':
map_list (core->io, 'r', core->print);
map_list (core->io, input[1], core->print, -1);
break;
default:
case '?':