[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() {
char prop_value[PROP_VALUE_MAX]; static int32_t api_level = []() {
__system_property_get("ro.build.version.sdk", prop_value); char prop_value[PROP_VALUE_MAX];
return atoi(prop_value); __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 && (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();
"_ZN3artL25DexFile_openDexFileNativeEP7_JNIEnvP7_jclassP8_jstringS5_iP8_jobjectP13_jobjectArray"))) && if (api_level < __ANDROID_API_P__ || (
( (sym_openDexFileNative = reinterpret_cast<void *>(art.getSymbAddress(
(sym_openInMemoryDexFilesNative = reinterpret_cast<void *>(art.getSymbAddress( "_ZN3artL25DexFile_openDexFileNativeEP7_JNIEnvP7_jclassP8_jstringS5_iP8_jobjectP13_jobjectArray"))) &&
"_ZN3artL34DexFile_openInMemoryDexFilesNativeEP7_JNIEnvP7_jclassP13_jobjectArrayS5_P10_jintArrayS7_P8_jobjectS5_"))) || (
( (sym_openInMemoryDexFilesNative = reinterpret_cast<void *>(art.getSymbAddress(
(sym_createCookieWithArray = reinterpret_cast<void *>(art.getSymbAddress( "_ZN3artL34DexFile_openInMemoryDexFilesNativeEP7_JNIEnvP7_jclassP13_jobjectArrayS5_P10_jintArrayS7_P8_jobjectS5_"))) ||
"_ZN3artL29DexFile_createCookieWithArrayEP7_JNIEnvP7_jclassP11_jbyteArrayii"))) && (
(sym_createCookieWithDirectBuffer = reinterpret_cast<void *>(art.getSymbAddress( (sym_createCookieWithArray = reinterpret_cast<void *>(art.getSymbAddress(
"_ZN3artL36DexFile_createCookieWithDirectBufferEP7_JNIEnvP7_jclassP8_jobjectii"))) "_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")))) ) &&
(sym_setTrusted = reinterpret_cast<void *>(art.getSymbAddress(
"_ZN3artL18DexFile_setTrustedEP7_JNIEnvP7_jclassP8_jobject")))))
return soinfo->to_handle(); return soinfo->to_handle();
} }
} }