From 7831e430aeff6b00a8626710c70f5fd5d236b143 Mon Sep 17 00:00:00 2001 From: "SND\\ussrhero_cp" Date: Fri, 22 Jan 2016 23:00:09 +0000 Subject: [PATCH] [0.3.x] added : module.enumTypes method ( return list of types name ) git-svn-id: https://pykd.svn.codeplex.com/svn@90913 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/pymod.cpp | 91 +++++++++++++++++++++------------------- pykd/pymodule.cpp | 17 ++++++++ pykd/pymodule.h | 2 + test/scripts/typeinfo.py | 11 ++++- 4 files changed, 76 insertions(+), 45 deletions(-) diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index 664c84d..65bf83b 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -83,6 +83,7 @@ BOOST_PYTHON_FUNCTION_OVERLOADS( setHardwareBreakpoint_, Breakpoint::setHardware BOOST_PYTHON_FUNCTION_OVERLOADS( Module_enumSymbols, ModuleAdapter::enumSymbols, 1, 2 ); BOOST_PYTHON_FUNCTION_OVERLOADS( Module_findSymbol, ModuleAdapter::findSymbol, 2, 3 ); +BOOST_PYTHON_FUNCTION_OVERLOADS( Module_enumTypes, ModuleAdapter::enumTypes, 1, 2 ); BOOST_PYTHON_FUNCTION_OVERLOADS( TypeInfo_ptrTo, TypeInfoAdapter::ptrTo, 1, 2 ); @@ -641,50 +642,52 @@ BOOST_PYTHON_MODULE( pykd ) "Get thread's stack tarce") ; - python::class_, boost::noncopyable>("module", "Class representing executable module", python::no_init ) - .def("__init__", python::make_constructor(&ModuleAdapter::loadModuleByName ) ) - .def("__init__", python::make_constructor(&ModuleAdapter::loadModuleByOffset) ) - .def("begin", ModuleAdapter::getBase, - "Return start address of the module" ) - .def("end", ModuleAdapter::getEnd, - "Return end address of the module" ) - .def("size", ModuleAdapter::getSize, - "Return size of the module" ) - .def("name", ModuleAdapter::getName, - "Return name of the module" ) - .def("reload", ModuleAdapter::reloadSymbols, - "(Re)load symbols for the module" ) - .def("image", ModuleAdapter::getImageName, - "Return name of the image of the module" ) - .def("symfile", ModuleAdapter::getSymFile, - "Return the full path to the module's symbol information" ) - .def("offset", ModuleAdapter::getSymbolVa, - "Return offset of the symbol" ) - .def("findSymbol", ModuleAdapter::findSymbol, Module_findSymbol( python::args("offset", "showDisplacement"), - "Return symbol name by virtual address" ) ) - .def("findSymbolAndDisp", ModuleAdapter::findSymbolAndDisp, - "Return tuple(symbol_name, displacement) by virtual address" ) - .def("rva", ModuleAdapter::getSymbolRva, - "Return rva of the symbol" ) - .def("sizeof", ModuleAdapter::getSymbolSize, - "Return a size of the type or variable" ) - .def("type", ModuleAdapter::getTypeByName, - "Return typeInfo class by type name" ) - .def("typedVar", ModuleAdapter::getTypedVarByAddr, - "Return a typedVar class instance" ) - .def("typedVar",ModuleAdapter::getTypedVarByName, - "Return a typedVar class instance" ) - .def("typedVar", ModuleAdapter::getTypedVarByTypeName, - "Return a typedVar class instance" ) - .def("typedVarList", ModuleAdapter::getTypedVarListByTypeName, - "Return a list of the typedVar class instances. Each item represents an item of the linked list in the target memory" ) - .def("typedVarArray", ModuleAdapter::getTypedVarArrayByTypeName, - "Return a list of the typedVar class instances. Each item represents an item of the counted array in the target memory" ) - .def("containingRecord", ModuleAdapter::containingRecord, - "Return instance of the typedVar class. It's value are loaded from the target memory." - "The start address is calculated by the same method as the standard macro CONTAINING_RECORD does" ) - .def("enumSymbols", ModuleAdapter::enumSymbols, Module_enumSymbols( python::args("mask"), - "Return list of tuple ( symbolname, offset )" ) ) + python::class_, boost::noncopyable>("module", "Class representing executable module", python::no_init) + .def("__init__", python::make_constructor(&ModuleAdapter::loadModuleByName)) + .def("__init__", python::make_constructor(&ModuleAdapter::loadModuleByOffset)) + .def("begin", ModuleAdapter::getBase, + "Return start address of the module") + .def("end", ModuleAdapter::getEnd, + "Return end address of the module") + .def("size", ModuleAdapter::getSize, + "Return size of the module") + .def("name", ModuleAdapter::getName, + "Return name of the module") + .def("reload", ModuleAdapter::reloadSymbols, + "(Re)load symbols for the module") + .def("image", ModuleAdapter::getImageName, + "Return name of the image of the module") + .def("symfile", ModuleAdapter::getSymFile, + "Return the full path to the module's symbol information") + .def("offset", ModuleAdapter::getSymbolVa, + "Return offset of the symbol") + .def("findSymbol", ModuleAdapter::findSymbol, Module_findSymbol(python::args("offset", "showDisplacement"), + "Return symbol name by virtual address")) + .def("findSymbolAndDisp", ModuleAdapter::findSymbolAndDisp, + "Return tuple(symbol_name, displacement) by virtual address") + .def("rva", ModuleAdapter::getSymbolRva, + "Return rva of the symbol") + .def("sizeof", ModuleAdapter::getSymbolSize, + "Return a size of the type or variable") + .def("type", ModuleAdapter::getTypeByName, + "Return typeInfo class by type name") + .def("typedVar", ModuleAdapter::getTypedVarByAddr, + "Return a typedVar class instance") + .def("typedVar", ModuleAdapter::getTypedVarByName, + "Return a typedVar class instance") + .def("typedVar", ModuleAdapter::getTypedVarByTypeName, + "Return a typedVar class instance") + .def("typedVarList", ModuleAdapter::getTypedVarListByTypeName, + "Return a list of the typedVar class instances. Each item represents an item of the linked list in the target memory") + .def("typedVarArray", ModuleAdapter::getTypedVarArrayByTypeName, + "Return a list of the typedVar class instances. Each item represents an item of the counted array in the target memory") + .def("containingRecord", ModuleAdapter::containingRecord, + "Return instance of the typedVar class. It's value are loaded from the target memory." + "The start address is calculated by the same method as the standard macro CONTAINING_RECORD does") + .def("enumSymbols", ModuleAdapter::enumSymbols, Module_enumSymbols(python::args("mask"), + "Return list of tuple ( symbolname, offset )")) + .def("enumTypes", ModuleAdapter::enumTypes, Module_enumTypes(python::args("mask"), + "Return list of types name")) .def("checksum", ModuleAdapter::getCheckSum, "Return a image file checksum: IMAGE_OPTIONAL_HEADER.CheckSum" ) .def("timestamp", ModuleAdapter::getTimeDataStamp, diff --git a/pykd/pymodule.cpp b/pykd/pymodule.cpp index 0866ebd..d6ce49e 100644 --- a/pykd/pymodule.cpp +++ b/pykd/pymodule.cpp @@ -70,6 +70,23 @@ python::list ModuleAdapter::enumSymbols( kdlib::Module& module, const std::wstri /////////////////////////////////////////////////////////////////////////////// +python::list ModuleAdapter::enumTypes(kdlib::Module& module, const std::wstring &mask) +{ + kdlib::TypeNameList typeLst; + + do { + AutoRestorePyState pystate; + typeLst = module.enumTypes(mask); + } while (false); + + python::list pyLst; + for (kdlib::TypeNameList::const_iterator it = typeLst.begin(); it != typeLst.end(); ++it) + pyLst.append(*it); + return pyLst; +} + +/////////////////////////////////////////////////////////////////////////////// + std::wstring ModuleAdapter::findSymbol( kdlib::Module& module, kdlib::MEMOFFSET_64 offset, bool showDisplacement ) { diff --git a/pykd/pymodule.h b/pykd/pymodule.h index 86537cb..03507bc 100644 --- a/pykd/pymodule.h +++ b/pykd/pymodule.h @@ -161,6 +161,8 @@ struct ModuleAdapter : public kdlib::Module static python::list enumSymbols( kdlib::Module& module, const std::wstring &mask = L"*" ); + static python::list enumTypes(kdlib::Module& module, const std::wstring &mask = L"*"); + static std::wstring findSymbol( kdlib::Module& module, kdlib::MEMOFFSET_64 offset, bool showDisplacement = true ); static python::tuple findSymbolAndDisp( kdlib::Module& module, kdlib::MEMOFFSET_64 offset ); diff --git a/test/scripts/typeinfo.py b/test/scripts/typeinfo.py index 2379d0e..e566705 100644 --- a/test/scripts/typeinfo.py +++ b/test/scripts/typeinfo.py @@ -1,4 +1,4 @@ -# +# # # @@ -316,3 +316,12 @@ class TypeInfoTest( unittest.TestCase ): self.assertEqual(5, len(dir(ti))) self.assertTrue("m_field3" in dir(ti)) self.assertFalse("m_field33" in dir(ti)) + + def testEnumTypes(self): + lst = target.module.enumTypes() + self.assertNotEqual([], lst) + lst = target.module.enumTypes("structTest") + self.assertEqual(["structTest"], lst) + lst = target.module.enumTypes("NonExsistType") + self.assertEqual([],lst) +