From 099f57419519c36fd9eb82b8d4e47155f5fd12b8 Mon Sep 17 00:00:00 2001 From: pancake Date: Wed, 19 Jun 2024 17:45:20 +0200 Subject: [PATCH] Fix missing entries in the afla matching with aflq ##analysis --- libr/core/cmd_anal.inc.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/libr/core/cmd_anal.inc.c b/libr/core/cmd_anal.inc.c index 0e459eee0ee4da..bdc16e2ca261e9 100644 --- a/libr/core/cmd_anal.inc.c +++ b/libr/core/cmd_anal.inc.c @@ -4873,6 +4873,7 @@ static bool afla_leafs(void *user, const ut64 addr, const void *data) { RVecAddr *va = (RVecAddr *)data; if (RVecAddr_empty (va)) { r_cons_printf ("0x%08"PFMT64x"\n", addr); + RVecAddr_push_back (rcd->list, &addr); RVecAddr_push_back (rcd->togo, &addr); } return true; @@ -4898,7 +4899,7 @@ static bool afla_purge(void *user, const ut64 key, const void *val) { index++; } if (!hasdone) { - R_LOG_WARN ("Leaving an infinite loop before it's too late"); + R_LOG_DEBUG ("Leaving an infinite loop before it's too late"); rcd->inloop = false; } return true; @@ -4912,8 +4913,14 @@ static void cmd_afla(RCore *core, const char *input) { RVecAddr *unrefed = RVecAddr_new (); r_list_foreach (core->anal->fcns, iter, fcn) { RVecAnalRef *xrefs = r_anal_xrefs_get (core->anal, fcn->addr); - if (!xrefs) { - RVecAddr_push_back (unrefed, &fcn->addr); + if (!xrefs || RVecAnalRef_length (xrefs) == 0) { + const ut64 v = fcn->addr; + RVecAddr_push_back (unrefed, &v); + RVecAddr *va0 = RVecAddr_new (); + RVecAddr_push_back (va0, &v); + eprintf ("ADD UNREFED FUNC %s\n", fcn->name); + ht_up_insert (ht, v, va0); + // RVecAddr *va = ht_up_find (ht, k, NULL); continue; } R_VEC_FOREACH (xrefs, xref) { @@ -4943,6 +4950,7 @@ static void cmd_afla(RCore *core, const char *input) { ReverseCallData rcd = { .core = core, .togo = RVecAddr_new (), + .list = RVecAddr_new (), .inloop = true }; do { @@ -4955,6 +4963,20 @@ static void cmd_afla(RCore *core, const char *input) { RVecAddr_free (rcd.togo); rcd.togo = RVecAddr_new (); } while (rcd.inloop); + + // add missing entries here + r_list_foreach (core->anal->fcns, iter, fcn) { + bool found = false; + R_VEC_FOREACH (rcd.list, v) { + if (*v == fcn->addr) { + found = true; + break; + } + } + if (!found) { + r_cons_printf ("0x%08"PFMT64x"\n", fcn->addr); + } + } } static int cmd_af(RCore *core, const char *input) {