-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEncodeFeatures.py
86 lines (56 loc) · 1.81 KB
/
EncodeFeatures.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 5 15:33:41 2018
@author: gowtham
"""
import os
import pandas as pd
from EncodeAFeature import encodeFeature
import ast
permissions = pd.read_csv('Permissions.csv', header = None)
permissions_l = list(permissions.iloc[:, 0].values)
uses_features = pd.read_csv('Uses-Features.csv', header = None)
uses_features_l = list(uses_features.iloc[:, 0].values)
actions = pd.read_csv('intents.csv', header = None)
actions_l = list(actions.iloc[:, 0].values)
cwd = os.getcwd()
dirs = os.listdir(cwd + "/malwareF")
dirs.remove("ENC")
x = 1
for tsv in dirs:
print str(x) + " - " + tsv
x = x+1
csvf = open("malwareF/ENC/" + tsv[:-4]+"_ENC.tsv", "w")
data = pd.read_csv("malwareF/" + tsv, sep = '\t')
for i in encodeFeature(data, permissions_l, 4, 548):
csvf.write(str(i) + "\t")
FeauX = data.iloc[:, 5].values
b = []
i = 0
while(not pd.isnull(FeauX[i]) and (not data.shape[0] == i+1) ):
dic = ast.literal_eval(FeauX[i])
if 'name' in dic.keys():
if dic['name'] in uses_features_l:
b.append(uses_features_l.index(dic['name']))
else:
b.append(73)
else:
b.append(73)
i = i +1
encoded_lst = []
for i in range(74):
encoded_lst.append(0)
for i in b:
encoded_lst[int(i)] = encoded_lst[int(i)] + 1
for i in encoded_lst:
csvf.write(str(i) + "\t")
FeauX = data.iloc[:, 0].values
b = []
i = 0
while(not pd.isnull(FeauX[i]) and (not data.shape[0] == i+1)):
i = i+1
csvf.write(str(i) + '\t')
for i in encodeFeature(data, actions_l, -1, 291):
csvf.write(str(i) + "\t")
csvf.close()