[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 { namespace lspd {
using namespace std::literals::string_literals; using namespace std::literals::string_literals;
static inline int32_t GetAndroidApiLevel() { inline int32_t GetAndroidApiLevel() {
static int32_t api_level = []() {
char prop_value[PROP_VALUE_MAX]; char prop_value[PROP_VALUE_MAX];
__system_property_get("ro.build.version.sdk", prop_value); __system_property_get("ro.build.version.sdk", prop_value);
return atoi(prop_value); return atoi(prop_value);
}();
return api_level;
} }

View File

@ -124,7 +124,9 @@ namespace lspd {
(real_path && (real_path &&
std::string_view(real_path).find(kLibArtName) != std::string_view::npos)) { std::string_view(real_path).find(kLibArtName) != std::string_view::npos)) {
auto art = SandHook::ElfImg(real_path); auto art = SandHook::ElfImg(real_path);
if ((sym_openDexFileNative = reinterpret_cast<void *>(art.getSymbAddress( 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"))) && "_ZN3artL25DexFile_openDexFileNativeEP7_JNIEnvP7_jclassP8_jstringS5_iP8_jobjectP13_jobjectArray"))) &&
( (
(sym_openInMemoryDexFilesNative = reinterpret_cast<void *>(art.getSymbAddress( (sym_openInMemoryDexFilesNative = reinterpret_cast<void *>(art.getSymbAddress(
@ -137,7 +139,7 @@ namespace lspd {
) )
) && ) &&
(sym_setTrusted = reinterpret_cast<void *>(art.getSymbAddress( (sym_setTrusted = reinterpret_cast<void *>(art.getSymbAddress(
"_ZN3artL18DexFile_setTrustedEP7_JNIEnvP7_jclassP8_jobject")))) "_ZN3artL18DexFile_setTrustedEP7_JNIEnvP7_jclassP8_jobject")))))
return soinfo->to_handle(); return soinfo->to_handle();
} }
} }