aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0022-Remap-reflection-calls-in-plugins-using-internals.patch
diff options
context:
space:
mode:
authorNassim Jahnke <[email protected]>2024-07-19 13:08:08 +0200
committerGitHub <[email protected]>2024-07-19 13:08:08 +0200
commit75af62b298eb70f535486df3343a1a333a60a002 (patch)
tree1571aa3ade589036a36df4570cbe4f6ac430b93c /patches/server/0022-Remap-reflection-calls-in-plugins-using-internals.patch
parent2a392767942799bc93a70a8698a0ef4ca7b8b6f9 (diff)
downloadPaper-75af62b298eb70f535486df3343a1a333a60a002.tar.gz
Paper-75af62b298eb70f535486df3343a1a333a60a002.zip
Split rewriting flag into `paper.disableOldApiSupport` and `paper.disablePluginRemapping` (#11108)
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.patch90
1 files changed, 49 insertions, 41 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 b2618a220f..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,30 +237,19 @@ 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
-index f576060c8fe872772bbafe2016fc9b83a3c095f1..f9d4b33050a6fe8c2dabe8e5eec075d95dc513e0 100644
+index f576060c8fe872772bbafe2016fc9b83a3c095f1..f871a329eb52da077f58d0ceaaabd3349f84cad0 100644
--- a/src/main/java/io/papermc/paper/plugin/loader/PaperClasspathBuilder.java
+++ b/src/main/java/io/papermc/paper/plugin/loader/PaperClasspathBuilder.java
@@ -2,12 +2,12 @@ package io.papermc.paper.plugin.loader;
@@ -292,7 +281,7 @@ index f576060c8fe872772bbafe2016fc9b83a3c095f1..f9d4b33050a6fe8c2dabe8e5eec075d9
try {
- return new PaperPluginClassLoader(logger, source, jarFile, configuration, this.getClass().getClassLoader(), new URLClassLoader(urls, getClass().getClassLoader()));
-+ final URLClassLoader libraryLoader = MappingEnvironment.DISABLE_PLUGIN_REWRITING
++ final URLClassLoader libraryLoader = MappingEnvironment.DISABLE_PLUGIN_REMAPPING
+ ? new URLClassLoader(urls, this.getClass().getClassLoader())
+ : new BytecodeModifyingURLClassLoader(urls, this.getClass().getClassLoader());
+ return new PaperPluginClassLoader(logger, source, jarFile, configuration, this.getClass().getClassLoader(), libraryLoader);
@@ -300,7 +289,7 @@ index f576060c8fe872772bbafe2016fc9b83a3c095f1..f9d4b33050a6fe8c2dabe8e5eec075d9
throw new RuntimeException(exception);
}
diff --git a/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java b/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java
-index bdd9bc8a414719b9f1d6f01f90539ddb8603a878..fdb52ad85cfaa1d53aadcad72cec3d3c8c12c058 100644
+index bdd9bc8a414719b9f1d6f01f90539ddb8603a878..1bf0fa1530b8e5f94d726d0313b7a00f675b500c 100644
--- a/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java
+++ b/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java
@@ -1,9 +1,12 @@
@@ -321,7 +310,7 @@ index bdd9bc8a414719b9f1d6f01f90539ddb8603a878..fdb52ad85cfaa1d53aadcad72cec3d3c
class SpigotPluginProviderFactory implements PluginTypeFactory<SpigotPluginProvider, PluginDescriptionFile> {
+ static {
-+ if (!MappingEnvironment.DISABLE_PLUGIN_REWRITING) {
++ if (!MappingEnvironment.DISABLE_PLUGIN_REMAPPING) {
+ LibraryLoader.LIBRARY_LOADER_FACTORY = BytecodeModifyingURLClassLoader::new;
+ }
+ }
@@ -331,10 +320,10 @@ index bdd9bc8a414719b9f1d6f01f90539ddb8603a878..fdb52ad85cfaa1d53aadcad72cec3d3c
// 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);
@@ -612,14 +608,14 @@ index 0000000000000000000000000000000000000000..5fa5868e82d1f00498d0c5771369e171
+ }
+}
diff --git a/src/main/java/io/papermc/paper/util/MappingEnvironment.java b/src/main/java/io/papermc/paper/util/MappingEnvironment.java
-index 8e4229634d41a42b3d93948eebb77def7c0c72b1..2458685e7612040cea9d638dd2d945da1399ed77 100644
+index 8e4229634d41a42b3d93948eebb77def7c0c72b1..fb6aa9e2575b22e3089ea7fb32e6abfa6bb07d18 100644
--- a/src/main/java/io/papermc/paper/util/MappingEnvironment.java
+++ b/src/main/java/io/papermc/paper/util/MappingEnvironment.java
@@ -10,6 +10,8 @@ import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
public final class MappingEnvironment {
-+ public static final boolean DISABLE_PLUGIN_REWRITING = Boolean.getBoolean("paper.disable-plugin-rewriting");
++ public static final boolean DISABLE_PLUGIN_REMAPPING = Boolean.getBoolean("paper.disablePluginRemapping");
+ public static final String LEGACY_CB_VERSION = "v1_21_R1";
private static final @Nullable String MAPPINGS_HASH = readMappingsHash();
private static final boolean REOBF = checkReobf();
@@ -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..1cef3614e81e751c98b504c26da4718dc88746df 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,33 +696,45 @@ index 421ddf6ca955215dff77655a7eda62eb9d90aa92..1cef3614e81e751c98b504c26da4718d
}
// Paper end - Plugin rewrites
-@@ -214,7 +204,7 @@ public class Commodore {
+@@ -214,6 +204,7 @@ public class Commodore {
visitor = new LimitedClassRemapper(cw, new SimpleRemapper(Commodore.ENUM_RENAMES));
}
-- cr.accept(new ClassRemapper(new ClassVisitor(Opcodes.ASM9, visitor) {
-+ cr.accept(new ClassRemapper(new ClassVisitor(Opcodes.ASM9, io.papermc.paper.pluginremap.reflect.ReflectionRemapper.visitor(visitor)) { // Paper
++ visitor = io.papermc.paper.pluginremap.reflect.ReflectionRemapper.visitor(visitor); // Paper
+ cr.accept(new ClassRemapper(new ClassVisitor(Opcodes.ASM9, visitor) {
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..7fdc5f5b8ce2401ac480dd5691d99b2d297c6168 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
-@@ -340,7 +340,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
+@@ -74,6 +74,7 @@ import org.bukkit.potion.PotionType;
+ @SuppressWarnings("deprecation")
+ public final class CraftMagicNumbers implements UnsafeValues {
+ public static final UnsafeValues INSTANCE = new CraftMagicNumbers();
++ public static final boolean DISABLE_OLD_API_SUPPORT = Boolean.getBoolean("paper.disableOldApiSupport"); // Paper
+
+ private CraftMagicNumbers() {}
+
+@@ -340,7 +341,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
throw new InvalidPluginException("Plugin API version " + pdf.getAPIVersion() + " is lower than the minimum allowed version. Please update or replace it.");
}
- if (toCheck.isOlderThan(ApiVersion.FLATTENING)) {
-+ if (!io.papermc.paper.util.MappingEnvironment.DISABLE_PLUGIN_REWRITING && toCheck.isOlderThan(ApiVersion.FLATTENING)) { // Paper
++ if (!DISABLE_OLD_API_SUPPORT && toCheck.isOlderThan(ApiVersion.FLATTENING)) { // Paper
CraftLegacy.init();
}
-@@ -355,6 +355,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 (io.papermc.paper.util.MappingEnvironment.DISABLE_PLUGIN_REWRITING) 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) {