From 03ff35d64f154b59ff5caf8b4636065c7975b694 Mon Sep 17 00:00:00 2001 From: "SND\\ussrhero_cp" Date: Thu, 5 Jan 2017 10:03:10 +0000 Subject: [PATCH] [0.3.x] added : typedVar.method has optional argument 'prototype' to work with overloaded methods git-svn-id: https://pykd.svn.codeplex.com/svn@91089 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/pymod.cpp | 2 +- pykd/pytypedvar.h | 4 ++-- test/scripts/typedvar.py | 6 ++++++ test/scripts/typeinfo.py | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index 48154ec..9e6aad6 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -938,7 +938,7 @@ BOOST_PYTHON_MODULE( pykd ) "Return list of tuple ( filedName, fieldOffset, fieldValue )" ) .def( "fieldName", TypedVarAdapter::getElementName, "Return name of struct field by index" ) - .def("method", TypedVarAdapter::getMethodByName, + .def("method", TypedVarAdapter::getMethodByName, ( python::arg("name"), python::arg("prototype") = "" ), "Return method of class as an object attribute" ) .def("deref",TypedVarAdapter::deref, "Return value by pointer" ) diff --git a/pykd/pytypedvar.h b/pykd/pytypedvar.h index e0a1268..c444342 100644 --- a/pykd/pytypedvar.h +++ b/pykd/pytypedvar.h @@ -129,10 +129,10 @@ struct TypedVarAdapter { return typedVar.getElement( index ); } - static kdlib::TypedVarPtr getMethodByName(kdlib::TypedVar& typedVar, const std::wstring &name) + static kdlib::TypedVarPtr getMethodByName(kdlib::TypedVar& typedVar, const std::wstring &name, const std::wstring &prototype = L"") { AutoRestorePyState pystate; - return typedVar.getMethod(name); + return typedVar.getMethod(name, prototype); } static std::wstring print( kdlib::TypedVar& typedVar ) diff --git a/test/scripts/typedvar.py b/test/scripts/typedvar.py index 9205b6a..c7bb187 100644 --- a/test/scripts/typedvar.py +++ b/test/scripts/typedvar.py @@ -401,12 +401,18 @@ class TypedVarTest( unittest.TestCase ): def testCallMethod(self): g_classChild = target.module.typedVar("g_classChild") + self.assertEqual( 1000*5, g_classChild.method("childMethod").call(10) ) self.assertEqual( 1000*5, g_classChild.childMethod(10) ) def testCallStdStr(self): g_stdString = target.module.typedVar("g_stdString") self.assertEqual( "testString".find('S'), g_stdString.find_first_of(ord('S'), 0) ) + def testCallOverloadMethod(self): + g_classChild = target.module.typedVar("g_classChild") + self.assertEqual( 10*10, g_classChild.method("overloadMethod", "Int4B(__thiscall)(Int4B)").call(10)) + self.assertEqual( 5*8, g_classChild.method("overloadMethod", "Int4B(__thiscall)(Int4B,Int4B)").call(5,8)) + def testGetTypedVar(self): addr = pykd.getOffset("g_structTest") self.assertTrue( None != target.module.type( "structTest" ).getTypedVar(addr) ) diff --git a/test/scripts/typeinfo.py b/test/scripts/typeinfo.py index 7dbfcb3..ad20f58 100644 --- a/test/scripts/typeinfo.py +++ b/test/scripts/typeinfo.py @@ -329,7 +329,7 @@ class TypeInfoTest( unittest.TestCase ): self.assertRaises(pykd.TypeException, pykd.baseTypes.UInt8B.arrayOf, 0xFFFFFFFFFFFFFFFF) def testMethodCount(self): - self.assertEqual( 8, target.module.type("classChild").getNumberMethods() ) + self.assertEqual( 12, target.module.type("classChild").getNumberMethods() ) def testGetMethod(self): self.assertEqual( "Int4B(__thiscall classChild::)(Int4B)", target.module.type("classChild").method("childMethod").name() )