Exemplo n.º 1
0
class DebugBreakpointsWidget(QWidget, DockContextHandler):
    def __init__(self, parent, name, data):
        if not type(data) == BinaryView:
            raise Exception('expected widget data to be a BinaryView')

        self.bv = data

        QWidget.__init__(self, parent)
        DockContextHandler.__init__(self, self, name)
        self.actionHandler = UIActionHandler()
        self.actionHandler.setupActionHandler(self)

        self.table = QTableView(self)
        self.model = DebugBreakpointsListModel(self.table, data)
        self.table.setModel(self.model)

        self.item_delegate = DebugBreakpointsItemDelegate(self)
        self.table.setItemDelegate(self.item_delegate)

        # self.table.setSortingEnabled(True)
        self.table.setSelectionBehavior(
            QAbstractItemView.SelectionBehavior.SelectRows)
        self.table.setSelectionMode(QAbstractItemView.ExtendedSelection)

        self.table.verticalHeader().setSectionResizeMode(
            QHeaderView.ResizeToContents)
        self.table.verticalHeader().setVisible(False)

        self.table.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel)
        self.table.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)

        self.table.resizeColumnsToContents()
        self.table.resizeRowsToContents()
        self.table.horizontalHeader().setSectionResizeMode(
            1, QHeaderView.Stretch)

        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        layout.addWidget(self.table)
        self.setLayout(layout)

    def notifyOffsetChanged(self, offset):
        pass

    def notifyBreakpointsChanged(self, new_rows):
        self.model.update_rows(new_rows)

    def contextMenuEvent(self, event):
        self.m_contextMenuManager.show(self.m_menu, self.actionHandler)

    def shouldBeVisible(self, view_frame):
        if view_frame is None:
            return False
        else:
            return True
Exemplo n.º 2
0
class DebugThreadsWidget(QWidget, DockContextHandler):
    def __init__(self, parent, name, data):
        if not type(data) == BinaryView:
            raise Exception('expected widget data to be a BinaryView')

        self.bv = data

        QWidget.__init__(self, parent)
        DockContextHandler.__init__(self, self, name)
        self.actionHandler = UIActionHandler()
        self.actionHandler.setupActionHandler(self)

        self.table = QTableView(self)
        self.model = DebugThreadsListModel(self.table)
        self.table.setModel(self.model)
        self.table.clicked.connect(self.threadRowClicked)

        self.item_delegate = DebugThreadsItemDelegate(self)
        self.table.setItemDelegate(self.item_delegate)

        # self.table.setSortingEnabled(True)
        self.table.setSelectionBehavior(
            QAbstractItemView.SelectionBehavior.SelectRows)
        self.table.setSelectionMode(QAbstractItemView.ExtendedSelection)

        self.table.verticalHeader().setSectionResizeMode(
            QHeaderView.ResizeToContents)
        self.table.verticalHeader().setVisible(False)

        self.table.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel)
        self.table.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)

        self.table.resizeColumnsToContents()
        self.table.resizeRowsToContents()
        self.table.horizontalHeader().setSectionResizeMode(
            1, QHeaderView.Stretch)

        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        layout.addWidget(self.table)
        self.setLayout(layout)

    def notifyOffsetChanged(self, offset):
        pass

    # called from QTableView's clicked signal
    # index: QModelIndex
    def threadRowClicked(self, index):
        index = self.model.createIndex(index.row(), 0)
        tid_str = self.model.data(index, Qt.DisplayRole)
        #print('clicked to change to thread %s' % tid_str)
        stateObj = binjaplug.get_state(self.bv)
        if stateObj.connected and not stateObj.running:
            tid = int(tid_str, 16)
            stateObj.threads.current = tid
            stateObj.ui.context_display()
            stateObj.ui.on_step()
        else:
            print('cannot set thread in current state')

    # called from plugin's context_display() function
    def notifyThreadsChanged(self, new_threads):
        idx_selected = self.model.update_rows(new_threads)
        if idx_selected:
            self.table.setCurrentIndex(idx_selected)

    def contextMenuEvent(self, event):
        self.m_contextMenuManager.show(self.m_menu, self.actionHandler)

    def shouldBeVisible(self, view_frame):
        if view_frame is None:
            return False
        else:
            return True