def _run_gui(): QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) QApplication.setOrganizationName("NiiFAQ") QApplication.setOrganizationDomain("niifaq.ru") app = QApplication(sys.argv) engine = QQmlApplicationEngine() model = _Model() handler = _LogHandler(model) logger = logging.getLogger() logger.addHandler(handler) logger.setLevel(logging.INFO) fixed_font = QFontDatabase.systemFont(QFontDatabase.FixedFont) root_context = engine.rootContext() root_context.setContextProperty("_fixedFont", fixed_font) root_context.setContextProperty("_model", model) engine.load(QUrl("qrc:/main.qml")) if len(engine.rootObjects()) == 0: return 1 signal.signal(signal.SIGINT, signal.SIG_DFL) try: sys.exit(app.exec_()) except KeyboardInterrupt: app.shutdown()
def __init__(self, parent): """ Args: parent (QWidget): Parent widget """ super().__init__(parent=parent) font = QFontDatabase.systemFont(QFontDatabase.FixedFont) self.setFont(font)
def _create_raw_widget(self, ) -> QWidget: widget = QPlainTextEdit(self) font = QFontDatabase.systemFont(QFontDatabase.FixedFont) font.setFixedPitch(True) metrics = QFontMetrics(font) widget.setFont(font) widget.setTabStopDistance(2 * metrics.width(' ')) as_signal_instance(widget.textChanged).connect(self._on_raw_changed, ) return widget
def __init__(self, log_format: str): logging.Handler.__init__(self) QTextEdit.__init__(self) self.setFormatter(logging.Formatter(log_format)) self.setReadOnly(True) self.setMinimumHeight(400) self.setMinimumWidth(600) font = QFontDatabase.systemFont(QFontDatabase.FixedFont) self.setFont(font)
def _build_ui(self): layout = QVBoxLayout() self.results = QTextBrowser() font = QFontDatabase.systemFont(QFontDatabase.FixedFont) self.results.setFont(font) layout.insertWidget(0, self.results, 1) self.ui_area.setLayout(layout) self.manage(None)
def paintEvent(self, event: QPaintEvent): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) # Draw background painter.setBrush(QBrush(self._bg_colors[self._state.mode])) painter.drawRect(event.rect()) # Draw digit font = QFontDatabase.systemFont(QFontDatabase.FixedFont) font.setPixelSize(int(self.width() * 6 / 7)) digit = str(self._state.digit) if self._state.digit != 0 else ' ' painter.setPen(self._fg_color) painter.setFont(font) flags = Qt.AlignCenter | Qt.TextJustificationForced painter.drawText(event.rect(), flags, digit)
def __init__(self): """ Init self with a log entry format (log_format). specifying which info to display and in what way, for example: '%(asctime)s - %(levelname)s - %(message)s'. :param log_format: Log entries format. """ QTextEdit.__init__(self) # QTextEdit self.setReadOnly(True) self.setMinimumHeight(400) self.setMinimumWidth(600) font = QFontDatabase.systemFont(QFontDatabase.FixedFont) self.setFont(font)
def modify_font(obj, bold=False, italic=False, underline=False, mono=False): if obj is None: return if mono: font = QFontDatabase.systemFont(QFontDatabase.FixedFont) else: if type(obj) is QTreeWidgetItem: font = obj.font(0) else: font = obj.font() font.setBold(bold) font.setItalic(italic) font.setUnderline(underline) if type(obj) is QTreeWidgetItem: obj.setFont(0, font) else: obj.setFont(font)
def _set_font(self): mono_font = QFontDatabase.systemFont(QFontDatabase.FixedFont) mono_font.setStyleStrategy(QFont.ForceIntegerMetrics) mono_font.setFixedPitch(True) mono_font.setPointSize(9) font_metrics = QFontMetrics(mono_font) self.font_width = font_metrics.width("M") self.setFont(mono_font) self.layout.setFont(mono_font) self.viewport().setFont(mono_font) self.line_height = self.fontMetrics().height() self.viewport().update()
def __init__(self): QMainWindow.__init__(self, parent=None) self.settings = QSettings(ORGANIZATION_STR) self.toolbar = self.createToolBar() self.widget = QWidget(self) self.layout = QVBoxLayout(self.widget) self.layout.setContentsMargins(1, 1, 1, 1) self.currentWidget = None self.editor = QTextEdit() self.editor.setAcceptRichText(False) font = QFontDatabase.systemFont(QFontDatabase.FixedFont) fs = int(self.settings.value("fontSize", 13)) font.setPointSize(fs) self.editor.setFont(font) self.preview = MarkdownRenderer() self.layout.addWidget(self.toolbar) self.widget.setLayout(self.layout) self.showWidget(self.editor) self.addToolBar(self.toolbar) self.setCentralWidget(self.widget) self.setWindowTitle(BASIC_TITLE) self.nbManager = NotebookManager() self.currentNotebook = None self.currentNote = None self.dirty = False self.editor.document().modificationChanged.connect(self.editorModified) self.updateUI() if len(self.nbManager.notebooks()) > 0: self.switchNotebook(self.nbManager.notebooks()[0].name) self.createTrayIcon() self.readConfig()
def __init__(self, text="", parent=None): super().__init__(parent) layout = QHBoxLayout(self) line_edit = QLineEdit(text) line_edit.setReadOnly(True) font = QFontDatabase.systemFont(QFontDatabase.FixedFont) line_edit.setFont(font) button = QToolButton() font = QFont('Font Awesome 5 Free Solid') button.setFont(font) button.setText("\uf0c5") button.setToolTip("Copy text") layout.addSpacing(20) layout.addWidget(line_edit) layout.addWidget(button) # pylint: disable=undefined-variable button.clicked.connect( lambda _=False, le=line_edit: qApp.clipboard().setText(le.text()))
def paintEvent(self, event: QPaintEvent): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) painter.eraseRect(event.rect()) painter.setBrush(QBrush(self._bg)) painter.drawRect(event.rect()) if self.mode == 'revealed': self.setFrameStyle(QFrame.Panel | QFrame.Plain) self.setLineWidth(0) self.setMidLineWidth(0) if self.content in self.content_colors.keys(): font = QFontDatabase.systemFont(QFontDatabase.FixedFont) font.setPixelSize(int(self.width() * 5 / 6)) painter.setPen(self.content_colors[self.content]) painter.setFont(font) flags = Qt.AlignCenter | Qt.TextJustificationForced painter.drawText(event.rect(), flags, self.content) if self.content == 'bomb': loc = 'exploded_bomb' if self.was_clicked_bomb else 'bomb' painter.drawImage(event.rect(), QImage(self.image_locations[loc])) if self.mode == 'hidden': self.setFrameStyle(QFrame.Panel | QFrame.Raised) self.setLineWidth(3) self.setMidLineWidth(2) if self.mode == 'false_bomb': painter.drawImage(event.rect(), QImage(self.image_locations['false_bomb'])) if self.mode == 'flag': self.setFrameStyle(QFrame.Panel | QFrame.Raised) self.setLineWidth(3) self.setMidLineWidth(2) painter.drawImage(event.rect(), QImage(self.image_locations['flag'])) super(CellWidget, self).paintEvent(event)
def __init__(self): super().__init__() self.window = Ui_MainWindow() self.window.setupUi(self) init_tree_view(self.window.treeWidget) init_tree_view(self.window.listWidget) self.setAcceptDrops(True) self.window.tabWidget.setCurrentIndex(0) default_font_size = self.window.treeWidget.font().pointSize() self.mono_space_font = QFontDatabase.systemFont( QFontDatabase.FixedFont) self.mono_space_font.setPointSize(default_font_size) self.tree_top_item = None self.window.treeWidget.itemDoubleClicked.connect( on_item_double_clicked) self.window.listWidget.header().sectionClicked.connect( self.section_clicked) self.list_dict = {} self.json_dict = {} self.total_time = 0
def _ui_setup(self): """Initialize user interface, and set color, size, alignment .etc.""" cmd_palette = QPalette() font = QFontDatabase.systemFont(QFontDatabase.FixedFont) cmd_palette.setColor(QPalette.Base, QtCore.Qt.black) cmd_palette.setColor(QPalette.Text, QtCore.Qt.green) self._serial_recv_box.setFont(font) self._serial_recv_box.setReadOnly(True) self._serial_recv_box.setPalette(cmd_palette) self._send_button.setEnabled(False) cmd_layout = QHBoxLayout() cmd_layout.addWidget(self._serial_send_box) cmd_layout.addWidget(self._send_button) self._main_layout = QVBoxLayout(self) self._main_layout.addWidget(self._title) self._main_layout.addWidget(self._serial_panel) self._main_layout.addWidget(self._serial_recv_box) self._main_layout.addLayout(cmd_layout) self.setLayout(self._main_layout)
def build_func_tree(self): """ Build the function target display tree """ self._func_tree.setSortingEnabled(False) self.model.clear() self.model.setHorizontalHeaderLabels([ "Function Name", "File", "File Offset", "Order Seen", "Calling Module", # "Return Address", "Targeting Mode", ]) self.model.horizontalHeaderItem(0).setToolTip( "The name of a fuzzable function") self.model.horizontalHeaderItem(1).setToolTip( "The name of the file (if any) the function tried to read") self.model.horizontalHeaderItem(2).setToolTip( "The bytes in the file that the program tried to read (if available)" ) self.model.horizontalHeaderItem(3).setToolTip( "The order in which the wizard encountered this function") self.model.horizontalHeaderItem(4).setToolTip( "Which part of the program called this function. .exe modules are generally the most promising" ) self.model.horizontalHeaderItem(5).setToolTip( "How we re-identify whether we're calling this function again") for index, option in enumerate(self.target_data): funcname_widget = CheckboxTreeWidgetItem( self._func_tree, index, "{func_name}".format(**option)) filename_widget = QStandardItem(option.get("source", None)) filename_widget.setEditable(False) offset_widget = QStandardItem( "0x{:x} - 0x{:x}".format(option["start"], option["end"]) if ( "end" in option and "start" in option) else None) offset_widget.setEditable(False) funcname_widget.setCheckState( Qt.Checked if option["selected"] else Qt.Unchecked) funcname_widget.setColumnCount(3) add = [] hx = [] asc = [] for address in range(0, min(len(option["buffer"]), 16 * 5), 16): add.append("0x%04X" % address) hx.append(" ".join("{:02X}".format(c) for c in option["buffer"][address:address + 16])) asc.append("".join( (chr(c) if c in range(31, 127) else ".") for c in option["buffer"][address:address + 16])) addr = QStandardItem("\n".join(add)) hexstr = QStandardItem("\n".join(hx)) asciistr = QStandardItem("\n".join(asc)) addr.setEditable(False) hexstr.setEditable(False) asciistr.setEditable(False) addr.setFont(QFontDatabase.systemFont(QFontDatabase.FixedFont)) hexstr.setFont(QFontDatabase.systemFont(QFontDatabase.FixedFont)) asciistr.setFont(QFontDatabase.systemFont(QFontDatabase.FixedFont)) funcname_widget.appendRow([addr, hexstr, asciistr]) idx_widget = QStandardItem(str(index)) idx_widget.setEditable(False) mod_widget = QStandardItem(str(option.get("called_from", None))) mod_widget.setEditable(False) addr_widget = QStandardItem(str(option.get("retAddrOffset", None))) addr_widget.setEditable(False) mode_widget = QStandardItem(mode_labels[option.get("mode")]) mode_widget.setData(option.get("mode"), role=Qt.UserRole) mode_widget.setData(index, role=Qt.UserRole + 1) mode_widget.setData(QBrush(QColor(0, 0, 0, 16)), role=Qt.BackgroundRole) self.model.appendRow([ funcname_widget, filename_widget, offset_widget, idx_widget, mod_widget, # addr_widget, mode_widget, ]) # self._func_tree.edit(self.model.indexFromItem(mode_widget)) self._func_tree.expandAll() self._func_tree.resizeColumnToContents(0) self._func_tree.resizeColumnToContents(1) self._func_tree.resizeColumnToContents(2) self._func_tree.resizeColumnToContents(3) self._func_tree.sortByColumn(3, Qt.AscendingOrder) self._func_tree.setSortingEnabled(True)
def __init__(self): QtWidgets.QMainWindow.__init__(self) self.crashes = [] self.thread_holder = [] self.paused_fuzzer_threads = [] self.start_time = None # Select config profile before starting self.cfg = ConfigWindow() if self.cfg.exec() == QtWidgets.QDialog.Rejected: sys.exit(1) # Set up basic window self.setWindowTitle("Sienna Locomotive 2") self.setMinimumSize(QSize(1800, 1300)) _central_widget = QtWidgets.QWidget(self) self.setCentralWidget(_central_widget) self._layout = QtWidgets.QVBoxLayout(_central_widget) _central_widget.setLayout(self._layout) # Set up Checksec, Wizard and Server threads so we don't block the UI # when they're running self.checksec_thread = ChecksecThread( config.config["target_application_path"]) self.wizard_thread = WizardThread(config.config) self.server_thread = ServerThread(close_on_exit=True) # CREATE WIDGETS # # Menu bar self.menu_bar = self.menuBar() self.file_menu = self.menu_bar.addMenu("&File") self.change_profile_action = self.file_menu.addAction("Change Profile") self.open_report_in_browser = QtWidgets.QAction( "Open exported report in browser", self, checkable=True) self.file_menu.addAction(self.open_report_in_browser) self.open_report_in_browser.setChecked(True) # Target info self.target_status = QtWidgets.QStatusBar() self.target_label = QtWidgets.QLabel() self.target_status.addWidget(self.target_label) self._layout.addWidget(self.target_status) self.checksec_thread.start() self.checksec_thread.result_ready.connect(self.checksec_finished) # Create wizard button self.wizard_button = QtWidgets.QPushButton("Run Wizard") self._layout.addWidget(self.wizard_button) # Set up function tree display self._func_tree = CheckboxTreeWidget() self._layout.addWidget(self._func_tree) # Set up underlying model for exposing function data self.target_data = get_target(config.config) self.model = CheckboxTreeModel() self.func_proxy_model = CheckboxTreeSortFilterProxyModel() self.func_proxy_model.setSourceModel(self.model) self.func_proxy_model.setFilterKeyColumn(0) self.file_proxy_model = CheckboxTreeSortFilterProxyModel() self.file_proxy_model.setSourceModel(self.func_proxy_model) self.file_proxy_model.setFilterKeyColumn(1) self.module_proxy_model = CheckboxTreeSortFilterProxyModel() self.module_proxy_model.setSourceModel(self.file_proxy_model) self.module_proxy_model.setFilterKeyColumn(4) self.build_func_tree() self._func_tree.setModel(self.module_proxy_model) self._func_tree.setItemDelegate( ComboboxTreeItemDelegate(self.target_data)) # These need to happen after we set the model self._func_tree.expandAll() self._func_tree.resizeColumnToContents(0) self._func_tree.resizeColumnToContents(1) self._func_tree.resizeColumnToContents(2) self._func_tree.resizeColumnToContents(3) # Create menu items for the context menu self.expand_action = QtWidgets.QAction("Expand All") self.collapse_action = QtWidgets.QAction("Collapse All") self.check_action = QtWidgets.QAction("Check All") self.uncheck_action = QtWidgets.QAction("Uncheck All") # Build layout for function filter text boxes self.filter_layout = QtWidgets.QHBoxLayout() self.filter_layout.addWidget(QtWidgets.QLabel("Filter Function: ")) self.func_filter_box = QtWidgets.QLineEdit() self.filter_layout.addWidget(self.func_filter_box) self.filter_layout.addWidget(QtWidgets.QLabel("Filter Files: ")) self.file_filter_box = QtWidgets.QLineEdit() self.filter_layout.addWidget(self.file_filter_box) self.filter_layout.addWidget(QtWidgets.QLabel("Filter Modules: ")) self.module_filter_box = QtWidgets.QLineEdit() self.filter_layout.addWidget(self.module_filter_box) # Set up fuzzer button self.fuzzer_button = QtWidgets.QPushButton("Fuzz selected targets") if not self.target_data.target_list: self.fuzzer_button.setEnabled(False) # Create checkboxes for continuous mode self.continuous_mode_cbox = QtWidgets.QCheckBox("Continuous") self.pause_mode_cbox = QtWidgets.QCheckBox("Pause on crash") if config.config["continuous"]: self.continuous_mode_cbox.setChecked(True) if config.config["exit_early"]: self.pause_mode_cbox.setChecked(True) # Set up spinboxes for setting timeout values self.fuzz_timeout_box = QtWidgets.QSpinBox() self.fuzz_timeout_box.setSuffix(" seconds") self.fuzz_timeout_box.setMaximum(1200) if "fuzz_timeout" in config.config: self.fuzz_timeout_box.setValue(config.config["fuzz_timeout"]) self.fuzz_timeout_box.setSpecialValueText("None") self.tracer_timeout_box = QtWidgets.QSpinBox() self.tracer_timeout_box.setSuffix(" seconds") self.tracer_timeout_box.setMaximum(2400) if "tracer_timeout" in config.config: self.tracer_timeout_box.setValue(config.config["tracer_timeout"]) self.tracer_timeout_box.setSpecialValueText("None") self.tracer_timeout_box.setSingleStep(10) self.verbose_cbox = QtWidgets.QCheckBox() self.verbose_cbox.clicked.connect(self.toggle_verbose_state) # Create spinbox for controlling simultaneous fuzzing instances self.thread_count = QtWidgets.QSpinBox() self.thread_count.setSuffix(" threads") self.thread_count.setRange(1, 2 * cpu_count()) if "simultaneous" in config.config: self.thread_count.setValue(config.config["simultaneous"]) # Create button for hiding and showing the extended controls self.expand_button = QtWidgets.QToolButton() self.expand_button.setArrowType(Qt.DownArrow) # Create nested widget to hold the expanded fuzzing controls self.extension_widget = QtWidgets.QWidget() self.extension_layout = QtWidgets.QGridLayout() self.extension_widget.setLayout(self.extension_layout) # Create layouts for fuzzing controls self.fuzz_controls_outer_layout = QtWidgets.QHBoxLayout() self.fuzz_controls_inner_left = QtWidgets.QVBoxLayout() self.fuzz_controls_inner_right = QtWidgets.QVBoxLayout() # Add widgets to left, right, and expanded layouts self.fuzz_controls_inner_left.addLayout(self.filter_layout) self.fuzz_controls_inner_left.addWidget(self.extension_widget) self.extension_widget.hide() self.fuzz_controls_inner_left.addWidget(self.fuzzer_button) self.extension_layout.addWidget(self.continuous_mode_cbox, 0, 0) self.extension_layout.addWidget(self.pause_mode_cbox, 1, 0) self.extension_layout.addWidget(QtWidgets.QLabel("Fuzz timeout:"), 0, 1, 1, 1, Qt.AlignRight) self.extension_layout.addWidget(self.fuzz_timeout_box, 0, 2, 1, 1, Qt.AlignLeft) self.extension_layout.addWidget(QtWidgets.QLabel("Triage Timeout:"), 1, 1, 1, 1, Qt.AlignRight) self.extension_layout.addWidget(self.tracer_timeout_box, 1, 2, 1, 1, Qt.AlignLeft) self.extension_layout.addWidget( QtWidgets.QLabel("Simultaneous fuzzing threads:"), 0, 3, 1, 1, Qt.AlignRight) self.extension_layout.addWidget(self.thread_count, 0, 4, 1, 1, Qt.AlignLeft) self.extension_layout.addWidget(QtWidgets.QLabel("Verbose:"), 1, 3, 1, 1, Qt.AlignRight) self.extension_layout.addWidget(self.verbose_cbox, 1, 4, 1, 1, Qt.AlignLeft) self.fuzz_controls_inner_right.addWidget(self.expand_button) # Compose layouts self.fuzz_controls_outer_layout.addLayout( self.fuzz_controls_inner_left) self.fuzz_controls_outer_layout.addLayout( self.fuzz_controls_inner_right) self._layout.addLayout(self.fuzz_controls_outer_layout) # Crashes table session = db.getSession() self.crashes_model = sqlalchemy_model.SqlalchemyModel( session, db.Crash, [ ("Time", db.Crash.timestamp, "timestamp", {}), ("RunID", db.Crash.runid, "runid", {}), ("Reason", db.Crash.crashReason, "crashReason", {}), ("Exploitability", db.Crash.exploitability, "exploitability", {}), ("Ranks", db.Crash.ranksString, "ranksString", {}), ("Crashash", db.Crash.crashash, "crashash", {}), ("Crash Address", db.Crash.crashAddressString, "crashAddressString", {}), ("RIP", db.Crash.instructionPointerString, "instructionPointerString", {}), ("RSP", db.Crash.stackPointerString, "stackPointerString", {}), ("RDI", db.Crash.rdi, "rdi", {}), ("RSI", db.Crash.rsi, "rsi", {}), ("RBP", db.Crash.rdx, "rbp", {}), ("RAX", db.Crash.rax, "rax", {}), ("RBX", db.Crash.rbx, "rbx", {}), ("RCX", db.Crash.rcx, "rcx", {}), ("RDX", db.Crash.rdx, "rdx", {}), ], orderBy=desc(db.Crash.timestamp), filters={"target_config_slug": get_target_slug(config.config)}, ) self.crashes_table = QtWidgets.QTableView() self.crashes_table.setFont( QFontDatabase.systemFont(QFontDatabase.FixedFont)) self.crashes_table.setModel(self.crashes_model) self._layout.addWidget(self.crashes_table) self.crashes_table.horizontalHeader().setStretchLastSection(True) self.crashes_table.resizeColumnsToContents() self.crashes_table.show() self.crashes_table.clicked.connect(self.crash_clicked) # Crash Browser, details about a crash self.crash_browser = QtWidgets.QTextBrowser() self.crash_browser.setText("<NO CRASH SELECTED>") self.crash_browser.setFont( QFontDatabase.systemFont(QFontDatabase.FixedFont)) self._layout.addWidget(self.crash_browser) self.stats_widget = stats.StatsWidget(get_target_slug(config.config)) self._layout.addWidget(self.stats_widget) # Set up stop button (and hide it) self.stop_button = QtWidgets.QPushButton("Stop Fuzzing") self.stop_button.hide() self._layout.addWidget(self.stop_button) self.export_triage_button = QtWidgets.QPushButton("Export Triage") self._layout.addWidget(self.export_triage_button) # Set up status bar self.status_bar = QtWidgets.QStatusBar() self._layout.addWidget(self.status_bar) # Create helper variables for storing counters with signals attached self.runs, self.crash_counter = QIntVariable(0), QIntVariable(0) self.throughput = QFloatVariable(0.0) self.run_adapter = QTextAdapter("Fuzzing Runs: {0.value} ", self.runs) self.throughput_adapter = QTextAdapter(" {0.value:.3f} Runs/s ", self.throughput) self.crash_adapter = QTextAdapter(" Crashes Found: {0.value} ", self.crash_counter) # Create the busy label self.busy_label = QtWidgets.QLabel() busy_gif = QMovie("gui/busy.gif") self.busy_label.setMovie(busy_gif) busy_gif.start() self.busy_label.hide() # Set up labels for the status bar self.fuzz_count = QtWidgets.QLabel() self.throughput_label = QtWidgets.QLabel() self.crash_count = QtWidgets.QLabel() # Add all the labels to the status bar self.status_bar.addPermanentWidget(self.busy_label) self.status_bar.addWidget(self.fuzz_count) self.status_bar.addWidget(self.throughput_label) self.status_bar.addWidget(self.crash_count) # CONNECT SIGNALS # self.change_profile_action.triggered.connect(self.change_profile) # Update the text of the status bar adapters whenever the underlying variables change self.runs.valueChanged.connect(self.run_adapter.update) self.throughput.valueChanged.connect(self.throughput_adapter.update) self.crash_counter.valueChanged.connect(self.crash_adapter.update) self.run_adapter.updated.connect(self.fuzz_count.setText) self.throughput_adapter.updated.connect(self.throughput_label.setText) self.crash_adapter.updated.connect(self.crash_count.setText) # Start the wizard when we click the button and update the tree when we're done self.wizard_button.clicked.connect(self.wizard_thread.start) self.wizard_thread.started.connect( partial(self.setCursor, Qt.WaitCursor)) self.wizard_thread.finished.connect(self.unsetCursor) self.wizard_thread.result_ready.connect(self.wizard_finished) # Connect the context menu buttons self.expand_action.triggered.connect(self._func_tree.expandAll) self.collapse_action.triggered.connect(self._func_tree.collapseAll) self.check_action.triggered.connect(self.check_all) self.uncheck_action.triggered.connect(self.uncheck_all) # Filter the list of functions displayed when we type things into the boxes self.func_filter_box.textChanged.connect( self.func_proxy_model.setFilterFixedString) self.file_filter_box.textChanged.connect( self.file_proxy_model.setFilterFixedString) self.module_filter_box.textChanged.connect( self.module_proxy_model.setFilterFixedString) # Handle checks/unchecks in the target tree self._func_tree.itemCheckedStateChanged.connect(self.tree_changed) self.export_triage_button.clicked.connect(self.export_triage) # Fuzzer control buttons for showing the panel and starting a run self.expand_button.clicked.connect(self.toggle_expansion) self.fuzzer_button.clicked.connect(self.server_thread.start) self.server_thread.finished.connect(self.start_all_threads) # If the user changes the continuous or pause mode, then we make sure the # two are consistent. self.pause_mode_cbox.stateChanged.connect(self.unify_pause_state) self.continuous_mode_cbox.stateChanged.connect( self.unify_continuous_state) # Connect the stop button to the thread so we can pause it self.stop_button.clicked.connect(self.pause_all_threads) # Connect the thread counter to the thread pool self.thread_count.valueChanged.connect(self.change_thread_count) self.change_thread_count(self.thread_count.value())
def __init__(self): super(SpchtChecker, self).__init__() FIXEDFONT = QFontDatabase.systemFont(QFontDatabase.FixedFont) FIXEDFONT.setPointSize(10) self.taube = Spcht() # * Window Setup self.setBaseSize(1280, 720) self.setMinimumSize(720, 480) self.setWindowTitle(i18n['window_title']) self.setWindowFlags(QtCore.Qt.WindowMinimizeButtonHint & QtCore.Qt.WindowMaximizeButtonHint) main_layout = QGridLayout(self) # left side top_file_bar = QHBoxLayout() self.linetext_spcht_filepath = QLineEdit() self.linetext_spcht_filepath.setPlaceholderText(i18n['str_sdf_file_placeholder']) self.linetext_spcht_filepath.setReadOnly(True) #self.btn_create_spcht = QPushButton(i18n['btn_create_spcht']) self.btn_load_spcht_file = QPushButton(i18n['btn_sdf_txt']) self.btn_load_spcht_retry = QPushButton(i18n['generic_retry']) self.btn_load_spcht_retry.setDisabled(True) top_file_bar.addWidget(self.linetext_spcht_filepath) #top_file_bar.addWidget(self.btn_create_spcht) top_file_bar.addWidget(self.btn_load_spcht_file) top_file_bar.addWidget(self.btn_load_spcht_retry) bottom_file_bar = QHBoxLayout() self.str_testdata_filepath = QLineEdit() self.str_testdata_filepath.setPlaceholderText(i18n['str_jsonfile_placeholder']) self.str_testdata_filepath.setReadOnly(True) self.linetext_subject_prefix = QLineEdit() self.linetext_subject_prefix.setPlaceholderText(i18n['str_subject_placeholder']) self.linetext_subject_prefix.setReadOnly(True) self.linetext_subject_prefix.setMaximumWidth(250) self.btn_load_testdata_file = QPushButton(i18n['btn_testdata_txt']) self.btn_load_testdata_file.setToolTip(i18n['btn_testdata_tooltip']) self.btn_load_testdata_file.setDisabled(True) self.btn_load_testdata_retry = QPushButton(i18n['generic_retry']) self.btn_load_testdata_retry.setToolTip(i18n['btn_retry_tooltip']) self.btn_load_testdata_retry.setDisabled(True) bottom_file_bar.addWidget(self.str_testdata_filepath) bottom_file_bar.addWidget(self.linetext_subject_prefix) bottom_file_bar.addWidget(self.btn_load_testdata_file) bottom_file_bar.addWidget(self.btn_load_testdata_retry) # middle part - View 1 center_layout = QHBoxLayout() control_bar_above_treeview = QGridLayout() control_bar_above_treeview.setMargin(0) self.btn_tree_expand = QPushButton(i18n['generic_expandall']) self.btn_tree_expand.setFlat(True) self.btn_tree_expand.setFixedHeight(15) self.btn_tree_collapse = QPushButton(i18n['generic_collapseall']) self.btn_tree_collapse.setFlat(True) self.btn_tree_collapse.setFixedHeight(15) self.treeview_main_spcht_data = QTreeView() self.spchttree_view_model = QStandardItemModel() self.spchttree_view_model.setHorizontalHeaderLabels( [i18n['generic_name'], i18n['generic_predicate'], i18n['generic_source'], i18n['generic_objects'], i18n['generic_info'], i18n['generic_comments']]) self.treeview_main_spcht_data.setModel(self.spchttree_view_model) self.treeview_main_spcht_data.setSelectionBehavior(QAbstractItemView.SelectRows) self.treeview_main_spcht_data.setUniformRowHeights(True) control_bar_above_treeview.addWidget(self.btn_tree_expand, 0, 0) control_bar_above_treeview.addWidget(self.btn_tree_collapse, 0, 1) control_bar_above_treeview.setColumnStretch(2, 1) control_bar_above_treeview.addWidget(self.treeview_main_spcht_data, 1, 0, 1, 3) label_fields = QLabel("Fields") self.lst_fields = QListView() self.lst_fields.setMaximumWidth(200) self.lst_fields_model = QStandardItemModel() self.lst_fields.setModel(self.lst_fields_model) fields = QVBoxLayout() fields.addWidget(label_fields) fields.addWidget(self.lst_fields) label_graphs = QLabel("Graphs") self.lst_graphs = QListView() self.lst_graphs.setMaximumWidth(300) self.lst_graphs_model = QStandardItemModel() self.lst_graphs.setModel(self.lst_graphs_model) graphs = QVBoxLayout() graphs.addWidget(label_graphs) graphs.addWidget(self.lst_graphs) center_layout.addLayout(control_bar_above_treeview) center_layout.addLayout(fields) center_layout.addLayout(graphs) # middle part - View 2 self.console = QTextEdit() self.console.setReadOnly(True) self.console.setFont(FIXEDFONT) # middle part - View 3 self.txt_tabview = QTextEdit() self.txt_tabview.setReadOnly(True) self.txt_tabview.setFont(FIXEDFONT) self.tbl_tabview = QTableView() self.tbl_tabview.horizontalHeader().setStretchLastSection(True) self.tbl_tabview.horizontalHeader().setSectionsClickable(False) self.mdl_tbl_sparql = QStandardItemModel() self.mdl_tbl_sparql.setHorizontalHeaderLabels(["resource identifier", "property name", "property value"]) self.tbl_tabview.setModel(self.mdl_tbl_sparql) self.tbl_tabview.setColumnWidth(0, 300) self.tbl_tabview.setColumnWidth(1, 300) tabView = QTabWidget() tabView.setTabShape(QTabWidget.Triangular) tabView.addTab(self.txt_tabview, "Text") tabView.addTab(self.tbl_tabview, "Table") # bottom self.bottomStack = QStackedWidget() self.bottomStack.setContentsMargins(0, 0, 0, 0) self.bottomStack.setMaximumHeight(20) self.btn_tristate = QPushButton() self.btn_tristate.setMaximumWidth(60) self.btn_tristate.setFlat(True) self.tristate = 0 self.notifybar = QStatusBar() self.notifybar.setSizeGripEnabled(False) self.processBar = QProgressBar() bottombar = QHBoxLayout() bottombar.setContentsMargins(0, 0, 0, 0) bottombar.addWidget(self.btn_tristate) bottombar.addWidget(self.notifybar) randombarasWidget = QWidget() randombarasWidget.setLayout(bottombar) self.bottomStack.addWidget(randombarasWidget) self.bottomStack.addWidget(self.processBar) # * explorer layout self.explorer = QWidget() self.explore_main_vertical = QVBoxLayout(self.explorer) # ? top row explorer self.explorer_top_layout = QHBoxLayout() self.linetext_field_filter = QLineEdit(self.explorer) self.linetext_field_filter.setPlaceholderText(i18n['linetext_field_filter_placeholder']) # additional widgets here self.explorer_top_layout.addWidget(self.linetext_field_filter) self.explore_main_vertical.addLayout(self.explorer_top_layout) # ? central row self.explorer_center_layout = QHBoxLayout() self.explorer_toolbox = QToolBox(self.explorer) self.explorer_toolbox_page1 = QWidget() self.explorer_toolbox_page2 = QWidget() self.explorer_toolbox.addItem(self.explorer_toolbox_page1, i18n['toolbox_page1']) self.explorer_toolbox.addItem(self.explorer_toolbox_page2, i18n['toolbox_page2']) self.explorer_dictionary_treeview = QTreeView(self.explorer_toolbox_page1) self.explorer_marc_treeview = QTreeView(self.explorer_toolbox_page2) self.explorer_center_layout.addWidget(self.explorer_toolbox) self.explore_main_vertical.addLayout(self.explorer_center_layout) # ? bottom row self.explorer_bottom_layout = QHBoxLayout() self.explorer_left_horizontal_spacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.explorer_right_horizontal_spacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.explorer_leftleft_button = QPushButton("<<") self.explorer_left_button = QPushButton("<") self.explorer_rightright_button = QPushButton(">>") self.explorer_right_button = QPushButton(">") self.explorer_bottom_center_layout = QVBoxLayout() self.explorer_linetext_search = QLineEdit(self.explorer) self.explorer_center_search_button = QPushButton(i18n['find']) self.explorer_bottom_center_layout.addWidget(self.explorer_linetext_search) self.explorer_bottom_center_layout.addWidget(self.explorer_center_search_button) self.explorer_bottom_layout.addItem(self.explorer_left_horizontal_spacer) self.explorer_bottom_layout.addWidget(self.explorer_leftleft_button) self.explorer_bottom_layout.addWidget(self.explorer_left_button) self.explorer_bottom_layout.addLayout(self.explorer_bottom_center_layout) self.explorer_bottom_layout.addWidget(self.explorer_right_button) self.explorer_bottom_layout.addWidget(self.explorer_rightright_button) self.explorer_bottom_layout.addItem(self.explorer_right_horizontal_spacer) self.explore_main_vertical.addLayout(self.explorer_bottom_layout) # general layouting self.MainPageLayout = QStackedWidget() randomStackasWidget = QWidget() randomStackasWidget.setLayout(center_layout) self.MainPageLayout.addWidget(self.console) self.MainPageLayout.addWidget(randomStackasWidget) self.MainPageLayout.addWidget(tabView) self.MainPageLayout.addWidget(self.explorer) main_layout.addLayout(top_file_bar, 0, 0) main_layout.addWidget(self.MainPageLayout, 1, 0) main_layout.addLayout(bottom_file_bar, 2, 0) #main_layout.addLayout(bottombar, 3, 0) main_layout.addWidget(self.bottomStack, 3, 0) # * Event Binds self.btn_load_spcht_file.clicked.connect(self.btn_spcht_load_dialogue) self.btn_load_spcht_retry.clicked.connect(self.btn_spcht_load_retry) self.btn_tristate.clicked.connect(self.toogleTriState) self.btn_load_testdata_file.clicked.connect(self.btn_clk_loadtestdata) self.btn_load_testdata_retry.clicked.connect(self.btn_clk_loadtestdata_retry) self.btn_tree_expand.clicked.connect(self.treeview_main_spcht_data.expandAll) self.btn_tree_collapse.clicked.connect(self.treeview_main_spcht_data.collapseAll) self.toogleTriState(0) # various self.console.insertPlainText(time_log(f"Init done, program started")) self.console.insertPlainText(f"Working Directory: {os.getcwd()}")
def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) layout = QVBoxLayout() self.editor = QPlainTextEdit( ) # Could also use a QTextEdit and set self.editor.setAcceptRichText(False) # Setup the QTextEdit editor configuration fixedfont = QFontDatabase.systemFont(QFontDatabase.FixedFont) fixedfont.setPointSize(12) self.editor.setFont(fixedfont) # self.path holds the path of the currently open file. # If none, we haven't got a file open yet (or creating new). self.path = None layout.addWidget(self.editor) container = QWidget() container.setLayout(layout) self.setCentralWidget(container) self.status = QStatusBar() self.setStatusBar(self.status) file_toolbar = QToolBar("File") file_toolbar.setIconSize(QSize(14, 14)) self.addToolBar(file_toolbar) file_menu = self.menuBar().addMenu("&File") open_file_action = QAction( QIcon(os.path.join('images', 'blue-folder-open-document.png')), "Open file...", self) open_file_action.setStatusTip("Open file") open_file_action.triggered.connect(self.file_open) file_menu.addAction(open_file_action) file_toolbar.addAction(open_file_action) save_file_action = QAction(QIcon(os.path.join('images', 'disk.png')), "Save", self) save_file_action.setStatusTip("Save current page") save_file_action.triggered.connect(self.file_save) file_menu.addAction(save_file_action) file_toolbar.addAction(save_file_action) saveas_file_action = QAction( QIcon(os.path.join('images', 'disk--pencil.png')), "Save As...", self) saveas_file_action.setStatusTip("Save current page to specified file") saveas_file_action.triggered.connect(self.file_saveas) file_menu.addAction(saveas_file_action) file_toolbar.addAction(saveas_file_action) print_action = QAction(QIcon(os.path.join('images', 'printer.png')), "Print...", self) print_action.setStatusTip("Print current page") print_action.triggered.connect(self.file_print) file_menu.addAction(print_action) file_toolbar.addAction(print_action) edit_toolbar = QToolBar("Edit") edit_toolbar.setIconSize(QSize(16, 16)) self.addToolBar(edit_toolbar) edit_menu = self.menuBar().addMenu("&Edit") undo_action = QAction( QIcon(os.path.join('images', 'arrow-curve-180-left.png')), "Undo", self) undo_action.setStatusTip("Undo last change") undo_action.triggered.connect(self.editor.undo) edit_menu.addAction(undo_action) redo_action = QAction(QIcon(os.path.join('images', 'arrow-curve.png')), "Redo", self) redo_action.setStatusTip("Redo last change") redo_action.triggered.connect(self.editor.redo) edit_toolbar.addAction(redo_action) edit_menu.addAction(redo_action) edit_menu.addSeparator() cut_action = QAction(QIcon(os.path.join('images', 'scissors.png')), "Cut", self) cut_action.setStatusTip("Cut selected text") cut_action.triggered.connect(self.editor.cut) edit_toolbar.addAction(cut_action) edit_menu.addAction(cut_action) copy_action = QAction( QIcon(os.path.join('images', 'document-copy.png')), "Copy", self) copy_action.setStatusTip("Copy selected text") copy_action.triggered.connect(self.editor.copy) edit_toolbar.addAction(copy_action) edit_menu.addAction(copy_action) paste_action = QAction( QIcon(os.path.join('images', 'clipboard-paste-document-text.png')), "Paste", self) paste_action.setStatusTip("Paste from clipboard") paste_action.triggered.connect(self.editor.paste) edit_toolbar.addAction(paste_action) edit_menu.addAction(paste_action) select_action = QAction( QIcon(os.path.join('images', 'selection-input.png')), "Select all", self) select_action.setStatusTip("Select all text") select_action.triggered.connect(self.editor.selectAll) edit_menu.addAction(select_action) edit_menu.addSeparator() wrap_action = QAction( QIcon(os.path.join('images', 'arrow-continue.png')), "Wrap text to window", self) wrap_action.setStatusTip("Toggle wrap text to window") wrap_action.setCheckable(True) wrap_action.setChecked(True) wrap_action.triggered.connect(self.edit_toggle_wrap) edit_menu.addAction(wrap_action) self.update_title() self.show()
def __init__(self, ctx): super().__init__() self.setWindowTitle('ESP32 Flasher - By @kapraran') self.running = False row_btn_width = 160 self.ctx = ctx self.resize(800, 500) self.cb = self.createComboBox() fixedFont = QFontDatabase.systemFont(QFontDatabase.FixedFont) self.output = QTextEdit() self.output.setReadOnly(True) self.output.setFont(fixedFont) self.output.setStyleSheet( "QTextEdit { background-color : #000; color: orange; }") mainWidget = QWidget() button1 = QPushButton("Επιλογή Αρχείου") button1.setFixedWidth(row_btn_width) button1.clicked.connect(self.openFile) self.btn_upload = QPushButton("Μεταφόρτωση") self.btn_upload.clicked.connect(self.extractZip) self.btn_upload.setFixedHeight(60) self.selectedDir = QLabel("-") self.selectedDir.setStyleSheet( "QLabel { background-color : #cccccc; padding: 0 4px; }") self.btn_refresh = QPushButton("Ανανέωση") self.btn_refresh.setFixedWidth(row_btn_width) self.btn_refresh.clicked.connect(self.refresh_comports) row1 = QWidget() row1_layout = QHBoxLayout() row1_layout.setMargin(0) row1_layout.addWidget(self.cb) row1_layout.addWidget(self.btn_refresh) row1.setLayout(row1_layout) row2 = QWidget() row2_layout = QHBoxLayout() row2_layout.setMargin(0) row2_layout.addWidget(self.selectedDir) row2_layout.addWidget(button1) row2.setLayout(row2_layout) layout = QVBoxLayout() # layout.addWidget(self.cb) layout.addWidget(row1) # layout.addWidget(self.selectedDir) # layout.addWidget(button1) layout.addWidget(row2) layout.addWidget(self.output) layout.addWidget(self.btn_upload) self.dlg = QFileDialog() self.dlg.setFileMode(QFileDialog.ExistingFiles) self.dlg.setNameFilter("esbin (*.esbin)") self.process = QProcess(self) self.process.readyRead.connect(self.dataReady) self.process.finished.connect(self.onprocFinished) mainWidget.setLayout(layout) self.setCentralWidget(mainWidget)
def data(self, index: QModelIndex, role: Qt.ItemDataRole = Qt.DisplayRole) -> Any: if not index.isValid(): return None col = self.getColumnKey(index.column()) if not col: return None if role == Qt.FontRole: if col in ( 'datatype', 'size', ): return QFontDatabase.systemFont(QFontDatabase.FixedFont) return None if role == Qt.CheckStateRole: if col in ('enabled', ): mod = self.modmodel[index.row()] val = mod[col] return Qt.Checked if val else Qt.Unchecked return None if role == Qt.BackgroundRole: mod = self.modmodel[index.row()] if not mod.enabled: return QColor(240, 240, 240) if col in ('priority', ) and mod.datatype not in ( 'mod', 'udf', ): return QColor(240, 240, 240) if mod.installdate > self._lastUpdate: return QColor(242, 255, 242) if mod.installdate > self._lastInitialization: return QColor(242, 246, 255) if not mod.installed: return QColor(250, 240, 240) return None if role == Qt.ForegroundRole: mod = self.modmodel[index.row()] if not mod.enabled: return QColor(60, 60, 60) return None if role == Qt.DecorationRole: if col in ('datatype', ): mod = self.modmodel[index.row()] val = mod[col] return self._icons[val] if val in self._icons else self._icons[ 'udf'] return None if role == Qt.ToolTipRole: mod = self.modmodel[index.row()] if col in ('datatype', ): val = mod[col] return self._datatypes[ val] if val in self._datatypes else self._datatypes['udf'] if col in ('enabled', ): val = mod[col] return 'Enabled' if val else 'Disabled' return str(mod[col]) if role == Qt.TextAlignmentRole: if col in ('size', ): # Right|VCenter return 0x0082 if col in ( 'priority', 'installdate', 'binFiles', 'menuFiles', 'settings', 'inputs', 'contentFiles', 'scriptFiles', ): # HCenter|VCenter return 0x0084 # Left|VCenter return 0x0081 if role == Qt.EditRole: if col in ( 'package', 'filename', 'category', 'priority', ): mod = self.modmodel[index.row()] return str(mod[col]) return None # role used for sorting if role == Qt.UserRole: mod = self.modmodel[index.row()] if col in ('priority', ): return f'{int(mod[col]): >20} {mod["filename"]}' if col in ('size', ): return int(mod[col]) if col in ('binFiles', 'menuFiles', 'contentFiles', \ 'scriptFiles', 'settings', 'inputs',): return len(mod[col]) return str(mod[col]) if role == Qt.DisplayRole: if col in ('enabled', ): return None mod = self.modmodel[index.row()] if col in ('datatype', ): return str(mod[col]).upper() if col in ('priority', ): val = mod[col] if val <= 0: return 'none' return val if col in ('installdate', ): return mod[col].astimezone( tz=None).strftime('%Y-%m-%d %H:%M:%S') if col in ('size', ): val = mod[col] frm = 'b' val /= 1024 frm = 'K' if val // 1024: val /= 1024 frm = 'M' return '%.1f %s' % (val, frm) if col in ( 'inputs', 'settings', ): val = 0 for s in mod[col]: for n in s.config.sections(): val += len(s.config.items(n)) return val if val else None if col in ( 'binFiles', 'menuFiles', 'contentFiles', 'scriptFiles', ): val = len(mod[col]) if val < 1: return '' return val return str(mod[col]) return None
def __init__(self, parent=None, menu_handler=None): super(HexViewWidget, self).__init__() self.setupUi(self) self._model = HexTableModel(self) self.view = HexTableView(parent=self) sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.view.sizePolicy().hasHeightForWidth()) self.view.setSizePolicy(sizePolicy) # self.view.setMinimumSize(QSize(660, 0)) self.view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self.view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.view.setSelectionMode(QAbstractItemView.NoSelection) self.view.setShowGrid(False) self.view.setWordWrap(False) self.view.setStyleSheet( "QHeaderView { } QTableView::item { } ") # bypass stylesheet # self.view.setObjectName("view") # self.view.horizontalHeader().setDefaultSectionSize(10) self.view.horizontalHeader().setMinimumSectionSize(5) # self.view.verticalHeader().setDefaultSectionSize(21) # self.view.setMinimumWidth( self.view.width() ) self.mainLayout.insertWidget(0, self.view) self.view.setModel(self._model) for i in range(0x10): self.view.setColumnWidth(i, 25) self.view.setColumnWidth(0x10, 5) for i in range(0x11, 0x22): self.view.setColumnWidth(i, 11) self._hsm = HexItemSelectionModel(self._model, self.view) self.view.setSelectionModel(self._hsm) self.view.setContextMenuPolicy(Qt.CustomContextMenu) self.view.customContextMenuRequested.connect( self._handle_context_menu_requested) if menu_handler is not None: self.get_context_menu = menu_handler self.optimal_width = self.view.verticalScrollBar().width( ) + self.view.verticalHeader().width() # - 40 for i in range(0x22): self.optimal_width += self.view.columnWidth(i) f = QFontDatabase.systemFont(QFontDatabase.FixedFont) f.setPointSize(8) self.view.horizontalHeader().setFont(f) self.view.verticalHeader().setFont(f) self.view.setFont(f) self.statusLabel.setFont(f) self.view.setMinimumWidth(self.optimal_width) self.view.setMaximumWidth(self.optimal_width) self._hsm.selectionRangeChanged.connect( self._handle_selection_range_changed) self.view.moveKeyPressed.connect(self._hsm.handle_move_key) self.view.selectKeyPressed.connect(self._hsm.handle_select_key) self.view.setItemDelegate(HexItemDelegate(self._model, self)) self.full_data_changed.connect(self._handle_data_changed) self.single_data_changed.connect(self._handle_single_data_changed) # self.data_edited.connect(self._handle_data_edited) self.statusLabel.setText("")