0

I have a Ghidra project with an imported binary file, which was created on computer A, then I want to move this project to Computer B. However, the path of the binary file isn't the same as A. How do I change the path setting in Ghidra?

Edited: Error Message (Black blocks are the original path in computer A.)

qqaatw
  • 3
  • 3
  • How are you moving the project? Ghidra will refuse a project that was not created on the same machine, you have to either use `File > Archive Current Project` or a Ghidra Server to sync between computers. Also what kind of path setting do you mean? Once the binary is imported the paths on the computer should not matter anymore anymore – Florian Magin Jan 18 '21 at 10:06
  • I just copied the project folder to computer B. The reason I want to change the path setting is because I built a new debugger included Ghidra from source, and GDB debugger needs original binary file to run debug processes. So it turns out this question. – qqaatw Jan 20 '21 at 09:36
  • Interesting, Ghidra used to reject copied folders like this, but maybe that changed. The debugger integration is fairly new and still experimental, but I can check where this binary file path is stored and how to change it, I actually need that information for some other things and wasn't aware that Ghidra stores this. – Florian Magin Jan 20 '21 at 14:00
  • Is there some concrete error or stacktrace you get when this fails? That would make it a lot easier for me to find the relevant part of the codebase – Florian Magin Jan 20 '21 at 14:04
  • Yes, I've updated the error message in the question. – qqaatw Jan 21 '21 at 05:01

1 Answers1

1

It seems that Ghidra uses the information from currentProgram.getExecutablePath() which takes the value from the options stored with the binary information inside the project:

Code snippet from ghidra.program.database.ProgramDB#getExecutablePath:

    @Override
    public String getExecutablePath() {
        String path = null;
        Options pl = getOptions(PROGRAM_INFO);
        path = pl.getString(EXECUTABLE_PATH, UNKNOWN);
        return path == null ? UNKNOWN : path;
    }

    @Override
    public void setExecutablePath(String path) {
        Options pl = getOptions(PROGRAM_INFO);
        pl.setString(EXECUTABLE_PATH, path);
        changed = true;
    }

To change this you should be able to simply use the corresponding setExecutablePath method, e.g. by running

currentProgram.setExecutablePath("/new/path/to/binary.elf")

inside the Python REPL.

Florian Magin
  • 576
  • 3
  • 6