moved rz_print_columns into core and use rz_cons

This commit is contained in:
wargio 2022-02-27 15:01:04 +01:00 committed by Giovanni
parent 02cf266820
commit 165a38207b
3 changed files with 59 additions and 61 deletions

View file

@ -3754,6 +3754,62 @@ static ut8 *analBars(RzCore *core, size_t type, size_t nblocks, size_t blocksize
return ptr;
}
static void core_print_columns(RzCore *core, const ut8 *buf, ut32 len, ut32 height) {
size_t i, j;
bool colors = rz_config_get_i(core->config, "scr.color") > 0;
RzCons *cons = rz_cons_singleton();
RzConsPrintablePalette *pal = &cons->context->pal;
ut32 cols = 78;
ut32 rows = height > 0 ? height : 10;
const char *vline = cons->use_utf8 ? RUNE_LINE_VERT : "|";
const char *block = cons->use_utf8 ? UTF_BLOCK : "#";
const char *kol[5];
kol[0] = pal->call;
kol[1] = pal->jmp;
kol[2] = pal->cjmp;
kol[3] = pal->mov;
kol[4] = pal->nop;
if (colors) {
for (i = 0; i < rows; i++) {
size_t threshold = i * (0xff / rows);
size_t koli = i * 5 / rows;
for (j = 0; j < cols; j++) {
int realJ = j * len / cols;
if (255 - buf[realJ] < threshold || (i + 1 == rows)) {
if (core->print->histblock) {
rz_cons_printf("%s%s%s", kol[koli], block, Color_RESET);
} else {
rz_cons_printf("%s%s%s", kol[koli], vline, Color_RESET);
}
} else {
rz_cons_print(" ");
}
}
rz_cons_print("\n");
}
return;
}
for (i = 0; i < rows; i++) {
size_t threshold = i * (0xff / rows);
for (j = 0; j < cols; j++) {
size_t realJ = j * len / cols;
if (255 - buf[realJ] < threshold) {
if (core->print->histblock) {
rz_cons_printf("%s%s%s", Color_BGGRAY, block, Color_RESET);
} else {
rz_cons_printf("%s", vline);
}
} else if (i + 1 == rows) {
rz_cons_print("_");
} else {
rz_cons_print(" ");
}
}
rz_cons_print("\n");
}
}
static void cmd_print_bars(RzCore *core, const char *input) {
bool print_bars = false;
ut8 *ptr = NULL;
@ -3935,7 +3991,7 @@ static void cmd_print_bars(RzCore *core, const char *input) {
}
ptr[i] = 256 * k / blocksize;
}
rz_print_columns(core->print, ptr, nblocks, 14);
core_print_columns(core, ptr, nblocks, 14);
free(p);
} break;
case 'e': // "p=e"
@ -3959,10 +4015,10 @@ static void cmd_print_bars(RzCore *core, const char *input) {
ptr[i] = (ut8)(255 * rz_hash_entropy_fraction(p, blocksize));
}
free(p);
rz_print_columns(core->print, ptr, nblocks, 14);
core_print_columns(core, ptr, nblocks, 14);
} break;
default:
rz_print_columns(core->print, core->block, core->blocksize, 14);
core_print_columns(core, core->block, core->blocksize, 14);
break;
}
break;

View file

@ -140,7 +140,6 @@ RZ_API void rz_print_set_flags(RzPrint *p, int _flags);
RZ_API void rz_print_unset_flags(RzPrint *p, int flags);
RZ_API void rz_print_addr(RzPrint *p, ut64 addr);
RZ_API void rz_print_section(RzPrint *p, ut64 at);
RZ_API void rz_print_columns(RzPrint *p, const ut8 *buf, int len, int height);
RZ_API void rz_print_hexii(RzPrint *p, ut64 addr, const ut8 *buf, int len, int step);
RZ_API void rz_print_hexdump(RzPrint *p, ut64 addr, const ut8 *buf, int len, int base, int step, size_t zoomsz);
RZ_API void rz_print_hexdump_simple(const ut8 *buf, int len);

View file

@ -30,63 +30,6 @@ static int libc_eprintf(const char *format, ...) {
static RzPrintIsInterruptedCallback is_interrupted_cb = NULL;
RZ_API void rz_print_columns(RzPrint *p, const ut8 *buf, int len, int height) {
#define cb_print(x) p->cb_printf("%s", x)
size_t i, j;
int cols = 78; // TODO: do not hardcode this value, columns should be defined by the user
int rows = height > 0 ? height : 10;
// int realrows = rows * 2;
bool colors = p->flags & RZ_PRINT_FLAGS_COLOR;
RzConsPrintablePalette *pal = &p->cons->context->pal;
const char *vline = p->cons->use_utf8 ? RUNE_LINE_VERT : "|";
const char *block = p->cons->use_utf8 ? UTF_BLOCK : "#";
const char *kol[5];
kol[0] = pal->call;
kol[1] = pal->jmp;
kol[2] = pal->cjmp;
kol[3] = pal->mov;
kol[4] = pal->nop;
if (colors) {
for (i = 0; i < rows; i++) {
size_t threshold = i * (0xff / rows);
size_t koli = i * 5 / rows;
for (j = 0; j < cols; j++) {
int realJ = j * len / cols;
if (255 - buf[realJ] < threshold || (i + 1 == rows)) {
if (p->histblock) {
p->cb_printf("%s%s%s", kol[koli], block, Color_RESET);
} else {
p->cb_printf("%s%s%s", kol[koli], vline, Color_RESET);
}
} else {
cb_print(" ");
}
}
cb_print("\n");
}
return;
}
for (i = 0; i < rows; i++) {
size_t threshold = i * (0xff / rows);
for (j = 0; j < cols; j++) {
size_t realJ = j * len / cols;
if (255 - buf[realJ] < threshold) {
if (p->histblock) {
p->cb_printf("%s%s%s", Color_BGGRAY, block, Color_RESET);
} else {
cb_print(vline);
}
} else if (i + 1 == rows) {
cb_print("_");
} else {
cb_print(" ");
}
}
cb_print("\n");
}
}
RZ_API bool rz_print_is_interrupted(void) {
if (is_interrupted_cb) {
return is_interrupted_cb();