Initial implementation of scr.rainbow for disasm and hexdump

This commit is contained in:
pancake 2017-08-31 01:11:34 +02:00
parent f40ca6d5cd
commit 7d4db495eb
7 changed files with 36 additions and 1 deletions

View File

@ -308,6 +308,7 @@ R_API RCons *r_cons_new() {
if (I.refcnt != 1) { if (I.refcnt != 1) {
return &I; return &I;
} }
I.rgbstr = r_cons_rgb_str_off;
I.line = r_line_new (); I.line = r_line_new ();
I.highlight = NULL; I.highlight = NULL;
I.event_interrupt = NULL; I.event_interrupt = NULL;

View File

@ -144,7 +144,14 @@ R_API int r_cons_rgb_parse(const char *p, ut8 *r, ut8 *g, ut8 *b, int *is_bg) {
return 1; return 1;
} }
R_API char *r_cons_rgb_str (char *outstr, ut8 r, ut8 g, ut8 b, int is_bg) { R_API char *r_cons_rgb_str_off(char *outstr, ut64 off) {
const int r = (off >> 4) & 0xff;
const int g = (off >> 7) & 0xff;
const int b = (off >> 10) & 0xff;
return r_cons_rgb_str (outstr, r, g, b, false);
}
R_API char *r_cons_rgb_str(char *outstr, ut8 r, ut8 g, ut8 b, int is_bg) {
int fgbg = is_bg ? 48: 38; int fgbg = is_bg ? 48: 38;
if (!outstr) outstr = malloc (32); if (!outstr) outstr = malloc (32);
if (!outstr) return NULL; if (!outstr) return NULL;

View File

@ -291,6 +291,18 @@ static int cb_asmminvalsub(void *user, void *data) {
return true; return true;
} }
static int cb_scrrainbow(void *user, void *data) {
RCore *core = (RCore *) user;
RConfigNode *node = (RConfigNode *) data;
if (node->i_value) {
core->print->flags |= R_PRINT_FLAGS_RAINBOW;
} else {
core->print->flags &= (~R_PRINT_FLAGS_RAINBOW);
}
r_print_set_flags (core->print, core->print->flags);
return true;
}
static int cb_asmsecsub(void *user, void *data) { static int cb_asmsecsub(void *user, void *data) {
RCore *core = (RCore *) user; RCore *core = (RCore *) user;
RConfigNode *node = (RConfigNode *) data; RConfigNode *node = (RConfigNode *) data;
@ -2170,6 +2182,7 @@ R_API int r_core_config_init(RCore *core) {
SETPREF ("asm.middle", "false", "Allow disassembling jumps in the middle of an instruction"); SETPREF ("asm.middle", "false", "Allow disassembling jumps in the middle of an instruction");
SETPREF ("asm.noisy", "true", "Show comments considered noisy but possibly useful"); SETPREF ("asm.noisy", "true", "Show comments considered noisy but possibly useful");
SETPREF ("asm.offset", "true", "Show offsets at disassembly"); SETPREF ("asm.offset", "true", "Show offsets at disassembly");
SETCB ("scr.rainbow", "true", &cb_scrrainbow, "Shows rainbow colors depending of address");
SETPREF ("asm.reloff", "false", "Show relative offsets instead of absolute address in disasm"); SETPREF ("asm.reloff", "false", "Show relative offsets instead of absolute address in disasm");
SETPREF ("asm.reloff.flags", "false", "Show relative offsets to flags (not only functions)"); SETPREF ("asm.reloff.flags", "false", "Show relative offsets to flags (not only functions)");
SETPREF ("asm.section", "false", "Show section name before offset"); SETPREF ("asm.section", "false", "Show section name before offset");

View File

@ -5413,7 +5413,11 @@ R_API void r_print_offset(RPrint *p, ut64 off, int invert, int offseg, int offde
const char *white; const char *white;
bool show_color = p->flags & R_PRINT_FLAGS_COLOR; bool show_color = p->flags & R_PRINT_FLAGS_COLOR;
if (show_color) { if (show_color) {
char rgbstr[32];
const char *k = r_cons_singleton ()->pal.offset; // TODO etooslow. must cache const char *k = r_cons_singleton ()->pal.offset; // TODO etooslow. must cache
if (p->flags & R_PRINT_FLAGS_RAINBOW) {
k = r_cons_rgb_str_off (rgbstr, off);
}
if (invert) { if (invert) {
r_cons_invert (true, true); r_cons_invert (true, true);
} }

View File

@ -347,6 +347,7 @@ typedef struct r_cons_t {
bool use_color; bool use_color;
bool use_tts; bool use_tts;
bool filter; bool filter;
char* (*rgbstr)(char *str, ut64 addr);
} RCons; } RCons;
// XXX THIS MUST BE A SINGLETON AND WRAPPED INTO RCons */ // XXX THIS MUST BE A SINGLETON AND WRAPPED INTO RCons */
@ -611,6 +612,7 @@ R_API void r_cons_rgb(ut8 r, ut8 g, ut8 b, int is_bg);
R_API void r_cons_rgb_fgbg(ut8 r, ut8 g, ut8 b, ut8 R, ut8 G, ut8 B); R_API void r_cons_rgb_fgbg(ut8 r, ut8 g, ut8 b, ut8 R, ut8 G, ut8 B);
R_API void r_cons_rgb_init(void); R_API void r_cons_rgb_init(void);
R_API char *r_cons_rgb_str(char *outstr, ut8 r, ut8 g, ut8 b, int is_bg); R_API char *r_cons_rgb_str(char *outstr, ut8 r, ut8 g, ut8 b, int is_bg);
R_API char *r_cons_rgb_str_off(char *outstr, ut64 off);
R_API void r_cons_color(int fg, int r, int g, int b); R_API void r_cons_color(int fg, int r, int g, int b);
R_API char *r_cons_color_random(int bg); R_API char *r_cons_color_random(int bg);
R_API char *r_cons_color_random_string(int bg); R_API char *r_cons_color_random_string(int bg);

View File

@ -25,6 +25,7 @@ extern "C" {
#define R_PRINT_FLAGS_COMPACT 0x00000800 #define R_PRINT_FLAGS_COMPACT 0x00000800
#define R_PRINT_FLAGS_NONHEX 0x00001000 #define R_PRINT_FLAGS_NONHEX 0x00001000
#define R_PRINT_FLAGS_SECSUB 0x00002000 #define R_PRINT_FLAGS_SECSUB 0x00002000
#define R_PRINT_FLAGS_RAINBOW 0x00004000
typedef int (*RPrintZoomCallback)(void *user, int mode, ut64 addr, ut8 *bufz, ut64 size); typedef int (*RPrintZoomCallback)(void *user, int mode, ut64 addr, ut8 *bufz, ut64 size);
typedef const char *(*RPrintNameCallback)(void *user, ut64 addr); typedef const char *(*RPrintNameCallback)(void *user, ut64 addr);

View File

@ -370,6 +370,13 @@ R_API void r_print_addr(RPrint *p, ut64 addr) {
if (use_color) { if (use_color) {
const char *pre = PREOFF (offset): Color_GREEN; const char *pre = PREOFF (offset): Color_GREEN;
const char *fin = Color_RESET; const char *fin = Color_RESET;
if (p->flags & R_PRINT_FLAGS_RAINBOW) {
// pre = r_cons_rgb_str_off (rgbstr, addr);
if (p && p->cons && p->cons->rgbstr) {
char rgbstr[32];
pre = p->cons->rgbstr (rgbstr, addr);
}
}
if (dec) { if (dec) {
printfmt ("%s%s%" PFMT64d "%s%c", pre, white, addr, fin, ch); printfmt ("%s%s%" PFMT64d "%s%c", pre, white, addr, fin, ch);
} else { } else {