From 1f28b5238c8ba59119193473541406abf48e0901 Mon Sep 17 00:00:00 2001 From: Dan <46821332+nsadeveloper789@users.noreply.github.com> Date: Mon, 7 Aug 2023 15:56:50 -0400 Subject: [PATCH] GP-3553: Use double-quotes for default command lines, if needed. --- .../AbstractDebuggerProgramLaunchOffer.java | 5 +++-- .../ghidra/dbg/target/TargetLauncher.java | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/model/launch/AbstractDebuggerProgramLaunchOffer.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/model/launch/AbstractDebuggerProgramLaunchOffer.java index 949987d2ba..b6a9a796a3 100644 --- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/model/launch/AbstractDebuggerProgramLaunchOffer.java +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/model/launch/AbstractDebuggerProgramLaunchOffer.java @@ -15,7 +15,7 @@ */ package ghidra.app.plugin.core.debug.service.model.launch; -import static ghidra.async.AsyncUtils.*; +import static ghidra.async.AsyncUtils.loop; import java.io.IOException; import java.util.*; @@ -275,7 +275,8 @@ public abstract class AbstractDebuggerProgramLaunchOffer implements DebuggerProg for (Entry> entry : params.entrySet()) { map.put(entry.getKey(), entry.getValue().defaultValue); } - map.put(TargetCmdLineLauncher.CMDLINE_ARGS_NAME, program.getExecutablePath()); + map.put(TargetCmdLineLauncher.CMDLINE_ARGS_NAME, + TargetCmdLineLauncher.quoteImagePathIfSpaces(program.getExecutablePath())); return map; } diff --git a/Ghidra/Debug/Framework-Debugging/src/main/java/ghidra/dbg/target/TargetLauncher.java b/Ghidra/Debug/Framework-Debugging/src/main/java/ghidra/dbg/target/TargetLauncher.java index 262811ad0a..9f08318f9d 100644 --- a/Ghidra/Debug/Framework-Debugging/src/main/java/ghidra/dbg/target/TargetLauncher.java +++ b/Ghidra/Debug/Framework-Debugging/src/main/java/ghidra/dbg/target/TargetLauncher.java @@ -60,6 +60,25 @@ public interface TargetLauncher extends TargetObject { */ TargetParameterMap PARAMETERS = TargetMethod.makeParameters(PARAMETER_CMDLINE_ARGS); + /** + * Check if the given image path contains spaces, and surround it in double quotes + * ({@code "}) if necessary. + * + *

+ * Without the quotes the launcher will likely confuse the spaces for separating arguments. + * When constructing the command-line to launch a program, this method must be used, even if + * the image is the only "argument." + * + * @param imagePath the path to the image on the target platform. + * @return the path, possibly surrounded in quotes. + */ + static String quoteImagePathIfSpaces(String imagePath) { + if (imagePath.contains(" ")) { + return '"' + imagePath + '"'; + } + return imagePath; + } + @Override default public TargetParameterMap getParameters() { return PARAMETERS;