mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-12 15:38:09 +00:00
Fix #2648 - Fix save/restore comments using base64, enhace default output and add CC?
This commit is contained in:
parent
c27327cac5
commit
33a8338b97
@ -282,37 +282,84 @@ static void printmetaitem(RAnal *a, RAnalMetaItem *d, int rad) {
|
||||
d->from, r_meta_type_to_string (d->type), str);
|
||||
break;
|
||||
case 0:
|
||||
a->printf ("0x%08"PFMT64x" %s\n",
|
||||
d->from, str);
|
||||
case 1:
|
||||
case '*':
|
||||
default:
|
||||
switch (d->type) {
|
||||
case 'C':
|
||||
a->printf ("\"%s %s\" @ 0x%08"PFMT64x"\n",
|
||||
r_meta_type_to_string (d->type), pstr, d->from);
|
||||
{
|
||||
const char *type = r_meta_type_to_string (d->type);
|
||||
char *s = sdb_encode ((const ut8*)pstr, -1);
|
||||
if (!s) s = strdup (pstr);
|
||||
if (rad) {
|
||||
if (!strcmp (type, "CCu")) {
|
||||
a->printf ("%s base64:%s @ 0x%08"PFMT64x"\n",
|
||||
type, s, d->from);
|
||||
} else {
|
||||
a->printf ("%s %s @ 0x%08"PFMT64x"\n",
|
||||
type, pstr, d->from);
|
||||
}
|
||||
} else {
|
||||
if (!strcmp (type, "CCu")) {
|
||||
char *mys = r_str_escape (pstr);
|
||||
a->printf ("0x%08"PFMT64x" %s \"%s\"\n",
|
||||
d->from, type, mys);
|
||||
free (mys);
|
||||
} else {
|
||||
a->printf ("0x%08"PFMT64x" %s \"%s\"\n",
|
||||
d->from, type, pstr);
|
||||
}
|
||||
}
|
||||
free (s);
|
||||
}
|
||||
break;
|
||||
case 'h': /* hidden */
|
||||
case 's': /* string */
|
||||
a->printf ("%s %d @ 0x%08"PFMT64x" # %s\n",
|
||||
r_meta_type_to_string (d->type),
|
||||
d->size, d->from, pstr);
|
||||
if (rad) {
|
||||
a->printf ("%s %d @ 0x%08"PFMT64x" # %s\n",
|
||||
r_meta_type_to_string (d->type),
|
||||
d->size, d->from, pstr);
|
||||
} else {
|
||||
// TODO: use b64 here
|
||||
a->printf ("0x%08"PFMT64x" string[%d] \"%s\"\n",
|
||||
d->from, d->size, pstr);
|
||||
}
|
||||
break;
|
||||
case 'd': /* data */
|
||||
a->printf ("%s %d @ 0x%08"PFMT64x"\n",
|
||||
r_meta_type_to_string (d->type),
|
||||
d->size, d->from);
|
||||
if (rad) {
|
||||
a->printf ("%s %d @ 0x%08"PFMT64x"\n",
|
||||
r_meta_type_to_string (d->type),
|
||||
d->size, d->from);
|
||||
} else {
|
||||
a->printf ("0x%08"PFMT64x" data %s %d\n",
|
||||
d->from, r_meta_type_to_string (d->type), d->size);
|
||||
|
||||
}
|
||||
break;
|
||||
case 'm': /* magic */
|
||||
case 'f': /* formatted */
|
||||
a->printf ("%s %d %s @ 0x%08"PFMT64x"\n",
|
||||
r_meta_type_to_string (d->type),
|
||||
d->size, pstr, d->from);
|
||||
if (rad) {
|
||||
a->printf ("%s %d %s @ 0x%08"PFMT64x"\n",
|
||||
r_meta_type_to_string (d->type),
|
||||
d->size, pstr, d->from);
|
||||
} else {
|
||||
const char *dtype = d->type=='m'?"magic":"format";
|
||||
a->printf ("0x%08"PFMT64x" %s %d %s\n",
|
||||
d->from, dtype, d->size, pstr);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
a->printf ("%s %d 0x%08"PFMT64x" # %s\n",
|
||||
r_meta_type_to_string (d->type),
|
||||
d->size, d->from, pstr);
|
||||
if (rad) {
|
||||
a->printf ("%s %d 0x%08"PFMT64x" # %s\n",
|
||||
r_meta_type_to_string (d->type),
|
||||
d->size, d->from, pstr);
|
||||
} else {
|
||||
// TODO: use b64 here
|
||||
a->printf ("0x%08"PFMT64x" array[%d] %s %s\n",
|
||||
d->from, d->size,
|
||||
r_meta_type_to_string (d->type), pstr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1498,7 +1498,7 @@ static void cmd_anal_esil(RCore *core, const char *input) {
|
||||
if (input[1] == 'u' && input[2] == 'e')
|
||||
until_expr = input + 3;
|
||||
else if (input[1] == 'u')
|
||||
until_addr = r_num_math(core->num, input + 2);
|
||||
until_addr = r_num_math (core->num, input + 2);
|
||||
else until_expr = "0";
|
||||
esil_step (core, until_addr, until_expr);
|
||||
break;
|
||||
|
@ -239,6 +239,25 @@ error:
|
||||
static int cmd_meta_comment(RCore *core, const char *input) {
|
||||
ut64 addr = core->offset;
|
||||
switch (input[1]) {
|
||||
case '?': {
|
||||
const char* help_msg[] = {
|
||||
"Usage:", "CC[-+!*au] [base64:..|str] @ addr", "",
|
||||
"CC", "", "list all comments in human friednly form",
|
||||
"CC*", "", "list all comments in r2 commands",
|
||||
"CC.", "", "show comment at current offset",
|
||||
"CC", " or maybe not", "append comment at current address",
|
||||
"CC!", "", "clear all meta information (remove comments, ...)",
|
||||
"CC-", " @ cmt_addr", "remove comment at given address",
|
||||
"CCu", " good boy @ addr", "add good boy comment at given address",
|
||||
"CCu", " base64:AA== @ addr", "add comment in base64",
|
||||
NULL};
|
||||
r_core_cmd_help (core, help_msg);
|
||||
} break;
|
||||
case '.':
|
||||
break;
|
||||
case 0:
|
||||
r_meta_list (core->anal, R_META_TYPE_COMMENT, 0);
|
||||
break;
|
||||
case '!':
|
||||
{
|
||||
char *out, *comment = r_meta_get_string (
|
||||
@ -286,15 +305,29 @@ static int cmd_meta_comment(RCore *core, const char *input) {
|
||||
case 'u':
|
||||
//
|
||||
{
|
||||
const char* newcomment = input+2;
|
||||
while (*newcomment==' ') newcomment++;
|
||||
char *comment = r_meta_get_string (
|
||||
core->anal, R_META_TYPE_COMMENT, addr);
|
||||
if (!comment || (comment && !strstr (comment, newcomment))) {
|
||||
r_meta_set_string (core->anal, R_META_TYPE_COMMENT,
|
||||
addr, newcomment);
|
||||
char *newcomment;
|
||||
char *arg = input+2;
|
||||
while (*arg && *arg == ' ') arg++;
|
||||
if (!strncmp (arg, "base64:", 7)) {
|
||||
char *s = (char *)sdb_decode (arg+7, NULL);
|
||||
if (s) {
|
||||
newcomment = s;
|
||||
} else {
|
||||
newcomment = NULL;
|
||||
}
|
||||
} else {
|
||||
newcomment = strdup (arg);
|
||||
}
|
||||
if (newcomment) {
|
||||
char *comment = r_meta_get_string (
|
||||
core->anal, R_META_TYPE_COMMENT, addr);
|
||||
if (!comment || (comment && !strstr (comment, newcomment))) {
|
||||
r_meta_set_string (core->anal, R_META_TYPE_COMMENT,
|
||||
addr, newcomment);
|
||||
}
|
||||
free (comment);
|
||||
free (newcomment);
|
||||
}
|
||||
free (comment);
|
||||
}
|
||||
break;
|
||||
case 'a':
|
||||
|
Loading…
Reference in New Issue
Block a user