Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colorize function arguments #10752

Merged
merged 2 commits into from Jul 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions libr/cons/pal.c
Expand Up @@ -47,13 +47,17 @@ 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) },

{ "ai.read", r_offsetof (RConsPrintablePalette, ai_read), r_offsetof (RConsPalette, ai_read) },
{ "ai.write", r_offsetof (RConsPrintablePalette, ai_write), r_offsetof (RConsPalette, ai_write) },
{ "ai.exec", r_offsetof (RConsPrintablePalette, ai_exec), r_offsetof (RConsPalette, ai_exec) },
{ "ai.seq", r_offsetof (RConsPrintablePalette, ai_seq), r_offsetof (RConsPalette, ai_seq) },
{ "ai.ascii", r_offsetof (RConsPrintablePalette, ai_ascii), r_offsetof (RConsPalette, ai_ascii) },


{ "graph.box", r_offsetof (RConsPrintablePalette, graph_box), r_offsetof (RConsPalette, graph_box) },
{ "graph.box2", r_offsetof (RConsPrintablePalette, graph_box2), r_offsetof (RConsPalette, graph_box2) },
{ "graph.box3", r_offsetof (RConsPrintablePalette, graph_box3), r_offsetof (RConsPalette, graph_box3) },
Expand All @@ -71,6 +75,8 @@ static struct {
{ "gui.border", r_offsetof (RConsPrintablePalette, gui_border), r_offsetof (RConsPalette, gui_border) },
{ "wordhl", r_offsetof (RConsPrintablePalette, wordhl), r_offsetof (RConsPalette, wordhl) },
{ "linehl", r_offsetof (RConsPrintablePalette, linehl), r_offsetof (RConsPalette, linehl) },


{ NULL, 0, 0 }
};
static const int keys_len = sizeof (keys) / sizeof (keys[0]) - 1;
Expand Down Expand Up @@ -163,6 +169,10 @@ 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.graph_box = (RColor) RColor_NULL;
cons->cpal.graph_box2 = (RColor) RColor_BLUE;
cons->cpal.graph_box3 = (RColor) RColor_MAGENTA;
Expand Down
1 change: 1 addition & 0 deletions libr/core/cconfig.c
Expand Up @@ -2870,6 +2870,7 @@ R_API int r_core_config_init(RCore *core) {
SETPREF ("scr.zoneflags", "true", "Show zoneflags in visual mode before the title (see fz?)");
SETPREF ("scr.slow", "true", "Do slow stuff on visual mode like RFlag.get_at(true)");
SETPREF ("scr.color.ops", "true", "Colorize numbers and registers in opcodes");
SETPREF ("scr.color.args", "true", "Colorize arguments and variables of functions");
SETPREF ("scr.color.bytes", "true", "Colorize bytes that represent the opcodes of the instruction");
#if __WINDOWS__ && !__CYGWIN__
SETCB ("scr.ansicon", r_str_bool (r_cons_singleton ()->ansicon),
Expand Down
3 changes: 3 additions & 0 deletions libr/core/core.c
Expand Up @@ -1390,6 +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("ai.read")
ADDARG("ai.write")
ADDARG("ai.exec")
Expand Down
20 changes: 16 additions & 4 deletions libr/core/disasm.c
Expand Up @@ -12,6 +12,7 @@
#define R_MIDFLAGS_SYMALIGN 3

#define COLOR(ds, field) (ds->show_color ? ds->field : "")
#define COLOR_ARG(ds, field) (ds->show_color && ds->show_color_args ? ds->field : "")
#define COLOR_CONST(ds, color) (ds->show_color ? Color_ ## color : "")
#define COLOR_RESET(ds) COLOR_CONST(ds, RESET)

Expand Down Expand Up @@ -80,6 +81,7 @@ typedef struct {
bool use_esil;
bool show_color;
bool show_color_bytes;
bool show_color_args;
int colorop;
int acase;
bool capitalize;
Expand Down Expand Up @@ -209,6 +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;

RFlagItem *lastflag;
RAnalHint *hint;
Expand Down Expand Up @@ -556,6 +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->immstr = r_config_get_i (core->config, "asm.imm.str");
ds->immtrim = r_config_get_i (core->config, "asm.imm.trim");
Expand All @@ -570,6 +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->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");
Expand Down Expand Up @@ -1389,8 +1398,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%c0x%x", pfx, var->type, r_str_endswith (var->type, "*") ? "" : " ",
var->name, base, sign, delta);
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_str_endswith (var->type, "*") ? "" : " ",
var->name, COLOR_ARG (ds, color_func_arg_addr), base, sign, delta);
}

static void printVarSummary(RDisasmState *ds, RList *list) {
Expand Down Expand Up @@ -1664,9 +1675,10 @@ static void ds_show_functions(RDisasmState *ds) {
eprintf("Register not found");
break;
}
r_cons_printf ("arg %s%s%s @ %s",
r_cons_printf ("%sarg %s%s%s%s %s@ %s", COLOR_ARG (ds, color_func_arg),
COLOR_ARG (ds, color_func_arg_type),
var->type, r_str_endswith (var->type, "*") ? "" : " ",
var->name, i->name);
var->name, COLOR_ARG (ds, color_func_arg_addr), i->name);
}
break;
case 's': {
Expand Down
6 changes: 6 additions & 0 deletions libr/include/r_cons.h
Expand Up @@ -207,6 +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;

/* Graph colors */
RColor graph_box;
Expand Down Expand Up @@ -272,6 +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;

/* graph colors */
char *graph_box;
Expand Down