-
Notifications
You must be signed in to change notification settings - Fork 2
/
getSDKVersion.py
74 lines (61 loc) · 1.95 KB
/
getSDKVersion.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
# apt dump badging *.apk|grep Version
import os
import re
import subprocess
def getFileList(rootDir, pickstr):
filePath = []
for parent, dirnames, filenames in os.walk(rootDir):
for filename in filenames:
if pickstr in filename:
file = os.path.join(parent, filename)
filePath.append(file)
return filePath
def getSDK(apkpath):
try:
AAPT_CMD = "aapt dump badging " + apkpath + "| grep Version"
# sdkVersion:'19'
# targetSdkVersion:'28'
output = subprocess.check_output(AAPT_CMD, shell=True, timeout=20)
except subprocess.TimeoutExpired as exc:
print("Command timed out: {}".format(exc))
return
except subprocess.CalledProcessError as e:
output = e.output # Output generated before error
code = e.returncode # Return code
return
aapt_output = output.decode('utf-8')
min = re.findall(r"sdkVersion:'([0-9]+)'", aapt_output)
if min:
minSdk = min[0]
else:
return
target = re.findall(r"targetSdkVersion:'([0-9]+)'", aapt_output)
if target:
targetSdk = target[0]
else:
return
print(minSdk, targetSdk)
return minSdk, targetSdk
if __name__ == "__main__":
min1 = {}
target = {}
APKPATH = "/data/sdc/username/APK2020"
files = getFileList(APKPATH, ".apk")
print(len(files))
for file in files:
try:
minSdk, targetSdk = getSDK(file)
if minSdk and targetSdk:
sha256 = os.path.split(file)[-1][:-4]
min1[sha256] = minSdk
target[sha256] = targetSdk
except Exception as e:
print(file)
print(e)
continue
print(len(min1))
with open("/data/sdc/username/APIMatchmaker/minSdkVersion.txt", "w") as fw:
for sha256 in min1:
fw.write(sha256 + " ")
fw.write(str(min1[sha256]))
fw.write("\n")