def testRemoveAllBp(self):
     bp1 = pykd.setBp(self.targetModule.CdeclFunc)
     bp2 = pykd.setBp(self.targetModule.CdeclFunc + 1)
     bp3 = pykd.setBp(self.targetModule.CdeclFunc + 2)
     self.assertEqual(3, pykd.getNumberBreakpoints())
     pykd.removeAllBp()
     self.assertEqual(0, pykd.getNumberBreakpoints())
     self.assertEqual(pykd.executionStatus.NoDebuggee, pykd.go())
    def testBreakpointEnum(self):

        b1 = pykd.setBp(self.targetModule.CdeclFunc)
        b2 = pykd.setBp(self.targetModule.CdeclFunc + 1)
        b3 = pykd.setBp(self.targetModule.CdeclFunc + 2)

        self.assertEqual(3, pykd.getNumberBreakpoints())
        bpLst = [pykd.getBp(i) for i in range(3)]
        self.assertEqual(3, len(bpLst))
        for bp in bpLst:
            bp.remove()

        self.assertEqual(0, pykd.getNumberBreakpoints())
Ejemplo n.º 3
0
        def breakpoints(self, target_id=0):
            """
            Return a list of breakpoints.

            Returns data in the following structure:
            [
                {
                    "id":           1,
                    "enabled":      True,
                    "one_shot":     False,
                    "hit_count":    5,
                    "locations": [
                        {
                            "address":  0x100000cf0,
                            "name":     'main'
                        }
                    ]
                }
            ]
            """
            breakpoints = []

            for i in range(0, pykd.getNumberBreakpoints()):
                b = pykd.getBp(i)
                addr = b.getOffset()

                name = hex(addr)
                try:
                    name = pykd.findSymbol(addr)
                except:
                    log.exception(
                        "No symbol found for address {}".format(addr))
                    pass

                breakpoints.append({
                    'id':
                    i,
                    'enabled':
                    True,
                    'one_shot':
                    False,
                    'hit_count':
                    '-',
                    'locations': [{
                        "address": addr,
                        "name": name
                    }]
                })

            return breakpoints
    def testBreakpointChangeHandler(self):
        class BreakpointChangeHandler(pykd.eventHandler):
            def __init__(self):
                pykd.eventHandler.__init__(self)
                self.count = 0

            def onChangeBreakpoints(self):
                self.count += 1

        handler = BreakpointChangeHandler()
        bp = pykd.setBp(self.targetModule.CdeclFunc)
        bp.remove()
        self.assertEqual(0, pykd.getNumberBreakpoints())
        self.assertEqual(4, handler.count)
Ejemplo n.º 5
0
Archivo: debug.py Proyecto: Junch/debug
def main():
    pykd.initialize()
    pykd.handler = ExceptionHandler()
    pykd.startProcess("hello.exe")
    targetModule = pykd.module("hello")
    targetModule.reload()

    breakCount = callCounter()
    b1 = pykd.setBp(targetModule.offset('add'), breakCount) # The b1 cannot be commented
    print "There is %d breakpoint" % pykd.getNumberBreakpoints()

    pykd.go()
    print breakCount.count

    targetModule = None
    pykd.killAllProcesses()
Ejemplo n.º 6
0
def main():
    pykd.initialize()
    pykd.handler = ExceptionHandler()
    pykd.startProcess("hello.exe")
    targetModule = pykd.module("hello")
    targetModule.reload()

    breakCount = callCounter()
    b1 = pykd.setBp(targetModule.offset('add'),
                    breakCount)  # The b1 cannot be commented
    print "There is %d breakpoint" % pykd.getNumberBreakpoints()

    pykd.go()
    print breakCount.count

    targetModule = None
    pykd.killAllProcesses()
Ejemplo n.º 7
0
        def breakpoints(self, target_id=0):
            """
            Return a list of breakpoints.

            Returns data in the following structure:
            [
                {
                    "id":           1,
                    "enabled":      True,
                    "one_shot":     False,
                    "hit_count":    5,
                    "locations": [
                        {
                            "address":  0x100000cf0,
                            "name":     'main'
                        }
                    ]
                }
            ]
            """
            breakpoints = []

            for i in range(0, pykd.getNumberBreakpoints()):
                b = pykd.getBp(i)
                addr = b.getOffset()

                name = hex(addr)
                try:
                    name = pykd.findSymbol(addr)
                except:
                    log.exception("No symbol found for address {}".format(addr))
                    pass

                breakpoints.append({
                    'id':           i,
                    'enabled':      True,
                    'one_shot':     False,
                    'hit_count':    '-',
                    'locations':    [{
                        "address":  addr,
                        "name":     name
                    }]
                })

            return breakpoints
Ejemplo n.º 8
0
	def callBack(self):
		print("callBack:{0}".format(self))
		if self.isOneShot == True:
			self.bp_obj.remove()
		return False
		
	def setBreakPoint(self, addr):
		#内部で保持しておかないと、消される。
		self.bp_obj = pykd.setBp(int(addr), self.callBack)
		
		return


print("onceBreakPoint.py")
str = pykd.dbgCommand("x CheckPass2!printf")
print(str)
ary = str.split("\n")
count = 0
list = []

for i  in range(0, len(ary) - 1):
	d = ary[i].split(" ")
	if d[0] != "" :
		myBp = MyBpObject(False)
		myBp.setBreakPoint(int(d[0], 16))
		list.append(myBp)
		
print("set breakpoint Num={0}".format(pykd.getNumberBreakpoints()))

pykd.go()
        else:
            iatEntry = addr64(ptrQWord( iatAddr + i*pSize ))

        if  iatEntry != None and iatEntry != 0:
            symbolName = findSymbol( iatEntry ) 
            if fnmatch.fnmatch( symbolName, mask ): 
                myBp = MyBpObject(True)
                myBp.setBreakPoint(iatEntry, symbolName)
                list.append(myBp)
                #dprintln( "{0:x}\t{1}".format(iatEntry, symbolName) ) 




if __name__ == "__main__":
    if not isWindbgExt():
        print "script is launch out of windbg"
        quit( 0 )

    if len (sys.argv)<=1:
        dprintln( "usage: !py import module_name ( symbol name mask )" )
        quit( 0 )
    elif len( sys.argv ) == 2:
        iat( sys.argv[1] )
    else:
        iat( sys.argv[1], sys.argv[2] )
        
    print("set breakpoint Num={0}".format(pykd.getNumberBreakpoints()))
    pykd.go()

Ejemplo n.º 10
0
def BPsSet():
	"""List breakpoint sets through setBp API."""
	BPs = []
	for i in xrange(0, pykd.getNumberBreakpoints()):
		BPs.append(pykd.getBp(i).getOffset())
	return BPs
 def testBpCommand(self):
     pykd.dbgCommand("bp 0x100")
     self.assertEqual(1, pykd.getNumberBreakpoints())
     bp = pykd.getBp(0)
     self.assertEqual(0x100, bp.getOffset())