[+] part of functional (work with types) moved from typedVarClass into base class: typeClass

[-] remove field m_size, which is duplicated in TypeInfo m_typeInfo
 [+] added function getTypeClass() - create instance of typeClass by module an type name

git-svn-id: https://pykd.svn.codeplex.com/svn@61649 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\EreTIk_cp 2011-02-18 20:56:26 +00:00
parent b091e32be0
commit 5879200d07
3 changed files with 185 additions and 105 deletions

View File

@ -107,6 +107,7 @@ BOOST_PYTHON_MODULE( pykd )
boost::python::def( "typedVarList", &loadTypedVarList ); boost::python::def( "typedVarList", &loadTypedVarList );
boost::python::def( "typedVarArray", &loadTypedVarArray ); boost::python::def( "typedVarArray", &loadTypedVarArray );
boost::python::def( "containingRecord", &containingRecord ); boost::python::def( "containingRecord", &containingRecord );
boost::python::def( "getTypeClass", &getTypeClass );
boost::python::def( "sizeof", &sizeofType ); boost::python::def( "sizeof", &sizeofType );
boost::python::def( "loadModule", &loadModule ); boost::python::def( "loadModule", &loadModule );
boost::python::def( "findSymbol", &findSymbolForAddress ); boost::python::def( "findSymbol", &findSymbolForAddress );
@ -150,10 +151,11 @@ BOOST_PYTHON_MODULE( pykd )
boost::python::def( "setCurrentProcess", &setCurrentProcess ); boost::python::def( "setCurrentProcess", &setCurrentProcess );
boost::python::def( "getProcessorMode", &getProcessorMode ); boost::python::def( "getProcessorMode", &getProcessorMode );
boost::python::def( "setProcessorMode", &setProcessorMode ); boost::python::def( "setProcessorMode", &setProcessorMode );
boost::python::class_<typedVarClass, boost::shared_ptr<typedVarClass> >( "typedVarClass" ) boost::python::class_<typeClass, boost::shared_ptr<typeClass> >( "typeClass" )
.def("getAddress", &typedVarClass::getAddress ) .def("sizeof", &typeClass::size )
.def("sizeof", &typedVarClass::size ) .def("__str__", &typeClass::print);
.def("__str__", &typedVarClass::print); boost::python::class_<typedVarClass, boost::python::bases<typeClass>, boost::shared_ptr<typedVarClass> >( "typedVarClass" )
.def("getAddress", &typedVarClass::getAddress );
boost::python::class_<dbgModuleClass>( "dbgModuleClass" ) boost::python::class_<dbgModuleClass>( "dbgModuleClass" )
.def("begin", &dbgModuleClass::getBegin ) .def("begin", &dbgModuleClass::getBegin )
.def("end", &dbgModuleClass::getEnd ) .def("end", &dbgModuleClass::getEnd )

View File

@ -91,6 +91,32 @@ containingRecord( ULONG64 address, const std::string &moduleName, const std::str
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
boost::python::object
getTypeClass( const std::string &moduleName, const std::string &typeName )
{
try
{
boost::shared_ptr<typeClass> ptr(
new typeClass( TypeInfo::get( moduleName, typeName ))
);
boost::python::object var( ptr );
ptr->setPyObj(var);
return var;
}
catch( std::exception &e )
{
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
}
catch(...)
{
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
}
return boost::python::object();
}
/////////////////////////////////////////////////////////////////////////////////
boost::python::object boost::python::object
loadTypedVarList( ULONG64 address, const std::string &moduleName, const std::string &typeName, const std::string &listEntryName ) loadTypedVarList( ULONG64 address, const std::string &moduleName, const std::string &typeName, const std::string &listEntryName )
{ {
@ -330,7 +356,7 @@ TypeInfo::load( ULONG64 addr ) const
if ( m_baseType ) if ( m_baseType )
return loadBaseType( addr ); return loadBaseType( addr );
boost::shared_ptr<typedVarClass> ptr( new typedVarClass( *this, addr, m_size ) ); boost::shared_ptr<typedVarClass> ptr( new typedVarClass( *this, addr ) );
boost::python::object var( ptr ); boost::python::object var( ptr );
ptr->setPyObj( var ); ptr->setPyObj( var );
@ -436,25 +462,41 @@ valueLoader( ULONG64 address, ULONG size )
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
std::string std::string typeClass::print() const
typedVarClass::print() const
{ {
stringstream sstr; stringstream sstr;
for ( sstr << getTypeInfo().name() << std::endl;
TypeInfo::TypeFieldList::const_iterator field = m_typeInfo.getFields().begin();
field != m_typeInfo.getFields().end();
field++ )
{
sstr << "\t" << hex << "+" << field->offset << " " << field->name << " ";
if ( field->type.isComplex() && !field->type.isPtr()) TypeInfo::TypeFieldList::const_iterator itField =
sstr << field->type.name(); getTypeInfo().getFields().begin();
while (itField != getTypeInfo().getFields().end())
{
sstr << "\t" << hex << "+" << itField->offset;
sstr << " " << itField->name << " ";
printField(*itField, sstr);
sstr << std::endl;
++itField;
}
return sstr.str();
}
/////////////////////////////////////////////////////////////////////////////////
void
typedVarClass::printField(const TypeInfo::TypeField &field, stringstream &sstr) const
{
if ( field.type.isComplex() && !field.type.isPtr())
sstr << field.type.name();
else else
{ {
boost::python::object attr = m_pyobj.attr( field->name.c_str() ); boost::python::object attr = getPyObj().attr( field.name.c_str() );
if ( field->size == field->type.size() ) if ( field.size == field.type.size() )
{ {
if ( attr.ptr() == Py_None ) if ( attr.ptr() == Py_None )
{ {
@ -466,7 +508,7 @@ typedVarClass::print() const
sstr << hex << "0x" << val; sstr << hex << "0x" << val;
if ( field->type.name() == "char*" ) if ( field.type.name() == "char*" )
{ {
char buf[0x100]; char buf[0x100];
if ( loadCStrToBuffer( val, buf, sizeof(buf) ) ) if ( loadCStrToBuffer( val, buf, sizeof(buf) ) )
@ -474,7 +516,7 @@ typedVarClass::print() const
else else
sstr << " ( read string error )"; sstr << " ( read string error )";
} }
else if ( field->type.name() == "unsigned short*" ) else if ( field.type.name() == "unsigned short*" )
{ {
wchar_t wbuf[0x100]; wchar_t wbuf[0x100];
if ( loadWStrToBuffer( val, wbuf, sizeof(wbuf) ) ) if ( loadWStrToBuffer( val, wbuf, sizeof(wbuf) ) )
@ -496,7 +538,7 @@ typedVarClass::print() const
} }
else else
{ {
for ( size_t i = 0; i < field->size/field->type.size(); ++i ) for ( size_t i = 0; i < field.size/field.type.size(); ++i )
{ {
unsigned __int64 val = boost::python::extract<unsigned __int64>( attr[i] ); unsigned __int64 val = boost::python::extract<unsigned __int64>( attr[i] );
@ -504,11 +546,6 @@ typedVarClass::print() const
} }
} }
} }
sstr << std::endl;
}
return sstr.str();
} }
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////

View File

@ -23,6 +23,9 @@ loadTypedVarArray( ULONG64 address, const std::string &moduleName, const std::st
boost::python::object boost::python::object
containingRecord( ULONG64 address, const std::string &moduleName, const std::string &typeName, const std::string &fieldName ); containingRecord( ULONG64 address, const std::string &moduleName, const std::string &typeName, const std::string &fieldName );
boost::python::object
getTypeClass( const std::string &moduleName, const std::string &typeName );
ULONG ULONG
sizeofType( const std::string &moduleName, const std::string &typeName ); sizeofType( const std::string &moduleName, const std::string &typeName );
@ -138,29 +141,83 @@ private:
private: private:
bool m_baseType; bool m_baseType;
bool m_pointer; bool m_pointer;
TypeFieldList m_fields; TypeFieldList m_fields;
std::string m_typeName; std::string m_typeName;
ULONG m_size; ULONG m_size;
}; };
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
class typedVarClass { class typeClass
{
public:
typeClass()
{
}
typeClass(
const TypeInfo &typeInfo
) : m_typeInfo(typeInfo)
{
}
ULONG size() const
{
return m_typeInfo.size();
}
void setPyObj( const boost::python::object &obj )
{
m_pyobj = obj;
}
TypeInfo &getTypeInfo()
{
return m_typeInfo;
}
const TypeInfo &getTypeInfo() const
{
return m_typeInfo;
}
boost::python::object &getPyObj()
{
return m_pyobj;
}
const boost::python::object &getPyObj() const
{
return m_pyobj;
}
std::string print() const;
virtual void printField(
const TypeInfo::TypeField &field,
std::stringstream &sstr
) const
{
// no data - nothing print
}
private:
TypeInfo m_typeInfo;
boost::python::object m_pyobj;
};
/////////////////////////////////////////////////////////////////////////////////
class typedVarClass : public typeClass {
public: public:
typedVarClass() typedVarClass()
{} {}
typedVarClass( const TypeInfo &typeInfo, ULONG64 addr, ULONG size ) : typedVarClass( const TypeInfo &typeInfo, ULONG64 addr) :
m_typeInfo( typeInfo ), typeClass( typeInfo ),
m_addr( addr ), m_addr( addr )
m_size( size )
{} {}
ULONG64 ULONG64
@ -168,28 +225,12 @@ public:
return m_addr; return m_addr;
} }
ULONG virtual void
size() const { printField(const TypeInfo::TypeField &field, std::stringstream &sstr) const override;
return m_size;
}
std::string
print() const;
void
setPyObj( const boost::python::object &obj ) {
m_pyobj = obj;
}
private: private:
ULONG64 m_addr; ULONG64 m_addr;
ULONG m_size;
TypeInfo m_typeInfo;
boost::python::object m_pyobj;
}; };
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////