From 53a3e52b4a32badffae3eb16d3d630a94c28d1ed Mon Sep 17 00:00:00 2001 From: Rot127 Date: Wed, 27 Nov 2024 11:56:35 -0500 Subject: [PATCH] Restructure help for visual mode. Add VH and VHH for key list in the visual mode. Remove examples, but add a more detailed description about the key-sequence parameter. --- librz/core/cmd/cmd_interactive.c | 12 ++ librz/core/cmd/cmd_interactive_panel.c | 1 - librz/core/cmd_descs/cmd_descs.c | 46 ++++--- librz/core/cmd_descs/cmd_descs.h | 4 + librz/core/cmd_descs/cmd_interactive.yaml | 39 +++--- librz/core/core_private.h | 3 + librz/core/tui/visual.c | 154 ++++++++++++---------- test/db/cmd/cmd_visual | 79 +++++++++++ 8 files changed, 226 insertions(+), 112 deletions(-) diff --git a/librz/core/cmd/cmd_interactive.c b/librz/core/cmd/cmd_interactive.c index 7574612333f..bfde788f894 100644 --- a/librz/core/cmd/cmd_interactive.c +++ b/librz/core/cmd/cmd_interactive.c @@ -32,3 +32,15 @@ RZ_IPI RzCmdStatus rz_interactive_visual_emu_handler(RzCore *core, int argc, con rz_core_visual(core, "pp"); return RZ_CMD_STATUS_OK; } + +RZ_IPI RzCmdStatus rz_interactive_visual_help_handler(RzCore *core, int argc, const char **argv) { + rz_core_cmd_help(core, rz_core_visual_get_short_help()); + return RZ_CMD_STATUS_OK; +} + +RZ_IPI RzCmdStatus rz_interactive_visual_help_detail_handler(RzCore *core, int argc, const char **argv) { + rz_core_cmd_help(core, rz_core_visual_get_long_help()); + rz_cons_printf("%s\n", "Function Keys: (See 'e key.'), defaults to"); + rz_core_cmd_help(core, rz_core_visual_get_fcn_help()); + return RZ_CMD_STATUS_OK; +} diff --git a/librz/core/cmd/cmd_interactive_panel.c b/librz/core/cmd/cmd_interactive_panel.c index 8b1a1c12f57..d6dd9a7e8c5 100644 --- a/librz/core/cmd/cmd_interactive_panel.c +++ b/librz/core/cmd/cmd_interactive_panel.c @@ -45,4 +45,3 @@ RZ_IPI RzCmdStatus rz_interactive_panel_store_handler(RzCore *core, int argc, co rz_config_set(core->config, "scr.layout", argv[1]); return RZ_CMD_STATUS_OK; } - diff --git a/librz/core/cmd_descs/cmd_descs.c b/librz/core/cmd_descs/cmd_descs.c index a5d646bc331..ad3b4bf07a2 100644 --- a/librz/core/cmd_descs/cmd_descs.c +++ b/librz/core/cmd_descs/cmd_descs.c @@ -65,7 +65,7 @@ static const RzCmdDescDetail history_list_or_exec_details[2]; static const RzCmdDescDetail cmd_print_byte_array_details[3]; static const RzCmdDescDetail pf_details[3]; static const RzCmdDescDetail print_rising_and_falling_entropy_details[2]; -static const RzCmdDescDetail interactive_visual_details[3]; +static const RzCmdDescDetail interactive_visual_details[2]; static const RzCmdDescDetail write_details[3]; static const RzCmdDescDetail write_bits_details[2]; static const RzCmdDescDetail wv_details[2]; @@ -17347,27 +17347,17 @@ static const RzCmdDescHelp type_xrefs_list_all_help = { static const RzCmdDescHelp V_help = { .summary = "Interactive mode", }; -static const RzCmdDescDetailEntry interactive_visual_Basic_space_usage_space__oparen_in_space_interactive_space_visual_space_mode_cparen__detail_entries[] = { - { .text = "", .arg_str = "Press: q", .comment = "Quits the current view." }, - { .text = "", .arg_str = "Press: ?", .comment = "Opens the help." }, - { .text = "", .arg_str = "Press: p", .comment = "Switches between different printing modes (disassembly, hex view, etc.)." }, - { .text = "", .arg_str = "Press: ", .comment = "Toggles different configurations of the current printing mode." }, - { 0 }, -}; - -static const RzCmdDescDetailEntry interactive_visual_Examples_detail_entries[] = { - { .text = "V", .arg_str = " ?", .comment = "Enter interactive visual mode and open the detailed help." }, - { .text = "V", .arg_str = " p", .comment = "Enter interactive visual mode and select the next printing mode." }, +static const RzCmdDescDetailEntry interactive_visual_Parameters_detail_entries[] = { + { .text = "V", .arg_str = " ", .comment = "The argument is a string of keys to press directly after entering the visual mode. See 'VH' or 'VHH' for a full list of valid keys." }, { 0 }, }; static const RzCmdDescDetail interactive_visual_details[] = { - { .name = "Basic usage (in interactive visual mode)", .entries = interactive_visual_Basic_space_usage_space__oparen_in_space_interactive_space_visual_space_mode_cparen__detail_entries }, - { .name = "Examples", .entries = interactive_visual_Examples_detail_entries }, + { .name = "Parameters", .entries = interactive_visual_Parameters_detail_entries }, { 0 }, }; static const RzCmdDescArg interactive_visual_args[] = { { - .name = "visual-commands", + .name = "key-sequence", .type = RZ_CMD_ARG_TYPE_STRING, .flags = RZ_CMD_ARG_FLAG_LAST, .optional = true, @@ -17382,11 +17372,27 @@ static const RzCmdDescHelp interactive_visual_help = { .args = interactive_visual_args, }; +static const RzCmdDescArg interactive_visual_help_args[] = { + { 0 }, +}; +static const RzCmdDescHelp interactive_visual_help_help = { + .summary = "Show most common keys shortcuts of the visual mode.", + .args = interactive_visual_help_args, +}; + +static const RzCmdDescArg interactive_visual_help_detail_args[] = { + { 0 }, +}; +static const RzCmdDescHelp interactive_visual_help_detail_help = { + .summary = "Show all keys shortcuts of the visual mode.", + .args = interactive_visual_help_detail_args, +}; + static const RzCmdDescArg interactive_visual_disas_args[] = { { 0 }, }; static const RzCmdDescHelp interactive_visual_disas_help = { - .summary = "Enter interactive visual mode and select next mode.", + .summary = "Enter interactive visual mode and select next mode (alias for 'V p').", .args = interactive_visual_disas_args, }; @@ -17394,7 +17400,7 @@ static const RzCmdDescArg interactive_visual_emu_args[] = { { 0 }, }; static const RzCmdDescHelp interactive_visual_emu_help = { - .summary = "Enter interactive visual mode and select the mode after next.", + .summary = "Enter interactive visual mode and select the mode after next (alias for 'V pp').", .args = interactive_visual_emu_args, }; @@ -22935,6 +22941,12 @@ RZ_IPI void rzshell_cmddescs_init(RzCore *core) { RzCmdDesc *V_cd = rz_cmd_desc_group_new(core->rcmd, root_cd, "V", rz_interactive_visual_handler, &interactive_visual_help, &V_help); rz_warn_if_fail(V_cd); + RzCmdDesc *interactive_visual_help_cd = rz_cmd_desc_argv_new(core->rcmd, V_cd, "VH", rz_interactive_visual_help_handler, &interactive_visual_help_help); + rz_warn_if_fail(interactive_visual_help_cd); + + RzCmdDesc *interactive_visual_help_detail_cd = rz_cmd_desc_argv_new(core->rcmd, V_cd, "VHH", rz_interactive_visual_help_detail_handler, &interactive_visual_help_detail_help); + rz_warn_if_fail(interactive_visual_help_detail_cd); + RzCmdDesc *interactive_visual_disas_cd = rz_cmd_desc_argv_new(core->rcmd, V_cd, "Vp", rz_interactive_visual_disas_handler, &interactive_visual_disas_help); rz_warn_if_fail(interactive_visual_disas_cd); diff --git a/librz/core/cmd_descs/cmd_descs.h b/librz/core/cmd_descs/cmd_descs.h index 6ed19822504..05b563fdff4 100644 --- a/librz/core/cmd_descs/cmd_descs.h +++ b/librz/core/cmd_descs/cmd_descs.h @@ -2364,6 +2364,10 @@ RZ_IPI RzCmdStatus rz_type_xrefs_graph_handler(RzCore *core, int argc, const cha RZ_IPI RzCmdStatus rz_type_xrefs_list_all_handler(RzCore *core, int argc, const char **argv); // "V" RZ_IPI RzCmdStatus rz_interactive_visual_handler(RzCore *core, int argc, const char **argv); +// "VH" +RZ_IPI RzCmdStatus rz_interactive_visual_help_handler(RzCore *core, int argc, const char **argv); +// "VHH" +RZ_IPI RzCmdStatus rz_interactive_visual_help_detail_handler(RzCore *core, int argc, const char **argv); // "Vp" RZ_IPI RzCmdStatus rz_interactive_visual_disas_handler(RzCore *core, int argc, const char **argv); // "Vpp" diff --git a/librz/core/cmd_descs/cmd_interactive.yaml b/librz/core/cmd_descs/cmd_interactive.yaml index e669344fcb3..1306423d79a 100644 --- a/librz/core/cmd_descs/cmd_interactive.yaml +++ b/librz/core/cmd_descs/cmd_interactive.yaml @@ -11,37 +11,30 @@ commands: Scrolling disassembly, debugging, searching or graph views. All with a few keyboard shortcuts. args: - - name: visual-commands + - name: key-sequence type: RZ_CMD_ARG_TYPE_STRING optional: true details: - - name: Basic usage (in interactive visual mode) + - name: Parameters entries: - - text: "" - arg_str: "Press: q" - comment: Quits the current view. - - text: "" - arg_str: "Press: ?" - comment: Opens the help. - - text: "" - arg_str: "Press: p" - comment: Switches between different printing modes (disassembly, hex view, etc.). - - text: "" - arg_str: "Press: " - comment: Toggles different configurations of the current printing mode. - - name: Examples - entries: - - text: "V" - arg_str: " ?" - comment: Enter interactive visual mode and open the detailed help. - text: "V" - arg_str: " p" - comment: Enter interactive visual mode and select the next printing mode. + arg_str: " " + comment: > + The argument is a string of keys to press directly after entering the visual mode. + See 'VH' or 'VHH' for a full list of valid keys. + - name: VH + cname: interactive_visual_help + summary: Show most common keys shortcuts of the visual mode. + args: [] + - name: VHH + cname: interactive_visual_help_detail + summary: Show all keys shortcuts of the visual mode. + args: [] - name: Vp cname: interactive_visual_disas - summary: Enter interactive visual mode and select next mode. + summary: Enter interactive visual mode and select next mode (alias for 'V p'). args: [] - name: Vpp cname: interactive_visual_emu - summary: Enter interactive visual mode and select the mode after next. + summary: Enter interactive visual mode and select the mode after next (alias for 'V pp'). args: [] diff --git a/librz/core/core_private.h b/librz/core/core_private.h index 5fd2918a79e..01807187a34 100644 --- a/librz/core/core_private.h +++ b/librz/core/core_private.h @@ -444,6 +444,9 @@ RZ_IPI void rz_core_visual_nexttab(RzCore *core); RZ_IPI void rz_core_visual_prevtab(RzCore *core); RZ_IPI void rz_core_visual_closetab(RzCore *core); +RZ_IPI const char **rz_core_visual_get_short_help(); +RZ_IPI const char **rz_core_visual_get_long_help(); +RZ_IPI const char **rz_core_visual_get_fcn_help(); RZ_IPI int rz_core_visual(RzCore *core, const char *input); RZ_IPI int rz_core_visual_graph(RzCore *core, RzAGraph *g, RzAnalysisFunction *_fcn, int is_interactive); RZ_IPI bool rz_core_visual_panels_root(RzCore *core, RzPanelsRoot *panels_root); diff --git a/librz/core/tui/visual.c b/librz/core/tui/visual.c index ee9b36118db..cdbc038cd8a 100644 --- a/librz/core/tui/visual.c +++ b/librz/core/tui/visual.c @@ -254,85 +254,97 @@ static bool __core_visual_gogo(RzCore *core, int ch) { } static const char *help_visual[] = { - "?", "full help", - "!", "enter panels", - "a", "code analysis", - "b", "browse mode", - "c", "toggle cursor", - "d", "debugger / emulator", - "e", "toggle configurations", - "i", "insert / write", - "m", "moving around (seeking)", - "p", "print commands and modes", - "v", "view management", + "?", "", "full help", + "!", "", "enter panels", + "a", "", "code analysis", + "b", "", "browse mode", + "c", "", "toggle cursor", + "d", "", "debugger / emulator", + "e", "", "toggle configurations", + "i", "", "insert / write", + "m", "", "moving around (seeking)", + "p", "", "print commands and modes", + "v", "", "view management", NULL }; static const char *help_msg_visual[] = { - "?", "show visual help menu", - "??", "show this help", - "$", "set the program counter to the current offset + cursor", - "&", "rotate asm.bits between 8, 16, 32 and 64 applying hints", - "%", "in cursor mode finds matching pair, otherwise toggle autoblocksz", - "^", "seek to the beginning of the function", - "!", "enter into the visual panels mode", - "TAB", "switch to the next print mode (or element in cursor mode)", - "_", "enter the flag/comment/functions/.. hud (same as VF_)", - "=", "set cmd.vprompt (top row)", - "|", "set cmd.cprompt (right column)", - ".", "seek to program counter", - "#", "toggle decompiler comments in disasm (see pdd* from jsdec)", - "\\", "toggle visual split mode", - "\"", "toggle the column mode (uses pC..)", - "/", "in cursor mode search in current block", - ")", "toggle emu.str", - ":cmd", "run rizin command", - ";[-]cmt", "add/remove comment", - "0", "seek to beginning of current function", - "[1-9]", "follow jmp/call identified by shortcut (like ;[1])", - ",file", "add a link to the text file", - "/*+-[]", "change block size, [] = resize hex.cols", - "<,>", "seek aligned to block size (in cursor slurp or dump files)", - "a/A", "(a)ssemble code, visual (A)ssembler", - "b", "browse evals, symbols, flags, evals, classes, ...", - "B", "toggle breakpoint", - "c/C", "toggle (c)ursor and (C)olors", - "d[f?]", "define function, data, code, ..", - "D", "enter visual diff mode (set diff.from/to)", - "f/F", "set/unset or browse flags. f- to unset, F to browse, ..", - "hjkl", "move around (left-down-up-right)", - "HJKL", "select in cursor mode (left-down-up-right)", - "i", "insert hex or string (in hexdump) use tab to toggle", - "I", "insert hexpair block ", - "mK/'K", "mark/go to Key (any key)", - "n/N", "seek next/prev function/flag/hit (scr.nkey)", - "g", "go/seek to given offset (g[g/G] to seek begin/end of file)", - "o/O", "rotate between different formats (next/prev)", - "p/P", "rotate print modes (hex, disasm, debug, words, buf)", - "q", "back to rizin shell", - "r", "toggle call/jmp/lea hints", - "R", "changes the theme or randomizes colors if scr.randpal option is true.", - "sS", "step / step over", - "tT", "tt new tab, t[1-9] switch to nth tab, t= name tab, t- close tab", - "uU", "undo/redo seek", - "v", "visual function/vars code analysis menu", - "V", "(V)iew interactive ascii art graph (agfv)", - "wW", "seek cursor to next/prev word", - "xX", "show xrefs/refs of current function from/to data/code", - "yY", "copy and paste selection", - "Enter", "follow address of jump/call", + "?", "", "show visual help menu", + "??", "", "show this help", + "$", "", "set the program counter to the current offset + cursor", + "&", "", "rotate asm.bits between 8, 16, 32 and 64 applying hints", + "%", "", "in cursor mode finds matching pair, otherwise toggle autoblocksz", + "^", "", "seek to the beginning of the function", + "!", "", "enter into the visual panels mode", + "TAB", "", "switch to the next print mode (or element in cursor mode)", + "_", "", "enter the flag/comment/functions/.. hud (same as VF_)", + "=", "", "set cmd.vprompt (top row)", + "|", "", "set cmd.cprompt (right column)", + ".", "", "seek to program counter", + "#", "", "toggle decompiler comments in disasm (see pdd* from jsdec)", + "\\", "", "toggle visual split mode", + "\"", "", "toggle the column mode (uses pC..)", + "/", "", "in cursor mode search in current block", + ")", "", "toggle emu.str", + ":cmd", "", "run rizin command", + ";[-]cmt", "", "add/remove comment", + "0", "", "seek to beginning of current function", + "[1-9]", "", "follow jmp/call identified by shortcut (like ;[1])", + ",file", "", "add a link to the text file", + "/*+-[]", "", "change block size, [] = resize hex.cols", + "<,>", "", "seek aligned to block size (in cursor slurp or dump files)", + "a/A", "", "(a)ssemble code, visual (A)ssembler", + "b", "", "browse evals, symbols, flags, evals, classes, ...", + "B", "", "toggle breakpoint", + "c/C", "", "toggle (c)ursor and (C)olors", + "d[f?]", "", "define function, data, code, ..", + "D", "", "enter visual diff mode (set diff.from/to)", + "f/F", "", "set/unset or browse flags. f- to unset, F to browse, ..", + "hjkl", "", "move around (left-down-up-right)", + "HJKL", "", "select in cursor mode (left-down-up-right)", + "i", "", "insert hex or string (in hexdump) use tab to toggle", + "I", "", "insert hexpair block", + "mK/'K", "", "mark/go to Key (any key)", + "n/N", "", "seek next/prev function/flag/hit (scr.nkey)", + "g", "", "go/seek to given offset (g[g/G] to seek begin/end of file)", + "o/O", "", "rotate between different formats (next/prev)", + "p/P", "", "rotate print modes (hex, disasm, debug, words, buf)", + "q", "", "back to rizin shell", + "r", "", "toggle call/jmp/lea hints", + "R", "", "changes the theme or randomizes colors if scr.randpal option is true.", + "sS", "", "step / step over", + "tT", "", "tt new tab, t[1-9] switch to nth tab, t= name tab, t- close tab", + "uU", "", "undo/redo seek", + "v", "", "visual function/vars code analysis menu", + "V", "", "(V)iew interactive ascii art graph (agfv)", + "wW", "", "seek cursor to next/prev word", + "xX", "", "show xrefs/refs of current function from/to data/code", + "yY", "", "copy and paste selection", + "Enter", "", "follow address of jump/call", NULL }; static const char *help_msg_visual_fn[] = { - "F2", "toggle breakpoint", - "F4", "run to cursor", - "F7", "single step", - "F8", "step over", - "F9", "continue", + "F2", "", "toggle breakpoint", + "F4", "", "run to cursor", + "F7", "", "single step", + "F8", "", "step over", + "F9", "", "continue", NULL }; +RZ_IPI const char **rz_core_visual_get_short_help() { + return help_visual; +} + +RZ_IPI const char **rz_core_visual_get_long_help() { + return help_msg_visual; +} + +RZ_IPI const char **rz_core_visual_get_fcn_help() { + return help_msg_visual_fn; +} + static void rotateAsmBits(RzCore *core) { RzAnalysisHint *hint = rz_analysis_hint_get(core->analysis, core->offset); int bits = hint ? hint->bits : rz_config_get_i(core->config, "asm.bits"); @@ -443,17 +455,17 @@ RZ_IPI void rz_core_visual_append_help(RzStrBuf *p, const char *title, const cha const char *pal_args_color = cons_ctx->color_mode ? cons_ctx->pal.args : "", *pal_help_color = cons_ctx->color_mode ? cons_ctx->pal.help : "", *pal_reset = cons_ctx->color_mode ? cons_ctx->pal.reset : ""; - for (i = 0; help[i]; i += 2) { + for (i = 0; help[i]; i += 3) { max_length = RZ_MAX(max_length, strlen(help[i])); } rz_strbuf_appendf(p, "|%s:\n", title); - for (i = 0; help[i]; i += 2) { + for (i = 0; help[i]; i += 3) { padding = max_length - (strlen(help[i])); rz_strbuf_appendf(p, "| %s%s%*s %s%s%s\n", pal_args_color, help[i], padding, "", - pal_help_color, help[i + 1], pal_reset); + pal_help_color, help[i + 2], pal_reset); } } diff --git a/test/db/cmd/cmd_visual b/test/db/cmd/cmd_visual index acef1141b45..200fc48e468 100644 --- a/test/db/cmd/cmd_visual +++ b/test/db/cmd/cmd_visual @@ -1,3 +1,82 @@ +NAME=panels VH/VHH +FILE== +CMDS=< seek aligned to block size (in cursor slurp or dump files) +| a/A (a)ssemble code, visual (A)ssembler +| b browse evals, symbols, flags, evals, classes, ... +| B toggle breakpoint +| c/C toggle (c)ursor and (C)olors +| d[f?] define function, data, code, .. +| D enter visual diff mode (set diff.from/to) +| f/F set/unset or browse flags. f- to unset, F to browse, .. +| hjkl move around (left-down-up-right) +| HJKL select in cursor mode (left-down-up-right) +| i insert hex or string (in hexdump) use tab to toggle +| I insert hexpair block +| mK/'K mark/go to Key (any key) +| n/N seek next/prev function/flag/hit (scr.nkey) +| g go/seek to given offset (g[g/G] to seek begin/end of file) +| o/O rotate between different formats (next/prev) +| p/P rotate print modes (hex, disasm, debug, words, buf) +| q back to rizin shell +| r toggle call/jmp/lea hints +| R changes the theme or randomizes colors if scr.randpal option is true. +| sS step / step over +| tT tt new tab, t[1-9] switch to nth tab, t= name tab, t- close tab +| uU undo/redo seek +| v visual function/vars code analysis menu +| V (V)iew interactive ascii art graph (agfv) +| wW seek cursor to next/prev word +| xX show xrefs/refs of current function from/to data/code +| yY copy and paste selection +| Enter follow address of jump/call +Function Keys: (See 'e key.'), defaults to +| F2 toggle breakpoint +| F4 run to cursor +| F7 single step +| F8 step over +| F9 continue +EOF +RUN + NAME=panels vl/vs FILE== CMDS=<