Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ghidra 9.2 bug in "-scriptPath" option of analyzeHeadless #2561

Closed
jimmy-sonny opened this issue Dec 16, 2020 · 4 comments
Closed

Ghidra 9.2 bug in "-scriptPath" option of analyzeHeadless #2561

jimmy-sonny opened this issue Dec 16, 2020 · 4 comments
Assignees
Labels
Feature: Python/API Type: Bug Something isn't working
Milestone

Comments

@jimmy-sonny
Copy link

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
@meowmeowxw
Copy link

meowmeowxw commented Dec 18, 2020

I've the same problem :( .

@jpleasu
Copy link
Contributor

jpleasu commented Dec 18, 2020

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.

meowmeowxw added a commit to cesena/ghidra2dwarf that referenced this issue Jan 7, 2021
9.2 Should work but it's not tested because of this: NationalSecurityAgency/ghidra#2561
@jpleasu
Copy link
Contributor

jpleasu commented Jan 14, 2021

despite the typo in the commit message (doh), THIS issue is fixed by e4e15cd

@lxyeternal
Copy link

I have a project with the following structure:

project_root/
│
├── backend/
│   └── app.py
│
└── preprocess/
    ├── ghidra_analysis.py
    └── ghidra_call_graph.py
  • app.py calls ghidra_analysis.py to analyze a given binary file.
  • ghidra_analysis.py is responsible for invoking Ghidra and uses ghidra_call_graph.py as a Ghidra script to perform the actual analysis.

Problem:
When app.py calls ghidra_analysis.py, it triggers the following error:

ERROR REPORT SCRIPT ERROR: ghidra_call_graph.py : Script not found: ghidra_call_graph.py (HeadlessAnalyzer)
ERROR Abort due to Headless analyzer error: Invalid script: ghidra_call_graph.py (HeadlessAnalyzer) java.lang.IllegalArgumentException: Invalid script: ghidra_call_graph.py

However, if I move all three files (app.py, ghidra_analysis.py, and ghidra_call_graph.py) into the same directory, the issue does not occur, and everything works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: Python/API Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants