mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-26 17:15:38 +00:00
Honor flag colors in 'px' hexdump ##print
This commit is contained in:
parent
45160a5854
commit
3c3bc79ebd
@ -1904,7 +1904,7 @@ static void annotated_hexdump(RCore *core, const char *str, int len) {
|
||||
hascolor = false;
|
||||
if (usecolor) {
|
||||
if (!setcolor) {
|
||||
const char *bytecolor = r_print_byte_color (core->print, ch);
|
||||
const char *bytecolor = r_print_byte_color (core->print, addr + j, ch);
|
||||
if (bytecolor) {
|
||||
append (ebytes, bytecolor);
|
||||
append (echars, bytecolor);
|
||||
@ -6608,7 +6608,7 @@ static int cmd_print(void *data, const char *input) {
|
||||
RFlagItem *f;
|
||||
ut32 v = r_read_ble32 (core->block + i, core->print->big_endian);
|
||||
if (p && p->colorfor) {
|
||||
a = p->colorfor (p->user, v, true);
|
||||
a = p->colorfor (p->user, core->offset + i, v, true);
|
||||
if (a && *a) {
|
||||
b = Color_RESET;
|
||||
} else {
|
||||
@ -6688,7 +6688,7 @@ static int cmd_print(void *data, const char *input) {
|
||||
RFlagItem *f;
|
||||
ut64 v = (ut64) r_read_ble16 (core->block + i, p->big_endian);
|
||||
if (p && p->colorfor) {
|
||||
a = p->colorfor (p->user, v, true);
|
||||
a = p->colorfor (p->user, core->offset + i, v, true);
|
||||
if (a && *a) {
|
||||
b = Color_RESET;
|
||||
} else {
|
||||
@ -6736,7 +6736,7 @@ static int cmd_print(void *data, const char *input) {
|
||||
RFlagItem *f;
|
||||
ut64 v = r_read_ble64 (core->block + i, p->big_endian);
|
||||
if (p && p->colorfor) {
|
||||
a = p->colorfor (p->user, v, true);
|
||||
a = p->colorfor (p->user, core->offset + i, v, true);
|
||||
if (a && *a) {
|
||||
b = Color_RESET;
|
||||
} else {
|
||||
@ -6861,7 +6861,7 @@ static int cmd_print(void *data, const char *input) {
|
||||
r_cons_print (" ");
|
||||
for (j = i; j < len && j < i + cols; j += 1) {
|
||||
ut8 *p = (ut8 *) core->block + j;
|
||||
r_print_byte (core->print, "%c", j, *p);
|
||||
r_print_byte (core->print, core->offset + j, "%c", j, *p);
|
||||
}
|
||||
r_cons_newline ();
|
||||
}
|
||||
|
@ -2325,7 +2325,7 @@ R_API char *r_core_anal_hasrefs_to_depth(RCore *core, ut64 value, PJ *pj, int de
|
||||
}
|
||||
}
|
||||
if (type) {
|
||||
const char *c = r_core_anal_optype_colorfor (core, value, true);
|
||||
const char *c = r_core_anal_optype_colorfor (core, fcn? fcn->addr: value, value, true);
|
||||
const char *cend = (c && *c) ? Color_RESET: "";
|
||||
if (!c) {
|
||||
c = "";
|
||||
@ -2505,21 +2505,25 @@ R_API char *r_core_anal_get_comments(RCore *core, ut64 addr) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
R_API const char *r_core_anal_optype_colorfor(RCore *core, ut64 addr, bool verbose) {
|
||||
static R_TH_LOCAL char *const_color = NULL;
|
||||
|
||||
R_API const char *r_core_anal_optype_colorfor(RCore *core, ut64 addr, ut8 ch, bool verbose) {
|
||||
if (!(core->print->flags & R_PRINT_FLAGS_COLOR)) {
|
||||
return NULL;
|
||||
}
|
||||
if (!r_config_get_i (core->config, "scr.color")) {
|
||||
return NULL;
|
||||
}
|
||||
#if 0
|
||||
// check for flag colors
|
||||
RFlagItem *fi = r_flag_get_i (core->flags, addr);
|
||||
if (fi && fi->color) {
|
||||
return r_cons_pal_parse (fi->color, NULL);
|
||||
//return fi->color;
|
||||
if (!verbose) {
|
||||
// check for flag colors
|
||||
RFlagItem *fi = r_flag_get_at (core->flags, addr, true);
|
||||
if (fi && fi->offset + fi->size >= addr && fi->color) {
|
||||
free (const_color);
|
||||
const_color = r_cons_pal_parse (fi->color, NULL);
|
||||
return const_color;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
ut64 type = r_core_anal_address (core, addr);
|
||||
if (type & R_ANAL_ADDR_TYPE_EXEC) {
|
||||
return core->cons->context->pal.ai_exec; //Color_RED;
|
||||
@ -2684,8 +2688,8 @@ static void __init_autocomplete(RCore* core) {
|
||||
}
|
||||
}
|
||||
|
||||
static const char *colorfor_cb(void *user, ut64 addr, bool verbose) {
|
||||
return r_core_anal_optype_colorfor ((RCore *)user, addr, verbose);
|
||||
static const char *colorfor_cb(void *user, ut64 addr, ut8 ch, bool verbose) {
|
||||
return r_core_anal_optype_colorfor ((RCore *)user, addr, ch, verbose);
|
||||
}
|
||||
|
||||
static char *hasrefs_cb(void *user, ut64 addr, int mode) {
|
||||
|
@ -595,7 +595,7 @@ R_API RAnalOp* r_core_anal_op(RCore *core, ut64 addr, int mask);
|
||||
R_IPI int core_type_by_addr(RCore *core, ut64 addr);
|
||||
R_API void r_core_anal_esil(RCore *core, const char *str, const char *addr);
|
||||
R_API void r_core_anal_fcn_merge(RCore *core, ut64 addr, ut64 addr2);
|
||||
R_API const char *r_core_anal_optype_colorfor(RCore *core, ut64 addr, bool verbose);
|
||||
R_API const char *r_core_anal_optype_colorfor(RCore *core, ut64 addr, ut8 ch, bool verbose);
|
||||
R_API ut64 r_core_anal_address(RCore *core, ut64 addr);
|
||||
R_API void r_core_anal_undefine(RCore *core, ut64 off);
|
||||
R_API void r_core_anal_hint_print(RAnal* a, ut64 addr, int mode);
|
||||
|
@ -72,7 +72,7 @@ typedef const char *(*RPrintNameCallback)(void *user, ut64 addr);
|
||||
typedef int (*RPrintSizeCallback)(void *user, ut64 addr);
|
||||
typedef char *(*RPrintCommentCallback)(void *user, ut64 addr);
|
||||
typedef const char *(*RPrintSectionGet)(void *user, ut64 addr);
|
||||
typedef const char *(*RPrintColorFor)(void *user, ut64 addr, bool verbose);
|
||||
typedef const char *(*RPrintColorFor)(void *user, ut64 addr, ut8 ch, bool verbose);
|
||||
typedef char *(*RPrintHasRefs)(void *user, ut64 addr, int mode);
|
||||
|
||||
typedef struct r_print_zoom_t {
|
||||
@ -195,8 +195,8 @@ R_API void r_print_hexpairs(RPrint *p, ut64 addr, const ut8 *buf, int len);
|
||||
R_API void r_print_hexdiff(RPrint *p, ut64 aa, const ut8* a, ut64 ba, const ut8 *b, int len, int scndcol);
|
||||
R_API void r_print_bytes(RPrint *p, const ut8* buf, int len, const char *fmt);
|
||||
R_API void r_print_fill(RPrint *p, const ut8 *arr, int size, ut64 addr, int step);
|
||||
R_API void r_print_byte(RPrint *p, const char *fmt, int idx, ut8 ch);
|
||||
R_API const char *r_print_byte_color(RPrint *p, int ch);
|
||||
R_API void r_print_byte(RPrint *p, ut64 addr, const char *fmt, int idx, ut8 ch);
|
||||
R_API const char *r_print_byte_color(RPrint *p, ut64 addr, int ch);
|
||||
R_API void r_print_c(RPrint *p, const ut8 *str, int len);
|
||||
R_API void r_print_raw(RPrint *p, ut64 addr, const ut8* buf, int len, int offlines);
|
||||
R_API bool r_print_have_cursor(RPrint *p, int cur, int len);
|
||||
|
@ -610,13 +610,20 @@ R_API char* r_print_hexpair(RPrint *p, const char *str, int n) {
|
||||
|
||||
static char colorbuffer[64];
|
||||
#define P(x) (p->cons && p->cons->context->pal.x)? p->cons->context->pal.x
|
||||
R_API const char *r_print_byte_color(RPrint *p, int ch) {
|
||||
R_API const char *r_print_byte_color(RPrint *p, ut64 addr, int ch) {
|
||||
if (p->flags & R_PRINT_FLAGS_RAINBOW) {
|
||||
// EXPERIMENTAL
|
||||
int bg = (p->flags & R_PRINT_FLAGS_NONHEX)? 48: 38;
|
||||
snprintf (colorbuffer, sizeof (colorbuffer), "\033[%d;5;%dm", bg, ch);
|
||||
return colorbuffer;
|
||||
}
|
||||
// check for flag colors
|
||||
if (p && p->colorfor) {
|
||||
const char *r = p->colorfor (p->user, addr, ch, false);
|
||||
if (r) {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
const bool use_color = p->flags & R_PRINT_FLAGS_COLOR;
|
||||
if (!use_color) {
|
||||
return NULL;
|
||||
@ -630,7 +637,7 @@ R_API const char *r_print_byte_color(RPrint *p, int ch) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
R_API void r_print_byte(RPrint *p, const char *fmt, int idx, ut8 ch) {
|
||||
R_API void r_print_byte(RPrint *p, ut64 addr, const char *fmt, int idx, ut8 ch) {
|
||||
PrintfCallback printfmt = (PrintfCallback) (p? p->cb_printf: libc_printf);
|
||||
#define print(x) printfmt("%s", x)
|
||||
ut8 rch = ch;
|
||||
@ -639,9 +646,9 @@ R_API void r_print_byte(RPrint *p, const char *fmt, int idx, ut8 ch) {
|
||||
}
|
||||
r_print_cursor (p, idx, 1, 1);
|
||||
if (p && p->flags & R_PRINT_FLAGS_COLOR) {
|
||||
const char *bytecolor = r_print_byte_color (p, ch);
|
||||
const char *bytecolor = r_print_byte_color (p, addr, ch);
|
||||
if (bytecolor) {
|
||||
print ( bytecolor);
|
||||
print (bytecolor);
|
||||
}
|
||||
printfmt (fmt, rch);
|
||||
if (bytecolor) {
|
||||
@ -1139,7 +1146,7 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba
|
||||
if (!p->iob.addr_is_mapped (p->iob.io, addr + j)) {
|
||||
a = p->cons->context->pal.ai_unmap;
|
||||
} else {
|
||||
a = p->colorfor (p->user, n, true);
|
||||
a = p->colorfor (p->user, addr, n, true);
|
||||
}
|
||||
if (a && *a) {
|
||||
b = Color_RESET;
|
||||
@ -1158,7 +1165,7 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba
|
||||
}
|
||||
printValue = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (printValue) {
|
||||
if (use_offset && !hasNull && isPxr) {
|
||||
r_print_section (p, at);
|
||||
@ -1218,7 +1225,7 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba
|
||||
char dbl_ch_str[] = { ch, ch, 0 };
|
||||
p->cb_printf ("%s", dbl_ch_str);
|
||||
} else {
|
||||
r_print_byte (p, bytefmt, j, buf[j]);
|
||||
r_print_byte (p, addr + j, bytefmt, j, buf[j]);
|
||||
}
|
||||
if (pairs && !compact && (inc & 1)) {
|
||||
bool mustspace = (rows % 2) ? !(j&1) : (j&1);
|
||||
@ -1263,7 +1270,7 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba
|
||||
bytes = 0;
|
||||
size_t end = i + inc;
|
||||
for (j = i; j < end; j++) {
|
||||
if (j != i && use_align && bytes >= rowbytes) {
|
||||
if (j != i && use_align && bytes >= rowbytes) {
|
||||
int sz = (p && p->offsize)? p->offsize (p->user, addr + j): -1;
|
||||
if (sz >= 0) {
|
||||
print (" ");
|
||||
@ -1285,7 +1292,7 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba
|
||||
ch = '?';
|
||||
}
|
||||
}
|
||||
r_print_byte (p, "%c", j, ch);
|
||||
r_print_byte (p, addr + j, "%c", j, ch);
|
||||
bytes++;
|
||||
}
|
||||
}
|
||||
@ -1337,7 +1344,7 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba
|
||||
if (p && p->offname) {
|
||||
a = p->offname (p->user, addr + j);
|
||||
if (p->colorfor && a && *a) {
|
||||
const char *color = p->colorfor (p->user, addr + j, true);
|
||||
const char *color = p->colorfor (p->user, addr + j, addr + j, true);
|
||||
printfmt ("%s ; %s%s", r_str_get (color), a,
|
||||
color ? Color_RESET : "");
|
||||
}
|
||||
@ -1345,7 +1352,7 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba
|
||||
char *comment = p->get_comments (p->user, addr + j);
|
||||
if (comment) {
|
||||
if (p && p->colorfor) {
|
||||
a = p->colorfor (p->user, addr + j, true);
|
||||
a = p->colorfor (p->user, addr + j, addr +j, true);
|
||||
if (R_STR_ISEMPTY (a)) {
|
||||
a = "";
|
||||
}
|
||||
@ -1599,7 +1606,7 @@ R_API void r_print_c(RPrint *p, const ut8 *str, int len) {
|
||||
"unsigned char buffer[_BUFFER_SIZE] = {\n",
|
||||
len);
|
||||
for (i = 0; !r_print_is_interrupted () && i < len;) {
|
||||
r_print_byte (p, "0x%02x", i, str[i]);
|
||||
r_print_byte (p, (ut64)i, "0x%02x", i, str[i]);
|
||||
if (++i < len) {
|
||||
p->cb_printf (", ");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user