mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 12:53:23 +08:00
[+] added : go, stepin, stepover routine for control execution
[+] added : dbgBreakpointClass class for control breakpoints git-svn-id: https://pykd.svn.codeplex.com/svn@58740 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
ee971fa0e9
commit
ca6c731376
@ -95,3 +95,76 @@ dbgExtensionClass::call( const std::string &command, const std::string params )
|
|||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
dbgBreakpointClass::dbgBreakpointClass( ULONG64 offset )
|
||||||
|
{
|
||||||
|
m_offset = offset;
|
||||||
|
m_breakpoint = NULL;
|
||||||
|
|
||||||
|
set();
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
dbgBreakpointClass::~dbgBreakpointClass()
|
||||||
|
{
|
||||||
|
remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
bool
|
||||||
|
dbgBreakpointClass::set()
|
||||||
|
{
|
||||||
|
HRESULT hres;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
if ( m_breakpoint )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
hres = dbgExt->control->AddBreakpoint( DEBUG_BREAKPOINT_CODE, DEBUG_ANY_ID, &m_breakpoint );
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugControl::AddBreakpoint failed" );
|
||||||
|
|
||||||
|
hres = m_breakpoint->SetOffset( m_offset );
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugBreakpoint::SetOffset failed" );
|
||||||
|
|
||||||
|
hres = m_breakpoint->SetFlags( DEBUG_BREAKPOINT_ENABLED );
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugBreakpoint::SetFlags failed" );
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch( std::exception &e )
|
||||||
|
{
|
||||||
|
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
|
||||||
|
}
|
||||||
|
|
||||||
|
remove();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void
|
||||||
|
dbgBreakpointClass::remove()
|
||||||
|
{
|
||||||
|
if ( m_breakpoint )
|
||||||
|
{
|
||||||
|
dbgExt->control->RemoveBreakpoint( m_breakpoint );
|
||||||
|
m_breakpoint = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -10,6 +10,35 @@
|
|||||||
std::string
|
std::string
|
||||||
dbgCommand( const std::string &command );
|
dbgCommand( const std::string &command );
|
||||||
|
|
||||||
|
template <ULONG status>
|
||||||
|
void
|
||||||
|
setExecutionStatus()
|
||||||
|
{
|
||||||
|
HRESULT hres;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
hres = dbgExt->control->SetExecutionStatus( status );
|
||||||
|
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugControl::SetExecutionStatus failed" );
|
||||||
|
|
||||||
|
hres = dbgExt->control->WaitForEvent( 0, INFINITE );
|
||||||
|
|
||||||
|
if ( FAILED( hres ) )
|
||||||
|
throw DbgException( "IDebugControl::SetExecutionStatus failed" );
|
||||||
|
|
||||||
|
}
|
||||||
|
catch( std::exception &e )
|
||||||
|
{
|
||||||
|
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd error: %s\n", e.what() );
|
||||||
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
dbgExt->control->Output( DEBUG_OUTPUT_ERROR, "pykd unexpected error\n" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class dbgExtensionClass {
|
class dbgExtensionClass {
|
||||||
@ -34,3 +63,27 @@ private:
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
class dbgBreakpointClass {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
dbgBreakpointClass( ULONG64 offset );
|
||||||
|
|
||||||
|
~dbgBreakpointClass();
|
||||||
|
|
||||||
|
bool
|
||||||
|
set();
|
||||||
|
|
||||||
|
void
|
||||||
|
remove();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
ULONG64 m_offset;
|
||||||
|
|
||||||
|
IDebugBreakpoint *m_breakpoint;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -85,6 +85,9 @@ BOOST_PYTHON_FUNCTION_OVERLOADS( compareMemoryOver, compareMemory, 3, 4 )
|
|||||||
|
|
||||||
BOOST_PYTHON_MODULE( pykd )
|
BOOST_PYTHON_MODULE( pykd )
|
||||||
{
|
{
|
||||||
|
boost::python::def( "go", &setExecutionStatus<DEBUG_STATUS_GO> );
|
||||||
|
boost::python::def( "stepin", &setExecutionStatus<DEBUG_STATUS_STEP_INTO> );
|
||||||
|
boost::python::def( "stepover", &setExecutionStatus<DEBUG_STATUS_STEP_OVER> );
|
||||||
boost::python::def( "createSession", &dbgCreateSession );
|
boost::python::def( "createSession", &dbgCreateSession );
|
||||||
boost::python::def( "isSessionStart", &dbgIsSessionStart );
|
boost::python::def( "isSessionStart", &dbgIsSessionStart );
|
||||||
boost::python::def( "symbolsPath", &dbgSymPath );
|
boost::python::def( "symbolsPath", &dbgSymPath );
|
||||||
@ -130,7 +133,7 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
boost::python::def( "ptrPtr", &loadPtrByPtr );
|
boost::python::def( "ptrPtr", &loadPtrByPtr );
|
||||||
boost::python::def( "compareMemory", &compareMemory, compareMemoryOver( boost::python::args( "addr1", "addr2", "length", "phyAddr" ), "" ) );
|
boost::python::def( "compareMemory", &compareMemory, compareMemoryOver( boost::python::args( "addr1", "addr2", "length", "phyAddr" ), "" ) );
|
||||||
boost::python::def( "getCurrentStack", &getCurrentStack );
|
boost::python::def( "getCurrentStack", &getCurrentStack );
|
||||||
boost::python::def( "reloadSymbols", &reloadSymbols );
|
boost::python::def( "reloadModule", &reloadModule );
|
||||||
boost::python::def( "getPdbFile", &getPdbFile );
|
boost::python::def( "getPdbFile", &getPdbFile );
|
||||||
boost::python::def( "getImplicitThread", &getImplicitThread );
|
boost::python::def( "getImplicitThread", &getImplicitThread );
|
||||||
boost::python::def( "setImplicitThread", &setImplicitThread );
|
boost::python::def( "setImplicitThread", &setImplicitThread );
|
||||||
@ -162,6 +165,12 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
.def( "write", &dbgOut::write );
|
.def( "write", &dbgOut::write );
|
||||||
boost::python::class_<dbgIn>( "windbgIn", "windbgIn" )
|
boost::python::class_<dbgIn>( "windbgIn", "windbgIn" )
|
||||||
.def( "readline", &dbgIn::readline );
|
.def( "readline", &dbgIn::readline );
|
||||||
|
boost::python::class_<dbgBreakpointClass>(
|
||||||
|
"dbgBreakpointClass",
|
||||||
|
"dbgBreakpointClass",
|
||||||
|
boost::python::init<ULONG64>( boost::python::args("offset"), "__init__ dbgBreakpointClass" ) )
|
||||||
|
.def( "set", &dbgBreakpointClass::set )
|
||||||
|
.def( "remove", &dbgBreakpointClass::remove );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "dbgext.h"
|
#include "dbgext.h"
|
||||||
#include "dbgexcept.h"
|
#include "dbgexcept.h"
|
||||||
#include "dbgsystem.h"
|
#include "dbgsystem.h"
|
||||||
|
#include "dbgcallback.h"
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -122,19 +123,19 @@ getPdbFile( ULONG64 moduleBase )
|
|||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void
|
void
|
||||||
reloadSymbols( const char * moduleName )
|
reloadModule( const char * moduleName )
|
||||||
{
|
{
|
||||||
HRESULT hres;
|
HRESULT hres;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
std::string reloadParam( "/f " );
|
// ïîäàâèòü âûâîä ñîîáùåíèé îá îòñóòñòâèè ñèìâîëîâ
|
||||||
reloadParam += moduleName;
|
OutputReader outputReader( dbgExt->client );
|
||||||
|
|
||||||
hres = dbgExt->symbols->Reload( reloadParam.c_str() );
|
hres = dbgExt->symbols->Reload( moduleName );
|
||||||
|
|
||||||
if ( FAILED( hres ) )
|
//if ( FAILED( hres ) )
|
||||||
throw DbgException( "IDebugSymbol::Reload failed" );
|
// throw DbgException( "IDebugSymbol::Reload failed" );
|
||||||
}
|
}
|
||||||
catch( std::exception &e )
|
catch( std::exception &e )
|
||||||
{
|
{
|
||||||
|
@ -20,7 +20,7 @@ std::string
|
|||||||
getImageFile( ULONG64 moduleBase );
|
getImageFile( ULONG64 moduleBase );
|
||||||
|
|
||||||
void
|
void
|
||||||
reloadSymbols( const char * moduleName );
|
reloadModule( const char * moduleName );
|
||||||
|
|
||||||
bool
|
bool
|
||||||
isKernelDebugging();
|
isKernelDebugging();
|
||||||
|
29
snippets/reload.py
Normal file
29
snippets/reload.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from pykd import *
|
||||||
|
|
||||||
|
def symreload():
|
||||||
|
|
||||||
|
reloadModule( "/f" )
|
||||||
|
|
||||||
|
PsLoadedModuleList = getOffset( "nt", "PsLoadedModuleList" )
|
||||||
|
|
||||||
|
loadedModulesInfo = typedVarList( PsLoadedModuleList, "nt", "_LDR_DATA_TABLE_ENTRY", "InLoadOrderLinks" )
|
||||||
|
|
||||||
|
for module in loadedModulesInfo:
|
||||||
|
|
||||||
|
if "" == getPdbFile( module.DllBase ):
|
||||||
|
baseName = loadUnicodeString( module.BaseDllName.getAddress() )
|
||||||
|
if baseName=="ntoskrnl.exe": baseName = "nt"
|
||||||
|
reloadModule( " /u " + str(baseName) )
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
if not isSessionStart():
|
||||||
|
dprintln( "script is launch out of windbg" )
|
||||||
|
quit( 0 )
|
||||||
|
|
||||||
|
symreload()
|
Loading…
Reference in New Issue
Block a user