blob: 6ace3876a4e5f0f98c5c3d15423acefd3e19c120 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
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)
|