[core] Fix Android O MR1 (#544)

This commit is contained in:
LoveSy 2021-05-06 21:42:34 +08:00 committed by GitHub
parent 3fae782f0c
commit 5f68cbea36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 18 deletions

View File

@ -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;
}

View File

@ -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<void *>(art.getSymbAddress(
"_ZN3artL25DexFile_openDexFileNativeEP7_JNIEnvP7_jclassP8_jstringS5_iP8_jobjectP13_jobjectArray"))) &&
(
(sym_openInMemoryDexFilesNative = reinterpret_cast<void *>(art.getSymbAddress(
"_ZN3artL34DexFile_openInMemoryDexFilesNativeEP7_JNIEnvP7_jclassP13_jobjectArrayS5_P10_jintArrayS7_P8_jobjectS5_"))) ||
(
(sym_createCookieWithArray = reinterpret_cast<void *>(art.getSymbAddress(
"_ZN3artL29DexFile_createCookieWithArrayEP7_JNIEnvP7_jclassP11_jbyteArrayii"))) &&
(sym_createCookieWithDirectBuffer = reinterpret_cast<void *>(art.getSymbAddress(
"_ZN3artL36DexFile_createCookieWithDirectBufferEP7_JNIEnvP7_jclassP8_jobjectii")))
)
) &&
(sym_setTrusted = reinterpret_cast<void *>(art.getSymbAddress(
"_ZN3artL18DexFile_setTrustedEP7_JNIEnvP7_jclassP8_jobject"))))
auto api_level = GetAndroidApiLevel();
if (api_level < __ANDROID_API_P__ || (
(sym_openDexFileNative = reinterpret_cast<void *>(art.getSymbAddress(
"_ZN3artL25DexFile_openDexFileNativeEP7_JNIEnvP7_jclassP8_jstringS5_iP8_jobjectP13_jobjectArray"))) &&
(
(sym_openInMemoryDexFilesNative = reinterpret_cast<void *>(art.getSymbAddress(
"_ZN3artL34DexFile_openInMemoryDexFilesNativeEP7_JNIEnvP7_jclassP13_jobjectArrayS5_P10_jintArrayS7_P8_jobjectS5_"))) ||
(
(sym_createCookieWithArray = reinterpret_cast<void *>(art.getSymbAddress(
"_ZN3artL29DexFile_createCookieWithArrayEP7_JNIEnvP7_jclassP11_jbyteArrayii"))) &&
(sym_createCookieWithDirectBuffer = reinterpret_cast<void *>(art.getSymbAddress(
"_ZN3artL36DexFile_createCookieWithDirectBufferEP7_JNIEnvP7_jclassP8_jobjectii")))
)
) &&
(sym_setTrusted = reinterpret_cast<void *>(art.getSymbAddress(
"_ZN3artL18DexFile_setTrustedEP7_JNIEnvP7_jclassP8_jobject")))))
return soinfo->to_handle();
}
}