Fixes for enum types in t and pf

This commit is contained in:
pancake 2016-09-06 04:29:42 +02:00
parent 11bbcfd690
commit 6df53f8bb1
4 changed files with 45 additions and 18 deletions

View File

@ -223,12 +223,14 @@ R_API char *r_anal_type_format(RAnal *anal, const char *t) {
fmt = r_str_concat (fmt, tfmt);
vars = r_str_concat (vars, q);
vars = r_str_concat (vars, " ");
} else eprintf ("Cannot resolve type '%s'\n", var3);
} else eprintf ("Cannot resolve3 type '%s'\n", var3);
} else eprintf ("Cannot resolve type '%s'\n", var2);
free (type2);
free (q);
}
} else {
bool isStruct = false;
bool isEnum = false;
elements = sdb_array_get_num (DB, var2, 2, NULL);
// special case for char[]. Use char* format type without *
if (!strncmp (type, "char", 5) && elements > 0) {
@ -236,7 +238,12 @@ R_API char *r_anal_type_format(RAnal *anal, const char *t) {
if (tfmt && *tfmt == '*')
tfmt++;
} else {
snprintf (var3, sizeof (var3), "type.%s", type);
if (!strncmp (type, "enum ", 5)) {
snprintf (var3, sizeof (var3), "%s", type + 5);
isEnum = true;
} else {
snprintf (var3, sizeof (var3), "type.%s", type);
}
tfmt = sdb_const_get (DB, var3, NULL);
}
if (tfmt) {
@ -244,10 +251,22 @@ R_API char *r_anal_type_format(RAnal *anal, const char *t) {
if (elements > 0) {
fmt = r_str_concatf (fmt, "[%d]", elements);
}
fmt = r_str_concat (fmt, tfmt);
vars = r_str_concat (vars, p);
vars = r_str_concat (vars, " ");
} else eprintf ("Cannot resolve type '%s'\n", var3);
if (isStruct) {
fmt = r_str_concat (fmt, "?");
vars = r_str_concatf (vars, "(%s)%s", p, p);
vars = r_str_concat (vars, " ");
} else if (isEnum) {
fmt = r_str_concat (fmt, "E");
vars = r_str_concatf (vars, "(%s)%s", type + 5, p);
vars = r_str_concat (vars, " ");
} else {
fmt = r_str_concat (fmt, tfmt);
vars = r_str_concat (vars, p);
vars = r_str_concat (vars, " ");
}
} else {
eprintf ("Cannot resolve type '%s'\n", var3);
}
}
}
free (type);

View File

@ -251,7 +251,7 @@ static int cmd_type(void *data, const char *input) {
if (p) {
*p++ = 0;
isenum = sdb_const_get (core->anal->sdb_types, s, 0);
if (isenum && !strcmp (isenum, "enum")) {
if (isenum && !strncmp (isenum, "enum", 4)) {
const char *q = sdb_fmt (0, "%s.0x%x", s, (ut32)r_num_math (core->num, p));
const char *res = sdb_const_get (core->anal->sdb_types, q, 0);
if (res)

View File

@ -1015,11 +1015,11 @@ static char *getenumname(void *_core, const char *name, ut64 val) {
RCore *core = (RCore*)_core;
isenum = sdb_const_get (core->anal->sdb_types, name, 0);
if (isenum && !strcmp (isenum, "enum")) {
if (isenum && !strncmp (isenum, "enum", 4)) {
const char *q = sdb_fmt (0, "%s.0x%x", name, val);
return sdb_get (core->anal->sdb_types, q, 0);
} else {
eprintf ("This is not an enum\n");
eprintf ("This is not an enum (%s)\n", name);
}
return NULL;
}

View File

@ -968,20 +968,28 @@ static void r_print_format_enum (const RPrint* p, ut64 seeki, char* fmtname,
case 2: addr &= UT16_MAX; break;
case 4: addr &= UT32_MAX; break;
}
if (MUSTSEE)
if (!SEEVALUE) p->cb_printf ("0x%08"PFMT64x" = ", seeki);
if (p->get_enumname)
if (MUSTSEE && !SEEVALUE) {
p->cb_printf ("0x%08"PFMT64x" = ", seeki);
}
if (p->get_enumname) {
enumvalue = p->get_enumname (p->user, fmtname, addr);
}
if (enumvalue && *enumvalue) {
if (mode & R_PRINT_DOT) {
p->cb_printf ("%s.%s", fmtname, enumvalue);
} else if (MUSTSEEJSON) p->cb_printf ("\"%s\"}", fmtname);
else if (MUSTSEE) p->cb_printf (" %s (enum) = 0x%"PFMT64x" ; %s\n",
fieldname, addr, enumvalue);
} else if (MUSTSEEJSON) {
p->cb_printf ("\"%s\"}", fmtname);
} else if (MUSTSEE) {
p->cb_printf ("%s (enum %s) = 0x%"PFMT64x" ; %s\n",
fieldname, fmtname, addr, enumvalue);
}
} else {
if (MUSTSEEJSON) p->cb_printf ("\"`te %s 0x%x`\"}", fmtname, addr);
else if (MUSTSEE) p->cb_printf (" %s (enum) = %s\n",//`te %s 0x%x`\n",
fieldname, enumvalue); //fmtname, addr);
if (MUSTSEEJSON) {
p->cb_printf ("\"`te %s 0x%x`\"}", fmtname, addr);
} else if (MUSTSEE) {
p->cb_printf ("%s (enum %s) = 0x%x\n",//`te %s 0x%x`\n",
fieldname, fmtname, addr); //enumvalue); //fmtname, addr);
}
}
free (enumvalue);
}