From 3e63efc670aed0f3a399a0d29645317b539bac23 Mon Sep 17 00:00:00 2001 From: Dan <46821332+nsadeveloper789@users.noreply.github.com> Date: Thu, 5 Aug 2021 11:07:49 -0400 Subject: [PATCH 1/3] GP-1187: Wrote test case demonstrating the issue. --- .../exec/trace/TracePcodeEmulatorTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Ghidra/Debug/Framework-TraceModeling/src/test/java/ghidra/pcode/exec/trace/TracePcodeEmulatorTest.java b/Ghidra/Debug/Framework-TraceModeling/src/test/java/ghidra/pcode/exec/trace/TracePcodeEmulatorTest.java index 568c3ad71f..3d7da631ad 100644 --- a/Ghidra/Debug/Framework-TraceModeling/src/test/java/ghidra/pcode/exec/trace/TracePcodeEmulatorTest.java +++ b/Ghidra/Debug/Framework-TraceModeling/src/test/java/ghidra/pcode/exec/trace/TracePcodeEmulatorTest.java @@ -705,4 +705,31 @@ public class TracePcodeEmulatorTest extends AbstractGhidraHeadlessIntegrationTes TraceSleighUtils.evaluate("RAX", tb.trace, 1, thread, 0)); } } + + @Test + public void testCachedReadAfterSmallWrite() throws Throwable { + try (ToyDBTraceBuilder tb = new ToyDBTraceBuilder("Test", "x86:LE:64:default")) { + TraceThread thread = initTrace(tb, + List.of( + "RIP = 0x00400000;", + "RSP = 0x00110000;", + "RAX = 0x12345678;"), + List.of( + "XOR AH, AH", + "MOV RCX, RAX")); + + TracePcodeEmulator emu = new TracePcodeEmulator(tb.trace, 0); + PcodeThread emuThread = emu.newThread(thread.getPath()); + emuThread.overrideContextWithDefault(); + emuThread.stepInstruction(); + emuThread.stepInstruction(); + + try (UndoableTransaction tid = tb.startTransaction()) { + emu.writeDown(tb.trace, 1, 1, false); + } + + assertEquals(BigInteger.valueOf(0x12340078), + TraceSleighUtils.evaluate("RAX", tb.trace, 1, thread, 0)); + } + } } From 11322c4982f83418c10f34097ee6d4b2e498ebc7 Mon Sep 17 00:00:00 2001 From: Dan <46821332+nsadeveloper789@users.noreply.github.com> Date: Thu, 5 Aug 2021 11:18:04 -0400 Subject: [PATCH 2/3] GP-1187: Fix for cache reading issue. --- .../trace/TraceCachedWriteBytesPcodeExecutorState.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/pcode/exec/trace/TraceCachedWriteBytesPcodeExecutorState.java b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/pcode/exec/trace/TraceCachedWriteBytesPcodeExecutorState.java index ee9c0e3360..f40028c6ea 100644 --- a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/pcode/exec/trace/TraceCachedWriteBytesPcodeExecutorState.java +++ b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/pcode/exec/trace/TraceCachedWriteBytesPcodeExecutorState.java @@ -131,7 +131,8 @@ public class TraceCachedWriteBytesPcodeExecutorState public byte[] read(long offset, int size) { if (source != null) { // TODO: Warn or bail when reading UNKNOWN bytes - // NOTE: Not going to worry about gaps here: + // NOTE: Read without regard to gaps + // NOTE: Cannot write those gaps, though!!! RangeSet uninitialized = cache.getUninitialized(offset, offset + size); if (!uninitialized.isEmpty()) { @@ -141,7 +142,11 @@ public class TraceCachedWriteBytesPcodeExecutorState long upper = upper(toRead); ByteBuffer buf = ByteBuffer.allocate((int) (upper - lower + 1)); source.getBytes(snap, space.getAddress(lower), buf); - cache.putData(lower, buf.array()); + for (Range rng : uninitialized.asRanges()) { + long l = lower(rng); + long u = upper(rng); + cache.putData(l, buf.array(), (int) (l - lower), (int) (u - l + 1)); + } } } byte[] data = new byte[size]; From c9650f831c41b4eb9c0fd159a1df1e15e50e042c Mon Sep 17 00:00:00 2001 From: Ryan Kurtz Date: Fri, 6 Aug 2021 11:52:05 -0400 Subject: [PATCH 3/3] Bumping patch to 10.0.3-DEV --- Ghidra/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Ghidra/application.properties b/Ghidra/application.properties index 8522e4dfbb..b75f8f4457 100644 --- a/Ghidra/application.properties +++ b/Ghidra/application.properties @@ -1,5 +1,5 @@ application.name=Ghidra -application.version=10.0.2 +application.version=10.0.3 application.release.name=DEV application.layout.version=1 application.gradle.min=6.0