mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 12:53:23 +08:00
[+] 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:
parent
b091e32be0
commit
5879200d07
@ -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 )
|
||||||
|
167
pykd/dbgtype.cpp
167
pykd/dbgtype.cpp
@ -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,76 +462,24 @@ 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();
|
TypeInfo::TypeFieldList::const_iterator itField =
|
||||||
field++ )
|
getTypeInfo().getFields().begin();
|
||||||
|
while (itField != getTypeInfo().getFields().end())
|
||||||
{
|
{
|
||||||
sstr << "\t" << hex << "+" << field->offset << " " << field->name << " ";
|
sstr << "\t" << hex << "+" << itField->offset;
|
||||||
|
sstr << " " << itField->name << " ";
|
||||||
|
|
||||||
if ( field->type.isComplex() && !field->type.isPtr())
|
printField(*itField, sstr);
|
||||||
sstr << field->type.name();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
boost::python::object attr = m_pyobj.attr( field->name.c_str() );
|
|
||||||
|
|
||||||
if ( field->size == field->type.size() )
|
|
||||||
{
|
|
||||||
if ( attr.ptr() == Py_None )
|
|
||||||
{
|
|
||||||
sstr << "memory error";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
unsigned __int64 val = boost::python::extract<unsigned __int64>( attr );
|
|
||||||
|
|
||||||
sstr << hex << "0x" << val;
|
|
||||||
|
|
||||||
if ( field->type.name() == "char*" )
|
|
||||||
{
|
|
||||||
char buf[0x100];
|
|
||||||
if ( loadCStrToBuffer( val, buf, sizeof(buf) ) )
|
|
||||||
sstr << " (" << buf << " )";
|
|
||||||
else
|
|
||||||
sstr << " ( read string error )";
|
|
||||||
}
|
|
||||||
else if ( field->type.name() == "unsigned short*" )
|
|
||||||
{
|
|
||||||
wchar_t wbuf[0x100];
|
|
||||||
if ( loadWStrToBuffer( val, wbuf, sizeof(wbuf) ) )
|
|
||||||
{
|
|
||||||
char mbBuf[0x100] = { 0 };
|
|
||||||
|
|
||||||
WideCharToMultiByte( CP_ACP, 0, wbuf, wcslen(wbuf)+1, mbBuf, sizeof(mbBuf), NULL, NULL );
|
|
||||||
|
|
||||||
sstr << " (" << mbBuf << " )";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
sstr << " ( read string error )";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sstr << dec << " ( " << val << " )";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for ( size_t i = 0; i < field->size/field->type.size(); ++i )
|
|
||||||
{
|
|
||||||
unsigned __int64 val = boost::python::extract<unsigned __int64>( attr[i] );
|
|
||||||
|
|
||||||
sstr << "\n\t\t\t[" << i << "] " << hex << "0x" << val << dec << " ( " << val << " )";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sstr << std::endl;
|
sstr << std::endl;
|
||||||
|
|
||||||
|
++itField;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sstr.str();
|
return sstr.str();
|
||||||
@ -513,4 +487,67 @@ typedVarClass::print() const
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void
|
||||||
|
typedVarClass::printField(const TypeInfo::TypeField &field, stringstream &sstr) const
|
||||||
|
{
|
||||||
|
if ( field.type.isComplex() && !field.type.isPtr())
|
||||||
|
sstr << field.type.name();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
boost::python::object attr = getPyObj().attr( field.name.c_str() );
|
||||||
|
|
||||||
|
if ( field.size == field.type.size() )
|
||||||
|
{
|
||||||
|
if ( attr.ptr() == Py_None )
|
||||||
|
{
|
||||||
|
sstr << "memory error";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unsigned __int64 val = boost::python::extract<unsigned __int64>( attr );
|
||||||
|
|
||||||
|
sstr << hex << "0x" << val;
|
||||||
|
|
||||||
|
if ( field.type.name() == "char*" )
|
||||||
|
{
|
||||||
|
char buf[0x100];
|
||||||
|
if ( loadCStrToBuffer( val, buf, sizeof(buf) ) )
|
||||||
|
sstr << " (" << buf << " )";
|
||||||
|
else
|
||||||
|
sstr << " ( read string error )";
|
||||||
|
}
|
||||||
|
else if ( field.type.name() == "unsigned short*" )
|
||||||
|
{
|
||||||
|
wchar_t wbuf[0x100];
|
||||||
|
if ( loadWStrToBuffer( val, wbuf, sizeof(wbuf) ) )
|
||||||
|
{
|
||||||
|
char mbBuf[0x100] = { 0 };
|
||||||
|
|
||||||
|
WideCharToMultiByte( CP_ACP, 0, wbuf, wcslen(wbuf)+1, mbBuf, sizeof(mbBuf), NULL, NULL );
|
||||||
|
|
||||||
|
sstr << " (" << mbBuf << " )";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
sstr << " ( read string error )";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sstr << dec << " ( " << val << " )";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for ( size_t i = 0; i < field.size/field.type.size(); ++i )
|
||||||
|
{
|
||||||
|
unsigned __int64 val = boost::python::extract<unsigned __int64>( attr[i] );
|
||||||
|
|
||||||
|
sstr << "\n\t\t\t[" << i << "] " << hex << "0x" << val << dec << " ( " << val << " )";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
@ -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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
Loading…
Reference in New Issue
Block a user