From 2509de349bd443e8ea5ca9b4b58bf7260b922625 Mon Sep 17 00:00:00 2001 From: ussrhero Date: Wed, 3 Oct 2018 00:52:41 +0300 Subject: [PATCH] added : typeInfo.getMethodName ( Return method's name ) added : typeInfo.methods ( Return list of tuples ( methodName, methodType ) ) --- kdlibcpp | 2 +- pykd/pykdver.h | 2 +- pykd/pymod.cpp | 4 ++++ pykd/pytypeinfo.cpp | 28 ++++++++++++++++++++++++++++ pykd/pytypeinfo.h | 8 ++++++++ test/scripts/typeinfo.py | 9 ++++++--- 6 files changed, 48 insertions(+), 5 deletions(-) diff --git a/kdlibcpp b/kdlibcpp index c1cd0e4..65930b3 160000 --- a/kdlibcpp +++ b/kdlibcpp @@ -1 +1 @@ -Subproject commit c1cd0e4fd727d87d23e1cf26e214ca45068d00e5 +Subproject commit 65930b3307d248503d3c1051f61b50476437845b diff --git a/pykd/pykdver.h b/pykd/pykdver.h index 6638aa4..09624ce 100644 --- a/pykd/pykdver.h +++ b/pykd/pykdver.h @@ -2,7 +2,7 @@ #define PYKD_VERSION_MAJOR 0 #define PYKD_VERSION_MINOR 3 #define PYKD_VERSION_SUBVERSION 4 -#define PYKD_VERSION_BUILDNO 0 +#define PYKD_VERSION_BUILDNO 1 #define __VER_STR2__(x) #x #define __VER_STR1__(x) __VER_STR2__(x) diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index afc98ac..cf44987 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -908,6 +908,10 @@ void pykd_init() "Return method's type by name") .def( "method", TypeInfoAdapter::getMethodByIndex, "Return method's by index") + .def( "methodName", TypeInfoAdapter::getMethodName, + "Return method's name") + .def( "methods", TypeInfoAdapter::getMethods, + "Return list of tuples ( methodName, methodPrototype )" ) .def( "getNumberBaseClasses", TypeInfoAdapter::getBaseClassesCount, "Return number of base classes" ) .def( "baseClass", TypeInfoAdapter::getBaseClassByName, diff --git a/pykd/pytypeinfo.cpp b/pykd/pytypeinfo.cpp index b60f652..f289fb2 100644 --- a/pykd/pytypeinfo.cpp +++ b/pykd/pytypeinfo.cpp @@ -103,6 +103,34 @@ python::list TypeInfoAdapter::getFields( kdlib::TypeInfo &typeInfo ) return pylst; } +python::list TypeInfoAdapter::getMethods(kdlib::TypeInfo &typeInfo) +{ + typedef boost::tuple FieldTuple; + + std::list lst; + + do { + + AutoRestorePyState pystate; + + for (size_t i = 0; i < typeInfo.getMethodsCount(); ++i) + { + std::wstring name = typeInfo.getMethodName(i); + kdlib::TypeInfoPtr val = typeInfo.getMethod(i); + + lst.push_back(FieldTuple(name, val)); + } + + } while (false); + + python::list pylst; + + for (std::list::const_iterator it = lst.begin(); it != lst.end(); ++it) + pylst.append(python::make_tuple(it->get<0>(), it->get<1>())); + + return pylst; +} + /////////////////////////////////////////////////////////////////////////////// kdlib::TypeInfoPtr TypeInfoAdapter::getElementAttr(kdlib::TypeInfo &typeInfo, const std::wstring &name) diff --git a/pykd/pytypeinfo.h b/pykd/pytypeinfo.h index de6ed01..096cf22 100644 --- a/pykd/pytypeinfo.h +++ b/pykd/pytypeinfo.h @@ -178,6 +178,12 @@ struct TypeInfoAdapter : public kdlib::TypeInfo { return typeInfo.getMethod(index); } + static std::wstring getMethodName(kdlib::TypeInfo &typeInfo, size_t index) + { + AutoRestorePyState pystate; + return typeInfo.getMethodName(index); + } + static size_t getBaseClassesCount(kdlib::TypeInfo &typeInfo ) { AutoRestorePyState pystate; @@ -306,6 +312,8 @@ struct TypeInfoAdapter : public kdlib::TypeInfo { static python::list getFields( kdlib::TypeInfo &typeInfo ); + static python::list getMethods(kdlib::TypeInfo &typeInfo); + static python::list getElementDir(kdlib::TypeInfo &typeInfo); static bool isZero(kdlib::TypeInfo &typeInfo) { diff --git a/test/scripts/typeinfo.py b/test/scripts/typeinfo.py index 94dd680..f7be3b3 100644 --- a/test/scripts/typeinfo.py +++ b/test/scripts/typeinfo.py @@ -331,14 +331,17 @@ class TypeInfoTest( unittest.TestCase ): self.assertRaises(pykd.TypeException, pykd.baseTypes.UInt8B.arrayOf, 0xFFFFFFFFFFFFFFFF) def testMethodCount(self): - self.assertEqual( 12, target.module.type("classChild").getNumberMethods() ) - + self.assertEqual( 14, target.module.type("classChild").getNumberMethods() ) + def testGetMethod(self): self.assertEqual( "Int4B(__thiscall classChild::)(Int4B)", target.module.type("classChild").method("childMethod").name() ) self.assertEqual( "Int4B(__thiscall classChild::)(Int4B)", target.module.type("classChild").childMethod.name() ) self.assertEqual( "Int4B(__thiscall classChild::)(Int4B)", target.module.type("classChild").method(1).name() ) - def testGteBaseClass(self): + def testMethods(self): + self.assertEqual( 14, len(target.module.type("classChild").methods())) + + def testGetBaseClass(self): classChild = target.module.type("classChild") self.assertEqual( ["classBase1", "classBase2"], [ classChild.baseClass(i).name() for i in range(classChild.getNumberBaseClasses()) ] )