f.java 源代码
package j;
import j.c;
import j.e;
import j.o;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UTFDataFormatException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.AbstractList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.RandomAccess;
import java.util.zip.Adler32;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public final class f {
static final short[] f22954j = new short[0];
private ByteBuffer f22955a;
private final s f22956b = new s();
private int f22957c = 0;
private final h f22958d;
private final i f22959e;
private final j f22960f;
private final C0290f f22961g;
private final d f22962h;
private final e f22963i;
private final class b implements Iterable<j.d> {
private b() {
}
@Override
public Iterator<j.d> iterator() {
if (!f.this.f22956b.f23017g.b()) {
return Collections.emptySet().iterator();
}
return new c();
}
}
private final class c implements Iterator<j.d> {
private final g f22965q;
private int f22966r;
private c() {
this.f22965q = f.this.p(f.this.f22956b.f23017g.f23039s);
this.f22966r = 0;
}
@Override
public j.d next() {
if (hasNext()) {
this.f22966r++;
return this.f22965q.o();
}
throw new NoSuchElementException();
}
@Override
public boolean hasNext() {
if (this.f22966r < f.this.f22956b.f23017g.f23038r) {
return true;
}
return false;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}
private final class d extends AbstractList<m> implements RandomAccess {
private d() {
}
@Override
public m get(int i6) {
f.e(i6, f.this.f22956b.f23015e.f23038r);
f fVar = f.this;
return fVar.p(fVar.f22956b.f23015e.f23039s + (i6 * 8)).r();
}
@Override
public int size() {
return f.this.f22956b.f23015e.f23038r;
}
}
private final class e extends AbstractList<p> implements RandomAccess {
private e() {
}
@Override
public p get(int i6) {
f.e(i6, f.this.f22956b.f23016f.f23038r);
f fVar = f.this;
return fVar.p(fVar.f22956b.f23016f.f23039s + (i6 * 8)).v();
}
@Override
public int size() {
return f.this.f22956b.f23016f.f23038r;
}
}
private final class C0290f extends AbstractList<r> implements RandomAccess {
private C0290f() {
}
@Override
public r get(int i6) {
f.e(i6, f.this.f22956b.f23014d.f23038r);
f fVar = f.this;
return fVar.p(fVar.f22956b.f23014d.f23039s + (i6 * 12)).x();
}
@Override
public int size() {
return f.this.f22956b.f23014d.f23038r;
}
}
public final class g implements k.b, k.c {
private final String f22971a;
private final ByteBuffer f22972b;
private final int f22973c;
private e.b[] C(int i6, e.a[] aVarArr) {
e.b[] bVarArr = new e.b[i6];
for (int i7 = 0; i7 < i6; i7++) {
bVarArr[i7] = new e.b(t(), G(), f(aVarArr, G()));
}
return bVarArr;
}
private int f(e.a[] aVarArr, int i6) {
for (int i7 = 0; i7 < aVarArr.length; i7++) {
if (aVarArr[i7].c() == i6) {
return i7;
}
}
throw new IllegalArgumentException();
}
private byte[] g(int i6) {
byte[] bArr = new byte[this.f22972b.position() - i6];
this.f22972b.position(i6);
this.f22972b.get(bArr);
return bArr;
}
private e.a l(int i6) {
int i7;
int A = A();
int abs = Math.abs(A);
int[] iArr = new int[abs];
int[] iArr2 = new int[abs];
for (int i8 = 0; i8 < abs; i8++) {
iArr[i8] = E();
iArr2[i8] = E();
}
if (A <= 0) {
i7 = E();
} else {
i7 = -1;
}
return new e.a(iArr, iArr2, i7, i6);
}
private e.a[] m() {
int position = this.f22972b.position();
int E = E();
e.a[] aVarArr = new e.a[E];
for (int i6 = 0; i6 < E; i6++) {
aVarArr[i6] = l(this.f22972b.position() - position);
}
return aVarArr;
}
public j.c n() {
return new j.c(s(E()), s(E()), w(E()), w(E()));
}
public j.e p() {
e.b[] bVarArr;
e.a[] aVarArr;
int G = G();
int G2 = G();
int G3 = G();
int G4 = G();
int t6 = t();
short[] z6 = z(t());
if (G4 > 0) {
if (z6.length % 2 == 1) {
y();
}
g p6 = f.this.p(this.f22972b.position());
H(G4 * 8);
aVarArr = m();
bVarArr = p6.C(G4, aVarArr);
} else {
bVarArr = new e.b[0];
aVarArr = new e.a[0];
}
return new j.e(G, G2, G3, t6, z6, bVarArr, aVarArr);
}
private c.a[] s(int i6) {
c.a[] aVarArr = new c.a[i6];
int i7 = 0;
for (int i8 = 0; i8 < i6; i8++) {
i7 += E();
aVarArr[i8] = new c.a(i7, E());
}
return aVarArr;
}
private c.b[] w(int i6) {
c.b[] bVarArr = new c.b[i6];
int i7 = 0;
for (int i8 = 0; i8 < i6; i8++) {
i7 += E();
bVarArr[i8] = new c.b(i7, E(), E());
}
return bVarArr;
}
public int A() {
return n.a(this);
}
public String B() {
int t6 = t();
int position = this.f22972b.position();
int limit = this.f22972b.limit();
this.f22972b.position(t6);
ByteBuffer byteBuffer = this.f22972b;
byteBuffer.limit(byteBuffer.capacity());
try {
try {
int E = E();
String b6 = q.b(this, new char[E]);
if (b6.length() == E) {
return b6;
}
throw new j.g("Declared length " + E + " doesn't match decoded length of " + b6.length());
} catch (UTFDataFormatException e6) {
throw new j.g(e6);
}
} finally {
this.f22972b.position(position);
this.f22972b.limit(limit);
}
}
public t D() {
short[] z6 = z(t());
c();
return new t(f.this, z6);
}
public int E() {
return n.b(this);
}
public int F() {
return n.b(this) - 1;
}
public int G() {
return y() & 65535;
}
public void H(int i6) {
if (i6 >= 0) {
ByteBuffer byteBuffer = this.f22972b;
byteBuffer.position(byteBuffer.position() + i6);
return;
}
throw new IllegalArgumentException();
}
public int I() {
return this.f22972b.position() - this.f22973c;
}
public void J(byte[] bArr) {
this.f22972b.put(bArr);
}
public void K(short[] sArr) {
for (short s6 : sArr) {
M(s6);
}
}
public void L(int i6) {
this.f22972b.putInt(i6);
}
public void M(short s6) {
this.f22972b.putShort(s6);
}
public void N(int i6) {
try {
n.c(this, i6);
} catch (ArrayIndexOutOfBoundsException unused) {
throw new j.g("Section limit " + this.f22972b.limit() + " exceeded by " + this.f22971a);
}
}
public void O(String str) {
try {
Q(str.length());
J(q.d(str));
writeByte(0);
} catch (UTFDataFormatException unused) {
throw new AssertionError();
}
}
public void P(t tVar) {
short[] b6 = tVar.b();
L(b6.length);
for (short s6 : b6) {
M(s6);
}
d();
}
public void Q(int i6) {
try {
n.d(this, i6);
} catch (ArrayIndexOutOfBoundsException unused) {
throw new j.g("Section limit " + this.f22972b.limit() + " exceeded by " + this.f22971a);
}
}
public void R(int i6) {
Q(i6 + 1);
}
public void S(int i6) {
short s6 = (short) i6;
if (i6 == (65535 & s6)) {
M(s6);
return;
}
throw new IllegalArgumentException("Expected an unsigned short: " + i6);
}
public void c() {
ByteBuffer byteBuffer = this.f22972b;
byteBuffer.position((byteBuffer.position() + 3) & (-4));
}
public void d() {
while ((this.f22972b.position() & 3) != 0) {
this.f22972b.put((byte) 0);
}
}
public void e() {
if ((this.f22972b.position() & 3) == 0) {
} else {
throw new IllegalStateException("Not four byte aligned!");
}
}
public int h() {
return this.f22972b.position();
}
public j.a i() {
byte readByte = readByte();
int position = this.f22972b.position();
new l(this, 29).w();
return new j.a(f.this, readByte, new j.j(g(position)));
}
public byte[] j(int i6) {
byte[] bArr = new byte[i6];
this.f22972b.get(bArr);
return bArr;
}
public j.b k() {
return new j.b(f.this, t());
}
public j.d o() {
return new j.d(f.this, h(), t(), t(), t(), t(), t(), t(), t(), t());
}
public j.j q() {
int position = this.f22972b.position();
new l(this, 28).w();
return new j.j(g(position));
}
public m r() {
return new m(f.this, G(), G(), t());
}
@Override
public byte readByte() {
return this.f22972b.get();
}
public int t() {
return this.f22972b.getInt();
}
public o u() {
return new o(f.this, o.b.b(G()), G(), G(), G());
}
public p v() {
return new p(f.this, G(), G(), t());
}
@Override
public void writeByte(int i6) {
this.f22972b.put((byte) i6);
}
public r x() {
return new r(f.this, t(), t(), t());
}
public short y() {
return this.f22972b.getShort();
}
public short[] z(int i6) {
if (i6 == 0) {
return f.f22954j;
}
short[] sArr = new short[i6];
for (int i7 = 0; i7 < i6; i7++) {
sArr[i7] = y();
}
return sArr;
}
private g(String str, ByteBuffer byteBuffer) {
this.f22971a = str;
this.f22972b = byteBuffer;
this.f22973c = byteBuffer.position();
}
}
public final class h extends AbstractList<String> implements RandomAccess {
private h() {
}
@Override
public String get(int i6) {
f.e(i6, f.this.f22956b.f23012b.f23038r);
f fVar = f.this;
return fVar.p(fVar.f22956b.f23012b.f23039s + (i6 * 4)).B();
}
@Override
public int size() {
return f.this.f22956b.f23012b.f23038r;
}
}
private final class i extends AbstractList<Integer> implements RandomAccess {
private i() {
}
@Override
public Integer get(int i6) {
return Integer.valueOf(f.this.i(i6));
}
@Override
public int size() {
return f.this.f22956b.f23013c.f23038r;
}
}
private final class j extends AbstractList<String> implements RandomAccess {
private j() {
}
@Override
public String get(int i6) {
return f.this.f22958d.get(f.this.i(i6));
}
@Override
public int size() {
return f.this.f22956b.f23013c.f23038r;
}
}
public f(int i6) throws IOException {
this.f22958d = new h();
this.f22959e = new i();
this.f22960f = new j();
this.f22961g = new C0290f();
this.f22962h = new d();
this.f22963i = new e();
ByteBuffer wrap = ByteBuffer.wrap(new byte[i6]);
this.f22955a = wrap;
wrap.order(ByteOrder.LITTLE_ENDIAN);
}
public static void e(int i6, int i7) {
if (i6 >= 0 && i6 < i7) {
return;
}
throw new IndexOutOfBoundsException("index:" + i6 + ", length=" + i7);
}
private void n(InputStream inputStream) throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] bArr = new byte[8192];
while (true) {
int read = inputStream.read(bArr);
if (read != -1) {
byteArrayOutputStream.write(bArr, 0, read);
} else {
ByteBuffer wrap = ByteBuffer.wrap(byteArrayOutputStream.toByteArray());
this.f22955a = wrap;
wrap.order(ByteOrder.LITTLE_ENDIAN);
this.f22956b.c(this);
return;
}
}
}
public g d(int i6, String str) {
if ((i6 & 3) == 0) {
int i7 = this.f22957c + i6;
ByteBuffer duplicate = this.f22955a.duplicate();
duplicate.order(ByteOrder.LITTLE_ENDIAN);
duplicate.position(this.f22957c);
duplicate.limit(i7);
g gVar = new g(str, duplicate);
this.f22957c = i7;
return gVar;
}
throw new IllegalStateException("Not four byte aligned!");
}
public Iterable<j.d> f() {
return new b();
}
public int g() throws IOException {
Adler32 adler32 = new Adler32();
byte[] bArr = new byte[8192];
ByteBuffer duplicate = this.f22955a.duplicate();
duplicate.limit(duplicate.capacity());
duplicate.position(12);
while (duplicate.hasRemaining()) {
int min = Math.min(8192, duplicate.remaining());
duplicate.get(bArr, 0, min);
adler32.update(bArr, 0, min);
}
return (int) adler32.getValue();
}
public byte[] h() throws IOException {
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
byte[] bArr = new byte[8192];
ByteBuffer duplicate = this.f22955a.duplicate();
duplicate.limit(duplicate.capacity());
duplicate.position(32);
while (duplicate.hasRemaining()) {
int min = Math.min(8192, duplicate.remaining());
duplicate.get(bArr, 0, min);
messageDigest.update(bArr, 0, min);
}
return messageDigest.digest();
} catch (NoSuchAlgorithmException unused) {
throw new AssertionError();
}
}
public int i(int i6) {
e(i6, this.f22956b.f23013c.f23038r);
return this.f22955a.getInt(this.f22956b.f23013c.f23039s + (i6 * 4));
}
public List<m> j() {
return this.f22962h;
}
public int k() {
return this.f22955a.capacity();
}
public int l() {
return this.f22957c;
}
public s m() {
return this.f22956b;
}
public List<p> o() {
return this.f22963i;
}
public g p(int i6) {
if (i6 >= 0 && i6 < this.f22955a.capacity()) {
ByteBuffer duplicate = this.f22955a.duplicate();
duplicate.order(ByteOrder.LITTLE_ENDIAN);
duplicate.position(i6);
duplicate.limit(this.f22955a.capacity());
return new g("section", duplicate);
}
throw new IllegalArgumentException("position=" + i6 + " length=" + this.f22955a.capacity());
}
public List<r> q() {
return this.f22961g;
}
public j.c r(j.d dVar) {
int c6 = dVar.c();
if (c6 != 0) {
return p(c6).n();
}
throw new IllegalArgumentException("offset == 0");
}
public j.e s(c.b bVar) {
int b6 = bVar.b();
if (b6 != 0) {
return p(b6).p();
}
throw new IllegalArgumentException("offset == 0");
}
public t t(int i6) {
if (i6 == 0) {
return t.f23041s;
}
return p(i6).D();
}
public List<String> u() {
return this.f22958d;
}
public List<String> v() {
return this.f22960f;
}
public void w() throws IOException {
p(12).J(h());
p(8).L(g());
}
public void x(File file) throws IOException {
FileOutputStream fileOutputStream = new FileOutputStream(file);
try {
y(fileOutputStream);
fileOutputStream.close();
} catch (Throwable th) {
try {
fileOutputStream.close();
} catch (Throwable th2) {
th.addSuppressed(th2);
}
throw th;
}
}
public void y(OutputStream outputStream) throws IOException {
byte[] bArr = new byte[8192];
ByteBuffer duplicate = this.f22955a.duplicate();
duplicate.clear();
while (duplicate.hasRemaining()) {
int min = Math.min(8192, duplicate.remaining());
duplicate.get(bArr, 0, min);
outputStream.write(bArr, 0, min);
}
}
public f(File file) throws IOException {
this.f22958d = new h();
this.f22959e = new i();
this.f22960f = new j();
this.f22961g = new C0290f();
this.f22962h = new d();
this.f22963i = new e();
if (k.e.a(file.getName())) {
ZipFile zipFile = new ZipFile(file);
ZipEntry entry = zipFile.getEntry("classes.dex");
if (entry != null) {
InputStream inputStream = zipFile.getInputStream(entry);
try {
n(inputStream);
if (inputStream != null) {
inputStream.close();
}
zipFile.close();
return;
} catch (Throwable th) {
if (inputStream != null) {
try {
inputStream.close();
} catch (Throwable th2) {
th.addSuppressed(th2);
}
}
throw th;
}
}
throw new j.g("Expected classes.dex in " + file);
}
if (file.getName().endsWith(".dex")) {
FileInputStream fileInputStream = new FileInputStream(file);
try {
n(fileInputStream);
fileInputStream.close();
return;
} catch (Throwable th3) {
try {
fileInputStream.close();
} catch (Throwable th4) {
th3.addSuppressed(th4);
}
throw th3;
}
}
throw new j.g("unknown output extension: " + file);
}
}