Skip to content

Commit

Permalink
Add asm.flags.real option disabled by default
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanpencil committed Jul 4, 2018
1 parent 97acda4 commit 6a4f901
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 26 deletions.
4 changes: 2 additions & 2 deletions libr/core/cbin.c
Expand Up @@ -216,10 +216,10 @@ static void _print_strings(RCore *r, RList *list, int mode, int va) {
r_name_filter (f_name, -1);
if (r->bin->prefix) {
str = r_str_newf ("%s.str.%s", r->bin->prefix, f_name);
f_realname = r_str_newf ("%s.str.%s", r->bin->prefix, string->string);
f_realname = r_str_newf ("%s.\"%s\"", r->bin->prefix, string->string);
} else {
str = r_str_newf ("str.%s", f_name);
f_realname = r_str_newf ("str.%s", string->string);
f_realname = r_str_newf ("\"%s\"", string->string);
}
RFlagItem *flag = r_flag_set (r->flags, str, addr, string->size);
r_flag_item_set_realname (flag, f_realname);
Expand Down
8 changes: 8 additions & 0 deletions libr/core/cconfig.c
Expand Up @@ -649,6 +649,13 @@ static void update_asmfeatures_options(RCore *core, RConfigNode *node) {
}
}

static int cb_flag_realnames(void *user, void *data) {
RCore *core = (RCore *) user;
RConfigNode *node = (RConfigNode *) data;
core->flags->realnames = node->i_value;
return true;
}

static int cb_asmfeatures(void *user, void *data) {
RCore *core = (RCore *) user;
RConfigNode *node = (RConfigNode *) data;
Expand Down Expand Up @@ -2475,6 +2482,7 @@ R_API int r_core_config_init(RCore *core) {
n = NODEICB ("asm.flags.middle", 2, &cb_midflags);
SETOPTIONS (n, "0 = do not show flag", "1 = show without realign", "2 = realign at middle flag",
"3 = realign at middle flag if sym.*", NULL);
SETCB ("asm.flags.real", "false", &cb_flag_realnames, "Show flags unfiltered realnames instead of names");
SETDESC (n, "Realign disassembly if there is a flag in the middle of an instruction");
SETPREF ("asm.lbytes", "true", "Align disasm bytes to left");
SETPREF ("asm.lines", "true", "Show ASCII-art lines at disassembly");
Expand Down
8 changes: 4 additions & 4 deletions libr/core/cmd_anal.c
Expand Up @@ -1392,7 +1392,7 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int
// 0x33->sym.xx
char *p = strdup (strsub);
r_parse_filter (core->parser, core->flags, p,
strsub, sizeof (strsub), be, core->cons->use_utf8);
strsub, sizeof (strsub), be);
free (p);
r_cons_printf ("\"disasm\":\"%s\",", strsub);
}
Expand Down Expand Up @@ -5276,7 +5276,7 @@ static bool cmd_anal_refs(RCore *core, const char *input) {
asmop.buf_asm, asmop.buf_asm, sizeof (asmop.buf_asm));
}
r_parse_filter (core->parser, core->flags,
asmop.buf_asm, str, sizeof (str), core->print->big_endian, core->cons->use_utf8);
asmop.buf_asm, str, sizeof (str), core->print->big_endian);

r_cons_printf ("{\"from\":%" PFMT64u ",\"type\":\"%s\",\"opcode\":\"%s\"", ref->addr, r_anal_xrefs_type_tostring (ref->type), str);
if (fcn) {
Expand Down Expand Up @@ -5340,7 +5340,7 @@ static bool cmd_anal_refs(RCore *core, const char *input) {
asmop.buf_asm, asmop.buf_asm, sizeof (asmop.buf_asm));
}
r_parse_filter (core->parser, core->flags,
asmop.buf_asm, str, sizeof (str), core->print->big_endian, core->cons->use_utf8);
asmop.buf_asm, str, sizeof (str), core->print->big_endian);
if (has_color) {
buf_asm = r_print_colorize_opcode (core->print, str,
core->cons->pal.reg, core->cons->pal.num, false);
Expand Down Expand Up @@ -5417,7 +5417,7 @@ static bool cmd_anal_refs(RCore *core, const char *input) {
r_asm_set_pc (core->assembler, ref->at);
r_asm_disassemble (core->assembler, &asmop, buf, 12);
r_parse_filter (core->parser, core->flags,
asmop.buf_asm, str, sizeof (str), core->print->big_endian, core->cons->use_utf8);
asmop.buf_asm, str, sizeof (str), core->print->big_endian);
if (has_color) {
buf_asm = r_print_colorize_opcode (core->print, str,
core->cons->pal.reg, core->cons->pal.num, false);
Expand Down
6 changes: 3 additions & 3 deletions libr/core/cmd_flag.c
Expand Up @@ -817,7 +817,7 @@ static int cmd_flag(void *data, const char *input) {
case '*': // "f*"
case 'j': // "fj"
case 'q': // "fq"
r_flag_list (core->flags, *input, input[0]? input + 1: "", core->cons->use_utf8);
r_flag_list (core->flags, *input, input[0]? input + 1: "");
break;
case 'i': // "fi"
if (input[1] == ' ' || input[2] == ' ') {
Expand All @@ -840,13 +840,13 @@ static int cmd_flag(void *data, const char *input) {
arg = r_str_newf (" 0x%"PFMT64x" 0x%"PFMT64x,
core->offset, core->offset + core->blocksize);
}
r_flag_list (core->flags, 'i', arg, core->cons->use_utf8);
r_flag_list (core->flags, 'i', arg);
free (arg);
} else {
// XXX dupe for prev case
char *arg = r_str_newf (" 0x%"PFMT64x" 0x%"PFMT64x,
core->offset, core->offset + core->blocksize);
r_flag_list (core->flags, 'i', arg, core->cons->use_utf8);
r_flag_list (core->flags, 'i', arg);
free (arg);
}
break;
Expand Down
4 changes: 2 additions & 2 deletions libr/core/cmd_search.c
Expand Up @@ -1823,7 +1823,7 @@ static void do_ref_search(RCore *core, ut64 addr,ut64 from, ut64 to, struct sear
r_asm_disassemble (core->assembler, &asmop, buf, size);
fcn = r_anal_get_fcn_in (core->anal, ref->addr, 0);
r_parse_filter (core->parser, core->flags,
asmop.buf_asm, str, sizeof (str), core->print->big_endian, core->cons->use_utf8);
asmop.buf_asm, str, sizeof (str), core->print->big_endian);
comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, ref->addr);
char *buf_fcn = comment
? r_str_newf ("%s; %s", fcn ? fcn->name : "(nofunc)", strtok (comment, "\n"))
Expand Down Expand Up @@ -2083,7 +2083,7 @@ static void do_asm_search(RCore *core, struct search_parameters *param, const ch
0
};
r_parse_filter (core->parser, core->flags, hit->code, tmp, sizeof (tmp),
core->print->big_endian, core->cons->use_utf8);
core->print->big_endian);
r_cons_printf ("0x%08"PFMT64x " # %i: %s\n",
hit->addr, hit->len, tmp);
} else {
Expand Down
2 changes: 1 addition & 1 deletion libr/core/cmd_zign.c
Expand Up @@ -782,7 +782,7 @@ static int cmdInfo(void *data, const char *input) {
}
RCore *core = (RCore *) data;
r_flag_space_push (core->flags, "sign");
r_flag_list (core->flags, *input, input[0] ? input + 1: "", core->cons->use_utf8);
r_flag_list (core->flags, *input, input[0] ? input + 1: "");
r_flag_space_pop (core->flags);
return true;
}
Expand Down
10 changes: 5 additions & 5 deletions libr/core/disasm.c
Expand Up @@ -968,7 +968,7 @@ static void ds_build_op_str(RDisasmState *ds, bool print_color) {
}
}
r_parse_filter (core->parser, core->flags, asm_str,
ds->str, sizeof (ds->str), core->print->big_endian, core->cons->use_utf8);
ds->str, sizeof (ds->str), core->print->big_endian);
core->parser->flagspace = ofs;
free (ds->opstr);
ds->opstr = strdup (ds->str);
Expand Down Expand Up @@ -5029,7 +5029,7 @@ R_API int r_core_print_disasm_instructions(RCore *core, int nb_bytes, int nb_opc
}
core->parser->hint = ds->hint;
r_parse_filter (core->parser, core->flags, ds->asmop.buf_asm, ds->str,
sizeof (ds->str), core->print->big_endian, core->cons->use_utf8);
sizeof (ds->str), core->print->big_endian);
ds->opstr = strdup (ds->str);
asm_str = colorize_asm_string (core, ds, true);
core->parser->flagspace = ofs;
Expand Down Expand Up @@ -5223,7 +5223,7 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte
}
}
r_parse_filter (core->parser, core->flags, asmop.buf_asm, str,
sizeof (str), core->print->big_endian, core->cons->use_utf8);
sizeof (str), core->print->big_endian);

r_cons_printf (j > 0 ? ",{" : "{");
r_cons_printf ("\"offset\":%"PFMT64d, at);
Expand Down Expand Up @@ -5401,7 +5401,7 @@ R_API int r_core_print_disasm_all(RCore *core, ut64 addr, int l, int len, int mo
switch (mode) {
case 'i':
r_parse_filter (core->parser, core->flags, asmop.buf_asm,
str, sizeof (str), core->print->big_endian, core->cons->use_utf8);
str, sizeof (str), core->print->big_endian);
if (scr_color) {
char *buf_asm;
RAnalOp aop;
Expand Down Expand Up @@ -5887,7 +5887,7 @@ R_API int r_core_disasm_pdi(RCore *core, int nb_opcodes, int nb_bytes, int fmt)
if (filter) {
core->parser->hint = r_anal_hint_get (core->anal, at);
r_parse_filter (core->parser, core->flags,
asm_str, opstr, sizeof (opstr) - 1, core->print->big_endian, core->cons->use_utf8);
asm_str, opstr, sizeof (opstr) - 1, core->print->big_endian);
asm_str = (char *)&opstr;
}
if (show_color) {
Expand Down
2 changes: 1 addition & 1 deletion libr/core/project.c
Expand Up @@ -653,7 +653,7 @@ static bool projectSaveScript(RCore *core, const char *file, int opts) {
r_str_write (fd, "# flags\n");
tmp = core->flags->space_idx;
core->flags->space_idx = -1;
r_flag_list (core->flags, true, NULL, core->cons->use_utf8);
r_flag_list (core->flags, true, NULL);
core->flags->space_idx = tmp;
r_cons_flush ();
}
Expand Down
4 changes: 2 additions & 2 deletions libr/flag/flag.c
Expand Up @@ -208,7 +208,7 @@ R_API RFlag *r_flag_free(RFlag *f) {
}

/* print with r_cons the flag items in the flag f, given as a parameter */
R_API void r_flag_list(RFlag *f, int rad, const char *pfx, bool flag_realnames) {
R_API void r_flag_list(RFlag *f, int rad, const char *pfx) {
bool in_range = false;
ut64 range_from = UT64_MAX;
ut64 range_to = UT64_MAX;
Expand Down Expand Up @@ -331,7 +331,7 @@ R_API void r_flag_list(RFlag *f, int rad, const char *pfx, bool flag_realnames)
flag->alias, flag->size, flag->name);
} else {
f->cb_printf ("0x%08"PFMT64x" %"PFMT64d" %s\n",
flag->offset, flag->size, flag_realnames ? flag->realname : flag->name);
flag->offset, flag->size, f->realnames ? flag->realname : flag->name);
}
}
break;
Expand Down
3 changes: 2 additions & 1 deletion libr/include/r_flag.h
Expand Up @@ -52,6 +52,7 @@ typedef struct r_flag_t {
st64 base; /* base address for all flag items */
int space_idx; /* index of the selected space in spaces array */
bool space_strict; /* when true returned flag items must belong to the selected space */
bool realnames;
char *spaces[R_FLAG_SPACES_MAX]; /* array of flag spaces */
Sdb *tags;
RNum *num;
Expand Down Expand Up @@ -91,7 +92,7 @@ R_API int r_flag_bind(RFlag *io, RFlagBind *bnd);
#ifdef R_API
R_API RFlag * r_flag_new(void);
R_API RFlag * r_flag_free(RFlag *f);
R_API void r_flag_list(RFlag *f, int rad, const char *pfx, bool flag_realnames);
R_API void r_flag_list(RFlag *f, int rad, const char *pfx);
R_API bool r_flag_exist_at(RFlag *f, const char *flag_prefix, ut16 fp_size, ut64 off);
R_API RFlagItem *r_flag_get(RFlag *f, const char *name);
R_API RFlagItem *r_flag_get_i(RFlag *f, ut64 off);
Expand Down
2 changes: 1 addition & 1 deletion libr/include/r_parse.h
Expand Up @@ -57,7 +57,7 @@ R_API int r_parse_list(RParse *p);
R_API int r_parse_use(RParse *p, const char *name);
R_API int r_parse_parse(RParse *p, const char *data, char *str);
R_API int r_parse_assemble(RParse *p, char *data, char *str);
R_API int r_parse_filter(RParse *p, RFlag *f, char *data, char *str, int len, bool big_endian, bool flag_realnames);
R_API int r_parse_filter(RParse *p, RFlag *f, char *data, char *str, int len, bool big_endian);
R_API bool r_parse_varsub(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len);
R_API char *r_parse_c_string(RAnal *anal, const char *code);
R_API char *r_parse_c_file(RAnal *anal, const char *path);
Expand Down
8 changes: 4 additions & 4 deletions libr/parse/parse.c
Expand Up @@ -175,7 +175,7 @@ static char *findNextNumber(char *op) {
return NULL;
}

static int filter(RParse *p, RFlag *f, char *data, char *str, int len, bool big_endian, bool flag_realnames) {
static int filter(RParse *p, RFlag *f, char *data, char *str, int len, bool big_endian) {
char *ptr = data, *ptr2, *ptr_backup;
RAnalFunction *fcn;
RFlagItem *flag;
Expand Down Expand Up @@ -276,7 +276,7 @@ static int filter(RParse *p, RFlag *f, char *data, char *str, int len, bool big_
}
}
*ptr = 0;
snprintf (str, len, "%s%s%s", data, flag_realnames? flag->realname : flag->name,
snprintf (str, len, "%s%s%s", data, f->realnames? flag->realname : flag->name,
(ptr != ptr2) ? ptr2 : "");
bool banned = false;
{
Expand Down Expand Up @@ -527,8 +527,8 @@ R_API bool r_parse_immtrim (char *opstr) {
return changed;
}

R_API int r_parse_filter(RParse *p, RFlag *f, char *data, char *str, int len, bool big_endian, bool flag_realnames) {
filter (p, f, data, str, len, big_endian, flag_realnames);
R_API int r_parse_filter(RParse *p, RFlag *f, char *data, char *str, int len, bool big_endian) {
filter (p, f, data, str, len, big_endian);
if (p->cur && p->cur->filter) {
return p->cur->filter (p, f, data, str, len, big_endian);
}
Expand Down

0 comments on commit 6a4f901

Please sign in to comment.