package V;

import b0.o;
import com.seewo.sdk.model.SDKKeyboardCode;
import okhttp3.HttpUrl;

/* JADX INFO: loaded from: classes.dex */
public class c {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private I.a f1715a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    String f1716b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    a f1717c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    boolean f1718d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    int f1719e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    int f1720f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    int f1721g;

    class a {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        int f1722a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        String f1723b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        b f1724c;

        a() {
        }

        public long a(I.a aVar, long j2) throws Exception {
            o.d("PacketParser", "start PESPacketData offset = " + j2, 16);
            long j3 = 1 + j2;
            try {
                int iA = aVar.a(j2);
                this.f1722a = iA;
                c.this.c(16, 31, iA & 255);
                b bVar = c.this.new b();
                this.f1724c = bVar;
                long jA = bVar.a(aVar, j3);
                this.f1723b = this.f1724c.f1735j;
                o.d("PacketParser", "page loop  offset = " + jA + ", packetTxt: " + this.f1723b, 16);
                StringBuilder sb = new StringBuilder();
                sb.append(HttpUrl.FRAGMENT_ENCODE_SET);
                sb.append(this);
                o.d("PacketParser", sb.toString(), 16);
                return jA;
            } catch (Exception e2) {
                e2.printStackTrace();
                throw e2;
            }
        }
    }

    /* JADX INFO: renamed from: V.c$c, reason: collision with other inner class name */
    class C0042c extends b {

        /* JADX INFO: renamed from: m, reason: collision with root package name */
        byte[] f1738m;

        /* JADX INFO: renamed from: n, reason: collision with root package name */
        char[] f1739n;

        public C0042c(b bVar) {
            super(bVar);
            this.f1738m = new byte[40];
            this.f1739n = new char[40];
        }

        @Override // V.c.b
        public long a(I.a aVar, long j2) {
            o.d("PageDisplay", "showLanguage = " + c.this.f1721g + " optLanguage = " + this.f1731f, 16);
            int i2 = 0;
            long j3 = j2;
            while (i2 < 40) {
                try {
                    byte[] bArr = this.f1738m;
                    long j4 = 1 + j3;
                    byte b2 = V.a.b(this.f1734i, aVar.a(j3));
                    byte b3 = SDKKeyboardCode.FUNCTION_KEY_BOARD_3;
                    if (b2 >= 32) {
                        b3 = b2;
                    }
                    bArr[i2] = b3;
                    if (c.this.f1721g != 2 && this.f1731f != 2) {
                        this.f1739n[i2] = (char) this.f1738m[i2];
                    } else if (b2 == 36) {
                        this.f1739n[i2] = 164;
                    } else if (b2 == 64) {
                        this.f1739n[i2] = 201;
                    } else if (b2 == 91) {
                        this.f1739n[i2] = 196;
                    } else if (b2 == 92) {
                        this.f1739n[i2] = 214;
                    } else if (b2 == 93) {
                        this.f1739n[i2] = 197;
                    } else if (b2 == 94) {
                        this.f1739n[i2] = 220;
                    } else if (b2 == 96) {
                        this.f1739n[i2] = 233;
                    } else if (b2 == 123) {
                        this.f1739n[i2] = 228;
                    } else if (b2 == 124) {
                        this.f1739n[i2] = 246;
                    } else if (b2 == 125) {
                        this.f1739n[i2] = 229;
                    } else if (b2 == 126) {
                        this.f1739n[i2] = 252;
                    } else {
                        this.f1739n[i2] = (char) this.f1738m[i2];
                    }
                    o.d("PageDisplay", "display page data " + i2 + " = " + ((int) this.f1738m[i2]), 16);
                    i2++;
                    j3 = j4;
                } catch (Exception unused) {
                    return j2;
                }
            }
            o.d("PageDisplay", "display page txt= " + new String(this.f1739n), 16);
            return j3;
        }
    }

    class d extends b {

        /* JADX INFO: renamed from: m, reason: collision with root package name */
        byte f1741m;

        /* JADX INFO: renamed from: n, reason: collision with root package name */
        byte f1742n;

        /* JADX INFO: renamed from: o, reason: collision with root package name */
        byte f1743o;

        /* JADX INFO: renamed from: p, reason: collision with root package name */
        byte f1744p;

        /* JADX INFO: renamed from: q, reason: collision with root package name */
        byte f1745q;

        /* JADX INFO: renamed from: r, reason: collision with root package name */
        byte f1746r;

        /* JADX INFO: renamed from: s, reason: collision with root package name */
        byte f1747s;

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

        /* JADX INFO: renamed from: u, reason: collision with root package name */
        byte f1749u;

        /* JADX INFO: renamed from: v, reason: collision with root package name */
        byte f1750v;

        /* JADX INFO: renamed from: w, reason: collision with root package name */
        byte f1751w;

        /* JADX INFO: renamed from: x, reason: collision with root package name */
        byte[] f1752x;

        public d(b bVar) {
            super(bVar);
            this.f1752x = new byte[32];
        }

        @Override // V.c.b
        public long a(I.a aVar, long j2) {
            o.d("PageHeader", "page parserBuffer off = " + j2, 16);
            try {
                this.f1741m = V.a.a(this.f1734i, aVar.a(j2));
                this.f1742n = V.a.a(this.f1734i, aVar.a(j2 + 1));
                this.f1743o = V.a.a(this.f1734i, aVar.a(2 + j2));
                byte bA = V.a.a(this.f1734i, aVar.a(3 + j2));
                this.f1744p = (byte) (bA & 7);
                this.f1747s = (byte) ((bA >> 3) & 1);
                this.f1745q = V.a.a(this.f1734i, aVar.a(4 + j2));
                byte bA2 = V.a.a(this.f1734i, aVar.a(5 + j2));
                this.f1746r = (byte) (bA2 & 3);
                this.f1748t = (byte) ((bA2 >> 2) & 3);
                this.f1749u = V.a.a(this.f1734i, aVar.a(6 + j2));
                long j3 = 8 + j2;
                byte bA3 = V.a.a(this.f1734i, aVar.a(7 + j2));
                this.f1750v = bA3;
                this.f1751w = (byte) ((bA3 >> 1) & 7);
                o.d("PageHeader", " this = " + this, 16);
                int i2 = 0;
                while (i2 < 32) {
                    long j4 = j3 + 1;
                    this.f1752x[i2] = V.a.b(this.f1734i, aVar.a(j3));
                    i2++;
                    j3 = j4;
                }
                return j3;
            } catch (Exception unused) {
                return j2;
            }
        }

        public boolean b() {
            return this.f1748t == 2;
        }

        @Override // V.c.b
        public String toString() {
            return "PageHeader [pageUnits= " + Integer.toHexString(this.f1741m) + ", pageTens=" + Integer.toHexString(this.f1742n) + ", subcodeS1=" + Integer.toHexString(this.f1743o) + ", subcodeS2=" + Integer.toHexString(this.f1744p) + ", subcodeS3=" + Integer.toHexString(this.f1745q) + ", subcodeS4=" + Integer.toHexString(this.f1746r) + ", C4=" + Integer.toHexString(this.f1747s) + ", C5_6=" + Integer.toHexString(this.f1748t) + ", C7_10=" + Integer.toHexString(this.f1749u) + ", C11_14=" + Integer.toHexString(this.f1750v) + ", C12_14=" + Integer.toHexString(this.f1751w) + "]";
        }
    }

    public c(byte[] bArr, boolean z2, int i2, int i3, int i4) throws Exception {
        this.f1715a = new I.a(bArr);
        this.f1718d = z2;
        this.f1719e = i2;
        this.f1720f = i3;
        this.f1721g = i4;
        i();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void c(int i2, int i3, int i4) throws Exception {
        if (i4 < i2 || i4 > i3) {
            throw new Exception("exceptMin = " + i2 + " exceptMax : " + i3 + " but val = " + (i4 & 255));
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void d(int i2, int i3) throws Exception {
        if (i3 == i2) {
            return;
        }
        throw new Exception("except = " + i2 + " but val = " + (i3 & 255));
    }

    private void i() throws Exception {
        a aVar = new a();
        this.f1717c = aVar;
        aVar.a(this.f1715a, 0L);
        this.f1716b = this.f1717c.f1723b;
    }

    public boolean e() {
        b bVar;
        a aVar = this.f1717c;
        if (aVar == null || (bVar = aVar.f1724c) == null || bVar.f1730e == -1) {
            return false;
        }
        return bVar.f1736k;
    }

    public int f() {
        b bVar;
        int i2;
        a aVar = this.f1717c;
        if (aVar == null || (bVar = aVar.f1724c) == null || (i2 = bVar.f1730e) == -1) {
            return -1;
        }
        return i2;
    }

    public final void finalize() {
    }

    public boolean g() {
        b bVar;
        a aVar = this.f1717c;
        if (aVar == null || (bVar = aVar.f1724c) == null) {
            return false;
        }
        return bVar.f1736k;
    }

    public int h() {
        b bVar;
        a aVar = this.f1717c;
        if (aVar == null || (bVar = aVar.f1724c) == null || bVar.f1730e == -1) {
            return -1;
        }
        return bVar.f1731f;
    }

    class b {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        final int[] f1726a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        int f1727b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        int f1728c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        int f1729d;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        int f1730e;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        int f1731f;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        byte f1732g;

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        byte f1733h;

        /* JADX INFO: renamed from: i, reason: collision with root package name */
        byte f1734i;

        /* JADX INFO: renamed from: j, reason: collision with root package name */
        String f1735j;

        /* JADX INFO: renamed from: k, reason: collision with root package name */
        boolean f1736k;

        public b() {
            this.f1726a = new int[]{2, 3};
            this.f1730e = -1;
            this.f1731f = -1;
            this.f1735j = HttpUrl.FRAGMENT_ENCODE_SET;
            this.f1736k = false;
        }

        public long a(I.a aVar, long j2) {
            long j3;
            o.d("Page", "page parserBuffer off = " + j2, 16);
            long jA = j2;
            while (aVar.c() > jA) {
                try {
                    long j4 = 1 + jA;
                    this.f1727b = aVar.a(jA);
                    o.d("Page", "page get unit off=" + j4 + ", id=" + this.f1727b, 16);
                    int i2 = this.f1727b;
                    if (i2 != 2 && i2 != 3) {
                        return j4;
                    }
                    if (i2 != 3) {
                        j3 = 46;
                    } else {
                        long j5 = 2 + jA;
                        int iA = aVar.a(j4);
                        this.f1728c = iA;
                        c.this.d(44, iA);
                        if (aVar.c() < ((long) this.f1728c) + j5) {
                            return j5;
                        }
                        long j6 = 4 + jA;
                        this.f1729d = aVar.a(3 + jA);
                        o.d("Page", " frammingCode = " + this.f1729d, 16);
                        int i3 = this.f1729d;
                        if (i3 == 27) {
                            this.f1734i = (byte) 2;
                        } else if (i3 == 39) {
                            this.f1734i = (byte) 1;
                        } else if (i3 == 216) {
                            this.f1734i = (byte) 3;
                        } else if (i3 != 228) {
                            jA = ((long) (this.f1728c - 2)) + j6;
                        } else {
                            this.f1734i = (byte) 0;
                        }
                        long j7 = 5 + jA;
                        byte bA = V.a.a(this.f1734i, aVar.a(j6));
                        this.f1732g = (byte) (bA & 7);
                        this.f1733h = (byte) ((bA >> 3) & 1);
                        jA += 6;
                        this.f1733h = (byte) (this.f1733h + ((V.a.a(this.f1734i, aVar.a(j7)) & SDKKeyboardCode.FUNCTION_KEY_BOARD_L) << 1));
                        o.d("Page", "this = " + this, 16);
                        byte b2 = this.f1733h;
                        if (b2 == 0) {
                            this.f1736k = false;
                            d dVar = c.this.new d(this);
                            jA = dVar.a(aVar, jA);
                            this.f1730e = (dVar.f1742n * SDKKeyboardCode.FUNCTION_KEY_BOARD_M) + dVar.f1741m;
                            this.f1731f = dVar.f1751w;
                            if (dVar.b()) {
                                this.f1736k = true;
                            }
                            o.d("Page", "pageNumber = " + this.f1730e + " isSubtitle = " + this.f1736k + " optLanguage = " + this.f1731f, 16);
                        } else if (b2 < 1 || b2 > 23) {
                            j3 = this.f1728c - 4;
                        } else {
                            C0042c c0042c = c.this.new C0042c(this);
                            jA = c0042c.a(aVar, jA);
                            o.d("Page", "pageNumber: " + this.f1730e + " isSubtitle: " + this.f1736k + " headerShowSubtitle: " + c.this.f1718d + " headerShowPageNum = " + c.this.f1719e, 16);
                            if (!this.f1736k || this.f1730e != c.this.f1720f) {
                                c cVar = c.this;
                                if (!cVar.f1718d || cVar.f1719e != cVar.f1720f) {
                                }
                            }
                            String strTrim = new String(c0042c.f1739n).trim();
                            o.d("Page", "tmptxt: " + strTrim, 16);
                            if (!strTrim.isEmpty()) {
                                if (!this.f1735j.isEmpty()) {
                                    this.f1735j += "\n";
                                }
                                this.f1735j += new String(c0042c.f1739n);
                                o.d("Page", "txt: " + this.f1735j, 16);
                            }
                        }
                    }
                    jA += j3;
                } catch (Exception e2) {
                    e2.printStackTrace();
                    return j2;
                }
            }
            return jA;
        }

        public String toString() {
            return "Page [unitId=Integer.toHexString(" + this.f1727b + "), unitLen=Integer.toHexString(" + this.f1728c + "), frammingCode=Integer.toHexString(" + this.f1729d + "), magNum=Integer.toHexString(" + ((int) this.f1732g) + "), packetNum=Integer.toHexString(" + ((int) this.f1733h) + "), frammingCodeType=Integer.toHexString(" + ((int) this.f1734i) + "]";
        }

        public b(b bVar) {
            this.f1726a = new int[]{2, 3};
            this.f1730e = -1;
            this.f1731f = -1;
            this.f1735j = HttpUrl.FRAGMENT_ENCODE_SET;
            this.f1736k = false;
            this.f1732g = bVar.f1732g;
            this.f1733h = bVar.f1733h;
            this.f1734i = bVar.f1734i;
            this.f1731f = bVar.f1731f;
        }
    }
}
