discord-jadx/app/src/main/java/com/discord/utilities/systemlog/SystemLogUtils.java
2021-07-04 01:36:06 +02:00

337 lines
13 KiB
Java

package com.discord.utilities.systemlog;
import c.d.b.a.a;
import com.discord.utilities.debug.DebugPrintableCollection;
import d0.f0.q;
import d0.g0.c;
import d0.g0.i;
import d0.g0.t;
import d0.g0.w;
import d0.t.k;
import d0.t.n0;
import d0.z.d.m;
import j0.l.e.j;
import java.io.BufferedReader;
import java.io.File;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import kotlin.jvm.internal.Ref$ObjectRef;
import kotlin.sequences.Sequence;
import kotlin.text.MatchResult;
import kotlin.text.Regex;
import rx.Observable;
/* compiled from: SystemLogUtils.kt */
public final class SystemLogUtils {
public static final SystemLogUtils INSTANCE = new SystemLogUtils();
private static final DebugPrintableCollection debugPrintables = new DebugPrintableCollection();
public static final String logcatPath = "/system/bin/logcat";
private static final int maxLogSize = 2500000;
private static final Regex regexExtractTombstone;
private static final SystemLogCapture systemLogCapture = new SystemLogCapture();
/* compiled from: SystemLogUtils.kt */
public static final class Tombstone {
private final String groupBy;
private final String hash;
private final String origin;
private final String text;
public Tombstone(String str, String str2, String str3, String str4) {
m.checkNotNullParameter(str, "text");
m.checkNotNullParameter(str2, "groupBy");
m.checkNotNullParameter(str3, "origin");
m.checkNotNullParameter(str4, "hash");
this.text = str;
this.groupBy = str2;
this.origin = str3;
this.hash = str4;
}
public static /* synthetic */ Tombstone copy$default(Tombstone tombstone, String str, String str2, String str3, String str4, int i, Object obj) {
if ((i & 1) != 0) {
str = tombstone.text;
}
if ((i & 2) != 0) {
str2 = tombstone.groupBy;
}
if ((i & 4) != 0) {
str3 = tombstone.origin;
}
if ((i & 8) != 0) {
str4 = tombstone.hash;
}
return tombstone.copy(str, str2, str3, str4);
}
public final String component1() {
return this.text;
}
public final String component2() {
return this.groupBy;
}
public final String component3() {
return this.origin;
}
public final String component4() {
return this.hash;
}
public final Tombstone copy(String str, String str2, String str3, String str4) {
m.checkNotNullParameter(str, "text");
m.checkNotNullParameter(str2, "groupBy");
m.checkNotNullParameter(str3, "origin");
m.checkNotNullParameter(str4, "hash");
return new Tombstone(str, str2, str3, str4);
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Tombstone)) {
return false;
}
Tombstone tombstone = (Tombstone) obj;
return m.areEqual(this.text, tombstone.text) && m.areEqual(this.groupBy, tombstone.groupBy) && m.areEqual(this.origin, tombstone.origin) && m.areEqual(this.hash, tombstone.hash);
}
public final String getGroupBy() {
return this.groupBy;
}
public final String getHash() {
return this.hash;
}
public final String getOrigin() {
return this.origin;
}
public final String getText() {
return this.text;
}
public int hashCode() {
String str = this.text;
int i = 0;
int hashCode = (str != null ? str.hashCode() : 0) * 31;
String str2 = this.groupBy;
int hashCode2 = (hashCode + (str2 != null ? str2.hashCode() : 0)) * 31;
String str3 = this.origin;
int hashCode3 = (hashCode2 + (str3 != null ? str3.hashCode() : 0)) * 31;
String str4 = this.hash;
if (str4 != null) {
i = str4.hashCode();
}
return hashCode3 + i;
}
public String toString() {
StringBuilder L = a.L("Tombstone(text=");
L.append(this.text);
L.append(", groupBy=");
L.append(this.groupBy);
L.append(", origin=");
L.append(this.origin);
L.append(", hash=");
return a.D(L, this.hash, ")");
}
}
static {
StringBuilder L = a.L("(?:^(?:[^\\s]+\\s+){4}F\\s+DEBUG\\s+:\\s(.+))|(^.+(\\[");
L.append(Regex.i.escape("libdiscord_version"));
L.append("\\].+))");
regexExtractTombstone = new Regex(L.toString());
}
private SystemLogUtils() {
}
public static final /* synthetic */ void access$waitFor(SystemLogUtils systemLogUtils, Process process) {
systemLogUtils.waitFor(process);
}
private final Observable<LinkedList<String>> fetch(Regex regex) {
LinkedList linkedList = new LinkedList();
boolean z2 = regex == null;
if (!new File("/system/bin/logcat").exists()) {
if (z2) {
linkedList.add("Unable to locate '/system/bin/logcat'");
}
j jVar = new j(linkedList);
m.checkNotNullExpressionValue(jVar, "Observable.just(output)");
return jVar;
}
Observable<LinkedList<String>> X = Observable.C(new SystemLogUtils$fetch$1(linkedList, regex, z2)).X(j0.p.a.b().d);
m.checkNotNullExpressionValue(X, "Observable.fromCallable …n(Schedulers.newThread())");
return X;
}
private final String hashString(String str) {
MessageDigest instance = MessageDigest.getInstance("SHA-1");
Charset charset = c.a;
Objects.requireNonNull(str, "null cannot be cast to non-null type java.lang.String");
byte[] bytes = str.getBytes(charset);
m.checkNotNullExpressionValue(bytes, "(this as java.lang.String).getBytes(charset)");
byte[] digest = instance.digest(bytes);
m.checkNotNullExpressionValue(digest, "bytes");
return k.joinToString$default(digest, "", (CharSequence) null, (CharSequence) null, 0, (CharSequence) null, SystemLogUtils$hashString$1.INSTANCE, 30, (Object) null);
}
private final void waitFor(Process process) {
long nanos = TimeUnit.SECONDS.toNanos(15) + System.nanoTime();
do {
try {
process.exitValue();
return;
} catch (IllegalThreadStateException unused) {
Thread.sleep(100);
if (System.nanoTime() >= nanos) {
}
}
} while (System.nanoTime() >= nanos);
}
public final String fetch() {
StringBuilder sb = new StringBuilder();
debugPrintables.debugPrint(sb);
systemLogCapture.appendOutput(sb);
String sb2 = sb.toString();
m.checkNotNullExpressionValue(sb2, "sb.toString()");
return sb2;
}
public final Observable<Tombstone> fetchLastTombstone() {
Observable<R> z2 = fetch(regexExtractTombstone).z(SystemLogUtils$fetchLastTombstone$1.INSTANCE);
m.checkNotNullExpressionValue(z2, "fetch(regexExtractTombst…ble.just(tombstone)\n }");
return z2;
}
public final Tombstone fetchLastTombstone$app_productionBetaRelease(Collection<String> collection) {
String str;
m.checkNotNullParameter(collection, "crashes");
if (collection.isEmpty()) {
return null;
}
Ref$ObjectRef ref$ObjectRef = new Ref$ObjectRef();
ref$ObjectRef.element = null;
Ref$ObjectRef ref$ObjectRef2 = new Ref$ObjectRef();
ref$ObjectRef2.element = null;
String invoke = new SystemLogUtils$fetchLastTombstone$text$1(collection, ref$ObjectRef, ref$ObjectRef2).mo1invoke();
m.checkNotNullExpressionValue(invoke, "{\n val sb = StringB… sb.toString()\n }()");
String str2 = invoke;
if (t.isBlank(str2)) {
return null;
}
Sequence map = q.map(Regex.findAll$default(new Regex("^\\s+#\\d+ pc .+/(.+? .+?)\\+?[+)]", i.MULTILINE), str2, 0, 2, null), new SystemLogUtils$fetchLastTombstone$extractedGroups$1(new Regex("classes\\d+.dex")));
HashSet hashSetOf = n0.hashSetOf("libc.so (abort", "libart.so (art::Runtime::Abort(char const*", "libbase.so (android::base::LogMessage::~LogMessage(");
try {
for (Object obj : map) {
if (!hashSetOf.contains((String) obj)) {
str = (String) obj;
String joinToString$default = q.joinToString$default(map, "\n", null, null, 0, null, null, 62, null);
return new Tombstone(str2, joinToString$default, str, hashString(joinToString$default));
}
}
throw new NoSuchElementException("Sequence contains no element matching the predicate.");
} catch (NoSuchElementException unused) {
str = "Unknown";
}
}
public final DebugPrintableCollection getDebugPrintables$app_productionBetaRelease() {
return debugPrintables;
}
public final Regex getRegexExtractTombstone$app_productionBetaRelease() {
return regexExtractTombstone;
}
public final Thread initSystemLogCapture() {
return systemLogCapture.startThread();
}
/* JADX WARNING: Removed duplicated region for block: B:39:0x0084 */
/* JADX WARNING: Removed duplicated region for block: B:41:0x009a */
/* JADX WARNING: Removed duplicated region for block: B:59:? A[RETURN, SYNTHETIC] */
public final void processLogs$app_productionBetaRelease(BufferedReader bufferedReader, LinkedList<String> linkedList, Regex regex) {
Exception e;
boolean z2;
m.checkNotNullParameter(bufferedReader, "reader");
m.checkNotNullParameter(linkedList, "output");
int i = 0;
while (true) {
try {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
if (regex != null) {
MatchResult find$default = Regex.find$default(regex, readLine, 0, 2, null);
if (find$default != null) {
List<String> groupValues = find$default.getGroupValues();
ListIterator<String> listIterator = groupValues.listIterator(groupValues.size());
while (listIterator.hasPrevious()) {
String previous = listIterator.previous();
if (previous.length() > 0) {
z2 = true;
continue;
} else {
z2 = false;
continue;
}
if (z2) {
readLine = previous;
}
}
throw new NoSuchElementException("List contains no element matching the predicate.");
}
continue;
}
if (!t.isBlank(readLine)) {
if (!w.contains$default((CharSequence) readLine, (CharSequence) "Accessing hidden method", false, 2, (Object) null)) {
int length = readLine.length() + 1 + i;
try {
linkedList.add(readLine);
if (length > 2500000) {
length -= linkedList.pop().length() - 1;
}
i = length;
} catch (Exception e2) {
e = e2;
i = length;
e.printStackTrace();
if (regex == null) {
}
if (i > 2500000) {
}
}
}
}
} catch (Exception e3) {
e = e3;
e.printStackTrace();
if (regex == null) {
linkedList.add("IOException: " + e);
}
if (i > 2500000) {
}
}
}
if (i > 2500000) {
linkedList.pop().length();
}
}
}