From 16c796799bb4af2fc3a713fdaa7469c784a7e45c Mon Sep 17 00:00:00 2001
From: "SND\\ussrhero_cp"
 <SND\ussrhero_cp@9b283d60-5439-405e-af05-b73fd8c4d996>
Date: Sat, 22 Apr 2017 12:30:46 +0000
Subject: [PATCH] [0.3.x] added : module.typedVar can accept python byte
 sequance

git-svn-id: https://pykd.svn.codeplex.com/svn@91218 9b283d60-5439-405e-af05-b73fd8c4d996
---
 pykd/pymod.cpp  | 97 ++++++++++++++++++++++++-------------------------
 pykd/pymodule.h |  6 +--
 2 files changed, 51 insertions(+), 52 deletions(-)

diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp
index 169d346..fb9c4d2 100644
--- a/pykd/pymod.cpp
+++ b/pykd/pymod.cpp
@@ -767,54 +767,54 @@ BOOST_PYTHON_MODULE( pykd )
         .def("__str__", TargetThreadAdapter::print)
         ;
 
-	python::class_<kdlib::Module, kdlib::ModulePtr, python::bases<kdlib::NumBehavior>, 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("typedVar", ModuleAdapter::getTypedVarWithPrototype,
-			"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"))
+    python::class_<kdlib::Module, kdlib::ModulePtr, python::bases<kdlib::NumBehavior>, 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("typedVar", ModuleAdapter::getTypedVarWithPrototype,
+            "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,
@@ -920,7 +920,6 @@ BOOST_PYTHON_MODULE( pykd )
 #endif
         ;
 
-
     python::class_<kdlib::TypedVar, kdlib::TypedVarPtr, python::bases<kdlib::NumBehavior>, boost::noncopyable >("typedVar", 
         "Class of non-primitive type object, child class of typeClass. Data from target is copied into object instance", python::no_init  )
         .def("__init__", python::make_constructor(pykd::getTypedVarByName) )
diff --git a/pykd/pymodule.h b/pykd/pymodule.h
index 5c938d6..33fec8d 100644
--- a/pykd/pymodule.h
+++ b/pykd/pymodule.h
@@ -11,6 +11,7 @@
 #include "stladaptor.h"
 #include "pythreadstate.h"
 #include "dbgexcept.h"
+#include "pytypedvar.h"
 
 namespace pykd {
 
@@ -125,10 +126,9 @@ struct ModuleAdapter : public kdlib::Module
         return module.getTypedVarByName(symbolName);
     }
 
-    static kdlib::TypedVarPtr getTypedVarByTypeName( kdlib::Module& module, const std::wstring &typeName, kdlib::MEMOFFSET_64 offset )
+    static kdlib::TypedVarPtr getTypedVarByTypeName( kdlib::Module& module, const std::wstring &typeName, python::object& dataStorage )
     {
-        AutoRestorePyState  pystate;
-        return module.getTypedVarByTypeName(typeName, offset);
+        return  getTypedVarByTypeInfo( getTypeByName(module, typeName), dataStorage);
     }
 
     static kdlib::TypedVarPtr getTypedVarWithPrototype(kdlib::Module& module, const std::wstring &symbolName, const std::wstring &prototype)