mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 19:42:36 +02:00
GP-5538: Add 'Image' to remote-[gdb,lldb].*. Convert to powershell.
This commit is contained in:
parent
7ab4989d4b
commit
b7570e1f52
22 changed files with 341 additions and 171 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue