def project_selected_changed(self):
     """
     This method listens for a change in the current project and updates the singleton and updates the view.
     :return: none
     """
     if self.project_tab.listWidget.count() != 0:
         project = self.project_tab.listWidget.selectedItems()
         project_name = [item.text().encode("ascii") for item in project]
         if project_name:
             self.project_name = str(project_name[0], 'utf-8')
             try:
                 Singleton.set_project(self.project_name)
                 project_db = DBConnection.get_collection(self.project_name)
                 project_info = project_db["projectInfo"]
                 bin_info = project_db["binaryInfo"]
                 cursor = project_info.find()
                 for db in cursor:
                     self.project_tab.textEdit_2.setPlainText(db['ProjectDescription'])
                     self.project_tab.lineEdit_2.setText(db['ProjectName'])
                     self.project_tab.lineEdit_3.setText(db['BnyFilePath'])
                     Singleton.set_path(db['BnyFilePath'])
                 cursor_bin = bin_info.find()
                 for db in cursor_bin:
                     self.set_binary_prop()
                     self.fill_binary_prop(db)
                 self.selected_project_changed.emit()
             except Exception as e:
                 msg = ErrorDialog(self.project_tab, str(e), "Error")
                 msg.exec()
    def save_project(self):
        """
        This method saves the newly created project into the database.
        :return: none
        """
        if self.project_tab.lineEdit_3.text() != "":
            saved = False
            project_db = DBConnection.get_collection(self.project_name)
            project_info = project_db["projectInfo"]
            info = {"ProjectName": self.project_tab.lineEdit_2.text(),
                    "ProjectDescription": self.project_tab.textEdit_2.toPlainText(),
                    "BnyFilePath": self.project_tab.lineEdit_3.text()}
            insert_info = project_info.insert(info, check_keys=False)
            bin_info = project_db["binaryInfo"]
            insert_obj = bin_info.insert(r2_bin_info, check_keys=False)
            msg = QtWidgets.QMessageBox()
            msg.setIcon(QtWidgets.QMessageBox.Information)
            msg.setWindowTitle("Save Project")
            msg.setText("Project Saved")
            msg.setStandardButtons(QtWidgets.QMessageBox.Ok)
            retval = msg.exec_()
            Singleton.set_path(self.project_tab.lineEdit_3.text())
            Singleton.set_project(self.project_name)
            self.project_tab.textEdit_2.setReadOnly(True)
            self.delete_save_operations(self.project_creation_finished, [self.project_tab.pushButton_7],
                                   [self.project_tab.pushButton_8, self.project_tab.pushButton_10],
                                   self.project_tab.listWidget)

        else:
            msg = ErrorDialog(self.project_tab, "Please select a binary file", "Error Saving Project")
            msg.exec_()
    def delete_project(self):
        """
        This method gets the selected project and deletes it form the database.
        :return: none
        """
        if self.project_name != "":
            button_reply = QtWidgets.QMessageBox.question(self.project_tab, 'PyQt5 message',
                                                          "Do you like to erase Project %s ?" % self.project_name,
                                                          QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
                                                          QtWidgets.QMessageBox.No)
            if button_reply == QtWidgets.QMessageBox.Yes:

                DBConnection.drop_db(self.project_name)

                self.project_tab.lineEdit_2.setText("")
                self.project_tab.textEdit_2.setText("")
                self.project_tab.lineEdit_3.setText("")
                self.set_binary_prop()
                self.delete_save_operations(self.project_creation_finished, [self.project_tab.pushButton_7],
                                            [self.project_tab.pushButton_8, self.project_tab.pushButton_10],
                                            self.project_tab.listWidget)

                list_items = self.project_tab.listWidget.selectedItems()
                if not list_items:
                    return
                for item in list_items:
                    self.project_tab.listWidget.takeItem(self.project_tab.listWidget.row(item))
                Singleton.set_project("BEAT")
                Singleton.set_path("")
                self.delete_project_signal.emit()
                self.project_selected_changed()
        else:
            msg = ErrorDialog(self.project_tab, "Please select a project", "Error Deleting Project")
            msg.exec_()
Пример #4
0
    def setup_ui(self, main_window):
        """Sets up the ui for the main window and establishes the ui_implementation and their connections for each tab"""
        self.main_window = main_window
        self.main_window.setObjectName("BEAT")
        self.main_window.resize(804, 615)
        self.main_window.setFixedSize(self.main_window.width(), self.main_window.height())
        self.setWindowIcon(QtGui.QIcon('./resources/beat.png'))

        self.main_window.setWindowTitle("BEAT")

        s = Singleton()
        s.set_project("BEAT")

        self.centralwidget = QtWidgets.QWidget(self.main_window)
        self.centralwidget.setObjectName("centralwidget")
        self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
        self.tabWidget.setGeometry(QtCore.QRect(5, 5, 794, 605))
        self.tabWidget.setObjectName("tabWidget")

        self.ProjectTab = Tab1.Tab1(self)
        self.tabWidget.addTab(self.ProjectTab, "")

        self.analysisTab = Tab2.Tab2(self)
        self.tabWidget.addTab(self.analysisTab, "")

        self.pluginTab = Tab3.Tab3(self)
        self.tabWidget.addTab(self.pluginTab, "")

        self.pointsOfInterestTab = Tab4.Tab4(self)
        self.tabWidget.addTab(self.pointsOfInterestTab, "")

        self.documentationTab = Tab5.Tab5(self)
        self.tabWidget.addTab(self.documentationTab, "")

        self.project_implementation = ProjectTabImplementation.ProjectTabImplementation(self.ProjectTab)
        self.project_implementation.establish_connections()
        self.project_implementation.establish_calls()

        self.analysis_implementation = AnalysisTabImplementation.AnalysisTabImplementation(self.analysisTab)
        self.analysis_implementation.establish_connections()
        self.analysis_implementation.establish_calls()

        self.plugin_implementation = PluginTabImplementation.PluginTabImplementation(self.pluginTab)
        self.plugin_implementation.establish_connections()
        self.plugin_implementation.establish_calls()

        self.poi_implementation = POITabImplementation.POITabImplementation(self.pointsOfInterestTab)
        self.poi_implementation.establish_connections()
        self.poi_implementation.establish_calls()

        self.doc_implementation = DocumentationTabImplementation.DocumentationTabImplementation(self.documentationTab)
        self.doc_implementation.establish_connections()
        self.doc_implementation.establish_calls()

        self.project_implementation.selected_project_changed.connect(
            lambda: self.analysis_implementation.poi_comboBox_change("All"))
        self.project_implementation.selected_project_changed.connect(lambda: self.set_project_name())
        self.project_implementation.selected_project_changed.connect(
            lambda: self.analysisTab.terminal_output_textEdit.clear())
        self.project_implementation.project_creation_started.connect(lambda: self.disable_tabs())
        self.project_implementation.project_creation_finished.connect(lambda: self.enable_tabs())
        self.project_implementation.delete_project_signal.connect(lambda: self.analysisTab.poi_listWidget.clear())
        self.project_implementation.delete_project_signal.connect(lambda: self.set_clear_name())
        self.project_implementation.delete_project_signal.connect(
            lambda: self.analysisTab.poi_content_area_textEdit.clear())

        self.analysis_implementation.dynamic_started.connect(lambda: self.set_running())
        self.analysis_implementation.dynamic_stopped.connect(lambda: self.set_project_name())
        self.analysis_implementation.dynamic_started.connect(lambda: self.disable_tabs())
        self.analysis_implementation.dynamic_stopped.connect(lambda: self.enable_tabs())

        self.plugin_implementation.plugin_signal.connect(self.analysis_implementation.set_plugins)
        self.plugin_implementation.plugin_signal.connect(self.poi_implementation.set_plugins)
        self.plugin_implementation.plugin_creation_started.connect(lambda: self.disable_tabs())
        self.plugin_implementation.plugin_creation_finished.connect(lambda: self.enable_tabs())
        self.plugin_implementation.plugin_delete_signal.connect(self.poi_implementation.set_plugins)
        self.plugin_implementation.plugin_delete_signal.connect(
            lambda: self.poi_implementation.fill_poi(self.pointsOfInterestTab.comboBox_2.currentText()))
        self.plugin_implementation.plugin_delete_signal.connect(self.pointsOfInterestTab.textEdit.clear)
        self.plugin_implementation.plugin_delete_signal.connect(self.analysis_implementation.set_plugins)

        self.poi_implementation.add_poi_signal.connect(self.plugin_implementation.item_activated)

        self.main_window.setCentralWidget(self.centralwidget)
        self.retranslate_ui()
        self.tabWidget.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(main_window)