diff --git a/pykd/pykd_vc120.vcxproj b/pykd/pykd_vc120.vcxproj
index ccdd926..3bc43ae 100644
--- a/pykd/pykd_vc120.vcxproj
+++ b/pykd/pykd_vc120.vcxproj
@@ -579,6 +579,7 @@
+
diff --git a/pykd/pykd_vc120.vcxproj.filters b/pykd/pykd_vc120.vcxproj.filters
index ffa05a7..464d7d1 100644
--- a/pykd/pykd_vc120.vcxproj.filters
+++ b/pykd/pykd_vc120.vcxproj.filters
@@ -78,6 +78,9 @@
Header Files
+
+ Header Files
+
diff --git a/pykd/pykdver.h b/pykd/pykdver.h
index 4c9caf4..ab49d4b 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 2
-#define PYKD_VERSION_BUILDNO 3
+#define PYKD_VERSION_BUILDNO 5
#define __VER_STR2__(x) #x
#define __VER_STR1__(x) __VER_STR2__(x)
diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp
index 95f63b5..169d346 100644
--- a/pykd/pymod.cpp
+++ b/pykd/pymod.cpp
@@ -942,9 +942,13 @@ BOOST_PYTHON_MODULE( pykd )
.def("getNumberFields", TypedVarAdapter::getElementCount,
"Return number of fields")
.def("field", TypedVarAdapter::getField,
- "Return field of structure as an object attribute" )
+ "Return field of structure")
.def("field", TypedVarAdapter::getElementByIndex,
- "Return field of structure as an object attribute" )
+ "Return field of structure or array" )
+ .def("setField", TypedVarAdapter::setField,
+ "Set field of structure")
+ .def("setField", TypedVarAdapter::setElementByIndex,
+ "Set field of a structire or an element od array")
.def( "fields", TypedVarAdapter::getFields,
"Return list of tuple ( filedName, fieldOffset, fieldValue )" )
.def( "fieldName", TypedVarAdapter::getElementName,
@@ -964,9 +968,11 @@ BOOST_PYTHON_MODULE( pykd )
.def("call", python::raw_function(pykd::callFunctionByVar, 0) )
.def("__getattr__", TypedVarAdapter::getFieldAttr,
"Return field of structure as an object attribute" )
+ .def("__setattr__", TypedVarAdapter::setFieldAttr )
.def( "__str__", TypedVarAdapter::print )
.def("__len__", TypedVarAdapter::getElementCount )
.def("__getitem__", TypedVarAdapter::getElementByIndex )
+ .def("__setitem__", TypedVarAdapter::setElementByIndex )
.def("__dir__", TypedVarAdapter::getElementsDir)
.def("__call__", python::raw_function(pykd::callFunctionByVar, 0) )
//.def("__getitem__", &kdlib::TypedVar::getElementByIndexPtr )
diff --git a/pykd/pytypedvar.cpp b/pykd/pytypedvar.cpp
index 6b2f67e..c9823f1 100644
--- a/pykd/pytypedvar.cpp
+++ b/pykd/pytypedvar.cpp
@@ -200,6 +200,24 @@ kdlib::TypedVarPtr TypedVarAdapter::getFieldAttr(kdlib::TypedVar& typedVar, cons
///////////////////////////////////////////////////////////////////////////////
+void TypedVarAdapter::setFieldAttr(kdlib::TypedVar& typedVar, const std::wstring &name, NumVariantAdaptor& var)
+{
+ try
+ {
+ AutoRestorePyState pystate;
+ typedVar.setElement(name, var);
+ return;
+ }
+ catch (kdlib::TypeException&)
+ {}
+
+ std::wstringstream sstr;
+ sstr << L"typed var has no field " << L'\'' << name << L'\'';
+ throw AttributeException(std::string(_bstr_t(sstr.str().c_str())).c_str());
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
python::list TypedVarAdapter::getRawBytes(kdlib::TypedVar& typedVar)
{
diff --git a/pykd/pytypedvar.h b/pykd/pytypedvar.h
index ad02661..dfe2559 100644
--- a/pykd/pytypedvar.h
+++ b/pykd/pytypedvar.h
@@ -11,6 +11,7 @@ namespace python = boost::python;
#include "stladaptor.h"
#include "pythreadstate.h"
#include "dbgexcept.h"
+#include "variant.h"
namespace pykd {
@@ -108,8 +109,16 @@ struct TypedVarAdapter {
AutoRestorePyState pystate;
return typedVar.getElement( name );
}
+
+ static void setField(kdlib::TypedVar& typedVar, const std::wstring &name, NumVariantAdaptor& var)
+ {
+ AutoRestorePyState pystate;
+ typedVar.setElement(name, var);
+ }
static kdlib::TypedVarPtr getFieldAttr(kdlib::TypedVar& typedVar, const std::wstring &name);
+
+ static void setFieldAttr(kdlib::TypedVar& typedVar, const std::wstring &name, NumVariantAdaptor& var);
static size_t getElementCount( kdlib::TypedVar& typedVar )
{
@@ -129,6 +138,12 @@ struct TypedVarAdapter {
return typedVar.getElement( index );
}
+ static void setElementByIndex(kdlib::TypedVar& typedVar, long index, NumVariantAdaptor& var)
+ {
+ AutoRestorePyState pystate;
+ typedVar.setElement(index, var);
+ }
+
static kdlib::TypedVarPtr getMethodByName(kdlib::TypedVar& typedVar, const std::wstring &name, const std::wstring &prototype = L"")
{
AutoRestorePyState pystate;
diff --git a/test/scripts/typedvar.py b/test/scripts/typedvar.py
index 9b6d146..76c1303 100644
--- a/test/scripts/typedvar.py
+++ b/test/scripts/typedvar.py
@@ -425,4 +425,11 @@ class TypedVarTest( unittest.TestCase ):
def testRawBytes(self):
self.assertEqual( [ 0x55, 0x55, 0, 0], target.module.typedVar( "ulongConst" ).rawBytes() )
+
+ def testSetField(self):
+ var = target.module.typedVar("structTest", [0x55] * 20 )
+ var.setField("m_field2", 0xAA)
+ var.m_field3 == 0xAAAA
+ self.assertEqual( 0xAAAA, var.m_filed3)
+
\ No newline at end of file