ghidra icon indicating copy to clipboard operation
ghidra copied to clipboard

getJavaData results in "InvalidPathException: Illegal char <:> at index 2"

Open NancyAurum opened this issue 1 year ago • 1 comments

Describe the bug

Error running script: Cantordust.java java.nio.file.InvalidPathException: Illegal char <:> at index 2: /C:/Users/nangl/d/code/test/sdlstasy.exe at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182) at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153) at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77) at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92) at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:232) at java.base/java.nio.file.Path.of(Path.java:147) at java.base/java.nio.file.Paths.get(Paths.java:69) at resources.GhidraSrc.getJavaData(GhidraSrc.java:121) at resources.GhidraSrc.getData(GhidraSrc.java:78) at Cantordust.run(Cantordust.java:36) at ghidra.app.script.GhidraScript.executeNormal(GhidraScript.java:405) at ghidra.app.script.GhidraScript.doExecute(GhidraScript.java:260) at ghidra.app.script.GhidraScript.execute(GhidraScript.java:238) 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)

To Reproduce Steps to reproduce the behavior:

  1. Analyze the attached exe with the default settings
  2. Open Script Manager, click Manage Script Directories button.
  3. Add the folder containing Cantordust.java, in the repository checked out from https://github.com/Battelle/cantordust
  4. Run Cantordust.java from the Script Manager

Expected behavior Ghidra handles Windows pathes properly

Attachments sdlstasy.zip

Environment (please complete the following information):

  • OS: Windows 11, 23H2
  • Java Version: Java(TM) SE Runtime Environment (build 17.0.7+8-LTS-224)
  • Ghidra Version: 11.1.1
  • Ghidra Origin: https://github.com/NationalSecurityAgency/ghidra/releases/tag/Ghidra_11.1.1_build

Additional context The exception doesn't appear to be related to Cantordust, but to the Ghidra prefixing the Windows path with '/'.

NancyAurum avatar Jul 21 '24 18:07 NancyAurum

did you file this with cantordust first?

nvmd,. https://github.com/Battelle/cantordust/issues/14

"windows 11" != "windows 10" is probably the issue

mumbel avatar Jul 21 '24 21:07 mumbel

As a general java programming issue, I've found that creating Path objects from random strings is something that needs to be done carefully, because of the exception you are running into.

Rather than checking the OS name, doing something like new File(randomstring).toPath() is a bit safer and File gives you some automatic fixing of those java-fied strings with the leading '/'.

The location that is causing the problem seems to be resources.GhidraSrc, which is a Cantordust file, not a Ghidra file.

dev747368 avatar Jul 22 '24 15:07 dev747368

As a general java programming issue, I've found that creating Path objects from random strings is something that needs to be done carefully, because of the exception you are running into.

Rather than checking the OS name, doing something like new File(randomstring).toPath() is a bit safer and File gives you some automatic fixing of those java-fied strings with the leading '/'.

The location that is causing the problem seems to be resources.GhidraSrc, which is a Cantordust file, not a Ghidra file.

Yeah. System.getProperty("os.name").equals("Windows 10") looks really crufty. Wonder what happens on Windows 7.

NancyAurum avatar Jul 22 '24 16:07 NancyAurum