Skip to content

Commit

Permalink
Honor scr.color and use red for invalid bits in aobv ##visual
Browse files Browse the repository at this point in the history
  • Loading branch information
radare authored and trufae committed Nov 26, 2024
1 parent a58cb44 commit 319bce7
Showing 1 changed file with 17 additions and 30 deletions.
47 changes: 17 additions & 30 deletions libr/core/cmd_anal.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6328,26 +6328,14 @@ static bool reg_name_roll_set(RCore *core, const char *name, ut64 n) {

// XXX dup from drp :OOO
void cmd_anal_reg(RCore *core, const char *str) {
#if 0
if (0) {
/* enable this block when dr and ar use the same code but just using
core->dbg->reg or core->anal->reg and removing all the debugger
dependent code */
RReg *reg = core->dbg->reg;
core->dbg->reg = core->anal->reg;
cmd_debug_reg (core, str);
core->dbg->reg = reg;
return;
}
#endif
int size = 0, i, type = R_REG_TYPE_GPR;
int use_colors = r_config_get_i (core->config, "scr.color");
const char *use_color = NULL;
const char *name;
char *arg;
char *save_ptr = NULL;

if (use_colors) {
if (use_colors > 0) {
#define ConsP(x) (core->cons && core->cons->context->pal.x)? core->cons->context->pal.x
use_color = ConsP (creg) : Color_BWHITE;
}
Expand Down Expand Up @@ -9118,13 +9106,12 @@ static const char guess_arg(int n, const char *arg) {
return 'r';
}

#define colors_last 6
#define colors_last 5
static const char *colors[colors_last] = {
Color_YELLOW,
Color_CYAN,
Color_YELLOW,
Color_GREEN,
Color_MAGENTA,
Color_RED,
Color_BLUE,
};

Expand All @@ -9141,6 +9128,7 @@ static void cmd_anal_opcode_bits(RCore *core, const char *arg, int mode) {
} else {
r_io_read_at (core->io, core->offset, buf, sizeof (buf));
}
bool use_color = r_config_get_i (core->config, "scr.color") > 0;
RList *args[8];
int i, j;
RAnalOp analop, op;
Expand Down Expand Up @@ -9302,37 +9290,36 @@ static void cmd_anal_opcode_bits(RCore *core, const char *arg, int mode) {
rows++;
}
}
#if 0
for (i = 0; i < rows; i++) {
r_cons_printf ("--> %d %s%d%s\n", i, colors[i], row[i].idx - 1, Color_RESET);
}
#endif
r_cons_printf (" ");
for (p = s; *p; p++) {
int idx = *p - '0';
if (idx < 0 || idx > 7) {
r_cons_printf ("%c", *p);
r_cons_printf (Color_RED"%c"Color_RESET, *p);
continue;
}
const char *color = colors[idx % colors_last];
r_cons_printf ("%s%c%s", color, *p, Color_RESET);
if (use_color) {
const char *color = colors[idx % colors_last];
r_cons_printf ("%s%c%s", color, *p, Color_RESET);
} else {
r_cons_printf ("%c", *p);
}
}
RList *args = mnemonic_tolist (analop.mnemonic);
#if 0
r_cons_printf (" %s\n ", analop.mnemonic);
#else
r_cons_printf (" ");
RListIter *iter;
const char *arg;
int idx = 0;
r_list_foreach (args, iter, arg) {
const char *color = colors[idx % colors_last];
const char *sep = (idx > 0)? ", ": " ";
r_cons_printf ("%s%s%s%s", sep, color, arg, Color_RESET);
if (use_color) {
const char *color = colors[idx % colors_last];
r_cons_printf ("%s%s%s%s", sep, color, arg, Color_RESET);
} else {
r_cons_printf ("%s%s", sep, arg);
}
idx++;
}
r_cons_printf ("\n ");
#endif
int i;
for (i = 0; i < rows; i++) {
int iref = row[i].idx - 1;
Expand Down

0 comments on commit 319bce7

Please sign in to comment.