3

I am trying to understand the difference between analyze functions and analyze functions recursively in Radare2. Given a code snippet like this:

#include <stdio.h>

void b() {
    printf("b is called\n");
}

void a() {
   printf("a is called\n");
   b();
}


int main() {
    a();
    return 0;
}

When I run afr on the main function, it finds the following functions:

0x0000066a    1 21           main
0x0000064d    1 29           sym.a
0x00000510    1 6            sym.imp.puts
0x0000063a    1 19           sym.b

However, when I run af on the main function, it again finds the same functions:

0x0000066a    1 21           main
0x0000064d    1 29           sym.a
0x00000510    1 6            sym.imp.puts
0x0000063a    1 19           sym.b

I have not changed the default value of anal.calls which is set to false

So, my question is what extra is afr finding that af isn't?

I am using Radare2 version 5.1.1

2

af and afr are different. Check radare's code base for deep understanding - https://github.com/radareorg/radare2/blob/8d678888a97d9aed4049d1a7467132c41ad6ffa7/libr/core/cmd_anal.c.

enter image description here

enter image description here

Now, consider following example to understand how they differ.

#include <stdio.h>

int one()
{
return 1;
}

int fact(int n) {
   if (n==0)
      return 1;
   else if (n==1)
      return one();
   else
      return n*fact(n-1);
}

int main(void) {
      return fact(5);
}

I just used this factorial code and modified it a little. And following is the radare2 output.

$ radare2 a.out
 -- This page intentionally left blank.
[0x00401020]> afl
[0x00401020]> s main
[0x0040114e]> afl
[0x0040114e]> af main
[0x0040114e]> afl
0x0040114e    1 16           main
0x00401111    6 61           sym.fact
[0x0040114e]> afr main
[0x0040114e]> afl
0x0040114e    1 16           main
0x00401111    6 61           sym.fact
0x00401106    1 11           sym.one

Note the detection of additional function when recursive analysis is used.

2
  • I am still now sure why my code isn't able to produce different results. Mar 27 at 5:34
  • 2
    R is for recursive your function is not recursive a recursive function is function that calls itself until it is stopped by an external condition. Like in the answer above fact (n) calls itself until n is 1 so if n is 10 fact will be calked 9 times like main fact10,9,8,7,6,5,4,3,2,1 return to main
    – blabb
    Mar 27 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.