-
Notifications
You must be signed in to change notification settings - Fork 43
/
utils.py
48 lines (43 loc) · 1.41 KB
/
utils.py
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
import hashlib
import magic
import pydeep
import ConfigParser
import json
import os
def get_configuration(config_file):
config = ConfigParser.SafeConfigParser()
try:
config.read(config_file)
return config
except Exception, err:
print "%s - %s" %(Exception, err)
def initialize_environment(config):
# Create malwarehouse root directory
base_dir = os.path.expanduser(config.get('settings', 'basedir'))
try:
if not os.path.exists(base_dir):
os.makedirs(base_dir)
return True
except Exception, err:
print err
return False
def parse_sqlite_result(unparsed):
"Takes the results from a SQLite query and parses it as a dictionary."
return unparsed
return {'datetime': unparsed[0], 'name': unparsed[1], 'mimetype': unparsed[2], 'tags': unparsed[3], 'size': unparsed[4], 'md5': unparsed[5], 'sha256': unparsed[6], 'source': unparsed[7], 'notes': unparsed[8]}
def get_json(dictionary):
return json.dumps(dictionary
)
def get_mimetype(malware_path):
"""Finds the standard mimetype for file and returns type name."""
mime = magic.Magic(mime=True)
return mime.from_file(malware_path)
def __json__(self):
print "JSON would have been returned."
pass
def __str__(self):
return self.summary()
def first(iterable, default=None):
for item in iterable:
return item
return default