[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
This commit is contained in:
SND\kernelnet_cp 2012-05-25 07:29:53 +00:00 committed by Mikhail I. Izmestev
parent 080feb5709
commit 3f42d04cff
3 changed files with 52 additions and 12 deletions

View File

@ -204,20 +204,33 @@ std::wstring loadWChars( ULONG64 address, ULONG number, bool phyAddr )
std::string DebugClient::loadCStr( ULONG64 address ) std::string DebugClient::loadCStr( ULONG64 address )
{ {
const size_t maxLength = 0x1000; const size_t maxLength = 0x10000;
address = addr64( address ); address = addr64( address );
std::vector<char> buffer(maxLength); ULONG strLength = 0;
HRESULT hres = HRESULT hres =
m_dataSpaces->ReadMultiByteStringVirtual( m_dataSpaces->ReadMultiByteStringVirtual(
address, address,
maxLength, maxLength,
NULL,
0,
&strLength );
if ( FAILED( hres ) )
throw MemoryException( address );
std::vector<char> buffer(strLength);
hres =
m_dataSpaces->ReadMultiByteStringVirtual(
address,
strLength,
&buffer[0], &buffer[0],
maxLength, strLength,
NULL ); NULL );
if ( FAILED( hres ) ) if ( FAILED( hres ) )
throw MemoryException( address ); throw MemoryException( address );
@ -233,24 +246,34 @@ std::string loadCStr( ULONG64 offset )
std::wstring DebugClient::loadWStr( ULONG64 address ) std::wstring DebugClient::loadWStr( ULONG64 address )
{ {
const size_t maxLength = 0x2000; const size_t maxLength = 0x10000;
address = addr64( address ); address = addr64( address );
std::vector<char> buffer(maxLength); ULONG strLength = 0;
HRESULT hres = HRESULT hres =
m_dataSpaces->ReadMultiByteStringVirtual( m_dataSpaces->ReadUnicodeStringVirtualWide(
address, address,
maxLength, maxLength,
NULL,
0,
&strLength );
std::vector<wchar_t> buffer(strLength);
hres =
m_dataSpaces->ReadUnicodeStringVirtualWide(
address,
strLength,
&buffer[0], &buffer[0],
maxLength, strLength,
NULL ); NULL );
if ( FAILED( hres ) ) if ( FAILED( hres ) )
throw MemoryException( address ); throw MemoryException( address );
return std::wstring( (wchar_t*)&buffer[0] ); return std::wstring( &buffer[0] );
} }
std::wstring loadWStr( ULONG64 offset ) std::wstring loadWStr( ULONG64 offset )

View File

@ -82,6 +82,10 @@ class MemoryTest( unittest.TestCase ):
self.assertEqual( 'Hello', pykd.loadCStr( target.module.helloStr ) ) self.assertEqual( 'Hello', pykd.loadCStr( target.module.helloStr ) )
self.assertEqual( u'Hello', pykd.loadWStr( target.module.helloWStr ) ) 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 ): def testVaValid( self ):
self.assertTrue( pykd.isValid( target.module.begin() ) ) self.assertTrue( pykd.isValid( target.module.begin() ) )
self.assertFalse( pykd.isValid( 0 ) ) self.assertFalse( pykd.isValid( 0 ) )

View File

@ -347,6 +347,11 @@ VirtualChildClass g_virtChild;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
char* bigCStr = NULL;
wchar_t* bigWStr = NULL;
////////////////////////////////////////////////////////////////////////////////
WNDENUMPROC g_ptrToFunction; WNDENUMPROC g_ptrToFunction;
void *g_unTypedPtrToFunction = g_ptrToFunction; void *g_unTypedPtrToFunction = g_ptrToFunction;
#pragma pack( pop ) #pragma pack( pop )
@ -599,6 +604,14 @@ int _tmain(int argc, _TCHAR* argv[])
g_ptrToFunction = &EnumWindowsProc2; g_ptrToFunction = &EnumWindowsProc2;
g_unTypedPtrToFunction = &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 // Let test scripts to execute
__debugbreak(); __debugbreak();