AdGuard v3.6.45版本的 MD5 值为:ce30a13dcef92cf942973fffcc6d20fb
以下内容为反编译后的 b.java 源代码,内容仅作参考
package com.adguard.android.service.b;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import androidx.core.os.EnvironmentCompat;
import com.adguard.android.a.p;
import com.adguard.android.a.s;
import com.adguard.android.service.PreferencesService;
import com.adguard.corelibs.CoreLibs;
import com.adguard.dnslibs.proxy.BuildConfig;
import io.sentry.EventProcessor;
import io.sentry.Sentry;
import io.sentry.SentryEvent;
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import io.sentry.android.core.SentryAndroid;
import io.sentry.android.core.SentryAndroidOptions;
import io.sentry.android.ndk.SentryNdk;
import io.sentry.protocol.Message;
import io.sentry.protocol.SentryThread;
import java.io.File;
import java.io.InputStream;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.apache.commons.codec.compatible.digest.MessageDigestAlgorithms;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.c;
import org.slf4j.d;
public class b implements a {
private static final c f268a = d.a(b.class);
private final boolean b;
private Context c;
private PreferencesService d;
public b(Context context, PreferencesService preferencesService) {
boolean z;
f268a.info("Creating CrashReportingService instance for {}", context);
this.c = context;
this.d = preferencesService;
String m = com.adguard.android.a.a().m();
boolean an = preferencesService.an();
final String d = d();
if (d != null) {
if (new File(d + "/.sentry-native/last_crash").exists()) {
z = true;
this.b = z;
if (z) {
f268a.debug("Last session ends with native crash");
}
if (!an && StringUtils.isNotBlank(m)) {
a(m);
return;
} else if (d == null) {
c();
a(new s() {
@Override
public final Object get() {
Object c;
c = b.c(d);
return c;
}
}, (s) null, "Failed to init SentryNdk");
return;
} else {
return;
}
}
}
z = false;
this.b = z;
if (z) {
}
if (!an) {
}
if (d == null) {
}
}
public SentryEvent a(SentryAndroidOptions sentryAndroidOptions, SentryEvent sentryEvent, Object obj) {
boolean z;
if (sentryEvent.getPlatform().equals("native")) {
c();
if (Objects.equals(sentryEvent.getRelease(), sentryAndroidOptions.getRelease())) {
List<SentryThread> threads = sentryEvent.getThreads();
if (threads == null) {
threads = new ArrayList<>();
}
sentryEvent.setThreads(threads);
for (EventProcessor eventProcessor : sentryAndroidOptions.getEventProcessors()) {
eventProcessor.process(sentryEvent, (Object) null);
}
z = true;
} else {
z = false;
}
if (!z) {
return null;
}
}
a(sentryEvent);
return sentryEvent;
}
private synchronized <T> T a(s<T> sVar, T t, String str) {
try {
} catch (Throwable th) {
try {
f268a.warn(str, th);
return t;
} catch (Throwable th2) {
throw th2;
}
}
return sVar.get();
}
private static List<String> a(ApplicationInfo applicationInfo) {
int i;
try {
JarFile jarFile = new JarFile(applicationInfo.sourceDir);
ArrayList arrayList = new ArrayList();
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry nextElement = entries.nextElement();
if (nextElement.getName().endsWith("dex")) {
arrayList.add(nextElement);
}
}
ArrayList arrayList2 = new ArrayList();
Iterator it = arrayList.iterator();
while (it.hasNext()) {
MessageDigest messageDigest = MessageDigest.getInstance(MessageDigestAlgorithms.MD5);
InputStream inputStream = jarFile.getInputStream((JarEntry) it.next());
byte[] bArr = new byte[8192];
while (true) {
if (inputStream.available() == 0) {
break;
}
messageDigest.update(bArr, 0, inputStream.read(bArr));
}
StringBuilder sb = new StringBuilder();
for (byte b : messageDigest.digest()) {
sb.append(Integer.toString((b & 255) + 256, 16).substring(1));
}
arrayList2.add(sb.toString());
}
return arrayList2;
} catch (Exception e) {
f268a.error("The error occurred while magic numbers generating the Lost serial", (Throwable) e);
return new ArrayList();
}
}
private void a(SentryEvent sentryEvent) {
String aq = com.adguard.android.a.a().aq();
if (StringUtils.isNotBlank(aq)) {
sentryEvent.setTag("developer.name", aq);
}
com.adguard.kit.h.d dVar = com.adguard.kit.h.d.f739a;
boolean z = true;
String a2 = com.adguard.kit.h.d.a(16000, true);
if (StringUtils.isNotEmpty(a2)) {
sentryEvent.setExtra("LogFile", a2);
}
sentryEvent.setExtra("APK size in Mb", com.adguard.kit.h.a.a(this.c));
List<String> a3 = a(this.c.getApplicationInfo());
sentryEvent.setExtra("The current serial codes", a3);
List<String> b = b("serial.txt");
sentryEvent.setExtra("The initial serial codes", b);
Iterator<String> it = a3.iterator();
while (true) {
if (!it.hasNext()) {
break;
} else if (!b.contains(it.next())) {
z = false;
boolean z2 = true;
break;
}
}
sentryEvent.setTag("serial_codes.matched", String.valueOf(z));
sentryEvent.setTag("version.app", com.adguard.android.a.a().i());
sentryEvent.setTag("version.title", com.adguard.android.a.a().k());
sentryEvent.setTag("version.dnslibs", BuildConfig.VERSION_NAME);
sentryEvent.setTag("version.kit", "2.0.74.3");
sentryEvent.setTag("version.showcase", "1.4.11");
sentryEvent.setTag("version.events", "1.1.1");
Boolean b2 = com.adguard.kit.h.a.b(this.c);
sentryEvent.setTag("debuggable", b2 != null ? b2.toString() : EnvironmentCompat.MEDIA_UNKNOWN);
CoreLibs.Versions coreLibsVersions = CoreLibs.getCoreLibsVersions();
sentryEvent.setTag("version.cl", coreLibsVersions.core);
sentryEvent.setTag("version.cl.contentScript", coreLibsVersions.contentScript);
sentryEvent.setTag("version.cl.scriptletsLibrary", coreLibsVersions.scriptletsLibrary);
sentryEvent.setTag("version.cl.stealthScript", coreLibsVersions.stealthScript);
sentryEvent.setTag("version.cl.userScriptWrapper", coreLibsVersions.userScriptWrapper);
}
private void a(final String str) {
a(new s() {
@Override
public final Object get() {
Object d;
d = b.this.d(str);
return d;
}
}, (s) null, "Sentry can't be initialized");
}
public void a(String str, final SentryAndroidOptions sentryAndroidOptions) {
sentryAndroidOptions.setDsn(str);
sentryAndroidOptions.setBeforeSend(new SentryOptions.BeforeSendCallback() {
@Override
public final SentryEvent execute(SentryEvent sentryEvent, Object obj) {
SentryEvent a2;
a2 = b.this.a(sentryAndroidOptions, sentryEvent, obj);
return a2;
}
});
}
private List<String> b(String str) {
try {
return Arrays.asList(com.adguard.android.a.c.a(this.c, str).split("\n"));
} catch (Exception e) {
f268a.error("The error occurred while getting the strings list from the assets file {}", str, e);
return new ArrayList();
}
}
public static Object c(String str) {
SentryAndroidOptions sentryAndroidOptions = new SentryAndroidOptions();
sentryAndroidOptions.setCacheDirPath(new File(str).getAbsolutePath());
sentryAndroidOptions.setDsn("");
SentryNdk.init(sentryAndroidOptions);
return null;
}
private void c() {
String d = d();
if (d == null) {
f268a.debug("Native crash dir does not exist");
return;
}
File file = new File(d + "/.sentry-native/last_crash");
if (file.exists() && file.delete()) {
f268a.debug("Last crash was removed from cache");
}
}
public Object d(final String str) {
SentryAndroid.init(this.c, new Sentry.OptionsConfiguration() {
@Override
public final void configure(SentryOptions sentryOptions) {
b.this.a(str, (SentryAndroidOptions) sentryOptions);
}
});
return null;
}
private String d() {
File cacheDir = this.c.getCacheDir();
if (cacheDir == null) {
return null;
}
File file = new File(cacheDir, "sentry");
if (file.exists() || file.mkdir()) {
return file.getAbsolutePath();
}
return null;
}
public static Void e() {
Sentry.close();
return null;
}
@Override
public final void a(Throwable th) {
if (this.d.an() && ((Boolean) a((s<$$Lambda$I53h9WLlHYt_4e17gnGqfE0XaL8>) new s() {
@Override
public final Object get() {
return Boolean.valueOf(Sentry.isEnabled());
}
}, ($$Lambda$I53h9WLlHYt_4e17gnGqfE0XaL8) Boolean.FALSE, "Failed to check Sentry state")).booleanValue()) {
String format = String.format("(%s) %s", p.c(this.c), th.getMessage());
try {
Message message = new Message();
message.setMessage(format);
SentryEvent sentryEvent = new SentryEvent(th);
sentryEvent.setMessage(message);
sentryEvent.setLevel(SentryLevel.FATAL);
Sentry.captureEvent(sentryEvent);
} catch (Throwable th2) {
f268a.warn("Failed to capture event {}", format, th2);
}
}
}
@Override
public final void a(boolean z) {
String m = com.adguard.android.a.a().m();
boolean an = this.d.an();
if (z && !an && StringUtils.isNotBlank(m)) {
a(m);
} else if (!z && an) {
b();
}
this.d.x(z);
}
@Override
public final boolean a() {
return this.b;
}
@Override
public final void b() {
a(new s() {
@Override
public final Object get() {
Void e;
e = b.e();
return e;
}
}, ($$Lambda$b$tuBPYVhqdUyQwvbq2chuufqwNA4) null, "Can't close Sentry");
}
}