-
Notifications
You must be signed in to change notification settings - Fork 0
/
staticFeatureProcessor.py
executable file
·56 lines (44 loc) · 1.68 KB
/
staticFeatureProcessor.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
49
50
51
52
53
54
55
56
#!/usr/bin/env python
__author__ = 'AR'
import os, hashlib, json, sys, time
from collections import Counter
from datetime import datetime as dt
# Usage Message
if len(os.sys.argv) < 5:
print "Usage: ./staticfeatureProcessor -i <source to folder with strace files> -o <destination to store output files>"
os.sys.exit()
for i in xrange(len(sys.argv)):
if sys.argv[i] == '-i':
sourcePath = sys.argv[i + 1] # Path to folder containing strace files
if sys.argv[i] == '-o':
destPath = sys.argv[i + 1]
def main():
files = [x for x in os.listdir(sourcePath) if x.endswith('.static')]
featureDict = {}
# Define the keys for static features with values as list
if files:
for f in files:
with open(sourcePath + '\\' + f, 'r') as f:
for line in f.readlines():
if ':' in line:
featureDict[line[:line.index(':')]] = [] #line[33:-1]
# Adding values to the key's list
if files:
for f in files:
with open(sourcePath + '\\' + f, 'r') as f:
for line in f.readlines():
if ':' in line:
if line[33:-1] not in featureDict[line[:line.index(':')]]:
m = hashlib.sha256()
m.update(str(line[33:-1]))
featureDict[line[:line.index(':')]].append(m.hexdigest())
# Dumping the dictionaty to the
with open(destPath + 'StaticfeatureDict.json', 'w') as featureListFile:
json.dump(featureDict, featureListFile)
#print featureDict
if __name__=="__main__":
print '{:*^70}'.format(" Machine Learning and Malware Classification ")
main()
print '{:*^70}'.format('All Strace stored to ' + destPath + ' directory')
print
print '{:*^70}'.format(" EOP ")