|
|
|
|
@ -4,12 +4,9 @@ import android.util.Base64; |
|
|
|
|
|
|
|
|
|
import com.fongmi.android.tv.utils.UrlUtil; |
|
|
|
|
import com.github.catvod.net.OkHttp; |
|
|
|
|
import com.github.catvod.utils.Asset; |
|
|
|
|
import com.github.catvod.utils.Json; |
|
|
|
|
import com.github.catvod.utils.Path; |
|
|
|
|
import com.github.catvod.utils.Util; |
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
|
import java.util.regex.Matcher; |
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
@ -18,19 +15,22 @@ import javax.crypto.Cipher; |
|
|
|
|
import javax.crypto.spec.IvParameterSpec; |
|
|
|
|
import javax.crypto.spec.SecretKeySpec; |
|
|
|
|
|
|
|
|
|
import okhttp3.Response; |
|
|
|
|
|
|
|
|
|
public class Decoder { |
|
|
|
|
|
|
|
|
|
private static final Pattern JS_URI = Pattern.compile("\"(\\.|\\.\\.)/(.?|.+?)\\.js\\?(.?|.+?)\""); |
|
|
|
|
|
|
|
|
|
public static String getJson(String url) throws Exception { |
|
|
|
|
String key = url.contains(";") ? url.split(";")[2] : ""; |
|
|
|
|
url = url.contains(";") ? url.split(";")[0] : url; |
|
|
|
|
String data = getData(url); |
|
|
|
|
Response res = OkHttp.newCall(UrlUtil.convert(url)).execute(); |
|
|
|
|
return verify(res.request().url().toString(), res.body().string()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static String verify(String url, String data) throws Exception { |
|
|
|
|
if (data.isEmpty()) throw new Exception(); |
|
|
|
|
if (Json.valid(data)) return fix(url, data); |
|
|
|
|
if (data.contains("**")) data = base64(data); |
|
|
|
|
if (data.startsWith("2423")) data = cbc(data); |
|
|
|
|
if (key.length() > 0) data = ecb(data, key); |
|
|
|
|
return fix(url, data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -52,38 +52,6 @@ public class Decoder { |
|
|
|
|
return data.replace(ext, t); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static String getExt(String ext) { |
|
|
|
|
try { |
|
|
|
|
return base64(getData(ext.substring(4))); |
|
|
|
|
} catch (Exception ignored) { |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static File getSpider(String url) { |
|
|
|
|
try { |
|
|
|
|
File file = Path.jar(url); |
|
|
|
|
String data = extract(getData(url.substring(4))); |
|
|
|
|
return data.isEmpty() ? file : Path.write(file, Base64.decode(data, Base64.DEFAULT)); |
|
|
|
|
} catch (Exception ignored) { |
|
|
|
|
return Path.jar(url); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static String getData(String url) { |
|
|
|
|
if (url.startsWith("file")) return Path.read(url); |
|
|
|
|
if (url.startsWith("assets")) return Asset.read(url); |
|
|
|
|
if (url.startsWith("http")) return OkHttp.string(url); |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static String ecb(String data, String key) throws Exception { |
|
|
|
|
SecretKeySpec spec = new SecretKeySpec(padEnd(key).getBytes(), "AES"); |
|
|
|
|
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); |
|
|
|
|
cipher.init(Cipher.DECRYPT_MODE, spec); |
|
|
|
|
return new String(cipher.doFinal(Util.hex2byte(data)), StandardCharsets.UTF_8); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static String cbc(String data) throws Exception { |
|
|
|
|
String decode = new String(Util.hex2byte(data)).toLowerCase(); |
|
|
|
|
String key = padEnd(decode.substring(decode.indexOf("$#") + 2, decode.indexOf("#$"))); |
|
|
|
|
|