NationalSecurityAgency / ghidra

Ghidra is a software reverse engineering (SRE) framework
https://www.nsa.gov/ghidra
Apache License 2.0
51.15k stars 5.83k forks source link

Could not find default tools for project #6753

Open tpimh opened 2 months ago

tpimh commented 2 months ago

Describe the bug On startup, default tools are not found, so this error is triggered: https://github.com/NationalSecurityAgency/ghidra/blob/2517a3234822de74e05e642a55f79d8f3b4c5198/Ghidra/Framework/Project/src/main/java/ghidra/framework/project/DefaultProjectManager.java#L338-L344

To Reproduce Steps to reproduce the behavior:

  1. Download and extract Ghidra
  2. Download and extract Adoptium OpenJDK
  3. Set PATH to jdk_extract_location/bin:$PATH and run ghidra_extract_location/ghidraRun
  4. Accept user agreement, wait for Ghidra to load, see error

Expected behavior Ghidra starts without errors.

Logs

DEBUG | (DefaultProjectManager) No tools found; Installing default tools
DEBUG | (DefaultProjectManager)     no recent project directories found
ERROR | (DefaultProjectManager) Default Tools Not Found: Could not find default tools for project.

Environment (please complete the following information):

Ghidra Version: 11.1.2
Ghidra Release: PUBLIC
Ghidra Build Date: 2024-Jul-09 1157 EDT
Ghidra Revision: 68cad06ddfae2b92c03054357c67c32f2d0553a8
Ghidra Development Mode: false
OS Name: Linux
OS Arch: amd64
OS Version: 6.9.3-76060903-generic
OS Pretty Name: Pop!_OS 22.04 LTS
Java Vendor: Eclipse Adoptium
Java Version: 17.0.12
openjdk 17.0.12 2024-07-16
OpenJDK Runtime Environment Temurin-17.0.12+7 (build 17.0.12+7)
OpenJDK 64-Bit Server VM Temurin-17.0.12+7 (build 17.0.12+7, mixed mode, sharing)
tpimh commented 2 months ago

Also tested with Coretto, same error.

Ghidra Version: 11.1.2
Ghidra Release: PUBLIC
Ghidra Build Date: 2024-Jul-09 1157 EDT
Ghidra Revision: 68cad06ddfae2b92c03054357c67c32f2d0553a8
Ghidra Development Mode: false
OS Name: Linux
OS Arch: amd64
OS Version: 6.9.3-76060903-generic
OS Pretty Name: Pop!_OS 22.04 LTS
Java Vendor: Amazon.com Inc.
Java Version: 17.0.12
openjdk 17.0.12 2024-07-16 LTS
OpenJDK Runtime Environment Corretto-17.0.12.7.1 (build 17.0.12+7-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.12.7.1 (build 17.0.12+7-LTS, mixed mode, sharing)
dragonmacher commented 2 months ago

The default tools are inside of a jar file in the installation, specifically:

{root Ghidra install dir}Ghidra/Configurations/Public_Release/lib/Public_Release.jar

It sounds like your extraction did not work work correctly. The *.tool files should be found on the classpath when Ghidra runs.

tpimh commented 2 months ago

I can confirm that this jar exists, and there's defaultTools/CodeBrowser.tool inside it. I can confirm with inotify that the file is being opened when I run Ghidra:

$ inotifywait ghidra_11.1.2_PUBLIC/Ghidra/Configurations/Public_Release/lib/Public_Release.jar
Setting up watches.
Watches established.
ghidra_11.1.2_PUBLIC/Ghidra/Configurations/Public_Release/lib/Public_Release.jar OPEN 
dragonmacher commented 2 months ago

The next thing to confirm is whether that jar is on the classpath when you run Ghidra. From the Front End's menu, press Help -> Runtime Information. Then select the Classpath tab. You can then use the filter at the bottom to see if that jar is in the list.

tpimh commented 2 months ago

Yes, full path to Public_Release.jar is shown in the list. Just in case, indexes go from 0 to 165, and the index of this jar is 57.

dragonmacher commented 2 months ago

At this point I can't think of anything else for you to try, aside from debugging the issue. If you are interested in trying to debug the issue, let me know and I will offer source code locations to add breakpoints.

tpimh commented 2 months ago

Thank you very much for your support! So I built Ghidra from source, and the error is gone. I don't know now how can I reproduce it. All I did was download the source for 11.1.2, download gradle, build the source.

I started Ghidra from the resulting ghidra_11.1.2_DEV build, and it started with no error. So I tried starting ghidra_11.1.2_PUBLIC again, and there was no error as well. I don't know how could it have fixed it, but it certainly did.

I will try to figure out what changed in my environment, but if I can not reproduce the error, this issue can be closed.

dragonmacher commented 2 months ago

Glad to hear the issue is fixed for you now. We can investigate further if you encounter the issue again.

tpimh commented 2 months ago

Curiously, I am still getting this error on 11.1.1, but not on 11.1.2.

dragonmacher commented 2 months ago

I'll post some debugging tips here, in case you get the desire to debug the issue.

The code is loaded in ToolUtils.getDefaultApplicationTools():

    public static synchronized Set<ToolTemplate> getDefaultApplicationTools() {
        if (defaultTools != null) {
            return defaultTools;
        }

        Set<ToolTemplate> set = new HashSet<>();

        Set<String> toolNames = ResourceManager.getResourceNames("defaultTools", ".tool");
        for (String toolName : toolNames) {
            if (skipTool(toolName)) {
                continue;
            }

            ToolTemplate tool = readToolTemplate(toolName);
            if (tool != null) {
                set.add(tool);
            }
        }

        defaultTools = Collections.unmodifiableSet(set);
        return defaultTools;
    }

One of 2 steps in here is failing: either finding the tool templates or reading the tool templates that have been found. If you debug this method, then you can see if toolNames is empty or if the reading of the tool template is returning null.

If toolNames is empty, then the next step is to debug why we are not able to find a URL in the call to ResourceManager.getResourceNames("defaultTools", ".tool"). Otherwise, you can step into the call to readToolTemplate() to see why that is not correctly reading any discovered template files.