翰林优商.apk(点击下载) / ay.java


package com.baidu.mobads.sdk.internal;

import android.content.Context;
import android.os.Build;
import android.util.Base64;
import com.baidu.mobads.sdk.internal.bf;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
import java.security.DigestInputStream;
import java.security.KeyFactory;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import javax.crypto.Cipher;
import kotlin.UByte;

public class ay extends File {
    public static final String a = "LocalApkFile";
    private static final long b = 6916965592955692235L;
    private static ClassLoader h;
    private bd c;
    private Class<?> d;
    private Context e;
    private PublicKey f;
    private az g;

    public ay(String str, Context context) {
        this(str, context, null);
    }

    public ay(String str, Context context, bd bdVar) {
        super(str);
        this.d = null;
        this.e = null;
        this.g = az.a();
        this.e = context;
        this.c = bdVar;
        if (bdVar != null) {
            try {
                this.f = c("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDBcp8gg3O7bjdnz+pSxg+JH/mbcKfm7dEjcRqVNAFwG7bTpLwDQh40bZJzrcBKQWbD6kArR6TPuQUCMQ09/y55Vk1P2Kq7vJGGisFpjlqv2qlg8drLdhXkLQUt/SeZVJgT+CNxVbuzxAF61EEf8M0MHi1I2dm6n6lOA6fomiCD9wIDAQAB");
            } catch (Exception unused) {
                this.f = null;
            }
        }
    }

    /* access modifiers changed from: protected */
    public void a() {
        if (this.c != null) {
            String a2 = a(new File(getAbsolutePath()));
            String b2 = b(this.c.d());
            if (!b2.equalsIgnoreCase(a2)) {
                throw new bf.a("doCheckApkIntegrity failed, md5sum: " + a2 + ", checksum in json info: " + b2);
            }
            return;
        }
        this.g.a(a, "built-in apk, no need to check");
    }

    /* access modifiers changed from: protected */
    public Class<?> b() {
        if (this.d == null) {
            File file = new File(getAbsolutePath());
            try {
                this.d = b(file);
            } catch (Exception unused) {
                file.delete();
            }
        }
        return this.d;
    }

    /* access modifiers changed from: protected */
    public void a(String str) {
        renameTo(new File(str));
    }

    /* access modifiers changed from: protected */
    public double c() {
        bd bdVar = this.c;
        if (bdVar == null) {
            return 0.0d;
        }
        return bdVar.b();
    }

    private String b(String str) {
        if (this.f == null) {
            return null;
        }
        byte[] decode = Base64.decode(str, 0);
        try {
            Cipher instance = Cipher.getInstance("RSA/ECB/PKCS1Padding");
            instance.init(2, this.f);
            return new String(instance.doFinal(decode), "UTF-8").trim();
        } catch (Exception e2) {
            this.g.c("ErrorWhileVerifySigNature", e2);
            return null;
        }
    }

    private static PublicKey c(String str) {
        try {
            return KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(Base64.decode(str, 0)));
        } catch (NoSuchAlgorithmException unused) {
            throw new Exception("NoSuchAlgorithmException");
        } catch (InvalidKeySpecException unused2) {
            throw new Exception("InvalidKeySpecException");
        } catch (NullPointerException unused3) {
            throw new Exception("NullPointerException");
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:28:0x0071 A[SYNTHETIC, Splitter:B:28:0x0071] */
    /* JADX WARNING: Removed duplicated region for block: B:33:0x0082 A[SYNTHETIC, Splitter:B:33:0x0082] */
    /* JADX WARNING: Removed duplicated region for block: B:41:? A[RETURN, SYNTHETIC] */
    private String a(File file) {
        Throwable th;
        Exception e2;
        FileInputStream fileInputStream = null;
        try {
            FileInputStream fileInputStream2 = new FileInputStream(file);
            try {
                MessageDigest instance = MessageDigest.getInstance("MD5");
                while (new DigestInputStream(fileInputStream2, instance).read(new byte[4096]) != -1) {
                }
                byte[] digest = instance.digest();
                String str = "";
                for (int i = 0; i < digest.length; i++) {
                    str = str + Integer.toString((digest[i] & UByte.MAX_VALUE) + 256, 16).substring(1);
                }
                try {
                    fileInputStream2.close();
                } catch (Exception e3) {
                    this.g.a(a, e3.getMessage());
                }
                return str;
            } catch (Exception e4) {
                e2 = e4;
                fileInputStream = fileInputStream2;
                try {
                    this.g.a(a, e2.getMessage());
                    if (fileInputStream != null) {
                        return "";
                    }
                    try {
                        fileInputStream.close();
                        return "";
                    } catch (Exception e5) {
                        this.g.a(a, e5.getMessage());
                        return "";
                    }
                } catch (Throwable th2) {
                    th = th2;
                    if (fileInputStream != null) {
                        try {
                            fileInputStream.close();
                        } catch (Exception e6) {
                            this.g.a(a, e6.getMessage());
                        }
                    }
                    throw th;
                }
            } catch (Throwable th3) {
                th = th3;
                fileInputStream = fileInputStream2;
                if (fileInputStream != null) {
                }
                throw th;
            }
        } catch (Exception e7) {
            e2 = e7;
            this.g.a(a, e2.getMessage());
            if (fileInputStream != null) {
            }
        }
    }

    private void d() {
        File[] listFiles = this.e.getFilesDir().listFiles(new a());
        int i = 0;
        while (listFiles != null && i < listFiles.length) {
            if (listFiles[i].getAbsolutePath().contains("__xadsdk__remote__final__")) {
                az azVar = this.g;
                azVar.a(a, "clearDexCacheFiles-->" + i + "--" + listFiles[i].getAbsolutePath());
                listFiles[i].delete();
            }
            i++;
        }
    }

    private Class<?> b(File file) {
        Class<?> cls;
        az azVar = this.g;
        azVar.a(a, "Android version:" + Build.VERSION.RELEASE);
        Class<?> cls2 = null;
        try {
            synchronized (bf.class) {
                String absolutePath = file.getAbsolutePath();
                ClassLoader classLoader = getClass().getClassLoader();
                String absolutePath2 = this.e.getFilesDir().getAbsolutePath();
                String str = r.au;
                h = af.a(absolutePath, absolutePath2, null, classLoader);
                az azVar2 = this.g;
                azVar2.a(a, "dexPath=" + absolutePath + ", cl=" + classLoader + ", dir=" + absolutePath2 + ", len=" + file.length() + ", list=" + file.list());
                cls = Class.forName(str, true, h);
            }
            cls2 = cls;
        } catch (Exception e2) {
            this.g.a(a, e2.getMessage());
        }
        az azVar3 = this.g;
        azVar3.a(a, "jar.path=" + file.getAbsolutePath() + ", clz=" + cls2);
        return cls2;
    }

    public static ClassLoader a(Context context) {
        ClassLoader classLoader = h;
        if (classLoader != null) {
            return classLoader;
        }
        return aj.a(context.getApplicationContext());
    }

    class a implements FilenameFilter {
        public boolean accept(File file, String str) {
            return true;
        }

        a() {
        }
    }
}