DEV Community

Yuil Tripathee
Yuil Tripathee

Posted on

Reverse engineering C code with Cflow - GNU project (to trace back calling)

Install the program in Linux (Ubuntu used for this test case) using the below command:

apt search cflow
sudo apt install cflow
Enter fullscreen mode Exit fullscreen mode

After this, go to the specific project folder. To run the analysis, you can run the following command.

cflow --verbose --tree main.c
Enter fullscreen mode Exit fullscreen mode

In this example, we can analyze main.c. Changing the file name allows us to check other files as well. The output is printed on ASCII tree format with quality details. Now, you can use this information to draw on the software design applications such as PlantUML or StarUML manually if you would like to have a graphical presentation of your reverse analyzed C code.

Here's the example printout:

+-main() <int main (int argc, char *argv[]) at main.c:26>
  +-printf()
  +-serial_open()
  +-WitInit()
  +-WitRegisterCallBack()
  +-SensorDataUpdata() <void SensorDataUpdata (uint32_t uiReg, uint32_t uiRegNum) at main.c:100>
  +-AutoScanSensor() <void AutoScanSensor (char *dev) at main.c:142>
  | +-serial_close()
  | +-serial_open()
  | +-WitReadReg()
  | +-Delayms() <void Delayms (uint16_t ucMs) at main.c:136>
  | | \-usleep()
  | +-serial_read_data()
  | +-WitSerialDataIn()
  | \-printf()
  +-serial_read_data()
  +-WitSerialDataIn()
  +-Delayms() <void Delayms (uint16_t ucMs) at main.c:136>
  | \-usleep()
  \-serial_close()
Enter fullscreen mode Exit fullscreen mode

The source is from Linux C SDK for Witmotion IMU sensor. Here's the link for documentation: https://support-73.gitbook.io/witmotion-sdk/wit-standard-protocol/

Top comments (0)