added : typeInfo.getMethodName ( Return method's name )

added : typeInfo.methods ( Return list of tuples ( methodName,
methodType ) )
This commit is contained in:
ussrhero 2018-10-03 00:52:41 +03:00
parent 67c66c593c
commit 2509de349b
6 changed files with 48 additions and 5 deletions

@ -1 +1 @@
Subproject commit c1cd0e4fd727d87d23e1cf26e214ca45068d00e5
Subproject commit 65930b3307d248503d3c1051f61b50476437845b

View File

@ -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)

View File

@ -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,

View File

@ -103,6 +103,34 @@ python::list TypeInfoAdapter::getFields( kdlib::TypeInfo &typeInfo )
return pylst;
}
python::list TypeInfoAdapter::getMethods(kdlib::TypeInfo &typeInfo)
{
typedef boost::tuple<std::wstring, kdlib::TypeInfoPtr> FieldTuple;
std::list<FieldTuple> 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<FieldTuple>::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)

View File

@ -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) {

View File

@ -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()) ] )