-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathfeatures_extraction.py
More file actions
42 lines (38 loc) · 1.18 KB
/
features_extraction.py
File metadata and controls
42 lines (38 loc) · 1.18 KB
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
'''
Extracting features from every file,
and counting the number of its occurrences
'''
features_set = {
"feature": 1,
"permission": 2,
"activity": 3,
"service_receiver": 3,
"provider": 3,
"service": 3,
"intent": 4,
"api_call": 5,
"real_permission": 6,
"call": 7,
"url": 8
}
def extract_features(file_content):
# list to have the occurrences of each feature in this file,
# initially filled with zeros
features_occurrences = {el: 0 for el in range(1, 9)}
# looping over file content
for line in file_content:
# take only lines with set and feature
# e.g. set is 'url' and feature is 'http://10.0.0.172/'
# if line != '\n':
line_set = line.split('::')[0]
# increment counter for this feature set found
temp_var = features_set.get(line_set, None)
if(temp_var is not None):
features_occurrences[temp_var] += 1
# returning copy of the features map
# we created features_occurrences as a dictionary, changing it to a list
# before returning it
features = []
for i in range(1, 9):
features.append(features_occurrences[i])
return features