mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 04:13:22 +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()
|
python::list getCurrentStack()
|
||||||
{
|
{
|
||||||
kdlib::StackPtr stack;
|
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;
|
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;
|
std::wstring name;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
AutoRestorePyState pystate;
|
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
|
} // end namespace pykd
|
||||||
|
@ -70,11 +70,31 @@ python::object getRegisterByName( const std::wstring &name );
|
|||||||
|
|
||||||
python::object getRegisterByIndex( unsigned long index );
|
python::object getRegisterByIndex( unsigned long index );
|
||||||
|
|
||||||
|
std::wstring getRegisterNameByIndex(unsigned long index);
|
||||||
|
|
||||||
inline unsigned long getNumberRegisters() {
|
inline unsigned long getNumberRegisters() {
|
||||||
AutoRestorePyState pystate;
|
AutoRestorePyState pystate;
|
||||||
return kdlib::getRegisterNumber();
|
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 )
|
inline unsigned long long loadMSR( unsigned long msrIndex )
|
||||||
{
|
{
|
||||||
AutoRestorePyState pystate;
|
AutoRestorePyState pystate;
|
||||||
@ -156,51 +176,45 @@ class CPUContextAdapter
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static kdlib::CPUContextPtr getCPUContext() {
|
CPUContextAdapter()
|
||||||
AutoRestorePyState pystate;
|
{}
|
||||||
return kdlib::loadCPUContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
static python::object getRegisterByName( kdlib::CPUContextPtr& cpu, const std::wstring &name );
|
python::object getRegisterByName(const std::wstring &name)
|
||||||
|
|
||||||
static python::tuple getRegisterByIndex( kdlib::CPUContextPtr& cpu, unsigned long index );
|
|
||||||
|
|
||||||
static unsigned long getRegisterNumber( kdlib::CPUContextPtr& cpu)
|
|
||||||
{
|
{
|
||||||
AutoRestorePyState pystate;
|
return pykd::getRegisterByName(name);
|
||||||
return cpu->getRegisterNumber();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static kdlib::MEMOFFSET_64 getIP( kdlib::CPUContextPtr& cpu )
|
python::tuple getRegisterByIndex(unsigned long index);
|
||||||
|
|
||||||
|
unsigned long getRegisterNumber()
|
||||||
{
|
{
|
||||||
AutoRestorePyState pystate;
|
return pykd::getNumberRegisters();
|
||||||
return cpu->getIP();
|
|
||||||
}
|
|
||||||
|
|
||||||
static kdlib::MEMOFFSET_64 getSP( kdlib::CPUContextPtr& cpu )
|
|
||||||
{
|
|
||||||
AutoRestorePyState pystate;
|
|
||||||
return cpu->getSP();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static kdlib::MEMOFFSET_64 getFP( kdlib::CPUContextPtr& cpu )
|
kdlib::CPUType getCPUType()
|
||||||
{
|
{
|
||||||
AutoRestorePyState pystate;
|
return pykd::getProcessorType();
|
||||||
return cpu->getFP();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static kdlib::CPUType getCPUType( kdlib::CPUContextPtr& cpu )
|
kdlib::CPUType getCPUMode()
|
||||||
{
|
{
|
||||||
AutoRestorePyState pystate;
|
return pykd::getProcessorMode();
|
||||||
return cpu->getCPUType();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static kdlib::CPUType getCPUMode( kdlib::CPUContextPtr& cpu )
|
kdlib::MEMOFFSET_64 getIP()
|
||||||
{
|
{
|
||||||
AutoRestorePyState pystate;
|
return pykd::getIP();
|
||||||
return cpu->getCPUMode();
|
}
|
||||||
|
|
||||||
|
kdlib::MEMOFFSET_64 getSP()
|
||||||
|
{
|
||||||
|
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");
|
"Return a CPU register value by the register's number");
|
||||||
python::def( "getNumberRegisters", pykd::getNumberRegisters,
|
python::def( "getNumberRegisters", pykd::getNumberRegisters,
|
||||||
"Return a number of CPU registers");
|
"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,
|
python::def ( "rdmsr", pykd::loadMSR,
|
||||||
"Return MSR value" );
|
"Return MSR value" );
|
||||||
python::def( "wrmsr", pykd::setMSR,
|
python::def( "wrmsr", pykd::setMSR,
|
||||||
@ -867,17 +873,16 @@ 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_<CPUContextAdapter>("cpu", "class for CPU context representation" )
|
||||||
"class for CPU context representation", python::no_init )
|
//.def("__init__", python::make_constructor(CPUContextAdapter::getCPUContext) )
|
||||||
.def("__init__", python::make_constructor(CPUContextAdapter::getCPUContext) )
|
.add_property("ip", &CPUContextAdapter::getIP )
|
||||||
.add_property("ip", CPUContextAdapter::getIP )
|
.add_property("sp", &CPUContextAdapter::getSP )
|
||||||
.add_property("sp", CPUContextAdapter::getSP )
|
.add_property("fp", &CPUContextAdapter::getFP )
|
||||||
.add_property("fp", CPUContextAdapter::getFP )
|
.def("getCPUType", &CPUContextAdapter::getCPUType )
|
||||||
.def("getCPUType", CPUContextAdapter::getCPUType )
|
.def("getCPUMode", &CPUContextAdapter::getCPUMode )
|
||||||
.def("getCPUMode", CPUContextAdapter::getCPUMode )
|
.def("__getattr__", &CPUContextAdapter::getRegisterByName )
|
||||||
.def("__getattr__", CPUContextAdapter::getRegisterByName )
|
.def("__getitem__", &CPUContextAdapter::getRegisterByIndex )
|
||||||
.def("__getitem__", CPUContextAdapter::getRegisterByIndex )
|
.def("__len__", &CPUContextAdapter::getRegisterNumber );
|
||||||
.def("__len__", CPUContextAdapter::getRegisterNumber );
|
|
||||||
|
|
||||||
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