mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-29 20:03:33 +08:00
[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:
parent
a0a7ef8196
commit
9cf68441ae
@ -579,6 +579,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="dbgexcept.h" />
|
<ClInclude Include="dbgexcept.h" />
|
||||||
<ClInclude Include="pycpucontext.h" />
|
<ClInclude Include="pycpucontext.h" />
|
||||||
|
<ClInclude Include="pydataaccess.h" />
|
||||||
<ClInclude Include="pydisasm.h" />
|
<ClInclude Include="pydisasm.h" />
|
||||||
<ClInclude Include="pydbgeng.h" />
|
<ClInclude Include="pydbgeng.h" />
|
||||||
<ClInclude Include="pydbgio.h" />
|
<ClInclude Include="pydbgio.h" />
|
||||||
|
@ -78,6 +78,9 @@
|
|||||||
<ClInclude Include="pyprocess.h">
|
<ClInclude Include="pyprocess.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="pydataaccess.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="stdafx.cpp">
|
<ClCompile Include="stdafx.cpp">
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#define PYKD_VERSION_MAJOR 0
|
#define PYKD_VERSION_MAJOR 0
|
||||||
#define PYKD_VERSION_MINOR 3
|
#define PYKD_VERSION_MINOR 3
|
||||||
#define PYKD_VERSION_SUBVERSION 2
|
#define PYKD_VERSION_SUBVERSION 2
|
||||||
#define PYKD_VERSION_BUILDNO 3
|
#define PYKD_VERSION_BUILDNO 5
|
||||||
|
|
||||||
#define __VER_STR2__(x) #x
|
#define __VER_STR2__(x) #x
|
||||||
#define __VER_STR1__(x) __VER_STR2__(x)
|
#define __VER_STR1__(x) __VER_STR2__(x)
|
||||||
|
@ -942,9 +942,13 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
.def("getNumberFields", TypedVarAdapter::getElementCount,
|
.def("getNumberFields", TypedVarAdapter::getElementCount,
|
||||||
"Return number of fields")
|
"Return number of fields")
|
||||||
.def("field", TypedVarAdapter::getField,
|
.def("field", TypedVarAdapter::getField,
|
||||||
"Return field of structure as an object attribute" )
|
"Return field of structure")
|
||||||
.def("field", TypedVarAdapter::getElementByIndex,
|
.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,
|
.def( "fields", TypedVarAdapter::getFields,
|
||||||
"Return list of tuple ( filedName, fieldOffset, fieldValue )" )
|
"Return list of tuple ( filedName, fieldOffset, fieldValue )" )
|
||||||
.def( "fieldName", TypedVarAdapter::getElementName,
|
.def( "fieldName", TypedVarAdapter::getElementName,
|
||||||
@ -964,9 +968,11 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
.def("call", python::raw_function(pykd::callFunctionByVar, 0) )
|
.def("call", python::raw_function(pykd::callFunctionByVar, 0) )
|
||||||
.def("__getattr__", TypedVarAdapter::getFieldAttr,
|
.def("__getattr__", TypedVarAdapter::getFieldAttr,
|
||||||
"Return field of structure as an object attribute" )
|
"Return field of structure as an object attribute" )
|
||||||
|
.def("__setattr__", TypedVarAdapter::setFieldAttr )
|
||||||
.def( "__str__", TypedVarAdapter::print )
|
.def( "__str__", TypedVarAdapter::print )
|
||||||
.def("__len__", TypedVarAdapter::getElementCount )
|
.def("__len__", TypedVarAdapter::getElementCount )
|
||||||
.def("__getitem__", TypedVarAdapter::getElementByIndex )
|
.def("__getitem__", TypedVarAdapter::getElementByIndex )
|
||||||
|
.def("__setitem__", TypedVarAdapter::setElementByIndex )
|
||||||
.def("__dir__", TypedVarAdapter::getElementsDir)
|
.def("__dir__", TypedVarAdapter::getElementsDir)
|
||||||
.def("__call__", python::raw_function(pykd::callFunctionByVar, 0) )
|
.def("__call__", python::raw_function(pykd::callFunctionByVar, 0) )
|
||||||
//.def("__getitem__", &kdlib::TypedVar::getElementByIndexPtr )
|
//.def("__getitem__", &kdlib::TypedVar::getElementByIndexPtr )
|
||||||
|
@ -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)
|
python::list TypedVarAdapter::getRawBytes(kdlib::TypedVar& typedVar)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ namespace python = boost::python;
|
|||||||
#include "stladaptor.h"
|
#include "stladaptor.h"
|
||||||
#include "pythreadstate.h"
|
#include "pythreadstate.h"
|
||||||
#include "dbgexcept.h"
|
#include "dbgexcept.h"
|
||||||
|
#include "variant.h"
|
||||||
|
|
||||||
namespace pykd {
|
namespace pykd {
|
||||||
|
|
||||||
@ -109,8 +110,16 @@ struct TypedVarAdapter {
|
|||||||
return typedVar.getElement( name );
|
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 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 )
|
static size_t getElementCount( kdlib::TypedVar& typedVar )
|
||||||
{
|
{
|
||||||
AutoRestorePyState pystate;
|
AutoRestorePyState pystate;
|
||||||
@ -129,6 +138,12 @@ struct TypedVarAdapter {
|
|||||||
return typedVar.getElement( index );
|
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"")
|
static kdlib::TypedVarPtr getMethodByName(kdlib::TypedVar& typedVar, const std::wstring &name, const std::wstring &prototype = L"")
|
||||||
{
|
{
|
||||||
AutoRestorePyState pystate;
|
AutoRestorePyState pystate;
|
||||||
|
@ -426,3 +426,10 @@ class TypedVarTest( unittest.TestCase ):
|
|||||||
def testRawBytes(self):
|
def testRawBytes(self):
|
||||||
self.assertEqual( [ 0x55, 0x55, 0, 0], target.module.typedVar( "ulongConst" ).rawBytes() )
|
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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user