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!
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
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).
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).
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/