Skip to content

Commit

Permalink
Ensure necessary system props
Browse files Browse the repository at this point in the history
Some other Magisk modules may override the system props we set, e.g.
compiler-filter, which will likely result in boot loops.

We PLT hook native getSystemProp implementation methods to make sure
the values of related system props are always what we want.

Fix #156.
  • Loading branch information
solohsu committed Mar 16, 2019
1 parent 8c4a7e9 commit e2fb970
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.gradle.internal.os.OperatingSystem;

apply plugin: 'com.android.library'
version "v0.3.1.4_beta-SNAPSHOT"
version "v0.3.1.5_beta-SNAPSHOT"
extensions["module_name"] = "EdXposed"
android {
compileSdkVersion 28
Expand Down
1 change: 1 addition & 0 deletions Core/jni/main/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ LOCAL_LDFLAGS := -Wl
LOCAL_SRC_FILES:= \
main.cpp \
native_hook/native_hook.cpp \
native_hook/riru_hook.cpp \
include/misc.cpp \
include/riru.c \
yahfa/HookMain.c \
Expand Down
2 changes: 2 additions & 0 deletions Core/jni/main/native_hook/native_hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "include/logging.h"
#include "native_hook.h"
#include "riru_hook.h"

static bool inlineHooksInstalled = false;

Expand Down Expand Up @@ -272,6 +273,7 @@ void install_inline_hooks() {
LOGE("api level not supported: %d, skip", api_level);
return;
}
install_riru_hooks();
LOGI("using api level %d", api_level);
void *whaleHandle = dlopen(kLibWhalePath, RTLD_LAZY | RTLD_GLOBAL);
if (!whaleHandle) {
Expand Down
82 changes: 82 additions & 0 deletions Core/jni/main/native_hook/riru_hook.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// Created by solo on 2019/3/16.
//

#include <cstring>
#include <string>
#include <include/riru.h>
#include <xhook/xhook.h>
#include <sys/system_properties.h>
#include <include/logging.h>
#include <include/android_build.h>
#include "riru_hook.h"

#define PROP_KEY_COMPILER_FILTER "dalvik.vm.dex2oat-filter"
#define PROP_KEY_COMPILER_FLAGS "dalvik.vm.dex2oat-flags"
#define PROP_VALUE_COMPILER_FILTER "quicken"
#define PROP_VALUE_COMPILER_FLAGS "--inline-max-code-units=0"

#define XHOOK_REGISTER(NAME) \
if (xhook_register(".*", #NAME, (void*) new_##NAME, (void **) &old_##NAME) == 0) { \
if (riru_get_version() >= 8) { \
void *f = riru_get_func(#NAME); \
if (f != nullptr) { \
memcpy(&old_##NAME, &f, sizeof(void *)); \
} \
riru_set_func(#NAME, (void *) new_##NAME); \
} \
} else { \
LOGE("failed to register riru hook " #NAME "."); \
}

#define NEW_FUNC_DEF(ret, func, ...) \
static ret (*old_##func)(__VA_ARGS__); \
static ret new_##func(__VA_ARGS__)

NEW_FUNC_DEF(int, __system_property_get, const char *key, char *value) {
int res = old___system_property_get(key, value);
if (key) {
if (strcmp(PROP_KEY_COMPILER_FILTER, key) == 0) {
strcpy(value, PROP_VALUE_COMPILER_FILTER);
LOGI("system_property_get: %s -> %s", key, value);
} else if (strcmp(PROP_KEY_COMPILER_FLAGS, key) == 0) {
strcpy(value, PROP_VALUE_COMPILER_FLAGS);
LOGI("system_property_get: %s -> %s", key, value);
}
}
return res;
}

NEW_FUNC_DEF(std::string,
_ZN7android4base11GetPropertyERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_,
const std::string &key, const std::string &default_value) {
std::string res = old__ZN7android4base11GetPropertyERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_(
key, default_value);
if (strcmp(PROP_KEY_COMPILER_FILTER, key.c_str()) == 0) {
res = PROP_VALUE_COMPILER_FILTER;
LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str());
} else if (strcmp(PROP_KEY_COMPILER_FLAGS, key.c_str()) == 0) {
res = PROP_VALUE_COMPILER_FLAGS;
LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str());
}
return res;
}

void install_riru_hooks() {

LOGI("install riru hook");

XHOOK_REGISTER(__system_property_get);

if (GetAndroidApiLevel() >= ANDROID_P) {
XHOOK_REGISTER(
_ZN7android4base11GetPropertyERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_);
}

if (xhook_refresh(0) == 0) {
xhook_clear();
LOGI("riru hooks installed");
} else {
LOGE("failed to install riru hooks");
}
}
10 changes: 10 additions & 0 deletions Core/jni/main/native_hook/riru_hook.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Created by solo on 2019/3/16.
//

#ifndef EDXPOSED_RIRU_HOOK_H
#define EDXPOSED_RIRU_HOOK_H

void install_riru_hooks();

#endif //EDXPOSED_RIRU_HOOK_H
2 changes: 1 addition & 1 deletion Core/template_override/common/util_functions.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/system/bin/sh

EDXP_VERSION="0.3.1.4_beta-SNAPSHOT (3140)"
EDXP_VERSION="0.3.1.5_beta-SNAPSHOT (3150)"
ANDROID_SDK=`getprop ro.build.version.sdk`
BUILD_DESC=`getprop ro.build.description`
PRODUCT=`getprop ro.build.product`
Expand Down
2 changes: 1 addition & 1 deletion Core/template_override/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ LATESTARTSERVICE=false

print_modname() {
ui_print "************************************"
ui_print " Riru - Ed Xposed v0.3.1.4 "
ui_print " Riru - Ed Xposed v0.3.1.5 "
ui_print "************************************"
}

Expand Down
4 changes: 2 additions & 2 deletions Core/template_override/module.prop
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
id=riru_edxposed
name=Riru - Ed Xposed
version=v0.3.1.4_beta-SNAPSHOT
versionCode=3140
version=v0.3.1.5_beta-SNAPSHOT
versionCode=3150
author=solohsu & MlgmXyysd
description=Magisk version of Xposed. Require Riru - Core installed.
minMagisk=17000
4 changes: 2 additions & 2 deletions Core/template_override/riru_module.prop
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Ed Xposed
version=v0.3.1.4_beta-SNAPSHOT
versionCode=3140
version=v0.3.1.5_beta-SNAPSHOT
versionCode=3150
author=solohsu & MlgmXyysd
description=Magisk version of Xposed. Require Riru - Core installed.
2 changes: 1 addition & 1 deletion Core/template_override/system/framework/edconfig.dex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=90.0-0.3.1.4-beta-SNAPSHOT
version=90.0-0.3.1.5-beta-SNAPSHOT
arch=arm64
minsdk=23
maxsdk=28
Expand Down

0 comments on commit e2fb970

Please sign in to comment.