mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-21 08:21:34 +08:00
GP-6423: better setuputils
GP-6423: docs GP-6423: slashes GP-6423: lldb variants GP-6423: bool fixed GP-6423: str->bool GP-6423: gdb/lldb w/ .init GP-6423: tmp
This commit is contained in:
@@ -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|
|
||||
|
||||
@@ -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 <html><body width="300px">
|
||||
#@desc <h3>Launch with <tt>gdb</tt> via <tt>ssh</tt> to a remote Windows machine</h3>
|
||||
#@desc <p>
|
||||
#@desc This will launch the target on a remote Windows machine using <tt>gdb</tt> via <tt>ssh</tt>.
|
||||
#@desc For setup instructions, press <b>F1</b>.
|
||||
#@desc </p>
|
||||
#@desc </body></html>
|
||||
#@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" "<SELF>"
|
||||
|
||||
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
|
||||
}
|
||||
@@ -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 <html><body width="300px">
|
||||
#@desc <h3>Launch with <tt>gdb</tt> via <tt>ssh</tt></h3>
|
||||
#@desc <p>
|
||||
#@desc This will launch the target on a remote machine using <tt>gdb</tt> via <tt>ssh</tt>.
|
||||
#@desc For setup instructions, press <b>F1</b>.
|
||||
#@desc </p>
|
||||
#@desc </body></html>
|
||||
#@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" "<SELF>"
|
||||
|
||||
echo "Installing Wheels into GDB's embedded Python"
|
||||
do-installation
|
||||
fi
|
||||
@@ -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
|
||||
@@ -11,6 +11,9 @@
|
||||
<tocdef id="gdb_ssh" text="Via SSH"
|
||||
target="help/topics/gdb/gdb.html#ssh" />
|
||||
|
||||
<tocdef id="gdb_ssh_win" text="Via SSH (to Windows cmd shell)"
|
||||
target="help/topics/gdb/gdb.html#ssh-win" />
|
||||
|
||||
<tocdef id="gdb_gdbserver_ssh" text="gdbserver via SSH"
|
||||
target="help/topics/gdb/gdb.html#gdbserver_ssh" />
|
||||
|
||||
|
||||
@@ -191,6 +191,20 @@ python3 -m pip install --no-index -f ~/ghidra-pypkg/ ghidragdb
|
||||
<LI>Note there is no option to create a second Terminal (TTY) for the target.</LI>
|
||||
</UL>
|
||||
|
||||
<H2><A name="ssh-win"></A>Via SSH (to Windows cmd shell)</H2>
|
||||
|
||||
<P>Essentially identical to <TT>ssh</TT> from the standpoint of usage and options, this launcher
|
||||
runs <TT>gdb</TT> on a remote Windows system via <TT>ssh</TT>. The behavior of <TT>ssh</TT>
|
||||
on Windows, however, requires a slightly different mechanism. The command options are used to
|
||||
rewrite the <TT>gdbinit_template</TT> in the <TT>support</TT> directory. The result is copied to
|
||||
<TT>.gdbinit</TT> 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 <TT>ssh</TT> configuration.
|
||||
</P>
|
||||
|
||||
<P>Once the <TT>.gdbinit</TT> 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 <TT>gdb</TT> on the remote box.
|
||||
</P>
|
||||
|
||||
<H2><A name="gdbserver_ssh"></A><TT>gdbserver</TT> via SSH</H2>
|
||||
|
||||
<P>This works similarly to the GDB via SSH launcher, but instead of tunneling the Trace RMI
|
||||
|
||||
@@ -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|
|
||||
|
||||
@@ -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 <html><body width="300px">
|
||||
#@desc <h3>Launch with <tt>lldb</tt> via <tt>ssh</tt> to a remote Windows machine</h3>
|
||||
#@desc <p>
|
||||
#@desc This will launch the target on a remote Windows machine using <tt>lldb</tt> via <tt>ssh</tt>.
|
||||
#@desc For setup instructions, press <b>F1</b>.
|
||||
#@desc </p>
|
||||
#@desc </body></html>
|
||||
#@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" "<SELF>"
|
||||
|
||||
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
|
||||
}
|
||||
@@ -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 <html><body width="300px">
|
||||
#@desc <h3>Launch with <tt>lldb</tt> via <tt>ssh</tt></h3>
|
||||
#@desc <p>
|
||||
#@desc This will launch the target on a remote machine using <tt>lldb</tt> via <tt>ssh</tt>.
|
||||
#@desc For setup instructions, press <b>F1</b>.
|
||||
#@desc </p>
|
||||
#@desc </body></html>
|
||||
#@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" "<SELF>"
|
||||
|
||||
echo "Installing Wheels into LLDB's embedded Python"
|
||||
do-installation
|
||||
fi
|
||||
@@ -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
|
||||
@@ -17,6 +17,9 @@
|
||||
<tocdef id="lldb_ssh" text="Via SSH"
|
||||
target="help/topics/lldb/lldb.html#ssh" />
|
||||
|
||||
<tocdef id="lldb_ssh_win" text="Via SSH (to Windows cmd shell)"
|
||||
target="help/topics/lldb/lldb.html#ssh-win" />
|
||||
|
||||
<tocdef id="lldb_android" text="Android (native)"
|
||||
target="help/topics/lldb/lldb.html#android" />
|
||||
|
||||
|
||||
@@ -206,7 +206,13 @@ perl -i -pe 's/(?<=pendingNMI\x00{4})\x00/\x01/' macOS_15-1234567.vmss
|
||||
<P>This works the same as the <A href="help/topics/gdb/gdb.html#ssh">GDB via SSH</A> launcher,
|
||||
but runs <TT>lldb</TT> on a remote system via <TT>ssh</TT>.</P>
|
||||
|
||||
<H2><A name="android"></A>Android</H2>
|
||||
<H2><A name="ssh-win"></A>Via SSH (to Windows cmd shell)</H2>
|
||||
|
||||
<P> This works the same as the <A href="help/topics/gdb/gdb.html#ssh-win">GDB via SSH (to Windows cmd shell)</A>
|
||||
launcher, but runs <TT>lldb</TT> on a remote Windows system via <TT>ssh</TT>.
|
||||
</P>
|
||||
|
||||
<H2><A name="android"></A>Android</H2>
|
||||
|
||||
<P>This has the same options as the <A href="#ssh">LLDB via SSH</A> launcher, which are
|
||||
necessary for connecting to the Android debugger, but uses <B>Device</B> in place of <B>Host</B>
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user