From e3b6bd821909a5ce6be553c228136315eaf7e242 Mon Sep 17 00:00:00 2001 From: Vologhat <47892605+Vologhat@users.noreply.github.com> Date: Thu, 30 Jun 2022 13:00:48 +0300 Subject: [PATCH] fixed fox1d code --- .../vtosters/lite/f0x1d/VTVerifications.java | 161 +++++++++--------- .../ru/vtosters/lite/utils/Base64Utils.java | 17 ++ .../ru/vtosters/lite/utils/JsonInjectors.java | 14 +- .../ru/vtosters/lite/utils/Preferences.java | 4 +- .../vtosters/lite/utils/SignatureChecker.java | 3 +- 5 files changed, 107 insertions(+), 92 deletions(-) create mode 100644 app/src/main/java/ru/vtosters/lite/utils/Base64Utils.java diff --git a/app/src/main/java/ru/vtosters/lite/f0x1d/VTVerifications.java b/app/src/main/java/ru/vtosters/lite/f0x1d/VTVerifications.java index f0ddcd583..8e10bcf79 100644 --- a/app/src/main/java/ru/vtosters/lite/f0x1d/VTVerifications.java +++ b/app/src/main/java/ru/vtosters/lite/f0x1d/VTVerifications.java @@ -4,20 +4,18 @@ import static ru.vtosters.lite.utils.Preferences.getBoolValue; import android.content.Context; import android.content.SharedPreferences; -import android.util.Base64; import android.util.Log; -import android.widget.Toast; import com.vk.dto.common.VerifyInfo; import com.vk.navigation.NavigatorKeys; import org.json.JSONArray; +import org.json.JSONException; import org.json.JSONObject; import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.Map; +import java.util.ArrayList; +import java.util.List; import okhttp3.Call; import okhttp3.Callback; @@ -26,145 +24,140 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; +import ru.vtosters.lite.utils.Globals; -public class VTVerifications{ - public static final HashMap sServiceAccountsMap = new HashMap<>(); - private static final String TAG = "VTVerifications"; - private static final String DEVELOPERS_KEY = "VTNRS3"; - private static final String PROMETHEUS_KEY = "VTNRS1"; - private static final String SERVICE_ACCOUNTS_KEY = "VTNRS4"; - private static final String VERIFICATIONS_KEY = "VTNRS0"; - private static final HashMap sDevelopersMap = new HashMap<>(); - private static final HashMap sPrometheusMap = new HashMap<>(); - private static final HashMap sVerificationsMap = new HashMap<>(); - private static final OkHttpClient client = new OkHttpClient(); - private static SharedPreferences mVerificationsCache; +public class VTVerifications { + private static List sVerifications = new ArrayList<>(); + private static List sPrometheuses = new ArrayList<>(); + private static List sDevelopers = new ArrayList<>(); + private static List sServiceAccounts = new ArrayList<>(); + + private static final OkHttpClient sClient = new OkHttpClient(); + + private static SharedPreferences sVerificationsPrefs; public static void load(Context context){ - mVerificationsCache = context.getSharedPreferences("vt_another_data", 0); + sVerificationsPrefs = context.getSharedPreferences("vt_another_data", 0); - try { - processArray(new JSONArray(getLoaded(VERIFICATIONS_KEY)), sVerificationsMap, null); - processArray(new JSONArray(getLoaded(PROMETHEUS_KEY)), sPrometheusMap, null); - processArray(new JSONArray(getLoaded(DEVELOPERS_KEY)), sDevelopersMap, null); - processArray(new JSONArray(getLoaded(SERVICE_ACCOUNTS_KEY)), sServiceAccountsMap, null); - } catch (Exception e) { - e.printStackTrace(); - Toast.makeText(context, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show(); + if (!Globals.isNetworkConnected() && sVerificationsPrefs.contains("ids")) { + parseJson(sVerificationsPrefs.getString("ids", "[]")); + return; } - Request request = new Request.a() + var request = new Request.a() .b("https://vtosters.app/vktoaster/getGalo4kiBatch") .a(RequestBody.a(MediaType.b("application/json; charset=UTF-8"), "{\"types\":[0,228,404,1337]}")) .a(); - client.a(request).a(new Callback(){ - @Override - public void a(Call call, IOException e){ - Log.d(TAG, "" + e); - } + sClient.a(request).a(new Callback(){ @Override public void a(Call call, Response response){ try { - getVerifications(response.a().g()); + var payload = response.a().g(); + parseJson(payload); + sVerificationsPrefs.edit().putString("ids", payload).apply(); } catch (Exception e) { e.printStackTrace(); } } + + @Override + public void a(Call call, IOException e) { + Log.d("VTVerifications", "" + e); + } + }); } - private static void getVerifications(String body) throws Exception{ - JSONObject jSONObject = new JSONObject(body); - processArray(jSONObject.optJSONArray("0"), sVerificationsMap, VERIFICATIONS_KEY); - processArray(jSONObject.optJSONArray("228"), sPrometheusMap, PROMETHEUS_KEY); - processArray(jSONObject.optJSONArray("404"), sDevelopersMap, DEVELOPERS_KEY); - processArray(jSONObject.optJSONArray("1337"), sServiceAccountsMap, SERVICE_ACCOUNTS_KEY); + /** + * 0 - Verifications + * 228 - Prometheus + * 404 - Developer + * 1337 - Service account*/ + private static void parseJson(String payload) { + try { + var json = new JSONObject(payload); + + processIds(json.optJSONArray("0"), sVerifications); + processIds(json.optJSONArray("228"), sPrometheuses); + processIds(json.optJSONArray("404"), sDevelopers); + processIds(json.optJSONArray("1337"), sServiceAccounts); + } catch (JSONException e) { + e.printStackTrace(); + } } - private static void processArray(JSONArray jSONArray, Map map, String str){ - if(jSONArray != null){ - for(int i = 0; i < jSONArray.length(); i++) { - map.put(jSONArray.optInt(i), true); - } - if(str != null){ - setLoaded(str, jSONArray.toString()); - } - } + private static void processIds(JSONArray jsonIds, List member) { + if (jsonIds == null || jsonIds.length() == 0) + return; + + for (int i = 0; i < jsonIds.length(); i++) + member.add(jsonIds.optInt(i)); } public static boolean isVerified(int i){ - return sVerificationsMap.get(i) != null ? sVerificationsMap.get(i) : false; + return sVerifications.contains(i); } - public static boolean hasPrometheus(int i){ - return sPrometheusMap.get(i) != null ? sPrometheusMap.get(i) : false; + public static boolean isPrometheus(int i){ + return sPrometheuses.contains(i); } public static boolean isDeveloper(int i){ - return sDevelopersMap.get(i) != null ? sDevelopersMap.get(i) : false; + return sDevelopers.contains(i); } public static boolean isServiceAccount(int i){ - return sServiceAccountsMap.get(i) != null ? sServiceAccountsMap.get(i) : false; - + return sServiceAccounts.contains(i); } - private static String getLoaded(String str){ - return decode(mVerificationsCache.getString(str, encode("[]"))); - } - - public static void setLoaded(String str, String str2){ - mVerificationsCache.edit().putString(str, encode(str2)).apply(); - } - - public static String decode(String str){ - return new String(Base64.decode(str, 1), StandardCharsets.UTF_8); - } - - public static String encode(String str){ - return Base64.encodeToString(str.getBytes(), 1); - } - - - public static boolean vtverif(){ + public static boolean vtverif() { return getBoolValue("VT_Verification", true); } - public static boolean isVerified(JSONObject jSONObject){ - if(jSONObject.optInt("verified", 0) == 1){ + private static int getId(JSONObject json) { + var id = json.optInt("id", 0); + if (!json.optString(NavigatorKeys.e).equals("group") && !json.optString(NavigatorKeys.e).equals("page") + || json.optString(NavigatorKeys.e) == null) + return id; + else + return -id; + } + + public static boolean isVerified(JSONObject jSONObject) { + if (jSONObject.optInt("verified", 0) == 1) { return true; } - if(!getBoolValue("VT_Verification", true)){ + if (!getBoolValue("VT_Verification", true)) { return false; } - return isVerified((jSONObject.optString(NavigatorKeys.e) == null || (!jSONObject.optString(NavigatorKeys.e).equals("group") && !jSONObject.optString(NavigatorKeys.e).equals("page"))) ? jSONObject.optInt("id", 0) : -jSONObject.optInt("id", 0)); + return isVerified(getId(jSONObject)); } - public static boolean hasPrometheus(JSONObject jSONObject){ - if(jSONObject.optInt("trending", 0) == 1){ + public static boolean hasPrometheus(JSONObject jSONObject) { + if (jSONObject.optInt("trending", 0) == 1) { return true; } - if(!getBoolValue("VT_Fire", true)){ + if (!getBoolValue("VT_Fire", true)) { return false; } - return hasPrometheus((jSONObject.optString(NavigatorKeys.e) == null || (!jSONObject.optString(NavigatorKeys.e).equals("group") && !jSONObject.optString(NavigatorKeys.e).equals("page"))) ? jSONObject.optInt("id", 0) : -jSONObject.optInt("id", 0)); + return isPrometheus(getId(jSONObject)); } - public static boolean hasDeveloper(JSONObject jSONObject){ - if(!getBoolValue("VT_Dev", true)){ + public static boolean hasDeveloper(JSONObject jSONObject) { + if (!getBoolValue("VT_Dev", true)) { return false; } - return isDeveloper((jSONObject.optString(NavigatorKeys.e) == null || (!jSONObject.optString(NavigatorKeys.e).equals("group") && !jSONObject.optString(NavigatorKeys.e).equals("page"))) ? jSONObject.optInt("id", 0) : -jSONObject.optInt("id", 0)); + return isDeveloper(getId(jSONObject)); } - public static VerifyInfo VerifyInfo(JSONObject jSONObject){ + public static VerifyInfo VerifyInfo(JSONObject jSONObject) { return new VerifyInfo(isVerified(jSONObject), hasPrometheus(jSONObject)); } } diff --git a/app/src/main/java/ru/vtosters/lite/utils/Base64Utils.java b/app/src/main/java/ru/vtosters/lite/utils/Base64Utils.java new file mode 100644 index 000000000..4f3e1c039 --- /dev/null +++ b/app/src/main/java/ru/vtosters/lite/utils/Base64Utils.java @@ -0,0 +1,17 @@ +package ru.vtosters.lite.utils; + +import android.util.Base64; + +/* + *Extension of Base64 class for decoding/encoding with flag NO_PADDING + */ +public class Base64Utils { + + public static String decode(String base) { + return new String(Base64.decode(base, Base64.NO_PADDING)); + } + + public static String encode(String base) { + return Base64.encodeToString(base.getBytes(), Base64.NO_PADDING); + } +} diff --git a/app/src/main/java/ru/vtosters/lite/utils/JsonInjectors.java b/app/src/main/java/ru/vtosters/lite/utils/JsonInjectors.java index e80e8a7bb..cbf772f8e 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/JsonInjectors.java +++ b/app/src/main/java/ru/vtosters/lite/utils/JsonInjectors.java @@ -1,7 +1,6 @@ package ru.vtosters.lite.utils; -import static ru.vtosters.lite.f0x1d.VTVerifications.decode; -import static ru.vtosters.lite.f0x1d.VTVerifications.hasPrometheus; +import static ru.vtosters.lite.f0x1d.VTVerifications.isPrometheus; import static ru.vtosters.lite.f0x1d.VTVerifications.isDeveloper; import static ru.vtosters.lite.f0x1d.VTVerifications.isVerified; import static ru.vtosters.lite.utils.Preferences.hasVerification; @@ -22,7 +21,14 @@ public class JsonInjectors{ var text_color = "2D81E0"; // JSONObject jsonObj = new JSONObject("{\"action\":{\"target\":\"internal\",\"type\":\"open_url\",\"url\":\"" + link + "\"},\"title\":\"" + title + "\",\"icons\":[{\"url\":\"" + pic + "\",\"width\":20,\"height\":20},{\"url\":\"" + pic + "\",\"width\":40,\"height\":40},{\"url\":\"" + pic + "\",\"width\":60,\"height\":60},{\"url\":\"" + pic + "\",\"width\":80,\"height\":80}],\"text_color\":\"" + text_color + "\"}"); - return new JSONObject(decode("eyJhY3Rpb24iOnsidGFyZ2V0IjoiaW50ZXJuYWwiLCJ0eXBlIjoib3Blbl91cmwiLCJ1cmwiOiI=") + link + decode("In0sInRpdGxlIjoi") + title + decode("IiwiaWNvbnMiOlt7InVybCI6Ig==") + pic + decode("Iiwid2lkdGgiOjIwLCJoZWlnaHQiOjIwfSx7InVybCI6Ig==") + pic + decode("Iiwid2lkdGgiOjQwLCJoZWlnaHQiOjQwfSx7InVybCI6Ig==") + pic + decode("Iiwid2lkdGgiOjYwLCJoZWlnaHQiOjYwfSx7InVybCI6Ig==") + pic + decode("Iiwid2lkdGgiOjgwLCJoZWlnaHQiOjgwfV0sInRleHRfY29sb3IiOiI=") + text_color + decode("In0=")); + return new JSONObject(Base64Utils.decode("eyJhY3Rpb24iOnsidGFyZ2V0IjoiaW50ZXJuYWwiLCJ0eXBlIjoib3Blbl91cmwiLCJ1cmwiOiI=") + + link + Base64Utils.decode("In0sInRpdGxlIjoi") + + title + Base64Utils.decode("IiwiaWNvbnMiOlt7InVybCI6Ig==") + + pic + Base64Utils.decode("Iiwid2lkdGgiOjIwLCJoZWlnaHQiOjIwfSx7InVybCI6Ig==") + + pic + Base64Utils.decode("Iiwid2lkdGgiOjQwLCJoZWlnaHQiOjQwfSx7InVybCI6Ig==") + + pic + Base64Utils.decode("Iiwid2lkdGgiOjYwLCJoZWlnaHQiOjYwfSx7InVybCI6Ig==") + + pic + Base64Utils.decode("Iiwid2lkdGgiOjgwLCJoZWlnaHQiOjgwfV0sInRleHRfY29sb3IiOiI=") + + text_color + Base64Utils.decode("In0=")); } public static JSONObject convBar(JSONObject orig) throws JSONException{ @@ -34,7 +40,7 @@ public class JsonInjectors{ if(isVerified(peerid)) textverif = "Я купил VTosters Premium"; - if(hasPrometheus(peerid)) textverif = "Я купил VTosters Premium Gold Prime Pro Plus"; + if(isPrometheus(peerid)) textverif = "Я купил VTosters Premium Gold Prime Pro Plus"; if(isDeveloper(peerid)) textverif = "Я создал говно"; diff --git a/app/src/main/java/ru/vtosters/lite/utils/Preferences.java b/app/src/main/java/ru/vtosters/lite/utils/Preferences.java index 90a5f3c0f..d4ffaac34 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/Preferences.java +++ b/app/src/main/java/ru/vtosters/lite/utils/Preferences.java @@ -1,7 +1,7 @@ package ru.vtosters.lite.utils; import static java.lang.Long.MAX_VALUE; -import static ru.vtosters.lite.f0x1d.VTVerifications.hasPrometheus; +import static ru.vtosters.lite.f0x1d.VTVerifications.isPrometheus; import static ru.vtosters.lite.f0x1d.VTVerifications.isVerified; import static ru.vtosters.lite.utils.CacheUtils.getInstance; import static ru.vtosters.lite.utils.Globals.edit; @@ -370,7 +370,7 @@ public class Preferences{ } public static boolean hasSpecialVerif(){ - return hasPrometheus(getUserId()); + return isPrometheus(getUserId()); } public static String getLocale(){ diff --git a/app/src/main/java/ru/vtosters/lite/utils/SignatureChecker.java b/app/src/main/java/ru/vtosters/lite/utils/SignatureChecker.java index a4857e7fa..e613798c9 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/SignatureChecker.java +++ b/app/src/main/java/ru/vtosters/lite/utils/SignatureChecker.java @@ -2,7 +2,6 @@ package ru.vtosters.lite.utils; import static android.content.pm.PackageManager.GET_SIGNATURES; import static android.content.pm.PackageManager.NameNotFoundException; -import static ru.vtosters.lite.f0x1d.VTVerifications.decode; import static ru.vtosters.lite.utils.Globals.getContext; import static ru.vtosters.lite.utils.Globals.getPackageName; @@ -40,7 +39,7 @@ public class SignatureChecker{ @SuppressLint("PackageManagerGetSignatures") PackageInfo packageInfo = getContext().getPackageManager().getPackageInfo(getPackageName(), GET_SIGNATURES); for(Signature signature : packageInfo.signatures) { String sha1 = getSHA1(signature.toByteArray()); - return decode(APP_SIGNATURE).equals(sha1); + return Base64Utils.decode(APP_SIGNATURE).equals(sha1); } return false; } // Sig check to detect actions builds and etc