From 4621b6a485bc74cff310b8e9a8528e64c3d1c5ca Mon Sep 17 00:00:00 2001 From: Paulo Costa Date: Thu, 20 Feb 2020 20:24:19 -0300 Subject: [PATCH] YAHFA: Support for android 10 Change-Id: I8d31014abff1ed15919ab10604a90be52d96c3a6 --- .../main/cpp/external/yahfa/src/HookMain.c | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) 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 fc49eed4..c9fda466 100644 --- a/edxp-core/src/main/cpp/external/yahfa/src/HookMain.c +++ b/edxp-core/src/main/cpp/external/yahfa/src/HookMain.c @@ -20,6 +20,7 @@ static int OFFSET_access_flags_in_ArtMethod; static size_t ArtMethodSize; static int kAccNative = 0x0100; static int kAccCompileDontBother = 0x01000000; +static int kAccFastInterpreterToInterpreterInvoke = 0x40000000; static inline uint16_t read16(void *addr) { return *((uint16_t *) addr); @@ -29,8 +30,8 @@ static inline uint32_t read32(void *addr) { return *((uint32_t *) addr); } -static inline uint64_t read64(void *addr) { - return *((uint64_t *) addr); +static inline void write32(void *addr, uint32_t value) { + *((uint32_t *) addr) = value; } void Java_lab_galaxy_yahfa_HookMain_init(JNIEnv *env, jclass clazz, jint sdkVersion) { @@ -122,11 +123,7 @@ void setNonCompilable(void *method) { int access_flags = read32((char *) method + OFFSET_access_flags_in_ArtMethod); LOGI("setNonCompilable: access flags is 0x%x", access_flags); access_flags |= kAccCompileDontBother; - memcpy( - (char *) method + OFFSET_access_flags_in_ArtMethod, - &access_flags, - 4 - ); + write32((char *) method + OFFSET_access_flags_in_ArtMethod, access_flags); } bool setNativeFlag(void *method, bool isNative) { @@ -135,15 +132,15 @@ bool setNativeFlag(void *method, bool isNative) { int old_access_flags = access_flags; if (isNative) { access_flags |= kAccNative; + if (SDKVersion >= ANDROID_Q) { + // On API 29 whether to use the fast path or not is cached in the ART method structure + access_flags &= ~kAccFastInterpreterToInterpreterInvoke; + } } else { access_flags &= ~kAccNative; } if (access_flags != old_access_flags) { - memcpy( - (char *) method + OFFSET_access_flags_in_ArtMethod, - &access_flags, - 4 - ); + write32((char *) method + OFFSET_access_flags_in_ArtMethod, access_flags); return true; } return false;