导航菜单

页面标题

页面副标题

Clean Center v0.5.5 - CloudScanClient.java 源代码

正在查看: Clean Center v0.5.5 应用的 CloudScanClient.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.trustlook.sdk.cloudscan;

import android.app.ActivityManager;
import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.pm.ApkChecksum;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.Signature;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import com.tom_roush.pdfbox.contentstream.operator.OperatorName;
import com.trustlook.sdk.BuildConfig;
import com.trustlook.sdk.Constants;
import com.trustlook.sdk.R;
import com.trustlook.sdk.ScanUtils;
import com.trustlook.sdk.Utility;
import com.trustlook.sdk.data.AppCertificate;
import com.trustlook.sdk.data.AppInfo;
import com.trustlook.sdk.data.DataUtils;
import com.trustlook.sdk.data.PkgInfo;
import com.trustlook.sdk.data.Region;
import com.trustlook.sdk.data.StatInfo;
import com.trustlook.sdk.database.DBManager;
import com.trustlook.sdk.database.SimplifiedAppDAO;
import com.trustlook.sdk.database.SimplifiedAppDBManager;
import com.trustlook.sdk.database.SimplifiedPkgInfo;
import com.trustlook.sdk.job.TlJobService;
import com.trustlook.sdk.ngsescan.FileUtils;
import com.wxiwei.office.fc.openxml4j.opc.PackagingURIHelper;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.net.HttpURLConnection;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.UnknownHostException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionException;
import org.apache.commons.codec.binary.Hex;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class CloudScanClient {
    private static String n;
    private static final Map<Region, String> o;
    private Context a;
    private Region b;
    private String c;
    int d;
    int e;
    private int f;
    private int g;
    private CloudScanListener h;
    private CloudScanCancelListener i;
    private Boolean j;
    private AppInfo k;
    private boolean l;
    private Handler m;

    public static class Builder {
        private Context a;
        private Region b;
        int c = 10000;
        int d = 10000;

        public Builder(Context context) {
            this.a = context.getApplicationContext();
            String unused = CloudScanClient.n = context.getClass().getSimpleName();
        }

        public CloudScanClient build() {
            return new CloudScanClient(this, null);
        }

        public Builder setConnectionTimeout(int i) {
            this.c = i;
            return this;
        }

        public Builder setRegion(Region region) {
            Objects.toString(region);
            this.b = region;
            return this;
        }

        public Builder setSocketTimeout(int i) {
            this.d = i;
            return this;
        }
    }

    class a extends Handler {
        a(Looper looper) {
            super(looper);
        }

        @Override
        public void handleMessage(Message message) {
            int i = message.what;
            if (i == 1) {
                CloudScanClient.a(CloudScanClient.this);
                return;
            }
            if (i == 7) {
                CloudScanClient.i(CloudScanClient.this);
                return;
            }
            if (i == 3) {
                CloudScanClient.b(CloudScanClient.this, 1);
                CloudScanClient cloudScanClient = CloudScanClient.this;
                CloudScanClient.a(cloudScanClient, cloudScanClient.g, CloudScanClient.this.f, (AppInfo) message.obj);
            } else if (i != 4) {
                if (i != 5) {
                    return;
                }
                CloudScanClient.c(CloudScanClient.this, (List) message.obj);
            } else {
                Object obj = message.obj;
                if (obj instanceof Integer) {
                    CloudScanClient.a(CloudScanClient.this, ((Integer) obj).intValue(), "");
                } else {
                    CloudScanClient.a(CloudScanClient.this, 0, obj.toString());
                }
            }
        }
    }

    class b implements Runnable {
        final CloudScanListener a;
        final List b;

        b(CloudScanListener cloudScanListener, List list) {
            this.a = cloudScanListener;
            this.b = list;
        }

        @Override
        public void run() {
            try {
                if (CloudScanClient.this.h != null) {
                    return;
                }
                CloudScanClient.this.h = this.a;
                CloudScanClient.this.j = Boolean.FALSE;
                HashSet hashSet = new HashSet();
                File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Download");
                ArrayList arrayList = new ArrayList();
                ArrayList arrayList2 = new ArrayList();
                ScanUtils.simpleScanning(file, arrayList, arrayList2);
                hashSet.addAll(arrayList2);
                CloudScanClient.this.a(1, (Object) null);
                List list = this.b;
                if (list == null) {
                    CloudScanClient.this.a(4, (Object) 2);
                    return;
                }
                CloudScanClient.this.f = ((ArrayList) CloudScanClient.a(CloudScanClient.this, list)).size() + hashSet.size();
                CloudScanClient.this.g = 0;
                int unused = CloudScanClient.this.f;
                List<AppInfo> a = CloudScanClient.this.a((List<String>) this.b, false);
                if (a != null) {
                    for (AppInfo appInfo : a) {
                        appInfo.getMd5();
                        appInfo.getPackageName();
                        appInfo.getVirusName();
                        appInfo.getScore();
                    }
                    List b = CloudScanClient.b(CloudScanClient.this, new ArrayList(hashSet));
                    if (b != null && !b.isEmpty()) {
                        a.addAll(b);
                    }
                    List b2 = CloudScanClient.b(CloudScanClient.this, new ArrayList(arrayList));
                    if (b2 != null && !b2.isEmpty()) {
                        a.addAll(b2);
                    }
                }
                CloudScanClient.this.a(5, a);
                CloudScanClient.d(CloudScanClient.this);
            } catch (Exception e) {
                int a2 = CloudScanClient.this.a(e);
                if (a2 == 0) {
                    CloudScanClient.this.a(4, e.getMessage());
                } else {
                    CloudScanClient.this.a(4, Integer.valueOf(a2));
                }
            }
        }
    }

    class c implements Runnable {
        final CloudScanListener a;

        c(CloudScanListener cloudScanListener) {
            this.a = cloudScanListener;
        }

        @Override
        public void run() {
            try {
                List b = CloudScanClient.this.b();
                if (CloudScanClient.this.h != null) {
                    return;
                }
                CloudScanClient.this.h = this.a;
                CloudScanClient.this.j = Boolean.FALSE;
                CloudScanClient.this.a(1, (Object) null);
                HashSet hashSet = new HashSet();
                HashSet hashSet2 = new HashSet();
                Iterator it = ((ArrayList) CloudScanClient.g(CloudScanClient.this)).iterator();
                while (it.hasNext()) {
                    String str = (String) it.next();
                    if (str != null && !str.isEmpty()) {
                        File file = new File(str);
                        ArrayList arrayList = new ArrayList();
                        ArrayList arrayList2 = new ArrayList();
                        ScanUtils.simpleScanning(file, arrayList, arrayList2);
                        hashSet.addAll(arrayList);
                        hashSet2.addAll(arrayList2);
                    }
                }
                List a = CloudScanClient.a(CloudScanClient.this, b);
                ArrayList arrayList3 = (ArrayList) a;
                CloudScanClient.this.f = arrayList3.size() + hashSet.size() + hashSet2.size();
                CloudScanClient.this.g = 0;
                if (arrayList3.isEmpty() && hashSet.isEmpty() && hashSet2.isEmpty()) {
                    CloudScanClient.this.a(4, (Object) 2);
                    return;
                }
                List arrayList4 = new ArrayList();
                if (!arrayList3.isEmpty()) {
                    arrayList3.size();
                    arrayList4 = CloudScanClient.this.a((List<String>) b, false);
                    arrayList4.toString();
                }
                if (!hashSet.isEmpty()) {
                    hashSet.size();
                    arrayList4.addAll(CloudScanClient.this.a((List<String>) new ArrayList(hashSet), true));
                }
                Iterator it2 = arrayList4.iterator();
                while (it2.hasNext()) {
                    String apkPath = ((AppInfo) it2.next()).getApkPath();
                    if (hashSet.contains(apkPath)) {
                        hashSet.remove(apkPath);
                    }
                }
                if (!hashSet.isEmpty()) {
                    hashSet2.addAll(hashSet);
                }
                hashSet2.size();
                List b2 = CloudScanClient.b(CloudScanClient.this, new ArrayList(hashSet2));
                if (b2 != null && !b2.isEmpty()) {
                    arrayList4.addAll(b2);
                }
                CloudScanClient.this.a(5, arrayList4);
                CloudScanClient.d(CloudScanClient.this);
            } catch (Exception e) {
                e.getMessage();
                CloudScanClient.this.a(4, Integer.valueOf(CloudScanClient.this.a(e)));
            }
        }
    }

    class d implements Runnable {
        final CloudScanListener a;
        final List b;

        d(CloudScanListener cloudScanListener, List list) {
            this.a = cloudScanListener;
            this.b = list;
        }

        @Override
        public void run() {
            try {
                if (CloudScanClient.this.h != null) {
                    return;
                }
                CloudScanClient.this.h = this.a;
                CloudScanClient.this.j = Boolean.FALSE;
                CloudScanClient.this.a(1, (Object) null);
                List list = this.b;
                if (list == null || list.isEmpty()) {
                    throw new com.trustlook.sdk.cloudscan.c();
                }
                HashSet hashSet = new HashSet();
                HashSet hashSet2 = new HashSet();
                for (String str : this.b) {
                    if (str != null && !str.isEmpty()) {
                        File file = new File(str);
                        ArrayList arrayList = new ArrayList();
                        ArrayList arrayList2 = new ArrayList();
                        ScanUtils.simpleScanning(file, arrayList, arrayList2);
                        hashSet.addAll(arrayList);
                        hashSet2.addAll(arrayList2);
                    }
                }
                CloudScanClient.this.f = hashSet.size() + hashSet2.size();
                CloudScanClient.this.g = 0;
                List a = CloudScanClient.this.a((List<String>) new ArrayList(hashSet), true);
                if (a != null) {
                    Iterator it = a.iterator();
                    while (it.hasNext()) {
                        String apkPath = ((AppInfo) it.next()).getApkPath();
                        if (hashSet.contains(apkPath)) {
                            hashSet.remove(apkPath);
                        }
                    }
                    if (!hashSet.isEmpty()) {
                        hashSet2.addAll(hashSet);
                    }
                    List b = CloudScanClient.b(CloudScanClient.this, new ArrayList(hashSet2));
                    if (b != null && !b.isEmpty()) {
                        a.addAll(b);
                    }
                }
                CloudScanClient.this.a(5, a);
                CloudScanClient.d(CloudScanClient.this);
            } catch (Exception e) {
                CloudScanClient.this.a(4, Integer.valueOf(CloudScanClient.this.a(e)));
            }
        }
    }

    class e implements Runnable {
        final CloudScanListener a;
        final List b;

        e(CloudScanListener cloudScanListener, List list) {
            this.a = cloudScanListener;
            this.b = list;
        }

        @Override
        public void run() {
            try {
                if (CloudScanClient.this.h != null) {
                    return;
                }
                CloudScanClient.this.h = this.a;
                CloudScanClient.this.j = Boolean.FALSE;
                CloudScanClient.this.a(1, (Object) null);
                List list = this.b;
                if (list == null || list.isEmpty()) {
                    throw new com.trustlook.sdk.cloudscan.c();
                }
                HashSet hashSet = new HashSet();
                for (String str : this.b) {
                    if (str != null && !str.isEmpty()) {
                        File file = new File(str);
                        ArrayList arrayList = new ArrayList();
                        ArrayList arrayList2 = new ArrayList();
                        ScanUtils.simpleScanning(file, arrayList, arrayList2);
                        hashSet.addAll(arrayList);
                        hashSet.addAll(arrayList2);
                    }
                }
                CloudScanClient.this.f = hashSet.size();
                CloudScanClient.this.g = 0;
                CloudScanClient.this.a(5, CloudScanClient.b(CloudScanClient.this, new ArrayList(hashSet)));
            } catch (Exception e) {
                CloudScanClient.this.a(4, Integer.valueOf(CloudScanClient.this.a(e)));
            }
        }
    }

    class f implements Runnable {
        final CloudScanListener a;
        final String b;

        class a implements PackageManager.OnChecksumsReadyListener {
            final PkgInfo a;

            a(PkgInfo pkgInfo) {
                this.a = pkgInfo;
            }

            @Override
            public void onChecksumsReady(List<ApkChecksum> list) {
                if (list == null) {
                    return;
                }
                try {
                    String str = "";
                    for (ApkChecksum apkChecksum : list) {
                        if (apkChecksum.getType() == 2) {
                            str = Hex.encodeHexString(apkChecksum.getValue()).toUpperCase(Locale.US);
                            String str2 = f.this.b;
                        }
                    }
                    if (Utility.isNullOrEmpty(str)) {
                        CloudScanClient.this.a(4, (Object) 2);
                        return;
                    }
                    ArrayList arrayList = new ArrayList();
                    this.a.setMd5(str);
                    arrayList.add(this.a);
                    ScanResult cloudScan = CloudScanClient.this.cloudScan(arrayList, false);
                    if (cloudScan == null || cloudScan.getList() == null) {
                        if (cloudScan == null || cloudScan.isSuccess()) {
                            return;
                        }
                        CloudScanClient.this.a(4, Integer.valueOf(cloudScan.getError()));
                        return;
                    }
                    List<AppInfo> list2 = cloudScan.getList();
                    for (AppInfo appInfo : list2) {
                        appInfo.getPackageName();
                        appInfo.getScore();
                    }
                    CloudScanClient.this.a(5, list2);
                } catch (Throwable th) {
                    th.getMessage();
                    CloudScanClient.this.a(4, (Object) 0);
                }
            }
        }

        f(CloudScanListener cloudScanListener, String str) {
            this.a = cloudScanListener;
            this.b = str;
        }

        @Override
        public void run() {
            try {
                if (CloudScanClient.this.h != null) {
                    return;
                }
                CloudScanClient.this.h = this.a;
                CloudScanClient.this.j = Boolean.FALSE;
                if (Utility.isNullOrEmpty(this.b)) {
                    throw new com.trustlook.sdk.cloudscan.c();
                }
                CloudScanClient.this.a(1, (Object) null);
                CloudScanClient.this.a.getPackageManager().getPackageInfo(this.b, 64);
                PkgInfo pkgInfo = new PkgInfo(this.b);
                CloudScanClient.this.a(pkgInfo, false);
                try {
                    int i = Build.VERSION.SDK_INT;
                    if (i >= 31) {
                        CloudScanClient.this.a.getPackageManager().requestChecksums(this.b, false, 2, PackageManager.TRUST_ALL, new a(pkgInfo));
                    } else {
                        Log.e("TL", "SDK version is too low for checksum " + i);
                        CloudScanClient.this.a(4, (Object) 2);
                    }
                } catch (PackageManager.NameNotFoundException e) {
                    Log.e("TL", "Checksum package name not found exception:" + e.getMessage());
                    CloudScanClient.this.a(4, Integer.valueOf(CloudScanClient.this.a(e)));
                } catch (CertificateEncodingException e2) {
                    Log.e("TL", "Certificate encoding exception:" + e2.getMessage());
                    CloudScanClient.this.a(4, Integer.valueOf(CloudScanClient.this.a(e2)));
                }
            } catch (Exception e3) {
                CloudScanClient.this.a(4, Integer.valueOf(CloudScanClient.this.a(e3)));
            }
        }
    }

    class g implements PackageManager.OnChecksumsReadyListener {
        final String a;

        g(String str) {
            this.a = str;
        }

        @Override
        public void onChecksumsReady(List<ApkChecksum> list) {
            if (list == null) {
                CloudScanClient.this.l = true;
                return;
            }
            try {
                String str = "";
                for (ApkChecksum apkChecksum : list) {
                    if (apkChecksum.getType() == 2) {
                        str = Utility.byteArrayToHexString(apkChecksum.getValue());
                    }
                }
                if (Utility.isNullOrEmpty(str)) {
                    CloudScanClient.this.l = true;
                    return;
                }
                PkgInfo pkgInfo = new PkgInfo(this.a);
                CloudScanClient.this.a(pkgInfo, false);
                ArrayList arrayList = new ArrayList();
                pkgInfo.setMd5(str);
                arrayList.add(pkgInfo);
                ScanResult cloudScan = CloudScanClient.this.cloudScan(arrayList, false);
                if (cloudScan != null) {
                    List<AppInfo> list2 = cloudScan.getList();
                    if (list2 == null) {
                        CloudScanClient.this.l = true;
                        return;
                    }
                    for (AppInfo appInfo : list2) {
                        appInfo.getPackageName();
                        appInfo.getScore();
                    }
                    CloudScanClient.this.k = list2.get(0);
                }
                CloudScanClient.this.l = true;
            } catch (Throwable th) {
                th.getMessage();
                CloudScanClient.this.l = true;
            }
        }
    }

    class h implements Runnable {
        final CloudScanListener a;
        final List b;
        final boolean c;

        h(CloudScanListener cloudScanListener, List list, boolean z) {
            this.a = cloudScanListener;
            this.b = list;
            this.c = z;
        }

        @Override
        public void run() {
            if (CloudScanClient.this.h != null) {
                return;
            }
            CloudScanClient.this.h = this.a;
            CloudScanClient.b(CloudScanClient.this, this.b, this.c);
        }
    }

    static {
        HashMap hashMap = new HashMap();
        o = hashMap;
        hashMap.put(Region.INTL, "https://sla-intl.trustlook.com/");
        hashMap.put(Region.CHN, "https://api.luweitech.com/");
        hashMap.put(Region.BAIDU, "http://queryapi-1431840856.bceapp.com/");
    }

    CloudScanClient(Builder builder, a aVar) {
        this(builder);
    }

    static void d(CloudScanClient cloudScanClient) {
        cloudScanClient.getClass();
        if (a(cloudScanClient.a) > 1024) {
            ((JobScheduler) cloudScanClient.a.getSystemService("jobscheduler")).schedule(new JobInfo.Builder(1, new ComponentName(cloudScanClient.a, (Class<?>) TlJobService.class)).setRequiredNetworkType(2).setRequiresCharging(true).setPeriodic(10800000L).build());
        }
    }

    static List g(CloudScanClient cloudScanClient) {
        cloudScanClient.getClass();
        ArrayList arrayList = new ArrayList();
        File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
        cloudScanClient.a(file.listFiles(), arrayList);
        arrayList.add(file.getAbsolutePath());
        return arrayList;
    }

    public static String getVersion() {
        return BuildConfig.VERSION_NAME;
    }

    static boolean i(CloudScanClient cloudScanClient) {
        if (!cloudScanClient.j.booleanValue()) {
            return false;
        }
        CloudScanListener cloudScanListener = cloudScanClient.h;
        if (cloudScanListener != null) {
            cloudScanListener.onScanCanceled();
            cloudScanClient.h = null;
        }
        CloudScanCancelListener cloudScanCancelListener = cloudScanClient.i;
        if (cloudScanCancelListener != null) {
            cloudScanCancelListener.onOtherScanCancelSuccess();
        }
        return true;
    }

    public void cancelScan() {
        this.j = Boolean.TRUE;
    }

    public ScanResult cloudScan(List<PkgInfo> list, boolean z) {
        boolean z2;
        ScanResult scanResult;
        String str;
        Region region;
        int i;
        if (NetworkUtils.isNetworkAvailable(this.a)) {
            int i2 = 3;
            while (i2 >= 0) {
                int i3 = i2 - 1;
                try {
                    Long valueOf = Long.valueOf(DataUtils.getLongValue(this.a, Constants.KEY_EXPIRE, 0L));
                    Long valueOf2 = Long.valueOf(System.currentTimeMillis() / 1000);
                    if (valueOf2.longValue() >= valueOf.longValue()) {
                        URL url = new URL(DataUtils.getStringValue(this.a, Constants.HOST_URL, "https://sla-intl.trustlook.com/") + "verify");
                        url.toString();
                        HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
                        String trustlookApiKey = CloudUtil.getTrustlookApiKey(this.a);
                        httpURLConnection.setRequestMethod("POST");
                        httpURLConnection.setRequestProperty("Content-Type", "application/json");
                        httpURLConnection.setRequestProperty("Accept", "application/json");
                        httpURLConnection.setRequestProperty("X-TL-APIKEY", trustlookApiKey);
                        httpURLConnection.setConnectTimeout(this.d);
                        httpURLConnection.setReadTimeout(this.e);
                        JSONObject jSONObject = new JSONObject();
                        jSONObject.put("host_pkg_name", this.a.getPackageName());
                        jSONObject.put("hcs", a());
                        jSONObject.toString();
                        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(httpURLConnection.getOutputStream(), "UTF-8"));
                        bufferedWriter.write(jSONObject.toString());
                        bufferedWriter.close();
                        i = httpURLConnection.getResponseCode();
                        if (i == 200) {
                            if (httpURLConnection.getHeaderField("Cache-Control").contains("=")) {
                                DataUtils.saveLongValue(this.a, Constants.KEY_EXPIRE, Long.valueOf(Long.valueOf(Integer.valueOf(r0.split("=")[1]).intValue()).longValue() + (System.currentTimeMillis() / 1000)).longValue());
                                DBManager.getInstance(this.a).getDataSource().clearAppInfoCache();
                            }
                        }
                    } else {
                        valueOf.longValue();
                        valueOf2.longValue();
                        i = 200;
                    }
                    break;
                } catch (Exception e2) {
                    e2.printStackTrace();
                    Log.w("TL", "Verify API key error:" + e2.getMessage());
                    i2 = i3;
                }
            }
            i = 0;
            break;
            if (i == 403) {
                a(4, (Object) 8);
                return null;
            }
            if (i != 200) {
                a(4, (Object) 12);
                return null;
            }
        }
        if (list == null || list.size() == 0) {
            return null;
        }
        list.size();
        list.size();
        ScanResult scanResult2 = new ScanResult();
        ArrayList arrayList = new ArrayList();
        ArrayList arrayList2 = new ArrayList();
        for (PkgInfo pkgInfo : list) {
            try {
                AppInfo appInfoFromMD5 = DBManager.getInstance(this.a).getDataSource().getAppInfoFromMD5(pkgInfo);
                if (appInfoFromMD5 != null && appInfoFromMD5.getScore() >= 0) {
                    pkgInfo.getMd5();
                    appInfoFromMD5.getScore();
                    appInfoFromMD5.getPackageName();
                    appInfoFromMD5.getVirusName();
                    arrayList.add(appInfoFromMD5);
                    arrayList2.add(pkgInfo);
                    a(3, appInfoFromMD5);
                }
            } catch (Exception e3) {
                e3.getMessage();
            }
        }
        if (!arrayList2.isEmpty()) {
            Iterator it = arrayList2.iterator();
            while (it.hasNext()) {
                list.remove((PkgInfo) it.next());
            }
        }
        if (arrayList.isEmpty()) {
            z2 = true;
        } else {
            scanResult2.setList(arrayList);
            z2 = true;
            scanResult2.setIsSuccess(true);
        }
        arrayList.size();
        list.size();
        if (list.size() == 0) {
            scanResult2.setIsSuccess(z2);
            return scanResult2;
        }
        if (!NetworkUtils.isNetworkAvailable(this.a)) {
            Log.w("TL", "No network, return without cloud scan");
            a(4, (Object) 6);
            return scanResult2;
        }
        this.j = Boolean.FALSE;
        ScanResult scanResult3 = new ScanResult();
        new ArrayList();
        try {
            str = this.c;
            region = this.b;
        } catch (Exception e4) {
            e4.getLocalizedMessage();
            int a2 = a(e4);
            a(4, Integer.valueOf(a2));
            scanResult3.setIsSuccess(false);
            scanResult3.setError(a2);
        }
        if (str == null || region == null) {
            throw new com.trustlook.sdk.cloudscan.b(1);
        }
        JSONArray jSONArray = new JSONArray();
        Iterator<PkgInfo> it2 = list.iterator();
        while (it2.hasNext()) {
            jSONArray.put(it2.next().toJSON(this.a, z));
        }
        JSONObject jSONObject2 = new JSONObject();
        c(jSONObject2);
        jSONObject2.put("pks", jSONArray);
        jSONObject2.getString("pks");
        a(jSONObject2);
        NetworkUtils networkUtils = new NetworkUtils(this.a, this.d, this.e);
        String stringValue = DataUtils.getStringValue(this.a, Constants.SDK_INFO_API_VERSION, Constants.SDK_INFO_API_VERSION_DEFAULT);
        b(jSONObject2);
        this.c = DataUtils.getStringValue(this.a, Constants.HOST_URL, "https://sla-intl.trustlook.com/");
        jSONObject2.toString();
        List<AppInfo> a3 = networkUtils.a(this.c + OperatorName.CURVE_TO_REPLICATE_INITIAL_POINT + stringValue + PackagingURIHelper.FORWARD_SLASH_STRING + "virus/scan", jSONObject2.toString(), list);
        if (a3.isEmpty()) {
            scanResult3.setIsSuccess(false);
            scanResult3.setError(13);
        } else {
            a3.size();
            if (jSONObject2.has("exif")) {
                DataUtils.saveBooleanValue(this.a, Constants.EXTRA_INFO_SENT, true);
            }
            ArrayList arrayList3 = new ArrayList();
            for (AppInfo appInfo : a3) {
                if (this.j.booleanValue()) {
                    a(7, (Object) 0);
                    scanResult = null;
                    break;
                }
                if (appInfo.getUpload() == 1) {
                    appInfo.getPackageName();
                    appInfo.getMd5();
                    arrayList3.add(appInfo);
                }
                a(appInfo);
                a(3, appInfo);
            }
            if (arrayList3.size() > 0) {
                PkgUtils.persistInterestList(this.a, arrayList3);
            }
            DBManager.getInstance(this.a).getDataSource().setAppInfoLimit(500L);
            SimplifiedAppDBManager.getInstance(this.a).getDataSource().countAllData();
            scanResult3.setIsSuccess(true);
            scanResult3.setList(a3);
        }
        scanResult = scanResult3;
        if (scanResult != null && scanResult.getList() != null) {
            scanResult.getList().size();
            if (scanResult2.getList() != null) {
                scanResult2.getList().addAll(scanResult.getList());
            } else {
                scanResult2 = scanResult;
            }
            scanResult2.setIsSuccess(true);
        }
        return scanResult2;
    }

    public void cloudScanAsync(List<PkgInfo> list, boolean z, CloudScanListener cloudScanListener) {
        new Thread(new h(cloudScanListener, list, z)).start();
    }

    public AppInfo packageNameScan(String str, int i) {
        if (Utility.isNullOrEmpty(str)) {
            return null;
        }
        this.k = null;
        int i2 = 0;
        this.l = false;
        try {
            int i3 = Build.VERSION.SDK_INT;
            if (i3 < 31) {
                Log.e("TL", "SDK version is too low for checksum " + i3);
                return null;
            }
            this.a.getPackageManager().requestChecksums(str, false, 2, PackageManager.TRUST_ALL, new g(str));
            int i4 = i / 20;
            while (!this.l) {
                try {
                    Thread.sleep(20L);
                } catch (InterruptedException e2) {
                    e2.printStackTrace();
                }
                i2++;
                if (i2 >= i4) {
                    break;
                }
            }
            return this.k;
        } catch (PackageManager.NameNotFoundException e3) {
            Log.e("TL", trustlook_cloudscan.c.a("Checksum package name not found exception:").append(e3.getMessage()).toString());
            return null;
        } catch (CertificateEncodingException e4) {
            Log.e("TL", trustlook_cloudscan.c.a("Certificate encoding exception:").append(e4.getMessage()).toString());
            return null;
        }
    }

    public PkgInfo populatePkgInfo(String str, String str2, boolean z) {
        String str3;
        PkgInfo pkgInfo = new PkgInfo(str);
        if (!Utility.isNullOrEmpty(str2)) {
            File file = new File(str2);
            try {
                str3 = a(file, "MD5");
            } catch (Exception unused) {
                Log.e("TL", trustlook_cloudscan.c.a("Failed to calculate md5 for ").append(file.getAbsolutePath()).toString());
                str3 = "";
            }
            pkgInfo.setMd5(str3);
            pkgInfo.setPkgSize(file.length());
            pkgInfo.setPkgPath(str2);
            try {
                if (z) {
                    pkgInfo.setIsSystemApp(false);
                } else {
                    pkgInfo.setIsSystemApp(PkgUtils.isSystemPackage(this.a, str));
                }
            } catch (Exception unused2) {
                pkgInfo.setIsSystemApp(false);
                Log.w("TL", "App is not installed");
            }
            a(pkgInfo, z);
            try {
                if (z) {
                    pkgInfo.setPkgSource("");
                } else {
                    pkgInfo.setPkgSource(this.a.getPackageManager().getInstallerPackageName(str));
                }
            } catch (Exception unused3) {
                Log.w("TL", "Exception while apk have not been installed on device");
            }
        }
        return pkgInfo;
    }

    public void startComprehensiveScan(int i, CloudScanListener cloudScanListener) {
        Constants.GIGANTIC_APK_MB = i;
        startComprehensiveScan(cloudScanListener);
    }

    public void startEicarScan(List<String> list, CloudScanListener cloudScanListener) {
        new Thread(new e(cloudScanListener, list)).start();
    }

    public void startFolderScan(List<String> list, CloudScanListener cloudScanListener) {
        startFolderScan(list, cloudScanListener, false);
    }

    public void startPackagenameScan(String str, CloudScanListener cloudScanListener) {
        new Thread(new f(cloudScanListener, str)).start();
    }

    public void startQuickScan(List<String> list, CloudScanListener cloudScanListener) {
        startQuickScan(list, cloudScanListener, false);
    }

    private CloudScanClient(Builder builder) {
        this.f = 0;
        this.g = 0;
        this.j = Boolean.FALSE;
        this.k = null;
        this.l = false;
        this.m = new a(Looper.getMainLooper());
        this.a = builder.a;
        Region region = builder.b;
        this.b = region;
        if (region == null) {
            this.b = Region.INTL;
        }
        this.c = (String) ((HashMap) o).get(this.b);
        Objects.toString(this.b);
        this.d = builder.c;
        this.e = builder.d;
        Long valueOf = Long.valueOf(DataUtils.getLongValue(this.a, Constants.KEY_EXPIRE, 0L));
        SharedPreferences.Editor edit = this.a.getSharedPreferences(Constants.PREFERENCE_NAME, 0).edit();
        edit.clear();
        edit.commit();
        DataUtils.saveLongValue(this.a, Constants.KEY_EXPIRE, valueOf.longValue());
        DataUtils.saveRegionValue(builder.a, builder.b);
        DataUtils.saveIntValue(builder.a, Constants.CLIENT_CONNECTION_TIMEOUT, builder.c);
        DataUtils.saveIntValue(builder.a, Constants.CLIENT_SOCKET_TIMEOUT, builder.d);
    }

    static int b(CloudScanClient cloudScanClient, int i) {
        int i2 = cloudScanClient.g + i;
        cloudScanClient.g = i2;
        return i2;
    }

    public void cancelScan(CloudScanCancelListener cloudScanCancelListener) {
        this.j = Boolean.TRUE;
        this.i = cloudScanCancelListener;
        if (this.h != null || cloudScanCancelListener == null) {
            return;
        }
        cloudScanCancelListener.onOtherScanCancelSuccess();
    }

    public void startFolderScan(List<String> list, CloudScanListener cloudScanListener, boolean z) {
        new Thread(new d(cloudScanListener, list)).start();
    }

    public void startQuickScan(CloudScanListener cloudScanListener) {
        startQuickScan(b(), cloudScanListener, false);
    }

    static List b(CloudScanClient cloudScanClient, List list) {
        cloudScanClient.getClass();
        ArrayList arrayList = new ArrayList();
        String aesDecryptString = CloudUtil.aesDecryptString(Constants.ENCRYPE_STRING_1);
        String aesDecryptString2 = CloudUtil.aesDecryptString(Constants.ENCRYPE_STRING_2);
        String aesDecryptString3 = CloudUtil.aesDecryptString(Constants.ENCRYPE_STRING_3);
        String aesDecryptString4 = CloudUtil.aesDecryptString(Constants.ENCRYPE_STRING_4);
        Iterator it = list.iterator();
        while (it.hasNext()) {
            String str = (String) it.next();
            if (cloudScanClient.j.booleanValue()) {
                cloudScanClient.a(7, (Object) 0);
                return null;
            }
            AppInfo appInfo = new AppInfo("", "");
            appInfo.setApkPath(str);
            if (cloudScanClient.a(str, aesDecryptString, aesDecryptString2, aesDecryptString3, aesDecryptString4)) {
                String MD5 = FileUtils.MD5(new File(str), 8192);
                appInfo.setScore(8);
                appInfo.setMd5(MD5);
                appInfo.setVirusName("EICAR-Test-File (not a virus)");
                arrayList.add(appInfo);
            }
            cloudScanClient.a(3, appInfo);
        }
        return arrayList;
    }

    private void c(JSONObject jSONObject) throws JSONException {
        String str;
        jSONObject.put("sv", BuildConfig.VERSION_NAME);
        jSONObject.put("hpn", this.a.getPackageName());
        String a2 = a();
        if (a2 != null) {
            jSONObject.put("hcs1", a2);
        }
        jSONObject.put("ha", n);
        Integer num = null;
        try {
            str = this.a.getPackageManager().getPackageInfo(this.a.getPackageName(), 0).versionName;
        } catch (Exception unused) {
            str = null;
        }
        if (str != null) {
            jSONObject.put("hvn", str);
        }
        try {
            num = Integer.valueOf(this.a.getPackageManager().getPackageInfo(this.a.getPackageName(), 0).versionCode);
        } catch (Exception unused2) {
        }
        if (num != null) {
            jSONObject.put("hvc", num.toString());
        }
    }

    public void startComprehensiveScan(CloudScanListener cloudScanListener) {
        new Thread(new c(cloudScanListener)).start();
    }

    public void startQuickScan(CloudScanListener cloudScanListener, boolean z) {
        startQuickScan(b(), cloudScanListener, z);
    }

    public void startQuickScan(List<String> list, CloudScanListener cloudScanListener, boolean z) {
        new Thread(new b(cloudScanListener, list)).start();
    }

    private void a(File[] fileArr, List<String> list) {
        if (fileArr != null) {
            for (File file : fileArr) {
                if (file.isDirectory()) {
                    a(file.listFiles(), list);
                } else if (file.getName().endsWith(".apk")) {
                    list.add(file.getPath());
                }
            }
        }
    }

    static List a(CloudScanClient cloudScanClient, List list) {
        PackageManager packageManager;
        String str;
        File file;
        String parent;
        File file2;
        File[] listFiles;
        String[] stringArray;
        CloudScanClient cloudScanClient2 = cloudScanClient;
        PackageManager packageManager2 = cloudScanClient2.a.getPackageManager();
        ArrayList arrayList = new ArrayList();
        Iterator it = list.iterator();
        while (it.hasNext()) {
            String str2 = (String) it.next();
            try {
                str = packageManager2.getPackageInfo(str2, 64).applicationInfo.publicSourceDir;
                file = new File(str);
                parent = file.getParent();
                file2 = new File(parent);
                listFiles = file2.listFiles();
                stringArray = cloudScanClient2.a.getResources().getStringArray(R.array.languages);
            } catch (PackageManager.NameNotFoundException unused) {
                packageManager = packageManager2;
            } catch (Exception e2) {
                e = e2;
                packageManager = packageManager2;
            }
            if (listFiles == null) {
                file2.toString();
                if (file.exists() && str.endsWith(".apk")) {
                    arrayList.add(str);
                }
            }
            int length = listFiles.length;
            int i = 0;
            while (i < length) {
                File file3 = listFiles[i];
                if (file3.getName().endsWith(".apk") && !file3.getName().contains("dpi.apk")) {
                    int length2 = stringArray.length;
                    int i2 = 0;
                    while (true) {
                        if (i2 < length2) {
                            packageManager = packageManager2;
                            try {
                                if (file3.getName().contains("." + stringArray[i2] + ".apk")) {
                                    file3.getName();
                                    break;
                                }
                                i2++;
                                packageManager2 = packageManager;
                            } catch (PackageManager.NameNotFoundException unused2) {
                                Log.e("TL", "Package Name Not Found: " + str2 + ", may not installed.");
                                cloudScanClient2 = cloudScanClient;
                                packageManager2 = packageManager;
                            } catch (Exception e3) {
                                e = e3;
                                e.getMessage();
                                cloudScanClient2 = cloudScanClient;
                                packageManager2 = packageManager;
                            }
                        } else {
                            packageManager = packageManager2;
                            arrayList.add(parent + PackagingURIHelper.FORWARD_SLASH_STRING + file3.getName());
                            break;
                        }
                    }
                } else {
                    packageManager = packageManager2;
                }
                i++;
                packageManager2 = packageManager;
            }
            cloudScanClient2 = cloudScanClient;
        }
        return arrayList;
    }

    static void c(CloudScanClient cloudScanClient, List list) {
        if (cloudScanClient.h != null && !cloudScanClient.j.booleanValue()) {
            cloudScanClient.h.onScanFinished(list);
        }
        cloudScanClient.h = null;
    }

    static void b(CloudScanClient cloudScanClient, List list, boolean z) {
        cloudScanClient.a(2, list);
        ScanResult cloudScan = cloudScanClient.cloudScan(list, z);
        if (cloudScan == null || cloudScan.getList() == null) {
            return;
        }
        cloudScanClient.a(5, cloudScan.getList());
    }

    private List<AppInfo> b(ExecutorService executorService, List<SimplifiedPkgInfo> list, SimplifiedAppDAO simplifiedAppDAO, HashMap<String, SimplifiedPkgInfo> hashMap, boolean z) {
        ArrayList arrayList = new ArrayList();
        ArrayList arrayList2 = new ArrayList();
        for (SimplifiedPkgInfo simplifiedPkgInfo : list) {
            if (new File(simplifiedPkgInfo.getApkPath()).length() <= Constants.APP_SIZE_THRESHOLD) {
                arrayList.add(simplifiedPkgInfo);
            } else {
                arrayList2.add(simplifiedPkgInfo);
            }
        }
        System.currentTimeMillis();
        ArrayList arrayList3 = new ArrayList();
        if (arrayList.size() > 0) {
            arrayList.size();
            ArrayList<AppInfo> a2 = a(executorService, arrayList, simplifiedAppDAO, hashMap, z);
            if (a2 != null && a2.size() > 0) {
                arrayList3.addAll(a2);
            }
            System.currentTimeMillis();
        }
        if (arrayList2.size() > 0) {
            arrayList2.size();
            ArrayList<AppInfo> a3 = a(executorService, arrayList2, simplifiedAppDAO, hashMap, z);
            if (a3 != null && a3.size() > 0) {
                arrayList3.addAll(a3);
            }
            System.currentTimeMillis();
        }
        return arrayList3;
    }

    public java.util.List<com.trustlook.sdk.data.AppInfo> a(java.util.List<java.lang.String> r39, boolean r40) {
        throw new UnsupportedOperationException("Method not decompiled: com.trustlook.sdk.cloudscan.CloudScanClient.a(java.util.List, boolean):java.util.List");
    }

    private void b(JSONObject jSONObject) throws JSONException {
        String stringValue = DataUtils.getStringValue(this.a, Constants.EXTRA_INFO_FIELD, "");
        if (Utility.isNullOrEmpty(stringValue)) {
            return;
        }
        String[] split = stringValue.split(",");
        ?? arrayList = new ArrayList();
        if (DataUtils.getBooleanValue(this.a, Constants.EXTRA_INFO_SENT, false)) {
            for (String str : split) {
                if (str.equals("longitude") || str.equals("latitude")) {
                    arrayList.add(str);
                }
            }
        } else {
            arrayList = Arrays.asList(split);
        }
        List<StatInfo> collectExtraInfo = CloudUtil.collectExtraInfo(this.a, arrayList);
        if (collectExtraInfo == null || collectExtraInfo.size() < 1) {
            return;
        }
        JSONObject jSONObject2 = new JSONObject();
        for (StatInfo statInfo : collectExtraInfo) {
            jSONObject2.put(statInfo.getStatField(), statInfo.getStatValue());
        }
        jSONObject.put("exif", jSONObject2);
        jSONObject.getString("exif");
    }

    public List<String> b() {
        List<PackageInfo> list;
        ArrayList arrayList = new ArrayList();
        PackageManager packageManager = this.a.getPackageManager();
        if (Build.VERSION.SDK_INT < 33) {
            try {
                list = packageManager.getInstalledPackages(64);
            } catch (Exception e2) {
                trustlook_cloudscan.a.a(e2, trustlook_cloudscan.c.a("getInstalledPackages failed:"), "TL");
                list = null;
            }
            if (list != null) {
                list.size();
                for (PackageInfo packageInfo : list) {
                    if (!packageInfo.packageName.equals(this.a.getPackageName())) {
                        try {
                            if ((packageInfo.applicationInfo.flags & 1) == 0) {
                                arrayList.add(packageInfo.packageName);
                            }
                        } catch (Exception unused) {
                            Log.w("TL", trustlook_cloudscan.c.a("Can not find ").append(packageInfo.packageName).append("installed on device").toString());
                        }
                    }
                }
            } else {
                Log.w("TL", "Fail to get installed packages");
            }
        } else {
            Intent intent = new Intent("android.intent.action.MAIN");
            intent.addCategory("android.intent.category.LAUNCHER");
            List<ResolveInfo> queryIntentActivities = packageManager.queryIntentActivities(intent, PackageManager.ResolveInfoFlags.of(64L));
            if (!queryIntentActivities.isEmpty()) {
                for (ResolveInfo resolveInfo : queryIntentActivities) {
                    try {
                        if (resolveInfo.activityInfo.packageName.equals(this.a.getPackageName())) {
                            String str = resolveInfo.activityInfo.packageName;
                        } else {
                            ActivityInfo activityInfo = resolveInfo.activityInfo;
                            if ((activityInfo.applicationInfo.flags & 1) != 0) {
                                String str2 = resolveInfo.activityInfo.packageName;
                            } else {
                                arrayList.add(activityInfo.packageName);
                            }
                        }
                    } catch (Exception e3) {
                        e3.getMessage();
                    }
                }
            }
        }
        return arrayList;
    }

    private ArrayList<AppInfo> a(ExecutorService executorService, List<SimplifiedPkgInfo> list, SimplifiedAppDAO simplifiedAppDAO, HashMap<String, SimplifiedPkgInfo> hashMap, boolean z) {
        ArrayList arrayList = new ArrayList();
        ArrayList arrayList2 = new ArrayList();
        ArrayList<AppInfo> arrayList3 = new ArrayList<>();
        for (SimplifiedPkgInfo simplifiedPkgInfo : list) {
            Callable populateApkFilePkgInfoTask = z ? new PopulateApkFilePkgInfoTask(this.a, simplifiedPkgInfo) : new PopulatePkgInfoTask(simplifiedPkgInfo);
            try {
            } catch (NullPointerException e2) {
                e2.getMessage();
            } catch (RejectedExecutionException e3) {
                e3.getMessage();
            } catch (Exception e4) {
                e4.getMessage();
            } catch (Throwable th) {
                th.getMessage();
            }
            if (!executorService.isShutdown() && !executorService.isTerminated()) {
                if ((new File(simplifiedPkgInfo.getApkPath()).length() / 1024) / 1024 > a(this.a)) {
                    simplifiedPkgInfo.getApkPath();
                } else {
                    simplifiedPkgInfo.getApkPath();
                    arrayList.add(executorService.submit(populateApkFilePkgInfoTask));
                }
            }
            a(7, (Object) 0);
            return null;
        }
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            Future future = (Future) it.next();
            try {
            } catch (InterruptedException e5) {
                e5.getMessage();
            } catch (ExecutionException e6) {
                e6.getMessage();
            } catch (Exception e7) {
                e7.getMessage();
            }
            if (this.j.booleanValue()) {
                executorService.shutdownNow();
                a(7, (Object) 0);
                return null;
            }
            PkgInfo pkgInfo = (PkgInfo) future.get();
            if (pkgInfo != null) {
                arrayList2.add(pkgInfo);
                a(simplifiedAppDAO, pkgInfo, hashMap);
                pkgInfo.getPkgName();
                pkgInfo.getMd5();
            }
        }
        ScanResult cloudScan = cloudScan(arrayList2, z);
        if (cloudScan != null && cloudScan.getList() != null) {
            arrayList3.addAll(cloudScan.getList());
            cloudScan.getList().size();
        } else if (cloudScan != null && !cloudScan.isSuccess()) {
            a(4, Integer.valueOf(cloudScan.getError()));
            return null;
        }
        return arrayList3;
    }

    private void a(SimplifiedAppDAO simplifiedAppDAO, PkgInfo pkgInfo, HashMap<String, SimplifiedPkgInfo> hashMap) {
        SimplifiedPkgInfo simplifiedPkgInfo;
        if (simplifiedAppDAO.getPkgInfoFromDB(pkgInfo.getPkgPath()) == null) {
            String pkgPath = pkgInfo.getPkgPath();
            Iterator<Map.Entry<String, SimplifiedPkgInfo>> it = hashMap.entrySet().iterator();
            while (true) {
                if (!it.hasNext()) {
                    simplifiedPkgInfo = null;
                    break;
                }
                Map.Entry<String, SimplifiedPkgInfo> next = it.next();
                if (next.getKey().equalsIgnoreCase(pkgPath)) {
                    Objects.toString(next.getValue());
                    simplifiedPkgInfo = next.getValue();
                    break;
                }
            }
            if (simplifiedPkgInfo != null) {
                simplifiedPkgInfo.setMd5(pkgInfo.getMd5());
                simplifiedAppDAO.insertSimplifiedApp(pkgInfo.getPkgPath(), simplifiedPkgInfo.toJSON().toString());
            }
        }
    }

    public void a(PkgInfo pkgInfo, boolean z) {
        PackageInfo packageArchiveInfo;
        String pkgName = pkgInfo.getPkgName();
        new ArrayList();
        try {
            CertificateFactory certificateFactory = CertificateFactory.getInstance("X509");
            PackageManager packageManager = this.a.getPackageManager();
            if (!z) {
                packageArchiveInfo = packageManager.getPackageInfo(pkgName, 64);
            } else {
                packageArchiveInfo = packageManager.getPackageArchiveInfo(pkgInfo.getPkgPath(), 64);
            }
            if (packageArchiveInfo != null) {
                pkgInfo.setPkgName(packageArchiveInfo.packageName);
                pkgInfo.setPkgPath(packageArchiveInfo.applicationInfo.publicSourceDir);
                pkgInfo.setVersionCode(packageArchiveInfo.versionCode);
                pkgInfo.setVersionName(packageArchiveInfo.versionName);
                pkgInfo.setAppName(packageManager.getApplicationLabel(packageArchiveInfo.applicationInfo).toString());
                ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(packageArchiveInfo.signatures[0].toByteArray());
                X509Certificate x509Certificate = (X509Certificate) certificateFactory.generateCertificate(byteArrayInputStream);
                MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
                messageDigest.update(x509Certificate.getEncoded());
                pkgInfo.setCertSha1(PkgUtils.formatHexComma(messageDigest.digest()));
                byteArrayInputStream.close();
            }
        } catch (PackageManager.NameNotFoundException e2) {
            Log.e("TL", trustlook_cloudscan.c.a("populateApkCertificate Package name not found: ").append(e2.getMessage()).toString());
        } catch (CertificateException e3) {
            Log.e("TL", trustlook_cloudscan.c.a("populateApkCertificate certificate error: ").append(e3.getMessage()).toString());
        } catch (Exception e4) {
            trustlook_cloudscan.a.a(e4, trustlook_cloudscan.c.a("populateApkCertificate error: "), "TL");
        }
    }

    private static String a(File file, String str) {
        try {
            MessageDigest messageDigest = MessageDigest.getInstance(str);
            try {
                FileInputStream fileInputStream = new FileInputStream(file);
                byte[] bArr = new byte[8192];
                while (true) {
                    try {
                        try {
                            int read = fileInputStream.read(bArr);
                            if (read <= 0) {
                                break;
                            }
                            messageDigest.update(bArr, 0, read);
                        } catch (IOException e2) {
                            throw new RuntimeException("Unable to process file for MD5", e2);
                        }
                    } finally {
                        try {
                            fileInputStream.close();
                        } catch (IOException e3) {
                            Log.e("TL", "Exception on closing MD5 input stream " + e3);
                        }
                    }
                }
                return String.format("%32s", new BigInteger(1, messageDigest.digest()).toString(16)).replace(' ', '0').toUpperCase(Locale.US);
            } catch (FileNotFoundException e4) {
                Log.e("TL", "Exception while getting FileInputStream", e4);
                return null;
            }
        } catch (NoSuchAlgorithmException e5) {
            Log.e("TL", "Exception while getting Digest", e5);
            return null;
        }
    }

    private void a(JSONObject jSONObject) throws JSONException {
        JSONObject jSONObject2 = new JSONObject();
        try {
            Context context = this.a;
            if (context != null) {
                Objects.toString(context.getResources().getConfiguration().locale);
                Locale locale = this.a.getResources().getConfiguration().locale;
                if (locale != null) {
                    jSONObject2.put("lc", locale.toString().toLowerCase());
                } else {
                    jSONObject2.put("lc", Locale.US.toString().toLowerCase());
                }
            }
            String str = Build.MODEL;
            if (str != null) {
                jSONObject2.put("mod", str);
            }
            String str2 = Build.VERSION.RELEASE;
            if (str2 != null) {
                jSONObject2.put("os", str2);
            }
            String str3 = Build.VERSION.SECURITY_PATCH;
            if (str3 != null) {
                jSONObject2.put("pat", str3);
            }
            if (CloudUtil.getAndroidId(this.a) != null) {
                jSONObject2.put("di", CloudUtil.getAndroidId(this.a));
            }
        } catch (JSONException unused) {
        }
        jSONObject.put("info", jSONObject2);
    }

    public int a(Exception exc) {
        int i = 2;
        if (exc instanceof com.trustlook.sdk.cloudscan.b) {
            com.trustlook.sdk.cloudscan.b bVar = (com.trustlook.sdk.cloudscan.b) exc;
            Log.e("TL", trustlook_cloudscan.c.a("========== HTTP_REQUEST_EXCEPTION: ").append(bVar.a).append(" ========").toString());
            int i2 = bVar.a;
            if (i2 == 403) {
                i = 8;
            } else if (i2 != 406) {
                i = (i2 == 504 || i2 == 502) ? 9 : i2;
            }
            trustlook_cloudscan.a.a(exc, trustlook_cloudscan.c.a("handleExceptions HttpRequestException: "), "TL");
            return i;
        }
        if (exc instanceof JSONException) {
            Log.e("TL", "========== JSON_EXCEPTION ========");
            trustlook_cloudscan.a.a(exc, new StringBuilder().append("handleExceptions JSON_EXCEPTION: "), "TL");
            return 4;
        }
        if (exc instanceof UnknownHostException) {
            Log.e("TL", "========== NO NETWORK ========");
            trustlook_cloudscan.a.a(exc, new StringBuilder().append("handleExceptions NO_NETWORK: "), "TL");
            return 6;
        }
        if (exc instanceof SocketTimeoutException) {
            Log.e("TL", "========== SOCKET TIMEOUT EXCEPTION ========");
            trustlook_cloudscan.a.a(exc, new StringBuilder().append("handleExceptions SOCKET_TIMEOUT_EXCEPTION: "), "TL");
            return 7;
        }
        if (exc instanceof com.trustlook.sdk.cloudscan.c) {
            Log.e("TL", "========== INVALID INPUT EXCEPTION ========");
            trustlook_cloudscan.a.a(exc, new StringBuilder().append("handleExceptions INVALID_INPUT: "), "TL");
            return 2;
        }
        if (exc instanceof IOException) {
            Log.e("TL", "========== IO EXCEPTION ========");
            exc.printStackTrace();
            trustlook_cloudscan.a.a(exc, new StringBuilder().append("handleExceptions IO_EXCEPTION: "), "TL");
            return 5;
        }
        Log.e("TL", "========== UNKNOWN ERROR ========");
        exc.printStackTrace();
        trustlook_cloudscan.a.a(exc, new StringBuilder().append("handleExceptions UNKNOWN_ERROR: "), "TL");
        return 0;
    }

    private boolean a(String str, String str2, String str3, String str4, String str5) {
        try {
        } catch (IOException e2) {
            e2.getMessage();
        }
        if (new File(str).length() > 500) {
            return false;
        }
        byte[] bArr = new byte[512];
        FileInputStream fileInputStream = new FileInputStream(str);
        if (fileInputStream.read(bArr) != -1) {
            if (KPM.indexOf(bArr, str2.getBytes()) > -1) {
                if (KPM.indexOf(bArr, str3.getBytes()) > -1) {
                    if (KPM.indexOf(bArr, str4.getBytes()) > -1) {
                        if (KPM.indexOf(bArr, str5.getBytes()) > -1) {
                            fileInputStream.close();
                            return true;
                        }
                        fileInputStream.close();
                        return false;
                    }
                    fileInputStream.close();
                    return false;
                }
                fileInputStream.close();
                return false;
            }
            fileInputStream.close();
            return false;
        }
        fileInputStream.close();
        return false;
    }

    private void a(AppInfo appInfo) {
        if (appInfo.getScore() <= 7) {
            appInfo.getMd5();
            appInfo.getScore();
            appInfo.getApkPath();
            if (appInfo.getApkPath() != null && !appInfo.getApkPath().isEmpty()) {
                if (a(appInfo.getApkPath(), CloudUtil.aesDecryptString(Constants.ENCRYPE_STRING_1), CloudUtil.aesDecryptString(Constants.ENCRYPE_STRING_2), CloudUtil.aesDecryptString(Constants.ENCRYPE_STRING_3), CloudUtil.aesDecryptString(Constants.ENCRYPE_STRING_4))) {
                    appInfo.setScore(8);
                    appInfo.setVirusName("EICAR-Test-File (not a virus)");
                    appInfo.getMd5();
                    appInfo.getScore();
                    appInfo.getApkPath();
                    return;
                }
                return;
            }
            appInfo.getMd5();
        }
    }

    private String a() {
        try {
            CertificateFactory certificateFactory = CertificateFactory.getInstance("X509");
            Signature[] signatureArr = this.a.getPackageManager().getPackageInfo(this.a.getPackageName(), 64).signatures;
            if (signatureArr.length <= 0) {
                return null;
            }
            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(signatureArr[0].toByteArray());
            X509Certificate x509Certificate = (X509Certificate) certificateFactory.generateCertificate(byteArrayInputStream);
            AppCertificate appCertificate = new AppCertificate();
            appCertificate.setPemIssuer(x509Certificate.getIssuerDN().toString());
            appCertificate.setPemStartDate(x509Certificate.getNotBefore().getTime() / 1000);
            appCertificate.setPemExpiredDate(x509Certificate.getNotAfter().getTime() / 1000);
            appCertificate.setPemSerialNumber(x509Certificate.getSerialNumber().toString(16));
            MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
            messageDigest.update(x509Certificate.getEncoded());
            byte[] digest = messageDigest.digest();
            byteArrayInputStream.close();
            return PkgUtils.formatHexComma(digest);
        } catch (Exception unused) {
            return null;
        }
    }

    static void a(CloudScanClient cloudScanClient) {
        CloudScanListener cloudScanListener = cloudScanClient.h;
        if (cloudScanListener != null) {
            cloudScanListener.onScanStarted();
        }
    }

    static void a(CloudScanClient cloudScanClient, int i, String str) {
        CloudScanListener cloudScanListener = cloudScanClient.h;
        if (cloudScanListener != null) {
            cloudScanListener.onScanError(i, str);
        }
        cloudScanClient.h = null;
    }

    static void a(CloudScanClient cloudScanClient, int i, int i2, AppInfo appInfo) {
        if (cloudScanClient.h == null || cloudScanClient.j.booleanValue()) {
            return;
        }
        cloudScanClient.h.onScanProgress(i, i2, appInfo);
    }

    public void a(int i, Object obj) {
        Message message = new Message();
        message.what = i;
        message.obj = obj;
        this.m.sendMessage(message);
    }

    private static long a(Context context) {
        ActivityManager activityManager = (ActivityManager) context.getSystemService("activity");
        ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
        activityManager.getMemoryInfo(memoryInfo);
        return (memoryInfo.availMem / 1024) / 1024;
    }
}