From d2db80bcbad9596a317a3a4a32d39886a15a5222 Mon Sep 17 00:00:00 2001 From: Anthony Nelson <67963151+daPharaoh@users.noreply.github.com> Date: Wed, 9 Mar 2022 02:50:26 -0500 Subject: [PATCH] Initial commit --- .github/FUNDING.yml | 1 + .github/workflows/magisk.yml | 590 ++++++++++++++++ LICENSE | 661 ++++++++++++++++++ README.md | 96 +++ .../priv-app/SetupWizard/SetupWizard.apk | Bin 0 -> 5740166 bytes .../product/overlay/GoogleWebViewOverlay.apk | Bin 0 -> 20911 bytes .../ExternalStorageProvider.apk | Bin 0 -> 61854 bytes .../system/priv-app/WSAHelper/WSAHelper.apk | Bin 0 -> 5854 bytes .../msxml6/msxml6-KB973686-enu-amd64.exe | Bin 0 -> 1862488 bytes wine/makepri.exe | Bin 0 -> 1457672 bytes .../priv-app/SetupWizard/SetupWizard.apk | Bin 0 -> 5703365 bytes .../product/overlay/GoogleWebViewOverlay.apk | Bin 0 -> 20911 bytes .../ExternalStorageProvider.apk | Bin 0 -> 61854 bytes .../system/priv-app/WSAHelper/WSAHelper.apk | Bin 0 -> 5854 bytes 14 files changed, 1348 insertions(+) create mode 100644 .github/FUNDING.yml create mode 100644 .github/workflows/magisk.yml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 arm64/gapps/priv-app/SetupWizard/SetupWizard.apk create mode 100644 arm64/gapps/product/overlay/GoogleWebViewOverlay.apk create mode 100644 arm64/system/system/priv-app/ExternalStorageProvider/ExternalStorageProvider.apk create mode 100755 arm64/system/system/priv-app/WSAHelper/WSAHelper.apk create mode 100755 wine/.cache/winetricks/msxml6/msxml6-KB973686-enu-amd64.exe create mode 100755 wine/makepri.exe create mode 100644 x64/gapps/priv-app/SetupWizard/SetupWizard.apk create mode 100644 x64/gapps/product/overlay/GoogleWebViewOverlay.apk create mode 100644 x64/system/system/priv-app/ExternalStorageProvider/ExternalStorageProvider.apk create mode 100755 x64/system/system/priv-app/WSAHelper/WSAHelper.apk diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..39bc9a9 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: [yujincheng08] diff --git a/.github/workflows/magisk.yml b/.github/workflows/magisk.yml new file mode 100644 index 0000000..2fe9726 --- /dev/null +++ b/.github/workflows/magisk.yml @@ -0,0 +1,590 @@ +name: Build WSA +on: + push: + paths-ignore: + - 'README.md' + pull_request: + paths-ignore: + - 'README.md' + workflow_dispatch: + inputs: + arch: + description: "Build arch" + required: true + default: "x64 & arm64" + type: choice + options: + - x64 + - arm64 + - x64 & arm64 + magisk_apk: + description: "Magisk version" + required: true + default: "stable" + type: choice + options: + - stable + - beta + - canary + gapps_variant: + description: "Variants of gapps" + required: true + default: "none" + type: choice + options: + - none + - super + - stock + - full + - mini + - micro + - nano + - pico + - tvstock + - tvmini + root_sol: + description: "Root solution" + required: true + default: "magisk" + type: choice + options: + - magisk + - none + +jobs: + matrix: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - name: Generate build matrix + id: set-matrix + uses: actions/github-script@v6 + with: + script: | + let matrix = {}; + let arch = "${{ github.event.inputs.arch }}" + switch ( arch ) { + case "x64": + matrix.arch = ["x64"]; + break; + case "arm64": + matrix.arch = ["arm64"]; + break; + default: + matrix.arch = ["x64", "arm64"]; + break; + } + core.setOutput("matrix",JSON.stringify(matrix)); + + build: + runs-on: ubuntu-20.04 + needs: matrix + strategy: + matrix: ${{fromJson(needs.matrix.outputs.matrix)}} + steps: + - name: Dependencies + run: | + pip3 install beautifulsoup4 lxml + sudo apt-get update && sudo apt-get install setools lzip qemu-utils wine winetricks + wget -qO- "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/archive/$GITHUB_REF.tar.gz" | sudo tar --wildcards -zxvf- -C ~ --strip-component=2 '*/wine/*' + winetricks msxml6 + - name: Download WSA + shell: python + run: | + import requests + from bs4 import BeautifulSoup + import re + import zipfile + import os + import urllib.request + + arch = "${{ matrix.arch }}" + + res = requests.post("https://store.rg-adguard.net/api/GetFiles", "type=CategoryId&url=858014f3-3934-4abe-8078-4aa193e74ca8&ring=WIS&lang=en-US", headers={ + "content-type": "application/x-www-form-urlencoded" + }) + html = BeautifulSoup(res.content, "lxml") + + a = html.find("a", string=re.compile(f"Microsoft\.UI\.Xaml\..*_{arch}_.*\.appx")) + link = a["href"] + print(f"downloading link: {link}", flush=True) + out_file = "xaml.appx" + if not os.path.isfile(out_file): + urllib.request.urlretrieve(link, out_file) + + a = html.find("a", string=re.compile(f"Microsoft\.VCLibs\..*_{arch}_.*\.appx")) + link = a["href"] + print(f"downloading link: {link}", flush=True) + out_file = "vclibs.appx" + if not os.path.isfile(out_file): + urllib.request.urlretrieve(link, out_file) + + a = html.find("a", string=re.compile("MicrosoftCorporationII\.WindowsSubsystemForAndroid_.*\.msixbundle")) + link = a["href"] + print(f"downloading link: {link}", flush=True) + out_file = "wsa.zip" + if not os.path.isfile(out_file): + urllib.request.urlretrieve(link, out_file) + + zip_name = "" + with zipfile.ZipFile(out_file) as zip: + for f in zip.filelist: + if arch in f.filename.lower(): + zip_name = f.filename + if not os.path.isfile(zip_name): + print(f"unzipping to {zip_name}", flush=True) + zip.extract(f) + ver_no = zip_name.split("_") + ver = ver_no[1] + with open(os.environ['GITHUB_ENV'], 'a') as g: + g.write(f'WSA_VER={ver}\n') + rel = ver_no[3].split(".") + rell = str(rel[0]) + with open(os.environ['GITHUB_ENV'], 'a') as g: + g.write(f'WSA_REL={rell}\n') + if 'language' in f.filename.lower() or 'scale' in f.filename.lower(): + name = f.filename.split("-", 1)[1].split(".")[0] + zip.extract(f) + with zipfile.ZipFile(f.filename) as l: + for g in l.filelist: + if g.filename == 'resources.pri': + g.filename = f'{name}.pri' + l.extract(g, 'pri') + print(f"extract resource pack {g.filename}") + elif g.filename == 'AppxManifest.xml': + g.filename = f'{name}.xml' + l.extract(g, 'xml') + + with zipfile.ZipFile(zip_name) as zip: + if not os.path.isdir(arch): + print(f"unzipping from {zip_name}", flush=True) + zip.extractall(arch) + + print("done", flush=True) + - name: Download Magisk + shell: python + run: | + import urllib.request + import zipfile + import os + import json + import requests + + magisk_apk = """${{ github.event.inputs.magisk_apk }}""" + + if not magisk_apk: + magisk_apk = "stable" + if magisk_apk == "stable" or magisk_apk == "beta" or magisk_apk == "canary": + magisk_apk = json.loads(requests.get(f"https://github.com/topjohnwu/magisk-files/raw/master/{magisk_apk}.json").content)['magisk']['link'] + + out_file = "magisk.zip" + + arch = "${{ matrix.arch }}" + + 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, 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") + extract_as(zip, f"lib/{ abi_map[arch][0] }/libmagiskinit.so", "magiskinit", "magisk") + 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") + extract_as(zip, f"lib/{ abi_map['x64'][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") + - name: Download OpenGApps + if: ${{ github.event.inputs.gapps_variant != 'none' && github.event.inputs.gapps_variant != '' }} + shell: python + run: | + import requests + import zipfile + import os + import urllib.request + import json + import re + + arch = "${{ matrix.arch }}" + variant = "${{ github.event.inputs.gapps_variant }}" + abi_map = {"x64" : "x86_64", "arm64": "arm64"} + try: + res = requests.get(f"https://api.opengapps.org/list") + j = json.loads(res.content) + link = {i["name"]: i for i in j["archs"][abi_map[arch]]["apis"]["11.0"]["variants"]}[variant]["zip"] + except Exception: + print("Failed to fetch from opengapps api, fallbacking to sourceforge rss...") + res = requests.get(f'https://sourceforge.net/projects/opengapps/rss?path=/{abi_map[arch]}&limit=100') + link = re.search(f'https://.*{abi_map[arch]}/.*{variant}.*\.zip/download', res.text).group().replace('.zip/download', '.zip').replace('sourceforge.net/projects/opengapps/files', 'downloads.sourceforge.net/project/opengapps') + + print(f"downloading link: {link}", flush=True) + + out_file = "gapps.zip" + + if not os.path.isfile(out_file): + urllib.request.urlretrieve(link, out_file) + print("done", flush=True) + + - name: Extract GApps and expand images + if: ${{ github.event.inputs.gapps_variant != 'none' && github.event.inputs.gapps_variant != '' }} + run: | + mkdir gapps + unzip -p gapps.zip {Core,GApps}/'*.lz' | tar --lzip -C gapps -xvf - -i --strip-components=2 --exclude='setupwizardtablet-x86_64' --exclude='packageinstallergoogle-all' --exclude='speech-common' --exclude='markup-lib-arm' --exclude='markup-lib-arm64' --exclude='markup-all' --exclude='setupwizarddefault-x86_64' --exclude='pixellauncher-all' --exclude='pixellauncher-common' + + e2fsck -yf ${{ matrix.arch }}/system.img + resize2fs ${{ matrix.arch }}/system.img $(( $(du -sB512 gapps | cut -f1) + $(du -sB512 ${{ matrix.arch }}/system.img | cut -f1) ))s + e2fsck -yf ${{ matrix.arch }}/product.img + resize2fs ${{ matrix.arch }}/product.img 1024M + e2fsck -yf ${{ matrix.arch }}/system_ext.img + resize2fs ${{ matrix.arch }}/system_ext.img 108M + - name: Expand vendor + run: | + e2fsck -yf ${{ matrix.arch }}/vendor.img + resize2fs ${{ matrix.arch }}/vendor.img 320M + - name: Mount images + run: | + sudo mkdir system + sudo mkdir userdata + sudo mount -o loop ${{ matrix.arch }}/system.img system + sudo mount -o loop ${{ matrix.arch }}/vendor.img system/vendor + sudo mount -o loop ${{ matrix.arch }}/product.img system/product + sudo mount -o loop ${{ matrix.arch }}/system_ext.img system/system_ext + qemu-img convert -O raw ${{ matrix.arch }}/userdata.vhdx userdata.img + sudo mount -o loop userdata.img userdata + - name: Integrate Magisk + if: ${{ github.event.inputs.root_sol == 'magisk' || github.event.inputs.root_sol == '' }} + run: | + sudo mkdir system/sbin + sudo chcon --reference system/init.environ.rc system/sbin + sudo chown root:root system/sbin + sudo chmod 0700 system/sbin + sudo cp magisk/* system/sbin/ + sudo mkdir -p userdata/adb/magisk + sudo chmod -R 700 userdata/adb + sudo cp magisk/* userdata/adb/magisk/ + sudo find userdata/adb/magisk -type f -exec chmod 0755 {} \; + sudo cp magisk.zip userdata/adb/magisk/magisk.apk + sudo tee -a system/sbin/loadpolicy.sh < + + + + + + + EOF + wine64 ~/makepri.exe new /pr pri /in MicrosoftCorporationII.WindowsSubsystemForAndroid /cf priconfig.xml /of ${{ matrix.arch }}/resources.pri /o + sed -i -zE "s//\n$(cat xml/* | grep -Po ']*/>' | sed ':a;N;$!ba;s/\n/\\n/g' | sed 's/\$/\\$/g' | sed 's/\//\\\//g')\n<\/Resources>/g" ${{ matrix.arch }}/AppxManifest.xml + - name: Add extra packages + run: | + wget -qO- "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/archive/$GITHUB_REF.tar.gz" | sudo tar --wildcards -zxvf- --strip-component=2 '*/${{ matrix.arch }}/system/*' + sudo find system/system/priv-app -type d -exec chmod 0755 {} \; + sudo find system/system/priv-app -type f -exec chmod 0644 {} \; + sudo find system/system/priv-app -exec chcon --reference=system/system/priv-app {} \; + - name: Integrate GApps + if: ${{ github.event.inputs.gapps_variant != 'none' && github.event.inputs.gapps_variant != '' }} + run: | + wget -qO- "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/archive/$GITHUB_REF.tar.gz" | sudo tar --wildcards -zxvf- --strip-component=2 '*/${{ matrix.arch }}/gapps/*' + shopt -s extglob + sudo cp -vr gapps/!(product) system/system + sudo cp -vr gapps/product/* system/product/ + + sudo find system/system/{app,etc,framework,priv-app} -exec chown root:root {} \; + sudo find system/product/{app,etc,overlay,priv-app} -exec chown root:root {} \; + + sudo find system/system/{app,etc,framework,priv-app} -type d -exec chmod 0755 {} \; + sudo find system/product/{app,etc,overlay,priv-app} -type d -exec chmod 0755 {} \; + + sudo find system/system/{app,framework,priv-app} -type f -exec chmod 0644 {} \; + ls gapps/etc/ | xargs -n 1 -I dir sudo find system/system/etc/dir -type f -exec chmod 0644 {} \; + sudo find system/product/{app,etc,overlay,priv-app} -type f -exec chmod 0644 {} \; + + sudo find system/system/{app,framework,priv-app} -type d -exec chcon --reference=system/system/app {} \; + sudo find system/product/{app,etc,overlay,priv-app} -type d -exec chcon --reference=system/product/app {} \; + ls gapps/etc/ | xargs -n 1 -I dir sudo find system/system/etc/dir -type d -exec chcon --reference=system/system/etc/permissions {} \; + + sudo find system/system/{app,framework,priv-app} -type f -exec chcon --reference=system/system/framework/ext.jar {} \; + ls gapps/etc/ | xargs -n 1 -I dir sudo find system/system/etc/dir -type f -exec chcon --reference=system/system/etc/permissions {} \; + sudo find system/product/{app,etc,overlay,priv-app} -type f -exec chcon --reference=system/product/etc/permissions/privapp-permissions-venezia.xml {} \; + chmod +x ./magiskpolicy + sudo ./magiskpolicy --load system/vendor/etc/selinux/precompiled_sepolicy --save system/vendor/etc/selinux/precompiled_sepolicy "allow gmscore_app gmscore_app vsock_socket { create connect write read }" "allow gmscore_app device_config_runtime_native_boot_prop file read" "allow gmscore_app system_server_tmpfs dir search" "allow gmscore_app system_server_tmpfs file open" + - name: Fix GApps prop + if: ${{ github.event.inputs.gapps_variant != 'none' && github.event.inputs.gapps_variant != '' }} + shell: sudo python {0} + run: | + from __future__ import annotations + from io import TextIOWrapper + from os import system + from typing import OrderedDict + + + class Prop(OrderedDict): + def __init__(self, file: TextIOWrapper) -> None: + super().__init__() + for i, line in enumerate(file.read().splitlines(False)): + if '=' in line: + k, v = line.split('=', 2) + self[k] = v + else: + self[f".{i}"] = line + + def __str__(self) -> str: + return '\n'.join([v if k.startswith('.') else f"{k}={v}" for k, v in self.items()]) + + def __iadd__(self, other: str) -> Prop: + self[f".{len(self)}"] = other + return self + + + new_props = { + ("product", "brand"): "google", + ("product", "manufacturer"): "Google", + ("build", "product"): "redfin", + ("product", "name"): "redfin", + ("product", "device"): "redfin", + ("product", "model"): "Pixel 5", + ("build", "flavor"): "redfin-user" + } + + + def description(sec: str, p: Prop) -> str: + return f"{p[f'ro.{sec}.build.flavor']} {p[f'ro.{sec}.build.version.release_or_codename']} {p[f'ro.{sec}.build.id']} {p[f'ro.{sec}.build.version.incremental']} {p[f'ro.{sec}.build.tags']}" + + + def fingerprint(sec: str, p: Prop) -> str: + return f"""{p[f"ro.product.{sec}.brand"]}/{p[f"ro.product.{sec}.name"]}/{p[f"ro.product.{sec}.device"]}:{p[f"ro.{sec}.build.version.release"]}/{p[f"ro.{sec}.build.id"]}/{p[f"ro.{sec}.build.version.incremental"]}:{p[f"ro.{sec}.build.type"]}/{p[f"ro.{sec}.build.tags"]}""" + + + def fix_prop(sec, prop): + print(f"fixing {prop}", flush=True) + with open(prop, 'r') as f: + p = Prop(f) + + p += "# extra prop added by MagiskOnWSA" + + for k, v in new_props.items(): + p[f"ro.{k[0]}.{k[1]}"] = v + + if k[0] == "build": + p[f"ro.{sec}.{k[0]}.{k[1]}"] = v + elif k[0] == "product": + p[f"ro.{k[0]}.{sec}.{k[1]}"] = v + + p["ro.build.description"] = description(sec, p) + p[f"ro.build.fingerprint"] = fingerprint(sec, p) + p[f"ro.{sec}.build.description"] = description(sec, p) + p[f"ro.{sec}.build.fingerprint"] = fingerprint(sec, p) + p[f"ro.bootimage.build.fingerprint"] = fingerprint(sec, p) + + with open(prop, 'w') as f: + f.write(str(p)) + + for sec, prop in {"system": "system/system/build.prop", "product": "system/product/build.prop", "system_ext": "system/system_ext/build.prop", "vendor": "system/vendor/build.prop", "odm": "system/vendor/odm/etc/build.prop"}.items(): + fix_prop(sec, prop) + - name: Umount images + run: | + sudo umount system/vendor + sudo umount system/product + sudo umount system/system_ext + sudo umount system + sudo umount userdata + qemu-img convert -o subformat=dynamic -f raw -O vhdx userdata.img ${{ matrix.arch }}/userdata.vhdx + - name: Shrink images + run: | + e2fsck -yf ${{ matrix.arch }}/system.img + resize2fs -M ${{ matrix.arch }}/system.img + e2fsck -yf ${{ matrix.arch }}/vendor.img + resize2fs -M ${{ matrix.arch }}/vendor.img + e2fsck -yf ${{ matrix.arch }}/product.img + resize2fs -M ${{ matrix.arch }}/product.img + e2fsck -yf ${{ matrix.arch }}/system_ext.img + resize2fs -M ${{ matrix.arch }}/system_ext.img + - name: Remove signature and add scripts + run: | + rm -rf ${{ matrix.arch }}/\[Content_Types\].xml ${{ matrix.arch }}/AppxBlockMap.xml ${{ matrix.arch }}/AppxSignature.p7x ${{ matrix.arch }}/AppxMetadata + cp vclibs.appx xaml.appx ${{ matrix.arch }} + tee ${{ matrix.arch }}/Install.ps1 <