ghidra: NoClassDefFoundError when compiling GhidraScript

Describe the bug NoClassDefFoundError occurs when attempting to run a GhidraScript

To Reproduce Steps to reproduce the behavior:

  1. Attempt to run any GhidraScript

Attachments

stack trace
ERROR Task Error: compiling script directory - Uncaught Exception: java.lang.NoClassDefFoundError: Could not initialize class aQute.bnd.osgi.Analyzer  (Task.java:133)
java.lang.NoClassDefFoundError: Could not initialize class aQute.bnd.osgi.Analyzer
	at ghidra.app.plugin.core.osgi.GhidraSourceBundle.generateManifest(GhidraSourceBundle.java:824) ~[Base.jar:?]
	at ghidra.app.plugin.core.osgi.GhidraSourceBundle.compileToExplodedBundle(GhidraSourceBundle.java:1024) ~[Base.jar:?]
	at ghidra.app.plugin.core.osgi.GhidraSourceBundle.build(GhidraSourceBundle.java:605) ~[Base.jar:?]
	at ghidra.app.plugin.core.osgi.BundleHost.activateAll(BundleHost.java:708) ~[Base.jar:?]
	at ghidra.app.script.JavaScriptProvider.loadClass(JavaScriptProvider.java:116) ~[Base.jar:?]
	at ghidra.app.script.JavaScriptProvider.getScriptInstance(JavaScriptProvider.java:81) ~[Base.jar:?]
	at ghidra.app.plugin.core.script.GhidraScriptComponentProvider.getScriptInstance(GhidraScriptComponentProvider.java:642) ~[Base.jar:?]
	at ghidra.app.plugin.core.script.GhidraScriptComponentProvider.doRunScript(GhidraScriptComponentProvider.java:624) ~[Base.jar:?]
	at ghidra.app.plugin.core.script.GhidraScriptComponentProvider$5.run(GhidraScriptComponentProvider.java:611) ~[Base.jar:?]
	at ghidra.util.task.Task.monitoredRun(Task.java:126) ~[Generic.jar:?]
	at ghidra.util.task.TaskRunner.lambda$startTaskThread$1(TaskRunner.java:94) ~[Docking.jar:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) [?:?]
	at java.lang.Thread.run(Thread.java:832) [?:?]

Environment (please complete the following information):

  • OS: Microsoft Windows [Version 10.0.19041.388]
  • Java Version: 14.0.2
  • Ghidra Version: 9.2 aac0c2229f29395e58ea2d77d0a63360548c1a47

Additional context I had just run gradle clean, deleted the flatRepo, ran gradle --init-script gradle/support/fetchDependencies.gradle init, rebuilt ghidra and still encounter this.

Also other GhidraScript classes in the same directory as the GhidraScript being run that are not imported should not be recompiled. I am encountering compile errors do to outdated scripts in the same directory.

@ryanmkurtz

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 24 (19 by maintainers)

Most upvoted comments

Fix has been merged

@astrelsky ClassSearcher will load extension point classes, not, for example, the bndlib classes or BuildError, I wouldn’t expect it to make a difference. Actually priming the classloader with all of the classes used after the JavaCompiler task completes would be pretty tedious.

I think we’ve addressed all of the issues you’ve raised and I’ve prepared the patch. Is there anything else?

The JavaCompiler task closes the main classloader on call. If I override the close method of GhidraClassLoader to do nothing, everything works for me. I don’t know if classloading is lazier in jdk14 or if closing the loader in the task is new, but I’m still working at it.

I’m guilty – trying to recreate the issue now.

It seems you’re not getting the new dependency: https://github.com/NationalSecurityAgency/ghidra/blob/master/Ghidra/Features/Base/build.gradle#L31

Compiling everything in the directory is intended – the new scripting model treats scripting directories as modules, everything in a directory will be built once and cached. In the new model, even sub-packages will be recompiled as necessary.

A lot of failing scripts in a directory shouldn’t break anything, it’ll just make noise (the compilation errors).