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)
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")
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, )
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
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()
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)
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)
def openDockWidget(): dock_handler = DockHandler.getActiveDockHandler() dock_handler.addDockWidget( "JMPscare Overview", JumpOverview.create_widget, Qt.RightDockWidgetArea, Qt.Vertical, True, )
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)
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
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)
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'])
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)
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)
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)
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
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)
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)
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)
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
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)
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)
def switch_view(): dh = DockHandler.getActiveDockHandler() vf = dh.getViewFrame() vf.setViewType('Debugger:' + bv.view_type)
def trigger_action(self, action: str): handler = UIActionHandler().actionHandlerFromWidget( DockHandler.getActiveDockHandler().parent()) handler.executeAction(action)
def addDynamicDockWidget(): dock_handler = DockHandler.getActiveDockHandler() dock_handler.addDockWidget("HelloDockWidget (Dynamic Dock)", HelloDockWidget.create_widget, Qt.BottomDockWidgetArea, Qt.Horizontal, True)
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)
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, )
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)