mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-20 03:23:23 +08:00
[0.3.x] reworked : cpu class
git-svn-id: https://pykd.svn.codeplex.com/svn@90939 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
84bf4b8bfd
commit
f2a596d65b
@ -43,6 +43,14 @@ python::object getRegisterByIndex(unsigned long index)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::wstring getRegisterNameByIndex(unsigned long index)
|
||||
{
|
||||
AutoRestorePyState pystate;
|
||||
return kdlib::getRegisterName(index);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
python::list getCurrentStack()
|
||||
{
|
||||
kdlib::StackPtr stack;
|
||||
@ -194,45 +202,28 @@ python::dict StackFrameAdapter::getLocalsDict(kdlib::StackFramePtr& frame)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
python::object CPUContextAdapter::getRegisterByName( kdlib::CPUContextPtr& cpu, const std::wstring &name )
|
||||
python::tuple CPUContextAdapter::getRegisterByIndex(unsigned long index)
|
||||
{
|
||||
|
||||
kdlib::NumVariant var;
|
||||
|
||||
do {
|
||||
|
||||
AutoRestorePyState pystate;
|
||||
|
||||
var = cpu->getRegisterByName(name);
|
||||
|
||||
} while(false);
|
||||
|
||||
return NumVariantAdaptor::convertToPython( var );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
python::tuple CPUContextAdapter::getRegisterByIndex( kdlib::CPUContextPtr& cpu, unsigned long index )
|
||||
{
|
||||
|
||||
kdlib::NumVariant var;
|
||||
|
||||
std::wstring name;
|
||||
|
||||
do {
|
||||
|
||||
AutoRestorePyState pystate;
|
||||
|
||||
var = cpu->getRegisterByIndex(index);
|
||||
if (index >= kdlib::getRegisterNumber())
|
||||
throw kdlib::IndexException(index);
|
||||
|
||||
name = cpu->getRegisterName(index);
|
||||
name = kdlib::getRegisterName(index);
|
||||
|
||||
} while(false);
|
||||
var = kdlib::getRegisterByIndex(index);
|
||||
|
||||
return python::make_tuple( name, NumVariantAdaptor::convertToPython( var ) );
|
||||
} while (false);
|
||||
|
||||
return python::make_tuple(name, NumVariantAdaptor::convertToPython(var));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
} // end namespace pykd
|
||||
|
@ -70,11 +70,31 @@ python::object getRegisterByName( const std::wstring &name );
|
||||
|
||||
python::object getRegisterByIndex( unsigned long index );
|
||||
|
||||
std::wstring getRegisterNameByIndex(unsigned long index);
|
||||
|
||||
inline unsigned long getNumberRegisters() {
|
||||
AutoRestorePyState pystate;
|
||||
return kdlib::getRegisterNumber();
|
||||
}
|
||||
|
||||
inline kdlib::MEMOFFSET_64 getIP()
|
||||
{
|
||||
AutoRestorePyState pystate;
|
||||
return kdlib::getInstructionOffset();
|
||||
}
|
||||
|
||||
inline kdlib::MEMOFFSET_64 getSP()
|
||||
{
|
||||
AutoRestorePyState pystate;
|
||||
return kdlib::getStackOffset();
|
||||
}
|
||||
|
||||
inline kdlib::MEMOFFSET_64 getFP()
|
||||
{
|
||||
AutoRestorePyState pystate;
|
||||
return kdlib::getFrameOffset();
|
||||
}
|
||||
|
||||
inline unsigned long long loadMSR( unsigned long msrIndex )
|
||||
{
|
||||
AutoRestorePyState pystate;
|
||||
@ -156,51 +176,45 @@ class CPUContextAdapter
|
||||
{
|
||||
public:
|
||||
|
||||
static kdlib::CPUContextPtr getCPUContext() {
|
||||
AutoRestorePyState pystate;
|
||||
return kdlib::loadCPUContext();
|
||||
}
|
||||
CPUContextAdapter()
|
||||
{}
|
||||
|
||||
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)
|
||||
python::object getRegisterByName(const std::wstring &name)
|
||||
{
|
||||
AutoRestorePyState pystate;
|
||||
return cpu->getRegisterNumber();
|
||||
return pykd::getRegisterByName(name);
|
||||
}
|
||||
|
||||
static kdlib::MEMOFFSET_64 getIP( kdlib::CPUContextPtr& cpu )
|
||||
python::tuple getRegisterByIndex(unsigned long index);
|
||||
|
||||
unsigned long getRegisterNumber()
|
||||
{
|
||||
AutoRestorePyState pystate;
|
||||
return cpu->getIP();
|
||||
return pykd::getNumberRegisters();
|
||||
}
|
||||
|
||||
static kdlib::MEMOFFSET_64 getSP( kdlib::CPUContextPtr& cpu )
|
||||
kdlib::CPUType getCPUType()
|
||||
{
|
||||
AutoRestorePyState pystate;
|
||||
return cpu->getSP();
|
||||
return pykd::getProcessorType();
|
||||
}
|
||||
|
||||
static kdlib::MEMOFFSET_64 getFP( kdlib::CPUContextPtr& cpu )
|
||||
kdlib::CPUType getCPUMode()
|
||||
{
|
||||
AutoRestorePyState pystate;
|
||||
return cpu->getFP();
|
||||
return pykd::getProcessorMode();
|
||||
}
|
||||
|
||||
static kdlib::CPUType getCPUType( kdlib::CPUContextPtr& cpu )
|
||||
kdlib::MEMOFFSET_64 getIP()
|
||||
{
|
||||
AutoRestorePyState pystate;
|
||||
return cpu->getCPUType();
|
||||
return pykd::getIP();
|
||||
}
|
||||
|
||||
static kdlib::CPUType getCPUMode( kdlib::CPUContextPtr& cpu )
|
||||
kdlib::MEMOFFSET_64 getSP()
|
||||
{
|
||||
AutoRestorePyState pystate;
|
||||
return cpu->getCPUMode();
|
||||
return pykd::getSP();
|
||||
}
|
||||
|
||||
kdlib::MEMOFFSET_64 getFP()
|
||||
{
|
||||
return pykd::getFP();
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -355,6 +355,12 @@ BOOST_PYTHON_MODULE( pykd )
|
||||
"Return a CPU register value by the register's number");
|
||||
python::def( "getNumberRegisters", pykd::getNumberRegisters,
|
||||
"Return a number of CPU registers");
|
||||
python::def("getIP", pykd::getIP,
|
||||
"Return instruction pointer");
|
||||
python::def("getSP", pykd::getSP,
|
||||
"Return stack pointer");
|
||||
python::def("getFP", pykd::getFP,
|
||||
"Return frame pointer");
|
||||
python::def ( "rdmsr", pykd::loadMSR,
|
||||
"Return MSR value" );
|
||||
python::def( "wrmsr", pykd::setMSR,
|
||||
@ -867,17 +873,16 @@ BOOST_PYTHON_MODULE( pykd )
|
||||
"return the function's local variable by it's name")
|
||||
.def( "__str__", StackFrameAdapter::print );
|
||||
|
||||
python::class_<kdlib::CPUContext, kdlib::CPUContextPtr, boost::noncopyable>( "cpu",
|
||||
"class for CPU context representation", python::no_init )
|
||||
.def("__init__", python::make_constructor(CPUContextAdapter::getCPUContext) )
|
||||
.add_property("ip", CPUContextAdapter::getIP )
|
||||
.add_property("sp", CPUContextAdapter::getSP )
|
||||
.add_property("fp", CPUContextAdapter::getFP )
|
||||
.def("getCPUType", CPUContextAdapter::getCPUType )
|
||||
.def("getCPUMode", CPUContextAdapter::getCPUMode )
|
||||
.def("__getattr__", CPUContextAdapter::getRegisterByName )
|
||||
.def("__getitem__", CPUContextAdapter::getRegisterByIndex )
|
||||
.def("__len__", CPUContextAdapter::getRegisterNumber );
|
||||
python::class_<CPUContextAdapter>("cpu", "class for CPU context representation" )
|
||||
//.def("__init__", python::make_constructor(CPUContextAdapter::getCPUContext) )
|
||||
.add_property("ip", &CPUContextAdapter::getIP )
|
||||
.add_property("sp", &CPUContextAdapter::getSP )
|
||||
.add_property("fp", &CPUContextAdapter::getFP )
|
||||
.def("getCPUType", &CPUContextAdapter::getCPUType )
|
||||
.def("getCPUMode", &CPUContextAdapter::getCPUMode )
|
||||
.def("__getattr__", &CPUContextAdapter::getRegisterByName )
|
||||
.def("__getitem__", &CPUContextAdapter::getRegisterByIndex )
|
||||
.def("__len__", &CPUContextAdapter::getRegisterNumber );
|
||||
|
||||
python::class_<kdlib::SystemInfo>(
|
||||
"systemVersion", "Operation system version", python::no_init)
|
||||
|
Loading…
Reference in New Issue
Block a user