package com.pgl.ssdk;

import com.bytedance.adsdk.ugeno.yoga.YFl.KJ.lnwyDuIkf;
import java.io.Closeable;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.zip.ZipFile;
/* renamed from: com.pgl.ssdk.c  reason: case insensitive filesystem */
/* loaded from: classes8.dex */
public abstract class AbstractC1464c {

    /* renamed from: com.pgl.ssdk.c$a */
    /* loaded from: classes6.dex */
    public static class a extends C1477p {
        public a(long j, long j2, int i, long j3, ByteBuffer byteBuffer) {
            super(j, j2, i, j3, byteBuffer);
        }
    }

    public static void a(Runnable runnable) {
        Q c = M.a().c();
        if (c != null) {
            c.post(runnable);
        }
    }

    public static a a(InterfaceC1475n interfaceC1475n) throws IOException, C1476o {
        C1473l<ByteBuffer, Long> a2 = AbstractC1474m.a(interfaceC1475n);
        if (a2 != null) {
            ByteBuffer a3 = a2.a();
            long longValue = a2.b().longValue();
            a3.order(ByteOrder.LITTLE_ENDIAN);
            long b = AbstractC1474m.b(a3);
            if (b <= longValue) {
                long c = AbstractC1474m.c(a3);
                long j = b + c;
                if (j <= longValue) {
                    C1477p c1477p = new C1477p(b, c, AbstractC1474m.d(a3), longValue, a3);
                    return new a(c1477p.a(), c1477p.c(), c1477p.b(), c1477p.e(), c1477p.d());
                }
                throw new C1476o("ZIP Central Directory overlaps with End of Central Directory. CD end: " + j + ", EoCD start: " + longValue);
            }
            throw new C1476o("ZIP Central Directory start offset out of range: " + b + ". ZIP End of Central Directory offset: " + longValue);
        }
        throw new C1476o("ZIP End of Central Directory record not found");
    }

    public static C1465d a(InterfaceC1475n interfaceC1475n, C1477p c1477p) throws IOException, C1463b {
        long a2 = c1477p.a();
        long c = c1477p.c() + a2;
        long e = c1477p.e();
        if (c == e) {
            if (a2 >= 32) {
                C1472k c1472k = (C1472k) interfaceC1475n;
                ByteBuffer a3 = c1472k.a(a2 - 24, 24);
                a3.order(ByteOrder.LITTLE_ENDIAN);
                if (a3.getLong(8) == 2334950737559900225L && a3.getLong(16) == 3617552046287187010L) {
                    long j = a3.getLong(0);
                    if (j < a3.capacity() || j > 2147483639) {
                        throw new C1463b("APK Signing Block size out of range: ".concat(String.valueOf(j)));
                    }
                    long j2 = (int) (8 + j);
                    long j3 = a2 - j2;
                    if (j3 >= 0) {
                        ByteBuffer a4 = c1472k.a(j3, 8);
                        a4.order(ByteOrder.LITTLE_ENDIAN);
                        long j4 = a4.getLong(0);
                        if (j4 == j) {
                            return new C1465d(j3, c1472k.a(j3, j2));
                        }
                        throw new C1463b("APK Signing Block sizes in header and footer do not match: " + j4 + " vs " + j);
                    }
                    throw new C1463b("APK Signing Block offset out of range: ".concat(String.valueOf(j3)));
                }
                throw new C1463b("No APK Signing Block before ZIP Central Directory");
            }
            throw new C1463b(lnwyDuIkf.Nokmgtf.concat(String.valueOf(a2)));
        }
        throw new C1463b("ZIP Central Directory is not immediately followed by End of Central Directory. CD end: " + c + ", EoCD start: " + e);
    }

    public static void a(Closeable closeable) {
        if (closeable == null) {
            return;
        }
        try {
            closeable.close();
        } catch (IOException unused) {
        }
    }

    public static void a(ZipFile zipFile) {
        if (zipFile == null) {
            return;
        }
        try {
            zipFile.close();
        } catch (IOException unused) {
        }
    }
}
