From acea95544d6a37706cd92e0960151eb3d48a85a9 Mon Sep 17 00:00:00 2001 From: Khairul Azhar Kasmiran Date: Sat, 24 Feb 2018 19:01:21 +0800 Subject: [PATCH] asm.asciidot -> scr.strconv=asciidot (#9485) --- libr/core/cconfig.c | 26 ++++++++++++++++++++++++-- libr/core/disasm.c | 2 +- libr/include/r_print.h | 1 + libr/util/print.c | 1 + 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/libr/core/cconfig.c b/libr/core/cconfig.c index 7eb91716a0..f384b738e0 100644 --- a/libr/core/cconfig.c +++ b/libr/core/cconfig.c @@ -1680,6 +1680,27 @@ static int cb_scrflush(void *user, void *data) { return true; } +static int cb_scrstrconv(void *user, void *data) { + RCore *core = (RCore*) user; + RConfigNode *node = (RConfigNode*) data; + if (node->value[0] == '?') { + if (strlen (node->value) > 1 && node->value[1] == '?') { + r_cons_printf ("Valid values for scr.strconv:\n" + " asciiesc convert to ascii with non-ascii chars escaped\n" + " asciidot convert to ascii with non-ascii chars turned into a dot (except some control chars)\n" + "\n" + "Ascii chars are in the range 0x20-0x7e.\n"); + } else { + print_node_options (node); + } + return false; + } else { + free ((char *)core->print->strconv_mode); + core->print->strconv_mode = strdup (node->value); + } + return true; +} + static int cb_exectrap(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; RCore *core = (RCore*) user; @@ -2408,8 +2429,6 @@ R_API int r_core_config_init(RCore *core) { SETPREF ("asm.cmt.patch", "false", "Show patch comments in disasm"); SETPREF ("asm.cmt.off", "nodup", "Show offset comment in disasm (true, false, nodup)"); SETPREF ("asm.payloads", "false", "Show payload bytes in disasm"); - SETPREF ("asm.asciidot", "false", "Enable a char filter for string comments that passes through chars in the " - "range 0x20-0x7e and turns the rest into dots (except some control chars)"); n = NODECB ("asm.strenc", "guess", &cb_asmstrenc); SETDESC (n, "Assumed string encoding for disasm"); SETOPTIONS (n, "latin1", "utf8", "utf16le", "utf32le", "guess", NULL); @@ -2786,6 +2805,9 @@ R_API int r_core_config_init(RCore *core) { &cb_utf8, "Show UTF-8 characters instead of ANSI"); SETCB ("scr.utf8.curvy", "false", &cb_utf8_curvy, "Show curved UTF-8 corners (requires scr.utf8)"); SETPREF ("scr.histsave", "true", "Always save history on exit"); + n = NODECB ("scr.strconv", "asciiesc", &cb_scrstrconv); + SETDESC (n, "Convert string before display"); + SETOPTIONS (n, "asciiesc", "asciidot", NULL); /* str */ SETCB ("str.escbslash", "false", &cb_str_escbslash, "Escape the backslash (iz and Cs-based output only)"); diff --git a/libr/core/disasm.c b/libr/core/disasm.c index 84d7bb1986..20dcdeb16d 100644 --- a/libr/core/disasm.c +++ b/libr/core/disasm.c @@ -636,7 +636,7 @@ static RDisasmState * ds_init(RCore *core) { ds->show_functions = r_config_get_i (core->config, "asm.functions"); ds->show_fcncalls = r_config_get_i (core->config, "asm.fcncalls"); ds->nbytes = r_config_get_i (core->config, "asm.nbytes"); - ds->show_asciidot = r_config_get_i (core->config, "asm.asciidot"); + ds->show_asciidot = !strcmp (core->print->strconv_mode, "asciidot"); const char *strenc_str = r_config_get (core->config, "asm.strenc"); if (!strcmp (strenc_str, "latin1")) { ds->strenc = R_STRING_ENC_LATIN1; diff --git a/libr/include/r_print.h b/libr/include/r_print.h index e10da9e658..2f23fac90c 100644 --- a/libr/include/r_print.h +++ b/libr/include/r_print.h @@ -88,6 +88,7 @@ typedef struct r_print_t { int lines_cache_sz; int lines_abs; bool esc_bslash; + const char *strconv_mode; // when true it uses row_offsets bool calc_row_offsets; diff --git a/libr/util/print.c b/libr/util/print.c index 6bab06ce03..3990401969 100644 --- a/libr/util/print.c +++ b/libr/util/print.c @@ -303,6 +303,7 @@ R_API RPrint* r_print_new() { p->vflush = true; p->screen_bounds = 0; p->esc_bslash = false; + p->strconv_mode = NULL; memset (&p->consbind, 0, sizeof (p->consbind)); return p; }