From a8dd668d7e4ca40b80b2e27aac7e09110d00724b Mon Sep 17 00:00:00 2001 From: Riccardo Schirone <562321+ret2libc@users.noreply.github.com> Date: Thu, 14 Sep 2023 02:53:25 +0200 Subject: [PATCH] Fix old math commands (#3828) * core/cmd: Adjust math commands * shell: make `?x` commands a parsing failure We have moved the `?x` commands to `%x`, thus now no command should start with `?`. This patch makes the parser fail to parse `?x` strings. * core/tui: use APIs in panels * There's no `%q` anymore, use `%=` --- doc/debug.md | 4 +- doc/hud | 46 ++-- librz/analysis/p/analysis_mips_gnu.c | 2 +- librz/bin/format/xnu/scripts/machtraps.py | 4 +- librz/core/cautocmpl.c | 2 +- librz/core/cbin.c | 1 - librz/core/cconfig.c | 2 +- librz/core/cfile.c | 4 +- librz/core/cmd/cmd.c | 8 +- librz/core/cmd/cmd_math.c | 80 +++---- librz/core/cmd/cmd_print.c | 81 ++++--- librz/core/cmd_descs/cmd_debug.yaml | 2 +- librz/core/cmd_descs/cmd_descs.c | 210 +++++++++--------- librz/core/cmd_descs/cmd_descs.h | 8 +- librz/core/cmd_descs/cmd_descs.yaml | 4 +- librz/core/cmd_descs/cmd_math.yaml | 192 ++++++++-------- librz/core/tui/config.c | 2 +- librz/core/tui/define.c | 4 +- librz/core/tui/panels.c | 18 +- librz/core/tui/vasm.c | 2 +- librz/core/tui/vmenus_graph.c | 2 +- librz/include/rz_egg.h | 14 -- librz/type/format.c | 4 +- .../corpus/cmd_substitution.txt | 10 +- .../rizin-shell-parser/corpus/comments.txt | 6 +- .../rizin-shell-parser/corpus/escape_args.txt | 4 +- .../corpus/grep_commands.txt | 6 +- .../corpus/iter_commands.txt | 4 +- .../rizin-shell-parser/corpus/quoted_args.txt | 14 +- .../corpus/simple_commands.txt | 36 ++- .../corpus/special_commands.txt | 2 +- subprojects/rizin-shell-parser/src/scanner.c | 11 +- .../db/archos/not-windows-any/cmd_interpreter | 2 +- test/db/cmd/cmd_pipe | 6 +- test/db/cmd/feat_input | 2 +- test/db/tools/rz | 2 +- test/notworking_db/darwin-x64/dbg | 4 +- test/notworking_db/darwin-x64/dbg_cmdbps | 4 +- test/notworking_db/darwin-x64/dbg_dcu | 4 +- test/notworking_db/darwin-x64/dbg_step | 4 +- test/scripts/rztest.spp | 2 +- 41 files changed, 418 insertions(+), 401 deletions(-) diff --git a/doc/debug.md b/doc/debug.md index e73c04f112b..bf0d1ac815e 100644 --- a/doc/debug.md +++ b/doc/debug.md @@ -10,7 +10,7 @@ conditional breakpoints are implemented in the following way: 1. ignore breakpoint at address `0x4000ce` for five times: f times=5 - (dec_times,f times=`?vi times-1`,?= times) + (dec_times,f times=`%vi times-1`,?= times) db @ 0x4000ce dbC .(dec_times) @ 0x4000ce dc @@ -18,7 +18,7 @@ conditional breakpoints are implemented in the following way: 2. execute until rax==0x31c0 at address `0x4000ce` e cmd.hitinfo=0 - (break_rax,f reg_rax=`dr rax`,f test=`?vi reg_rax-0x31c0`,?= test) + (break_rax,f reg_rax=`dr rax`,f test=`%vi reg_rax-0x31c0`,?= test) db @ 0x4000ce dbC .(break_rax) @ 0x4000ce dc diff --git a/doc/hud b/doc/hud index c5c47eb32ff..635b4828204 100644 --- a/doc/hud +++ b/doc/hud @@ -1,10 +1,10 @@ -add comment;?i Comment;CC `ys` -list comments;CC;?ik -change block size;?i block size;b `ys` +add comment;%i Comment;CC `ys` +list comments;CC;%ik +change block size;%i block size;b `ys` analyze all;aa analyze function;af analyze preludes;ap -continue process execution;dc;?i +continue process execution;dc;%i disable colors;e scr.color=0 enable colors (ANSI 16);e scr.color=1 enable colors (256);e scr.color=2 @@ -12,27 +12,27 @@ enable colors (16M);e scr.color=3 randomize colors;ecr hide bytes in disassembly;e asm.bytes=false show bytes in disassembly;e asm.bytes=true -list imports ;ii;?ik -list sections;iS;?ik -list symbols;is;?ik -list processes;dp*;?ik -run command;?i cmd;`ys`;?ik +list imports ;ii;%ik +list sections;iS;%ik +list symbols;is;%ik +list processes;dp*;%ik +run command;%i cmd;`ys`;%ik seek to entrypoint;s entry0 seek to main;s main -set breakpoint;db;?i new breakpoint address;db `ys` -remove breakpoint ?i delete breakpoint at given address;db-`ys` -show backtrace;dbt;?ik +set breakpoint;db;%i new breakpoint address;db `ys` +remove breakpoint %i delete breakpoint at given address;db-`ys` +show backtrace;dbt;%ik show bytes in disassembly;e asm.bytes=1 -show debugger register values;dr;?ik -show process memory maps;dm;?ik -step instruction;sr PC;pd 1;ds;?ik -step over call;sr PC;pd 1;dso;?ik -write string;?i string;w `ys` -write hexadecimal data in current offset;?i hexpairs;wx `ys` -xor current block with hexpair key;?i hexpair key;wox `ys` +show debugger register values;dr;%ik +show process memory maps;dm;%ik +step instruction;sr PC;pd 1;ds;%ik +step over call;sr PC;pd 1;dso;%ik +write string;%i string;w `ys` +write hexadecimal data in current offset;%i hexpairs;wx `ys` +xor current block with hexpair key;%i hexpair key;wox `ys` edit eval configuration;Veq -calculator;?i enter math expression;? `ys`;?ik +calculator;%i enter math expression;? `ys`;%ik disassemble 1024 bytes and pipe to less(1);b 1024;pd|less -R -rename function;?i New name;afn `ys` -set flag;?i Flag name;f `ys` -unset flag;?i Flag name to delete;f-`ys` +rename function;%i New name;afn `ys` +set flag;%i Flag name;f `ys` +unset flag;%i Flag name to delete;f-`ys` diff --git a/librz/analysis/p/analysis_mips_gnu.c b/librz/analysis/p/analysis_mips_gnu.c index ae96b056d2d..cdbe1eb3838 100644 --- a/librz/analysis/p/analysis_mips_gnu.c +++ b/librz/analysis/p/analysis_mips_gnu.c @@ -1461,7 +1461,7 @@ static int mips_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 // TODO: currently there is no way for the macro to get access to this register op->src[0] = rz_analysis_value_new(); op->src[0]->reg = rz_reg_get(analysis->reg, mips_reg_decode(rs), RZ_REG_TYPE_GPR); - op->val = imm; // Beware: this one is signed... use `?vi $v` + op->val = imm; // Beware: this one is signed... use `%vi $v` if (rs == 0) { insn.id = MIPS_INS_LI; snprintf((char *)insn.i_reg.imm, REG_BUF_MAX, "0x%" PFMT32x, imm); diff --git a/librz/bin/format/xnu/scripts/machtraps.py b/librz/bin/format/xnu/scripts/machtraps.py index 17fef960462..c7ca1ed2cf4 100644 --- a/librz/bin/format/xnu/scripts/machtraps.py +++ b/librz/bin/format/xnu/scripts/machtraps.py @@ -39,12 +39,12 @@ def walk_back_until(addr, pattern, min_addr): def carve_trap_num(addr, flag): - saved_seek = r.cmd("?v $$") + saved_seek = r.cmd("%v $$") r.cmd("e io.cache=true") r.cmd("e emu.write=true") r.cmd("aei") r.cmd("aeim") - min_addr = int(r.cmd("?v " + flag), 0) + min_addr = int(r.cmd("%v " + flag), 0) emu_start = walk_back_until(addr - 4, r"^b|^ret|^invalid", min_addr) r.cmd("s " + str(emu_start)) obj = r.cmd("aefa 0x%08x~[0]:0" % addr) diff --git a/librz/core/cautocmpl.c b/librz/core/cautocmpl.c index b0425f08d94..aeb55296f44 100644 --- a/librz/core/cautocmpl.c +++ b/librz/core/cautocmpl.c @@ -68,7 +68,7 @@ static void guess_data_free(struct guess_data_t *g) { /** * Modify the input in \p buf to add additional characters, trying to detect * what token could go in the current position of the buffer. For example, to - * detect that a CMD_ID is expected at * `?e $(`, you could try inserting + * detect that a CMD_ID is expected at `echo $(`, you could try inserting * a letter and see what would be the new syntax tree. */ static struct guess_data_t *guess_next_autocmplt_token(RzCore *core, RzLineBuffer *buf, const char *fake_text, size_t offset) { diff --git a/librz/core/cbin.c b/librz/core/cbin.c index e0205559f1c..6d522cb939a 100644 --- a/librz/core/cbin.c +++ b/librz/core/cbin.c @@ -102,7 +102,6 @@ RZ_API void rz_core_bin_export_info(RzCore *core, int mode) { char *k = sdbkv_key(kv); char *v = sdbkv_value(kv); char *dup = strdup(k); - // printf ("?e (%s) (%s)\n", k, v); if ((flagname = strstr(dup, ".offset"))) { *flagname = 0; flagname = dup; diff --git a/librz/core/cconfig.c b/librz/core/cconfig.c index 356ebb0de31..b702a60dc86 100644 --- a/librz/core/cconfig.c +++ b/librz/core/cconfig.c @@ -3264,7 +3264,7 @@ RZ_API int rz_core_config_init(RzCore *core) { SETPREF("cfg.user", rz_sys_whoami(buf), "Set current username/pid"); SETCB("cfg.fortunes", "true", &cb_cfg_fortunes, "If enabled show tips at start"); SETCB("cfg.fortunes.file", "tips", &cb_cfg_fortunes_file, "Type of fortunes to show (tips, fun)"); - SETBPREF("cfg.fortunes.clippy", "false", "Use ?E instead of ?e"); + SETBPREF("cfg.fortunes.clippy", "false", "Use 'clippy' instead of 'echo'"); SETPREF("cfg.prefixdump", "dump", "Filename prefix for automated dumps"); SETBPREF("cfg.wseek", "false", "Seek after write"); SETICB("cfg.seek.histsize", 63, NULL, "Maximum size of the seek history"); diff --git a/librz/core/cfile.c b/librz/core/cfile.c index a4aaf72e255..5c401422e8a 100644 --- a/librz/core/cfile.c +++ b/librz/core/cfile.c @@ -617,9 +617,9 @@ static bool setbpint(RzCore *r, const char *mode, const char *sym) { if (bp) { bp->internal = true; #if __linux__ - bp->data = rz_str_newf("?e %s: %s", mode, sym); + bp->data = rz_str_newf("echo %s: %s", mode, sym); #else - bp->data = rz_str_newf("?e %s: %s;ps@rdi", mode, sym); + bp->data = rz_str_newf("echo %s: %s;ps@rdi", mode, sym); #endif return true; } diff --git a/librz/core/cmd/cmd.c b/librz/core/cmd/cmd.c index a85bc2cf6d9..4ab4a5f00f3 100644 --- a/librz/core/cmd/cmd.c +++ b/librz/core/cmd/cmd.c @@ -1879,7 +1879,7 @@ static int rz_core_cmd_subst_i(RzCore *core, char *cmd, char *colon, bool *tmpse if (ptr[1] == '!') { str = rz_core_cmd_str_pipe(core, ptr + 1); } else { - // Color disabled when doing backticks ?e `pi 1` + // Color disabled when doing backticks echo `pi 1` int ocolor = rz_config_get_i(core->config, "scr.color"); rz_config_set_i(core->config, "scr.color", 0); core->cmd_in_backticks = true; @@ -3972,11 +3972,13 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(help_stmt) { if (node_str_len >= 2 && !strcmp(node_string + node_str_len - 2, "?*")) { node_string[node_str_len - 2] = 0; const char *argv[2] = { NULL, node_string }; - return rz_cmd_help_search_handler(state->core, 2, argv, RZ_OUTPUT_MODE_STANDARD); + int argc = node_str_len > 2 ? 2 : 1; + return rz_cmd_help_search_handler(state->core, argc, argv, RZ_OUTPUT_MODE_STANDARD); } else if (node_str_len >= 3 && !strcmp(node_string + node_str_len - 3, "?*j")) { node_string[node_str_len - 3] = 0; const char *argv[2] = { NULL, node_string }; - return rz_cmd_help_search_handler(state->core, 2, argv, RZ_OUTPUT_MODE_JSON); + int argc = node_str_len > 2 ? 2 : 1; + return rz_cmd_help_search_handler(state->core, argc, argv, RZ_OUTPUT_MODE_JSON); } TSNode command = ts_node_child_by_field_name(node, "command", strlen("command")); diff --git a/librz/core/cmd/cmd_math.c b/librz/core/cmd/cmd_math.c index f809679dbcc..e44d8561d59 100644 --- a/librz/core/cmd/cmd_math.c +++ b/librz/core/cmd/cmd_math.c @@ -31,7 +31,7 @@ struct rz_core_var core_vars[] = { { "$b", "block size" }, { "$c", "get terminal width in character columns" }, { "$Cn", "get nth call of function" }, - { "$D", "current debug map base address ?v $D @ rsp" }, + { "$D", "current debug map base address %v $D @ rsp" }, { "$DB", "same as dbg.baddr, progam base address" }, { "$DD", "current debug map size" }, { "$Dn", "get nth data reference in function" }, @@ -258,33 +258,23 @@ RZ_IPI RzCmdStatus rz_print_binary_handler(RzCore *core, int argc, const char ** } RZ_IPI RzCmdStatus rz_base64_encode_handler(RzCore *core, int argc, const char **argv) { - char *buf = NULL; - for (int i = 1; i < argc; i++) { - const int buflen = (strlen(argv[i]) * 4) + 1; - buf = (char *)realloc((void *)buf, buflen * sizeof(char)); - if (!buf) { - RZ_LOG_ERROR("core: Out of memory!"); - return RZ_CMD_STATUS_ERROR; - } - rz_base64_encode(buf, (const ut8 *)argv[i], strlen(argv[i])); - rz_cons_println((const char *)buf); + char *buf = rz_base64_encode_dyn((ut8 *)argv[1], strlen(argv[1])); + if (!buf) { + RZ_LOG_ERROR("core: Out of memory!"); + return RZ_CMD_STATUS_ERROR; } + rz_cons_println(buf); free(buf); return RZ_CMD_STATUS_OK; } RZ_IPI RzCmdStatus rz_base64_decode_handler(RzCore *core, int argc, const char **argv) { - ut8 *buf = NULL; - for (int i = 1; i < argc; i++) { - const int buflen = (strlen(argv[i]) * 4) + 1; - buf = (ut8 *)realloc((void *)buf, buflen * sizeof(ut8)); - if (!buf) { - RZ_LOG_ERROR("core: Out of memory!"); - return RZ_CMD_STATUS_ERROR; - } - rz_base64_decode(buf, argv[i], -1); - rz_cons_println((const char *)buf); + ut8 *buf = rz_base64_decode_dyn(argv[1], -1); + if (!buf) { + RZ_LOG_ERROR("core: Out of memory!"); + return RZ_CMD_STATUS_ERROR; } + rz_cons_println((char *)buf); free(buf); return RZ_CMD_STATUS_OK; } @@ -298,7 +288,7 @@ RZ_IPI RzCmdStatus rz_check_between_handler(RzCore *core, int argc, const char * } RZ_IPI RzCmdStatus rz_print_boundaries_prot_handler(RzCore *core, int argc, const char **argv) { - const char *mode = rz_str_trim_head_ro(argv[0]); + const char *mode = rz_str_trim_head_ro(argv[1]); RzList *list = rz_core_get_boundaries_prot(core, -1, mode, "search"); if (!list) { RZ_LOG_ERROR("core: Failed to get boundaries protection values in RzList"); @@ -314,10 +304,8 @@ RZ_IPI RzCmdStatus rz_print_boundaries_prot_handler(RzCore *core, int argc, cons } RZ_IPI RzCmdStatus rz_print_djb2_hash_handler(RzCore *core, int argc, const char **argv) { - for (int i = 1; i < argc; i++) { - ut32 hash = (ut32)rz_str_djb2_hash(argv[i]); - rz_cons_printf("0x%08x\n", hash); - } + ut32 hash = (ut32)rz_str_djb2_hash(argv[1]); + rz_cons_printf("0x%08x\n", hash); return RZ_CMD_STATUS_OK; } @@ -345,10 +333,6 @@ RZ_IPI RzCmdStatus rz_num_to_units_handler(RzCore *core, int argc, const char ** } RZ_IPI RzCmdStatus rz_set_last_eval_expr_handler(RzCore *core, int argc, const char **argv) { - if (core->num->dbz) { - RZ_LOG_ERROR("core: RzNum ERROR: Division by Zero\n"); - return RZ_CMD_STATUS_ERROR; - } rz_num_math(core->num, argv[1]); return RZ_CMD_STATUS_OK; } @@ -369,7 +353,7 @@ RZ_IPI RzCmdStatus rz_show_value_hex_handler(RzCore *core, int argc, const char RZ_LOG_ERROR("core: RzNum ERROR: Division by Zero\n"); return RZ_CMD_STATUS_ERROR; } - rz_cons_printf("0x%08" PFMT64x "\n", n); // differs from ?v here 0x%08 + rz_cons_printf("0x%08" PFMT64x "\n", n); // differs from %v here 0x%08 return RZ_CMD_STATUS_OK; } @@ -421,11 +405,6 @@ RZ_IPI RzCmdStatus rz_show_value_int_handler(RzCore *core, int argc, const char return RZ_CMD_STATUS_OK; } -RZ_IPI RzCmdStatus rz_set_core_num_value_handler(RzCore *core, int argc, const char **argv) { - rz_num_math(core->num, argv[1]); - return RZ_CMD_STATUS_OK; -} - RZ_IPI RzCmdStatus rz_compare_and_set_core_num_value_handler(RzCore *core, int argc, const char **argv) { core->num->value = strcmp(argv[1], argv[2]); return RZ_CMD_STATUS_OK; @@ -596,7 +575,7 @@ RZ_IPI RzCmdStatus rz_yank_hud_file_handler(RzCore *core, int argc, const char * return RZ_CMD_STATUS_OK; } -RZ_IPI RzCmdStatus rz_input_numerical_expr_handler(RzCore *core, int argc, const char **argv) { +static RzCmdStatus prompt_handler(RzCore *core, int argc, const char **argv, bool echo) { if (!rz_cons_is_interactive()) { RZ_LOG_ERROR("core: Not running in interactive mode\n"); return RZ_CMD_STATUS_WRONG_ARGS; @@ -611,27 +590,36 @@ RZ_IPI RzCmdStatus rz_input_numerical_expr_handler(RzCore *core, int argc, const rz_core_yank_set_str(core, RZ_CORE_FOREIGN_ADDR, foo); core->num->value = rz_num_math(core->num, foo); rz_cons_set_raw(0); + if (echo) { + rz_cons_printf("%s\n", foo); + } return RZ_CMD_STATUS_OK; } -RZ_IPI RzCmdStatus rz_input_yesno_no_handler(RzCore *core, int argc, const char **argv) { +RZ_IPI RzCmdStatus rz_input_prompt_handler(RzCore *core, int argc, const char **argv) { + return prompt_handler(core, argc, argv, false); +} + +RZ_IPI RzCmdStatus rz_input_prompt_echo_handler(RzCore *core, int argc, const char **argv) { + return prompt_handler(core, argc, argv, true); +} + +static RzCmdStatus yesno_handler(RzCore *core, int argc, const char **argv, const char *yn) { if (!rz_cons_is_interactive()) { RZ_LOG_ERROR("core: Not running in interactive mode\n"); return RZ_CMD_STATUS_WRONG_ARGS; } - core->num->value = rz_cons_yesno(0, "%s? (y/N)", argv[1]); + core->num->value = rz_cons_yesno(0, "%s? (%s) ", argv[1], yn); rz_cons_set_raw(0); return RZ_CMD_STATUS_OK; } +RZ_IPI RzCmdStatus rz_input_yesno_no_handler(RzCore *core, int argc, const char **argv) { + return yesno_handler(core, argc, argv, "y/N"); +} + RZ_IPI RzCmdStatus rz_input_yesno_yes_handler(RzCore *core, int argc, const char **argv) { - if (!rz_cons_is_interactive()) { - RZ_LOG_ERROR("core: Not running in interactive mode\n"); - return RZ_CMD_STATUS_WRONG_ARGS; - } - core->num->value = rz_cons_yesno(0, "%s? (Y/n)", argv[1]); - rz_cons_set_raw(0); - return RZ_CMD_STATUS_OK; + return yesno_handler(core, argc, argv, "Y/n"); } RZ_IPI RzCmdStatus rz_input_any_key_handler(RzCore *core, int argc, const char **argv) { diff --git a/librz/core/cmd/cmd_print.c b/librz/core/cmd/cmd_print.c index f6631b26da5..9f39bcc6dc9 100644 --- a/librz/core/cmd/cmd_print.c +++ b/librz/core/cmd/cmd_print.c @@ -2399,7 +2399,7 @@ static inline char *__refs(RzCore *core, ut64 x) { return refs; } -static bool cmd_pxr(RzCore *core, int len, RzCmdStateOutput *state, int wordsize, const char *query) { +static bool cmd_pxr(RzCore *core, ut64 at, int len, RzCmdStateOutput *state, int wordsize, const char *query) { if (!len) { return true; } @@ -2422,7 +2422,7 @@ static bool cmd_pxr(RzCore *core, int len, RzCmdStateOutput *state, int wordsize rz_table_add_column(t, n, "value", 0); rz_table_add_column(t, s, "refs", 0); for (ut64 i = 0; i + wordsize < end; i += wordsize) { - ut64 addr = core->offset + i; + ut64 addr = at + i; ut64 val = rz_read_ble(buf + i, be, bitsize); char *refs = __refs(core, val); rz_table_add_rowf(t, "xxs", addr, val, refs); @@ -2434,7 +2434,7 @@ static bool cmd_pxr(RzCore *core, int len, RzCmdStateOutput *state, int wordsize const int hex_depth = (int)rz_config_get_i(core->config, "hex.depth"); pj_a(pj); for (ut64 i = 0; i + wordsize < end; i += wordsize) { - ut64 addr = core->offset + i; + ut64 addr = at + i; ut64 val = rz_read_ble(buf + i, be, bitsize); pj_o(pj); pj_kn(pj, "addr", addr); @@ -2459,7 +2459,7 @@ static bool cmd_pxr(RzCore *core, int len, RzCmdStateOutput *state, int wordsize } } else if (mode == RZ_OUTPUT_MODE_RIZIN) { for (ut64 i = 0; i + wordsize < end; i += wordsize) { - ut64 addr = core->offset + i; + ut64 addr = at + i; ut64 val = rz_read_ble(buf + i, be, bitsize); rz_strbuf_appendf(sb, "f pxr.%" PFMT64x " @ 0x%" PFMT64x "\n", val, addr); } @@ -3458,7 +3458,7 @@ RZ_IPI RzCmdStatus rz_print_hexword_references_common_handler(RzCore *core, int case 2: case 4: case 8: - cmd_pxr(core, len, state, wordsize, query); + cmd_pxr(core, core->offset, len, state, wordsize, query); break; default: rz_warn_if_reached(); @@ -5523,13 +5523,38 @@ RZ_IPI RzCmdStatus rz_print_columns_disassembly_handler(RzCore *core, int argc, return RZ_CMD_STATUS_OK; } +static void print_stack(RzCore *core) { + RzCmdStateOutput so; + ut64 sp_addr = rz_core_reg_getv_by_role_or_name(core, "SP"); + if (rz_config_get_b(core->config, "dbg.slow")) { + rz_cmd_state_output_init(&so, RZ_OUTPUT_MODE_STANDARD); + int wordsize = rz_analysis_get_address_bits(core->analysis) / 8; + cmd_pxr(core, sp_addr, 128, &so, wordsize, NULL); + rz_cmd_state_output_print(&so); + rz_cmd_state_output_fini(&so); + } else if (rz_config_get_b(core->config, "stack.bytes")) { + char *string = rz_core_print_hexdump_or_hexdiff_str(core, RZ_OUTPUT_MODE_STANDARD, sp_addr, 128, false); + if (!string) { + RZ_LOG_ERROR("fail to print hexdump at 0x%" PFMT64x "\n", sp_addr); + return; // TODO: free stuff + } + rz_cons_print(string); + } else if (core->rasm->bits == 64) { + rz_core_print_dump(core, RZ_OUTPUT_MODE_STANDARD, sp_addr, 8, 128, RZ_CORE_PRINT_FORMAT_TYPE_HEXADECIMAL); + } else if (core->rasm->bits == 32) { + rz_core_print_dump(core, RZ_OUTPUT_MODE_STANDARD, sp_addr, 4, 128, RZ_CORE_PRINT_FORMAT_TYPE_HEXADECIMAL); + } + rz_cmd_state_output_init(&so, RZ_OUTPUT_MODE_STANDARD); + core_disassembly(core, core->blocksize, 0, &so, false); + rz_cmd_state_output_fini(&so); +} + RZ_IPI RzCmdStatus rz_print_columns_debug_handler(RzCore *core, int argc, const char **argv) { if (!rz_config_get_b(core->config, "cfg.debug")) { RZ_LOG_ERROR("Command works only in debug mode\n"); return RZ_CMD_STATUS_ERROR; } int h, w = rz_cons_get_size(&h); - int i; int rows = h - 2; int obsz = core->blocksize; int user_rows = argc > 1 ? rz_num_math(core->num, argv[1]) : -1; @@ -5549,32 +5574,32 @@ RZ_IPI RzCmdStatus rz_print_columns_debug_handler(RzCore *core, int argc, const ut64 osek = core->offset; c->color = rz_config_get_i(core->config, "scr.color"); rz_core_block_size(core, rows * 32); - char *cmd = NULL; - int columns = 2; - for (i = 0; i < columns; i++) { - switch (i) { - case 0: - (void)rz_cons_canvas_gotoxy(c, 0, 0); - // TODO: Use the API directly - cmd = rz_str_newf("dr; ?e; ?e backtrace:; dbt"); - break; - case 1: - (void)rz_cons_canvas_gotoxy(c, 28, 0); - // TODO: Use the API directly - // cmd = rz_str_newf ("pxw 128@r:SP;pd@r:PC"); - cmd = rz_str_newf("%s 128 @r:SP; pd @ 0x%" PFMT64x, rz_core_print_stack_command(core), osek); - break; - } - char *dis = rz_core_cmd_str(core, cmd); - rz_cons_canvas_write(c, dis); - free(cmd); - free(dis); - } + + // Left column + RzCmdStateOutput so; + (void)rz_cons_canvas_gotoxy(c, 0, 0); + rz_cons_push(); + rz_debug_regs_args_handler(core, 0, NULL, RZ_OUTPUT_MODE_STANDARD); + rz_cons_print("\nbacktrace:\n"); + rz_cmd_state_output_init(&so, RZ_OUTPUT_MODE_STANDARD); + rz_cmd_debug_display_bt_handler(core, 0, NULL, &so); + rz_cmd_state_output_print(&so); + rz_cmd_state_output_fini(&so); + rz_cons_canvas_write(c, rz_cons_get_buffer()); + rz_cons_pop(); + + // Right column + (void)rz_cons_canvas_gotoxy(c, RZ_MAX(w / 3, 28), 0); + rz_cons_push(); + print_stack(core); + rz_cons_canvas_write(c, rz_cons_get_buffer()); + rz_cons_pop(); + rz_core_block_size(core, obsz); rz_core_seek(core, osek, true); - rz_cons_canvas_print(c); rz_cons_canvas_free(c); + if (asm_minicols) { rz_config_set(core->config, "asm.offset", o_ao); rz_config_set(core->config, "asm.bytes", o_ab); diff --git a/librz/core/cmd_descs/cmd_debug.yaml b/librz/core/cmd_descs/cmd_debug.yaml index 93111d438d0..fe8104d76eb 100644 --- a/librz/core/cmd_descs/cmd_debug.yaml +++ b/librz/core/cmd_descs/cmd_debug.yaml @@ -61,7 +61,7 @@ commands: - name: Usage example entries: - text: "Example of a condition" - comment: "?v rax-0x0" + comment: "%v rax-0x0" - name: dbd summary: Disable breakpoint at current offset cname: cmd_debug_disable_bp diff --git a/librz/core/cmd_descs/cmd_descs.c b/librz/core/cmd_descs/cmd_descs.c index b7176ada963..11f585adb15 100644 --- a/librz/core/cmd_descs/cmd_descs.c +++ b/librz/core/cmd_descs/cmd_descs.c @@ -119,7 +119,6 @@ static const RzCmdDescArg print_djb2_hash_args[2]; static const RzCmdDescArg print_bitstring_args[3]; static const RzCmdDescArg eval_expr_print_octal_args[2]; static const RzCmdDescArg num_to_units_args[2]; -static const RzCmdDescArg set_last_eval_expr_args[2]; static const RzCmdDescArg show_value_args[2]; static const RzCmdDescArg show_value_hex_args[2]; static const RzCmdDescArg show_value_i1_args[2]; @@ -127,7 +126,7 @@ static const RzCmdDescArg show_value_i2_args[2]; static const RzCmdDescArg show_value_i4_args[2]; static const RzCmdDescArg show_value_i8_args[2]; static const RzCmdDescArg show_value_int_args[2]; -static const RzCmdDescArg set_core_num_value_args[2]; +static const RzCmdDescArg set_last_eval_expr_args[2]; static const RzCmdDescArg compare_and_set_core_num_value_args[3]; static const RzCmdDescArg exec_cmd_if_core_num_value_positive_args[2]; static const RzCmdDescArg exec_cmd_if_core_num_value_negative_args[2]; @@ -142,7 +141,8 @@ static const RzCmdDescArg generate_sequence_args[4]; static const RzCmdDescArg phys2virt_args[2]; static const RzCmdDescArg virt2phys_args[2]; static const RzCmdDescArg yank_hud_file_args[2]; -static const RzCmdDescArg input_numerical_expr_args[2]; +static const RzCmdDescArg input_prompt_args[2]; +static const RzCmdDescArg input_prompt_echo_args[2]; static const RzCmdDescArg input_yesno_no_args[2]; static const RzCmdDescArg input_yesno_yes_args[2]; static const RzCmdDescArg input_yank_hud_args[2]; @@ -1042,8 +1042,8 @@ static const RzCmdDescHelp tasks_wait_help = { static const RzCmdDescDetailEntry oparen__Examples_detail_entries[] = { { .text = "(", .arg_str = "", .comment = "List defined macros" }, - { .text = "(", .arg_str = "foo; ?e Disassemble 10 bytes at 0x10000; pd 10 @ 0x10000)", .comment = "Define a new macro 'foo', which executes `?` followed by `pd` when called." }, - { .text = "(", .arg_str = "foo a b; ?e Disassemble ${a} bytes at ${b}; pd ${a} @ ${b})", .comment = "Define a new macro 'foo' with two arguments. ${a}/${b} are replaced before execution." }, + { .text = "(", .arg_str = "foo; echo Disassemble 10 bytes at 0x10000; pd 10 @ 0x10000)", .comment = "Define a new macro 'foo', which executes `?` followed by `pd` when called." }, + { .text = "(", .arg_str = "foo a b; echo Disassemble ${a} bytes at ${b}; pd ${a} @ ${b})", .comment = "Define a new macro 'foo' with two arguments. ${a}/${b} are replaced before execution." }, { .text = "(-", .arg_str = "foo", .comment = "Remove previously defined macro named 'foo'" }, { 0 }, }; @@ -1482,7 +1482,7 @@ static const RzCmdDescArg calculate_expr_args[] = { { 0 }, }; static const RzCmdDescHelp calculate_expr_help = { - .summary = "Evaluate given numerical expression", + .summary = "Evaluate numerical expression ", .args = calculate_expr_args, }; @@ -1533,16 +1533,13 @@ static const RzCmdDescArg generate_random_number_args[] = { { 0 }, }; static const RzCmdDescHelp generate_random_number_help = { - .summary = "Generate random number", + .summary = "Generate a random number between and ", .args = generate_random_number_args, }; -static const RzCmdDescHelp perc_b_help = { - .summary = "Base64 encode/decode and print binary commands", -}; static const RzCmdDescArg print_binary_args[] = { { - .name = "num", + .name = "expr", .type = RZ_CMD_ARG_TYPE_RZNUM, .flags = RZ_CMD_ARG_FLAG_LAST, @@ -1550,7 +1547,7 @@ static const RzCmdDescArg print_binary_args[] = { { 0 }, }; static const RzCmdDescHelp print_binary_help = { - .summary = "Print binary format", + .summary = "Print in binary format", .args = print_binary_args, }; @@ -1564,15 +1561,15 @@ static const RzCmdDescDetail base64_encode_details[] = { }; static const RzCmdDescArg base64_encode_args[] = { { - .name = "strs", + .name = "str", .type = RZ_CMD_ARG_TYPE_STRING, - .flags = RZ_CMD_ARG_FLAG_ARRAY, + .flags = RZ_CMD_ARG_FLAG_LAST, }, { 0 }, }; static const RzCmdDescHelp base64_encode_help = { - .summary = "Base64 encode", + .summary = "Encode in Base64", .details = base64_encode_details, .args = base64_encode_args, }; @@ -1587,15 +1584,15 @@ static const RzCmdDescDetail base64_decode_details[] = { }; static const RzCmdDescArg base64_decode_args[] = { { - .name = "b64strs", + .name = "str", .type = RZ_CMD_ARG_TYPE_STRING, - .flags = RZ_CMD_ARG_FLAG_ARRAY, + .flags = RZ_CMD_ARG_FLAG_LAST, }, { 0 }, }; static const RzCmdDescHelp base64_decode_help = { - .summary = "Base64 decode. Maximum input length = 4*(strlen(str)).", + .summary = "Decode from Base64", .details = base64_decode_details, .args = base64_decode_args, }; @@ -1620,7 +1617,7 @@ static const RzCmdDescArg check_between_args[] = { { 0 }, }; static const RzCmdDescHelp check_between_help = { - .summary = "Check if middle number is between the other two (first and last)", + .summary = "Check if number is between and ", .args = check_between_args, }; @@ -1659,15 +1656,15 @@ static const RzCmdDescDetail print_djb2_hash_details[] = { }; static const RzCmdDescArg print_djb2_hash_args[] = { { - .name = "strs", + .name = "", .type = RZ_CMD_ARG_TYPE_STRING, - .flags = RZ_CMD_ARG_FLAG_ARRAY, + .flags = RZ_CMD_ARG_FLAG_LAST, }, { 0 }, }; static const RzCmdDescHelp print_djb2_hash_help = { - .summary = "Print hash value of given input", + .summary = "Print hash value of string ", .details = print_djb2_hash_details, .args = print_djb2_hash_args, }; @@ -1713,7 +1710,7 @@ static const RzCmdDescDetail eval_expr_print_octal_details[] = { }; static const RzCmdDescArg eval_expr_print_octal_args[] = { { - .name = "input", + .name = "expr", .type = RZ_CMD_ARG_TYPE_RZNUM, .flags = RZ_CMD_ARG_FLAG_LAST, @@ -1721,14 +1718,14 @@ static const RzCmdDescArg eval_expr_print_octal_args[] = { { 0 }, }; static const RzCmdDescHelp eval_expr_print_octal_help = { - .summary = "Evaluate expression and print value in octal.", + .summary = "Print in octal format", .details = eval_expr_print_octal_details, .args = eval_expr_print_octal_args, }; static const RzCmdDescArg num_to_units_args[] = { { - .name = "input", + .name = "expr", .type = RZ_CMD_ARG_TYPE_RZNUM, .flags = RZ_CMD_ARG_FLAG_LAST, @@ -1736,39 +1733,16 @@ static const RzCmdDescArg num_to_units_args[] = { { 0 }, }; static const RzCmdDescHelp num_to_units_help = { - .summary = "Convert evaluated numbers/expressions to K, M, G, T etc... units", + .summary = "Convert to K, M, G, T etc... units", .args = num_to_units_args, }; -static const RzCmdDescDetailEntry set_last_eval_expr_Examples_detail_entries[] = { - { .text = "%q", .arg_str = " 123", .comment = "This will set $?. Then commands like ??x can be used to do some task by checking whether $? holds positive value or not." }, - { 0 }, -}; -static const RzCmdDescDetail set_last_eval_expr_details[] = { - { .name = "Examples", .entries = set_last_eval_expr_Examples_detail_entries }, - { 0 }, -}; -static const RzCmdDescArg set_last_eval_expr_args[] = { - { - .name = "input", - .type = RZ_CMD_ARG_TYPE_RZNUM, - .flags = RZ_CMD_ARG_FLAG_LAST, - - }, - { 0 }, -}; -static const RzCmdDescHelp set_last_eval_expr_help = { - .summary = "Update $? (last evaluated expression) without printing anything", - .details = set_last_eval_expr_details, - .args = set_last_eval_expr_args, -}; - static const RzCmdDescHelp perc_v_help = { .summary = "Show value commands", }; static const RzCmdDescArg show_value_args[] = { { - .name = "input", + .name = "expr", .type = RZ_CMD_ARG_TYPE_RZNUM, .flags = RZ_CMD_ARG_FLAG_LAST, .optional = true, @@ -1777,13 +1751,13 @@ static const RzCmdDescArg show_value_args[] = { { 0 }, }; static const RzCmdDescHelp show_value_help = { - .summary = "Show last or currently evaluated expression", + .summary = "Show last expression ($?) or currently evaluated ", .args = show_value_args, }; static const RzCmdDescArg show_value_hex_args[] = { { - .name = "input", + .name = "expr", .type = RZ_CMD_ARG_TYPE_RZNUM, .flags = RZ_CMD_ARG_FLAG_LAST, .optional = true, @@ -1792,13 +1766,13 @@ static const RzCmdDescArg show_value_hex_args[] = { { 0 }, }; static const RzCmdDescHelp show_value_hex_help = { - .summary = "Show last or currently evaluated expression in hex", + .summary = "Show last expression ($?) or currently evaluated in hex", .args = show_value_hex_args, }; static const RzCmdDescArg show_value_i1_args[] = { { - .name = "input", + .name = "expr", .type = RZ_CMD_ARG_TYPE_RZNUM, .flags = RZ_CMD_ARG_FLAG_LAST, .optional = true, @@ -1807,13 +1781,13 @@ static const RzCmdDescArg show_value_i1_args[] = { { 0 }, }; static const RzCmdDescHelp show_value_i1_help = { - .summary = "Show last or currently evaluated expression as 1 byte integer", + .summary = "Show last expression ($?) or currently evaluated as 1 byte integer", .args = show_value_i1_args, }; static const RzCmdDescArg show_value_i2_args[] = { { - .name = "input", + .name = "expr", .type = RZ_CMD_ARG_TYPE_RZNUM, .flags = RZ_CMD_ARG_FLAG_LAST, .optional = true, @@ -1822,13 +1796,13 @@ static const RzCmdDescArg show_value_i2_args[] = { { 0 }, }; static const RzCmdDescHelp show_value_i2_help = { - .summary = "Show last or currently evaluated expression as 2 byte integer", + .summary = "Show last expression ($?) or currently evaluated as 2 bytes integer", .args = show_value_i2_args, }; static const RzCmdDescArg show_value_i4_args[] = { { - .name = "input", + .name = "expr", .type = RZ_CMD_ARG_TYPE_RZNUM, .flags = RZ_CMD_ARG_FLAG_LAST, .optional = true, @@ -1837,13 +1811,13 @@ static const RzCmdDescArg show_value_i4_args[] = { { 0 }, }; static const RzCmdDescHelp show_value_i4_help = { - .summary = "Show last or currently evaluated expression as 4 byte integer", + .summary = "Show last expression ($?) or currently evaluated as 4 bytes integer", .args = show_value_i4_args, }; static const RzCmdDescArg show_value_i8_args[] = { { - .name = "input", + .name = "expr", .type = RZ_CMD_ARG_TYPE_RZNUM, .flags = RZ_CMD_ARG_FLAG_LAST, .optional = true, @@ -1852,13 +1826,13 @@ static const RzCmdDescArg show_value_i8_args[] = { { 0 }, }; static const RzCmdDescHelp show_value_i8_help = { - .summary = "Show last or currently evaluated expression as 8 byte integer", + .summary = "Show last expression ($?) or currently evaluated as 8 bytes integer", .args = show_value_i8_args, }; static const RzCmdDescArg show_value_int_args[] = { { - .name = "input", + .name = "expr", .type = RZ_CMD_ARG_TYPE_RZNUM, .flags = RZ_CMD_ARG_FLAG_LAST, .optional = true, @@ -1867,22 +1841,31 @@ static const RzCmdDescArg show_value_int_args[] = { { 0 }, }; static const RzCmdDescHelp show_value_int_help = { - .summary = "Show last or currently evaluated expression as integer", + .summary = "Show last expression ($?) or currently evaluated as integer", .args = show_value_int_args, }; -static const RzCmdDescArg set_core_num_value_args[] = { +static const RzCmdDescDetailEntry set_last_eval_expr_Examples_detail_entries[] = { + { .text = "%q", .arg_str = " 123", .comment = "This will set $?. Then commands like %+, %-, etc. can be used to do some task by checking whether $? holds positive value or not." }, + { 0 }, +}; +static const RzCmdDescDetail set_last_eval_expr_details[] = { + { .name = "Examples", .entries = set_last_eval_expr_Examples_detail_entries }, + { 0 }, +}; +static const RzCmdDescArg set_last_eval_expr_args[] = { { - .name = "input", + .name = "expr", .type = RZ_CMD_ARG_TYPE_RZNUM, .flags = RZ_CMD_ARG_FLAG_LAST, }, { 0 }, }; -static const RzCmdDescHelp set_core_num_value_help = { - .summary = "Replace the value of last evalued expression with given value", - .args = set_core_num_value_args, +static const RzCmdDescHelp set_last_eval_expr_help = { + .summary = "Update $? (last evaluated expression) with , without printing anything", + .details = set_last_eval_expr_details, + .args = set_last_eval_expr_args, }; static const RzCmdDescDetailEntry compare_and_set_core_num_value_Examples_detail_entries[] = { @@ -1908,7 +1891,7 @@ static const RzCmdDescArg compare_and_set_core_num_value_args[] = { { 0 }, }; static const RzCmdDescHelp compare_and_set_core_num_value_help = { - .summary = "Compare two given strings and set $? register to cmp result", + .summary = "Compare strings and and set $? register to cmp result", .details = compare_and_set_core_num_value_details, .args = compare_and_set_core_num_value_args, }; @@ -1933,7 +1916,7 @@ static const RzCmdDescArg exec_cmd_if_core_num_value_positive_args[] = { { 0 }, }; static const RzCmdDescHelp exec_cmd_if_core_num_value_positive_help = { - .summary = "Execute given command if $? register is greater than 0", + .summary = "Execute command if $? register is greater than 0", .details = exec_cmd_if_core_num_value_positive_details, .args = exec_cmd_if_core_num_value_positive_args, }; @@ -1958,7 +1941,7 @@ static const RzCmdDescArg exec_cmd_if_core_num_value_negative_args[] = { { 0 }, }; static const RzCmdDescHelp exec_cmd_if_core_num_value_negative_help = { - .summary = "Execute given command if $? register is less than 0", + .summary = "Execute command if $? register is less than 0", .details = exec_cmd_if_core_num_value_negative_details, .args = exec_cmd_if_core_num_value_negative_args, }; @@ -1973,7 +1956,7 @@ static const RzCmdDescArg exec_cmd_if_core_num_value_zero_args[] = { { 0 }, }; static const RzCmdDescHelp exec_cmd_if_core_num_value_zero_help = { - .summary = "Execute command if result of last numeric expression evaluation (related) command was 0", + .summary = "Execute command if $? is 0", .args = exec_cmd_if_core_num_value_zero_args, }; @@ -1987,7 +1970,7 @@ static const RzCmdDescArg exec_cmd_if_core_num_value_nonzero_args[] = { { 0 }, }; static const RzCmdDescHelp exec_cmd_if_core_num_value_nonzero_help = { - .summary = "Execute command if result of last numeric expression evaluation (related) command was not 0", + .summary = "Execute command if $? is not 0", .args = exec_cmd_if_core_num_value_nonzero_args, }; @@ -2001,7 +1984,7 @@ static const RzCmdDescArg calculate_string_length_args[] = { { 0 }, }; static const RzCmdDescHelp calculate_string_length_help = { - .summary = "Calculate length of string. Quite mode stores value in `$?` register.", + .summary = "Calculate length of string . Quite mode stores value in `$?` register.", .args = calculate_string_length_args, }; @@ -2015,7 +1998,7 @@ static const RzCmdDescArg calc_expr_show_hex_args[] = { { 0 }, }; static const RzCmdDescHelp calc_expr_show_hex_help = { - .summary = "Show evaluated expression in hex", + .summary = "Show evaluated expression in hex", .args = calc_expr_show_hex_args, }; @@ -2084,14 +2067,15 @@ static const RzCmdDescArg generate_sequence_args[] = { { 0 }, }; static const RzCmdDescHelp generate_sequence_help = { - .summary = "Generate sequence of numbers (?s from to step)", + .summary = "Generate sequence of numbers from to with increments", .args = generate_sequence_args, }; static const RzCmdDescArg phys2virt_args[] = { { .name = "paddr", - .type = RZ_CMD_ARG_TYPE_NUM, + .type = RZ_CMD_ARG_TYPE_RZNUM, + .flags = RZ_CMD_ARG_FLAG_LAST, .optional = true, }, @@ -2105,7 +2089,8 @@ static const RzCmdDescHelp phys2virt_help = { static const RzCmdDescArg virt2phys_args[] = { { .name = "vaddr", - .type = RZ_CMD_ARG_TYPE_NUM, + .type = RZ_CMD_ARG_TYPE_RZNUM, + .flags = RZ_CMD_ARG_FLAG_LAST, .optional = true, }, @@ -2133,22 +2118,37 @@ static const RzCmdDescHelp yank_hud_file_help = { static const RzCmdDescHelp perc_i_help = { .summary = "Input commands", }; -static const RzCmdDescArg input_numerical_expr_args[] = { +static const RzCmdDescArg input_prompt_args[] = { { - .name = "vaddr", - .type = RZ_CMD_ARG_TYPE_NUM, + .name = "prompt", + .type = RZ_CMD_ARG_TYPE_STRING, + .flags = RZ_CMD_ARG_FLAG_LAST, + + }, + { 0 }, +}; +static const RzCmdDescHelp input_prompt_help = { + .summary = "Input the and save response in yank clipboard (`y` commands)", + .args = input_prompt_args, +}; + +static const RzCmdDescArg input_prompt_echo_args[] = { + { + .name = "prompt", + .type = RZ_CMD_ARG_TYPE_STRING, + .flags = RZ_CMD_ARG_FLAG_LAST, }, { 0 }, }; -static const RzCmdDescHelp input_numerical_expr_help = { - .summary = "Input numerical expression and store in $? register", - .args = input_numerical_expr_args, +static const RzCmdDescHelp input_prompt_echo_help = { + .summary = "Input the , save response in yank clipboard (`y` commands), and print it", + .args = input_prompt_echo_args, }; static const RzCmdDescArg input_yesno_no_args[] = { { - .name = "opt", + .name = "question", .type = RZ_CMD_ARG_TYPE_STRING, .flags = RZ_CMD_ARG_FLAG_LAST, .optional = true, @@ -2157,13 +2157,13 @@ static const RzCmdDescArg input_yesno_no_args[] = { { 0 }, }; static const RzCmdDescHelp input_yesno_no_help = { - .summary = "Input YES/NO and store result in $? register", + .summary = "Input Yes/No and store result in $? register (default No)", .args = input_yesno_no_args, }; static const RzCmdDescArg input_yesno_yes_args[] = { { - .name = "opt", + .name = "question", .type = RZ_CMD_ARG_TYPE_STRING, .flags = RZ_CMD_ARG_FLAG_LAST, .optional = true, @@ -2172,7 +2172,7 @@ static const RzCmdDescArg input_yesno_yes_args[] = { { 0 }, }; static const RzCmdDescHelp input_yesno_yes_help = { - .summary = "Input YES/NO and store result in $? register", + .summary = "Input Yes/No and store result in $? register (default Yes)", .args = input_yesno_yes_args, }; @@ -2189,12 +2189,13 @@ static const RzCmdDescArg input_yank_hud_args[] = { .name = "path", .type = RZ_CMD_ARG_TYPE_STRING, .flags = RZ_CMD_ARG_FLAG_LAST, + .optional = true, }, { 0 }, }; static const RzCmdDescHelp input_yank_hud_help = { - .summary = "Yank HUD path and store result in $? register", + .summary = "Interactive HUD mode to find files in ", .args = input_yank_hud_args, }; @@ -2208,21 +2209,21 @@ static const RzCmdDescArg input_msg_args[] = { { 0 }, }; static const RzCmdDescHelp input_msg_help = { - .summary = "Input message and display in console", + .summary = "Display in console and wait for key", .args = input_msg_args, }; static const RzCmdDescArg input_conditional_args[] = { { - .name = "cond", - .type = RZ_CMD_ARG_TYPE_STRING, + .name = "expr", + .type = RZ_CMD_ARG_TYPE_RZNUM, .flags = RZ_CMD_ARG_FLAG_LAST, }, { 0 }, }; static const RzCmdDescHelp input_conditional_help = { - .summary = "Input conditional and store result in $? register", + .summary = "Evaluate , store result in $? register and print true if != 0, false otherwise", .args = input_conditional_args, }; @@ -7388,7 +7389,7 @@ static const RzCmdDescHelp cmd_debug_command_bp_help = { }; static const RzCmdDescDetailEntry cmd_debug_add_cond_bp_Usage_space_example_detail_entries[] = { - { .text = "Example of a condition", .arg_str = NULL, .comment = "?v rax-0x0" }, + { .text = "Example of a condition", .arg_str = NULL, .comment = "%v rax-0x0" }, { 0 }, }; static const RzCmdDescDetail cmd_debug_add_cond_bp_details[] = { @@ -18762,12 +18763,13 @@ RZ_IPI void rzshell_cmddescs_init(RzCore *core) { RzCmdDesc *generate_random_number_cd = rz_cmd_desc_argv_new(core->rcmd, cmd_math_cd, "%r", rz_generate_random_number_handler, &generate_random_number_help); rz_warn_if_fail(generate_random_number_cd); - RzCmdDesc *perc_b_cd = rz_cmd_desc_group_new(core->rcmd, cmd_math_cd, "%b", rz_print_binary_handler, &print_binary_help, &perc_b_help); - rz_warn_if_fail(perc_b_cd); - RzCmdDesc *base64_encode_cd = rz_cmd_desc_argv_new(core->rcmd, perc_b_cd, "%b64", rz_base64_encode_handler, &base64_encode_help); + RzCmdDesc *print_binary_cd = rz_cmd_desc_argv_new(core->rcmd, cmd_math_cd, "%b", rz_print_binary_handler, &print_binary_help); + rz_warn_if_fail(print_binary_cd); + + RzCmdDesc *base64_encode_cd = rz_cmd_desc_argv_new(core->rcmd, cmd_math_cd, "%b64", rz_base64_encode_handler, &base64_encode_help); rz_warn_if_fail(base64_encode_cd); - RzCmdDesc *base64_decode_cd = rz_cmd_desc_argv_new(core->rcmd, perc_b_cd, "%b64-", rz_base64_decode_handler, &base64_decode_help); + RzCmdDesc *base64_decode_cd = rz_cmd_desc_argv_new(core->rcmd, cmd_math_cd, "%b64-", rz_base64_decode_handler, &base64_decode_help); rz_warn_if_fail(base64_decode_cd); RzCmdDesc *check_between_cd = rz_cmd_desc_argv_new(core->rcmd, cmd_math_cd, "%btw", rz_check_between_handler, &check_between_help); @@ -18788,9 +18790,6 @@ RZ_IPI void rzshell_cmddescs_init(RzCore *core) { RzCmdDesc *num_to_units_cd = rz_cmd_desc_argv_new(core->rcmd, cmd_math_cd, "%u", rz_num_to_units_handler, &num_to_units_help); rz_warn_if_fail(num_to_units_cd); - RzCmdDesc *set_last_eval_expr_cd = rz_cmd_desc_argv_new(core->rcmd, cmd_math_cd, "%q", rz_set_last_eval_expr_handler, &set_last_eval_expr_help); - rz_warn_if_fail(set_last_eval_expr_cd); - RzCmdDesc *perc_v_cd = rz_cmd_desc_group_new(core->rcmd, cmd_math_cd, "%v", rz_show_value_handler, &show_value_help, &perc_v_help); rz_warn_if_fail(perc_v_cd); RzCmdDesc *show_value_hex_cd = rz_cmd_desc_argv_new(core->rcmd, perc_v_cd, "%vx", rz_show_value_hex_handler, &show_value_hex_help); @@ -18811,8 +18810,8 @@ RZ_IPI void rzshell_cmddescs_init(RzCore *core) { RzCmdDesc *show_value_int_cd = rz_cmd_desc_argv_new(core->rcmd, perc_v_cd, "%vi", rz_show_value_int_handler, &show_value_int_help); rz_warn_if_fail(show_value_int_cd); - RzCmdDesc *set_core_num_value_cd = rz_cmd_desc_argv_new(core->rcmd, cmd_math_cd, "%=", rz_set_core_num_value_handler, &set_core_num_value_help); - rz_warn_if_fail(set_core_num_value_cd); + RzCmdDesc *set_last_eval_expr_cd = rz_cmd_desc_argv_new(core->rcmd, cmd_math_cd, "%=", rz_set_last_eval_expr_handler, &set_last_eval_expr_help); + rz_warn_if_fail(set_last_eval_expr_cd); RzCmdDesc *compare_and_set_core_num_value_cd = rz_cmd_desc_argv_new(core->rcmd, cmd_math_cd, "%==", rz_compare_and_set_core_num_value_handler, &compare_and_set_core_num_value_help); rz_warn_if_fail(compare_and_set_core_num_value_cd); @@ -18855,8 +18854,11 @@ RZ_IPI void rzshell_cmddescs_init(RzCore *core) { RzCmdDesc *yank_hud_file_cd = rz_cmd_desc_argv_new(core->rcmd, cmd_math_cd, "%_", rz_yank_hud_file_handler, &yank_hud_file_help); rz_warn_if_fail(yank_hud_file_cd); - RzCmdDesc *perc_i_cd = rz_cmd_desc_group_new(core->rcmd, cmd_math_cd, "%i", rz_input_numerical_expr_handler, &input_numerical_expr_help, &perc_i_help); + RzCmdDesc *perc_i_cd = rz_cmd_desc_group_new(core->rcmd, cmd_math_cd, "%i", rz_input_prompt_handler, &input_prompt_help, &perc_i_help); rz_warn_if_fail(perc_i_cd); + RzCmdDesc *input_prompt_echo_cd = rz_cmd_desc_argv_new(core->rcmd, perc_i_cd, "%ie", rz_input_prompt_echo_handler, &input_prompt_echo_help); + rz_warn_if_fail(input_prompt_echo_cd); + RzCmdDesc *input_yesno_no_cd = rz_cmd_desc_argv_new(core->rcmd, perc_i_cd, "%in", rz_input_yesno_no_handler, &input_yesno_no_help); rz_warn_if_fail(input_yesno_no_cd); diff --git a/librz/core/cmd_descs/cmd_descs.h b/librz/core/cmd_descs/cmd_descs.h index 682617810b3..bcc025aa6fd 100644 --- a/librz/core/cmd_descs/cmd_descs.h +++ b/librz/core/cmd_descs/cmd_descs.h @@ -118,8 +118,6 @@ RZ_IPI RzCmdStatus rz_print_bitstring_handler(RzCore *core, int argc, const char RZ_IPI RzCmdStatus rz_eval_expr_print_octal_handler(RzCore *core, int argc, const char **argv); // "%u" RZ_IPI RzCmdStatus rz_num_to_units_handler(RzCore *core, int argc, const char **argv); -// "%q" -RZ_IPI RzCmdStatus rz_set_last_eval_expr_handler(RzCore *core, int argc, const char **argv); // "%v" RZ_IPI RzCmdStatus rz_show_value_handler(RzCore *core, int argc, const char **argv); // "%vx" @@ -135,7 +133,7 @@ RZ_IPI RzCmdStatus rz_show_value_i8_handler(RzCore *core, int argc, const char * // "%vi" RZ_IPI RzCmdStatus rz_show_value_int_handler(RzCore *core, int argc, const char **argv); // "%=" -RZ_IPI RzCmdStatus rz_set_core_num_value_handler(RzCore *core, int argc, const char **argv); +RZ_IPI RzCmdStatus rz_set_last_eval_expr_handler(RzCore *core, int argc, const char **argv); // "%==" RZ_IPI RzCmdStatus rz_compare_and_set_core_num_value_handler(RzCore *core, int argc, const char **argv); // "%+" @@ -165,7 +163,9 @@ RZ_IPI RzCmdStatus rz_virt2phys_handler(RzCore *core, int argc, const char **arg // "%_" RZ_IPI RzCmdStatus rz_yank_hud_file_handler(RzCore *core, int argc, const char **argv); // "%i" -RZ_IPI RzCmdStatus rz_input_numerical_expr_handler(RzCore *core, int argc, const char **argv); +RZ_IPI RzCmdStatus rz_input_prompt_handler(RzCore *core, int argc, const char **argv); +// "%ie" +RZ_IPI RzCmdStatus rz_input_prompt_echo_handler(RzCore *core, int argc, const char **argv); // "%in" RZ_IPI RzCmdStatus rz_input_yesno_no_handler(RzCore *core, int argc, const char **argv); // "%iy" diff --git a/librz/core/cmd_descs/cmd_descs.yaml b/librz/core/cmd_descs/cmd_descs.yaml index fd3ff82385a..2e3920d7381 100644 --- a/librz/core/cmd_descs/cmd_descs.yaml +++ b/librz/core/cmd_descs/cmd_descs.yaml @@ -112,10 +112,10 @@ commands: arg_str: "" comment: List defined macros - text: ( - arg_str: foo; ?e Disassemble 10 bytes at 0x10000; pd 10 @ 0x10000) + arg_str: foo; echo Disassemble 10 bytes at 0x10000; pd 10 @ 0x10000) comment: Define a new macro 'foo', which executes `?` followed by `pd` when called. - text: ( - arg_str: foo a b; ?e Disassemble ${a} bytes at ${b}; pd ${a} @ ${b}) + arg_str: foo a b; echo Disassemble ${a} bytes at ${b}; pd ${a} @ ${b}) comment: Define a new macro 'foo' with two arguments. ${a}/${b} are replaced before execution. - text: (- arg_str: foo diff --git a/librz/core/cmd_descs/cmd_math.yaml b/librz/core/cmd_descs/cmd_math.yaml index b043aa80fb6..bd5b35ed36a 100644 --- a/librz/core/cmd_descs/cmd_math.yaml +++ b/librz/core/cmd_descs/cmd_math.yaml @@ -4,7 +4,7 @@ name: cmd_math commands: - name: "%" - summary: Evaluate given numerical expression + summary: Evaluate numerical expression cname: calculate_expr type: RZ_CMD_DESC_TYPE_ARGV_STATE modes: @@ -30,7 +30,7 @@ commands: cname: set_active_tab_next args: [] - name: "%r" - summary: Generate random number + summary: Generate a random number between and cname: generate_random_number args: - name: lowlimit @@ -38,43 +38,37 @@ commands: - name: uplimit type: RZ_CMD_ARG_TYPE_RZNUM - name: "%b" - summary: Base64 encode/decode and print binary commands - type: RZ_CMD_DESC_TYPE_GROUP - subcommands: - - name: "%b" - summary: Print binary format - cname: print_binary - args: - - name: num - type: RZ_CMD_ARG_TYPE_RZNUM - - name: "%b64" - summary: Base64 encode - cname: base64_encode - args: - - name: strs - type: RZ_CMD_ARG_TYPE_STRING - flags: RZ_CMD_ARG_FLAG_ARRAY - details: - - name: Examples - entries: - - text: "%b64" - arg_str: " ILoveRizin" - comment: (SUxvdmVSaXppbgo=) Encodes given string into base64 - - name: "%b64-" - summary: Base64 decode. Maximum input length = 4*(strlen(str)). - cname: base64_decode - args: - - name: b64strs - type: RZ_CMD_ARG_TYPE_STRING - flags: RZ_CMD_ARG_FLAG_ARRAY - details: - - name: Examples - entries: - - text: "%b64- " - arg_str: SUxvdmVSaXppbgo= - comment: (ILoveRizin) Decodes given base64 string + summary: Print in binary format + cname: print_binary + args: + - name: expr + type: RZ_CMD_ARG_TYPE_RZNUM + - name: "%b64" + summary: Encode in Base64 + cname: base64_encode + args: + - name: str + type: RZ_CMD_ARG_TYPE_STRING + details: + - name: Examples + entries: + - text: "%b64" + arg_str: " ILoveRizin" + comment: (SUxvdmVSaXppbgo=) Encodes given string into base64 + - name: "%b64-" + summary: Decode from Base64 + cname: base64_decode + args: + - name: str + type: RZ_CMD_ARG_TYPE_STRING + details: + - name: Examples + entries: + - text: "%b64- " + arg_str: SUxvdmVSaXppbgo= + comment: (ILoveRizin) Decodes given base64 string - name: "%btw" - summary: Check if middle number is between the other two (first and last) + summary: Check if number is between and cname: check_between args: - name: first @@ -103,12 +97,11 @@ commands: arg_str: io.maps comment: Prints boundaries of all io maps - name: "%h" - summary: Print hash value of given input + summary: Print hash value of string cname: print_djb2_hash args: - - name: strs + - name: type: RZ_CMD_ARG_TYPE_STRING - flags: RZ_CMD_ARG_FLAG_ARRAY details: - name: Examples entries: @@ -138,10 +131,10 @@ commands: arg_str: " 12 Hello" comment: "LL (00110b selected : big-endian bitstring)" - name: "%o" - summary: Evaluate expression and print value in octal. + summary: Print in octal format cname: eval_expr_print_octal args: - - name: input + - name: expr type: RZ_CMD_ARG_TYPE_RZNUM details: - name: Examples @@ -153,86 +146,80 @@ commands: arg_str: " 321" comment: 0501 in octal - name: "%u" - summary: "Convert evaluated numbers/expressions to K, M, G, T etc... units" + summary: "Convert to K, M, G, T etc... units" cname: num_to_units args: - - name: input - type: RZ_CMD_ARG_TYPE_RZNUM - - name: "%q" - summary: Update $? (last evaluated expression) without printing anything - cname: set_last_eval_expr - args: - - name: input + - name: expr type: RZ_CMD_ARG_TYPE_RZNUM - details: - - name: Examples - entries: - - text: "%q" - arg_str: " 123" - comment: >- - This will set $?. Then commands like ??x can be used to do some task - by checking whether $? holds positive value or not. - name: "%v" summary: Show value commands type: RZ_CMD_DESC_TYPE_GROUP subcommands: - name: "%v" - summary: Show last or currently evaluated expression + summary: Show last expression ($?) or currently evaluated cname: show_value args: - - name: input + - name: expr type: RZ_CMD_ARG_TYPE_RZNUM optional: true - name: "%vx" - summary: Show last or currently evaluated expression in hex + summary: Show last expression ($?) or currently evaluated in hex cname: show_value_hex args: - - name: input + - name: expr type: RZ_CMD_ARG_TYPE_RZNUM optional: true - name: "%vi1" - summary: Show last or currently evaluated expression as 1 byte integer + summary: Show last expression ($?) or currently evaluated as 1 byte integer cname: show_value_i1 args: - - name: input + - name: expr type: RZ_CMD_ARG_TYPE_RZNUM optional: true - name: "%vi2" - summary: Show last or currently evaluated expression as 2 byte integer + summary: Show last expression ($?) or currently evaluated as 2 bytes integer cname: show_value_i2 args: - - name: input + - name: expr type: RZ_CMD_ARG_TYPE_RZNUM optional: true - name: "%vi4" - summary: Show last or currently evaluated expression as 4 byte integer + summary: Show last expression ($?) or currently evaluated as 4 bytes integer cname: show_value_i4 args: - - name: input + - name: expr type: RZ_CMD_ARG_TYPE_RZNUM optional: true - name: "%vi8" - summary: Show last or currently evaluated expression as 8 byte integer + summary: Show last expression ($?) or currently evaluated as 8 bytes integer cname: show_value_i8 args: - - name: input + - name: expr type: RZ_CMD_ARG_TYPE_RZNUM optional: true - name: "%vi" - summary: Show last or currently evaluated expression as integer + summary: Show last expression ($?) or currently evaluated as integer cname: show_value_int args: - - name: input + - name: expr type: RZ_CMD_ARG_TYPE_RZNUM optional: true - name: "%=" - summary: Replace the value of last evalued expression with given value - cname: set_core_num_value + summary: Update $? (last evaluated expression) with , without printing anything + cname: set_last_eval_expr args: - - name: input + - name: expr type: RZ_CMD_ARG_TYPE_RZNUM + details: + - name: Examples + entries: + - text: "%q" + arg_str: " 123" + comment: >- + This will set $?. Then commands like %+, %-, etc. can be used to do some task + by checking whether $? holds positive value or not. - name: "%==" - summary: Compare two given strings and set $? register to cmp result + summary: Compare strings and and set $? register to cmp result cname: compare_and_set_core_num_value args: - name: str1 @@ -246,7 +233,7 @@ commands: arg_str: " str1 str2" comment: $? will be set to 0 if these two strings are equal, otherwise some other positive value. - name: "%+" - summary: Execute given command if $? register is greater than 0 + summary: Execute command if $? register is greater than 0 cname: exec_cmd_if_core_num_value_positive args: - name: cmd @@ -264,7 +251,7 @@ commands: arg_str: " %%x" comment: Won"t do anything - name: "%-" - summary: Execute given command if $? register is less than 0 + summary: Execute command if $? register is less than 0 cname: exec_cmd_if_core_num_value_negative args: - name: cmd @@ -282,19 +269,19 @@ commands: arg_str: " %%x" comment: Won"t do anything - name: "%!" - summary: Execute command if result of last numeric expression evaluation (related) command was 0 + summary: Execute command if $? is 0 cname: exec_cmd_if_core_num_value_zero args: - name: cmd type: RZ_CMD_ARG_TYPE_CMD - name: "%%" - summary: Execute command if result of last numeric expression evaluation (related) command was not 0 + summary: Execute command if $? is not 0 cname: exec_cmd_if_core_num_value_nonzero args: - name: cmd type: RZ_CMD_ARG_TYPE_CMD - name: "%l" - summary: Calculate length of string. Quite mode stores value in `$?` register. + summary: Calculate length of string . Quite mode stores value in `$?` register. cname: calculate_string_length args: - name: str @@ -304,7 +291,7 @@ commands: - RZ_OUTPUT_MODE_STANDARD - RZ_OUTPUT_MODE_QUIET - name: "%X" - summary: Show evaluated expression in hex + summary: Show evaluated expression in hex cname: calc_expr_show_hex args: - name: expr @@ -332,7 +319,7 @@ commands: - name: hexnum type: RZ_CMD_ARG_TYPE_RZNUM - name: "%s" - summary: Generate sequence of numbers (?s from to step) + summary: Generate sequence of numbers from to with increments cname: generate_sequence args: - name: start @@ -346,14 +333,14 @@ commands: cname: phys2virt args: - name: paddr - type: RZ_CMD_ARG_TYPE_NUM + type: RZ_CMD_ARG_TYPE_RZNUM optional: true - name: "%p" summary: Virtual to physical address conversion cname: virt2phys args: - name: vaddr - type: RZ_CMD_ARG_TYPE_NUM + type: RZ_CMD_ARG_TYPE_RZNUM optional: true - name: "%_" summary: HUD input @@ -366,23 +353,29 @@ commands: type: RZ_CMD_DESC_TYPE_GROUP subcommands: - name: "%i" - summary: Input numerical expression and store in $? register - cname: input_numerical_expr + summary: Input the and save response in yank clipboard (`y` commands) + cname: input_prompt + args: + - name: prompt + type: RZ_CMD_ARG_TYPE_STRING + - name: "%ie" + summary: Input the , save response in yank clipboard (`y` commands), and print it + cname: input_prompt_echo args: - - name: vaddr - type: RZ_CMD_ARG_TYPE_NUM + - name: prompt + type: RZ_CMD_ARG_TYPE_STRING - name: "%in" - summary: Input YES/NO and store result in $? register + summary: Input Yes/No and store result in $? register (default No) cname: input_yesno_no args: - - name: opt + - name: question type: RZ_CMD_ARG_TYPE_STRING optional: true - name: "%iy" - summary: Input YES/NO and store result in $? register + summary: Input Yes/No and store result in $? register (default Yes) cname: input_yesno_yes args: - - name: opt + - name: question type: RZ_CMD_ARG_TYPE_STRING optional: true - name: "%ik" @@ -390,23 +383,24 @@ commands: cname: input_any_key args: [] - name: "%ip" - summary: Yank HUD path and store result in $? register + summary: Interactive HUD mode to find files in cname: input_yank_hud args: - name: path type: RZ_CMD_ARG_TYPE_STRING + optional: true - name: "%im" - summary: Input message and display in console + summary: Display in console and wait for key cname: input_msg args: - name: msg type: RZ_CMD_ARG_TYPE_STRING - name: "%if" - summary: Input conditional and store result in $? register + summary: Evaluate , store result in $? register and print true if != 0, false otherwise cname: input_conditional args: - - name: cond - type: RZ_CMD_ARG_TYPE_STRING + - name: expr + type: RZ_CMD_ARG_TYPE_RZNUM - name: "%w" summary: Get references of given address cname: get_addr_references diff --git a/librz/core/tui/config.c b/librz/core/tui/config.c index e1ccd308f39..60b95318c34 100644 --- a/librz/core/tui/config.c +++ b/librz/core/tui/config.c @@ -221,7 +221,7 @@ RZ_IPI void rz_core_visual_config(RzCore *core) { " q - quit menu\n" " j/k - down/up keys\n" " h/b - go back\n" - " $ - same as ?$ - show values of vars\n" + " $ - same as %%$ - show values of vars\n" " e/' ' - edit/toggle current variable\n" " E - edit variable with 'cfg.editor' (vi?)\n" " +/- - increase/decrease numeric value (* and /, too)\n" diff --git a/librz/core/tui/define.c b/librz/core/tui/define.c index 687c50fa9c3..2627d061994 100644 --- a/librz/core/tui/define.c +++ b/librz/core/tui/define.c @@ -326,10 +326,10 @@ RZ_IPI void rz_core_visual_define(RzCore *core, const char *args, int distance) handleHints(core); break; case 'r': // "Vdr" - rz_core_cmdf(core, "?i new function name;afn `yp` @ 0x%08" PFMT64x, off); + rz_core_cmdf(core, "%%i new function name;afn `yp` @ 0x%08" PFMT64x, off); break; case 'z': // "Vdz" - rz_core_cmdf(core, "?i zone name;fz `yp` @ 0x%08" PFMT64x, off); + rz_core_cmdf(core, "%%i zone name;fz `yp` @ 0x%08" PFMT64x, off); break; case 'R': // "VdR" eprintf("Finding references to 0x%08" PFMT64x " ...\n", off); diff --git a/librz/core/tui/panels.c b/librz/core/tui/panels.c index 13dad734c14..b05514e1ef0 100644 --- a/librz/core/tui/panels.c +++ b/librz/core/tui/panels.c @@ -5266,21 +5266,29 @@ bool __handle_console(RzCore *core, RzPanel *panel, const int key) { switch (key) { case 'i': { char cmd[128] = { 0 }; - char *prompt = rz_str_newf("[0x%08" PFMT64x "]) ", core->offset); + char *prompt = rz_str_newf("[0x%08" PFMT64x "] ", core->offset); __panel_prompt(prompt, cmd, sizeof(cmd)); if (*cmd) { if (!strcmp(cmd, "clear")) { rz_cons_clear00(); } else { - rz_core_cmdf(core, "?e %s %s>>$console", prompt, cmd); - rz_core_cmdf(core, "%s >>$console", cmd); + char *res = rz_core_cmd_str(core, cmd); + if (!res) { + free(prompt); + return false; + } + char *old_value = rz_cmd_alias_get(core->rcmd, "$console", 1); + char *new_value = rz_str_newf("%s%s %s\n%s\n", old_value ? old_value : "$", prompt, cmd, res); + rz_cmd_alias_set(core->rcmd, "$console", new_value, 1); + free(new_value); } } + free(prompt); panel->view->refresh = true; - } return true; + } case 'l': - rz_core_cmd0(core, ":>$console"); + rz_cmd_alias_set(core->rcmd, "$console", "", 1); panel->view->refresh = true; return true; default: diff --git a/librz/core/tui/vasm.c b/librz/core/tui/vasm.c index 6ac5f2ab5b9..2326b8313b8 100644 --- a/librz/core/tui/vasm.c +++ b/librz/core/tui/vasm.c @@ -57,7 +57,7 @@ static int readline_callback(void *_a, const char *str) { core->print->cur_enabled = 1; core->print->ocur = 0; core->print->cur = (a->acode && a->acode->len) ? a->acode->len - 1 : 0; - char *cmd = rz_str_newf("pd %d @x:%s @0x%" PFMT64x, rows - 11, a->codebuf, a->off); + char *cmd = rz_str_newf("pd %d @x:%s @ 0x%" PFMT64x, rows - 11, a->codebuf, a->off); char *res = rz_core_cmd_str(a->core, cmd); char *msg = rz_str_ansi_crop(res, 0, 0, cols - 2, rows - 5); rz_cons_printf("%s\n", msg); diff --git a/librz/core/tui/vmenus_graph.c b/librz/core/tui/vmenus_graph.c index c6ddc950d10..bae08ae5952 100644 --- a/librz/core/tui/vmenus_graph.c +++ b/librz/core/tui/vmenus_graph.c @@ -242,7 +242,7 @@ RZ_IPI int __core_visual_view_graph_update(RzCore *core, RzCoreVisualViewGraph * rz_cons_strcat_at(mainColstr, colx, 2, colw * 2, colh); rz_cons_strcat_at(refsColstr, colx * 2, 2, colw, colh); - char *output = rz_core_cmd_strf(core, "pd %d @e:asm.flags=0@ 0x%08" PFMT64x "; pds 256 @ 0x%08" PFMT64x "\n", + char *output = rz_core_cmd_strf(core, "pd %d @e:asm.flags=0 @ 0x%08" PFMT64x "; pds 256 @ 0x%08" PFMT64x "\n", 32, status->addr, status->addr); int disy = colh + 2; rz_cons_strcat_at(output, 10, disy, w, h - disy); diff --git a/librz/include/rz_egg.h b/librz/include/rz_egg.h index 7c14f56742e..03c320f62be 100644 --- a/librz/include/rz_egg.h +++ b/librz/include/rz_egg.h @@ -109,20 +109,6 @@ typedef struct rz_egg_t { int context; } RzEgg; -/* XXX: this may fail in different arches */ -#if 0 -rizin -q - <name Use newlines in echo ==================== -?e "Hello\nWorld" +echo "Hello\nWorld" --- @@ -30,7 +30,7 @@ Use newlines in echo Escape hash =========== -?e Hello\#World +echo Hello\#World --- diff --git a/subprojects/rizin-shell-parser/corpus/grep_commands.txt b/subprojects/rizin-shell-parser/corpus/grep_commands.txt index 565b6a43889..db97a1ca977 100644 --- a/subprojects/rizin-shell-parser/corpus/grep_commands.txt +++ b/subprojects/rizin-shell-parser/corpus/grep_commands.txt @@ -28,9 +28,9 @@ afl~$ Grep with cmd substitution as specifier ======================================= -pd 10~`?e mov` -pd 10~mo`?e v` -pd 10~mo$(?e v) +pd 10~`echo mov` +pd 10~mo`echo v` +pd 10~mo$(echo v) --- diff --git a/subprojects/rizin-shell-parser/corpus/iter_commands.txt b/subprojects/rizin-shell-parser/corpus/iter_commands.txt index 2d6c594a5fd..9ea7e2a0583 100644 --- a/subprojects/rizin-shell-parser/corpus/iter_commands.txt +++ b/subprojects/rizin-shell-parser/corpus/iter_commands.txt @@ -66,7 +66,7 @@ p8 @@/x 9090 Iter interpret cmd ================== -p8 @@c:?e hello +p8 @@c:echo hello --- @@ -81,7 +81,7 @@ p8 @@c:?e hello Iter interpret offsetssizes cmd =============================== -p8 @@@c:?e hello 10 +p8 @@@c:echo hello 10 --- diff --git a/subprojects/rizin-shell-parser/corpus/quoted_args.txt b/subprojects/rizin-shell-parser/corpus/quoted_args.txt index 70988ac1735..b4c6215748d 100644 --- a/subprojects/rizin-shell-parser/corpus/quoted_args.txt +++ b/subprojects/rizin-shell-parser/corpus/quoted_args.txt @@ -2,7 +2,7 @@ Echo with (double) quoted args ============================== -?e "This;is.one@string" +echo "This;is.one@string" --- @@ -14,7 +14,7 @@ Echo with (double) quoted args Echo with (single) quoted args ============================== -?e 'This;is.one@string' +echo 'This;is.one@string' --- @@ -27,7 +27,7 @@ Echo with (single) quoted args Legacy command - all quoted =========================== -"?e This;is.one@string" +"echo This;is.one@string" --- @@ -39,7 +39,7 @@ Legacy command - all quoted Double quoted arg with cmd substitution ======================================= -?e "This is $(?e "a command")" +echo "This is $(echo "a command")" --- @@ -56,9 +56,9 @@ Double quoted arg with cmd substitution Quoted hash ================== -?e "#" -?e " #$(pdf)" -?e '#' +echo "#" +echo " #$(pdf)" +echo '#' --- diff --git a/subprojects/rizin-shell-parser/corpus/simple_commands.txt b/subprojects/rizin-shell-parser/corpus/simple_commands.txt index 02e05b52d40..e3f50b3a780 100644 --- a/subprojects/rizin-shell-parser/corpus/simple_commands.txt +++ b/subprojects/rizin-shell-parser/corpus/simple_commands.txt @@ -54,6 +54,20 @@ af 0xdeadbeef (args (arg (arg_identifier))))) +========================= +?v not valid +========================= + +?v 3 + +--- + +(statements + (help_stmt + (cmd_identifier)) + (ERROR)) + + ====================== Percentage mark statements ====================== @@ -160,7 +174,7 @@ pf??? (help_stmt (cmd_identifier)) (help_stmt (cmd_identifier)) (help_stmt (cmd_identifier)) - (arged_stmt (cmd_identifier)) + (help_stmt (cmd_identifier)) (help_stmt (cmd_identifier)) (help_stmt (cmd_identifier)) (help_stmt (cmd_identifier)) @@ -173,7 +187,7 @@ pf??? Command with concatenation args =============================== -?e Hello" World"'!' And All +echo Hello" World"'!' And All --- @@ -193,7 +207,7 @@ Command with concatenation args Tasks command ============= -& ?e Hello +& echo Hello && 1 &= & @@ -215,7 +229,7 @@ Tasks command Arg with (...) ============== -?e Hello(World) +echo Hello(World) --- @@ -235,7 +249,7 @@ Arg with (...) Expressions with (...) ============================ -?v (100 + (2 - 3)) * 2 +%v (100 + (2 - 3)) * 2 --- @@ -263,13 +277,13 @@ Expressions with (...) Arg with $ ========== -?v $$ +%v $$ s $ -?v $* -?v $$$ test -?v $alias -?e hello$alias -?e test +%v $* +%v $$$ test +%v $alias +echo hello$alias +echo test --- diff --git a/subprojects/rizin-shell-parser/corpus/special_commands.txt b/subprojects/rizin-shell-parser/corpus/special_commands.txt index e9627d06bb0..8a465863e70 100644 --- a/subprojects/rizin-shell-parser/corpus/special_commands.txt +++ b/subprojects/rizin-shell-parser/corpus/special_commands.txt @@ -268,7 +268,7 @@ Interpreter statements Pointer type statements with substitution ======================================= -*entr$(?e y0)=$(?v $$) +*entr$(echo y0)=$(%v $$) --- diff --git a/subprojects/rizin-shell-parser/src/scanner.c b/subprojects/rizin-shell-parser/src/scanner.c index 5df51c9bcfb..133c5850da9 100644 --- a/subprojects/rizin-shell-parser/src/scanner.c +++ b/subprojects/rizin-shell-parser/src/scanner.c @@ -60,11 +60,11 @@ static bool is_interpret_cmd(const char *s) { static bool is_special_start(const int32_t ch) { return ch == '*' || ch == '(' || ch == '@' || ch == '|' || ch == '>' || - ch == '.' || ch == '|' || ch == '~' || ch == '!'; + ch == '.' || ch == '|' || ch == '~' || ch == '!' || ch == '?'; } static bool is_start_of_command(const int32_t ch) { - return iswalpha (ch) || ch == '$' || ch == '?' || ch == ':' || ch == '+' || + return iswalpha (ch) || ch == '$' || ch == ':' || ch == '+' || ch == '=' || ch == '/' || ch == '_' || ch == '#' || ch == '\\' || ch == '-' || ch == '<' || ch == '&' || ch == '%' || is_special_start (ch); } @@ -180,10 +180,9 @@ bool tree_sitter_rzcmd_external_scanner_scan(void *payload, TSLexer *lexer, cons if (is_comment (res)) { return false; } - // ?? is not considered an help command, just a regular one - if ((res[i_res - 1] == '?' && strcmp (res, "??") != 0) || - (i_res > 2 && is_recursive_help (res[i_res - 2], res[i_res - 1])) || - (i_res > 3 && is_recursive_help_json (res[i_res - 3], res[i_res - 2], res[i_res - 1]))) { + if ((res[i_res - 1] == '?') || + (i_res >= 2 && is_recursive_help(res[i_res - 2], res[i_res - 1])) || + (i_res >= 3 && is_recursive_help_json(res[i_res - 3], res[i_res - 2], res[i_res - 1]))) { if (i_res == 1) { return false; } diff --git a/test/db/archos/not-windows-any/cmd_interpreter b/test/db/archos/not-windows-any/cmd_interpreter index 4bdd0ac21d4..346c801655e 100644 --- a/test/db/archos/not-windows-any/cmd_interpreter +++ b/test/db/archos/not-windows-any/cmd_interpreter @@ -13,7 +13,7 @@ RUN NAME=#! with ext != name FILE== CMDS=<\nint main(){printf(\"Hello\\n\");return 0;}" > .tmp-hashextname.c #!cpipe .tmp-hashextname.c diff --git a/test/db/cmd/cmd_pipe b/test/db/cmd/cmd_pipe index 62d4eccc5a4..65b3eb19ebf 100644 --- a/test/db/cmd/cmd_pipe +++ b/test/db/cmd/cmd_pipe @@ -9,7 +9,7 @@ RUN NAME=rzpipe.py FILE=bins/elf/_Exit (42) CMDS=<