More fixes for bitfield prints

This commit is contained in:
pancake 2014-09-22 18:08:29 +02:00
parent f73ecd35dd
commit bd3b5fe636
3 changed files with 12 additions and 6 deletions

View File

@ -72,6 +72,8 @@ static int cmd_type(void *data, const char *input) {
p = strchr (s, ' ');
if (p) {
*p++ = 0;
// dupp in core.c (see getbitfield())
#if 1
isenum = sdb_const_get (core->anal->sdb_types, s, 0);
if (isenum && !strcmp (isenum, "enum")) {
int empty = 1;
@ -92,6 +94,7 @@ static int cmd_type(void *data, const char *input) {
} else {
eprintf ("This is not an enum\n");
}
#endif
free (s);
} else {
eprintf ("Missing value\n");

View File

@ -519,26 +519,30 @@ static char *getenumname(void *_core, const char *name, ut64 val) {
return NULL;
}
// TODO: dupped in cmd_type.c
static char *getbitfield(void *_core, const char *name, ut64 val) {
const char *isenum;
char *ret = NULL;
int i;
RCore *core = (RCore*)_core;
isenum = sdb_const_get (core->anal->sdb_types, name, 0);
if (isenum && !strcmp (isenum, "enum")) {
int empty = 1;
for (i=0; i< 32; i++) {
if (val & (1<<i)) {
const char *q = sdb_fmt (0, "%s.0x%x", name, (1<<i));
const char *res = sdb_const_get (core->anal->sdb_types, q, 0);
if (res) r_cons_printf ("%s | ", res);
else r_cons_printf ("0x%x | ", (1<<i));
if (!empty)
ret = r_str_concat (ret, " | ");
if (res) ret = r_str_concat (ret, res);
else ret = r_str_concatf (ret, "0x%x", (1<<i));
empty = 0;
}
}
r_cons_printf ("0\n");
} else {
eprintf ("This is not an enum\n");
}
return NULL;
return ret;
}
R_API int r_core_init(RCore *core) {

View File

@ -789,7 +789,6 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len,
if (name) *(name++) = '\0';
else eprintf ("No ')'\n");
// TODO: add a callback in RPrint to resolve a bitfield
if (p->get_bitfield)
bitfield = p->get_bitfield (p->user, structname, addr);
if (bitfield && *bitfield) {