From 10e12fc6b6b3401c2049fd4629ce39852ae6c074 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Mon, 31 Oct 2011 09:10:43 +0000 Subject: [PATCH] [0.1.x] added : typedVar class git-svn-id: https://pykd.svn.codeplex.com/svn@70920 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgevent.h | 2 +- pykd/dbgext.cpp | 99 +++++++++++++++++++++++-- pykd/dbgmem.cpp | 4 +- pykd/intbase.h | 169 +++++++++++++++++++++--------------------- pykd/pykd_2008.vcproj | 4 + pykd/typedvar.cpp | 25 +++++++ pykd/typedvar.h | 48 +++++++++++- pykd/typeinfo.cpp | 32 ++++++++ pykd/typeinfo.h | 14 +++- 9 files changed, 301 insertions(+), 96 deletions(-) create mode 100644 pykd/typedvar.cpp diff --git a/pykd/dbgevent.h b/pykd/dbgevent.h index 6a34b60..aaacaf4 100644 --- a/pykd/dbgevent.h +++ b/pykd/dbgevent.h @@ -90,7 +90,7 @@ protected: ///////////////////////////////////////////////////////////////////////////////// -class EventHandlerWrap : public boost::python::wrapper, public EventHandler +class EventHandlerWrap : public python::wrapper, public EventHandler { public: diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 3554340..9d02a86 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -16,6 +16,7 @@ #include "typeinfo.h" #include "typedvar.h" #include "dbgmem.h" +#include "intbase.h" using namespace pykd; @@ -75,6 +76,88 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( DebugClient_loadQWords, DebugClient::loa BOOST_PYTHON_MODULE( pykd ) { + python::class_( "intBase", "intBase", python::no_init ) + .def( int_( boost::python::self ) ) + //.def( boost::python::self = long() ) + + .def( boost::python::self + long() ) + .def( long() + boost::python::self ) + .def( boost::python::self += long() ) + .def( boost::python::self + boost::python::self ) + .def( boost::python::self += boost::python::self ) + + .def( boost::python::self - long() ) + .def( long() - boost::python::self ) + .def( boost::python::self -= long() ) + .def( boost::python::self - boost::python::self ) + .def( boost::python::self -= boost::python::self ) + + .def( boost::python::self * long() ) + .def( long() * boost::python::self ) + .def( boost::python::self *= long() ) + .def( boost::python::self * boost::python::self ) + .def( boost::python::self *= boost::python::self ) + + .def( boost::python::self / long() ) + .def( long() / boost::python::self ) + .def( boost::python::self /= long() ) + .def( boost::python::self / boost::python::self ) + .def( boost::python::self /= boost::python::self ) + + .def( boost::python::self % long() ) + .def( long() % boost::python::self ) + .def( boost::python::self %= long() ) + .def( boost::python::self % boost::python::self ) + .def( boost::python::self %= boost::python::self ) + + .def( boost::python::self & long() ) + .def( long() & boost::python::self ) + .def( boost::python::self &= long() ) + .def( boost::python::self & boost::python::self ) + .def( boost::python::self &= boost::python::self ) + + .def( boost::python::self | long() ) + .def( long() | boost::python::self ) + .def( boost::python::self |= long() ) + .def( boost::python::self | boost::python::self ) + .def( boost::python::self |= boost::python::self ) + + .def( boost::python::self ^ long() ) + .def( long() ^ boost::python::self ) + .def( boost::python::self ^= long() ) + .def( boost::python::self ^ boost::python::self ) + .def( boost::python::self ^= boost::python::self ) + + .def( boost::python::self << long() ) + .def( boost::python::self <<= long() ) + + .def( boost::python::self >> long() ) + .def( boost::python::self >>= long() ) + + .def( boost::python::self < long() ) + .def( boost::python::self < boost::python::self ) + + .def( boost::python::self <= long() ) + .def( boost::python::self <= boost::python::self ) + + .def( boost::python::self == long() ) + .def( boost::python::self == boost::python::self ) + + .def( boost::python::self >= long() ) + .def( boost::python::self >= boost::python::self ) + + .def( boost::python::self > long() ) + .def( boost::python::self > boost::python::self ) + + .def( boost::python::self != long() ) + .def( boost::python::self != boost::python::self ) + + .def( ~boost::python::self ) + .def( !boost::python::self ) + + .def( "__str__", &intBase::str ) + .def( "__hex__", &intBase::hex ); + python::class_("dbgClient", "Class representing a debugging session", python::no_init ) .def( "loadDump", &pykd::DebugClient::loadDump, "Load crash dump" ) @@ -191,19 +274,23 @@ BOOST_PYTHON_MODULE( pykd ) .def( "field", &pykd::TypeInfo::getField ) .def( "__getattr__", &pykd::TypeInfo::getField ); - python::class_("typedVar", - "Class of non-primitive type object, child class of typeClass. Data from target is copied into object instance", + python::class_ >("typedVar", + "Class of non-primitive type object, child class of typeClass. Data from target is copied into object instance", python::no_init ) - .def("getAddress", &pykd::TypedVar::getAddress, + .def( python::init() ) + .def("getAddress", &TypedVar::getAddress, "Return virtual address" ) - .def("sizeof", &pykd::TypedVar::getSize, - "Return size of a variable in the target memory" ); + .def("sizeof", &TypedVar::getSize, + "Return size of a variable in the target memory" ) + .def("__getattr__", &TypedVar::getField, + "Return field of structure as an object attribute" ) + .def( "__str__", &TypedVar::print ); + //.def("data", &pykd::TypedVar::data, // "Return raw string object with data stream" ); //.def("__getattr__", &pykd::TypedVar::getFieldWrap, // "Return field of structure as an object attribute" ); - python::class_("module", "Class representing executable module", python::no_init ) .def("begin", &pykd::Module::getBase, "Return start address of the module" ) diff --git a/pykd/dbgmem.cpp b/pykd/dbgmem.cpp index fda9699..ab580dd 100644 --- a/pykd/dbgmem.cpp +++ b/pykd/dbgmem.cpp @@ -89,7 +89,7 @@ std::string DebugClient::loadChars( ULONG64 address, ULONG number, bool phyAddr { std::vector buffer(number); - ULONG bufferSize = sizeof(std::vector::value_type)*buffer.size(); + ULONG bufferSize = (ULONG)( sizeof(std::vector::value_type)*buffer.size() ); if (number) readMemory( address, &buffer[0], bufferSize, phyAddr ); @@ -108,7 +108,7 @@ std::wstring DebugClient::loadWChars( ULONG64 address, ULONG number, bool phyAd { std::vector buffer(number); - ULONG bufferSize = sizeof(std::vector::value_type)*buffer.size(); + ULONG bufferSize = (ULONG)( sizeof(std::vector::value_type)*buffer.size() ); if (number) readMemory( address, &buffer[0], bufferSize, phyAddr ); diff --git a/pykd/intbase.h b/pykd/intbase.h index fd35205..890420c 100644 --- a/pykd/intbase.h +++ b/pykd/intbase.h @@ -1,88 +1,87 @@ #pragma once +namespace pykd { -//class intBase : boost::integer_arithmetic -//{ -// -//public: -// -// explicit intBase( ULONG64 val = 0 ) : m_value( val) {} -// -// virtual ~intBase() {} -// -// operator ULONG64() const { -// return value(); -// } -// -// intBase& operator= ( ULONG64 val ) { -// setValue( val ); -// return *this; -// } -// -// virtual ULONG64 value() const { -// return m_value; -// } -// -// virtual void setValue( ULONG64 value) { -// m_value = value; -// } -// -// std::string -// str() const { -// std::stringstream ss; -// ss << value(); -// return ss.str(); -// } -// -// std::string -// hex() const { -// std::stringstream ss; -// ss << std::hex << value(); -// return ss.str(); -// } -// -// template -// intBase& operator+=(T const& rhs) -// { m_value += rhs; return *this; } -// -// template -// intBase& operator-=(T const& rhs) -// { m_value -= rhs; return *this; } -// -// template -// intBase& operator*=(T const& rhs) -// { m_value *= rhs; return *this; } -// -// template -// intBase& operator/=(T const& rhs) -// { m_value /= rhs; return *this; } -// -// template -// intBase& operator%=(T const& rhs) -// { m_value %= rhs; return *this; } -// -// template -// intBase& operator&=(T const& rhs) -// { m_value &= rhs; return *this; } -// -// template -// intBase& operator|=(T const& rhs) -// { m_value |= rhs; return *this; } -// -// template -// intBase& operator^=(T const& rhs) -// { m_value ^= rhs; return *this; } -// -// template -// intBase& operator<<=(T const& rhs) -// { m_value <<= rhs; return *this; } -// -// template -// intBase& operator>>=(T const& rhs) -// { m_value >>= rhs; return *this; } -// -//protected: -// -// mutable ULONG64 m_value; -// -//}; \ No newline at end of file +class intBase : boost::integer_arithmetic +{ + +public: + + operator ULONG64() const { + return getValue(); + } + + intBase& operator= ( ULONG64 val ) { + setValue( val ); + return *this; + } + + virtual ULONG64 getValue() const { + return m_intValue; + } + + virtual void setValue( ULONG64 value ) { + m_intValue = value; + } + + std::string + str() const { + std::stringstream ss; + ss << getValue(); + return ss.str(); + } + + std::string + hex() const { + std::stringstream ss; + ss << std::hex << getValue(); + return ss.str(); + } + + template + intBase& operator+=(T const& rhs) + { setValue( getValue() + rhs ); return *this; } + + template + intBase& operator-=(T const& rhs) + { setValue( getValue() - rhs ); return *this; } + + template + intBase& operator*=(T const& rhs) + { setValue( getValue() * rhs ); return *this; } + + template + intBase& operator/=(T const& rhs) + { setValue( getValue() / rhs ); return *this; } + + template + intBase& operator%=(T const& rhs) + { setValue( getValue() % rhs ); return *this; } + + template + intBase& operator&=(T const& rhs) + { setValue( getValue() & rhs ); return *this; } + + template + intBase& operator|=(T const& rhs) + { setValue( getValue() | rhs ); return *this; } + + template + intBase& operator^=(T const& rhs) + { setValue( getValue() ^ rhs ); return *this; } + + template + intBase& operator<<=(T const& rhs) + { setValue( getValue() << rhs ); return *this; } + + template + intBase& operator>>=(T const& rhs) + { setValue( getValue() >> rhs ); return *this; } + +private: + + ULONG64 m_intValue; + +}; + +}; \ No newline at end of file diff --git a/pykd/pykd_2008.vcproj b/pykd/pykd_2008.vcproj index 9ce30fb..57caf37 100644 --- a/pykd/pykd_2008.vcproj +++ b/pykd/pykd_2008.vcproj @@ -441,6 +441,10 @@ /> + + diff --git a/pykd/typedvar.cpp b/pykd/typedvar.cpp new file mode 100644 index 0000000..dd20761 --- /dev/null +++ b/pykd/typedvar.cpp @@ -0,0 +1,25 @@ +#include "stdafx.h" + +#include "typedvar.h" + + +namespace pykd { + +/////////////////////////////////////////////////////////////////////////////////// + +TypedVarPtr +TypedVar::getField( const std::string &fieldName ) +{ + TypeInfo fieldType = m_typeInfo.getField( fieldName ); + + if ( fieldType.isBasicType() ) + { + return TypedVarPtr( new BasicTypedVar( fieldType, 0 ) ); + } + + throw DbgException( "can not get field" ); +} + +/////////////////////////////////////////////////////////////////////////////////// + +} // end pykd namespace \ No newline at end of file diff --git a/pykd/typedvar.h b/pykd/typedvar.h index 92016f3..8e4e298 100644 --- a/pykd/typedvar.h +++ b/pykd/typedvar.h @@ -1,12 +1,18 @@ #pragma once #include "typeinfo.h" +#include "intbase.h" namespace pykd { +///////////////////////////////////////////////////////////////////////////////// + +class TypedVar; +typedef boost::shared_ptr TypedVarPtr; + /////////////////////////////////////////////////////////////////////////////////// -class TypedVar { +class TypedVar : public intBase { public: @@ -23,6 +29,27 @@ public: return m_typeInfo.getSize(); } + TypeInfo + getType() const { + return m_typeInfo; + } + + virtual TypedVarPtr getField( const std::string &fieldName ); + + virtual std::string print() { + return "TypeVar"; + } + +protected: + + virtual ULONG64 getValue() const { + return m_offset; + } + + virtual void setValue( ULONG64 value) { + m_offset = value; + } + private: TypeInfo m_typeInfo; @@ -32,4 +59,23 @@ private: /////////////////////////////////////////////////////////////////////////////////// +class BasicTypedVar : public TypedVar { + +public: + + BasicTypedVar ( const TypeInfo& typeInfo, ULONG64 offset ) : TypedVar(typeInfo, offset){} + + TypedVarPtr + virtual getField( const std::string &fieldName ) { + throw DbgException("no fields"); + } + + virtual std::string print() { + return "BasicTypedVar"; + } + +}; + +/////////////////////////////////////////////////////////////////////////////////// + }; // namespace pykd diff --git a/pykd/typeinfo.cpp b/pykd/typeinfo.cpp index 87256b0..9724b9f 100644 --- a/pykd/typeinfo.cpp +++ b/pykd/typeinfo.cpp @@ -58,4 +58,36 @@ TypeInfo::getName() /////////////////////////////////////////////////////////////////////////////////// +bool +TypeInfo::isBasicType() +{ + return m_dia->getSymTag() == SymTagBaseType; +} + +/////////////////////////////////////////////////////////////////////////////////// + +bool +TypeInfo::isArrayType() +{ + return m_dia->getSymTag() == SymTagArrayType; +} + +/////////////////////////////////////////////////////////////////////////////////// + +bool +TypeInfo::isPointer() +{ + return m_dia->getSymTag() == SymTagPointerType; +} + +/////////////////////////////////////////////////////////////////////////////////// + +bool +TypeInfo::isUserDefined() +{ + return m_dia->getSymTag() == SymTagUDT; +} + +/////////////////////////////////////////////////////////////////////////////////// + }; // end namespace pykd \ No newline at end of file diff --git a/pykd/typeinfo.h b/pykd/typeinfo.h index c1dd14c..5814ff4 100644 --- a/pykd/typeinfo.h +++ b/pykd/typeinfo.h @@ -38,7 +38,19 @@ public: ULONG getSize() { return (ULONG)m_dia->getSize(); - } + } + + bool + isBasicType(); + + bool + isArrayType(); + + bool + isPointer(); + + bool + isUserDefined(); private: