Ghidra 9.2 bug in "-scriptPath" option of analyzeHeadless
jimmy-sonny opened this issue · 3 comments
I've noticed a strange behaviour in the "-scriptPath" option of Ghidra analyzeHeadless.
Up to Ghidra 9.1.2, analyzeHeadless runs a custom Python script either if it is in the local folder or in the path specified in "-scriptPath".
However, in Ghidra 9.2 analyzeHeadless runs a custom Python script only if it is in the local folder, regardless the path specified in "-scriptPath".
How to reproduce the bug:
- Tested on Ubuntu 19.10
- Create a simple
HelloWorld.py
script in the~/Desktop/tmp_ghidra/
folder. - Run the following commands from the
Desktop
folder.
It works as expected in version 9.1.2
~/Desktop/ghidra_9.1.2/support/analyzeHeadless ~/Desktop/tmp_ghidra/ Project1 -scriptPath ~/Desktop/tmp_ghidra/ -postScript HelloWorld.py
It does not work. BUG in version 9.2
~/Desktop/ghidra_9.2/support/analyzeHeadless ~/Desktop/tmp_ghidra/ Project1 -scriptPath ~/Desktop/tmp_ghidra/ -postScript HelloWorld.py
...
INFO HEADLESS Script Paths:
/home/osboxes/Desktop/ghidra_9.2/Ghidra/Features/Base/ghidra_scripts
/home/osboxes/Desktop/ghidra_9.2/Ghidra/Features/Decompiler/ghidra_scripts
/home/osboxes/Desktop/ghidra_9.2/Ghidra/Processors/8051/ghidra_scripts
/home/osboxes/Desktop/tmp_ghidra
/home/osboxes/Desktop/ghidra_9.2/Ghidra/Processors/PIC/ghidra_scripts
/home/osboxes/Desktop/ghidra_9.2/Ghidra/Features/FunctionID/ghidra_scripts
/home/osboxes/Desktop/ghidra_9.2/Ghidra/Features/GnuDemangler/ghidra_scripts
/home/osboxes/Desktop/ghidra_9.2/Ghidra/Features/FileFormats/ghidra_scripts
/home/osboxes/Desktop/ghidra_9.2/Ghidra/Features/VersionTracking/ghidra_scripts
/home/osboxes/Desktop/ghidra_9.2/Ghidra/Features/BytePatterns/ghidra_scripts
/home/osboxes/ghidra_scripts
/home/osboxes/Desktop/ghidra_9.2/Ghidra/Features/Python/ghidra_scripts
/home/osboxes/Desktop/ghidra_9.2/Ghidra/Processors/DATA/ghidra_scripts (HeadlessAnalyzer)
ERROR REPORT SCRIPT ERROR: HelloWorld.py : Script not found: HelloWorld.py (HeadlessAnalyzer)
ERROR Abort due to Headless analyzer error: Invalid script: HelloWorld.py (HeadlessAnalyzer) java.lang.IllegalArgumentException: Invalid script: HelloWorld.py
at ghidra.app.util.headless.HeadlessAnalyzer.checkScript(HeadlessAnalyzer.java:770)
at ghidra.app.util.headless.HeadlessAnalyzer.checkScriptsList(HeadlessAnalyzer.java:783)
at ghidra.app.util.headless.HeadlessAnalyzer.compileScripts(HeadlessAnalyzer.java:817)
at ghidra.app.util.headless.HeadlessAnalyzer.processLocal(HeadlessAnalyzer.java:406)
at ghidra.app.util.headless.AnalyzeHeadless.launch(AnalyzeHeadless.java:121)
at ghidra.GhidraLauncher.main(GhidraLauncher.java:82)
Further tests
Running the commands from ~/Desktop/tmp_ghidra
They work, as expected:
~/Desktop/ghidra_9.2/support/analyzeHeadless ~/Desktop/tmp_ghidra/ Project1 -scriptPath ~/Desktop/tmp_ghidra/ -postScript HelloWorld.py
~/Desktop/ghidra_9.1.2/support/analyzeHeadless ~/Desktop/tmp_ghidra/ Project1 -scriptPath ~/Desktop/tmp_ghidra/ -postScript HelloWorld.py
They work, but the HelloWorld.py
is not in the ~/Desktop/
folder:
~/Desktop/ghidra_9.2/support/analyzeHeadless ~/Desktop/tmp_ghidra/ Project1 -scriptPath ~/Desktop/ -postScript HelloWorld.py
~/Desktop/ghidra_9.1.2/support/analyzeHeadless ~/Desktop/tmp_ghidra/ Project1 -scriptPath ~/Desktop/ -postScript HelloWorld.py
Running the commands from ~/Desktop/
They do not work, as expected.
~/Desktop/ghidra_9.2/support/analyzeHeadless ~/Desktop/tmp_ghidra/ Project1 -scriptPath ~/Desktop/ -postScript HelloWorld.py
~/Desktop/ghidra_9.1.2/support/analyzeHeadless ~/Desktop/tmp_ghidra/ Project1 -scriptPath ~/Desktop/ -postScript HelloWorld.py
I've the same problem :( .
I'm sorry -- I never know how much detail to give about progress for tickets. A fix is in the pipeline.
The bug is due to GhidraScriptUtil#fixupName assuming all scripts are Java. A hack to fix this problem would return name
if it ends with .py
.