QQ浏览器 v12.2.3.7053版本的 MD5 值为:8285ab3059e5c8b521a264dfbc5c3685

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


package com.tencent.mtt.browser.download.engine.dns;

import android.text.TextUtils;
import com.tencent.common.http.MttInputStream;
import com.tencent.common.http.MttRequestBase;
import com.tencent.common.http.MttResponse;
import com.tencent.common.http.Requester;
import com.tencent.common.http.RequesterFactory;
import com.tencent.common.utils.UrlUtils;
import com.tencent.mtt.browser.download.engine.network.IDownloadNetworkPolicy;
import com.tencent.mtt.browser.download.engine.utils.DLogger;
import java.io.ByteArrayOutputStream;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

class CFDnsRequest implements IDnsRequest {

    private static final String[] f37771a = {"https://1.0.0.1/dns-query?name=%s&type=A", "https://1.1.1.1/dns-query?name=%s&type=A"};

    private final String f37772b;

    private final IDownloadNetworkPolicy f37773c;

    private Requester f37774d;

    private DnsResult a(String str) {
        JSONArray optJSONArray;
        try {
            JSONObject jSONObject = new JSONObject(str);
            if (jSONObject.optInt("Status", -1) == 0 && (optJSONArray = jSONObject.optJSONArray("Answer")) != null && optJSONArray.length() >= 1) {
                int length = optJSONArray.length();
                for (int i = 0; i < length; i++) {
                    JSONObject jSONObject2 = optJSONArray.getJSONObject(i);
                    if (jSONObject2 != null && jSONObject2.optInt("type", -1) == 1) {
                        long optInt = jSONObject2.optInt("TTL", 0);
                        String optString = jSONObject2.optString("data");
                        if (optInt > 0 && UrlUtils.isIpUrl(optString)) {
                            return new DnsResult(true, optString, this.f37772b, this.f37773c.a(), optInt);
                        }
                    }
                }
            }
        } catch (JSONException unused) {
        }
        return null;
    }

    private DnsResult a(String str, String str2, Requester requester) {
        String format = String.format(str, str2);
        MttRequestBase mttRequestBase = RequesterFactory.getMttRequestBase();
        mttRequestBase.setConnectTimeout(3000);
        mttRequestBase.setReadTimeout(3000);
        mttRequestBase.addHeader("Cache-Control", "no-store");
        mttRequestBase.addHeader("Accept", "application/dns-json");
        mttRequestBase.setUrl(format);
        mttRequestBase.setHostVerifier(new HostnameVerifier() {
            @Override
            public boolean verify(String str3, SSLSession sSLSession) {
                return "1.1.1.1".equalsIgnoreCase(str3) || "1.0.0.1".equalsIgnoreCase(str3);
            }
        });
        DLogger.a("QB_DOWN::CFDnsREQ", "[DNS_RESOLVE] url=[" + format + "]");
        DnsResult dnsResult = null;
        try {
            MttResponse execute = requester.execute(mttRequestBase);
            if (execute != null) {
                Integer statusCode = execute.getStatusCode();
                DLogger.a("QB_DOWN::CFDnsREQ", "[RESOLVE_SC] statusCode=[" + statusCode + "]");
                if (statusCode != null && statusCode.intValue() == 200) {
                    String a2 = a(execute);
                    DLogger.a("QB_DOWN::CFDnsREQ", "[RESOLVE_RSP] responseString=[" + a2 + "]");
                    if (!TextUtils.isEmpty(a2)) {
                        dnsResult = a(a2);
                    }
                }
            }
        } catch (Exception unused) {
        } catch (Throwable th) {
            requester.close();
            throw th;
        }
        requester.close();
        return dnsResult;
    }

    private String a(MttResponse mttResponse) throws Exception {
        MttInputStream inputStream = mttResponse.getInputStream();
        if (inputStream == null) {
            return null;
        }
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(4096);
        byte[] bArr = new byte[4096];
        while (true) {
            int read = inputStream.read(bArr, 0, bArr.length);
            if (read == -1) {
                return byteArrayOutputStream.toString("utf-8");
            }
            byteArrayOutputStream.write(bArr, 0, read);
        }
    }

    @Override
    public DnsResult a() {
        if (this.f37774d == null) {
            this.f37774d = RequesterFactory.getRequester(0);
        }
        DLogger.a("QB_DOWN::CFDnsREQ", "[START_RESOLVE] domain=[" + this.f37772b + "]");
        DnsResult a2 = a(f37771a[0], this.f37772b, this.f37774d);
        if (a2 == null) {
            a2 = a(f37771a[1], this.f37772b, this.f37774d);
        }
        DLogger.a("QB_DOWN::CFDnsREQ", "[RESOLVE_RST] result=[" + a2 + "]");
        return a2;
    }

    @Override
    public void b() {
        if (this.f37774d != null) {
            DLogger.a("QB_DOWN::CFDnsREQ", "[CANCEL_RESOLVE] domain=[" + this.f37772b + "]");
            this.f37774d.close();
        }
    }
}