Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions libr/anal/xrefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ R_API ut64 r_anal_xrefs_count_at(RAnal *anal, ut64 to) {
return ref_manager_count_xrefs_at (anal->rm, to);
}

#if 0
R_API RVecAnalRef *r_anal_function_get_xrefs(RAnalFunction *fcn) {
R_RETURN_VAL_IF_FAIL (fcn, NULL);

Expand All @@ -517,6 +518,7 @@ R_API RVecAnalRef *r_anal_function_get_xrefs(RAnalFunction *fcn) {
}
return anal_refs;
}
#endif

typedef RVecAnalRef *(*CollectFn)(RefManager *rm, ut64 addr);

Expand Down Expand Up @@ -545,13 +547,12 @@ static RVecAnalRef *fcn_get_all_refs(RAnalFunction *fcn, RefManager *rm, Collect
return anal_refs;
}

// XXX rename to r_anal_function_get_all_refs?
R_API RVecAnalRef *r_anal_function_get_refs(RAnalFunction *fcn) {
R_RETURN_VAL_IF_FAIL (fcn, NULL);
return fcn_get_all_refs (fcn, fcn->anal->rm, ref_manager_get_refs);
}

R_API RVecAnalRef *r_anal_function_get_all_xrefs(RAnalFunction *fcn) {
R_API RVecAnalRef *r_anal_function_get_xrefs(RAnalFunction *fcn) {
R_RETURN_VAL_IF_FAIL (fcn, NULL);
return fcn_get_all_refs (fcn, fcn->anal->rm, ref_manager_get_xrefs);
}
Expand Down Expand Up @@ -627,6 +628,7 @@ R_API const char *r_anal_ref_type_tostring(RAnalRefType type) {
}
}

#if 0
// UNUSED
R_API RAnalRefType r_anal_xrefs_type_from_string(const char *s) {
RAnalRefType rt = R_ANAL_REF_TYPE_NULL;
Expand Down Expand Up @@ -656,6 +658,7 @@ R_API RAnalRefType r_anal_xrefs_type_from_string(const char *s) {
}
return rt;
}
#endif

R_API int r_anal_ref_typemask(int x) {
const int maskedType = x & 0xff;
Expand All @@ -676,18 +679,3 @@ R_API int r_anal_ref_typemask(int x) {
// SHOULD NEVER HAPPEN MAYBE WARN HERE
return 0;
}

// TODO: deprecate
R_API RAnalRefType r_anal_xrefs_type(char ch) {
switch (ch) {
case R_ANAL_REF_TYPE_CODE:
case R_ANAL_REF_TYPE_CALL:
case R_ANAL_REF_TYPE_DATA:
case R_ANAL_REF_TYPE_STRN:
case R_ANAL_REF_TYPE_ICOD:
case R_ANAL_REF_TYPE_NULL:
return (RAnalRefType)ch;
default:
return R_ANAL_REF_TYPE_NULL;
}
}
54 changes: 33 additions & 21 deletions libr/core/canal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2731,29 +2731,36 @@ R_API ut64 r_core_anal_fcn_list_size(RCore *core) {
return total;
}

static int count_callrefs(RAnalFunction *fcn) {
// Count the number of references and number of calls
RAnalRef *ref;
// R2_590: wasteful, make count function that does not allocate
RVecAnalRef *refs = r_anal_function_get_refs (fcn);
int numcallrefs = 0;
if (refs) {
R_VEC_FOREACH (refs, ref) {
if (R_ANAL_REF_TYPE_MASK (ref->type) == R_ANAL_REF_TYPE_CALL) {
numcallrefs++;
}
}
}
RVecAnalRef_free (refs);
return numcallrefs;
}

/* Fill out metadata struct of functions */
static int fcnlist_gather_metadata(RAnal *anal, RList *fcns) {
RListIter *iter;
RAnalFunction *fcn;
r_list_foreach (fcns, iter, fcn) {
// Count the number of references and number of calls
RAnalRef *ref;
// R2_590: wasteful, make count function that does not allocate
RVecAnalRef *refs = r_anal_function_get_refs (fcn);
int numcallrefs = 0;
if (refs) {
R_VEC_FOREACH (refs, ref) {
if (R_ANAL_REF_TYPE_MASK (ref->type) == R_ANAL_REF_TYPE_CALL) {
numcallrefs++;
}
}
}
RVecAnalRef_free (refs);
fcn->meta.numcallrefs = numcallrefs;

fcn->meta.numcallrefs = count_callrefs (fcn);
RVecAnalRef *xrefs = r_anal_xrefs_get (anal, fcn->addr);
fcn->meta.numrefs = xrefs? RVecAnalRef_length (xrefs): 0;
RVecAnalRef_free (xrefs);
if (xrefs) {
fcn->meta.numrefs = RVecAnalRef_length (xrefs);
RVecAnalRef_free (xrefs);
} else {
fcn->meta.numrefs = 0;
}
}
// TODO: Determine sgnc, sgec
return 0;
Expand Down Expand Up @@ -3249,7 +3256,8 @@ static int fcn_print_json(RCore *core, RAnalFunction *fcn, bool dorefs, PJ *pj)
}
RVecAnalRef_free (xrefs);

xrefs = r_anal_function_get_all_xrefs (fcn);
#if 0
xrefs = r_anal_function_get_xrefs (fcn);
if (xrefs && !RVecAnalRef_empty (xrefs)) {
pj_k (pj, "allxrefs");
pj_a (pj);
Expand All @@ -3269,6 +3277,7 @@ static int fcn_print_json(RCore *core, RAnalFunction *fcn, bool dorefs, PJ *pj)
pj_end (pj);
}
RVecAnalRef_free (xrefs);
#endif
} else {
RVecAnalRef *refs = r_anal_function_get_refs (fcn);
if (refs) {
Expand Down Expand Up @@ -3513,8 +3522,8 @@ static int fcn_print_legacy(RCore *core, RAnalFunction *fcn, bool dorefs) {
}
}
RVecAnalRef_free (xrefs);

xrefs = r_anal_function_get_all_xrefs (fcn);
#if 0
xrefs = r_anal_function_get_xrefs (fcn);
r_cons_printf ("\nall-code-xrefs:");
if (xrefs && !RVecAnalRef_empty (xrefs)) {
R_VEC_FOREACH (xrefs, refi) {
Expand All @@ -3534,6 +3543,7 @@ static int fcn_print_legacy(RCore *core, RAnalFunction *fcn, bool dorefs) {
}
}
RVecAnalRef_free (xrefs);
#endif
} else {
RVecAnalRef *xrefs = r_anal_function_get_xrefs (fcn);
if (xrefs) {
Expand Down Expand Up @@ -3660,9 +3670,11 @@ static int fcn_list_table(RCore *core, const char *q, int fmt) {
snprintf (xref, sizeof (xref), "%"PFMT64u, xrefs ? RVecAnalRef_length (xrefs) : 0);
RVecAnalRef_free (xrefs);

xrefs = r_anal_function_get_all_xrefs (fcn);
#if 0
xrefs = r_anal_function_get_xrefs (fcn);
snprintf (axref, sizeof (axref), "%"PFMT64u, xrefs ? RVecAnalRef_length (xrefs) : 0);
RVecAnalRef_free (xrefs);
#endif
RVecAnalRef *calls = r_core_anal_fcn_get_calls (core, fcn);
if (calls) {
RVecAnalRef_sort (calls, RAnalRef_compare_by_addr);
Expand Down
14 changes: 14 additions & 0 deletions libr/core/cmd_anal.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10524,6 +10524,20 @@ static void axfm(RCore *core) {
RVecAnalRef_free (refs);
}

static RAnalRefType r_anal_xrefs_type(char ch) {
switch (ch) {
case R_ANAL_REF_TYPE_CODE:
case R_ANAL_REF_TYPE_CALL:
case R_ANAL_REF_TYPE_DATA:
case R_ANAL_REF_TYPE_STRN:
case R_ANAL_REF_TYPE_ICOD:
case R_ANAL_REF_TYPE_NULL:
return (RAnalRefType)ch;
default:
return R_ANAL_REF_TYPE_NULL;
}
}

static bool cmd_anal_refs(RCore *core, const char *input) {
ut64 addr = core->offset;
switch (input[0]) {
Expand Down
1 change: 0 additions & 1 deletion libr/include/r_anal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,6 @@ R_API RList *r_anal_ref_list_new(void);
R_API const char *r_anal_ref_type_tostring(RAnalRefType t);
R_API int r_anal_ref_size(RAnalRef *ref);
R_API int r_anal_ref_typemask(int x);
R_DEPRECATE R_API RAnalRefType r_anal_xrefs_type(char ch);

R_API const char *r_anal_ref_perm_tostring(RAnalRef *ref);
R_API char r_anal_ref_perm_tochar(RAnalRef *ref);
Expand Down
Loading