e.java 源代码


package t1;

import android.content.Context;
import android.os.Build;
import com.x8zs.plugin.utils.FileUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class e {

    private static List<String> f26303a = new ArrayList();

    private static File a(Context context) {
        if (context != null && context.getFilesDir() != null) {
            File file = new File(context.getFilesDir(), "libso");
            if (!file.exists()) {
                b.d(file.getAbsolutePath());
            }
            return file;
        }
        return null;
    }

    private static String b(Context context, String str, File file) {
        InputStream inputStream;
        ZipFile zipFile;
        String message;
        String str2;
        ZipEntry entry;
        FileOutputStream fileOutputStream = null;
        try {
            zipFile = new ZipFile(new File(context.getApplicationInfo().sourceDir), 1);
            try {
                StringBuilder sb = new StringBuilder();
                sb.append("lib/");
                str2 = Build.CPU_ABI;
                sb.append(str2);
                sb.append("/");
                sb.append(System.mapLibraryName(str));
                entry = zipFile.getEntry(sb.toString());
            } catch (Throwable th) {
                th = th;
                inputStream = null;
            }
        } catch (Throwable th2) {
            th = th2;
            inputStream = null;
            zipFile = null;
        }
        if (entry == null) {
            int indexOf = str2.indexOf(45);
            StringBuilder sb2 = new StringBuilder();
            sb2.append("lib/");
            if (indexOf <= 0) {
                indexOf = str2.length();
            }
            sb2.append(str2.substring(0, indexOf));
            sb2.append("/");
            sb2.append(System.mapLibraryName(str));
            String sb3 = sb2.toString();
            ZipEntry entry2 = zipFile.getEntry(sb3);
            if (entry2 == null) {
                message = "Library entry not found:" + sb3;
                b.a(null);
                b.a(null);
                b.c(zipFile);
                return message;
            }
            entry = entry2;
        }
        file.createNewFile();
        InputStream inputStream2 = zipFile.getInputStream(entry);
        try {
            FileOutputStream fileOutputStream2 = new FileOutputStream(file);
            try {
                byte[] bArr = new byte[16384];
                while (true) {
                    int read = inputStream2.read(bArr);
                    if (read > 0) {
                        fileOutputStream2.write(bArr, 0, read);
                    } else {
                        b.b(file.getAbsolutePath(), FileUtils.FileMode.MODE_755);
                        b.a(fileOutputStream2);
                        b.a(inputStream2);
                        b.c(zipFile);
                        return null;
                    }
                }
            } catch (Throwable th3) {
                fileOutputStream = fileOutputStream2;
                inputStream = inputStream2;
                th = th3;
                try {
                    message = th.getMessage();
                    b.a(fileOutputStream);
                    b.a(inputStream);
                    b.c(zipFile);
                    return message;
                } catch (Throwable th4) {
                    b.a(fileOutputStream);
                    b.a(inputStream);
                    b.c(zipFile);
                    throw th4;
                }
            }
        } catch (Throwable th5) {
            inputStream = inputStream2;
            th = th5;
        }
    }

    public static synchronized boolean c(Context context, String str) {
        synchronized (e.class) {
            if (f26303a.contains(str)) {
                return true;
            }
            try {
                System.loadLibrary(str);
                f26303a.add(str);
            } catch (UnsatisfiedLinkError unused) {
                File d6 = d(context, str);
                if (d6 == null) {
                    return false;
                }
                if (d6.exists()) {
                    d6.delete();
                }
                if (b(context, str, d6) != null) {
                    return false;
                }
                try {
                    System.load(d6.getAbsolutePath());
                    f26303a.add(str);
                } catch (Throwable unused2) {
                    return false;
                }
            } catch (Throwable unused3) {
                return false;
            }
            return true;
        }
    }

    private static File d(Context context, String str) {
        String mapLibraryName = System.mapLibraryName(str);
        File a7 = a(context);
        if (a7 != null) {
            return new File(a7, mapLibraryName);
        }
        return null;
    }
}