def arbitrarySearch(self, searchTasks): """Execute an arbitrary search process""" self.searchRunning = True # Reset the progress bar GObject.idle_add(self._view.searchProgressBar.show) GObject.idle_add(self._view.searchProgressBar.set_fraction, 0.0) # create a task for the text searcher = Searcher(self.vocabularyController.getCurrentProject(), self.updateProgessBar) if searchTasks is not None: self.executedSearchTasks = searcher.search(searchTasks) self.idResult = -1 self.nbResult = 0 for searchTask in self.executedSearchTasks: self.nbResult += len(searchTask.getResults()) if self.nbResult == 0: GObject.idle_add(self._view.imageWarning.show) GObject.idle_add(self._view.numberOfResultLabel.show) GObject.idle_add(self._view.numberOfResultLabel.set_label, _("No occurrence found.")) else: GObject.idle_add(self._view.imageWarning.hide) GObject.idle_add(self._view.numberOfResultLabel.show) label = ngettext("{0} occurrence found.", "{0} occurrences found.", self.nbResult).format(self.nbResult) GObject.idle_add(self._view.numberOfResultLabel.set_label, label) if not self.stopFlag and self.nbResult > 0: # if search has completed (not stopped), nav. is allowed GObject.idle_add(self._view.research_previous.set_sensitive, False) GObject.idle_add(self._view.research_next.set_sensitive, True) else: self.executedSearchTasks = None self.idResult = 0 self.searchRunning = False self.stopFlag = False GObject.idle_add(self._view.searchProgressBar.hide)
def search(self, pattern, typeOfPattern): # Initialize the searcher searcher = Searcher(self.project) # First we generate the different researched data searchedData = [] if typeOfPattern == Format.IP: searchedData.extend(searcher.getSearchedDataForIP(pattern)) if typeOfPattern == Format.BINARY: searchedData.extend(searcher.getSearchedDataForBinary(pattern)) if typeOfPattern == Format.OCTAL: searchedData.extend(searcher.getSearchedDataForOctal(pattern)) if typeOfPattern == Format.DECIMAL: searchedData.extend(searcher.getSearchedDataForDecimal(pattern)) if typeOfPattern == Format.HEX: searchedData.extend( searcher.getSearchedDataForHexadecimal(pattern)) if typeOfPattern == Format.STRING: searchedData.extend(searcher.getSearchedDataForString(pattern)) if len(searchedData) == 0: self.log.warn("No data to search after were computed.") return self.log.debug("The following data will be searched for:") for data in searchedData: self.log.info(" - " + str(data)) # Then we search them in the list of messages included in the vocabulary searchTasks = searcher.search(searchedData) self.log.info("A number of {0} results found!".format( str(len(searchTasks)))) # Colorize the segments self.colorizeResults(searchTasks) # Display the dedicated view self.updateView(searchTasks)
def envDepsSearch(self): """Search within symbol the environmental deps""" currentProject = self.vocabularyController.getCurrentProject() if currentProject is None: return # Create the Searcher searcher = Searcher(currentProject) # Retrieve all the possibles env dependencies (properties of messages And vocabulary env deps) envDeps = currentProject.getEnvironmentDependencies() # Search in the same time all the applicative data in the project appData = currentProject.getApplicativeData() for data in appData: print "data found" envDeps.append( Property(data.getName(), data.getType(), data.getValue())) # Create the search tasks self.searchTasks = [] for prop in envDeps: if prop.getFormat() == Format.STRING: self.log.debug("Search for String {0}...".format( prop.getCurrentValue())) self.searchTasks.extend( searcher.getSearchedDataForString( str(prop.getCurrentValue()))) elif prop.getFormat() == Format.IP: self.log.debug("Search for IP {0}...".format( prop.getCurrentValue())) self.searchTasks.extend( searcher.getSearchedDataForIP(prop.getCurrentValue())) else: self.log.warn( "A property with format {0} cannot be searched.".format( prop.getFormat()))
def search(self, text, format): """Execute the search process (to be executed in a dedicated thread)""" self.searchRunning = True symbols = self.vocabularyController.getCurrentProject().getVocabulary( ).getSymbols() # Reset the progress bar GObject.idle_add(self._view.searchProgressBar.show) GObject.idle_add(self._view.searchProgressBar.set_fraction, 0.0) # create a task for the text searcher = Searcher(self.vocabularyController.getCurrentProject(), self.updateProgessBar) # generate variations for each provided format (see glade file) if format == "string": searchTasks = searcher.getSearchedDataForString(text) elif format == "hexa": searchTasks = searcher.getSearchedDataForHexadecimal(text) elif format == "decimal": searchTasks = searcher.getSearchedDataForDecimal(text) elif format == "octal": searchTasks = searcher.getSearchedDataForOctal(text) elif format == "binary": searchTasks = searcher.getSearchedDataForBinary(text) elif format == "ipv4": searchTasks = searcher.getSearchedDataForIP(text) else: searchTasks = None self.log.error( "Cannot search for data if provided with type {0}".format( format)) if searchTasks is not None and len(searchTasks) > 0: self.executedSearchTasks = searcher.search(searchTasks) self.idResult = -1 self.nbResult = 0 for searchTask in self.executedSearchTasks: self.nbResult += len(searchTask.getResults()) if self.nbResult == 0: GObject.idle_add(self._view.imageWarning.show) GObject.idle_add(self._view.numberOfResultLabel.show) GObject.idle_add(self._view.numberOfResultLabel.set_label, _("No occurrence found.")) else: GObject.idle_add(self._view.imageWarning.hide) GObject.idle_add(self._view.numberOfResultLabel.show) label = ngettext("{0} occurrence found.", "{0} occurrences found.", self.nbResult).format(self.nbResult) GObject.idle_add(self._view.numberOfResultLabel.set_label, label) if not self.stopFlag and self.nbResult > 0: # if search has completed (not stopped), nav. is allowed GObject.idle_add(self._view.research_previous.set_sensitive, False) GObject.idle_add(self._view.research_next.set_sensitive, True) else: self.executedSearchTasks = None self.idResult = 0 self.searchRunning = False self.stopFlag = False GObject.idle_add(self._view.searchProgressBar.hide)