diff --git a/libr/core/cconfig.c b/libr/core/cconfig.c index 082af2e724..9fbfb83b65 100644 --- a/libr/core/cconfig.c +++ b/libr/core/cconfig.c @@ -3366,7 +3366,7 @@ R_API int r_core_config_init(RCore *core) { SETBPREF ("prj.simple", "false", "Use simple project saving style (functions, comments, options)"); /* cfg */ - SETCB ("cfg.charset", "", &cb_cfgcharset, "Specify encoding to use in pse"); + SETCB ("cfg.charset", "", &cb_cfgcharset, "Specify encoding to use when printing strings"); SETBPREF ("cfg.r2wars", "false", "Enable some tweaks for the r2wars game"); SETBPREF ("cfg.plugins", "true", "Load plugins at startup"); SETCB ("time.fmt", "%Y-%m-%d %H:%M:%S %z", &cb_cfgdatefmt, "Date format (%Y-%m-%d %H:%M:%S %z)"); diff --git a/libr/core/cmd_print.c b/libr/core/cmd_print.c index ff8ef55e67..e0b386f93b 100644 --- a/libr/core/cmd_print.c +++ b/libr/core/cmd_print.c @@ -5770,9 +5770,30 @@ l = use_blocksize; } } break; - case ' ': // "ps" - r_print_string (core->print, core->offset, core->block, l, 0); + case ' ': // "ps" + { + const char *current_charset = r_config_get (core->config, "cfg.charset"); + if (R_STR_ISEMPTY (current_charset)) { + r_print_string (core->print, core->offset, core->block, l, 0); + } else { + if (len > 0) { + size_t out_len = len * 10; + ut8 *out = calloc (len, 10); + if (out) { + ut8 *data = malloc (len); + if (data) { + r_io_read_at (core->io, core->offset, data, len); + r_charset_encode_str (core->print->charset, out, out_len, data, len); + r_print_string (core->print, core->offset, + out, len, 0); + free (data); + } + free (out); + } + } + } break; + } case 'u': // "psu" if (l > 0) { bool json = input[2] == 'j'; // "psuj" @@ -5840,30 +5861,30 @@ l = use_blocksize; } } break; - case 'e': // "pse" - // should be done in `ps` when cfg.charset is set - if (len > 0) { - size_t out_len = len * 10; - ut8 *out = calloc (len, 10); - if (out) { - ut8 *data = malloc (len); - if (data) { - r_io_read_at (core->io, core->offset, data, len); - r_charset_encode_str (core->print->charset, out, out_len, data, len); - r_print_string (core->print, core->offset, - out, len, R_PRINT_STRING_ZEROEND); - free (data); + default: // "ps" + { + const char *current_charset = r_config_get (core->config, "cfg.charset"); + if (R_STR_ISEMPTY (current_charset)) { + r_print_string (core->print, core->offset, core->block, len, R_PRINT_STRING_ZEROEND); + } else { + if (len > 0) { + size_t out_len = len * 10; + ut8 *out = calloc (len, 10); + if (out) { + ut8 *data = malloc (len); + if (data) { + r_io_read_at (core->io, core->offset, data, len); + r_charset_encode_str (core->print->charset, out, out_len, data, len); + r_print_string (core->print, core->offset, + out, len, R_PRINT_STRING_ZEROEND); + free (data); + } + free (out); + } } - free (out); } + break; } - break; - default: - if (l > 0) { - r_print_string (core->print, core->offset, core->block, - len, R_PRINT_STRING_ZEROEND); - } - break; } break; case 'm': // "pm" diff --git a/test/db/cmd/charset b/test/db/cmd/charset index 2e3db8ef0f..0528d2ea7b 100644 --- a/test/db/cmd/charset +++ b/test/db/cmd/charset @@ -1,12 +1,12 @@ -NAME=pse +NAME=e cfg.charset FILE=- CMDS=<