Skip to content

Commit

Permalink
Consolidated deserialization of sdb val into r_meta_deserialize_val() (
Browse files Browse the repository at this point in the history
  • Loading branch information
kazarmy authored and radare committed Oct 25, 2017
1 parent 2eb8af0 commit 4cfb06e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 62 deletions.
48 changes: 14 additions & 34 deletions libr/anal/meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,19 +278,23 @@ static void meta_serialize(RAnalMetaItem *it, char *k, size_t k_size, char *v, s
}

static bool meta_deserialize(RAnalMetaItem *it, const char *k, const char *v) {
const char *v2;
char *v3;
if (strlen (k) < 8) {
return false;
}
if (memcmp (k + 6, ".0x", 3)) {
return false;
}
it->type = k[5];
return r_meta_deserialize_val (it, k[5], sdb_atoi (k + 7), v);
}

R_API bool r_meta_deserialize_val(RAnalMetaItem *it, int type, ut64 from, const char *v) {
const char *v2;
char *v3;
it->type = type;
it->subtype = 0;
it->size = sdb_atoi (v);
it->from = sdb_atoi (k + 7);
it->to = it->from + it->size;
it->from = from;
it->to = from + it->size;
v2 = strchr (v, ',');
if (!v2) {
return false;
Expand Down Expand Up @@ -368,49 +372,25 @@ R_API RAnalMetaItem *r_meta_find(RAnal *a, ut64 at, int type, int where) {
return NULL;
}

snprintf (key, sizeof (key)-1, "meta.0x%"PFMT64x, at);
snprintf (key, sizeof (key), "meta.0x%" PFMT64x, at);
infos = sdb_const_get (s, key, 0);
if (!infos) {
return NULL;
}
for (; *infos; infos++) {
/* XXX wtf, must use anal.meta.deserialize() */
char *p, *q, *r;
if (*infos == ',') {
continue;
}
snprintf (key, sizeof (key) - 1, "meta.%c.0x%"PFMT64x, *infos, at);
metas = sdb_const_get (s, key, 0);
mi.size = sdb_array_get_num (s, key, 0, 0);
mi.type = *infos;
mi.subtype = 0;
mi.from = at;
mi.to = at + mi.size;
if (type != R_META_TYPE_ANY && type != mi.type) {
if (type != R_META_TYPE_ANY && type != *infos) {
continue;
}
snprintf (key, sizeof (key), "meta.%c.0x%" PFMT64x, *infos, at);
metas = sdb_const_get (s, key, 0);
if (metas) {
p = strchr (metas, ',');
if (!p) {
continue;
}
mi.space = atoi (p + 1);
q = strchr (p + 1, ',');
if (!q) {
if (!r_meta_deserialize_val (&mi, *infos, at, metas)) {
continue;
}
if (mi.type == R_META_TYPE_STRING) {
r = strchr (q + 1, ',');
if (r) {
mi.subtype = *(q + 1);
q = r;
}
}
free (mi.str);
mi.str = (char*)sdb_decode (q + 1, 0);
return &mi;
} else {
mi.str = NULL;
}
}
return NULL;
Expand Down
33 changes: 5 additions & 28 deletions libr/core/disasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2068,47 +2068,24 @@ static int ds_print_meta_infos(RDisasmState *ds, ut8* buf, int len, int idx) {
const char *infos, *metas;
char key[100];
RAnalMetaItem MI, *mi = &MI;
RCore * core = ds->core;
RCore *core = ds->core;
Sdb *s = core->anal->sdb_meta;

snprintf (key, sizeof (key)-1, "meta.0x%"PFMT64x, ds->at);
snprintf (key, sizeof (key), "meta.0x%" PFMT64x, ds->at);
infos = sdb_const_get (s, key, 0);

ds->mi_found = false;
if (infos) {
for (;*infos; infos++) {
/* XXX wtf, must use anal.meta.deserialize() */
char *p, *q, *r;
for (; *infos; infos++) {
if (*infos == ',') {
continue;
}
snprintf (key, sizeof (key)-1, "meta.%c.0x%"PFMT64x, *infos, ds->at);
snprintf (key, sizeof (key), "meta.%c.0x%" PFMT64x, *infos, ds->at);
metas = sdb_const_get (s, key, 0);
MI.size = sdb_array_get_num (s, key, 0, 0);
MI.type = *infos;
MI.subtype = 0;
MI.from = ds->at;
MI.to = ds->at + MI.size;
if (metas) {
p = strchr (metas, ',');
if (!p) {
continue;
}
MI.space = atoi (p + 1);
q = strchr (p + 1, ',');
if (!q) {
if (!r_meta_deserialize_val (mi, *infos, ds->at, metas)) {
continue;
}
if (MI.type == R_META_TYPE_STRING) {
r = strchr (q + 1, ',');
if (r) {
MI.subtype = *(q + 1);
q = r;
}
}
MI.str = (char*)sdb_decode (q + 1, 0);
} else {
MI.str = NULL;
}
// TODO: implement ranged meta find (if not at the begging of function..
char *out = NULL;
Expand Down
1 change: 1 addition & 0 deletions libr/include/r_anal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,7 @@ R_API int r_meta_list_at(RAnal *m, int type, int rad, ut64 addr);
R_API int r_meta_list_cb(RAnal *m, int type, int rad, SdbForeachCallback cb, void *user, ut64 addr);
R_API void r_meta_item_free(void *_item);
R_API RAnalMetaItem *r_meta_item_new(int type);
R_API bool r_meta_deserialize_val(RAnalMetaItem *it, int type, ut64 from, const char *v);
R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, int rad, bool show_full);

R_API int r_anal_fcn_xref_add (RAnal *anal, RAnalFunction *fcn, ut64 at, ut64 addr, int type);
Expand Down

0 comments on commit 4cfb06e

Please sign in to comment.