I'm interested in open a binary file (.bin
, without arch info), and analyze it with analyzeHeadless.bat
(Ghidra version without GUI).
I know what is the architecture of the file, so I pass it as a flag to the analyzer.
My command line is:
analyzeHeadless.bat <project_location> <project_name> -import <my_file> -processor <my_known_processor> -postscript <my_script.py> -scriptPath <path>
my_script.py is:
for block in getMemoryBlocks():
current = block.getStart().getOffset()
end = block.getEnd().getOffset()
addr = currentProgram.getAddressFactory().getAddress(hex(current).replace('L', ''))
disassemble(addr)
current +=1
func = getFirstFunction()
print("First func is: " + str(func))
I try to disassemble every address (looks like Ghigra doesn't do it itself), and after that I want to print the first function.
The problem is:
func
appears to be None
.
But if after the headless execution I open the project in the GUI Ghidra
, and execute:
func = getFirstFunction()
print("First func is: " + str(func))
It works and gets me the function.
Any ideas what am I doing wrong? I guess there is some analysis that runs in the background and created the functions. How can I run it in my python script?