Commit 58ee1ee9 authored by Administrator's avatar Administrator

Merge branch 'dev-1.0' into 'dev-1.0'

Partial read: nowhere to return size (pykd/pykd#16)

See merge request !5
parents 9bfa80d7 f42b8323
......@@ -49,6 +49,7 @@ void readMemory( MEMOFFSET_64 offset, void* buffer, size_t length, bool phyAddr,
{
offset = addr64(offset);
unsigned long readedLocal = 0;
if ( readed )
*readed = 0;
......@@ -58,15 +59,21 @@ void readMemory( MEMOFFSET_64 offset, void* buffer, size_t length, bool phyAddr,
{
offset = addr64( offset );
hres = g_dbgMgr->dataspace->ReadVirtual( offset, buffer, numeric_cast<ULONG>(length), readed );
hres = g_dbgMgr->dataspace->ReadVirtual( offset, buffer, numeric_cast<ULONG>(length), readed ? readed : &readedLocal );
}
else
{
hres = g_dbgMgr->dataspace->ReadPhysical( offset, buffer, numeric_cast<ULONG>(length), readed );
hres = g_dbgMgr->dataspace->ReadPhysical( offset, buffer, numeric_cast<ULONG>(length), readed ? readed : &readedLocal );
}
if ( FAILED( hres ) )
throw MemoryException( offset, phyAddr );
if (!readed && (readedLocal < length))
{
// read less than requested, but "readed" has nowhere to return
throw MemoryException( offset + readedLocal, phyAddr );
}
}
///////////////////////////////////////////////////////////////////////////////
......
......@@ -256,4 +256,19 @@ TEST_F(MemoryTest, InvalidBigRegion)
EXPECT_THROW(loadWChars(offset, 0xF0000000), MemoryException);
}
TEST_F(MemoryTest, testPartial)
{
const auto delta = sizeof(ULONGLONG) / 2;
const MEMOFFSET_64 offset = m_targetModule->getEnd() - delta;
EXPECT_THROW(loadBytes(offset, sizeof(ULONGLONG)), MemoryException);
EXPECT_THROW(ptrQWord(offset), MemoryException);
EXPECT_THROW(writeBytes(offset, std::vector<unsigned char>(sizeof(ULONGLONG))), MemoryException);
EXPECT_THROW(setQWord(offset, 0), MemoryException);
ULONGLONG tmp;
unsigned long readed = 0;
EXPECT_NO_THROW( readMemory(offset, &tmp, sizeof(tmp), false, &readed) );
EXPECT_EQ( delta, readed );
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment