2

I'm working on reverse engineering a firmware which I was able to get its functions control flow graphs to display successfully on Ghidra. I am trying to see if there is a way to save those control flow graphs as a text file or something parse able so that I can write a parser for it and use it in my program (I want to recreate the graph programmatically to train my program to detect certain functions). Thank you!

1

You can do this using [headless analyser] (https://ghidra.re/ghidra_docs/analyzeHeadlessREADME.html#recursive) script.

Check out it's usage here. You can find this file in ghidhra/support directory.

The ghidra api is available here. You can use this api to write custom scripts, either in java or python 2.7.

Then you can do:

./analyzeHeadless /projectloacation projectname -import /binary_location -postscript /yourscript-location -deleteproject

To run your analysis. This command runs your script on binary by creating a new project and then deleting it later (-deleteproject flag, which is optional).

You can find a lot of examples in their github repository. e.g. script.

As you said in your question, if you want to work with functions, you can:

functions = currentProgram.getFunctionManager().getFunctions(True)

get the list of functions (in python, changed the syntax if you are using java).

  • If I may ask, how do you import the API into eclipse or a development environment of the sort? – Sparval Jul 18 at 17:58
  • I am not sure about eclipse, because I used python. My take on this is - read the api, write a code in java, and then use the above command to run the code. – R4444 Jul 18 at 19:00
  • 1
    here is an example "hello world" script that you can run - github.com/DiegoMagdaIeno/Ghidra-Launcher/blob/… – R4444 Jul 18 at 19:03
1

After a few days of trial and error I figured out something called GhidraDev which is an add-on to eclipse, through it you can create your own Ghidra projects and use the API with ease. Instructions on how to install it into eclipse can be found in ghidra_9.0.4 -> Extensions -> Eclipse -> GhidraDev -> GhidraDev_README.html.

Ghidra can be downloaded here: https://ghidra-sre.org/

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.