2015-09-14 09:31:54 +00:00
|
|
|
/* radare - LGPL - Copyright 2010-2015 - nibble, pancake */
|
2010-03-12 02:05:20 +00:00
|
|
|
|
|
|
|
#include <r_anal.h>
|
|
|
|
#include <r_util.h>
|
|
|
|
#include <r_list.h>
|
|
|
|
|
2014-09-21 23:39:24 +00:00
|
|
|
// This file contains the reversed api for querying xrefs.c which
|
|
|
|
// is implemented on top of sdb. Anyway, the sdbization is not
|
|
|
|
// complete because there's still r_anal_ref_new() which doesnt
|
|
|
|
// serializes with sdb_native
|
|
|
|
|
2010-09-28 11:58:03 +00:00
|
|
|
R_API RAnalRef *r_anal_ref_new() {
|
2016-02-09 17:38:55 +00:00
|
|
|
RAnalRef *ref = R_NEW0 (RAnalRef);
|
2010-06-13 22:57:40 +00:00
|
|
|
if (ref) {
|
|
|
|
ref->addr = -1;
|
2010-08-02 10:42:59 +00:00
|
|
|
ref->at = -1;
|
2010-09-28 11:58:03 +00:00
|
|
|
ref->type = R_ANAL_REF_TYPE_CODE;
|
2010-06-13 22:57:40 +00:00
|
|
|
}
|
2010-05-20 15:40:58 +00:00
|
|
|
return ref;
|
2010-03-12 02:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
R_API RList *r_anal_ref_list_new() {
|
|
|
|
RList *list = r_list_new ();
|
2015-06-20 11:38:11 +00:00
|
|
|
if (!list) return NULL;
|
2010-03-12 02:05:20 +00:00
|
|
|
list->free = &r_anal_ref_free;
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API void r_anal_ref_free(void *ref) {
|
|
|
|
free (ref);
|
|
|
|
}
|
2010-09-28 11:58:03 +00:00
|
|
|
|
|
|
|
R_API int r_anal_ref_add(RAnal *anal, ut64 addr, ut64 at, int type) {
|
2014-05-05 15:31:10 +00:00
|
|
|
r_anal_xrefs_set (anal, type, at, addr);
|
2015-09-14 09:31:54 +00:00
|
|
|
return true;
|
2010-09-28 11:58:03 +00:00
|
|
|
}
|
|
|
|
|
2017-12-15 00:12:54 +00:00
|
|
|
R_API const char *r_anal_ref_to_string(int type) {
|
2016-02-09 17:38:55 +00:00
|
|
|
switch (type) {
|
|
|
|
case R_ANAL_REF_TYPE_NULL: return "null";
|
|
|
|
case R_ANAL_REF_TYPE_CODE: return "code";
|
|
|
|
case R_ANAL_REF_TYPE_CALL: return "call";
|
|
|
|
case R_ANAL_REF_TYPE_DATA: return "data";
|
|
|
|
case R_ANAL_REF_TYPE_STRING: return "strg";
|
|
|
|
}
|
|
|
|
return "unk";
|
|
|
|
}
|
|
|
|
|
2015-07-08 18:43:02 +00:00
|
|
|
R_API int r_anal_ref_del(RAnal *anal, ut64 from, ut64 to) {
|
2017-12-11 17:00:14 +00:00
|
|
|
#if USE_MHT
|
|
|
|
// TODO Must delete from mht_refs too
|
|
|
|
mht *m = anal->mht_xrefs;
|
|
|
|
mhtkv *kv = mht_getr (m, from);
|
|
|
|
if (kv) {
|
|
|
|
mht *ht = kv->u;
|
|
|
|
if (ht) {
|
|
|
|
mht_del (ht, to);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2015-07-08 18:43:02 +00:00
|
|
|
r_anal_xrefs_deln (anal, R_ANAL_REF_TYPE_NULL, from, to);
|
|
|
|
r_anal_xrefs_deln (anal, R_ANAL_REF_TYPE_CODE, from, to);
|
|
|
|
r_anal_xrefs_deln (anal, R_ANAL_REF_TYPE_CALL, from, to);
|
|
|
|
r_anal_xrefs_deln (anal, R_ANAL_REF_TYPE_DATA, from, to);
|
|
|
|
r_anal_xrefs_deln (anal, R_ANAL_REF_TYPE_STRING, from, to);
|
2017-12-11 17:00:14 +00:00
|
|
|
#endif
|
2015-09-14 09:31:54 +00:00
|
|
|
return true;
|
2010-09-28 11:58:03 +00:00
|
|
|
}
|
2010-09-28 16:05:31 +00:00
|
|
|
|
|
|
|
R_API RList *r_anal_xref_get(RAnal *anal, ut64 addr) {
|
2013-07-19 01:35:45 +00:00
|
|
|
return r_anal_xrefs_get (anal, addr);
|
|
|
|
}
|