Skip to content

Commit

Permalink
Fix missing entries in the afla matching with aflq ##analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
trufae committed Jun 19, 2024
1 parent 2bd3d75 commit 08eccc5
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 58 deletions.
27 changes: 24 additions & 3 deletions libr/core/cmd_anal.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -4912,8 +4913,13 @@ 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);
ht_up_insert (ht, v, va0);
// RVecAddr *va = ht_up_find (ht, k, NULL);
continue;
}
R_VEC_FOREACH (xrefs, xref) {
Expand Down Expand Up @@ -4943,6 +4949,7 @@ static void cmd_afla(RCore *core, const char *input) {
ReverseCallData rcd = {
.core = core,
.togo = RVecAddr_new (),
.list = RVecAddr_new (),
.inloop = true
};
do {
Expand All @@ -4955,6 +4962,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) {
Expand Down
1 change: 1 addition & 0 deletions test/db/anal/avr
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ EXPECT=<<EOF
0x00001bde 46 fcn.00001bde
0x00001c4e 48 fcn.00001c4e
0x00001c84 44 fcn.00001c84
0x00001dfe 30 fcn.00001dfe
0x00001e78 88 fcn.00001e78
0x00001efe 38 fcn.00001efe
0x00001f24 14 fcn.00001f24
Expand Down
1 change: 1 addition & 0 deletions test/db/anal/x86_32
Original file line number Diff line number Diff line change
Expand Up @@ -3577,6 +3577,7 @@ EXPECT=<<EOF
| 0x08048056 xor eax, eax
| 0x08048058 inc eax
| ;-- syscall.exit:
| ;-- syscall.exit.0:
\ 0x08048059 int 0x80
EOF
RUN
Expand Down
86 changes: 31 additions & 55 deletions test/db/cmd/cmd_afl
Original file line number Diff line number Diff line change
Expand Up @@ -104,67 +104,43 @@ CMDS=<<EOF
aa
afla
EOF
EXPECT_ERR=<<EOF
WARN: Relocs has not been applied. Please use `-e bin.relocs.apply=true` or `-e bin.cache=true` next time
INFO: Analyze all flags starting with sym. and entry0 (aa)
INFO: Analyze imports (af@@@i)
INFO: Analyze entrypoint (af@ entry0)
INFO: Analyze symbols (af@@@s)
INFO: Recovering variables (afva@@@F)
INFO: Analyze all functions arguments/locals (afva@@@F)
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
WARN: Leaving an infinite loop before it's too late
EOF
EXPECT=<<EOF
0x000029b0
0x000029e0
0x00002a10
0x00002a80
0x00002af0
0x000029f0
0x0000201c
0x00002a60
0x00001cf0
0x00002ad0
0x00001e64
0x00002a40
0x00002ab0
0x000029b0
0x00002a20
0x00002a90
0x00002b00
0x00002a00
0x00002a70
0x00002ae0
0x00002aa0
0x00002ad0
0x00002b00
0x000029f0
0x00002a20
0x000022c8
0x000029e0
0x00002a50
0x00002ac0
0x00002a30
0x00002aa0
0x00001d54
0x00002a80
0x00002ab0
0x00001e64
0x00002ae0
0x00002b10
0x00001cf0
0x00001d54
0x00002a00
0x00002a30
0x00002a60
0x00002a90
0x00002ac0
0x00002af0
0x0000201c
0x00001c6c
0x00001f64
0x000029c0
0x000029d0
0x00001c58
0x00001cb0
0x00001cc4
0x00001ce0
0x0000286c
0x00002114
0x000022cc
EOF
RUN

0 comments on commit 08eccc5

Please sign in to comment.