Refactor xrefs.c to use pj api (#13085)

This commit is contained in:
Deepak Chethan 2019-02-14 06:13:42 +05:30 committed by radare
parent 0349e65ec4
commit 7a79fcb2fd

View File

@ -197,10 +197,15 @@ R_API void r_anal_xrefs_list(RAnal *anal, int rad) {
bool is_first = true;
RListIter *iter;
RAnalRef *ref;
PJ *pj = NULL;
RList *list = r_anal_ref_list_new();
listxrefs (anal->dict_refs, UT64_MAX, list);
if (rad == 'j') {
anal->cb_printf ("[");
pj = pj_new ();
if (!pj) {
return;
}
pj_a (pj);
}
r_list_foreach (list, iter, ref) {
int t = ref->type ? ref->type: ' ';
@ -234,27 +239,23 @@ R_API void r_anal_xrefs_list(RAnal *anal, int rad) {
break;
case 'j':
{
if (is_first) {
is_first = false;
} else {
anal->cb_printf (",");
}
anal->cb_printf ("{");
pj_o (pj);
char *name = anal->coreb.getNameDelta (anal->coreb.core, ref->at);
if (name) {
r_str_replace_ch (name, ' ', 0, true);
anal->cb_printf ("\"name\":\"%s\",", name);
pj_ks (pj, "name", name);
free (name);
}
anal->cb_printf ("\"from\":%"PFMT64u",\"type\":\"%s\",\"addr\":%"PFMT64u,
ref->at, r_anal_xrefs_type_tostring (t), ref->addr);
pj_kn (pj, "from", ref->at);
pj_ks (pj, "type", r_anal_xrefs_type_tostring (t));
pj_kn (pj, "addr", ref->addr);
name = anal->coreb.getNameDelta (anal->coreb.core, ref->addr);
if (name) {
r_str_replace_ch (name, ' ', 0, true);
anal->cb_printf (",\"refname\":\"%s\"", name);
pj_ks (pj, "refname", name);
free (name);
}
anal->cb_printf ("}");
pj_end (pj);
}
break;
default:
@ -262,7 +263,9 @@ R_API void r_anal_xrefs_list(RAnal *anal, int rad) {
}
}
if (rad == 'j') {
anal->cb_printf ("]\n");
pj_end (pj);
anal->cb_printf ("%s", pj_string (pj));
pj_free (pj);
}
r_list_free (list);
}