Exemple #1
0
    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()
Exemple #2
0
    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)
Exemple #3
0
	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()
Exemple #4
0
    def __init__(self, parent, data):
        QScrollArea.__init__(self, parent)
        View.__init__(self)
        View.setBinaryDataNavigable(self, True)
        self.setupView(self)
        self.data = data
        self.currentOffset = 0
        self.byteView = None
        self.fullAnalysisButton = None
        self.importsWidget = None

        container = QWidget(self)
        layout = QVBoxLayout()

        entropyGroup = QGroupBox("Entropy", container)
        entropyLayout = QVBoxLayout()
        entropyLayout.addWidget(
            entropy.EntropyWidget(entropyGroup, self, self.data))
        entropyGroup.setLayout(entropyLayout)
        layout.addWidget(entropyGroup)

        hdr = None
        try:
            if self.data.view_type == "PE":
                hdr = headers.PEHeaders(self.data)
            elif self.data.view_type != "Raw":
                hdr = headers.GenericHeaders(self.data)
        except:
            log.log_error(traceback.format_exc())

        if hdr is not None:
            headerGroup = QGroupBox("Headers", container)
            headerLayout = QVBoxLayout()
            headerWidget = headers.HeaderWidget(headerGroup, hdr)
            headerLayout.addWidget(headerWidget)
            headerGroup.setLayout(headerLayout)
            layout.addWidget(headerGroup)

        if self.data.executable:
            importExportSplitter = QSplitter(Qt.Horizontal)

            importGroup = QGroupBox("Imports", container)
            importLayout = QVBoxLayout()
            self.importsWidget = imports.ImportsWidget(importGroup, self,
                                                       self.data)
            importLayout.addWidget(self.importsWidget)
            importGroup.setLayout(importLayout)
            importExportSplitter.addWidget(importGroup)

            exportGroup = QGroupBox("Exports", container)
            exportLayout = QVBoxLayout()
            exportLayout.addWidget(
                exports.ExportsWidget(exportGroup, self, self.data))
            exportGroup.setLayout(exportLayout)
            importExportSplitter.addWidget(exportGroup)

            layout.addWidget(importExportSplitter)

            if self.data.view_type != "PE":
                segmentsGroup = QGroupBox("Segments", container)
                segmentsLayout = QVBoxLayout()
                segmentsWidget = sections.SegmentsWidget(
                    segmentsGroup, self.data)
                segmentsLayout.addWidget(segmentsWidget)
                segmentsGroup.setLayout(segmentsLayout)
                layout.addWidget(segmentsGroup)
                if len(segmentsWidget.segments) == 0:
                    segmentsGroup.hide()

            sectionsGroup = QGroupBox("Sections", container)
            sectionsLayout = QVBoxLayout()
            sectionsWidget = sections.SectionsWidget(sectionsGroup, self.data)
            sectionsLayout.addWidget(sectionsWidget)
            sectionsGroup.setLayout(sectionsLayout)
            layout.addWidget(sectionsGroup)
            if len(sectionsWidget.sections) == 0:
                sectionsGroup.hide()

            buttonLayout = QHBoxLayout()
            buttonLayout.addStretch(1)
            self.loadDynamicButton = QPushButton("Load Dynamic Imports")
            self.loadDynamicButton.clicked.connect(
                self.importsWidget.scanDynamic)
            buttonLayout.addWidget(self.loadDynamicButton)
            self.fullAnalysisButton = QPushButton("Start Full Analysis")
            self.fullAnalysisButton.clicked.connect(self.startFullAnalysis)
            buttonLayout.addWidget(self.fullAnalysisButton)
            layout.addLayout(buttonLayout)
            layout.addStretch(1)
        else:
            self.byteView = byte.ByteView(self, self.data)
            layout.addWidget(self.byteView, 1)

        container.setLayout(layout)
        self.setWidgetResizable(True)
        self.setWidget(container)

        if self.fullAnalysisButton is not None and Settings().get_string(
                "analysis.mode", data) == "full":
            self.fullAnalysisButton.hide()
Exemple #5
0
    def __init__(self, parent, data):
        QAbstractScrollArea.__init__(self, parent)
        View.__init__(self)
        View.setBinaryDataNavigable(self, True)
        self.setupView(self)
        self.data = data
        self.byte_mapping = [
            u' ', u'☺', u'☻', u'♥', u'♦', u'♣', u'♠', u'•', u'◘', u'○', u'◙',
            u'♂', u'♀', u'♪', u'♫', u'☼', u'▸', u'◂', u'↕', u'‼', u'¶', u'§',
            u'▬', u'↨', u'↑', u'↓', u'→', u'←', u'∟', u'↔', u'▴', u'▾', u' ',
            u'!', u'"', u'#', u'$', u'%', u'&', u'\'', u'(', u')', u'*', u'+',
            u',', u'-', u'.', u'/', u'0', u'1', u'2', u'3', u'4', u'5', u'6',
            u'7', u'8', u'9', u':', u';', u'<', u'=', u'>', u'?', u'@', u'A',
            u'B', u'C', u'D', u'E', u'F', u'G', u'H', u'I', u'J', u'K', u'L',
            u'M', u'N', u'O', u'P', u'Q', u'R', u'S', u'T', u'U', u'V', u'W',
            u'X', u'Y', u'Z', u'[', u'\\', u']', u'^', u'_', u'`', u'a', u'b',
            u'c', u'd', u'e', u'f', u'g', u'h', u'i', u'j', u'k', u'l', u'm',
            u'n', u'o', u'p', u'q', u'r', u's', u't', u'u', u'v', u'w', u'x',
            u'y', u'z', u'{', u'|', u'}', u'~', u'⌂', u'Ç', u'ü', u'é', u'â',
            u'ä', u'à', u'å', u'ç', u'ê', u'ë', u'è', u'ï', u'î', u'ì', u'Ä',
            u'Å', u'É', u'æ', u'Æ', u'ô', u'ö', u'ò', u'û', u'ù', u'ÿ', u'Ö',
            u'Ü', u'¢', u'£', u'¥', u'₧', u'ƒ', u'á', u'í', u'ó', u'ú', u'ñ',
            u'Ñ', u'ª', u'º', u'¿', u'⌐', u'¬', u'½', u'¼', u'¡', u'«', u'»',
            u'░', u'▒', u'▓', u'│', u'┤', u'╡', u'╢', u'╖', u'╕', u'╣', u'║',
            u'╗', u'╝', u'╜', u'╛', u'┐', u'└', u'┴', u'┬', u'├', u'─', u'┼',
            u'╞', u'╟', u'╚', u'╔', u'╩', u'╦', u'╠', u'═', u'╬', u'╧', u'╨',
            u'╤', u'╥', u'╙', u'╘', u'╒', u'╓', u'╫', u'╪', u'┘', u'┌', u'█',
            u'▄', u'▌', u'▐', u'▀', u'α', u'ß', u'Γ', u'π', u'Σ', u'σ', u'µ',
            u'τ', u'Φ', u'Θ', u'Ω', u'δ', u'∞', u'φ', u'ε', u'∩', u'≡', u'±',
            u'≥', u'≤', u'⌠', u'⌡', u'÷', u'≈', u'°', u'∙', u'·', u'√', u'ⁿ',
            u'²', u'■', u' '
        ]

        if sys.version_info.major == 2:
            mapping = {}
            for i in range(0, 256):
                mapping[chr(i)] = self.byte_mapping[i]
            self.byte_mapping = mapping

        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        self.setFocusPolicy(Qt.StrongFocus)

        self.cursorAddr = self.data.start
        self.prevCursorAddr = self.cursorAddr
        self.selectionStartAddr = self.cursorAddr
        self.topAddr = self.cursorAddr
        self.topLine = 0
        self.selectionVisible = False
        self.caretVisible = False
        self.caretBlink = True
        self.leftButtonDown = False
        self.cols = 128
        self.updatesRequired = False
        self.visibleRows = 1
        self.lines = []

        self.updateRanges()

        areaSize = self.viewport().size()
        self.adjustSize(areaSize.width(), areaSize.height())

        if self.allocatedLength > 0x7fffffff:
            self.scrollBarMultiplier = (self.allocatedLength // 0x7fffffff) + 1
        else:
            self.scrollBarMultiplier = 1
        self.wheelDelta = 0
        self.updatingScrollBar = False
        self.verticalScrollBar().setRange(0, (self.allocatedLength - 1) //
                                          self.scrollBarMultiplier)
        self.verticalScrollBar().sliderMoved.connect(self.scrollBarMoved)
        self.verticalScrollBar().actionTriggered.connect(self.scrollBarAction)

        self.cursorTimer = QTimer(self)
        self.cursorTimer.setInterval(500)
        self.cursorTimer.setSingleShot(False)
        self.cursorTimer.timeout.connect(self.cursorTimerEvent)
        self.cursorTimer.start()

        self.updateTimer = QTimer(self)
        self.updateTimer.setInterval(200)
        self.updateTimer.setSingleShot(False)
        #self.updateTimer.timeout.connect(self.updateTimerEvent)

        self.actionHandler().bindAction("Move Cursor Up",
                                        UIAction(lambda ctxt: self.up(False)))
        self.actionHandler().bindAction(
            "Move Cursor Down", UIAction(lambda ctxt: self.down(False)))
        self.actionHandler().bindAction(
            "Move Cursor Left", UIAction(lambda ctxt: self.left(1, False)))
        self.actionHandler().bindAction(
            "Move Cursor Right", UIAction(lambda ctxt: self.right(1, False)))
        self.actionHandler().bindAction(
            "Move Cursor Word Left",
            UIAction(lambda ctxt: self.left(8, False)))
        self.actionHandler().bindAction(
            "Move Cursor Word Right",
            UIAction(lambda ctxt: self.right(8, False)))
        self.actionHandler().bindAction("Extend Selection Up",
                                        UIAction(lambda ctxt: self.up(True)))
        self.actionHandler().bindAction("Extend Selection Down",
                                        UIAction(lambda ctxt: self.down(True)))
        self.actionHandler().bindAction(
            "Extend Selection Left", UIAction(lambda ctxt: self.left(1, True)))
        self.actionHandler().bindAction(
            "Extend Selection Right",
            UIAction(lambda ctxt: self.right(1, True)))
        self.actionHandler().bindAction(
            "Extend Selection Word Left",
            UIAction(lambda ctxt: self.left(8, True)))
        self.actionHandler().bindAction(
            "Extend Selection Word Right",
            UIAction(lambda ctxt: self.right(8, True)))
        self.actionHandler().bindAction(
            "Page Up", UIAction(lambda ctxt: self.pageUp(False)))
        self.actionHandler().bindAction(
            "Page Down", UIAction(lambda ctxt: self.pageDown(False)))
        self.actionHandler().bindAction(
            "Extend Selection Page Up",
            UIAction(lambda ctxt: self.pageUp(True)))
        self.actionHandler().bindAction(
            "Extend Selection Page Down",
            UIAction(lambda ctxt: self.pageDown(True)))
        self.actionHandler().bindAction(
            "Move Cursor to Start of Line",
            UIAction(lambda ctxt: self.moveToStartOfLine(False)))
        self.actionHandler().bindAction(
            "Move Cursor to End of Line",
            UIAction(lambda ctxt: self.moveToEndOfLine(False)))
        self.actionHandler().bindAction(
            "Move Cursor to Start of View",
            UIAction(lambda ctxt: self.moveToStartOfView(False)))
        self.actionHandler().bindAction(
            "Move Cursor to End of View",
            UIAction(lambda ctxt: self.moveToEndOfView(False)))
        self.actionHandler().bindAction(
            "Extend Selection to Start of Line",
            UIAction(lambda ctxt: self.moveToStartOfLine(True)))
        self.actionHandler().bindAction(
            "Extend Selection to End of Line",
            UIAction(lambda ctxt: self.moveToEndOfLine(True)))
        self.actionHandler().bindAction(
            "Extend Selection to Start of View",
            UIAction(lambda ctxt: self.moveToStartOfView(True)))
        self.actionHandler().bindAction(
            "Extend Selection to End of View",
            UIAction(lambda ctxt: self.moveToEndOfView(True)))
Exemple #6
0
    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)")