[0.3.x] added : typedVar.getLocation method ( Return location of the varibale )

git-svn-id: https://pykd.svn.codeplex.com/svn@90929 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\ussrhero_cp 2016-02-22 20:17:56 +00:00 committed by Mikhail I. Izmestev
parent 7497fed621
commit 84bf4b8bfd
4 changed files with 53 additions and 23 deletions

View File

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

View File

@ -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_<kdlib::VarStorage>("Location", "Location of a varibale")
.value("Reg", kdlib::RegisterVar)
.value("Memory", kdlib::MemoryVar)
;
python::enum_<kdlib::MemoryProtect>("memoryProtect", "Memory protection attribiuties")
.value("PageNoAccess", kdlib::PageNoAccess)
.value("PageReadOnly", kdlib::PageReadOnly)

View File

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

View File

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