From 926508c3df41848c50ce60f5b2e171c1c3a792e4 Mon Sep 17 00:00:00 2001 From: Jim Wu <1204074991@qq.com> Date: Sun, 17 May 2020 16:24:05 +0800 Subject: [PATCH 01/11] Disable AppVeyor CI Pull Requests build Build and test your Pull Requests yourself~ --- appveyor.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index ac454144..f8fe5a1b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -25,6 +25,10 @@ artifacts: pull_requests: do_not_increment_build_number: true +skip_tags: true + +skip_branch_with_pr: true + only_commits: files: - dalvikdx/ @@ -39,4 +43,4 @@ only_commits: - build.gradle - settings.gradle - gradle.properties - - appveyor.yml \ No newline at end of file + - appveyor.yml From 30f8b6390d211b2b7dd76b0dc3a1f8fd103a2205 Mon Sep 17 00:00:00 2001 From: Jim Wu <1204074991@qq.com> Date: Mon, 18 May 2020 00:32:35 +0800 Subject: [PATCH 02/11] Revert changes To trigger auto compile test --- appveyor.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index f8fe5a1b..96ec2cbc 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -27,8 +27,6 @@ pull_requests: skip_tags: true -skip_branch_with_pr: true - only_commits: files: - dalvikdx/ From a9dee2a5298079753da2df2e987761c340c0ee36 Mon Sep 17 00:00:00 2001 From: kotori0 Date: Sat, 13 Jun 2020 21:26:58 +0800 Subject: [PATCH 03/11] Fix compile error on *nix systems --- dalvikdx/build.gradle | 25 +++++++++++++++++++++---- dexmaker/build.gradle | 10 ++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/dalvikdx/build.gradle b/dalvikdx/build.gradle index b031d497..c31ce47a 100644 --- a/dalvikdx/build.gradle +++ b/dalvikdx/build.gradle @@ -8,17 +8,34 @@ dependencies { sourceCompatibility = "7" targetCompatibility = "7" +task findDx { + if (OperatingSystem.current().isWindows()){ + return true + } + doLast { + new ByteArrayOutputStream().withStream { os -> + exec { + commandLine "which", "dx" + standardOutput os + } + rootProject.ext.dxPath = os.toString() + } + } +} task dexInJar(type: Jar) { dependsOn jar + dependsOn findDx doFirst { exec { workingDir jar.destinationDir - if (OperatingSystem.current().isWindows()) + if (OperatingSystem.current().isWindows()){ executable "dx.bat" - else - executable "dx" - args "--dex", "--output", "classes.dex", "${jar.archiveName}" + args "--dex", "--output", "classes.dex", "${jar.archiveName}" + } else { + executable "bash" + args rootProject.ext.dxPath.trim(), "--dex", "--output", "classes.dex", "${jar.archiveName}" + } } } from "${jar.destinationDir}/classes.dex" diff --git a/dexmaker/build.gradle b/dexmaker/build.gradle index 8642d24e..9d4bc920 100644 --- a/dexmaker/build.gradle +++ b/dexmaker/build.gradle @@ -19,11 +19,13 @@ task dexInJar(type: Jar) { doFirst { exec { workingDir jar.destinationDir - if (OperatingSystem.current().isWindows()) + if (OperatingSystem.current().isWindows()){ executable "dx.bat" - else - executable "dx" - args "--dex", "--output", "classes.dex", "${jar.archiveName}" + args "--dex", "--output", "classes.dex", "${jar.archiveName}" + } else { + executable "bash" + args rootProject.ext.dxPath.trim(), "--dex", "--output", "classes.dex", "${jar.archiveName}" + } } } from "${jar.destinationDir}/classes.dex" From cd8c3b5639269a1795741433a865bf8eb327782b Mon Sep 17 00:00:00 2001 From: EBK21 Date: Fri, 19 Jun 2020 11:14:00 +0800 Subject: [PATCH 04/11] Do not force quicken, preserve dex2oat flags (#571) * Do not force quicken, preserve dex2oat flags * Add value with space --- edxp-core/src/main/cpp/main/src/riru_hook.cpp | 53 ++++++++++++++++++- edxp-core/src/main/cpp/main/src/riru_hook.h | 1 + 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/edxp-core/src/main/cpp/main/src/riru_hook.cpp b/edxp-core/src/main/cpp/main/src/riru_hook.cpp index dbbae41d..eda5fccd 100644 --- a/edxp-core/src/main/cpp/main/src/riru_hook.cpp +++ b/edxp-core/src/main/cpp/main/src/riru_hook.cpp @@ -14,10 +14,16 @@ namespace edxp { static int api_level = 0; + + //Max length of property values + //Ref https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/os/SystemProperties.java + //static const int PROP_VALUE_MAX = 91; NEW_FUNC_DEF(int, __system_property_get, const char *key, char *value) { int res = old___system_property_get(key, value); + if (key) { + /* if (strcmp(kPropKeyCompilerFilter, key) == 0) { strcpy(value, kPropValueCompilerFilter); LOGI("system_property_get: %s -> %s", key, value); @@ -25,6 +31,29 @@ namespace edxp { strcpy(value, kPropValueCompilerFlags); LOGI("system_property_get: %s -> %s", key, value); } + */ + + if(strcmp(kPropKeyCompilerFlags, key) == 0) { + if(strcmp(value,"") == 0) + strcpy(value, kPropValueCompilerFlags); + else { + if(strstr(value,kPropValueCompilerFlags) == NULL) { + if(strlen(value) + strlen(kPropValueCompilerFlagsWS) > PROP_VALUE_MAX) { + //just fallback,why not + LOGI("Cannot add option to disable inline opt!Fall back to replace.."); + strcpy(value, kPropValueCompilerFlags); + }else { + strcat(value,kPropValueCompilerFlagsWS); + } + } + if(strstr(value,kPropValueCompilerFlags) != NULL) + 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), @@ -48,6 +77,7 @@ namespace edxp { const std::string &key, const std::string &default_value) { std::string res = old__ZN7android4base11GetPropertyERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_( key, default_value); + /* if (strcmp(kPropKeyCompilerFilter, key.c_str()) == 0) { res = kPropValueCompilerFilter; LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); @@ -55,6 +85,27 @@ namespace edxp { res = kPropValueCompilerFlags; LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); } + */ + + if(strcmp(kPropKeyCompilerFlags, key.c_str()) == 0) { + if(strcmp(res.c_str(),"") == 0) + res = kPropValueCompilerFlags; + else{ + if(strstr(res.c_str(),kPropValueCompilerFlags) == NULL) { + if(strlen(res.c_str()) + strlen(kPropValueCompilerFlagsWS) > PROP_VALUE_MAX) { + //just fallback,why not + LOGI("Cannot add option to disable inline opt!Fall back to replace.."); + res = kPropValueCompilerFlags; + }else { + res.append(kPropValueCompilerFlagsWS); + } + } + if(strstr(res.c_str(),kPropValueCompilerFlags) != NULL) + 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(kPropKeyUseJitProfiles, key.c_str()) == 0) { @@ -88,4 +139,4 @@ namespace edxp { } } -} \ No newline at end of file +} diff --git a/edxp-core/src/main/cpp/main/src/riru_hook.h b/edxp-core/src/main/cpp/main/src/riru_hook.h index 892afa90..0f551bc6 100644 --- a/edxp-core/src/main/cpp/main/src/riru_hook.h +++ b/edxp-core/src/main/cpp/main/src/riru_hook.h @@ -28,6 +28,7 @@ namespace edxp { static constexpr const char *kPropValueCompilerFilter = "quicken"; static constexpr const char *kPropValuePmBgDexopt = "speed"; static constexpr const char *kPropValueCompilerFlags = "--inline-max-code-units=0"; + static constexpr const char *kPropValueCompilerFlagsWS = " --inline-max-code-units=0"; void InstallRiruHooks(); From 1374ff6745d186890d3fae3279bf9d28325f4990 Mon Sep 17 00:00:00 2001 From: lrh2000 Date: Tue, 23 Jun 2020 16:00:00 +0800 Subject: [PATCH 05/11] Keep the log catcher alive. --- edxp-core/template_override/post-fs-data.sh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/edxp-core/template_override/post-fs-data.sh b/edxp-core/template_override/post-fs-data.sh index e3b1b2ac..84deebdf 100644 --- a/edxp-core/template_override/post-fs-data.sh +++ b/edxp-core/template_override/post-fs-data.sh @@ -85,6 +85,19 @@ if [[ -f ${DISABLE_VERBOSE_LOG_FILE} ]]; then LOG_VERBOSE=false fi +# If logcat client is kicked out by klogd server, we'll restart it. +# However, if it is killed manually or by EdXposed Manager, we'll exit. +# Refer to https://github.com/ElderDrivers/EdXposed/pull/575 for more information. +loop_logcat() { + while true + do + logcat $* + if [[ $? -ne 1 ]]; then + break + fi + done +} + start_log_cather () { LOG_FILE_NAME=$1 LOG_TAG_FILTERS=$2 @@ -126,7 +139,7 @@ start_log_cather () { echo "Riru version: ${RIRU_VERSION} (${RIRU_VERCODE})">>${LOG_FILE} echo "Riru api: ${RIRU_APICODE}">>${LOG_FILE} echo "Magisk: ${MAGISK_VERSION%:*} (${MAGISK_VERCODE})">>${LOG_FILE} - logcat -f ${LOG_FILE} *:S ${LOG_TAG_FILTERS} & + loop_logcat -f ${LOG_FILE} *:S ${LOG_TAG_FILTERS} & LOG_PID=$! echo "${LOG_PID}">"${LOG_PATH}/${LOG_FILE_NAME}.pid" } @@ -167,4 +180,4 @@ fi chcon -R u:object_r:system_file:s0 "${MODDIR}" chcon -R ${PATH_CONTEXT} "${LOG_PATH}" chown -R ${PATH_OWNER} "${LOG_PATH}" -chmod -R 666 "${LOG_PATH}" \ No newline at end of file +chmod -R 666 "${LOG_PATH}" From 1d60bb9d46a246364cfec0109b8af7c9f3c3c980 Mon Sep 17 00:00:00 2001 From: EBK21 Date: Sun, 5 Jul 2020 12:56:53 +0800 Subject: [PATCH 06/11] Fix property log not showing and do not force quicken (#573) * fix property log not showing * do not force quicken --- edxp-core/src/main/cpp/main/src/riru_hook.cpp | 4 ++-- edxp-core/template_override/system.prop | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/edxp-core/src/main/cpp/main/src/riru_hook.cpp b/edxp-core/src/main/cpp/main/src/riru_hook.cpp index eda5fccd..7282ee12 100644 --- a/edxp-core/src/main/cpp/main/src/riru_hook.cpp +++ b/edxp-core/src/main/cpp/main/src/riru_hook.cpp @@ -46,10 +46,10 @@ namespace edxp { strcat(value,kPropValueCompilerFlagsWS); } } + } if(strstr(value,kPropValueCompilerFlags) != NULL) LOGI("system_property_get: %s -> %s", key, value); } - } @@ -100,9 +100,9 @@ namespace edxp { res.append(kPropValueCompilerFlagsWS); } } + } if(strstr(res.c_str(),kPropValueCompilerFlags) != NULL) LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); - } } diff --git a/edxp-core/template_override/system.prop b/edxp-core/template_override/system.prop index f6dd1a88..e7264828 100644 --- a/edxp-core/template_override/system.prop +++ b/edxp-core/template_override/system.prop @@ -1,3 +1,3 @@ -dalvik.vm.dex2oat-filter=quicken +#dalvik.vm.dex2oat-filter=quicken dalvik.vm.dex2oat-flags=--inline-max-code-units=0 -#dalvik.vm.image-dex2oat-flags=--inline-max-code-units=0 --compiler-filter=speed \ No newline at end of file +#dalvik.vm.image-dex2oat-flags=--inline-max-code-units=0 --compiler-filter=speed From e4f24e4674a782d62e8b9eff8926eb15a5c620f8 Mon Sep 17 00:00:00 2001 From: solohsu Date: Thu, 30 Jul 2020 15:54:05 +0800 Subject: [PATCH 07/11] Fix debug build This resolves #584 --- edxp-sandhook/build.gradle | 8 +++++--- edxp-whale/build.gradle | 8 +++++--- edxp-yahfa/build.gradle | 8 +++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/edxp-sandhook/build.gradle b/edxp-sandhook/build.gradle index 277d3e98..8612f93f 100644 --- a/edxp-sandhook/build.gradle +++ b/edxp-sandhook/build.gradle @@ -12,7 +12,7 @@ android { targetSdkVersion 28 versionCode 1 versionName "1.0" - multiDexEnabled true + multiDexEnabled false } buildTypes { @@ -62,8 +62,10 @@ afterEvaluate { task("makeAndCopy${variantNameCapped}", type: Jar, dependsOn: "assemble${variantNameCapped}") { dependsOn tasks.getByPath(":edxp-common:copyCommonProperties") - from "${buildDir}/intermediates/transforms/dexMerger/${variantNameLowered}/0/", - "${projectDir}/src/main/resources/" + def dexOutPath = variant.name.contains("release") ? + "${buildDir}/intermediates/transforms/dexMerger/${variantNameLowered}/0/" : + "${buildDir}/intermediates/dex/${variantNameLowered}/mergeDex${variantNameCapped}/out/" + from dexOutPath, "${projectDir}/src/main/resources/" destinationDir file(myTemplatePath + "system/framework/") baseName "edxp" doLast { diff --git a/edxp-whale/build.gradle b/edxp-whale/build.gradle index 686adfaa..93e8a4f6 100644 --- a/edxp-whale/build.gradle +++ b/edxp-whale/build.gradle @@ -12,7 +12,7 @@ android { targetSdkVersion 28 versionCode 1 versionName "1.0" - multiDexEnabled true + multiDexEnabled false } buildTypes { @@ -61,8 +61,10 @@ afterEvaluate { task("makeAndCopy${variantNameCapped}", type: Jar, dependsOn: "assemble${variantNameCapped}") { dependsOn tasks.getByPath(":edxp-common:copyCommonProperties") - from "${buildDir}/intermediates/transforms/dexMerger/${variantNameLowered}/0/", - "${projectDir}/src/main/resources/" + def dexOutPath = variant.name.contains("release") ? + "${buildDir}/intermediates/transforms/dexMerger/${variantNameLowered}/0/" : + "${buildDir}/intermediates/dex/${variantNameLowered}/mergeDex${variantNameCapped}/out/" + from dexOutPath, "${projectDir}/src/main/resources/" destinationDir file(myTemplatePath + "system/framework/") baseName "edxp" doLast { diff --git a/edxp-yahfa/build.gradle b/edxp-yahfa/build.gradle index 28233df2..3e68e503 100644 --- a/edxp-yahfa/build.gradle +++ b/edxp-yahfa/build.gradle @@ -12,7 +12,7 @@ android { targetSdkVersion 28 versionCode 1 versionName "1.0" - multiDexEnabled true + multiDexEnabled false } buildTypes { @@ -61,8 +61,10 @@ afterEvaluate { task("makeAndCopy${variantNameCapped}", type: Jar, dependsOn: "assemble${variantNameCapped}") { dependsOn tasks.getByPath(":edxp-common:copyCommonProperties") - from "${buildDir}/intermediates/transforms/dexMerger/${variantNameLowered}/0/", - "${projectDir}/src/main/resources/" + def dexOutPath = variant.name.contains("release") ? + "${buildDir}/intermediates/transforms/dexMerger/${variantNameLowered}/0/" : + "${buildDir}/intermediates/dex/${variantNameLowered}/mergeDex${variantNameCapped}/out/" + from dexOutPath, "${projectDir}/src/main/resources/" destinationDir file(myTemplatePath + "system/framework/") baseName "edxp" doLast { From 8d7a6627ab33c19e450ff1876bc283c1e5ee91f9 Mon Sep 17 00:00:00 2001 From: solohsu Date: Thu, 30 Jul 2020 23:39:59 +0800 Subject: [PATCH 08/11] Sync with YAHFA This commit contains changes from PAGalaxyLab/YAHFA@d617833, PAGalaxyLab/YAHFA@87abb05, PAGalaxyLab/YAHFA@ee20e5f, PAGalaxyLab/YAHFA@1324f85, PAGalaxyLab/YAHFA@82d1873 --- .../elderdrivers/riru/edxp/core/Yahfa.java | 2 +- .../main/cpp/external/yahfa/src/HookMain.c | 41 +++++++++---------- .../src/main/cpp/external/yahfa/src/common.h | 3 ++ .../src/main/cpp/external/yahfa/src/env.h | 33 --------------- .../main/cpp/external/yahfa/src/trampoline.c | 6 ++- .../src/main/cpp/main/include/android_build.h | 17 -------- .../cpp/main/include/art/runtime/hidden_api.h | 4 +- .../include/art/runtime/oat_file_manager.h | 4 +- edxp-core/src/main/cpp/main/include/config.h | 2 +- .../src/main/cpp/main/src/config_manager.cpp | 2 +- .../src/main/cpp/main/src/native_hook.cpp | 4 +- edxp-core/src/main/cpp/main/src/riru_hook.cpp | 6 +-- 12 files changed, 40 insertions(+), 84 deletions(-) delete mode 100644 edxp-core/src/main/cpp/external/yahfa/src/env.h diff --git a/edxp-common/src/main/java/com/elderdrivers/riru/edxp/core/Yahfa.java b/edxp-common/src/main/java/com/elderdrivers/riru/edxp/core/Yahfa.java index d439dd55..2fd0686f 100644 --- a/edxp-common/src/main/java/com/elderdrivers/riru/edxp/core/Yahfa.java +++ b/edxp-common/src/main/java/com/elderdrivers/riru/edxp/core/Yahfa.java @@ -12,7 +12,7 @@ public class Yahfa { // JNI.ToReflectedMethod() could return either Method or Constructor public static native Object findMethodNative(Class targetClass, String methodName, String methodSig); - public static native void init(int SDK_version); + public static native void init(int sdkVersion); public static native void setMethodNonCompilable(Member member); diff --git a/edxp-core/src/main/cpp/external/yahfa/src/HookMain.c b/edxp-core/src/main/cpp/external/yahfa/src/HookMain.c index c9fda466..70e73ecc 100644 --- a/edxp-core/src/main/cpp/external/yahfa/src/HookMain.c +++ b/edxp-core/src/main/cpp/external/yahfa/src/HookMain.c @@ -5,7 +5,6 @@ #include #include "common.h" -#include "env.h" #include "trampoline.h" #include "HookMain.h" @@ -22,10 +21,6 @@ static int kAccNative = 0x0100; static int kAccCompileDontBother = 0x01000000; static int kAccFastInterpreterToInterpreterInvoke = 0x40000000; -static inline uint16_t read16(void *addr) { - return *((uint16_t *) addr); -} - static inline uint32_t read32(void *addr) { return *((uint32_t *) addr); } @@ -34,13 +29,17 @@ static inline void write32(void *addr, uint32_t value) { *((uint32_t *) addr) = value; } +static inline void* readAddr(void *addr) { + return *((void**) addr); +} + void Java_lab_galaxy_yahfa_HookMain_init(JNIEnv *env, jclass clazz, jint sdkVersion) { int i; SDKVersion = sdkVersion; LOGI("init to SDK %d", sdkVersion); switch (sdkVersion) { - case ANDROID_Q: - case ANDROID_P: + case __ANDROID_API_Q__: + case __ANDROID_API_P__: kAccCompileDontBother = 0x02000000; OFFSET_ArtMehod_in_Object = 0; OFFSET_access_flags_in_ArtMethod = 4; @@ -50,9 +49,9 @@ void Java_lab_galaxy_yahfa_HookMain_init(JNIEnv *env, jclass clazz, jint sdkVers roundUpToPtrSize(4 * 4 + 2 * 2) + pointer_size; ArtMethodSize = roundUpToPtrSize(4 * 4 + 2 * 2) + pointer_size * 2; break; - case ANDROID_O2: + case __ANDROID_API_O_MR1__: kAccCompileDontBother = 0x02000000; - case ANDROID_O: + case __ANDROID_API_O__: OFFSET_ArtMehod_in_Object = 0; OFFSET_access_flags_in_ArtMethod = 4; OFFSET_dex_method_index_in_ArtMethod = 4 * 3; @@ -62,8 +61,8 @@ void Java_lab_galaxy_yahfa_HookMain_init(JNIEnv *env, jclass clazz, jint sdkVers roundUpToPtrSize(4 * 4 + 2 * 2) + pointer_size * 2; ArtMethodSize = roundUpToPtrSize(4 * 4 + 2 * 2) + pointer_size * 3; break; - case ANDROID_N2: - case ANDROID_N: + case __ANDROID_API_N_MR1__: + case __ANDROID_API_N__: OFFSET_ArtMehod_in_Object = 0; OFFSET_access_flags_in_ArtMethod = 4; // sizeof(GcRoot) = 4 OFFSET_dex_method_index_in_ArtMethod = 4 * 3; @@ -76,7 +75,7 @@ void Java_lab_galaxy_yahfa_HookMain_init(JNIEnv *env, jclass clazz, jint sdkVers ArtMethodSize = roundUpToPtrSize(4 * 4 + 2 * 2) + pointer_size * 4; break; - case ANDROID_M: + case __ANDROID_API_M__: OFFSET_ArtMehod_in_Object = 0; OFFSET_entry_point_from_interpreter_in_ArtMethod = roundUpToPtrSize(4 * 7); OFFSET_entry_point_from_quick_compiled_code_in_ArtMethod = @@ -86,7 +85,7 @@ void Java_lab_galaxy_yahfa_HookMain_init(JNIEnv *env, jclass clazz, jint sdkVers OFFSET_array_in_PointerArray = 4 * 3; ArtMethodSize = roundUpToPtrSize(4 * 7) + pointer_size * 3; break; - case ANDROID_L2: + case __ANDROID_API_L_MR1__: OFFSET_ArtMehod_in_Object = 4 * 2; OFFSET_entry_point_from_interpreter_in_ArtMethod = roundUpToPtrSize( OFFSET_ArtMehod_in_Object + 4 * 7); @@ -97,7 +96,7 @@ void Java_lab_galaxy_yahfa_HookMain_init(JNIEnv *env, jclass clazz, jint sdkVers OFFSET_array_in_PointerArray = 12; ArtMethodSize = OFFSET_entry_point_from_interpreter_in_ArtMethod + pointer_size * 3; break; - case ANDROID_L: + case __ANDROID_API_L__: OFFSET_ArtMehod_in_Object = 4 * 2; OFFSET_entry_point_from_interpreter_in_ArtMethod = OFFSET_ArtMehod_in_Object + 4 * 4; OFFSET_entry_point_from_quick_compiled_code_in_ArtMethod = @@ -117,7 +116,7 @@ void Java_lab_galaxy_yahfa_HookMain_init(JNIEnv *env, jclass clazz, jint sdkVers } void setNonCompilable(void *method) { - if (SDKVersion < ANDROID_N) { + if (SDKVersion < __ANDROID_API_N__) { return; } int access_flags = read32((char *) method + OFFSET_access_flags_in_ArtMethod); @@ -132,7 +131,7 @@ bool setNativeFlag(void *method, bool isNative) { int old_access_flags = access_flags; if (isNative) { access_flags |= kAccNative; - if (SDKVersion >= ANDROID_Q) { + if (SDKVersion >= __ANDROID_API_Q__) { // On API 29 whether to use the fast path or not is cached in the ART method structure access_flags &= ~kAccFastInterpreterToInterpreterInvoke; } @@ -162,7 +161,7 @@ static int doBackupAndHook(JNIEnv *env, void *targetMethod, void *hookMethod, vo // set kAccCompileDontBother for a method we do not want the compiler to compile // so that we don't need to worry about hotness_count_ - if (SDKVersion >= ANDROID_N) { + if (SDKVersion >= __ANDROID_API_N__) { setNonCompilable(targetMethod); setNonCompilable(hookMethod); } @@ -199,7 +198,7 @@ static int doBackupAndHook(JNIEnv *env, void *targetMethod, void *hookMethod, vo } // set the target method to native so that Android O wouldn't invoke it with interpreter - if (SDKVersion >= ANDROID_O) { + if (SDKVersion >= __ANDROID_API_O__) { setNativeFlag(targetMethod, true); LOGI("access flags is 0x%x", access_flags); } @@ -231,7 +230,7 @@ static void ensureMethodCached(void *hookMethod, void *backupMethod, } // finally the addr of backup method is put at the corresponding location in cached methods array - if (SDKVersion >= ANDROID_O2) { + if (SDKVersion >= __ANDROID_API_O_MR1__) { // array of MethodDexCacheType is used as dexCacheResolvedMethods in Android 8.1 // struct: // struct NativeDexCachePair = { T*, size_t idx } @@ -319,11 +318,11 @@ static void *getResolvedMethodsAddr(JNIEnv *env, jobject hook) { jobject dexCacheObj = (*env)->GetObjectField(env, backupClass, dexCacheFid); // get resolvedMethods address jclass dexCacheClass = (*env)->GetObjectClass(env, dexCacheObj); - if (SDKVersion >= ANDROID_N) { + if (SDKVersion >= __ANDROID_API_N__) { jfieldID resolvedMethodsFid = (*env)->GetFieldID(env, dexCacheClass, "resolvedMethods", "J"); return (void *) (*env)->GetLongField(env, dexCacheObj, resolvedMethodsFid); - } else if (SDKVersion >= ANDROID_L) { + } else if (SDKVersion >= __ANDROID_API_L__) { LOGE("this should has been done in java world: %d", SDKVersion); return 0; } else { diff --git a/edxp-core/src/main/cpp/external/yahfa/src/common.h b/edxp-core/src/main/cpp/external/yahfa/src/common.h index 6d99272d..570f794c 100644 --- a/edxp-core/src/main/cpp/external/yahfa/src/common.h +++ b/edxp-core/src/main/cpp/external/yahfa/src/common.h @@ -26,4 +26,7 @@ #endif // DEBUG #endif // LOG_DISABLED +#define pointer_size sizeof(void*) +#define roundUpToPtrSize(v) (v + pointer_size - 1 - ((v + pointer_size - 1) & (pointer_size - 1))) + #endif //YAHFA_COMMON_H diff --git a/edxp-core/src/main/cpp/external/yahfa/src/env.h b/edxp-core/src/main/cpp/external/yahfa/src/env.h deleted file mode 100644 index 026f20ed..00000000 --- a/edxp-core/src/main/cpp/external/yahfa/src/env.h +++ /dev/null @@ -1,33 +0,0 @@ -// -// Created by liuruikai756 on 05/07/2017. -// - -#ifndef YAHFA_ENV_H -#define YAHFA_ENV_H - -#define ANDROID_L 21 -#define ANDROID_L2 22 -#define ANDROID_M 23 -#define ANDROID_N 24 -#define ANDROID_N2 25 -#define ANDROID_O 26 -#define ANDROID_O2 27 -#define ANDROID_P 28 -#define ANDROID_Q 29 - -#define roundUpTo4(v) ((v+4-1) - ((v+4-1)&3)) -#define roundUpTo8(v) ((v+8-1) - ((v+8-1)&7)) - -#if defined(__i386__) || defined(__arm__) -#define pointer_size 4 -#define readAddr(addr) read32(addr) -#define roundUpToPtrSize(x) roundUpTo4(x) -#elif defined(__aarch64__) || defined(__x86_64__) -#define pointer_size 8 -#define readAddr(addr) read64(addr) -#define roundUpToPtrSize(x) roundUpTo8(x) -#else -#error Unsupported architecture -#endif - -#endif //YAHFA_ENV_H diff --git a/edxp-core/src/main/cpp/external/yahfa/src/trampoline.c b/edxp-core/src/main/cpp/external/yahfa/src/trampoline.c index 8b8daebf..6ca8f7fe 100644 --- a/edxp-core/src/main/cpp/external/yahfa/src/trampoline.c +++ b/edxp-core/src/main/cpp/external/yahfa/src/trampoline.c @@ -12,7 +12,6 @@ #include #include "common.h" -#include "env.h" #include "trampoline.h" static unsigned char *trampolineCode; // place where trampolines are saved @@ -89,6 +88,9 @@ void *genTrampoline(void *hookMethod) { #elif defined(__aarch64__) memcpy(targetAddr + 12, &hookMethod, pointer_size); + +#else +#error Unsupported architecture #endif return targetAddr; @@ -106,6 +108,8 @@ void setupTrampoline() { ((unsigned char) OFFSET_entry_point_from_quick_compiled_code_in_ArtMethod) << 4; trampoline[6] |= ((unsigned char) OFFSET_entry_point_from_quick_compiled_code_in_ArtMethod) >> 4; +#else +#error Unsupported architecture #endif } diff --git a/edxp-core/src/main/cpp/main/include/android_build.h b/edxp-core/src/main/cpp/main/include/android_build.h index 4507c49b..46c8c609 100644 --- a/edxp-core/src/main/cpp/main/include/android_build.h +++ b/edxp-core/src/main/cpp/main/include/android_build.h @@ -5,23 +5,6 @@ #include #include -#define ANDROID_ICE_CREAM_SANDWICH 14 -#define ANDROID_ICE_CREAM_SANDWICH_MR1 15 -#define ANDROID_JELLY_BEAN 16 -#define ANDROID_JELLY_BEAN_MR1 17 -#define ANDROID_JELLY_BEAN_MR2 18 -#define ANDROID_KITKAT 19 -#define ANDROID_KITKAT_WATCH 20 -#define ANDROID_LOLLIPOP 21 -#define ANDROID_LOLLIPOP_MR1 22 -#define ANDROID_M 23 -#define ANDROID_N 24 -#define ANDROID_N_MR1 25 -#define ANDROID_O 26 -#define ANDROID_O_MR1 27 -#define ANDROID_P 28 -#define ANDROID_Q 29 - static inline int32_t GetAndroidApiLevel() { char prop_value[PROP_VALUE_MAX]; __system_property_get("ro.build.version.sdk", prop_value); diff --git a/edxp-core/src/main/cpp/main/include/art/runtime/hidden_api.h b/edxp-core/src/main/cpp/main/include/art/runtime/hidden_api.h index abb3d394..0e515731 100644 --- a/edxp-core/src/main/cpp/main/include/art/runtime/hidden_api.h +++ b/edxp-core/src/main/cpp/main/include/art/runtime/hidden_api.h @@ -32,10 +32,10 @@ namespace art { static void DisableHiddenApi(void *handle, HookFunType hook_func) { const int api_level = GetAndroidApiLevel(); - if (api_level < ANDROID_P) { + if (api_level < __ANDROID_API_P__) { return; } - if (api_level == ANDROID_P) { + if (api_level == __ANDROID_API_P__) { HOOK_FUNC(GetMethodActionImpl, "_ZN3art9hiddenapi6detail19GetMemberActionImplINS_9ArtMethodEEENS0_" "6ActionEPT_NS_20HiddenApiAccessFlags7ApiListES4_NS0_12AccessMethodE"); diff --git a/edxp-core/src/main/cpp/main/include/art/runtime/oat_file_manager.h b/edxp-core/src/main/cpp/main/include/art/runtime/oat_file_manager.h index a9445ee5..a2c1a8c1 100644 --- a/edxp-core/src/main/cpp/main/include/art/runtime/oat_file_manager.h +++ b/edxp-core/src/main/cpp/main/include/art/runtime/oat_file_manager.h @@ -14,11 +14,11 @@ namespace art { // http://androidxref.com/9.0.0_r3/xref/art/runtime/oat_file_manager.cc#637 static void DisableOnlyUseSystemOatFiles(void *handle, HookFunType hook_func) { const int api_level = GetAndroidApiLevel(); - if (api_level == ANDROID_P) { + if (api_level == __ANDROID_API_P__) { HOOK_FUNC(SetOnlyUseSystemOatFiles, "_ZN3art14OatFileManager24SetOnlyUseSystemOatFilesEv"); } - if (api_level == ANDROID_Q) { + if (api_level == __ANDROID_API_Q__) { HOOK_FUNC(SetOnlyUseSystemOatFiles, "_ZN3art14OatFileManager24SetOnlyUseSystemOatFilesEbb"); } diff --git a/edxp-core/src/main/cpp/main/include/config.h b/edxp-core/src/main/cpp/main/include/config.h index 1075f09a..ce52c60b 100644 --- a/edxp-core/src/main/cpp/main/include/config.h +++ b/edxp-core/src/main/cpp/main/include/config.h @@ -37,7 +37,7 @@ namespace edxp { LP_SELECT("/apex/com.android.runtime/lib/", "/apex/com.android.runtime/lib64/")); static const auto kLibArtPath = - (GetAndroidApiLevel() >= ANDROID_Q ? kLibRuntimeBasePath : kLibBasePath) + kLibArtName; + (GetAndroidApiLevel() >= __ANDROID_API_Q__ ? kLibRuntimeBasePath : kLibBasePath) + kLibArtName; static const auto kLibWhalePath = kLibBasePath + kLibWhaleName; static const auto kLibSandHookPath = kLibBasePath + kLibSandHookName; diff --git a/edxp-core/src/main/cpp/main/src/config_manager.cpp b/edxp-core/src/main/cpp/main/src/config_manager.cpp index 8e3cf37a..b0a1425c 100644 --- a/edxp-core/src/main/cpp/main/src/config_manager.cpp +++ b/edxp-core/src/main/cpp/main/src/config_manager.cpp @@ -214,7 +214,7 @@ namespace edxp { }; ConfigManager::ConfigManager() { - use_prot_storage_ = GetAndroidApiLevel() >= ANDROID_N; + use_prot_storage_ = GetAndroidApiLevel() >= __ANDROID_API_N__; last_user_ = 0; UpdateConfigPath(last_user_); } diff --git a/edxp-core/src/main/cpp/main/src/native_hook.cpp b/edxp-core/src/main/cpp/main/src/native_hook.cpp index 4e42a99a..582bef64 100644 --- a/edxp-core/src/main/cpp/main/src/native_hook.cpp +++ b/edxp-core/src/main/cpp/main/src/native_hook.cpp @@ -46,7 +46,7 @@ namespace edxp { } LOGI("Start to install inline hooks"); int api_level = GetAndroidApiLevel(); - if (UNLIKELY(api_level < ANDROID_LOLLIPOP)) { + if (UNLIKELY(api_level < __ANDROID_API_L__)) { LOGE("API level not supported: %d, skip inline hooks", api_level); return; } @@ -66,7 +66,7 @@ namespace edxp { } hook_func = reinterpret_cast(hook_func_symbol); - if (api_level > ANDROID_P) { + if (api_level > __ANDROID_API_P__) { ScopedDlHandle dl_handle(kLibDlPath.c_str()); void *handle = dl_handle.Get(); HOOK_FUNC(mydlopen, "__loader_dlopen"); diff --git a/edxp-core/src/main/cpp/main/src/riru_hook.cpp b/edxp-core/src/main/cpp/main/src/riru_hook.cpp index 7282ee12..b21a14a6 100644 --- a/edxp-core/src/main/cpp/main/src/riru_hook.cpp +++ b/edxp-core/src/main/cpp/main/src/riru_hook.cpp @@ -54,7 +54,7 @@ namespace edxp { - if (api_level == ANDROID_O_MR1) { + if (api_level == __ANDROID_API_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 @@ -106,7 +106,7 @@ namespace edxp { } - if (api_level == ANDROID_O_MR1) { + if (api_level == __ANDROID_API_O_MR1__) { // see __system_property_get hook above for explanations if (strcmp(kPropKeyUseJitProfiles, key.c_str()) == 0) { res = "false"; @@ -126,7 +126,7 @@ namespace edxp { XHOOK_REGISTER(__system_property_get); - if (GetAndroidApiLevel() >= ANDROID_P) { + if (GetAndroidApiLevel() >= __ANDROID_API_P__) { XHOOK_REGISTER( _ZN7android4base11GetPropertyERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_); } From 398d8b0553efd77652bb2fe0dbd09d2dcbb757ae Mon Sep 17 00:00:00 2001 From: solohsu Date: Fri, 31 Jul 2020 11:26:48 +0800 Subject: [PATCH 09/11] Bump version --- appveyor.yml | 2 +- edxp-core/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 96ec2cbc..1bfe270a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: '0.4.6.3 ({build})' +version: '0.4.6.4 ({build})' environment: ANDROID_HOME: C:\android-sdk-windows diff --git a/edxp-core/build.gradle b/edxp-core/build.gradle index 55cc6ce9..94fb01c5 100644 --- a/edxp-core/build.gradle +++ b/edxp-core/build.gradle @@ -4,7 +4,7 @@ import org.gradle.internal.os.OperatingSystem apply plugin: 'com.android.library' // Values set here will be overriden by AppVeyor, feel free to modify during development. -def buildVersionName = 'v0.4.6.3' +def buildVersionName = 'v0.4.6.4' def buildVersionCode = 233 if (System.env.APPVEYOR_BUILD_VERSION != null) { From 32370d69abbca048e9a3672bd063a0a025bf83de Mon Sep 17 00:00:00 2001 From: solohsu Date: Fri, 31 Jul 2020 15:10:07 +0800 Subject: [PATCH 10/11] Fix fd for anonymous mmap --- edxp-core/src/main/cpp/external/yahfa/src/trampoline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edxp-core/src/main/cpp/external/yahfa/src/trampoline.c b/edxp-core/src/main/cpp/external/yahfa/src/trampoline.c index 6ca8f7fe..5b9eb8da 100644 --- a/edxp-core/src/main/cpp/external/yahfa/src/trampoline.c +++ b/edxp-core/src/main/cpp/external/yahfa/src/trampoline.c @@ -123,7 +123,7 @@ int doInitHookCap(unsigned int cap) { } unsigned int allSize = trampolineSize * cap; unsigned char *buf = mmap(NULL, allSize, PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_ANONYMOUS | MAP_PRIVATE, 0, 0); + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); if (buf == MAP_FAILED) { LOGE("mmap failed, errno = %s", strerror(errno)); return 1; From cb1e86810e3740644eace07456fa1443a6e17cdb Mon Sep 17 00:00:00 2001 From: solohsu Date: Sat, 1 Aug 2020 22:08:02 +0800 Subject: [PATCH 11/11] Fix compilation error when debugging log is enabled --- edxp-core/src/main/cpp/external/yahfa/src/HookMain.c | 1 - 1 file changed, 1 deletion(-) diff --git a/edxp-core/src/main/cpp/external/yahfa/src/HookMain.c b/edxp-core/src/main/cpp/external/yahfa/src/HookMain.c index 70e73ecc..57e0faf1 100644 --- a/edxp-core/src/main/cpp/external/yahfa/src/HookMain.c +++ b/edxp-core/src/main/cpp/external/yahfa/src/HookMain.c @@ -200,7 +200,6 @@ static int doBackupAndHook(JNIEnv *env, void *targetMethod, void *hookMethod, vo // set the target method to native so that Android O wouldn't invoke it with interpreter if (SDKVersion >= __ANDROID_API_O__) { setNativeFlag(targetMethod, true); - LOGI("access flags is 0x%x", access_flags); } LOGI("hook and backup done");