Skip to content

Commit

Permalink
core/cmd: fix some leftover of ?i command (#3911)
Browse files Browse the repository at this point in the history
  • Loading branch information
ret2libc committed Oct 5, 2023
1 parent 7c7b4c0 commit a1cb888
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 23 deletions.
4 changes: 2 additions & 2 deletions librz/core/agraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -4231,7 +4231,7 @@ RZ_IPI int rz_core_visual_graph(RzCore *core, RzAGraph *g, RzAnalysisFunction *_
get_bbupdate(g, core, fcn);
} break;
case '\\':
nextword(core, g, rz_config_get(core->config, "scr.highlight"));
nextword(core, g, rz_cons_singleton()->highlight);
break;
case 'b':
rz_core_visual_browse(core, "");
Expand Down Expand Up @@ -4706,7 +4706,7 @@ RZ_IPI int rz_core_visual_graph(RzCore *core, RzAGraph *g, RzAnalysisFunction *_
break;
case '/':
showcursor(core, true);
rz_core_cmd0(core, "?i highlight;e scr.highlight=`yp`");
rz_core_prompt_highlight(core);
showcursor(core, false);
break;
case ':':
Expand Down
39 changes: 32 additions & 7 deletions librz/core/cmd/cmd_math.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "rz_util.h"
#include "rz_types.h"

#define HIGHLIGHT_SZ 1024

static const char *help_msg_greater_sign[] = {
"Usage:", "[cmd]>[file]", "redirects console from 'cmd' output to 'file'",
"[cmd] > [file]", "", "redirect STDOUT of 'cmd' to 'file'",
Expand Down Expand Up @@ -575,18 +577,41 @@ RZ_IPI RzCmdStatus rz_yank_hud_file_handler(RzCore *core, int argc, const char *
return RZ_CMD_STATUS_OK;
}

static RzCmdStatus prompt_handler(RzCore *core, int argc, const char **argv, bool echo) {
static bool get_prompt(RzCore *core, char *prompt, char *output, size_t output_sz) {
if (!rz_cons_is_interactive()) {
RZ_LOG_ERROR("core: Not running in interactive mode\n");
return RZ_CMD_STATUS_WRONG_ARGS;
return false;
}
char foo[1024];
rz_cons_flush();
// TODO: rz_cons_input()
rz_line_set_prompt(prompt);
rz_cons_fgets(output, output_sz, 0, NULL);
output[output_sz - 1] = 0;
return true;
}

/**
* \brief Show a prompt "highlight" and highlights the string inserted by the user
*
* \param core Reference to RzCore
*/
RZ_IPI void rz_core_prompt_highlight(RzCore *core) {
char highlight_str[HIGHLIGHT_SZ];

if (!get_prompt(core, "highlight: ", highlight_str, sizeof(highlight_str))) {
return;
}

rz_cons_highlight(highlight_str);
}

static RzCmdStatus prompt_handler(RzCore *core, int argc, const char **argv, bool echo) {
char foo[1024];

snprintf(foo, sizeof(foo) - 1, "%s: ", argv[1]);
rz_line_set_prompt(foo);
rz_cons_fgets(foo, sizeof(foo), 0, NULL);
foo[sizeof(foo) - 1] = 0;
if (!get_prompt(core, foo, foo, sizeof(foo))) {
return RZ_CMD_STATUS_ERROR;
}

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);
Expand Down
2 changes: 1 addition & 1 deletion librz/core/cmd/cmd_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ static const char *help_detail2_pf[] = {
"pf", " 5sqw string quad word", "Print an array with sqw struct along with its field names",
"pf", " {integer}? (bifc)", "Print integer times the following format (bifc)",
"pf", " [4]w[7]i", "Print an array of 4 words and then an array of 7 integers",
"pf", " ic...?i foo bar \"(pf xw yo foo)troll\" yo", "Print nested anonymous structures",
"pf", " ic...%i foo bar \"(pf xw yo foo)troll\" yo", "Print nested anonymous structures",
"pf", " ;..x", "Print value located 6 bytes from current offset",
"pf", " [10]z[3]i[10]Zb", "Print an fixed size str, widechar, and var",
"pfj", " +F @ 0x14", "Print the content at given offset with flag",
Expand Down
2 changes: 2 additions & 0 deletions librz/core/core_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,6 @@ static inline char *rz_address_str(ut64 addr) {
return rz_str_newf("0x%" PFMT64x, addr);
}

RZ_IPI void rz_core_prompt_highlight(RzCore *core);

#endif
6 changes: 3 additions & 3 deletions librz/core/tui/panels.c
Original file line number Diff line number Diff line change
Expand Up @@ -2000,7 +2000,7 @@ static bool __handle_mouse_on_panel(RzCore *core, RzPanel *panel, int x, int y,
__set_addr_by_type(core, PANEL_CMD_DISASSEMBLY, addr);
}
rz_flag_set(core->flags, "panel.addr", addr, 1);
rz_config_set(core->config, "scr.highlight", word);
rz_cons_highlight(word);
#if 1
// TODO implement sync
{
Expand Down Expand Up @@ -6758,7 +6758,7 @@ void __panels_process(RzCore *core, RzPanels *panels) {
__set_panel_addr(core, cur, core->offset);
break;
case 'G': {
const char *hl = rz_config_get(core->config, "scr.highlight");
const char *hl = rz_cons_singleton()->highlight;
if (hl) {
ut64 addr = rz_num_math(core->num, hl);
__set_panel_addr(core, cur, addr);
Expand Down Expand Up @@ -6808,7 +6808,7 @@ void __panels_process(RzCore *core, RzPanels *panels) {
cur->view->refresh = true;
break;
case '/':
rz_core_cmd0(core, "?i highlight;e scr.highlight=`yp`");
rz_core_prompt_highlight(core);
break;
case 'z':
if (panels->curnode > 0) {
Expand Down
2 changes: 1 addition & 1 deletion librz/core/tui/rop.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ RZ_IPI int rz_core_visual_view_rop(RzCore *core) {
}
} break;
case '/':
rz_core_cmd0(core, "?i highlight;e scr.highlight=`yp`");
rz_core_prompt_highlight(core);
break;
case 'i': {
rz_line_set_prompt("insert value: ");
Expand Down
10 changes: 5 additions & 5 deletions librz/core/tui/visual.c
Original file line number Diff line number Diff line change
Expand Up @@ -1281,10 +1281,10 @@ RZ_IPI int rz_core_visual_xrefs(RzCore *core, bool xref_to, bool fcnInsteadOfAdd
rz_cons_newline();
}
/* prepare highlight */
char *cmd = strdup(rz_config_get(core->config, "scr.highlight"));
char *cmd = strdup(rz_cons_singleton()->highlight);
char *ats = rz_str_newf("%" PFMT64x, curat);
if (ats && !*cmd) {
(void)rz_config_set(core->config, "scr.highlight", ats);
rz_cons_highlight(ats);
}
/* print disasm */
char *d = rz_str_ansi_crop(dis, 0, 0, cols, rows - 9);
Expand All @@ -1294,7 +1294,7 @@ RZ_IPI int rz_core_visual_xrefs(RzCore *core, bool xref_to, bool fcnInsteadOfAdd
}
/* flush and restore highlight */
rz_cons_flush();
rz_config_set(core->config, "scr.highlight", cmd);
rz_cons_highlight(cmd);
free(ats);
free(cmd);
free(dis);
Expand Down Expand Up @@ -1345,7 +1345,7 @@ RZ_IPI int rz_core_visual_xrefs(RzCore *core, bool xref_to, bool fcnInsteadOfAdd
}
goto repeat;
} else if (ch == '/') {
rz_core_cmd0(core, "?i highlight;e scr.highlight=`yp`");
rz_core_prompt_highlight(core);
goto repeat;
} else if (ch == 'x' || ch == '<') {
xref_to = true;
Expand Down Expand Up @@ -2920,7 +2920,7 @@ RZ_IPI int rz_core_visual_cmd(RzCore *core, const char *arg) {
visual_search(core);
} else {
if (visual->autoblocksize) {
rz_core_cmd0(core, "?i highlight;e scr.highlight=`yp`");
rz_core_prompt_highlight(core);
} else {
rz_core_block_size(core, core->blocksize - cols);
}
Expand Down
2 changes: 1 addition & 1 deletion librz/core/tui/vmenus.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ RZ_IPI void rz_core_visual_analysis(RzCore *core, const char *input) {
}
continue;
case '/':
rz_core_cmd0(core, "?i highlight;e scr.highlight=`yp`");
rz_core_prompt_highlight(core);
break;
case 'a':
switch (level) {
Expand Down
2 changes: 1 addition & 1 deletion librz/core/tui/vmenus_graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ RZ_IPI int rz_core_visual_view_graph(RzCore *core) {
if (rz_cons_fgets(cmd, sizeof(cmd), 0, NULL) < 0) {
cmd[0] = '\0';
}
rz_config_set(core->config, "scr.highlight", cmd);
rz_cons_highlight(cmd);
rz_cons_set_raw(1);
rz_cons_show_cursor(false);
rz_cons_clear();
Expand Down
4 changes: 2 additions & 2 deletions librz/debug/p/native/windows/windows_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ RZ_API bool rz_w32_add_winmsg_breakpoint(RzDebug *dbg, const char *msg_name, con
} else {
reg = "edx";
}
b->cond = rz_str_newf("?q `ae %s,%d,-`", reg, type);
b->cond = rz_str_newf("%= `ae %s,%d,-`", reg, type);
} else {
char *reg;
if (!strcmp(dbg->arch, "arm")) {
Expand All @@ -529,7 +529,7 @@ RZ_API bool rz_w32_add_winmsg_breakpoint(RzDebug *dbg, const char *msg_name, con
reg = "ecx";
}
}
b->cond = rz_str_newf("?q `ae %lu,%s,%d,+,[4],-`", type, reg, dbg->bits);
b->cond = rz_str_newf("%= `ae %lu,%s,%d,+,[4],-`", type, reg, dbg->bits);
}
free(name);
return true;
Expand Down

0 comments on commit a1cb888

Please sign in to comment.