Exemple #1
0
R_API RAnalVar *r_anal_var_get (RAnal *a, ut64 addr, char kind, int scope, int delta) {
	RAnalVar *av;
	struct VarType vt;
	RAnalFunction *fcn = r_anal_get_fcn_in (a, addr, 0);
	if (!fcn)
		return NULL;
	if (delta<0) {
		kind = 'v';
		delta = -delta;
	}
	char *vardef = sdb_get (DB,
		sdb_fmt (0, "var.0x%"PFMT64x".%c.%d.%d",
			fcn->addr, kind, scope, delta), 0);
	if (!vardef)
		return NULL;
	sdb_fmt_tobin (vardef, SDB_VARTYPE_FMT, &vt);

	av = R_NEW0 (RAnalVar);
	av->addr = addr;
	av->scope = scope;
	av->delta = delta;
	av->name = strdup (vt.name);
	av->size = vt.size;
	av->type = strdup (vt.type);

	sdb_fmt_free (&vt, SDB_VARTYPE_FMT);
	// TODO:
	// get name from sdb
	// get size from sdb
	// get type from sdb
	return av;
}
Exemple #2
0
static RAnalVar *get_used_var(RAnal *anal, RAnalOp *op) {
	char *inst_key = sdb_fmt (0, "inst.0x%"PFMT64x".vars", op->addr);
	const char *var_def = sdb_const_get (anal->sdb_fcns, inst_key, 0);
	struct VarUsedType vut;
	RAnalVar *res;

	if (sdb_fmt_tobin (var_def, SDB_VARUSED_FMT, &vut) != 4) {
		return NULL;
	}
	res = r_anal_var_get (anal, vut.fcn_addr, vut.type[0], vut.scope, vut.delta);
	sdb_fmt_free (&vut, SDB_VARUSED_FMT);
	return res;
}
Exemple #3
0
R_API RAnalVar *get_link_var(RAnal *anal, ut64 faddr, RAnalVar *var) {
	const char *var_local = sdb_fmt ("var.0x%"PFMT64x".%d.%d.%s",
			faddr, 1, var->delta, "reads");
	const char *xss = sdb_const_get (anal->sdb_fcns, var_local, 0);
	ut64 addr = r_num_math (NULL, xss);
	char *inst_key = r_str_newf ("inst.0x%"PFMT64x".lvar", addr);
	char *var_def = sdb_get (anal->sdb_fcns, inst_key, 0);

	if (!var_def) {
		free (inst_key);
		return NULL;
	}
	struct VarUsedType vut;
	RAnalVar *res = NULL;
	if (sdb_fmt_tobin (var_def, SDB_VARUSED_FMT, &vut) == 4) {
		res = r_anal_var_get (anal, vut.fcn_addr, vut.type[0], vut.scope, vut.delta);
		sdb_fmt_free (&vut, SDB_VARUSED_FMT);
	}
	free (inst_key);
	free (var_def);
	return res;
}
Exemple #4
0
R_API int r_anal_fcn_labels (RAnal *anal, RAnalFunction *fcn, int rad) {
	if (!anal || !fcn)
		return 0;
	
	if (fcn) {
		char *cur, *token;
		char *str = sdb_get (DB, LABELS, 0);
		sdb_aforeach (cur, str) {
			struct {
				ut64 addr;
				char *name;
			} loc;
			token = strchr (cur, '/');
			if (!token)
				break;
			*token = ',';
			sdb_fmt_tobin (cur, "qz", &loc);
			switch (rad) {
			case '*':
			case 1:
				anal->printf ("f.%s@0x%08"PFMT64x"\n",
					loc.name, loc.addr);
				break;
			case 'j':
				eprintf ("TODO\n");
				break;
			default:
				anal->printf ("0x%08"PFMT64x" %s   [%s + %"PFMT64d"]\n",
					loc.addr,
					loc.name, fcn->name,
					loc.addr - fcn->addr, loc.addr);
			}
			*token = '/';
			sdb_fmt_free (&loc, "qz");
			sdb_aforeach_next (cur);
		}
		free (str);
	} else {