Add decoder
This commit is contained in:
parent
37660049d7
commit
7c9d8f1e7b
|
|
@ -9,5 +9,6 @@ java {
|
|||
|
||||
dependencies {
|
||||
implementation 'com.squareup.okhttp3:okhttp:3.12.13'
|
||||
implementation 'com.google.guava:guava:32.0.0-jre'
|
||||
implementation 'com.google.code.gson:gson:2.8.6'
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
package com.fongmi.tools;
|
||||
|
||||
import com.google.common.io.BaseEncoding;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
public class Config {
|
||||
|
||||
private final Gson gson;
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
Config config = new Config();
|
||||
String json = config.getJson("http://饭太硬.top/tv");
|
||||
System.out.println(config.gson.toJson(JsonParser.parseString(json)));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Config() {
|
||||
gson = new Gson().newBuilder().disableHtmlEscaping().setPrettyPrinting().create();
|
||||
}
|
||||
|
||||
private String getJson(String url) throws Exception {
|
||||
String key = url.contains(";") ? url.split(";")[2] : "";
|
||||
url = url.contains(";") ? url.split(";")[0] : url;
|
||||
String data = getData(url);
|
||||
if (Utils.isJson(data)) return data;
|
||||
if (data.isEmpty()) throw new Exception();
|
||||
if (data.contains("**")) data = base64(data);
|
||||
if (data.startsWith("2423")) data = cbc(data);
|
||||
if (key.length() > 0) data = ecb(data, key);
|
||||
return data;
|
||||
}
|
||||
|
||||
private String getData(String url) throws Exception {
|
||||
if (url.startsWith("http")) return Utils.call(url);
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
private String ecb(String data, String key) throws Exception {
|
||||
SecretKeySpec spec = new SecretKeySpec(padEnd(key), "AES");
|
||||
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
||||
cipher.init(Cipher.DECRYPT_MODE, spec);
|
||||
return new String(cipher.doFinal(decodeHex(data)), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private String cbc(String data) throws Exception {
|
||||
int indexKey = data.indexOf("2324") + 4;
|
||||
String key = new String(decodeHex(data.substring(0, indexKey)), StandardCharsets.UTF_8);
|
||||
key = key.replace("$#", "").replace("#$", "");
|
||||
int indexIv = data.length() - 26;
|
||||
String iv = data.substring(indexIv).trim();
|
||||
iv = new String(decodeHex(iv), StandardCharsets.UTF_8);
|
||||
SecretKeySpec keySpec = new SecretKeySpec(padEnd(key), "AES");
|
||||
IvParameterSpec ivSpec = new IvParameterSpec(padEnd(iv));
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
|
||||
data = data.substring(indexKey, indexIv).trim();
|
||||
byte[] encryptDataBytes = decodeHex(data);
|
||||
byte[] decryptData = cipher.doFinal(encryptDataBytes);
|
||||
return new String(decryptData, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private String base64(String data) {
|
||||
String extract = extract(data);
|
||||
if (extract.isEmpty()) return data;
|
||||
return new String(Base64.getDecoder().decode(extract));
|
||||
}
|
||||
|
||||
private String extract(String data) {
|
||||
Matcher matcher = Pattern.compile("[A-Za-z0-9]{8}\\*\\*").matcher(data);
|
||||
return matcher.find() ? data.substring(data.indexOf(matcher.group()) + 10) : "";
|
||||
}
|
||||
|
||||
private byte[] padEnd(String key) {
|
||||
return (key + "0000000000000000".substring(key.length())).getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private byte[] decodeHex(String s) {
|
||||
return BaseEncoding.base16().decode(s.toUpperCase());
|
||||
}
|
||||
}
|
||||
|
|
@ -13,25 +13,25 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class Run {
|
||||
public class Live {
|
||||
|
||||
private final List<Group> groups;
|
||||
private final List<Data> data;
|
||||
private final Gson gson;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
new Run().start("http://home.jundie.top:81/Cat/tv/live.txt");
|
||||
new Live().start("http://home.jundie.top:81/Cat/tv/live.txt");
|
||||
}
|
||||
|
||||
public Run() {
|
||||
public Live() {
|
||||
groups = new ArrayList<>();
|
||||
data = Data.arrayFrom(Util.getFile(getClass(), "data.json"));
|
||||
data = Data.arrayFrom(Utils.getFile(getClass(), "data.json"));
|
||||
gson = new Gson().newBuilder().disableHtmlEscaping().setPrettyPrinting().create();
|
||||
}
|
||||
|
||||
private void start(String text) throws IOException {
|
||||
//parseTxt(Util.getFile(getClass(), "live.txt"));
|
||||
parse(Util.call(text));
|
||||
parse(Utils.call(text));
|
||||
writeFile();
|
||||
}
|
||||
|
||||
|
|
@ -44,7 +44,6 @@ public class Run {
|
|||
Group group = groups.get(groups.size() - 1);
|
||||
String name = split[0];
|
||||
String url = split[1].trim();
|
||||
if (url.startsWith("http://txtest")) url = url.replace("http://txtest", "http://121.51.249.6/txtest");
|
||||
group.find(Channel.create().name(name).epg(name)).addUrls(url.split("#"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
package com.fongmi.tools;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
|
@ -11,7 +14,16 @@ import java.util.stream.Stream;
|
|||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
|
||||
public class Util {
|
||||
public class Utils {
|
||||
|
||||
public static boolean isJson(String text) {
|
||||
try {
|
||||
JsonParser.parseString(text);
|
||||
return true;
|
||||
} catch (JsonSyntaxException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static String call(String url) throws IOException {
|
||||
return new OkHttpClient().newCall(new Request.Builder().url(url).build()).execute().body().string();
|
||||
Loading…
Reference in New Issue