mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-26 17:15:38 +00:00
Add scr.color.ophex to colorize 'px' with opcode type ##print
This commit is contained in:
parent
3c3bc79ebd
commit
52f2f8a2bb
@ -1583,6 +1583,17 @@ static bool cb_scrnull(void *user, void *data) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool cb_scr_color_ophex(void *user, void *data) {
|
||||
RCore *core = (RCore *) user;
|
||||
RConfigNode *node = (RConfigNode *) data;
|
||||
if (node->i_value) {
|
||||
core->print->flags |= R_PRINT_FLAGS_COLOROP;
|
||||
} else {
|
||||
core->print->flags &= (~R_PRINT_FLAGS_COLOROP);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool cb_color(void *user, void *data) {
|
||||
RCore *core = (RCore *) user;
|
||||
RConfigNode *node = (RConfigNode *) data;
|
||||
@ -4073,6 +4084,7 @@ R_API int r_core_config_init(RCore *core) {
|
||||
SETCB ("scr.color.grep", "false", &cb_scr_color_grep, "Enable colors when using ~grep");
|
||||
SETBPREF ("scr.color.pipe", "false", "Enable colors when using pipes");
|
||||
SETBPREF ("scr.color.ops", "true", "Colorize numbers and registers in opcodes");
|
||||
SETCB ("scr.color.ophex", "false", &cb_scr_color_ophex, "Colorize in hexdump depending on opcode type (px)");
|
||||
SETBPREF ("scr.color.args", "true", "Colorize arguments and variables of functions");
|
||||
SETBPREF ("scr.color.bytes", "true", "Colorize bytes that represent the opcodes of the instruction");
|
||||
SETCB ("scr.null", "false", &cb_scrnull, "Show no output");
|
||||
|
@ -2546,8 +2546,9 @@ static int cmd_print_pxA(RCore *core, int len, const char *input) {
|
||||
|
||||
static void cmd_print_op(RCore *core, const char *input) {
|
||||
ut8 *buf;
|
||||
if (!input[0])
|
||||
if (!input[0]) {
|
||||
return;
|
||||
}
|
||||
switch (input[1]) {
|
||||
case 'a':
|
||||
case 's':
|
||||
@ -2576,8 +2577,7 @@ static void cmd_print_op(RCore *core, const char *input) {
|
||||
return;
|
||||
}
|
||||
if (buf) {
|
||||
r_print_hexdump(core->print, core->offset, buf,
|
||||
core->blocksize, 16, 1, 1);
|
||||
r_print_hexdump (core->print, core->offset, buf, core->blocksize, 16, 1, 1);
|
||||
free (buf);
|
||||
}
|
||||
}
|
||||
|
@ -2507,10 +2507,42 @@ R_API char *r_core_anal_get_comments(RCore *core, ut64 addr) {
|
||||
|
||||
static R_TH_LOCAL char *const_color = NULL;
|
||||
|
||||
R_API const char *colorforop(RCore *core, ut64 addr) {
|
||||
RList *fcns = r_anal_get_functions_in (core->anal, addr);
|
||||
if (r_list_empty (fcns)) {
|
||||
r_list_free (fcns);
|
||||
return NULL;
|
||||
}
|
||||
RAnalFunction *fcn = r_list_pop (fcns);
|
||||
r_list_free (fcns);
|
||||
if (!fcn) {
|
||||
return NULL;
|
||||
}
|
||||
RListIter *iter;
|
||||
RAnalBlock *bb;
|
||||
r_list_foreach (fcn->bbs, iter, bb) {
|
||||
if (addr >= bb->addr && addr < (bb->addr + bb->size)) {
|
||||
ut64 opat = r_anal_bb_opaddr_at (bb, addr);
|
||||
RAnalOp *op = r_core_anal_op (core, opat, 0);
|
||||
if (op) {
|
||||
const char* res = r_print_color_op_type (core->print, op->type);
|
||||
r_anal_op_free (op);
|
||||
return res;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 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 (!verbose && (core->print->flags & R_PRINT_FLAGS_COLOROP)) {
|
||||
// if function in place check optype for given offset
|
||||
return colorforop (core, addr);
|
||||
}
|
||||
if (!r_config_get_i (core->config, "scr.color")) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ extern "C" {
|
||||
#define R_PRINT_FLAGS_UNALLOC 0x00080000
|
||||
#define R_PRINT_FLAGS_BGFILL 0x00100000
|
||||
#define R_PRINT_FLAGS_SECTION 0x00200000
|
||||
#define R_PRINT_FLAGS_COLOROP 0x00400000
|
||||
|
||||
/*
|
||||
|
||||
|
@ -363,3 +363,51 @@ EXPECT=<<EOF
|
||||
0x000000f0 👩 👪 👮 👯 👺 👻 👼 👽 👾 👿 💀 💁 💂 💃 💄 💅 ................
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=hexdump colorized by optype
|
||||
FILE=bins/elf/ls
|
||||
CMDS=<<EOF
|
||||
e scr.color = 3
|
||||
e scr.color.ophex=true
|
||||
x 64
|
||||
e anal.hasnext=true
|
||||
afr
|
||||
x 64
|
||||
pD 65
|
||||
EOF
|
||||
EXPECT=<<EOF
|
||||
[38;2;19;161;14m- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
|
||||
[0m[38;2;19;161;14m0x00005ae0[0m [38;2;204;204;204mf3[0m[38;2;204;204;204m0f[0m [38;2;204;204;204m1e[0m[38;2;204;204;204mfa[0m [38;2;193;156;0m31[0m[38;2;204;204;204med[0m [38;2;193;156;0m49[0m[38;2;204;204;204m89[0m [38;2;204;204;204md1[0m[38;2;193;156;0m5e[0m [38;2;193;156;0m48[0m[38;2;204;204;204m89[0m [38;2;204;204;204me2[0m[38;2;193;156;0m48[0m [38;2;204;204;204m83[0m[38;2;204;204;204me4[0m [38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;193;156;0m1[0m[38;2;204;204;204m.[0m[38;2;193;156;0mI[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;193;156;0m^[0m[38;2;193;156;0mH[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;193;156;0mH[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m
|
||||
[38;2;19;161;14m0x00005af0[0m [38;2;204;204;204mf0[0m[38;2;193;156;0m50[0m [38;2;193;156;0m54[0m[38;2;193;156;0m4c[0m [38;2;204;204;204m8d[0m[38;2;204;204;204m05[0m [38;2;193;156;0m66[0m[38;2;204;204;204m0c[0m [38;2;204;204;204m01[0m[38;2;19;161;14m00[0m [38;2;193;156;0m48[0m[38;2;204;204;204m8d[0m [38;2;204;204;204m0d[0m[38;2;204;204;204mef[0m [38;2;204;204;204m0b[0m[38;2;204;204;204m01[0m [38;2;204;204;204m.[0m[38;2;193;156;0mP[0m[38;2;193;156;0mT[0m[38;2;193;156;0mL[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;193;156;0mf[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;19;161;14m.[0m[38;2;193;156;0mH[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m
|
||||
[38;2;19;161;14m0x00005b00[0m [38;2;19;161;14m00[0m[38;2;193;156;0m48[0m [38;2;204;204;204m8d[0m[38;2;193;156;0m3d[0m [38;2;193;156;0m68[0m[38;2;204;204;204me5[0m [38;2;197;15;31mff[0m[38;2;197;15;31mff[0m [38;2;197;15;31mff[0m[38;2;204;204;204m15[0m [38;2;204;204;204m0a[0m[38;2;204;204;204mc3[0m [38;2;204;204;204m01[0m[38;2;19;161;14m00[0m [38;2;204;204;204mf4[0m[38;2;204;204;204m90[0m [38;2;19;161;14m.[0m[38;2;193;156;0mH[0m[38;2;204;204;204m.[0m[38;2;193;156;0m=[0m[38;2;193;156;0mh[0m[38;2;204;204;204m.[0m[38;2;197;15;31m.[0m[38;2;197;15;31m.[0m[38;2;197;15;31m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;19;161;14m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m
|
||||
[38;2;19;161;14m0x00005b10[0m [38;2;193;156;0m48[0m[38;2;204;204;204m8d[0m [38;2;193;156;0m3d[0m[38;2;193;156;0m51[0m [38;2;204;204;204mc7[0m[38;2;204;204;204m01[0m [38;2;19;161;14m00[0m[38;2;193;156;0m48[0m [38;2;204;204;204m8d[0m[38;2;204;204;204m05[0m [38;2;193;156;0m4a[0m[38;2;204;204;204mc7[0m [38;2;204;204;204m01[0m[38;2;19;161;14m00[0m [38;2;193;156;0m48[0m[38;2;193;156;0m39[0m [38;2;193;156;0mH[0m[38;2;204;204;204m.[0m[38;2;193;156;0m=[0m[38;2;193;156;0mQ[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;19;161;14m.[0m[38;2;193;156;0mH[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;193;156;0mJ[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;19;161;14m.[0m[38;2;193;156;0mH[0m[38;2;193;156;0m9[0m
|
||||
[38;2;19;161;14m- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
|
||||
[0m[38;2;19;161;14m0x00005ae0[0m [38;2;204;204;204mf3[0m[38;2;204;204;204m0f[0m [38;2;204;204;204m1e[0m[38;2;204;204;204mfa[0m [38;2;193;156;0m31[0m[38;2;193;156;0med[0m [38;2;204;204;204m49[0m[38;2;204;204;204m89[0m [38;2;204;204;204md1[0m[38;2;136;23;152m5e[0m [38;2;204;204;204m48[0m[38;2;204;204;204m89[0m [38;2;204;204;204me2[0m[38;2;193;156;0m48[0m [38;2;193;156;0m83[0m[38;2;193;156;0me4[0m [38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;193;156;0m1[0m[38;2;193;156;0m.[0m[38;2;204;204;204mI[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;136;23;152m^[0m[38;2;204;204;204mH[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;193;156;0mH[0m[38;2;193;156;0m.[0m[38;2;193;156;0m.[0m
|
||||
[38;2;19;161;14m0x00005af0[0m [38;2;193;156;0mf0[0m[38;2;136;23;152m50[0m [38;2;136;23;152m54[0m[38;2;204;204;204m4c[0m [38;2;204;204;204m8d[0m[38;2;204;204;204m05[0m [38;2;204;204;204m66[0m[38;2;204;204;204m0c[0m [38;2;204;204;204m01[0m[38;2;204;204;204m00[0m [38;2;204;204;204m48[0m[38;2;204;204;204m8d[0m [38;2;204;204;204m0d[0m[38;2;204;204;204mef[0m [38;2;204;204;204m0b[0m[38;2;204;204;204m01[0m [38;2;193;156;0m.[0m[38;2;136;23;152mP[0m[38;2;136;23;152mT[0m[38;2;204;204;204mL[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204mf[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204mH[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m
|
||||
[38;2;19;161;14m0x00005b00[0m [38;2;204;204;204m00[0m[38;2;204;204;204m48[0m [38;2;204;204;204m8d[0m[38;2;204;204;204m3d[0m [38;2;204;204;204m68[0m[38;2;204;204;204me5[0m [38;2;204;204;204mff[0m[38;2;204;204;204mff[0m [38;2;19;161;14mff[0m[38;2;19;161;14m15[0m [38;2;19;161;14m0a[0m[38;2;19;161;14mc3[0m [38;2;19;161;14m01[0m[38;2;19;161;14m00[0m [38;2;204;204;204mf4[0m[38;2;204;204;204m90[0m [38;2;204;204;204m.[0m[38;2;204;204;204mH[0m[38;2;204;204;204m.[0m[38;2;204;204;204m=[0m[38;2;204;204;204mh[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;19;161;14m.[0m[38;2;19;161;14m.[0m[38;2;19;161;14m.[0m[38;2;19;161;14m.[0m[38;2;19;161;14m.[0m[38;2;19;161;14m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m
|
||||
[38;2;19;161;14m0x00005b10[0m [38;2;204;204;204m48[0m[38;2;204;204;204m8d[0m [38;2;204;204;204m3d[0m[38;2;204;204;204m51[0m [38;2;204;204;204mc7[0m[38;2;204;204;204m01[0m [38;2;204;204;204m00[0m[38;2;204;204;204m48[0m [38;2;204;204;204m8d[0m[38;2;204;204;204m05[0m [38;2;204;204;204m4a[0m[38;2;204;204;204mc7[0m [38;2;204;204;204m01[0m[38;2;204;204;204m00[0m [38;2;193;156;0m48[0m[38;2;193;156;0m39[0m [38;2;204;204;204mH[0m[38;2;204;204;204m.[0m[38;2;204;204;204m=[0m[38;2;204;204;204mQ[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204mH[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204mJ[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;204;204;204m.[0m[38;2;193;156;0mH[0m[38;2;193;156;0m9[0m
|
||||
[38;2;58;150;221m/[0m 46: [38;2;197;15;31mentry0[0m (int64_t arg3);
|
||||
[38;2;58;150;221m|[0m [38;2;204;204;204m; [38;2;204;204;204marg [38;2;0;55;218mint64_t arg3 [38;2;58;150;221m@ rdx[0m
|
||||
[38;2;58;150;221m|[0m [38;2;19;161;14m0x00005ae0[0m [38;2;204;204;204mf3[38;2;204;204;204m0f[38;2;204;204;204m1e[38;2;204;204;204mfa[0m [38;2;204;204;204mendbr64[0m[0m[0m
|
||||
[38;2;58;150;221m|[0m [38;2;19;161;14m0x00005ae4[0m [38;2;193;156;0m31[38;2;204;204;204med[0m [38;2;193;156;0mxor[38;2;58;150;221m ebp[0m,[38;2;58;150;221m ebp[0m[0m[0m
|
||||
[38;2;58;150;221m|[0m [38;2;19;161;14m0x00005ae6[0m [38;2;193;156;0m49[38;2;204;204;204m89[38;2;204;204;204md1[0m [38;2;204;204;204mmov[38;2;58;150;221m r9[0m,[38;2;58;150;221m rdx[0m[0m[0m [38;2;0;55;218m; arg3[0m
|
||||
[38;2;58;150;221m|[0m [38;2;19;161;14m0x00005ae9[0m [38;2;193;156;0m5e[0m [38;2;136;23;152mpop[38;2;58;150;221m rsi[0m[0m[0m
|
||||
[38;2;58;150;221m|[0m [38;2;19;161;14m0x00005aea[0m [38;2;193;156;0m48[38;2;204;204;204m89[38;2;204;204;204me2[0m [38;2;204;204;204mmov[38;2;58;150;221m rdx[0m,[38;2;58;150;221m rsp[0m[0m[0m
|
||||
[38;2;58;150;221m|[0m [38;2;19;161;14m0x00005aed[0m [38;2;193;156;0m48[38;2;204;204;204m83[38;2;204;204;204me4[38;2;204;204;204mf0[0m [38;2;193;156;0mand[38;2;58;150;221m rsp[0m,[38;2;58;150;221m[38;2;58;150;221m [38;2;193;156;0m0xfffffffffffffff0[0m[0m[0m
|
||||
[38;2;58;150;221m|[0m [38;2;19;161;14m0x00005af1[0m [38;2;193;156;0m50[0m [38;2;136;23;152mpush[38;2;58;150;221m rax[0m[0m[0m
|
||||
[38;2;58;150;221m|[0m [38;2;19;161;14m0x00005af2[0m [38;2;193;156;0m54[0m [38;2;136;23;152mpush[38;2;58;150;221m rsp[0m[0m[0m
|
||||
[38;2;58;150;221m|[0m [38;2;19;161;14m0x00005af3[0m [38;2;193;156;0m4c[38;2;204;204;204m8d[38;2;204;204;204m05[38;2;193;156;0m66[38;2;204;204;204m0c[38;2;204;204;204m01[38;2;204;204;204m.[0m [38;2;204;204;204mlea[38;2;58;150;221m r8[0m,[38;2;58;150;221m[38;2;58;150;221m [0m[[38;2;193;156;0m0x00016760[0m][38;2;58;150;221m[0m[0m[0m
|
||||
[38;2;58;150;221m|[0m [38;2;19;161;14m0x00005afa[0m [38;2;193;156;0m48[38;2;204;204;204m8d[38;2;204;204;204m0d[38;2;204;204;204mef[38;2;204;204;204m0b[38;2;204;204;204m01[38;2;204;204;204m.[0m [38;2;204;204;204mlea[38;2;58;150;221m rcx[0m,[38;2;58;150;221m[38;2;58;150;221m [0m[[38;2;193;156;0m0x000166f0[0m][38;2;58;150;221m[0m[0m[0m
|
||||
[38;2;58;150;221m|[0m [38;2;19;161;14m0x00005b01[0m [38;2;193;156;0m48[38;2;204;204;204m8d[38;2;193;156;0m3d[38;2;193;156;0m68[38;2;204;204;204me5[38;2;197;15;31mff[38;2;204;204;204m.[0m [38;2;204;204;204mlea[38;2;58;150;221m rdi[0m,[38;2;58;150;221m[38;2;58;150;221m main[0m[0m[38;2;197;15;31m [38;2;197;15;31m; 0x4070[38;2;197;15;31m [38;2;197;15;31m; "AWAVAUATU\x89\xfdSH\x89\xf3H\x83\xecXH\x8b>dH\x8b\x04%("[0m
|
||||
[38;2;58;150;221m\[0m [38;2;19;161;14m0x00005b08[0m [38;2;197;15;31mff[38;2;204;204;204m15[38;2;204;204;204m0a[38;2;204;204;204mc3[38;2;204;204;204m01[38;2;19;161;14m00[0m [38;2;19;161;14mcall qword[38;2;58;150;221m [0m[[38;2;58;150;221mreloc.__libc_start_main[0m][38;2;58;150;221m[0m[0m[38;2;197;15;31m [38;2;197;15;31m; [0x21e18:8]=0[0m
|
||||
[38;2;19;161;14m0x00005b0e[0m [38;2;204;204;204mf4[0m [1;38;2;231;72;86mhlt[0m[0m[0m
|
||||
[38;2;19;161;14m0x00005b0f[0m [38;2;204;204;204m90[0m [38;2;0;55;218mnop[0m[0m[0m
|
||||
[38;2;197;15;31m[38;2;197;15;31m; CALL XREF from entry.fini0 @ [38;2;197;15;31m0x5ba8[38;2;197;15;31m[0m
|
||||
[38;2;58;150;221m/[0m 34: [38;2;197;15;31mfcn.00005b0e[0m ();
|
||||
[38;2;58;150;221m|[0m [38;2;19;161;14m0x00005b10[0m [38;2;193;156;0m48[38;2;204;204;204m8d[38;2;193;156;0m3d[38;2;193;156;0m51[38;2;204;204;204mc7[38;2;204;204;204m01[38;2;204;204;204m.[0m [38;2;204;204;204mlea[38;2;58;150;221m rdi[0m,[38;2;58;150;221m[38;2;58;150;221m loc._edata[0m[0m[38;2;197;15;31m [38;2;197;15;31m; loc.__bss_start
|
||||
[38;2;58;150;221m|[0m [38;2;197;15;31m [38;2;197;15;31m; 0x22268[0m
|
||||
[38;2;58;150;221m|[0m [38;2;19;161;14m0x00005b17[0m [38;2;193;156;0m48[38;2;204;204;204m8d[38;2;204;204;204m05[38;2;193;156;0m4a[38;2;204;204;204mc7[38;2;204;204;204m01[38;2;204;204;204m.[0m [38;2;204;204;204mlea[38;2;58;150;221m rax[0m,[38;2;58;150;221m[38;2;58;150;221m loc._edata[0m[0m[38;2;197;15;31m [38;2;197;15;31m; loc.__bss_start
|
||||
[38;2;58;150;221m|[0m [38;2;197;15;31m [38;2;197;15;31m; 0x22268[0m
|
||||
[38;2;58;150;221m|[0m [38;2;19;161;14m0x00005b1e[0m [38;2;193;156;0m48[38;2;193;156;0m39[38;2;204;204;204mf8[0m [38;2;193;156;0mcmp[38;2;58;150;221m rax[0m,[38;2;58;150;221m rdi[0m[0m[0m
|
||||
EOF
|
||||
RUN
|
||||
|
Loading…
x
Reference in New Issue
Block a user