Skip to content

Commit

Permalink
Load modules by Magisk
Browse files Browse the repository at this point in the history
  • Loading branch information
Howard20181 committed Mar 2, 2024
1 parent 44df7ca commit 502e3c7
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
download
output
python3-env
token
Binary file added bin/arm64/lspinit
Binary file not shown.
Binary file added bin/x64/lspinit
Binary file not shown.
32 changes: 19 additions & 13 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ clean_download() {
rm -f "${MAGISK_PATH:?}"
fi
if [ "$CLEAN_DOWNLOAD_GAPPS" ]; then
rm -f "${GAPPS_PATH:?}"
rm -f "${GAPPS_IMAGE_PATH:?}"
rm -f "${GAPPS_RC_PATH:?}"
fi
if [ "$CLEAN_DOWNLOAD_KERNELSU" ]; then
rm -f "${KERNELSU_PATH:?}"
Expand Down Expand Up @@ -300,6 +301,7 @@ fi
}
declare -A RELEASE_NAME_MAP=(["retail"]="Retail" ["RP"]="Release Preview" ["WIS"]="Insider Slow" ["WIF"]="Insider Fast")
declare -A ANDROID_API_MAP=(["30"]="11.0" ["32"]="12.1" ["33"]="13.0")
declare -A ARCH_NAME_MAP=(["x64"]="x86_64" ["arm64"]="arm64")
RELEASE_NAME=${RELEASE_NAME_MAP[$RELEASE_TYPE]} || abort
echo -e "INFO: Release Name: $RELEASE_NAME\n"
WSA_ZIP_PATH=$DOWNLOAD_DIR/wsa-$RELEASE_TYPE.zip
Expand All @@ -308,6 +310,7 @@ UWPVCLibs_PATH="$DOWNLOAD_DIR/Microsoft.VCLibs.140.00.UWPDesktop_$ARCH.appx"
xaml_PATH="$DOWNLOAD_DIR/Microsoft.UI.Xaml.2.8_$ARCH.appx"
MAGISK_ZIP=magisk-$MAGISK_VER.zip
MAGISK_PATH=$DOWNLOAD_DIR/$MAGISK_ZIP
CUST_PATH="$DOWNLOAD_DIR/cust.img"
if [ "$CUSTOM_MAGISK" ]; then
if [ ! -f "$MAGISK_PATH" ]; then
echo "Custom Magisk $MAGISK_ZIP not found"
Expand All @@ -320,9 +323,11 @@ if [ "$CUSTOM_MAGISK" ]; then
fi
fi
ANDROID_API=33
update_gapps_file_name() {
GAPPS_FILE_NAME=GApps-$ARCH-${ANDROID_API_MAP[$ANDROID_API]}.img
GAPPS_PATH=$DOWNLOAD_DIR/$GAPPS_FILE_NAME
update_gapps_files_name() {
GAPPS_IMAGE_NAME=gapps-${ANDROID_API_MAP[$ANDROID_API]}-${ARCH_NAME_MAP[$ARCH]}.img
GAPPS_RC_NAME=gapps-${ANDROID_API_MAP[$ANDROID_API]}.rc
GAPPS_IMAGE_PATH=$DOWNLOAD_DIR/$GAPPS_IMAGE_NAME
GAPPS_RC_PATH=$DOWNLOAD_DIR/$GAPPS_RC_NAME
}
WSA_MAJOR_VER=0
getKernelVersion() {
Expand Down Expand Up @@ -402,8 +407,8 @@ if [ -z ${OFFLINE+x} ]; then
echo "KERNELSU_VER=$KERNELSU_VER" >"$KERNELSU_INFO"
fi
if [ "$HAS_GAPPS" ]; then
update_gapps_file_name
python3 generateGappsLink.py "$ARCH" "$DOWNLOAD_DIR" "$DOWNLOAD_CONF_NAME" "$ANDROID_API" "$GAPPS_FILE_NAME" || abort
update_gapps_files_name
python3 generateGappsLink.py "$ARCH" "$DOWNLOAD_DIR" "$DOWNLOAD_CONF_NAME" "$ANDROID_API" "$GAPPS_IMAGE_NAME" || abort
fi
if [ -f "$DOWNLOAD_DIR/$DOWNLOAD_CONF_NAME" ]; then
echo "Downloading Artifacts"
Expand All @@ -416,15 +421,15 @@ if [ -z ${OFFLINE+x} ]; then
fi
declare -A FILES_CHECK_LIST=([xaml_PATH]="$xaml_PATH" [vclibs_PATH]="$vclibs_PATH" [UWPVCLibs_PATH]="$UWPVCLibs_PATH")
if [ "$HAS_GAPPS" ] || [ "$ROOT_SOL" = "magisk" ]; then
FILES_CHECK_LIST+=(["MAGISK_PATH"]="$MAGISK_PATH")
FILES_CHECK_LIST+=(["MAGISK_PATH"]="$MAGISK_PATH" ["CUST_PATH"]="$CUST_PATH")
fi
if [ "$ROOT_SOL" = "kernelsu" ]; then
update_ksu_zip_name
FILES_CHECK_LIST+=(["KERNELSU_PATH"]="$KERNELSU_PATH")
fi
if [ "$HAS_GAPPS" ]; then
update_gapps_file_name
FILES_CHECK_LIST+=(["GAPPS_PATH"]="$GAPPS_PATH")
update_gapps_files_name
FILES_CHECK_LIST+=(["GAPPS_IMAGE_PATH"]="$GAPPS_IMAGE_PATH" ["GAPPS_RC_PATH"]="$GAPPS_RC_PATH")
fi
for i in "${FILES_CHECK_LIST[@]}"; do
if [ ! -f "$i" ]; then
Expand Down Expand Up @@ -476,6 +481,7 @@ if [ "$HAS_GAPPS" ] || [ "$ROOT_SOL" = "magisk" ]; then
"mkdir 000 .backup" \
"add 000 overlay.d/init.lsp.magisk.rc init.lsp.magisk.rc" \
"add 000 overlay.d/sbin/post-fs-data.sh post-fs-data.sh" \
"add 000 overlay.d/sbin/lsp_cust.img $CUST_PATH" \
|| abort "Unable to patch initrd"
elif [ "$ROOT_SOL" = "kernelsu" ]; then
echo "Extracting KernelSU"
Expand All @@ -498,13 +504,13 @@ elif [ "$ROOT_SOL" = "kernelsu" ]; then
fi
echo -e "done\n"
if [ "$HAS_GAPPS" ]; then
update_gapps_file_name
if [ -f "$GAPPS_PATH" ]; then
update_gapps_files_name
if [ -f "$GAPPS_IMAGE_PATH" ] && [ -f "$GAPPS_RC_PATH" ]; then
echo "Integrating GApps"
"$WORK_DIR/magisk/magiskboot" cpio "$WORK_DIR/wsa/$ARCH/Tools/initrd.img" \
"add 000 overlay.d/init.lsp.cust.rc init.lsp.cust.rc" \
"add 000 /lspolicy.rule sepolicy.rule" \
"add 000 overlay.d/sbin/cust.img $GAPPS_PATH" \
"add 000 overlay.d/gapps.rc $GAPPS_RC_PATH" \
"add 000 overlay.d/sbin/lsp_gapps.img $GAPPS_IMAGE_PATH" \
|| abort "Unable to patch initrd"
echo -e "done\n"
else
Expand Down
8 changes: 4 additions & 4 deletions scripts/extractWSA.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ def __repr__(self):
if not Path(workdir / zip_name).is_file():
print(f"unzipping {zip_name} to {workdir}", flush=True)
zip_path = zip.extract(f, workdir)
with zipfile.ZipFile(zip_path) as zip:
stat = Path(zip_path).stat()
print(f"unzipping from {zip_path}", flush=True)
zip.extractall(archdir)
ver_no = zip_name.split("_")
long_ver = ver_no[1]
ver = long_ver.split(".")
Expand Down Expand Up @@ -106,7 +110,3 @@ def __repr__(self):
l.extract(g, xmldir)
elif re.search(u'Images/.+\.png', g.filename):
l.extract(g, archdir)
with zipfile.ZipFile(zip_path) as zip:
stat = Path(zip_path).stat()
print(f"unzipping from {zip_path}", flush=True)
zip.extractall(archdir)
42 changes: 31 additions & 11 deletions scripts/generateGappsLink.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,29 @@
#

from datetime import datetime
import os
import sys

import requests
import json
import re
from pathlib import Path


class BearerAuth(requests.auth.AuthBase):
def __init__(self, token):
self.token = token

def __call__(self, r):
r.headers["authorization"] = "Bearer " + self.token
return r


github_auth = None
if Path.cwd().joinpath('token').exists():
with open(Path.cwd().joinpath('token'), 'r') as token_file:
github_auth = BearerAuth(token_file.read())
print("Using token file for authentication", flush=True)
arch = sys.argv[1]
arg2 = sys.argv[2]
download_dir = Path.cwd().parent / "download" if arg2 == "" else Path(arg2)
Expand All @@ -36,27 +52,31 @@
abi_map = {"x64": "x86_64", "arm64": "arm64"}
android_api_map = {"30": "11.0", "32": "12.1", "33": "13.0"}
release = android_api_map[android_api]
res = requests.get(f"https://api.github.com/repos/LSPosed/WSA-Addon/releases/latest")
res = requests.get(f"https://api.github.com/repos/LSPosed/WSA-Addon/releases/latest", auth=github_auth)
json_data = json.loads(res.content)
headers = res.headers
x_ratelimit_remaining = headers["x-ratelimit-remaining"]
if res.status_code == 200:
download_files = {}
assets = json_data["assets"]
for asset in assets:
if re.match(f'gapps.*{release}.*{abi_map[arch]}.*\.apex$', asset["name"]):
link = asset["browser_download_url"]
if re.match(f'GApps.*{release}.*\.rc$', asset["name"]):
download_files[asset["name"]] = asset["browser_download_url"]
continue
elif re.match(f'GApps.*{release}.*{abi_map[arch]}.*\.img$', asset["name"]):
download_files[asset["name"]] = asset["browser_download_url"]
break
with open(download_dir/tempScript, 'a') as f:
for key, value in download_files.items():
print(f"download link: {value}\npath: {download_dir / key}\n", flush=True)
f.writelines(value + '\n')
f.writelines(f' dir={download_dir}\n')
f.writelines(f' out={key}\n')
elif res.status_code == 403 and x_ratelimit_remaining == '0':
message = json_data["message"]
print(f"Github API Error: {message}", flush=True)
ratelimit_reset = headers["x-ratelimit-reset"]
ratelimit_reset = datetime.fromtimestamp(int(ratelimit_reset))
print(f"The current rate limit window resets in {ratelimit_reset}", flush=True)
print(
f"The current rate limit window resets in {ratelimit_reset}", flush=True)
exit(1)

print(f"download link: {link}", flush=True)

with open(download_dir/tempScript, 'a') as f:
f.writelines(f'{link}\n')
f.writelines(f' dir={download_dir}\n')
f.writelines(f' out={file_name}\n')
12 changes: 0 additions & 12 deletions scripts/init.lsp.cust.rc

This file was deleted.

23 changes: 19 additions & 4 deletions scripts/post-fs-data.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/system/bin/sh
#!/bin/sh
MAGISKTMP=/sbin
[ -d /sbin ] || MAGISKTMP=/debug_ramdisk
MAGISKBIN=/data/adb/magisk
Expand All @@ -11,17 +11,32 @@ if [ ! -d $MAGISKBIN ]; then
mkdir -p -m 755 $MAGISKBIN
chcon u:object_r:system_file:s0 $MAGISKBIN
fi
ABI=$(/system/bin/getprop ro.product.cpu.abi)
ABI=$(getprop ro.product.cpu.abi)
for file in busybox magiskpolicy magiskboot magiskinit; do
[ -x "$MAGISKBIN/$file" ] || {
/system/bin/unzip -d $MAGISKBIN -oj $MAGISKTMP/stub.apk "lib/$ABI/lib$file.so"
unzip -d $MAGISKBIN -oj $MAGISKTMP/stub.apk "lib/$ABI/lib$file.so"
mv $MAGISKBIN/lib$file.so $MAGISKBIN/$file
chmod 755 "$MAGISKBIN/$file"
}
done
for file in util_functions.sh boot_patch.sh; do
[ -x "$MAGISKBIN/$file" ] || {
/system/bin/unzip -d $MAGISKBIN -oj $MAGISKTMP/stub.apk "assets/$file"
unzip -d $MAGISKBIN -oj $MAGISKTMP/stub.apk "assets/$file"
chmod 755 "$MAGISKBIN/$file"
}
done
for file in "$MAGISKTMP"/*; do
if echo "$file" | grep -Eq "lsp_.+\.img"; then
foldername=$(basename "$file" .img)
mkdir -p "$MAGISKTMP/$foldername"
mount -t auto -o ro,loop "$file" "$MAGISKTMP/$foldername"
"$MAGISKTMP/$foldername/post-fs-data.sh" &
fi
done
wait
for file in "$MAGISKTMP"/*; do
if echo "$file" | grep -Eq "lsp_.+\.img"; then
foldername=$(basename "$file" .img)
umount "$MAGISKTMP/$foldername"
fi
done

0 comments on commit 502e3c7

Please sign in to comment.