forked from opengapps/apkcrawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apkhelper.py
176 lines (149 loc) · 7.26 KB
/
apkhelper.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
from functools import total_ordering
import logging
import re
oneVariantPerRealver = {'com.google.android.apps.books',
'com.google.android.apps.cloudprint',
'com.google.android.apps.enterprise.dmagent',
'com.google.android.apps.gcs',
'com.google.android.apps.genie.geniewidget',
'com.google.android.apps.turbo',
'com.google.android.calculator',
'com.google.android.calendar',
'com.google.android.deskclock',
'com.google.android.ears',
'com.google.android.gm',
'com.google.android.gm.exchange',
'com.google.android.marvin.talkback',
'com.google.android.music',
'com.google.android.tv.remote'}
oneVercodePerRealver = {'com.google.android.apps.docs',
'com.google.android.apps.docs.editors.docs',
'com.google.android.apps.docs.editors.sheets',
'com.google.android.apps.docs.editors.slides',
'com.google.android.apps.fitness',
'com.google.android.apps.inputmethod.hindi',
'com.google.android.apps.inputmethod.zhuyin',
'com.google.android.apps.messaging',
'com.google.android.apps.tycho',
'com.google.android.gms',
'com.google.android.googlecamera',
'com.google.android.googlequicksearchbox',
'com.google.android.inputmethod.japanese',
'com.google.android.inputmethod.korean',
'com.google.android.inputmethod.latin',
'com.google.android.inputmethod.pinyin',
'com.google.android.keep',
'com.google.android.play.games',
'com.google.android.tv'}
@total_ordering
class ApkVersionInfo(object):
"""ApkVersionInfo"""
def __init__(self, name='', arch='', sdk='', target='', dpi='', ver='', vercode='', scrape_src='', download_src='', crawler_name='unknown', malware=''):
super(ApkVersionInfo, self).__init__()
sName = '^(?P<name>.*)(?P<extra>\.(leanback|beta|stub|vrmode|default|tablet|watch))$'
reName = re.compile(sName)
sVer = '^(?P<ver>[^\s-]*)(?P<extra>([\s-].*|(\.(arm|arm\.arm_neon|arm64|x86|large|small))))$' # .release?
reVer = re.compile(sVer)
self.name = name
self.lowername = name.lower()
self.extraname = None # used for beta/leanback versions
self.arch = arch
self.sdk = 0 if sdk == '' else sdk
try:
self.sdk = int(self.sdk)
except:
pass
self.target = 0 if target == '' else target
try:
self.target = int(self.target)
except:
pass
self.dpi = dpi
self.ver = ver # used for comparing (could be shortened later)
self.realver = ver # used for full/original versions
self.vercode = 0 if vercode == '' else int(vercode)
self.scrape_src = scrape_src
self.download_src = download_src
self.crawler_name = crawler_name
self.malware = malware
m = reName.match(self.name)
if m:
self.extraname = self.name
self.name = m.group('name')
# Let's keep .beta its own package for now
if m.group('extra') == '.beta':
self.name = self.extraname
m = reVer.match(self.ver)
if m:
self.ver = m.group('ver')
if ('com.google.android.projection.gearhead' in self.name):
self.ver = '.'.join(self.ver.split('.')[0:2])
if ('com.google.android.apps.classroom' in self.name or
'com.google.android.apps.docs' in self.name or
'com.google.android.apps.pdfviewer' in self.name or
'com.google.android.keep' in self.name):
self.ver = '.'.join(self.ver.split('.')[0:4])
# END: def init
def fullString(self, max):
mymax = max
if self.realver != self.ver:
mymax += self.realver[len(self.ver):]
return '{0}|{1}|{2}|{3}|{4}|{5}'.format(self.name,
self.arch,
self.sdk,
self.dpi,
mymax,
self.vercode)
# END: def fullString
def getFilename(self):
return '{0}-{1}.apk'.format(self.lowername, '[{0}]'.format(self.crawler_name) if self.vercode == 0 else str(self.vercode))
# END: def getFilename
def isRealverAbsolute(self):
return (self.name in oneVariantPerRealver) or (self.name in oneVercodePerRealver)
def isVercodeAbsolute(self):
return (self.name in oneVariantPerRealver)
def __lt__(self, other):
if self.ver == '':
logging.error('AVI.cmp(): self.ver is empty [{0}]'.format(self.ver))
return NotImplemented
elif other.ver == '':
logging.error('AVI.cmp(): other.ver is empty [{0}]'.format(other.ver))
return NotImplemented
else:
# Make blank-->'0', replace - and _ with . and split into parts
ps = [int(x if x != '' else '0') for x in re.sub('[A-Za-z]+', '', self.ver.replace('-', '.').replace('_', '.')).split('.')]
po = [int(x if x != '' else '0') for x in re.sub('[A-Za-z]+', '', other.ver.replace('-', '.').replace('_', '.')).split('.')]
# fill up the shorter version with zeros ...
lendiff = len(ps) - len(po)
if lendiff > 0:
po.extend([0] * lendiff)
elif lendiff < 0:
ps.extend([0] * (-lendiff))
for i, p in enumerate(ps):
if p != po[i]:
return p < po[i]
return ps < po
# END: def __lt__
def __eq__(self, other):
if self.ver == '':
logging.error('AVI.cmp(): self.ver is empty [{0}]'.format(self.ver))
return NotImplemented
elif other.ver == '':
logging.error('AVI.cmp(): other.ver is empty [{0}]'.format(other.ver))
return NotImplemented
else:
import re
# Make blank-->'0', replace - and _ with . and split into parts
ps = [int(x if x != '' else '0') for x in re.sub('[A-Za-z]+', '', self.ver.replace('-', '.').replace('_', '.')).split('.')]
po = [int(x if x != '' else '0') for x in re.sub('[A-Za-z]+', '', other.ver.replace('-', '.').replace('_', '.')).split('.')]
# fill up the shorter version with zeros ...
lendiff = len(ps) - len(po)
if lendiff > 0:
po.extend([0] * lendiff)
elif lendiff < 0:
ps.extend([0] * (-lendiff))
return ps == (po)
# END: def __eq__
def __str__(self):
return str(self.__dict__)
# END: class ApkVersionInfo