1
0
Fork 0

DBG: improve savedata command

This commit is contained in:
Duncan Ogilvie 2019-10-31 15:27:25 +01:00
parent 5b92e85cb4
commit 3efe95135b
3 changed files with 12 additions and 8 deletions

View File

@ -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<unsigned char*> 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;
}

View File

@ -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;
}

View File

@ -29,7 +29,7 @@ bool MemFindInPage(const SimplePage & page, duint startoffset, const std::vector
bool MemFindInMap(const std::vector<SimplePage> & pages, const std::vector<PatternByte> & pattern, std::vector<duint> & 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"