diff --git a/Ghidra/Debug/Debugger-agent-gdb/certification.manifest b/Ghidra/Debug/Debugger-agent-gdb/certification.manifest index c6aac33ff6..5d01f29560 100644 --- a/Ghidra/Debug/Debugger-agent-gdb/certification.manifest +++ b/Ghidra/Debug/Debugger-agent-gdb/certification.manifest @@ -6,6 +6,7 @@ data/scripts/fallback_info_proc_mappings.gdb||GHIDRA||||END| data/scripts/fallback_maintenance_info_sections.gdb||GHIDRA||||END| data/scripts/getpid-linux-i386.gdb||GHIDRA||||END| data/scripts/wine32_info_proc_mappings.gdb||GHIDRA||||END| +data/support/gdbinit_template||GHIDRA||||END| src/main/help/help/TOC_Source.xml||GHIDRA||||END| src/main/help/help/topics/gdb/gdb.html||GHIDRA||||END| src/main/help/help/topics/gdb/images/GdbLauncher.png||GHIDRA||||END| diff --git a/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/ssh-gdb-win.ps1 b/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/ssh-gdb-win.ps1 new file mode 100644 index 0000000000..4551fa9430 --- /dev/null +++ b/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/ssh-gdb-win.ps1 @@ -0,0 +1,104 @@ +## ### +# IP: GHIDRA +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +## +#@title gdb via ssh ((remote=cmd shell) +#@image-opt arg:1 +#@desc +#@desc

Launch with gdb via ssh to a remote Windows machine

+#@desc

+#@desc This will launch the target on a remote Windows machine using gdb via ssh. +#@desc For setup instructions, press F1. +#@desc

+#@desc +#@menu-group gdb +#@icon icon.debugger +#@help gdb#ssh-win +#@depends Debugger-rmi-trace +#@enum StartCmd:str run start starti +#@enum Endian:str auto big little +#@arg :str "Image" "The target binary executable image on the remote system" +#@env OPT_TARGET_ARGS:str="" "Arguments" "Command-line arguments to pass to the target" +##@env OPT_SSH_PATH:file="ssh" "ssh command" "The path to ssh on the local system. Omit the full path to resolve using the system PATH." +#@env OPT_HOST:str="localhost" "[User@]Host" "The hostname or user@host" +#@env OPT_REMOTE_PORT:int=12345 "Remote Trace RMI Port" "A free port on the remote end to receive and forward the Trace RMI connection." +#@env OPT_EXTRA_SSH_ARGS:str="" "Extra ssh arguments" "Extra arguments to pass to ssh. Use with care." +#@env OPT_GDB_PATH:str="gdb" "gdb command" "The path to gdb on the remote system. Omit the full path to resolve using the system PATH." +#@env OPT_GDB_ARGS:str="" "gdb cmd args" "Arguments passed to gdb (versus the target)" +#@env OPT_START_CMD:StartCmd="starti" "Run command" "The gdb command to actually run the target." +#@env OPT_ARCH:str="i386:x86-64" "Architecture" "Target architecture" +#@env OPT_ENDIAN:Endian="auto" "Endian" "Target byte order" + +. ..\support\gdbsetuputils.ps1 + +$Env:OPT_OS_WINDOWS = $true +$arglist = @("") +$arglist += ("cat > .\.gdbinit") +$sshargs = Compute-Ssh-Args $arglist True + +$image = ($args[0]).Replace("\", "\\") + +(Get-Content ..\support\gdbinit_template).` +Replace('$OPT_ARCH', $Env:OPT_ARCH).` +Replace('$OPT_ENDIAN', $Env:OPT_ENDIAN).` +Replace('$OPT_TARGET_IMG', $image).` +Replace('$OPT_TARGET_ARGS', $Env:OPT_TARGET_ARGS).` +Replace('$OPT_REMOTE_PORT', $Env:OPT_REMOTE_PORT).` +Replace('$OPT_START_CMD', $Env:OPT_START_CMD)` + | ssh $sshargs[1..$sshargs.Count] + +$arglist = @("") +$arglist += ("$Env:OPT_GDB_PATH") +$arglist += ("-q") +$sshargs = Compute-Ssh-Args $arglist True + +$sshproc = Start-Process -FilePath ssh -ArgumentList $sshargs[1..$sshargs.Count] -NoNewWindow -Wait -PassThru + +$version = Get-Ghidra-Version +$answer = Check-Result-And-Prompt-Mitigation $sshproc @" +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 +the packages to a different Python environment than is being used by the +remote's gdb. + +This script is about to offer automatic resolution. If you'd like to resolve +this manually, answer no to the next question and then see Ghidra's help by +pressing F1 in the dialog of launch parameters. + +WARNING: Answering yes to the next question will invoke pip to try to install +missing or incorrectly-versioned dependencies. It may attempt to find packages +from the PyPI mirror configured on the REMOTE system. If you have not configured +one, it will connect to the official one. + +WARNING: We invoke pip with the --break-system-packages flag, because some +debuggers that embed Python (gdb, lldb) may not support virtual environments, +and so the packages must be installed to your user environment. + +NOTE: This will copy Python wheels into the HOME directory of the user on the +remote system. You may be prompted to authenticate a few times while packages +are copied and installed. + +NOTE: Automatic resolution will cause this session to terminate. When it has +finished, try launching again. +"@ "Would you like to install 'ghidragdb>=$version'?" + +if ($answer) { + Write-Host "Copying Wheels to $Env:OPT_HOST" + Mitigate-Scp-PyModules "Debugger-rmi-trace" "" + + Write-Host "Installing Wheels into GDB's embedded Python" + $arglist = Compute-Gdb-PipInstall-Args "'-f'" "os.environ['HOME']" "'ghidragdb>=$version'" + $sshargs = Compute-Ssh-Args $arglist False + Start-Process -FilePath $sshargs[0] -ArgumentList $sshargs[1..$sshargs.Count] -NoNewWindow -Wait +} diff --git a/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/ssh-gdb-win.sh b/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/ssh-gdb-win.sh new file mode 100755 index 0000000000..b2ded6d66a --- /dev/null +++ b/Ghidra/Debug/Debugger-agent-gdb/data/debugger-launchers/ssh-gdb-win.sh @@ -0,0 +1,125 @@ +#!/usr/bin/env bash +## ### +# IP: GHIDRA +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +## +#@title gdb via ssh (to cmd) +#@image-opt arg:1 +#@desc +#@desc

Launch with gdb via ssh

+#@desc

+#@desc This will launch the target on a remote machine using gdb via ssh. +#@desc For setup instructions, press F1. +#@desc

+#@desc +#@menu-group gdb +#@icon icon.debugger +#@help gdb#ssh-win +#@depends Debugger-rmi-trace +#@enum StartCmd:str run start starti +#@enum Endian:str auto big little +#@arg :str "Image" "The target binary executable image on the remote system" +#@args "Arguments" "Command-line arguments to pass to the target" +#@env OPT_SSH_PATH:file!="ssh" "ssh command" "The path to ssh on the local system. Omit the full path to resolve using the system PATH." +#@env OPT_HOST:str="localhost" "[User@]Host" "The hostname or user@host" +#@env OPT_REMOTE_PORT:int=12345 "Remote Trace RMI Port" "A free port on the remote end to receive and forward the Trace RMI connection." +#@env OPT_EXTRA_SSH_ARGS:str="" "Extra ssh arguments" "Extra arguments to pass to ssh. Use with care." +#@env OPT_GDB_PATH:str="gdb" "gdb command" "The path to gdb on the remote system. Omit the full path to resolve using the system PATH." +#@env OPT_GDB_ARGS:str="" "gdb cmd args" "Arguments passed to gdb (versus the target)" +#@env OPT_START_CMD:StartCmd="starti" "Run command" "The gdb command to actually run the target." +#@env OPT_ARCH:str="i386:x86-64" "Architecture" "Target architecture" +#@env OPT_ENDIAN:Endian="auto" "Endian" "Target byte order" + +. ../support/gdbsetuputils.sh + +target_image="$1" +shift +target_image=$(echo $target_image | sed 's/\\/\\\\/g') + +OPT_OS_WINDOWS=true + +function rewrite-gdbinit() { + local -a gdbcmds + gdbcmds+=$(sed -e 's/$OPT_ARCH/'$OPT_ARCH'/g' \ + -e 's/$OPT_ENDIAN/'$OPT_ENDIAN'/g' \ + -e 's/$OPT_TARGET_IMG/'"$target_image"'/g' \ + -e 's/$OPT_TARGET_ARGS/'"$args"'/g' \ + -e 's/$OPT_REMOTE_PORT/'$OPT_REMOTE_PORT'/g' \ + -e 's/$OPT_START_CMD/'$OPT_START_CMD'/g' \ + "../support/gdbinit_template") + + echo "$gdbcmds" +} + +function launch-gdb-ssh-init() { + local -a sshargs + compute-ssh-args true "cat > .\.gdbinit" + + "${sshargs[@]}" +} + +rewrite-gdbinit | launch-gdb-ssh-init + +function launch-gdb-ssh() { + local -a sshargs + compute-ssh-args true "gdb -q" + + "${sshargs[@]}" +} + +version=$(get-ghidra-version) + +function do-installation() { + local -a pipargs + compute-gdb-pipinstall-args "'-f'" "os.environ['HOME']" "'ghidragdb>=$version'" + local -a sshargs + compute-ssh-args false "${pipargs[@]}" + + "${sshargs[@]}" +} + +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 +the packages to a different Python environment than is being used by the +remote's gdb. + +This script is about to offer automatic resolution. If you'd like to resolve +this manually, answer no to the next question and then see Ghidra's help by +pressing F1 in the dialog of launch parameters. + +WARNING: Answering yes to the next question will invoke pip to try to install +missing or incorrectly-versioned dependencies. It may attempt to find packages +from the PyPI mirror configured on the REMOTE system. If you have not configured +one, it will connect to the official one. + +WARNING: We invoke pip with the --break-system-packages flag, because some +debuggers that embed Python (gdb, lldb) may not support virtual environments, +and so the packages must be installed to your user environment. + +NOTE: This will copy Python wheels into the HOME directory of the user on the +remote system. You may be prompted to authenticate a few times while packages +are copied and installed. + +NOTE: Automatic resolution will cause this session to terminate. When it has +finished, try launching again. +" "Would you like to install 'ghidragdb>=$version'?"; then + + echo "Copying Wheels to $OPT_HOST" + mitigate-scp-pymodules "Debugger-rmi-trace" "" + + echo "Installing Wheels into GDB's embedded Python" + do-installation +fi diff --git a/Ghidra/Debug/Debugger-agent-gdb/data/support/gdbinit_template b/Ghidra/Debug/Debugger-agent-gdb/data/support/gdbinit_template new file mode 100644 index 0000000000..ab55be9810 --- /dev/null +++ b/Ghidra/Debug/Debugger-agent-gdb/data/support/gdbinit_template @@ -0,0 +1,14 @@ +set pagination off +set confirm off +show version +python import ghidragdb +python if not 'ghidragdb' in locals(): exit(253) +set architecture $OPT_ARCH +set endian $OPT_ENDIAN +file '$OPT_TARGET_IMG' +set args $OPT_TARGET_ARGS +ghidra trace connect 'localhost:$OPT_REMOTE_PORT' +ghidra trace start +ghidra trace sync-enable +$OPT_START_CMD +set confirm on diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/help/help/TOC_Source.xml b/Ghidra/Debug/Debugger-agent-gdb/src/main/help/help/TOC_Source.xml index 2bfd57f400..f2971baa56 100644 --- a/Ghidra/Debug/Debugger-agent-gdb/src/main/help/help/TOC_Source.xml +++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/help/help/TOC_Source.xml @@ -11,6 +11,9 @@ + + diff --git a/Ghidra/Debug/Debugger-agent-gdb/src/main/help/help/topics/gdb/gdb.html b/Ghidra/Debug/Debugger-agent-gdb/src/main/help/help/topics/gdb/gdb.html index 3e0dd3eff5..f66a8c7afc 100644 --- a/Ghidra/Debug/Debugger-agent-gdb/src/main/help/help/topics/gdb/gdb.html +++ b/Ghidra/Debug/Debugger-agent-gdb/src/main/help/help/topics/gdb/gdb.html @@ -191,6 +191,20 @@ python3 -m pip install --no-index -f ~/ghidra-pypkg/ ghidragdb
  • Note there is no option to create a second Terminal (TTY) for the target.
  • +

    Via SSH (to Windows cmd shell)

    + +

    Essentially identical to ssh from the standpoint of usage and options, this launcher + runs gdb on a remote Windows system via ssh. The behavior of ssh + on Windows, however, requires a slightly different mechanism. The command options are used to + rewrite the gdbinit_template in the support directory. The result is copied to + .gdbinit in the user's home directory on the remote machine. Because two commands are + executed, the user may be asked to authenticate twice depending on their ssh configuration. +

    + +

    Once the .gdbinit file is in place, the user may wish to modify the launchers, or connect + without the launcher by setting the RMI port by hand and running gdb on the remote box. +

    +

    gdbserver via SSH

    This works similarly to the GDB via SSH launcher, but instead of tunneling the Trace RMI diff --git a/Ghidra/Debug/Debugger-agent-lldb/certification.manifest b/Ghidra/Debug/Debugger-agent-lldb/certification.manifest index 4491d87e61..73b81dc24c 100644 --- a/Ghidra/Debug/Debugger-agent-lldb/certification.manifest +++ b/Ghidra/Debug/Debugger-agent-lldb/certification.manifest @@ -4,6 +4,7 @@ Module.manifest||GHIDRA||||END| README.md||GHIDRA||||END| build.gradle||GHIDRA||||END| +data/support/lldbinit_template||GHIDRA||||END| src/main/help/help/TOC_Source.xml||GHIDRA||||END| src/main/help/help/topics/lldb/lldb.html||GHIDRA||||END| src/main/py/LICENSE||GHIDRA||||END| diff --git a/Ghidra/Debug/Debugger-agent-lldb/data/debugger-launchers/ssh-lldb-win.ps1 b/Ghidra/Debug/Debugger-agent-lldb/data/debugger-launchers/ssh-lldb-win.ps1 new file mode 100644 index 0000000000..760998b2de --- /dev/null +++ b/Ghidra/Debug/Debugger-agent-lldb/data/debugger-launchers/ssh-lldb-win.ps1 @@ -0,0 +1,106 @@ +## ### +# IP: GHIDRA +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +## +#@title lldb via ssh (remote=cmd shell) +#@image-opt arg:1 +#@desc +#@desc

    Launch with lldb via ssh to a remote Windows machine

    +#@desc

    +#@desc This will launch the target on a remote Windows machine using lldb via ssh. +#@desc For setup instructions, press F1. +#@desc

    +#@desc +#@menu-group lldb +#@icon icon.debugger +#@help lldb#ssh-win +#@depends Debugger-rmi-trace +#@enum StartCmd:str "process launch" "process launch --stop-at-entry" +#@enum Endian:str auto big little +#@arg :str "Image" "The target binary executable image on the remote system" +#@env OPT_TARGET_ARGS:str="" "Arguments" "Command-line arguments to pass to the target" +##@env OPT_SSH_PATH:file!="ssh" "ssh command" "The path to ssh on the local system. Omit the full path to resolve using the system PATH." +#@env OPT_HOST:str="localhost" "[User@]Host" "The hostname or user@host" +#@env OPT_REMOTE_PORT:int=12345 "Remote Trace RMI Port" "A free port on the remote end to receive and forward the Trace RMI connection." +#@env OPT_EXTRA_SSH_ARGS:str="" "Extra ssh arguments" "Extra arguments to pass to ssh. Use with care." +#@env OPT_LLDB_PATH:str="lldb" "lldb command" "The path to lldb on the remote system. Omit the full path to resolve using the system PATH." +#@env OPT_LLDB_ARGS:str="" "lldb cmd args" "Arguments passed to lldb (versus the target)" +#@env OPT_START_CMD:StartCmd="process launch" "Run command" "The lldb command to actually run the target." +#@env OPT_ARCH:str="x86_64" "Architecture" "Target architecture" + +. ..\support\lldbsetuputils.ps1 + +$Env:OPT_OS_WINDOWS = $true +$arglist = @("") +$arglist += ("cat > .\.lldbinit") +$sshargs = Compute-Ssh-Args $arglist True + +$tgtargs = $Env:OPT_TARGET_ARGS +if ($tgtargs) { + $tgtargs = "settings set target.run-args $tgtargs" +} + +(Get-Content ..\support\lldbinit_template).` +Replace('$OPT_ARCH', $Env:OPT_ARCH).` +Replace('$OPT_TARGET_IMG', $args[0]).` +Replace('$OPT_TARGET_ARGS', $tgtargs).` +Replace('$OPT_REMOTE_PORT', $Env:OPT_REMOTE_PORT).` +Replace('$OPT_START_CMD', $Env:OPT_START_CMD).` +Replace('$OPT_EXTRA_CMDS', $Env:OPT_EXTRA_CMDS)` + | ssh $sshargs[1..$sshargs.Count] + +$arglist = @("") +$arglist += ("$Env:OPT_LLDB_PATH") +$arglist += ("$Env:OPT_LLDB_ARGS") +$sshargs = Compute-Ssh-Args $arglist True + +$sshproc = Start-Process -FilePath ssh -ArgumentList $sshargs[1..$sshargs.Count] -NoNewWindow -Wait -PassThru + +$version = Get-Ghidra-Version +$answer = Check-Result-And-Prompt-Mitigation $sshproc @" +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 +the packages to a different Python environment than is being used by the +remote's lldb. + +This script is about to offer automatic resolution. If you'd like to resolve +this manually, answer no to the next question and then see Ghidra's help by +pressing F1 in the dialog of launch parameters. + +WARNING: Answering yes to the next question will invoke pip to try to install +missing or incorrectly-versioned dependencies. It may attempt to find packages +from the PyPI mirror configured on the REMOTE system. If you have not configured +one, it will connect to the official one. + +WARNING: We invoke pip with the --break-system-packages flag, because some +debuggers that embed Python (gdb, lldb) may not support virtual environments, +and so the packages must be installed to your user environment. + +NOTE: This will copy Python wheels into the HOME directory of the user on the +remote system. You may be prompted to authenticate a few times while packages +are copied and installed. + +NOTE: Automatic resolution will cause this session to terminate. When it has +finished, try launching again. +"@ "Would you like to install 'ghidralldb>=$version'?" + +if ($answer) { + Write-Host "Copying Wheels to $Env:OPT_HOST" + Mitigate-Scp-PyModules "Debugger-rmi-trace" "" + + Write-Host "Installing Wheels into LLDB's embedded Python" + $arglist = Compute-Lldb-PipInstall-Args "'-f'" "os.environ['HOME']" "'ghidralldb>=$version'" + $sshargs = Compute-Ssh-Args $arglist False + Start-Process -FilePath $sshargs[0] -ArgumentList $sshargs[1..$sshargs.Count] -NoNewWindow -Wait +} diff --git a/Ghidra/Debug/Debugger-agent-lldb/data/debugger-launchers/ssh-lldb-win.sh b/Ghidra/Debug/Debugger-agent-lldb/data/debugger-launchers/ssh-lldb-win.sh new file mode 100755 index 0000000000..ea0cbab20f --- /dev/null +++ b/Ghidra/Debug/Debugger-agent-lldb/data/debugger-launchers/ssh-lldb-win.sh @@ -0,0 +1,123 @@ +#!/usr/bin/env bash +## ### +# IP: GHIDRA +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +## +#@title lldb via ssh (to cmd) +#@image-opt arg:1 +#@desc +#@desc

    Launch with lldb via ssh

    +#@desc

    +#@desc This will launch the target on a remote machine using lldb via ssh. +#@desc For setup instructions, press F1. +#@desc

    +#@desc +#@menu-group lldb +#@icon icon.debugger +#@help lldb#ssh-win +#@depends Debugger-rmi-trace +#@enum StartCmd:str "process launch" "process launch --stop-at-entry" +#@enum Endian:str auto big little +#@arg :str "Image" "The target binary executable image on the remote system" +#@env OPT_TARGET_ARGS:str="" "Arguments" "Command-line arguments to pass to the target" +#@env OPT_SSH_PATH:file!="ssh" "ssh command" "The path to ssh on the local system. Omit the full path to resolve using the system PATH." +#@env OPT_HOST:str="localhost" "[User@]Host" "The hostname or user@host" +#@env OPT_REMOTE_PORT:int=12345 "Remote Trace RMI Port" "A free port on the remote end to receive and forward the Trace RMI connection." +#@env OPT_EXTRA_SSH_ARGS:str="" "Extra ssh arguments" "Extra arguments to pass to ssh. Use with care." +#@env OPT_LLDB_PATH:str="lldb" "lldb command" "The path to lldb on the remote system. Omit the full path to resolve using the system PATH." +#@env OPT_LLDB_ARGS:str="" "lldb cmd args" "Arguments passed to lldb (versus the target)" +#@env OPT_START_CMD:StartCmd="process launch" "Run command" "The lldb command to actually run the target." +#@env OPT_ARCH:str="x86_64" "Architecture" "Target architecture" + +. ../support/lldbsetuputils.sh + +target_image="$1" +shift +target_image=$(echo $target_image | sed 's/\\/\\\\/g') + +OPT_OS_WINDOWS=true + +function rewrite-lldbinit() { + local -a lldbcmds + lldbcmds+=$(sed -e 's/$OPT_ARCH/'$OPT_ARCH'/g' \ + -e 's/$OPT_TARGET_IMG/'"$target_image"'/g' \ + -e 's/$OPT_TARGET_ARGS/'"$args"'/g' \ + -e 's/$OPT_REMOTE_PORT/'$OPT_REMOTE_PORT'/g' \ + -e 's/$OPT_START_CMD/'"$OPT_START_CMD"'/g' \ + "../support/lldbinit_template") + + echo "$lldbcmds" +} + +function launch-lldb-ssh-init() { + local -a sshargs + compute-ssh-args true "cat > .\.lldbinit" + + "${sshargs[@]}" +} + +rewrite-lldbinit | launch-lldb-ssh-init + +function launch-lldb-ssh() { + local -a sshargs + compute-ssh-args true "lldb" + + "${sshargs[@]}" +} + +version=$(get-ghidra-version) + +function do-installation() { + local -a pipargs + compute-lldb-pipinstall-args "'-f'" "os.environ['HOME']" "'ghidralldb>=$version'" + local -a sshargs + compute-ssh-args false "${pipargs[@]}" + + "${sshargs[@]}" +} + +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 +the packages to a different Python environment than is being used by the +remote's lldb. + +This script is about to offer automatic resolution. If you'd like to resolve +this manually, answer no to the next question and then see Ghidra's help by +pressing F1 in the dialog of launch parameters. + +WARNING: Answering yes to the next question will invoke pip to try to install +missing or incorrectly-versioned dependencies. It may attempt to find packages +from the PyPI mirror configured on the REMOTE system. If you have not configured +one, it will connect to the official one. + +WARNING: We invoke pip with the --break-system-packages flag, because some +debuggers that embed Python (gdb, lldb) may not support virtual environments, +and so the packages must be installed to your user environment. + +NOTE: This will copy Python wheels into the HOME directory of the user on the +remote system. You may be prompted to authenticate a few times while packages +are copied and installed. + +NOTE: Automatic resolution will cause this session to terminate. When it has +finished, try launching again. +" "Would you like to install 'ghidralldb>=$version'?"; then + + echo "Copying Wheels to $OPT_HOST" + mitigate-scp-pymodules "Debugger-rmi-trace" "" + + echo "Installing Wheels into LLDB's embedded Python" + do-installation +fi diff --git a/Ghidra/Debug/Debugger-agent-lldb/data/support/lldbinit_template b/Ghidra/Debug/Debugger-agent-lldb/data/support/lldbinit_template new file mode 100644 index 0000000000..c26a4cea53 --- /dev/null +++ b/Ghidra/Debug/Debugger-agent-lldb/data/support/lldbinit_template @@ -0,0 +1,10 @@ +version +script import os, ghidralldb +script if not 'ghidralldb' in locals(): os._exit(253) +settings set target.default-arch $OPT_ARCH +target create '$OPT_TARGET_IMG' +$OPT_TARGET_ARGS +ghidra trace connect 'localhost:$OPT_REMOTE_PORT' +ghidra trace start +ghidra trace sync-enable +$OPT_START_CMD diff --git a/Ghidra/Debug/Debugger-agent-lldb/src/main/help/help/TOC_Source.xml b/Ghidra/Debug/Debugger-agent-lldb/src/main/help/help/TOC_Source.xml index 1897ae5fa1..74575c82ef 100644 --- a/Ghidra/Debug/Debugger-agent-lldb/src/main/help/help/TOC_Source.xml +++ b/Ghidra/Debug/Debugger-agent-lldb/src/main/help/help/TOC_Source.xml @@ -17,6 +17,9 @@ + + diff --git a/Ghidra/Debug/Debugger-agent-lldb/src/main/help/help/topics/lldb/lldb.html b/Ghidra/Debug/Debugger-agent-lldb/src/main/help/help/topics/lldb/lldb.html index 9120cb593b..fd0050dfc1 100644 --- a/Ghidra/Debug/Debugger-agent-lldb/src/main/help/help/topics/lldb/lldb.html +++ b/Ghidra/Debug/Debugger-agent-lldb/src/main/help/help/topics/lldb/lldb.html @@ -206,7 +206,13 @@ perl -i -pe 's/(?<=pendingNMI\x00{4})\x00/\x01/' macOS_15-1234567.vmss

    This works the same as the GDB via SSH launcher, but runs lldb on a remote system via ssh.

    -

    Android

    +

    Via SSH (to Windows cmd shell)

    + +

    This works the same as the GDB via SSH (to Windows cmd shell) + launcher, but runs lldb on a remote Windows system via ssh. +

    + +

    Android

    This has the same options as the LLDB via SSH launcher, which are necessary for connecting to the Android debugger, but uses Device in place of Host diff --git a/Ghidra/Debug/Debugger-rmi-trace/data/support/setuputils.ps1 b/Ghidra/Debug/Debugger-rmi-trace/data/support/setuputils.ps1 index 5c39b5990e..e068525c28 100644 --- a/Ghidra/Debug/Debugger-rmi-trace/data/support/setuputils.ps1 +++ b/Ghidra/Debug/Debugger-rmi-trace/data/support/setuputils.ps1 @@ -75,14 +75,14 @@ function Compute-Ssh-Args { if ($forward) { $sshargs+=("-R$Env:OPT_REMOTE_PORT`:$Env:GHIDRA_TRACE_RMI_ADDR") } - if ("$Env:OPT_EXTRA_SSH_ARGS" -ne "") { + if ("$Env:OPT_EXTRA_SSH_ARGS") { $sshargs+=("$Env:OPT_EXTRA_SSH_ARGS") } $sshargs+=("$Env:OPT_HOST") - if ("$Env:OPT_OS_WINDOWS" -ne "") { + if ("$Env:OPT_OS_WINDOWS" -ne $true) { $sshargs+=("TERM='$Env:TERM'") } - $sshargs+=($cmdline) + $sshargs+=("$cmdline") return $sshargs }