forked from GrapheneOS/apps.grapheneos.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.py
executable file
·81 lines (63 loc) · 2.76 KB
/
generate.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
#!/usr/bin/env python3
import datetime
import hashlib
import json
import os
import shlex
import shutil
import subprocess
from pathlib import Path
channels = "stable", "beta", "alpha"
apps = {}
for channel in channels:
top = "apps-" + channel
for src in sorted(os.listdir(top)):
metadata = {"label": "", "versionCode": -1, "dependencies": [], "packages": [], "hashes": []}
src_dir = os.path.join(top, src)
src_packages = os.listdir(src_dir)
if len(src_packages) == 1:
base_apk = src_packages[0]
else:
base_apk = "base.apk"
badging = subprocess.check_output(["aapt2", "dump", "badging", os.path.join(src_dir, base_apk)])
lines = badging.split(b"\n")
for kv in shlex.split(lines[0].decode()):
if kv.startswith("versionCode"):
version_code = int(kv.split("=")[1])
metadata["versionCode"] = version_code
elif kv.startswith("name"):
app_id = kv.split("=")[1]
for line in lines[1:-1]:
kv = shlex.split(line.decode())
if kv[0].startswith("application-label:"):
metadata["label"] = kv[0].split(":")[1]
elif kv[0].startswith("uses-static-library:"):
metadata["dependencies"].append(kv[1].split("=")[1])
elif kv[0].startswith("sdkVersion"):
metadata["minSdkVersion"] = int(kv[0].split(":")[1])
if src in ("com.android.vending.33", "com.google.android.gms.33"):
metadata["minSdkVersion"] = 33
if app_id == "com.google.android.gms":
metadata["dependencies"] = ["com.google.android.gsf"]
elif app_id == "com.android.vending":
metadata["dependencies"] = ["com.google.android.gsf", "com.google.android.gms"]
if app_id == "app.grapheneos.pdfviewer":
metadata["originalPackage"] = "org.grapheneos.pdfviewer"
app_dir = os.path.join("apps", "packages", app_id, str(version_code))
assert os.path.isdir(app_dir)
for package in sorted(os.listdir(app_dir)):
if not package.endswith(".apk"):
continue
h = hashlib.new("sha256")
with open(os.path.join(app_dir, package), "rb") as f:
h.update(f.read())
metadata["hashes"].append(h.hexdigest())
metadata["packages"].append(package)
apps.setdefault(app_id, {}).setdefault(channel, []).append(metadata)
metadata = {
"time": int(datetime.datetime.utcnow().timestamp()),
"apps": apps
}
with open("apps/metadata.0.json", "w") as f:
json.dump(metadata, f, separators=(',', ':'))
subprocess.check_output(["signify", "-S", "-s", "apps.0.sec", "-m", "apps/metadata.0.json", "-x", "apps/metadata.0.json.0.sig"])