GP-5538: Add 'Image' to remote-[gdb,lldb].*. Convert to powershell.

This commit is contained in:
Dan
2025-04-04 17:15:41 +00:00
parent 7ab4989d4b
commit b7570e1f52
22 changed files with 341 additions and 171 deletions
@@ -4,7 +4,7 @@ Module.manifest||GHIDRA||||END|
README.md||GHIDRA||||END|
data/debugger-launchers/local-gdb.bat||GHIDRA||||END|
data/debugger-launchers/qemu-sys-gdb.bat||GHIDRA||||END|
data/debugger-launchers/remote-gdb.bat||GHIDRA||||END|
data/debugger-launchers/remote-gdb.ps1||GHIDRA||||END|
data/debugger-launchers/ssh-gdb.bat||GHIDRA||||END|
data/debugger-launchers/ssh-gdbserver.bat||GHIDRA||||END|
data/scripts/fallback_info_proc_mappings.gdb||GHIDRA||||END|
@@ -1,4 +1,4 @@
#!/usr/bin/bash
#!/usr/bin/env bash
## ###
# IP: GHIDRA
#
@@ -1,4 +1,4 @@
#!/usr/bin/bash
#!/usr/bin/env bash
## ###
# IP: GHIDRA
#
@@ -1,4 +1,4 @@
#!/usr/bin/bash
#!/usr/bin/env bash
## ###
# IP: GHIDRA
#
@@ -66,32 +66,27 @@ fi
# Give QEMU a moment to open the socket
sleep 0.1
gdb_args=(
-q
-ex "set pagination off"
-ex "set confirm off"
-ex "show version"
-ex "python import ghidragdb"
-ex "set architecture $OPT_ARCH"
-ex "set endian $OPT_ENDIAN"
-ex "file \"$target_image\""
-ex "ghidra trace connect \"$GHIDRA_TRACE_RMI_ADDR\""
-ex "ghidra trace start"
-ex "ghidra trace sync-enable"
-ex "target remote localhost:$QEMU_GDB"
-ex "set confirm on"
-ex "set pagination on"
)
declare -a args
# If using OPT_PULL_ALL_SECTIONS, append instructions to push all sections from qemu
args+=(-q)
args+=(-ex "set pagination off")
args+=(-ex "set confirm off")
args+=(-ex "show version")
args+=(-ex "python import ghidragdb")
args+=(-ex "set architecture $OPT_ARCH")
args+=(-ex "set endian $OPT_ENDIAN")
args+=(-ex "file '$target_image'")
args+=(-ex "ghidra trace connect '$GHIDRA_TRACE_RMI_ADDR'")
args+=(-ex "ghidra trace start")
args+=(-ex "ghidra trace sync-enable")
args+=(-ex "target remote localhost:$QEMU_GDB")
if [ "$OPT_PULL_ALL_SECTIONS" = "true" ]
then
gdb_args+=(
-ex "ghidra trace tx-start put-all-sections"
-ex "ghidra trace put-sections -all-objects"
-ex "ghidra trace tx-commit"
)
args+=(-ex "ghidra trace tx-start put-all-sections")
args+=(-ex "ghidra trace put-sections -all-objects")
args+=(-ex "ghidra trace tx-commit")
fi
args+=(-ex "set confirm on")
args+=(-ex "set pagination on")
IFS=""
"$OPT_GDB_PATH" ${gdb_args[*]}
"$OPT_GDB_PATH" "${args[@]}"
@@ -1,4 +1,4 @@
#!/usr/bin/bash
#!/usr/bin/env bash
## ###
# IP: GHIDRA
#
@@ -1,49 +0,0 @@
::@title remote gdb
::@desc <html><body width="300px">
::@desc <h3>Launch with local <tt>gdb</tt> and connect to a stub (e.g., <tt>gdbserver</tt>)</h3>
::@desc <p>
::@desc This will start <tt>gdb</tt> on the local system and then use it to connect to the remote system.
::@desc For setup instructions, press <b>F1</b>.
::@desc </p>
::@desc </body></html>
::@menu-group remote
::@icon icon.debugger
::@help gdb#remote
::@enum TargetType:str remote extended-remote
::@enum Endian:str auto big little
::@env OPT_TARGET_TYPE:TargetType="remote" "Target" "The type of remote target"
::@env OPT_HOST:str="localhost" "Host" "The hostname of the target"
::@env OPT_PORT:int=9999 "Port" "The host's listening port"
::@env OPT_GDB_PATH:file="gdb" "gdb command" "The path to gdb on the local system. Omit the full path to resolve using the system PATH."
::@env OPT_ARCH:str="auto" "Architecture" "Target architecture override"
::@env OPT_ENDIAN:Endian="auto" "Endian" "Target byte order"
@echo off
set PYTHONPATH0=%GHIDRA_HOME%\Ghidra\Debug\Debugger-agent-gdb\pypkg\src
set PYTHONPATH1=%GHIDRA_HOME%\Ghidra\Debug\Debugger-rmi-trace\pypkg\src
IF EXIST %GHIDRA_HOME%\.git (
set PYTHONPATH0=%GHIDRA_HOME%\Ghidra\Debug\Debugger-agent-gdb\build\pypkg\src
set PYTHONPATH1=%GHIDRA_HOME%\Ghidra\Debug\Debugger-rmi-trace\build\pypkg\src
)
IF EXIST %GHIDRA_HOME%\ghidra\.git (
set PYTHONPATH0=%GHIDRA_HOME%\ghidra\Ghidra\Debug\Debugger-agent-gdb\build\pypkg\src
set PYTHONPATH1=%GHIDRA_HOME%\ghidra\Ghidra\Debug\Debugger-rmi-trace\build\pypkg\src
)
set PYTHONPATH=%PYTHONPATH1%;%PYTHONPATH0%;%PYTHONPATH%
"%OPT_GDB_PATH%" ^
-q ^
-ex "set pagination off" ^
-ex "set confirm off" ^
-ex "show version" ^
-ex "python import ghidragdb" ^
-ex "set architecture %OPT_ARCH%" ^
ex "set endian %OPT_ENDIAN%" ^
-ex "echo Connecting to %OPT_HOST%:%OPT_PORT%... " ^
-ex "target %OPT_TARGET_TYPE% %OPT_HOST%:%OPT_PORT%" ^
-ex "ghidra trace connect '%GHIDRA_TRACE_RMI_ADDR%'" ^
-ex "ghidra trace start" ^
-ex "ghidra trace sync-enable" ^
-ex "ghidra trace sync-synth-stopped" ^
-ex "set confirm on" ^
-ex "set pagination on"
@@ -0,0 +1,61 @@
#@title remote gdb
#@image-opt arg:1
#@desc <html><body width="300px">
#@desc <h3>Launch with local <tt>gdb</tt> and connect to a stub (e.g., <tt>gdbserver</tt>)</h3>
#@desc <p>
#@desc This will start <tt>gdb</tt> on the local system and then use it to connect to the remote system.
#@desc For setup instructions, press <b>F1</b>.
#@desc </p>
#@desc </body></html>
#@menu-group remote
#@icon icon.debugger
#@help gdb#remote
#@enum TargetType:str remote extended-remote
#@enum Endian:str auto big little
#@arg :file "Image" "The target binary executable image (a copy on the local system)"
#@env OPT_TARGET_TYPE:TargetType="remote" "Target" "The type of remote target"
#@env OPT_HOST:str="localhost" "Host" "The hostname of the target"
#@env OPT_PORT:int=9999 "Port" "The host's listening port"
#@env OPT_GDB_PATH:file="gdb" "gdb command" "The path to gdb on the local system. Omit the full path to resolve using the system PATH."
#@env OPT_ARCH:str="auto" "Architecture" "Target architecture override"
#@env OPT_ENDIAN:Endian="auto" "Endian" "Target byte order"
[IO.DirectoryInfo] $repo = "$Env:GHIDRA_HOME\.git"
[IO.DirectoryInfo] $repoParent = "$Env:GHIDRA_HOME\ghidra\.git"
if ($repo.Exists) {
$pypathGdb = "$Env:GHIDRA_HOME\Ghidra\Debug\Debugger-agent-gdb\build\pypkg\src"
$pypathTrace = "$Env:GHIDRA_HOME\Ghidra\Debug\Debugger-rmi-trace\build\pypkg\src"
}
elseif ($repoParent.Exists) {
$pypathGdb = "$Env:GHIDRA_HOME\ghidra\Ghidra\Debug\Debugger-agent-gdb\build\pypkg\src"
$pypathTrace = "$Env:GHIDRA_HOME\ghidra\Ghidra\Debug\Debugger-rmi-trace\build\pypkg\src"
}
else {
$pypathGdb = "$Env:GHIDRA_HOME\Ghidra\Debug\Debugger-agent-gdb\pypkg\src"
$pypathTrace = "$Env:GHIDRA_HOME\Ghidra\Debug\Debugger-rmi-trace\pypkg\src"
}
$Env:PYTHONPATH = "$pypathGdb;$pypathTrace;$Env:PYTHONPATH"
$arglist = @()
$arglist+=("-q")
$arglist+=("-ex", "`"set pagination off`"")
$arglist+=("-ex", "`"set confirm off`"")
$arglist+=("-ex", "`"show version`"")
$arglist+=("-ex", "`"python import ghidragdb`"")
$arglist+=("-ex", "`"set architecture $Env:OPT_ARCH`"")
$arglist+=("-ex", "`"set endian $Env:OPT_ENDIAN`"")
if ("$($args[0])" -ne "") {
$image = $args[0] -replace "\\", "\\\\"
$arglist+=("-ex", "`"file '$image'`"")
}
$arglist+=("-ex", "`"echo Connecting to $Env:OPT_HOST`:$Env:OPT_PORT... `"")
$arglist+=("-ex", "`"target $Env:OPT_TARGET_TYPE $Env:OPT_HOST`:$Env:OPT_PORT`"")
$arglist+=("-ex", "`"ghidra trace connect '$Env:GHIDRA_TRACE_RMI_ADDR'`"")
$arglist+=("-ex", "`"ghidra trace start`"")
$arglist+=("-ex", "`"ghidra trace sync-enable`"")
$arglist+=("-ex", "`"ghidra trace sync-synth-stopped`"")
$arglist+=("-ex", "`"set confirm on`"")
$arglist+=("-ex", "`"set pagination on`"")
Start-Process -FilePath $Env:OPT_GDB_PATH -ArgumentList $arglist -NoNewWindow -Wait
@@ -15,6 +15,7 @@
# limitations under the License.
##
#@title remote gdb
#@image-opt arg:1
#@desc <html><body width="300px">
#@desc <h3>Launch with local <tt>gdb</tt> and connect to a stub (e.g., <tt>gdbserver</tt>)</h3>
#@desc <p>
@@ -27,6 +28,7 @@
#@help gdb#remote
#@enum TargetType:str remote extended-remote
#@enum Endian:str auto big little
#@arg :file "Image" "The target binary executable image (a copy on the local system)"
#@env OPT_TARGET_TYPE:TargetType="remote" "Target" "The type of remote target"
#@env OPT_HOST:str="localhost" "Host" "The hostname of the target"
#@env OPT_PORT:int=9999 "Port" "The host's listening port"
@@ -47,19 +49,26 @@ else
export PYTHONPATH=$GHIDRA_HOME/Ghidra/Debug/Debugger-rmi-trace/pypkg/src:$PYTHONPATH
fi
"$OPT_GDB_PATH" \
-q \
-ex "set pagination off" \
-ex "set confirm off" \
-ex "show version" \
-ex "python import ghidragdb" \
-ex "set architecture $OPT_ARCH" \
-ex "set endian $OPT_ENDIAN" \
-ex "echo Connecting to $OPT_HOST:$OPT_PORT... " \
-ex "target $OPT_TARGET_TYPE $OPT_HOST:$OPT_PORT" \
-ex "ghidra trace connect \"$GHIDRA_TRACE_RMI_ADDR\"" \
-ex "ghidra trace start" \
-ex "ghidra trace sync-enable" \
-ex "ghidra trace sync-synth-stopped" \
-ex "set confirm on" \
-ex "set pagination on"
declare -a args
args+=(-q)
args+=(-ex "set pagination off")
args+=(-ex "set confirmation off")
args+=(-ex "show version")
args+=(-ex "python import ghidragdb")
args+=(-ex "set architecture $OPT_ARCH")
args+=(-ex "set endian $OPT_ENDIAN")
if [ -n "$1" ]
then
args+=(-ex "file '$1'")
fi
args+=(-ex "echo Connecting to $OPT_HOST:$OPT_PORT...")
args+=(-ex "target $OPT_TARGET_TYPE $OPT_HOST:$OPT_PORT")
args+=(-ex "ghidra trace connect '$GHIDRA_TRACE_RMI_ADDR'")
args+=(-ex "ghidra trace start")
args+=(-ex "ghidra trace sync-enable")
args+=(-ex "ghidra trace sync-synth-stopped")
args+=(-ex "set confirm on")
args+=(-ex "set pagination on")
"$OPT_GDB_PATH" "${args[@]}"
@@ -1,4 +1,4 @@
#!/usr/bin/bash
#!/usr/bin/env bash
## ###
# IP: GHIDRA
#
@@ -1,4 +1,4 @@
#!/usr/bin/bash
#!/usr/bin/env bash
## ###
# IP: GHIDRA
#
@@ -1,4 +1,4 @@
#!/usr/bin/bash
#!/usr/bin/env bash
## ###
# IP: GHIDRA
#
@@ -7,7 +7,7 @@ build.gradle||GHIDRA||||END|
data/debugger-launchers/android-lldb.bat||GHIDRA||||END|
data/debugger-launchers/kernel-lldb.bat||GHIDRA||||END|
data/debugger-launchers/local-lldb.bat||GHIDRA||||END|
data/debugger-launchers/remote-lldb.bat||GHIDRA||||END|
data/debugger-launchers/remote-lldb.ps1||GHIDRA||||END|
data/debugger-launchers/ssh-lldb.bat||GHIDRA||||END|
src/main/help/help/TOC_Source.xml||GHIDRA||||END|
src/main/help/help/topics/lldb/lldb.html||GHIDRA||||END|
@@ -1,49 +0,0 @@
::@title remote lldb
::@desc <html><body width="300px">
::@desc <h3>Launch with local <tt>lldb</tt> and connect to a stub (e.g., <tt>gdbserver</tt>)</h3>
::@desc <p>
::@desc This will start <tt>lldb</tt> on the local system and then use it to connect to the remote system.
::@desc For setup instructions, press <b>F1</b>.
::@desc </p>
::@desc </body></html>
::@menu-group remote
::@icon icon.debugger
::@help lldb#remote
::@env OPT_HOST:str="localhost" "Host" "The hostname of the target"
::@env OPT_PORT:str="9999" "Port" "The host's listening port"
::@env OPT_ARCH:str="" "Architecture" "Target architecture override"
::@env OPT_LLDB_PATH:file="lldb" "lldb command" "The path to lldb on the local system. Omit the full path to resolve using the system PATH."
@echo off
set PYTHONPATH0=%GHIDRA_HOME%\Ghidra\Debug\Debugger-agent-lldb\pypkg\src
set PYTHONPATH1=%GHIDRA_HOME%\Ghidra\Debug\Debugger-rmi-trace\pypkg\src
IF EXIST %GHIDRA_HOME%\.git (
set PYTHONPATH0=%GHIDRA_HOME%\Ghidra\Debug\Debugger-agent-lldb\build\pypkg\src
set PYTHONPATH1=%GHIDRA_HOME%\Ghidra\Debug\Debugger-rmi-trace\build\pypkg\src
)
IF EXIST %GHIDRA_HOME%\ghidra\.git (
set PYTHONPATH0=%GHIDRA_HOME%\ghidra\Ghidra\Debug\Debugger-agent-lldb\build\pypkg\src
set PYTHONPATH1=%GHIDRA_HOME%\ghidra\Ghidra\Debug\Debugger-rmi-trace\build\pypkg\src
)
set PYTHONPATH=%PYTHONPATH1%;%PYTHONPATH0%;%PYTHONPATH%
IF %OPT_ARCH%=="" (
"$OPT_LLDB_PATH" ^
-o "version" ^
-o "script import ghidralldb" ^
-o "gdb-remote %OPT_HOST%:%OPT_PORT%" ^
-o "ghidra trace connect %GHIDRA_TRACE_RMI_ADDR%" ^
-o "ghidra trace start" ^
-o "ghidra trace sync-enable" ^
-o "ghidra trace sync-synth-stopped"
) ELSE (
"$OPT_LLDB_PATH" ^
-o "version" ^
-o "script import ghidralldb" ^
-o "settings set target.default-arch %OPT_ARCH%"
-o "gdb-remote %OPT_HOST%:%OPT_PORT%" ^
-o "ghidra trace connect %GHIDRA_TRACE_RMI_ADDR%" ^
-o "ghidra trace start" ^
-o "ghidra trace sync-enable" ^
-o "ghidra trace sync-synth-stopped"
)
@@ -0,0 +1,52 @@
#@title remote lldb
#@image-opt arg:1
#@desc <html><body width="300px">
#@desc <h3>Launch with local <tt>lldb</tt> and connect to a stub (e.g., <tt>gdbserver</tt>)</h3>
#@desc <p>
#@desc This will start <tt>lldb</tt> on the local system and then use it to connect to the remote system.
#@desc For setup instructions, press <b>F1</b>.
#@desc </p>
#@desc </body></html>
#@menu-group remote
#@icon icon.debugger
#@help lldb#remote
#@arg :file "Image" "The target binary executable image (a copy on the local system)"
#@env OPT_HOST:str="localhost" "Host" "The hostname of the target"
#@env OPT_PORT:str="9999" "Port" "The host's listening port"
#@env OPT_ARCH:str="" "Architecture" "Target architecture override"
#@env OPT_LLDB_PATH:file="lldb" "lldb command" "The path to lldb on the local system. Omit the full path to resolve using the system PATH."
[IO.DirectoryInfo] $repo = "$Env:GHIDRA_HOME\.git"
[IO.DirectoryInfo] $repoParent = "$Env:GHIDRA_HOME\ghidra\.git"
if ($repo.Exists) {
$pypathLldb = "$Env:GHIDRA_HOME\Ghidra\Debug\Debugger-agent-lldb\build\pypkg\src"
$pypathTrace = "$Env:GHIDRA_HOME\Ghidra\Debug\Debugger-rmi-trace\build\pypkg\src"
}
elseif ($repoParent.Exists) {
$pypathLldb = "$Env:GHIDRA_HOME\ghidra\Ghidra\Debug\Debugger-agent-lldb\build\pypkg\src"
$pypathTrace = "$Env:GHIDRA_HOME\ghidra\Ghidra\Debug\Debugger-rmi-trace\build\pypkg\src"
}
else {
$pypathLldb = "$Env:GHIDRA_HOME\Ghidra\Debug\Debugger-agent-lldb\pypkg\src"
$pypathTrace = "$Env:GHIDRA_HOME\Ghidra\Debug\Debugger-rmi-trace\pypkg\src"
}
$Env:PYTHONPATH = "$pypathLldb;$pypathTrace;$Env:PYTHONPATH"
$arglist = @()
$arglist+=("-o", "`"version`"")
$arglist+=("-o", "`"script import ghidralldb`"")
if ("$Env:OPT_ARCH" -ne "") {
$arglist+=("-o", "`"settings set target.default-arch $Env:OPT_ARCH`"")
}
if ("$($args[0])" -ne "") {
$image = $args[0]
$arglist+=("-o", "`"file '$image'`"")
}
$arglist+=("-o", "`"gdb-remote $Env:OPT_HOST`:$Env:OPT_PORT`"")
$arglist+=("-o", "`"ghidra trace connect '$Env:GHIDRA_TRACE_RMI_ADDR'`"")
$arglist+=("-o", "`"ghidra trace start`"")
$arglist+=("-o", "`"ghidra trace sync-enable`"")
$arglist+=("-o", "`"ghidra trace sync-synth-stopped`"")
Start-Process -FilePath $Env:OPT_LLDB_PATH -ArgumentList $arglist -NoNewWindow -Wait
@@ -15,6 +15,7 @@
# limitations under the License.
##
#@title remote lldb
#@image-opt arg:1
#@desc <html><body width="300px">
#@desc <h3>Launch with local <tt>lldb</tt> and connect to a stub (e.g., <tt>gdbserver</tt>)</h3>
#@desc <p>
@@ -25,6 +26,7 @@
#@menu-group remote
#@icon icon.debugger
#@help lldb#remote
#@arg :file "Image" "The target binary executable image (a copy on the local system)"
#@env OPT_HOST:str="localhost" "Host" "The hostname of the target"
#@env OPT_PORT:str="9999" "Port" "The host's listening port"
#@env OPT_ARCH:str="" "Architecture" "Target architecture override"
@@ -43,19 +45,22 @@ else
export PYTHONPATH=$GHIDRA_HOME/Ghidra/Debug/Debugger-rmi-trace/pypkg/src:$PYTHONPATH
fi
if [ -z "$OPT_ARCH" ]
then
archcmd=
else
archcmd=-o "settings set target.default-arch $OPT_ARCH"
fi
declare -a args
"$OPT_LLDB_PATH" \
-o "version" \
-o "script import ghidralldb" \
$archcmd \
-o "gdb-remote $OPT_HOST:$OPT_PORT" \
-o "ghidra trace connect \"$GHIDRA_TRACE_RMI_ADDR\"" \
-o "ghidra trace start" \
-o "ghidra trace sync-enable" \
-o "ghidra trace sync-synth-stopped"
args+=(-o version)
args+=(-o "script import ghidralldb")
if [ -n "$OPT_ARCH" ]
then
args+=(-o "settings set target.default-arch $OPT_ARCH")
fi
if [ -n "$1" ]
then
args+=(-o "file '$1'")
fi
args+=(-o "gdb-remote $OPT_HOST:$OPT_PORT")
args+=(-o "ghidra trace connect '$GHIDRA_TRACE_RMI_ADDR'")
args+=(-o "ghidra trace start")
args+=(-o "ghidra trace sync-enable")
args+=(-o "ghidra trace sync-synth-stopped")
"$OPT_LLDB_PATH" "${args[@]}"
@@ -1,4 +1,4 @@
#!/usr/bin/bash
#!/usr/bin/env bash
## ###
# IP: GHIDRA
#
@@ -1698,8 +1698,8 @@ def should_query_regions() -> bool:
def put_regions() -> None:
regions = []
proc = util.get_process()
if should_query_regions():
proc = util.get_process()
try:
regions = util.REGION_INFO_READER.get_regions()
except Exception:
@@ -17,12 +17,8 @@ package ghidra.app.plugin.core.debug.gui.tracermi.launcher;
import java.io.File;
import java.io.FileNotFoundException;
import java.net.SocketAddress;
import java.util.List;
import java.util.Map;
import ghidra.app.plugin.core.debug.gui.tracermi.launcher.ScriptAttributesParser.ScriptAttributes;
import ghidra.debug.api.ValStr;
import ghidra.program.model.listing.Program;
/**
@@ -0,0 +1,83 @@
/* ###
* 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.
*/
package ghidra.app.plugin.core.debug.gui.tracermi.launcher;
import java.io.File;
import java.io.FileNotFoundException;
import java.net.SocketAddress;
import java.util.List;
import java.util.Map;
import ghidra.app.plugin.core.debug.gui.tracermi.launcher.ScriptAttributesParser.ScriptAttributes;
import ghidra.debug.api.ValStr;
import ghidra.program.model.listing.Program;
/**
* A launcher implemented by a Window PowerShell file.
*
* <p>
* The script must start with an attributes header in a comment block. See
* {@link ScriptAttributesParser}.
*/
public class PowerShellScriptTraceRmiLaunchOffer extends AbstractScriptTraceRmiLaunchOffer {
public static final String REM = "#";
public static final int REM_LEN = REM.length();
/**
* Create a launch offer from the given PowerShell file.
*
* @param plugin the launcher service plugin
* @param program the current program, usually the target image. In general, this should be used
* for at least two purposes. 1) To populate the default command line. 2) To ensure
* the target image is mapped in the resulting target trace.
* @param script the PowerShell file that implements this offer
* @return the offer
* @throws FileNotFoundException if the batch file does not exist
*/
public static PowerShellScriptTraceRmiLaunchOffer create(TraceRmiLauncherServicePlugin plugin,
Program program, File script) throws FileNotFoundException {
ScriptAttributesParser parser = new ScriptAttributesParser() {
@Override
protected boolean ignoreLine(int lineNo, String line) {
return line.isBlank();
}
@Override
protected String removeDelimiter(String line) {
String stripped = line.stripLeading();
if (!stripped.startsWith(REM)) {
return null;
}
return stripped.substring(REM_LEN);
}
};
ScriptAttributes attrs = parser.parseFile(script);
return new PowerShellScriptTraceRmiLaunchOffer(plugin, program, script,
"PS1_FILE:" + script.getName(), attrs);
}
private PowerShellScriptTraceRmiLaunchOffer(TraceRmiLauncherServicePlugin plugin,
Program program, File script, String configName, ScriptAttributes attrs) {
super(plugin, program, script, configName, attrs);
}
@Override
protected void prepareSubprocess(List<String> commandLine, Map<String, String> env,
Map<String, ValStr<?>> args, SocketAddress address) {
super.prepareSubprocess(commandLine, env, args, address);
commandLine.add(0, "powershell");
}
}
@@ -0,0 +1,54 @@
/* ###
* 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.
*/
package ghidra.app.plugin.core.debug.gui.tracermi.launcher;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import generic.jar.ResourceFile;
import ghidra.debug.api.tracermi.TraceRmiLaunchOffer;
import ghidra.framework.OperatingSystem;
import ghidra.program.model.listing.Program;
import ghidra.util.Msg;
public class PowerShellScriptTraceRmiLaunchOpinion extends AbstractTraceRmiLaunchOpinion {
@Override
public Collection<TraceRmiLaunchOffer> getOffers(TraceRmiLauncherServicePlugin plugin,
Program program) {
if (OperatingSystem.CURRENT_OPERATING_SYSTEM == OperatingSystem.WINDOWS) {
return getScriptPaths(plugin.getTool())
.flatMap(rf -> Stream.of(rf.listFiles(crf -> crf.getName().endsWith(".ps1"))))
.flatMap(sf -> createOffer(plugin, program, sf))
.collect(Collectors.toList());
}
return List.of();
}
protected Stream<TraceRmiLaunchOffer> createOffer(TraceRmiLauncherServicePlugin plugin,
Program program, ResourceFile scriptFile) {
try {
return Stream.of(PowerShellScriptTraceRmiLaunchOffer.create(plugin, program,
scriptFile.getFile(false)));
}
catch (Exception e) {
Msg.error(this, "Could not offer " + scriptFile + ": " + e.getMessage(), e);
return Stream.of();
}
}
}
@@ -45,6 +45,7 @@ import ghidra.framework.model.*;
import ghidra.framework.plugintool.AutoService;
import ghidra.framework.plugintool.AutoService.Wiring;
import ghidra.framework.plugintool.annotation.AutoServiceConsumed;
import ghidra.framework.store.local.LocalFileSystem;
import ghidra.program.model.address.*;
import ghidra.program.model.lang.*;
import ghidra.program.util.DefaultLanguageService;
@@ -861,8 +862,20 @@ public class TraceRmiHandler extends AbstractTraceRmiConnection {
return ReplyCreateTrace.getDefaultInstance();
}
protected static String sanitizeName(String name) {
StringBuffer buf = new StringBuffer(name.length());
for (int i = 0; i < name.length(); i++) {
char c = name.charAt(i);
buf.append(LocalFileSystem.isValidNameCharacter(c) ? c : '_');
}
return buf.toString();
}
protected static List<String> sanitizePath(String path) {
return Stream.of(path.split("\\\\|/")).filter(p -> !p.isBlank()).toList();
return Stream.of(path.split("\\\\|/"))
.filter(n -> !n.isBlank())
.map(n -> sanitizeName(n))
.toList();
}
protected ReplyDeleteBytes handleDeleteBytes(RequestDeleteBytes req)
@@ -4,9 +4,9 @@
* 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.