discord-jadx/app/src/main/java/c/f/m/m.java

560 lines
20 KiB
Java

package c.f.m;
import android.content.Context;
import android.os.Parcel;
import android.os.StrictMode;
import android.util.Log;
import com.airbnb.lottie.parser.AnimatableValueParser;
import com.facebook.soloader.SysUtil$LollipopSysdeps;
import java.io.Closeable;
import java.io.DataInput;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/* compiled from: UnpackingSoSource */
public abstract class m extends c {
/* renamed from: c reason: collision with root package name */
public final Context f510c;
public String d;
public final Map<String, Object> e = new HashMap();
/* compiled from: UnpackingSoSource */
public class a implements Runnable {
public final /* synthetic */ File i;
public final /* synthetic */ byte[] j;
public final /* synthetic */ c k;
public final /* synthetic */ File l;
public final /* synthetic */ g m;
public a(File file, byte[] bArr, c cVar, File file2, g gVar) {
this.i = file;
this.j = bArr;
this.k = cVar;
this.l = file2;
this.m = gVar;
}
/* JADX WARNING: Code restructure failed: missing block: B:20:0x008d, code lost:
r4 = move-exception;
*/
/* JADX WARNING: Code restructure failed: missing block: B:22:?, code lost:
r5.close();
*/
/* JADX WARNING: Code restructure failed: missing block: B:23:0x0092, code lost:
r5 = move-exception;
*/
/* JADX WARNING: Code restructure failed: missing block: B:24:0x0093, code lost:
r2.addSuppressed(r5);
*/
/* JADX WARNING: Code restructure failed: missing block: B:25:0x0096, code lost:
throw r4;
*/
/* JADX WARNING: Code restructure failed: missing block: B:29:0x0099, code lost:
r5 = move-exception;
*/
/* JADX WARNING: Code restructure failed: missing block: B:31:?, code lost:
r4.close();
*/
/* JADX WARNING: Code restructure failed: missing block: B:32:0x009e, code lost:
r4 = move-exception;
*/
/* JADX WARNING: Code restructure failed: missing block: B:33:0x009f, code lost:
r2.addSuppressed(r4);
*/
/* JADX WARNING: Code restructure failed: missing block: B:34:0x00a2, code lost:
throw r5;
*/
@Override // java.lang.Runnable
public void run() {
String str = " (from syncer thread)";
String str2 = "releasing dso store lock for ";
String str3 = "fb-UnpackingSoSource";
try {
Log.v("fb-UnpackingSoSource", "starting syncer worker");
RandomAccessFile randomAccessFile = new RandomAccessFile(this.i, "rw");
randomAccessFile.write(this.j);
randomAccessFile.setLength(randomAccessFile.getFilePointer());
randomAccessFile.close();
RandomAccessFile randomAccessFile2 = new RandomAccessFile(new File(m.this.a, "dso_manifest"), "rw");
c cVar = this.k;
Objects.requireNonNull(cVar);
randomAccessFile2.writeByte(1);
randomAccessFile2.writeInt(cVar.a.length);
int i = 0;
while (true) {
b[] bVarArr = cVar.a;
if (i < bVarArr.length) {
randomAccessFile2.writeUTF(bVarArr[i].i);
randomAccessFile2.writeUTF(cVar.a[i].j);
i++;
} else {
randomAccessFile2.close();
AnimatableValueParser.o0(m.this.a);
m.k(this.l, (byte) 1);
try {
return;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
} finally {
Log.v(str3, str2 + m.this.a + str);
this.m.close();
}
}
}
/* compiled from: UnpackingSoSource */
public static class b {
public final String i;
public final String j;
public b(String str, String str2) {
this.i = str;
this.j = str2;
}
}
/* compiled from: UnpackingSoSource */
public static final class c {
public final b[] a;
public c(b[] bVarArr) {
this.a = bVarArr;
}
public static final c a(DataInput dataInput) throws IOException {
if (dataInput.readByte() == 1) {
int readInt = dataInput.readInt();
if (readInt >= 0) {
b[] bVarArr = new b[readInt];
for (int i = 0; i < readInt; i++) {
bVarArr[i] = new b(dataInput.readUTF(), dataInput.readUTF());
}
return new c(bVarArr);
}
throw new RuntimeException("illegal number of shared libraries");
}
throw new RuntimeException("wrong dso manifest version");
}
}
/* compiled from: UnpackingSoSource */
public static final class d implements Closeable {
public final b i;
public final InputStream j;
public d(b bVar, InputStream inputStream) {
this.i = bVar;
this.j = inputStream;
}
@Override // java.io.Closeable, java.lang.AutoCloseable
public void close() throws IOException {
this.j.close();
}
}
/* compiled from: UnpackingSoSource */
public static abstract class e implements Closeable {
public abstract boolean a();
public abstract d b() throws IOException;
@Override // java.io.Closeable, java.lang.AutoCloseable
public void close() throws IOException {
}
}
/* compiled from: UnpackingSoSource */
public static abstract class f implements Closeable {
public abstract c a() throws IOException;
public abstract e b() throws IOException;
@Override // java.io.Closeable, java.lang.AutoCloseable
public void close() throws IOException {
}
}
public m(Context context, String str) {
super(new File(context.getApplicationInfo().dataDir + "/" + str), 1);
this.f510c = context;
}
/* JADX WARNING: Code restructure failed: missing block: B:10:?, code lost:
r0.close();
*/
/* JADX WARNING: Code restructure failed: missing block: B:11:0x0028, code lost:
r0 = move-exception;
*/
/* JADX WARNING: Code restructure failed: missing block: B:12:0x0029, code lost:
r3.addSuppressed(r0);
*/
/* JADX WARNING: Code restructure failed: missing block: B:13:0x002c, code lost:
throw r4;
*/
/* JADX WARNING: Code restructure failed: missing block: B:8:0x0023, code lost:
r4 = move-exception;
*/
public static void k(File file, byte b2) throws IOException {
RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
randomAccessFile.seek(0);
randomAccessFile.write(b2);
randomAccessFile.setLength(randomAccessFile.getFilePointer());
randomAccessFile.getFD().sync();
randomAccessFile.close();
}
@Override // c.f.m.c, c.f.m.l
public int a(String str, int i, StrictMode.ThreadPolicy threadPolicy) throws IOException {
int c2;
synchronized (g(str)) {
c2 = c(str, i, this.a, threadPolicy);
}
return c2;
}
@Override // c.f.m.l
public void b(int i) throws IOException {
String str = "releasing dso store lock for ";
String str2 = "fb-UnpackingSoSource";
File file = this.a;
if (file.mkdirs() || file.isDirectory()) {
g gVar = new g(new File(this.a, "dso_lock"));
try {
Log.v("fb-UnpackingSoSource", "locked dso store " + this.a);
if (i(gVar, i, f())) {
gVar = null;
} else {
Log.i("fb-UnpackingSoSource", "dso store is up-to-date: " + this.a);
}
if (gVar == null) {
StringBuilder L = c.d.b.a.a.L("not releasing dso store lock for ");
L.append(this.a);
L.append(" (syncer thread started)");
Log.v("fb-UnpackingSoSource", L.toString());
}
} finally {
StringBuilder L2 = c.d.b.a.a.L(str);
L2.append(this.a);
Log.v(str2, L2.toString());
gVar.close();
}
} else {
throw new IOException("cannot mkdir: " + file);
}
}
public final void d(b[] bVarArr) throws IOException {
String[] list = this.a.list();
if (list != null) {
for (String str : list) {
if (!str.equals("dso_state") && !str.equals("dso_lock") && !str.equals("dso_deps") && !str.equals("dso_manifest")) {
boolean z2 = false;
int i = 0;
while (!z2 && i < bVarArr.length) {
if (bVarArr[i].i.equals(str)) {
z2 = true;
}
i++;
}
if (!z2) {
File file = new File(this.a, str);
Log.v("fb-UnpackingSoSource", "deleting unaccounted-for file " + file);
AnimatableValueParser.d0(file);
}
}
}
return;
}
StringBuilder L = c.d.b.a.a.L("unable to list directory ");
L.append(this.a);
throw new IOException(L.toString());
}
public final void e(d dVar, byte[] bArr) throws IOException {
RandomAccessFile randomAccessFile;
StringBuilder L = c.d.b.a.a.L("extracting DSO ");
L.append(dVar.i.i);
Log.i("fb-UnpackingSoSource", L.toString());
if (this.a.setWritable(true, true)) {
File file = new File(this.a, dVar.i.i);
try {
randomAccessFile = new RandomAccessFile(file, "rw");
} catch (IOException e2) {
Log.w("fb-UnpackingSoSource", "error overwriting " + file + " trying to delete and start over", e2);
AnimatableValueParser.d0(file);
randomAccessFile = new RandomAccessFile(file, "rw");
}
try {
int available = dVar.j.available();
if (available > 1) {
SysUtil$LollipopSysdeps.fallocateIfSupported(randomAccessFile.getFD(), (long) available);
}
InputStream inputStream = dVar.j;
int i = 0;
while (i < Integer.MAX_VALUE) {
int read = inputStream.read(bArr, 0, Math.min(bArr.length, Integer.MAX_VALUE - i));
if (read == -1) {
break;
}
randomAccessFile.write(bArr, 0, read);
i += read;
}
randomAccessFile.setLength(randomAccessFile.getFilePointer());
if (file.setExecutable(true, false)) {
randomAccessFile.close();
return;
}
throw new IOException("cannot make file executable: " + file);
} catch (IOException e3) {
AnimatableValueParser.d0(file);
throw e3;
} catch (Throwable th) {
randomAccessFile.close();
throw th;
}
} else {
StringBuilder L2 = c.d.b.a.a.L("cannot make directory writable for us: ");
L2.append(this.a);
throw new IOException(L2.toString());
}
}
/* JADX WARNING: Code restructure failed: missing block: B:12:0x0038, code lost:
r2 = move-exception;
*/
/* JADX WARNING: Code restructure failed: missing block: B:13:0x0039, code lost:
if (r1 != null) goto L_0x003b;
*/
/* JADX WARNING: Code restructure failed: missing block: B:15:?, code lost:
r1.close();
*/
/* JADX WARNING: Code restructure failed: missing block: B:16:0x003f, code lost:
r1 = move-exception;
*/
/* JADX WARNING: Code restructure failed: missing block: B:17:0x0040, code lost:
r0.addSuppressed(r1);
*/
/* JADX WARNING: Code restructure failed: missing block: B:18:0x0043, code lost:
throw r2;
*/
public byte[] f() throws IOException {
Parcel obtain = Parcel.obtain();
f h = h();
b[] bVarArr = h.a().a;
obtain.writeByte((byte) 1);
obtain.writeInt(bVarArr.length);
for (int i = 0; i < bVarArr.length; i++) {
obtain.writeString(bVarArr[i].i);
obtain.writeString(bVarArr[i].j);
}
h.close();
byte[] marshall = obtain.marshall();
obtain.recycle();
return marshall;
}
public final Object g(String str) {
Object obj;
synchronized (this.e) {
obj = this.e.get(str);
if (obj == null) {
obj = new Object();
this.e.put(str, obj);
}
}
return obj;
}
public abstract f h() throws IOException;
/* JADX WARNING: Code restructure failed: missing block: B:10:?, code lost:
r1.close();
*/
/* JADX WARNING: Code restructure failed: missing block: B:11:0x003d, code lost:
r14 = move-exception;
*/
/* JADX WARNING: Code restructure failed: missing block: B:12:0x003e, code lost:
r12.addSuppressed(r14);
*/
/* JADX WARNING: Code restructure failed: missing block: B:13:0x0041, code lost:
throw r13;
*/
/* JADX WARNING: Code restructure failed: missing block: B:51:0x00d3, code lost:
r13 = move-exception;
*/
/* JADX WARNING: Code restructure failed: missing block: B:52:0x00d4, code lost:
if (r0 != null) goto L_0x00d6;
*/
/* JADX WARNING: Code restructure failed: missing block: B:54:?, code lost:
r0.close();
*/
/* JADX WARNING: Code restructure failed: missing block: B:55:0x00da, code lost:
r14 = move-exception;
*/
/* JADX WARNING: Code restructure failed: missing block: B:56:0x00db, code lost:
r12.addSuppressed(r14);
*/
/* JADX WARNING: Code restructure failed: missing block: B:57:0x00de, code lost:
throw r13;
*/
/* JADX WARNING: Code restructure failed: missing block: B:61:0x00e1, code lost:
r13 = move-exception;
*/
/* JADX WARNING: Code restructure failed: missing block: B:63:?, code lost:
r7.close();
*/
/* JADX WARNING: Code restructure failed: missing block: B:64:0x00e6, code lost:
r14 = move-exception;
*/
/* JADX WARNING: Code restructure failed: missing block: B:65:0x00e7, code lost:
r12.addSuppressed(r14);
*/
/* JADX WARNING: Code restructure failed: missing block: B:66:0x00ea, code lost:
throw r13;
*/
/* JADX WARNING: Code restructure failed: missing block: B:8:0x0038, code lost:
r13 = move-exception;
*/
/* JADX WARNING: Removed duplicated region for block: B:37:0x009d A[RETURN] */
/* JADX WARNING: Removed duplicated region for block: B:38:0x009e */
public final boolean i(g gVar, int i, byte[] bArr) throws IOException {
File file = new File(this.a, "dso_state");
RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
byte b2 = randomAccessFile.readByte();
if (b2 != 1) {
Log.v("fb-UnpackingSoSource", "dso store " + this.a + " regeneration interrupted: wiping clean");
b2 = 0;
}
randomAccessFile.close();
File file2 = new File(this.a, "dso_deps");
c cVar = null;
RandomAccessFile randomAccessFile2 = new RandomAccessFile(file2, "rw");
int length = (int) randomAccessFile2.length();
byte[] bArr2 = new byte[length];
if (randomAccessFile2.read(bArr2) != length) {
Log.v("fb-UnpackingSoSource", "short read of so store deps file: marking unclean");
b2 = 0;
}
if (!Arrays.equals(bArr2, bArr)) {
Log.v("fb-UnpackingSoSource", "deps mismatch on deps store: regenerating");
b2 = 0;
}
if (b2 != 0) {
if ((i & 2) != 0) {
}
randomAccessFile2.close();
if (cVar != null) {
return false;
}
a aVar = new a(file2, bArr, cVar, file, gVar);
if ((i & 1) != 0) {
StringBuilder L = c.d.b.a.a.L("SoSync:");
L.append(this.a.getName());
new Thread(aVar, L.toString()).start();
} else {
aVar.run();
}
return true;
}
Log.v("fb-UnpackingSoSource", "so store dirty: regenerating");
k(file, (byte) 0);
f h = h();
cVar = h.a();
j(b2, cVar, h.b());
h.close();
randomAccessFile2.close();
if (cVar != null) {
}
}
/* JADX WARNING: Code restructure failed: missing block: B:47:0x00c5, code lost:
r9 = move-exception;
*/
/* JADX WARNING: Code restructure failed: missing block: B:49:?, code lost:
r2.close();
*/
/* JADX WARNING: Code restructure failed: missing block: B:50:0x00ca, code lost:
r10 = move-exception;
*/
/* JADX WARNING: Code restructure failed: missing block: B:51:0x00cb, code lost:
r8.addSuppressed(r10);
*/
/* JADX WARNING: Code restructure failed: missing block: B:52:0x00ce, code lost:
throw r9;
*/
/* JADX WARNING: Removed duplicated region for block: B:12:0x003f A[Catch:{ all -> 0x00c5 }] */
/* JADX WARNING: Removed duplicated region for block: B:16:0x0056 A[Catch:{ all -> 0x00c5 }] */
public final void j(byte b2, c cVar, e eVar) throws IOException {
c cVar2;
StringBuilder L = c.d.b.a.a.L("regenerating DSO store ");
L.append(getClass().getName());
Log.v("fb-UnpackingSoSource", L.toString());
RandomAccessFile randomAccessFile = new RandomAccessFile(new File(this.a, "dso_manifest"), "rw");
if (b2 == 1) {
try {
cVar2 = c.a(randomAccessFile);
} catch (Exception e2) {
Log.i("fb-UnpackingSoSource", "error reading existing DSO manifest", e2);
}
if (cVar2 == null) {
cVar2 = new c(new b[0]);
}
d(cVar.a);
byte[] bArr = new byte[32768];
while (eVar.a()) {
d b3 = eVar.b();
boolean z2 = true;
int i = 0;
while (z2) {
try {
b[] bVarArr = cVar2.a;
if (i >= bVarArr.length) {
break;
}
if (bVarArr[i].i.equals(b3.i.i) && cVar2.a[i].j.equals(b3.i.j)) {
z2 = false;
}
i++;
} catch (Throwable th) {
if (b3 != null) {
try {
b3.j.close();
} catch (Throwable th2) {
th.addSuppressed(th2);
}
}
throw th;
}
}
if (z2) {
e(b3, bArr);
}
if (b3 != null) {
b3.j.close();
}
}
randomAccessFile.close();
Log.v("fb-UnpackingSoSource", "Finished regenerating DSO store " + getClass().getName());
}
cVar2 = null;
if (cVar2 == null) {
}
d(cVar.a);
byte[] bArr = new byte[32768];
while (eVar.a()) {
}
randomAccessFile.close();
Log.v("fb-UnpackingSoSource", "Finished regenerating DSO store " + getClass().getName());
}
}