diff --git a/core/src/main/cpp/main/include/utils.h b/core/src/main/cpp/main/include/utils.h index d83ef186..de23bb4e 100644 --- a/core/src/main/cpp/main/include/utils.h +++ b/core/src/main/cpp/main/include/utils.h @@ -33,10 +33,13 @@ namespace lspd { using namespace std::literals::string_literals; - static inline int32_t GetAndroidApiLevel() { - char prop_value[PROP_VALUE_MAX]; - __system_property_get("ro.build.version.sdk", prop_value); - return atoi(prop_value); + inline int32_t GetAndroidApiLevel() { + static int32_t api_level = []() { + char prop_value[PROP_VALUE_MAX]; + __system_property_get("ro.build.version.sdk", prop_value); + return atoi(prop_value); + }(); + return api_level; } diff --git a/core/src/main/cpp/main/src/symbol_cache.cpp b/core/src/main/cpp/main/src/symbol_cache.cpp index e46cd3cb..f2cf7f66 100644 --- a/core/src/main/cpp/main/src/symbol_cache.cpp +++ b/core/src/main/cpp/main/src/symbol_cache.cpp @@ -124,20 +124,22 @@ namespace lspd { (real_path && std::string_view(real_path).find(kLibArtName) != std::string_view::npos)) { auto art = SandHook::ElfImg(real_path); - if ((sym_openDexFileNative = reinterpret_cast(art.getSymbAddress( - "_ZN3artL25DexFile_openDexFileNativeEP7_JNIEnvP7_jclassP8_jstringS5_iP8_jobjectP13_jobjectArray"))) && - ( - (sym_openInMemoryDexFilesNative = reinterpret_cast(art.getSymbAddress( - "_ZN3artL34DexFile_openInMemoryDexFilesNativeEP7_JNIEnvP7_jclassP13_jobjectArrayS5_P10_jintArrayS7_P8_jobjectS5_"))) || - ( - (sym_createCookieWithArray = reinterpret_cast(art.getSymbAddress( - "_ZN3artL29DexFile_createCookieWithArrayEP7_JNIEnvP7_jclassP11_jbyteArrayii"))) && - (sym_createCookieWithDirectBuffer = reinterpret_cast(art.getSymbAddress( - "_ZN3artL36DexFile_createCookieWithDirectBufferEP7_JNIEnvP7_jclassP8_jobjectii"))) - ) - ) && - (sym_setTrusted = reinterpret_cast(art.getSymbAddress( - "_ZN3artL18DexFile_setTrustedEP7_JNIEnvP7_jclassP8_jobject")))) + auto api_level = GetAndroidApiLevel(); + if (api_level < __ANDROID_API_P__ || ( + (sym_openDexFileNative = reinterpret_cast(art.getSymbAddress( + "_ZN3artL25DexFile_openDexFileNativeEP7_JNIEnvP7_jclassP8_jstringS5_iP8_jobjectP13_jobjectArray"))) && + ( + (sym_openInMemoryDexFilesNative = reinterpret_cast(art.getSymbAddress( + "_ZN3artL34DexFile_openInMemoryDexFilesNativeEP7_JNIEnvP7_jclassP13_jobjectArrayS5_P10_jintArrayS7_P8_jobjectS5_"))) || + ( + (sym_createCookieWithArray = reinterpret_cast(art.getSymbAddress( + "_ZN3artL29DexFile_createCookieWithArrayEP7_JNIEnvP7_jclassP11_jbyteArrayii"))) && + (sym_createCookieWithDirectBuffer = reinterpret_cast(art.getSymbAddress( + "_ZN3artL36DexFile_createCookieWithDirectBufferEP7_JNIEnvP7_jclassP8_jobjectii"))) + ) + ) && + (sym_setTrusted = reinterpret_cast(art.getSymbAddress( + "_ZN3artL18DexFile_setTrustedEP7_JNIEnvP7_jclassP8_jobject"))))) return soinfo->to_handle(); } }