mirror of
https://github.com/MustardChef/WSABuilds.git
synced 2024-11-23 19:59:17 +01:00
80 lines
2.6 KiB
Python
80 lines
2.6 KiB
Python
#!/usr/bin/python
|
|
|
|
import sys
|
|
|
|
import urllib.request
|
|
import zipfile
|
|
import os
|
|
import json
|
|
import requests
|
|
from pathlib import Path
|
|
import platform
|
|
|
|
magisk_apk = sys.argv[2]
|
|
|
|
is_x86_64 = platform.machine() in ("AMD64", "x86_64")
|
|
host_abi = "x64" if is_x86_64 else "arm64"
|
|
|
|
if not os.path.exists(Path.cwd().parent / "download"):
|
|
os.makedirs(Path.cwd().parent / "download")
|
|
download_dir = Path.cwd().parent / "download"
|
|
|
|
if not os.path.exists(Path.cwd().parent / sys.argv[3] / "magisk"):
|
|
os.makedirs(Path.cwd().parent / sys.argv[3] / "magisk")
|
|
workdir = Path.cwd().parent / sys.argv[3] / "magisk"
|
|
|
|
if not magisk_apk:
|
|
magisk_apk = "stable"
|
|
if magisk_apk == "stable" or magisk_apk == "beta" or magisk_apk == "canary" or magisk_apk == "debug":
|
|
magisk_apk = json.loads(requests.get(
|
|
f"https://github.com/topjohnwu/magisk-files/raw/master/{magisk_apk}.json").content)['magisk']['link']
|
|
|
|
out_file = download_dir / "magisk.zip"
|
|
|
|
arch = sys.argv[1]
|
|
|
|
abi_map = {"x64": ["x86_64", "x86"], "arm64": ["arm64-v8a", "armeabi-v7a"]}
|
|
|
|
if not os.path.isfile(out_file):
|
|
urllib.request.urlretrieve(magisk_apk, out_file)
|
|
|
|
|
|
def extract_as(zip, name, as_name, dir):
|
|
info = zip.getinfo(name)
|
|
info.filename = as_name
|
|
zip.extract(info, workdir / dir)
|
|
|
|
|
|
with zipfile.ZipFile(out_file) as zip:
|
|
extract_as(
|
|
zip, f"lib/{ abi_map[arch][0] }/libmagisk64.so", "magisk64", "magisk")
|
|
extract_as(
|
|
zip, f"lib/{ abi_map[arch][1] }/libmagisk32.so", "magisk32", "magisk")
|
|
standalone_policy = False
|
|
try:
|
|
zip.getinfo(f"lib/{ abi_map[arch][0] }/libmagiskpolicy.so")
|
|
standalone_policy = True
|
|
except:
|
|
pass
|
|
extract_as(
|
|
zip, f"lib/{ abi_map[arch][0] }/libmagiskinit.so", "magiskinit", "magisk")
|
|
if standalone_policy:
|
|
extract_as(
|
|
zip, f"lib/{ abi_map[arch][0] }/libmagiskpolicy.so", "magiskpolicy", "magisk")
|
|
else:
|
|
extract_as(
|
|
zip, f"lib/{ abi_map[arch][0] }/libmagiskinit.so", "magiskpolicy", "magisk")
|
|
extract_as(
|
|
zip, f"lib/{ abi_map[arch][0] }/libmagiskboot.so", "magiskboot", "magisk")
|
|
extract_as(
|
|
zip, f"lib/{ abi_map[arch][0] }/libbusybox.so", "busybox", "magisk")
|
|
if standalone_policy:
|
|
extract_as(
|
|
zip, f"lib/{ abi_map[host_abi][0] }/libmagiskpolicy.so", "magiskpolicy", ".")
|
|
else:
|
|
extract_as(
|
|
zip, f"lib/{ abi_map[host_abi][0] }/libmagiskinit.so", "magiskpolicy", ".")
|
|
extract_as(zip, f"assets/boot_patch.sh", "boot_patch.sh", "magisk")
|
|
extract_as(zip, f"assets/util_functions.sh",
|
|
"util_functions.sh", "magisk")
|