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 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_plugin(self): """ This method after creating a new plugin this method communicates with the model to save the changes to the database. :return: none """ plugin_db = DBConnection.get_collection("plugin") plg_cllc = plugin_db[self.plugin_tab.DPVPluginName.text()] info = { "name": self.plugin_tab.DPVPluginName.text(), "desc": self.plugin_tab.DPVPluginDescription.toPlainText(), "poi": { "item": [] }, "output": self.plugin_tab.DPVDefaultOutputField.text() } plg = Plugin.get_name(self.plugin_tab.DPVPluginName.text()) self.delete_save_operations(self.plugin_creation_finished, [self.plugin_tab.pushButton_7], [self.plugin_tab.ButtonSavePlugin], self.plugin_tab.listWidget) if not plg: plg_cllc.insert(info, check_keys=False) x = ErrorDialog(self.plugin_tab, "Plugin Saved", "Save Plugin") x.exec_() self.plugin_signal.emit() else: x = ErrorDialog(self, "Plugin already exists", "Error Plugin") x.exec_() return
def delete_plugin(self): """ This method deletes the selected plugin from the database. :return: none """ if self.plugin != "": button_reply = QtWidgets.QMessageBox.question( self.plugin_tab, 'PyQt5 message', "Do you like to erase Plugin %s ?" % self.plugin, QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No) if button_reply == QtWidgets.QMessageBox.Yes: project_db = DBConnection.get_collection("plugin") project_db.drop_collection(self.plugin) self.plugin = "" self.plugin_tab.DPVPluginDescription.setText("") self.plugin_tab.DPVPluginName.setText("") self.plugin_tab.DVPPointOfInterest.setText("") self.plugin_tab.DPVDefaultOutputField.setText("") self.delete_save_operations(self.plugin_creation_finished, [self.plugin_tab.pushButton_7], [self.plugin_tab.ButtonSavePlugin], self.plugin_tab.listWidget) list_items = self.plugin_tab.listWidget.selectedItems() if not list_items: return for item in list_items: self.plugin_tab.listWidget.takeItem( self.plugin_tab.listWidget.row(item)) self.plugin_delete_signal.emit() else: x = ErrorDialog(self.plugin_tab, "Please select a plugin", "Error") x.exec_()
def static_functions(rlocal, cplugin): """ analysis all the functions in the binary and filters with the selected plugin and adds them to the database :param rlocal: R2Connection of the binary file :param cplugin: string current selected plugin :return: List of dict with filtered functions """ items = [] s = Singleton.get_project() project_db = DBConnection.get_collection(s) #if project_db["functions"]: # project_db.drop_collection("functions") func_db = project_db["functions"] func_all = rlocal.cmdj("aflj") func_plg = Plugin.plugin_types("Function", cplugin) for fc in func_all: if fc["name"] in func_plg: function = rlocal.cmdj("axtj %s" % fc["name"]) tmp = fc["name"] for f in function: fc["name"] = tmp + " " + hex(f["from"]) items.append(fc["name"]) fc["comment"] = "" fc["runs"] = [] fc["from"] = hex(f["from"]) if "_id" in fc: del fc["_id"] if func_db.find({"name": fc["name"]}).count() == 0: func_db.insert_one(fc) return items
def create_plugin(self): """ This method communicates with the view for creating a new plugin and check if the created plugin already exists. :return: none """ text, ok_pressed = QtWidgets.QInputDialog.getText( self.plugin_tab, "Create New Plugin", "Name of Plugin:", QtWidgets.QLineEdit.Normal, "") if ok_pressed and text != '': db_names = DBConnection.get_collection("plugin") coll = db_names.list_collections() for i in coll: if text in i: x = ErrorDialog(self.plugin_tab, "Plugin with that name already exists", "Error Creating Plugin") x.exec_() return self.plugin_tab.DPVPluginDescription.setText("") self.plugin_tab.DPVPluginName.setText(text) self.plugin_tab.DVPPointOfInterest.setText("") self.plugin_tab.DPVDefaultOutputField.setText("") self.plugin_tab.listWidget.addItem(text) item = self.plugin_tab.listWidget.findItems( text, QtCore.Qt.MatchExactly) self.plugin_tab.listWidget.setCurrentItem(item[0]) self.create_operations(self.plugin_creation_started, [self.plugin_tab.pushButton_7], [self.plugin_tab.ButtonSavePlugin], self.plugin_tab.listWidget)
def open_comment(self): """ This method opens the comment pop-up to add a comment/ or edit an exiting comment.Afterwards it updates the information to the detailed point of interest in the database. :return: none """ item = self.analysis_tab.poi_listWidget.currentItem() value = DBConnection.search_by_item(item) project_db = DBConnection.get_collection(Singleton.get_project()) if item.toolTip() == "Functions": db_info = project_db["functions"] elif item.toolTip() == "Strings": db_info = project_db["string"] if value is not None: id = value["_id"] cmt = value["comment"] if cmt is None: cmt = "" pop_up = CommentDialog(self.analysis_tab, cmt) comm = pop_up.exec_() index = {"_id": id} new_value = {"$set": {"comment": comm}} db_info.update_one(index, new_value) self.detailed_poi(item) new_font = QtGui.QFont() new_font.setBold(True) item.setFont(new_font)
def get_file(current): """ Get the output file of the selected plugin :param current: string current selected plugin :return: string path of output file of plugin """ plugin_db = DBConnection.get_collection("plugin") coll = plugin_db[current] cursor = coll.find() for y in cursor: out = y["output"] return out
def update_poi(poi_list, current): """ Updates pois list in the selected plugin :param poi_list: list new pois to add :param current: string current selected plugin :return: None """ plugin_db = DBConnection.get_collection("plugin") my_col = plugin_db[current] query = {"name": current} new_values = {"$set": {"poi": poi_list}} my_col.update_one(query, new_values)
def get_name(plugin): """ Gets the information and pois from the selected plugin :param plugin: current selected plugin :return: Mongo cursor with the info from the plugin """ project_db = DBConnection.get_collection("plugin") x = DBConnection.list_collections("plugin") for i in x: if plugin == i: project_info = project_db[i] cursor = project_info.find() return cursor
def get_output(item, current): """ Get the output of the poi in the current plugin :param item: string name of poi :param current: string selected plugin :return: string output of poi """ plugin_db = DBConnection.get_collection("plugin") current_coll = plugin_db[current] cursor = current_coll.find() for y in cursor: poi = y["poi"]["item"] for ash in poi: if ash["name"] in item: return ash["pythonOutput"]
def poi_comboBox_change(self, text): """ This function listens for a change in the poi window to change the current filter and updates the filtered pois which are stored in the database in the list view :param text: poi's type :return: none """ s = Singleton.get_project() if s == "BEAT": msg = ErrorDialog(self.analysis_tab, "Please select a project first", "Static analysis Error") msg.exec_() return self.analysis_tab.poi_listWidget.clear() project_db = DBConnection.get_collection(s) if text == "Functions": project_info = project_db["functions"] cursor = project_info.find() for db in cursor: item = self.set_item(db["name"], "Functions") item = self.change_font(item) self.analysis_tab.poi_listWidget.addItem(item) elif text == "Strings": project_info = project_db["string"] cursor = project_info.find() for db in cursor: text = db["string"] item = self.set_item(text, "Strings") item = self.change_font(item) self.analysis_tab.poi_listWidget.addItem(item) elif text == "All": project_info = project_db["functions"] cursor = project_info.find() for db in cursor: item = self.set_item(db["name"], "Functions") item = self.change_font(item) self.analysis_tab.poi_listWidget.addItem(item) project_info = project_db["string"] cursor = project_info.find() for db in cursor: text = db["string"] item = self.set_item(text, "Strings") item = self.change_font(item) self.analysis_tab.poi_listWidget.addItem(item)
def return_funcitions(self, text): """ This method receives the information from the breakpoint and stores the information into the database. :param text: information received :return: none """ value = DBConnection.search_by_name(text["name"], "Functions") project_db = DBConnection.get_collection(Singleton.get_project()) db_info = project_db["functions"] if value is not None: id = value["_id"] index = {"_id": id} runs = value["runs"] run = {"name":input,"rtnPara": text["rtnPara"], "rtnFnc": text["rtnFnc"]} runs.append(run) new_value = {"$set": {"runs": runs}} db_info.update_one(index, new_value)
def plugin_types(plugin_types, current): """ Filters the pois installed in the current plugin with the string passed :param plugin_types: string with the type of poi :param current: Current selected plugin :return: list of pois that matches the type """ plugin_list = [] plugin_db = DBConnection.get_collection("plugin") current_coll = plugin_db[current] cursor = current_coll.find() for y in cursor: poi = y["poi"]["item"] for ash in poi: if plugin_types == ash["type"]: plugin_list.append(ash["name"]) return plugin_list
def static_strings(rlocal, cplugin): """ analysis all the strings in the binary and filters with nthe selected plugin and adds them to the database :param rlocal: R2Connection of the binary file :param cplugin: string current selected plugin :return: List of dict with filtered strings """ items = [] s = Singleton.get_project() project_db = DBConnection.get_collection(s) # Strings strings = rlocal.cmdj("izj") str_plg = Plugin.plugin_types("String", cplugin) #if project_db["string"]: # project_db.drop_collection("string") str_db = project_db["string"] for string in strings: text = string["string"] text_decoded = base64.b64decode(text) for i in str_plg: if i.upper() in text_decoded.decode().upper(): x = rlocal.cmdj("axtj %s" % string["vaddr"]) tmp = text_decoded.decode() for str in x: string["string"] = tmp + " " + hex(str["from"]) items.append(string["string"]) string["from"] = hex(str["from"]) string["comment"] = "" if "_id" in string: del string["_id"] if str_db.find({"string": string["string"]}).count() == 0: str_db.insert_one(string) break return items