I want to write a script which imports an exe file, analyzes it, extracts some features and saves it using python.

The part which I am not able to understand is, how to import a file from the script itself. I do not want to use the askFile function and i do not want to use the headleassAnalyzer.

Are there any functions which let me do this from the script itself?

  • Why do you not want to use the headlessAnalyzer or askFile? The APIs to import a file are probably available to a script, but to me it seems like there is more to your requirements. Is the file you want to import already referenced or available when the script is run? How should the script know which file should be imported? Jun 21, 2020 at 6:33

1 Answer 1


In order to run a script in Ghidra you can run the following:

analyzeHeadless <project_location> <project_name> -import <path/to/file> -scriptPath <path/to/scripts> -preScript <preScript_name> <preScript_params> -postScript <postScript_name> <postScript_params>

analyzeHeadless is the Ghidra GUI-less executable script.

You can specify postScript, preScript, or both of them.

From the script itself, you can reference your program with currentProgram variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.