Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-5667: Fix gdbi and lldb argument passing in bash.

Dan6ab32ff4264b
diff --git a/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/local-gdb.sh b/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/local-gdb.sh
index e79d86177c..b4a922456d 100755
--- a/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/local-gdb.sh
+++ b/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/local-gdb.sh
@@ -52,4 +52,4 @@ function launch-gdb() {
"${args[@]}"
}
-launch-gdb
+launch-gdb "$@"
diff --git a/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/ssh-gdb.sh b/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/ssh-gdb.sh
index 34a450424d..17977f17ed 100755
--- a/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/ssh-gdb.sh
+++ b/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/ssh-gdb.sh
@@ -64,7 +64,7 @@ function do-installation() {
"${sshargs[@]}"
}
-launch-gdb-ssh
+launch-gdb-ssh "$@"
if check-result-and-prompt-mitigation $? "
It appears ghidragdb is missing from the remote system. This can happen if you
forgot to install the required package. This can also happen if you installed
diff --git a/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/ssh-gdbserver.sh b/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/ssh-gdbserver.sh
index 3cc5144d90..978a5a016e 100755
--- a/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/ssh-gdbserver.sh
+++ b/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/ssh-gdbserver.sh
@@ -49,9 +49,11 @@ target_image="$1"
shift
function launch-gdb() {
+ local qargs
+ printf -v qargs '%q ' "$@"
local -a args
- compute-gdb-remote-args "$target_image" "remote | '$OPT_SSH_PATH' $OPT_EXTRA_SSH_ARGS '$OPT_HOST' '$OPT_GDBSERVER_PATH' $OPT_EXTRA_GDBSERVER_ARGS - '$target_image' $@" "$GHIDRA_TRACE_RMI_ADDR"
+ compute-gdb-remote-args "$target_image" "remote | '$OPT_SSH_PATH' $OPT_EXTRA_SSH_ARGS '$OPT_HOST' '$OPT_GDBSERVER_PATH' $OPT_EXTRA_GDBSERVER_ARGS - '$target_image' $qargs" "$GHIDRA_TRACE_RMI_ADDR"
"${args[@]}"
}
-launch-gdb
+launch-gdb "$@"
diff --git a/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/wine-gdb.sh b/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/wine-gdb.sh
index f13facef0b..af4e57e470 100755
--- a/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/wine-gdb.sh
+++ b/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/wine-gdb.sh
@@ -52,4 +52,4 @@ function launch-gdb() {
"${args[@]}"
}
-launch-gdb
+launch-gdb "$@"
diff --git a/Ghidra/Debug/Debugger-agent-gdb/data/support/gdbsetuputils.sh b/Ghidra/Debug/Debugger-agent-gdb/data/support/gdbsetuputils.sh
index 5324f295f0..d2bc3fc3d3 100644
--- a/Ghidra/Debug/Debugger-agent-gdb/data/support/gdbsetuputils.sh
+++ b/Ghidra/Debug/Debugger-agent-gdb/data/support/gdbsetuputils.sh
@@ -28,13 +28,15 @@ add-gdb-init-args() {
add-gdb-image-and-args() {
target_image=$1
- target_args=$2
+ shift
if [ -n "$target_image" ]; then
args+=(-ex "file '$target_image'")
fi
- if [ -n "$target_args" ]; then
- args+=(-ex "set args $target_args")
+ if [ "$#" -ne 0 ]; then
+ local qargs
+ printf -v qargs '%q ' "$@"
+ args+=(-ex "set args $qargs")
fi
}
@@ -104,7 +106,7 @@ compute-gdb-remote-args() {
args+=("$OPT_GDB_PATH")
add-gdb-init-args
- add-gdb-image-and-args "$target_image" ""
+ add-gdb-image-and-args "$target_image"
args+=(-ex "echo Connecting to $target_cx\n")
args+=(-ex "target $target_cx")
add-gdb-connect-and-sync "$rmi_address"
diff --git a/Ghidra/Debug/Debugger-agent-lldb/data/debugger-launchers/android-lldb.sh b/Ghidra/Debug/Debugger-agent-lldb/data/debugger-launchers/android-lldb.sh
index a0779c177f..daf34d3716 100755
--- a/Ghidra/Debug/Debugger-agent-lldb/data/debugger-launchers/android-lldb.sh
+++ b/Ghidra/Debug/Debugger-agent-lldb/data/debugger-launchers/android-lldb.sh
@@ -51,4 +51,4 @@ function launch-lldb() {
"${args[@]}"
}
-launch-lldb
+launch-lldb "$@"
diff --git a/Ghidra/Debug/Debugger-agent-lldb/data/debugger-launchers/local-lldb.sh b/Ghidra/Debug/Debugger-agent-lldb/data/debugger-launchers/local-lldb.sh
index 75086e9a71..4e98d7c489 100755
--- a/Ghidra/Debug/Debugger-agent-lldb/data/debugger-launchers/local-lldb.sh
+++ b/Ghidra/Debug/Debugger-agent-lldb/data/debugger-launchers/local-lldb.sh
@@ -49,4 +49,4 @@ function launch-lldb() {
"${args[@]}"
}
-launch-lldb
+launch-lldb "$@"
diff --git a/Ghidra/Debug/Debugger-agent-lldb/data/debugger-launchers/ssh-lldb.sh b/Ghidra/Debug/Debugger-agent-lldb/data/debugger-launchers/ssh-lldb.sh
index 3fbaf2f5cf..be4d8e64f8 100755
--- a/Ghidra/Debug/Debugger-agent-lldb/data/debugger-launchers/ssh-lldb.sh
+++ b/Ghidra/Debug/Debugger-agent-lldb/data/debugger-launchers/ssh-lldb.sh
@@ -63,7 +63,7 @@ function do-installation() {
"${sshargs[@]}"
}
-launch-lldb-ssh
+launch-lldb-ssh "$@"
if check-result-and-prompt-mitigation $? "
It appears ghidralldb is missing from the remote system. This can happen if you
forgot to install the required package. This can also happen if you installed
diff --git a/Ghidra/Debug/Debugger-agent-lldb/data/support/lldbsetuputils.sh b/Ghidra/Debug/Debugger-agent-lldb/data/support/lldbsetuputils.sh
index 32135faf2e..9a68e26066 100644
--- a/Ghidra/Debug/Debugger-agent-lldb/data/support/lldbsetuputils.sh
+++ b/Ghidra/Debug/Debugger-agent-lldb/data/support/lldbsetuputils.sh
@@ -27,7 +27,7 @@ add-lldb-init-args() {
add-lldb-image-and-args() {
target_image=$1
- target_args=$2
+ shift
if [ -n "$target_image" ]; then
if [ -n "$OPT_ARCH" ]; then
@@ -36,8 +36,10 @@ add-lldb-image-and-args() {
args+=(-o "target create '$target_image'")
fi
fi
- if [ -n "$target_args" ]; then
- args+=(-o "settings set target.run-args $target_args")
+ if [ "$#" -ne 0 ]; then
+ local qargs
+ printf -v qargs '%q ' "$@"
+ args+=(-o "settings set -- target.run-args $qargs")
fi
}