This commit is contained in:
Álvaro Felipe Melchor 2015-10-13 17:18:20 +02:00 committed by pancake
parent feb11b7861
commit c1f023ae5a
3 changed files with 74 additions and 0 deletions

View File

@ -721,6 +721,7 @@ static int cmd_debug_map(RCore *core, const char *input) {
const char* help_msg[] = {
"Usage:", "dm", " # Memory maps commands",
"dm", "", "List memory maps of target process",
"dm=", "", "List memory maps of target process (ascii-art bars)",
"dm", " <address> <size>", "Allocate <size> bytes at <address> (anywhere if address is -1) in child process",
"dm.", "", "Show map name of current address",
"dm*", "", "List memmaps in radare commands",
@ -887,6 +888,12 @@ static int cmd_debug_map(RCore *core, const char *input) {
r_debug_map_sync (core->dbg); // update process memory maps
r_debug_map_list (core->dbg, core->offset, input[0]);
break;
case '=':
r_debug_map_sync (core->dbg);
r_debug_map_list_visual (core->dbg, core->offset,
r_config_get_i (core->config,
"scr.color"));
break;
}
return true;
}

View File

@ -75,6 +75,72 @@ R_API void r_debug_map_list(RDebug *dbg, ut64 addr, int rad) {
}
}
static void print_debug_map_ascii_art(RList *maps, ut64 addr,
int use_color, PrintfCallback cb_printf,
int bits) {
ut64 mul, min = -1, max = 0;
int width = r_cons_get_size (NULL) - 80;
const char *fmtstr;
RListIter *iter;
RDebugMap *map;
if (width < 1) width = 30;
r_list_foreach (maps, iter, map) {
if (map->addr < min)
min = map->addr;
if (map->addr_end > max)
max = map->addr_end;
}
mul = (max - min) / width;
if (min != -1 && mul != 0) {
const char *c = "", *c_end = "";
char buf[56];
const char *fmtstr;
int j;
r_list_foreach (maps, iter, map) {
r_num_units (buf, map->size);
if (use_color) {
c_end = Color_RESET;
if (map->perm & 1) c = Color_GREEN;
if (map->perm & 2) c = Color_RED;
else { c = "" ; c_end = ""; }
} else {
c = "";
c_end = "";
}
fmtstr = bits & R_SYS_BITS_64 ?
"sys %04s %c %s0x%016"PFMT64x"%s |" :
"sys %04s %c %s0x%08"PFMT64x"%s |";
cb_printf (fmtstr, buf,
(addr >= map->addr && \
addr < map->addr_end) ? '*' : '-',
c, map->addr, c_end);
for (j = 0; j < width; j++) {
ut64 pos = min + (j * mul);
ut64 npos = min + ((j + 1) * mul);
if (map->addr < npos && map->addr_end > pos) {
cb_printf ("#");
} else {
cb_printf ("-");
}
}
fmtstr = bits & R_SYS_BITS_64 ?
"| %s0x%016"PFMT64x"%s %s %s\n" :
"| %s0x%08"PFMT64x"%s %s %s\n";
cb_printf (fmtstr, c, map->addr_end, c_end,
r_str_rwx_i (map->perm), map->name);
}
}
}
R_API void r_debug_map_list_visual(RDebug *dbg, ut64 addr, int use_color ) {
if (dbg && dbg->maps) print_debug_map_ascii_art (dbg->maps, addr,
use_color, dbg->cb_printf,
dbg->bits);
if (dbg && dbg->maps_user) print_debug_map_ascii_art (dbg->maps_user,
addr, use_color,
dbg->cb_printf, dbg->bits);
}
R_API RDebugMap *r_debug_map_new(char *name, ut64 addr, ut64 addr_end, int perm, int user) {
RDebugMap *map;
if (name == NULL || addr >= addr_end) {

View File

@ -359,6 +359,7 @@ R_API RDebugMap *r_debug_map_get(RDebug *dbg, ut64 addr);
R_API RDebugMap *r_debug_map_new (char *name, ut64 addr, ut64 addr_end, int perm, int user);
R_API void r_debug_map_free(RDebugMap *map);
R_API void r_debug_map_list(RDebug *dbg, ut64 addr, int rad);
R_API void r_debug_map_list_visual(RDebug *dbg, ut64 addr, int use_color);
/* descriptors */
R_API RDebugDesc *r_debug_desc_new (int fd, char* path, int perm, int type, int off);