Beispiel #1
0
def add_commands(plugin):
    DbgAction = namedtuple('DbgAction', 'name, key_seq, handler')
    plugin_actions = (DbgAction("SyncEnable", QKeySequence(Qt.ALT + Qt.Key_S),
                                UIAction(plugin.cmd_sync)),
                      DbgAction("SyncDisable",
                                QKeySequence(Qt.ALT + Qt.SHIFT + Qt.Key_S),
                                UIAction(plugin.cmd_syncoff)),
                      DbgAction("SyncGo", QKeySequence(Qt.ALT + Qt.Key_F5),
                                UIAction(plugin.cmd_go)),
                      DbgAction("SyncStepOver", QKeySequence(Qt.Key_F10),
                                UIAction(plugin.cmd_so)),
                      DbgAction("SyncStepInto", QKeySequence(Qt.Key_F11),
                                UIAction(plugin.cmd_si)),
                      DbgAction("SyncTranslate",
                                QKeySequence(Qt.ALT + Qt.Key_F2),
                                UIAction(plugin.cmd_translate)),
                      DbgAction("SyncBp", QKeySequence(Qt.Key_F2),
                                UIAction(plugin.cmd_bp)),
                      DbgAction("SyncHwBp", QKeySequence(Qt.CTRL + Qt.Key_F2),
                                UIAction(plugin.cmd_hwbp)),
                      DbgAction("SyncBpOneShot",
                                QKeySequence(Qt.ALT + Qt.Key_F3),
                                UIAction(plugin.cmd_bp1)),
                      DbgAction("SyncHwBpOneShot",
                                QKeySequence(Qt.CTRL + Qt.Key_F3),
                                UIAction(plugin.cmd_hwbp1)))

    for action in plugin_actions:
        UIAction.registerAction(action.name, action.key_seq)
        UIActionHandler.globalActions().bindAction(action.name, action.handler)

    rs_log('commands added')
Beispiel #2
0
    def __init__(self, data):
        global instance_id
        QWidget.__init__(self)
        self.actionHandler = UIActionHandler()
        self.actionHandler.setupActionHandler(self)
        offset_layout = QHBoxLayout()
        offset_layout.addWidget(QLabel("Offset: "))
        self.offset = QLabel(hex(0))
        offset_layout.addWidget(self.offset)
        offset_layout.setAlignment(QtCore.Qt.AlignCenter)
        datatype_layout = QHBoxLayout()
        datatype_layout.addWidget(QLabel("Data Type: "))
        self.datatype = QLabel("")
        datatype_layout.addWidget(self.datatype)
        datatype_layout.setAlignment(QtCore.Qt.AlignCenter)
        layout = QVBoxLayout()
        title = QLabel("Hello Pane", self)
        title.setAlignment(QtCore.Qt.AlignCenter)
        instance = QLabel("Instance: " + str(instance_id), self)
        instance.setAlignment(QtCore.Qt.AlignCenter)
        layout.addStretch()
        layout.addWidget(title)
        layout.addWidget(instance)
        layout.addLayout(datatype_layout)
        layout.addLayout(offset_layout)
        layout.addStretch()
        self.setLayout(layout)
        instance_id += 1
        self.data = data

        # Populate initial state
        self.updateState()

        # Set up view and address change notifications
        self.notifications = HelloNotifications(self)
Beispiel #3
0
    def run(self):
        if self.context == None:
            log_warn("Cannot run snippets outside of the UI at this time.")
            return
        if self.snippetChanged():
            question = QMessageBox.question(
                self, self.tr("Confirm"),
                self.tr("You have unsaved changes, must save first. Save?"))
            if (question == QMessageBox.StandardButton.No):
                return
            else:
                self.save()
        actionText = actionFromSnippet(self.currentFile,
                                       self.snippetDescription.text())
        UIActionHandler.globalActions().executeAction(actionText, self.context)

        log_debug("Saving snippet %s" % self.currentFile)
        outputSnippet = codecs.open(self.currentFile, "w", "utf-8")
        outputSnippet.write("#" + self.snippetDescription.text() + "\n")
        outputSnippet.write("#" +
                            self.keySequenceEdit.keySequence().toString() +
                            "\n")
        outputSnippet.write(self.edit.toPlainText())
        outputSnippet.close()
        self.registerAllSnippets()
Beispiel #4
0
    def __init__(self, parent, view, data):
        QTreeView.__init__(self, parent)
        FilterTarget.__init__(self)
        self.data = data
        self.parent = parent
        self.view = view

        # Allow view-specific shortcuts when exports are focused
        self.actionHandler = UIActionHandler()
        self.actionHandler.setupActionHandler(self)
        self.actionHandler.setActionContext(lambda: self.view.actionContext())

        self.model = GenericExportsModel(self.data)
        self.setModel(self.model)
        self.setRootIsDecorated(False)
        self.setUniformRowHeights(True)
        self.setSortingEnabled(True)
        self.sortByColumn(0, Qt.AscendingOrder)
        if self.model.ordinal_col is not None:
            self.setColumnWidth(self.model.ordinal_col, 55)

        self.setFont(binaryninjaui.getMonospaceFont(self))

        self.selectionModel().currentChanged.connect(self.exportSelected)
        self.doubleClicked.connect(self.exportDoubleClicked)
Beispiel #5
0
    def registerAllSnippets():
        for action in list(
                filter(lambda x: x.startswith("Snippets\\"),
                       UIAction.getAllRegisteredActions())):
            if action == "Snippets\\Snippet Editor...":
                continue
            UIActionHandler.globalActions().unbindAction(action)
            Menu.mainMenu("Tools").removeAction(action)
            UIAction.unregisterAction(action)

        for snippet in includeWalk(snippetPath, ".py"):
            snippetKeys = None
            (snippetDescription, snippetKeys,
             snippetCode) = loadSnippetFromFile(snippet)
            if not snippetDescription:
                actionText = "Snippets\\" + os.path.basename(snippet).rstrip(
                    ".py")
            else:
                actionText = "Snippets\\" + snippetDescription
            if snippetCode:
                if snippetKeys == None:
                    UIAction.registerAction(actionText)
                else:
                    UIAction.registerAction(actionText, snippetKeys)
                UIActionHandler.globalActions().bindAction(
                    actionText, UIAction(makeSnippetFunction(snippetCode)))
                Menu.mainMenu("Tools").addAction(actionText, actionText)
Beispiel #6
0
    def __init__(self, parent, name, data):
        QWidget.__init__(self, parent)
        DockContextHandler.__init__(self, self, name)
        self.actionHandler = UIActionHandler()
        self.actionHandler.setupActionHandler(self)

        status_layout = QHBoxLayout()
        status_layout.addWidget(QLabel('Status: '))
        self.status = QLabel('idle')
        status_layout.addWidget(self.status)
        status_layout.setAlignment(QtCore.Qt.AlignCenter)

        client_dbg_layout = QHBoxLayout()
        client_dbg_layout.addWidget(QLabel('Client debugger: '))
        self.client_dbg = QLabel('n/a')
        client_dbg_layout.addWidget(self.client_dbg)
        client_dbg_layout.setAlignment(QtCore.Qt.AlignCenter)

        client_pgm_layout = QHBoxLayout()
        client_pgm_layout.addWidget(QLabel('Client program: '))
        self.client_pgm = QLabel('n/a')
        client_pgm_layout.addWidget(self.client_pgm)
        client_pgm_layout.setAlignment(QtCore.Qt.AlignCenter)

        layout = QVBoxLayout()
        layout.addStretch()
        layout.addLayout(status_layout)
        layout.addLayout(client_dbg_layout)
        layout.addLayout(client_pgm_layout)
        layout.addStretch()
        self.setLayout(layout)
	def __init__(self, name):
		global instance_id
		GlobalAreaWidget.__init__(self, name)
		self.actionHandler = UIActionHandler()
		self.actionHandler.setupActionHandler(self)
		offset_layout = QHBoxLayout()
		offset_layout.addWidget(QLabel("Offset: "))
		self.offset = QLabel(hex(0))
		offset_layout.addWidget(self.offset)
		offset_layout.setAlignment(QtCore.Qt.AlignCenter)
		datatype_layout = QHBoxLayout()
		datatype_layout.addWidget(QLabel("Data Type: "))
		self.datatype = QLabel("")
		datatype_layout.addWidget(self.datatype)
		datatype_layout.setAlignment(QtCore.Qt.AlignCenter)
		layout = QVBoxLayout()
		title = QLabel(name, self)
		title.setAlignment(QtCore.Qt.AlignCenter)
		instance = QLabel("Instance: " + str(instance_id), self)
		instance.setAlignment(QtCore.Qt.AlignCenter)
		layout.addStretch()
		layout.addWidget(title)
		layout.addWidget(instance)
		layout.addLayout(datatype_layout)
		layout.addLayout(offset_layout)
		layout.addStretch()
		self.setLayout(layout)
		instance_id += 1
		self.data = None
Beispiel #8
0
    def __init__(self, parent, name, data):
        QWidget.__init__(self, parent)
        DockContextHandler.__init__(self, self, name)

        self.parent = parent
        self.arch = None
        self.current_state = None
        self.symb_idx = 0
        self.reg_to_index = dict()
        self.index_to_reg = dict()
        self.reg_cache = dict()
        self.data = data
        self.tab_name = None

        self.actionHandler = UIActionHandler()
        self.actionHandler.setupActionHandler(self)

        self._layout = QVBoxLayout()

        # Set up register table
        self._table = QTableWidget()
        self._table.setColumnCount(2)
        self._table.setHorizontalHeaderLabels(['Register', 'Value'])
        self._table.horizontalHeader().setStretchLastSection(True)
        self._table.verticalHeader().setVisible(False)

        self._table.setContextMenuPolicy(Qt.CustomContextMenu)
        self._table.customContextMenuRequested.connect(
            self.on_customContextMenuRequested)
        self._table.doubleClicked.connect(self.on_doubleClick)

        self._layout.addWidget(self._table)

        self.setLayout(self._layout)
Beispiel #9
0
class DebugConsoleWidget(QWidget, DockContextHandler):
	def __init__(self, parent, name, data):
		if not type(data) == binaryninja.binaryview.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)

		layout = QVBoxLayout()
		self.consoleText = QTextEdit(self)
		self.consoleText.setReadOnly(True)
		layout.addWidget(self.consoleText, 1)

		inputLayout = QHBoxLayout()
		inputLayout.setContentsMargins(4, 4, 4, 4)
		
		promptLayout = QVBoxLayout()
		promptLayout.setContentsMargins(0, 5, 0, 5)

		inputLayout.addLayout(promptLayout)

		self.consoleEntry = QLineEdit(self)
		inputLayout.addWidget(self.consoleEntry, 1)

		label = QLabel("lldb>>> ", self)
		label.setFont(getMonospaceFont(self))
		promptLayout.addWidget(label)
		promptLayout.addStretch(1)

		self.consoleEntry.returnPressed.connect(lambda: self.consoleText.append("TODO"))

		layout.addLayout(inputLayout)
		layout.setContentsMargins(0, 0, 0, 0)
		layout.setSpacing(0)
		self.setLayout(layout)

	def sizeHint(self):
		return QSize(300, 100)

	#--------------------------------------------------------------------------
	# callbacks to us api/ui/dockhandler.h
	#--------------------------------------------------------------------------
	def notifyOffsetChanged(self, offset):
		pass

	def notifyViewChanged(self, view_frame):
		pass

	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
Beispiel #10
0
    def __init__(self, parent, name, data):
        QWidget.__init__(self, parent)
        DockContextHandler.__init__(self, self, name)

        self.actionHandler = UIActionHandler()
        self.actionHandler.setupActionHandler(self)
        self.data = data
        self.parent = parent

        self.current_state = None
        self.arch = None
        self.address_start = None
        self.size = 512
        self.changes = set()
        self.tab_name = None

        self.symb_idx = 0

        self._layout = QVBoxLayout()
        self.button = QPushButton("Monitor Memory")
        self.button.clicked.connect(self.on_monitor_button_click)

        self.hexWidget = HexViewWidget(
            menu_handler=self.on_customContextMenuRequested)
        self.hexWidget.data_edited.connect(self._handle_data_edited)
        self.hexWidget.setEnabled(False)

        self._layout.addWidget(self.button)
        self._layout.addWidget(self.hexWidget)
        self._layout.setContentsMargins(0, 0, 0, 0)

        self.setMaximumWidth(self.hexWidget.optimal_width + 25)

        self.setLayout(self._layout)
Beispiel #11
0
    def __init__(self, parent, name, data):
        if not type(data) == binaryninja.binaryview.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 = DebugModulesListModel(self.table, data)
        self.table.setModel(self.model)

        self.item_delegate = DebugModulesItemDelegate(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()

        for i in range(len(self.model.columns)):
            self.table.setColumnWidth(
                i,
                self.item_delegate.sizeHint(
                    self.table.viewOptions(),
                    self.model.index(-1, i, QModelIndex())).width())

        update_layout = QHBoxLayout()
        update_layout.setContentsMargins(0, 0, 0, 0)

        update_label = QLabel("Data is Stale")
        update_button = QPushButton("Refresh")
        update_button.clicked.connect(lambda: self.refresh())

        update_layout.addWidget(update_label)
        update_layout.addStretch(1)
        update_layout.addWidget(update_button)

        self.update_box = QWidget()
        self.update_box.setLayout(update_layout)

        self.layout = QVBoxLayout()
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.layout.setSpacing(0)
        self.layout.addWidget(self.table)
        self.setLayout(self.layout)
Beispiel #12
0
        def __init__(self, parent, name):
            QtWidgets.QWidget.__init__(self, parent)
            DockContextHandler.__init__(self, self, name)

            self.actionHandler = UIActionHandler()
            self.actionHandler.setupActionHandler(self)

            self._active_view = None
            self._visible_for_view = collections.defaultdict(lambda: False)
Beispiel #13
0
    def __init__(self, parent, name, data):
        QtWidgets.QWidget.__init__(self, parent)
        DockContextHandler.__init__(self, self, name)

        self.actionHandler = UIActionHandler()
        self.actionHandler.setupActionHandler(self)

        self.HyaraBinaryNinja = HyaraBinaryNinja()
        self.setLayout(self.HyaraBinaryNinja.layout)
class HelloDockWidget(QWidget, DockContextHandler):
    def __init__(self, parent, name, data):
        global instance_id
        QWidget.__init__(self, parent)
        DockContextHandler.__init__(self, self, name)
        self.actionHandler = UIActionHandler()
        self.actionHandler.setupActionHandler(self)
        offset_layout = QHBoxLayout()
        offset_layout.addWidget(QLabel("Offset: "))
        self.offset = QLabel(hex(0))
        offset_layout.addWidget(self.offset)
        offset_layout.setAlignment(QtCore.Qt.AlignCenter)
        datatype_layout = QHBoxLayout()
        datatype_layout.addWidget(QLabel("Data Type: "))
        self.datatype = QLabel("")
        datatype_layout.addWidget(self.datatype)
        datatype_layout.setAlignment(QtCore.Qt.AlignCenter)
        layout = QVBoxLayout()
        title = QLabel(name, self)
        title.setAlignment(QtCore.Qt.AlignCenter)
        instance = QLabel("Instance: " + str(instance_id), self)
        instance.setAlignment(QtCore.Qt.AlignCenter)
        layout.addStretch()
        layout.addWidget(title)
        layout.addWidget(instance)
        layout.addLayout(datatype_layout)
        layout.addLayout(offset_layout)
        layout.addStretch()
        self.setLayout(layout)
        instance_id += 1
        self.data = data

    def notifyOffsetChanged(self, offset):
        self.offset.setText(hex(offset))

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

    def notifyViewChanged(self, view_frame):
        if view_frame is None:
            self.datatype.setText("None")
            self.data = None
        else:
            self.datatype.setText(view_frame.getCurrentView())
            view = view_frame.getCurrentViewInterface()
            self.data = view.getData()

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

    @staticmethod
    def create_widget(name, parent, data=None):
        return HelloDockWidget(parent, name, data)
Beispiel #15
0
class DebugBreakpointsWidget(QWidget, DockContextHandler):
	def __init__(self, parent, name, data):
		if not type(data) == binaryninja.binaryview.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()

		for i in range(len(self.model.columns)):
			self.table.setColumnWidth(i, self.item_delegate.sizeHint(self.table.viewOptions(), self.model.index(-1, i, QModelIndex())).width())
		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
Beispiel #16
0
	def __init__(self, parent, name, data):
		# Read the configuration
		settings = Settings()
		settings.register_group("ghinja", "Ghinja")
		settings.register_setting("ghinja.ghidra_install_path", """
				{
					"title" : "Ghidra Installation Path",
					"type" : "string",
					"default" : "",
					"description" : "Path to analyzeHeadless file in Ghidra installation dir."
				}
				""")
		if not os.path.exists(settings.get_string("ghinja.ghidra_install_path")):
			show_message_box("Path to Ghidra headless was not found!", "To allow the Ghinja plugin to work, you will be prompted to specify the path to the \"analyzeHeadless(.bat)\" file.", buttons=0, icon=2)
			settings.set_string("ghinja.ghidra_install_path",get_open_filename_input("Provide Path to Ghidra \"analyzeHeadless(.bat)\" file (Usually: <GHIDRA_INSTALL>/support/analyzeHeadless)").decode("utf-8"))
		
		self.rename_settings = Settings()
		self.rename_settings.register_group("ghinja_rename","Rename")
		self.rename_settings.register_setting("ghinja_rename.ghinja_rename_struct", """
				{
					"title" : "Ghidra Rename Struct",
					"type" : "string",
					"default" : "{}",
					"description" : "Settings to hold renames for variables."
				}
				""")

		global instance_id
		self.binja_renames = {} # {"function_name":[{"original":"new"})]}
		self.current_function = None
		self.current_offset = None
		self.decomp = None
		self.current_view = None
		self.function_output = None
		self.decompile_result_path = None
		self.decompile_offset_path = None
		self.decompiler_done = False
		self.function_args = []
		QWidget.__init__(self, parent)
		DockContextHandler.__init__(self, self, name)
		self.actionHandler = UIActionHandler()
		self.actionHandler.setupActionHandler(self)
		layout = QVBoxLayout()
		self.editor = QTextEdit(self)
		self.editor.setReadOnly(True)
		self.editor.installEventFilter(self)
		self.editor.setStyleSheet("QTextEdit { font-family: Consolas }")
		self.editor.setPlainText(" Click anywhere in the dock to start decompiler")
		self.editor.selectionChanged.connect(self.onSelect)
		highlighter = Highlighter(self.editor.document(),"",self.function_args)
		layout.addWidget(self.editor)
		layout.setAlignment(QtCore.Qt.AlignLeft)
		self.setLayout(layout)
		instance_id += 1
		self.data = data
Beispiel #17
0
    class DockableWidget(QtWidgets.QWidget, DockContextHandler):
        """
        A dockable Qt widget for Binary Ninja.
        """
        def __init__(self, parent, name):
            QtWidgets.QWidget.__init__(self, parent)
            DockContextHandler.__init__(self, self, name)

            self.actionHandler = UIActionHandler()
            self.actionHandler.setupActionHandler(self)

            self._active_view = None
            self._visible_for_view = collections.defaultdict(lambda: False)

        @property
        def visible(self):
            return self._visible_for_view[self._active_view]

        @visible.setter
        def visible(self, is_visible):
            self._visible_for_view[self._active_view] = is_visible

        def shouldBeVisible(self, view_frame):
            if not view_frame:
                return False

            if USING_PYSIDE6:
                import shiboken6 as shiboken
            else:
                import shiboken2 as shiboken

            vf_ptr = shiboken.getCppPointer(view_frame)[0]
            return self._visible_for_view[vf_ptr]

        def notifyVisibilityChanged(self, is_visible):
            self.visible = is_visible

        def notifyViewChanged(self, view_frame):
            if not view_frame:
                self._active_view = None
                return

            if USING_PYSIDE6:
                import shiboken6 as shiboken
            else:
                import shiboken2 as shiboken

            self._active_view = shiboken.getCppPointer(view_frame)[0]

            if self.visible:
                dock_handler = DockHandler.getActiveDockHandler()
                dock_handler.setVisible(self.m_name, True)
Beispiel #18
0
    def registerAllSnippets(self):
        for action in list(filter(lambda x: x.startswith("Snippet\\"), UIAction.getAllRegisteredActions())):
            UIActionHandler.globalActions().unbindAction(action)
            UIAction.unregisterAction(action)

        for snippet in includeWalk(snippetPath, ".py"):
            (snippetDescription, snippetKey, snippetCode) = loadSnippetFromFile(snippet)
            if not snippetDescription:
                actionText = "Snippet\\" + snippet
            else:
                actionText = "Snippet\\" + snippetDescription
            UIAction.registerAction(actionText, snippetKey)
            UIActionHandler.globalActions().bindAction(actionText, UIAction(makeSnippetFunction(snippetCode)))
Beispiel #19
0
    def _init_ui(self):
        # config dialog
        configure_binsync_id = "BinSync: Configure"
        UIAction.registerAction(configure_binsync_id)
        UIActionHandler.globalActions().bindAction(
            configure_binsync_id, UIAction(self._launch_config))
        Menu.mainMenu("Tools").addAction(configure_binsync_id, "BinSync")

        # control panel (per BV)
        dock_handler = DockHandler.getActiveDockHandler()
        dock_handler.addDockWidget(
            "BinSync: Control Panel", lambda n, p, d: create_widget(
                ControlPanelDockWidget, n, p, d, self.controllers),
            Qt.RightDockWidgetArea, Qt.Vertical, True)
Beispiel #20
0
    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()

        for i in range(len(self.model.columns)):
            self.table.setColumnWidth(
                i,
                self.item_delegate.sizeHint(
                    self.table.viewOptions(),
                    self.model.index(-1, i, QModelIndex())).width())
        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)
Beispiel #21
0
    def run(self):
        if self.context == None:
            log_warn("Cannot run snippets outside of the UI at this time.")
            return
        if self.snippetChanged():
            self.save()
        actionText = actionFromSnippet(self.currentFile, self.snippetDescription.text())
        UIActionHandler.globalActions().executeAction(actionText, self.context)

        log_debug("Saving snippet %s" % self.currentFile)
        outputSnippet = codecs.open(self.currentFile, "w", "utf-8")
        outputSnippet.write("#" + self.snippetDescription.text() + "\n")
        outputSnippet.write("#" + self.keySequenceEdit.keySequence().toString() + "\n")
        outputSnippet.write(self.edit.toPlainText())
        outputSnippet.close()
        self.registerAllSnippets()
Beispiel #22
0
    def __init__(self, parent):
        super(MiasmOptionsWidget, self).__init__(parent)
        self.statusBarWidget = parent

        self.setBackgroundRole(QPalette.Highlight)
        self.setForegroundRole(QPalette.WindowText)
        self.setText(" Options ▾ ")

        self.contextMenuManager = ContextMenuManager(self)

        self.menu = Menu()
        self.actionHandler = UIActionHandler()
        self.registerActions()
        self.addActions()
        self.bindActions()

        self.actionHandler.setChecked("IR graph", True)
Beispiel #23
0
	def __init__(self, parent):
		QLabel.__init__(self, parent)

		self.statusBarWidget = parent

		self.setBackgroundRole(QPalette.Highlight)
		self.setForegroundRole(QPalette.WindowText)
		self.setText(" Formats ▾ ")

		# see api/ui/menus.h
		self.contextMenuManager = ContextMenuManager(self)

		self.menu = Menu()
		self.actionHandler = UIActionHandler()
		self.registerActions()
		self.addActions()
		self.bindActions()
class HelloGlobalAreaWidget(GlobalAreaWidget):
	def __init__(self, name):
		global instance_id
		GlobalAreaWidget.__init__(self, name)
		self.actionHandler = UIActionHandler()
		self.actionHandler.setupActionHandler(self)
		offset_layout = QHBoxLayout()
		offset_layout.addWidget(QLabel("Offset: "))
		self.offset = QLabel(hex(0))
		offset_layout.addWidget(self.offset)
		offset_layout.setAlignment(QtCore.Qt.AlignCenter)
		datatype_layout = QHBoxLayout()
		datatype_layout.addWidget(QLabel("Data Type: "))
		self.datatype = QLabel("")
		datatype_layout.addWidget(self.datatype)
		datatype_layout.setAlignment(QtCore.Qt.AlignCenter)
		layout = QVBoxLayout()
		title = QLabel(name, self)
		title.setAlignment(QtCore.Qt.AlignCenter)
		instance = QLabel("Instance: " + str(instance_id), self)
		instance.setAlignment(QtCore.Qt.AlignCenter)
		layout.addStretch()
		layout.addWidget(title)
		layout.addWidget(instance)
		layout.addLayout(datatype_layout)
		layout.addLayout(offset_layout)
		layout.addStretch()
		self.setLayout(layout)
		instance_id += 1
		self.data = None

	def notifyOffsetChanged(self, offset):
		self.offset.setText(hex(offset))

	def notifyViewChanged(self, view_frame):
		if view_frame is None:
			self.datatype.setText("None")
			self.data = None
		else:
			self.datatype.setText(view_frame.getCurrentView())
			view = view_frame.getCurrentViewInterface()
			self.data = view.getData()

	def contextMenuEvent(self, event):
		self.m_contextMenuManager.show(self.m_menu, self.actionHandler)
Beispiel #25
0
    def __init__(self, parent, name, data, bnwidgets):
        QWidget.__init__(self, parent)
        DockContextHandler.__init__(self, self, name)

        self.actionHandler = UIActionHandler()
        self.actionHandler.setupActionHandler(self)
        self.data = data
        self.parent = parent
        self.bnwidgets = bnwidgets

        self.current_state = None
        self.arch = None
        self.address_start = None
        self.size = 512
        self.changes = set()
        self.tab_name = None

        self.monitor_history = list()

        self.symb_idx = 0

        self._layout = QGridLayout()
        self.button = QPushButton("Monitor Memory")
        self.button.setStyleSheet("margin-left: 10px;")
        self.button.clicked.connect(
            self._condom_async(self, self.on_monitor_button_click))
        self.back_button = QPushButton("Back")
        self.back_button.setStyleSheet("margin-right: 10px;")
        self.back_button.clicked.connect(
            self._condom_async(self, self.on_back_click))

        self.hexWidget = HexViewWidget(
            menu_handler=self.on_customContextMenuRequested)
        self.hexWidget.data_edited.connect(self._handle_data_edited)
        self.hexWidget.setEnabled(False)

        self._layout.addWidget(self.button, 0, 0, 1, 4)
        self._layout.addWidget(self.back_button, 0, 4, 1, 1)
        self._layout.addWidget(self.hexWidget, 1, 0, 1, 5)
        self._layout.setContentsMargins(0, 0, 0, 0)

        self.setMaximumWidth(self.hexWidget.optimal_width + 25)

        self.setLayout(self._layout)
Beispiel #26
0
    def __init__(self, context):
        super(TriageFilePicker, self).__init__()
        self.context = context
        self.actionHandler = UIActionHandler()
        self.actionHandler.setupActionHandler(self)
        self.contextMenu = Menu()
        self.contextMenuManager = ContextMenuManager(self)

        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)

        self.model = QFileSystemModel()
        self.model.setRootPath("")
        self.model.setFilter(QDir.AllEntries | QDir.Hidden | QDir.System)
        self.tree = QTreeView(self)
        self.tree.setModel(self.model)
        self.tree.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.tree.setColumnWidth(0, 500)
        layout.addWidget(self.tree, 1)

        self.setLayout(layout)

        self.tree.doubleClicked.connect(self.onDoubleClick)

        recentFile = QSettings().value("triage/recentFile",
                                       os.path.expanduser("~"))
        while len(recentFile) > 0:
            f = self.model.index(recentFile)
            if f.isValid():
                self.tree.scrollTo(f)
                self.tree.setExpanded(f, True)
                break
            parentDir = os.path.dirname(recentFile)
            if parentDir == recentFile:
                break
            recentFile = parentDir

        self.actionHandler.bindAction(
            "Open Selected Files",
            UIAction(lambda context: self.openSelectedFiles(),
                     lambda context: self.areFilesSelected()))
        self.contextMenu.addAction("Open Selected Files", "Open")
Beispiel #27
0
    def __init__(self, parent, name):
        QWidget.__init__(self, parent)
        DockContextHandler.__init__(self, self, name)
        self.actionHandler = UIActionHandler()
        self.actionHandler.setupActionHandler(self)

        font = getMonospaceFont(self)
        fm = QFontMetricsF(font)

        table_layout = QVBoxLayout()
        self.table = QTableView()
        self.table.setFont(font)
        self.table.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.table.verticalHeader().hide()
        self.table.verticalHeader().setSectionResizeMode(QHeaderView.Fixed)
        self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)

        # sorting
        self.table.setSortingEnabled(True)
        self.table.horizontalHeader().setSortIndicator(0, QtCore.Qt.AscendingOrder)

        data = []
        self.model = TableModel(data)
        self.table.setModel(self.model)
        table_layout.addWidget(self.table)

        layout = QVBoxLayout()
        layout.addLayout(table_layout)
        self.setLayout(layout)

        # init double click action
        self.table.doubleClicked.connect(self._ui_entry_double_click)
        # init right click menu
        self.ctx_menu = QMenu()
        self._action_patch = QAction("Invert Branch", None)
        self.ctx_menu.addAction(self._action_patch)
        self.setContextMenuPolicy(Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self._ui_table_ctx_menu_handler)

        self.bv = None
        self.filename = None
        self.do_sync = True
Beispiel #28
0
	def __init__(self, parent, name, data):
		if not type(data) == binaryninja.binaryview.BinaryView:
			raise Exception('expected widget data to be a BinaryView')

		self.bv = data

		memory_view = binjaplug.get_state(data).memory_view

		QWidget.__init__(self, parent)
		DockContextHandler.__init__(self, self, name)

		self.editor = LinearView(memory_view, ViewFrame.viewFrameForWidget(self))
		self.actionHandler = UIActionHandler()
		self.actionHandler.setupActionHandler(self)

		layout = QVBoxLayout()
		layout.setContentsMargins(0, 0, 0, 0)
		layout.setSpacing(0)
		layout.addWidget(self.editor)
		self.setLayout(layout)
Beispiel #29
0
class DebugMemoryWidget(QWidget, DockContextHandler):
    def __init__(self, parent, name, data):
        if not type(data) == binaryninja.binaryview.BinaryView:
            raise Exception('expected widget data to be a BinaryView')

        self.bv = data

        memory_view = binjaplug.get_state(data).memory_view

        QWidget.__init__(self, parent)
        DockContextHandler.__init__(self, self, name)

        self.editor = LinearView(memory_view,
                                 ViewFrame.viewFrameForWidget(self))
        self.actionHandler = UIActionHandler()
        self.actionHandler.setupActionHandler(self)

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

    def notifyOffsetChanged(self, offset):
        pass

    def notifyMemoryChanged(self):
        adapter = binjaplug.get_state(self.bv).adapter

        # Refresh the editor
        if adapter is None:
            self.editor.navigate(0)
            return

        self.editor.navigate(adapter.reg_read('rsp'))

    def shouldBeVisible(self, view_frame):
        if view_frame is None:
            return False
        else:
            return True
Beispiel #30
0
    def __init__(self, parent, name, data):
        if not type(data) == binaryninja.binaryview.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)

        layout = QVBoxLayout()
        self.consoleText = QTextEdit(self)
        self.consoleText.setReadOnly(True)
        self.consoleText.setFont(getMonospaceFont(self))
        layout.addWidget(self.consoleText, 1)

        inputLayout = QHBoxLayout()
        inputLayout.setContentsMargins(4, 4, 4, 4)

        promptLayout = QVBoxLayout()
        promptLayout.setContentsMargins(0, 5, 0, 5)

        inputLayout.addLayout(promptLayout)

        self.consoleEntry = QLineEdit(self)
        inputLayout.addWidget(self.consoleEntry, 1)

        label = QLabel("dbg>>> ", self)
        label.setFont(getMonospaceFont(self))
        promptLayout.addWidget(label)
        promptLayout.addStretch(1)

        self.consoleEntry.returnPressed.connect(lambda: self.sendLine())

        layout.addLayout(inputLayout)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        self.setLayout(layout)