diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 72b5e27..ae824a3 100755 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,13 +14,13 @@ jobs: permissions: write-all runs-on: ubuntu-latest steps: - - uses: actions/setup-java@v4 + - uses: actions/setup-java@v5 with: - distribution: 'zulu' - java-version: '17' + distribution: "zulu" + java-version: "21" - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: fetch-depth: 0 submodules: true @@ -71,7 +71,7 @@ jobs: file_glob: true overwrite: true - - name: Update changelog and Magisk update json + - name: Update changelog and update json id: update_config run: | git checkout -f update || git switch --discard-changes --orphan update @@ -86,8 +86,8 @@ jobs: } cd build || { echo "build folder not found"; exit 1; } - for OUTPUT in *magisk*.zip; do - [ "$OUTPUT" = "*magisk*.zip" ] && continue + for OUTPUT in *module*.zip; do + [ "$OUTPUT" = "*module*.zip" ] && continue ZIP_S=$(unzip -p "$OUTPUT" module.prop) if ! UPDATE_JSON=$(echo "$ZIP_S" | grep updateJson); then continue; fi UPDATE_JSON="${UPDATE_JSON##*/}" @@ -100,7 +100,7 @@ jobs: find . -name "*-update.json" | grep . || : >dummy-update.json - - uses: stefanzweifel/git-auto-commit-action@v5 + - uses: stefanzweifel/git-auto-commit-action@v7 with: branch: update skip_checkout: true @@ -114,7 +114,7 @@ jobs: run: | cd build || { echo "build folder not found"; exit 1; } - TG_CHAT="-1002417137882" + TG_CHAT="@rvc_magisk" NL=$'\n' APKS="" MODULES="" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 78d4045..25bb179 100755 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: fetch-depth: 0 @@ -47,4 +47,4 @@ jobs: needs: check uses: ./.github/workflows/build.yml if: ${{ needs.check.outputs.SHOULD_BUILD == 1 }} - secrets: inherit + secrets: inherit \ No newline at end of file diff --git a/.gitignore b/.gitignore index 84d7cb1..7cb0124 100755 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,3 @@ test* /logs build.md cmpr - -utils-refer.sh diff --git a/CONFIG.md b/CONFIG.md index a55e39c..4c95c56 100755 --- a/CONFIG.md +++ b/CONFIG.md @@ -1,32 +1,29 @@ # Config Adding another revanced app is as easy as this: - ```toml [Some-App] apkmirror-dlurl = "https://www.apkmirror.com/apk/inc/app" # or uptodown-dlurl = "https://app.en.uptodown.com/android" ``` +> [!WARNING] +> When a patch name itself contains a single quote, double it inside the string (e.g. 'Hide ''Get Music Premium'''). + ## More about other options: There exists an example below with all defaults shown and all the keys explicitly set. -**All keys are optional** (except download urls) and are assigned to their default values if not set explicitly. +**All keys are optional** (except download urls) and are assigned to their default values if not set explicitly. ```toml parallel-jobs = 1 # amount of cores to use for parallel patching, if not set $(nproc) is used compression-level = 9 # module zip compression level remove-rv-integrations-checks = true # remove checks from the revanced integrations +dpi = "nodpi anydpi 120-640dpi" # dpi packages to be searched in order. default: "nodpi anydpi" patches-source = "revanced/revanced-patches" # where to fetch patches bundle from. default: "revanced/revanced-patches" -cli-source = "j-hc/revanced-cli" # where to fetch cli from. default: "j-hc/revanced-cli" +cli-source = "ReVanced/revanced-cli" # where to fetch cli from. default: "ReVanced/revanced-cli" # options like cli-source can also set per app -# -# Supported sources: -# - ReVanced: patches-source = "revanced/revanced-patches", cli-source = "j-hc/revanced-cli" -# - ReVanced Extended: patches-source = "inotia00/revanced-patches", cli-source = "inotia00/revanced-cli" -# - Morphe: patches-source = "MorpheApp/morphe-patches", cli-source = "MorpheApp/morphe-cli" -# rv-brand = "ReVanced Extended" # rebrand from 'ReVanced' to something different. default: "ReVanced" patches-version = "v2.160.0" # 'latest', 'dev', or a version number. default: "latest" @@ -57,11 +54,13 @@ excluded-patches = """\ included-patches = "'Some Patch'" # whitespace seperated list of non-default patches to include. default: "" include-stock = true # includes stock apk in the module. default: true exclusive-patches = false # exclude all patches by default. default: false + apkmirror-dlurl = "https://www.apkmirror.com/apk/inc/app" uptodown-dlurl = "https://spotify.en.uptodown.com/android" -module-prop-name = "some-app-magisk" # magisk module prop name. -apkmirror-dpi = "360-480dpi" # used to select apk variant from apkmirror. default: nodpi -arch = "arm64-v8a" # 'arm64-v8a', 'arm-v7a', 'all', 'both'. 'both' downloads both arm64-v8a and arm-v7a. default: all -riplib = true # enables ripping x86 and x86_64 libs from apks with j-hc revanced cli. default: true +# direct download url. the url must have point to an apk file with name format shown in this example +direct-dlurl = "https://website/com.google.android.youtube-20.40.45-all.apk" +module-prop-name = "some-app-module" # module prop name. +dpi = "360-480dpi" # used to select apk variant from apkmirror. default: nodpi +arch = "arm64-v8a" # 'arm64-v8a', 'arm-v7a', 'all', 'both'. 'both' downloads both arm64-v8a and arm-v7a. default: all ``` diff --git a/README.md b/README.md index 2c0af7d..d9c0832 100755 --- a/README.md +++ b/README.md @@ -1,20 +1,19 @@ # ReVanced Magisk Module - [![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white)](https://t.me/rvc_magisk) [![CI](https://github.com/j-hc/revanced-magisk-module/actions/workflows/ci.yml/badge.svg?event=schedule)](https://github.com/j-hc/revanced-magisk-module/actions/workflows/ci.yml) -Extensive ReVanced builder +Extensive ReVanced builder Get the [latest CI release](https://github.com/j-hc/revanced-magisk-module/releases). -Use [**zygisk-detach**](https://github.com/j-hc/zygisk-detach) to detach YouTube and YT Music from Play Store if you are using magisk modules. +Use [**zygisk-detach**](https://github.com/j-hc/zygisk-detach) to detach YouTube and YT Music from Play Store if you are using magisk modules.
Features -Note that the CI workflow is scheduled to build the modules and APKs everyday using GitHub Actions if there is a change in ReVanced patches. You may want to disable it.
## To include/exclude patches or patch other apps -- Star the repo :eyes: -- Use the repo as a [template](https://github.com/new?template_name=revanced-magisk-module&template_owner=j-hc) -- Customize [`config.toml`](./config.toml) using [rvmm-config-gen](https://j-hc.github.io/rvmm-config-gen/) -- Run the build [workflow](../../actions/workflows/build.yml) -- Grab your modules and APKs from [releases](../../releases) + * Star the repo :eyes: + * Use the repo as a [template](https://github.com/new?template_name=revanced-magisk-module&template_owner=j-hc) + * Customize [`config.toml`](./config.toml) using [rvmm-config-gen](https://j-hc.github.io/rvmm-config-gen/) + * Run the build [workflow](../../actions/workflows/build.yml) + * Grab your modules and APKs from [releases](../../releases) also see here [`CONFIG.md`](./CONFIG.md) +## If you are having trouble with the classic mount method of the modules +such as, +- **"Reflash needed"** error after reboots +- **"Suspicious mount detected"** warnings from root detector apps + +You can consider using [rvmm-zygisk-mount](https://github.com/j-hc/rvmm-zygisk-mount) + ## Building Locally - ### On Termux - ```console bash <(curl -sSf https://raw.githubusercontent.com/j-hc/revanced-magisk-module/main/build-termux.sh) ``` -### On Desktop - +### On Linux ```console -$ git clone https://github.com/j-hc/revanced-magisk-module +$ git clone https://github.com/j-hc/revanced-magisk-module --depth 1 $ cd revanced-magisk-module $ ./build.sh ``` diff --git a/bin/aapt2/aapt2-arm b/bin/aapt2/aapt2-arm index f383b2e..0d83e52 100755 Binary files a/bin/aapt2/aapt2-arm and b/bin/aapt2/aapt2-arm differ diff --git a/bin/aapt2/aapt2-arm64 b/bin/aapt2/aapt2-arm64 index 7bd9eb2..464b66d 100755 Binary files a/bin/aapt2/aapt2-arm64 and b/bin/aapt2/aapt2-arm64 differ diff --git a/build-termux.sh b/build-termux.sh index b4b2234..4905afb 100755 --- a/build-termux.sh +++ b/build-termux.sh @@ -26,7 +26,7 @@ until do sleep 1; done if [ ! -f ~/.rvmm_"$(date '+%Y%m')" ]; then pr "Setting up environment..." - yes "" | pkg update -y && pkg upgrade -y && pkg install -y git curl jq openjdk-17 zip + yes "" | pkg update -y && pkg upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" && pkg install -y git curl jq openjdk-17 zip : >~/.rvmm_"$(date '+%Y%m')" fi mkdir -p /sdcard/Download/revanced-magisk-module/ diff --git a/build.sh b/build.sh index 8fdbfc4..27b507a 100755 --- a/build.sh +++ b/build.sh @@ -2,15 +2,16 @@ set -euo pipefail shopt -s nullglob -trap "rm -rf temp/*tmp.* temp/*/*tmp.* temp/*-temporary-files; exit 130" INT - -if [ "${1-}" = "clean" ]; then - rm -rf temp build logs build.md - exit 0 -fi source utils.sh +trap "abort" INT + +if [ "${1-}" = "clean" ]; then + rm -r "$TEMP_DIR" "$BUILD_DIR" build.md + exit 0 +fi + jq --version >/dev/null || abort "\`jq\` is not installed. install it with 'apt install jq' or equivalent" java --version >/dev/null || abort "\`openjdk 17\` is not installed. install it with 'apt install openjdk-17-jre' or equivalent" zip --version >/dev/null || abort "\`zip\` is not installed. install it with 'apt install zip' or equivalent" @@ -32,6 +33,7 @@ DEF_CLI_VER=$(toml_get "$main_config_t" cli-version) || DEF_CLI_VER="latest" DEF_PATCHES_SRC=$(toml_get "$main_config_t" patches-source) || DEF_PATCHES_SRC="ReVanced/revanced-patches" DEF_CLI_SRC=$(toml_get "$main_config_t" cli-source) || DEF_CLI_SRC="ReVanced/revanced-cli" DEF_RV_BRAND=$(toml_get "$main_config_t" rv-brand) || DEF_RV_BRAND="ReVanced" +DEF_DPI_LIST=$(toml_get "$main_config_t" dpi) || DEF_DPI_LIST="nodpi anydpi" mkdir -p "$TEMP_DIR" "$BUILD_DIR" if [ "${2-}" = "--config-update" ]; then @@ -40,17 +42,17 @@ if [ "${2-}" = "--config-update" ]; then fi : >build.md -ENABLE_MAGISK_UPDATE=$(toml_get "$main_config_t" enable-magisk-update) || ENABLE_MAGISK_UPDATE=true -if [ "$ENABLE_MAGISK_UPDATE" = true ] && [ -z "${GITHUB_REPOSITORY-}" ]; then - pr "You are building locally. Magisk updates will not be enabled." - ENABLE_MAGISK_UPDATE=false +ENABLE_MODULE_UPDATE=$(toml_get "$main_config_t" enable-module-update) || ENABLE_MODULE_UPDATE=true +if [ "$ENABLE_MODULE_UPDATE" = true ] && [ -z "${GITHUB_REPOSITORY-}" ]; then + pr "You are building locally. Module updates will not be enabled." + ENABLE_MODULE_UPDATE=false fi if ((COMPRESSION_LEVEL > 9)) || ((COMPRESSION_LEVEL < 0)); then abort "compression-level must be within 0-9"; fi -rm -rf revanced-magisk/bin/*/tmp.* -if [ "$(echo "$TEMP_DIR"/*-rv/changelog.md)" ]; then - : >"$TEMP_DIR"/*-rv/changelog.md || : -fi +rm -rf module/bin/*/tmp.* +for file in "$TEMP_DIR"/*/changelog.md; do + [ -f "$file" ] && : >"$file" +done mkdir -p ${MODULE_TEMPLATE_DIR}/bin/arm64 ${MODULE_TEMPLATE_DIR}/bin/arm ${MODULE_TEMPLATE_DIR}/bin/x86 ${MODULE_TEMPLATE_DIR}/bin/x64 gh_dl "${MODULE_TEMPLATE_DIR}/bin/arm64/cmpr" "https://github.com/j-hc/cmpr/releases/latest/download/cmpr-arm64-v8a" @@ -58,7 +60,6 @@ gh_dl "${MODULE_TEMPLATE_DIR}/bin/arm/cmpr" "https://github.com/j-hc/cmpr/releas gh_dl "${MODULE_TEMPLATE_DIR}/bin/x86/cmpr" "https://github.com/j-hc/cmpr/releases/latest/download/cmpr-x86" gh_dl "${MODULE_TEMPLATE_DIR}/bin/x64/cmpr" "https://github.com/j-hc/cmpr/releases/latest/download/cmpr-x86_64" -declare -A cliriplib idx=0 for table_name in $(toml_get_table_names); do if [ -z "$table_name" ]; then continue; fi @@ -77,22 +78,13 @@ for table_name in $(toml_get_table_names); do cli_src=$(toml_get "$t" cli-source) || cli_src=$DEF_CLI_SRC cli_ver=$(toml_get "$t" cli-version) || cli_ver=$DEF_CLI_VER - if ! RVP="$(get_rv_prebuilts "$cli_src" "$cli_ver" "$patches_src" "$patches_ver")"; then - abort "could not download rv prebuilts" + if ! PREBUILTS="$(get_prebuilts "$cli_src" "$cli_ver" "$patches_src" "$patches_ver")"; then + epr "Could not get prebuilts" + continue fi - read -r rv_cli_jar rv_patches_jar <<<"$RVP" - app_args[cli]=$rv_cli_jar - app_args[ptjar]=$rv_patches_jar - if [[ -v cliriplib[${app_args[cli]}] ]]; then app_args[riplib]=${cliriplib[${app_args[cli]}]}; else - if [[ $(java -jar "${app_args[cli]}" patch 2>&1) == *rip-lib* ]]; then - cliriplib[${app_args[cli]}]=true - app_args[riplib]=true - else - cliriplib[${app_args[cli]}]=false - app_args[riplib]=false - fi - fi - if [ "${app_args[riplib]}" = "true" ] && [ "$(toml_get "$t" riplib)" = "false" ]; then app_args[riplib]=false; fi + read -r cli_jar patches_jar <<<"$PREBUILTS" + app_args[cli]=$cli_jar + app_args[ptjar]=$patches_jar app_args[rv_brand]=$(toml_get "$t" rv-brand) || app_args[rv_brand]=$DEF_RV_BRAND app_args[excluded_patches]=$(toml_get "$t" excluded-patches) || app_args[excluded_patches]="" @@ -109,28 +101,25 @@ for table_name in $(toml_get_table_names); do abort "ERROR: build-mode '${app_args[build_mode]}' is not a valid option for '${table_name}': only 'both', 'apk' or 'module' is allowed" fi } || app_args[build_mode]=apk - app_args[uptodown_dlurl]=$(toml_get "$t" uptodown-dlurl) && { - app_args[uptodown_dlurl]=${app_args[uptodown_dlurl]%/} - app_args[uptodown_dlurl]=${app_args[uptodown_dlurl]%download} - app_args[uptodown_dlurl]=${app_args[uptodown_dlurl]%/} - app_args[dl_from]=uptodown - } || app_args[uptodown_dlurl]="" - app_args[apkmirror_dlurl]=$(toml_get "$t" apkmirror-dlurl) && { - app_args[apkmirror_dlurl]=${app_args[apkmirror_dlurl]%/} - app_args[dl_from]=apkmirror - } || app_args[apkmirror_dlurl]="" - app_args[archive_dlurl]=$(toml_get "$t" archive-dlurl) && { - app_args[archive_dlurl]=${app_args[archive_dlurl]%/} - app_args[dl_from]=archive - } || app_args[archive_dlurl]="" - if [ -z "${app_args[dl_from]-}" ]; then abort "ERROR: no 'apkmirror_dlurl', 'uptodown_dlurl' or 'archive_dlurl' option was set for '$table_name'."; fi + + for dl_from in "${DL_SRCS[@]}"; do + if app_args[${dl_from}_dlurl]=$(toml_get "$t" "${dl_from}-dlurl"); then + app_args[${dl_from}_dlurl]=${app_args[${dl_from}_dlurl]%/} + app_args[${dl_from}_dlurl]=${app_args[${dl_from}_dlurl]%download} + app_args[${dl_from}_dlurl]=${app_args[${dl_from}_dlurl]%/} + app_args[dl_from]=${dl_from} + else + app_args[${dl_from}_dlurl]="" + fi + done + if [ -z "${app_args[dl_from]-}" ]; then abort "ERROR: no 'dlurl' option was set for '$table_name'. (${DL_SRCS[*]})"; fi app_args[arch]=$(toml_get "$t" arch) || app_args[arch]="all" - if [ "${app_args[arch]}" != "both" ] && [ "${app_args[arch]}" != "all" ] && [[ ${app_args[arch]} != "arm64-v8a"* ]] && [[ ${app_args[arch]} != "arm-v7a"* ]]; then + if ! isoneof "${app_args[arch]}" "both" "all" "arm64-v8a" "arm-v7a" "x86_64" "x86"; then abort "wrong arch '${app_args[arch]}' for '$table_name'" fi app_args[include_stock]=$(toml_get "$t" include-stock) || app_args[include_stock]=true && vtf "${app_args[include_stock]}" "include-stock" - app_args[dpi]=$(toml_get "$t" apkmirror-dpi) || app_args[dpi]="nodpi" + app_args[dpi]=$(toml_get "$t" dpi) || app_args[dpi]="$DEF_DPI_LIST" table_name_f=${table_name,,} table_name_f=${table_name_f// /-} app_args[module_prop_name]=$(toml_get "$t" module-prop-name) || app_args[module_prop_name]="${table_name_f}-jhc" @@ -166,9 +155,9 @@ rm -rf temp/tmp.* if [ -z "$(ls -A1 "${BUILD_DIR}")" ]; then abort "All builds failed."; fi log "\nInstall [Microg](https://github.com/ReVanced/GmsCore/releases) for non-root YouTube and YT Music APKs" -log "Use [zygisk-detach](https://github.com/j-hc/zygisk-detach) to detach root ReVanced YouTube and YT Music from Play Store" +log "Use [zygisk-detach](https://github.com/j-hc/zygisk-detach) to detach YouTube and YT Music modules from Play Store" log "\n[revanced-magisk-module](https://github.com/j-hc/revanced-magisk-module)\n" -log "$(cat "$TEMP_DIR"/*-rv/changelog.md)" +log "$(cat "$TEMP_DIR"/*/changelog.md)" SKIPPED=$(cat "$TEMP_DIR"/skipped 2>/dev/null || :) if [ -n "$SKIPPED" ]; then diff --git a/config.toml b/config.toml index e453697..fb89fe3 100755 --- a/config.toml +++ b/config.toml @@ -1,4 +1,4 @@ -enable-magisk-update = false # set this to false if you do not want to receive updates for the module in magisk app +enable-module-update = true # set this to false if you do not want to receive updates for the module parallel-jobs = 1 # add 'enabled = false' for not patching a specific app or remove it from the config @@ -8,65 +8,58 @@ parallel-jobs = 1 [YouTube] build-mode = "both" -excluded-patches = "" -included-patches = "" -version = "auto" apkmirror-dlurl = "https://www.apkmirror.com/apk/google-inc/youtube" uptodown-dlurl = "https://youtube.en.uptodown.com/android" -# archive-dlurl = "https://archive.org/download/jhc-apks/apks/com.google.android.youtube" - -[Music] -build-mode = "both" -arch = "both" -apkmirror-dlurl = "https://www.apkmirror.com/apk/google-inc/youtube-music" -uptodown-dlurl = "https://youtube-music.en.uptodown.com/android" -# archive-dlurl = "https://archive.org/download/jhc-apks/apks/com.google.android.apps.youtube.music" - -[GooglePhotos] -build-mode = "both" -arch = "both" -version = "auto" -apkmirror-dlurl = "https://www.apkmirror.com/apk/google-inc/photos/" -uptodown-dlurl = "https://google-photos.en.uptodown.com/android" -archive-dlurl = "https://archive.org/download/jhc-apks/apks/com.google.android.apps.photos" - -[Spotify] -uptodown-dlurl = "https://spotify.en.uptodown.com/android" +archive-dlurl = "https://archive.org/download/jhc-apks/apks/com.google.android.youtube" [YouTube-Morphe] app-name = "YouTube" patches-source = "MorpheApp/morphe-patches" cli-source = "MorpheApp/morphe-cli" rv-brand = "Morphe" -build-mode = "apk" -version = "auto" +build-mode = "both" apkmirror-dlurl = "https://www.apkmirror.com/apk/google-inc/youtube" uptodown-dlurl = "https://youtube.en.uptodown.com/android" -included-patches = "" -excluded-patches = "" +archive-dlurl = "https://archive.org/download/jhc-apks/apks/com.google.android.youtube" + +[Music] +build-mode = "both" +arch = "both" +apkmirror-dlurl = "https://www.apkmirror.com/apk/google-inc/youtube-music" +uptodown-dlurl = "https://youtube-music.en.uptodown.com/android" +archive-dlurl = "https://archive.org/download/jhc-apks/apks/com.google.android.apps.youtube.music" [Music-Morphe] app-name = "Music" patches-source = "MorpheApp/morphe-patches" cli-source = "MorpheApp/morphe-cli" rv-brand = "Morphe" -build-mode = "apk" +build-mode = "both" arch = "both" apkmirror-dlurl = "https://www.apkmirror.com/apk/google-inc/youtube-music" uptodown-dlurl = "https://youtube-music.en.uptodown.com/android" -included-patches = "" -excluded-patches = "" +archive-dlurl = "https://archive.org/download/jhc-apks/apks/com.google.android.apps.youtube.music" -[TikTok] -enabled = false -# archive-dlurl = "https://archive.org/download/jhc-apks/apks/com.zhiliaoapp.musically" -included-patches = "'SIM spoof'" +[Reddit-Morphe] +app-name = "Reddit" +rv-brand = "Morphe" +build-mode = "both" +patches-source = "MorpheApp/morphe-patches" +cli-source = "MorpheApp/morphe-cli" +apkmirror-dlurl = "https://www.apkmirror.com/apk/redditinc/reddit/" +archive-dlurl = "https://archive.org/download/jhc-apks/apks/com.reddit.frontpage" +uptodown-dlurl = "https://reddit-official-app.en.uptodown.com/android" +dpi = "120-640dpi" -[Messenger] +[Twitch] enabled = false -apkmirror-dlurl = "https://www.apkmirror.com/apk/facebook-2/messenger/" -arch = "arm64-v8a" +apkmirror-dlurl = "https://www.apkmirror.com/apk/twitch-interactive-inc/twitch/" +uptodown-dlurl = "https://twitch.en.uptodown.com/android" +# archive-dlurl = "https://archive.org/download/jhc-apks/apks/tv.twitch.android.app" -[IconPackStudio] +[Twitter] enabled = false -apkmirror-dlurl = "https://www.apkmirror.com/apk/smart-launcher-team/icon-pack-studio/" +apkmirror-dlurl = "https://www.apkmirror.com/apk/x-corp/twitter" +build-mode = "apk" +dpi = "120-640dpi" +# archive-dlurl = "https://archive.org/download/jhc-apks/apks/com.twitter.android" \ No newline at end of file diff --git a/ks-p12.keystore b/ks-p12.keystore new file mode 100644 index 0000000..609170a Binary files /dev/null and b/ks-p12.keystore differ diff --git a/ksu_profile/.gitignore b/ksu_profile/.gitignore new file mode 100644 index 0000000..b3444dd --- /dev/null +++ b/ksu_profile/.gitignore @@ -0,0 +1,3 @@ +libs +obj +*.mk diff --git a/ksu_profile/jni/ksu_profile.c b/ksu_profile/jni/ksu_profile.c new file mode 100644 index 0000000..9f52764 --- /dev/null +++ b/ksu_profile/jni/ksu_profile.c @@ -0,0 +1,128 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define KSU_INSTALL_MAGIC1 0xDEADBEEF +#define KSU_INSTALL_MAGIC2 0xCAFEBABE + +#define KSU_APP_PROFILE_VER 2 +#define KSU_MAX_PACKAGE_NAME 256 +#define KSU_MAX_GROUPS 32 +#define KSU_SELINUX_DOMAIN 64 + +#define KSU_IOCTL_MAGIC 'K' +#define KSU_IOCTL_UID_SHOULD_UMOUNT _IOC(_IOC_READ | _IOC_WRITE, KSU_IOCTL_MAGIC, 9, 0) +#define KSU_IOCTL_GET_MANAGER_APPID _IOC(_IOC_READ, KSU_IOCTL_MAGIC, 10, 0) +#define KSU_IOCTL_GET_APP_PROFILE _IOC(_IOC_READ | _IOC_WRITE, KSU_IOCTL_MAGIC, 11, 0) +#define KSU_IOCTL_SET_APP_PROFILE _IOC(_IOC_WRITE, KSU_IOCTL_MAGIC, 12, 0) + +struct root_profile { + int32_t uid; + int32_t gid; + int32_t groups_count; + int32_t groups[KSU_MAX_GROUPS]; + + struct { + uint64_t effective; + uint64_t permitted; + uint64_t inheritable; + } capabilities; + + char selinux_domain[KSU_SELINUX_DOMAIN]; + int32_t namespaces; +}; + +struct non_root_profile { + bool umount_modules; +}; + +struct app_profile { + uint32_t version; + char key[KSU_MAX_PACKAGE_NAME]; + int32_t current_uid; + bool allow_su; + union { + struct { + bool use_default; + char template_name[KSU_MAX_PACKAGE_NAME]; + struct root_profile profile; + } rp_config; + struct { + bool use_default; + struct non_root_profile profile; + } nrp_config; + }; +}; + +struct ksu_uid_should_umount_cmd { + uint32_t uid; + uint8_t should_umount; +}; + +struct ksu_get_manager_appid_cmd { + uint32_t appid; +}; + +static int _fd = -1; +#define ksuctl(op, ...) (ioctl(_fd, op, __VA_ARGS__) >= 0) + +#define REPORT_ERR() fprintf(stderr, "%s:%d ERROR: %s\n", __FILE__, __LINE__, strerror(errno)); + +int main(int argc, char* argv[]) { + if (argc <= 2) { + fprintf(stderr, + "ksu_profile (github.com/j-hc)\n" + "Disables \"Unmount modules\" for given package\n" + " Usage: %s \n", + argv[0]); + return 1; + } + + syscall(SYS_reboot, KSU_INSTALL_MAGIC1, KSU_INSTALL_MAGIC2, 0, &_fd); + if (_fd == -1) { + REPORT_ERR(); + return 1; + } + long uid = atol(argv[1]); + + struct ksu_uid_should_umount_cmd umount_cmd = {0}; + if (!ksuctl(KSU_IOCTL_UID_SHOULD_UMOUNT, &umount_cmd)) { + REPORT_ERR(); + return 1; + } + if (!umount_cmd.should_umount) return 0; + + struct ksu_get_manager_appid_cmd appid_cmd = {0}; + if (!ksuctl(KSU_IOCTL_GET_MANAGER_APPID, &appid_cmd)) { + REPORT_ERR(); + return 1; + } + + if (setuid(appid_cmd.appid) != 0) { + REPORT_ERR(); + return 1; + } + struct app_profile profile = {0}; + profile.current_uid = uid; + if (!ksuctl(KSU_IOCTL_GET_APP_PROFILE, &profile)) { + printf("Create profile for %s\n", argv[2]); + profile.version = KSU_APP_PROFILE_VER; + strncpy(profile.key, argv[2], sizeof(profile.key) / sizeof(profile.key[0])); + } + + profile.nrp_config.use_default = false; + profile.nrp_config.profile.umount_modules = false; + + if (!ksuctl(KSU_IOCTL_SET_APP_PROFILE, &profile)) { + REPORT_ERR(); + return 1; + } + + return 0; +} diff --git a/module/META-INF/com/google/android/update-binary b/module/META-INF/com/google/android/update-binary new file mode 100644 index 0000000..28b48e5 --- /dev/null +++ b/module/META-INF/com/google/android/update-binary @@ -0,0 +1,33 @@ +#!/sbin/sh + +################# +# Initialization +################# + +umask 022 + +# echo before loading util_functions +ui_print() { echo "$1"; } + +require_new_magisk() { + ui_print "*******************************" + ui_print " Please install Magisk v20.4+! " + ui_print "*******************************" + exit 1 +} + +######################### +# Load util_functions.sh +######################### + +OUTFD=$2 +ZIPFILE=$3 + +mount /data 2>/dev/null + +[ -f /data/adb/magisk/util_functions.sh ] || require_new_magisk +. /data/adb/magisk/util_functions.sh +[ $MAGISK_VER_CODE -lt 20400 ] && require_new_magisk + +install_module +exit 0 diff --git a/module/META-INF/com/google/android/updater-script b/module/META-INF/com/google/android/updater-script new file mode 100644 index 0000000..11d5c96 --- /dev/null +++ b/module/META-INF/com/google/android/updater-script @@ -0,0 +1 @@ +#MAGISK diff --git a/module/bin/arm/ksu_profile b/module/bin/arm/ksu_profile new file mode 100644 index 0000000..10bc3e4 Binary files /dev/null and b/module/bin/arm/ksu_profile differ diff --git a/module/bin/arm64/ksu_profile b/module/bin/arm64/ksu_profile new file mode 100644 index 0000000..a5c23b8 Binary files /dev/null and b/module/bin/arm64/ksu_profile differ diff --git a/module/bin/x64/ksu_profile b/module/bin/x64/ksu_profile new file mode 100644 index 0000000..e2d92e4 Binary files /dev/null and b/module/bin/x64/ksu_profile differ diff --git a/module/bin/x86/ksu_profile b/module/bin/x86/ksu_profile new file mode 100644 index 0000000..a058154 Binary files /dev/null and b/module/bin/x86/ksu_profile differ diff --git a/module/customize.sh b/module/customize.sh new file mode 100644 index 0000000..6ce2220 --- /dev/null +++ b/module/customize.sh @@ -0,0 +1,206 @@ +. "$MODPATH/config" + +ui_print "" +if [ -n "$MODULE_ARCH" ] && [ "$MODULE_ARCH" != "$ARCH" ]; then + abort "ERROR: Wrong arch +Your device: $ARCH +Module: $MODULE_ARCH" +fi +if [ "$ARCH" = "arm" ]; then + ARCH_LIB=armeabi-v7a +elif [ "$ARCH" = "arm64" ]; then + ARCH_LIB=arm64-v8a +elif [ "$ARCH" = "x86" ]; then + ARCH_LIB=x86 +elif [ "$ARCH" = "x64" ]; then + ARCH_LIB=x86_64 +else abort "ERROR: unreachable: ${ARCH}"; fi +RVPATH=/data/adb/rvhc/${MODPATH##*/}.apk + +set_perm_recursive "$MODPATH/bin" 0 0 0755 0777 + +if su -M -c true >/dev/null 2>/dev/null; then + alias mm='su -M -c' +else alias mm='nsenter -t1 -m'; fi + +mm grep -F "$PKG_NAME" /proc/mounts | while read -r line; do + ui_print "* Un-mount" + mp=${line#* } mp=${mp%% *} + mm umount -l "${mp%%\\*}" +done +am force-stop "$PKG_NAME" + +pmex() { + OP=$(pm "$@" 2>&1 &2; then + if pmex install-existing "$PKG_NAME" >&2; then + pmex uninstall-system-updates "$PKG_NAME" + fi +fi + +IS_SYS=false +INS=true +if BASEPATH=$(pmex path "$PKG_NAME"); then + echo >&2 "'$BASEPATH'" + BASEPATH=${BASEPATH##*:} BASEPATH=${BASEPATH%/*} + if [ "${BASEPATH:1:4}" != data ]; then + ui_print "* $PKG_NAME is a system app." + IS_SYS=true + elif [ ! -f "$MODPATH/$PKG_NAME.apk" ]; then + ui_print "* Stock $PKG_NAME APK was not found" + VERSION=$(dumpsys package "$PKG_NAME" 2>&1 | grep -m1 versionName) VERSION="${VERSION#*=}" + if [ "$VERSION" = "$PKG_VER" ] || [ -z "$VERSION" ]; then + ui_print "* Skipping stock installation" + INS=false + else + abort "ERROR: Version mismatch + installed: $VERSION + module: $PKG_VER + " + fi + elif "${MODPATH:?}/bin/$ARCH/cmpr" "$BASEPATH/base.apk" "$MODPATH/$PKG_NAME.apk"; then + ui_print "* $PKG_NAME is up-to-date" + INS=false + fi +fi + +install() { + if [ ! -f "$MODPATH/$PKG_NAME.apk" ]; then + abort "ERROR: Stock $PKG_NAME apk was not found" + fi + ui_print "* Updating $PKG_NAME to $PKG_VER" + install_err="" + VERIF1=$(settings get global verifier_verify_adb_installs) + VERIF2=$(settings get global package_verifier_enable) + settings put global verifier_verify_adb_installs 0 + settings put global package_verifier_enable 0 + SZ=$(stat -c "%s" "$MODPATH/$PKG_NAME.apk") + for IT in 1 2; do + if ! SES=$(pmex install-create --user 0 -i com.android.vending -r -d -S "$SZ"); then + ui_print "ERROR: install-create failed" + install_err="$SES" + break + fi + SES=${SES#*[} SES=${SES%]*} + set_perm "$MODPATH/$PKG_NAME.apk" 1000 1000 644 u:object_r:apk_data_file:s0 + if ! op=$(pmex install-write -S "$SZ" "$SES" "$PKG_NAME.apk" "$MODPATH/$PKG_NAME.apk"); then + ui_print "ERROR: install-write failed" + install_err="$op" + break + fi + if ! op=$(pmex install-commit "$SES"); then + ui_print "$op" + if echo "$op" | grep -q -e INSTALL_FAILED_VERSION_DOWNGRADE -e INSTALL_FAILED_UPDATE_INCOMPATIBLE; then + ui_print "* Handling install error" + pmex uninstall-system-updates "$PKG_NAME" + if BASEPATH=$(pmex path "$PKG_NAME"); then + BASEPATH=${BASEPATH##*:} BASEPATH=${BASEPATH%/*} + if [ "${BASEPATH:1:4}" != data ]; then IS_SYS=true; fi + fi + if [ "$IS_SYS" = true ]; then + SCNM="/data/adb/post-fs-data.d/$PKG_NAME-uninstall.sh" + if [ -f "$SCNM" ]; then + ui_print "* Remove the old module. Reboot and reflash!" + ui_print "" + install_err=" " + break + fi + mkdir -p /data/adb/rvhc/empty /data/adb/post-fs-data.d + echo "mount -o bind /data/adb/rvhc/empty $BASEPATH" >"$SCNM" + chmod +x "$SCNM" + ui_print "* Created the uninstall script." + ui_print "" + ui_print "* Reboot and reflash the module!" + install_err=" " + break + else + ui_print "* Uninstalling..." + if ! op=$(pmex uninstall -k --user 0 "$PKG_NAME"); then + ui_print "$op" + if [ $IT = 2 ]; then + install_err="ERROR: pm uninstall failed." + break + fi + fi + continue + fi + fi + ui_print "ERROR: install-commit failed" + install_err="$op" + break + fi + if BASEPATH=$(pmex path "$PKG_NAME"); then + BASEPATH=${BASEPATH##*:} BASEPATH=${BASEPATH%/*} + else + install_err=" " + break + fi + break + done + settings put global verifier_verify_adb_installs "$VERIF1" + settings put global package_verifier_enable "$VERIF2" + if [ "$install_err" ]; then + ui_print "$install_err" + abort "ERROR: disable the module, reboot, install $PKG_NAME manually and reflash again" + fi +} +if [ $INS = true ] && ! install; then abort; fi +BASEPATHLIB=${BASEPATH}/lib/${ARCH} +if [ $INS = true ] || [ -z "$(ls -A1 "$BASEPATHLIB")" ]; then + ui_print "* Extracting native libs" + if [ ! -d "$BASEPATHLIB" ]; then mkdir -p "$BASEPATHLIB"; else rm -f "$BASEPATHLIB"/* >/dev/null 2>&1 || :; fi + if ! op=$(unzip -o -j "$MODPATH/$PKG_NAME.apk" "lib/${ARCH_LIB}/*" -d "$BASEPATHLIB" 2>&1); then + ui_print "ERROR: extracting native libs failed" + abort "$op" + fi + set_perm_recursive "${BASEPATH}/lib" 1000 1000 755 755 u:object_r:apk_data_file:s0 +fi + +ui_print "* Setting Permissions" +set_perm "$MODPATH/base.apk" 1000 1000 644 u:object_r:apk_data_file:s0 + +ui_print "* Mounting $PKG_NAME" +mkdir -p "/data/adb/rvhc" +RVPATH=/data/adb/rvhc/${MODPATH##*/}.apk +mv -f "$MODPATH/base.apk" "$RVPATH" + +if ! op=$(mm mount -o bind "$RVPATH" "$BASEPATH/base.apk" 2>&1); then + ui_print "ERROR: Mount failed!" + ui_print "$op" +fi +am force-stop "$PKG_NAME" +ui_print "* Optimizing $PKG_NAME" + +cmd package compile -m speed-profile -f "$PKG_NAME" +# nohup cmd package compile -m speed-profile -f "$PKG_NAME" >/dev/null 2>&1 + +if [ "$KSU" ]; then + UID=$(dumpsys package "$PKG_NAME" 2>&1 | grep -m1 uid) + UID=${UID#*=} UID=${UID%% *} + if [ -z "$UID" ]; then + UID=$(dumpsys package "$PKG_NAME" 2>&1 | grep -m1 userId) + UID=${UID#*=} UID=${UID%% *} + fi + if [ "$UID" ]; then + if ! OP=$("${MODPATH:?}/bin/$ARCH/ksu_profile" "$UID" "$PKG_NAME" 2>&1); then + ui_print " $OP" + ui_print "* Because you are using a fork of KernelSU, " + ui_print " you need to go to your root manager app and" + ui_print " disable 'Unmount modules' option for $PKG_NAME" + fi + else + ui_print "ERROR: UID could not be found for $PKG_NAME" + dumpsys package "$PKG_NAME" >&2 + fi +fi + +rm -rf "${MODPATH:?}/bin" "$MODPATH/$PKG_NAME.apk" + +ui_print "* Done" +ui_print " by j-hc (github.com/j-hc)" +ui_print " " diff --git a/module/service.sh b/module/service.sh new file mode 100644 index 0000000..bd83d9e --- /dev/null +++ b/module/service.sh @@ -0,0 +1,49 @@ +#!/system/bin/sh +MODDIR=${0%/*} +RVPATH=/data/adb/rvhc/${MODDIR##*/}.apk +. "$MODDIR/config" + +err() { + [ ! -f "$MODDIR/err" ] && cp "$MODDIR/module.prop" "$MODDIR/err" + sed -i "s/^des.*/description=⚠️ Needs reflash: '${1}'/g" "$MODDIR/module.prop" +} + +until [ "$(getprop sys.boot_completed)" = 1 ]; do sleep 1; done +until [ -d "/sdcard/Android" ]; do sleep 1; done +while + BASEPATH=$(pm path "$PKG_NAME" 2>&1 &1 | grep -m1 versionName) VERSION="${VERSION#*=}" + if [ "$VERSION" != "$PKG_VER" ] && [ "$VERSION" ]; then + err "version mismatch (installed:${VERSION}, module:$PKG_VER)" + return + fi + grep "$PKG_NAME" /proc/mounts | while read -r line; do + mp=${line#* } mp=${mp%% *} + umount -l "${mp%%\\*}" + done + if ! chcon u:object_r:apk_data_file:s0 "$RVPATH"; then + err "apk not found" + return + fi + mount -o bind "$RVPATH" "$BASEPATH/base.apk" + am force-stop "$PKG_NAME" + [ -f "$MODDIR/err" ] && mv -f "$MODDIR/err" "$MODDIR/module.prop" +} + +run diff --git a/module/uninstall.sh b/module/uninstall.sh new file mode 100644 index 0000000..7854a99 --- /dev/null +++ b/module/uninstall.sh @@ -0,0 +1,13 @@ +#!/system/bin/sh +{ + + until [ "$(getprop sys.boot_completed)" = 1 ]; do sleep 1; done + until [ -d "/sdcard/Android" ]; do sleep 1; done + + MODDIR=${0%/*} + . "$MODDIR/config" + + rm "/data/adb/rvhc/${MODDIR##*/}.apk" + rmdir "/data/adb/rvhc" + rm "/data/adb/post-fs-data.d/$PKG_NAME-uninstall.sh" +} & diff --git a/sig.txt b/sig.txt index 93841b1..e2f24c1 100644 --- a/sig.txt +++ b/sig.txt @@ -2,4 +2,4 @@ a2a1ad7ba7f41dfca4514e2afeb90691719af6d0fdbed4b09bbf0ed897701ceb com.google.andr 3d7a1223019aa39d9ea0e3436ab7c0896bfb4fb679f4de5fe7c23f326c8f994a com.google.android.youtube 970b91143813b4c9d5f3634f672c9fcaa5621b4efaaedafd6c235cbbb869736f com.reddit.frontpage 9041803e91bcb814b4b4399fb5c85a91640b755e5e8ba76813814bf4cf2ab5ba com.zhiliaoapp.musically -1338f9b049893cc70b78432a177582f90bd4bc6296ea4ed35bcc7df59687ac53 tv.twitch.android.app \ No newline at end of file +1338f9b049893cc70b78432a177582f90bd4bc6296ea4ed35bcc7df59687ac53 tv.twitch.android.app diff --git a/utils.sh b/utils.sh index dcff869..dbf1d06 100755 --- a/utils.sh +++ b/utils.sh @@ -1,10 +1,11 @@ #!/usr/bin/env bash -MODULE_TEMPLATE_DIR="revanced-magisk" +MODULE_TEMPLATE_DIR="module" CWD=$(pwd) TEMP_DIR="temp" BIN_DIR="bin" BUILD_DIR="build" +DL_SRCS=("direct" "archive" "apkmirror" "uptodown") if [ "${GITHUB_TOKEN-}" ]; then GH_HEADER="Authorization: token ${GITHUB_TOKEN}"; else GH_HEADER=; fi NEXT_VER_CODE=${NEXT_VER_CODE:-$(date +'%Y%m%d')} @@ -22,12 +23,15 @@ toml_get_table_names() { jq -r -e 'to_entries[] | select(.value | type == "objec toml_get_table_main() { jq -r -e 'to_entries | map(select(.value | type != "object")) | from_entries' <<<"$__TOML__"; } toml_get_table() { jq -r -e ".\"${1}\"" <<<"$__TOML__"; } toml_get() { - local op + local op quote_placeholder=$'\001' op=$(jq -r ".\"${2}\" | values" <<<"$1") if [ "$op" ]; then op="${op#"${op%%[![:space:]]*}"}" op="${op%"${op##*[![:space:]]}"}" + op=${op//\\\'/$quote_placeholder} + op=${op//"''"/$quote_placeholder} op=${op//"'"/'"'} + op=${op//$quote_placeholder/$'\''} echo "$op" else return 1; fi } @@ -35,56 +39,47 @@ toml_get() { pr() { echo -e "\033[0;32m[+] ${1}\033[0m"; } epr() { echo >&2 -e "\033[0;31m[-] ${1}\033[0m" - if [ "${GITHUB_REPOSITORY-}" ]; then echo -e "::error::utils.sh [-] ${1}\n"; fi + if [ "${GITHUB_REPOSITORY-}" ]; then echo >&2 -e "::error::utils.sh [-] ${1}\n"; fi +} +wpr() { + echo >&2 -e "\033[0;33m[!] ${1}\033[0m" + if [ "${GITHUB_REPOSITORY-}" ]; then echo >&2 -e "::warning::utils.sh [!] ${1}\n"; fi } abort() { epr "ABORT: ${1-}" - exit 1 + rm -rf ./${TEMP_DIR}/*tmp.* ./${TEMP_DIR}/*/*tmp.* ./${TEMP_DIR}/*-temporary-files + kill -n 9 0 } +java() { env -i java --enable-native-access=ALL-UNNAMED "$@"; } -get_rv_prebuilts() { +get_prebuilts() { local cli_src=$1 cli_ver=$2 patches_src=$3 patches_ver=$4 pr "Getting prebuilts (${patches_src%/*})" >&2 local cl_dir=${patches_src%/*} cl_dir=${TEMP_DIR}/${cl_dir,,}-rv [ -d "$cl_dir" ] || mkdir "$cl_dir" - - # Detect if using Morphe or ReVanced based on patches source - local is_morphe=false - if [[ "$patches_src" == *"MorpheApp"* ]] || [[ "$patches_src" == *"morphe"* ]]; then - is_morphe=true - fi - - # Set CLI filename prefix based on source - local cli_prefix="revanced-cli" - if [ "$is_morphe" = true ]; then - cli_prefix="morphe-cli" - fi - - for src_ver in "$cli_src CLI $cli_ver $cli_prefix" "$patches_src Patches $patches_ver patches"; do + + for src_ver in "$cli_src CLI $cli_ver cli" "$patches_src Patches $patches_ver patches"; do set -- $src_ver local src=$1 tag=$2 ver=${3-} fprefix=$4 - local ext + if [ "$tag" = "CLI" ]; then - ext="jar" local grab_cl=false elif [ "$tag" = "Patches" ]; then - # Use .mpp for Morphe, .rvp for ReVanced - if [ "$is_morphe" = true ]; then - ext="mpp" - else - ext="rvp" - fi local grab_cl=true else abort unreachable; fi + local dir=${src%/*} dir=${TEMP_DIR}/${dir,,}-rv [ -d "$dir" ] || mkdir "$dir" local rv_rel="https://api.github.com/repos/${src}/releases" name_ver if [ "$ver" = "dev" ]; then - name_ver="*-dev*" - elif [ "$ver" = "latest" ]; then + local resp + resp=$(gh_req "$rv_rel" -) || return 1 + ver=$(jq -e -r '.[] | .tag_name' <<<"$resp" | get_highest_ver) || return 1 + fi + if [ "$ver" = "latest" ]; then rv_rel+="/latest" name_ver="*" else @@ -92,22 +87,27 @@ get_rv_prebuilts() { name_ver="$ver" fi - local url file tag_name name - file=$(find "$dir" -name "${fprefix}-${name_ver#v}.${ext}" -type f 2>/dev/null) + local url file tag_name matches + file=$(find "$dir" -name "*${fprefix}-${name_ver#v}.*" -type f 2>/dev/null) if [ -z "$file" ]; then local resp asset name resp=$(gh_req "$rv_rel" -) || return 1 - if [ "$ver" = "dev" ]; then resp=$(jq -r '.[0]' <<<"$resp"); fi - tag_name=$(jq -r '.tag_name' <<<"$resp") - # Filter assets by extension and handle multiple matches - # Use jq array syntax to get first match as a complete JSON object - if [ "$ver" = "dev" ]; then - # For dev version, prefer the one with "dev" in the name - asset=$(jq -e -r "[.assets[] | select(.name | endswith(\"$ext\") and contains(\"dev\"))][0] // [.assets[] | select(.name | endswith(\"$ext\"))][0]" <<<"$resp") || return 1 - else - # For non-dev versions, exclude dev builds and take the first match - asset=$(jq -e -r "[.assets[] | select(.name | endswith(\"$ext\") and (contains(\"dev\") | not))][0] // [.assets[] | select(.name | endswith(\"$ext\"))][0]" <<<"$resp") || return 1 + tag_name=$(jq -r '.tag_name' <<<"$resp") || return 1 + matches=$(jq -e '.assets | map(select(.name | (endswith("asc") or endswith("json")) | not))' <<<"$resp") || return 1 + if [ "$(jq 'length' <<<"$matches")" -gt 1 ]; then + local matches_new + matches_new=$(jq -e -r 'map(select(.name | contains("-dev") | not))' <<<"$matches") + if [ "$(jq 'length' <<<"$matches_new")" -eq 1 ]; then + matches=$matches_new + fi fi + if [ "$(jq 'length' <<<"$matches")" -eq 0 ]; then + epr "No asset was found" + return 1 + elif [ "$(jq 'length' <<<"$matches")" -ne 1 ]; then + wpr "More than 1 asset was found for this release. Falling back to the first one found..." + fi + asset=$(jq -r ".[0]" <<<"$matches") url=$(jq -r .url <<<"$asset") name=$(jq -r .name <<<"$asset") file="${dir}/${name}" @@ -124,15 +124,17 @@ get_rv_prebuilts() { tag_name=$(cut -d'-' -f3- <<<"$name") tag_name=v${tag_name%.*} fi + if [ "$tag" = "Patches" ]; then - if [ $grab_cl = true ]; then echo -e "[Changelog](https://github.com/${src}/releases/tag/${tag_name})\n" >>"${cl_dir}/changelog.md"; fi - # Skip integrations check patching for Morphe (not applicable) - if [ "$REMOVE_RV_INTEGRATIONS_CHECKS" = true ] && [ "$is_morphe" = false ]; then + if [ "$grab_cl" = true ]; then echo -e "[Changelog](https://github.com/${src}/releases/tag/${tag_name})\n" >>"${cl_dir}/changelog.md"; fi + if [ "$REMOVE_RV_INTEGRATIONS_CHECKS" = true ]; then + local extensions_ext + extensions_ext=$(unzip -l "${file}" "extensions/shared.*" | grep -o "shared\..*") extensions_ext="${extensions_ext#*.}" if ! ( mkdir -p "${file}-zip" || return 1 unzip -qo "${file}" -d "${file}-zip" || return 1 - java -cp "${BIN_DIR}/paccer.jar:${BIN_DIR}/dexlib2.jar" com.jhc.Main "${file}-zip/extensions/shared.rve" "${file}-zip/extensions/shared-patched.rve" || return 1 - mv -f "${file}-zip/extensions/shared-patched.rve" "${file}-zip/extensions/shared.rve" || return 1 + java -cp "${BIN_DIR}/paccer.jar:${BIN_DIR}/dexlib2.jar" com.jhc.Main "${file}-zip/extensions/shared.${extensions_ext}" "${file}-zip/extensions/shared-patched.${extensions_ext}" || return 1 + mv -f "${file}-zip/extensions/shared-patched.${extensions_ext}" "${file}-zip/extensions/shared.${extensions_ext}" || return 1 rm "${file}" || return 1 cd "${file}-zip" || abort zip -0rq "${CWD}/${file}" . || return 1 @@ -167,7 +169,7 @@ config_update() { if [ -z "$table_name" ]; then continue; fi t=$(toml_get_table "$table_name") enabled=$(toml_get "$t" enabled) || enabled=true - if [ "$enabled" = false ]; then continue; fi + if [ "$enabled" = "false" ]; then continue; fi PATCHES_SRC=$(toml_get "$t" patches-source) || PATCHES_SRC=$DEF_PATCHES_SRC PATCHES_VER=$(toml_get "$t" patches-version) || PATCHES_VER=$DEF_PATCHES_VER if [[ -v sources["$PATCHES_SRC/$PATCHES_VER"] ]]; then @@ -176,22 +178,17 @@ config_update() { sources["$PATCHES_SRC/$PATCHES_VER"]=0 local rv_rel="https://api.github.com/repos/${PATCHES_SRC}/releases" if [ "$PATCHES_VER" = "dev" ]; then - last_patches=$(gh_req "$rv_rel" - | jq -e -r '.[0]') + last_patches=$(gh_req "$rv_rel" - | jq -e -r '.[0]') || continue elif [ "$PATCHES_VER" = "latest" ]; then - last_patches=$(gh_req "$rv_rel/latest" -) + last_patches=$(gh_req "$rv_rel/latest" -) || continue else - last_patches=$(gh_req "$rv_rel/tags/${ver}" -) + last_patches=$(gh_req "$rv_rel/tags/${ver}" -) || continue fi - # Detect if using Morphe or ReVanced based on patches source - local patches_ext="rvp" - if [[ "$PATCHES_SRC" == *"MorpheApp"* ]] || [[ "$PATCHES_SRC" == *"morphe"* ]]; then - patches_ext="mpp" - fi - if ! last_patches=$(jq -e -r ".assets[] | select(.name | endswith(\"$patches_ext\")) | .name" <<<"$last_patches"); then - abort oops + if ! last_patches=$(jq -e -r '.assets[] | select(.name | (endswith("asc") or endswith("json")) | not) | .name' <<<"$last_patches"); then + abort "config_update error: '$last_patches'" fi if [ "$last_patches" ]; then - if ! OP=$(grep "^Patches: ${PATCHES_SRC%%/*}/" build.md | grep "$last_patches"); then + if ! OP=$(grep "^Patches: ${PATCHES_SRC%%/*}/" build.md | grep -m1 "$last_patches"); then sources["$PATCHES_SRC/$PATCHES_VER"]=1 prcfg=true upped+=("$table_name") @@ -214,32 +211,24 @@ config_update() { _req() { local ip="$1" op="$2" shift 2 - if [ "$op" = - ]; then - if ! curl -L -c "$TEMP_DIR/cookie.txt" -b "$TEMP_DIR/cookie.txt" --connect-timeout 10 --retry 3 --retry-delay 2 --fail -s -S "$@" "$ip"; then - epr "Request failed: $ip" - return 1 - fi - else + local dlp="$op" + if [ "$op" != - ]; then if [ -f "$op" ]; then return; fi - local dlp dlp="$(dirname "$op")/tmp.$(basename "$op")" if [ -f "$dlp" ]; then while [ -f "$dlp" ]; do sleep 1; done return fi - if ! curl -L -c "$TEMP_DIR/cookie.txt" -b "$TEMP_DIR/cookie.txt" --connect-timeout 10 --retry 3 --retry-delay 2 --fail -s -S "$@" "$ip" -o "$dlp"; then - epr "Request failed: $ip" - return 1 - fi + fi + if ! curl -L -c "$TEMP_DIR/cookie.txt" -b "$TEMP_DIR/cookie.txt" --connect-timeout 10 --retry 1 --fail -s -S "$@" "$ip" -o "$dlp"; then + epr "Request failed: $ip" + return 1 + fi + if [ "$dlp" != - ]; then mv -f "$dlp" "$op" fi } -req() { - _req "$1" "$2" \ - -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0" \ - -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8" \ - -H "Accept-Language: en-US,en;q=0.5" -} +req() { _req "$1" "$2" -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0"; } gh_req() { _req "$1" "$2" -H "$GH_HEADER"; } gh_dl() { if [ ! -f "$1" ]; then @@ -257,6 +246,7 @@ get_highest_ver() { } semver_validate() { local a="${1%-*}" + local a="${a#v}" local ac="${a//[.0-9]/}" [ ${#ac} = 0 ] } @@ -280,11 +270,13 @@ get_patch_last_supported_ver() { return fi fi - op=$(patches_list_versions "$rv_cli_jar" "$rv_patches_jar" "$pkg_name") || return 1 - op=$(tail -n +3 <<<"$op" | awk '{$1=$1}1') + op=$(patches_list_versions "$cli_jar" "$patches_jar" "$pkg_name") || return 1 + op=$(sed -n '/(.* patch.*/,$p' <<<"$op" | awk '{$1=$1}1') if [ "$op" = "Any" ]; then return; fi pcount=$(head -1 <<<"$op") pcount=${pcount#*(} pcount=${pcount% *} - if [ -z "$pcount" ]; then abort "No patches found for '$pkg_name' in patches '$rv_patches_jar'"; fi + if [ -z "$pcount" ]; then + abort "No patches found for '$pkg_name' in patches '$patches_jar'" + fi grep -F "($pcount patch" <<<"$op" | sed 's/ (.* patch.*//' | get_highest_ver || return 1 } @@ -321,27 +313,18 @@ merge_splits() { local bundle=$1 output=$2 pr "Merging splits" gh_dl "$TEMP_DIR/apkeditor.jar" "https://github.com/REAndroid/APKEditor/releases/download/V1.4.7/APKEditor-1.4.7.jar" >/dev/null || return 1 - if ! OP=$(java -jar "$TEMP_DIR/apkeditor.jar" merge -i "${bundle}" -o "${bundle}.mzip" -clean-meta -f 2>&1); then - epr "Apkeditor ERROR: $OP" + if ! OP=$(java -jar "$TEMP_DIR/apkeditor.jar" merge -i "$bundle" -o "${output}-unsigned" -clean-meta -f 2>&1); then + epr "APKEditor error: $OP" return 1 fi - # this is required because of apksig - mkdir "${bundle}-zip" - unzip -qo "${bundle}.mzip" -d "${bundle}-zip" - ( - cd "${bundle}-zip" || abort - zip -0rq "${CWD}/${bundle}.zip" . - ) - # if building module, sign the merged apk properly - if isoneof "module" "${build_mode_arr[@]}"; then - patch_apk "${bundle}.zip" "${output}" "--exclusive" "${args[cli]}" "${args[ptjar]}" - local ret=$? - else - cp "${bundle}.zip" "${output}" - local ret=$? + # sign the merged stock apk + if ! OP=$(java -jar "$APKSIGNER" sign --ks ks-p12.keystore --ks-pass pass:123456789 --key-pass pass:123456789 --ks-key-alias jhc \ + --out "${output}" "${output}-unsigned"); then + epr "apksigner error: $OP" + return 1 fi - rm -r "${bundle}-zip" "${bundle}.zip" "${bundle}.mzip" || : - return $ret + rm "${output}.idsig" "${output}-unsigned" 2>/dev/null || : + return 0 } # -------------------- apkmirror -------------------- @@ -354,7 +337,7 @@ apkmirror_search() { for ((n = 1; n < 40; n++)); do node=$($HTMLQ "div.table-row.headerFont:nth-last-child($n)" -r "span:nth-child(n+3)" <<<"$resp") if [ -z "$node" ]; then break; fi - emptyCheck=$($HTMLQ -t -w "div.table-cell:nth-child(1) > a:nth-child(1)" --attribute class <<<"$node" | xargs) + emptyCheck=$($HTMLQ -t -w "div.table-cell:nth-child(1) > a:nth-child(1)" <<<"$node" | xargs) if [ "$emptyCheck" ]; then dlurl=$($HTMLQ --base https://www.apkmirror.com --attribute href "div:nth-child(1) > a:nth-child(1)" <<<"$node") else break; fi @@ -501,30 +484,34 @@ dl_archive() { } get_archive_resp() { local r - r=$(req "$1" -) || return 1 + r=$(req "$1" -) if [ -z "$r" ]; then return 1; else __ARCHIVE_RESP__=$(sed -n 's;^/dev/null || : @@ -537,6 +524,7 @@ check_sig() { local sig if grep -q "$pkg_name" sig.txt; then sig=$(java -jar "$APKSIGNER" verify --print-certs "$file" | grep ^Signer | grep SHA-256 | tail -1 | awk '{print $NF}') + echo "$pkg_name signature: ${sig}" grep -qFx "$sig $pkg_name" sig.txt fi } @@ -559,9 +547,9 @@ build_rv() { [ "${args[exclusive_patches]}" = true ] && p_patcher_args+=("--exclusive") local tried_dl=() - for dl_p in archive apkmirror uptodown; do + for dl_p in "${DL_SRCS[@]}"; do if [ -z "${args[${dl_p}_dlurl]}" ]; then continue; fi - if ! get_${dl_p}_resp "${args[${dl_p}_dlurl]}" || ! pkg_name=$(get_"${dl_p}"_pkg_name) || [ -z "$pkg_name" ]; then + if ! get_${dl_p}_resp "${args[${dl_p}_dlurl]}" || ! pkg_name=$(get_"${dl_p}"_pkg_name); then args[${dl_p}_dlurl]="" epr "ERROR: Could not find ${table} in ${dl_p}" continue @@ -574,14 +562,15 @@ build_rv() { epr "empty pkg name, not building ${table}." return 0 fi + pr "Package name of '${table}' is '$pkg_name'" local list_patches - list_patches=$(patches_list "$rv_cli_jar" "$rv_patches_jar" "$pkg_name") || return 1 - + list_patches=$(patches_list "$cli_jar" "$patches_jar" "$pkg_name") || return 1 local get_latest_ver=false if [ "$version_mode" = auto ]; then if ! version=$(get_patch_last_supported_ver "$list_patches" "$pkg_name" \ "${args[included_patches]}" "${args[excluded_patches]}" "${args[exclusive_patches]}"); then - exit 1 + epr "get_patch_last_supported_ver failed '$list_patches'" + return elif [ -z "$version" ]; then get_latest_ver=true; fi elif isoneof "$version_mode" latest beta; then get_latest_ver=true @@ -613,27 +602,36 @@ build_rv() { version_f=${version_f#v} local stock_apk="${TEMP_DIR}/${pkg_name}-${version_f}-${arch_f}.apk" if [ ! -f "$stock_apk" ]; then - for dl_p in archive apkmirror uptodown; do + for dl_p in "${DL_SRCS[@]}"; do if [ -z "${args[${dl_p}_dlurl]}" ]; then continue; fi - pr "Downloading '${table}' from ${dl_p}" - if ! isoneof $dl_p "${tried_dl[@]}"; then get_${dl_p}_resp "${args[${dl_p}_dlurl]}" || true; fi + pr "Downloading '${table}' from '${dl_p}'" + if ! isoneof $dl_p "${tried_dl[@]}"; then + if ! get_${dl_p}_resp "${args[${dl_p}_dlurl]}"; then + epr "ERROR: Could not get '${table}' from '${dl_p}'" + continue + fi + fi if ! dl_${dl_p} "${args[${dl_p}_dlurl]}" "$version" "$stock_apk" "$arch" "${args[dpi]}" "$get_latest_ver"; then - epr "ERROR: Could not download '${table}' from ${dl_p} with version '${version}', arch '${arch}', dpi '${args[dpi]}'" + epr "ERROR: Could not download '${table}' from '${dl_p}' with version '${version}', arch '${arch}', dpi '${args[dpi]}'" continue fi break done - if [ ! -f "$stock_apk" ]; then return 0; fi + if [ ! -f "$stock_apk" ]; then + epr "Stock apk not found ($stock_apk)" + return 0 + fi fi - if ! OP=$(check_sig "$stock_apk" "$pkg_name" 2>&1) && ! grep -qFx "ERROR: Missing META-INF/MANIFEST.MF" <<<"$OP"; then - abort "apk signature mismatch '$stock_apk': $OP" + if [ ! -f "${stock_apk}.apkm" ] && ! OP=$(check_sig "$stock_apk" "$pkg_name" 2>&1) && ! grep -qFx "ERROR: Missing META-INF/MANIFEST.MF" <<<"$OP"; then + epr "Not building $table, apk signature mismatch '$stock_apk': $OP" + return 0 fi log "${table}: ${version}" local microg_patch microg_patch=$(grep "^Name: " <<<"$list_patches" | grep -i "gmscore\|microg" || :) microg_patch=${microg_patch#*: } if [ -n "$microg_patch" ] && [[ ${p_patcher_args[*]} =~ $microg_patch ]]; then - epr "You cant include/exclude microg patch as that's done by rvmm builder automatically." + wpr "You cant include/exclude microg patch as that's done by rvmm builder automatically." p_patcher_args=("${p_patcher_args[@]//-[ei] ${microg_patch}/}") fi @@ -656,24 +654,31 @@ build_rv() { patcher_args+=("-d \"${microg_patch}\"") fi fi - if [ "${args[riplib]}" = true ]; then - patcher_args+=("--rip-lib x86_64 --rip-lib x86") - if [ "$build_mode" = module ]; then - patcher_args+=("--rip-lib arm64-v8a --rip-lib armeabi-v7a --unsigned") + + local stock_apk_to_patch="${stock_apk}.stripped.apk" + cp -f "$stock_apk" "$stock_apk_to_patch" + if [ "$build_mode" = module ]; then + zip -d "$stock_apk_to_patch" "lib/*" >/dev/null 2>&1 || : + else + if [ "$arch" = "arm64-v8a" ]; then + zip -d "$stock_apk_to_patch" "lib/armeabi-v7a/*" "lib/x86_64/*" "lib/x86/*" >/dev/null 2>&1 || : + elif [ "$arch" = "arm-v7a" ]; then + zip -d "$stock_apk_to_patch" "lib/arm64-v8a/*" "lib/x86_64/*" "lib/x86/*" >/dev/null 2>&1 || : + elif [ "$arch" = "x86" ]; then + zip -d "$stock_apk_to_patch" "lib/arm64-v8a/*" "lib/x86_64/*" "lib/armeabi-v7a/*" >/dev/null 2>&1 || : + elif [ "$arch" = "x86_64" ]; then + zip -d "$stock_apk_to_patch" "lib/arm64-v8a/*" "lib/armeabi-v7a/*" "lib/x86/*" >/dev/null 2>&1 || : else - if [ "$arch" = "arm64-v8a" ]; then - patcher_args+=("--rip-lib armeabi-v7a") - elif [ "$arch" = "arm-v7a" ]; then - patcher_args+=("--rip-lib arm64-v8a") - fi + zip -d "$stock_apk_to_patch" "lib/x86_64/*" "lib/x86/*" >/dev/null 2>&1 || : fi fi if [ "${NORB:-}" != true ] || [ ! -f "$patched_apk" ]; then - if ! patch_apk "$stock_apk" "$patched_apk" "${patcher_args[*]}" "${args[cli]}" "${args[ptjar]}"; then + if ! patch_apk "$stock_apk_to_patch" "$patched_apk" "${patcher_args[*]}" "${args[cli]}" "${args[ptjar]}"; then epr "Building '${table}' failed!" return 0 fi fi + rm "$stock_apk_to_patch" if [ "$build_mode" = apk ]; then local apk_output="${BUILD_DIR}/${app_name_l}-${rv_brand_f}-v${version_f}-${arch_f}.apk" mv -f "$patched_apk" "$apk_output" @@ -687,18 +692,16 @@ build_rv() { module_config "$base_template" "$pkg_name" "$version" "$arch" - local rv_patches_ver="${rv_patches_jar##*-}" - rv_patches_ver="${rv_patches_ver%%.rvp}" - rv_patches_ver="${rv_patches_ver%%.mpp}" + local patches_ver="${patches_jar##*-}" module_prop \ "${args[module_prop_name]}" \ "${app_name} ${args[rv_brand]}" \ - "${version} (patches: ${rv_patches_ver})" \ - "${app_name} ${args[rv_brand]} Magisk module" \ + "${version} (patches ${patches_ver})" \ + "${app_name} ${args[rv_brand]} module" \ "https://raw.githubusercontent.com/${GITHUB_REPOSITORY-}/update/${upj}" \ "$base_template" - local module_output="${app_name_l}-${rv_brand_f}-magisk-v${version_f}-${arch_f}.zip" + local module_output="${app_name_l}-${rv_brand_f}-module-v${version_f}-${arch_f}.zip" pr "Packing module ${table}" cp -f "$patched_apk" "${base_template}/base.apk" if [ "${args[include_stock]}" = true ]; then cp -f "$stock_apk" "${base_template}/${pkg_name}.apk"; fi @@ -731,5 +734,5 @@ versionCode=${NEXT_VER_CODE} author=j-hc description=${4}" >"${6}/module.prop" - if [ "$ENABLE_MAGISK_UPDATE" = true ]; then echo "updateJson=${5}" >>"${6}/module.prop"; fi + if [ "$ENABLE_MODULE_UPDATE" = true ]; then echo "updateJson=${5}" >>"${6}/module.prop"; fi }