[0.3.x] added : typedVar.setField method ( Set field of a structire or an element od array )

git-svn-id: https://pykd.svn.codeplex.com/svn@91217 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\ussrhero_cp 2017-04-22 11:04:43 +00:00 committed by Mikhail I. Izmestev
parent a0a7ef8196
commit 9cf68441ae
7 changed files with 53 additions and 3 deletions

View File

@ -579,6 +579,7 @@
<ItemGroup>
<ClInclude Include="dbgexcept.h" />
<ClInclude Include="pycpucontext.h" />
<ClInclude Include="pydataaccess.h" />
<ClInclude Include="pydisasm.h" />
<ClInclude Include="pydbgeng.h" />
<ClInclude Include="pydbgio.h" />

View File

@ -78,6 +78,9 @@
<ClInclude Include="pyprocess.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="pydataaccess.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">

View File

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

View File

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

View File

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

View File

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

View File

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