Implement asm.demangle and bin.demangle, add 'fn' to display realname of flags

This commit is contained in:
pancake 2014-09-24 03:01:18 +02:00
parent 8f4b2cdf5b
commit 0931f502ed
7 changed files with 82 additions and 44 deletions

View File

@ -758,7 +758,7 @@ static int bin_symbols (RCore *r, int mode, ut64 baddr, ut64 laddr, int va, ut64
} else
if ((mode & R_CORE_BIN_SET)) {
int is_thumb = 0;
char *name, *dname, *cname;
char *name, *dname, *cname, *realname;
//ut8 cname_greater_than_15;
r_flag_space_set (r->flags, "symbols");
r_list_foreach (symbols, iter, symbol) {
@ -774,15 +774,15 @@ static int bin_symbols (RCore *r, int mode, ut64 baddr, ut64 laddr, int va, ut64
r_anal_hint_set_bits (r->anal, addr, 16);
}
if (r_config_get_i (r->config, "asm.demangle")) {
if (r_config_get_i (r->config, "bin.demangle")) {
char *demname = r_bin_demangle (r->bin->cur, name);
if (demname) {
free (name);
name = demname;
}
}
realname = strdup (name);
r_name_filter (name, 80);
if (cname) {
RFlagItem *flag_item = NULL;
@ -797,7 +797,7 @@ static int bin_symbols (RCore *r, int mode, ut64 baddr, ut64 laddr, int va, ut64
flag_item = NULL;
}
// set the new sym.[cname].[name] with comment
snprintf (str, R_FLAG_NAME_SIZE, "sym.%s.%s", cname, name);
snprintf (str, R_FLAG_NAME_SIZE, "sym.%s.%s", cname, realname);
r_flag_set (r->flags, str, addr, symbol->size, 0);
if (comment) {
flag_item = r_flag_get (r->flags, str);
@ -806,8 +806,11 @@ static int bin_symbols (RCore *r, int mode, ut64 baddr, ut64 laddr, int va, ut64
}
} else {
snprintf (str, R_FLAG_NAME_SIZE, "sym.%s", name);
r_flag_set (r->flags, str, addr, symbol->size, 0);
r_flag_item_set_name (
r_flag_set (r->flags, sdb_fmt (0, "sym.%s", name), addr, symbol->size, 0),
sdb_fmt (1,"sym.%s", realname));
}
R_FREE (realname);
#if 0
// dunno why this is here and mips results in wrong dis
if (!strncmp (symbol->type, "OBJECT", 6)) {

View File

@ -341,6 +341,7 @@ static int cmd_flag(void *data, const char *input) {
} else eprintf ("Cannot find flag\n");
}
break;
case 'n':
case '*':
case '\0':
case 'j':
@ -396,6 +397,7 @@ static int cmd_flag(void *data, const char *input) {
"fj","","list flags in JSON format",
"fl"," [flagname]","show flag length (size)",
"fm"," addr","move flag at current offset to new address",
"fn","","list flags displaying the real name (demangled)",
"fo","","show fortunes",
//" fc [name] [cmt] ; set execution command for a specific flag"
"fr"," [old] [[new]]","rename flag (if no new flag current seek one is used)",

View File

@ -769,7 +769,8 @@ R_API int r_core_config_init(RCore *core) {
SETICB("asm.bits", 32, &cb_asmbits, "Word size in bits at assembler");
SETPREF("asm.functions", "true", "Show functions in disassembly");
SETPREF("asm.xrefs", "true", "Show xrefs in disassembly");
SETPREF("asm.demangle", "false", "Show demangled symbols");
SETPREF("asm.demangle", "true", "Show demangled symbols in disasm");
SETPREF("bin.demangle", "false", "Import demangled symbols from RBin");
#if 0
r_config_set (cfg, "asm.offseg", "false");
r_config_desc (cfg, "asm.offseg", "Show offsets as in 16 bit segment addressing mode");

View File

@ -55,6 +55,7 @@ typedef struct r_disam_options_t {
int show_trace;
int linesout;
int adistrick;
int asm_demangle;
int show_offset;
int show_offseg;
int show_flags;
@ -228,6 +229,7 @@ static RDisasmState * handle_init_ds (RCore * core) {
ds->show_trace = r_config_get_i (core->config, "asm.trace");
ds->linesout = r_config_get_i (core->config, "asm.linesout");
ds->adistrick = r_config_get_i (core->config, "asm.middle"); // TODO: find better name
ds->asm_demangle = r_config_get_i (core->config, "asm.demangle");
ds->show_offset = r_config_get_i (core->config, "asm.offset");
ds->show_offseg = r_config_get_i (core->config, "asm.segoff");
ds->show_flags = r_config_get_i (core->config, "asm.flags");
@ -823,8 +825,13 @@ static void handle_show_flags_option(RCore *core, RDisasmState *ds) {
}
if (ds->show_offset) r_cons_printf (";-- ");
if (ds->show_color) r_cons_strcat (ds->color_flag);
if (ds->show_functions) r_cons_printf ("%s:\n", flag->name);
else r_cons_printf ("%s:\n", flag->name);
if (ds->asm_demangle) {
if (ds->show_functions) r_cons_printf ("%s:\n", flag->realname);
else r_cons_printf ("%s:\n", flag->realname);
} else {
if (ds->show_functions) r_cons_printf ("%s:\n", flag->name);
else r_cons_printf ("%s:\n", flag->name);
}
//handle_set_pre (ds, " ");
if (ds->show_color) {
r_cons_printf (Color_RESET"%s%s"Color_RESET, ds->color_fline,

View File

@ -77,7 +77,8 @@ R_API void r_flag_list(RFlag *f, int rad) {
RListIter *iter;
RFlagItem *flag;
if (rad=='j') {
switch (rad) {
case 'j': {
int first = 1;
r_cons_printf ("[");
r_list_foreach_prev (f->flags, iter, flag) {
@ -96,38 +97,58 @@ R_API void r_flag_list(RFlag *f, int rad) {
first = 0;
}
r_cons_printf ("]\n");
return;
}
r_list_foreach_prev (f->flags, iter, flag) {
if ((f->space_idx != -1) && (flag->space != f->space_idx))
continue;
if (rad) {
if (fs == -1 || flag->space != fs) {
const char *flagspace;
fs = flag->space;
flagspace = r_flag_space_get_i (f, fs);
if (!flagspace || !*flagspace)
flagspace = "*";
r_cons_printf ("fs %s\n", flagspace);
}
if (flag->alias) {
r_cons_printf ("fa %s %s\n", flag->name, flag->alias);
if (flag->comment && *flag->comment)
r_cons_printf ("\"fC %s %s\"\n", flag->name, flag->comment);
} else {
r_cons_printf ("f %s %"PFMT64d" 0x%08"PFMT64x" %s\n",
flag->name, flag->size, flag->offset,
flag->comment? flag->comment:"");
}
} else {
if (flag->alias) {
r_cons_printf ("%s %"PFMT64d" %s\n",
flag->alias, flag->size, flag->name);
} else {
r_cons_printf ("0x%08"PFMT64x" %"PFMT64d" %s\n",
flag->offset, flag->size, flag->name);
}
}
break;
case 1:
case '*':
r_list_foreach_prev (f->flags, iter, flag) {
if ((f->space_idx != -1) && (flag->space != f->space_idx))
continue;
if (fs == -1 || flag->space != fs) {
const char *flagspace;
fs = flag->space;
flagspace = r_flag_space_get_i (f, fs);
if (!flagspace || !*flagspace)
flagspace = "*";
r_cons_printf ("fs %s\n", flagspace);
}
if (flag->alias) {
r_cons_printf ("fa %s %s\n", flag->name, flag->alias);
if (flag->comment && *flag->comment)
r_cons_printf ("\"fC %s %s\"\n", flag->name, flag->comment);
} else {
r_cons_printf ("f %s %"PFMT64d" 0x%08"PFMT64x" %s\n",
flag->name, flag->size, flag->offset,
flag->comment? flag->comment:"");
}
}
break;
case 'n': // show original name
r_list_foreach_prev (f->flags, iter, flag) {
if ((f->space_idx != -1) && (flag->space != f->space_idx))
continue;
if (flag->alias) {
r_cons_printf ("%s %"PFMT64d" %s\n",
flag->alias, flag->size, flag->realname);
} else {
r_cons_printf ("0x%08"PFMT64x" %"PFMT64d" %s\n",
flag->offset, flag->size, flag->realname);
}
}
break;
default:
r_list_foreach_prev (f->flags, iter, flag) {
if ((f->space_idx != -1) && (flag->space != f->space_idx))
continue;
if (flag->alias) {
r_cons_printf ("%s %"PFMT64d" %s\n",
flag->alias, flag->size, flag->name);
} else {
r_cons_printf ("0x%08"PFMT64x" %"PFMT64d" %s\n",
flag->offset, flag->size, flag->name);
}
}
break;
}
}
@ -309,14 +330,19 @@ R_API void r_flag_item_set_comment(RFlagItem *item, const char *comment) {
R_API int r_flag_item_set_name(RFlagItem *item, const char *name) {
int len;
if (!item || !r_name_check (name))
if (!item)
return R_FALSE;
strncpy (item->realname, name, R_FLAG_NAME_SIZE);
if (!r_name_check (name))
return R_FALSE;
/* original name. maybe do some char mangling : printable*/
/* filtered name : typable */
strncpy (item->name, name, R_FLAG_NAME_SIZE);
len = R_MIN (R_FLAG_NAME_SIZE, strlen (r_str_chop (item->name)) + 1);
memmove (item->name, r_str_chop (item->name), len);
r_name_filter (item->name, 0);
item->name[R_FLAG_NAME_SIZE-1]='\0';
item->namehash = r_str_hash64 (item->name);
item->namehash = r_str_hash64 (item->realname);
return R_TRUE;
}

View File

@ -26,6 +26,7 @@ R_LIB_VERSION_HEADER(r_flag);
typedef struct r_flag_item_t {
char name[R_FLAG_NAME_SIZE];
char realname[R_FLAG_NAME_SIZE];
ut64 namehash;
ut64 offset;
ut64 size;

View File

@ -8,8 +8,6 @@
static int r_name_validate_char(const char ch) {
if ((ch>='a' && ch<='z') || (ch>='A' && ch<='Z') || (ch>='0' && ch<='9'))
return R_TRUE;
if (isprint (ch))
return R_TRUE;
switch (ch) {
case '.':
case '_':