From aac725484080df6fa1445a48b5c8fc21e958fa83 Mon Sep 17 00:00:00 2001 From: eebssk1 Date: Wed, 11 Dec 2019 15:19:54 +0800 Subject: [PATCH 1/6] Do not force quicken,preserve dex2oat flags. --- edxp-core/src/main/cpp/main/src/riru_hook.cpp | 41 ++++++++++++++++++- edxp-core/src/main/cpp/main/src/riru_hook.h | 1 + 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/edxp-core/src/main/cpp/main/src/riru_hook.cpp b/edxp-core/src/main/cpp/main/src/riru_hook.cpp index dbbae41d0..62860fb75 100644 --- a/edxp-core/src/main/cpp/main/src/riru_hook.cpp +++ b/edxp-core/src/main/cpp/main/src/riru_hook.cpp @@ -17,7 +17,9 @@ namespace edxp { NEW_FUNC_DEF(int, __system_property_get, const char *key, char *value) { int res = old___system_property_get(key, value); + if (key) { + /* if (strcmp(kPropKeyCompilerFilter, key) == 0) { strcpy(value, kPropValueCompilerFilter); LOGI("system_property_get: %s -> %s", key, value); @@ -25,6 +27,26 @@ namespace edxp { strcpy(value, kPropValueCompilerFlags); LOGI("system_property_get: %s -> %s", key, value); } + */ + + if(strcmp(kPropKeyCompilerFlags, key) == 0) { + if(strcmp(value,"") == 0) { + strcpy(value, kPropValueCompilerFlags); + }else{ + if(strlen(value) + strlen(kPropValueCompilerFlagsWS) > 91) { + LOGI("Cannot add option to disable inline opt!"); + }else{ + if(strstr(value,kPropValueCompilerFlags) == NULL) + strcat(value,kPropValueCompilerFlagsWS); + } + } + if(strstr(value,kPropValueCompilerFlags) != NULL) + LOGI("system_property_get: %s -> %s", key, value); + } + + + + if (api_level == ANDROID_O_MR1) { // https://android.googlesource.com/platform/art/+/f5516d38736fb97bfd0435ad03bbab17ddabbe4e // Android 8.1 add a fatal check for debugging (removed in Android 9.0), @@ -48,6 +70,7 @@ namespace edxp { const std::string &key, const std::string &default_value) { std::string res = old__ZN7android4base11GetPropertyERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_( key, default_value); + /* if (strcmp(kPropKeyCompilerFilter, key.c_str()) == 0) { res = kPropValueCompilerFilter; LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); @@ -55,6 +78,22 @@ namespace edxp { res = kPropValueCompilerFlags; LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); } + */ + if(strcmp(kPropKeyCompilerFlags, key.c_str()) == 0) { + if(strcmp(res.c_str(),"") == 0) { + res = kPropValueCompilerFlags; + }else{ + if(strlen(res.c_str()) + strlen(kPropValueCompilerFlagsWS) > 91) { + LOGI("Cannot add option to disable inline opt!"); + }else{ + if(strstr(res.c_str(),kPropValueCompilerFlags) == NULL) + res.append(kPropValueCompilerFlagsWS); + } + } + if(strstr(res.c_str(),kPropValueCompilerFlags) != NULL) + LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); + } + if (api_level == ANDROID_O_MR1) { // see __system_property_get hook above for explanations if (strcmp(kPropKeyUseJitProfiles, key.c_str()) == 0) { @@ -88,4 +127,4 @@ namespace edxp { } } -} \ No newline at end of file +} diff --git a/edxp-core/src/main/cpp/main/src/riru_hook.h b/edxp-core/src/main/cpp/main/src/riru_hook.h index 892afa90a..0f551bc60 100644 --- a/edxp-core/src/main/cpp/main/src/riru_hook.h +++ b/edxp-core/src/main/cpp/main/src/riru_hook.h @@ -28,6 +28,7 @@ namespace edxp { static constexpr const char *kPropValueCompilerFilter = "quicken"; static constexpr const char *kPropValuePmBgDexopt = "speed"; static constexpr const char *kPropValueCompilerFlags = "--inline-max-code-units=0"; + static constexpr const char *kPropValueCompilerFlagsWS = " --inline-max-code-units=0"; void InstallRiruHooks(); From 782a1c15a48b9336a5a758219c9cfb4d96a76a4b Mon Sep 17 00:00:00 2001 From: EBK21 Date: Thu, 18 Jun 2020 19:02:16 +0800 Subject: [PATCH 2/6] Update logic,add description of PROP_VALUE_MAX. --- edxp-core/src/main/cpp/main/src/riru_hook.cpp | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/edxp-core/src/main/cpp/main/src/riru_hook.cpp b/edxp-core/src/main/cpp/main/src/riru_hook.cpp index 62860fb75..d457df06f 100644 --- a/edxp-core/src/main/cpp/main/src/riru_hook.cpp +++ b/edxp-core/src/main/cpp/main/src/riru_hook.cpp @@ -14,6 +14,10 @@ namespace edxp { static int api_level = 0; + + //Max length of property values + //Ref https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/os/SystemProperties.java + static const int PROP_VALUE_MAX = 91; NEW_FUNC_DEF(int, __system_property_get, const char *key, char *value) { int res = old___system_property_get(key, value); @@ -30,16 +34,18 @@ namespace edxp { */ if(strcmp(kPropKeyCompilerFlags, key) == 0) { - if(strcmp(value,"") == 0) { + if(strcmp(value,"") == 0) strcpy(value, kPropValueCompilerFlags); - }else{ - if(strlen(value) + strlen(kPropValueCompilerFlagsWS) > 91) { - LOGI("Cannot add option to disable inline opt!"); - }else{ - if(strstr(value,kPropValueCompilerFlags) == NULL) + else { + if(strstr(value,kPropValueCompilerFlags) == NULL) { + if(strlen(value) + strlen(kPropValueCompilerFlagsWS) > PROP_VALUE_MAX) { + //just fallback,why not + LOGI("Cannot add option to disable inline opt!Fall back to replace.."); + strcpy(value, kPropValueCompilerFlags); + }else { strcat(value,kPropValueCompilerFlagsWS); + } } - } if(strstr(value,kPropValueCompilerFlags) != NULL) LOGI("system_property_get: %s -> %s", key, value); } @@ -79,17 +85,22 @@ namespace edxp { LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); } */ + if(strcmp(kPropKeyCompilerFlags, key.c_str()) == 0) { - if(strcmp(res.c_str(),"") == 0) { + if(strcmp(res.c_str(),"") == 0) res = kPropValueCompilerFlags; - }else{ - if(strlen(res.c_str()) + strlen(kPropValueCompilerFlagsWS) > 91) { - LOGI("Cannot add option to disable inline opt!"); - }else{ - if(strstr(res.c_str(),kPropValueCompilerFlags) == NULL) + else{ + if(strstr(res.c_str(),kPropValueCompilerFlags) == NULL) { + if(strlen(res.c_str()) + strlen(kPropValueCompilerFlagsWS) > PROP_VALUE_MAX) { + //just fallback,why not + LOGI("Cannot add option to disable inline opt!Fall back to replace.."); + res = kPropValueCompilerFlags; + }else { res.append(kPropValueCompilerFlagsWS); + } } } + if(strstr(res.c_str(),kPropValueCompilerFlags) != NULL) LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); } From e99dd63d7dcb49124100955b9c50035ca2cd146b Mon Sep 17 00:00:00 2001 From: EBK21 Date: Thu, 18 Jun 2020 19:08:43 +0800 Subject: [PATCH 3/6] Use SDK provided constant --- edxp-core/src/main/cpp/main/src/riru_hook.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edxp-core/src/main/cpp/main/src/riru_hook.cpp b/edxp-core/src/main/cpp/main/src/riru_hook.cpp index d457df06f..8dbe20d5a 100644 --- a/edxp-core/src/main/cpp/main/src/riru_hook.cpp +++ b/edxp-core/src/main/cpp/main/src/riru_hook.cpp @@ -17,7 +17,7 @@ namespace edxp { //Max length of property values //Ref https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/os/SystemProperties.java - static const int PROP_VALUE_MAX = 91; + //static const int PROP_VALUE_MAX = 91; NEW_FUNC_DEF(int, __system_property_get, const char *key, char *value) { int res = old___system_property_get(key, value); From 9203b6bf22232f114c4379068c0bdfd76618e668 Mon Sep 17 00:00:00 2001 From: EBK21 Date: Thu, 18 Jun 2020 19:25:59 +0800 Subject: [PATCH 4/6] fix.. --- edxp-core/src/main/cpp/main/src/riru_hook.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/edxp-core/src/main/cpp/main/src/riru_hook.cpp b/edxp-core/src/main/cpp/main/src/riru_hook.cpp index 8dbe20d5a..a08e9ec5f 100644 --- a/edxp-core/src/main/cpp/main/src/riru_hook.cpp +++ b/edxp-core/src/main/cpp/main/src/riru_hook.cpp @@ -69,6 +69,7 @@ namespace edxp { } } return res; + } } NEW_FUNC_DEF(std::string, From 6287b7821573bcec65f9678cd7953fc226a6b81a Mon Sep 17 00:00:00 2001 From: EBK21 Date: Thu, 18 Jun 2020 19:35:52 +0800 Subject: [PATCH 5/6] truly fix --- edxp-core/src/main/cpp/main/src/riru_hook.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/edxp-core/src/main/cpp/main/src/riru_hook.cpp b/edxp-core/src/main/cpp/main/src/riru_hook.cpp index a08e9ec5f..88e584b87 100644 --- a/edxp-core/src/main/cpp/main/src/riru_hook.cpp +++ b/edxp-core/src/main/cpp/main/src/riru_hook.cpp @@ -69,7 +69,6 @@ namespace edxp { } } return res; - } } NEW_FUNC_DEF(std::string, @@ -100,11 +99,10 @@ namespace edxp { res.append(kPropValueCompilerFlagsWS); } } + if(strstr(res.c_str(),kPropValueCompilerFlags) != NULL) + LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); } - if(strstr(res.c_str(),kPropValueCompilerFlags) != NULL) - LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); - } if (api_level == ANDROID_O_MR1) { // see __system_property_get hook above for explanations From a861f27928a2ad86d4ffb55f10579150ff242f71 Mon Sep 17 00:00:00 2001 From: EBK21 Date: Thu, 18 Jun 2020 19:44:09 +0800 Subject: [PATCH 6/6] finally fix the problem emmmmm --- edxp-core/src/main/cpp/main/src/riru_hook.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/edxp-core/src/main/cpp/main/src/riru_hook.cpp b/edxp-core/src/main/cpp/main/src/riru_hook.cpp index 88e584b87..440e48e2b 100644 --- a/edxp-core/src/main/cpp/main/src/riru_hook.cpp +++ b/edxp-core/src/main/cpp/main/src/riru_hook.cpp @@ -1,4 +1,4 @@ -// +/ // Created by solo on 2019/3/16. // @@ -49,6 +49,7 @@ namespace edxp { if(strstr(value,kPropValueCompilerFlags) != NULL) LOGI("system_property_get: %s -> %s", key, value); } + } @@ -102,6 +103,7 @@ namespace edxp { if(strstr(res.c_str(),kPropValueCompilerFlags) != NULL) LOGI("android::base::GetProperty: %s -> %s", key.c_str(), res.c_str()); } + } if (api_level == ANDROID_O_MR1) {