q.java 源代码
package x4;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;
import com.google.common.io.ByteStreams;
import d5.j;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.AbstractList;
import java.util.Iterator;
import java.util.List;
import o4.c;
import x4.g;
import x4.q;
public class q extends x4.o implements d5.j<x4.g> {
private static final byte[] f27685g = {Byte.MAX_VALUE, 69, 76, 70};
private static final byte[] f27686h = {111, 97, 116, 10};
private final boolean f27687c;
private final j f27688d;
private final o4.h f27689e;
private final p f27690f;
public class a extends v5.a<x4.g> {
}
class b extends v5.a<String> {
class a implements Function<h, String> {
a() {
}
@Override
public String apply(h hVar) {
return hVar.f27701a;
}
}
b() {
}
@Override
public Iterator<String> iterator() {
return Iterators.s(Iterators.i(new d(q.this, null), new Predicate() {
@Override
public final boolean apply(Object obj) {
return r.a((q.h) obj);
}
}), new a());
}
@Override
public int size() {
return Iterators.q(Iterators.i(new d(q.this, null), new Predicate() {
@Override
public final boolean apply(Object obj) {
return r.a((q.h) obj);
}
}));
}
}
public class c extends AbstractList<m> {
final int f27693q;
final int f27694r;
final int f27695s;
c(int i6, int i7, int i8) {
this.f27693q = i6;
this.f27694r = i7;
this.f27695s = i8;
}
@Override
public m get(int i6) {
if (i6 >= 0 && i6 < this.f27693q) {
if (q.this.f27687c) {
return new l(this.f27694r + (i6 * this.f27695s));
}
return new k(this.f27694r + (i6 * this.f27695s));
}
throw new IndexOutOfBoundsException();
}
@Override
public int size() {
return this.f27693q;
}
}
public static class e extends RuntimeException {
public e(String str) {
super(str);
}
}
public static class f extends RuntimeException {
}
public class g extends x4.a {
public g(byte[] bArr, int i6) {
super(q.this.f27689e, bArr, i6);
}
@Override
public boolean K() {
return true;
}
}
public class h implements j.a<x4.g> {
public final String f27701a;
public final byte[] f27702b;
public final int f27703c;
public h(String str, byte[] bArr, int i6) {
this.f27701a = str;
this.f27702b = bArr;
this.f27703c = i6;
}
@Override
public x4.g a() {
if (x4.a.O(this.f27702b, this.f27703c)) {
return new g(this.f27702b, this.f27703c);
}
try {
p5.b.c(this.f27702b, this.f27703c);
return new i(this.f27702b, this.f27703c);
} catch (g.l e6) {
if (q.this.v() >= 87) {
throw new c.a(e6, "Could not locate the embedded dex file %s. Is the vdex file missing?", this.f27701a);
}
throw new c.a(e6, "The embedded dex file %s does not appear to be a valid dex file.", this.f27701a);
}
}
public String c() {
return this.f27701a;
}
}
public class i extends x4.g {
public i(byte[] bArr, int i6) {
super(q.this.f27689e, bArr, i6);
}
@Override
public boolean K() {
return true;
}
}
public class j {
private final int f27706a;
private final int f27707b;
public j(int i6) {
this.f27706a = i6;
if (f() >= 170) {
this.f27707b = 56;
return;
}
if (f() >= 166) {
this.f27707b = 64;
return;
}
if (f() >= 162) {
this.f27707b = 68;
} else if (f() >= 127) {
this.f27707b = 76;
} else {
this.f27707b = 72;
}
}
public int b() {
return q.this.j(this.f27706a + 20);
}
public int c() {
int i6;
int d6;
if (f() >= 127) {
i6 = this.f27706a;
d6 = q.this.j(i6 + 24);
} else {
i6 = this.f27706a;
d6 = d();
}
return i6 + d6;
}
public int d() {
if (f() >= 56) {
return this.f27707b + e();
}
throw new IllegalStateException("Unsupported oat version");
}
public int e() {
if (f() >= 56) {
return q.this.j(this.f27706a + (this.f27707b - 4));
}
throw new IllegalStateException("Unsupported oat version");
}
public int f() {
return Integer.valueOf(new String(q.this.f27681a, this.f27706a + 4, 3)).intValue();
}
public boolean g() {
for (int i6 = 0; i6 < q.f27686h.length; i6++) {
if (q.this.f27681a[this.f27706a + i6] != q.f27686h[i6]) {
return false;
}
}
for (int i7 = 4; i7 < 7; i7++) {
byte[] bArr = q.this.f27681a;
int i8 = this.f27706a;
if (bArr[i8 + i7] < 48 || bArr[i8 + i7] > 57) {
return false;
}
}
if (q.this.f27681a[this.f27706a + 7] != 0) {
return false;
}
return true;
}
}
public class k extends m {
public k(int i6) {
super(i6);
}
@Override
public long a() {
return q.this.e(this.f27711a + 12) & 4294967295L;
}
@Override
public int b() {
return q.this.j(this.f27711a + 36);
}
@Override
public int c() {
return q.this.j(this.f27711a + 24);
}
@Override
public int d() {
return q.this.j(this.f27711a + 16);
}
@Override
public int e() {
return q.this.j(this.f27711a + 20);
}
}
public class l extends m {
public l(int i6) {
super(i6);
}
@Override
public long a() {
return q.this.f(this.f27711a + 16);
}
@Override
public int b() {
return q.this.g(this.f27711a + 56);
}
@Override
public int c() {
return q.this.j(this.f27711a + 40);
}
@Override
public int d() {
return q.this.g(this.f27711a + 24);
}
@Override
public int e() {
return q.this.g(this.f27711a + 32);
}
}
public abstract class m {
protected final int f27711a;
public m(int i6) {
this.f27711a = i6;
}
public abstract long a();
public abstract int b();
public abstract int c();
public abstract int d();
public abstract int e();
public int getType() {
return q.this.e(this.f27711a + 4);
}
}
private class n {
private final int f27713a;
private final int f27714b;
public n(m mVar) {
int d6 = mVar.d();
this.f27713a = d6;
int e6 = mVar.e();
this.f27714b = e6;
if (d6 + e6 <= q.this.f27681a.length) {
} else {
throw new e("String table extends past end of file");
}
}
public String a(int i6) {
if (i6 < this.f27714b) {
int i7 = this.f27713a + i6;
int i8 = i7;
do {
byte[] bArr = q.this.f27681a;
if (bArr[i8] != 0) {
i8++;
} else {
return new String(bArr, i7, i8 - i7, Charset.forName("US-ASCII"));
}
} while (i8 < this.f27713a + this.f27714b);
throw new e("String extends past end of string table");
}
throw new e("String index is out of bounds");
}
}
public class o {
private final n f27716a;
private final int f27717b;
private final int f27718c;
private final int f27719d;
public class a extends AbstractList<d> {
a() {
}
@Override
public d get(int i6) {
if (i6 >= 0 && i6 < o.this.f27718c) {
if (q.this.f27687c) {
o oVar = o.this;
return new c(oVar.f27717b + (i6 * o.this.f27719d));
}
o oVar2 = o.this;
return new b(oVar2.f27717b + (i6 * o.this.f27719d));
}
throw new IndexOutOfBoundsException();
}
@Override
public int size() {
return o.this.f27718c;
}
}
public class b extends d {
public b(int i6) {
super(i6);
}
@Override
public String b() {
return o.this.f27716a.a(q.this.j(this.f27724a));
}
@Override
public int c() {
return q.this.l(this.f27724a + 14);
}
@Override
public long d() {
return q.this.j(this.f27724a + 4);
}
}
public class c extends d {
public c(int i6) {
super(i6);
}
@Override
public String b() {
return o.this.f27716a.a(q.this.j(this.f27724a));
}
@Override
public int c() {
return q.this.l(this.f27724a + 6);
}
@Override
public long d() {
return q.this.f(this.f27724a + 8);
}
}
public abstract class d {
protected final int f27724a;
public d(int i6) {
this.f27724a = i6;
}
public int a() {
try {
m mVar = (m) q.this.w().get(c());
long a7 = mVar.a();
int d6 = mVar.d();
int e6 = mVar.e();
long d7 = d();
if (d7 >= a7 && d7 < e6 + a7) {
return (int) (d6 + (d() - a7));
}
throw new e("symbol address lies outside it's associated section");
} catch (IndexOutOfBoundsException unused) {
throw new e("Section index for symbol is out of bounds");
}
}
public abstract String b();
public abstract int c();
public abstract long d();
}
public o(m mVar) {
try {
this.f27716a = new n((m) q.this.w().get(mVar.c()));
int d6 = mVar.d();
this.f27717b = d6;
int b6 = mVar.b();
this.f27719d = b6;
int e6 = mVar.e() / b6;
this.f27718c = e6;
if (d6 + (e6 * b6) <= q.this.f27681a.length) {
} else {
throw new e("Symbol table extends past end of file");
}
} catch (IndexOutOfBoundsException unused) {
throw new e("String table section index is invalid");
}
}
public List<d> e() {
return new a();
}
}
public interface p {
byte[] a();
}
public q(byte[] bArr, p pVar) {
super(bArr);
j jVar;
if (bArr.length >= 52) {
z(bArr);
byte b6 = bArr[4];
if (b6 == 1) {
this.f27687c = false;
} else if (b6 == 2) {
this.f27687c = true;
} else {
throw new e(String.format("Invalid word-size value: %x", Byte.valueOf(bArr[5])));
}
Iterator<o.d> it = x().e().iterator();
while (true) {
if (it.hasNext()) {
o.d next = it.next();
if (next.b().equals("oatdata")) {
jVar = new j(next.a());
break;
}
} else {
jVar = null;
break;
}
}
if (jVar != null) {
this.f27688d = jVar;
if (jVar.g()) {
this.f27689e = o4.h.b(jVar.f());
this.f27690f = pVar;
return;
}
throw new e("Invalid oat magic value");
}
throw new e("Oat file has no oatdata symbol");
}
throw new f();
}
public static q t(InputStream inputStream, p pVar) throws IOException {
if (inputStream.markSupported()) {
inputStream.mark(4);
byte[] bArr = new byte[4];
try {
try {
ByteStreams.d(inputStream, bArr);
inputStream.reset();
z(bArr);
inputStream.reset();
return new q(ByteStreams.i(inputStream), pVar);
} catch (EOFException unused) {
throw new f();
}
} catch (Throwable th) {
inputStream.reset();
throw th;
}
}
throw new IllegalArgumentException("InputStream must support mark");
}
public List<m> w() {
int j6;
int l6;
int l7;
if (this.f27687c) {
j6 = g(40);
l6 = l(58);
l7 = l(60);
} else {
j6 = j(32);
l6 = l(46);
l7 = l(48);
}
if ((l6 * l7) + j6 <= this.f27681a.length) {
return new c(l7, j6, l6);
}
throw new e("The ELF section headers extend past the end of the file");
}
private o x() {
for (m mVar : w()) {
if (mVar.getType() == 11) {
return new o(mVar);
}
}
throw new e("Oat file has no symbol table");
}
private static void z(byte[] bArr) {
int i6 = 0;
while (true) {
byte[] bArr2 = f27685g;
if (i6 < bArr2.length) {
if (bArr[i6] == bArr2[i6]) {
i6++;
} else {
throw new f();
}
} else {
return;
}
}
}
@Override
public List<String> a() throws IOException {
return new b();
}
@Override
public h b(String str) throws IOException {
d dVar = new d(this, null);
while (dVar.hasNext()) {
h next = dVar.next();
if (next != null && next.c().equals(str)) {
return next;
}
}
return null;
}
public int v() {
return this.f27688d.f();
}
public int y() {
int v6 = v();
if (v6 < 56) {
return 0;
}
if (v6 <= 178) {
return 1;
}
return 2;
}
public class d implements Iterator<h> {
int f27697q;
int f27698r;
private d() {
this.f27697q = 0;
this.f27698r = q.this.f27688d.c();
}
@Override
public h next() {
byte[] bArr;
while (hasNext()) {
int j6 = q.this.j(this.f27698r);
int i6 = this.f27698r + 4;
this.f27698r = i6;
String str = new String(q.this.f27681a, i6, j6, Charset.forName("US-ASCII"));
int i7 = this.f27698r + j6 + 4;
this.f27698r = i7;
int j7 = q.this.j(i7);
this.f27698r += 4;
if (q.this.v() >= 87 && q.this.f27690f != null && q.this.f27690f.a() != null) {
bArr = q.this.f27690f.a();
} else {
q qVar = q.this;
byte[] bArr2 = qVar.f27681a;
j7 += qVar.f27688d.f27706a;
bArr = bArr2;
}
if (q.this.v() >= 75) {
this.f27698r += 4;
}
if (q.this.v() >= 73) {
this.f27698r += 4;
}
if (q.this.v() >= 131) {
this.f27698r += 4;
}
if (q.this.v() >= 127) {
this.f27698r += 4;
}
if (q.this.v() >= 135) {
this.f27698r += 8;
}
if (q.this.v() < 75) {
this.f27698r += q.this.j(j7 + 96) * 4;
}
this.f27697q++;
if (q.this.v() < 138 || j7 != 0) {
return new h(str, bArr, j7);
}
}
return null;
}
@Override
public boolean hasNext() {
if (this.f27697q < q.this.f27688d.b()) {
return true;
}
return false;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
d(q qVar, a aVar) {
this();
}
}
}