discord-jadx/app/src/main/java/c/i/a/c/c2/k/b.java

620 lines
20 KiB
Java

package c.i.a.c.c2.k;
import android.util.Log;
import androidx.annotation.Nullable;
import c.i.a.c.c2.d;
import c.i.a.c.c2.g;
import c.i.a.c.i2.f0;
import c.i.a.c.i2.v;
import c.i.a.c.i2.w;
import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.id3.ApicFrame;
import com.google.android.exoplayer2.metadata.id3.BinaryFrame;
import com.google.android.exoplayer2.metadata.id3.ChapterFrame;
import com.google.android.exoplayer2.metadata.id3.ChapterTocFrame;
import com.google.android.exoplayer2.metadata.id3.CommentFrame;
import com.google.android.exoplayer2.metadata.id3.GeobFrame;
import com.google.android.exoplayer2.metadata.id3.Id3Frame;
import com.google.android.exoplayer2.metadata.id3.MlltFrame;
import com.google.android.exoplayer2.metadata.id3.PrivFrame;
import com.google.android.exoplayer2.metadata.id3.TextInformationFrame;
import com.google.android.exoplayer2.metadata.id3.UrlLinkFrame;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
/* compiled from: Id3Decoder */
public final class b extends g {
public static final /* synthetic */ int a = 0;
@Nullable
public final a b;
/* compiled from: Id3Decoder */
public interface a {
boolean a(int i, int i2, int i3, int i4, int i5);
}
/* compiled from: Id3Decoder */
/* renamed from: c.i.a.c.c2.k.b$b reason: collision with other inner class name */
public static final class C0085b {
public final int a;
public final boolean b;
/* renamed from: c reason: collision with root package name */
public final int f779c;
public C0085b(int i, boolean z2, int i2) {
this.a = i;
this.b = z2;
this.f779c = i2;
}
}
public b() {
this.b = null;
}
public b(@Nullable a aVar) {
this.b = aVar;
}
public static byte[] c(byte[] bArr, int i, int i2) {
return i2 <= i ? f0.f : Arrays.copyOfRange(bArr, i, i2);
}
public static ApicFrame e(w wVar, int i, int i2) throws UnsupportedEncodingException {
String str;
int i3;
int s2 = wVar.s();
String t = t(s2);
int i4 = i - 1;
byte[] bArr = new byte[i4];
System.arraycopy(wVar.a, wVar.b, bArr, 0, i4);
wVar.b += i4;
if (i2 == 2) {
StringBuilder K = c.d.b.a.a.K("image/");
K.append(f0.K(new String(bArr, 0, 3, "ISO-8859-1")));
str = K.toString();
if ("image/jpg".equals(str)) {
str = "image/jpeg";
}
i3 = 2;
} else {
int w = w(bArr, 0);
String K2 = f0.K(new String(bArr, 0, w, "ISO-8859-1"));
if (K2.indexOf(47) == -1) {
i3 = w;
str = c.d.b.a.a.s("image/", K2);
} else {
i3 = w;
str = K2;
}
}
int i5 = i3 + 2;
int v = v(bArr, i5, s2);
return new ApicFrame(str, new String(bArr, i5, v - i5, t), bArr[i3 + 1] & 255, c(bArr, s(s2) + v, i4));
}
public static BinaryFrame f(w wVar, int i, String str) {
byte[] bArr = new byte[i];
System.arraycopy(wVar.a, wVar.b, bArr, 0, i);
wVar.b += i;
return new BinaryFrame(str, bArr);
}
public static ChapterFrame g(w wVar, int i, int i2, boolean z2, int i3, @Nullable a aVar) throws UnsupportedEncodingException {
int i4 = wVar.b;
int w = w(wVar.a, i4);
String str = new String(wVar.a, i4, w - i4, "ISO-8859-1");
wVar.D(w + 1);
int f = wVar.f();
int f2 = wVar.f();
long t = wVar.t();
long j = t == 4294967295L ? -1 : t;
long t2 = wVar.t();
long j2 = t2 == 4294967295L ? -1 : t2;
ArrayList arrayList = new ArrayList();
int i5 = i4 + i;
while (wVar.b < i5) {
Id3Frame j3 = j(i2, wVar, z2, i3, aVar);
if (j3 != null) {
arrayList.add(j3);
}
}
return new ChapterFrame(str, f, f2, j, j2, (Id3Frame[]) arrayList.toArray(new Id3Frame[0]));
}
public static ChapterTocFrame h(w wVar, int i, int i2, boolean z2, int i3, @Nullable a aVar) throws UnsupportedEncodingException {
int i4 = wVar.b;
int w = w(wVar.a, i4);
String str = new String(wVar.a, i4, w - i4, "ISO-8859-1");
wVar.D(w + 1);
int s2 = wVar.s();
boolean z3 = (s2 & 2) != 0;
boolean z4 = (s2 & 1) != 0;
int s3 = wVar.s();
String[] strArr = new String[s3];
for (int i5 = 0; i5 < s3; i5++) {
int i6 = wVar.b;
int w2 = w(wVar.a, i6);
strArr[i5] = new String(wVar.a, i6, w2 - i6, "ISO-8859-1");
wVar.D(w2 + 1);
}
ArrayList arrayList = new ArrayList();
int i7 = i4 + i;
while (wVar.b < i7) {
Id3Frame j = j(i2, wVar, z2, i3, aVar);
if (j != null) {
arrayList.add(j);
}
}
return new ChapterTocFrame(str, z3, z4, strArr, (Id3Frame[]) arrayList.toArray(new Id3Frame[0]));
}
@Nullable
public static CommentFrame i(w wVar, int i) throws UnsupportedEncodingException {
if (i < 4) {
return null;
}
int s2 = wVar.s();
String t = t(s2);
byte[] bArr = new byte[3];
System.arraycopy(wVar.a, wVar.b, bArr, 0, 3);
wVar.b += 3;
String str = new String(bArr, 0, 3);
int i2 = i - 4;
byte[] bArr2 = new byte[i2];
System.arraycopy(wVar.a, wVar.b, bArr2, 0, i2);
wVar.b += i2;
int v = v(bArr2, 0, s2);
String str2 = new String(bArr2, 0, v, t);
int s3 = s(s2) + v;
return new CommentFrame(str, str2, n(bArr2, s3, v(bArr2, s3, s2), t));
}
/* JADX WARNING: Code restructure failed: missing block: B:129:0x0188, code lost:
if (r13 == 67) goto L_0x018a;
*/
@Nullable
public static Id3Frame j(int i, w wVar, boolean z2, int i2, @Nullable a aVar) {
int v;
int i3;
int i4;
String str;
boolean z3;
boolean z4;
boolean z5;
boolean z6;
boolean z7;
Id3Frame id3Frame;
int s2 = wVar.s();
int s3 = wVar.s();
int s4 = wVar.s();
int s5 = i >= 3 ? wVar.s() : 0;
if (i == 4) {
v = wVar.v();
if (!z2) {
v = (((v >> 24) & 255) << 21) | (v & 255) | (((v >> 8) & 255) << 7) | (((v >> 16) & 255) << 14);
}
} else {
v = i == 3 ? wVar.v() : wVar.u();
}
int i5 = v;
int x2 = i >= 3 ? wVar.x() : 0;
if (s2 == 0 && s3 == 0 && s4 == 0 && s5 == 0 && i5 == 0 && x2 == 0) {
wVar.D(wVar.f913c);
return null;
}
int i6 = wVar.b + i5;
if (i6 > wVar.f913c) {
Log.w("Id3Decoder", "Frame size exceeds remaining tag data");
wVar.D(wVar.f913c);
return null;
}
if (aVar != null) {
str = "Id3Decoder";
i4 = i6;
i3 = x2;
if (!aVar.a(i, s2, s3, s4, s5)) {
wVar.D(i4);
return null;
}
} else {
str = "Id3Decoder";
i4 = i6;
i3 = x2;
}
if (i == 3) {
z6 = (i3 & 128) != 0;
z5 = (i3 & 64) != 0;
z7 = (i3 & 32) != 0;
z3 = z6;
z4 = false;
} else if (i == 4) {
boolean z8 = (i3 & 64) != 0;
boolean z9 = (i3 & 8) != 0;
boolean z10 = (i3 & 4) != 0;
z4 = (i3 & 2) != 0;
z7 = z8;
z6 = (i3 & 1) != 0;
z3 = z9;
z5 = z10;
} else {
z7 = false;
z6 = false;
z5 = false;
z4 = false;
z3 = false;
}
if (z3 || z5) {
Log.w(str, "Skipping unsupported compressed or encrypted frame");
wVar.D(i4);
return null;
}
if (z7) {
i5--;
wVar.E(1);
}
if (z6) {
i5 -= 4;
wVar.E(4);
}
if (z4) {
i5 = x(wVar, i5);
}
if (s2 == 84 && s3 == 88 && s4 == 88 && (i == 2 || s5 == 88)) {
try {
id3Frame = p(wVar, i5);
} catch (UnsupportedEncodingException unused) {
Log.w(str, "Unsupported character encoding");
wVar.D(i4);
return null;
} catch (Throwable th) {
wVar.D(i4);
throw th;
}
} else if (s2 == 84) {
id3Frame = o(wVar, i5, u(i, s2, s3, s4, s5));
} else if (s2 == 87 && s3 == 88 && s4 == 88 && (i == 2 || s5 == 88)) {
id3Frame = r(wVar, i5);
} else if (s2 == 87) {
id3Frame = q(wVar, i5, u(i, s2, s3, s4, s5));
} else if (s2 == 80 && s3 == 82 && s4 == 73 && s5 == 86) {
id3Frame = m(wVar, i5);
} else if (s2 == 71 && s3 == 69 && s4 == 79 && (s5 == 66 || i == 2)) {
id3Frame = k(wVar, i5);
} else {
if (i == 2) {
if (s2 == 80 && s3 == 73 && s4 == 67) {
}
id3Frame = (s2 != 67 && s3 == 79 && s4 == 77 && (s5 == 77 || i == 2)) ? i(wVar, i5) : (s2 != 67 && s3 == 72 && s4 == 65 && s5 == 80) ? g(wVar, i5, i, z2, i2, aVar) : (s2 != 67 && s3 == 84 && s4 == 79 && s5 == 67) ? h(wVar, i5, i, z2, i2, aVar) : (s2 != 77 && s3 == 76 && s4 == 76 && s5 == 84) ? l(wVar, i5) : f(wVar, i5, u(i, s2, s3, s4, s5));
} else {
if (s2 == 65) {
if (s3 == 80) {
if (s4 == 73) {
}
}
}
if (s2 != 67) {
}
}
id3Frame = e(wVar, i5, i);
}
if (id3Frame == null) {
Log.w(str, "Failed to decode frame: id=" + u(i, s2, s3, s4, s5) + ", frameSize=" + i5);
}
wVar.D(i4);
return id3Frame;
}
public static GeobFrame k(w wVar, int i) throws UnsupportedEncodingException {
int s2 = wVar.s();
String t = t(s2);
int i2 = i - 1;
byte[] bArr = new byte[i2];
System.arraycopy(wVar.a, wVar.b, bArr, 0, i2);
wVar.b += i2;
int w = w(bArr, 0);
String str = new String(bArr, 0, w, "ISO-8859-1");
int i3 = w + 1;
int v = v(bArr, i3, s2);
String n = n(bArr, i3, v, t);
int s3 = s(s2) + v;
int v2 = v(bArr, s3, s2);
return new GeobFrame(str, n, n(bArr, s3, v2, t), c(bArr, s(s2) + v2, i2));
}
public static MlltFrame l(w wVar, int i) {
int x2 = wVar.x();
int u = wVar.u();
int u2 = wVar.u();
int s2 = wVar.s();
int s3 = wVar.s();
v vVar = new v();
vVar.j(wVar.a, wVar.f913c);
vVar.k(wVar.b * 8);
int i2 = ((i - 10) * 8) / (s2 + s3);
int[] iArr = new int[i2];
int[] iArr2 = new int[i2];
for (int i3 = 0; i3 < i2; i3++) {
int g = vVar.g(s2);
int g2 = vVar.g(s3);
iArr[i3] = g;
iArr2[i3] = g2;
}
return new MlltFrame(x2, u, u2, iArr, iArr2);
}
public static PrivFrame m(w wVar, int i) throws UnsupportedEncodingException {
byte[] bArr = new byte[i];
System.arraycopy(wVar.a, wVar.b, bArr, 0, i);
wVar.b += i;
int w = w(bArr, 0);
return new PrivFrame(new String(bArr, 0, w, "ISO-8859-1"), c(bArr, w + 1, i));
}
public static String n(byte[] bArr, int i, int i2, String str) throws UnsupportedEncodingException {
return (i2 <= i || i2 > bArr.length) ? "" : new String(bArr, i, i2 - i, str);
}
@Nullable
public static TextInformationFrame o(w wVar, int i, String str) throws UnsupportedEncodingException {
if (i < 1) {
return null;
}
int s2 = wVar.s();
String t = t(s2);
int i2 = i - 1;
byte[] bArr = new byte[i2];
System.arraycopy(wVar.a, wVar.b, bArr, 0, i2);
wVar.b += i2;
return new TextInformationFrame(str, null, new String(bArr, 0, v(bArr, 0, s2), t));
}
@Nullable
public static TextInformationFrame p(w wVar, int i) throws UnsupportedEncodingException {
if (i < 1) {
return null;
}
int s2 = wVar.s();
String t = t(s2);
int i2 = i - 1;
byte[] bArr = new byte[i2];
System.arraycopy(wVar.a, wVar.b, bArr, 0, i2);
wVar.b += i2;
int v = v(bArr, 0, s2);
String str = new String(bArr, 0, v, t);
int s3 = s(s2) + v;
return new TextInformationFrame("TXXX", str, n(bArr, s3, v(bArr, s3, s2), t));
}
public static UrlLinkFrame q(w wVar, int i, String str) throws UnsupportedEncodingException {
byte[] bArr = new byte[i];
System.arraycopy(wVar.a, wVar.b, bArr, 0, i);
wVar.b += i;
return new UrlLinkFrame(str, null, new String(bArr, 0, w(bArr, 0), "ISO-8859-1"));
}
@Nullable
public static UrlLinkFrame r(w wVar, int i) throws UnsupportedEncodingException {
if (i < 1) {
return null;
}
int s2 = wVar.s();
String t = t(s2);
int i2 = i - 1;
byte[] bArr = new byte[i2];
System.arraycopy(wVar.a, wVar.b, bArr, 0, i2);
wVar.b += i2;
int v = v(bArr, 0, s2);
String str = new String(bArr, 0, v, t);
int s3 = s(s2) + v;
return new UrlLinkFrame("WXXX", str, n(bArr, s3, w(bArr, s3), "ISO-8859-1"));
}
public static int s(int i) {
return (i == 0 || i == 3) ? 1 : 2;
}
public static String t(int i) {
return i != 1 ? i != 2 ? i != 3 ? "ISO-8859-1" : "UTF-8" : "UTF-16BE" : "UTF-16";
}
public static String u(int i, int i2, int i3, int i4, int i5) {
return i == 2 ? String.format(Locale.US, "%c%c%c", Integer.valueOf(i2), Integer.valueOf(i3), Integer.valueOf(i4)) : String.format(Locale.US, "%c%c%c%c", Integer.valueOf(i2), Integer.valueOf(i3), Integer.valueOf(i4), Integer.valueOf(i5));
}
public static int v(byte[] bArr, int i, int i2) {
int w = w(bArr, i);
if (i2 == 0 || i2 == 3) {
return w;
}
while (w < bArr.length - 1) {
if (w % 2 == 0 && bArr[w + 1] == 0) {
return w;
}
w = w(bArr, w + 1);
}
return bArr.length;
}
public static int w(byte[] bArr, int i) {
while (i < bArr.length) {
if (bArr[i] == 0) {
return i;
}
i++;
}
return bArr.length;
}
public static int x(w wVar, int i) {
byte[] bArr = wVar.a;
int i2 = wVar.b;
int i3 = i2;
while (true) {
int i4 = i3 + 1;
if (i4 >= i2 + i) {
return i;
}
if ((bArr[i3] & 255) == 255 && bArr[i4] == 0) {
System.arraycopy(bArr, i3 + 2, bArr, i4, (i - (i3 - i2)) - 2);
i--;
}
i3 = i4;
}
}
/* JADX WARNING: Code restructure failed: missing block: B:30:0x0074, code lost:
if ((r10 & 1) != 0) goto L_0x0087;
*/
/* JADX WARNING: Code restructure failed: missing block: B:37:0x0082, code lost:
if ((r10 & 128) != 0) goto L_0x0087;
*/
public static boolean y(w wVar, int i, int i2, boolean z2) {
int i3;
long j;
int i4;
int i5;
int i6 = wVar.b;
while (true) {
try {
boolean z3 = true;
if (wVar.a() >= i2) {
if (i >= 3) {
i4 = wVar.f();
j = wVar.t();
i3 = wVar.x();
} else {
i4 = wVar.u();
j = (long) wVar.u();
i3 = 0;
}
if (i4 == 0 && j == 0 && i3 == 0) {
wVar.D(i6);
return true;
}
if (i == 4 && !z2) {
if ((8421504 & j) != 0) {
wVar.D(i6);
return false;
}
j = (((j >> 24) & 255) << 21) | (j & 255) | (((j >> 8) & 255) << 7) | (((j >> 16) & 255) << 14);
}
if (i == 4) {
i5 = (i3 & 64) != 0 ? 1 : 0;
} else if (i == 3) {
i5 = (i3 & 32) != 0 ? 1 : 0;
} else {
i5 = 0;
}
z3 = false;
if (z3) {
i5 += 4;
}
if (j < ((long) i5)) {
wVar.D(i6);
return false;
} else if (((long) wVar.a()) < j) {
return false;
} else {
wVar.E((int) j);
}
} else {
wVar.D(i6);
return true;
}
} finally {
wVar.D(i6);
}
}
}
@Override // c.i.a.c.c2.g
@Nullable
public Metadata b(d dVar, ByteBuffer byteBuffer) {
return d(byteBuffer.array(), byteBuffer.limit());
}
/* JADX WARNING: Removed duplicated region for block: B:44:0x00b6 A[RETURN] */
/* JADX WARNING: Removed duplicated region for block: B:45:0x00b7 */
@Nullable
public Metadata d(byte[] bArr, int i) {
C0085b bVar;
ArrayList arrayList = new ArrayList();
w wVar = new w(bArr, i);
boolean z2 = false;
int i2 = 10;
if (wVar.a() < 10) {
Log.w("Id3Decoder", "Data too short to be an ID3 tag");
} else {
int u = wVar.u();
if (u != 4801587) {
StringBuilder K = c.d.b.a.a.K("Unexpected first three bytes of ID3 tag header: 0x");
K.append(String.format("%06X", Integer.valueOf(u)));
Log.w("Id3Decoder", K.toString());
} else {
int s2 = wVar.s();
wVar.E(1);
int s3 = wVar.s();
int r = wVar.r();
if (s2 == 2) {
if ((s3 & 64) != 0) {
Log.w("Id3Decoder", "Skipped ID3 tag with majorVersion=2 and undefined compression scheme");
}
} else if (s2 == 3) {
if ((s3 & 64) != 0) {
int f = wVar.f();
wVar.E(f);
r -= f + 4;
}
} else if (s2 == 4) {
if ((s3 & 64) != 0) {
int r2 = wVar.r();
wVar.E(r2 - 4);
r -= r2;
}
if ((s3 & 16) != 0) {
r -= 10;
}
} else {
c.d.b.a.a.d0("Skipped ID3 tag with unsupported majorVersion=", s2, "Id3Decoder");
}
bVar = new C0085b(s2, s2 < 4 && (s3 & 128) != 0, r);
if (bVar != null) {
return null;
}
int i3 = wVar.b;
if (bVar.a == 2) {
i2 = 6;
}
int i4 = bVar.f779c;
if (bVar.b) {
i4 = x(wVar, i4);
}
wVar.C(i3 + i4);
if (!y(wVar, bVar.a, i2, false)) {
if (bVar.a != 4 || !y(wVar, 4, i2, true)) {
StringBuilder K2 = c.d.b.a.a.K("Failed to validate ID3 tag with majorVersion=");
K2.append(bVar.a);
Log.w("Id3Decoder", K2.toString());
return null;
}
z2 = true;
}
while (wVar.a() >= i2) {
Id3Frame j = j(bVar.a, wVar, z2, i2, this.b);
if (j != null) {
arrayList.add(j);
}
}
return new Metadata(arrayList);
}
}
bVar = null;
if (bVar != null) {
}
}
}