From d44cc55f211d843702834ea9a5a41d0a74b39f9a Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Mon, 19 Mar 2012 06:44:18 +0000 Subject: [PATCH] [0.1.x] fixed : issue #10521 ( typeInfo returns invalid type name for array's element ) git-svn-id: https://pykd.svn.codeplex.com/svn@74958 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/typeinfo.cpp | 34 +++++++++++++++++++++++++++++++--- test/scripts/typeinfo.py | 4 ++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/pykd/typeinfo.cpp b/pykd/typeinfo.cpp index 0bcb096..f819da8 100644 --- a/pykd/typeinfo.cpp +++ b/pykd/typeinfo.cpp @@ -379,18 +379,46 @@ static const boost::regex ptrMatch("^\\*(.*)$"); static const boost::regex arrayMatch("^(.*)\\[(\\d+)\\]$"); +static const boost::regex symbolMatch("^([\\*]*)([^\\(\\)\\*\\[\\]]*)([\\(\\)\\*\\[\\]\\d]*)$"); + TypeInfoPtr TypeInfo::getComplexType( pyDia::SymbolPtr &symScope, const std::string &symName ) { ULONG ptrSize = (symScope->getMachineType() == IMAGE_FILE_MACHINE_AMD64) ? 8 : 4; boost::cmatch matchResult; - if ( !boost::regex_match( symName.c_str(), matchResult, typeMatch ) ) - throw TypeException( symName, "type name is invalid" ); + if ( !boost::regex_match( symName.c_str(), matchResult, symbolMatch ) ) + throw TypeException( symName, "symbol name is invalid" ); + + std::string innerSymName = std::string( matchResult[2].first, matchResult[2].second ); + + TypeInfoPtr basePtr = getBaseTypeInfo( innerSymName ); + if ( basePtr != 0 ) + { + return getRecurciveComplexType( basePtr, std::string( matchResult[3].first, matchResult[3].second ), ptrSize ); + } + + pyDia::SymbolPtr lowestSymbol = symScope->getChildByName( innerSymName ); + + if ( lowestSymbol->getSymTag() == SymTagData ) + { + throw TypeException( symName, "symbol name can not be an expresion" ); + } + + return getRecurciveComplexType( getTypeInfo( lowestSymbol ), std::string( matchResult[3].first, matchResult[3].second ), ptrSize ); + + + + //ULONG ptrSize = (symScope->getMachineType() == IMAGE_FILE_MACHINE_AMD64) ? 8 : 4; + + //boost::cmatch matchResult; + + //if ( !boost::regex_match( symName.c_str(), matchResult, typeMatch ) ) + // throw TypeException( symName, "type name is invalid" ); TypeInfoPtr lowestTypeInfo = getTypeInfo( symScope, std::string( matchResult[1].first, matchResult[1].second ) ); - return getRecurciveComplexType( lowestTypeInfo, std::string( matchResult[2].first, matchResult[2].second ), ptrSize ); + //return getRecurciveComplexType( lowestTypeInfo, std::string( matchResult[2].first, matchResult[2].second ), ptrSize ); } ///////////////////////////////////////////////////////////////////////////////////// diff --git a/test/scripts/typeinfo.py b/test/scripts/typeinfo.py index 31d189b..86341e7 100644 --- a/test/scripts/typeinfo.py +++ b/test/scripts/typeinfo.py @@ -86,8 +86,8 @@ class TypeInfoTest( unittest.TestCase ): def testVarName( self ): self.assertEqual( "structTest", target.module.type( "g_structTest").name() ) - self.assertEqual( "structTest", target.module.type( "g_testArray[0]").name() ) - self.assertEqual( "structTest", target.module.type( "*g_structTestPtr").name() ) + self.assertRaises( pykd.TypeException, target.module.type, "g_testArray[0]" ) + self.assertRaises( pykd.TypeException, target.module.type, "*g_structTestPtr" ) def testOffset( self ): ti1 = target.module.type( "structTest" )