mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 04:13:22 +08:00
[+] offset into TypeInfo (for fields)
[+] method TypeInfo::build() for recursive typeClass building [+] virtual method printSelf() for address value for typedVarClass [~] remove trailing blanks, tabs replaced by spaces git-svn-id: https://pykd.svn.codeplex.com/svn@61693 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
5879200d07
commit
dfbbc434d3
@ -153,6 +153,7 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
boost::python::def( "setProcessorMode", &setProcessorMode );
|
boost::python::def( "setProcessorMode", &setProcessorMode );
|
||||||
boost::python::class_<typeClass, boost::shared_ptr<typeClass> >( "typeClass" )
|
boost::python::class_<typeClass, boost::shared_ptr<typeClass> >( "typeClass" )
|
||||||
.def("sizeof", &typeClass::size )
|
.def("sizeof", &typeClass::size )
|
||||||
|
.def("offset", &typeClass::getOffset )
|
||||||
.def("__str__", &typeClass::print);
|
.def("__str__", &typeClass::print);
|
||||||
boost::python::class_<typedVarClass, boost::python::bases<typeClass>, boost::shared_ptr<typedVarClass> >( "typedVarClass" )
|
boost::python::class_<typedVarClass, boost::python::bases<typeClass>, boost::shared_ptr<typedVarClass> >( "typedVarClass" )
|
||||||
.def("getAddress", &typedVarClass::getAddress );
|
.def("getAddress", &typedVarClass::getAddress );
|
||||||
|
@ -37,7 +37,6 @@ sizeofType( const std::string &moduleName, const std::string &typeName )
|
|||||||
|
|
||||||
typeSize = (ULONG)TypeInfo::get( moduleName, typeName ).size();
|
typeSize = (ULONG)TypeInfo::get( moduleName, typeName ).size();
|
||||||
}
|
}
|
||||||
|
|
||||||
catch( std::exception &e )
|
catch( std::exception &e )
|
||||||
{
|
{
|
||||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
||||||
@ -76,7 +75,6 @@ containingRecord( ULONG64 address, const std::string &moduleName, const std::str
|
|||||||
|
|
||||||
return TypeInfo::get( moduleName, typeName ).load( address - fieldOffset );
|
return TypeInfo::get( moduleName, typeName ).load( address - fieldOffset );
|
||||||
}
|
}
|
||||||
|
|
||||||
catch( std::exception &e )
|
catch( std::exception &e )
|
||||||
{
|
{
|
||||||
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
||||||
@ -96,13 +94,7 @@ getTypeClass( const std::string &moduleName, const std::string &typeName )
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
boost::shared_ptr<typeClass> ptr(
|
return TypeInfo::get( moduleName, typeName ).build();
|
||||||
new typeClass( TypeInfo::get( moduleName, typeName ))
|
|
||||||
);
|
|
||||||
boost::python::object var( ptr );
|
|
||||||
ptr->setPyObj(var);
|
|
||||||
|
|
||||||
return var;
|
|
||||||
}
|
}
|
||||||
catch( std::exception &e )
|
catch( std::exception &e )
|
||||||
{
|
{
|
||||||
@ -269,7 +261,7 @@ TypeInfo::TypeInfo( const std::string &moduleName, const std::string &typeName
|
|||||||
m_size = 0;
|
m_size = 0;
|
||||||
m_baseType = false;
|
m_baseType = false;
|
||||||
m_pointer = false;
|
m_pointer = false;
|
||||||
|
m_offset = 0;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if ( typeName.find("*") < typeName.size() )
|
if ( typeName.find("*") < typeName.size() )
|
||||||
@ -330,7 +322,6 @@ TypeInfo::TypeInfo( const std::string &moduleName, const std::string &typeName
|
|||||||
|
|
||||||
m_fields.push_back( TypeField( fieldName, get(moduleName, fieldTypeName), fieldSize, fieldOffset ) );
|
m_fields.push_back( TypeField( fieldName, get(moduleName, fieldTypeName), fieldSize, fieldOffset ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch( std::exception &e )
|
catch( std::exception &e )
|
||||||
{
|
{
|
||||||
@ -345,7 +336,43 @@ TypeInfo::TypeInfo( const std::string &moduleName, const std::string &typeName
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
boost::python::object
|
boost::python::object
|
||||||
TypeInfo::load( ULONG64 addr ) const
|
TypeInfo::build( ULONG offset /* = 0 */ ) const
|
||||||
|
{
|
||||||
|
boost::shared_ptr<typeClass> ptr( new typeClass( *this ) );
|
||||||
|
boost::python::object var( ptr );
|
||||||
|
ptr->setPyObj( var );
|
||||||
|
ptr->getTypeInfo().setOffset(offset);
|
||||||
|
|
||||||
|
TypeFieldList::const_iterator field = m_fields.begin();
|
||||||
|
for ( field = m_fields.begin(); field != m_fields.end(); ++field )
|
||||||
|
{
|
||||||
|
|
||||||
|
if ( field->size == field->type.size() )
|
||||||
|
{
|
||||||
|
var.attr( field->name.c_str() ) =
|
||||||
|
field->type.build( offset + field->offset );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
boost::python::dict arr;
|
||||||
|
|
||||||
|
for ( unsigned int i = 0; i < field->size / field->type.size(); ++i )
|
||||||
|
{
|
||||||
|
const ULONG locOffset = field->offset + i * (ULONG)field->type.size();
|
||||||
|
arr[i] = field->type.build( offset + locOffset );
|
||||||
|
}
|
||||||
|
|
||||||
|
var.attr( field->name.c_str() ) = arr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return var;
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
boost::python::object
|
||||||
|
TypeInfo::load( ULONG64 addr, ULONG offset /* = 0 */ ) const
|
||||||
{
|
{
|
||||||
if ( !isOffsetValid( addr) )
|
if ( !isOffsetValid( addr) )
|
||||||
return boost::python::object();
|
return boost::python::object();
|
||||||
@ -359,6 +386,7 @@ TypeInfo::load( ULONG64 addr ) const
|
|||||||
boost::shared_ptr<typedVarClass> ptr( new typedVarClass( *this, addr ) );
|
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 );
|
||||||
|
ptr->getTypeInfo().setOffset(offset);
|
||||||
|
|
||||||
TypeFieldList::const_iterator field = m_fields.begin();
|
TypeFieldList::const_iterator field = m_fields.begin();
|
||||||
for ( field = m_fields.begin(); field != m_fields.end(); ++field )
|
for ( field = m_fields.begin(); field != m_fields.end(); ++field )
|
||||||
@ -366,15 +394,18 @@ TypeInfo::load( ULONG64 addr ) const
|
|||||||
|
|
||||||
if ( field->size == field->type.size() )
|
if ( field->size == field->type.size() )
|
||||||
{
|
{
|
||||||
var.attr( field->name.c_str() ) = field->type.load( addr + field->offset );
|
var.attr( field->name.c_str() ) =
|
||||||
|
field->type.load( addr + field->offset, offset + field->offset );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
boost::python::dict arr;
|
boost::python::dict arr;
|
||||||
|
|
||||||
for ( unsigned int i = 0; i < field->size / field->type.size(); ++i )
|
for ( unsigned int i = 0; i < field->size / field->type.size(); ++i )
|
||||||
arr[i] = field->type.load( addr + field->offset + i * field->type.size() );
|
{
|
||||||
|
const ULONG locOffset = field->offset + i * (ULONG)field->type.size();
|
||||||
|
arr[i] = field->type.load( addr + locOffset, offset + locOffset );
|
||||||
|
}
|
||||||
|
|
||||||
var.attr( field->name.c_str() ) = arr;
|
var.attr( field->name.c_str() ) = arr;
|
||||||
}
|
}
|
||||||
@ -466,14 +497,17 @@ std::string typeClass::print() const
|
|||||||
{
|
{
|
||||||
stringstream sstr;
|
stringstream sstr;
|
||||||
|
|
||||||
sstr << getTypeInfo().name() << std::endl;
|
sstr << getTypeInfo().name() << " ";
|
||||||
|
printSelf(sstr);
|
||||||
|
sstr << std::endl;
|
||||||
|
|
||||||
TypeInfo::TypeFieldList::const_iterator itField =
|
TypeInfo::TypeFieldList::const_iterator itField =
|
||||||
getTypeInfo().getFields().begin();
|
getTypeInfo().getFields().begin();
|
||||||
while (itField != getTypeInfo().getFields().end())
|
while (itField != getTypeInfo().getFields().end())
|
||||||
{
|
{
|
||||||
sstr << "\t" << hex << "+" << itField->offset;
|
sstr << "\t" << hex << "+" << itField->offset << " ";
|
||||||
sstr << " " << itField->name << " ";
|
sstr << itField->type.name() << " ";
|
||||||
|
sstr << itField->name << " ";
|
||||||
|
|
||||||
printField(*itField, sstr);
|
printField(*itField, sstr);
|
||||||
|
|
||||||
|
@ -85,13 +85,18 @@ public:
|
|||||||
TypeInfo() :
|
TypeInfo() :
|
||||||
m_size( 0 ),
|
m_size( 0 ),
|
||||||
m_baseType( false ),
|
m_baseType( false ),
|
||||||
m_pointer( false )
|
m_pointer( false ),
|
||||||
|
m_offset(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
TypeInfo( const std::string &moduleName, const std::string &typeName );
|
TypeInfo( const std::string &moduleName, const std::string &typeName );
|
||||||
|
|
||||||
boost::python::object
|
boost::python::object
|
||||||
load( ULONG64 addr ) const;
|
load( ULONG64 addr, ULONG offset = 0 ) const;
|
||||||
|
|
||||||
|
boost::python::object
|
||||||
|
build( ULONG offset = 0 ) const;
|
||||||
|
|
||||||
|
|
||||||
ULONG64
|
ULONG64
|
||||||
size() const
|
size() const
|
||||||
@ -123,6 +128,10 @@ public:
|
|||||||
return m_pointer;
|
return m_pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// field offset getter/setter
|
||||||
|
void setOffset(ULONG offset) { m_offset = offset; }
|
||||||
|
ULONG getOffset() const { return m_offset; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static TypeInfoMap g_typeInfoCache;
|
static TypeInfoMap g_typeInfoCache;
|
||||||
@ -145,6 +154,7 @@ private:
|
|||||||
TypeFieldList m_fields;
|
TypeFieldList m_fields;
|
||||||
std::string m_typeName;
|
std::string m_typeName;
|
||||||
ULONG m_size;
|
ULONG m_size;
|
||||||
|
ULONG m_offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -163,9 +173,10 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sizeof(TYPE)
|
||||||
ULONG size() const
|
ULONG size() const
|
||||||
{
|
{
|
||||||
return m_typeInfo.size();
|
return (ULONG)m_typeInfo.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPyObj( const boost::python::object &obj )
|
void setPyObj( const boost::python::object &obj )
|
||||||
@ -173,6 +184,7 @@ public:
|
|||||||
m_pyobj = obj;
|
m_pyobj = obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TypeInfo getter
|
||||||
TypeInfo &getTypeInfo()
|
TypeInfo &getTypeInfo()
|
||||||
{
|
{
|
||||||
return m_typeInfo;
|
return m_typeInfo;
|
||||||
@ -182,6 +194,7 @@ public:
|
|||||||
return m_typeInfo;
|
return m_typeInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// boost::python::object getter
|
||||||
boost::python::object &getPyObj()
|
boost::python::object &getPyObj()
|
||||||
{
|
{
|
||||||
return m_pyobj;
|
return m_pyobj;
|
||||||
@ -200,6 +213,14 @@ public:
|
|||||||
{
|
{
|
||||||
// no data - nothing print
|
// no data - nothing print
|
||||||
}
|
}
|
||||||
|
virtual void printSelf(
|
||||||
|
std::stringstream &sstr
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
// no data - nothing print
|
||||||
|
}
|
||||||
|
|
||||||
|
ULONG getOffset() const { return m_typeInfo.getOffset(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TypeInfo m_typeInfo;
|
TypeInfo m_typeInfo;
|
||||||
@ -228,6 +249,12 @@ public:
|
|||||||
virtual void
|
virtual void
|
||||||
printField( const TypeInfo::TypeField &field, std::stringstream &sstr ) const override;
|
printField( const TypeInfo::TypeField &field, std::stringstream &sstr ) const override;
|
||||||
|
|
||||||
|
virtual void
|
||||||
|
printSelf( std::stringstream &sstr ) const override
|
||||||
|
{
|
||||||
|
sstr << std::hex << "0x" << getAddress() << std::dec << " ";
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
ULONG64 m_addr;
|
ULONG64 m_addr;
|
||||||
|
Loading…
Reference in New Issue
Block a user