[0.3.x] added : getStack routine

git-svn-id: https://pykd.svn.codeplex.com/svn@84471 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2013-07-26 07:10:39 +00:00 committed by Mikhail I. Izmestev
parent 95162f8de7
commit b011fc2da3
5 changed files with 89 additions and 30 deletions

View File

@ -26,4 +26,38 @@ python::object CPUContextAdaptor::getRegisterByIndex( kdlib::CPUContext& cpu, si
///////////////////////////////////////////////////////////////////////////////
python::list CPUContextAdaptor::getStack( kdlib::CPUContext& cpu )
{
size_t numberFrames = cpu.getStackLength();
python::list lst;
python::object typeObj = python::object( python::handle<>(&PyType_Type) );
python::object frameType = typeObj("frameType", python::tuple(), python::dict() );
for ( size_t i = 0; i < numberFrames; ++i )
{
StackFrame frame;
cpu.getStackFrame( i, frame.ip, frame.ret, frame.fp, frame.sp );
lst.append( frame );
}
return lst;
}
///////////////////////////////////////////////////////////////////////////////
std::wstring printStackFrame( StackFrame& frame )
{
std::wstringstream sstr;
sstr << L"Frame: ";
sstr << L"IP=" << std::hex << frame.ip << L" ";
sstr << L"Return=" << std::hex << frame.ret << L" ";
sstr << L"Frame Offset=" << std::hex << frame.fp << L" ";
sstr << L"Stack Offset=" << std::hex << frame.sp;
return sstr.str();
}
///////////////////////////////////////////////////////////////////////////////
} // end namespace pykd

View File

@ -15,8 +15,15 @@ class CPUContextAdaptor
public:
static python::object getRegisterByName( kdlib::CPUContext& cpu, const std::wstring &name );
static python::object getRegisterByIndex( kdlib::CPUContext& cpu, size_t index );
static python::list getStack( kdlib::CPUContext& cpu );
};
struct StackFrame {
kdlib::MEMOFFSET_64 ip, ret, fp, sp;
};
std::wstring printStackFrame( StackFrame& frame );
inline python::object getRegisterByName( const std::wstring &name )
{
return CPUContextAdaptor::getRegisterByName( *kdlib::loadCPUCurrentContext().get(), name );
@ -40,6 +47,10 @@ inline kdlib::CPUType getProcessorType() {
return kdlib::loadCPUCurrentContext()->getCPUType();
}
inline python::list getCurrentStack() {
return CPUContextAdaptor::getStack( *kdlib::loadCPUCurrentContext() );
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -155,20 +155,24 @@ python::tuple findSymbolAndDisp( ULONG64 offset )
///////////////////////////////////////////////////////////////////////////////
python::object getSystemVersion()
kdlib::SystemInfo getSystemVersion()
{
kdlib::SystemInfo sysInfo;
kdlib::getSystemInfo( sysInfo );
return sysInfo;
}
python::object obj;
///////////////////////////////////////////////////////////////////////////////
obj.attr("majorVersion") = sysInfo.majorVersion;
obj.attr("minorVersion") = sysInfo.minorVersion;
obj.attr("buildNumber") = sysInfo.buildNumber;
obj.attr("buildDescription") = sysInfo.buildDescription;
std::wstring printSystemVersion( kdlib::SystemInfo& sysInfo )
{
std::wstringstream sstr;
return obj;
sstr << L"Major Version: " << sysInfo.majorVersion << std::endl;
sstr << L"Minor Version: " << sysInfo.minorVersion << std::endl;;
sstr << L"Description: " << sysInfo.buildDescription << std::endl;
return sstr.str();
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -25,7 +25,9 @@ python::tuple getSourceLine( kdlib::MEMOFFSET_64 offset = 0 );
python::tuple findSymbolAndDisp( ULONG64 offset );
python::object getSystemVersion();
kdlib::SystemInfo getSystemVersion();
std::wstring printSystemVersion( kdlib::SystemInfo& sysInfo );
///////////////////////////////////////////////////////////////////////////////

View File

@ -262,9 +262,9 @@ BOOST_PYTHON_MODULE( pykd )
// python::def( "setProcessorMode", &setProcessorMode,
// "Set current processor mode by string (X86, ARM, IA64 or X64)" );
// // stack and local variables
// python::def( "getStack", &getCurrentStack,
// "Return a current stack as a list of stackFrame objects" );
// stack and local variables
python::def( "getStack", &getCurrentStack,
"Return a current stack as a list of stackFrame objects" );
// python::def( "getStackWow64", &getCurrentStackWow64,
// "Return a stack for wow64 context as a list of stackFrame objects" );
// python::def( "getFrame", &getCurrentStackFrame,
@ -543,6 +543,13 @@ BOOST_PYTHON_MODULE( pykd )
.def("__init__", python::make_constructor(Breakpoint::setSoftwareBreakpoint) )
;
python::class_<StackFrame>( "stackFrame",
"class for stack's frame representation", python::no_init )
.def_readonly( "ip", &StackFrame::ip, "instruction pointer" )
.def_readonly( "ret", &StackFrame::ret, "return pointer" )
.def_readonly( "fp", &StackFrame::fp, "frame pointer" )
.def_readonly( "sp", &StackFrame::sp, "stack pointer" )
.def( "__str__", &printStackFrame );
python::class_<kdlib::CPUContext, kdlib::CPUContextPtr, boost::noncopyable>( "cpu",
"class for CPU context representation", python::no_init )
@ -553,6 +560,7 @@ BOOST_PYTHON_MODULE( pykd )
.add_property("fp", &kdlib::CPUContext::getSP )
.def("getCPUType", &kdlib::CPUContext::getCPUType )
.def("getCPUMode", &kdlib::CPUContext::getCPUMode )
.def("getStack", &CPUContextAdaptor::getStack )
.def("__getattr__", &CPUContextAdaptor::getRegisterByName )
.def("__getitem__", &CPUContextAdaptor::getRegisterByIndex );
@ -587,24 +595,24 @@ BOOST_PYTHON_MODULE( pykd )
// .def( "__str__", &StackFrame::print,
// "Return stacks frame as a string");
// python::class_< SystemVersion, SystemVersionPtr, boost::noncopyable >(
// "systemVersion", "Operation system version", python::no_init)
python::class_< kdlib::SystemInfo>(
"systemVersion", "Operation system version", python::no_init)
//.def_readonly( "platformId", &SystemVersion::platformId,
// "Platform ID: VER_PLATFORM_WIN32_NT for NT-based Windows")
// .def_readonly( "win32Major", &SystemVersion::win32Major,
// "Major version number of the target's operating system")
// .def_readonly( "win32Minor", &SystemVersion::win32Minor,
// "Minor version number of the target's operating system")
.def_readonly( "win32Major", &kdlib::SystemInfo::majorVersion,
"Major version number of the target's operating system")
.def_readonly( "win32Minor", &kdlib::SystemInfo::minorVersion,
"Minor version number of the target's operating system")
//.def_readonly( "buildNumber", &SystemVersion::buildNumber,
// "Build number for the target's operating system")
// .def_readonly( "buildString", &SystemVersion::buildString,
// "String that identifies the build of the system")
.def_readonly( "buildString", &kdlib::SystemInfo::buildDescription,
"String that identifies the build of the system")
//.def_readonly( "servicePackString", &SystemVersion::servicePackString,
// "String for the service pack level of the target computer")
//.def_readonly( "isCheckedBuild", &SystemVersion::isCheckedBuild,
// "Checked build flag")
// .def("__str__", pysupport::printSystemVersion,
// "Return object as a string");
.def("__str__", &printSystemVersion,
"Return object as a string");
// python::class_< ExceptionInfo, ExceptionInfoPtr, boost::noncopyable >(