package g.i.a.c.l.e;

import g.h.a.i;
import g.i.a.c.b;
import io.netty.handler.codec.dns.DnsRecord;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Locale;

/* JADX INFO: loaded from: classes.dex */
public abstract class a extends BufferedInputStream {

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static int f5561f = 1;
    public int A;
    public String B;
    public int C;
    public int D;
    public byte E;
    public short F;
    public byte[] G;
    public byte[] H;
    public final int I;
    public int J;
    public int K;
    public int L;
    public int M;
    public int N;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public boolean f5562m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public final byte[] f5563n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public List<g.i.a.c.i.a> f5564o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public int f5565p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public int f5566q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final byte[] f5567r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public int f5568s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public byte f5569t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public int f5570u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public boolean f5571v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public int f5572w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public int f5573x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public int f5574y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public int f5575z;

    public a(InputStream inputStream) throws IOException {
        super(new BufferedInputStream(inputStream));
        this.f5562m = true;
        this.f5568s = 0;
        this.f5574y = 0;
        this.K = 1;
        this.L = 1;
        this.M = DnsRecord.CLASS_NONE;
        this.N = 1;
        this.f5562m = b.a;
        this.I = 20;
        byte[] bArr = new byte[512];
        this.f5563n = bArr;
        byte[] bArr2 = new byte[12];
        this.f5567r = bArr2;
        this.G = new byte[12];
        this.J = 0;
        if (f5561f != 1 || !markSupported()) {
            read(bArr2, 0, 12);
            if (bArr2[0] == 1 && bArr2[1] == 0 && bArr2[2] == 2) {
                System.arraycopy(bArr2, 0, bArr, 0, 12);
                read(bArr, 12, 500);
                c();
                read(bArr2, 0, 12);
            }
            boolean z2 = this instanceof g.i.a.c.j.a;
            i.V3(false, String.format(Locale.US, "isNeedReadDfuHeader()=%b, available()=%d", Boolean.valueOf(z2), Integer.valueOf(available())));
            if (!z2 || available() < 316) {
                System.arraycopy(bArr2, 0, this.G, 0, 12);
            } else {
                byte[] bArr3 = new byte[304];
                System.arraycopy(bArr2, 0, bArr3, 0, 12);
                read(bArr3, 12, 292);
                read(this.G, 0, 12);
                a();
            }
            d();
            return;
        }
        mark(0);
        read(bArr, 0, 512);
        c();
        List<g.i.a.c.i.a> list = this.f5564o;
        if (!(list != null && list.size() > 0)) {
            i.V3(false, "reset to begin");
            reset();
        }
        boolean z3 = this instanceof g.i.a.c.j.a;
        i.V3(false, String.format(Locale.US, "isNeedReadDfuHeader()=%b, available()=%d", Boolean.valueOf(z3), Integer.valueOf(available())));
        if (!z3 || available() < 316) {
            read(bArr2, 0, 12);
            System.arraycopy(bArr2, 0, this.G, 0, 12);
        } else {
            mark(0);
            try {
                skip(304L);
            } catch (IOException unused) {
                i.W3("skip error");
            }
            read(this.G, 0, 12);
            a();
            reset();
            read(this.f5567r, 0, 12);
        }
        d();
    }

    public void a() {
    }

    /* JADX WARN: Removed duplicated region for block: B:145:0x0098 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:148:0x0095 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:64:0x00d3  */
    /* JADX WARN: Removed duplicated region for block: B:65:0x00e6  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void c() {
        /*
            Method dump skipped, instruction units count: 784
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: g.i.a.c.l.e.a.c():void");
    }

    public void d() {
    }

    public void e() {
        try {
            int i2 = this.f5569t == 11 ? 260 : 360;
            int i3 = i2 + 32;
            byte[] bArr = new byte[i3];
            read(bArr, 0, i3);
            byte[] bArr2 = new byte[32];
            this.H = bArr2;
            System.arraycopy(bArr, i2, bArr2, 0, 32);
            i.V3(false, "sha256=" + i.y(this.H));
        } catch (Exception e2) {
            i.D0(e2.toString());
        }
    }

    public int g(byte[] bArr, int i2) throws IOException {
        int i3 = read(bArr, 0, i2);
        if (i3 > 0) {
            this.J += i3;
        }
        return i3;
    }

    public int h() {
        return this.f5573x - this.J;
    }

    @Override // java.io.BufferedInputStream, java.io.FilterInputStream, java.io.InputStream
    public int read() {
        throw new UnsupportedOperationException("Use readPacket() method instead");
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public int read(byte[] bArr) {
        return g(bArr, bArr.length);
    }

    @Override // java.io.BufferedInputStream, java.io.FilterInputStream, java.io.InputStream
    public synchronized void reset() {
        super.reset();
        this.J = 0;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        Locale locale = Locale.US;
        sb.append(String.format(locale, "otaVersion=0x%02X, icType=0x%02X, imageId=0x%04X,binId=0x%04X, imageVersion=0x%08X, imageSize=0x%08X(%d)", Integer.valueOf(this.f5568s), Byte.valueOf(this.f5569t), Integer.valueOf(this.f5570u), Integer.valueOf(this.f5575z), Integer.valueOf(this.f5572w), Integer.valueOf(this.f5573x), Integer.valueOf(this.f5573x)));
        sb.append(String.format(locale, ", sha256=%s, activeCompareVersionFlag=%d, inactiveCompareVersionFlag=%d,otaTempBufferCheckOrder=%d", i.y(this.H), Integer.valueOf(this.K), Integer.valueOf(this.L), Integer.valueOf(this.N)));
        return sb.toString();
    }
}
