GP-6445: post review

GP-6445: functional remote tests for dbgeng & x64dbg
GP-6445: more progress?
GP-6445: untested
GP-445: first pass (gdb)
GP-6445: gdb connector tests workingGP-6445: gdb+lldb connectors test workingGP-6445: x64dbg connector test
This commit is contained in:
d-millar
2026-02-23 10:40:50 -05:00
parent cfc5dd2b3a
commit fa7fae0579
23 changed files with 393 additions and 83 deletions
@@ -15,9 +15,8 @@
*/
package agent;
import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import java.io.FileOutputStream;
import java.io.OutputStream;
@@ -91,16 +90,24 @@ public abstract class AbstractRmiConnectorsTest
assertEquals("pip failed", 0, result);
}
protected boolean isWindows() {
return OperatingSystem.CURRENT_OPERATING_SYSTEM == OperatingSystem.WINDOWS;
}
protected PathIsFile chooseImage() {
if (OperatingSystem.CURRENT_OPERATING_SYSTEM == OperatingSystem.WINDOWS) {
if (isWindows()) {
return new PathIsFile(Path.of("C:\\Windows\\notepad.exe"));
}
return new PathIsFile(Path.of("/bin/ls"));
}
protected String chooseImageToString() {
return chooseImage().path().toString();
}
protected PathIsFile findQemu(String bin) {
if (OperatingSystem.CURRENT_OPERATING_SYSTEM == OperatingSystem.WINDOWS) {
return new PathIsFile(Path.of("C:\\msys64\\ucrt64\bin\\").resolve(bin));
if (isWindows()) {
return new PathIsFile(Path.of("C:\\msys64\\ucrt64\\bin\\").resolve(bin));
}
return new PathIsFile(Path.of(bin));
}
@@ -16,13 +16,14 @@
package agent.dbgeng.rmi;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
@@ -52,7 +53,27 @@ public class DbgEngConnectorsTest extends AbstractRmiConnectorsTest {
// Make sure system doesn't cause path failures to pass
unpip("ghidradbg", "ghidratrace");
// Ensure a compatible version of protobuf
pip("protobuf==6.31.0");
pip("protobuf>=6.31.0");
}
@Test
public void testLocalDbgWithImage() throws Exception {
try (LaunchResult result = doLaunch("dbgeng", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("env:OPT_PYTHON_EXE",
new PathIsFile(Path.of(getPythonCmd())))))) {
checkResult(result);
}
}
@Test
public void testLocalDbgWithImageBat() throws Exception {
try (LaunchResult result = doLaunch("dbgeng (.bat)", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("env:OPT_PYTHON_EXE",
new PathIsFile(Path.of(getPythonCmd())))))) {
checkResult(result);
}
}
@Test
@@ -61,7 +82,7 @@ public class DbgEngConnectorsTest extends AbstractRmiConnectorsTest {
try (LaunchResult result = doLaunch("dbgeng", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("env:OPT_PYTHON_EXE",
new PathIsFile(Path.of("C:\\Python313\\python.exe")))))) {
new PathIsFile(Path.of(getPythonCmd())))))) {
assertThat(result.exception(), instanceOf(EarlyTerminationException.class));
assertThat(result.sessions().get("Shell").content(),
containsString("Would you like to install"));
@@ -69,17 +90,77 @@ public class DbgEngConnectorsTest extends AbstractRmiConnectorsTest {
try (LaunchResult result = doLaunch("dbgeng", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("env:OPT_PYTHON_EXE",
new PathIsFile(Path.of("C:\\Python313\\python.exe")))))) {
new PathIsFile(Path.of(getPythonCmd())))))) {
checkResult(result);
}
}
@Test
public void testLocalDbgWithImage() throws Exception {
try (LaunchResult result = doLaunch("dbgeng", Map.ofEntries(
public void testLocalDbgSetupBat() throws Exception {
pipOob("protobuf==3.19.0");
try (LaunchResult result = doLaunch("dbgeng (.bat)", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("env:OPT_PYTHON_EXE",
new PathIsFile(Path.of("C:\\Python313\\python.exe")))))) {
new PathIsFile(Path.of(getPythonCmd())))))) {
assertThat(result.exception(), instanceOf(EarlyTerminationException.class));
assertThat(result.sessions().get("Shell").content(),
containsString("Would you like to install"));
}
try (LaunchResult result = doLaunch("dbgeng (.bat)", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("env:OPT_PYTHON_EXE",
new PathIsFile(Path.of(getPythonCmd())))))) {
checkResult(result);
}
}
// NB: The next three tests tend to leave residual python processes running
// which will cause permissions problems when subsequent tests attempt
// to access python's site-packages
@Test
public void testDbgViaSsh() throws Exception {
pip("ghidradbg==%s".formatted(Application.getApplicationVersion()));
try (LaunchResult result = doLaunch("dbgeng via ssh", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("OPT_HOST", "localhost")))) {
checkResult(result);
}
}
@Test
public void testDbgViaSshSetupProtobuf() throws Exception {
// NB: If you fail on the next line, delete everything (ghidradbg,
// ghidratrace, google, protobuf) from site-packages
pip("ghidradbg==%s".formatted(Application.getApplicationVersion()));
// Overwrite with an incompatible version we don't include
pipOob("protobuf==3.19.0");
try (LaunchResult result = doLaunch("dbgeng via ssh", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("OPT_HOST", "localhost")))) {
assertTrue(result.exception() instanceof EarlyTerminationException);
assertThat(result.sessions().get("Shell").content(),
Matchers.containsString("Would you like to install"));
}
try (LaunchResult result = doLaunch("dbgeng via ssh", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("OPT_HOST", "localhost")))) {
checkResult(result);
}
}
@Test
public void testDbgViaSshSetupGhidraDbg() throws Exception {
try (LaunchResult result = doLaunch("dbgeng via ssh", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("OPT_HOST", "localhost")))) {
assertTrue(result.exception() instanceof EarlyTerminationException);
assertThat(result.sessions().get("Shell").content(),
Matchers.containsString("Would you like to install"));
}
try (LaunchResult result = doLaunch("dbgeng via ssh", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("OPT_HOST", "localhost")))) {
checkResult(result);
}
}
@@ -16,7 +16,7 @@
package agent.gdb.rmi;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import java.nio.file.Path;
import java.util.List;
@@ -53,7 +53,11 @@ public class GdbConnectorsTest extends AbstractRmiConnectorsTest {
// Make sure system doesn't cause path failures to pass
unpip("ghidragdb", "ghidratrace");
// Ensure a compatible version of protobuf
pip("protobuf==6.31.0");
pip("protobuf>=6.31.0");
}
private String sshLauncherTitle() {
return isWindows() ? "gdb via ssh (cmd shell)" : "gdb via ssh";
}
@Test
@@ -102,7 +106,7 @@ public class GdbConnectorsTest extends AbstractRmiConnectorsTest {
}
programManager.openProgram(program);
try (LaunchResult result = doLaunch("gdb + qemu-system", Map.ofEntries(
Map.entry("arg:1", dummy),
Map.entry(isWindows() ? "env:OPT_TARGET_IMG" : "arg:1", dummy),
Map.entry("env:OPT_GDB_PATH", new PathIsFile(Path.of("gdb"))),
Map.entry("env:GHIDRA_LANG_EXTTOOL_qemu_system", findQemu("qemu-system-aarch64")),
Map.entry("env:OPT_EXTRA_QEMU_ARGS", "-machine virt")))) {
@@ -127,8 +131,8 @@ public class GdbConnectorsTest extends AbstractRmiConnectorsTest {
@Test
public void testGdbViaSsh() throws Exception {
pip("ghidragdb==%s".formatted(Application.getApplicationVersion()));
try (LaunchResult result = doLaunch("gdb via ssh", Map.ofEntries(
Map.entry("arg:1", "/bin/ls"),
try (LaunchResult result = doLaunch(sshLauncherTitle(), Map.ofEntries(
Map.entry("arg:1", chooseImage().path().toFile().getAbsolutePath()),
Map.entry("OPT_HOST", "localhost")))) {
checkResult(result);
}
@@ -136,15 +140,15 @@ public class GdbConnectorsTest extends AbstractRmiConnectorsTest {
@Test
public void testGdbViaSshSetupGhidraGdb() throws Exception {
try (LaunchResult result = doLaunch("gdb via ssh", Map.ofEntries(
Map.entry("arg:1", "/bin/ls"),
try (LaunchResult result = doLaunch(sshLauncherTitle(), Map.ofEntries(
Map.entry("arg:1", chooseImageToString()),
Map.entry("OPT_HOST", "localhost")))) {
assertTrue(result.exception() instanceof EarlyTerminationException);
assertThat(result.sessions().get("Shell").content(),
Matchers.containsString("Would you like to install"));
}
try (LaunchResult result = doLaunch("gdb via ssh", Map.ofEntries(
Map.entry("arg:1", "/bin/ls"),
try (LaunchResult result = doLaunch(sshLauncherTitle(), Map.ofEntries(
Map.entry("arg:1", chooseImageToString()),
Map.entry("OPT_HOST", "localhost")))) {
checkResult(result);
}
@@ -152,18 +156,20 @@ public class GdbConnectorsTest extends AbstractRmiConnectorsTest {
@Test
public void testGdbViaSshSetupProtobuf() throws Exception {
// NB: If you fail on the next line, delete everything (ghidragdb,
// ghidratrace, google, protobuf) from site-packages
pip("ghidragdb==%s".formatted(Application.getApplicationVersion()));
// Overwrite with an incompatible version we don't include
pipOob("protobuf==3.19.0");
try (LaunchResult result = doLaunch("gdb via ssh", Map.ofEntries(
Map.entry("arg:1", "/bin/ls"),
try (LaunchResult result = doLaunch(sshLauncherTitle(), Map.ofEntries(
Map.entry("arg:1", chooseImageToString()),
Map.entry("OPT_HOST", "localhost")))) {
assertTrue(result.exception() instanceof EarlyTerminationException);
assertThat(result.sessions().get("Shell").content(),
Matchers.containsString("Would you like to install"));
}
try (LaunchResult result = doLaunch("gdb via ssh", Map.ofEntries(
Map.entry("arg:1", "/bin/ls"),
try (LaunchResult result = doLaunch(sshLauncherTitle(), Map.ofEntries(
Map.entry("arg:1", chooseImageToString()),
Map.entry("OPT_HOST", "localhost")))) {
checkResult(result);
}
@@ -16,8 +16,8 @@
package agent.lldb.rmi;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import java.nio.file.Path;
import java.util.List;
@@ -36,7 +36,6 @@ import ghidra.app.util.importer.MessageLog;
import ghidra.debug.api.action.AutoMapSpec;
import ghidra.debug.api.tracermi.TraceRmiLaunchOffer.LaunchResult;
import ghidra.framework.Application;
import ghidra.framework.OperatingSystem;
import ghidra.framework.plugintool.AutoConfigState.PathIsFile;
import ghidra.pty.testutil.DummyProc;
@@ -60,7 +59,11 @@ public class LldbConnectorsTest extends AbstractRmiConnectorsTest {
// Make sure system doesn't cause path failures to pass
unpip("ghidralldb", "ghidratrace");
// Ensure a compatible version of protobuf
pip("protobuf==6.31.0");
pip("protobuf>=6.31.0");
}
private String sshLauncherTitle() {
return isWindows() ? "lldb via ssh (cmd shell)" : "lldb via ssh";
}
/**
@@ -72,6 +75,7 @@ public class LldbConnectorsTest extends AbstractRmiConnectorsTest {
* @throws Exception because
*/
@Test
@Ignore("TODO")
public void testLocalLldbSetup() throws Exception {
pipOob("protobuf==3.19.0");
try (LaunchResult result = doLaunch("lldb", Map.of("arg:1", chooseImage()))) {
@@ -94,7 +98,7 @@ public class LldbConnectorsTest extends AbstractRmiConnectorsTest {
@Test
@Ignore("TODO")
public void testLldbQemuUser() throws Exception {
assumeFalse(OperatingSystem.WINDOWS == OperatingSystem.CURRENT_OPERATING_SYSTEM);
assumeFalse(isWindows());
PathIsFile image = createArmElfImage();
program = AutoImporter.importByUsingBestGuess(image.path().toFile(), null, "/", this,
new MessageLog(), monitor).getPrimaryDomainObject();
@@ -151,43 +155,45 @@ public class LldbConnectorsTest extends AbstractRmiConnectorsTest {
@Test
public void testLldbViaSsh() throws Exception {
pip("ghidralldb==%s".formatted(Application.getApplicationVersion()));
try (LaunchResult result = doLaunch("lldb via ssh", Map.ofEntries(
Map.entry("arg:1", "/bin/ls"),
try (LaunchResult result = doLaunch(sshLauncherTitle(), Map.ofEntries(
Map.entry("arg:1", chooseImageToString()),
Map.entry("OPT_HOST", "localhost")))) {
checkResult(result);
}
}
@Test
@Ignore("TODO")
public void testLldbViaSshSetupGhidraLldb() throws Exception {
try (LaunchResult result = doLaunch("lldb via ssh", Map.ofEntries(
Map.entry("arg:1", "/bin/ls"),
try (LaunchResult result = doLaunch(sshLauncherTitle(), Map.ofEntries(
Map.entry("arg:1", chooseImageToString()),
Map.entry("OPT_HOST", "localhost")))) {
assertTrue(result.exception() instanceof EarlyTerminationException);
assertThat(result.sessions().get("Shell").content(),
Matchers.containsString("Would you like to install"));
}
try (LaunchResult result = doLaunch("lldb via ssh", Map.ofEntries(
Map.entry("arg:1", "/bin/ls"),
try (LaunchResult result = doLaunch(sshLauncherTitle(), Map.ofEntries(
Map.entry("arg:1", chooseImageToString()),
Map.entry("OPT_HOST", "localhost")))) {
checkResult(result);
}
}
@Test
@Ignore("TODO")
public void testLldbViaSshSetupProtobuf() throws Exception {
pip("ghidralldb==%s".formatted(Application.getApplicationVersion()));
// Overwrite with an incompatible version we don't include
pipOob("protobuf==3.19.0");
try (LaunchResult result = doLaunch("lldb via ssh", Map.ofEntries(
Map.entry("arg:1", "/bin/ls"),
try (LaunchResult result = doLaunch(sshLauncherTitle(), Map.ofEntries(
Map.entry("arg:1", chooseImageToString()),
Map.entry("OPT_HOST", "localhost")))) {
assertTrue(result.exception() instanceof EarlyTerminationException);
assertThat(result.sessions().get("Shell").content(),
Matchers.containsString("Would you like to install"));
}
try (LaunchResult result = doLaunch("lldb via ssh", Map.ofEntries(
Map.entry("arg:1", "/bin/ls"),
try (LaunchResult result = doLaunch(sshLauncherTitle(), Map.ofEntries(
Map.entry("arg:1", chooseImageToString()),
Map.entry("OPT_HOST", "localhost")))) {
checkResult(result);
}
@@ -0,0 +1,177 @@
/* ###
* 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 agent.x64dbg.rmi;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import agent.AbstractRmiConnectorsTest;
import generic.jar.ResourceFile;
import ghidra.app.plugin.core.debug.gui.tracermi.launcher.AbstractTraceRmiLaunchOffer.EarlyTerminationException;
import ghidra.debug.api.tracermi.TraceRmiLaunchOffer.LaunchResult;
import ghidra.framework.Application;
import ghidra.framework.plugintool.AutoConfigState.PathIsFile;
public class X64dbgConnectorsTest extends AbstractRmiConnectorsTest {
@Override
protected String getPythonCmd() {
return "C:\\Python313\\python";
}
@Override
protected List<ResourceFile> getPipLinkModules() {
return List.of(
Application.getModuleRootDir("Debugger-rmi-trace"),
Application.getModuleRootDir("Debugger-agent-x64dbg"));
}
@Before
public void setUpX64Dbg() throws Exception {
// Make sure system doesn't cause path failures to pass
unpip("ghidraxdbg", "ghidratrace");
// Ensure a compatible version of protobuf
pip("protobuf>=6.31.0");
}
@Test
public void testLocalX64dbgWithImage() throws Exception {
try (LaunchResult result = doLaunch("x64dbg", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("env:OPT_X64DBG_EXE", new PathIsFile(Path.of("x64dbg.exe"))),
Map.entry("env:OPT_PYTHON_EXE",
new PathIsFile(Path.of(getPythonCmd())))))) {
checkResult(result);
}
}
@Test
public void testLocalX64dbgWithImageBat() throws Exception {
try (LaunchResult result = doLaunch("x64dbg (.bat)", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("env:OPT_PYTHON_EXE",
new PathIsFile(Path.of(getPythonCmd())))))) {
checkResult(result);
}
}
@Test
public void testLocalX64dbgSetup() throws Exception {
pipOob("protobuf==3.19.0");
try (LaunchResult result = doLaunch("x64dbg", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("env:OPT_X64DBG_EXE", new PathIsFile(Path.of("x64dbg.exe"))),
Map.entry("env:OPT_PYTHON_EXE",
new PathIsFile(Path.of(getPythonCmd())))))) {
assertThat(result.exception(), instanceOf(EarlyTerminationException.class));
assertThat(result.sessions().get("Shell").content(),
containsString("Would you like to install"));
}
try (LaunchResult result = doLaunch("x64dbg", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("env:OPT_X64DBG_EXE", new PathIsFile(Path.of("x64dbg.exe"))),
Map.entry("env:OPT_PYTHON_EXE",
new PathIsFile(Path.of(getPythonCmd())))))) {
checkResult(result);
}
}
@Test
public void testLocalX64dbgSetupBat() throws Exception {
pipOob("protobuf==3.19.0");
try (LaunchResult result = doLaunch("x64dbg (.bat)", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("env:OPT_PYTHON_EXE",
new PathIsFile(Path.of(getPythonCmd())))))) {
assertThat(result.exception(), instanceOf(EarlyTerminationException.class));
assertThat(result.sessions().get("Shell").content(),
containsString("Would you like to install"));
}
try (LaunchResult result = doLaunch("x64dbg (.bat)", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("env:OPT_PYTHON_EXE",
new PathIsFile(Path.of(getPythonCmd())))))) {
checkResult(result);
}
}
// NB: The next three tests tend to leave residual python processes running
// which will cause permissions problems when subsequent tests attempt
// to access python's site-packages
@Test
public void testX64dbgViaSsh() throws Exception {
pip("ghidratrace==%s".formatted(Application.getApplicationVersion()));
pip("ghidraxdbg==%s".formatted(Application.getApplicationVersion()));
try (LaunchResult result = doLaunch("x64dbg via ssh", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("env:OPT_X64DBG_EXE", new PathIsFile(Path.of("x64dbg.exe"))),
Map.entry("OPT_HOST", "localhost")))) {
checkResult(result);
}
}
@Test
public void testX64dbgViaSshSetupProtobuf() throws Exception {
// NB: If you fail on the next line, delete everything (ghidradbg,
// ghidratrace, google, protobuf) from site-packages
pip("ghidraxdbg==%s".formatted(Application.getApplicationVersion()));
// Overwrite with an incompatible version we don't include
pipOob("protobuf==3.19.0");
try (LaunchResult result = doLaunch("x64dbg via ssh", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("env:OPT_X64DBG_EXE", new PathIsFile(Path.of("x64dbg.exe"))),
Map.entry("OPT_HOST", "localhost")))) {
assertTrue(result.exception() instanceof EarlyTerminationException);
assertThat(result.sessions().get("Shell").content(),
Matchers.containsString("Would you like to install"));
}
try (LaunchResult result = doLaunch("x64dbg via ssh", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("env:OPT_X64DBG_EXE", new PathIsFile(Path.of("x64dbg.exe"))),
Map.entry("OPT_HOST", "localhost")))) {
checkResult(result);
}
}
@Test
public void testX64dbgViaSshSetupGhidraDbg() throws Exception {
try (LaunchResult result = doLaunch("x64dbg via ssh", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("env:OPT_X64DBG_EXE", new PathIsFile(Path.of("x64dbg.exe"))),
Map.entry("OPT_HOST", "localhost")))) {
assertTrue(result.exception() instanceof EarlyTerminationException);
assertThat(result.sessions().get("Shell").content(),
Matchers.containsString("Would you like to install"));
}
try (LaunchResult result = doLaunch("x64dbg via ssh", Map.ofEntries(
Map.entry("env:OPT_TARGET_IMG", chooseImage()),
Map.entry("env:OPT_X64DBG_EXE", new PathIsFile(Path.of("x64dbg.exe"))),
Map.entry("OPT_HOST", "localhost")))) {
checkResult(result);
}
}
}