-
Notifications
You must be signed in to change notification settings - Fork 0
/
apkdiff-analyzer.py
executable file
·96 lines (80 loc) · 2.19 KB
/
apkdiff-analyzer.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
#!/usr/bin/python3
from sys import argv
def get_new_types(app):
types = []
with open(app + '-apkdiff.txt') as f:
in_types_section = False
for line in f:
line = line.strip()
if not in_types_section:
if line == '∆|value':
in_types_section = True
continue
if line == '':
break
if line.startswith('+') or '[]' in line:
continue
types.append(line[2:])
return types
def get_real_names(app):
names = {}
with open(app + '-proguard.map') as f:
for line in f:
if line[0] == ' ':
continue
line = line.strip()
split = line.split(' -> ')
names[split[0]] = split[1][0:-1]
return names
def get_sizes(app):
sizes = {}
with open(app + '-dex2jar.txt') as f:
for line in f:
split = line.strip().split(' ')
# print('%s:%d' % (split[7].split('.')[0], int(split[0].strip())))
sizes[split[7].split('.')[0].replace('/', '.')] = int(split[0].strip())
return sizes
class Type():
def __init__(self, name, size):
self._name = name
self._size = size
def __lt__(self, other):
return self._size < other._size
def __str__(self):
return '%-10d: %s' % (self._size, self._name)
if __name__ == '__main__':
app = argv[1]
sizes = get_sizes(app)
type_names = get_new_types(app)
names = get_real_names(app)
types = []
for type in type_names:
if type in names:
name = names[type]
else:
name = type
if name in sizes:
types.append(Type(type, sizes[name]))
elif not (name.startswith('java') or name.startswith('android') or name.endswith('package-info')):
print('%s not found' % name)
types.sort()
total = 0
package_map = {}
print("Classes:")
for type in reversed(types):
total += type._size
package = type._name[0:type._name.rfind('.')]
if package in package_map:
size = package_map[package]
else:
size = 0
package_map[package] = size + type._size
print(type)
packages = []
for package, size in package_map.items():
packages.append(Type(package, size))
packages.sort()
print("\nPackages:")
for package in reversed(packages):
print(package)
print("\nTotal: %d" % total)