// afvn local_48 counter R_API int r_anal_var_rename (RAnal *a, ut64 var_addr, int scope, char kind, const char *old_name, const char *new_name) { char key[128]; char *stored_name; int delta; if (!r_anal_var_check_name (new_name)) return 0; if (scope>0) { // local SETKEY ("var.0x%"PFMT64x".%c.%d.%s", var_addr, kind, scope, old_name); delta = sdb_num_get (DB, key, 0); if (!delta) return 0; sdb_unset (DB, key, 0); SETKEY ("var.0x%"PFMT64x".%c.%d.%s", var_addr, kind, scope, new_name); sdb_num_set (DB, key, delta, 0); SETKEY ("var.0x%"PFMT64x".%c.%d.%d", var_addr, kind, scope, delta); sdb_array_set (DB, key, R_ANAL_VAR_SDB_NAME, new_name, 0); } else { // global SETKEY ("var.0x%"PFMT64x, var_addr); stored_name = sdb_array_get (DB, key, R_ANAL_VAR_SDB_NAME, 0); if (!stored_name) return 0; if (stored_name != old_name) return 0; sdb_unset (DB, key, 0); SETKEY ("var.0x%"PFMT64x, var_addr); sdb_array_set (DB, key, R_ANAL_VAR_SDB_NAME, new_name, 0); } // var.sdb_hash(old_name)=var_addr.scope.delta return 1; }
R_API int r_anal_var_add (RAnal *a, ut64 addr, int scope, int delta, char kind, const char *type, int size, const char *name) { char key[128], key2[128], val[128]; if (!kind) kind ='v'; switch (kind) { case 'a': case 'r': case 'v': break; default: eprintf ("Invalid var kind '%c'\n", kind); return R_FALSE; } if (scope>0) { // local SETKEY("fcn.0x%"PFMT64x".%c", addr, kind); SETVAL("var.0x%"PFMT64x".%c.%d.%d", addr, kind, scope, delta); sdb_array_add (DB, key, val, 0); strcpy (key, val); SETVAL("%s,%d,%s", type, size, name); sdb_set (DB, key, val, 0); #if 0 fcn.0x80480.a=1.8,1.16 fcn.0x80480.a.1.8=type,size,name fcn.0x80480.a.1.16=type,size,name #endif SETKEY("var.0x%"PFMT64x".%d.%d", addr, scope, delta); // TODO: link to function // fcn.<addr>.kind+=var.0x%"PFMT64x".. } else { // global snprintf (key, sizeof(key), "var.0x%"PFMT64x, addr); } sdb_array_add (DB, key, val, 0); return R_TRUE; }
R_API void r_anal_var_access_clear (RAnal *a, ut64 var_addr, int scope, int delta) { char key[128], key2[128]; if (scope>0) { // local arg or var SETKEY ("var.0x%"PFMT64x".%d.%d.%s", var_addr, scope, delta, "writes"); SETKEY2 ("var.0x%"PFMT64x".%d.%d.%s", var_addr, scope, delta, "reads"); } else { // global SETKEY ("var.0x%"PFMT64x".%s", var_addr, "writes"); SETKEY2 ("var.0x%"PFMT64x".%s", var_addr, "reads"); } sdb_unset (DB, key, 0); sdb_unset (DB, key2, 0); }
// avr 1,4 counter @ var_addr R_API int r_anal_var_rename (RAnal *a, ut64 var_addr, int scope, int delta, const char *new_name) { ut32 hash; char key[128], *old_name; if (!r_anal_var_check_name (new_name)) return 0; if (scope>0) { // local SETKEY ("var.0x%"PFMT64x".%d.%d", var_addr, scope, delta); old_name = sdb_array_get (DB, key, R_ANAL_VAR_SDB_NAME, 0); if (!old_name) return 0; SETKEY ("var.%s.%d", old_name, scope); sdb_unset (DB, key, 0); free (old_name); SETKEY ("var.%s.%d", new_name, scope); sdb_num_set (DB, key, var_addr, 0); SETKEY ("var.0x%x.%d.%d", hash, scope, delta); sdb_array_set (DB, key, R_ANAL_VAR_SDB_NAME, new_name, 0); } else { // global SETKEY ("var.0x%"PFMT64x, var_addr); old_name = sdb_array_get (DB, key, R_ANAL_VAR_SDB_NAME, 0); if (!old_name) return 0; SETKEY ("var.%s", old_name); sdb_unset (DB, key, 0); free (old_name); SETKEY ("var.%s.%d", new_name, scope); sdb_num_set (DB, key, var_addr, 0); SETKEY ("var.0x%x.%d.%d", hash, scope, delta); sdb_array_set (DB, key, R_ANAL_VAR_SDB_NAME, new_name, 0); } // var.sdb_hash(old_name)=var_addr.scope.delta return 1; }
// avr R_API int r_anal_var_access (RAnal *a, ut64 var_addr, char kind, int scope, int delta, int xs_type, ut64 xs_addr) { const char *xs_type_str = xs_type? "writes": "reads"; char key[128]; // TODO: kind is not used if (scope>0) { // local SETKEY ("var.0x%"PFMT64x, var_addr); //sdb_add (DB, key, var, 0); SETKEY ("var.0x%"PFMT64x".%d.%d.%s", var_addr, scope, delta, xs_type_str); } else { // global SETKEY ("var.0x%"PFMT64x, var_addr); sdb_add (DB, key, "a,", 0); SETKEY ("var.0x%"PFMT64x".%s", var_addr, xs_type_str); } return sdb_array_add_num (DB, key, xs_addr, 0); }