From 2ac95074a6ce21133ec5854c2e8cff84cb974f91 Mon Sep 17 00:00:00 2001 From: Haowei Wen Date: Wed, 29 Apr 2020 01:35:27 +0800 Subject: [PATCH] Add classloader exclusion to launchwrapper (#68) --- .../authlibinjector/AuthlibInjector.java | 2 + .../LaunchwrapperExclusionTransformer.java | 70 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 src/main/java/moe/yushi/authlibinjector/transform/support/LaunchwrapperExclusionTransformer.java diff --git a/src/main/java/moe/yushi/authlibinjector/AuthlibInjector.java b/src/main/java/moe/yushi/authlibinjector/AuthlibInjector.java index 7346086..5812fd4 100644 --- a/src/main/java/moe/yushi/authlibinjector/AuthlibInjector.java +++ b/src/main/java/moe/yushi/authlibinjector/AuthlibInjector.java @@ -60,6 +60,7 @@ import moe.yushi.authlibinjector.transform.ConstantURLTransformUnit; import moe.yushi.authlibinjector.transform.DumpClassListener; import moe.yushi.authlibinjector.transform.support.AuthlibLogInterceptor; import moe.yushi.authlibinjector.transform.support.CitizensTransformer; +import moe.yushi.authlibinjector.transform.support.LaunchwrapperExclusionTransformer; import moe.yushi.authlibinjector.transform.support.MC52974Workaround; import moe.yushi.authlibinjector.transform.support.MC52974_1710Workaround; import moe.yushi.authlibinjector.transform.support.MainArgumentsTransformer; @@ -449,6 +450,7 @@ public final class AuthlibInjector { transformer.units.add(new AuthlibLogInterceptor()); } + transformer.units.add(new LaunchwrapperExclusionTransformer()); transformer.units.add(new MainArgumentsTransformer()); transformer.units.add(new ConstantURLTransformUnit(urlProcessor)); transformer.units.add(new CitizensTransformer()); diff --git a/src/main/java/moe/yushi/authlibinjector/transform/support/LaunchwrapperExclusionTransformer.java b/src/main/java/moe/yushi/authlibinjector/transform/support/LaunchwrapperExclusionTransformer.java new file mode 100644 index 0000000..6d5b08c --- /dev/null +++ b/src/main/java/moe/yushi/authlibinjector/transform/support/LaunchwrapperExclusionTransformer.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2020 Haowei Wen and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package moe.yushi.authlibinjector.transform.support; + +import static org.objectweb.asm.Opcodes.ALOAD; +import static org.objectweb.asm.Opcodes.ASM7; +import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL; +import java.util.Optional; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.MethodVisitor; +import moe.yushi.authlibinjector.transform.TransformUnit; + +public class LaunchwrapperExclusionTransformer implements TransformUnit { + + @Override + public Optional transform(ClassLoader classLoader, String className, ClassVisitor writer, TransformContext context) { + if ("net.minecraft.launchwrapper.LaunchClassLoader".equals(className)) { + return Optional.of(new ClassVisitor(ASM7, writer) { + @Override + public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) { + if ("".equals(name)) { + return new MethodVisitor(ASM7, super.visitMethod(access, name, descriptor, signature, exceptions)) { + + boolean exclusionAdded = false; + + @Override + public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) { + super.visitMethodInsn(opcode, owner, name, descriptor, isInterface); + + if (!exclusionAdded && + opcode == INVOKEVIRTUAL && + "net/minecraft/launchwrapper/LaunchClassLoader".equals(owner) && + "addClassLoaderExclusion".equals(name) && + "(Ljava/lang/String;)V".equals(descriptor)) { + super.visitVarInsn(ALOAD, 0); + super.visitLdcInsn("moe.yushi.authlibinjector."); + super.visitMethodInsn(opcode, owner, name, descriptor, isInterface); + exclusionAdded = true; + context.markModified(); + } + } + }; + } + return super.visitMethod(access, name, descriptor, signature, exceptions); + } + }); + } else { + return Optional.empty(); + } + } + + @Override + public String toString() { + return "Launchwrapper ClassLoader Exclusion"; + } +}