From 4e51e811be8f53fb58e357b6c15ca01b98b182fe Mon Sep 17 00:00:00 2001 From: Vane11ope Date: Sun, 1 Sep 2019 23:27:11 +0900 Subject: [PATCH] O in visual is supported in panels with the "i" key ##panels (#14942) --- libr/core/panels.c | 66 ++++++++++++++++++++++++++++++++++----- libr/core/visual.c | 9 +++--- libr/core/visual_tabs.inc | 2 +- libr/include/r_core.h | 1 + 4 files changed, 66 insertions(+), 12 deletions(-) diff --git a/libr/core/panels.c b/libr/core/panels.c index 79c4e9da39..db076d6330 100644 --- a/libr/core/panels.c +++ b/libr/core/panels.c @@ -166,8 +166,8 @@ static const char *entropy_rotate[] = { NULL }; -static const char *hexdump_rotate[] = { - "", "a", "r", "b", "h", "w", "q", "d", "r", +static char *hexdump_rotate[] = { + "xc", "pxa", "pxr", "prx", "pxb", "pxh", "pxw", "pxq", "pxd", "pxr", NULL }; @@ -808,16 +808,47 @@ bool __check_panel_type(RPanel *panel, const char *type) { if (!panel->model->cmd || !type) { return false; } + char *tmp = r_str_new (panel->model->cmd); + int n = r_str_split (tmp, ' '); + if (!n) { + return false; + } + const char *base = r_str_word_get0 (tmp, 0); + if (R_STR_ISEMPTY (base)) { + return false; + } int len = strlen (type); if (!strcmp (type, PANEL_CMD_DISASSEMBLY)) { - if (!strncmp (panel->model->cmd, type, len) && + if (!strncmp (tmp, type, len) && strcmp (panel->model->cmd, PANEL_CMD_DECOMPILER) && strcmp (panel->model->cmd, PANEL_CMD_DECOMPILER_O) && strcmp (panel->model->cmd, PANEL_CMD_DISASMSUMMARY)) { + free (tmp); return true; } + free (tmp); return false; } + if (!strcmp (type, PANEL_CMD_STACK)) { + if (!strcmp (tmp, PANEL_CMD_STACK)) { + free (tmp); + return true; + } + free (tmp); + return false; + } + if (!strcmp (type, PANEL_CMD_HEXDUMP)) { + int i = 0; + for (; i < COUNT (hexdump_rotate); i++) { + if (!strcmp (tmp, hexdump_rotate[i])) { + free (tmp); + return true; + } + } + free (tmp); + return false; + } + free (tmp); return !strncmp (panel->model->cmd, type, len); } @@ -4131,10 +4162,10 @@ void __print_stack_cb(void *user, void *p) { int i; for (i = 0; i < n; i++) { const char *s = r_str_word_get0 (panel->model->cmd, i); - if (strncmp (s, PANEL_CMD_STACK, strlen (PANEL_CMD_STACK))) { - cmd = r_str_append (cmd, s); - break; + if (!i) { + continue; } + cmd = r_str_append (cmd, s); } panel->model->cmd = cmd; const char *cmdstr = r_core_cmd_str (core, r_str_newf ("%s%c%d", cmd, sign, absdelta)); @@ -4152,6 +4183,18 @@ void __print_hexdump_cb(void *user, void *p) { r_core_seek (core, core->offset, 1); r_core_block_read (core); } + char *base = hexdump_rotate[R_ABS(panel->model->rotate) % COUNT (hexdump_rotate)]; + char *cmd = r_str_newf ("%s ", base); + int n = r_str_split (panel->model->cmd, ' '); + int i; + for (i = 0; i < n; i++) { + const char *s = r_str_word_get0 (panel->model->cmd, i); + if (!i) { + continue; + } + cmd = r_str_append (cmd, s); + } + panel->model->cmd = cmd; cmdstr = __handle_cmd_str_cache (core, panel, false); core->offset = o_offset; } @@ -5070,6 +5113,7 @@ void __init_rotate_db(RCore *core) { sdb_ptr_set (panels->rotate_db, "px", &__rotate_hexdump_cb, 0); sdb_ptr_set (panels->rotate_db, "dr", &__rotate_register_cb, 0); sdb_ptr_set (panels->rotate_db, "af", &__rotate_function_cb, 0); + sdb_ptr_set (panels->rotate_db, PANEL_CMD_HEXDUMP, &__rotate_hexdump_cb, 0); } void __init_sdb(RCore *core) { @@ -6131,7 +6175,15 @@ void __rotate_entropy_h_cb(void *user, bool rev) { void __rotate_hexdump_cb (void *user, bool rev) { RCore *core = (RCore *)user; - __rotate_panel_cmds (core, hexdump_rotate, COUNT (hexdump_rotate), "px", rev); + RPanel *p = __get_cur_panel (core->panels); + + if (rev) { + p->model->rotate--; + } else { + p->model->rotate++; + } + r_core_visual_applyHexMode (core, p->model->rotate); + __rotate_asmemu (core, p); } void __rotate_register_cb (void *user, bool rev) { diff --git a/libr/core/visual.c b/libr/core/visual.c index b46ab4e1d0..3159db181e 100644 --- a/libr/core/visual.c +++ b/libr/core/visual.c @@ -64,7 +64,8 @@ static int current5format = 0; static const char *print5Formats[PRINT_5_FORMATS] = { "pca", "pcA", "p8", "pcc", "pss", "pcp", "pcd", "pcj" }; -static void applyHexMode(RCore *core, int hexMode) { + +R_API void r_core_visual_applyHexMode(RCore *core, int hexMode) { currentFormat = R_ABS(hexMode) % 3; switch (currentFormat) { case 0: @@ -2364,7 +2365,7 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { { switch (core->printidx) { case R_CORE_VISUAL_MODE_PX: // 0 // xc - applyHexMode (core, --hexMode); + r_core_visual_applyHexMode (core, --hexMode); printfmtSingle[0] = printHexFormats[R_ABS(hexMode) % PRINT_HEX_FORMATS]; break; case R_CORE_VISUAL_MODE_PD: // pd @@ -2427,7 +2428,7 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { } else { switch (core->printidx) { case R_CORE_VISUAL_MODE_PX: // 0 // xc - applyHexMode (core, ++hexMode); + r_core_visual_applyHexMode (core, ++hexMode); printfmtSingle[0] = printHexFormats[R_ABS(hexMode) % PRINT_HEX_FORMATS]; break; case R_CORE_VISUAL_MODE_PD: // pd @@ -3534,7 +3535,7 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { } else { switch (core->printidx) { case R_CORE_VISUAL_MODE_PX: // 0 // xc - applyHexMode (core, --hexMode); + r_core_visual_applyHexMode (core, --hexMode); printfmtSingle[0] = printHexFormats[R_ABS(hexMode) % PRINT_HEX_FORMATS]; break; case R_CORE_VISUAL_MODE_PD: // pd diff --git a/libr/core/visual_tabs.inc b/libr/core/visual_tabs.inc index 2d47dc8ef6..8071444126 100644 --- a/libr/core/visual_tabs.inc +++ b/libr/core/visual_tabs.inc @@ -72,7 +72,7 @@ static void visual_tabset(RCore *core, RCoreVisualTab *tab) { current4format = tab->current4format; current5format = tab->current5format; r_core_visual_applyDisMode (core, disMode); - applyHexMode (core, hexMode); + r_core_visual_applyHexMode (core, hexMode); r_config_set_i (core->config, "asm.offset", tab->asm_offset); r_config_set_i (core->config, "asm.instr", tab->asm_instr); r_config_set_i (core->config, "asm.bytes", tab->asm_bytes); diff --git a/libr/include/r_core.h b/libr/include/r_core.h index 187519dbba..af75c95389 100644 --- a/libr/include/r_core.h +++ b/libr/include/r_core.h @@ -445,6 +445,7 @@ R_API void r_core_print_scrollbar_bottom(RCore *core); R_API void r_core_visual_prompt_input (RCore *core); R_API void r_core_visual_toggle_decompiler_disasm(RCore *core, bool for_graph, bool reset); R_API void r_core_visual_applyDisMode(RCore *core, int disMode); +R_API void r_core_visual_applyHexMode(RCore *core, int hexMode); R_API int r_core_visual_refs(RCore *core, bool xref, bool fcnInsteadOfAddr); R_API void r_core_visual_append_help(RStrBuf *p, const char *title, const char **help); R_API bool r_core_prevop_addr(RCore* core, ut64 start_addr, int numinstrs, ut64* prev_addr);