mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-29 11:53:23 +08:00
[0.1.x] added : typedVar class
git-svn-id: https://pykd.svn.codeplex.com/svn@70920 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
95c135ed38
commit
10e12fc6b6
@ -90,7 +90,7 @@ protected:
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class EventHandlerWrap : public boost::python::wrapper<EventHandler>, public EventHandler
|
||||
class EventHandlerWrap : public python::wrapper<EventHandler>, public EventHandler
|
||||
{
|
||||
|
||||
public:
|
||||
|
@ -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", "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_<pykd::DebugClient, pykd::DebugClientPtr>("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_<pykd::TypedVar>("typedVar",
|
||||
"Class of non-primitive type object, child class of typeClass. Data from target is copied into object instance",
|
||||
python::class_<TypedVar, TypedVarPtr, python::bases<intBase> >("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<const TypeInfo&, ULONG64>() )
|
||||
.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_<pykd::Module>("module", "Class representing executable module", python::no_init )
|
||||
.def("begin", &pykd::Module::getBase,
|
||||
"Return start address of the module" )
|
||||
|
@ -89,7 +89,7 @@ std::string DebugClient::loadChars( ULONG64 address, ULONG number, bool phyAddr
|
||||
{
|
||||
std::vector<char> buffer(number);
|
||||
|
||||
ULONG bufferSize = sizeof(std::vector<char>::value_type)*buffer.size();
|
||||
ULONG bufferSize = (ULONG)( sizeof(std::vector<char>::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<wchar_t> buffer(number);
|
||||
|
||||
ULONG bufferSize = sizeof(std::vector<wchar_t>::value_type)*buffer.size();
|
||||
ULONG bufferSize = (ULONG)( sizeof(std::vector<wchar_t>::value_type)*buffer.size() );
|
||||
|
||||
if (number)
|
||||
readMemory( address, &buffer[0], bufferSize, phyAddr );
|
||||
|
169
pykd/intbase.h
169
pykd/intbase.h
@ -1,88 +1,87 @@
|
||||
#pragma once
|
||||
|
||||
namespace pykd {
|
||||
|
||||
//class intBase : boost::integer_arithmetic<intBase>
|
||||
//{
|
||||
//
|
||||
//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 <class T>
|
||||
// intBase& operator+=(T const& rhs)
|
||||
// { m_value += rhs; return *this; }
|
||||
//
|
||||
// template <class T>
|
||||
// intBase& operator-=(T const& rhs)
|
||||
// { m_value -= rhs; return *this; }
|
||||
//
|
||||
// template <class T>
|
||||
// intBase& operator*=(T const& rhs)
|
||||
// { m_value *= rhs; return *this; }
|
||||
//
|
||||
// template <class T>
|
||||
// intBase& operator/=(T const& rhs)
|
||||
// { m_value /= rhs; return *this; }
|
||||
//
|
||||
// template <class T>
|
||||
// intBase& operator%=(T const& rhs)
|
||||
// { m_value %= rhs; return *this; }
|
||||
//
|
||||
// template <class T>
|
||||
// intBase& operator&=(T const& rhs)
|
||||
// { m_value &= rhs; return *this; }
|
||||
//
|
||||
// template <class T>
|
||||
// intBase& operator|=(T const& rhs)
|
||||
// { m_value |= rhs; return *this; }
|
||||
//
|
||||
// template <class T>
|
||||
// intBase& operator^=(T const& rhs)
|
||||
// { m_value ^= rhs; return *this; }
|
||||
//
|
||||
// template <class T>
|
||||
// intBase& operator<<=(T const& rhs)
|
||||
// { m_value <<= rhs; return *this; }
|
||||
//
|
||||
// template <class T>
|
||||
// intBase& operator>>=(T const& rhs)
|
||||
// { m_value >>= rhs; return *this; }
|
||||
//
|
||||
//protected:
|
||||
//
|
||||
// mutable ULONG64 m_value;
|
||||
//
|
||||
//};
|
||||
class intBase : boost::integer_arithmetic<intBase>
|
||||
{
|
||||
|
||||
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 <class T>
|
||||
intBase& operator+=(T const& rhs)
|
||||
{ setValue( getValue() + rhs ); return *this; }
|
||||
|
||||
template <class T>
|
||||
intBase& operator-=(T const& rhs)
|
||||
{ setValue( getValue() - rhs ); return *this; }
|
||||
|
||||
template <class T>
|
||||
intBase& operator*=(T const& rhs)
|
||||
{ setValue( getValue() * rhs ); return *this; }
|
||||
|
||||
template <class T>
|
||||
intBase& operator/=(T const& rhs)
|
||||
{ setValue( getValue() / rhs ); return *this; }
|
||||
|
||||
template <class T>
|
||||
intBase& operator%=(T const& rhs)
|
||||
{ setValue( getValue() % rhs ); return *this; }
|
||||
|
||||
template <class T>
|
||||
intBase& operator&=(T const& rhs)
|
||||
{ setValue( getValue() & rhs ); return *this; }
|
||||
|
||||
template <class T>
|
||||
intBase& operator|=(T const& rhs)
|
||||
{ setValue( getValue() | rhs ); return *this; }
|
||||
|
||||
template <class T>
|
||||
intBase& operator^=(T const& rhs)
|
||||
{ setValue( getValue() ^ rhs ); return *this; }
|
||||
|
||||
template <class T>
|
||||
intBase& operator<<=(T const& rhs)
|
||||
{ setValue( getValue() << rhs ); return *this; }
|
||||
|
||||
template <class T>
|
||||
intBase& operator>>=(T const& rhs)
|
||||
{ setValue( getValue() >> rhs ); return *this; }
|
||||
|
||||
private:
|
||||
|
||||
ULONG64 m_intValue;
|
||||
|
||||
};
|
||||
|
||||
};
|
@ -441,6 +441,10 @@
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\typedvar.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\typeinfo.cpp"
|
||||
>
|
||||
|
25
pykd/typedvar.cpp
Normal file
25
pykd/typedvar.cpp
Normal file
@ -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
|
@ -1,12 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "typeinfo.h"
|
||||
#include "intbase.h"
|
||||
|
||||
namespace pykd {
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class TypedVar;
|
||||
typedef boost::shared_ptr<TypedVar> 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
|
||||
|
@ -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
|
@ -38,7 +38,19 @@ public:
|
||||
ULONG
|
||||
getSize() {
|
||||
return (ULONG)m_dia->getSize();
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
isBasicType();
|
||||
|
||||
bool
|
||||
isArrayType();
|
||||
|
||||
bool
|
||||
isPointer();
|
||||
|
||||
bool
|
||||
isUserDefined();
|
||||
|
||||
private:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user