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

Could not initialize class libdwarf.LibdwarfLibrary #26

Open
xobs opened this issue Jan 29, 2024 · 3 comments
Open

Could not initialize class libdwarf.LibdwarfLibrary #26

xobs opened this issue Jan 29, 2024 · 3 comments

Comments

@xobs
Copy link

xobs commented Jan 29, 2024

Adding an issue here in case anyone else runs into the same issue.

I installed ghidra2dwarf by extracting the release zipfile and adding the resulting ghidra2dwarf directory to the Script Manager. However, when I run the script, Python gives me an error that says it cannot load the library:

ghidra2dwarf.py> Running...
Traceback (most recent call last):
  File "/Users/seancross/Code/Ghidra/ghidra2dwarf/ghidra2dwarf.py", line 34, in <module>
    from libdwarf import LibdwarfLibrary
java.lang.NoClassDefFoundError: Could not initialize class libdwarf.LibdwarfLibrary
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:534)
	at java.base/java.lang.Class.forName(Class.java:513)
	at org.python.core.Py.loadAndInitClass(Py.java:1176)
	at org.python.core.Py.findClassInternal(Py.java:1111)
	at org.python.core.Py.findClassEx(Py.java:1163)
	at org.python.core.packagecache.SysPackageManager.findClass(SysPackageManager.java:233)
	at org.python.core.packagecache.PackageManager.findClass(PackageManager.java:36)
	at org.python.core.packagecache.SysPackageManager.findClass(SysPackageManager.java:221)
	at org.python.core.PyJavaPackage.__findattr_ex__(PyJavaPackage.java:137)
	at org.python.core.PyObject.__findattr__(PyObject.java:902)
	at org.python.core.PyObject.__findattr__(PyObject.java:889)
	at org.python.core.imp.ensureFromList(imp.java:1500)
	at org.python.core.imp.ensureFromList(imp.java:1465)
	at org.python.core.imp.import_module_level(imp.java:1379)
	at org.python.core.imp.importName(imp.java:1544)
	at org.python.core.ImportFunction.__call__(__builtin__.java:1285)
	at org.python.core.PyObject.__call__(PyObject.java:433)
	at org.python.core.__builtin__.__import__(__builtin__.java:1232)
	at org.python.core.imp.importFromAs(imp.java:1636)
	at org.python.core.imp.importFrom(imp.java:1611)
	at org.python.pycode._pyx41.f$0(/Users/seancross/Code/Ghidra/ghidra2dwarf/ghidra2dwarf.py:524)
	at org.python.pycode._pyx41.call_function(/Users/seancross/Code/Ghidra/ghidra2dwarf/ghidra2dwarf.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:173)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1703)
	at org.python.core.__builtin__.execfile_flags(__builtin__.java:535)
	at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:287)
	at ghidra.python.GhidraPythonInterpreter.execFile(GhidraPythonInterpreter.java:239)
	at ghidra.python.PythonScriptExecutionThread.run(PythonScriptExecutionThread.java:51)
Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.NoClassDefFoundError: Could not initialize class com.sun.jna.Native [in thread "Python script execution thread"]
	at libdwarf.LibdwarfLibrary.<clinit>(LibdwarfLibrary.java:13)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:534)
	at java.base/java.lang.Class.forName(Class.java:513)
	at org.python.core.Py.loadAndInitClass(Py.java:1176)
	at org.python.core.Py.findClassInternal(Py.java:1111)
	at org.python.core.Py.findClass(Py.java:1145)
	at org.python.core.JavaImportHelper.isJavaClass(JavaImportHelper.java:184)
	at org.python.core.JavaImportHelper.tryAddPackage(JavaImportHelper.java:42)
	at org.python.core.imp.import_next(imp.java:1168)
	at org.python.core.imp.import_module_level(imp.java:1352)
	... 15 more
java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: Could not initialize class libdwarf.LibdwarfLibrary
ghidra2dwarf.py> Finished!
@xobs
Copy link
Author

xobs commented Jan 29, 2024

Update: After removing and re-adding the script, I get a different error now. It seems like there is something precompiled that does not work on aarch64:

ghidra2dwarf.py> Running...
Traceback (most recent call last):
  File "/Users/seancross/Code/Ghidra/ghidra2dwarf/ghidra2dwarf.py", line 34, in <module>
    from libdwarf import LibdwarfLibrary
java.lang.NoClassDefFoundError: Could not initialize class com.sun.jna.Native
	at libdwarf.LibdwarfLibrary.<clinit>(LibdwarfLibrary.java:13)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:534)
	at java.base/java.lang.Class.forName(Class.java:513)
	at org.python.core.Py.loadAndInitClass(Py.java:1176)
	at org.python.core.Py.findClassInternal(Py.java:1111)
	at org.python.core.Py.findClassEx(Py.java:1163)
	at org.python.core.packagecache.SysPackageManager.findClass(SysPackageManager.java:233)
	at org.python.core.packagecache.PackageManager.findClass(PackageManager.java:36)
	at org.python.core.packagecache.SysPackageManager.findClass(SysPackageManager.java:221)
	at org.python.core.PyJavaPackage.__findattr_ex__(PyJavaPackage.java:137)
	at org.python.core.PyObject.__findattr__(PyObject.java:902)
	at org.python.core.PyObject.__findattr__(PyObject.java:889)
	at org.python.core.imp.ensureFromList(imp.java:1500)
	at org.python.core.imp.ensureFromList(imp.java:1465)
	at org.python.core.imp.import_module_level(imp.java:1379)
	at org.python.core.imp.importName(imp.java:1544)
	at org.python.core.ImportFunction.__call__(__builtin__.java:1285)
	at org.python.core.PyObject.__call__(PyObject.java:433)
	at org.python.core.__builtin__.__import__(__builtin__.java:1232)
	at org.python.core.imp.importFromAs(imp.java:1636)
	at org.python.core.imp.importFrom(imp.java:1611)
	at org.python.pycode._pyx48.f$0(/Users/seancross/Code/Ghidra/ghidra2dwarf/ghidra2dwarf.py:524)
	at org.python.pycode._pyx48.call_function(/Users/seancross/Code/Ghidra/ghidra2dwarf/ghidra2dwarf.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:173)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1703)
	at org.python.core.__builtin__.execfile_flags(__builtin__.java:535)
	at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:287)
	at ghidra.python.GhidraPythonInterpreter.execFile(GhidraPythonInterpreter.java:239)
	at ghidra.python.PythonScriptExecutionThread.run(PythonScriptExecutionThread.java:51)
Caused by: java.lang.ExceptionInInitializerError: Exception java.lang.UnsatisfiedLinkError: /Users/seancross/Library/Caches/JNA/temp/jna6129151767107641477.tmp: dlopen(/Users/seancross/Library/Caches/JNA/temp/jna6129151767107641477.tmp, 0x0001): tried: '/Users/seancross/Library/Caches/JNA/temp/jna6129151767107641477.tmp' (fat file, but missing compatible architecture (have 'i386,x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/seancross/Library/Caches/JNA/temp/jna6129151767107641477.tmp' (no such file), '/Users/seancross/Library/Caches/JNA/temp/jna6129151767107641477.tmp' (fat file, but missing compatible architecture (have 'i386,x86_64', need 'arm64')) [in thread "Ghidra"]
	at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
	at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:331)
	at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:197)
	at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:139)
	at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2418)
	at java.base/java.lang.Runtime.load0(Runtime.java:852)
	at java.base/java.lang.System.load(System.java:2025)
	at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:1018)
	at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:988)
	at com.sun.jna.Native.<clinit>(Native.java:195)
	at com.sun.jna.Structure.setAlignType(Structure.java:280)
	at com.sun.jna.Structure.<init>(Structure.java:197)
	at com.sun.jna.Structure.<init>(Structure.java:193)
	at com.sun.jna.Structure.<init>(Structure.java:180)
	at com.sun.jna.Structure.<init>(Structure.java:172)
	at com.sun.jna.platform.win32.Guid$GUID.<init>(Guid.java:126)
	at com.sun.jna.platform.win32.Guid$GUID.fromString(Guid.java:257)
	at com.sun.jna.platform.win32.Guid$GUID.<init>(Guid.java:150)
	at com.sun.jna.platform.win32.Guid$IID.<init>(Guid.java:582)
	at agent.dbgmodel.jna.dbgmodel.datamodel.script.IDataModelScriptProvider.<clinit>(IDataModelScriptProvider.java:27)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:534)
	at java.base/java.lang.Class.forName(Class.java:513)
	at ghidra.util.classfinder.ClassFinder.loadExtensionPoint(ClassFinder.java:146)
	at ghidra.util.classfinder.ClassJar.processClassFiles(ClassJar.java:177)
	at ghidra.util.classfinder.ClassJar.scanJar(ClassJar.java:83)
	at ghidra.util.classfinder.ClassJar.<init>(ClassJar.java:60)
	at ghidra.util.classfinder.ClassFinder.initialize(ClassFinder.java:74)
	at ghidra.util.classfinder.ClassFinder.<init>(ClassFinder.java:50)
	at ghidra.util.classfinder.ClassSearcher.search(ClassSearcher.java:261)
	at ghidra.framework.HeadlessGhidraApplicationConfiguration.performClassSearching(HeadlessGhidraApplicationConfiguration.java:76)
	at ghidra.framework.HeadlessGhidraApplicationConfiguration.initializeApplication(HeadlessGhidraApplicationConfiguration.java:40)
	at ghidra.framework.GhidraApplicationConfiguration.initializeApplication(GhidraApplicationConfiguration.java:56)
	at ghidra.framework.Application.initializeApplication(Application.java:118)
	at ghidra.GhidraRun.lambda$launch$1(GhidraRun.java:74)
	at java.base/java.lang.Thread.run(Thread.java:1583)
java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: Could not initialize class com.sun.jna.Native
ghidra2dwarf.py> Finished!

@xobs
Copy link
Author

xobs commented Jan 29, 2024

I've tried recompiling libdwarf.dylib as arm64 and rebuilding libdwarf.jar but that doesn't seem to make any difference.

Note that as part of this change I had to change the target version from 1.7 to 1.8 in order to get it to build.

@xobs
Copy link
Author

xobs commented Jan 31, 2024

I'm unable to get this working on x86-64 under Windows as well:

Could not initialize class LibdwarfLibrary
java.lang.NoClassDefFoundError: Could not initialize class LibdwarfLibrary
	at ExportDwarfELFSymbols.run(ExportDwarfELFSymbols.java:110)
	at ghidra.app.script.GhidraScript.executeNormal(GhidraScript.java:403)
	at ghidra.app.script.GhidraScript.doExecute(GhidraScript.java:258)
	at ghidra.app.script.GhidraScript.execute(GhidraScript.java:236)
	at ghidra.app.plugin.core.script.RunScriptTask.run(RunScriptTask.java:47)
	at ghidra.util.task.Task.monitoredRun(Task.java:134)
	at ghidra.util.task.TaskRunner.lambda$startTaskThread$0(TaskRunner.java:106)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)

---------------------------------------------------
Build Date: 2024-Jan-30 1212 EST
Ghidra Version: 11.0.1
Java Home: C:\Program Files\ojdkbuild\java-17-openjdk-17.0.3.0.6-1
JVM Version: ojdkbuild 17.0.3
OS: Windows 11 10.0 amd64
Workstation: ONDO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant