From 4c3f55014a95d9c6d1659a4a1f9eb379fea8f572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=90=E4=B8=89?= <89683694+Tangsan99999@users.noreply.github.com> Date: Tue, 11 Oct 2022 15:51:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=82=E8=80=83=E4=BD=BF=E7=94=A8=20https://?= =?UTF-8?q?catvodtvofficial.github.io/CatVodTVJsonEditor/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/github/tvbox/osc/api/ApiConfig.java | 51 +++++++++++-- .../java/com/github/tvbox/osc/util/AES.java | 75 +++++++++++++++++++ 2 files changed, 119 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/com/github/tvbox/osc/util/AES.java diff --git a/app/src/main/java/com/github/tvbox/osc/api/ApiConfig.java b/app/src/main/java/com/github/tvbox/osc/api/ApiConfig.java index dd063a8b..c691f427 100644 --- a/app/src/main/java/com/github/tvbox/osc/api/ApiConfig.java +++ b/app/src/main/java/com/github/tvbox/osc/api/ApiConfig.java @@ -14,6 +14,7 @@ import com.github.tvbox.osc.bean.LiveChannelItem; import com.github.tvbox.osc.bean.ParseBean; import com.github.tvbox.osc.bean.SourceBean; import com.github.tvbox.osc.server.ControlManager; +import com.github.tvbox.osc.util.AES; import com.github.tvbox.osc.util.AdBlocker; import com.github.tvbox.osc.util.DefaultConfig; import com.github.tvbox.osc.util.HawkConfig; @@ -83,6 +84,32 @@ public class ApiConfig { return instance; } + public static String FindResult(String json, String configKey) { + try { + String content = ""; + if (AES.isJson(json)) { + return json; + } else if (!json.startsWith("2423")) { + String[] data = json.split("\\*\\*"); + content = new String(Base64.decode(data[1], Base64.DEFAULT)); + } else { + content = json; + } + if (content.startsWith("2423")) { + String data = content.substring(content.indexOf("2324") + 4, content.length() - 26); + content = new String(AES.toBytes(content)).toLowerCase(); + String key = AES.rightPadding(content.substring(content.indexOf("$#") + 2, content.indexOf("#$")), "0", 16); + String iv = AES.rightPadding(content.substring(content.length() - 13), "0", 16); + json = AES.CBC(data, key, iv); + } else { + json = AES.ECB(content, configKey); + } + } catch (Exception e) { + e.printStackTrace(); + } + return json; + } + public void loadConfig(boolean useCache, LoadConfigCallback callback, Activity activity) { String apiUrl = Hawk.get(HawkConfig.API_URL, ""); if (apiUrl.isEmpty()) { @@ -99,13 +126,22 @@ public class ApiConfig { th.printStackTrace(); } } - String apiFix = apiUrl; - if (apiUrl.startsWith("clan://")) { - apiFix = clanToAddress(apiUrl); - }else if(!apiUrl.startsWith("http")){ - apiFix = "http://" + apiFix; + String TempKey = null, configUrl = "", pk = ";pk;"; + if (apiUrl.contains(pk)) { + String[] a = apiUrl.split(pk); + TempKey = a[1]; + if (apiUrl.startsWith("clan")) configUrl = clanToAddress(a[0]); + if (apiUrl.startsWith("http")) configUrl = a[0]; + } else if (!apiUrl.contains(pk)){ + if (apiUrl.startsWith("clan")) configUrl = clanToAddress(apiUrl); + if (!apiUrl.startsWith("http")) { + configUrl = "http://" + configUrl; + } else { + configUrl = apiUrl; + } } - OkGo.get(apiFix) + String configKey = TempKey; + OkGo.get(configUrl) .headers("User-Agent", userAgent) .headers("Accept", requestAccept) .execute(new AbsCallback() { @@ -113,7 +149,8 @@ public class ApiConfig { public void onSuccess(Response response) { try { String json = response.body(); - parseJson(apiUrl, response.body()); + json = FindResult(json, configKey); + parseJson(apiUrl, json); try { File cacheDir = cache.getParentFile(); if (!cacheDir.exists()) diff --git a/app/src/main/java/com/github/tvbox/osc/util/AES.java b/app/src/main/java/com/github/tvbox/osc/util/AES.java new file mode 100644 index 00000000..d67f14cf --- /dev/null +++ b/app/src/main/java/com/github/tvbox/osc/util/AES.java @@ -0,0 +1,75 @@ +package com.github.tvbox.osc.util; + +import org.json.JSONObject; + +import java.security.spec.AlgorithmParameterSpec; + +import javax.crypto.Cipher; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; + +public class AES { + + public static String rightPadding(String key, String replace, int Length) { + String strReturn = ""; + String strtemp = ""; + int curLength = key .trim().length(); + if (key != null && curLength > Length) { + strReturn = key .trim().substring(0, Length); + } else if (key != null && curLength == Length) { + strReturn = key .trim(); + } else { + for (int i = 0; i < (Length - curLength); i++) { + strtemp = strtemp + replace; + } + strReturn = key .trim() + strtemp; + } + return strReturn; + } + + public static String ECB(String data, String key) { + try { + key = rightPadding(key, "0", 16); + byte[] data2 = toBytes(data); + SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES"); + Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding"); + cipher.init(Cipher.DECRYPT_MODE, keySpec); + return new String(cipher.doFinal(data2)); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public static String CBC(String data, String key, String iv) { + try { + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding"); + SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES"); + AlgorithmParameterSpec paramSpec = new IvParameterSpec(iv.getBytes()); + cipher.init(Cipher.DECRYPT_MODE, keySpec, paramSpec); + return new String(cipher.doFinal(toBytes(data))); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public static boolean isJson(String content) { + try { + new JSONObject(content); + return true; + } catch (Exception e) { + return false; + } + } + + public static byte[] toBytes(String src) { + int l = src.length() / 2; + byte[] ret = new byte[l]; + for (int i = 0; i < l; i++) { + ret[i] = Integer.valueOf(src.substring(i * 2, i * 2 + 2), 16).byteValue(); + } + return ret; + } + +} \ No newline at end of file