Skip to content

Commit

Permalink
Restructure help for visual mode.
Browse files Browse the repository at this point in the history
Add VH and VHH for key list in the visual mode.
Remove examples, but add a more detailed description about the key-sequence parameter.
  • Loading branch information
Rot127 committed Nov 27, 2024
1 parent 3037ae9 commit 53a3e52
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 112 deletions.
12 changes: 12 additions & 0 deletions librz/core/cmd/cmd_interactive.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 0 additions & 1 deletion librz/core/cmd/cmd_interactive_panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

46 changes: 29 additions & 17 deletions librz/core/cmd_descs/cmd_descs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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: <TAB>", .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 = " <key_sequence>", .comment = "The <key-sequence> 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,
Expand All @@ -17382,19 +17372,35 @@ 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,
};

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

Expand Down Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions librz/core/cmd_descs/cmd_descs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
39 changes: 16 additions & 23 deletions librz/core/cmd_descs/cmd_interactive.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: <TAB>"
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: " <key_sequence>"
comment: >
The <key-sequence> 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: []
3 changes: 3 additions & 0 deletions librz/core/core_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
154 changes: 83 additions & 71 deletions librz/core/tui/visual.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]<enter> 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]<enter> 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");
Expand Down Expand Up @@ -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);
}
}

Expand Down
Loading

0 comments on commit 53a3e52

Please sign in to comment.