Ejemplo n.º 1
0
def addStaticDockWidget():
    dock_handler = DockHandler.getActiveDockHandler()
    parent = dock_handler.parent()
    dock_widget = HelloDockWidget.create_widget(
        "HelloDockWidget (Static Dock)", parent)
    dock_handler.addDockWidget(dock_widget, Qt.BottomDockWidgetArea,
                               Qt.Horizontal, True, False)
Ejemplo n.º 2
0
    def run(self):
        with open(self.file, "r") as f:
            data = []
            for l in f:
                args = l.split(" ")
                data.append(args)
                addr = int(args[0], 16)
                if "ALWAYS" in args[2]:
                    for func in self.bv.get_functions_containing(addr):
                        func.set_auto_instr_highlight(addr, colors["green"])
                else:
                    for func in self.bv.get_functions_containing(addr):
                        func.set_auto_instr_highlight(addr, colors["red"])

        for x in data:
            x[1] = x[1][10:]
            x[2] = x[2][:-6]
            x[3] = int(x[3])

        dock_handler = DockHandler.getActiveDockHandler()
        table = dock_handler.getDockWidget("JMPscare Overview").widget()

        table.model = TableModel(table.model._data + data)
        table.table.setModel(table.model)

        log.log(1, "[JMPscare] Successfully imported analysis data")
Ejemplo n.º 3
0
def register_widget(
    widget_class: Any,
    name: str,
    area: Qt.DockWidgetArea,
    orientation: Qt.Orientation,
    default_visibility: bool,
):
    """
    Register a dock widget.

    :param widget_class: the class of the widget to instantiate
    :param name: the name for the widget (will appear in menus)
    :param area: where the widget should be docker
    :param orientation: the orientation of the widget
    :param default_visibility: whether the widget be visible by default
    """

    dock_handler = DockHandler.getActiveDockHandler()
    dock_handler.addDockWidget(
        name,
        lambda n, p, d: _create_widget(widget_class, n, p, d),
        area,
        orientation,
        default_visibility,
    )
Ejemplo n.º 4
0
def setupGlobals(context):
    snippetGlobals = {}
    if context.binaryView == None:
        dock = DockHandler.getActiveDockHandler()
        if not dock:
            return snippetGlobals
        viewFrame = dock.getViewFrame()
        if not viewFrame:
            return snippetGlobals
        viewInterface = viewFrame.getCurrentViewInterface()
        context.binaryView = viewInterface.getData()
    snippetGlobals['current_view'] = context.binaryView
    snippetGlobals['bv'] = context.binaryView
    if not context.function:
        if not context.lowLevelILFunction:
            if not context.mediumLevelILFunction:
                snippetGlobals['current_hlil'] = None
                snippetGlobals['current_mlil'] = None
                snippetGlobals['current_function'] = None
                snippetGlobals['current_llil'] = None
            else:
                snippetGlobals['current_mlil'] = context.mediumLevelILFunction
                snippetGlobals[
                    'current_function'] = context.mediumLevelILFunction.source_function
                snippetGlobals[
                    'current_llil'] = context.mediumLevelILFunction.source_function.llil
                snippetGlobals[
                    'current_hlil'] = context.mediumLevelILFunction.source_function.hlil
        else:
            snippetGlobals['current_llil'] = context.lowLevelILFunction
            snippetGlobals[
                'current_function'] = context.lowLevelILFunction.source_function
            snippetGlobals[
                'current_mlil'] = context.lowLevelILFunction.source_function.mlil
            snippetGlobals[
                'current_hlil'] = context.lowLevelILFunction.source_function.hlil
    else:
        snippetGlobals['current_function'] = context.function
        snippetGlobals['current_mlil'] = context.function.mlil
        snippetGlobals['current_hlil'] = context.function.hlil
        snippetGlobals['current_llil'] = context.function.llil
        snippetGlobals['current_token'] = context.function.llil

    if context.function is not None:
        snippetGlobals[
            'current_basic_block'] = context.function.get_basic_block_at(
                context.address)
    else:
        snippetGlobals['current_basic_block'] = None
    snippetGlobals['current_address'] = context.address
    snippetGlobals['here'] = context.address
    if context.address is not None and isinstance(context.length,
                                                  numbers.Integral):
        snippetGlobals['current_selection'] = (context.address,
                                               context.address +
                                               context.length)
    else:
        snippetGlobals['current_selection'] = None
    snippetGlobals['uicontext'] = context
    return snippetGlobals
Ejemplo n.º 5
0
    def run(self):
        asyncio.set_event_loop(self.loop)
        self.rpc.connect()

        dock_handler = DockHandler.getActiveDockHandler()

        start = None
        while self.active:
            view_frame = dock_handler.getViewFrame()

            if view_frame:
                name = view_frame.getShortFileName()

                if not start:
                    start = int(time.time())

                self.rpc.update(large_image="bn-logo-round", large_text="Binary Ninja",
                                small_image="bn-logo-round", small_text="Binary Ninja",
                                start=start, details=f"{name}")

            else:
                start = None
                self.rpc.clear()

            time.sleep(5)

        self.rpc.close()
Ejemplo n.º 6
0
def _registerDynamicWidgets():
    dock_handler = DockHandler.getActiveDockHandler()
    dock_handler.addDockWidget("SENinja Registers", _get_registerview_widget,
                               Qt.RightDockWidgetArea, Qt.Vertical, False)
    dock_handler.addDockWidget("SENinja Memory", _get_memoryview_widget,
                               Qt.BottomDockWidgetArea, Qt.Horizontal, False)
    dock_handler.addDockWidget("SENinja Buffers", _get_buffer_view_widget,
                               Qt.RightDockWidgetArea, Qt.Vertical, False)
Ejemplo n.º 7
0
def register_dockwidget(widget_class, name, area, orientation,
                        default_visibility, *args):
    dock_handler = DockHandler.getActiveDockHandler()

    # create main debugger controls
    dock_handler.addDockWidget(
        name, lambda n, p, d: create_widget(widget_class, n, p, d, *args),
        area, orientation, default_visibility)
Ejemplo n.º 8
0
def openDockWidget():
    dock_handler = DockHandler.getActiveDockHandler()
    dock_handler.addDockWidget(
        "JMPscare Overview",
        JumpOverview.create_widget,
        Qt.RightDockWidgetArea,
        Qt.Vertical,
        True,
    )
Ejemplo n.º 9
0
def register_dockwidget(widget_class,
                        name,
                        area=Qt.BottomDockWidgetArea,
                        orientation=Qt.Horizontal,
                        default_visibility=True,
                        *args):
    dock_handler = DockHandler.getActiveDockHandler()
    dock_handler.addDockWidget(
        name, lambda n, p, d: _create_widget(widget_class, n, p, d, *args),
        area, orientation, default_visibility)
Ejemplo n.º 10
0
def binja_get_bv_from_dock():
    dh = DockHandler.getActiveDockHandler()
    if not dh:
        return None
    vf = dh.getViewFrame()
    if not vf:
        return None
    vi = vf.getCurrentViewInterface()
    bv = vi.getData()
    return bv
Ejemplo n.º 11
0
        def notifyViewChanged(self, view_frame):
            if not view_frame:
                self._active_view = None
                return

            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)
Ejemplo n.º 12
0
def executeSnippet(code, context):
    snippetGlobals = {}
    if context.binaryView == None:
        dock = DockHandler.getActiveDockHandler()
        if not dock:
            log_error("Snippet triggered with no context and no dock handler. This should not happen. Please report reproduction steps if possible.")
            return
        viewFrame = dock.getViewFrame()
        if not viewFrame:
            log_error("Snippet triggered with no context and no view frame. Snippets require at least one open binary.")
            return
        viewInterface = viewFrame.getCurrentViewInterface()
        context.binaryView = viewInterface.getData()
    snippetGlobals['current_view'] = context.binaryView
    snippetGlobals['bv'] = context.binaryView
    if not context.function:
        if not context.lowLevelILFunction:
            if not context.mediumLevelILFunction:
                snippetGlobals['current_mlil'] = None
                snippetGlobals['current_function'] = None
                snippetGlobals['current_llil'] = None
            else:
                snippetGlobals['current_mlil'] = context.mediumLevelILFunction
                snippetGlobals['current_function'] = context.mediumLevelILFunction.source_function
                snippetGlobals['current_llil'] = context.mediumLevelILFunction.source_function.llil
        else:
            snippetGlobals['current_llil'] = context.lowLevelILFunction
            snippetGlobals['current_function'] = context.lowLevelILFunction.source_function
            snippetGlobals['current_mlil'] = context.lowLevelILFunction.source_function.mlil
    else:
        snippetGlobals['current_function'] = context.function
        snippetGlobals['current_mlil'] = context.function.mlil
        snippetGlobals['current_llil'] = context.function.llil
        snippetGlobals['current_token'] = context.function.llil

    if context.function is not None:
        snippetGlobals['current_basic_block'] = context.function.get_basic_block_at(context.address)
    else:
        snippetGlobals['current_basic_block'] = None
    snippetGlobals['current_address'] = context.address
    snippetGlobals['here'] = context.address
    if context.address is not None and isinstance(context.length, numbers.Integral):
        snippetGlobals['current_selection'] = (context.address, context.address+context.length)
    else:
        snippetGlobals['current_selection'] = None
    snippetGlobals['uicontext'] = context

    exec("from binaryninja import *", snippetGlobals)
    exec(code, snippetGlobals)
    if snippetGlobals['here'] != context.address:
        context.binaryView.file.navigate(context.binaryView.file.view, snippetGlobals['here'])
    if snippetGlobals['current_address'] != context.address:
        context.binaryView.file.navigate(context.binaryView.file.view, snippetGlobals['current_address'])
Ejemplo n.º 13
0
def ui_set_arch(arch, state):
    assert BNWidgets.RW is not None
    assert BNWidgets.MW is not None
    assert BNWidgets.BW is not None

    BNWidgets.RW.init(arch, state)
    BNWidgets.MW.init(arch, state)
    BNWidgets.BW.init(state)

    dock_handler = DockHandler.getActiveDockHandler()
    dock_handler.setVisible("SENinja Registers", True)
    dock_handler.setVisible("SENinja Memory", True)
    dock_handler.setVisible("SENinja Buffers", True)
Ejemplo n.º 14
0
def ui_reset_view():
    assert BNWidgets.RW is not None
    assert BNWidgets.MW is not None
    assert BNWidgets.BW is not None

    BNWidgets.RW.reset()
    BNWidgets.MW.reset()
    BNWidgets.BW.reset()

    dock_handler = DockHandler.getActiveDockHandler()
    dock_handler.setVisible("SENinja Registers", False)
    dock_handler.setVisible("SENinja Memory", False)
    dock_handler.setVisible("SENinja Buffers", False)
Ejemplo n.º 15
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)
Ejemplo n.º 16
0
    def list_dyn(self):
        self.opened = {}
        dock = DockHandler.getActiveDockHandler()
        view_frame = dock.getViewFrame()

        if view_frame:
            frames = view_frame.parent()
            for i in range(frames.count()):
                widget = frames.widget(i)
                vf = ViewFrame.viewFrameForWidget(widget)
                if vf:
                    file_name = vf.getFileContext().getFilename
                    self.add(file_name)

        return self.opened
Ejemplo n.º 17
0
    def __init__(self, parent, name, view):
        try:
            QWidget.__init__(self, parent)
            DockContextHandler.__init__(self, self, name)

            view.session_data['emulator.memory.dockWidget'] = self

            self.view = view

            self.layout = QHBoxLayout(self)

            dock_handler = DockHandler.getActiveDockHandler()
            dock_handler.setVisible('Emulator Memory View', False)

        except Exception as e:
            print(e)
Ejemplo n.º 18
0
def get_active_view_image(scale: float) -> QPixmap:
    """
    Get an image of the currently active linear/graph view. Will raise a
    ValueError if the active view could not be found.

    :param scale: the DPI-scaling factor to render the image at
    """

    dh = DockHandler.getActiveDockHandler()

    # Get the current ViewFrame and the underlying widget
    vf = dh.getViewFrame()
    view = vf.getCurrentWidget()

    if view is None:
        raise ValueError("Could not find active view.")

    return get_widget_image(view, scale)
    def __init__(self, parent, name, view):
        try:
            QWidget.__init__(self, parent)
            DockContextHandler.__init__(self, self, name)

            layout = QGridLayout(self)
            self.registers_label = QLabel(None)
            self.registers_label.setText('Registers')
            self.registers_view = RegisterEmulatorView(None, view)

            self.memory_label = QLabel(None)
            self.memory_label.setText('Memory Map')
            self.memory_view = EmulatorMemoryView(None, view)

            self.stack_label = QLabel(None)
            self.stack_label.setText('Stack View')
            self.stack_view = EmulatorStackView(None, view)

            # TODO
            # Implement a view that shows the top 0x100 bytes of the stack
            # OR....OR...let's make a "local variables" view

            self.button_widget = EmulatorButtonsWidget(self, view)

            layout.addWidget(self.button_widget, 0, 0, Qt.AlignLeft)
            layout.addWidget(self.memory_label, 1, 0)
            layout.addWidget(self.memory_view, 2, 0)

            layout.addWidget(self.registers_label, 1, 1)
            layout.addWidget(self.registers_view, 2, 1)

            layout.addWidget(self.stack_label, 1, 2)
            layout.addWidget(self.stack_view, 2, 2)

            self.registers_view.horizontalHeader().setStretchLastSection(True)

            self.view = view
            self.view_frame = None
            self.emulator = BinaryNinjaEmulator(view, self)

            dock_handler = DockHandler.getActiveDockHandler()
            dock_handler.setVisible('BNIL Emulator', False)
        except Exception as e:
            print(e)
Ejemplo n.º 20
0
def worker(bv):
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.bind(('127.0.0.1', 31337))

    while True:
        print('udp_nav: calling sock.recvfrom()')
        data, addr = sock.recvfrom(1024)
        print("udp_nav: received ", data)

        try:
            data = data.decode('utf-8')
            address = int(data, 16)
        except Exception:
            continue

        dh = DockHandler.getActiveDockHandler()
        vf = dh.getViewFrame()
        cv = vf.getCurrentView()
        print('udp_nav: bv.navigate(\'%s\', 0x%X)' % (cv, address))
        bv.navigate(cv, address)
Ejemplo n.º 21
0
def get_all_binaryviews():
    all_binaryviews = []
    dock = DockHandler.getActiveDockHandler()
    if not dock:
        log_error("No dock handler. This should not happen.")
        return
    viewFrame = dock.getViewFrame()
    if not viewFrame:
        log_error("No open binary")
        return
    stackedViewFrames = viewFrame.parent()  # QStackedWidget
    for i in range(stackedViewFrames.count()):
        viewFrame = stackedViewFrames.widget(i)
        if isinstance(viewFrame, binaryninjaui.ViewFrame):
            # New tab is not a ViewFrame
            viewInterface = viewFrame.getCurrentViewInterface()
            binaryview = viewInterface.getData()
            all_binaryviews.append(binaryview)

    return all_binaryviews
Ejemplo n.º 22
0
def load_emulator(view, il):
    emulator = view.session_data.get("emulator")
    if emulator is None:
        return

    dock_handler = DockHandler.getActiveDockHandler()
    if dock_handler is None:
        return

    view.session_data["emulator.memory.view"] = rewrite_segments(view)
    model = EmulatorMemoryModel(view)
    view.session_data["emulator.memory.model"] = model
    view.session_data["emulator.memory.widget"].setModel(model)

    model = EmulatorStackModel(view)
    view.session_data['emulator.stack.widget'].setModel(model)

    memory_dock_widget = view.session_data['emulator.memory.dockWidget']
    memory_dock_widget.linear_view = LinearView(
        view.session_data['emulator.memory.view'], None
    )
    memory_dock_widget.layout.addWidget(memory_dock_widget.linear_view)

    dock_handler.setVisible("BNIL Emulator", True)
Ejemplo n.º 23
0
 def init_widget(self):
     dock_handler = DockHandler.getActiveDockHandler()
     parent = dock_handler.parent()
     self.widget = SyncDockWidget.create_widget("ret-sync plugin", parent)
     dock_handler.addDockWidget(self.widget, Qt.BottomDockWidgetArea,
                                Qt.Horizontal, True, False)
Ejemplo n.º 24
0
 def switch_view():
     dh = DockHandler.getActiveDockHandler()
     vf = dh.getViewFrame()
     vf.setViewType('Debugger:' + bv.view_type)
Ejemplo n.º 25
0
 def trigger_action(self, action: str):
     handler = UIActionHandler().actionHandlerFromWidget(
         DockHandler.getActiveDockHandler().parent())
     handler.executeAction(action)
Ejemplo n.º 26
0
def addDynamicDockWidget():
    dock_handler = DockHandler.getActiveDockHandler()
    dock_handler.addDockWidget("HelloDockWidget (Dynamic Dock)",
                               HelloDockWidget.create_widget,
                               Qt.BottomDockWidgetArea, Qt.Horizontal, True)
Ejemplo n.º 27
0
def addStaticDockWidget():
	dock_handler = DockHandler.getActiveDockHandler()
	parent = dock_handler.parent()
	dock_widget = GhinjaDockWidget.create_widget("Ghinja Decompiler", parent)
	dock_handler.addDockWidget(dock_widget, Qt.TopDockWidgetArea, Qt.Horizontal, True, False)
Ejemplo n.º 28
0
        DockContextHandler.__init__(self, self, name)

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

        self.HyaraBinaryNinja = HyaraBinaryNinja()
        self.setLayout(self.HyaraBinaryNinja.layout)

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

    def notifyViewChanged(self, view_frame):
        pass

    @staticmethod
    def create_widget(name, parent, data=None):
        return HyaraDockWidget(parent, name, data)


dock_handler = DockHandler.getActiveDockHandler()
dock_handler.addDockWidget(
    "Hyara",
    HyaraDockWidget.create_widget,
    Qt.BottomDockWidgetArea,
    Qt.Horizontal,
    False,
)
Ejemplo n.º 29
0
 def navigate_to_addr(self, index):
     addr = int(self.model._data[index.row()][0], 16)
     dh = DockHandler.getActiveDockHandler()
     vf = dh.getViewFrame()
     vi = vf.getCurrentViewInterface()
     vi.navigate(addr)