mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-23 14:28:07 +00:00
[WIP] Colorize function arguments and variables part 2 (#10777)
* Colorize comments that hint type of data * Use new colors for comments that hint type of data * Colorize local variables and args in disasm * Fixed leak in r_anal_var_all_list() * Refactoring + rename color func_arg* to func_var* * Updated all color themes for func_var* colors * Directly query sdb for faster and cleaner var colorizing in r_colorize_opcode * Remove hackish r_core.h include in print.c and use callbacks instead
This commit is contained in:
parent
87bd92a64c
commit
13a2cb344a
@ -793,9 +793,15 @@ R_API RList *r_anal_var_all_list(RAnal *anal, RAnalFunction *fcn) {
|
||||
if (!list) {
|
||||
return NULL;
|
||||
}
|
||||
r_list_join (list, r_anal_var_list (anal, fcn, R_ANAL_VAR_KIND_REG));
|
||||
r_list_join (list, r_anal_var_list (anal, fcn, R_ANAL_VAR_KIND_BPV));
|
||||
r_list_join (list, r_anal_var_list (anal, fcn, R_ANAL_VAR_KIND_SPV));
|
||||
RList *reg_vars = r_anal_var_list (anal, fcn, R_ANAL_VAR_KIND_REG);
|
||||
RList *bpv_vars = r_anal_var_list (anal, fcn, R_ANAL_VAR_KIND_BPV);
|
||||
RList *spv_vars = r_anal_var_list (anal, fcn, R_ANAL_VAR_KIND_SPV);
|
||||
r_list_join (list, reg_vars);
|
||||
r_list_join (list, bpv_vars);
|
||||
r_list_join (list, spv_vars);
|
||||
r_list_free (reg_vars);
|
||||
r_list_free (bpv_vars);
|
||||
r_list_free (spv_vars);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
@ -44,3 +44,7 @@ ec ret rgb:d66 # ret opcode
|
||||
ec swi rgb:d66
|
||||
ec trap rgb:d66
|
||||
ec usrcmt rgb:fa6e32 # user comment
|
||||
|
||||
ec func_var rgb:95e6cb
|
||||
ec func_var_type rgb:ffd580
|
||||
ec func_var_addr rgb:f28779
|
||||
|
@ -31,13 +31,11 @@ ec num cyan
|
||||
ec invalid red
|
||||
ec swi cyan
|
||||
ec cmp yellow
|
||||
ec leave gray
|
||||
ec call cyan
|
||||
ec cjmp green
|
||||
ec jmp green
|
||||
ec pop yellow
|
||||
ec linehl rgb:004
|
||||
|
||||
ec graph.true green
|
||||
ec graph.false red
|
||||
ec graph.trufae blue
|
||||
@ -47,3 +45,7 @@ ec graph.box gray
|
||||
ec graph.box2 blue
|
||||
ec graph.box3 gray
|
||||
ec graph.box4 gray
|
||||
|
||||
ec func_var white
|
||||
ec func_var_type blue
|
||||
ec func_var_addr cyan
|
||||
|
@ -54,3 +54,7 @@ ec linehl rgb:1f1f1f
|
||||
# background of the terminal must be #121212
|
||||
# foreground of the terminal must be #5fff5f
|
||||
# xterm -bg rgb:12/12/12 -fg rgb:5f/ff/5f
|
||||
|
||||
ec func_var rgb:ff005f
|
||||
ec func_var_type blue
|
||||
ec func_var_addr rgb:5f87ff
|
||||
|
@ -56,3 +56,7 @@ ec crypto rgb:f72
|
||||
ec floc rgb:777
|
||||
ec invalid red
|
||||
ec linehl rgb:008
|
||||
|
||||
ec func_var yellow . bold
|
||||
ec func_var_type blue . bold
|
||||
ec func_var_addr cyan . bold
|
||||
|
@ -61,3 +61,7 @@ ec ai.write rgb:f0f
|
||||
ec ai.exec rgb:f0f
|
||||
ec ai.seq rgb:f0f
|
||||
ec ai.ascii rgb:f0f
|
||||
|
||||
ec func_var rgb:f0f
|
||||
ec func_var_type rgb:f0f
|
||||
ec func_var_addr rgb:0ff
|
||||
|
@ -47,3 +47,7 @@ ec graph.false rgb:d41
|
||||
ec graph.trufae rgb:4cf
|
||||
ec graph.current rgb:af2
|
||||
ec graph.traced rgb:090
|
||||
|
||||
ec func_var rgb:fcc
|
||||
ec func_var_type rgb:f2a
|
||||
ec func_var_addr white
|
||||
|
@ -42,3 +42,7 @@ ec graph.false rgb:e33
|
||||
ec graph.trufae rgb:28d
|
||||
ec graph.current rgb:0ff
|
||||
ec graph.traced rgb:e33
|
||||
|
||||
ec func_var rgb:d38
|
||||
ec func_var_type blue
|
||||
ec func_var_addr rgb:bbb
|
||||
|
@ -43,3 +43,7 @@ ec graph.false rgb:035
|
||||
ec graph.trufae rgb:06c
|
||||
ec graph.current rgb:99a
|
||||
ec graph.traced rgb:bbb
|
||||
|
||||
ec func_var rgb:99a
|
||||
ec func_var_type rgb:636
|
||||
ec func_var_addr rgb:366
|
||||
|
@ -44,3 +44,7 @@ ec graph.true rgb:009100
|
||||
ec graph.false rgb:bc0000
|
||||
ec graph.trufae rgb:0043cb
|
||||
ec graph.current rgb:fff
|
||||
|
||||
ec func_var rgb:99a
|
||||
ec func_var_type rgb:df077e
|
||||
ec func_var_addr rgb:ababab
|
||||
|
@ -54,3 +54,7 @@ ec gui.dataoffset rgb:ffff00
|
||||
ec gui.background rgb:303030
|
||||
ec gui.alt_background rgb:ffffff
|
||||
ec gui.border rgb:5fd700
|
||||
|
||||
ec func_var rgb:64604f
|
||||
ec func_var_type rgb:00afd7
|
||||
ec func_var_addr rgb:afafaf
|
||||
|
@ -44,3 +44,7 @@ ec graph.false red
|
||||
ec graph.trufae blue
|
||||
ec graph.current blue
|
||||
ec graph.traced red
|
||||
|
||||
ec func_var cyan
|
||||
ec func_var_type rgb:f3f
|
||||
ec func_var_addr white
|
||||
|
@ -48,3 +48,7 @@ ec graph.false rgb:5d5
|
||||
ec graph.trufae rgb:af2
|
||||
ec graph.current rgb:af2
|
||||
ec graph.traced rgb:090
|
||||
|
||||
ec func_var yellow
|
||||
ec func_var_type green
|
||||
ec func_var_addr yellow
|
||||
|
@ -44,3 +44,7 @@ ec graph.false rgb:050
|
||||
ec graph.trufae green
|
||||
ec graph.current green
|
||||
ec graph.traced rgb:060
|
||||
|
||||
ec func_var rgb:060
|
||||
ec func_var_type rgb:383
|
||||
ec func_var_addr rgb:060
|
||||
|
@ -44,3 +44,7 @@ ec graph.true rgb:A6df2E
|
||||
ec graph.false rgb:f92672
|
||||
ec graph.trufae rgb:a398e5
|
||||
ec graph.current rgb:fff
|
||||
|
||||
ec func_var cyan
|
||||
ec func_var_type rgb:a398e5
|
||||
ec func_var_addr rgb:f92672
|
||||
|
@ -46,3 +46,7 @@ ec gui.dataoffset rgb:f72
|
||||
ec crypto rgb:f72
|
||||
ec floc rgb:777
|
||||
ec linehl rgb:111
|
||||
|
||||
ec func_var rgb:f72
|
||||
ec func_var_type rgb:777
|
||||
ec func_var_addr rgb:555
|
||||
|
@ -52,3 +52,7 @@ ec gui.background black
|
||||
## ai.ascii
|
||||
## gui.alt_background
|
||||
## gui.border
|
||||
|
||||
ec func_var rgb:72d
|
||||
ec func_var_type blue
|
||||
ec func_var_addr rgb:72d
|
||||
|
@ -48,3 +48,7 @@ ec graph.false red
|
||||
ec graph.trufae green
|
||||
ec graph.current green
|
||||
ec graph.traced yellow
|
||||
|
||||
ec func_var green
|
||||
ec func_var_type red
|
||||
ec func_var_addr yellow
|
||||
|
@ -45,3 +45,7 @@ ec graph.box rgb:431
|
||||
ec graph.box2 rgb:ca6
|
||||
ec graph.box3 rgb:ca6
|
||||
ec graph.box4 rgb:ca6
|
||||
|
||||
ec func_var rgb:fd9
|
||||
ec func_var_type rgb:850
|
||||
ec func_var_addr rgb:960
|
||||
|
@ -45,3 +45,7 @@ ec graph.true rgb:9c4
|
||||
ec graph.false rgb:d66
|
||||
ec graph.trufae rgb:9c4
|
||||
ec graph.current rgb:fff
|
||||
|
||||
ec func_var rgb:9df
|
||||
ec func_var_type rgb:fd6
|
||||
ec func_var_addr rgb:bb5
|
||||
|
@ -44,5 +44,9 @@ ec graph.trufae rgb:899
|
||||
ec graph.current rgb:f00
|
||||
ec graph.traced red
|
||||
|
||||
ec func_var rgb:28d
|
||||
ec func_var_type rgb:cc8
|
||||
ec func_var_addr rgb:9aa
|
||||
|
||||
# background of the terminal must be 134 o 033
|
||||
# xterm -fn 10x20 -bg rgb:00/30/30 -fg rgb:e0/e0/e0 -e "r2 -c 'eco solarized' /bin/ls"
|
||||
|
@ -61,3 +61,7 @@ ec graph.box rgb:950
|
||||
ec graph.box2 rgb:7d1
|
||||
ec graph.box3 rgb:950
|
||||
ec graph.box4 rgb:950
|
||||
|
||||
ec func_var rgb:370
|
||||
ec func_var_type rgb:a41
|
||||
ec func_var_addr rgb:aaa
|
||||
|
@ -47,3 +47,7 @@ ec graph.box rgb:9b7
|
||||
ec graph.box2 rgb:b97
|
||||
ec graph.box3 rgb:b97
|
||||
ec graph.box4 rgb:b97
|
||||
|
||||
ec func_var rgb:c64
|
||||
ec func_var_type rgb:aa6
|
||||
ec func_var_addr rgb:788
|
||||
|
@ -42,3 +42,7 @@ ec graph.false red
|
||||
ec graph.trufae blue
|
||||
ec graph.current rgb:0ff
|
||||
ec graph.traced red
|
||||
|
||||
ec func_var magenta
|
||||
ec func_var_type blue
|
||||
ec func_var_addr magenta
|
||||
|
@ -56,3 +56,7 @@ ec gui.dataoffset yellow
|
||||
ec gui.background black
|
||||
ec gui.alt_background white
|
||||
ec gui.border black
|
||||
|
||||
ec func_var rgb:0cf
|
||||
ec func_var_type rgb:0c0
|
||||
ec func_var_addr rgb:366
|
||||
|
@ -47,3 +47,7 @@ ec graph.false rgb:d52
|
||||
ec graph.trufae rgb:aaa
|
||||
ec graph.current blue
|
||||
ec graph.traced red
|
||||
|
||||
ec func_var rgb:7a7
|
||||
ec func_var_type rgb:eec
|
||||
ec func_var_addr rgb:aaa
|
||||
|
@ -47,9 +47,9 @@ static struct {
|
||||
{ "creg", r_offsetof (RConsPrintablePalette, creg), r_offsetof (RConsPalette, creg) },
|
||||
{ "num", r_offsetof (RConsPrintablePalette, num), r_offsetof (RConsPalette, num) },
|
||||
{ "mov", r_offsetof (RConsPrintablePalette, mov), r_offsetof (RConsPalette, mov) },
|
||||
{ "func_arg", r_offsetof (RConsPrintablePalette, func_arg), r_offsetof (RConsPalette, func_arg) },
|
||||
{ "func_arg_type", r_offsetof (RConsPrintablePalette, func_arg_type), r_offsetof (RConsPalette, func_arg_type) },
|
||||
{ "func_arg_addr", r_offsetof (RConsPrintablePalette, func_arg_addr), r_offsetof (RConsPalette, func_arg_addr) },
|
||||
{ "func_var", r_offsetof (RConsPrintablePalette, func_var), r_offsetof (RConsPalette, func_var) },
|
||||
{ "func_var_type", r_offsetof (RConsPrintablePalette, func_var_type), r_offsetof (RConsPalette, func_var_type) },
|
||||
{ "func_var_addr", r_offsetof (RConsPrintablePalette, func_var_addr), r_offsetof (RConsPalette, func_var_addr) },
|
||||
|
||||
{ "ai.read", r_offsetof (RConsPrintablePalette, ai_read), r_offsetof (RConsPalette, ai_read) },
|
||||
{ "ai.write", r_offsetof (RConsPrintablePalette, ai_write), r_offsetof (RConsPalette, ai_write) },
|
||||
@ -169,9 +169,9 @@ R_API void r_cons_pal_init() {
|
||||
cons->cpal.wordhl = (RColor) RColor_BGRED;
|
||||
cons->cpal.linehl = (RColor) RCOLOR (ALPHA_BG, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00);
|
||||
|
||||
cons->cpal.func_arg = (RColor) RColor_WHITE;
|
||||
cons->cpal.func_arg_type = (RColor) RColor_BLUE;
|
||||
cons->cpal.func_arg_addr = (RColor) RColor_CYAN;
|
||||
cons->cpal.func_var = (RColor) RColor_WHITE;
|
||||
cons->cpal.func_var_type = (RColor) RColor_BLUE;
|
||||
cons->cpal.func_var_addr = (RColor) RColor_CYAN;
|
||||
|
||||
cons->cpal.graph_box = (RColor) RColor_NULL;
|
||||
cons->cpal.graph_box2 = (RColor) RColor_BLUE;
|
||||
|
@ -225,7 +225,7 @@ static void type_match(RCore *core, ut64 addr, char *fcn_name, ut64 baddr, const
|
||||
// Match type from function param to instr
|
||||
if (type_pos_hit (anal, trace, in_stack, j, size, place)) {
|
||||
if (!cmt_set && type && name) {
|
||||
r_meta_set_string (anal, R_META_TYPE_COMMENT, instr_addr,
|
||||
r_meta_set_string (anal, R_META_TYPE_VARTYPE, instr_addr,
|
||||
sdb_fmt ("%s%s%s", type, r_str_endswith (type, "*") ? "" : " ", name));
|
||||
cmt_set = true;
|
||||
}
|
||||
|
@ -5335,7 +5335,7 @@ static bool cmd_anal_refs(RCore *core, const char *input) {
|
||||
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);
|
||||
core->cons->pal.reg, core->cons->pal.num, false, fcn ? fcn->addr : 0);
|
||||
} else {
|
||||
buf_asm = r_str_new (str);
|
||||
}
|
||||
@ -5364,6 +5364,7 @@ static bool cmd_anal_refs(RCore *core, const char *input) {
|
||||
RAnalRef *ref;
|
||||
RListIter *iter;
|
||||
char *space = strchr (input, ' ');
|
||||
RAnalFunction * fcn = r_anal_get_fcn_in (core->anal, addr, 0);
|
||||
|
||||
if (space) {
|
||||
addr = r_num_math (core->num, space + 1);
|
||||
@ -5373,7 +5374,6 @@ static bool cmd_anal_refs(RCore *core, const char *input) {
|
||||
if (input[1] == '.') { // axf.
|
||||
list = list_ = r_anal_xrefs_get_from (core->anal, addr);
|
||||
if (!list) {
|
||||
RAnalFunction * fcn = r_anal_get_fcn_in (core->anal, addr, 0);
|
||||
list = r_anal_fcn_get_refs (core->anal, fcn);
|
||||
}
|
||||
} else {
|
||||
@ -5412,7 +5412,7 @@ static bool cmd_anal_refs(RCore *core, const char *input) {
|
||||
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);
|
||||
core->cons->pal.reg, core->cons->pal.num, false, fcn ? fcn->addr : 0);
|
||||
} else {
|
||||
buf_asm = r_str_new (str);
|
||||
}
|
||||
|
@ -1091,7 +1091,7 @@ static void print_rop(RCore *core, RList *hitlist, char mode, bool *json_first)
|
||||
r_cons_printf ("%s\n", opstr);
|
||||
} else if (colorize) {
|
||||
buf_asm = r_print_colorize_opcode (core->print, asmop.buf_asm,
|
||||
core->cons->pal.reg, core->cons->pal.num, false);
|
||||
core->cons->pal.reg, core->cons->pal.num, false, 0);
|
||||
r_cons_printf (" %s%s;", buf_asm, Color_RESET);
|
||||
free (buf_asm);
|
||||
} else {
|
||||
@ -1128,7 +1128,7 @@ static void print_rop(RCore *core, RList *hitlist, char mode, bool *json_first)
|
||||
}
|
||||
if (colorize) {
|
||||
buf_asm = r_print_colorize_opcode (core->print, asmop.buf_asm,
|
||||
core->cons->pal.reg, core->cons->pal.num, false);
|
||||
core->cons->pal.reg, core->cons->pal.num, false, 0);
|
||||
otype = r_print_color_op_type (core->print, analop.type);
|
||||
if (comment) {
|
||||
r_cons_printf (" 0x%08"PFMT64x " %18s%s %s%s ; %s\n",
|
||||
|
@ -1390,9 +1390,9 @@ static int autocomplete(RLine *line) {
|
||||
ADDARG("creg")
|
||||
ADDARG("num")
|
||||
ADDARG("mov")
|
||||
ADDARG("func_arg")
|
||||
ADDARG("func_arg_type")
|
||||
ADDARG("func_arg_addr")
|
||||
ADDARG("func_var")
|
||||
ADDARG("func_var_type")
|
||||
ADDARG("func_var_addr")
|
||||
ADDARG("ai.read")
|
||||
ADDARG("ai.write")
|
||||
ADDARG("ai.exec")
|
||||
@ -1867,6 +1867,14 @@ static int mywrite(const ut8 *buf, int len) {
|
||||
return r_cons_memcat ((const char *)buf, len);
|
||||
}
|
||||
|
||||
static bool exists_var(RPrint *print, ut64 func_addr, char *str) {
|
||||
char *name_key = sdb_fmt ("var.0x%"PFMT64x ".%d.%s", func_addr, 1, str);
|
||||
if (sdb_const_get_len (((RCore*)(print->user))->anal->sdb_fcns, name_key, NULL, 0)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool r_core_anal_log(struct r_anal_t *anal, const char *msg) {
|
||||
RCore *core = anal->user;
|
||||
if (core->cfglog) {
|
||||
@ -2028,6 +2036,7 @@ R_API bool r_core_init(RCore *core) {
|
||||
core->print->cb_printf = r_cons_printf;
|
||||
core->print->cb_color = r_cons_rainbow_get;
|
||||
core->print->write = mywrite;
|
||||
core->print->exists_var = exists_var;
|
||||
core->print->disasm = __disasm;
|
||||
core->print->colorfor = (RPrintColorFor)r_core_anal_optype_colorfor;
|
||||
core->print->hasrefs = (RPrintColorFor)r_core_anal_hasrefs;
|
||||
|
@ -211,9 +211,9 @@ typedef struct {
|
||||
const char *color_gui_alt_background;
|
||||
const char *color_gui_border;
|
||||
const char *color_linehl;
|
||||
const char *color_func_arg;
|
||||
const char *color_func_arg_type;
|
||||
const char *color_func_arg_addr;
|
||||
const char *color_func_var;
|
||||
const char *color_func_var_type;
|
||||
const char *color_func_var_addr;
|
||||
|
||||
RFlagItem *lastflag;
|
||||
RAnalHint *hint;
|
||||
@ -561,9 +561,9 @@ static RDisasmState * ds_init(RCore *core) {
|
||||
ds->color_gui_alt_background = P(gui_alt_background): Color_GRAY;
|
||||
ds->color_gui_border = P(gui_border): Color_BGGRAY;
|
||||
ds->color_linehl = P(linehl): Color_BGBLUE;
|
||||
ds->color_func_arg = P(func_arg): Color_WHITE;
|
||||
ds->color_func_arg_type = P(func_arg_type): Color_BLUE;
|
||||
ds->color_func_arg_addr = P(func_arg_addr): Color_CYAN;
|
||||
ds->color_func_var = P(func_var): Color_WHITE;
|
||||
ds->color_func_var_type = P(func_var_type): Color_BLUE;
|
||||
ds->color_func_var_addr = P(func_var_addr): Color_CYAN;
|
||||
|
||||
ds->immstr = r_config_get_i (core->config, "asm.imm.str");
|
||||
ds->immtrim = r_config_get_i (core->config, "asm.imm.trim");
|
||||
@ -578,7 +578,7 @@ static RDisasmState * ds_init(RCore *core) {
|
||||
ds->asm_anal = r_config_get_i (core->config, "asm.anal");
|
||||
ds->show_color = r_config_get_i (core->config, "scr.color");
|
||||
ds->show_color_bytes = r_config_get_i (core->config, "scr.color.bytes"); // maybe rename to asm.color.bytes
|
||||
ds->show_color_args = r_config_get_i (core->config, "scr.color.args");
|
||||
ds->show_color_args = r_config_get_i (core->config, "scr.color.args");
|
||||
ds->colorop = r_config_get_i (core->config, "scr.color.ops"); // XXX confusing name // asm.color.inst (mnemonic + operands) ?
|
||||
ds->show_utf8 = r_config_get_i (core->config, "scr.utf8");
|
||||
ds->acase = r_config_get_i (core->config, "asm.ucase");
|
||||
@ -850,6 +850,7 @@ static char *colorize_asm_string(RCore *core, RDisasmState *ds, bool print_color
|
||||
char *source = ds->opstr? ds->opstr: ds->asmop.buf_asm;
|
||||
char *hlstr = r_meta_get_string (ds->core->anal, R_META_TYPE_HIGHLIGHT, ds->at);
|
||||
bool partial_reset = line_highlighted (ds) ? true : ((hlstr && *hlstr) ? true : false);
|
||||
RAnalFunction *f = ds->show_color_args ? fcnIn (ds, ds->vat, R_ANAL_FCN_TYPE_NULL) : NULL;
|
||||
|
||||
if (!ds->show_color || !ds->colorop) {
|
||||
return strdup (source);
|
||||
@ -864,9 +865,9 @@ static char *colorize_asm_string(RCore *core, RDisasmState *ds, bool print_color
|
||||
char *scol1, *s1 = r_str_ndup (source, spacer - source);
|
||||
char *scol2, *s2 = strdup (spacer + 2);
|
||||
|
||||
scol1 = r_print_colorize_opcode (ds->core->print, s1, ds->color_reg, ds->color_num, partial_reset);
|
||||
scol1 = r_print_colorize_opcode (ds->core->print, s1, ds->color_reg, ds->color_num, partial_reset, f ? f->addr : 0);
|
||||
free (s1);
|
||||
scol2 = r_print_colorize_opcode (ds->core->print, s2, ds->color_reg, ds->color_num, partial_reset);
|
||||
scol2 = r_print_colorize_opcode (ds->core->print, s2, ds->color_reg, ds->color_num, partial_reset, f ? f->addr : 0);
|
||||
free (s2);
|
||||
if (!scol1) {
|
||||
scol1 = strdup ("");
|
||||
@ -882,7 +883,7 @@ static char *colorize_asm_string(RCore *core, RDisasmState *ds, bool print_color
|
||||
return source;
|
||||
}
|
||||
|
||||
return r_print_colorize_opcode (ds->core->print, source, ds->color_reg, ds->color_num, partial_reset);
|
||||
return r_print_colorize_opcode (ds->core->print, source, ds->color_reg, ds->color_num, partial_reset, f ? f->addr : 0);
|
||||
}
|
||||
|
||||
static bool ds_must_strip(RDisasmState *ds) {
|
||||
@ -1196,7 +1197,7 @@ static void ds_show_xrefs(RDisasmState *ds) {
|
||||
RFlagItem *f, *next_f;
|
||||
r_list_foreach (xrefs, iter, refi) {
|
||||
if (refi->at == ds->at) {
|
||||
fun = fcnIn (ds, refi->addr, -1);
|
||||
fun = fcnIn (ds, refi->addr, -1);
|
||||
if (fun) {
|
||||
if (iter != xrefs->tail) {
|
||||
ut64 next_addr = ((RAnalRef *)(iter->n->data))->addr;
|
||||
@ -1399,10 +1400,10 @@ static ut32 tmp_get_realsize (RAnalFunction *f) {
|
||||
static void ds_show_functions_argvar(RDisasmState *ds, RAnalVar *var, const char *base, bool is_var, char sign) {
|
||||
int delta = sign == '+' ? var->delta : -var->delta;
|
||||
const char *pfx = is_var ? "var" : "arg";
|
||||
r_cons_printf ("%s%s %s%s%s%s %s@ %s%c0x%x", COLOR_ARG (ds, color_func_arg), pfx,
|
||||
COLOR_ARG (ds, color_func_arg_type), var->type,
|
||||
r_cons_printf ("%s%s %s%s%s%s %s@ %s%c0x%x", COLOR_ARG (ds, color_func_var), pfx,
|
||||
COLOR_ARG (ds, color_func_var_type), var->type,
|
||||
r_str_endswith (var->type, "*") ? "" : " ",
|
||||
var->name, COLOR_ARG (ds, color_func_arg_addr), base, sign, delta);
|
||||
var->name, COLOR_ARG (ds, color_func_var_addr), base, sign, delta);
|
||||
}
|
||||
|
||||
static void printVarSummary(RDisasmState *ds, RList *list) {
|
||||
@ -1661,7 +1662,7 @@ static void ds_show_functions(RDisasmState *ds) {
|
||||
ds_print_offset (ds);
|
||||
r_cons_printf (" ");
|
||||
}
|
||||
r_cons_printf ("%s; ", COLOR (ds, color_other));
|
||||
r_cons_printf ("%s; ", COLOR_ARG (ds, color_func_var));
|
||||
switch (var->kind) {
|
||||
case 'b': {
|
||||
char sign = var->delta > 0 ? '+' : '-';
|
||||
@ -1676,10 +1677,10 @@ static void ds_show_functions(RDisasmState *ds) {
|
||||
eprintf("Register not found");
|
||||
break;
|
||||
}
|
||||
r_cons_printf ("%sarg %s%s%s%s %s@ %s", COLOR_ARG (ds, color_func_arg),
|
||||
COLOR_ARG (ds, color_func_arg_type),
|
||||
r_cons_printf ("%sarg %s%s%s%s %s@ %s", COLOR_ARG (ds, color_func_var),
|
||||
COLOR_ARG (ds, color_func_var_type),
|
||||
var->type, r_str_endswith (var->type, "*") ? "" : " ",
|
||||
var->name, COLOR_ARG (ds, color_func_arg_addr), i->name);
|
||||
var->name, COLOR_ARG (ds, color_func_var_addr), i->name);
|
||||
}
|
||||
break;
|
||||
case 's': {
|
||||
@ -1796,13 +1797,24 @@ static void ds_show_comments_right(RDisasmState *ds) {
|
||||
}
|
||||
//RAnalFunction *f = r_anal_get_fcn_in (core->anal, ds->at, R_ANAL_FCN_TYPE_NULL);
|
||||
item = r_flag_get_i (core->flags, ds->at);
|
||||
ds->comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, ds->at);
|
||||
if (!ds->comment && item && item->comment && *item->comment) {
|
||||
ds->ocomment = item->comment;
|
||||
ds->comment = strdup (item->comment);
|
||||
}
|
||||
if (!ds->comment) {
|
||||
return;
|
||||
char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, ds->at);
|
||||
char *vartype = r_meta_get_string (core->anal, R_META_TYPE_VARTYPE, ds->at);
|
||||
if (!comment) {
|
||||
if (vartype) {
|
||||
ds->comment = r_str_newf ("%s%s", COLOR_ARG (ds, color_func_var_type), vartype);
|
||||
free (vartype);
|
||||
} else if (item && item->comment && *item->comment) {
|
||||
ds->ocomment = item->comment;
|
||||
ds->comment = strdup (item->comment);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else if (vartype) {
|
||||
ds->comment = r_str_newf ("%s%s %s; %s", COLOR_ARG (ds, color_func_var_type), vartype, COLOR (ds, color_usrcmt), comment);
|
||||
free (vartype);
|
||||
free (comment);
|
||||
} else {
|
||||
ds->comment = comment;
|
||||
}
|
||||
maxclen = strlen (ds->comment) + 5;
|
||||
linelen = maxclen;
|
||||
@ -5457,9 +5469,10 @@ R_API int r_core_print_disasm_all(RCore *core, ut64 addr, int l, int len, int mo
|
||||
if (scr_color) {
|
||||
char *buf_asm;
|
||||
RAnalOp aop;
|
||||
RAnalFunction *f = fcnIn (ds, ds->vat, R_ANAL_FCN_TYPE_NULL);
|
||||
r_anal_op (core->anal, &aop, addr, buf+i, l-i, R_ANAL_OP_MASK_ALL);
|
||||
buf_asm = r_print_colorize_opcode (core->print, str,
|
||||
core->cons->pal.reg, core->cons->pal.num, false);
|
||||
core->cons->pal.reg, core->cons->pal.num, false, f ? f : 0);
|
||||
r_cons_printf ("%s%s\n",
|
||||
r_print_color_op_type (core->print, aop.type),
|
||||
buf_asm);
|
||||
@ -5946,9 +5959,10 @@ toro:
|
||||
RAnalOp aop = {
|
||||
0
|
||||
};
|
||||
RAnalFunction *f = r_anal_get_fcn_in (core->anal, core->offset + i, R_ANAL_FCN_TYPE_NULL);
|
||||
r_anal_op (core->anal, &aop, core->offset + i,
|
||||
core->block + addrbytes * i, core->blocksize - addrbytes * i, R_ANAL_OP_MASK_BASIC);
|
||||
asm_str = r_print_colorize_opcode (core->print, asm_str, color_reg, color_num, false);
|
||||
asm_str = r_print_colorize_opcode (core->print, asm_str, color_reg, color_num, false, f ? f->addr : 0);
|
||||
r_cons_printf ("%s%s"Color_RESET "\n",
|
||||
r_print_color_op_type (core->print, aop.type),
|
||||
asm_str);
|
||||
|
@ -58,12 +58,13 @@ static inline char *getformat (RCoreVisualTypes *vt, const char *k) {
|
||||
sdb_fmt ("type.%s", k), 0);
|
||||
}
|
||||
|
||||
static char *colorize_asm_string(RCore *core, const char *buf_asm, int optype) {
|
||||
static char *colorize_asm_string(RCore *core, const char *buf_asm, int optype, ut64 addr) {
|
||||
char *tmp, *spacer = NULL;
|
||||
char *source = (char*)buf_asm;
|
||||
bool use_color = core->print->flags & R_PRINT_FLAGS_COLOR;
|
||||
const char *color_num = core->cons->pal.num;
|
||||
const char *color_reg = core->cons->pal.reg;
|
||||
RAnalFunction* fcn = r_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL);
|
||||
|
||||
if (!use_color) {
|
||||
return strdup (source);
|
||||
@ -73,8 +74,8 @@ static char *colorize_asm_string(RCore *core, const char *buf_asm, int optype) {
|
||||
if (spacer) {
|
||||
char *s1 = r_str_ndup (source, spacer - source);
|
||||
char *s2 = strdup (spacer + 2);
|
||||
char *scol1 = r_print_colorize_opcode (core->print, s1, color_reg, color_num, false);
|
||||
char *scol2 = r_print_colorize_opcode (core->print, s2, color_reg, color_num, false);
|
||||
char *scol1 = r_print_colorize_opcode (core->print, s1, color_reg, color_num, false, fcn ? fcn->addr : 0);
|
||||
char *scol2 = r_print_colorize_opcode (core->print, s2, color_reg, color_num, false, fcn ? fcn->addr : 0);
|
||||
char *source = r_str_newf ("%s||%s", r_str_get2 (scol1), r_str_get2 (scol2));
|
||||
free (scol1);
|
||||
free (scol2);
|
||||
@ -84,7 +85,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 (core->print, source, color_reg, color_num, false);
|
||||
tmp = r_print_colorize_opcode (core->print, source, color_reg, color_num, false, fcn ? fcn->addr : 0);
|
||||
res = r_str_append (res, tmp);
|
||||
free (tmp);
|
||||
return res;
|
||||
@ -156,7 +157,7 @@ R_API bool r_core_visual_esil(RCore *core) {
|
||||
free (res);
|
||||
}
|
||||
{
|
||||
char *op = colorize_asm_string (core, asmop.buf_asm, analopType);
|
||||
char *op = colorize_asm_string (core, asmop.buf_asm, analopType, core->offset);
|
||||
r_cons_printf (Color_RESET"asm: %s\n"Color_RESET, op);
|
||||
free (op);
|
||||
}
|
||||
@ -299,7 +300,7 @@ static bool edit_bits (RCore *core) {
|
||||
r_cons_printf ("shift: >> %d << %d\n", word, (asmop.size * 8) - word - 1);
|
||||
}
|
||||
{
|
||||
char *op = colorize_asm_string (core, asmop.buf_asm, analopType);
|
||||
char *op = colorize_asm_string (core, asmop.buf_asm, analopType, core->offset);
|
||||
r_cons_printf (Color_RESET"asm: %s\n"Color_RESET, op);
|
||||
free (op);
|
||||
}
|
||||
|
@ -335,6 +335,7 @@ enum {
|
||||
R_META_TYPE_COMMENT = 'C',
|
||||
R_META_TYPE_RUN = 'r',
|
||||
R_META_TYPE_HIGHLIGHT = 'H',
|
||||
R_META_TYPE_VARTYPE = 't',
|
||||
};
|
||||
|
||||
// anal
|
||||
|
@ -207,9 +207,9 @@ typedef struct r_cons_palette_t {
|
||||
RColor gui_border;
|
||||
RColor wordhl;
|
||||
RColor linehl;
|
||||
RColor func_arg;
|
||||
RColor func_arg_type;
|
||||
RColor func_arg_addr;
|
||||
RColor func_var;
|
||||
RColor func_var_type;
|
||||
RColor func_var_addr;
|
||||
|
||||
/* Graph colors */
|
||||
RColor graph_box;
|
||||
@ -275,9 +275,9 @@ typedef struct r_cons_printable_palette_t {
|
||||
char *gui_border;
|
||||
char *wordhl;
|
||||
char *linehl;
|
||||
char *func_arg;
|
||||
char *func_arg_type;
|
||||
char *func_arg_addr;
|
||||
char *func_var;
|
||||
char *func_var_type;
|
||||
char *func_var_addr;
|
||||
|
||||
/* graph colors */
|
||||
char *graph_box;
|
||||
|
@ -85,11 +85,13 @@ typedef struct r_print_t {
|
||||
RReg *reg;
|
||||
RRegItem* (*get_register)(RReg *reg, const char *name, int type);
|
||||
ut64 (*get_register_value)(RReg *reg, RRegItem *item);
|
||||
bool (*exists_var)(struct RPrint *print, ut64 func_addr, char *str);
|
||||
ut64* lines_cache;
|
||||
int lines_cache_sz;
|
||||
int lines_abs;
|
||||
bool esc_bslash;
|
||||
const char *strconv_mode;
|
||||
RList *vars;
|
||||
|
||||
// when true it uses row_offsets
|
||||
bool calc_row_offsets;
|
||||
@ -174,7 +176,7 @@ 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(RPrint *print, char *p, const char *reg, const char *num, bool partial_reset);
|
||||
R_API char * r_print_colorize_opcode(RPrint *print, char *p, const char *reg, const char *num, bool partial_reset, ut64 func_addr);
|
||||
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);
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
#define DFLT_ROWS 16
|
||||
|
||||
#define IS_ALPHA(C) (((C) >= 'a' && (C) <= 'z') || ((C) >= 'A' && (C) <= 'Z'))
|
||||
|
||||
static void nullprinter(const char *a, ...) { }
|
||||
static void libc_printf(const char *format, ...) {
|
||||
va_list ap;
|
||||
@ -1629,11 +1631,24 @@ static bool issymbol(char c) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool check_arg_name (RPrint *print, char *p, ut64 func_addr) {
|
||||
if (func_addr && print->exists_var) {
|
||||
int z;
|
||||
for (z = 0; p[z] && (IS_ALPHA (p[z]) || IS_DIGIT (p[z]) || p[z] == '_'); z++);
|
||||
char tmp = p[z];
|
||||
p[z] = '\0';
|
||||
bool ret = print->exists_var (print, func_addr, p);
|
||||
p[z] = tmp;
|
||||
return ret;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool ishexprefix(char *p) {
|
||||
return (p[0] == '0' && p[1] == 'x');
|
||||
}
|
||||
|
||||
R_API char* r_print_colorize_opcode(RPrint *print, char *p, const char *reg, const char *num, bool partial_reset) {
|
||||
R_API char* r_print_colorize_opcode(RPrint *print, char *p, const char *reg, const char *num, bool partial_reset, ut64 func_addr) {
|
||||
int i, j, k, is_mod, is_float = 0, is_arg = 0;
|
||||
char *reset = partial_reset ? Color_RESET_NOBG : Color_RESET;
|
||||
ut32 c_reset = strlen (reset);
|
||||
@ -1709,17 +1724,20 @@ R_API char* r_print_colorize_opcode(RPrint *print, char *p, const char *reg, con
|
||||
eprintf ("r_print_colorize_opcode(): buffer overflow!\n");
|
||||
return strdup (p);
|
||||
}
|
||||
|
||||
bool found_var = check_arg_name (print, p + i + 1, func_addr);
|
||||
strcpy (o + j, reset);
|
||||
j += strlen (reset);
|
||||
o[j] = p[i];
|
||||
if (!(p[i+1] == '$' || ((p[i+1] > '0') && (p[i+1] < '9')))) {
|
||||
ut32 reg_len = strlen (reg);
|
||||
if (reg_len + j + 10 >= COLORIZE_BUFSIZE) {
|
||||
char *color = found_var ? print->cons->pal.func_var_type : reg;
|
||||
ut32 color_len = strlen (color);
|
||||
if (color_len + j + 10 >= COLORIZE_BUFSIZE) {
|
||||
eprintf ("r_print_colorize_opcode(): buffer overflow!\n");
|
||||
return strdup (p);
|
||||
}
|
||||
strcpy (o + j + 1, reg);
|
||||
j += strlen (reg);
|
||||
strcpy (o + j + 1, color);
|
||||
j += strlen (color);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user