0

Update: I installed Eclipse and PyDev in Linux and my code works now. This confirms it was an issue setting up the Python/Jython paths. I would still like to know how to import ghidra.jar into jython so that I can use command line in the future. Any help here would be greatly appreciated.

I am making a ghidra project on Linux. I am using a Ghidra jar and jython to code my application. I am adding ghidra to my path with system.path.append() and I am running my program with jython main.py.

My code worked with Pydev in Eclipse on Windows, but on Linux I am getting java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: java.net.MalformedURLException: unknown protocol: ghidra when I reach ghidraProject.createProject(). I investigated the source and I found that the error occurs when Java tries to make a url from string. I know Ghidra has a protocol handler which should be handling the protocol "ghidra". I assume Java doesn't register the protocol handler somehow. I tried Handler.registerHandler() with no luck.

Why is "ghidra" an unknown protocol on Linux, but the same code works (save for the PyDev environment) in Eclipse/Windows?

Error printout: enter image description here

0

You are trying to use Ghidra without initializing it first, the Ghidra isn't really designed as a typical Java library which you could use like any other .jar. If you want to check out how the Ghidra provided pythonRun entry point handles a minimal jython REPL embedded inside Ghidra, check out: https://github.com/NationalSecurityAgency/ghidra/blob/da94eb86bd2b89c8b0ab9bd89e9f0dc5a3157055/Ghidra/Features/Python/src/main/java/ghidra/python/PythonRun.java

The crucial part here is:

ApplicationConfiguration configuration = new HeadlessGhidraApplicationConfiguration();
Application.initializeApplication(layout, configuration);

which runs through various initialization steps that the overall Ghidra code assumes to have happened when being executed, one of them being the setup for the ghidra:// protocol handler. Specifically the call to ghidra.framework.protocol.ghidra.Handler.registerHandler() happens inside ghidra.ProjectInitializer#run.

2
  • I initialized the application in my code: configuration = HeadlessGhidraApplicationConfiguration() configuration.setInitializeLogging(False) Application.initializeApplication(GhidraJarApplicationLayout(), configuration) I think the issue is that I'm not replicating how PyDev creates the Jython environment. – R-E Jun 3 at 14:20
  • I'd need more details on your project and how you are starting it then, especially if your Eclipse/PyDev install has the Ghidra Dev plugin installed – Florian Magin Jun 3 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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