Skip to content

Commit

Permalink
Add a switch to enable boot image deoptimization selectively
Browse files Browse the repository at this point in the history
  • Loading branch information
solohsu committed Feb 27, 2019
1 parent 628d4e7 commit 9a0044b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Core/jni/main/inject/config_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ static char whitelist_path[PATH_MAX];
static char use_whitelist_path[PATH_MAX];
static char black_white_list_path[PATH_MAX];
static char dynamic_modules_path[PATH_MAX];
static char deopt_boot_image_path[PATH_MAX];

static const char *installer_package_name;
static bool black_white_list_enabled = false;
static bool dynamic_modules_enabled = false;
static bool deopt_boot_image_enabled = false;
static bool inited = false;

static const char *get_installer_package_name() {
Expand Down Expand Up @@ -72,8 +74,11 @@ static void init_once() {
installer_package_name, "blackwhitelist");
snprintf(dynamic_modules_path, PATH_MAX, config_path_tpl, data_path_prefix,
installer_package_name, "dynamicmodules");
snprintf(deopt_boot_image_path, PATH_MAX, config_path_tpl, data_path_prefix,
installer_package_name, "deoptbootimage");
dynamic_modules_enabled = access(dynamic_modules_path, F_OK) == 0;
black_white_list_enabled = access(black_white_list_path, F_OK) == 0;
deopt_boot_image_enabled = access(deopt_boot_image_path, F_OK) == 0;
LOGI("black/white list mode: %d", black_white_list_enabled);
LOGI("dynamic modules mode: %d", dynamic_modules_enabled);
inited = true;
Expand Down Expand Up @@ -136,7 +141,12 @@ bool is_dynamic_modules_enabled() {
return dynamic_modules_enabled;
}

jstring get_installer_pkg_name(JNIEnv *env, jclass clazz) {
bool is_deopt_boot_image_enabled() {
init_once();
return deopt_boot_image_enabled;
}

jstring get_installer_pkg_name(JNIEnv *env, jclass) {
init_once();
return env->NewStringUTF(installer_package_name);
}
4 changes: 4 additions & 0 deletions Core/jni/main/inject/config_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
#ifndef EDXPOSED_CONFIG_MANAGER_H
#define EDXPOSED_CONFIG_MANAGER_H

#include <jni.h>

bool is_app_need_hook(JNIEnv *env, jstring appDataDir);

bool is_black_white_list_enabled();

bool is_dynamic_modules_enabled();

bool is_deopt_boot_image_enabled();

jstring get_installer_pkg_name(JNIEnv *env, jclass clazz);

#endif //EDXPOSED_CONFIG_MANAGER_H
4 changes: 4 additions & 0 deletions Core/jni/main/native_hook/native_hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <include/android_build.h>
#include <string>
#include <vector>
#include <inject/config_manager.h>

#include "include/logging.h"
#include "native_hook.h"
Expand Down Expand Up @@ -182,6 +183,9 @@ void deoptimize_method(JNIEnv *env, jclass clazz, jobject method) {
}

void hookRuntime(int api_level, void *artHandle, void (*hookFun)(void *, void *, void **)) {
if (!is_deopt_boot_image_enabled()) {
return;
}
void *runtimeInitSym = nullptr;
if (api_level >= ANDROID_O) {
// only oreo has deoptBootImageSym in Runtime
Expand Down

0 comments on commit 9a0044b

Please sign in to comment.