Craftsman 4 v1.20.43版本的 MD5 值为:44824ed1b4bf939cc4a771f5f317f768

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


package com.safedk.android.analytics.brandsafety.creatives.discoveries;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.view.View;
import com.ironsource.sdk.constants.a;
import com.safedk.android.SafeDK;
import com.safedk.android.analytics.brandsafety.BrandSafetyUtils;
import com.safedk.android.analytics.brandsafety.creatives.AdNetworkConfiguration;
import com.safedk.android.analytics.brandsafety.creatives.AdNetworkDiscovery;
import com.safedk.android.analytics.brandsafety.creatives.CreativeInfoManager;
import com.safedk.android.analytics.brandsafety.creatives.discoveries.c;
import com.safedk.android.analytics.brandsafety.creatives.g;
import com.safedk.android.analytics.brandsafety.creatives.infos.AdMobCreativeInfo;
import com.safedk.android.analytics.brandsafety.creatives.infos.CreativeInfo;
import com.safedk.android.analytics.brandsafety.i;
import com.safedk.android.utils.Logger;
import com.safedk.android.utils.SdksMapping;
import com.safedk.android.utils.h;
import com.safedk.android.utils.l;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.net.URL;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.ConcurrentModificationException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jose4j.jwk.RsaJsonWebKey;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Marker;
public class b extends d {
    private static final String A = "market";
    private static final String B = "AdGroup+Creative+ID+0";
    private static final String E = "afma-sdk-a-v";
    private static final String F = "java.util.LinkedHashMap";
    private static final String G = "ignore_this_destination";
    private static final String H = "question";
    private static final String I = "longform_questions";
    private static final String J = "com.google.android.gms.ads.admanager.AdManagerAdView";
    private static final String K = "com.google.android.gms.ads.internal.overlay.g";
    private static final String L = "\\{background-image:url\\(([^)]+?)\\)";
    public static final String f6008b = "appIcon:";
    public static final String f6009c = "shortAppName:";
    public static final String f6010d = "headline:";
    public static final String f6011e = "description:";
    public static final String f6012f = "image:";
    public static final String f6013g = "ytId:";
    private static final String f6014h = "AdMobDiscovery";
    private static final String t = "com.google.android.gms";
    private static final String u = "org.json.JSONObject";
    private static final String v = "ad_html";
    private static final String w = "clickUrl";
    private static final String x = "pubid";
    private static final String y = "http";
    private static final String z = "intent";
    private static final String C = "Backend+Query+ID";
    private static final String D = C.replace(Marker.ANY_NON_NULL_MARKER, "%2B");
    private static final String[] M = {"var url = 'https://googleads.g.doubleclick.net/dbm/ad?dbm_c=", "<div class=\"GoogleActiveViewInnerContainer\"", "src=\"https://googleads.g.doubleclick.net/xbbe/pixel?d", "googleInitIc(document.body"};

    public b() {
        super(h.f6562h, f6014h, false);
        this.f6055l.b(AdNetworkConfiguration.SHOULD_SCAN_BANNER_OBJECT_USING_REFLECTION, true);
        this.f6055l.b(AdNetworkConfiguration.SUPPORTS_BANNER_IMPRESSION_TRACKING, true);
        this.f6055l.b(AdNetworkConfiguration.APP_OPEN_IMPRESSION_TRACKING_ENABLED, true);
        this.f6055l.b(AdNetworkConfiguration.SHOULD_SCAN_INTERSTITIAL_VIEW_HIERARCHY_FOR_CI, true);
        this.f6055l.b(AdNetworkConfiguration.SUPPORTS_MREC_IMPRESSION_TRACKING, true);
        this.f6055l.b(AdNetworkConfiguration.SHOULD_INJECT_JS_TO_WEBVIEWS_FOR_TEXT_EXTRACTION, false);
        this.f6055l.b(AdNetworkConfiguration.WEBVIEW_REPLACE_ON_AD_DISPLAY_FAIL, true);
    }

    private BrandSafetyUtils.AdType a(long j2, long j3) {
        if (l.a((float) j2, (float) j3)) {
            Logger.d(f6014h, "generate info View check. banner identified");
            return BrandSafetyUtils.AdType.BANNER;
        } else if (l.b((float) j2, (float) j3)) {
            Logger.d(f6014h, "generate info View check. mrec identified");
            return BrandSafetyUtils.AdType.MREC;
        } else {
            Logger.d(f6014h, "generate info View check. inter identified");
            return BrandSafetyUtils.AdType.INTERSTITIAL;
        }
    }

    private long a(View view, List<Object> list, List<String> list2) {
        long currentTimeMillis = System.currentTimeMillis();
        a(view, new ArrayList(), list, new HashSet(), list2);
        long currentTimeMillis2 = System.currentTimeMillis();
        l.b(f6014h, "generate info, travel time " + (currentTimeMillis2 - currentTimeMillis) + ", info " + list);
        return currentTimeMillis2;
    }

    @Override
    public List<CreativeInfo> a(View view, String str) {
        BrandSafetyUtils.AdType a2;
        List<String> arrayList;
        ArrayList arrayList2;
        List arrayList3;
        List arrayList4;
        ArrayList arrayList5;
        ArrayList arrayList6;
        ArrayList arrayList7;
        ArrayList arrayList8;
        ArrayList arrayList9;
        String str2;
        String str3;
        String str4;
        ArrayList<String> arrayList10;
        ArrayList<String> arrayList11;
        ArrayList arrayList12;
        ArrayList arrayList13;
        ArrayList arrayList14;
        String str5;
        StringBuilder sb;
        String str6;
        boolean z2;
        List<String> list;
        List list2;
        boolean z3;
        int i2;
        long currentTimeMillis;
        List<String> list3;
        boolean z4;
        String s2;
        String b2;
        String str7;
        List a3;
        List<String> e2;
        String str8;
        String str9;
        String str10;
        ArrayList arrayList15;
        ArrayList arrayList16 = new ArrayList();
        try {
            Logger.d(f6014h, "generate info started, view: " + view);
            long measuredHeight = view.getMeasuredHeight();
            long measuredWidth = view.getMeasuredWidth();
            Logger.d(f6014h, "generate info View check. adInstance is a View, visibility = " + view.getVisibility() + ", dimensions (height= " + measuredHeight + ", width=" + measuredWidth + ")");
            a2 = a(measuredWidth, measuredHeight);
            long currentTimeMillis2 = System.currentTimeMillis();
            arrayList = new ArrayList<>();
            ArrayList<JSONObject> arrayList17 = new ArrayList();
            long a4 = a(view, arrayList17, arrayList);
            List arrayList18 = new ArrayList();
            arrayList2 = new ArrayList();
            arrayList3 = new ArrayList();
            arrayList4 = new ArrayList();
            arrayList5 = new ArrayList();
            arrayList6 = new ArrayList();
            arrayList7 = new ArrayList();
            arrayList8 = new ArrayList();
            arrayList9 = new ArrayList();
            str2 = null;
            str3 = null;
            str4 = null;
            arrayList10 = new ArrayList();
            arrayList11 = new ArrayList();
            arrayList12 = new ArrayList();
            arrayList13 = new ArrayList();
            arrayList14 = new ArrayList();
            str5 = null;
            sb = new StringBuilder("b|");
            sb.append(currentTimeMillis2);
            sb.append("|");
            sb.append(a4);
            sb.append("|");
            sb.append(arrayList.size());
            sb.append("|");
            sb.append(arrayList17.size());
            HashSet hashSet = new HashSet();
            int i3 = 0;
            for (JSONObject jSONObject : arrayList17) {
                Iterator<String> keys = jSONObject.keys();
                int i4 = i3;
                while (keys.hasNext()) {
                    i4 = keys.next().equals(w) ? i4 + 1 : i4;
                }
                i3 = i4;
            }
            Logger.d(f6014h, "generate info - clickUrlsCounter=" + i3);
            str6 = null;
            z2 = false;
            list = null;
            list2 = arrayList18;
            z3 = true;
            i2 = -1;
            for (JSONObject jSONObject2 : arrayList17) {
                Iterator<String> keys2 = jSONObject2.keys();
                String str11 = str6;
                boolean z5 = z2;
                List<String> list4 = list;
                ArrayList arrayList19 = arrayList2;
                List list5 = list2;
                int i5 = i2;
                while (keys2.hasNext()) {
                    String next = keys2.next();
                    String string = jSONObject2.getString(next);
                    i5 = Math.max(i5, v(string));
                    if (z5) {
                        z4 = z5;
                    } else {
                        z4 = i5 > 1;
                    }
                    l.b(f6014h, "generate info, found ad part - key: " + next + ", is multi ad? " + z4 + ", ad count: " + i5 + ", value: " + string);
                    sb.append("|");
                    sb.append(next);
                    sb.append("->");
                    List l2 = l(string);
                    boolean z6 = !hashSet.contains(next);
                    hashSet.add(next);
                    if (next.equals(v)) {
                        Logger.d(f6014h, "generate info, processing ad html");
                        ArrayList<String> arrayList20 = new ArrayList();
                        a(string, arrayList20, arrayList14);
                        Logger.d(f6014h, "generate info, vastAdBlocks contains " + arrayList20.size() + " items");
                        if (!arrayList20.isEmpty()) {
                            Logger.d(f6014h, "generate info, processing vast blocks");
                            z3 = false;
                            str4 = CreativeInfo.f6132r;
                            if (z4) {
                                str4 = CreativeInfo.f6132r + CreativeInfo.aG + i5;
                            }
                            sb.append(str4);
                            sb.append(a.i.f4725c);
                            str7 = string;
                            for (String str12 : arrayList20) {
                                str7 = str7.replace(str12, "");
                                ArrayList arrayList21 = new ArrayList();
                                g.a a5 = a(str12, arrayList21);
                                if (a5 != null) {
                                    Logger.d(f6014h, "generate info, vast info found, ad id: " + a5.c());
                                    arrayList13.add(a5);
                                    arrayList12.add(arrayList21);
                                    if (!z6) {
                                        sb.append("sk&");
                                        if (a5 != null) {
                                            sb.append(CreativeInfo.f6132r);
                                            sb.append(a.i.f4725c);
                                            sb.append("c=" + a5.a());
                                            sb.append("&i=" + a5.c());
                                        }
                                    }
                                }
                            }
                            s2 = str11;
                            b2 = str5;
                            a3 = arrayList4;
                        } else {
                            String j2 = l.j(string);
                            s2 = s(j2);
                            String f2 = f(f(j2, "app-open-publisher-tab-holder"), "advertisement-top");
                            b2 = b(string, arrayList10, a(f2, arrayList10, str5, sb), sb);
                            String n2 = n(f2);
                            if (n2 != null) {
                                arrayList3.add(n2);
                                sb.append("dd_c&");
                            }
                            str3 = o(f2);
                            str7 = string;
                            a3 = a(string, sb);
                        }
                        if (com.safedk.android.utils.g.Z().matcher(string).find()) {
                            b2 = CreativeInfo.u;
                            sb.append(CreativeInfo.u);
                            sb.append(a.i.f4725c);
                        }
                        String str13 = b2;
                        if (z4) {
                            a(string, arrayList5, arrayList6, arrayList7, arrayList8, arrayList9);
                        }
                        e2 = l.e(str7);
                        if (s2 != null && e2.contains(s2)) {
                            e2.remove(s2);
                            l.b(f6014h, "generate info, removed app icon url: " + s2);
                        }
                        if (r(string)) {
                            Logger.d(f6014h, "generate info, all mraid string found, marking this ad as mraid");
                            sb.append("mraidStringFound&");
                        }
                        for (int i6 = 0; i6 < e2.size(); i6++) {
                            String j3 = l.j(e2.get(i6));
                            e2.set(i6, j3);
                            Logger.d(f6014h, "htmlUrls url = " + j3);
                        }
                        l.b(f6014h, "generate info, html: " + string);
                        if (l.r(string)) {
                            Logger.d(f6014h, "generate info, content is Html content");
                            str8 = s(string);
                            String f3 = f(f(string, "app-open-publisher-tab-holder"), "advertisement-top");
                            ArrayList<String> e3 = l.e(f3);
                            l.b(f6014h, "generate info, urls extracted from source: " + e3);
                            if (str8 != null && e3.contains(str8)) {
                                e3.remove(str8);
                                l.b(f6014h, "generate info, removed app icon url: " + str8);
                            }
                            if (e3 != null && e3.size() > 0) {
                                ArrayList arrayList22 = new ArrayList();
                                for (String str14 : e3) {
                                    String replaceAll = l.j(str14).replaceAll("&quot;", a.i.f4725c);
                                    if (replaceAll != null && l.a((Object) replaceAll)) {
                                        arrayList22.add(replaceAll);
                                    } else {
                                        Logger.d(f6014h, "generate info, sanitizedUrl is not a url: " + replaceAll);
                                    }
                                }
                                l.b(f6014h, "generate info, Html content sanitized urls: " + arrayList22);
                                e2.addAll(arrayList22);
                            }
                            b(f3, arrayList11);
                        } else {
                            str8 = s2;
                        }
                        str9 = str8;
                        str5 = str13;
                        str10 = str4;
                        arrayList4 = a3;
                    } else if (next.equals("pubid")) {
                        if (!z6) {
                            sb.append("sk&");
                            sb.append(string.substring(0, string.lastIndexOf(47)));
                            z5 = z4;
                            list5 = l2;
                        } else {
                            str2 = string.substring(0, string.lastIndexOf(47));
                            Logger.d(f6014h, "generate info, placement ID: " + str2);
                            z3 = false;
                            sb.append(str2);
                            sb.append(a.i.f4725c);
                            str9 = str11;
                            e2 = list4;
                            str10 = str4;
                        }
                    } else if (next.equals(w)) {
                        Map<String, String> a6 = l.a(string, false);
                        if (a6.containsKey(C) || a6.containsKey(D)) {
                            String str15 = a6.containsKey(C) ? a6.get(C) : a6.get(D);
                            if (i3 > 1 && str != null && !str.equals(str15)) {
                                Logger.d(f6014h, "generate info, found json collection with wrong backend query id, skipping it");
                                z5 = z4;
                                list5 = l2;
                            }
                        }
                        sb.append(string).append(a.i.f4725c);
                        if (!z6) {
                            sb.append("sk&");
                            sb.append("c=").append(u(string));
                            sb.append("&i=").append(a(string, false));
                            z5 = z4;
                            list5 = l2;
                        } else {
                            Logger.d(f6014h, "generate info, click url value: " + string);
                            if (arrayList3 == null || arrayList3.isEmpty()) {
                                arrayList3 = u(string);
                                sb.append("dc2&");
                                sb.append(arrayList3).append(a.i.f4725c);
                                Logger.d(f6014h, "generate info, click urls: " + arrayList3);
                            }
                            if (arrayList19 == null || arrayList19.isEmpty()) {
                                Object a7 = a(string, false);
                                Logger.d(f6014h, "generate info, creative ID: " + a7);
                                arrayList15 = a7;
                            } else {
                                arrayList15 = arrayList19;
                            }
                            z3 = false;
                            str9 = str11;
                            e2 = list4;
                            str10 = str4;
                            arrayList19 = arrayList15;
                        }
                    } else {
                        str9 = str11;
                        e2 = list4;
                        str10 = str4;
                    }
                    if (z4 && str10 != null && !str10.contains(CreativeInfo.aI)) {
                        str10 = str10 + CreativeInfo.aI;
                        sb.append("&multiple_ads");
                    }
                    str11 = str9;
                    z5 = z4;
                    list4 = e2;
                    str4 = str10;
                    list5 = l2;
                }
                str6 = str11;
                z2 = z5;
                list = list4;
                arrayList2 = arrayList19;
                list2 = list5;
                i2 = i5;
            }
            currentTimeMillis = System.currentTimeMillis();
            Logger.d(f6014h, "generate info, json build time: " + (currentTimeMillis - a4));
        } catch (Throwable th) {
            Logger.e(f6014h, "Exception in generate info: " + th.getMessage(), th);
        }
        if (z3) {
            Logger.d(f6014h, "generate info, prefetch is NULL");
            return null;
        }
        if (!arrayList13.isEmpty()) {
            a(arrayList13, arrayList2, arrayList3, arrayList4, sb);
        }
        for (int i7 = 0; i7 < arrayList3.size(); i7++) {
            if (arrayList3.get(i7) != null && ((String) arrayList3.get(i7)).contains(G)) {
                arrayList3.set(i7, null);
            }
        }
        if (str4 == null) {
            str4 = str5;
        } else if (str5 != null) {
            str4 = str4 + "|" + str5;
        }
        Logger.d(f6014h, "generate info, downstream struct: " + str4 + ", adCount = " + i2);
        int i8 = 0;
        while (i8 < i2) {
            CreativeInfo adMobCreativeInfo = new AdMobCreativeInfo(null, a2, arrayList2.size() > i8 ? (String) arrayList2.get(i8) : null, arrayList3.size() > i8 ? (String) arrayList3.get(i8) : null, str2, arrayList4.size() > i8 ? (String) arrayList4.get(i8) : null, this.f6058p, str4, str3);
            Logger.d(f6014h, "generate info - set click url of CI to - " + adMobCreativeInfo.K());
            if (str6 != null) {
                adMobCreativeInfo.D(str6);
                Logger.d(f6014h, "generate info, application icon url added to ci WebView urls exclusion list : " + str6);
            }
            l.b(f6014h, "created ci : " + adMobCreativeInfo);
            sb.append("|");
            sb.append(currentTimeMillis);
            sb.append("|");
            sb.append(arrayList.size());
            sb.append("|");
            sb.append(list == null ? RsaJsonWebKey.EXPONENT_MEMBER_NAME : Integer.valueOf(list.size()));
            sb.append("|");
            if (i8 < arrayList13.size()) {
                g.a aVar = (g.a) arrayList13.get(i8);
                if (aVar != null) {
                    sb.append(aVar.j() == null ? "v" : Integer.valueOf(aVar.j().size()));
                }
                adMobCreativeInfo.b(arrayList);
                if (!z2) {
                    adMobCreativeInfo.b(list);
                }
                a(adMobCreativeInfo, aVar, null);
            } else {
                l.b(f6014h, "generate info, adCount is 1");
                if (i2 == 1) {
                    adMobCreativeInfo.b(arrayList);
                    adMobCreativeInfo.b(list);
                } else {
                    Logger.d(f6014h, "ad count is > 1 , not adding prefetch urls");
                }
            }
            l.b(f6014h, "generate info, creative info urls = " + adMobCreativeInfo.s());
            if (i8 < arrayList12.size() && (list3 = (List) arrayList12.get(i8)) != null) {
                for (String str16 : list3) {
                    adMobCreativeInfo.z(str16);
                }
            }
            Logger.d(f6014h, "generate info, downstreamSubtype: " + str5 + ", inter text collection: " + arrayList10);
            if (str5 != null && !str5.equals(CreativeInfo.f6132r) && arrayList10.size() > 3) {
                for (String str17 : arrayList10) {
                    Logger.d(f6014h, "generate info, inter ad text: " + str17);
                    adMobCreativeInfo.x(str17);
                }
            }
            if ((a2.equals(BrandSafetyUtils.AdType.BANNER) || a2.equals(BrandSafetyUtils.AdType.MREC)) && arrayList11.size() > 0) {
                for (String str18 : arrayList11) {
                    Logger.d(f6014h, "generate info, banner/mrec ad text: " + str18);
                    adMobCreativeInfo.x(str18);
                }
            }
            if (z2) {
                adMobCreativeInfo.ag();
                if (i8 < arrayList5.size() && arrayList5.get(i8) != null) {
                    adMobCreativeInfo.y(f6008b + ((String) arrayList5.get(i8)));
                }
                if (i8 < arrayList6.size() && arrayList6.get(i8) != null) {
                    adMobCreativeInfo.y(f6009c + ((String) arrayList6.get(i8)));
                }
                if (i8 < arrayList7.size() && arrayList7.get(i8) != null) {
                    adMobCreativeInfo.y(f6010d + ((String) arrayList7.get(i8)));
                }
                if (i8 < arrayList8.size() && arrayList8.get(i8) != null) {
                    adMobCreativeInfo.y(f6011e + ((String) arrayList8.get(i8)));
                }
                if (i8 < arrayList9.size() && arrayList9.get(i8) != null) {
                    adMobCreativeInfo.y(f6012f + ((String) arrayList9.get(i8)));
                }
                if (i8 < arrayList14.size() && arrayList14.get(i8) != null) {
                    adMobCreativeInfo.y(f6013g + ((String) arrayList14.get(i8)));
                }
            }
            adMobCreativeInfo.s(sb.toString());
            if (i8 < list2.size()) {
                adMobCreativeInfo = b((String) list2.get(i8), adMobCreativeInfo);
            } else {
                Logger.d(f6014h, "generate info, click string is empty, cannot check if scar CI exists");
            }
            Logger.d(f6014h, "generate info, generated info is: " + adMobCreativeInfo);
            arrayList16.add(adMobCreativeInfo);
            i8++;
        }
        return arrayList16;
    }

    public static void a(String str, List<String> list, List<String> list2) {
        Matcher matcher = com.safedk.android.utils.g.V().matcher(str);
        boolean z2 = false;
        while (matcher.find()) {
            a(matcher.group(1), list, list2, Integer.parseInt(matcher.group(2)));
            z2 = true;
        }
        if (!z2) {
            a(str, list, list2, 0);
        }
    }

    private static void a(String str, List<String> list, List<String> list2, int i2) {
        String e2 = l.e(com.safedk.android.utils.g.c(), str);
        if (e2 != null) {
            l.b(f6014h, "extractVastBlock adding vastBlock : " + e2);
            list.add(i2, e2);
        }
        String e3 = l.e(com.safedk.android.utils.g.U(), str);
        if (e3 == null) {
            e3 = l.e(com.safedk.android.utils.g.T(), str);
        }
        if (e3 != null) {
            l.b(f6014h, "extractVastBlock adding youtubeVideoId : " + e3);
            list2.add(i2, e3);
        }
    }

    public static void a(String str, List<String> list, List<String> list2, List<String> list3, List<String> list4, List<String> list5) {
        List<Integer> b2 = l.b(com.safedk.android.utils.g.S(), str);
        if (!b2.isEmpty()) {
            String substring = str.substring(b2.get(0).intValue());
            List<Integer> b3 = l.b(com.safedk.android.utils.g.R(), substring);
            if (!b3.isEmpty()) {
                for (Integer num : b3) {
                    String a2 = l.a(substring, num.intValue());
                    list2.add(l.a(com.safedk.android.utils.g.P(), a2, 1));
                    list3.add(l.a(com.safedk.android.utils.g.O(), a2, 1));
                    list4.add(l.a(com.safedk.android.utils.g.N(), a2, 1));
                    list.add(l.a(Pattern.compile(l.a(com.safedk.android.utils.g.Q(), a2, 1) + L), str, 1));
                    list5.add(l.a(Pattern.compile(l.a(com.safedk.android.utils.g.M(), a2, 1) + L), str, 1));
                }
                return;
            }
            Iterator<String> it = l.b(com.safedk.android.utils.g.M(), str, 1).iterator();
            while (it.hasNext()) {
                String a3 = l.a(Pattern.compile(it.next() + L), str, 1);
                if (a3 != null) {
                    list5.add(a3);
                }
            }
        }
    }

    private void a(List<g.a> list, List<String> list2, List<String> list3, List<String> list4, StringBuilder sb) {
        int i2 = 0;
        while (true) {
            int i3 = i2;
            if (i3 < list.size()) {
                g.a aVar = list.get(i3);
                list4.add(i3, aVar.b());
                if (aVar.b() != null) {
                    sb.append("dv&");
                }
                if (aVar.a() != null) {
                    if (i3 >= list3.size()) {
                        list3.add(i3, aVar.a());
                    } else {
                        list3.set(i3, aVar.a());
                    }
                    sb.append("dc&");
                }
                sb.append("&c=" + aVar.a() + a.i.f4725c);
                if (aVar.c() != null) {
                    if (i3 >= list2.size()) {
                        list2.add(i3, aVar.c());
                    } else {
                        list2.set(i3, aVar.c());
                    }
                    Logger.d(f6014h, "generate info, Using ad id from vast: " + aVar.c());
                    sb.append("debugi&");
                }
                sb.append("&i=" + aVar.c() + a.i.f4725c);
                i2 = i3 + 1;
            } else {
                return;
            }
        }
    }

    private List<String> a(String str, StringBuilder sb) {
        ArrayList arrayList = new ArrayList();
        Matcher matcher = com.safedk.android.utils.g.W().matcher(str);
        if (matcher.find()) {
            String group = matcher.group(2);
            if (group.length() > 20) {
                Logger.d(f6014h, "generate info, discarding bad url: " + group);
            } else {
                arrayList.add(l.d(group));
                sb.append("du&");
            }
        }
        return arrayList;
    }

    private String a(String str, List<String> list, String str2, StringBuilder sb) {
        String replaceAll;
        String replaceAll2 = str.replaceAll("<script\\b[^>]*>[\\s\\S]*?<\\/script\\b[^>]*>", "");
        l.b(f6014h, "generate info, sanitized html is: " + replaceAll2);
        Matcher matcher = com.safedk.android.utils.g.ab().matcher(replaceAll2);
        while (matcher.find()) {
            if (matcher.groupCount() > 1 && (replaceAll = matcher.group(2).replace("<br>", " ").replaceAll("<[^>]*>", "")) != null && replaceAll.length() > 0) {
                Logger.d(f6014h, "generate info, found ad text: " + replaceAll + ", decoded: " + l.j(replaceAll));
                list.add(l.j(replaceAll));
            }
            str2 = "text";
            sb.append("text");
            sb.append(a.i.f4725c);
            if (l.d(com.safedk.android.utils.g.Y(), str)) {
                str2 = CreativeInfo.v;
                sb.append(CreativeInfo.v);
                sb.append(a.i.f4725c);
            }
        }
        return str2;
    }

    private String b(String str, List<String> list, String str2, StringBuilder sb) {
        Matcher matcher = com.safedk.android.utils.g.aa().matcher(str);
        if (matcher.find()) {
            try {
                JSONArray jSONArray = new JSONObject(l.j(matcher.group(1))).getJSONArray(I);
                for (int i2 = 0; i2 < jSONArray.length(); i2++) {
                    String string = jSONArray.getJSONObject(i2).getString(H);
                    Logger.d(f6014h, "generate info, found ad survey text: " + string);
                    list.add(string);
                }
                return CreativeInfo.f6133s;
            } catch (Throwable th) {
                try {
                    Logger.d(f6014h, "generate info, error parsing ad survey text: " + th.getMessage());
                    return CreativeInfo.f6133s;
                } finally {
                    sb.append(CreativeInfo.f6133s);
                    sb.append(a.i.f4725c);
                }
            }
        }
        return str2;
    }

    private void b(String str, List<String> list) {
        String replaceAll;
        String replaceAll2 = str.replaceAll("<script\\b[^>]*>[\\s\\S]*?<\\/script\\b[^>]*>", "");
        l.b(f6014h, "generate info, sanitized  html is: " + replaceAll2);
        Matcher matcher = com.safedk.android.utils.g.ab().matcher(replaceAll2);
        while (matcher.find()) {
            if (matcher.groupCount() > 1 && (replaceAll = matcher.group(2).replace("<br>", " ").replaceAll("<[^>]*>", "")) != null && replaceAll.length() > 0) {
                Logger.d(f6014h, "generate info, found ad text: " + replaceAll + ", decoded: " + l.j(replaceAll));
                list.add(l.j(replaceAll));
            }
        }
    }

    private boolean r(String str) {
        String[] strArr;
        Logger.d(f6014h, "isMraidAd started ");
        for (String str2 : M) {
            if (!str.contains(str2)) {
                return false;
            }
            Logger.d(f6014h, "isMraidAd ad html contains the string " + str2);
        }
        Logger.d(f6014h, "isMraidAd ad is an mraid ad");
        return true;
    }

    @Override
    public void e() {
        Logger.d(f6014h, "get SDK version - checking version for Admob " + this.f6058p);
        if (this.f6058p == null) {
            this.f6058p = SdksMapping.getSdkVersionByPackage(h.f6562h);
            Logger.d(f6014h, "get SDK version - version is " + this.f6058p);
        }
    }

    private CreativeInfo b(String str, CreativeInfo creativeInfo) {
        if (BrandSafetyUtils.AdType.INTERSTITIAL == creativeInfo.I()) {
            Logger.d(f6014h, "handle scar-admob-video ad started, click string: " + str + ", CI: " + creativeInfo);
            if (SafeDK.getInstance().y().h(h.f6565k)) {
                AdNetworkDiscovery g2 = CreativeInfoManager.g(h.f6565k);
                if (g2 != null) {
                    CreativeInfo a2 = g2.a((Object) str);
                    if (a2 != null) {
                        l.b(f6014h, "handle scar-admob-video ad, found origin SDK: " + a2.O() + ", actual SDK: " + creativeInfo.O());
                        a2.a(creativeInfo);
                        return a2;
                    }
                    Logger.d(f6014h, "handle scar-admob-video ad - no CI matched, actual SDK: " + creativeInfo.O());
                    return creativeInfo;
                }
                Logger.d(f6014h, "handle scar-admob-video ad - no UnityAdsDiscovery found");
                return creativeInfo;
            } else if (!SafeDK.getInstance().y().h(h.f6562h)) {
                Logger.d(f6014h, "handle scar-admob-video ad - no interstitial info found for package name: com.google.ads");
                return creativeInfo;
            } else {
                return creativeInfo;
            }
        }
        return creativeInfo;
    }

    private String s(String str) {
        List<String> b2 = l.b(com.safedk.android.utils.g.L(), str, 3);
        if (b2 != null) {
            Iterator<String> it = b2.iterator();
            if (it.hasNext()) {
                String next = it.next();
                Logger.d(f6014h, "findPublisherAppIconUrl match  : " + next);
                return next;
            }
        }
        return null;
    }

    public String f(String str, String str2) {
        MatchResult matchResult;
        if (str.contains(str2)) {
            Iterator<MatchResult> it = l.c(Pattern.compile("<div|class=(?:\\\"|')" + str2 + "(?:\\\"|')|</div>"), str).iterator();
            int i2 = 0;
            boolean z2 = false;
            MatchResult matchResult2 = null;
            while (true) {
                if (!it.hasNext()) {
                    matchResult = null;
                    break;
                }
                matchResult = it.next();
                if (z2) {
                    if (matchResult.group().equals("<div")) {
                        i2++;
                    } else if (matchResult.group().equals("</div>")) {
                        i2--;
                    }
                    if (i2 == 0) {
                        break;
                    }
                }
                if (matchResult.group().contains(str2)) {
                    z2 = true;
                    i2++;
                } else {
                    matchResult = matchResult2;
                }
                matchResult2 = matchResult;
            }
            if (matchResult2 != null && matchResult != null) {
                String substring = str.substring((matchResult2.start() - "<div".length()) - 1, matchResult.end());
                Logger.d(f6014h, "find app icon url  remove element by className removing this matched string : " + substring);
                return str.replace(substring, "");
            }
            return str;
        }
        return str;
    }

    @Override
    protected List<CreativeInfo> b(String str, String str2, Map<String, List<String>> map, c.a aVar) throws JSONException {
        return null;
    }

    @Override
    protected String a(String str, CreativeInfo creativeInfo) {
        return null;
    }

    @Override
    protected boolean k(String str) {
        return false;
    }

    @Override
    protected boolean b(String str, Bundle bundle) {
        return false;
    }

    public g.a a(String str, List<String> list) {
        Logger.d(f6014h, "getVastInfoRecursive started");
        g.a c2 = g.c(str, true);
        if (c2 == null) {
            return null;
        }
        String c3 = c2.c();
        String d2 = c2.d();
        List<String> i2 = c2.i();
        List<String> o2 = c2.o();
        List<String> n2 = c2.n();
        List<String> p2 = c2.p();
        List<String> q2 = c2.q();
        Logger.d(f6014h, "get vast info - saved ad ID: " + c3 + ", ad system: " + d2 + " and impression urls: " + i2);
        l.b(f6014h, "get vast info - " + c2);
        while (true) {
            if (c2 != null && c2.e() != null) {
                Logger.d(f6014h, "get vast info - fetching vast ad uri: " + c2.e());
                list.add(c2.e());
                String t2 = t(c2.e());
                l.b(f6014h, "get vast info -  ad tag uri content=" + t2);
                if (!TextUtils.isEmpty(t2)) {
                    c2 = g.c(t2, true);
                    l.b(f6014h, "get vast info recursive: " + c2);
                } else {
                    Logger.d(f6014h, "get vast info -  ad tag uri content is empty");
                    break;
                }
            } else {
                break;
            }
        }
        if (c2 != null) {
            if (c3 != null && c2.c() != c3) {
                c2.a(c3);
                Logger.d(f6014h, "get vast info - saved adId from outer vast: " + c3);
            }
            if (d2 != null && c2.d() != d2) {
                c2.b(d2);
                Logger.d(f6014h, "get vast info - saved adSystem from outer vast: " + d2);
            }
            if (i2 != null) {
                c2.a(i2);
                Logger.d(f6014h, "get vast info - saved impressionUrls from outer vast: " + i2);
            }
            if (o2 != null) {
                c2.c(o2);
                Logger.d(f6014h, "get vast info - saved videoTrackingEventUrls from outer vast: " + o2);
            }
            if (n2 != null) {
                c2.b(n2);
                Logger.d(f6014h, "get vast info - saved videoCompletedUrls from outer vast: " + n2);
            }
            if (p2 != null) {
                c2.d(p2);
                Logger.d(f6014h, "get vast info - saved clickTrackingUrls from outer vast: " + p2);
            }
            if (q2 != null) {
                c2.e(q2);
                Logger.d(f6014h, "get vast info - saved companionClickTrackingUrls from outer vast: " + q2);
                return c2;
            }
            return c2;
        }
        return c2;
    }

    private String t(String str) {
        InputStream inputStream = null;
        StringBuffer stringBuffer = new StringBuffer();
        try {
            Logger.d(f6014h, "downloadUrl fetching " + str);
            inputStream = new URL(str).openStream();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            while (true) {
                String readLine = bufferedReader.readLine();
                if (readLine == null) {
                    break;
                }
                stringBuffer.append(readLine);
            }
            inputStream.close();
        } catch (Throwable th) {
            try {
                Logger.d(f6014h, "Exception in downloadUrl : " + th.getMessage(), th);
                if (inputStream != null) {
                    inputStream.close();
                }
            } catch (Throwable th2) {
                Logger.d(f6014h, "Exception in downloadUrl inner : " + th.getMessage(), th);
            }
        }
        return stringBuffer.toString();
    }

    private void a(String str, int i2, List<String> list) {
        int indexOf = str.indexOf(61);
        if (indexOf != -1) {
            int indexOf2 = str.indexOf(38, indexOf);
            if (indexOf2 == -1) {
                indexOf2 = str.length();
            }
            String substring = str.substring(indexOf + 1, indexOf2);
            Logger.d(f6014h, "extract click url index: " + i2 + ", landing page package id: " + substring);
            list.add(i2, i.c(substring));
        }
    }

    private List<String> u(String str) {
        ArrayList arrayList = new ArrayList();
        try {
            List<String> a2 = com.safedk.android.analytics.brandsafety.creatives.d.a(com.safedk.android.utils.g.ae(), str, 1, 2, false);
            for (int i2 = 0; i2 < a2.size(); i2 += 2) {
                int parseInt = Integer.parseInt(a2.get(i2));
                String lowerCase = URLDecoder.decode(a2.get(i2 + 1), "UTF-8").toLowerCase();
                Logger.d(f6014h, "extract click url index: " + parseInt + ", landing page: " + lowerCase);
                if (lowerCase.startsWith("http") || lowerCase.startsWith(A)) {
                    arrayList.add(parseInt, lowerCase);
                } else if (lowerCase.startsWith(z)) {
                    arrayList.add(parseInt, lowerCase);
                    a(lowerCase, parseInt, arrayList);
                    Logger.d(f6014h, "extractClickUrls: adding intent link with landing page: " + lowerCase);
                }
            }
        } catch (UnsupportedEncodingException e2) {
            Logger.e(f6014h, e2.getMessage());
        }
        return arrayList;
    }

    public static List<String> a(String str, boolean z2) {
        List<String> a2;
        ArrayList arrayList = new ArrayList();
        if (z2) {
            a2 = com.safedk.android.analytics.brandsafety.creatives.d.a(com.safedk.android.utils.g.ad(), str, 1, 2, false);
        } else {
            a2 = com.safedk.android.analytics.brandsafety.creatives.d.a(com.safedk.android.utils.g.ac(), str, 1, 2, false);
        }
        Logger.d(f6014h, "extract creative ids - the values are: " + Arrays.toString(a2.toArray()));
        for (int i2 = 0; i2 < a2.size(); i2 += 2) {
            int parseInt = Integer.parseInt(a2.get(i2));
            String str2 = a2.get(i2 + 1);
            if (!arrayList.contains(str2)) {
                arrayList.add(parseInt, str2);
            }
        }
        Logger.d(f6014h, "extract creative ids - creativeIds are: " + Arrays.toString(arrayList.toArray()));
        return arrayList;
    }

    public static List<String> l(String str) {
        int i2 = 0;
        ArrayList arrayList = new ArrayList();
        List<String> a2 = com.safedk.android.analytics.brandsafety.creatives.d.a(com.safedk.android.utils.g.X(), str, 1, 2, false);
        while (true) {
            int i3 = i2;
            if (i3 < a2.size()) {
                int parseInt = Integer.parseInt(a2.get(i3));
                String str2 = a2.get(i3 + 1);
                if (!arrayList.contains(str2)) {
                    arrayList.add(parseInt, str2);
                }
                i2 = i3 + 2;
            } else {
                return arrayList;
            }
        }
    }

    private int v(String str) {
        int i2 = -1;
        Matcher matcher = com.safedk.android.utils.g.af().matcher(str);
        while (matcher.find()) {
            i2 = Math.max(Integer.parseInt(matcher.group(1)), i2);
        }
        return i2 + 1;
    }

    private void a(Object obj, List<String> list, List<Object> list2, Set<Object> set, final List<String> list3) {
        if (obj != null && !set.contains(obj)) {
            set.add(obj);
            Class<?> cls = obj.getClass();
            ArrayList<Field> arrayList = new ArrayList();
            do {
                arrayList.addAll(Arrays.asList(cls.getDeclaredFields()));
                cls = cls.getSuperclass();
            } while (cls.getName().startsWith("com.google.android.gms"));
            for (Field field : arrayList) {
                field.setAccessible(true);
                try {
                    try {
                        final Object obj2 = field.get(obj);
                        if (obj2 != null) {
                            if (field.getType().getName().equals("interface") || obj2.getClass().getName().startsWith("com.google.android.gms")) {
                                list.add(field.getName());
                                a(obj2, list, list2, set, list3);
                                list.remove(list.size() - 1);
                            } else if (field.getType().getName().equals(u)) {
                                list.add(field.getName());
                                Logger.d(f6014h, "found prefetch info in path: " + list + ", object: " + obj2);
                                list2.add(obj2);
                                list.remove(list.size() - 1);
                            } else if (obj2.getClass().getName().startsWith(l.f6599d)) {
                                String str = (String) obj2;
                                if (!TextUtils.isEmpty(str)) {
                                    l.b(f6014h, "iterating over field " + field.getName() + " (non empty value) , string info = " + str);
                                }
                                if (str != null && str.startsWith(B)) {
                                    list.add(field.getName());
                                    Logger.d(f6014h, "found prefetch click url in path: " + list + ", object: " + obj2);
                                    try {
                                        list2.add(new JSONObject("{ \"clickUrl\" : \"" + str + "\" }"));
                                    } catch (JSONException e2) {
                                    }
                                    list.remove(list.size() - 1);
                                } else if (str != null && str.startsWith(E)) {
                                    list.add(field.getName());
                                    Logger.d(f6014h, "found sdk version in path: " + list + ", object: " + obj2);
                                    String[] split = str.split("\\.");
                                    if (split.length > 1) {
                                        this.f6058p = split[1];
                                        if (this.f6058p != null) {
                                            g(h.f6562h, this.f6058p);
                                        }
                                    }
                                    list.remove(list.size() - 1);
                                }
                            } else if (field.getType().getName().equals(F)) {
                                list.add(field.getName());
                                Logger.d(f6014h, "found resource url in path: " + list);
                                try {
                                    a(obj2, list3);
                                } catch (ConcurrentModificationException e3) {
                                    Logger.d(f6014h, "Couldn't access LinkedHashMap field : " + e3.getMessage());
                                    new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
                                        @Override
                                        public void run() {
                                            try {
                                                b.this.a(obj2, (List<String>) list3);
                                            } catch (Throwable th) {
                                                Logger.d(b.f6014h, "Couldn't access LinkedHashMap field (again!) : " + th.getMessage());
                                            }
                                        }
                                    }, 5L);
                                }
                                list.remove(list.size() - 1);
                            }
                        }
                    } catch (ConcurrentModificationException e4) {
                        Logger.e(f6014h, "Error in extract ad info : " + e4.getMessage(), e4);
                    }
                } catch (IllegalAccessException e5) {
                    Logger.e(f6014h, e5.getMessage());
                }
            }
        }
    }

    public void a(Object obj, List<String> list) {
        String w2;
        Logger.d(f6014h, "extractHashMapFieldResourceURLs started");
        for (Map.Entry entry : ((LinkedHashMap) obj).entrySet()) {
            if (entry != null && entry.getValue() != null && (w2 = w(entry.getValue().toString())) != null) {
                Logger.d(f6014h, "extractHashMapFieldResourceURLs resource url: " + w2);
                list.add(w2);
            }
        }
    }

    private String w(String str) {
        int indexOf;
        int indexOf2 = str.indexOf(34);
        if (indexOf2 <= -1 || (indexOf = str.indexOf(34, indexOf2 + 1)) <= -1) {
            return null;
        }
        return str.substring(indexOf2 + 1, indexOf);
    }

    @Override
    public Set<String> c() {
        return new HashSet();
    }

    @Override
    public String f() {
        return null;
    }

    @Override
    public AdNetworkDiscovery.WebViewResourceMatchingMethod b() {
        return AdNetworkDiscovery.WebViewResourceMatchingMethod.WEBVIEW_LOOKUP;
    }

    @Override
    public boolean e(View view) {
        if (view.getClass().getName().equals(K)) {
            Logger.d(f6014h, "is ad view: " + view.getClass().getName() + " is an instance of " + K);
            return true;
        }
        return false;
    }

    @Override
    public long a(CreativeInfo creativeInfo) {
        return SafeDK.getInstance().E() * 2;
    }
}