mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 04:13:22 +08:00
[0.3.x] added : class "cpu" for working with CPU registers come back
git-svn-id: https://pykd.svn.codeplex.com/svn@89119 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
7260e8f0c9
commit
d5e95624d7
@ -177,176 +177,45 @@ python::dict StackFrameAdapter::getLocalsDict(kdlib::StackFramePtr& frame)
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
python::object CPUContextAdapter::getRegisterByName( kdlib::CPUContextPtr& cpu, const std::wstring &name )
|
||||||
|
{
|
||||||
|
|
||||||
|
kdlib::NumVariant var;
|
||||||
|
|
||||||
|
do {
|
||||||
|
|
||||||
|
AutoRestorePyState pystate;
|
||||||
|
|
||||||
//python::object CPUContextAdapter::getRegisterByIndex( kdlib::CPUContextPtr& cpu, unsigned long index )
|
var = cpu->getRegisterByName(name);
|
||||||
//{
|
|
||||||
// kdlib::NumVariant var;
|
} while(false);
|
||||||
// std::wstring name;
|
|
||||||
//
|
return NumVariantAdaptor::convertToPython( var );
|
||||||
// do {
|
}
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// var = cpu->getRegisterByIndex(index);
|
|
||||||
// name = cpu->getRegisterName(index);
|
|
||||||
// }while(false);
|
|
||||||
//
|
|
||||||
// return python::make_tuple( name, NumVariantAdaptor::convertToPython( var ) );
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//python::list CPUContextAdapter::getStack( kdlib::CPUContextPtr& cpu )
|
|
||||||
//{
|
|
||||||
// kdlib::StackPtr stack;
|
|
||||||
// unsigned long numberFrames;
|
|
||||||
//
|
|
||||||
// do {
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// stack = kdlib::getStack(cpu);
|
|
||||||
// numberFrames = stack->getFrameCount();
|
|
||||||
// } while(false);
|
|
||||||
//
|
|
||||||
// python::list lst;
|
|
||||||
// for ( unsigned long i = 0; i < numberFrames; ++i )
|
|
||||||
// lst.append( stack->getFrame(i) );
|
|
||||||
//
|
|
||||||
// return lst;
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//std::wstring StackFrameAdapter::print( kdlib::StackFramePtr& frame )
|
|
||||||
//{
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
//
|
|
||||||
// std::wstringstream sstr;
|
|
||||||
// sstr << L"Frame: ";
|
|
||||||
// sstr << L"IP=" << std::hex << frame->getIP() << L" ";
|
|
||||||
// sstr << L"Return=" << std::hex << frame->getRET() << L" ";
|
|
||||||
// sstr << L"Frame Offset=" << std::hex << frame->getFP() << L" ";
|
|
||||||
// sstr << L"Stack Offset=" << std::hex << frame->getSP();
|
|
||||||
//
|
|
||||||
// return sstr.str();
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//python::list StackFrameAdapter::getParamsList( kdlib::StackFramePtr& frame)
|
|
||||||
//{
|
|
||||||
// typedef std::vector< std::pair< std::wstring, kdlib::TypedVarPtr> > FuncParamList;
|
|
||||||
//
|
|
||||||
// FuncParamList paramLst;
|
|
||||||
// unsigned long paramCount;
|
|
||||||
//
|
|
||||||
// do {
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// paramCount = frame->getTypedParamCount();
|
|
||||||
// for ( unsigned long i = 0; i < paramCount; ++i )
|
|
||||||
// {
|
|
||||||
// kdlib::TypedVarPtr param = frame->getTypedParam(i);
|
|
||||||
// std::wstring paramName = frame->getTypedParamName(i);
|
|
||||||
//
|
|
||||||
// paramLst.push_back( std::make_pair( paramName, param) );
|
|
||||||
// }
|
|
||||||
// } while(false);
|
|
||||||
//
|
|
||||||
// python::list pyLst;
|
|
||||||
//
|
|
||||||
// for ( unsigned long i = 0; i < paramCount; ++i )
|
|
||||||
// pyLst.append( python::make_tuple( paramLst[i].first, paramLst[i].second ) );
|
|
||||||
//
|
|
||||||
// return pyLst;
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//python::dict StackFrameAdapter::getParamsDict( kdlib::StackFramePtr& frame)
|
|
||||||
//{
|
|
||||||
// typedef std::vector< std::pair< std::wstring, kdlib::TypedVarPtr> > FuncParamList;
|
|
||||||
//
|
|
||||||
// FuncParamList paramLst;
|
|
||||||
// unsigned long paramCount;
|
|
||||||
//
|
|
||||||
// do {
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// paramCount = frame->getTypedParamCount();
|
|
||||||
// for ( unsigned long i = 0; i < paramCount; ++i )
|
|
||||||
// {
|
|
||||||
// kdlib::TypedVarPtr param = frame->getTypedParam(i);
|
|
||||||
// std::wstring paramName = frame->getTypedParamName(i);
|
|
||||||
//
|
|
||||||
// paramLst.push_back( std::make_pair( paramName, param) );
|
|
||||||
// }
|
|
||||||
// } while(false);
|
|
||||||
//
|
|
||||||
// python::dict pyLst;
|
|
||||||
//
|
|
||||||
// for ( unsigned long i = 0; i < paramCount; ++i )
|
|
||||||
// pyLst[paramLst[i].first] = paramLst[i].second;
|
|
||||||
//
|
|
||||||
// return pyLst;
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//python::list StackFrameAdapter::getLocalsList(kdlib::StackFramePtr& frame)
|
|
||||||
//{
|
|
||||||
// typedef std::vector< std::pair< std::wstring, kdlib::TypedVarPtr> > LocalVarList;
|
|
||||||
//
|
|
||||||
// LocalVarList localLst;
|
|
||||||
// unsigned long localCount;
|
|
||||||
//
|
|
||||||
// do {
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// localCount = frame->getLocalVarCount();
|
|
||||||
// for ( unsigned long i = 0; i < localCount; ++i )
|
|
||||||
// {
|
|
||||||
// kdlib::TypedVarPtr param = frame->getLocalVar(i);
|
|
||||||
// std::wstring paramName = frame->getLocalVarName(i);
|
|
||||||
//
|
|
||||||
// localLst.push_back( std::make_pair( paramName, param) );
|
|
||||||
// }
|
|
||||||
// } while(false);
|
|
||||||
//
|
|
||||||
// python::list pyLst;
|
|
||||||
//
|
|
||||||
// for ( unsigned long i = 0; i < localCount; ++i )
|
|
||||||
// pyLst.append( python::make_tuple( localLst[i].first, localLst[i].second ) );
|
|
||||||
//
|
|
||||||
// return pyLst;
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//python::dict StackFrameAdapter::getLocalsDict(kdlib::StackFramePtr& frame)
|
|
||||||
//{
|
|
||||||
// typedef std::vector< std::pair< std::wstring, kdlib::TypedVarPtr> > LocalVarList;
|
|
||||||
//
|
|
||||||
// LocalVarList localLst;
|
|
||||||
// unsigned long localCount;
|
|
||||||
//
|
|
||||||
// do {
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// localCount = frame->getLocalVarCount();
|
|
||||||
// for ( unsigned long i = 0; i < localCount; ++i )
|
|
||||||
// {
|
|
||||||
// kdlib::TypedVarPtr param = frame->getLocalVar(i);
|
|
||||||
// std::wstring paramName = frame->getLocalVarName(i);
|
|
||||||
//
|
|
||||||
// localLst.push_back( std::make_pair( paramName, param) );
|
|
||||||
// }
|
|
||||||
// } while(false);
|
|
||||||
//
|
|
||||||
// python::dict pyLst;
|
|
||||||
//
|
|
||||||
// for ( unsigned long i = 0; i < localCount; ++i )
|
|
||||||
// pyLst[localLst[i].first] = localLst[i].second;
|
|
||||||
//
|
|
||||||
// return pyLst;
|
|
||||||
//}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
python::tuple CPUContextAdapter::getRegisterByIndex( kdlib::CPUContextPtr& cpu, unsigned long index )
|
||||||
|
{
|
||||||
|
|
||||||
|
kdlib::NumVariant var;
|
||||||
|
|
||||||
|
std::wstring name;
|
||||||
|
|
||||||
|
do {
|
||||||
|
|
||||||
|
AutoRestorePyState pystate;
|
||||||
|
|
||||||
|
var = cpu->getRegisterByIndex(index);
|
||||||
|
|
||||||
|
name = cpu->getRegisterName(index);
|
||||||
|
|
||||||
|
} while(false);
|
||||||
|
|
||||||
|
return python::make_tuple( name, NumVariantAdaptor::convertToPython( var ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
} // end namespace pykd
|
} // end namespace pykd
|
||||||
|
@ -125,139 +125,56 @@ inline python::list getLocals() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class CPUContextAdapter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
static kdlib::CPUContextPtr getCPUContext() {
|
||||||
|
AutoRestorePyState pystate;
|
||||||
|
return kdlib::loadCPUContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
static python::object getRegisterByName( kdlib::CPUContextPtr& cpu, const std::wstring &name );
|
||||||
|
|
||||||
|
static python::tuple getRegisterByIndex( kdlib::CPUContextPtr& cpu, unsigned long index );
|
||||||
|
|
||||||
|
static unsigned long getRegisterNumber( kdlib::CPUContextPtr& cpu)
|
||||||
|
{
|
||||||
|
AutoRestorePyState pystate;
|
||||||
|
return cpu->getRegisterNumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
static kdlib::MEMOFFSET_64 getIP( kdlib::CPUContextPtr& cpu )
|
||||||
|
{
|
||||||
|
AutoRestorePyState pystate;
|
||||||
|
return cpu->getIP();
|
||||||
|
}
|
||||||
|
|
||||||
|
static kdlib::MEMOFFSET_64 getSP( kdlib::CPUContextPtr& cpu )
|
||||||
|
{
|
||||||
|
AutoRestorePyState pystate;
|
||||||
|
return cpu->getSP();
|
||||||
|
}
|
||||||
|
|
||||||
|
static kdlib::MEMOFFSET_64 getFP( kdlib::CPUContextPtr& cpu )
|
||||||
|
{
|
||||||
|
AutoRestorePyState pystate;
|
||||||
|
return cpu->getFP();
|
||||||
|
}
|
||||||
|
|
||||||
|
static kdlib::CPUType getCPUType( kdlib::CPUContextPtr& cpu )
|
||||||
|
{
|
||||||
|
AutoRestorePyState pystate;
|
||||||
|
return cpu->getCPUType();
|
||||||
|
}
|
||||||
|
|
||||||
|
static kdlib::CPUType getCPUMode( kdlib::CPUContextPtr& cpu )
|
||||||
|
{
|
||||||
|
AutoRestorePyState pystate;
|
||||||
|
return cpu->getCPUMode();
|
||||||
|
}
|
||||||
|
|
||||||
//
|
};
|
||||||
//
|
|
||||||
//inline kdlib::CPUContextPtr loadCPUCurrentContext() {
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// return kdlib::loadCPUCurrentContext();
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//inline kdlib::CPUContextPtr loadCPUContextByIndex( unsigned long index ) {
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// return kdlib::loadCPUContextByIndex(index);
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//inline unsigned long long loadMSR( unsigned long msrIndex )
|
|
||||||
//{
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// return kdlib::loadCPUCurrentContext()->loadMSR( msrIndex );
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//inline void setMSR( unsigned long msrIndex, unsigned long long value )
|
|
||||||
//{
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// return kdlib::loadCPUCurrentContext()->setMSR( msrIndex, value );
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//inline kdlib::CPUType getProcessorMode() {
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// return kdlib::loadCPUCurrentContext()->getCPUMode();
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//inline kdlib::CPUType getProcessorType() {
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// return kdlib::loadCPUCurrentContext()->getCPUType();
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//inline void setProcessorMode( kdlib::CPUType mode ) {
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// kdlib::loadCPUCurrentContext()->setCPUMode(mode);
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//inline void switchProcessorMode() {
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// kdlib::loadCPUCurrentContext()->switchCPUMode();
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//inline kdlib::StackFramePtr getCurrentFrame() {
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// return kdlib::getStack()->getFrame(0);
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//inline python::list getParams() {
|
|
||||||
// return StackFrameAdapter::getParamsList( getCurrentFrame() );
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//inline kdlib::TypedVarPtr getParam( const std::wstring &name ) {
|
|
||||||
// return StackFrameAdapter::getParam( getCurrentFrame(), name );
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//inline python::list getLocals() {
|
|
||||||
// return StackFrameAdapter::getLocalsList( getCurrentFrame() );
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//inline kdlib::TypedVarPtr getLocal( const std::wstring &name ) {
|
|
||||||
// return StackFrameAdapter::getLocal( getCurrentFrame(), name );
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//class CPUContextAdapter
|
|
||||||
//{
|
|
||||||
//public:
|
|
||||||
// static python::object getRegisterByName( kdlib::CPUContextPtr& cpu, const std::wstring &name );
|
|
||||||
// static python::object getRegisterByIndex( kdlib::CPUContextPtr& cpu, unsigned long index );
|
|
||||||
// static python::list getStack( kdlib::CPUContextPtr& cpu );
|
|
||||||
//
|
|
||||||
// static kdlib::MEMOFFSET_64 getIP( kdlib::CPUContextPtr& cpu )
|
|
||||||
// {
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// return cpu->getIP();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static kdlib::MEMOFFSET_64 getSP( kdlib::CPUContextPtr& cpu )
|
|
||||||
// {
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// return cpu->getSP();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static kdlib::MEMOFFSET_64 getFP( kdlib::CPUContextPtr& cpu )
|
|
||||||
// {
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// return cpu->getFP();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static kdlib::CPUType getCPUType( kdlib::CPUContextPtr& cpu )
|
|
||||||
// {
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// return cpu->getCPUType();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static kdlib::CPUType getCPUMode( kdlib::CPUContextPtr& cpu )
|
|
||||||
// {
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// return cpu->getCPUMode();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static void setCPUMode( kdlib::CPUContextPtr& cpu, kdlib::CPUType mode )
|
|
||||||
// {
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// cpu->setCPUMode(mode);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static void switchCPUMode( kdlib::CPUContextPtr& cpu )
|
|
||||||
// {
|
|
||||||
// AutoRestorePyState pystate;
|
|
||||||
// cpu->switchCPUMode();
|
|
||||||
// }
|
|
||||||
//};
|
|
||||||
//
|
|
||||||
//inline python::object getRegisterByName( const std::wstring &name )
|
|
||||||
//{
|
|
||||||
// return CPUContextAdapter::getRegisterByName( kdlib::loadCPUCurrentContext(), name );
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//inline python::list getCurrentStack() {
|
|
||||||
// return CPUContextAdapter::getStack( kdlib::loadCPUCurrentContext() );
|
|
||||||
//}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -682,20 +682,17 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
"return the function's local variable by it's name")
|
"return the function's local variable by it's name")
|
||||||
.def( "__str__", StackFrameAdapter::print );
|
.def( "__str__", StackFrameAdapter::print );
|
||||||
|
|
||||||
//python::class_<kdlib::CPUContext, kdlib::CPUContextPtr, boost::noncopyable>( "cpu",
|
python::class_<kdlib::CPUContext, kdlib::CPUContextPtr, boost::noncopyable>( "cpu",
|
||||||
// "class for CPU context representation", python::no_init )
|
"class for CPU context representation", python::no_init )
|
||||||
// .def("__init__", python::make_constructor(pykd::loadCPUCurrentContext) )
|
.def("__init__", python::make_constructor(CPUContextAdapter::getCPUContext) )
|
||||||
// .def("__init__", python::make_constructor(pykd::loadCPUContextByIndex) )
|
.add_property("ip", CPUContextAdapter::getIP )
|
||||||
// .add_property("ip", CPUContextAdapter::getIP )
|
.add_property("sp", CPUContextAdapter::getSP )
|
||||||
// .add_property("sp", CPUContextAdapter::getSP )
|
.add_property("fp", CPUContextAdapter::getSP )
|
||||||
// .add_property("fp", CPUContextAdapter::getSP )
|
.def("getCPUType", CPUContextAdapter::getCPUType )
|
||||||
// .def("getCPUType", CPUContextAdapter::getCPUType )
|
.def("getCPUMode", CPUContextAdapter::getCPUMode )
|
||||||
// .def("getCPUMode", CPUContextAdapter::getCPUMode )
|
.def("__getattr__", CPUContextAdapter::getRegisterByName )
|
||||||
// .def("setCPUMode", CPUContextAdapter::setCPUMode )
|
.def("__getitem__", CPUContextAdapter::getRegisterByIndex )
|
||||||
// .def("switchCPUMode", CPUContextAdapter::switchCPUMode )
|
.def("__len__", CPUContextAdapter::getRegisterNumber );
|
||||||
// .def("getStack", CPUContextAdapter::getStack )
|
|
||||||
// .def("__getattr__", CPUContextAdapter::getRegisterByName )
|
|
||||||
// .def("__getitem__", CPUContextAdapter::getRegisterByIndex );
|
|
||||||
|
|
||||||
python::class_<kdlib::SystemInfo>(
|
python::class_<kdlib::SystemInfo>(
|
||||||
"systemVersion", "Operation system version", python::no_init)
|
"systemVersion", "Operation system version", python::no_init)
|
||||||
|
Loading…
Reference in New Issue
Block a user