From 2e787e1b57feb3ec20f01f86d67975da050ed621 Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Fri, 25 Nov 2011 13:07:28 +0000 Subject: [PATCH] [0.1.x] added : reg routine [0.1.x] removed : cpuReg class git-svn-id: https://pykd.svn.codeplex.com/svn@71752 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/dbgclient.h | 5 ++ pykd/dbgext.cpp | 12 ++- pykd/dbgobj.h | 4 +- pykd/module.h | 184 --------------------------------------- pykd/pykd_2008.vcproj | 8 ++ test/scripts/basetest.py | 2 +- 6 files changed, 27 insertions(+), 188 deletions(-) diff --git a/pykd/dbgclient.h b/pykd/dbgclient.h index 970389d..1bebaa7 100644 --- a/pykd/dbgclient.h +++ b/pykd/dbgclient.h @@ -13,6 +13,7 @@ #include "dbgcmd.h" #include "pyaux.h" #include "disasm.h" +#include "cpureg.h" ///////////////////////////////////////////////////////////////////////////////// @@ -149,6 +150,10 @@ public: void readMemory( ULONG64 address, PVOID buffer, ULONG length, bool phyAddr = FALSE ); + python::object getRegByName( const std::wstring ®Name ); + + python::object getRegByIndex( ULONG index ); + void setExecutionStatus( ULONG status ); void waitForEvent(); diff --git a/pykd/dbgext.cpp b/pykd/dbgext.cpp index 2ac8f3b..19805d3 100644 --- a/pykd/dbgext.cpp +++ b/pykd/dbgext.cpp @@ -57,7 +57,7 @@ std::string getDebuggerImage() { std::vector buffer(MAX_PATH); - GetModuleFileNameExA( GetCurrentProcess(), NULL, &buffer[0], buffer.size() ); + GetModuleFileNameExA( GetCurrentProcess(), NULL, &buffer[0], (DWORD)buffer.size() ); return std::string( &buffer[0] ); } @@ -213,6 +213,10 @@ BOOST_PYTHON_MODULE( pykd ) "Print out string and insert end of line symbol. If dml = True string is printed with dml highlighting ( only for windbg )" ) .def( "ptrSize", &DebugClient::ptrSize, "Return effective pointer size" ) + .def( "reg", &DebugClient::getRegByName, + "Return a CPU regsiter value by the register's name" ) + .def( "reg", &DebugClient::getRegByIndex, + "Return a CPU regsiter value by the register's value" ) .def( "setExecutionStatus", &pykd::DebugClient::setExecutionStatus, "Requests that the debugger engine enter an executable state" ) .def( "step", &pykd::DebugClient::changeDebuggerStatus, @@ -252,6 +256,8 @@ BOOST_PYTHON_MODULE( pykd ) "Check if it is a dump analyzing ( not living debuggee )" ); python::def( "isKernelDebugging", &isKernelDebugging, "Check if kernel dubugging is running" ); + python::def( "isWindbgExt", &WindbgGlobalSession::isInit, + "Check if script works in windbg context" ); python::def( "loadBytes", &loadBytes, loadBytes_( python::args( "offset", "count", "phyAddr" ), "Read the block of the target's memory and return it as liat of unsigned bytes" ) ); python::def( "loadWords", &loadWords, loadWords_( python::args( "offset", "count", "phyAddr" ), @@ -308,6 +314,10 @@ BOOST_PYTHON_MODULE( pykd ) "Print out string and insert end of line symbol. If dml = True string is printed with dml highlighting ( only for windbg )" ) ); python::def( "ptrSize", &ptrSize, "Return effective pointer size" ); + python::def( "reg", &getRegByName, + "Return a CPU regsiter value by the register's name" ); + python::def( "reg", &getRegByIndex, + "Return a CPU regsiter value by the register's value" ); python::def( "setExecutionStatus", &pykd::setExecutionStatus, "Requests that the debugger engine enter an executable state" ); python::def( "step", &pykd::changeDebuggerStatus, diff --git a/pykd/dbgobj.h b/pykd/dbgobj.h index a82081b..76d44b7 100644 --- a/pykd/dbgobj.h +++ b/pykd/dbgobj.h @@ -36,7 +36,7 @@ protected: if ( FAILED( hres ) ) throw DbgException("QueryInterface IDebugDataSpaces failed"); - hres = client->QueryInterface( __uuidof(IDebugRegisters), (void**)&m_registers ); + hres = client->QueryInterface( __uuidof(IDebugRegisters2), (void**)&m_registers ); if ( FAILED( hres ) ) throw DbgException("QueryInterface IDebugDataSpaces failed"); } @@ -49,7 +49,7 @@ protected: CComPtr m_symbols; CComPtr m_advanced; CComPtr m_dataSpaces; - CComPtr m_registers; + CComPtr m_registers; }; diff --git a/pykd/module.h b/pykd/module.h index 50aa8c5..73e3648 100644 --- a/pykd/module.h +++ b/pykd/module.h @@ -98,187 +98,3 @@ Module loadModuleByOffset( ULONG64 offset ); }; // end pykd namespace - - - - - - - - - -//#include -//#include -// -//#include "dbgext.h" -//#include "dbgmem.h" -// -/////////////////////////////////////////////////////////////////////////////////// -// -//// global unique module data -//// WARNING: add only numeric field or change operator < -//struct ModuleInfo -//{ -// ULONG64 m_base; -// ULONG m_timeDataStamp; -// ULONG m_checkSumm; -// -// ModuleInfo() -// : m_base(0) -// , m_timeDataStamp(0) -// , m_checkSumm(0) -// { -// } -// ModuleInfo( -// const ModuleInfo &rhs -// ) : m_base(rhs.m_base) -// , m_timeDataStamp(rhs.m_timeDataStamp) -// , m_checkSumm(rhs.m_checkSumm) -// { -// } -// ModuleInfo( -// const IMAGEHLP_MODULEW64 &dbgImageHelperInfo -// ) : m_base(addr64(dbgImageHelperInfo.BaseOfImage)) -// , m_timeDataStamp(dbgImageHelperInfo.TimeDateStamp) -// , m_checkSumm(dbgImageHelperInfo.CheckSum) -// { -// } -// ModuleInfo( -// const DEBUG_MODULE_PARAMETERS &dbgModuleParameters -// ) : m_base(addr64(dbgModuleParameters.Base)) -// , m_timeDataStamp(dbgModuleParameters.TimeDateStamp) -// , m_checkSumm(dbgModuleParameters.Checksum) -// { -// } -// -// bool operator ==(const ModuleInfo &rhs) const -// { -// return m_base == rhs.m_base -// && m_timeDataStamp == rhs.m_timeDataStamp -// && m_checkSumm == rhs.m_checkSumm; -// } -// bool operator < (const ModuleInfo &rhs) const -// { -// return memcmp(this, &rhs, sizeof(ModuleInfo)) < 0; -// } -//}; -// -/////////////////////////////////////////////////////////////////////////////////// -// -//class dbgModuleClass { -// -//public: -// -// dbgModuleClass() : -// m_base( 0 ), -// m_end( 0 ) -// {} -// -// dbgModuleClass( const std::string &name, ULONG64 base, ULONG size ); -// -// ULONG64 -// getBegin() const { -// return m_base; -// } -// -// ULONG64 -// getEnd() const { -// return m_end; -// } -// -// ULONG -// getSize() const { -// return (ULONG)( m_end - m_base ); -// } -// -// bool -// contain( ULONG64 addr ) const { -// if ( *( (ULONG*)&addr + 1 ) == 0 ) -// *( (ULONG*)&addr + 1 ) = 0xFFFFFFFF; -// -// return m_base <= addr && addr <= m_end; -// } -// -// std::string -// getName() const { -// return m_name; -// } -// -// void -// reloadSymbols(); -// -// ULONG64 -// getOffset( const std::string &symName ); -// -// std::wstring -// getImageSymbolName() const { -// return m_imageFullName; -// } -// -// std::wstring -// getPdbName() const { -// return std::wstring( m_debugInfo.LoadedPdbName ); -// } -// -// ULONG -// getCheckSum() const { -// return m_debugInfo.CheckSum; -// } -// -// ULONG -// getTimeStamp() const { -// return m_debugInfo.TimeDateStamp; -// } -// -// bool -// addSyntheticSymbol( ULONG64 offset, ULONG size, const std::string &symName ); -// -// void -// delAllSyntheticSymbols(); -// -// ULONG -// delSyntheticSymbol( ULONG64 offset ); -// -// ULONG -// delSyntheticSymbolsMask( const std::string &symName ); -// -// std::string -// print() const; -// -//private: -// -// ULONG64 m_base; -// -// ULONG64 m_end; -// -// std::string m_name; -// -// std::wstring m_imageFullName; -// -// IMAGEHLP_MODULEW64 m_debugInfo; -// -// typedef std::map OffsetMap; -// OffsetMap m_offsets; -// -// void -// getImagePath(); -//}; -// -/////////////////////////////////////////////////////////////////////////////////// -// -//boost::python::object -//loadModule( const std::string &moduleName ); -// -//// query module parameters (for construct dbgModuleClass) by virtual address -//// error : DbgException exception -//void queryModuleParams( -// __in ULONG64 addr, -// __out std::string &name, -// __out ULONG64 &base, -// __out ULONG &size -//); -// -//boost::python::object -//findModule( ULONG64 addr ); -// -/////////////////////////////////////////////////////////////////////////////////// diff --git a/pykd/pykd_2008.vcproj b/pykd/pykd_2008.vcproj index e96db3d..3bf7832 100644 --- a/pykd/pykd_2008.vcproj +++ b/pykd/pykd_2008.vcproj @@ -349,6 +349,10 @@ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > + + @@ -455,6 +459,10 @@ Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > + + diff --git a/test/scripts/basetest.py b/test/scripts/basetest.py index f87e51a..a287fe3 100644 --- a/test/scripts/basetest.py +++ b/test/scripts/basetest.py @@ -95,7 +95,6 @@ class BaseTest( unittest.TestCase ): self.assertTrue( hasattr(pykd, 'TypeException') ) self.assertTrue( hasattr(pykd, 'WaitEventException') ) self.assertTrue( hasattr(pykd, 'bp') ) - self.assertTrue( hasattr(pykd, 'cpuReg') ) self.assertTrue( hasattr(pykd, 'dbgStackFrameClass') ) self.assertTrue( hasattr(pykd, 'disasm') ) self.assertTrue( hasattr(pykd, 'ext') ) @@ -105,6 +104,7 @@ class BaseTest( unittest.TestCase ): def testOldRemovedApi( self ): """ Branch test: old API 0.0.x what should be removed """ + self.assertFalse( hasattr(pykd, 'cpuReg') ) self.assertFalse( hasattr(pykd, 'dbgModuleClass') ) self.assertFalse( hasattr(pykd, 'debugEvent') ) self.assertFalse( hasattr(pykd, 'findModule') )