Ejemplo n.º 1
0
    def Sync(self, offset, added, removed):
        """ Sync(offset, added, removed) => None
        Synchronize debug info with gef. This is an internal function. It is
        not recommended using it from the command line.
        """
        global _breakpoints, _current_instruction, _current_instruction_color

        if _current_instruction > 0:
            idc.SetColor(_current_instruction, CIC_ITEM, _current_instruction_color)

        base_addr = idaapi.get_imagebase()
        pc = base_addr + int(offset, 16)
        _current_instruction = long(pc)
        _current_instruction_color = GetColor(_current_instruction, CIC_ITEM)
        idc.SetColor(_current_instruction, CIC_ITEM, 0x00ff00)
        print("PC @ " + hex(_current_instruction).strip('L'))
        # post it to the ida main thread to prevent race conditions
        idaapi.execute_sync(lambda: idc.Jump(_current_instruction), idaapi.MFF_WRITE)

        cur_bps = set([ idc.GetBptEA(n)-base_addr for n in range(idc.GetBptQty()) ])
        ida_added = cur_bps - _breakpoints
        ida_removed = _breakpoints - cur_bps
        _breakpoints = cur_bps

        # update bp from gdb
        for bp in added:
            idc.AddBpt(base_addr+bp)
            _breakpoints.add(bp)
        for bp in removed:
            if bp in _breakpoints:
                _breakpoints.remove(bp)
            idc.DelBpt(base_addr+bp)

        return [list(ida_added), list(ida_removed)]
Ejemplo n.º 2
0
    def export_bp_notice(self):
        if not self.dbg_dialect:
            print "[sync] idb isn't synced yet, can't export bp"
            return

        mod = self.name.split('.')[0].strip()
        nbp = idc.GetBptQty()

        for i in range(nbp):
            ea = idc.GetBptEA(i)
            attrs = [idc.BPTATTR_TYPE, idc.BPTATTR_COND, idc.BPTATTR_FLAGS]
            btype, cond, flags = [idc.GetBptAttr(ea, x) for x in attrs]

            if cond:
                print "bp %d: conditional bp not supported" % i
            else:
                if ((btype in [idc.BPT_EXEC, idc.BPT_SOFT])
                        and ((flags & idc.BPT_ENABLED) != 0)):
                    offset = ea - self.base
                    bp = self.dbg_dialect['hbp' if
                                          (btype == idc.BPT_EXEC) else 'bp']
                    cmd = "%s%s+0x%x" % (bp, mod, offset)
                    self.notice_broker("cmd", "\"cmd\":\"%s\"" % cmd)
                    print "bp %d: %s" % (i, cmd)

        print "[sync] export done"
Ejemplo n.º 3
0
    def UnregisterHandlers(self, purge=False):
        '''
		Deletes breakpoints for all registered handlers.

		@purge - Removes all handlers for all instances of IDBFunctionHandler.

		Returns None.
		'''
        self.UnregisterDefaultHandler()

        if not purge:
            # Only remove this instance's handlers
            for (name, info) in self.FUNCTION_HANDLERS.iteritems():
                condition = idc.GetBptAttr(info['address'], idc.BPTATTR_COND)

                if condition == self.bpt_cnd:
                    idc.DelBpt(info['address'])
        else:
            # Try to remove ALL instance's handlers (this could remove other conditional breakpoints...)
            for i in range(0, idc.GetBptQty()):
                ea = idc.GetBptEA(i)
                condition = idc.GetBptAttr(ea, idc.BPTATTR_COND)
                if condition.endswith(self.BPT_CND % ''):
                    idc.DelBpt(ea)

        self.FUNCTION_HANDLERS = {}
Ejemplo n.º 4
0
 def load_and_add(self, var):
     dbginfo = self.dbginfo
     bpupdate = set()
     for i in range(idc.GetBptQty()):
         bp = idc.GetBptEA(i)
         res = dbginfo.addbp2(bp)
         if res:
             bpupdate.add(res)
     for funcbp in bpupdate:
         self.bpnode_update(funcbp)
Ejemplo n.º 5
0
def disableAllBpts(exempt):
    qty = idc.GetBptQty()
    disabledSet = []
    for i in range(qty):
        bptEA = idc.GetBptEA(i)
        bptStat = idc.CheckBpt(bptEA)
        if bptStat > 0:
            if exempt is None or exempt != bptEA:
                disabledSet.append(bptEA)
                idc.EnableBpt(bptEA, False)
    return disabledSet
Ejemplo n.º 6
0
def delAllBpts():
    while (True):
        bp = idc.GetBptEA(0)
        if bp == 0xffffffffffffffff:
            break
        idc.DelBpt(bp)
Ejemplo n.º 7
0
def get_bpt_ea(i):
    if idaapi.IDA_SDK_VERSION <= 699:
        bpt_ea = idc.GetBptEA(i)
    else:
        bpt_ea = idc.get_bpt_ea(i)
    return bpt_ea
Ejemplo n.º 8
0
def remove_all_breakpoint():
    for i in range(idc.GetBptQty()):
        idc.DelBpt(idc.GetBptEA(i))
    all_breakpoint.clear()
Ejemplo n.º 9
0
 def _sync_disableBreakpoints(self):
     n = idc.GetBptQty()
     for i in range(n):
         ea = idc.GetBptEA(i)
         idc.EnableBpt(ea, False)