Exemple #1
0
// 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;
}
Exemple #2
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;
}