EhViewer v1.9.7.7版本的 MD5 值为:828893cd54837a794dab17a02809e194

以下内容为反编译后的 EhDns.java 源代码,内容仅作参考


package com.hippo.ehviewer.client;

import android.content.Context;
import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.Hosts;
import com.hippo.ehviewer.Settings;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import okhttp3.Dns;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.dnsoverhttps.DnsOverHttps;
public class EhDns implements Dns {
    private static final Map<String, List<InetAddress>> builtInHosts;
    private static DnsOverHttps dnsOverHttps;
    private final Hosts hosts;

    static {
        HashMap hashMap = new HashMap();
        if (Settings.getBuiltInHosts()) {
            put(hashMap, EhUrl.DOMAIN_E, "104.20.135.21", "104.20.134.21", "172.67.0.127");
            put(hashMap, "repo.e-hentai.org", "94.100.28.57", "94.100.29.73");
            put(hashMap, "forums.e-hentai.org", "94.100.18.243");
            put(hashMap, "ehgt.org", "37.48.89.44", "81.171.10.48", "178.162.139.24", "178.162.140.212", "2001:1af8:4700:a062:8::47de", "2001:1af8:4700:a062:9::47de", "2001:1af8:4700:a0c9:4::47de", "2001:1af8:4700:a0c9:3::47de");
            put(hashMap, "gt0.ehgt.org", "37.48.89.44", "81.171.10.48", "178.162.139.24", "178.162.140.212", "2001:1af8:4700:a062:8::47de", "2001:1af8:4700:a062:9::47de", "2001:1af8:4700:a0c9:4::47de", "2001:1af8:4700:a0c9:3::47de");
            put(hashMap, "gt1.ehgt.org", "37.48.89.44", "81.171.10.48", "178.162.139.24", "178.162.140.212", "2001:1af8:4700:a062:8::47de", "2001:1af8:4700:a062:9::47de", "2001:1af8:4700:a0c9:4::47de", "2001:1af8:4700:a0c9:3::47de");
            put(hashMap, "gt2.ehgt.org", "37.48.89.44", "81.171.10.48", "178.162.139.24", "178.162.140.212", "2001:1af8:4700:a062:8::47de", "2001:1af8:4700:a062:9::47de", "2001:1af8:4700:a0c9:4::47de", "2001:1af8:4700:a0c9:3::47de");
            put(hashMap, "gt3.ehgt.org", "37.48.89.44", "81.171.10.48", "178.162.139.24", "178.162.140.212", "2001:1af8:4700:a062:8::47de", "2001:1af8:4700:a062:9::47de", "2001:1af8:4700:a0c9:4::47de", "2001:1af8:4700:a0c9:3::47de");
            put(hashMap, "ul.ehgt.org", "94.100.24.82", "94.100.24.72");
            put(hashMap, "raw.githubusercontent.com", "151.101.0.133", "151.101.64.133", "151.101.128.133", "151.101.192.133");
        }
        if (Settings.getBuiltEXHosts()) {
            put(hashMap, EhUrl.DOMAIN_EX, "178.175.128.252", "178.175.129.252", "178.175.129.254", "178.175.128.254", "178.175.132.20", "178.175.132.22", "172.64.206.24", "172.64.207.24");
            put(hashMap, "s.exhentai.org", "178.175.132.22", "178.175.128.254", "178.175.129.254");
        }
        builtInHosts = hashMap;
    }

    public EhDns(Context context) {
        this.hosts = EhApplication.getHosts(context);
        dnsOverHttps = new DnsOverHttps.Builder().client(new OkHttpClient.Builder().cache(EhApplication.getOkHttpCache(context)).build()).url(HttpUrl.get("https://77.88.8.1/dns-query")).post(true).build();
    }

    private static void put(Map<String, List<InetAddress>> map, String str, String... strArr) {
        ArrayList arrayList = new ArrayList();
        for (String str2 : strArr) {
            arrayList.add(Hosts.toInetAddress(str, str2));
        }
        map.put(str, arrayList);
    }

    @Override
    public List<InetAddress> lookup(String str) throws UnknownHostException {
        List<InetAddress> list;
        List<InetAddress> lookup;
        List<InetAddress> list2 = (List) this.hosts.get(str);
        if (list2 != null) {
            return list2;
        }
        if ((Settings.getBuiltInHosts() || Settings.getBuiltEXHosts()) && (list = builtInHosts.get(str)) != null) {
            return list;
        }
        if (!Settings.getDoH() || (lookup = dnsOverHttps.lookup(str)) == null || lookup.size() <= 0) {
            try {
                return Arrays.asList(InetAddress.getAllByName(str));
            } catch (NullPointerException e) {
                UnknownHostException unknownHostException = new UnknownHostException("Broken system behaviour for dns lookup of " + str);
                unknownHostException.initCause(e);
                throw unknownHostException;
            }
        }
        return lookup;
    }
}