diff --git a/libr/anal/xrefs.c b/libr/anal/xrefs.c index 0e94f86c32950..8b58ce817d35a 100644 --- a/libr/anal/xrefs.c +++ b/libr/anal/xrefs.c @@ -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); @@ -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); @@ -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); } @@ -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; @@ -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; @@ -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; - } -} diff --git a/libr/core/canal.c b/libr/core/canal.c index a24f10e381cc4..f724bdcfd0c3f 100644 --- a/libr/core/canal.c +++ b/libr/core/canal.c @@ -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; @@ -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); @@ -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) { @@ -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) { @@ -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) { @@ -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); diff --git a/libr/core/cmd_anal.inc.c b/libr/core/cmd_anal.inc.c index f4f5fb74b44ad..84c675d299497 100644 --- a/libr/core/cmd_anal.inc.c +++ b/libr/core/cmd_anal.inc.c @@ -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]) { diff --git a/libr/include/r_anal.h b/libr/include/r_anal.h index 9f8e4a544cc31..7e364e338fb7d 100644 --- a/libr/include/r_anal.h +++ b/libr/include/r_anal.h @@ -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);