From 3f42d04cff650acca8c9212bce238fdb170a8517 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Fri, 25 May 2012 07:29:53 +0000 Subject: [PATCH] [0.1.x] fixed : issue #10541 ( loadWStr: string truncated to 128 chars ) git-svn-id: https://pykd.svn.codeplex.com/svn@76652 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgmem.cpp | 47 +++++++++++++++++++++++++++--------- test/scripts/memtest.py | 4 +++ test/targetapp/targetapp.cpp | 13 ++++++++++ 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/pykd/dbgmem.cpp b/pykd/dbgmem.cpp index 17ffbad..234f72b 100644 --- a/pykd/dbgmem.cpp +++ b/pykd/dbgmem.cpp @@ -204,20 +204,33 @@ std::wstring loadWChars( ULONG64 address, ULONG number, bool phyAddr ) std::string DebugClient::loadCStr( ULONG64 address ) { - const size_t maxLength = 0x1000; - + const size_t maxLength = 0x10000; + address = addr64( address ); - std::vector buffer(maxLength); - + ULONG strLength = 0; + HRESULT hres = m_dataSpaces->ReadMultiByteStringVirtual( address, maxLength, + NULL, + 0, + &strLength ); + + if ( FAILED( hres ) ) + throw MemoryException( address ); + + std::vector buffer(strLength); + + hres = + m_dataSpaces->ReadMultiByteStringVirtual( + address, + strLength, &buffer[0], - maxLength, + strLength, NULL ); - + if ( FAILED( hres ) ) throw MemoryException( address ); @@ -233,24 +246,34 @@ std::string loadCStr( ULONG64 offset ) std::wstring DebugClient::loadWStr( ULONG64 address ) { - const size_t maxLength = 0x2000; + const size_t maxLength = 0x10000; address = addr64( address ); - std::vector buffer(maxLength); - + ULONG strLength = 0; + HRESULT hres = - m_dataSpaces->ReadMultiByteStringVirtual( + m_dataSpaces->ReadUnicodeStringVirtualWide( address, maxLength, + NULL, + 0, + &strLength ); + + std::vector buffer(strLength); + + hres = + m_dataSpaces->ReadUnicodeStringVirtualWide( + address, + strLength, &buffer[0], - maxLength, + strLength, NULL ); if ( FAILED( hres ) ) throw MemoryException( address ); - return std::wstring( (wchar_t*)&buffer[0] ); + return std::wstring( &buffer[0] ); } std::wstring loadWStr( ULONG64 offset ) diff --git a/test/scripts/memtest.py b/test/scripts/memtest.py index b83a508..aed0802 100644 --- a/test/scripts/memtest.py +++ b/test/scripts/memtest.py @@ -82,6 +82,10 @@ class MemoryTest( unittest.TestCase ): self.assertEqual( 'Hello', pykd.loadCStr( target.module.helloStr ) ) self.assertEqual( u'Hello', pykd.loadWStr( target.module.helloWStr ) ) + def testBigCStr( self ): + self.assertEqual( 0x2000, len( pykd.loadCStr( pykd.ptrPtr( target.module.bigCStr ) ) ) ) + self.assertEqual( 0x2000, len( pykd.loadWStr( pykd.ptrPtr( target.module.bigWStr ) ) ) ) + def testVaValid( self ): self.assertTrue( pykd.isValid( target.module.begin() ) ) self.assertFalse( pykd.isValid( 0 ) ) diff --git a/test/targetapp/targetapp.cpp b/test/targetapp/targetapp.cpp index 62e5dbb..167d144 100644 --- a/test/targetapp/targetapp.cpp +++ b/test/targetapp/targetapp.cpp @@ -347,6 +347,11 @@ VirtualChildClass g_virtChild; //////////////////////////////////////////////////////////////////////////////// +char* bigCStr = NULL; +wchar_t* bigWStr = NULL; + +//////////////////////////////////////////////////////////////////////////////// + WNDENUMPROC g_ptrToFunction; void *g_unTypedPtrToFunction = g_ptrToFunction; #pragma pack( pop ) @@ -599,6 +604,14 @@ int _tmain(int argc, _TCHAR* argv[]) g_ptrToFunction = &EnumWindowsProc2; g_unTypedPtrToFunction = &EnumWindowsProc2; + bigCStr = new char[0x2000 + 1]; + memset( bigCStr, 'a', 0x2000 ); + bigCStr[0x2000] = 0; + + bigWStr = new wchar_t[0x2000 + 1]; + wmemset( bigWStr, L'a', 0x2000 ); + bigWStr[0x2000] = 0; + // Let test scripts to execute __debugbreak();