From ca4d73e776a9589bd41f9cfad7ed271fb172a464 Mon Sep 17 00:00:00 2001 From: "SND\\EreTIk_cp" Date: Wed, 1 May 2013 11:27:29 +0000 Subject: [PATCH] [0.2.x] + target system version git-svn-id: https://pykd.svn.codeplex.com/svn@83540 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgengine.h | 16 +++++++++++-- pykd/python/pymod.cpp | 24 ++++++++++++++++++++ pykd/python/pysupport.cpp | 15 +++++++++++++ pykd/python/pysupport.h | 3 +++ pykd/win/dbgeng.cpp | 47 +++++++++++++++++++++++++++++++++++++++ test/scripts/pykdtest.py | 1 + 6 files changed, 104 insertions(+), 2 deletions(-) diff --git a/pykd/dbgengine.h b/pykd/dbgengine.h index a062ffc..79baf04 100644 --- a/pykd/dbgengine.h +++ b/pykd/dbgengine.h @@ -38,7 +38,20 @@ ULONG getPageSize(); ULONG getSystemUptime(); ULONG getCurrentTime(); -//manage debug module +struct SystemVersion { + ULONG platformId; + ULONG win32Major; + ULONG win32Minor; + ULONG buildNumber; + std::string buildString; + std::string servicePackString; + bool isCheckedBuild; +}; +typedef boost::shared_ptr< SystemVersion > SystemVersionPtr; + +SystemVersionPtr getSystemVersion(); + +// manage debug module ULONG64 findModuleBase( const std::string &moduleName ); ULONG64 findModuleBase( ULONG64 offset ); ULONG64 findModuleBySymbol( const std::string &symbolName ); @@ -163,7 +176,6 @@ ULONG breakPointSet( ULONG64 offset, bool hardware = false, ULONG size = 0, ULON void breakPointRemove( ULONG id ); void breakPointRemoveAll(); - // processes end threads ULONG64 getCurrentProcess(); ULONG getCurrentProcessId(); diff --git a/pykd/python/pymod.cpp b/pykd/python/pymod.cpp index 7390af8..e98b0bd 100644 --- a/pykd/python/pymod.cpp +++ b/pykd/python/pymod.cpp @@ -145,6 +145,8 @@ BOOST_PYTHON_MODULE( pykd ) "Return the number of seconds the computer has been running" ); python::def( "currentTime", &getCurrentTime, "Return the number of seconds since the beginning of 1970" ); + python::def("getSystemVersion", &getSystemVersion, + "Return systemVersion"); // Manage target memory access python::def( "addr64", &addr64, @@ -531,6 +533,26 @@ 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) + .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( "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( "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"); + + python::class_< ExceptionInfo, ExceptionInfoPtr, boost::noncopyable >( "exceptionInfo", "Exception information", python::no_init ) .def_readonly( "FirstChance", &ExceptionInfo::FirstChance, @@ -548,6 +570,8 @@ BOOST_PYTHON_MODULE( pykd ) .def( "__str__", &ExceptionInfo::print, "Return object as a string"); + + python::enum_("eventType", "Type of debug event") .value("Breakpoint", EventTypeBreakpoint) .value("Exception", EventTypeException) diff --git a/pykd/python/pysupport.cpp b/pykd/python/pysupport.cpp index 3aeb444..caee133 100644 --- a/pykd/python/pysupport.cpp +++ b/pykd/python/pysupport.cpp @@ -53,6 +53,21 @@ python::tuple moduleFindSymbolAndDisp( pykd::Module &module, ULONG64 offset ) return python::make_tuple(symbolName,displacement); } +std::string printSystemVersion(SystemVersionPtr sysVer) +{ + std::stringstream sstream; + if (VER_PLATFORM_WIN32_NT == sysVer->platformId) + sstream << "WIN32_NT"; + else + sstream << "Platform ID: " << std::dec << sysVer->platformId; + sstream << " " << std::dec << sysVer->win32Major << "." << sysVer->win32Minor; + sstream << ", " << (sysVer->isCheckedBuild ? "checked" : "free") << " build: "; + sstream << std::dec << sysVer->buildNumber << ", " << sysVer->buildString; + if (!sysVer->servicePackString.empty()) + sstream << " (" << sysVer->servicePackString << ")"; + + return sstream.str(); +} /////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/python/pysupport.h b/pykd/python/pysupport.h index f8c7bdc..b68d6b8 100644 --- a/pykd/python/pysupport.h +++ b/pykd/python/pysupport.h @@ -3,6 +3,7 @@ #include #include "module.h" +#include "dbgengine.h" /////////////////////////////////////////////////////////////////////////////// @@ -17,6 +18,8 @@ python::tuple findSymbolAndDisp( ULONG64 offset ); python::tuple moduleFindSymbolAndDisp( pykd::Module &module, ULONG64 offset ); +std::string printSystemVersion(SystemVersionPtr sysVer); + } } //pykd::support namespace end /////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/win/dbgeng.cpp b/pykd/win/dbgeng.cpp index 0b42a92..e36a4c2 100644 --- a/pykd/win/dbgeng.cpp +++ b/pykd/win/dbgeng.cpp @@ -339,6 +339,53 @@ ULONG getCurrentTime() /////////////////////////////////////////////////////////////////////////////// +SystemVersionPtr getSystemVersion() +{ + SystemVersionPtr sysVer( new SystemVersion ); + ULONG kdMajor; + + boost::scoped_array< CHAR > arrSpString( new CHAR[MAX_PATH + 1] ); + memset(&arrSpString[0], 0, MAX_PATH + 1); + + boost::scoped_array< CHAR > arrBuildString( new CHAR[MAX_PATH + 1] ); + memset(&arrBuildString[0], 0, MAX_PATH + 1); + + ULONG tmp; + + HRESULT hres = + g_dbgEng->control->GetSystemVersion( + &sysVer->platformId, + &kdMajor, + &sysVer->buildNumber, + &arrSpString[0], + MAX_PATH, + &tmp, + &tmp, + &arrBuildString[0], + MAX_PATH, + &tmp); + if (S_OK != hres) + throw DbgException("IDebugControl::GetSystemVersion", hres); + + sysVer->buildString = &arrBuildString[0]; + sysVer->servicePackString = &arrSpString[0]; + sysVer->isCheckedBuild = 0xC == kdMajor; + + hres = + g_dbgEng->control->GetSystemVersionValues( + &sysVer->platformId, + &sysVer->win32Major, + &sysVer->win32Minor, + NULL, + NULL); + if (S_OK != hres) + throw DbgException("IDebugControl::GetSystemVersionValues", hres); + + return sysVer; +} + +/////////////////////////////////////////////////////////////////////////////// + ULONG64 loadMSR( ULONG msr ) { PyThread_StateRestore pyThreadRestore( g_dbgEng->pystate ); diff --git a/test/scripts/pykdtest.py b/test/scripts/pykdtest.py index 66854d4..82be89d 100644 --- a/test/scripts/pykdtest.py +++ b/test/scripts/pykdtest.py @@ -31,6 +31,7 @@ class StartProcessWithoutParamsTest(unittest.TestCase): target.processId = pykd.startProcess( target.appPath ) target.module = pykd.module( target.moduleName ) target.module.reload(); + print "\n" + str( pykd.getSystemVersion() ) pykd.go() class TerminateProcessTest(unittest.TestCase):