def navigate_to_rip(self): if self.debug_view is not None: if not self.state.connected: rip = self.state.bv.entry_point else: rip = self.state.ip # select instruction currently at frame = ViewFrame.viewFrameForWidget(self.debug_view) frame.navigate(self.state.bv, rip, True, True)
def exportDoubleClicked(self, cur): sym = self.model.getSymbol(cur) if sym is not None: viewFrame = ViewFrame.viewFrameForWidget(self) if len(self.data.get_functions_at(sym.address)) > 0: viewFrame.navigate("Graph:" + viewFrame.getCurrentDataType(), sym.address) else: viewFrame.navigate("Linear:" + viewFrame.getCurrentDataType(), sym.address)
def navigateToFileOffset(self, offset): if self.byteView is None: addr = self.data.get_address_for_data_offset(offset) view_frame = ViewFrame.viewFrameForWidget(self) if view_frame is None: return if addr is None: view_frame.navigate("Hex:Raw", offset) else: view_frame.navigate("Linear:" + view_frame.getCurrentDataType(), addr) else: if self.data == self.data.file.raw: addr = offset else: addr = self.data.get_address_for_data_offset(offset) if addr is None: view_frame = ViewFrame.viewFrameForWidget(self) if view_frame is not None: view_frame.navigate("Hex:Raw", offset) else: self.byteView.navigate(addr) self.byteView.setFocus(Qt.OtherFocusReason)
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, binaryView): QScrollArea.__init__(self, parent) View.__init__(self) View.setBinaryDataNavigable(self, True) self.setupView(self) # BinaryViewType self.binaryView = binaryView self.rootSelectionStart = 0 self.rootSelectionEnd = 1 self.ioRoot = None self.ioCurrent = None # top half = treeWidget + structPath self.treeWidget = MyQTreeWidget() self.treeWidget.setColumnCount(4) self.treeWidget.setHeaderLabels(['label', 'value', 'start', 'end']) self.treeWidget.itemSelectionChanged.connect(self.onTreeSelect) self.structPath = QLineEdit("root") self.structPath.setReadOnly(True) topHalf = QWidget(self) layout = QVBoxLayout() layout.addWidget(self.treeWidget) layout.addWidget(self.structPath) topHalf.setLayout(layout) # bottom half = hexWidget self.hexWidget = HexEditor(binaryView, ViewFrame.viewFrameForWidget(self), 0) # splitter = top half, bottom half self.splitter = QSplitter(self) self.splitter.setOrientation(Qt.Vertical) self.splitter.addWidget(topHalf) self.splitter.addWidget(self.hexWidget) self.setWidgetResizable(True) self.setWidget(self.splitter) self.kaitaiParse()
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 __init__(self, parent, binaryView): QScrollArea.__init__(self, parent) View.__init__(self) View.setBinaryDataNavigable(self, True) self.setupView(self) # input and output, Y = ROT13(X) X = binaryView.read(0, len(binaryView)) Y = codecs.encode(X.decode('utf-8'), 'rot_13').encode('utf-8') # store original binary view (X) and our translated binary view (Y) self.binaryViewX = binaryView self.binaryViewY = binaryview.BinaryView.new(Y) self.setWidgetResizable(True) self.hexWidget = HexEditor(self.binaryViewY, ViewFrame.viewFrameForWidget(self), 0) self.setWidget(self.hexWidget) # capture writes to translated binary view notification = Rot13Notification(self.binaryViewX) self.binaryViewY.register_notification(notification)
def onTreeSelect(self, wtf=None): # get KaitaiTreeWidgetItem items = self.treeWidget.selectedItems() if not items or len(items) < 1: return item = items[0] # build path, inform user structPath = item.label itemTmp = item while itemTmp.parent(): itemTmp = itemTmp.parent() label = itemTmp.label if label.startswith('_m_'): label = label[3:] structPath = label + '.' + structPath self.structPath.setText('root.' + structPath) # (start, end) = (item.start, item.end) if start == None or end == None: return # determine current IO we're in (the Kaitai input/output abstraction) _io = None # if the tree item is linked to a KaitaiNode, simply read the IO if item.ksobj: _io = item.ksobj._parent._io else: # else we're a leaf parent = item.parent() if parent: # a leaf with a parent -> read parent's IO _io = parent.ksobj._io else: # a leaf without a parent -> we must be at root -> use root IO _io = self.ioRoot # if the selection is in the root view, store the interval so that upon # getCurrentOffset() callback, we return the middle and feature map is # updated if _io == self.ioRoot: self.rootSelectionStart = start self.rootSelectionEnd = end # current kaitai object is on a different io? then swap HexEditor if _io != self.ioCurrent: # delete old view self.hexWidget.hide() self.hexWidget.setParent(None) self.hexWidget.deleteLater() self.hexWidget = None # if it's the original file IO, wrap the already-open file binary view if _io == self.ioRoot: self.hexWidget = HexEditor(self.binaryView, ViewFrame.viewFrameForWidget(self), 0) # otherwise delete old view, create a temporary view else: # create new view length = _io.size() _io.seek(0) data = _io.read_bytes(length) bv = binaryview.BinaryView.new(data) self.hexWidget = HexEditor(bv, ViewFrame.viewFrameForWidget(self), 0) self.splitter.addWidget(self.hexWidget) self.ioCurrent = _io # now position selection in whatever HexEditor is current #log.log_debug('selecting to [0x%X, 0x%X)' % (start, end)) self.hexWidget.setSelectionRange(start, end)
def __init__(self, parent, data): if not type(data) == BinaryView: raise Exception('expected widget data to be a BinaryView') self.bv = data self.debug_state = binjaplug.get_state(data) memory_view = self.debug_state.memory_view self.debug_state.ui.debug_view = self QWidget.__init__(self, parent) self.controls = ControlsWidget.DebugControlsWidget(self, "Controls", data, self.debug_state) View.__init__(self) self.setupView(self) self.current_offset = 0 self.splitter = QSplitter(Qt.Orientation.Horizontal, self) frame = ViewFrame.viewFrameForWidget(self) self.memory_editor = LinearView(memory_view, frame) self.binary_editor = DisassemblyContainer(frame, data, frame) self.binary_text = TokenizedTextView(self, memory_view) self.is_raw_disassembly = False self.raw_address = 0 self.is_navigating_history = False self.memory_history_addr = 0 # TODO: Handle these and change views accordingly # Currently they are just disabled as the DisassemblyContainer gets confused # about where to go and just shows a bad view self.binary_editor.getDisassembly().actionHandler().bindAction("View in Hex Editor", UIAction()) self.binary_editor.getDisassembly().actionHandler().bindAction("View in Linear Disassembly", UIAction()) self.binary_editor.getDisassembly().actionHandler().bindAction("View in Types View", UIAction()) self.memory_editor.actionHandler().bindAction("View in Hex Editor", UIAction()) self.memory_editor.actionHandler().bindAction("View in Disassembly Graph", UIAction()) self.memory_editor.actionHandler().bindAction("View in Types View", UIAction()) small_font = QApplication.font() small_font.setPointSize(11) bv_layout = QVBoxLayout() bv_layout.setSpacing(0) bv_layout.setContentsMargins(0, 0, 0, 0) bv_label = QLabel("Loaded File") bv_label.setFont(small_font) bv_layout.addWidget(bv_label) bv_layout.addWidget(self.binary_editor) self.bv_widget = QWidget() self.bv_widget.setLayout(bv_layout) disasm_layout = QVBoxLayout() disasm_layout.setSpacing(0) disasm_layout.setContentsMargins(0, 0, 0, 0) disasm_label = QLabel("Raw Disassembly at PC") disasm_label.setFont(small_font) disasm_layout.addWidget(disasm_label) disasm_layout.addWidget(self.binary_text) self.disasm_widget = QWidget() self.disasm_widget.setLayout(disasm_layout) memory_layout = QVBoxLayout() memory_layout.setSpacing(0) memory_layout.setContentsMargins(0, 0, 0, 0) memory_label = QLabel("Debugged Process") memory_label.setFont(small_font) memory_layout.addWidget(memory_label) memory_layout.addWidget(self.memory_editor) self.memory_widget = QWidget() self.memory_widget.setLayout(memory_layout) self.splitter.addWidget(self.bv_widget) self.splitter.addWidget(self.memory_widget) # Equally sized self.splitter.setSizes([0x7fffffff, 0x7fffffff]) layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.addWidget(self.controls) layout.addWidget(self.splitter, 100) self.setLayout(layout) self.needs_update = True self.update_timer = QTimer(self) self.update_timer.setInterval(200) self.update_timer.setSingleShot(False) self.update_timer.timeout.connect(lambda: self.updateTimerEvent()) self.add_scripting_ref()
def clickEvent(self): viewFrame = ViewFrame.viewFrameForWidget(self) viewFrame.navigate("Graph:" + viewFrame.getCurrentDataType(), self.address)
def importDoubleClicked(self, cur): sym = self.model.getSymbol(cur) if sym is not None: viewFrame = ViewFrame.viewFrameForWidget(self) viewFrame.navigate("Linear:" + viewFrame.getCurrentDataType(), sym.address)
def __init__(self, parent, data): if not type(data) == binaryninja.binaryview.BinaryView: raise Exception('expected widget data to be a BinaryView') self.bv = data self.debug_state = binjaplug.get_state(data) memory_view = self.debug_state.memory_view self.debug_state.ui.debug_view = self QWidget.__init__(self, parent) View.__init__(self) self.setupView(self) self.current_offset = 0 self.splitter = QSplitter(Qt.Orientation.Horizontal, self) frame = ViewFrame.viewFrameForWidget(self) self.memory_editor = LinearView(memory_view, frame) self.binary_editor = DisassemblyContainer(frame, data, frame) self.binary_text = TokenizedTextView(self, memory_view) self.is_raw_disassembly = False # TODO: Handle these and change views accordingly # Currently they are just disabled as the DisassemblyContainer gets confused # about where to go and just shows a bad view self.binary_editor.getDisassembly().actionHandler().bindAction( "View in Hex Editor", UIAction()) self.binary_editor.getDisassembly().actionHandler().bindAction( "View in Linear Disassembly", UIAction()) self.binary_editor.getDisassembly().actionHandler().bindAction( "View in Types View", UIAction()) self.memory_editor.actionHandler().bindAction("View in Hex Editor", UIAction()) self.memory_editor.actionHandler().bindAction( "View in Disassembly Graph", UIAction()) self.memory_editor.actionHandler().bindAction("View in Types View", UIAction()) small_font = QApplication.font() small_font.setPointSize(11) bv_layout = QVBoxLayout() bv_layout.setSpacing(0) bv_layout.setContentsMargins(0, 0, 0, 0) bv_label = QLabel("Loaded File") bv_label.setFont(small_font) bv_layout.addWidget(bv_label) bv_layout.addWidget(self.binary_editor) self.bv_widget = QWidget() self.bv_widget.setLayout(bv_layout) disasm_layout = QVBoxLayout() disasm_layout.setSpacing(0) disasm_layout.setContentsMargins(0, 0, 0, 0) disasm_label = QLabel("Raw Disassembly at PC") disasm_label.setFont(small_font) disasm_layout.addWidget(disasm_label) disasm_layout.addWidget(self.binary_text) self.disasm_widget = QWidget() self.disasm_widget.setLayout(disasm_layout) memory_layout = QVBoxLayout() memory_layout.setSpacing(0) memory_layout.setContentsMargins(0, 0, 0, 0) memory_label = QLabel("Debugged Process") memory_label.setFont(small_font) memory_layout.addWidget(memory_label) memory_layout.addWidget(self.memory_editor) self.memory_widget = QWidget() self.memory_widget.setLayout(memory_layout) self.splitter.addWidget(self.bv_widget) self.splitter.addWidget(self.memory_widget) # Equally sized self.splitter.setSizes([0x7fffffff, 0x7fffffff]) self.controls = ControlsWidget.DebugControlsWidget( self, "Controls", data, self.debug_state) layout = QVBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) layout.addWidget(self.controls) layout.addWidget(self.splitter, 100) self.setLayout(layout) self.needs_update = True self.update_timer = QTimer(self) self.update_timer.setInterval(200) self.update_timer.setSingleShot(False) self.update_timer.timeout.connect(lambda: self.updateTimerEvent()) # Add debugger state to the interpreter as `dbg` main_window = parent.window() dock_handler = main_window.findChild(DockHandler, '__DockHandler') if dock_handler: console = dock_handler.getDockWidget('Python Console') if console: # Hack: Currently no way to access the scripting provider directly # So just run the commands through the ui console.widget().addInput( "import debugger\ndbg = debugger.get(bv)")