Using Angr to extract the CFG of functions from the binaries

100 Views Asked by At

I started using angr and I am trying to extract the CFG of functions from the binary of a simple program but I can't find the symbol of any of the functions defined in source files in the detected symbols from the binaries.

this is the source of the binaries that I am trying to extract the cfg of the functions defined in it.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int randomInt(int min, int max) {
    return min + rand() % (max - min + 1);
}

// Example random function
int randomFunction(int x) {
    return 2 * x + randomInt(-10, 10);
}

void do_something()
{
    printf("nn\n");
}

int main()
{
    do_something();
}

the extracted symbols by angr do not include any of the names of the functions I was interested to know why and this is the script I used to extract the cfg

import angr

# Specify the path to the binary and the name of the function to analyze
binary_path = "bin/functions.o"
function_name = "do_something"

# Load the binary into an angr project
project = angr.Project(binary_path, load_options={"auto_load_libs": False})

# Find the address of the specified function
symbol = project.loader.find_symbol(function_name)
if symbol is None:
    print(f"Error: could not find symbol {function_name}")
    exit(1)
function_addr = symbol.rebased_addr

# Create an angr CFG object for the function
cfg = project.analyses.CFGFast(function_addr, start_at=function_addr, keep_state=True)
0

There are 0 best solutions below