mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-29 11:53:23 +08:00
[0.2.x] added : Ctrl+Break support
git-svn-id: https://pykd.svn.codeplex.com/svn@80474 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
d11fd6a958
commit
fbec5c4e5e
@ -59,6 +59,79 @@ WindbgGlobalSession *WindbgGlobalSession::windbgGlobalSession = NULL;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class InterruptWatch
|
||||
{
|
||||
public:
|
||||
InterruptWatch( PDEBUG_CLIENT4 client, python::object& global )
|
||||
{
|
||||
m_debugControl = client;
|
||||
|
||||
m_global = global;
|
||||
|
||||
m_stopEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
|
||||
|
||||
m_thread =
|
||||
CreateThread(
|
||||
NULL,
|
||||
0,
|
||||
threadRoutine,
|
||||
this,
|
||||
0,
|
||||
NULL );
|
||||
}
|
||||
|
||||
~InterruptWatch()
|
||||
{
|
||||
SetEvent( m_stopEvent );
|
||||
|
||||
WaitForSingleObject( m_thread, INFINITE );
|
||||
|
||||
CloseHandle( m_stopEvent );
|
||||
|
||||
CloseHandle( m_thread );
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
|
||||
static int quit(void *) {
|
||||
PyErr_SetString( PyExc_SystemExit, "" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
DWORD workRoutine(){
|
||||
|
||||
while( WAIT_TIMEOUT == WaitForSingleObject( m_stopEvent, 250 ) )
|
||||
{
|
||||
HRESULT hres = m_debugControl->GetInterrupt();
|
||||
if ( hres == S_OK )
|
||||
{
|
||||
PyGILState_STATE state = PyGILState_Ensure();
|
||||
Py_AddPendingCall(&quit, NULL);
|
||||
PyGILState_Release(state);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static DWORD WINAPI threadRoutine(LPVOID lpParameter) {
|
||||
return static_cast<InterruptWatch*>(lpParameter)->workRoutine();
|
||||
}
|
||||
|
||||
HANDLE m_thread;
|
||||
|
||||
HANDLE m_stopEvent;
|
||||
|
||||
python::object m_global;
|
||||
|
||||
CComQIPtr<IDebugControl> m_debugControl;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
BOOL WINAPI DllMain(
|
||||
__in HINSTANCE /*hinstDLL*/,
|
||||
__in DWORD fdwReason,
|
||||
@ -121,6 +194,8 @@ py( PDEBUG_CLIENT4 client, PCSTR args )
|
||||
|
||||
python::object global(main.attr("__dict__"));
|
||||
|
||||
InterruptWatch interruptWatch( client, global );
|
||||
|
||||
// íàñòðàèâàåì ââîä/âûâîä ( ÷òîáû â ñêðèïòå ìîæíî áûëî ïèñàòü print )
|
||||
|
||||
python::object sys = python::import("sys");
|
||||
@ -228,24 +303,28 @@ pycmd( PDEBUG_CLIENT4 client, PCSTR args )
|
||||
client->GetOutputMask( &mask );
|
||||
client->SetOutputMask( mask & ~DEBUG_OUTPUT_PROMPT ); // óáðàòü ýõî ââîäà
|
||||
|
||||
InterruptWatch interruptWatch( client, WindbgGlobalSession::global() );
|
||||
|
||||
try {
|
||||
|
||||
PyRun_String(
|
||||
"__import__('code').InteractiveConsole(__import__('__main__').__dict__).interact()",
|
||||
Py_file_input,
|
||||
WindbgGlobalSession::global().ptr(),
|
||||
WindbgGlobalSession::global().ptr()
|
||||
python::exec(
|
||||
"try:\n"
|
||||
" __import__('code').InteractiveConsole(__import__('__main__').__dict__).interact()\n"
|
||||
"except SystemExit:\n"
|
||||
" print 'Ctrl+Break'\n",
|
||||
WindbgGlobalSession::global(),
|
||||
WindbgGlobalSession::global()
|
||||
);
|
||||
|
||||
// âûõîä èç èíòåðïðåòàòîðà ïðîèñõîäèò ÷åðåç èñêëþ÷åíèå raise SystemExit(code)
|
||||
// êîòîðîå ïîòîì ìîæåò ïîìåøàòü èñïîëíåíèþ callback îâ
|
||||
PyErr_Clear();
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
eprintln( L"unexpected error" );
|
||||
}
|
||||
|
||||
// âûõîä èç èíòåðïðåòàòîðà ïðîèñõîäèò ÷åðåç èñêëþ÷åíèå raise SystemExit(code)
|
||||
// êîòîðîå ïîòîì ìîæåò ïîìåøàòü èñïîëíåíèþ callback îâ
|
||||
PyErr_Clear();
|
||||
|
||||
client->SetOutputMask( mask );
|
||||
|
||||
WindbgGlobalSession::SavePyState();
|
||||
|
@ -154,8 +154,8 @@ class IpProtocol:
|
||||
|
||||
def getNextLayerPacket( self, dataPos ):
|
||||
return {
|
||||
ICMP_PROTO : lambda x : "",
|
||||
UDP_PROTO : lambda x : UdpPacket(x),
|
||||
ICMP_PROTO : lambda x : "",
|
||||
UDP_PROTO : lambda x : UdpPacket(x),
|
||||
TCP_PROTO : lambda x : TcpPacket(x)
|
||||
}.get( self.typeVal, lambda x : "Unknown protocol" )(dataPos)
|
||||
|
||||
@ -382,7 +382,7 @@ def getPacketFromNb( nb ):
|
||||
|
||||
pcktBytes = list()
|
||||
|
||||
mdl = typedVar( "ndis", "_MDL", nb.CurrentMdl )
|
||||
mdl = typedVar( "ndis!_MDL", nb.CurrentMdl )
|
||||
dataLength = nb.DataLength
|
||||
dataOffset = nb.CurrentMdlOffset
|
||||
|
||||
@ -395,9 +395,9 @@ def getPacketFromNb( nb ):
|
||||
|
||||
dataLength -= copyData
|
||||
|
||||
mdl = typedVar( "ndis", "_MDL", mdl.Next )
|
||||
mdl = typedVar( "ndis!_MDL", mdl.Next )
|
||||
|
||||
return pcktBytes
|
||||
return pcktBytes
|
||||
|
||||
|
||||
|
||||
@ -405,11 +405,11 @@ def getPacketsFromNbl( nblAddr ):
|
||||
|
||||
pcktList = list()
|
||||
|
||||
nbl = typedVar( "ndis", "_NET_BUFFER_LIST", nblAddr )
|
||||
nbl = typedVar( "ndis!_NET_BUFFER_LIST", nblAddr )
|
||||
|
||||
while True:
|
||||
|
||||
nb = typedVar( "ndis", "_NET_BUFFER", nbl.FirstNetBuffer )
|
||||
nb = typedVar( "ndis!_NET_BUFFER", nbl.FirstNetBuffer )
|
||||
|
||||
while True:
|
||||
|
||||
@ -418,12 +418,12 @@ def getPacketsFromNbl( nblAddr ):
|
||||
if nb.Next == 0:
|
||||
break
|
||||
|
||||
nb = typedVar( "ndis", "_NET_BUFFER", nb.Next )
|
||||
nb = typedVar( "ndis!_NET_BUFFER", nb.Next )
|
||||
|
||||
if nbl.Next == 0:
|
||||
break
|
||||
|
||||
nbl = typedVar( "ndis", "_NET_BUFFER_LIST", nbl.Next )
|
||||
nbl = typedVar( "ndis!_NET_BUFFER_LIST", nbl.Next )
|
||||
|
||||
return pcktList
|
||||
|
||||
@ -437,7 +437,7 @@ def printNblStruct( nblAddr ):
|
||||
|
||||
dprintln( "NET_BUFFER_LIST %#x" % nblAddr )
|
||||
|
||||
nbl = typedVar( "ndis", "_NET_BUFFER_LIST", nblAddr )
|
||||
nbl = typedVar( "ndis!_NET_BUFFER_LIST", nblAddr )
|
||||
|
||||
nbAddr = nbl.FirstNetBuffer
|
||||
|
||||
@ -445,7 +445,7 @@ def printNblStruct( nblAddr ):
|
||||
|
||||
dprint( "\tNET_BUFFER %#x" % nbAddr )
|
||||
|
||||
nb = typedVar( "ndis", "_NET_BUFFER", nbAddr )
|
||||
nb = typedVar( "ndis!_NET_BUFFER", nbAddr )
|
||||
|
||||
dprintln( " data length = %d, data offset = %#x " % ( nb.DataLength, nb.DataOffset ) )
|
||||
|
||||
@ -455,7 +455,7 @@ def printNblStruct( nblAddr ):
|
||||
|
||||
dprint( "\t\tMDL %#x" % mdlAddr )
|
||||
|
||||
mdl = typedVar( "ndis", "_MDL", mdlAddr )
|
||||
mdl = typedVar( "ndis!_MDL", mdlAddr )
|
||||
|
||||
dprintln( " byte count = %d, byte offset = %#x, mapped addr = %#x" % ( mdl.ByteCount, mdl.ByteOffset, mdl.MappedSystemVa ) )
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user