From 4204fecce83f1339485a8c170f2098ed66c5f77d Mon Sep 17 00:00:00 2001 From: pancake Date: Fri, 5 May 2017 02:11:02 +0200 Subject: [PATCH] Fix #7406 - do not relsub on reg*x+base expressions --- libr/parse/parse.c | 50 +++++++++++++++++++++++++++++++++++----------- libr/util/str.c | 2 +- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/libr/parse/parse.c b/libr/parse/parse.c index d74adf1202..081de683e1 100644 --- a/libr/parse/parse.c +++ b/libr/parse/parse.c @@ -185,12 +185,24 @@ static int filter(RParse *p, RFlag *f, char *data, char *str, int len, bool big_ if (ptr2) { memmove (ptr2, ptr2 + 6, strlen (ptr2 + 6) + 1); } + ptr2 = strstr (ptr, "qword "); + if (ptr2) { + memmove (ptr2, ptr2 + 6, strlen (ptr2 + 6) + 1); + } #endif ptr2 = NULL; // remove "dword" 2 char *nptr; while ((nptr = findNextNumber (ptr))) { char *optr = ptr; +#if 0 + if (nptr[1]== ' ') { + for (nptr++;*nptr && *nptr >='0' && *nptr <= '9'; nptr++) { + } + ptr = nptr; + continue; + } +#endif ptr = nptr; if (x86) { for (ptr2 = ptr; *ptr2 && !isx86separator (*ptr2); ptr2++) { @@ -258,8 +270,16 @@ static int filter(RParse *p, RFlag *f, char *data, char *str, int len, bool big_ *ptr = 0; snprintf (str, len, "%s%s%s", data, flag->name, (ptr != ptr2) ? ptr2 : ""); - - if (p->relsub_addr) { + bool banned = false; + { + const char *p = strchr (str, '['); + const char *a = strchr (str, '+'); + const char *m = strchr (str, '*'); + if (p && a && m) { + banned = true; + } + } + if (p->relsub_addr && !banned) { // && strstr (str, " + ")) { int flag_len = strlen (flag->name); char *ptr_end = str + strlen (data) + flag_len - 1; char *ptr_right = ptr_end + 1, *ptr_left, *ptr_esc; @@ -268,31 +288,37 @@ static int filter(RParse *p, RFlag *f, char *data, char *str, int len, bool big_ while (*ptr_right) { if (*ptr_right == 0x1b) { while (*ptr_right && *ptr_right != 'm') ptr_right++; - if (*ptr_right) ptr_right++; + if (*ptr_right) { + ptr_right++; + } ansi_found = true; continue; - } else if (*ptr_right == ']') { + } + if (*ptr_right == ']') { ptr_left = ptr_esc = ptr_end - flag_len; while (ptr_left >= str) { if (*ptr_left == '[' && - (ptr_left == str || *(ptr_left - 1) != 0x1b)) break; + (ptr_left == str || *(ptr_left - 1) != 0x1b)) { + break; + } ptr_left--; } - if (ptr_left < str) break; - + if (ptr_left < str) { + break; + } for (; ptr_esc >= str && *ptr_esc != 0x1b; ptr_esc--); - if (ptr_esc < str) ptr_esc = ptr_end - flag_len + 1; - + if (ptr_esc < str) { + ptr_esc = ptr_end - flag_len + 1; + } copied_len = ptr_end - ptr_esc + 1; memmove (ptr_left, ptr_esc, copied_len); sprintf (ptr_left + copied_len, "%s%s", ansi_found && ptr_right - ptr_end + 1 >= 4 ? "\x1b[0m" : "", ptr_right + 1); - break; - } else break; + } + break; } } - return true; } } diff --git a/libr/util/str.c b/libr/util/str.c index 4dde047029..659fa7c975 100644 --- a/libr/util/str.c +++ b/libr/util/str.c @@ -1065,7 +1065,7 @@ R_API char* r_str_replace_thunked(char *str, char *clean, int *thunk, int clen, str_p = str + thunk[i] + delta; newo = thunk[i + klen] - thunk[i]; - r_str_ansi_filter(str_p, NULL, NULL, newo); + r_str_ansi_filter (str_p, NULL, NULL, newo); scnd = strdup (str_p + newo); bias = vlen - newo;