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

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


package com.tencent.mtt.search;

import android.text.TextUtils;
import android.webkit.ValueCallback;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.taf.JceUtil;
import com.tencent.common.task.QBTask;
import com.tencent.common.utils.FileUtilsF;
import com.tencent.common.utils.Md5Utils;
import com.tencent.common.utils.UrlUtils;
import com.tencent.common.wup.IWUPRequestCallBack;
import com.tencent.common.wup.WUPRequestBase;
import com.tencent.common.wup.WUPResponseBase;
import com.tencent.common.wup.WUPTaskProxy;
import com.tencent.mtt.ContextHolder;
import com.tencent.mtt.base.webview.QBWebView;
import com.tencent.mtt.base.wup.DomainListDataManager;
import com.tencent.mtt.base.wup.GUIDManager;
import com.tencent.mtt.base.wup.WUPRequest;
import com.tencent.mtt.browser.window.IWebView;
import com.tencent.mtt.external.reader.IReader;
import com.tencent.mtt.operation.event.EventLog;
import com.tencent.mtt.qbinfo.QUAUtils;
import com.tencent.mtt.search.jsapi.method.SearchJsMethodBase;
import com.tencent.mtt.search.network.MTT.SmartBox_DomainJSPathData;
import com.tencent.mtt.search.network.MTT.SmartBox_DomainJSPathReq;
import com.tencent.mtt.search.network.MTT.SmartBox_DomainJSPathRsp;
import com.tencent.mtt.setting.PublicSettingManager;
import com.tencent.mtt.view.toast.MttToaster;
import java.io.File;
import java.io.IOException;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.regex.Pattern;

public class SearchWebJsInjector implements IWUPRequestCallBack {

    private final List<SmartBox_DomainJSPathRsp> f70076a;

    private SoftReference<IWebView> f70077b;

    private String f70078c;

    public static class InjectorHolder {

        private static SearchWebJsInjector f70090a = new SearchWebJsInjector();

        private InjectorHolder() {
        }
    }

    private SearchWebJsInjector() {
        this.f70077b = null;
        this.f70078c = null;
        this.f70076a = new ArrayList();
        QBTask.c(new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                SearchWebJsInjector.this.b();
                return null;
            }
        });
    }

    public static SearchWebJsInjector a() {
        return InjectorHolder.f70090a;
    }

    public void a(QBWebView qBWebView) {
        if (qBWebView == null || !a(this.f70078c, 2)) {
            return;
        }
        qBWebView.evaluateJavascript("// 展示\ndocument.body.style.overflow = \"scroll\";\ndocument.body.style.visibility = \"visible\";\nwindow.hasShow = true;\n", null);
    }

    private void a(final IWebView iWebView, final String str, boolean z) {
        if (z) {
            str = "javascript:(" + String.format("!function(){var jsApiScript = document.createElement('script');\njsApiScript.setAttribute('type', 'text/javascript');\njsApiScript.setAttribute('src', 'https://jsapi.qq.com/get?api=qb.beacon');\njsApiScript.onload=function(){var injected = document.createElement('script');\ninjected.setAttribute('type', 'text/javascript');\ninjected.setAttribute('src', '%s');\ndocument.body.appendChild(injected);};\ndocument.body.appendChild(jsApiScript);}", str) + "())";
        }
        QBTask.b((Callable) new Callable<Object>() {
            @Override
            public Object call() {
                final QBWebView qBWebView = iWebView.getQBWebView();
                if (qBWebView == null) {
                    return null;
                }
                qBWebView.evaluateJavascript(str, new ValueCallback<String>() {
                    @Override
                    public void onReceiveValue(String str2) {
                        SearchWebJsInjector.this.a(qBWebView);
                    }
                });
                return null;
            }
        });
    }

    private synchronized void a(SmartBox_DomainJSPathRsp smartBox_DomainJSPathRsp) {
        if (smartBox_DomainJSPathRsp != null) {
            if ((smartBox_DomainJSPathRsp.iRetCode == 0 || smartBox_DomainJSPathRsp.iRetCode == 1) && smartBox_DomainJSPathRsp.vecData != null) {
                int i = smartBox_DomainJSPathRsp.iRetCode;
                int i2 = smartBox_DomainJSPathRsp.iVersion;
                String str = smartBox_DomainJSPathRsp.sDomain;
                if (i == 0) {
                    if (this.f70076a.size() == 0) {
                        this.f70076a.add(smartBox_DomainJSPathRsp);
                    } else {
                        boolean z = false;
                        Iterator<SmartBox_DomainJSPathRsp> it = this.f70076a.iterator();
                        while (true) {
                            if (!it.hasNext()) {
                                break;
                            }
                            SmartBox_DomainJSPathRsp next = it.next();
                            if (!TextUtils.isEmpty(next.sDomain) && TextUtils.equals(next.sDomain, str)) {
                                if (i2 > next.iVersion) {
                                    this.f70076a.remove(next);
                                    this.f70076a.add(smartBox_DomainJSPathRsp);
                                    b(smartBox_DomainJSPathRsp);
                                }
                                z = true;
                            } else if (TextUtils.equals(next.sDomain, "biaoti") && TextUtils.isEmpty(str)) {
                                this.f70076a.remove(next);
                                this.f70076a.add(smartBox_DomainJSPathRsp);
                                b(smartBox_DomainJSPathRsp);
                                z = true;
                            }
                        }
                        if (!z) {
                            this.f70076a.add(smartBox_DomainJSPathRsp);
                        }
                    }
                    b(smartBox_DomainJSPathRsp);
                }
            }
        }
    }

    private synchronized void a(File file) {
        SmartBox_DomainJSPathRsp smartBox_DomainJSPathRsp;
        if (file != null) {
            if (file.exists()) {
                try {
                    smartBox_DomainJSPathRsp = (SmartBox_DomainJSPathRsp) JceUtil.parseRawData(SmartBox_DomainJSPathRsp.class, FileUtilsF.g(file));
                } catch (Exception unused) {
                }
                if (smartBox_DomainJSPathRsp == null) {
                    return;
                }
                this.f70076a.add(smartBox_DomainJSPathRsp);
            }
        }
    }

    public boolean a(String str, int i) {
        DomainListDataManager a2;
        int i2;
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        ArrayList<String> arrayList = null;
        if (i != 1) {
            if (i == 2) {
                a2 = DomainListDataManager.a();
                i2 = IReader.APPLY_FILTER;
            }
            if (arrayList != null && arrayList.size() > 0) {
                StringBuilder sb = new StringBuilder();
                for (String str2 : arrayList) {
                    sb.append(str2);
                    if (b(str2, str)) {
                        EventLog.a("搜索JS注入", UrlUtils.getHost(str), "通过白名单校验", sb.toString(), "lypeerluo");
                        return true;
                    }
                }
                EventLog.a("搜索JS注入", UrlUtils.getHost(str), "白名单校验不通过", "规则为:" + sb.toString() + " , url为:" + str, "lypeerluo");
            }
            return false;
        }
        a2 = DomainListDataManager.a();
        i2 = 352;
        arrayList = a2.a(i2);
        if (arrayList != null) {
            StringBuilder sb2 = new StringBuilder();
            while (r0.hasNext()) {
            }
            EventLog.a("搜索JS注入", UrlUtils.getHost(str), "白名单校验不通过", "规则为:" + sb2.toString() + " , url为:" + str, "lypeerluo");
        }
        return false;
    }

    private boolean a(String str, String str2) {
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) {
            return false;
        }
        return Pattern.compile(str).matcher(str2).matches();
    }

    public void b() {
        c();
    }

    private void b(SmartBox_DomainJSPathRsp smartBox_DomainJSPathRsp) {
        if (smartBox_DomainJSPathRsp == null) {
            return;
        }
        if (TextUtils.isEmpty(smartBox_DomainJSPathRsp.sDomain)) {
            smartBox_DomainJSPathRsp.sDomain = "biaoti";
        }
        String str = smartBox_DomainJSPathRsp.sDomain;
        File file = new File(d(), Md5Utils.a(str) + ".sji");
        if (file.exists()) {
            file.delete();
        }
        try {
            file.createNewFile();
        } catch (IOException unused) {
        }
        FileUtilsF.a(file, JceUtil.jce2Bytes(smartBox_DomainJSPathRsp));
    }

    public void b(String str) {
        if (TextUtils.isEmpty(str)) {
            return;
        }
        WUPRequest wUPRequest = new WUPRequest("SearchThrough", "getDomainJSPath");
        SmartBox_DomainJSPathReq smartBox_DomainJSPathReq = new SmartBox_DomainJSPathReq();
        smartBox_DomainJSPathReq.sGuid = GUIDManager.a().f();
        smartBox_DomainJSPathReq.sQua2 = QUAUtils.a();
        smartBox_DomainJSPathReq.sSession = PublicSettingManager.a().getString("pskSearchJsInjectorSession", "");
        smartBox_DomainJSPathReq.sUrl = str;
        EventLog.a("搜索JS注入", UrlUtils.getHost(str), "发起请求", "session为:" + smartBox_DomainJSPathReq.sSession, "lypeerluo");
        wUPRequest.put(HiAnalyticsConstant.Direction.REQUEST, smartBox_DomainJSPathReq);
        wUPRequest.setRequestCallBack(this);
        WUPTaskProxy.send(wUPRequest);
    }

    private boolean b(String str, String str2) {
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) {
            return false;
        }
        return Pattern.compile(str).matcher(str2).matches();
    }

    private void c() {
        File[] listFiles = d().listFiles();
        if (listFiles == null || listFiles.length <= 0) {
            return;
        }
        for (File file : listFiles) {
            if (file != null && !TextUtils.isEmpty(file.getName())) {
                a(file);
            }
        }
    }

    private boolean c(String str, String str2) {
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) {
            return false;
        }
        return TextUtils.equals(UrlUtils.getHost(str2), str);
    }

    private File d() {
        File file = new File(FileUtilsF.e(ContextHolder.getAppContext()), "SearchJs");
        if (!file.exists()) {
            file.mkdirs();
        }
        return file;
    }

    private synchronized boolean e() {
        EventLog.a("搜索JS注入", UrlUtils.getHost(this.f70078c), "尝试注入", this.f70078c, "lypeerluo");
        if (f()) {
            EventLog.a("搜索JS注入", UrlUtils.getHost(this.f70078c), "界面未加载完毕,此次注入失败", this.f70078c, "lypeerluo");
            return false;
        }
        boolean[] zArr = {false};
        for (SmartBox_DomainJSPathRsp smartBox_DomainJSPathRsp : this.f70076a) {
            if (smartBox_DomainJSPathRsp != null) {
                if (smartBox_DomainJSPathRsp.JSData != null) {
                    EventLog.a("搜索JS注入", UrlUtils.getHost(this.f70078c), "检测到带有jsData,尝试注入jsData", "jsUrl为:" + smartBox_DomainJSPathRsp.JSData.sUrl + ", jsCode为:" + smartBox_DomainJSPathRsp.JSData.sJSCode, "lypeerluo");
                    if (a(smartBox_DomainJSPathRsp.JSData.sUrl, this.f70078c)) {
                        zArr[0] = true;
                        EventLog.a("搜索JS注入", UrlUtils.getHost(this.f70078c), "注入jsData成功", "", "lypeerluo");
                        if (f()) {
                            return false;
                        }
                        a(this.f70077b.get(), smartBox_DomainJSPathRsp.JSData.sJSCode, false);
                        if (SearchJsMethodBase.f70324a) {
                            QBTask.b((Callable) new Callable<Object>() {
                                @Override
                                public Object call() throws Exception {
                                    MttToaster.showSysToast(ContextHolder.getAppContext(), "jsData注入成功", 0);
                                    return null;
                                }
                            });
                        }
                    } else {
                        EventLog.a("搜索JS注入", UrlUtils.getHost(this.f70078c), "注入jsData失败,正则校验不通过", "", "lypeerluo");
                    }
                }
                String str = smartBox_DomainJSPathRsp.sDomain;
                if (c(str, this.f70078c)) {
                    ArrayList<SmartBox_DomainJSPathData> arrayList = smartBox_DomainJSPathRsp.vecData;
                    if (arrayList != null && arrayList.size() > 0) {
                        for (SmartBox_DomainJSPathData smartBox_DomainJSPathData : arrayList) {
                            if (a(smartBox_DomainJSPathData.sUrl, this.f70078c)) {
                                zArr[0] = true;
                                if (f()) {
                                    return false;
                                }
                                a(this.f70077b.get(), smartBox_DomainJSPathData.sJSPath, true);
                            }
                            if (SearchJsMethodBase.f70324a) {
                                QBTask.b((Callable) new Callable<Object>() {
                                    @Override
                                    public Object call() throws Exception {
                                        MttToaster.showSysToast(ContextHolder.getAppContext(), "js注入成功", 0);
                                        return null;
                                    }
                                });
                            }
                        }
                    }
                } else {
                    EventLog.a("搜索JS注入", UrlUtils.getHost(this.f70078c), "校验host失败", "host:" + str + " , url:" + this.f70078c, "lypeerluo");
                }
            }
        }
        if (!zArr[0]) {
            return false;
        }
        this.f70077b = null;
        this.f70078c = null;
        return true;
    }

    private boolean f() {
        SoftReference<IWebView> softReference;
        return TextUtils.isEmpty(this.f70078c) || (softReference = this.f70077b) == null || softReference.get() == null;
    }

    private void g() {
        QBTask.b((Callable) new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                if (SearchWebJsInjector.this.f70077b == null || SearchWebJsInjector.this.f70077b.get() == null) {
                    return null;
                }
                SearchWebJsInjector searchWebJsInjector = SearchWebJsInjector.this;
                searchWebJsInjector.a(((IWebView) searchWebJsInjector.f70077b.get()).getQBWebView());
                return null;
            }
        });
    }

    public void a(IWebView iWebView, int i) {
        if (iWebView == null) {
            return;
        }
        System.out.println("ldldldldldld:onProgressChanged=" + i + " , url=" + iWebView.getUrl());
        if (!a(iWebView.getUrl(), 2) || i <= 0 || i >= 50 || iWebView.getQBWebView() == null) {
            return;
        }
        iWebView.getQBWebView().evaluateJavascript("\n// 隐藏\nfunction show() \n{ \t\n\tif(!window.hasShow)\n\t{\n\t\tdocument.body.style.overflow = \"scroll\";\n\t\tdocument.body.style.visibility = \"visible\";\n\t\twindow.hasShow = true;\n\t}\n} \n\nif(!window.hasShow)\n{\n\tdocument.body.style.overflow = \"hidden\";\n\tdocument.body.style.visibility = \"hidden\";\n\tsetTimeout(\"show();\",4000);\n}\n", null);
    }

    public void a(IWebView iWebView, String str) {
        System.out.println("ldldldldldld:onPageFinish");
        this.f70077b = new SoftReference<>(iWebView);
        this.f70078c = str;
        if (e()) {
            return;
        }
        g();
    }

    public void a(final String str) {
        System.out.println("ldldldldldld:onPageStart");
        if (TextUtils.isEmpty(str)) {
            return;
        }
        EventLog.a("搜索JS注入", UrlUtils.getHost(str), "网页开始加载", str, "lypeerluo");
        this.f70078c = str;
        this.f70077b = null;
        QBTask.c(new Callable<Object>() {
            @Override
            public Object call() {
                if (!SearchWebJsInjector.this.a(str, 1) && !SearchWebJsInjector.this.a(str, 2)) {
                    return null;
                }
                SearchWebJsInjector.this.b(str);
                return null;
            }
        });
    }

    @Override
    public void onWUPTaskFail(WUPRequestBase wUPRequestBase) {
    }

    @Override
    public void onWUPTaskSuccess(WUPRequestBase wUPRequestBase, WUPResponseBase wUPResponseBase) {
        if (wUPResponseBase != null) {
            Object obj = wUPResponseBase.get(HiAnalyticsConstant.Direction.RESPONSE);
            if (obj instanceof SmartBox_DomainJSPathRsp) {
                EventLog.a("搜索JS注入", UrlUtils.getHost(this.f70078c), "收到后台回包", "", "lypeerluo");
                SmartBox_DomainJSPathRsp smartBox_DomainJSPathRsp = (SmartBox_DomainJSPathRsp) obj;
                PublicSettingManager.a().setString("pskSearchJsInjectorSession", smartBox_DomainJSPathRsp.sSession);
                a(smartBox_DomainJSPathRsp);
                e();
            }
        }
    }
}