def run(self):
searchhash = ''
if self.data_type == 'hash':
searchhash = self.getData()
if len(searchhash) != 32:
self.report({'isonvs': 'unknown',
'hash': searchhash})
elif self.data_type == 'file':
filepath = self.getParam('file')
hasher = hashlib.md5()
with io.open(filepath, mode='rb') as afile:
for chunk in iter(lambda: afile.read(65536), b''):
hasher.update(chunk)
searchhash = hasher.hexdigest()
else:
self.error('Unsupported data type.')
# Read files
for file in self.filelist:
filepath = os.path.join(self.path, file)
if not os.path.isfile(filepath):
continue
with io.open(filepath, 'r') as afile:
for line in afile:
# Skipping comments
if line[0] == '#':
continue
if searchhash.lower() in line:
self.report({'isonvs': True,
'md5': searchhash})
self.report({'isonvs': False,
'md5': searchhash})
评论列表
文章目录