2021-06-21 10:09:18 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
Date: Sun, 20 Jun 2021 18:19:09 -0700
2021-06-22 06:12:07 +02:00
Subject: [PATCH] Deobfuscate stacktraces in log messages, crash reports, and
etc.
2021-06-21 10:09:18 +02:00
diff --git a/build.gradle.kts b/build.gradle.kts
2022-03-11 21:13:46 +01:00
index fd4b0c173be72516f22c6e5d540249e3079a7216..cf6c265714d8241f52e83de59094d7ae2cd56884 100644
2021-06-21 10:09:18 +02:00
--- a/build.gradle.kts
+++ b/build.gradle.kts
2021-11-24 22:27:16 +01:00
@@ -1,4 +1,6 @@
2021-06-21 10:09:18 +02:00
+import io.papermc.paperweight.tasks.BaseTask
2021-10-11 23:31:53 +02:00
import io.papermc.paperweight.util.*
2021-06-21 10:09:18 +02:00
+import java.nio.file.Files
2021-07-20 00:58:48 +02:00
plugins {
2021-11-26 07:08:46 +01:00
java
@@ -8,6 +10,11 @@ plugins {
2021-06-21 10:09:18 +02:00
repositories {
maven("https://libraries.minecraft.net/")
+ // Paper start
2021-11-05 01:23:06 +01:00
+ maven("https://maven.fabricmc.net/") {
+ mavenContent { includeModule("net.fabricmc", "mapping-io") }
2021-06-21 10:09:18 +02:00
+ }
+ // Paper end
}
dependencies {
2021-11-26 07:08:46 +01:00
@@ -23,6 +30,7 @@ dependencies {
2021-11-24 22:27:16 +01:00
Scanning takes about 1-2 seconds so adding this speeds up the server start.
*/
implementation("org.apache.logging.log4j:log4j-core:2.14.1") // Paper - implementation
+ annotationProcessor("org.apache.logging.log4j:log4j-core:2.14.1") // Paper - Needed to generate meta for our Log4j plugins
// Paper end
2022-03-01 06:43:03 +01:00
implementation("org.apache.logging.log4j:log4j-iostreams:2.17.1") // Paper
2021-11-24 22:27:16 +01:00
implementation("org.ow2.asm:asm:9.2")
2021-11-27 07:54:18 +01:00
@@ -35,6 +43,8 @@ dependencies {
2021-12-20 23:46:51 +01:00
runtimeOnly("org.apache.maven.resolver:maven-resolver-connector-basic:1.7.2")
runtimeOnly("org.apache.maven.resolver:maven-resolver-transport-http:1.7.2")
2021-06-21 10:09:18 +02:00
2021-11-05 01:23:06 +01:00
+ implementation("net.fabricmc:mapping-io:0.3.0") // Paper - needed to read mappings for stacktrace deobfuscation
2021-06-21 10:09:18 +02:00
+
2021-12-20 23:46:51 +01:00
testImplementation("junit:junit:4.13.2")
2021-06-21 10:09:18 +02:00
testImplementation("org.hamcrest:hamcrest-library:1.3")
2021-09-09 18:57:16 +02:00
}
2021-12-05 08:42:28 +01:00
@@ -92,6 +102,45 @@ tasks.shadowJar {
2021-11-24 12:38:00 +01:00
}
2021-06-21 10:09:18 +02:00
}
+// Paper start - include reobf mappings in jar for stacktrace deobfuscation
+abstract class IncludeMappings : BaseTask() {
+ @get:InputFile
+ abstract val inputJar: RegularFileProperty
+
+ @get:InputFile
+ abstract val mappings: RegularFileProperty
+
+ @get:OutputFile
+ abstract val outputJar: RegularFileProperty
+
+ override fun init() {
2021-10-11 23:31:53 +02:00
+ super.init()
2021-06-21 10:09:18 +02:00
+ outputJar.convention(defaultOutput())
+ }
+
+ @TaskAction
+ private fun addMappings() {
+ outputJar.get().asFile.parentFile.mkdirs()
+ inputJar.get().asFile.copyTo(outputJar.get().asFile, overwrite = true)
+ outputJar.get().path.openZip().use { fs ->
+ val dir = fs.getPath("META-INF/mappings/")
+ Files.createDirectories(dir)
+ val target = dir.resolve("reobf.tiny")
+ Files.copy(mappings.path, target)
+ }
+ }
+}
+
+val includeMappings = tasks.register<IncludeMappings>("includeMappings") {
2021-06-27 05:26:17 +02:00
+ inputJar.set(tasks.fixJarForReobf.flatMap { it.outputJar })
2021-06-21 10:09:18 +02:00
+ mappings.set(tasks.reobfJar.flatMap { it.mappingsFile })
+}
+
+tasks.reobfJar {
+ inputJar.set(includeMappings.flatMap { it.outputJar })
+}
+// Paper end - include reobf mappings in jar for stacktrace deobfuscation
+
tasks.test {
exclude("org/bukkit/craftbukkit/inventory/ItemStack*Test.class")
}
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
2022-03-11 21:13:46 +01:00
index fda5a623ec6bba0ed4d230415f7b9779ee2e8ccf..af43c63df3c82e910b77afd2a8899b8e6fc6db6d 100644
2021-06-21 10:09:18 +02:00
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
2021-12-28 09:10:38 +01:00
@@ -430,4 +430,9 @@ public class PaperConfig {
2021-09-09 18:57:16 +02:00
log("Async Chunks: Enabled - Chunks will be loaded much faster, without lag.");
}
2021-06-21 10:09:18 +02:00
}
2021-09-09 18:57:16 +02:00
+
2021-06-21 10:09:18 +02:00
+ public static boolean deobfuscateStacktraces = true;
+ private static void loggerSettings() {
+ deobfuscateStacktraces = getBoolean("settings.loggers.deobfuscate-stacktraces", deobfuscateStacktraces);
+ }
2021-09-09 18:57:16 +02:00
}
2021-07-07 09:19:08 +02:00
diff --git a/src/main/java/com/destroystokyo/paper/io/SyncLoadFinder.java b/src/main/java/com/destroystokyo/paper/io/SyncLoadFinder.java
index 0bb4aaa546939b67a5d22865190f30478a9337c1..d3e619655382e50e9ac9323ed942502d85c9599c 100644
--- a/src/main/java/com/destroystokyo/paper/io/SyncLoadFinder.java
+++ b/src/main/java/com/destroystokyo/paper/io/SyncLoadFinder.java
@@ -91,7 +91,7 @@ public class SyncLoadFinder {
final JsonArray traces = new JsonArray();
- for (StackTraceElement element : pair.getFirst().stacktrace) {
+ for (StackTraceElement element : io.papermc.paper.util.StacktraceDeobfuscator.INSTANCE.deobfuscateStacktrace(pair.getFirst().stacktrace)) {
traces.add(String.valueOf(element));
}
2021-06-21 10:09:18 +02:00
diff --git a/src/main/java/io/papermc/paper/logging/StacktraceDeobfuscatingRewritePolicy.java b/src/main/java/io/papermc/paper/logging/StacktraceDeobfuscatingRewritePolicy.java
new file mode 100644
2021-09-30 20:05:51 +02:00
index 0000000000000000000000000000000000000000..c701ef3c287f62aa0ebfbdbd6da6ed82a1c7793c
2021-06-21 10:09:18 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/logging/StacktraceDeobfuscatingRewritePolicy.java
2021-09-30 20:05:51 +02:00
@@ -0,0 +1,38 @@
2021-06-21 10:09:18 +02:00
+package io.papermc.paper.logging;
+
2021-06-22 06:12:07 +02:00
+import io.papermc.paper.util.StacktraceDeobfuscator;
+import org.apache.logging.log4j.core.Core;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.appender.rewrite.RewritePolicy;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
2021-09-30 20:05:51 +02:00
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.checkerframework.checker.nullness.qual.NonNull;
2021-06-22 06:12:07 +02:00
+
+@Plugin(
+ name = "StacktraceDeobfuscatingRewritePolicy",
+ category = Core.CATEGORY_NAME,
+ elementType = "rewritePolicy",
+ printObject = true
+)
+public final class StacktraceDeobfuscatingRewritePolicy implements RewritePolicy {
2021-09-30 20:05:51 +02:00
+ private StacktraceDeobfuscatingRewritePolicy() {
+ }
+
2021-06-22 06:12:07 +02:00
+ @Override
2021-09-30 20:05:51 +02:00
+ public @NonNull LogEvent rewrite(final @NonNull LogEvent rewrite) {
2021-06-22 06:12:07 +02:00
+ final Throwable thrown = rewrite.getThrown();
+ if (thrown != null) {
+ StacktraceDeobfuscator.INSTANCE.deobfuscateThrowable(thrown);
2021-09-30 20:05:51 +02:00
+ return new Log4jLogEvent.Builder(rewrite)
+ .setThrownProxy(null)
+ .build();
2021-06-22 06:12:07 +02:00
+ }
+ return rewrite;
+ }
+
+ @PluginFactory
2021-09-30 20:05:51 +02:00
+ public static @NonNull StacktraceDeobfuscatingRewritePolicy createPolicy() {
2021-06-22 06:12:07 +02:00
+ return new StacktraceDeobfuscatingRewritePolicy();
+ }
+}
2021-07-20 04:22:18 +02:00
diff --git a/src/main/java/io/papermc/paper/util/ObfHelper.java b/src/main/java/io/papermc/paper/util/ObfHelper.java
2021-06-22 06:12:07 +02:00
new file mode 100644
2021-11-05 01:23:06 +01:00
index 0000000000000000000000000000000000000000..b8b17d046f836c8652ab094db00ab1af84971b2c
2021-06-22 06:12:07 +02:00
--- /dev/null
2021-07-20 04:22:18 +02:00
+++ b/src/main/java/io/papermc/paper/util/ObfHelper.java
2021-11-05 01:23:06 +01:00
@@ -0,0 +1,146 @@
2021-06-22 06:12:07 +02:00
+package io.papermc.paper.util;
+
2021-06-21 10:09:18 +02:00
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
2021-11-05 01:23:06 +01:00
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.HashSet;
2021-06-21 10:09:18 +02:00
+import java.util.Map;
2021-08-14 12:06:17 +02:00
+import java.util.Set;
2021-11-05 01:23:06 +01:00
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import net.fabricmc.mappingio.MappingReader;
+import net.fabricmc.mappingio.format.MappingFormat;
+import net.fabricmc.mappingio.tree.MappingTree;
+import net.fabricmc.mappingio.tree.MemoryMappingTree;
2021-07-20 04:22:18 +02:00
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.checkerframework.framework.qual.DefaultQualifier;
2021-06-21 10:09:18 +02:00
+
2021-07-20 04:22:18 +02:00
+@DefaultQualifier(NonNull.class)
+public enum ObfHelper {
2021-06-22 06:12:07 +02:00
+ INSTANCE;
+
2021-07-20 04:22:18 +02:00
+ public static final String MOJANG_PLUS_YARN_NAMESPACE = "mojang+yarn";
+ public static final String SPIGOT_NAMESPACE = "spigot";
2021-06-21 10:09:18 +02:00
+
2021-08-14 12:06:17 +02:00
+ private final @Nullable Map<String, ClassMapping> mappingsByObfName;
+ private final @Nullable Map<String, ClassMapping> mappingsByMojangName;
2021-06-21 10:09:18 +02:00
+
2021-07-20 04:22:18 +02:00
+ ObfHelper() {
2021-08-14 12:06:17 +02:00
+ final @Nullable Set<ClassMapping> maps = loadMappingsIfPresent();
+ if (maps != null) {
2021-11-05 01:23:06 +01:00
+ this.mappingsByObfName = maps.stream().collect(Collectors.toUnmodifiableMap(ClassMapping::obfName, map -> map));
+ this.mappingsByMojangName = maps.stream().collect(Collectors.toUnmodifiableMap(ClassMapping::mojangName, map -> map));
2021-08-14 12:06:17 +02:00
+ } else {
+ this.mappingsByObfName = null;
+ this.mappingsByMojangName = null;
+ }
+ }
+
+ public @Nullable Map<String, ClassMapping> mappingsByObfName() {
+ return this.mappingsByObfName;
+ }
+
+ public @Nullable Map<String, ClassMapping> mappingsByMojangName() {
+ return this.mappingsByMojangName;
2021-06-21 10:09:18 +02:00
+ }
+
2021-08-14 12:06:17 +02:00
+ /**
+ * Attempts to get the obf name for a given class by its Mojang name. Will
+ * return the input string if mappings are not present.
+ *
+ * @param fullyQualifiedMojangName fully qualified class name (dotted)
+ * @return mapped or original fully qualified (dotted) class name
+ */
+ public String reobfClassName(final String fullyQualifiedMojangName) {
+ if (this.mappingsByMojangName == null) {
+ return fullyQualifiedMojangName;
+ }
+
+ final ClassMapping map = this.mappingsByMojangName.get(fullyQualifiedMojangName);
+ if (map == null) {
+ return fullyQualifiedMojangName;
+ }
+
+ return map.obfName();
+ }
+
+ /**
+ * Attempts to get the Mojang name for a given class by its obf name. Will
+ * return the input string if mappings are not present.
+ *
+ * @param fullyQualifiedObfName fully qualified class name (dotted)
+ * @return mapped or original fully qualified (dotted) class name
+ */
+ public String deobfClassName(final String fullyQualifiedObfName) {
+ if (this.mappingsByObfName == null) {
+ return fullyQualifiedObfName;
+ }
+
+ final ClassMapping map = this.mappingsByObfName.get(fullyQualifiedObfName);
+ if (map == null) {
+ return fullyQualifiedObfName;
+ }
+
+ return map.mojangName();
2021-07-20 04:22:18 +02:00
+ }
+
2021-08-14 12:06:17 +02:00
+ private static @Nullable Set<ClassMapping> loadMappingsIfPresent() {
2021-09-09 18:57:16 +02:00
+ try (final @Nullable InputStream mappingsInputStream = ObfHelper.class.getClassLoader().getResourceAsStream("META-INF/mappings/reobf.tiny")) {
2021-06-21 10:09:18 +02:00
+ if (mappingsInputStream == null) {
+ return null;
+ }
2021-11-05 01:23:06 +01:00
+ final MemoryMappingTree tree = new MemoryMappingTree();
+ MappingReader.read(new InputStreamReader(mappingsInputStream, StandardCharsets.UTF_8), MappingFormat.TINY_2, tree);
+ final Set<ClassMapping> classes = new HashSet<>();
+
+ final StringPool pool = new StringPool();
+ for (final MappingTree.ClassMapping cls : tree.getClasses()) {
+ final Map<String, String> methods = new HashMap<>();
+
+ for (final MappingTree.MethodMapping methodMapping : cls.getMethods()) {
+ methods.put(
+ pool.string(methodKey(
+ methodMapping.getName(SPIGOT_NAMESPACE),
+ methodMapping.getDesc(SPIGOT_NAMESPACE)
+ )),
+ pool.string(methodMapping.getName(MOJANG_PLUS_YARN_NAMESPACE))
2021-06-21 10:09:18 +02:00
+ );
+ }
+
+ final ClassMapping map = new ClassMapping(
2021-11-05 01:23:06 +01:00
+ cls.getName(SPIGOT_NAMESPACE).replace('/', '.'),
+ cls.getName(MOJANG_PLUS_YARN_NAMESPACE).replace('/', '.'),
+ Map.copyOf(methods)
2021-06-21 10:09:18 +02:00
+ );
2021-11-05 01:23:06 +01:00
+ classes.add(map);
2021-06-21 10:09:18 +02:00
+ }
+
2021-11-05 01:23:06 +01:00
+ return Set.copyOf(classes);
2021-06-21 10:09:18 +02:00
+ } catch (final IOException ex) {
+ System.err.println("Failed to load mappings for stacktrace deobfuscation.");
+ ex.printStackTrace();
+ return null;
+ }
+ }
+
2021-11-05 01:23:06 +01:00
+ public static String methodKey(final String obfName, final String obfDescriptor) {
+ return obfName + obfDescriptor;
+ }
2021-07-20 04:22:18 +02:00
+
2021-11-05 01:23:06 +01:00
+ private static final class StringPool {
+ private final Map<String, String> pool = new HashMap<>();
+
+ public String string(final String string) {
+ return this.pool.computeIfAbsent(string, Function.identity());
+ }
+ }
+
+ public record ClassMapping(
2021-07-20 04:22:18 +02:00
+ String obfName,
+ String mojangName,
2021-11-05 01:23:06 +01:00
+ Map<String, String> methodsByObf
2021-07-20 04:22:18 +02:00
+ ) {}
+}
diff --git a/src/main/java/io/papermc/paper/util/StacktraceDeobfuscator.java b/src/main/java/io/papermc/paper/util/StacktraceDeobfuscator.java
new file mode 100644
2021-11-26 07:33:08 +01:00
index 0000000000000000000000000000000000000000..3c3051c2917548faf7e72276fb642202b33d1794
2021-07-20 04:22:18 +02:00
--- /dev/null
+++ b/src/main/java/io/papermc/paper/util/StacktraceDeobfuscator.java
2021-11-26 07:33:08 +01:00
@@ -0,0 +1,163 @@
2021-07-20 04:22:18 +02:00
+package io.papermc.paper.util;
+
+import com.destroystokyo.paper.PaperConfig;
+import it.unimi.dsi.fastutil.ints.IntArrayList;
+import it.unimi.dsi.fastutil.ints.IntList;
+import java.io.IOException;
2021-11-26 07:33:08 +01:00
+import java.io.InputStream;
2021-07-20 04:22:18 +02:00
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.checkerframework.framework.qual.DefaultQualifier;
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.Label;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+
+@DefaultQualifier(NonNull.class)
+public enum StacktraceDeobfuscator {
+ INSTANCE;
+
2021-11-05 01:23:06 +01:00
+ private final Map<Class<?>, Map<String, IntList>> lineMapCache = Collections.synchronizedMap(new LinkedHashMap<>(128, 0.75f, true) {
2021-07-20 04:22:18 +02:00
+ @Override
2021-11-05 01:23:06 +01:00
+ protected boolean removeEldestEntry(final Map.Entry<Class<?>, Map<String, IntList>> eldest) {
2021-07-20 04:22:18 +02:00
+ return this.size() > 127;
+ }
+ });
+
2021-06-22 06:12:07 +02:00
+ public void deobfuscateThrowable(final Throwable throwable) {
2021-06-21 10:09:18 +02:00
+ if (!PaperConfig.deobfuscateStacktraces) {
2021-06-22 06:12:07 +02:00
+ return;
2021-06-21 10:09:18 +02:00
+ }
+
+ throwable.setStackTrace(this.deobfuscateStacktrace(throwable.getStackTrace()));
+ final Throwable cause = throwable.getCause();
+ if (cause != null) {
+ this.deobfuscateThrowable(cause);
+ }
+ for (final Throwable suppressed : throwable.getSuppressed()) {
+ this.deobfuscateThrowable(suppressed);
+ }
+ }
+
+ public StackTraceElement[] deobfuscateStacktrace(final StackTraceElement[] traceElements) {
2021-06-22 06:12:07 +02:00
+ if (!PaperConfig.deobfuscateStacktraces) {
+ return traceElements;
+ }
+
2021-08-14 12:06:17 +02:00
+ final @Nullable Map<String, ObfHelper.ClassMapping> mappings = ObfHelper.INSTANCE.mappingsByObfName();
2021-07-20 04:22:18 +02:00
+ if (mappings == null || traceElements.length == 0) {
2021-06-21 10:09:18 +02:00
+ return traceElements;
+ }
+ final StackTraceElement[] result = new StackTraceElement[traceElements.length];
+ for (int i = 0; i < traceElements.length; i++) {
+ final StackTraceElement element = traceElements[i];
+
+ final String className = element.getClassName();
+ final String methodName = element.getMethodName();
+
2021-07-20 04:22:18 +02:00
+ final ObfHelper.ClassMapping classMapping = mappings.get(className);
2021-06-21 10:09:18 +02:00
+ if (classMapping == null) {
+ result[i] = element;
+ continue;
+ }
+
2021-07-20 04:22:18 +02:00
+ final Class<?> clazz;
2021-06-21 10:09:18 +02:00
+ try {
2021-07-20 04:22:18 +02:00
+ clazz = Class.forName(className);
+ } catch (final ClassNotFoundException ex) {
2021-06-21 10:09:18 +02:00
+ throw new RuntimeException(ex);
+ }
2021-11-05 01:23:06 +01:00
+ final @Nullable String methodKey = this.determineMethodForLine(clazz, element.getLineNumber());
+ final @Nullable String mappedMethodName = methodKey == null ? null : classMapping.methodsByObf().get(methodKey);
2021-06-21 10:09:18 +02:00
+
+ result[i] = new StackTraceElement(
+ element.getClassLoaderName(),
+ element.getModuleName(),
+ element.getModuleVersion(),
+ classMapping.mojangName(),
2021-11-05 01:23:06 +01:00
+ mappedMethodName != null ? mappedMethodName : methodName,
2021-07-20 04:22:18 +02:00
+ sourceFileName(classMapping.mojangName()),
2021-06-21 10:09:18 +02:00
+ element.getLineNumber()
+ );
+ }
+ return result;
+ }
+
2021-11-05 01:23:06 +01:00
+ private @Nullable String determineMethodForLine(final Class<?> clazz, final int lineNumber) {
+ final Map<String, IntList> lineMap = this.lineMapCache.computeIfAbsent(clazz, StacktraceDeobfuscator::buildLineMap);
2021-07-20 04:22:18 +02:00
+ for (final var entry : lineMap.entrySet()) {
2021-11-05 01:23:06 +01:00
+ final String methodKey = entry.getKey();
2021-07-20 04:22:18 +02:00
+ final IntList lines = entry.getValue();
+ for (int i = 0, linesSize = lines.size(); i < linesSize; i++) {
+ final int num = lines.getInt(i);
+ if (num == lineNumber) {
2021-11-05 01:23:06 +01:00
+ return methodKey;
2021-07-20 04:22:18 +02:00
+ }
+ }
+ }
+ return null;
+ }
+
+ private static String sourceFileName(final String fullClassName) {
+ final int dot = fullClassName.lastIndexOf('.');
+ final String className = dot == -1
+ ? fullClassName
+ : fullClassName.substring(dot + 1);
+ final String rootClassName = className.split("\\$")[0];
+ return rootClassName + ".java";
+ }
+
2021-11-05 01:23:06 +01:00
+ private static Map<String, IntList> buildLineMap(final Class<?> key) {
+ final Map<String, IntList> lineMap = new HashMap<>();
2021-06-21 10:09:18 +02:00
+ final class LineCollectingMethodVisitor extends MethodVisitor {
+ private final IntList lines = new IntArrayList();
+ private final String name;
+ private final String descriptor;
+
+ LineCollectingMethodVisitor(String name, String descriptor) {
+ super(Opcodes.ASM9);
+ this.name = name;
+ this.descriptor = descriptor;
+ }
+
+ @Override
+ public void visitLineNumber(int line, Label start) {
+ super.visitLineNumber(line, start);
+ this.lines.add(line);
+ }
+
+ @Override
+ public void visitEnd() {
+ super.visitEnd();
2021-11-05 01:23:06 +01:00
+ lineMap.put(ObfHelper.methodKey(this.name, this.descriptor), this.lines);
2021-06-21 10:09:18 +02:00
+ }
+ }
+ final ClassVisitor classVisitor = new ClassVisitor(Opcodes.ASM9) {
+ @Override
+ public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
+ return new LineCollectingMethodVisitor(name, descriptor);
+ }
+ };
+ try {
2021-11-26 07:33:08 +01:00
+ final @Nullable InputStream inputStream = StacktraceDeobfuscator.class.getClassLoader()
+ .getResourceAsStream(key.getName().replace('.', '/') + ".class");
+ if (inputStream == null) {
+ throw new IllegalStateException("Could not find class file: " + key.getName());
+ }
+ final byte[] classData;
+ try (inputStream) {
+ classData = inputStream.readAllBytes();
+ }
+ final ClassReader reader = new ClassReader(classData);
2021-06-21 10:09:18 +02:00
+ reader.accept(classVisitor, 0);
+ } catch (final IOException ex) {
+ throw new RuntimeException(ex);
+ }
+ return lineMap;
+ }
+}
2021-06-22 06:12:07 +02:00
diff --git a/src/main/java/io/papermc/paper/util/TraceUtil.java b/src/main/java/io/papermc/paper/util/TraceUtil.java
index 2d5494d2813b773e60ddba6790b750a9a08f21f8..7695bf44503f161523ea612ef8a884ae574a2e21 100644
--- a/src/main/java/io/papermc/paper/util/TraceUtil.java
+++ b/src/main/java/io/papermc/paper/util/TraceUtil.java
@@ -6,13 +6,15 @@ public final class TraceUtil {
public static void dumpTraceForThread(Thread thread, String reason) {
Bukkit.getLogger().warning(thread.getName() + ": " + reason);
- StackTraceElement[] trace = thread.getStackTrace();
+ StackTraceElement[] trace = StacktraceDeobfuscator.INSTANCE.deobfuscateStacktrace(thread.getStackTrace());
for (StackTraceElement traceElement : trace) {
Bukkit.getLogger().warning("\tat " + traceElement);
}
}
public static void dumpTraceForThread(String reason) {
- new Throwable(reason).printStackTrace();
+ final Throwable throwable = new Throwable(reason);
+ StacktraceDeobfuscator.INSTANCE.deobfuscateThrowable(throwable);
+ throwable.printStackTrace();
}
}
diff --git a/src/main/java/net/minecraft/CrashReport.java b/src/main/java/net/minecraft/CrashReport.java
2022-03-01 06:43:03 +01:00
index 4dd14d73a37b32288a64fbd67ee22c435b6e6d57..1a859fef0848cf23a672012e9764965ae1c07ec5 100644
2021-06-22 06:12:07 +02:00
--- a/src/main/java/net/minecraft/CrashReport.java
+++ b/src/main/java/net/minecraft/CrashReport.java
2021-07-07 08:52:40 +02:00
@@ -30,6 +30,7 @@ public class CrashReport {
2021-06-22 06:12:07 +02:00
private final SystemReport systemReport = new SystemReport();
public CrashReport(String message, Throwable cause) {
+ io.papermc.paper.util.StacktraceDeobfuscator.INSTANCE.deobfuscateThrowable(cause); // Paper
this.title = message;
this.exception = cause;
this.systemReport.setDetail("CraftBukkit Information", new org.bukkit.craftbukkit.CraftCrashReport()); // CraftBukkit
2021-07-04 12:20:11 +02:00
diff --git a/src/main/java/net/minecraft/CrashReportCategory.java b/src/main/java/net/minecraft/CrashReportCategory.java
index 3941e14d1c3e6e688e28904948039c8b2200de5f..a4fda4a3bae9ce600e778b44cd3ef432a8b65667 100644
--- a/src/main/java/net/minecraft/CrashReportCategory.java
+++ b/src/main/java/net/minecraft/CrashReportCategory.java
@@ -104,6 +104,7 @@ public class CrashReportCategory {
} else {
this.stackTrace = new StackTraceElement[stackTraceElements.length - 3 - ignoredCallCount];
System.arraycopy(stackTraceElements, 3 + ignoredCallCount, this.stackTrace, 0, this.stackTrace.length);
+ this.stackTrace = io.papermc.paper.util.StacktraceDeobfuscator.INSTANCE.deobfuscateStacktrace(this.stackTrace); // Paper
return this.stackTrace.length;
}
}
2021-12-23 11:32:26 +01:00
diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java
2022-03-01 06:43:03 +01:00
index a0d3d9e344f530b713167d0663634c40eefce5b5..c469688c2b55b1c93435a2ac6e8e4494ab7e5229 100644
2021-12-23 11:32:26 +01:00
--- a/src/main/java/net/minecraft/network/Connection.java
+++ b/src/main/java/net/minecraft/network/Connection.java
2022-03-01 06:43:03 +01:00
@@ -66,13 +66,13 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
});
2021-12-23 11:32:26 +01:00
public static final AttributeKey<ConnectionProtocol> ATTRIBUTE_PROTOCOL = AttributeKey.valueOf("protocol");
public static final LazyLoadedValue<NioEventLoopGroup> NETWORK_WORKER_GROUP = new LazyLoadedValue<>(() -> {
- return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Client IO #%d").setDaemon(true).build());
+ return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Client IO #%d").setDaemon(true).setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(LOGGER)).build()); // Paper
});
public static final LazyLoadedValue<EpollEventLoopGroup> NETWORK_EPOLL_WORKER_GROUP = new LazyLoadedValue<>(() -> {
- return new EpollEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Epoll Client IO #%d").setDaemon(true).build());
+ return new EpollEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Epoll Client IO #%d").setDaemon(true).setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(LOGGER)).build()); // Paper
});
public static final LazyLoadedValue<DefaultEventLoopGroup> LOCAL_WORKER_GROUP = new LazyLoadedValue<>(() -> {
- return new DefaultEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Local Client IO #%d").setDaemon(true).build());
+ return new DefaultEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Local Client IO #%d").setDaemon(true).setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(LOGGER)).build()); // Paper
});
private final PacketFlow receiving;
private final Queue<Connection.PacketHolder> queue = Queues.newConcurrentLinkedQueue();
diff --git a/src/main/java/net/minecraft/network/protocol/game/ServerboundChatPacket.java b/src/main/java/net/minecraft/network/protocol/game/ServerboundChatPacket.java
index 5165170e3289fe3939497c56a71eae9fdaa4bcfa..8a0ced3f9b9099913ade4b71181aff6cafbc4ee6 100644
--- a/src/main/java/net/minecraft/network/protocol/game/ServerboundChatPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ServerboundChatPacket.java
@@ -27,7 +27,7 @@ public class ServerboundChatPacket implements Packet<ServerGamePacketListener> {
// Spigot Start
private static final java.util.concurrent.ExecutorService executors = java.util.concurrent.Executors.newCachedThreadPool(
- new com.google.common.util.concurrent.ThreadFactoryBuilder().setDaemon( true ).setNameFormat( "Async Chat Thread - #%d" ).build() );
+ new com.google.common.util.concurrent.ThreadFactoryBuilder().setDaemon( true ).setNameFormat( "Async Chat Thread - #%d" ).setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(net.minecraft.server.MinecraftServer.LOGGER)).build() ); // Paper
public void handle(final ServerGamePacketListener listener) {
if ( !this.message.startsWith("/") )
{
2021-06-22 06:12:07 +02:00
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
2022-03-01 06:43:03 +01:00
index d0d058287fc1e87e944e99d4fc2cbd38eafb82b3..cec0082718c2a729044d6f19d74b8e4425816725 100644
2021-06-22 06:12:07 +02:00
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
2022-03-01 06:43:03 +01:00
@@ -215,6 +215,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
2021-09-09 18:57:16 +02:00
}
2021-06-22 06:12:07 +02:00
com.destroystokyo.paper.PaperConfig.registerCommands();
com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // load version history now
2021-07-20 04:22:18 +02:00
+ io.papermc.paper.util.ObfHelper.INSTANCE.getClass(); // load mappings for stacktrace deobf and etc.
2021-06-22 06:12:07 +02:00
// Paper end
this.setPvpAllowed(dedicatedserverproperties.pvp);
2021-12-23 11:32:26 +01:00
diff --git a/src/main/java/net/minecraft/server/network/ServerConnectionListener.java b/src/main/java/net/minecraft/server/network/ServerConnectionListener.java
2022-03-01 06:43:03 +01:00
index 7c820a8f9ae85eb6941dce0e6296775fb331d720..888e863b6d605bf587d0c071795a43d2157afa4d 100644
2021-12-23 11:32:26 +01:00
--- a/src/main/java/net/minecraft/server/network/ServerConnectionListener.java
+++ b/src/main/java/net/minecraft/server/network/ServerConnectionListener.java
@@ -52,10 +52,10 @@ public class ServerConnectionListener {
2022-03-01 06:43:03 +01:00
private static final Logger LOGGER = LogUtils.getLogger();
2021-12-23 11:32:26 +01:00
public static final LazyLoadedValue<NioEventLoopGroup> SERVER_EVENT_GROUP = new LazyLoadedValue<>(() -> {
- return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Server IO #%d").setDaemon(true).build());
+ return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Server IO #%d").setDaemon(true).setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(LOGGER)).build()); // Paper
});
public static final LazyLoadedValue<EpollEventLoopGroup> SERVER_EPOLL_EVENT_GROUP = new LazyLoadedValue<>(() -> {
- return new EpollEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Epoll Server IO #%d").setDaemon(true).build());
+ return new EpollEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Epoll Server IO #%d").setDaemon(true).setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(LOGGER)).build()); // Paper
});
final MinecraftServer server;
public volatile boolean running;
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftAsyncScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftAsyncScheduler.java
index 3c1992e212a6d6f1db4d5b807b38d71913619fc0..9c1aff17aabd062640e3f451a2ef8c50a7c62f10 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftAsyncScheduler.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftAsyncScheduler.java
@@ -40,9 +40,9 @@ public class CraftAsyncScheduler extends CraftScheduler {
private final ThreadPoolExecutor executor = new ThreadPoolExecutor(
4, Integer.MAX_VALUE,30L, TimeUnit.SECONDS, new SynchronousQueue<>(),
- new ThreadFactoryBuilder().setNameFormat("Craft Scheduler Thread - %1$d").build());
+ new ThreadFactoryBuilder().setNameFormat("Craft Scheduler Thread - %1$d").setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(net.minecraft.server.MinecraftServer.LOGGER)).build()); // Paper
private final Executor management = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder()
- .setNameFormat("Craft Async Scheduler Management Thread").build());
+ .setNameFormat("Craft Async Scheduler Management Thread").setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(net.minecraft.server.MinecraftServer.LOGGER)).build()); // Paper
private final List<CraftTask> temp = new ArrayList<>();
CraftAsyncScheduler() {
2021-06-22 06:12:07 +02:00
diff --git a/src/main/java/org/spigotmc/WatchdogThread.java b/src/main/java/org/spigotmc/WatchdogThread.java
index 4d271cae88c16ed2419f896c728fdff612540500..dcfbe77bdb25d9c58ffb7b75c48bdb580bc0de47 100644
--- a/src/main/java/org/spigotmc/WatchdogThread.java
+++ b/src/main/java/org/spigotmc/WatchdogThread.java
@@ -106,7 +106,7 @@ public class WatchdogThread extends Thread
log.log( Level.SEVERE, "During the run of the server, a plugin set an excessive velocity on an entity" );
log.log( Level.SEVERE, "This may be the cause of the issue, or it may be entirely unrelated" );
log.log( Level.SEVERE, org.bukkit.craftbukkit.CraftServer.excessiveVelEx.getMessage());
- for ( StackTraceElement stack : org.bukkit.craftbukkit.CraftServer.excessiveVelEx.getStackTrace() )
+ for ( StackTraceElement stack : io.papermc.paper.util.StacktraceDeobfuscator.INSTANCE.deobfuscateStacktrace(org.bukkit.craftbukkit.CraftServer.excessiveVelEx.getStackTrace()) ) // Paper
{
log.log( Level.SEVERE, "\t\t" + stack );
}
@@ -194,7 +194,7 @@ public class WatchdogThread extends Thread
}
log.log( Level.SEVERE, "\tStack:" );
//
- for ( StackTraceElement stack : thread.getStackTrace() )
+ for ( StackTraceElement stack : io.papermc.paper.util.StacktraceDeobfuscator.INSTANCE.deobfuscateStacktrace(thread.getStackTrace()) ) // Paper
{
log.log( Level.SEVERE, "\t\t" + stack );
}
2021-06-21 10:09:18 +02:00
diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml
2021-09-09 18:57:16 +02:00
index d285dbec16272db6b8a71865e05924ad66087407..1a05d23ff886b015fb9396f119822c678a47ec6f 100644
2021-06-21 10:09:18 +02:00
--- a/src/main/resources/log4j2.xml
+++ b/src/main/resources/log4j2.xml
2021-08-12 19:55:20 +02:00
@@ -30,10 +30,14 @@
2021-06-21 10:09:18 +02:00
<DefaultRolloverStrategy max="1000"/>
</RollingRandomAccessFile>
2021-08-12 19:55:20 +02:00
<Async name="Async">
+ <AppenderRef ref="rewrite"/>
+ </Async>
2021-06-21 10:09:18 +02:00
+ <Rewrite name="rewrite">
+ <StacktraceDeobfuscatingRewritePolicy />
2021-08-12 19:55:20 +02:00
<AppenderRef ref="File"/>
<AppenderRef ref="TerminalConsole" level="info"/>
<AppenderRef ref="ServerGuiConsole" level="info"/>
- </Async>
2021-06-21 10:09:18 +02:00
+ </Rewrite>
</Appenders>
<Loggers>
<Root level="info">