mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 21:03:23 +08:00
[0.1.x] added : getThreadList routine
[0.1.x] added : isValid routine git-svn-id: https://pykd.svn.codeplex.com/svn@72368 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
4b207aa77c
commit
1e2374d73b
@ -101,6 +101,8 @@ public:
|
|||||||
|
|
||||||
std::string getProcessorType();
|
std::string getProcessorType();
|
||||||
|
|
||||||
|
python::list getThreadList();
|
||||||
|
|
||||||
template<ULONG status>
|
template<ULONG status>
|
||||||
void changeDebuggerStatus();
|
void changeDebuggerStatus();
|
||||||
|
|
||||||
@ -110,6 +112,8 @@ public:
|
|||||||
|
|
||||||
bool isDumpAnalyzing();
|
bool isDumpAnalyzing();
|
||||||
|
|
||||||
|
bool isVaValid( ULONG64 addr );
|
||||||
|
|
||||||
void loadDump( const std::wstring &fileName );
|
void loadDump( const std::wstring &fileName );
|
||||||
|
|
||||||
Module loadModuleByName( const std::string &moduleName ) {
|
Module loadModuleByName( const std::string &moduleName ) {
|
||||||
|
@ -171,14 +171,18 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
"Return current processor mode as string: X86, ARM, IA64 or X64" )
|
"Return current processor mode as string: X86, ARM, IA64 or X64" )
|
||||||
.def( "getProcessorType", &DebugClient::getProcessorType,
|
.def( "getProcessorType", &DebugClient::getProcessorType,
|
||||||
"Return type of physical processor: X86, ARM, IA64 or X64" )
|
"Return type of physical processor: X86, ARM, IA64 or X64" )
|
||||||
|
.def( "getThreadList", &DebugClient::getThreadList,
|
||||||
|
"Return list of threads (each item is numeric identifier of thread)" )
|
||||||
.def( "go", &DebugClient::changeDebuggerStatus<DEBUG_STATUS_GO>,
|
.def( "go", &DebugClient::changeDebuggerStatus<DEBUG_STATUS_GO>,
|
||||||
"Change debugger status to DEBUG_STATUS_GO" )
|
"Change debugger status to DEBUG_STATUS_GO" )
|
||||||
.def( "is64bitSystem", &DebugClient::is64bitSystem,
|
.def( "is64bitSystem", &DebugClient::is64bitSystem,
|
||||||
"Check if target system has 64 address space" )
|
"Check if target system has 64 address space" )
|
||||||
.def( "isDumpAnalyzing", &pykd::DebugClient::isDumpAnalyzing,
|
.def( "isDumpAnalyzing", &DebugClient::isDumpAnalyzing,
|
||||||
"Check if it is a dump analyzing ( not living debuggee )" )
|
"Check if it is a dump analyzing ( not living debuggee )" )
|
||||||
.def( "isKernelDebugging", &pykd::DebugClient::isKernelDebugging,
|
.def( "isKernelDebugging", &DebugClient::isKernelDebugging,
|
||||||
"Check if kernel dubugging is running" )
|
"Check if kernel dubugging is running" )
|
||||||
|
.def( "isValid", &DebugClient::isVaValid,
|
||||||
|
"Check if the virtual address is valid" )
|
||||||
.def( "loadBytes", &DebugClient::loadBytes, DebugClient_loadBytes( python::args( "offset", "count", "phyAddr" ),
|
.def( "loadBytes", &DebugClient::loadBytes, DebugClient_loadBytes( python::args( "offset", "count", "phyAddr" ),
|
||||||
"Read the block of the target's memory and return it as list of unsigned bytes" ) )
|
"Read the block of the target's memory and return it as list of unsigned bytes" ) )
|
||||||
.def( "loadWords", &DebugClient::loadWords, DebugClient_loadWords( python::args( "offset", "count", "phyAddr" ),
|
.def( "loadWords", &DebugClient::loadWords, DebugClient_loadWords( python::args( "offset", "count", "phyAddr" ),
|
||||||
@ -302,6 +306,8 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
"Return current processor mode as string: X86, ARM, IA64 or X64" );
|
"Return current processor mode as string: X86, ARM, IA64 or X64" );
|
||||||
python::def( "getProcessorType", &getProcessorType,
|
python::def( "getProcessorType", &getProcessorType,
|
||||||
"Return type of physical processor: X86, ARM, IA64 or X64" );
|
"Return type of physical processor: X86, ARM, IA64 or X64" );
|
||||||
|
python::def( "getThreadList", &getThreadList,
|
||||||
|
"Return list of threads (each item is numeric identifier of thread)" );
|
||||||
python::def( "is64bitSystem", &is64bitSystem,
|
python::def( "is64bitSystem", &is64bitSystem,
|
||||||
"Check if target system has 64 address space" );
|
"Check if target system has 64 address space" );
|
||||||
python::def( "isDumpAnalyzing", &isDumpAnalyzing,
|
python::def( "isDumpAnalyzing", &isDumpAnalyzing,
|
||||||
@ -310,6 +316,8 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
"Check if kernel dubugging is running" );
|
"Check if kernel dubugging is running" );
|
||||||
python::def( "isWindbgExt", &WindbgGlobalSession::isInit,
|
python::def( "isWindbgExt", &WindbgGlobalSession::isInit,
|
||||||
"Check if script works in windbg context" );
|
"Check if script works in windbg context" );
|
||||||
|
python::def( "isValid", &isVaValid,
|
||||||
|
"Check if the virtual address is valid" );
|
||||||
python::def( "loadBytes", &loadBytes, loadBytes_( python::args( "offset", "count", "phyAddr" ),
|
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" ) );
|
"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" ),
|
python::def( "loadWords", &loadWords, loadWords_( python::args( "offset", "count", "phyAddr" ),
|
||||||
|
@ -73,6 +73,33 @@ addr64( ULONG64 addr)
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
bool DebugClient::isVaValid( ULONG64 addr )
|
||||||
|
{
|
||||||
|
HRESULT hres;
|
||||||
|
ULONG offsetInfo;
|
||||||
|
|
||||||
|
hres =
|
||||||
|
m_dataSpaces->GetOffsetInformation(
|
||||||
|
DEBUG_DATA_SPACE_VIRTUAL,
|
||||||
|
DEBUG_OFFSINFO_VIRTUAL_SOURCE,
|
||||||
|
addr,
|
||||||
|
&offsetInfo,
|
||||||
|
sizeof( offsetInfo ),
|
||||||
|
NULL );
|
||||||
|
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugDataSpace4::GetOffsetInformation failed" );
|
||||||
|
|
||||||
|
return offsetInfo != DEBUG_VSOURCE_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isVaValid( ULONG64 addr )
|
||||||
|
{
|
||||||
|
return g_dbgClient->isVaValid( addr );
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void
|
void
|
||||||
readMemory( IDebugDataSpaces4* dbgDataSpace, ULONG64 address, PVOID buffer, ULONG length, bool phyAddr = FALSE )
|
readMemory( IDebugDataSpaces4* dbgDataSpace, ULONG64 address, PVOID buffer, ULONG length, bool phyAddr = FALSE )
|
||||||
{
|
{
|
||||||
@ -91,51 +118,8 @@ readMemory( IDebugDataSpaces4* dbgDataSpace, ULONG64 address, PVOID buffer, ULO
|
|||||||
throw MemoryException( address, phyAddr );
|
throw MemoryException( address, phyAddr );
|
||||||
}
|
}
|
||||||
|
|
||||||
//void DebugClient::readMemory( ULONG64 address, PVOID buffer, ULONG length, bool phyAddr )
|
|
||||||
//{
|
|
||||||
// HRESULT hres;
|
|
||||||
//
|
|
||||||
// if ( phyAddr == false )
|
|
||||||
// {
|
|
||||||
// hres = m_dataSpaces->ReadVirtual( address, buffer, length, NULL );
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// hres = m_dataSpaces->ReadPhysical( address, buffer, length, NULL );
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if ( FAILED( hres ) )
|
|
||||||
// throw MemoryException( address, phyAddr );
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//void readMemory( ULONG64 address, PVOID buffer, ULONG length, bool phyAddr )
|
|
||||||
//{
|
|
||||||
// return g_dbgClient->readMemory( address, buffer, length, phyAddr );
|
|
||||||
//}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//bool DebugClient::compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length, bool phyAddr )
|
|
||||||
//{
|
|
||||||
// bool result = false;
|
|
||||||
//
|
|
||||||
// addr1 = addr64( addr1 );
|
|
||||||
// addr2 = addr64( addr2 );
|
|
||||||
//
|
|
||||||
// std::vector<char> m1(length);
|
|
||||||
// std::vector<char> m2(length);
|
|
||||||
//
|
|
||||||
// readMemory( addr1, &m1[0], length, phyAddr );
|
|
||||||
// readMemory( addr2, &m2[0], length, phyAddr );
|
|
||||||
//
|
|
||||||
// return std::equal( m1.begin(), m1.end(), m2.begin() );
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//bool compareMemory( ULONG64 addr1, ULONG64 addr2, ULONG length, bool phyAddr )
|
|
||||||
//{
|
|
||||||
// return g_dbgClient->compareMemory( addr1, addr2, length, phyAddr );
|
|
||||||
//}
|
|
||||||
|
|
||||||
bool compareMemoryRange( IDebugDataSpaces4* dbgDataSpace, ULONG64 addr1, ULONG64 addr2, ULONG length, bool phyAddr )
|
bool compareMemoryRange( IDebugDataSpaces4* dbgDataSpace, ULONG64 addr1, ULONG64 addr2, ULONG length, bool phyAddr )
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
@ -9,6 +9,9 @@ namespace pykd {
|
|||||||
ULONG64
|
ULONG64
|
||||||
addr64( ULONG64 addr );
|
addr64( ULONG64 addr );
|
||||||
|
|
||||||
|
bool
|
||||||
|
isVaValid( ULONG64 addr );
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -138,4 +138,54 @@ std::string getProcessorType()
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
python::list DebugClient::getThreadList()
|
||||||
|
{
|
||||||
|
HRESULT hres;
|
||||||
|
ULONG i;
|
||||||
|
ULONG oldThreadId = 0;
|
||||||
|
ULONG threadCount;
|
||||||
|
|
||||||
|
hres = m_system->GetNumberThreads( &threadCount );
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugSystemObjects::GetNumberThreads failed" );
|
||||||
|
|
||||||
|
std::vector<ULONG> threadIds(threadCount);
|
||||||
|
hres = m_system->GetThreadIdsByIndex( 0, threadCount, &threadIds[0], NULL );
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugSystemObjects::GetThreadIdsByIndex failed" );
|
||||||
|
|
||||||
|
hres = m_system->GetCurrentThreadId( &oldThreadId );
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugSystemObjects::GetCurrentThreadId failed" );
|
||||||
|
|
||||||
|
boost::python::list threadList;
|
||||||
|
|
||||||
|
for ( i = 0; i < threadCount; ++i )
|
||||||
|
{
|
||||||
|
m_system->SetCurrentThreadId( threadIds[i] );
|
||||||
|
|
||||||
|
ULONG64 threadOffset;
|
||||||
|
hres = m_system->GetCurrentThreadDataOffset( &threadOffset );
|
||||||
|
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
{
|
||||||
|
m_system->SetCurrentThreadId( oldThreadId );
|
||||||
|
throw DbgException( "IDebugSystemObjects::GetCurrentThreadDataOffset failed" );
|
||||||
|
}
|
||||||
|
|
||||||
|
threadList.append( threadOffset );
|
||||||
|
}
|
||||||
|
|
||||||
|
m_system->SetCurrentThreadId( oldThreadId );
|
||||||
|
|
||||||
|
return threadList;
|
||||||
|
}
|
||||||
|
|
||||||
|
python::list getThreadList()
|
||||||
|
{
|
||||||
|
return g_dbgClient->getThreadList();
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
}
|
@ -14,6 +14,8 @@ std::string getProcessorMode();
|
|||||||
|
|
||||||
std::string getProcessorType();
|
std::string getProcessorType();
|
||||||
|
|
||||||
|
python::list getThreadList();
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,11 @@ class DbgClientTest( unittest.TestCase ):
|
|||||||
self.assertEqual( pykd.DEBUG_STATUS_BREAK, pykd.getExecutionStatus() )
|
self.assertEqual( pykd.DEBUG_STATUS_BREAK, pykd.getExecutionStatus() )
|
||||||
|
|
||||||
def testPdbFile( self ):
|
def testPdbFile( self ):
|
||||||
self.assertNotEqual( '', target.module )
|
self.assertNotEqual( '', pykd.getPdbFile( target.module.begin() ) )
|
||||||
|
|
||||||
def testProcessorMode( self ):
|
def testProcessorMode( self ):
|
||||||
self.assertNotEqual( '', pykd.getProcessorMode() )
|
self.assertNotEqual( '', pykd.getProcessorMode() )
|
||||||
self.assertNotEqual( '', pykd.getProcessorType() )
|
self.assertNotEqual( '', pykd.getProcessorType() )
|
||||||
|
|
||||||
|
def testThreadList( self ):
|
||||||
|
self.assertNotEqual( 0, len(pykd.getThreadList()) )
|
||||||
|
@ -81,3 +81,9 @@ class MemoryTest( unittest.TestCase ):
|
|||||||
def testCStr( self ):
|
def testCStr( self ):
|
||||||
self.assertEqual( 'Hello', pykd.loadCStr( target.module.helloStr ) )
|
self.assertEqual( 'Hello', pykd.loadCStr( target.module.helloStr ) )
|
||||||
self.assertEqual( u'Hello', pykd.loadWStr( target.module.helloWStr ) )
|
self.assertEqual( u'Hello', pykd.loadWStr( target.module.helloWStr ) )
|
||||||
|
|
||||||
|
def testVaValid( self ):
|
||||||
|
self.assertTrue( pykd.isValid( target.module.begin() ) )
|
||||||
|
self.assertFalse( pykd.isValid( 0 ) )
|
||||||
|
self.assertFalse( pykd.isValid( 0xDEADBEAF ) )
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user