Fix #11464, reinstate Ct functionality (#11465)

* Step 1 in fixing Ct: behave like CC

* Strip functionality irrelevant to Ct

* Rename Ct function

* In Ps, dedicate formatting for Ct

* Do not escape Ct comments

* Cleaner sanitize (but not escape) for Ct comments

* Reinstate Ct. [@ addr] command

* Add help msgs for Ct

* Free mem-leaked comments

* Use strdup instead of r_str_ndup
This commit is contained in:
Northern-Lights 2018-09-10 01:27:47 -07:00 committed by radare
parent 57024df5f3
commit eea598d980
2 changed files with 83 additions and 2 deletions

View File

@ -503,6 +503,11 @@ R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, int rad, bool show_full) {
pstr = str;
} else if (d->type == 's') {
pstr = str;
} else if (d->type == 't') {
// Sanitize (don't escape) Ct comments so we can see "char *", etc.
str = strdup (d->str);
r_str_sanitize(str);
pstr = str;
} else if (d->type != 'C') {
r_name_filter (str, 0);
pstr = str;
@ -640,6 +645,14 @@ R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, int rad, bool show_full) {
}
}
break;
case 't': /* vartype */
if (rad) {
a->cb_printf ("%s %s @ 0x%08"PFMT64x"\n",
r_meta_type_to_string (d->type), pstr, d->from);
} else {
a->cb_printf ("0x%08"PFMT64x" %s\n", d->from, pstr);
}
break;
default:
if (rad) {
a->cb_printf ("%s %d 0x%08"PFMT64x" # %s\n",

View File

@ -18,11 +18,12 @@ static const char *help_msg_C[] = {
"CL", "[-][*] [file:line] [addr]", "show or add 'code line' information (bininfo)",
"CS", "[-][space]", "manage meta-spaces to filter comments, etc..",
"CC", "[?] [-] [comment-text] [@addr]", "add/remove comment",
"Ct", "[?] [-] [comment-text] [@addr]", "add/remove type analysis comment",
"CC.", "[addr]", "show comment in current address",
"CC!", " [@addr]", "edit comment with $EDITOR",
"CCa", "[-at]|[at] [text] [@addr]", "add/remove comment at given address",
"CCu", " [comment-text] [@addr]", "add unique comment",
"Ct", "[?] [-] [comment-text] [@addr]", "add/remove type analysis comment",
"Ct.", "[@addr]", "show comment at current or specified address",
"Cv", "[bsr][?]", "add comments to args",
"Cs", "[?] [-] [size] [@addr]", "add string",
"Cz", "[@addr]", "add string (see Cs?)",
@ -51,6 +52,15 @@ static const char *help_msg_CC[] = {
NULL
};
static const char *help_msg_Ct[] = {
"Usage: Ct", "[.|-] [@ addr]", " # Manage comments for variable types",
"Ct", "", "list all variable type comments",
"Ct", " comment-text [@ addr]", "place comment at current or specified address",
"Ct.", " [@ addr]", "show comment at current or specified address",
"Ct-", " [@ addr]", "remove comment at current or specified address",
NULL
};
static const char *help_msg_CS[] = {
"Usage: CS","[*] [+-][metaspace|addr]", " # Manage metaspaces",
"CS","","display metaspaces",
@ -416,6 +426,7 @@ static int cmd_meta_comment(RCore *core, const char *input) {
strcat (text, " ");
strcat (text, nc);
r_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, text);
free (comment);
free (text);
} else {
r_sys_perror ("malloc");
@ -519,6 +530,61 @@ static int cmd_meta_comment(RCore *core, const char *input) {
return true;
}
static int cmd_meta_vartype_comment(RCore *core, const char *input) {
ut64 addr = core->offset;
switch (input[1]) {
case '?': // "Ct?"
r_core_cmd_help (core, help_msg_Ct);
break;
case 0: // "Ct"
r_meta_list (core->anal, R_META_TYPE_VARTYPE, 0);
break;
case ' ': // "Ct <vartype comment> @ addr"
{
const char* newcomment = r_str_trim_ro (input + 2);
char *text, *comment = r_meta_get_string (core->anal, R_META_TYPE_VARTYPE, addr);
char *nc = strdup (newcomment);
r_str_unescape (nc);
if (comment) {
text = malloc (strlen (comment)+ strlen (newcomment)+2);
if (text) {
strcpy (text, comment);
strcat (text, " ");
strcat (text, nc);
r_meta_set_string (core->anal, R_META_TYPE_VARTYPE, addr, text);
free (comment);
free (text);
} else {
r_sys_perror ("malloc");
}
} else {
r_meta_set_string (core->anal, R_META_TYPE_VARTYPE, addr, nc);
}
free (nc);
}
break;
case '.': // "Ct. @ addr"
{
ut64 at = input[2]? r_num_math (core->num, input + 2): addr;
char *comment = r_meta_get_string (
core->anal, R_META_TYPE_VARTYPE, at);
if (comment) {
r_cons_println (comment);
free (comment);
}
}
break;
case '-': // "Ct-"
r_meta_del (core->anal, R_META_TYPE_VARTYPE, core->offset, 1);
break;
default:
r_core_cmd_help (core, help_msg_Ct);
break;
}
return true;
}
static int cmd_meta_others(RCore *core, const char *input) {
int n, type = input[0], subtype;
char *t = 0, *p, *p2, name[256];
@ -950,6 +1016,9 @@ static int cmd_meta(void *data, const char *input) {
case 'C': // "CC"
cmd_meta_comment (core, input);
break;
case 't': // "Ct" type analysis commnets
cmd_meta_vartype_comment (core, input);
break;
case 'r': // "Cr" run command
case 'h': // "Ch" comment
case 's': // "Cs" string
@ -957,7 +1026,6 @@ static int cmd_meta(void *data, const char *input) {
case 'd': // "Cd" data
case 'm': // "Cm" magic
case 'f': // "Cf" formatted
case 't': // "Ct" type analysis commnets
cmd_meta_others (core, input);
break;
case '-': // "C-"