Improve ecH (ecH-* dels them all, ecH- doesnt segfault, ecH list) ##disasm

This commit is contained in:
pancake 2020-02-17 18:52:42 +01:00 committed by radare
parent 77ce3bb7c3
commit 3b5c9bd775
2 changed files with 53 additions and 25 deletions

View File

@ -569,7 +569,7 @@ R_API const char *r_meta_type_to_string(int type) {
case R_META_TYPE_HIDE: return "Ch";
case R_META_TYPE_COMMENT: return "CCu";
case R_META_TYPE_RUN: return "Cr"; // not in C? help
case R_META_TYPE_HIGHLIGHT: return "CH"; // not in C?
case R_META_TYPE_HIGHLIGHT: return "ecHi"; // not in C?
case R_META_TYPE_VARTYPE: return "Ct";
}
return "# unknown meta # ";
@ -765,6 +765,16 @@ R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, int rad, PJ *pj, bool show_f
a->cb_printf ("0x%08"PFMT64x" %s\n", d->from, pstr);
}
break;
case 'H':
{
ut8 r, g, b, A;
const char *esc = strchr (d->str, '\x1b');
r_cons_rgb_parse (esc, &r, &g, &b, &A);
a->cb_printf ("%s rgb:%02x%02x%02x @ 0x%08"PFMT64x"\n",
r_meta_type_to_string (d->type), r, g, b, d->from);
// TODO: d->size
}
break;
default:
if (rad) {
a->cb_printf ("%s %d 0x%08"PFMT64x" # %s\n",

View File

@ -443,23 +443,40 @@ static int cmd_eval(void *data, const char *input) {
char *color_code = NULL;
char *word = NULL;
int argc = 0;
char** argv = r_str_argv (r_str_trim_ro (input + 3), &argc);
int delta = (input[2])? 3: 2;
char** argv = r_str_argv (r_str_trim_ro (input + delta), &argc);
switch (input[2]) {
case '?': {
const char *helpmsg[] = {
"Usage ecH[iw-?]","","",
"ecHi","[color]","highlight current instruction with 'color' background",
"ecHw","[word] [color]","highlight 'word ' in current instruction with 'color' background",
"ecH","","list all the highlight rules",
"ecH-","*","remove all the highlight hints",
"ecH-","","remove all highlights on current instruction",
NULL
};
r_core_cmd_help (core, helpmsg);
}
break;
r_str_argv_free (argv);
return false;
case '-':
r_meta_set_string (core->anal, R_META_TYPE_HIGHLIGHT, core->offset, "");
if (input[3] == '*') {
r_meta_del (core->anal, R_META_TYPE_HIGHLIGHT, 0, UT64_MAX);
} else {
r_meta_set_string (core->anal, R_META_TYPE_HIGHLIGHT, core->offset, "");
}
r_str_argv_free (argv);
return false;
case '\0':
r_meta_list (core->anal, R_META_TYPE_HIGHLIGHT, 0);
r_str_argv_free (argv);
return false;
case '*':
r_meta_list (core->anal, R_META_TYPE_HIGHLIGHT, '*');
r_str_argv_free (argv);
return false;
case ' ':
case 'i': // "ecHi"
if (argc) {
char *dup = r_str_newf ("bgonly %s", argv[0]);
@ -474,7 +491,7 @@ static int cmd_eval(void *data, const char *input) {
break;
case 'w': // "ecHw"
if (!argc) {
eprintf ("Usage: echw word [color]\n");
eprintf ("Usage: ecHw word [color]\n");
r_str_argv_free (argv);
return true;
}
@ -496,6 +513,7 @@ static int cmd_eval(void *data, const char *input) {
r_str_argv_free (argv);
return true;
}
r_meta_set_string (core->anal, R_META_TYPE_HIGHLIGHT, core->offset, "");
char *str = r_meta_get_string (core->anal, R_META_TYPE_HIGHLIGHT, core->offset);
char *dup = r_str_newf ("%s \"%s%s\"", str?str:"", word?word:"", color_code?color_code:r_cons_singleton ()->context->pal.wordhl);
r_meta_set_string (core->anal, R_META_TYPE_HIGHLIGHT, core->offset, dup);
@ -503,27 +521,27 @@ static int cmd_eval(void *data, const char *input) {
R_FREE (word);
R_FREE (dup);
break;
}
}
default: {
char *p = strdup (input + 2);
char *q = strchr (p, '=');
if (!q) {
q = strchr (p, ' ');
}
if (q) {
// Set color
*q++ = 0;
if (r_cons_pal_set (p, q)) {
r_cons_pal_update_event ();
}
} else {
char color[32];
RColor rcolor = r_cons_pal_get (p);
r_cons_rgb_str (color, sizeof (color), &rcolor);
eprintf ("(%s)(%sCOLOR"Color_RESET")\n", p, color);
}
free (p);
}
char *p = strdup (input + 2);
char *q = strchr (p, '=');
if (!q) {
q = strchr (p, ' ');
}
if (q) {
// Set color
*q++ = 0;
if (r_cons_pal_set (p, q)) {
r_cons_pal_update_event ();
}
} else {
char color[32];
RColor rcolor = r_cons_pal_get (p);
r_cons_rgb_str (color, sizeof (color), &rcolor);
eprintf ("(%s)(%sCOLOR"Color_RESET")\n", p, color);
}
free (p);
}
}
break;
case 'd': // "ed"