Disasm now honors str.escblash (#9667)

This commit is contained in:
Khairul Azhar Kasmiran 2018-03-12 22:54:05 +08:00 committed by radare
parent 405524d2f8
commit b2f301fb07
4 changed files with 17 additions and 16 deletions

View File

@ -2830,7 +2830,7 @@ R_API int r_core_config_init(RCore *core) {
SETOPTIONS (n, "asciiesc", "asciidot", NULL);
/* str */
SETCB ("str.escbslash", "false", &cb_str_escbslash, "Escape the backslash (iz and Cs-based output only)");
SETCB ("str.escbslash", "false", &cb_str_escbslash, "Escape the backslash");
/* search */
SETCB ("search.contiguous", "true", &cb_contiguous, "Accept contiguous/adjacent search hits");

View File

@ -3094,26 +3094,27 @@ static char *ds_esc_str(RDisasmState *ds, const char *str, int len, const char *
int str_len;
char *escstr = NULL;
const char *prefix = "";
bool esc_bslash = ds->core->print->esc_bslash;
switch (ds->strenc) {
case R_STRING_ENC_LATIN1:
escstr = r_str_escape_latin1 (str, ds->show_asciidot, true);
escstr = r_str_escape_latin1 (str, ds->show_asciidot, esc_bslash);
break;
case R_STRING_ENC_UTF8:
escstr = r_str_escape_utf8 (str, ds->show_asciidot, true);
escstr = r_str_escape_utf8 (str, ds->show_asciidot, esc_bslash);
break;
case R_STRING_ENC_UTF16LE:
escstr = r_str_escape_utf16le (str, len, ds->show_asciidot);
escstr = r_str_escape_utf16le (str, len, ds->show_asciidot, esc_bslash);
prefix = "u";
break;
case R_STRING_ENC_UTF32LE:
escstr = r_str_escape_utf32le (str, len, ds->show_asciidot);
escstr = r_str_escape_utf32le (str, len, ds->show_asciidot, esc_bslash);
prefix = "U";
break;
default:
str_len = strlen (str);
if ((str_len == 1 && len > 3 && str[2] && !str[3])
|| (str_len == 3 && len > 5 && !memcmp (str, "\xff\xfe", 2) && str[4] && !str[5])) {
escstr = r_str_escape_utf16le (str, len, ds->show_asciidot);
escstr = r_str_escape_utf16le (str, len, ds->show_asciidot, esc_bslash);
prefix = "u";
} else if (str_len == 1 && len > 7 && !str[2] && !str[3] && str[4] && !str[5]) {
RStrEnc enc = R_STRING_ENC_UTF32LE;
@ -3130,10 +3131,10 @@ static char *ds_esc_str(RDisasmState *ds, const char *str, int len, const char *
}
}
if (enc == R_STRING_ENC_UTF32LE) {
escstr = r_str_escape_utf32le (str, len, ds->show_asciidot);
escstr = r_str_escape_utf32le (str, len, ds->show_asciidot, esc_bslash);
prefix = "U";
} else {
escstr = r_str_escape_latin1 (str, ds->show_asciidot, true);
escstr = r_str_escape_latin1 (str, ds->show_asciidot, esc_bslash);
}
} else {
RStrEnc enc = R_STRING_ENC_LATIN1;
@ -3145,8 +3146,8 @@ static char *ds_esc_str(RDisasmState *ds, const char *str, int len, const char *
}
}
escstr = (enc == R_STRING_ENC_UTF8 ?
r_str_escape_utf8 (str, ds->show_asciidot, true) :
r_str_escape_latin1 (str, ds->show_asciidot, true));
r_str_escape_utf8 (str, ds->show_asciidot, esc_bslash) :
r_str_escape_latin1 (str, ds->show_asciidot, esc_bslash));
}
}
if (prefix_out) {

View File

@ -126,8 +126,8 @@ R_API char *r_str_escape(const char *buf);
R_API char *r_str_escape_dot(const char *buf);
R_API char *r_str_escape_latin1(const char *buf, bool show_asciidot, bool esc_bslash);
R_API char *r_str_escape_utf8(const char *buf, bool show_asciidot, bool esc_bslash);
R_API char *r_str_escape_utf16le(const char *buf, int buf_size, bool show_asciidot);
R_API char *r_str_escape_utf32le(const char *buf, int buf_size, bool show_asciidot);
R_API char *r_str_escape_utf16le(const char *buf, int buf_size, bool show_asciidot, bool esc_bslash);
R_API char *r_str_escape_utf32le(const char *buf, int buf_size, bool show_asciidot, bool esc_bslash);
R_API void r_str_uri_decode(char *buf);
R_API char *r_str_uri_encode(const char *buf);
R_API char *r_str_utf16_decode(const ut8 *s, int len);

View File

@ -1294,12 +1294,12 @@ R_API char *r_str_escape_utf8(const char *buf, bool show_asciidot, bool esc_bsla
return r_str_escape_utf (buf, -1, R_STRING_ENC_UTF8, show_asciidot, esc_bslash);
}
R_API char *r_str_escape_utf16le(const char *buf, int buf_size, bool show_asciidot) {
return r_str_escape_utf (buf, buf_size, R_STRING_ENC_UTF16LE, show_asciidot, true);
R_API char *r_str_escape_utf16le(const char *buf, int buf_size, bool show_asciidot, bool esc_bslash) {
return r_str_escape_utf (buf, buf_size, R_STRING_ENC_UTF16LE, show_asciidot, esc_bslash);
}
R_API char *r_str_escape_utf32le(const char *buf, int buf_size, bool show_asciidot) {
return r_str_escape_utf (buf, buf_size, R_STRING_ENC_UTF32LE, show_asciidot, true);
R_API char *r_str_escape_utf32le(const char *buf, int buf_size, bool show_asciidot, bool esc_bslash) {
return r_str_escape_utf (buf, buf_size, R_STRING_ENC_UTF32LE, show_asciidot, esc_bslash);
}
/* ansi helpers */