def __init__(self, title, contents, is_contents_from_table=False, does_detail_exists=True): QWidget.__init__(self) QObject.__init__(self) top_widget_height = 35 pointer_cursor = QCursor(Qt.PointingHandCursor) self.setWindowTitle(title) self.setMinimumSize(self.width(), self.height()) self.setWindowIcon(QIcon(CONSTANT.ICON_PATH[0])) layout = QBoxLayout(QBoxLayout.TopToBottom, self) top_layout = QBoxLayout(QBoxLayout.LeftToRight, self) layout.addLayout(top_layout) if is_contents_from_table: contents.setParent(self) self.table = contents else: self.table = ArtifactTable(self, contents) if not does_detail_exists: self.table.is_detail_allowed = does_detail_exists self.table.artifacts_list = contents self.table.ui() layout.addWidget(self.table) self.filtering_widget = filtering_widget("Filter ({})".format(title)) self.filtering_widget.setCheckedStatus(self.table.checked_status) self.filtering_widget.itemChanged.connect(self.table.filter) filter_btn = QPushButton(self) filter_btn.setIcon(QIcon(CONSTANT.ICON_PATH[1])) filter_btn.setFixedSize(top_widget_height, top_widget_height) filter_btn.setStyleSheet("background-color: darkslategray") filter_btn.setShortcut("Ctrl+D") filter_btn.clicked.connect(self.filtering_widget.show) filter_btn.setCursor(pointer_cursor) self.search_box = QLineEdit(self) self.search_box.setFixedHeight(top_widget_height) self.search_box.showMaximized() self.search_box.setFont(QFont("Arial", 12)) self.search_box.setPlaceholderText("Search") self.search_box.returnPressed.connect(self.search) top_layout.addWidget(filter_btn) top_layout.addWidget(self.search_box) layout.addWidget(self.table) if self.table.isHidden(): self.table.show()
def on_finished_importing(self, attr, result): parent_table = ArtifactTable(self.tab, result, is_parent=True, selected_sw=attr[2]) parent_table.setToolTip("{} - {}".format(attr[0], attr[1])) idx = self.tab.addTab(parent_table, self.get_tab_text("XML")) self.adding_tab_number = idx self.tab.setCurrentIndex(idx) if attr[2]: self.filtering_widget.change_status_for_color_parent_table() else: self.filtering_widget.change_status_for_no_color_parent_table() self.adding_tab_number = -1
def filter_by_software(self): checked_sw = { chk_box.text(): CONSTANT.SOFTWARE[chk_box.text()] for chk_box in self.filtering_widget.chk_list if chk_box.isChecked() } parent_table = self.tab.currentWidget() new_list = [] for item in parent_table.artifacts_list: if item[0][0] == CONSTANT.REGISTRY_KEYWORD: continue # 중복 색상 구분 추가 시, 해당문장 제거 if item[0][1] or item[0][2] in checked_sw.values(): new_list.append(item) new_tab_text = self.get_tab_text("App") self.adding_tab_number = self.tab.addTab( ArtifactTable(self.tab, new_list, selected_sw=list(checked_sw.values())), new_tab_text) child_table = self.tab.widget(self.adding_tab_number) child_table.setToolTip(", ".join(checked_sw.keys()) + "\nFrom \"{}\" Tab".format( self.tab.tabText(self.tab.currentIndex()))) child_table.navigated.connect(self.navigate) self.tab.setCurrentIndex(self.adding_tab_number) self.filtering_widget.set_checked_status(parent_table.checked_status) self.filtering_widget.change_status_for_color_table() self.table_dict[child_table] = parent_table self.adding_tab_number = -1
def on_finished_searching(self, artifacts_list, parent_table): new_tab_text = self.get_tab_text("Search") child_table = ArtifactTable(self.tab, artifacts_list, selected_sw=parent_table.selected_sw) self.adding_tab_number = self.tab.addTab(child_table, new_tab_text) child_table.setToolTip("From \"{}\" Tab".format( self.tab.tabText(self.tab.indexOf(parent_table)))) child_table.navigated.connect(self.navigate) self.tab.setCurrentIndex(self.adding_tab_number) if parent_table.selected_sw: self.filtering_widget.change_status_for_color_table() else: self.filtering_widget.change_status_for_no_color_table() self.table_dict[child_table] = parent_table self.adding_tab_number = -1
def import_csv(self): import os, csv dir_path = os.getcwd() + "\\" if len(self.env) == 2 else self.env[6] file_name, _ = QFileDialog.getOpenFileName(self, "Import CSV", dir_path, filter="*.csv") if not file_name and not _: return try: with open(file_name, newline='', encoding='utf-8') as f: reader = csv.reader(f) first_row = next(reader) selected_sw = first_row[-1].split("=")[1] selected_sw = None if selected_sw == 'None' else list( map(int, selected_sw.split("/"))) result = [] for row in reader: head = row[0].split("/") head[1] = True if head[1] == "True" else False head[2:] = map(int, head[2:]) if head[0] == CONSTANT.HISTORY_KEYWORD: result.append([head] + row[1:4]) elif head[0] == CONSTANT.PREFETCH_KEYWORD: result.append([head] + row[1:5]) else: result.append([head] + row[1:6]) except Exception as e: QMessageBox.warning(self, "Error", "{}".format(e), QMessageBox.Ok) return parent_table = ArtifactTable(self.tab, result, is_parent=True, selected_sw=selected_sw) idx = self.tab.addTab(parent_table, self.get_tab_text("CSV")) self.adding_tab_number = idx parent_table.is_detail_allowed = False parent_table.setToolTip(file_name) self.tab.setCurrentIndex(idx) if selected_sw: self.filtering_widget.change_status_for_color_parent_table() else: self.filtering_widget.change_status_for_no_color_parent_table() self.adding_tab_number = -1
def filter_in_parent_table(self): checked = self.filtering_widget.getCheckedItems() tab_idx = self.tab.currentIndex() parent_table = self.tab.widget(tab_idx) artifacts_list_of_child_table = [] if parent_table.selected_sw: for r in range(len(parent_table.artifacts_list)): row = parent_table.artifacts_list[r] if row[0][0] in checked["Artifact"] and row[0][3] in checked[ "Color"]: artifacts_list_of_child_table.append( parent_table.artifacts_list[r]) by_str = "\n".join( checked["Artifact"]) + "\nColor Number: " + ", ".join( map(str, checked["Color"])) self.filtering_widget.change_status_for_color_table() else: for r in range(len(parent_table.artifacts_list)): row = parent_table.artifacts_list[r] if row[0][0] in checked["Artifact"]: artifacts_list_of_child_table.append( parent_table.artifacts_list[r]) by_str = "\n".join(checked["Artifact"]) self.filtering_widget.change_status_for_no_color_table() new_tab_text = self.get_tab_text("Filtered") self.adding_tab_number = self.tab.addTab( ArtifactTable( self.tab, artifacts_list_of_child_table, checked_status=self.filtering_widget.get_checked_status()), new_tab_text) child_table = self.tab.widget(self.adding_tab_number) tool_tip = "filter_in_child_table by: \n {}\nFrom \"{}\" Tab".format( by_str, self.tab.tabText(new_tab_text)) child_table.setToolTip(tool_tip) child_table.navigated.connect(self.navigate) self.tab.setCurrentIndex(self.adding_tab_number) self.filtering_widget.setCheckedStatus(child_table.checked_status) self.table_dict[child_table] = parent_table self.adding_tab_number = -1
def show_analysis_result_tab(self, widget): import time from operator import itemgetter self.artifacts_list.sort(key=itemgetter(1)) status_msg = "total [{}], {} seconds".format(len( self.artifacts_list), (time.time() - self.start_time)) self.statusBar().showMessage(status_msg) tab_text = self.tab.tabText(self.analyzing_tab_number) tab_idx = self.tab.insertTab( self.analyzing_tab_number, ArtifactTable(self.tab, self.artifacts_list, is_parent=True), tab_text) self.tab.removeTab(tab_idx + 1) logs = widget.logLabel.logs widget.deleteLater() self.tab.setCurrentIndex(tab_idx) self.analyzed_tab_number = self.analyzing_tab_number self.analyzing_tab_number = -1 self.filtering_widget.changeStatusForNoColorParentTable() timestamp = datetime.datetime.strftime(datetime.datetime.now(), "%Y%m%d%H%M%S%f") with open(self.env[-1] + "{}.log".format(timestamp), 'w') as f: f.write(logs)