diff --git a/libr/core/canal.c b/libr/core/canal.c index e759226945..c8dabc5f2b 100644 --- a/libr/core/canal.c +++ b/libr/core/canal.c @@ -1364,7 +1364,7 @@ static void hint_node_print(HintNode *node, int mode, PJ *pj) { HINTCMD_ADDR (node, "ahe %s", record->esil); // TODO: escape for newcmd break; case R_ANAL_ADDR_HINT_TYPE_HIGH: - r_cons_printf ("ahh @ 0x%"PFMT64x"\n", node->addr); + r_cons_printf ("'@0x0x%"PFMT64x"'ahh\n", node->addr); break; case R_ANAL_ADDR_HINT_TYPE_VAL: // no command for this @@ -1546,7 +1546,7 @@ static void print_hint_tree(RBTree tree, int mode) { } if (pj) { pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + r_cons_println (pj_string (pj)); pj_free (pj); } #undef END_ADDR @@ -1584,7 +1584,7 @@ R_API void r_core_anal_hint_print(RAnal* a, ut64 addr, int mode) { static char *core_anal_graph_label(RCore *core, RAnalBlock *bb, int opts) { const bool is_html = r_cons_context ()->is_html; const bool is_json = opts & R_CORE_ANAL_JSON; - char cmd[1024], file[1024], *cmdstr = NULL, *filestr = NULL, *str = NULL; + char file[1024], *cmdstr = NULL, *filestr = NULL, *str = NULL; int line = 0, oline = 0, colu = 0; ut64 at; @@ -1611,14 +1611,13 @@ static char *core_anal_graph_label(RCore *core, RAnalBlock *bb, int opts) { } cmdstr = r_strbuf_drain (sb); } else if (opts & R_CORE_ANAL_STAR) { - str = r_core_cmd_strf (core, "pdb %"PFMT64u" @ 0x%08" PFMT64x, bb->size, bb->addr); + str = r_core_cmd_strf (core, "'@0x%08"PFMT64x"'pdb %"PFMT64u, bb->addr, bb->size); } else if (opts & R_CORE_ANAL_GRAPHBODY) { const bool scrColor = r_config_get (core->config, "scr.color"); const bool scrUtf8 = r_config_get_b (core->config, "scr.utf8"); r_config_set_i (core->config, "scr.color", COLOR_MODE_DISABLED); r_config_set_b (core->config, "scr.utf8", false); - snprintf (cmd, sizeof (cmd), "pD %"PFMT64u" @ 0x%08" PFMT64x, bb->size, bb->addr); - cmdstr = r_core_cmd_str (core, cmd); + cmdstr = r_core_cmd_strf (core, "'@0x%08"PFMT64x"'pD %"PFMT64u, bb->addr, bb->size); r_config_set_i (core->config, "scr.color", scrColor); r_config_set_b (core->config, "scr.utf8", scrUtf8); } @@ -3381,7 +3380,7 @@ static int fcn_print_detail(RCore *core, RAnalFunction *fcn) { // FIXME: this command prints something annoying. Does it have important side-effects? fcn_list_bbs (fcn); if (fcn->bits != 0) { - r_cons_printf ("afB %d @ 0x%08"PFMT64x"\n", fcn->bits, fcn->addr); + r_cons_printf ("'@0x%08"PFMT64x"'afB %d\n", fcn->addr, fcn->bits); } // FIXME command injection vuln here if (fcn->cc || defaultCC) { diff --git a/libr/core/cbin.c b/libr/core/cbin.c index 92c181753e..383984e35a 100644 --- a/libr/core/cbin.c +++ b/libr/core/cbin.c @@ -1413,7 +1413,7 @@ static bool bin_main(RCore *r, PJ *pj, int mode, int va) { r_flag_space_set (r->flags, R_FLAGS_FS_SYMBOLS); r_flag_set (r->flags, "main", addr, r->blocksize); if (isthumb) { - r_core_cmdf (r, "ahb 16 @ 0x%08"PFMT64x, addr); + r_core_cmd_call_at (r, addr, "ahb 16"); } } else if (IS_MODE_SIMPLE (mode)) { r_cons_printf ("%"PFMT64d, addr); @@ -1421,7 +1421,7 @@ static bool bin_main(RCore *r, PJ *pj, int mode, int va) { r_cons_printf ("fs symbols\n"); r_cons_printf ("f main @ 0x%08"PFMT64x"\n", addr); if (isthumb) { - r_cons_printf ("ahb 16 @ 0x%08"PFMT64x"\n", addr); + r_cons_printf ("'@0x%08"PFMT64x"'ahb 16\n", addr); } } else if (IS_MODE_JSON (mode)) { pj_o (pj); diff --git a/libr/core/cmd_anal.inc.c b/libr/core/cmd_anal.inc.c index 5180f9b15e..7e5257f872 100644 --- a/libr/core/cmd_anal.inc.c +++ b/libr/core/cmd_anal.inc.c @@ -10081,7 +10081,7 @@ static void anal_axg(RCore *core, const char *input, int level, Sdb *db, int opt } else { //snprintf (arg, sizeof (arg), "0x%08"PFMT64x, addr); //if (sdb_add (db, arg, "1", 0)) { - r_cons_printf ("%s0x%08"PFMT64x"\n", pre+2, addr); + r_cons_printf ("%s0x%08"PFMT64x"\n", pre + 2, addr); //} } } @@ -10938,6 +10938,10 @@ static void cmd_anal_hint(RCore *core, const char *input) { case 'b': // "ahb" set bits if (input[1] == '?') { r_core_cmd_help (core, help_msg_ahb); + } else if (input[1] == '*') { // "ahb*" + char *s = r_core_cmd_str (core, "ah*~ahb"); + r_cons_print (s); + free (s); } else if (input[1] == ' ') { char *ptr = r_str_trim_dup (input + 2); int bits; @@ -10948,11 +10952,11 @@ static void cmd_anal_hint(RCore *core, const char *input) { bits = r_num_math (core->num, r_str_word_get0 (ptr, 0)); r_anal_hint_set_bits (core->anal, core->offset, bits); free (ptr); - } else if (input[1] == '-') { + } else if (input[1] == '-') { // "ahb-" if (!strcmp (input + 2, "*")) { r_anal_hint_unset_bits (core->anal, UT64_MAX); } else { - ut64 off = input[2]? r_num_math (core->num, input + 2): core->offset; + const ut64 off = input[2]? r_num_math (core->num, input + 2): core->offset; r_anal_hint_unset_bits (core->anal, off); } } else { @@ -11049,7 +11053,7 @@ static void cmd_anal_hint(RCore *core, const char *input) { } else if (input[1] == '-') { if (input[2] == '*') { R_LOG_INFO ("Not implemented"); - // R2_590 - take arg to specify type of hint to remove .. r_anal_hint_clear (core->anal, ); + // R2_600 - take arg to specify type of hint to remove .. r_anal_hint_clear (core->anal, ); // r_anal_hint_unset_size (core->anal, UT64_MAX); // r_anal_hint_clear (core->anal); } else if (input[2]) { @@ -11061,7 +11065,9 @@ static void cmd_anal_hint(RCore *core, const char *input) { r_anal_hint_unset_size (core->anal, core->offset); } } else if (input[1] == 0) { - r_core_cmd0 (core, "ah~size="); + char *s = r_core_cmd_str (core, "ah~size="); + r_cons_print (s); + free (s); } else { r_core_cmd_help (core, help_msg_ahs); } @@ -13279,7 +13285,7 @@ static bool strnullpad_check(const ut8 *buf, int len, int clen, int inc, bool be if (!buf[i] && !buf[i + 1]) { return false; } - if (buf[i] || !IS_PRINTABLE (buf[i+1])) { + if (buf[i] || !IS_PRINTABLE (buf[i + 1])) { return false; } } diff --git a/libr/core/vmenus.c b/libr/core/vmenus.c index 6f8ebfc02f..9e3ad3983b 100644 --- a/libr/core/vmenus.c +++ b/libr/core/vmenus.c @@ -1808,7 +1808,7 @@ R_API int r_core_visual_view_rop(RCore *core) { int scr_h, scr_w = r_cons_get_size (&scr_h); - if (!line || !*line) { + if (R_STR_ISEMPTY (line)) { return false; } // maybe store in RCore, so we can save it in project and use it outside visual @@ -1986,9 +1986,8 @@ R_API int r_core_visual_view_rop(RCore *core) { { r_line_set_prompt ("comment: "); const char *line = r_line_readline (); - if (line && *line) { - // XXX code injection bug here - r_core_cmdf (core, "CC %s @ 0x%08"PFMT64x, line, addr + delta); + if (R_STR_ISNOTEMPTY (line)) { + r_core_cmdf (core, "'@0x%08"PFMT64x"'CC %s", addr + delta, line); } } break; @@ -1996,7 +1995,7 @@ R_API int r_core_visual_view_rop(RCore *core) { case '\n': case '\r': if (curline && *curline) { - char *line = r_core_cmd_strf (core, "piuq@0x%08"PFMT64x, addr + delta); + char *line = r_core_cmd_strf (core, "'@0x%08"PFMT64x"'piuq", addr + delta); r_str_replace_char (line, '\n', ';'); if (show_color) { // XXX parsing fails to read this ansi-offset @@ -2412,10 +2411,10 @@ R_API int r_core_visual_comments(RCore *core) { ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char switch (ch) { case 'a': - //TODO + // TODO break; case 'e': - //TODO + // TODO break; case 'd': if (p) { @@ -4156,7 +4155,7 @@ onemoretime: r_line_set_prompt ("format: "); strcpy (cmd, "Cf 0 "); if (r_cons_fgets (cmd + 5, sizeof (cmd) - 5, 0, NULL) > 0) { - r_core_cmdf (core, "%s @ 0x%08"PFMT64x, cmd, off); + r_core_cmdf (core, "'@0x%08"PFMT64x"'%s", off, cmd); r_cons_set_raw (1); r_cons_show_cursor (false); } @@ -4172,7 +4171,7 @@ onemoretime: r_cons_show_cursor (true); r_line_set_prompt (ch == 't'? "type: ": "opstr: "); if (r_cons_fgets (str, sizeof (str), 0, NULL) > 0) { - r_core_cmdf (core, "ah%c %s @ 0x%"PFMT64x, ch, str, off); + r_core_cmdf (core, "'@0x%08"PFMT64x"'ah%c %s", off, ch, str); } } break; @@ -4185,7 +4184,7 @@ onemoretime: r_cons_show_cursor (true); r_line_set_prompt ("immbase: "); if (r_cons_fgets (str, sizeof (str), 0, NULL) > 0) { - r_core_cmdf (core, "ahi %s @ 0x%"PFMT64x, str, off); + r_core_cmdf (core, "'@0x%08"PFMT64x"'ahi %s", off, str); } } break; @@ -4195,7 +4194,7 @@ onemoretime: r_cons_show_cursor (true); r_line_set_prompt ("immbase: "); if (r_cons_fgets (str, sizeof (str), 0, NULL) > 0) { - r_core_cmdf (core, "ahi1 %s @ 0x%"PFMT64x, str, off); + r_core_cmdf (core, "'@0x%08"PFMT64x"'ahi1 %s", off, str); } } break; diff --git a/test/db/anal/x86_64 b/test/db/anal/x86_64 index 28bca5d5bf..d0d56d5a4a 100644 --- a/test/db/anal/x86_64 +++ b/test/db/anal/x86_64 @@ -126,7 +126,7 @@ afb+ 0x100000da0 0x100000e64 16 0x100000e82 0x100000e74 afb+ 0x100000da0 0x100000e74 14 0x100000e8b 0xffffffffffffffff afb+ 0x100000da0 0x100000e8b 5 0x100000e99 0xffffffffffffffff afb+ 0x100000da0 0x100000e90 9 0x100000eba 0xffffffffffffffff -afB 64 @ 0x100000da0 +'@0x100000da0'afB 64 s 0x100000da0 'afc amd64 s- diff --git a/test/db/cmd/cmd_ah b/test/db/cmd/cmd_ah index 9ad07975b3..5ffc72fa10 100644 --- a/test/db/cmd/cmd_ah +++ b/test/db/cmd/cmd_ah @@ -120,7 +120,7 @@ ahc 0x804804 @ 0x1337 ahe 3,eax,+= @ 0x1337 ahf 0x12345 @ 0x1337 ahF 0x10 @ 0x1337 -ahh @ 0x1337 +'@0x0x1337'ahh ahi 10 @ 0x1337 ahd foo a0,33 @ 0x1337 ahp 0xc0ff33 @ 0x1337 @@ -136,7 +136,7 @@ ahc 0x804804 @ 0x1337 ahe 3,eax,+= @ 0x1337 ahf 0x12345 @ 0x1337 ahF 0x10 @ 0x1337 -ahh @ 0x1337 +'@0x0x1337'ahh ahi 10 @ 0x1337 ahd foo a0,33 @ 0x1337 ahp 0xc0ff33 @ 0x1337