Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
adapt Riru v18 (also support Android Q)
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkaW committed Apr 11, 2019
1 parent 4ed0191 commit c272fd3
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 31 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ android {

task zip(type: Exec) {
workingDir '..'
commandLine 'sh', 'build.sh', project.name, 'v7'
commandLine 'sh', 'build.sh', project.name, 'v8'
}
18 changes: 17 additions & 1 deletion jni/Application.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
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)
1 change: 0 additions & 1 deletion jni/external/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 2 additions & 1 deletion jni/main/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
27 changes: 10 additions & 17 deletions jni/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <utility>
#include <string>
#include <sys/system_properties.h>
#include <riru.h>

#include "logging.h"
#include "hook.h"
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
29 changes: 24 additions & 5 deletions template_override/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,37 @@ 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"
exit 1
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

Expand All @@ -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"
}
4 changes: 2 additions & 2 deletions template_override/module.prop
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions template_override/riru_module.prop
Original file line number Diff line number Diff line change
@@ -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.
description=Enable Google location report by hook system_property_get (and android::base::GetProperty for API 28+). Requires Riru - Core installed.
api=3

0 comments on commit c272fd3

Please sign in to comment.