From 5a26cec58c0c65543c4b8faf46d8db6c05bcdcb2 Mon Sep 17 00:00:00 2001 From: tehcneko <7764726+tehcneko@users.noreply.github.com> Date: Fri, 12 Mar 2021 16:57:47 +0800 Subject: [PATCH] [core] Use riru.sh from riru module template (#340) * [core] Use riru.sh from riru module template * [core] Remove unused scripts * [core] Fix riru version in log file --- core/build.gradle.kts | 12 +- core/template_override/customize.sh | 133 +++++++-------------- core/template_override/post-fs-data.sh | 145 ++++++++++------------- core/template_override/riru.sh | 64 ++++++++++ core/template_override/uninstall.sh | 26 +--- core/template_override/util_functions.sh | 59 ++------- core/template_override/verify.sh | 12 +- core/template_override/zh_CN.sh | 70 ----------- core/tpl/module.prop.tpl | 2 +- 9 files changed, 198 insertions(+), 325 deletions(-) create mode 100644 core/template_override/riru.sh delete mode 100644 core/template_override/zh_CN.sh diff --git a/core/build.gradle.kts b/core/build.gradle.kts index cb1156cb..ad2397d8 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -43,7 +43,7 @@ val authors = "LSPosed Developers" val riruModuleId = "lsposed" val moduleMinRiruApiVersion = 24 -val moduleMinRiruVersionName = "v24.0.0" +val moduleMinRiruVersionName = "v24.1.0" val moduleMaxRiruApiVersion = 24 val defaultManagerPackageName: String by rootProject.extra @@ -158,12 +158,13 @@ afterEvaluate { doFirst { copy { from("$projectDir/tpl/module.prop.tpl") - into("$projectDir/template_override") + into(zipPathMagiskReleasePath) rename("module.prop.tpl", "module.prop") expand("moduleId" to moduleId, "versionName" to verName, "versionCode" to verCode, - "authorList" to authors) + "authorList" to authors, + "minRiruVersionName" to moduleMinRiruVersionName) filter(mapOf("eol" to FixCrLfFilter.CrLf.newInstance("lf")), FixCrLfFilter::class.java) } copy { @@ -172,7 +173,6 @@ afterEvaluate { } } val libPathRelease = "${buildDir}/intermediates/cmake/$variantLowered/obj" - val excludeList = arrayOf("util_functions.sh") doLast { val dexOutPath = if (variant.name.contains("release")) "$buildDir/intermediates/dex/$variantLowered/minify${variantCapped}WithR8" else @@ -186,12 +186,12 @@ afterEvaluate { copy { from("${projectDir}/template_override") into(zipPathMagiskReleasePath) - exclude(*excludeList) + exclude("riru.sh") } copy { from("${projectDir}/template_override") into(zipPathMagiskReleasePath) - include("util_functions.sh") + include("riru.sh") filter { line -> line.replace("%%%RIRU_MODULE_ID%%%", riruModuleId) .replace("%%%RIRU_MODULE_API_VERSION%%%", moduleMaxRiruApiVersion.toString()) diff --git a/core/template_override/customize.sh b/core/template_override/customize.sh index e50d17bd..bc29f5c1 100644 --- a/core/template_override/customize.sh +++ b/core/template_override/customize.sh @@ -32,69 +32,16 @@ POUNDS="*********************************************************" VERSION=$(grep_prop version "${TMPDIR}/module.prop") -### lang start ### -# Default en_US -# customize -LANG_CUST_INST_VERSION="version" -LANG_CUST_INST_EXT_FILES="Extracting module files" -LANG_CUST_INST_EXT_LIB_X86="Extracting x86 libraries" -LANG_CUST_INST_EXT_LIB_X64="Extracting x86_64 libraries" -LANG_CUST_INST_EXT_LIB_ARM="Extracting arm libraries" -LANG_CUST_INST_EXT_LIB_ARM64="Extracting arm64 libraries" -LANG_CUST_INST_CONF_CREATE="Creating configuration directories" -LANG_CUST_INST_CONF_OLD="Use previous path" -LANG_CUST_DISABLE_EDXP="**WARNING**: This installation will disable edxposed because of incompatibility" -LANG_CUST_INST_CONF_NEW="Use new path" -LANG_CUST_INST_COPY_LIB="Copying framework libraries" -LANG_CUST_INST_DONE="Welcome to" +ui_print "- LSPosed version ${VERSION}" -LANG_CUST_ERR_VERIFY_FAIL="Unable to extract verify tool!" -LANG_CUST_ERR_PERM="Can't set permission" -LANG_CUST_ERR_CONF_CREATE="Can't create configuration path" -LANG_CUST_ERR_CONF_STORE="Can't store configuration path" -LANG_CUST_ERR_CONF_FIRST="Can't create first install flag" -LANG_CUST_ERR_CONF_UNINST="Can't write uninstall script" - -# verify -LANG_VERIFY_SUCCESS="Verified" - -LANG_VERIFY_ERR_MISMATCH="Failed to verify" -LANG_VERIFY_ERR_NOT_EXIST="not exists" -LANG_VERIFY_ERR_NOTICE="This zip may be corrupted, please try downloading again" - -# util_functions -LANG_UTIL_PLATFORM="Device platform" - -LANG_UTIL_ERR_RIRU_NOT_FOUND_1="is not installed" -LANG_UTIL_ERR_RIRU_NOT_FOUND_2="Please install Riru from Magisk Manager" -LANG_UTIL_ERR_RIRU_LOW_1="or above is required" -LANG_UTIL_ERR_RIRU_LOW_2="Please upgrade Riru from Magisk Manager" -LANG_UTIL_ERR_ANDROID_UNSUPPORT_1="Unsupported Android version" -LANG_UTIL_ERR_ANDROID_UNSUPPORT_2="(below Oreo)" -LANG_UTIL_ERR_ANDROID_UNSUPPORT_3="Learn more from our GitHub Wiki" -LANG_UTIL_ERR_PLATFORM_UNSUPPORT="Unsupported platform" -LANG_CUST_INST_MIGRATE_CONF="Migrating configuration" - -# Load lang -if [ ${BOOTMODE} == true ]; then - locale=$(getprop persist.sys.locale|awk -F "-" '{print $1"_"$NF}') - [ ${locale} == "" ] && locale=$(settings get system system_locales|awk -F "," '{print $1}'|awk -F "-" '{print $1"_"$NF}') - file=${locale}.sh - unzip -o "$ZIPFILE" "${file}" -d "$TMPDIR" >&2 - unzip -o "$ZIPFILE" "${file}.sha256" -d "$TMPDIR" >&2 - (echo "$(cat "${TMPDIR}/${file}.sha256") ${TMPDIR}/${file}" | sha256sum -c -s -) && . "${TMPDIR}/${file}" -fi -### lang end ### - -ui_print "- LSPosed ${LANG_CUST_INST_VERSION} ${VERSION}" - -# extract verify.sh +# Extract verify.sh +ui_print "- Extracting verify.sh" unzip -o "$ZIPFILE" 'verify.sh' -d "$TMPDIR" >&2 if [ ! -f "$TMPDIR/verify.sh" ]; then - ui_print "${POUNDS}" - ui_print "! ${LANG_CUST_ERR_VERIFY_FAIL}" - ui_print "! ${LANG_VERIFY_ERR_NOTICE}" - abortC "${POUNDS}" + ui_print "${POUNDS}" + ui_print "! Unable to extract verify.sh!" + ui_print "! This zip may be corrupted, please try downloading again" + abortC "${POUNDS}" fi . $TMPDIR/verify.sh @@ -103,81 +50,91 @@ extract "$ZIPFILE" 'util_functions.sh' "${TMPDIR}" . ${TMPDIR}/util_functions.sh check_android_version -check_riru_version -lspd_check_architecture -ui_print "- ${LANG_CUST_INST_EXT_FILES}" +extract "$ZIPFILE" 'riru.sh' "$MODPATH" +. $MODPATH/riru.sh + +# Functions from riru.sh +check_riru_version +enforce_install_from_magisk_app + +# Check architecture +if [ "$ARCH" != "arm" ] && [ "$ARCH" != "arm64" ] && [ "$ARCH" != "x86" ] && [ "$ARCH" != "x64" ]; then + abort "! Unsupported platform: $ARCH" +else + ui_print "- Device platform: $ARCH" +fi + +ui_print "- Extracting module files" # extract module files extract "${ZIPFILE}" 'module.prop' "${MODPATH}" extract "${ZIPFILE}" 'system.prop' "${MODPATH}" extract "${ZIPFILE}" 'sepolicy.rule' "${MODPATH}" extract "${ZIPFILE}" 'post-fs-data.sh' "${MODPATH}" -extract "${ZIPFILE}" 'service.sh' "${MODPATH}" +#extract "${ZIPFILE}" 'service.sh' "${MODPATH}" extract "${ZIPFILE}" 'uninstall.sh' "${MODPATH}" - extract "${ZIPFILE}" 'framework/lspd.dex' "${MODPATH}" + if [ "$ARCH" = "x86" ] || [ "$ARCH" = "x64" ]; then - ui_print "- ${LANG_CUST_INST_EXT_LIB_X86}" + ui_print "- Extracting x86 libraries" extract "$ZIPFILE" 'riru_x86/lib/liblspd.so' "${MODPATH}" if [ "$IS64BIT" = true ]; then - ui_print "- ${LANG_CUST_INST_EXT_LIB_X64}" + ui_print "- Extracting x86_64 libraries" extract "$ZIPFILE" 'riru_x86/lib64/liblspd.so' "${MODPATH}" fi mv "${MODPATH}/riru_x86" "${MODPATH}/riru" else - ui_print "- ${LANG_CUST_INST_EXT_LIB_ARM}" + ui_print "- Extracting arm libraries" extract "$ZIPFILE" 'riru/lib/liblspd.so' "${MODPATH}" if [ "$IS64BIT" = true ]; then - ui_print "- ${LANG_CUST_INST_EXT_LIB_ARM64}" + ui_print "- Extracting arm64 libraries" extract "$ZIPFILE" 'riru/lib64/liblspd.so' "${MODPATH}" fi fi -ui_print "- ${LANG_CUST_INST_CONF_CREATE}" +ui_print "- Creating configuration directories" if [ -f /data/adb/lspd/misc_path ]; then # read current MISC_PATH MISC_PATH=$(cat /data/adb/lspd/misc_path) - ui_print " - ${LANG_CUST_INST_CONF_OLD} $MISC_PATH" + ui_print " - Use previous path $MISC_PATH" elif [ -f /data/adb/edxp/misc_path ]; then - mkdir -p /data/adb/lspd || abortC "! ${LANG_CUST_ERR_CONF_CREATE}" + mkdir -p /data/adb/lspd || abortC "! Can't create configuration path" MISC_PATH=$(cat /data/adb/edxp/misc_path | sed "s/edxp/lspd/") - echo $MISC_PATH > /data/adb/lspd/misc_path - ui_print " - ${LANG_CUST_INST_CONF_OLD} $MISC_PATH" + echo $MISC_PATH >/data/adb/lspd/misc_path + ui_print " - Use previous path $MISC_PATH" cp -r /data/misc/$(cat /data/adb/edxp/misc_path) /data/misc/$MISC_PATH - ui_print " - ${LANG_CUST_DISABLE_EDXP}" + ui_print " - WARNING: This installation will disable EdXposed because of incompatibility" touch $(magisk --path)/.magisk/modules/riru_edxposed/disable touch $(magisk --path)/.magisk/modules/riru_edxposed_sandhook/disable else # generate random MISC_PATH - MISC_RAND=$(tr -cd 'A-Za-z0-9' < /dev/urandom | head -c16) + MISC_RAND=$(tr -cd 'A-Za-z0-9' /data/adb/lspd/misc_path || abortC "! ${LANG_CUST_ERR_CONF_STORE}" + ui_print " - Use new path ${MISC_RAND}" + mkdir -p /data/adb/lspd || abortC "! Can't create configuration path" + echo "$MISC_PATH" >/data/adb/lspd/misc_path || abortC "! Can't store configuration path" fi -touch /data/adb/lspd/new_install || abortC "! ${LANG_CUST_ERR_CONF_FIRST}" -ui_print "- ${LANG_CUST_INST_COPY_LIB}" + extract "${ZIPFILE}" 'manager.apk' "/data/adb/lspd/" mkdir -p /data/misc/$MISC_PATH -set_perm /data/misc/$MISC_PATH 0 0 0771 "u:object_r:magisk_file:s0" || abortC "! ${LANG_CUST_ERR_PERM}" +set_perm /data/misc/$MISC_PATH 0 0 0771 "u:object_r:magisk_file:s0" || abortC "! Can't set permission" if [ ! -d /data/adb/lspd/config ]; then mkdir -p /data/adb/lspd/config - ui_print "- ${LANG_CUST_INST_MIGRATE_CONF}" + ui_print "- Migrating configuration" cp -r /data/misc/$MISC_PATH/0/prefs /data/misc/$MISC_PATH/prefs /system/bin/app_process -Djava.class.path=/data/adb/lspd/framework/lspd.dex /system/bin --nice-name=lspd_config org.lsposed.lspd.service.ConfigManager fi -echo "rm -rf /data/misc/$MISC_PATH" >> "${MODPATH}/uninstall.sh" || abortC "! ${LANG_CUST_ERR_CONF_UNINST}" -echo "[ -f /data/adb/lspd/new_install ] || rm -rf /data/adb/lspd" >> "${MODPATH}/uninstall.sh" || abortC "! ${LANG_CUST_ERR_CONF_UNINST}" +echo "rm -rf /data/misc/$MISC_PATH" >>"${MODPATH}/uninstall.sh" || abortC "! Can't write uninstall script" +echo "rm -rf /data/adb/lspd" >>"${MODPATH}/uninstall.sh" || abortC "! Can't write uninstall script" if [ ! -e /data/adb/lspd/config/verbose_log ]; then - echo "0" > /data/adb/lspd/config/verbose_log + echo "0" >/data/adb/lspd/config/verbose_log fi set_perm_recursive "${MODPATH}" 0 0 0755 0644 -ui_print "- ${LANG_CUST_INST_DONE} LSPosed ${VERSION}!" - +ui_print "- Welcome to LSPosed ${VERSION}!" diff --git a/core/template_override/post-fs-data.sh b/core/template_override/post-fs-data.sh index bd25923f..56c04831 100644 --- a/core/template_override/post-fs-data.sh +++ b/core/template_override/post-fs-data.sh @@ -21,22 +21,23 @@ # grep_prop() { - local REGEX="s/^$1=//p" - shift - local FILES="$@" - [ -z "$FILES" ] && FILES='/system/build.prop' - sed -n "$REGEX" ${FILES} 2>/dev/null | head -n 1 + local REGEX="s/^$1=//p" + shift + local FILES="$@" + [ -z "$FILES" ] && FILES='/system/build.prop' + sed -n "$REGEX" ${FILES} 2>/dev/null | head -n 1 } MODDIR=${0%/*} -RIRU_PATH="/data/adb/riru" -RIRU_PROP="$(magisk --path)/.magisk/modules/riru-core/module.prop" -TARGET="${RIRU_PATH}/modules" +MAGISK_VERSION=$(magisk -v) +MAGISK_VER_CODE=$(magisk -V) + +[ ! -f "$MODDIR/riru.sh" ] && exit 1 +. $MODDIR/riru.sh LSPD_VERSION=$(grep_prop version "${MODDIR}/module.prop") LSPD_VERSIONCODE=$(grep_prop versionCode "${MODDIR}/module.prop") -LSPD_APICODE=$(grep_prop api "${MODDIR}/module.prop") ANDROID_SDK=$(getprop ro.build.version.sdk) BUILD_DESC=$(getprop ro.build.description) @@ -50,13 +51,6 @@ DEVICE=$(getprop ro.product.device) ANDROID=$(getprop ro.build.version.release) BUILD=$(getprop ro.build.id) -RIRU_VERSION=$(grep_prop version $RIRU_PROP) -RIRU_VERCODE=$(grep_prop versionCode $RIRU_PROP) -RIRU_APICODE=$(cat "${RIRU_PATH}/api_version") - -MAGISK_VERSION=$(magisk -v) -MAGISK_VERCODE=$(magisk -V) - MISC_PATH=$(cat /data/adb/lspd/misc_path) BASE_PATH="/data/misc/$MISC_PATH" @@ -65,76 +59,67 @@ ENABLE_VERBOSE_LOG_FILE="/data/adb/lspd/config/verbose_log" LOG_VERBOSE=false if [ "$(cat "${ENABLE_VERBOSE_LOG_FILE}")" = "1" ]; then - LOG_VERBOSE=true + LOG_VERBOSE=true fi # If logcat client is kicked out by klogd server, we'll restart it. # However, if it is killed manually or by LSPosed Manager, we'll exit. # Refer to https://github.com/ElderDrivers/LSPosed/pull/575 for more information. loop_logcat() { - while true - do - logcat $* - if [ $? -ne 1 ]; then - break - fi - done + while true; do + logcat $* + if [ $? -ne 1 ]; then + break + fi + done } print_log_head() { - LOG_FILE=$1 - touch "${LOG_FILE}" - chmod 666 "${LOG_FILE}" - echo "LSPosed Log">>"${LOG_FILE}" - echo "--------- beginning of information">>"${LOG_FILE}" - echo "Manufacturer: ${MANUFACTURER}">>"${LOG_FILE}" - echo "Brand: ${BRAND}">>"${LOG_FILE}" - echo "Device: ${DEVICE}">>"${LOG_FILE}" - echo "Product: ${PRODUCT}">>"${LOG_FILE}" - echo "Model: ${MODEL}">>"${LOG_FILE}" - echo "Fingerprint: ${FINGERPRINT}">>"${LOG_FILE}" - echo "ROM description: ${BUILD_DESC}">>"${LOG_FILE}" - echo "Architecture: ${ARCH}">>"${LOG_FILE}" - echo "Android build: ${BUILD}">>"${LOG_FILE}" - echo "Android version: ${ANDROID}">>"${LOG_FILE}" - echo "Android sdk: ${ANDROID_SDK}">>"${LOG_FILE}" - echo "LSPosed version: ${LSPD_VERSION}">>"${LOG_FILE}" - echo "LSPosed version code: ${LSPD_VERSIONCODE}">>"${LOG_FILE}" - echo "LSPosed api: ${LSPD_APICODE}">>"${LOG_FILE}" - echo "Riru version: ${RIRU_VERSION} (${RIRU_VERCODE})">>"${LOG_FILE}" - echo "Riru api: ${RIRU_APICODE}">>"${LOG_FILE}" - echo "Magisk: ${MAGISK_VERSION%:*} (${MAGISK_VERCODE})">>"${LOG_FILE}" + LOG_FILE=$1 + touch "${LOG_FILE}" + chmod 666 "${LOG_FILE}" + echo "LSPosed Log" >>"${LOG_FILE}" + echo "--------- beginning of information" >>"${LOG_FILE}" + echo "Manufacturer: ${MANUFACTURER}" >>"${LOG_FILE}" + echo "Brand: ${BRAND}" >>"${LOG_FILE}" + echo "Device: ${DEVICE}" >>"${LOG_FILE}" + echo "Product: ${PRODUCT}" >>"${LOG_FILE}" + echo "Model: ${MODEL}" >>"${LOG_FILE}" + echo "Fingerprint: ${FINGERPRINT}" >>"${LOG_FILE}" + echo "ROM description: ${BUILD_DESC}" >>"${LOG_FILE}" + echo "Architecture: ${ARCH}" >>"${LOG_FILE}" + echo "Android build: ${BUILD}" >>"${LOG_FILE}" + echo "Android version: ${ANDROID}" >>"${LOG_FILE}" + echo "Android sdk: ${ANDROID_SDK}" >>"${LOG_FILE}" + echo "LSPosed version: ${LSPD_VERSION} (${LSPD_VERSIONCODE})" >>"${LOG_FILE}" + echo "Riru version: ${RIRU_VERSION_NAME} (${RIRU_VERSION_CODE})" >>"${LOG_FILE}" + echo "Riru api: ${RIRU_API}" >>"${LOG_FILE}" + echo "Magisk: ${MAGISK_VERSION%:*} (${MAGISK_VER_CODE})" >>"${LOG_FILE}" } -start_log_catcher () { - LOG_FILE_NAME=$1 - LOG_TAG_FILTERS=$2 - CLEAN_OLD=$3 - START_NEW=$4 - LOG_FILE="${LOG_PATH}/${LOG_FILE_NAME}.log" - PID_FILE="${LOG_PATH}/${LOG_FILE_NAME}.pid" - mkdir -p ${LOG_PATH} - if [ ${CLEAN_OLD} == true ]; then - rm "${LOG_FILE}.old" - mv "${LOG_FILE}" "${LOG_FILE}.old" - fi - rm "${LOG_PATH}/${LOG_FILE_NAME}.pid" - if [ ${START_NEW} == false ]; then - return - fi - touch "${PID_FILE}" - print_log_head "${LOG_FILE}" - loop_logcat -f "${LOG_FILE}" *:S "${LOG_TAG_FILTERS}" & - LOG_PID=$! - echo "${LOG_PID}">"${LOG_PATH}/${LOG_FILE_NAME}.pid" +start_log_catcher() { + LOG_FILE_NAME=$1 + LOG_TAG_FILTERS=$2 + CLEAN_OLD=$3 + START_NEW=$4 + LOG_FILE="${LOG_PATH}/${LOG_FILE_NAME}.log" + PID_FILE="${LOG_PATH}/${LOG_FILE_NAME}.pid" + mkdir -p ${LOG_PATH} + if [ ${CLEAN_OLD} == true ]; then + rm "${LOG_FILE}.old" + mv "${LOG_FILE}" "${LOG_FILE}.old" + fi + rm "${LOG_PATH}/${LOG_FILE_NAME}.pid" + if [ ${START_NEW} == false ]; then + return + fi + touch "${PID_FILE}" + print_log_head "${LOG_FILE}" + loop_logcat -f "${LOG_FILE}" *:S "${LOG_TAG_FILTERS}" & + LOG_PID=$! + echo "${LOG_PID}" >"${LOG_PATH}/${LOG_FILE_NAME}.pid" } -if [ -f "/data/adb/riru/modules/lspd.prop" ]; then - CONFIG=$(cat "/data/adb/riru/modules/lspd.prop") - [ -d "${TARGET}/${CONFIG}" ] || mkdir -p "${TARGET}/${CONFIG}" - cp "${MODDIR}/module.prop" "${TARGET}/${CONFIG}/module.prop" -fi - chcon -R u:object_r:system_file:s0 "${MODDIR}" chcon -R u:object_r:system_file:s0 "/data/adb/lspd" rm -rf ${LOG_PATH}.old @@ -143,17 +128,15 @@ mkdir -p ${LOG_PATH} chcon -R u:object_r:magisk_file:s0 ${LOG_PATH} if [ ! -z "${MISC_PATH}" ]; then - chcon -R u:object_r:magisk_file:s0 "${BASE_PATH}" - chmod 771 "${BASE_PATH}" - print_log_head "${LOG_PATH}/modules.log" - # start_verbose_log_catcher - start_log_catcher all "LSPosed:V XSharedPreferences:V LSPosed-Bridge:V LSPosedManager:V LSPosedService:V *:F" true ${LOG_VERBOSE} + chcon -R u:object_r:magisk_file:s0 "${BASE_PATH}" + chmod 771 "${BASE_PATH}" + print_log_head "${LOG_PATH}/modules.log" + # start_verbose_log_catcher + start_log_catcher all "LSPosed:V XSharedPreferences:V LSPosed-Bridge:V LSPosedManager:V LSPosedService:V *:F" true ${LOG_VERBOSE} fi -rm -f /data/adb/lspd/new_install start_app_process() { - while true - do + while true; do if [ -S "/dev/socket/zygote" ]; then /system/bin/app_process -Djava.class.path=$(magisk --path)/.magisk/modules/riru_lsposed/framework/lspd.dex /system/bin --nice-name=lspd org.lsposed.lspd.core.Main fi diff --git a/core/template_override/riru.sh b/core/template_override/riru.sh new file mode 100644 index 00000000..d85c62bc --- /dev/null +++ b/core/template_override/riru.sh @@ -0,0 +1,64 @@ +#!/sbin/sh +RIRU_MODULE_ID="%%%RIRU_MODULE_ID%%%" + +# Variables for customize.sh +RIRU_API=0 +RIRU_MIN_COMPATIBLE_API=0 +RIRU_VERSION_CODE=0 +RIRU_VERSION_NAME="" + +# Used by /data/adb/riru/util_functions.sh +RIRU_MODULE_API_VERSION=%%%RIRU_MODULE_API_VERSION%%% +RIRU_MODULE_MIN_API_VERSION=%%%RIRU_MODULE_MIN_API_VERSION%%% +RIRU_MODULE_MIN_RIRU_VERSION_NAME="%%%RIRU_MODULE_MIN_RIRU_VERSION_NAME%%%" + +if [ "$MAGISK_VER_CODE" -ge 21000 ]; then + MAGISK_CURRENT_RIRU_MODULE_PATH=$(magisk --path)/.magisk/modules/riru-core +else + MAGISK_CURRENT_RIRU_MODULE_PATH=/sbin/.magisk/modules/riru-core +fi + +# This function will be used when util_functions.sh not exists +check_riru_version() { + if [ ! -f "$MAGISK_CURRENT_RIRU_MODULE_PATH/api_version" ] && [ ! -f "/data/adb/riru/api_version" ] && [ ! -f "/data/adb/riru/api_version.new" ]; then + ui_print "*********************************************************" + ui_print "! Riru $RIRU_MODULE_MIN_RIRU_VERSION_NAME or above is required" + ui_print "! Please install Riru from Magisk Manager or https://github.com/RikkaApps/Riru/releases" + abort "*********************************************************" + fi + RIRU_API=$(cat "$MAGISK_CURRENT_RIRU_MODULE_PATH/api_version") || RIRU_API=$(cat "/data/adb/riru/api_version.new") || RIRU_API=$(cat "/data/adb/riru/api_version") || RIRU_API=0 + [ "$RIRU_API" -eq "$RIRU_API" ] || RIRU_API=0 + ui_print "- Riru API version: $RIRU_API" + if [ "$RIRU_API" -lt $RIRU_MODULE_MIN_API_VERSION ]; then + ui_print "*********************************************************" + ui_print "! Riru $RIRU_MODULE_MIN_RIRU_VERSION_NAME or above is required" + ui_print "! Please upgrade Riru from Magisk Manager or https://github.com/RikkaApps/Riru/releases" + abort "*********************************************************" + fi +} + +# This function will be used when util_functions.sh not exists +enforce_install_from_magisk_app() { + if $BOOTMOE; then + ui_print "- Installing from Magisk app" + else + ui_print "*********************************************************" + ui_print "! Install from recovery is NOT supported" + ui_print "! Some recovery has broken implementations, install with such recovery will finally cause Riru or Riru modules not working" + ui_print "! Please install from Magisk app" + abort "*********************************************************" + fi +} + +if [ -f $MAGISK_CURRENT_RIRU_MODULE_PATH/util_functions.sh ]; then + ui_print "- Load $MAGISK_CURRENT_RIRU_MODULE_PATH/util_functions.sh" + # shellcheck disable=SC1090 + . $MAGISK_CURRENT_RIRU_MODULE_PATH/util_functions.sh +else + if [ -f /data/adb/riru/util_functions.sh ]; then + ui_print "- Load /data/adb/riru/util_functions.sh" + . /data/adb/riru/util_functions.sh + else + ui_print "- Can't find /data/adb/riru/util_functions.sh" + fi +fi \ No newline at end of file diff --git a/core/template_override/uninstall.sh b/core/template_override/uninstall.sh index 52005048..dfcc20e7 100644 --- a/core/template_override/uninstall.sh +++ b/core/template_override/uninstall.sh @@ -20,28 +20,4 @@ # Copyright (C) 2021 LSPosed Contributors # -MODDIR=${0%/*} -VARIANT="YAHFA" -REMOVE=false - -[ "$(echo ${MODDIR} | grep sandhook)" != "" ] && VARIANT="SandHook" - -if [ "${VARIANT}" == "SandHook" ]; then - [ -f "${MODDIR}/../riru_lsposed/module.prop" ] || REMOVE=true -else - [ -f "${MODDIR}/../riru_lsposed_sandhook/module.prop" ] || REMOVE=true -fi - -if [ "${REMOVE}" == true ]; then - rm -rf /data/misc/riru/modules/lspd - if [ -f "/data/adb/riru/modules/lspd.prop" ]; then - OLD_CONFIG=$(cat "/data/adb/riru/modules/lspd.prop") - rm -rf "/data/adb/riru/modules/${OLD_CONFIG}" - rm "/data/adb/riru/modules/lspd.prop" - fi - if [ -f "/data/misc/riru/modules/lspd.prop" ]; then - OLD_CONFIG=$(cat "/data/misc/riru/modules/lspd.prop") - rm -rf "/data/misc/riru/modules/${OLD_CONFIG}" - rm "/data/misc/riru/modules/lspd.prop" - fi -fi +MODDIR=${0%/*} \ No newline at end of file diff --git a/core/template_override/util_functions.sh b/core/template_override/util_functions.sh index 1490f021..551c2d48 100644 --- a/core/template_override/util_functions.sh +++ b/core/template_override/util_functions.sh @@ -18,59 +18,22 @@ # Copyright (C) 2021 LSPosed Contributors # -RIRU_MODULE_ID="%%%RIRU_MODULE_ID%%%" -RIRU_MODULE_API_VERSION=%%%RIRU_MODULE_API_VERSION%%% -RIRU_MODULE_MIN_API_VERSION=%%%RIRU_MODULE_MIN_API_VERSION%%% -RIRU_MODULE_MIN_RIRU_VERSION_NAME="%%%RIRU_MODULE_MIN_RIRU_VERSION_NAME%%%" - -if [ "$MAGISK_VER_CODE" -ge 21000 ]; then - MAGISK_CURRENT_RIRU_MODULE_PATH=$(magisk --path)/.magisk/modules/riru-core -else - MAGISK_CURRENT_RIRU_MODULE_PATH=/sbin/.magisk/modules/riru-core -fi - -check_riru_version() { - if [ ! -f "$MAGISK_CURRENT_RIRU_MODULE_PATH/api_version" ] && [ ! -f "/data/adb/riru/api_version" ] && [ ! -f "/data/adb/riru/api_version.new" ]; then - ui_print "*********************************************************" - ui_print "! Riru $RIRU_MODULE_MIN_RIRU_VERSION_NAME or above is required" - ui_print "! Please install Riru from Magisk Manager or https://github.com/RikkaApps/Riru/releases" - abort "*********************************************************" - fi - RIRU_API=$(cat "$MAGISK_CURRENT_RIRU_MODULE_PATH/api_version") || RIRU_API=$(cat "/data/adb/riru/api_version.new") || RIRU_API=$(cat "/data/adb/riru/api_version") || RIRU_API=0 - [ "$RIRU_API" -eq "$RIRU_API" ] || RIRU_API=0 - ui_print "- Riru API version: $RIRU_API" - if [ "$RIRU_API" -lt $RIRU_MODULE_MIN_API_VERSION ]; then - ui_print "*********************************************************" - ui_print "! Riru $RIRU_MODULE_MIN_RIRU_VERSION_NAME or above is required" - ui_print "! Please upgrade Riru from Magisk Manager or https://github.com/RikkaApps/Riru/releases" - abort "*********************************************************" - fi -} - check_magisk_version() { - ui_print "- Magisk ${LANG_CUST_INST_VERSION}: ${MAGISK_VER_CODE}" + ui_print "- Magisk version: ${MAGISK_VER_CODE}" } require_new_android() { - ui_print "${POUNDS}" - ui_print "! ${LANG_UTIL_ERR_ANDROID_UNSUPPORT_1} ${1} ${LANG_UTIL_ERR_ANDROID_UNSUPPORT_2}" - ui_print "! ${LANG_UTIL_ERR_ANDROID_UNSUPPORT_3}" - [ ${BOOTMODE} == true ] && am start -a android.intent.action.VIEW -d https://github.com/LSPosed/LSPosed/wiki/Available-Android-versions - abortC "${POUNDS}" -} - -lspd_check_architecture() { - if [ "${ARCH}" != "arm" && "${ARCH}" != "arm64" && "${ARCH}" != "x86" && "${ARCH}" != "x64" ]; then - abortC "! ${LANG_UTIL_ERR_PLATFORM_UNSUPPORT}: ${ARCH}" - else - ui_print "- ${LANG_UTIL_PLATFORM}: ${ARCH}" - fi + ui_print "${POUNDS}" + ui_print "! Unsupported Android version ${1} (below Oreo MR1)" + ui_print "! Learn more from our GitHub Wiki" + [ ${BOOTMODE} == true ] && am start -a android.intent.action.VIEW -d https://github.com/LSPosed/LSPosed/wiki/Available-Android-versions + abortC "${POUNDS}" } check_android_version() { - if [ ${API} -ge 27 ]; then - ui_print "- Android SDK ${LANG_CUST_INST_VERSION}: ${API}" - else - require_new_android "${API}" - fi + if [ ${API} -ge 27 ]; then + ui_print "- Android SDK version: ${API}" + else + require_new_android "${API}" + fi } diff --git a/core/template_override/verify.sh b/core/template_override/verify.sh index ab7c21f2..28844756 100644 --- a/core/template_override/verify.sh +++ b/core/template_override/verify.sh @@ -24,8 +24,8 @@ mkdir "$TMPDIR_FOR_VERIFY" abort_verify() { ui_print "*********************************************************" ui_print "! $1" - ui_print "! ${LANG_VERIFY_ERR_NOTICE}" - abort "*********************************************************" + ui_print "! This zip may be corrupted, please try downloading again" + abort "*********************************************************" } # extract @@ -49,11 +49,11 @@ extract() { fi unzip $opts "$zip" "$file" -d "$dir" >&2 - [ -f "$file_path" ] || abort_verify "$file ${LANG_VERIFY_ERR_NOT_EXIST}" + [ -f "$file_path" ] || abort_verify "$file not exists" unzip $opts "$zip" "$file.sha256" -d "$TMPDIR_FOR_VERIFY" >&2 - [ -f "$hash_path" ] || abort_verify "$file.sha256 ${LANG_VERIFY_ERR_NOT_EXIST}" + [ -f "$hash_path" ] || abort_verify "$file.sha256 not exists" - (echo "$(cat "$hash_path") $file_path" | sha256sum -c -s -) || abort_verify "${LANG_VERIFY_ERR_MISMATCH} $file" - ui_print "- ${LANG_VERIFY_SUCCESS} $file" >&1 + (echo "$(cat "$hash_path") $file_path" | sha256sum -c -s -) || abort_verify "Failed to verify $file" + ui_print "- Verified $file" >&1 } \ No newline at end of file diff --git a/core/template_override/zh_CN.sh b/core/template_override/zh_CN.sh deleted file mode 100644 index 3e433988..00000000 --- a/core/template_override/zh_CN.sh +++ /dev/null @@ -1,70 +0,0 @@ -# -# This file is part of LSPosed. -# -# LSPosed is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# LSPosed is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with LSPosed. If not, see . -# -# Copyright (C) 2020 EdXposed Contributors -# Copyright (C) 2021 LSPosed Contributors -# - -# Simplified Chinese (China) language file -# Load this shell will replace en_US lang - -# customize -LANG_CUST_INST_VERSION="版本" -LANG_CUST_INST_EXT_FILES="正在解压模块文件" -LANG_CUST_INST_EXT_LIB_X86="正在解压 x86 运行库" -LANG_CUST_INST_EXT_LIB_X64="正在解压 x86_64 运行库" -LANG_CUST_INST_EXT_LIB_ARM="正在解压 arm 运行库" -LANG_CUST_INST_EXT_LIB_ARM64="正在解压 arm64 运行库" -LANG_CUST_INST_STUB="正在预装管理器" -LANG_CUST_INST_CONF_CREATE="正在创建配置目录" -LANG_CUST_INST_CONF_OLD="使用旧目录" -LANG_CUST_DISABLE_EDXP="**警告**: 由于不兼容,此次安装会自动禁用EdXposed" -LANG_CUST_INST_CONF_NEW="使用新目录" -LANG_CUST_INST_COPY_LIB="正在复制框架运行库" -LANG_CUST_INST_DONE="欢迎使用" - -LANG_CUST_ERR_VERIFY_FAIL="无法解压校验工具!" -LANG_CUST_ERR_STUB="管理器预装失败! 请手动安装 LSPosed Manager" -LANG_CUST_ERR_PERM="无法设置权限" -LANG_CUST_ERR_CONF_CREATE="无法创建配置路径" -LANG_CUST_ERR_CONF_STORE="无法写入配置路径" -LANG_CUST_ERR_CONF_FIRST="无法创建首次安装标识" -LANG_CUST_ERR_CONF_UNINST="无法写入卸载脚本" - -# verify -LANG_VERIFY_SUCCESS="已验证" - -LANG_VERIFY_ERR_MISMATCH="校验失败" -LANG_VERIFY_ERR_NOT_EXIST="不存在" -LANG_VERIFY_ERR_NOTICE="模块可能已被损坏,请从官方重新下载" - -# util_functions -LANG_UTIL_PLATFORM="设备平台" - -LANG_UTIL_ERR_RIRU_NOT_FOUND_1="未安装" -LANG_UTIL_ERR_RIRU_NOT_FOUND_2="请先从 Magisk Manager 中安装 Riru" -LANG_UTIL_ERR_RIRU_LOW_1="或更高版本需要被安装" -LANG_UTIL_ERR_RIRU_LOW_2="请先从 Magisk Manager 中升级 Riru" -LANG_UTIL_ERR_REQUIRE_YAHFA_1="侦测到 x86 或 x86_64 架构" -LANG_UTIL_ERR_REQUIRE_YAHFA_2="仅 YAHFA 支持 x86 或 x86_64 架构的设备" -LANG_UTIL_ERR_REQUIRE_YAHFA_3="可从 'Magisk Manager' 或 'LSPosed Manager' 中下载" -LANG_UTIL_ERR_ANDROID_UNSUPPORT_1="不支持的 Android 版本" -LANG_UTIL_ERR_ANDROID_UNSUPPORT_2="(Oreo 以下版本)" -LANG_UTIL_ERR_ANDROID_UNSUPPORT_3="从我们的 GitHub Wiki 中了解更多" -LANG_UTIL_ERR_PLATFORM_UNSUPPORT="不支持的设备平台" -LANG_UTIL_ERR_DUPINST_1="不允许重复安装" -LANG_UTIL_ERR_DUPINST_2="删除" -LANG_UTIL_ERR_DUPINST_3="并重启以继续安装" diff --git a/core/tpl/module.prop.tpl b/core/tpl/module.prop.tpl index 2bfecab4..e85e5f28 100644 --- a/core/tpl/module.prop.tpl +++ b/core/tpl/module.prop.tpl @@ -3,4 +3,4 @@ name=Riru - LSPosed version=${versionName} versionCode=${versionCode} author=${authorList} -description=Another enhanced implementation of Xposed Framework. Supports Android 8.1 ~ 12 DP1. Requires Riru v23 or above installed. \ No newline at end of file +description=Another enhanced implementation of Xposed Framework. Supports Android 8.1 ~ 12 DP1. Requires Riru ${minRiruVersionName} or above installed. \ No newline at end of file