From c272fd3010dde233813c8a2083243ca8190555ee Mon Sep 17 00:00:00 2001 From: RikkaW Date: Fri, 12 Apr 2019 00:46:09 +0800 Subject: [PATCH] adapt Riru v18 (also support Android Q) --- build.gradle | 2 +- jni/Application.mk | 18 +++++++++++++++++- jni/external/Android.mk | 1 - jni/main/hook.cpp | 3 ++- jni/main/main.cpp | 27 ++++++++++----------------- template_override/config.sh | 29 ++++++++++++++++++++++++----- template_override/module.prop | 4 ++-- template_override/riru_module.prop | 7 ++++--- 8 files changed, 60 insertions(+), 31 deletions(-) diff --git a/build.gradle b/build.gradle index b6c61de..95ebfaa 100644 --- a/build.gradle +++ b/build.gradle @@ -22,5 +22,5 @@ android { task zip(type: Exec) { workingDir '..' - commandLine 'sh', 'build.sh', project.name, 'v7' + commandLine 'sh', 'build.sh', project.name, 'v8' } \ No newline at end of file diff --git a/jni/Application.mk b/jni/Application.mk index 7db8458..431d6f9 100644 --- a/jni/Application.mk +++ b/jni/Application.mk @@ -3,4 +3,20 @@ APP_PLATFORM := android-23 APP_CFLAGS := -std=gnu99 APP_CPPFLAGS := -std=c++11 APP_STL := c++_static -APP_SHORT_COMMANDS := true \ No newline at end of file +APP_SHORT_COMMANDS := true + +ifeq ($(NDK_DEBUG),1) +$(info building DEBUG version...) +APP_CFLAGS += -O0 +APP_CPPFLAGS += -O0 +else +$(info building RELEASE version...) +APP_CFLAGS += -fvisibility=hidden -fvisibility-inlines-hidden -O2 +APP_CPPFLAGS += -fvisibility=hidden -fvisibility-inlines-hidden -O2 +endif + +# do not remove this, or your module will crash apps on Android Q +SCS_FLAGS := -ffixed-x18 +APP_LDFLAGS += $(SCS_FLAGS) +APP_CFLAGS += $(SCS_FLAGS) +APP_CPPFLAGS += $(SCS_FLAGS) \ No newline at end of file diff --git a/jni/external/Android.mk b/jni/external/Android.mk index 056ebfb..04d3e48 100644 --- a/jni/external/Android.mk +++ b/jni/external/Android.mk @@ -12,5 +12,4 @@ LOCAL_SRC_FILES := xhook/xhook.c \ LOCAL_C_INCLUDES := $(LOCAL_PATH) LOCAL_CFLAGS := -Wall -Wextra -Werror -fvisibility=hidden LOCAL_CONLYFLAGS := -std=c11 -LOCAL_LDLIBS := -llog include $(BUILD_STATIC_LIBRARY) \ No newline at end of file diff --git a/jni/main/hook.cpp b/jni/main/hook.cpp index 82b01e1..d455828 100644 --- a/jni/main/hook.cpp +++ b/jni/main/hook.cpp @@ -74,8 +74,9 @@ void install_hook(const char *package_name, int user) { XHOOK_REGISTER(__system_property_get); char sdk[PROP_VALUE_MAX + 1]; - if (__system_property_get("ro.build.version.sdk", sdk) > 0 && atoi(sdk) >= 28) + if (__system_property_get("ro.build.version.sdk", sdk) > 0 && atoi(sdk) >= 28) { XHOOK_REGISTER(_ZN7android4base11GetPropertyERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_); + } if (xhook_refresh(0) == 0) xhook_clear(); diff --git a/jni/main/main.cpp b/jni/main/main.cpp index 3cb7d7f..4050d90 100644 --- a/jni/main/main.cpp +++ b/jni/main/main.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include "logging.h" #include "hook.h" @@ -33,7 +32,7 @@ int is_app_need_hook(JNIEnv *env, jstring appDataDir) { return 0; - const char *app_data_dir = env->GetStringUTFChars(appDataDir, NULL); + const char *app_data_dir = env->GetStringUTFChars(appDataDir, nullptr); int user = 0; if (sscanf(app_data_dir, "/data/%*[^/]/%d/%s", &user, package_name) != 2) { @@ -84,21 +83,15 @@ void nativeForkAndSpecialize(int res, int enable_hook, const char *package_name, } extern "C" { -__attribute__((visibility("default"))) void nativeForkAndSpecializePre(JNIEnv *env, jclass clazz, - jint _uid, jint gid, - jintArray gids, - jint runtime_flags, - jobjectArray rlimits, - jint _mount_external, - jstring se_info, - jstring se_name, - jintArray fdsToClose, - jintArray fdsToIgnore, - jboolean is_child_zygote, - jstring instructionSet, - jstring appDataDir) { - uid = _uid; - enable_hook = is_app_need_hook(env, appDataDir); +__attribute__((visibility("default"))) void nativeForkAndSpecializePre( + JNIEnv *env, jclass clazz, jint *_uid, jint *gid, jintArray *gids, jint *runtime_flags, + jobjectArray *rlimits, jint *_mount_external, jstring *se_info, jstring *se_name, + jintArray *fdsToClose, jintArray *fdsToIgnore, jboolean *is_child_zygote, + jstring *instructionSet, jstring *appDataDir, jstring *packageName, + jobjectArray *packagesForUID, jobjectArray *visibleVolIDs) { + + uid = *_uid; + enable_hook = is_app_need_hook(env, *appDataDir); if (enable_hook) load_config(); diff --git a/template_override/config.sh b/template_override/config.sh index 18b1a91..58f9c4d 100644 --- a/template_override/config.sh +++ b/template_override/config.sh @@ -101,6 +101,13 @@ fail() { exit 1 } +check_riru_version() { + [[ ! -f "/data/misc/riru/api_version" ]] && fail "! Please Install Riru - Core v18 or above" + VERSION=$(cat "/data/misc/riru/api_version") + ui_print "- Riru API version is $VERSION" + [[ "$VERSION" -ge 3 ]] || fail "! Please Install Riru - Core v18 or above" +} + check_architecture() { if [[ "$ARCH" != "arm" && "$ARCH" != "arm64" ]]; then ui_print "- Unsupported platform: $ARCH" @@ -108,11 +115,23 @@ check_architecture() { else ui_print "- Device platform: $ARCH" fi + + check_riru_version } copy_files() { - if [ $IS64BIT = false ]; then - ui_print "- Removing unnecessary files" + if [[ "$ARCH" == "x86" || "$ARCH" == "x64" ]]; then + ui_print "- Removing arm/arm64 libraries" + rm -rf "$MODPATH/system/lib" + rm -rf "$MODPATH/system/lib64" + ui_print "- Extracting x86/64 libraries" + unzip -o "$ZIP" 'system_x86/*' -d $MODPATH >&2 + mv "$MODPATH/system_x86/lib" "$MODPATH/system/lib" + mv "$MODPATH/system_x86/lib64" "$MODPATH/system/lib64" + fi + + if [[ "$IS64BIT" = false ]]; then + ui_print "- Removing 64-bit libraries" rm -rf "$MODPATH/system/lib64" fi @@ -122,10 +141,10 @@ copy_files() { TARGET="/data/misc/riru/modules" # TODO: do not overwrite if file exists - [ -d $TARGET ] || mkdir -p $TARGET || fail "- Can't mkdir -p $TARGET" - cp -af "$MODPATH$TARGET/." "$TARGET" || fail "- Can't cp -af $MODPATH$TARGET/. $TARGET" + [[ -d "$TARGET" ]] || mkdir -p "$TARGET" || fail "! Can't mkdir -p $TARGET" + cp -af "$MODPATH$TARGET/." "$TARGET" || fail "! Can't cp -af $MODPATH$TARGET/. $TARGET" - rm -rf $MODPATH/data 2>/dev/null + rm -rf "$MODPATH/data" 2>/dev/null ui_print "- Files copied" } \ No newline at end of file diff --git a/template_override/module.prop b/template_override/module.prop index 0e274f3..c2ac4a8 100644 --- a/template_override/module.prop +++ b/template_override/module.prop @@ -1,7 +1,7 @@ id=riru_location_report_enabler name=Riru - Location Report Enabler -version=v7 -versionCode=7 +version=v8 +versionCode=8 author=Rikka description=Enable location report by hook system_property_get. Require Riru - Core installed. minMagisk=17000 diff --git a/template_override/riru_module.prop b/template_override/riru_module.prop index 949bac8..d910496 100644 --- a/template_override/riru_module.prop +++ b/template_override/riru_module.prop @@ -1,5 +1,6 @@ name=Location Report Enabler -version=v7 -versionCode=7 +version=v8 +versionCode=8 author=Rikka -description=Enable location report by hook system_property_get. Require Riru - Core installed. \ No newline at end of file +description=Enable Google location report by hook system_property_get (and android::base::GetProperty for API 28+). Requires Riru - Core installed. +api=3 \ No newline at end of file