diff --git a/pykd/pykdver.h b/pykd/pykdver.h index d8cac0e..58c13a8 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 0 -#define PYKD_VERSION_BUILDNO 37 +#define PYKD_VERSION_BUILDNO 38 #define __VER_STR2__(x) #x #define __VER_STR1__(x) __VER_STR2__(x) diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index 2a226a1..3a8a1ac 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -648,46 +648,46 @@ BOOST_PYTHON_MODULE( pykd ) .def("__init__", python::make_constructor(&ModuleAdapter::loadModuleByName)) .def("__init__", python::make_constructor(&ModuleAdapter::loadModuleByOffset)) .def("begin", ModuleAdapter::getBase, - "Return start address of the module") + "Return start address of the module") .def("end", ModuleAdapter::getEnd, - "Return end address of the module") + "Return end address of the module") .def("size", ModuleAdapter::getSize, - "Return size of the module") + "Return size of the module") .def("name", ModuleAdapter::getName, - "Return name of the module") + "Return name of the module") .def("reload", ModuleAdapter::reloadSymbols, - "(Re)load symbols for the module") + "(Re)load symbols for the module") .def("image", ModuleAdapter::getImageName, - "Return name of the image of the module") + "Return name of the image of the module") .def("symfile", ModuleAdapter::getSymFile, - "Return the full path to the module's symbol information") + "Return the full path to the module's symbol information") .def("offset", ModuleAdapter::getSymbolVa, - "Return offset of the symbol") + "Return offset of the symbol") .def("findSymbol", ModuleAdapter::findSymbol, Module_findSymbol(python::args("offset", "showDisplacement"), - "Return symbol name by virtual address")) + "Return symbol name by virtual address")) .def("findSymbolAndDisp", ModuleAdapter::findSymbolAndDisp, - "Return tuple(symbol_name, displacement) by virtual address") + "Return tuple(symbol_name, displacement) by virtual address") .def("rva", ModuleAdapter::getSymbolRva, - "Return rva of the symbol") + "Return rva of the symbol") .def("sizeof", ModuleAdapter::getSymbolSize, - "Return a size of the type or variable") + "Return a size of the type or variable") .def("type", ModuleAdapter::getTypeByName, - "Return typeInfo class by type name") + "Return typeInfo class by type name") .def("typedVar", ModuleAdapter::getTypedVarByAddr, - "Return a typedVar class instance") + "Return a typedVar class instance") .def("typedVar", ModuleAdapter::getTypedVarByName, - "Return a typedVar class instance") + "Return a typedVar class instance") .def("typedVar", ModuleAdapter::getTypedVarByTypeName, - "Return a typedVar class instance") + "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") + "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") + "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") + "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 )")) + "Return list of tuple ( symbolname, offset )")) .def("enumTypes", ModuleAdapter::enumTypes, Module_enumTypes(python::args("mask"), "Return list of types name")) .def("checksum", ModuleAdapter::getCheckSum, @@ -781,6 +781,8 @@ BOOST_PYTHON_MODULE( pykd ) .def("__init__", python::make_constructor(pykd::getTypedVarByName) ) .def("__init__", python::make_constructor(pykd::getTypedVarByTypeName) ) .def("__init__", python::make_constructor(pykd::getTypedVarByTypeInfo) ) + .def("getLocation", TypedVarAdapter::getLocation, + "Return location of the varibale") .def("getAddress", TypedVarAdapter::getAddress, "Return virtual address" ) .def("getDebugStart", TypedVarAdapter::getDebugStart, @@ -1054,6 +1056,11 @@ BOOST_PYTHON_MODULE( pykd ) .value("AMD64", kdlib::CPU_AMD64 ) ; + python::enum_("Location", "Location of a varibale") + .value("Reg", kdlib::RegisterVar) + .value("Memory", kdlib::MemoryVar) + ; + python::enum_("memoryProtect", "Memory protection attribiuties") .value("PageNoAccess", kdlib::PageNoAccess) .value("PageReadOnly", kdlib::PageReadOnly) diff --git a/pykd/pytypedvar.h b/pykd/pytypedvar.h index b80dd1c..86f1c72 100644 --- a/pykd/pytypedvar.h +++ b/pykd/pytypedvar.h @@ -50,6 +50,26 @@ inline kdlib::TypedVarPtr containingRecordByType( kdlib::MEMOFFSET_64 offset, kd struct TypedVarAdapter { + static python::tuple getLocation(kdlib::TypedVar& typedVar) + { + + kdlib::VarStorage storage; + std::wstring regName; + kdlib::MEMOFFSET_64 memOffset; + { + AutoRestorePyState pystate; + storage = typedVar.getStorage(); + if (storage == kdlib::RegisterVar) + regName = typedVar.getRegisterName(); + else + memOffset = typedVar.getAddress(); + } + + if (storage == kdlib::RegisterVar) + return python::make_tuple(storage, regName); + return python::make_tuple(storage, memOffset); + } + static kdlib::MEMOFFSET_64 getAddress( kdlib::TypedVar& typedVar ) { AutoRestorePyState pystate; diff --git a/test/scripts/typedvar.py b/test/scripts/typedvar.py index 35f2ee6..66feeb2 100644 --- a/test/scripts/typedvar.py +++ b/test/scripts/typedvar.py @@ -1,4 +1,4 @@ -# +# # # @@ -344,3 +344,6 @@ class TypedVarTest( unittest.TestCase ): int, pykd.typedVar(pykd.baseTypes.UInt4B, 0xFFFFFFFFFFFFFFFF)) + def testLocation(self): + tv = target.module.typedVar( "structTest", target.module.g_structTest ) + self.assertEqual( ( pykd.Location.Memory, tv.getAddress()), tv.getLocation() )