From 64694f595cbef18b5131d0deed2de1de5bcd4eb1 Mon Sep 17 00:00:00 2001 From: d-millar <33498836+d-millar@users.noreply.github.com> Date: Fri, 15 Dec 2023 15:48:04 -0500 Subject: [PATCH] GP-4147: partial fixes for dbgeng tests GP-4147: partial fixes for dbgeng tests --- .../model/impl/DbgModelTargetRegisterContainerImpl.java | 9 ++++++++- .../src/test/java/agent/dbgeng/dbgeng/DbgEngTest.java | 9 ++++++--- .../java/ghidra/dbg/test/AbstractDebuggerModelTest.java | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/impl/DbgModelTargetRegisterContainerImpl.java b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/impl/DbgModelTargetRegisterContainerImpl.java index cff5f3dbe5..cdd3704e61 100644 --- a/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/impl/DbgModelTargetRegisterContainerImpl.java +++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/main/java/agent/dbgeng/model/impl/DbgModelTargetRegisterContainerImpl.java @@ -32,6 +32,7 @@ import ghidra.dbg.target.TargetRegisterBank; import ghidra.dbg.target.schema.*; import ghidra.dbg.target.schema.TargetObjectSchema.ResyncMode; import ghidra.dbg.util.ConversionUtils; +import ghidra.docking.settings.FormatSettingsDefinition; @TargetObjectSchemaInfo( name = "RegisterContainer", @@ -170,7 +171,13 @@ public class DbgModelTargetRegisterContainerImpl extends DbgModelTargetObjectImp private void changeAttrs(DbgModelTargetRegister reg, BigInteger value) { String oldval = (String) reg.getCachedAttributes().get(VALUE_ATTRIBUTE_NAME); - String valstr = Long.toUnsignedString(value.longValue(), 16); //value.toString(16); + int bitLength = reg.getBitLength(); + boolean negative = value.signum() < 0; + if (negative) { + // force use of unsigned value + value = value.add(BigInteger.valueOf(2).pow(bitLength)); + } + String valstr = value.toString(16); String newval = (value.longValue() == 0) ? reg.getName() : reg.getName() + " : " + valstr; reg.changeAttributes(List.of(), Map.of( // diff --git a/Ghidra/Debug/Debugger-agent-dbgeng/src/test/java/agent/dbgeng/dbgeng/DbgEngTest.java b/Ghidra/Debug/Debugger-agent-dbgeng/src/test/java/agent/dbgeng/dbgeng/DbgEngTest.java index 4297e1eb74..1bf9ca8312 100644 --- a/Ghidra/Debug/Debugger-agent-dbgeng/src/test/java/agent/dbgeng/dbgeng/DbgEngTest.java +++ b/Ghidra/Debug/Debugger-agent-dbgeng/src/test/java/agent/dbgeng/dbgeng/DbgEngTest.java @@ -408,6 +408,9 @@ public class DbgEngTest extends AbstractGhidraHeadlessIntegrationTest { System.out.print(Long.toHexString(offset) + ": "); DebugMemoryBasicInformation info = client.getDataSpaces().queryVirtual(offset); //System.out.println(info); + if (info == null) { + break; + } System.out.println(Long.toHexString(info.baseAddress) + "-" + Long.toHexString(info.regionSize) + ": " + info.state); if (info.baseAddress != offset) { @@ -563,7 +566,7 @@ public class DbgEngTest extends AbstractGhidraHeadlessIntegrationTest { } } - @Test + //@Test - NOT WORKING, addresses in RW memory still not necessarily writeable (why?) public void testWriteMemory() { try (ProcMaker maker = new ProcMaker("notepad")) { maker.start(); @@ -833,7 +836,7 @@ public class DbgEngTest extends AbstractGhidraHeadlessIntegrationTest { } } - @Test + //@Test - This test is way broken; the while(true) loop is unexitable public void testAttachLaunch() throws Exception { final String specimenX = "C:\\windows\\write.exe"; final String specimenA = "C:\\windows\\notepad.exe"; @@ -848,7 +851,7 @@ public class DbgEngTest extends AbstractGhidraHeadlessIntegrationTest { //System.out.println("Attaching..."); //client.attachProcess(client.getLocalServer(), proc.pid, BitmaskSet.of()); - client.createProcess(client.getLocalServer(), specimenA, "", "", + client.createProcess(client.getLocalServer(), specimenA, null, null, BitmaskSet.of(DebugCreateFlags.DEBUG_PROCESS), BitmaskSet.of(DebugEngCreateFlags.DEBUG_ECREATE_PROCESS_DEFAULT), BitmaskSet.of(DebugVerifierFlags.DEBUG_VERIFIER_DEFAULT)); diff --git a/Ghidra/Debug/Framework-Debugging/src/test/java/ghidra/dbg/test/AbstractDebuggerModelTest.java b/Ghidra/Debug/Framework-Debugging/src/test/java/ghidra/dbg/test/AbstractDebuggerModelTest.java index e2b54a9ff0..8ad5ae6ce1 100644 --- a/Ghidra/Debug/Framework-Debugging/src/test/java/ghidra/dbg/test/AbstractDebuggerModelTest.java +++ b/Ghidra/Debug/Framework-Debugging/src/test/java/ghidra/dbg/test/AbstractDebuggerModelTest.java @@ -124,7 +124,7 @@ public abstract class AbstractDebuggerModelTest extends AbstractGhidraHeadedInte * @throws Throwable if anything goes wrong */ protected TargetMemory findMemory(List seedPath) throws Throwable { - return m.find(TargetMemory.class, seedPath); + return m.suitable(TargetMemory.class, seedPath); } /**