static void unsetHint(RAnal *a, const char *type, ut64 addr) { int idx; char key[128]; setf (key, "hint.0x%08"PFMT64x, addr); idx = sdb_array_indexof (DB, key, type, 0); if (idx != -1) { sdb_array_delete (DB, key, idx, 0); sdb_array_delete (DB, key, idx, 0); } }
// previously named del_str... pair with _add SDB_API int sdb_array_remove(Sdb *s, const char *key, const char *val, ut32 cas) { const char *str = sdb_const_get (s, key, 0); const char *n, *p = str; int idx; if (p) for (idx=0; ; idx++) { if (!astrcmp (p, val)) return sdb_array_delete (s, key, idx, cas); n = strchr (p, SDB_RS); if (!n) break; p = n+1; } return 0; }
SDB_API int sdb_array_remove_num(Sdb *s, const char *key, ut64 val, ut32 cas) { const char *n, *p, *str = sdb_const_get (s, key, 0); int idx = 0; ut64 num; if (!str) return 0; for (p=str; ; idx++) { num = sdb_atoi (p); if (num == val) return sdb_array_delete (s, key, idx, cas); n = strchr (p, SDB_RS); if (!n) break; p = n+1; } return 0; }
static int meta_add(RAnal *a, int type, int subtype, ut64 from, ut64 to, const char *str) { int space_idx = a->meta_spaces.space_idx; char *e_str, key[100], val[2048]; int exists; if (from > to) { return false; } if (from == to) { to = from + 1; } if (type == 100 && (to - from) < 1) { return false; } /* set entry */ e_str = sdb_encode ((const void*)str, -1); RAnalMetaItem mi = {from, to, (int)(to - from), type, subtype, e_str, space_idx}; meta_serialize (&mi, key, sizeof (key), val, sizeof (val)); exists = sdb_exists (DB, key); sdb_set (DB, key, val, 0); free (e_str); // XXX: This is totally inefficient, using array_add withuot // checking return value is wrong practice, also it may lead // to inconsistent DB, and pretty bad performance. We should // store this list in a different storage that doesnt have // those limits and it's O(1) instead of O(n) snprintf (key, sizeof (key) - 1, "meta.0x%"PFMT64x, from); if (exists) { const char *value = sdb_const_get (DB, key, 0); int idx = sdb_array_indexof (DB, key, value, 0); sdb_array_delete (DB, key, idx, 0); } snprintf (val, sizeof (val)-1, "%c", type); sdb_array_add (DB, key, val, 0); meta_inrange_add (a, from, to - from); return true; }