Add scr.color.ophex to colorize 'px' with opcode type ##print

This commit is contained in:
pancake 2022-01-23 23:29:48 +01:00 committed by pancake
parent 3c3bc79ebd
commit 52f2f8a2bb
5 changed files with 96 additions and 3 deletions

View File

@ -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");

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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
/*

View File

@ -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
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x00005ae0 f30f 1efa 31ed 4989 d15e 4889 e248 83e4 ....1.I..^H..H..
0x00005af0 f050 544c 8d05 660c 0100 488d 0def 0b01 .PTL..f...H.....
0x00005b00 0048 8d3d 68e5 ffff ff15 0ac3 0100 f490 .H.=h...........
0x00005b10 488d 3d51 c701 0048 8d05 4ac7 0100 4839 H.=Q...H..J...H9
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
0x00005ae0 f30f 1efa 31ed 4989 d15e 4889 e248 83e4 ....1.I..^H..H..
0x00005af0 f050 544c 8d05 660c 0100 488d 0def 0b01 .PTL..f...H.....
0x00005b00 0048 8d3d 68e5 ffff ff15 0ac3 0100 f490 .H.=h...........
0x00005b10 488d 3d51 c701 0048 8d05 4ac7 0100 4839 H.=Q...H..J...H9
/ 46: entry0 (int64_t arg3);
| ; arg int64_t arg3 @ rdx
| 0x00005ae0 f30f1efa endbr64
| 0x00005ae4 31ed xor ebp, ebp
| 0x00005ae6 4989d1 mov r9, rdx ; arg3
| 0x00005ae9 5e pop rsi
| 0x00005aea 4889e2 mov rdx, rsp
| 0x00005aed 4883e4f0 and rsp, 0xfffffffffffffff0
| 0x00005af1 50 push rax
| 0x00005af2 54 push rsp
| 0x00005af3 4c8d05660c01. lea r8, [0x00016760]
| 0x00005afa 488d0def0b01. lea rcx, [0x000166f0]
| 0x00005b01 488d3d68e5ff. lea rdi, main ; 0x4070 ; "AWAVAUATU\x89\xfdSH\x89\xf3H\x83\xecXH\x8b>dH\x8b\x04%("
\ 0x00005b08 ff150ac30100 call qword [reloc.__libc_start_main] ; [0x21e18:8]=0
0x00005b0e f4 hlt
0x00005b0f 90 nop
; CALL XREF from entry.fini0 @ 0x5ba8
/ 34: fcn.00005b0e ();
| 0x00005b10 488d3d51c701. lea rdi, loc._edata ; loc.__bss_start
|  ; 0x22268
| 0x00005b17 488d054ac701. lea rax, loc._edata ; loc.__bss_start
|  ; 0x22268
| 0x00005b1e 4839f8 cmp rax, rdi
EOF
RUN