From 3efe95135b0075c98d120d33087ce4014c7afef7 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Thu, 31 Oct 2019 15:27:25 +0100 Subject: [PATCH] DBG: improve savedata command --- src/dbg/commands/cmd-memory-operations.cpp | 9 +++++---- src/dbg/memory.cpp | 9 ++++++--- src/dbg/memory.h | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/dbg/commands/cmd-memory-operations.cpp b/src/dbg/commands/cmd-memory-operations.cpp index 1fd50a1e..af2b7be7 100644 --- a/src/dbg/commands/cmd-memory-operations.cpp +++ b/src/dbg/commands/cmd-memory-operations.cpp @@ -158,11 +158,12 @@ bool cbInstrSavedata(int argc, char* argv[]) if(!valfromstring(argv[2], &addr, false) || !valfromstring(argv[3], &size, false)) return false; + bool success = true; Memory data(size); - if(!MemRead(addr, data(), data.size())) + if(!MemReadDumb(addr, data(), data.size())) { - dputs(QT_TRANSLATE_NOOP("DBG", "Failed to read memory...")); - return false; + dputs(QT_TRANSLATE_NOOP("DBG", "Failed to read (all) memory...")); + success = false; } String name = stringformatinline(argv[1]); @@ -180,5 +181,5 @@ bool cbInstrSavedata(int argc, char* argv[]) dprintf(QT_TRANSLATE_NOOP("DBG", "%p[%X] written to \"%s\" !\n"), addr, size, name.c_str()); #endif - return true; + return success; } \ No newline at end of file diff --git a/src/dbg/memory.cpp b/src/dbg/memory.cpp index bf54a4ef..d2d098a0 100644 --- a/src/dbg/memory.cpp +++ b/src/dbg/memory.cpp @@ -835,22 +835,25 @@ void MemInitRemoteProcessCookie(ULONG cookie) } //Workaround for modules that have holes between sections, it keeps parts it couldn't read the same as the input -void MemReadDumb(duint BaseAddress, void* Buffer, duint Size) +bool MemReadDumb(duint BaseAddress, void* Buffer, duint Size) { if(!MemIsCanonicalAddress(BaseAddress) || !Buffer || !Size) - return; + return false; duint offset = 0; duint requestedSize = Size; duint sizeLeftInFirstPage = PAGE_SIZE - (BaseAddress & (PAGE_SIZE - 1)); duint readSize = min(sizeLeftInFirstPage, requestedSize); + bool success = true; while(readSize) { SIZE_T bytesRead = 0; - MemoryReadSafePage(fdProcessInfo->hProcess, (PVOID)(BaseAddress + offset), (PBYTE)Buffer + offset, readSize, &bytesRead); + if(!MemoryReadSafePage(fdProcessInfo->hProcess, (PVOID)(BaseAddress + offset), (PBYTE)Buffer + offset, readSize, &bytesRead)) + success = false; offset += readSize; requestedSize -= readSize; readSize = min(PAGE_SIZE, requestedSize); } + return success; } diff --git a/src/dbg/memory.h b/src/dbg/memory.h index 8ab4e26d..49879365 100644 --- a/src/dbg/memory.h +++ b/src/dbg/memory.h @@ -29,7 +29,7 @@ bool MemFindInPage(const SimplePage & page, duint startoffset, const std::vector bool MemFindInMap(const std::vector & pages, const std::vector & pattern, std::vector & results, duint maxresults, bool progress = true); bool MemDecodePointer(duint* Pointer, bool vistaPlus); void MemInitRemoteProcessCookie(ULONG cookie); -void MemReadDumb(duint BaseAddress, void* Buffer, duint Size); +bool MemReadDumb(duint BaseAddress, void* Buffer, duint Size); #include "addrinfo.h"