-
Notifications
You must be signed in to change notification settings - Fork 1
/
REFLECTION-permission-barchart-from-csv.py
100 lines (69 loc) · 2.83 KB
/
REFLECTION-permission-barchart-from-csv.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
87
88
89
90
91
92
93
94
95
96
97
98
99
import pandas as pd
import csv
import matplotlib.pyplot as plt
import numpy as np
from operator import itemgetter
file_path = "D:\\Androguard\\androguard-master\\reflection-encryption-permission-pattern.csv"
# data = pd.read_csv(file_path)
with open(file_path, 'r') as csv_reader:
reader = csv.reader(csv_reader)
headers = next(reader)
print('Header Length = ', len(headers))
permission = []
counter = []
for k in range(len(headers)):
with open(file_path, 'r') as csv_reader:
reader = csv.reader(csv_reader)
headers = next(reader)
count = 0
count2 = 0
for header in headers[k + 1:k + 2]:
# print(k+1, header)
for i in reader:
if count % 2 == 0:
pass
else:
# print(count1, 'no position', i[count1])
if i[k + 1] == '1':
count2 += 1
count += 1
# print(header, 'Found', count2, 'times')
permission.append(header)
counter.append(count2)
count2 = 0
# print(permission[::])
# print(counter[::])
print('Permission Length = ', len(permission))
print('Counter Length = ', len(counter))
a = dict(zip(permission, counter))
# print(sorted(a.values(), reverse=True))
print(sorted(a.items(), key=itemgetter(1), reverse=True)[:])
# counter = sorted(a.values(), reverse=True)[:50]
# counter = sorted(a.values(), reverse=True)[50:100]
counter = sorted(a.values(), reverse=True)[100:]
# index = np.arange(len(sorted(a.keys(), key=itemgetter(1), reverse=True)[:50]))
# index = np.arange(len(sorted(a.keys(), key=itemgetter(1), reverse=True)[50:100]))
index = np.arange(len(sorted(a.keys(), key=itemgetter(1), reverse=True)[100:]))
plt.bar(index, counter)
plt.xlabel('Permissions', fontsize=10)
plt.ylabel('No. of Occurrences', fontsize=10)
# plt.xticks(index[:50], sorted(a.items(), key=itemgetter(1), reverse=True)[:50], fontsize=5, rotation=90)
# plt.xticks(index[:50], sorted(a.items(), key=itemgetter(1), reverse=True)[50:100], fontsize=5, rotation=90)
plt.xticks(index[:53], sorted(a.items(), key=itemgetter(1), reverse=True)[100:], fontsize=5, rotation=90)
# plt.title('0 to 50 of 152 Reflection ENC. Permissions')
# plt.title('51 to 100 of 152 Reflection ENC. Permissions')
plt.title('101 to Last of 152 Reflection ENC. Permissions')
# plt.figure(figsize=(50*3.13, 4*3.13))
# mng = plt.get_current_fig_manager()
# mng.full_screen_toggle()
# plt.savefig('pattern.svg', orientation='portrait', quality=95)
plt.show()
# with open('reflection-enc-permission.txt', 'w', encoding='utf-8') as f:
# count = 1
# for i, j in sorted(a.items(), key=itemgetter(1), reverse=True):
# f.write(str(count)+' ')
# f.write(i)
# f.write(' >>> ')
# f.write(str(j))
# f.write('\n')
# count += 1