diff options
-rw-r--r-- | gui/patternpassword.cpp | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/gui/patternpassword.cpp b/gui/patternpassword.cpp index 96054c15f..90566e219 100644 --- a/gui/patternpassword.cpp +++ b/gui/patternpassword.cpp @@ -15,7 +15,7 @@ extern "C" { #include "../twcommon.h" } #include "../minuitwrp/minui.h" - +#include "../twrp-functions.hpp" #include "rapidxml.hpp" #include "objects.hpp" @@ -403,6 +403,17 @@ int GUIPatternPassword::NotifyVarChange(const std::string& varName, const std::s return 0; } +static unsigned int getSDKVersion(void) { + unsigned int sdkver = 23; + string sdkverstr = TWFunc::System_Property_Get("ro.build.version.sdk"); + if (!sdkverstr.empty()) { + sdkver = (unsigned int)strtoull(sdkverstr.c_str(), NULL, 10); + sdkver = (sdkver != 0) ? sdkver : 23; + } + LOGINFO("sdk version is %u\n", sdkver); + return sdkver; +} + std::string GUIPatternPassword::GeneratePassphrase() { char pattern[mConnectedDotsLen]; @@ -411,12 +422,17 @@ std::string GUIPatternPassword::GeneratePassphrase() } std::stringstream pass; + char buffer[3] = {0}; - for(size_t i = 0; i < mConnectedDotsLen; i++) { - int digit = pattern[i] & 0xff; - + if ((mGridSize == 3) || (getSDKVersion() >= 23)) { + // Marshmallow uses a consistent method + for (size_t i = 0; i < mConnectedDotsLen; i++) { + buffer[0] = (pattern[i] & 0xff) + '1'; + pass << std::string(buffer); + } + } else { /* - * Okay, rant time. + * Okay, rant time for pre-Marshmallow ROMs. * It turns out that Android and CyanogenMod have *two* separate methods * for generating passphrases from patterns. This is a legacy issue, as * Android only supports 3x3 grids, and so we need to support both. @@ -431,14 +447,8 @@ std::string GUIPatternPassword::GeneratePassphrase() * they are generated by taking "%.2x" for each dot index and * concatenating the results (without adding 1). */ - - if(mGridSize == 3) - // Android (legacy) 3x3 grids. - pass << digit + 1; - else { - // Other NxN grids. - char buffer[3]; - snprintf(buffer, 3, "%.2x", digit); + for (size_t i = 0; i < mConnectedDotsLen; i++) { + snprintf(buffer, 3, "%.2x", pattern[i] & 0xff); pass << std::string(buffer); } } |