Commit 82099cb8 authored by swift_gan's avatar swift_gan

fix disable dex2oat inline

parent 956330a6
......@@ -24,7 +24,7 @@ bool isSandHooker(char *const args[]) {
int orig_arg_count = getArrayItemCount(args);
for (int i = 0; i < orig_arg_count; i++) {
if (SDK_INT >= ANDROID_N && strstr(args[i], "SandHooker")) {
if (strstr(args[i], "SandHooker")) {
LOGE("skip dex2oat hooker!");
return true;
}
......@@ -33,60 +33,46 @@ bool isSandHooker(char *const args[]) {
return false;
}
char **build_new_env(char *const envp[]) {
char *provided_ld_preload = NULL;
int provided_ld_preload_index = -1;
int orig_envp_count = getArrayItemCount(envp);
char **build_new_argv(char *const argv[]) {
for (int i = 0; i < orig_envp_count; i++) {
if (strstr(envp[i], "compiler-filter")) {
provided_ld_preload = envp[i];
provided_ld_preload_index = i;
}
}
char ld_preload[40];
if (provided_ld_preload) {
sprintf(ld_preload, "--compiler-filter=%s", "speed");
}
int orig_argv_count = getArrayItemCount(argv);
int new_envp_count = orig_envp_count;
if (SDK_INT >= ANDROID_M) {
new_envp_count = orig_envp_count + 1;
}
char **new_envp = (char **) malloc(new_envp_count * sizeof(char *));
int new_argv_count = orig_argv_count + 2;
char **new_argv = (char **) malloc(new_argv_count * sizeof(char *));
int cur = 0;
for (int i = 0; i < orig_envp_count; ++i) {
if (i != provided_ld_preload_index) {
new_envp[cur++] = envp[i];
} else {
new_envp[i] = ld_preload;
}
for (int i = 0; i < orig_argv_count; ++i) {
new_argv[cur++] = argv[i];
}
if (new_envp_count != orig_envp_count) {
new_envp[new_envp_count - 1] = (char *) (SDK_INT > ANDROID_N2 ? "--inline-max-code-units=0" : "--inline-depth-limit=0");
if (SDK_INT >= ANDROID_L2 && SDK_INT < ANDROID_Q) {
new_argv[cur++] = (char *) "--compile-pic";
}
if (SDK_INT >= 23) {
new_argv[cur++] = (char *) (SDK_INT > ANDROID_N2 ? "--inline-max-code-units=0" : "--inline-depth-limit=0");
}
return new_envp;
new_argv[cur] = NULL;
return new_argv;
}
extern "C" int fake_execve_disable_inline(const char *pathname, char *argv[], char *const envp[]) {
int fake_execve_disable_inline(const char *pathname, char *argv[], char *const envp[]) {
if (strstr(pathname, "dex2oat")) {
if (SDK_INT >= ANDROID_N && isSandHooker(argv)) {
LOGE("skip dex2oat!");
return -1;
}
char **new_envp = build_new_env(envp);
char **new_args = build_new_argv(argv);
LOGE("dex2oat by disable inline!");
int ret = static_cast<int>(syscall(__NR_execve, pathname, argv, new_envp));
free(new_envp);
int ret = static_cast<int>(syscall(__NR_execve, pathname, new_args, envp));
free(new_args);
return ret;
}
int ret = static_cast<int>(syscall(__NR_execve, pathname, argv, envp));
return ret;
}
extern "C" int fake_execve_disable_oat(const char *pathname, char *argv[], char *const envp[]) {
int fake_execve_disable_oat(const char *pathname, char *argv[], char *const envp[]) {
if (strstr(pathname, "dex2oat")) {
LOGE("skip dex2oat!");
return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment