Implement asm.section.sub to prefix offsets with section name in disasm

This commit is contained in:
pancake 2017-03-28 22:55:58 +02:00
parent 9578dffa1c
commit 8edcc53a18
8 changed files with 40 additions and 17 deletions

View File

@ -238,6 +238,18 @@ static int cb_analrecont(void *user, void *data) {
return true;
}
static int cb_asmsecsub(void *user, void *data) {
RCore *core = (RCore *) user;
RConfigNode *node = (RConfigNode *) data;
if (node->i_value) {
core->print->flags |= R_PRINT_FLAGS_SECSUB;
} else {
core->print->flags &= (~R_PRINT_FLAGS_SECSUB);
}
r_print_set_flags (core->print, core->print->flags);
return true;
}
static int cb_asmassembler(void *user, void *data) {
RCore *core = (RCore *) user;
RConfigNode *node = (RConfigNode *) data;
@ -1844,6 +1856,7 @@ R_API int r_core_config_init(RCore *core) {
SETPREF("asm.reloff.flags", "false", "Show relative offsets to flags (not only functions)");
SETPREF("asm.section", "false", "Show section name before offset");
SETI("asm.section.col", 20, "Columns width to show asm.section");
SETCB("asm.section.sub", "false", &cb_asmsecsub, "Show offsets in disasm prefixed with section/map name");
SETPREF("asm.pseudo", "false", "Enable pseudo syntax");
SETPREF("asm.size", "false", "Show size of opcodes in disassembly (pd)");
SETPREF("asm.stackptr", "false", "Show stack pointer at disassembly");

View File

@ -4039,8 +4039,8 @@ static bool cmd_anal_refs(RCore *core, const char *input) {
r_parse_filter (core->parser, core->flags,
asmop.buf_asm, str, sizeof (str), core->print->big_endian);
if (has_color) {
buf_asm = r_print_colorize_opcode (str, core->cons->pal.reg,
core->cons->pal.num);
buf_asm = r_print_colorize_opcode (core->print, str,
core->cons->pal.reg, core->cons->pal.num);
} else {
buf_asm = r_str_new (str);
}
@ -4118,8 +4118,8 @@ static bool cmd_anal_refs(RCore *core, const char *input) {
r_parse_filter (core->parser, core->flags,
asmop.buf_asm, str, sizeof (str), core->print->big_endian);
if (has_color) {
buf_asm = r_print_colorize_opcode (str, core->cons->pal.reg,
core->cons->pal.num);
buf_asm = r_print_colorize_opcode (core->print, str,
core->cons->pal.reg, core->cons->pal.num);
} else {
buf_asm = r_str_new (str);
}

View File

@ -1541,7 +1541,7 @@ static int pdi(RCore *core, int nb_opcodes, int nb_bytes, int fmt) {
RAnalOp aop = {
0
};
char *asm_str = r_print_colorize_opcode (asmop.buf_asm, color_reg, color_num);
char *asm_str = r_print_colorize_opcode (core->print, asmop.buf_asm, color_reg, color_num);
r_anal_op (core->anal, &aop, core->offset + i,
core->block + i, core->blocksize - i);
r_parse_filter (core->parser, core->flags,

View File

@ -1137,7 +1137,7 @@ static void print_rop(RCore *core, RList *hitlist, char mode, bool *json_first)
if (esil) {
r_cons_printf ("%s\n", opstr);
} else if (colorize) {
buf_asm = r_print_colorize_opcode (asmop.buf_asm,
buf_asm = r_print_colorize_opcode (core->print, asmop.buf_asm,
core->cons->pal.reg, core->cons->pal.num);
r_cons_printf (" %s%s;", buf_asm, Color_RESET);
free (buf_asm);
@ -1174,7 +1174,7 @@ static void print_rop(RCore *core, RList *hitlist, char mode, bool *json_first)
r_list_append (ropList, (void *) opstr_n);
}
if (colorize) {
buf_asm = r_print_colorize_opcode (asmop.buf_asm,
buf_asm = r_print_colorize_opcode (core->print, asmop.buf_asm,
core->cons->pal.reg, core->cons->pal.num);
otype = r_print_color_op_type (core->print, analop.type);
if (comment) {

View File

@ -663,9 +663,9 @@ static char *colorize_asm_string(RCore *core, RDisasmState *ds) {
char *scol1, *s1 = r_str_ndup (source, spacer - source);
char *scol2, *s2 = strdup (spacer + 2);
scol1 = r_print_colorize_opcode (s1, ds->color_reg, ds->color_num);
scol1 = r_print_colorize_opcode (ds->core->print, s1, ds->color_reg, ds->color_num);
free (s1);
scol2 = r_print_colorize_opcode (s2, ds->color_reg, ds->color_num);
scol2 = r_print_colorize_opcode (ds->core->print, s2, ds->color_reg, ds->color_num);
free (s2);
if (!scol1) {
scol1 = strdup ("");
@ -680,7 +680,7 @@ static char *colorize_asm_string(RCore *core, RDisasmState *ds) {
free (scol2);
return source;
}
return r_print_colorize_opcode (source, ds->color_reg, ds->color_num);
return r_print_colorize_opcode (ds->core->print, source, ds->color_reg, ds->color_num);
}
static void ds_build_op_str(RDisasmState *ds) {
@ -4250,7 +4250,7 @@ R_API int r_core_print_disasm_all(RCore *core, ut64 addr, int l, int len, int mo
char *buf_asm;
RAnalOp aop;
r_anal_op (core->anal, &aop, addr, buf+i, l-i);
buf_asm = r_print_colorize_opcode (str,
buf_asm = r_print_colorize_opcode (core->print, str,
core->cons->pal.reg, core->cons->pal.num);
r_cons_printf ("%s%s\n",
r_print_color_op_type (core->print, aop.type),

View File

@ -73,9 +73,9 @@ static char *colorize_asm_string(RCore *core, const char *buf_asm, int optype) {
if (spacer) {
char *scol1, *s1 = r_str_ndup (source, spacer - source);
char *scol2, *s2 = strdup (spacer + 2);
scol1 = r_print_colorize_opcode (s1, color_reg, color_num);
scol1 = r_print_colorize_opcode (core->print, s1, color_reg, color_num);
free (s1);
scol2 = r_print_colorize_opcode (s2, color_reg, color_num);
scol2 = r_print_colorize_opcode (core->print, s2, color_reg, color_num);
free (s2);
if (!scol1) {
scol1 = strdup ("");
@ -91,7 +91,7 @@ static char *colorize_asm_string(RCore *core, const char *buf_asm, int optype) {
}
char *res = strdup("");
res = r_str_append (res, r_print_color_op_type (core->print, optype));
tmp = r_print_colorize_opcode (source, color_reg, color_num);
tmp = r_print_colorize_opcode (core->print, source, color_reg, color_num);
res = r_str_append (res, tmp);
free (tmp);
return res;

View File

@ -24,6 +24,7 @@ extern "C" {
#define R_PRINT_FLAGS_COMMENT 0x00000400
#define R_PRINT_FLAGS_COMPACT 0x00000800
#define R_PRINT_FLAGS_NONHEX 0x00001000
#define R_PRINT_FLAGS_SECSUB 0x00002000
typedef int (*RPrintZoomCallback)(void *user, int mode, ut64 addr, ut8 *bufz, ut64 size);
typedef const char *(*RPrintNameCallback)(void *user, ut64 addr);
@ -155,8 +156,8 @@ R_API void r_print_rangebar(RPrint *p, ut64 startA, ut64 endA, ut64 min, ut64 ma
R_API char * r_print_randomart(const ut8 *dgst_raw, ut32 dgst_raw_len, ut64 addr);
R_API void r_print_2bpp_row(RPrint *p, ut8 *buf);
R_API void r_print_2bpp_tiles(RPrint *p, ut8 *buf, ut32 tiles);
R_API char * r_print_colorize_opcode (char *p, const char *reg, const char *num);
R_API const char * r_print_color_op_type ( RPrint *p, ut64 anal_type);
R_API char * r_print_colorize_opcode(RPrint *print, char *p, const char *reg, const char *num);
R_API const char * r_print_color_op_type(RPrint *p, ut64 anal_type);
R_API void r_print_set_interrupted(int i);
R_API void r_print_init_rowoffsets(RPrint *p);
R_API ut32 r_print_rowoff(RPrint *p, int i);

View File

@ -1612,7 +1612,7 @@ R_API const char* r_print_color_op_type(RPrint *p, ut64 anal_type) {
#define COLORIZE_BUFSIZE 1024
static char o[COLORIZE_BUFSIZE];
R_API char* r_print_colorize_opcode(char *p, const char *reg, const char *num) {
R_API char* r_print_colorize_opcode(RPrint *print, char *p, const char *reg, const char *num) {
int i, j, k, is_mod, is_float = 0, is_arg = 0;
ut32 c_reset = strlen (Color_RESET);
int is_jmp = p && (*p == 'j' || ((*p == 'c') && (p[1] == 'a')))? 1: 0;
@ -1758,6 +1758,15 @@ R_API char* r_print_colorize_opcode(char *p, const char *reg, const char *num) {
eprintf ("r_print_colorize_opcode(): buffer overflow!\n");
return strdup (p);
}
if (print->flags & R_PRINT_FLAGS_SECSUB) {
RIOSection *s = print->iob.section_vget (print->iob.io, r_num_get (NULL, p + i));
if (s) {
strcpy (o + j, s->name);
j += strlen (o + j);
strcpy (o + j, ".");
j++;
}
}
strcpy (o + j, num);
j += strlen (num);
}