mirror of
https://github.com/radareorg/radare2.git
synced 2025-04-01 17:11:51 +00:00
Honor color palete and honor hex.cols in p2 ##print
This commit is contained in:
parent
126f8c799f
commit
bf9f4fac04
@ -6650,7 +6650,15 @@ l = use_blocksize;
|
||||
r_cons_printf ("|Usage: p2 [number of bytes representing tiles]\n"
|
||||
"NOTE: Only full tiles will be printed\n");
|
||||
} else {
|
||||
r_print_2bpp_tiles (core->print, core->block, len / 16);
|
||||
RConsContext *c = core->cons->context;
|
||||
const char **colors = (const char *[]) {
|
||||
c->pal.mov, //black
|
||||
c->pal.nop, //dark
|
||||
c->pal.cmp, //light
|
||||
c->pal.jmp, //white
|
||||
};
|
||||
const int cols = r_config_get_i (core->config, "hex.cols");
|
||||
r_print_2bpp_tiles (core->print, core->block, len - 1, cols / 4, colors);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -207,8 +207,8 @@ R_API void r_print_progressbar_with_count(RPrint *pr, unsigned int pc, unsigned
|
||||
R_API void r_print_portionbar(RPrint *p, const ut64 *portions, int n_portions);
|
||||
R_API void r_print_rangebar(RPrint *p, ut64 startA, ut64 endA, ut64 min, ut64 max, int cols);
|
||||
R_API char * r_print_randomart(const ut8 *dgst_raw, ut32 dgst_raw_len, ut64 addr);
|
||||
R_API void r_print_2bpp_row(RPrint *p, ut8 *buf);
|
||||
R_API void r_print_2bpp_tiles(RPrint *p, ut8 *buf, ut32 tiles);
|
||||
R_API void r_print_2bpp_row(RPrint *p, ut8 *buf, const char **colors);
|
||||
R_API void r_print_2bpp_tiles(RPrint *p, ut8 *buf, size_t buflen, ut32 tiles, const char **colors);
|
||||
R_API char * r_print_colorize_opcode(RPrint *print, char *p, const char *reg, const char *num, bool partial_reset, ut64 func_addr);
|
||||
R_API const char * r_print_color_op_type(RPrint *p, ut32 anal_type);
|
||||
R_API void r_print_set_interrupted(int i);
|
||||
|
@ -1845,7 +1845,7 @@ R_API void r_print_fill(RPrint *p, const ut8 *arr, int size, ut64 addr, int step
|
||||
}
|
||||
}
|
||||
|
||||
R_API void r_print_2bpp_row(RPrint *p, ut8 *buf) {
|
||||
R_API void r_print_2bpp_row(RPrint *p, ut8 *buf, const char **colors) {
|
||||
const bool useColor = p? (p->flags & R_PRINT_FLAGS_COLOR): false;
|
||||
int i, c = 0;
|
||||
for (i = 0; i < 8; i++) {
|
||||
@ -1855,30 +1855,17 @@ R_API void r_print_2bpp_row(RPrint *p, ut8 *buf) {
|
||||
if (buf[0] & ((1 << 7) >> i)) {
|
||||
c++;
|
||||
}
|
||||
const char *chstr = ".=*@";
|
||||
const char ch = chstr[c % 4];
|
||||
if (useColor) {
|
||||
char *color = "";
|
||||
switch (c) {
|
||||
case 0:
|
||||
color = Color_BGWHITE;
|
||||
break;
|
||||
case 1:
|
||||
color = Color_BGRED;
|
||||
break;
|
||||
case 2:
|
||||
color = Color_BGBLUE;
|
||||
break;
|
||||
case 3:
|
||||
color = Color_BGBLACK;
|
||||
break;
|
||||
}
|
||||
const char *color = "";
|
||||
color = colors[c]; // c is by definition 0, 1, 2 or 3
|
||||
if (p) {
|
||||
p->cb_printf ("%s ", color);
|
||||
p->cb_printf ("%s%c%c"Color_RESET, color, ch, ch);
|
||||
} else {
|
||||
printf ("%s ", color);
|
||||
printf ("%s%c%c"Color_RESET, color, ch, ch);
|
||||
}
|
||||
} else {
|
||||
const char *chstr = "#=-.";
|
||||
const char ch = chstr[c % 4];
|
||||
if (p) {
|
||||
p->cb_printf ("%c%c", ch, ch);
|
||||
} else {
|
||||
@ -1889,22 +1876,48 @@ R_API void r_print_2bpp_row(RPrint *p, ut8 *buf) {
|
||||
}
|
||||
}
|
||||
|
||||
R_API void r_print_2bpp_tiles(RPrint *p, ut8 *buf, ut32 tiles) {
|
||||
static void r_print_2bpp_newline(RPrint *p, bool useColor) {
|
||||
if (p) {
|
||||
if (useColor) {
|
||||
p->cb_printf (Color_RESET "\n");
|
||||
} else {
|
||||
p->cb_printf ("\n");
|
||||
}
|
||||
} else {
|
||||
printf ("\n");
|
||||
}
|
||||
}
|
||||
|
||||
R_API void r_print_2bpp_tiles(RPrint *p, ut8 *buf, size_t buflen, ut32 tiles, const char **colors) {
|
||||
if (!colors) {
|
||||
colors = (const char *[]){
|
||||
Color_BGWHITE,
|
||||
Color_BGRED,
|
||||
Color_BGBLUE,
|
||||
Color_BGBLACK,
|
||||
};
|
||||
}
|
||||
int i, r;
|
||||
const bool useColor = p? (p->flags & R_PRINT_FLAGS_COLOR): false;
|
||||
for (i = 0; i < 8; i++) {
|
||||
for (r = 0; r < tiles; r++) {
|
||||
r_print_2bpp_row (p, buf + 2 * i + r * 16);
|
||||
}
|
||||
if (p) {
|
||||
if (useColor) {
|
||||
p->cb_printf (Color_RESET "\n");
|
||||
} else {
|
||||
p->cb_printf ("\n");
|
||||
int rows = buflen / tiles;
|
||||
int row, delta = 0;
|
||||
// hex.cols = 64 = 256 byte stride
|
||||
int stride = tiles * 16;
|
||||
bool eof = false;
|
||||
for (row = 1; row < rows; row++) {
|
||||
for (i = 0; i < 8 && !eof; i++) {
|
||||
for (r = 0; r < tiles; r++) {
|
||||
//int off = delta + 2 * i + r * 16;
|
||||
int off = delta + (2 * i) + (r * 16);
|
||||
if (off >= buflen) {
|
||||
eof = true;
|
||||
break;
|
||||
}
|
||||
r_print_2bpp_row (p, buf + off, colors);
|
||||
}
|
||||
} else {
|
||||
printf ("\n");
|
||||
r_print_2bpp_newline (p, useColor);
|
||||
}
|
||||
delta += stride;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,35 @@
|
||||
NAME=p2 hello-linux-x86_64
|
||||
FILE=bins/elf/analysis/hello-linux-x86_64
|
||||
CMDS=p2 16
|
||||
CMDS=p2 32@e:hex.cols=8
|
||||
EXPECT=<<EOF
|
||||
----..==----##..
|
||||
--==####..####..
|
||||
==..##..------==
|
||||
--==####..####--
|
||||
==..==##--##==##
|
||||
..----####--====
|
||||
==..==..########
|
||||
##..##==--==##--
|
||||
****@@==****..@@@@@@......======
|
||||
**==....@@....@@==..====..**..**
|
||||
==@@..@@******==..==............
|
||||
**==....@@....****@@....==******
|
||||
==@@==..**..==..====**........==
|
||||
@@****....**====..**......==..==
|
||||
==@@==@@..........**....**......
|
||||
..@@..==**==..**@@@@......@@@@@@
|
||||
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=p2 r2 gb logo
|
||||
FILE=-
|
||||
CMDS=<<EOF
|
||||
wx 6767f6f6fefe6e6e0606060606060f0f111133337777ffffffff777733331111
|
||||
p2 32@e:hex.cols=8
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
..@@@@....@@@@@@......@@......@@
|
||||
@@@@@@@@..@@@@......@@@@....@@@@
|
||||
@@@@@@@@@@@@@@....@@@@@@..@@@@@@
|
||||
..@@@@..@@@@@@..@@@@@@@@@@@@@@@@
|
||||
..........@@@@..@@@@@@@@@@@@@@@@
|
||||
..........@@@@....@@@@@@..@@@@@@
|
||||
..........@@@@......@@@@....@@@@
|
||||
........@@@@@@@@......@@......@@
|
||||
|
||||
EOF
|
||||
RUN
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user