mirror of
https://github.com/radareorg/radare2.git
synced 2024-10-07 10:33:30 +00:00
Fix #6428 - Honor scr.color in ad command
This commit is contained in:
parent
07c77484ba
commit
04ff4a5195
@ -89,7 +89,7 @@ static bool is_bin(const ut8 *buf, int size) {
|
||||
// TODO: add is_flag, is comment?
|
||||
|
||||
// XXX: optimize by removing all strlens here
|
||||
R_API char *r_anal_data_to_string(RAnalData *d) {
|
||||
R_API char *r_anal_data_to_string(RAnalData *d, RConsPalette *pal) {
|
||||
int i, len, idx, mallocsz = 1024;
|
||||
ut32 n32;
|
||||
char *line;
|
||||
@ -101,7 +101,12 @@ R_API char *r_anal_data_to_string(RAnalData *d) {
|
||||
eprintf ("Cannot allocate %d bytes\n", mallocsz);
|
||||
return NULL;
|
||||
}
|
||||
snprintf (line, mallocsz, "0x%08" PFMT64x " ", d->addr);
|
||||
if (pal) {
|
||||
const char *k = pal->offset;
|
||||
snprintf (line, mallocsz, "%s0x%08" PFMT64x Color_RESET" ", k, d->addr);
|
||||
} else {
|
||||
snprintf (line, mallocsz, "0x%08" PFMT64x " ", d->addr);
|
||||
}
|
||||
n32 = (ut32)d->ptr;
|
||||
len = R_MIN (d->len, 8);
|
||||
for (i = 0, idx = strlen (line); i < len; i++) {
|
||||
@ -121,27 +126,52 @@ R_API char *r_anal_data_to_string(RAnalData *d) {
|
||||
if (mallocsz - idx > 12) {
|
||||
switch (d->type) {
|
||||
case R_ANAL_DATA_TYPE_STRING:
|
||||
snprintf (line + idx, mallocsz - idx, "string \"%s\"", d->str);
|
||||
if (pal) {
|
||||
snprintf (line + idx, mallocsz - idx, "%sstring \"%s\""Color_RESET, pal->comment, d->str);
|
||||
} else {
|
||||
snprintf (line + idx, mallocsz - idx, "string \"%s\"", d->str);
|
||||
}
|
||||
break;
|
||||
case R_ANAL_DATA_TYPE_WIDE_STRING:
|
||||
strcat (line, "wide string");
|
||||
break;
|
||||
case R_ANAL_DATA_TYPE_NUMBER:
|
||||
if (n32 == d->ptr) {
|
||||
snprintf (line + idx, mallocsz - idx,
|
||||
"number %d 0x%x", n32, n32);
|
||||
if (pal) {
|
||||
const char *k = pal->num;
|
||||
if (n32 == d->ptr) {
|
||||
snprintf (line + idx, mallocsz - idx,
|
||||
"%snumber %d (0x%x)"Color_RESET, k, n32, n32);
|
||||
} else {
|
||||
snprintf (line + idx, mallocsz - idx,
|
||||
"%snumber %" PFMT64d " (0x%" PFMT64x ")"Color_RESET,
|
||||
k, d->ptr, d->ptr);
|
||||
}
|
||||
} else {
|
||||
snprintf (line + idx, mallocsz - idx,
|
||||
"number %" PFMT64d " 0x%" PFMT64x,
|
||||
d->ptr, d->ptr);
|
||||
if (n32 == d->ptr) {
|
||||
snprintf (line + idx, mallocsz - idx,
|
||||
"number %d 0x%x", n32, n32);
|
||||
} else {
|
||||
snprintf (line + idx, mallocsz - idx,
|
||||
"number %" PFMT64d " 0x%" PFMT64x,
|
||||
d->ptr, d->ptr);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case R_ANAL_DATA_TYPE_POINTER:
|
||||
strcat (line, "pointer ");
|
||||
sprintf (line + strlen (line), " 0x%08" PFMT64x, d->ptr);
|
||||
if (pal) {
|
||||
const char *k = pal->offset;
|
||||
sprintf (line + strlen (line), " %s0x%08" PFMT64x, k, d->ptr);
|
||||
} else {
|
||||
sprintf (line + strlen (line), " 0x%08" PFMT64x, d->ptr);
|
||||
}
|
||||
break;
|
||||
case R_ANAL_DATA_TYPE_INVALID:
|
||||
strcat (line, "invalid");
|
||||
if (pal) {
|
||||
snprintf (line + idx, mallocsz - idx, "%sinvalid"Color_RESET, pal->invalid);
|
||||
} else {
|
||||
strcat (line, "invalid");
|
||||
}
|
||||
break;
|
||||
case R_ANAL_DATA_TYPE_HEADER:
|
||||
strcat (line, "header");
|
||||
@ -153,10 +183,18 @@ R_API char *r_anal_data_to_string(RAnalData *d) {
|
||||
strcat (line, "pattern");
|
||||
break;
|
||||
case R_ANAL_DATA_TYPE_UNKNOWN:
|
||||
strcat (line, "unknown");
|
||||
if (pal) {
|
||||
snprintf (line + idx, mallocsz - idx, "%sunknown"Color_RESET, pal->invalid);
|
||||
} else {
|
||||
strcat (line, "unknown");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
strcat (line, "(null)");
|
||||
if (pal) {
|
||||
snprintf (line + idx, mallocsz - idx, "%s(null)"Color_RESET, pal->b0x00);
|
||||
} else {
|
||||
strcat (line, "(null)");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -2839,6 +2839,7 @@ R_API int r_core_anal_data (RCore *core, ut64 addr, int count, int depth, int wo
|
||||
r_io_read_at (core->io, addr, buf, len);
|
||||
buf[len - 1] = 0;
|
||||
|
||||
RConsPalette *pal = r_config_get_i (core->config, "scr.color")? &r_cons_singleton()->pal: NULL;
|
||||
for (i = j = 0; j < count; j++) {
|
||||
if (i >= len) {
|
||||
r_io_read_at (core->io, addr + i, buf, len);
|
||||
@ -2851,7 +2852,7 @@ R_API int r_core_anal_data (RCore *core, ut64 addr, int count, int depth, int wo
|
||||
/* but it should not.. so this must be fixed in anal/data.c instead of */
|
||||
/* null terminating here */
|
||||
d = r_anal_data (core->anal, addr + i, buf + i, len - i, wordsize);
|
||||
str = r_anal_data_to_string (d);
|
||||
str = r_anal_data_to_string (d, pal);
|
||||
r_cons_println (str);
|
||||
|
||||
if (d) {
|
||||
|
@ -1464,7 +1464,8 @@ R_API const char *r_anal_data_kind (RAnal *anal, ut64 addr, const ut8 *buf, int
|
||||
R_API RAnalData *r_anal_data_new_string (ut64 addr, const char *p, int size, int wide);
|
||||
R_API RAnalData *r_anal_data_new (ut64 addr, int type, ut64 n, const ut8 *buf, int len);
|
||||
R_API void r_anal_data_free (RAnalData *d);
|
||||
R_API char *r_anal_data_to_string (RAnalData *d);
|
||||
#include <r_cons.h>
|
||||
R_API char *r_anal_data_to_string(RAnalData *d, RConsPalette *pal);
|
||||
|
||||
R_API void r_meta_free(RAnal *m);
|
||||
R_API void r_meta_space_unset_for(RAnal *a, int type);
|
||||
|
Loading…
Reference in New Issue
Block a user