diff options
Diffstat (limited to 'patches/server/0022-Remap-reflection-calls-in-plugins-using-internals.patch')
-rw-r--r-- | patches/server/0022-Remap-reflection-calls-in-plugins-using-internals.patch | 68 |
1 files changed, 32 insertions, 36 deletions
diff --git a/patches/server/0022-Remap-reflection-calls-in-plugins-using-internals.patch b/patches/server/0022-Remap-reflection-calls-in-plugins-using-internals.patch index 0e3a3ca1d8..ed625b27de 100644 --- a/patches/server/0022-Remap-reflection-calls-in-plugins-using-internals.patch +++ b/patches/server/0022-Remap-reflection-calls-in-plugins-using-internals.patch @@ -237,26 +237,15 @@ index 0000000000000000000000000000000000000000..1240c061c121e8d5eb9add4e5e21955e + } +} diff --git a/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperClassloaderBytecodeModifier.java b/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperClassloaderBytecodeModifier.java -index f9a2c55a354c877749db3f92956de802ae575788..39182cdd17473da0123dc7172dce507eab29fedc 100644 +index f9a2c55a354c877749db3f92956de802ae575788..0e734c07dbe82ba4c319a237f9e79b08b57b997f 100644 --- a/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperClassloaderBytecodeModifier.java +++ b/src/main/java/io/papermc/paper/plugin/entrypoint/classloader/PaperClassloaderBytecodeModifier.java -@@ -1,12 +1,17 @@ - package io.papermc.paper.plugin.entrypoint.classloader; - - import io.papermc.paper.plugin.configuration.PluginMeta; -+import org.objectweb.asm.ClassReader; -+import org.objectweb.asm.ClassWriter; - - // Stub, implement in future. - public class PaperClassloaderBytecodeModifier implements ClassloaderBytecodeModifier { +@@ -7,6 +7,6 @@ public class PaperClassloaderBytecodeModifier implements ClassloaderBytecodeModi @Override public byte[] modify(PluginMeta configuration, byte[] bytecode) { - return bytecode; -+ ClassReader classReader = new ClassReader(bytecode); -+ ClassWriter classWriter = new ClassWriter(classReader, 0); -+ classReader.accept(io.papermc.paper.pluginremap.reflect.ReflectionRemapper.visitor(classWriter), 0); -+ return classWriter.toByteArray(); ++ return io.papermc.paper.pluginremap.reflect.ReflectionRemapper.processClass(bytecode); } } diff --git a/src/main/java/io/papermc/paper/plugin/loader/PaperClasspathBuilder.java b/src/main/java/io/papermc/paper/plugin/loader/PaperClasspathBuilder.java @@ -331,10 +320,10 @@ index bdd9bc8a414719b9f1d6f01f90539ddb8603a878..1bf0fa1530b8e5f94d726d0313b7a00f // Copied from SimplePluginManager#loadPlugins diff --git a/src/main/java/io/papermc/paper/pluginremap/reflect/PaperReflection.java b/src/main/java/io/papermc/paper/pluginremap/reflect/PaperReflection.java new file mode 100644 -index 0000000000000000000000000000000000000000..795d79bcfc4177edfcb12cf9db392780c3f04aa7 +index 0000000000000000000000000000000000000000..92bc8e4933ff13764fa2ac7f3729216332e202c9 --- /dev/null +++ b/src/main/java/io/papermc/paper/pluginremap/reflect/PaperReflection.java -@@ -0,0 +1,216 @@ +@@ -0,0 +1,211 @@ +package io.papermc.paper.pluginremap.reflect; + +import com.mojang.logging.LogUtils; @@ -352,8 +341,6 @@ index 0000000000000000000000000000000000000000..795d79bcfc4177edfcb12cf9db392780 +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.ClassWriter; +import org.slf4j.Logger; + +// todo proper inheritance handling @@ -541,10 +528,7 @@ index 0000000000000000000000000000000000000000..795d79bcfc4177edfcb12cf9db392780 + // todo apply bytecode remap here as well + private static byte[] processClass(final byte[] bytes) { + try { -+ final ClassReader reader = new ClassReader(bytes); -+ final ClassWriter writer = new ClassWriter(reader, 0); -+ reader.accept(ReflectionRemapper.visitor(writer), 0); -+ return writer.toByteArray(); ++ return ReflectionRemapper.processClass(bytes); + } catch (final Exception ex) { + LOGGER.warn("Failed to process class bytes", ex); + return bytes; @@ -553,10 +537,10 @@ index 0000000000000000000000000000000000000000..795d79bcfc4177edfcb12cf9db392780 +} diff --git a/src/main/java/io/papermc/paper/pluginremap/reflect/ReflectionRemapper.java b/src/main/java/io/papermc/paper/pluginremap/reflect/ReflectionRemapper.java new file mode 100644 -index 0000000000000000000000000000000000000000..5fa5868e82d1f00498d0c5771369e1718b2df4ee +index 0000000000000000000000000000000000000000..a3045afbc0cc057e99189b909367b21cf6a9e03f --- /dev/null +++ b/src/main/java/io/papermc/paper/pluginremap/reflect/ReflectionRemapper.java -@@ -0,0 +1,54 @@ +@@ -0,0 +1,66 @@ +package io.papermc.paper.pluginremap.reflect; + +import io.papermc.asm.ClassInfoProvider; @@ -569,7 +553,9 @@ index 0000000000000000000000000000000000000000..5fa5868e82d1f00498d0c5771369e171 +import java.lang.reflect.Method; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.framework.qual.DefaultQualifier; ++import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassVisitor; ++import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Opcodes; + +@DefaultQualifier(NonNull.class) @@ -593,12 +579,22 @@ index 0000000000000000000000000000000000000000..5fa5868e82d1f00498d0c5771369e171 + } + + public static ClassVisitor visitor(final ClassVisitor parent) { -+ if (MappingEnvironment.reobf()) { ++ if (MappingEnvironment.reobf() || MappingEnvironment.DISABLE_PLUGIN_REMAPPING) { + return parent; + } + return VISITOR_FACTORY.createVisitor(parent); + } + ++ public static byte[] processClass(final byte[] bytes) { ++ if (MappingEnvironment.DISABLE_PLUGIN_REMAPPING) { ++ return bytes; ++ } ++ final ClassReader classReader = new ClassReader(bytes); ++ final ClassWriter classWriter = new ClassWriter(classReader, 0); ++ classReader.accept(ReflectionRemapper.visitor(classWriter), 0); ++ return classWriter.toByteArray(); ++ } ++ + private static void setupProxy() { + try { + final byte[] bytes = ProxyGenerator.generateProxy(PaperReflection.class, PAPER_REFLECTION_HOLDER_DESC); @@ -649,7 +645,7 @@ index 242811578a786e3807a1a7019d472d5a68f87116..0b65fdf53124f3dd042b2363b1b8df8e return traceElements; } diff --git a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java -index 421ddf6ca955215dff77655a7eda62eb9d90aa92..5dafd7765e82a110803affebc9d7d1905b13d0c9 100644 +index 421ddf6ca955215dff77655a7eda62eb9d90aa92..8a1570ceb4755a1872911751943c84b8f06eb4c2 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java +++ b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java @@ -102,36 +102,26 @@ public class Commodore { @@ -700,21 +696,16 @@ index 421ddf6ca955215dff77655a7eda62eb9d90aa92..5dafd7765e82a110803affebc9d7d190 } // Paper end - Plugin rewrites -@@ -214,7 +204,12 @@ public class Commodore { +@@ -214,6 +204,7 @@ public class Commodore { visitor = new LimitedClassRemapper(cw, new SimpleRemapper(Commodore.ENUM_RENAMES)); } -+ // Paper start -+ if (!io.papermc.paper.util.MappingEnvironment.DISABLE_PLUGIN_REMAPPING) { -+ visitor = io.papermc.paper.pluginremap.reflect.ReflectionRemapper.visitor(visitor); -+ } ++ visitor = io.papermc.paper.pluginremap.reflect.ReflectionRemapper.visitor(visitor); // Paper cr.accept(new ClassRemapper(new ClassVisitor(Opcodes.ASM9, visitor) { -+ // Paper end final Set<RerouteMethodData> rerouteMethodData = new HashSet<>(); String className; - boolean isInterface; diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -index a6de88625aeb2c5ababd476e804e9b45b1185efe..37f3a9f939a947d2b5e1e81d83e74555a636e1eb 100644 +index a6de88625aeb2c5ababd476e804e9b45b1185efe..fa2e43020fafc283a9c063d10a82280158c7f93d 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java @@ -74,6 +74,7 @@ import org.bukkit.potion.PotionType; @@ -734,11 +725,16 @@ index a6de88625aeb2c5ababd476e804e9b45b1185efe..37f3a9f939a947d2b5e1e81d83e74555 CraftLegacy.init(); } -@@ -355,6 +356,7 @@ public final class CraftMagicNumbers implements UnsafeValues { +@@ -355,6 +356,12 @@ public final class CraftMagicNumbers implements UnsafeValues { @Override public byte[] processClass(PluginDescriptionFile pdf, String path, byte[] clazz) { -+ if (DISABLE_OLD_API_SUPPORT) return clazz; // Paper ++ // Paper start ++ if (DISABLE_OLD_API_SUPPORT) { ++ // Make sure we still go through our reflection rewriting if needed ++ return io.papermc.paper.pluginremap.reflect.ReflectionRemapper.processClass(clazz); ++ } ++ // Paper end try { clazz = Commodore.convert(clazz, pdf.getName(), ApiVersion.getOrCreateVersion(pdf.getAPIVersion()), ((CraftServer) Bukkit.getServer()).activeCompatibilities); } catch (Exception ex) { |