Skip to content

Commit

Permalink
Fix potential crashes for devices with Android 8.1
Browse files Browse the repository at this point in the history
Fix #163.
  • Loading branch information
solohsu committed Mar 17, 2019
1 parent 1041316 commit fc07607
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Core/jni/main/native_hook/riru_hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
#include <include/android_build.h>
#include "riru_hook.h"

int api_level = 0;

#define PROP_KEY_COMPILER_FILTER "dalvik.vm.dex2oat-filter"
#define PROP_KEY_COMPILER_FLAGS "dalvik.vm.dex2oat-flags"
#define PROP_KEY_USEJITPROFILES "dalvik.vm.usejitprofiles"
#define PROP_KEY_PM_BG_DEXOPT "pm.dexopt.bg-dexopt"
#define PROP_VALUE_COMPILER_FILTER "quicken"
#define PROP_VALUE_COMPILER_FLAGS "--inline-max-code-units=0"
#define PROP_VALUE_PM_BG_DEXOPT "speed"

#define XHOOK_REGISTER(NAME) \
if (xhook_register(".*", #NAME, (void*) new_##NAME, (void **) &old_##NAME) == 0) { \
Expand Down Expand Up @@ -43,6 +48,20 @@ NEW_FUNC_DEF(int, __system_property_get, const char *key, char *value) {
strcpy(value, PROP_VALUE_COMPILER_FLAGS);
LOGI("system_property_get: %s -> %s", key, value);
}
if (api_level == ANDROID_O_MR1) {
// https://android.googlesource.com/platform/art/+/f5516d38736fb97bfd0435ad03bbab17ddabbe4e
// Android 8.1 add a fatal check for debugging (removed in Android 9.0),
// which will be triggered by EdXposed in cases where target method is hooked
// (native flag set) after it has been called several times(getCounter() return positive number)
if (strcmp(PROP_KEY_USEJITPROFILES, key) == 0) {
strcpy(value, "false");
} else if (strcmp(PROP_KEY_PM_BG_DEXOPT, key) == 0) {
// use speed as bg-dexopt filter since that speed-profile won't work after
// jit profiles is disabled
strcpy(value, PROP_VALUE_PM_BG_DEXOPT);
}
LOGD("system_property_get: %s -> %s", key, value);
}
}
return res;
}
Expand All @@ -59,13 +78,24 @@ NEW_FUNC_DEF(std::string,
res = PROP_VALUE_COMPILER_FLAGS;
LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str());
}
if (api_level == ANDROID_O_MR1) {
// see __system_property_get hook above for explanations
if (strcmp(PROP_KEY_USEJITPROFILES, key.c_str()) == 0) {
res = "false";
} else if (strcmp(PROP_KEY_PM_BG_DEXOPT, key.c_str()) == 0) {
res = PROP_VALUE_PM_BG_DEXOPT;
}
LOGD("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str());
}
return res;
}

void install_riru_hooks() {

LOGI("install riru hook");

api_level = GetAndroidApiLevel();

XHOOK_REGISTER(__system_property_get);

if (GetAndroidApiLevel() >= ANDROID_P) {
Expand Down

0 comments on commit fc07607

Please sign in to comment.