2013-05-13 20:03:35 +08:00
|
|
|
"""Debug events handler: test [un-]load modules notification"""
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
import target
|
|
|
|
import pykd
|
|
|
|
import fnmatch
|
|
|
|
import testutils
|
|
|
|
|
|
|
|
class ModuleLoadHandler(pykd.eventHandler):
|
|
|
|
"""Track load/unload module implementation"""
|
|
|
|
def __init__(self, moduleMask):
|
|
|
|
pykd.eventHandler.__init__(self)
|
|
|
|
|
|
|
|
self.moduleMask = moduleMask.lower()
|
|
|
|
|
|
|
|
self.wasLoad = 0
|
|
|
|
self.wasUnload = False
|
|
|
|
|
2015-03-04 04:59:10 +08:00
|
|
|
def onLoadModule(self, modBase, name):
|
2013-05-13 20:03:35 +08:00
|
|
|
"""Load module handler"""
|
|
|
|
|
2015-03-04 04:59:10 +08:00
|
|
|
if ( fnmatch.fnmatch(name.lower(), self.moduleMask) ):
|
|
|
|
self.wasLoad = modBase
|
2013-05-13 20:03:35 +08:00
|
|
|
|
2015-03-04 04:59:10 +08:00
|
|
|
return pykd.executionStatus.NoChange
|
2013-05-13 20:03:35 +08:00
|
|
|
|
2015-03-04 04:59:10 +08:00
|
|
|
def onUnloadModule(self, modBase, name):
|
2013-05-13 20:03:35 +08:00
|
|
|
"""Unload module handler"""
|
|
|
|
|
|
|
|
if ( self.wasLoad and (self.wasLoad == modBase) ):
|
|
|
|
self.wasUnload = True
|
|
|
|
|
2015-03-04 04:59:10 +08:00
|
|
|
return pykd.executionStatus.NoChange
|
2013-05-13 20:03:35 +08:00
|
|
|
|
|
|
|
class EhLoadTest(unittest.TestCase):
|
|
|
|
"""Unit tests of [un-]load modules notification"""
|
|
|
|
|
|
|
|
def testLoadUnload(self):
|
|
|
|
"""Start new process and track loading and unloading modules"""
|
2015-03-03 16:05:50 +08:00
|
|
|
pykd.startProcess(target.appPath + " loadunloadmodule")
|
2013-05-13 20:03:35 +08:00
|
|
|
with testutils.ContextCallIt( pykd.killProcess ) as contextCallIt:
|
2015-03-03 16:05:50 +08:00
|
|
|
|
|
|
|
pykd.go() # skip initail break
|
|
|
|
|
|
|
|
modLoadHandler = ModuleLoadHandler( "ws2_32*" )
|
|
|
|
|
|
|
|
pykd.go()
|
|
|
|
|
|
|
|
#with testutils.ContextCallIt( getattr(modLoadHandler, "reset") ) as resetEventHandler:
|
|
|
|
# try:
|
|
|
|
# while True:
|
|
|
|
# pykd.go()
|
|
|
|
# except pykd.WaitEventException:
|
|
|
|
# pass
|
2013-05-13 20:03:35 +08:00
|
|
|
|
|
|
|
self.assertTrue(modLoadHandler.wasLoad)
|
|
|
|
self.assertTrue(modLoadHandler.wasUnload)
|
|
|
|
|