import ConfigParser import pickle class ScanModule(object): def __init__(self): self.config = ConfigParser.ConfigParser() self.config.read('modules.conf') self.samples = dict() try: self.populate(self.config.get(self.name, 'samples')) except ConfigParser.NoOptionError: pass try: self.load(self.config.get(self.name, 'persistence')) except ConfigParser.NoOptionError: pass def is_disable(self): try: return self.config.getboolean(self.name, 'disable') except ConfigParser.NoOptionError: return False def evaluate(self, path): ''' Return in percent, the probability that the file is a malware @param path File to evaluate ''' raise NotImplemented def populate(self, path): ''' Populate the module's internal database with data from the given path @param path Path to the data ''' raise NotImplemented def load(self, path): ''' Unpickle the given path, and updates the samples dict with it. @param path Path to the dict to unpickle ''' with open(path, 'r') as f: self.samples.update(pickle.load(f)) def save(self, path): ''' Save the database to the given file @param path Path where to save the database ''' with open(path, 'w') as f: pickle.dump(self.samples, f)