コード例 #1
0
    def testSecondChance(self):
        class ExceptionHandler(pykd.eventHandler):
            def __init__(self):
                pykd.eventHandler.__init__(self)

            def onException(self, exceptInfo):
                self.exceptInfo = exceptInfo
                return pykd.eventResult.Proceed

        processId = pykd.startProcess(target.appPath + " exception")
        with testutils.ContextCallIt(
                testutils.KillProcess(processId)) as killStartedProcess:
            exceptionHandler = ExceptionHandler()
            self.assertEqual(pykd.Break, pykd.go())
            self.assertEqual(True, exceptionHandler.exceptInfo.firstChance)
            self.assertEqual(pykd.Break, pykd.go())
            self.assertEqual(False, exceptionHandler.exceptInfo.firstChance)
コード例 #2
0
    def testExceptionHandler(self):
        class ExceptionHandler(pykd.eventHandler):
            def __init__(self):
                pykd.eventHandler.__init__(self)

            def onException(self, exceptInfo):
                self.exceptInfo = exceptInfo
                return pykd.eventResult.Break

        processId = pykd.startProcess(target.appPath + " exception")
        with testutils.ContextCallIt(
                testutils.KillProcess(processId)) as killStartedProcess:
            exceptionHandler = ExceptionHandler()

            self.assertEqual(pykd.Break, pykd.go())
            self.assertEqual(0xC0000005, exceptionHandler.exceptInfo.
                             exceptionCode)  #0xC0000005 = Access violation
コード例 #3
0
    def testException(self):
        """Start new process and track exceptions"""
        _locProcessId = pykd.startProcess(target.appPath +
                                          " -testChangeStatus")
        with testutils.ContextCallIt(
                testutils.KillProcess(_locProcessId)) as killStartedProcess:

            pykd.go()  #skip initial break

            statusChangeHandler = StatusChangeHandler()

            self.assertRaises(pykd.WaitEventException, testutils.infGo)

            self.assertEqual(2, statusChangeHandler.breakCount)
            self.assertEqual(1, statusChangeHandler.noDebuggee)
            self.assertEqual(
                statusChangeHandler.breakCount +
                statusChangeHandler.noDebuggee, statusChangeHandler.goCount)
コード例 #4
0
    def testChangeSymbolsState(self):
        """Start new process and track change symbols exception"""
        _locProcessId = pykd.startProcess(target.appPath + " -testLoadUnload")
        with testutils.ContextCallIt(
                testutils.KillProcess(_locProcessId)) as killStartedProcess:

            mod = pykd.module("targetapp")
            symbolsStateHandler = SymbolsStateHandler(mod.begin())

            pykd.dbgCommand(".reload /u targetapp.exe")
            self.assertTrue(symbolsStateHandler.unloadModuleTrigged)

            pykd.dbgCommand(".reload /u")
            self.assertTrue(symbolsStateHandler.unloadAllModulesTrigged)

            self.assertRaises(pykd.WaitEventException, testutils.infGo)

            self.assertTrue("iphlpapi" in symbolsStateHandler.modNames)
コード例 #5
0
    def testException(self):
        """Start new process and track exceptions"""
        _locProcessId = pykd.startProcess(target.appPath + " -testExceptions")
        with testutils.ContextCallIt(
                testutils.KillProcess(_locProcessId)) as killStartedProcess:
            exceptionHandler = ExceptionHandler()

            while not exceptionHandler.accessViolationOccured:
                pykd.go()

            self.assertEqual(pykd.lastEvent(), pykd.eventType.Exception)

            self.assertTrue(exceptionHandler.accessViolationOccured)
            self.assertEqual(exceptionHandler.param0, 1)  # write
            self.assertEqual(exceptionHandler.param1, 2)  # addr

            exceptInfo = pykd.lastException()
            self.assertEqual(exceptInfo.ExceptionCode, 0xC0000005)
            self.assertEqual(exceptionHandler.param0, exceptInfo.Parameters[0])
            self.assertEqual(exceptionHandler.param1, exceptInfo.Parameters[1])
コード例 #6
0
    def testLoadUnload(self):
        """Start new process and track loading and unloading modules"""
        pykd.startProcess(target.appPath + " loadunloadmodule")
        with testutils.ContextCallIt(pykd.killProcess) as contextCallIt:

            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

            self.assertTrue(modLoadHandler.wasLoad)
            self.assertTrue(modLoadHandler.wasUnload)
コード例 #7
0
    def testLocalVariable(self):
        """Start new process and test local variables"""
        _locProcessId = pykd.startProcess(target.appPath + " -testEnumWindows")
        with testutils.ContextCallIt(
                testutils.KillProcess(_locProcessId)) as killStartedProcess:
            pykd.go()  # initial breakpoint -> wmain
            pykd.go()  # wmain -> targetapp!EnumWindowsProc1

            testEnumWindowsProc1Locals(self, pykd.getLocals())

            pykd.go(
            )  # targetapp!EnumWindowsProc1 -> targetapp!functionCalledFromEnumWindowsProc1
            testEnumWindowsProc1Locals(self, pykd.getStack()[1].locals)

            pykd.go(
            )  # targetapp!EnumWindowsProc1 -> targetapp!EnumWindowsProc2
            locals = pykd.getLocals()
            self.assertEqual(len(locals), 2)
            self.assertTrue(locals[0] == 7 or locals[1] == 7)

            funcParams = pykd.getParams()
            self.assertEqual(len(funcParams), 2)
            self.assertTrue(funcParams[0] == 7 or funcParams[1] == 7)