Forsworns / GhidrAI

Equip Ghidra with LLM
https://forsworns.github.io/zh/blogs/20240220/
MIT License
1 stars 0 forks source link

Error creating class GhidraAnalyzer when creating extension points for ghidra.app.services.Analyzer #3

Open vanhauser-thc opened 6 months ago

vanhauser-thc commented 6 months ago

I compiled GhidrAI for Ghdira 11.0.2 (note that I had to remove line 106 in src/main/java/ghidrai/ui/GhidraiDialog.java because of illegal characters).

I installed the plugin and enabled it, however when starting ghidra on a target I get this error:

image

java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
    at ghidra.util.classfinder.ClassSearcher.getInstances(ClassSearcher.java:156)
    at ghidra.util.classfinder.ClassSearcher.getInstances(ClassSearcher.java:131)
    at ghidra.app.plugin.core.analysis.AutoAnalysisPlugin.findAnalyzers(AutoAnalysisPlugin.java:93)
    at ghidra.app.plugin.core.analysis.AutoAnalysisPlugin.<init>(AutoAnalysisPlugin.java:78)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
    at ghidra.framework.plugintool.util.PluginUtils.instantiatePlugin(PluginUtils.java:46)
    at ghidra.framework.plugintool.PluginManager.addPlugins(PluginManager.java:146)
    at ghidra.framework.plugintool.PluginManager.restorePluginsFromXml(PluginManager.java:314)
    at ghidra.framework.plugintool.PluginTool.restoreFromXml(PluginTool.java:628)
    at ghidra.framework.project.tool.GhidraTool.restoreFromXml(GhidraTool.java:136)
    at ghidra.framework.plugintool.PluginTool.<init>(PluginTool.java:140)
    at ghidra.framework.project.tool.GhidraTool.<init>(GhidraTool.java:67)
    at ghidra.framework.project.tool.GhidraToolTemplate.createTool(GhidraToolTemplate.java:215)
    at ghidra.framework.project.tool.ToolManagerImpl.getTool(ToolManagerImpl.java:651)
    at ghidra.framework.project.tool.WorkspaceImpl.runTool(WorkspaceImpl.java:79)
    at ghidra.framework.project.tool.ToolServicesImpl.defaultLaunch(ToolServicesImpl.java:211)
    at ghidra.framework.project.tool.ToolServicesImpl.launchTool(ToolServicesImpl.java:237)
    at ghidra.framework.main.ToolButton.openDomainFiles(ToolButton.java:564)
    at ghidra.framework.main.ToolButton$2.end(ToolButton.java:541)
    at ghidra.framework.main.ZoomImageRunner$1.end(ZoomImageRunner.java:54)
    at org.jdesktop.animation.timing.Animator.end(Animator.java:755)
    at org.jdesktop.animation.timing.Animator.stop(Animator.java:660)
    at org.jdesktop.animation.timing.Animator.timingEvent(Animator.java:732)
    at org.jdesktop.animation.timing.Animator.access$200(Animator.java:75)
    at org.jdesktop.animation.timing.Animator$TimerTarget.actionPerformed(Animator.java:1041)
    at java.desktop/javax.swing.Timer.fireActionPerformed(Timer.java:311)
    at java.desktop/javax.swing.Timer$DoPostEvent.run(Timer.java:243)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.util.ServiceConfigurationError: ghidrai.services.ServiceInterface: Provider ghidrai.services.DashScopeService could not be instantiated
    at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:586)
    at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:813)
    at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:729)
    at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1403)
    at ghidrai.services.GhidraiAgent.<clinit>(GhidraiAgent.java:30)
    at ghidrai.GhidraiAnalyzer.<init>(GhidraiAnalyzer.java:40)
    ... 49 more
Caused by: java.lang.ExceptionInInitializerError
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
    at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:789)
    ... 53 more
Caused by: java.lang.IllegalStateException: DashScope API key must be set via environment variable. Try `export DASHSCOPE_API_KEY=YOUR_DASHSCOPE_API_KEY`.
    at ghidrai.services.DashScopeService.<clinit>(DashScopeService.java:36)
    ... 59 more

---------------------------------------------------
Build Date: 2024-Mar-26 1446 EDT
Ghidra Version: 11.0.2
Java Home: /usr/lib/jvm/java-17-openjdk-amd64
JVM Version: Private Build 17.0.10
OS: Linux 6.5.0-26-generic amd64

Is that an incompatibility with Ghidra 11?

Forsworns commented 6 months ago

Seems that you didn't set your DASHSCOPE_API_KEY env. The Alibaba Dashscope SDK always load its API key from environment. Try to add the export DASHSCOPE_API_KEY=YOUR_DASHSCOPE_API_KEY=${your Dashscope key} to your ~/.bashrc (or other configuration file, upon your shell).

Forsworns commented 6 months ago

As for the illegal characters in the GhidraiDialog.java comment, maybe your platform did not support Chinese character, you can help remove this comment or translate it to English and submit a PR :)