forked from MirrorHub/authlib-injector
Apply AuthlibLogInterceptor only if necessary
This commit is contained in:
parent
57e145d7da
commit
42ed5a9b1e
6 changed files with 16 additions and 9 deletions
|
@ -196,18 +196,23 @@ public class AuthlibLogInterceptor implements TransformUnit {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Optional<ClassVisitor> transform(String className, ClassVisitor writer, Runnable modifiedCallback) {
|
||||
public Optional<ClassVisitor> transform(ClassLoader classLoader, String className, ClassVisitor writer, Runnable modifiedCallback) {
|
||||
if (className.startsWith("com.mojang.authlib.")) {
|
||||
synchronized (interceptedClassloaders) {
|
||||
if (interceptedClassloaders.contains(classLoader)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
return Optional.of(new ClassVisitor(ASM6, writer) {
|
||||
|
||||
@Override
|
||||
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
|
||||
MethodVisitor mv = super.visitMethod(access, name, descriptor, signature, exceptions);
|
||||
if ("<clinit>".equals(name)) {
|
||||
modifiedCallback.run();
|
||||
mv.visitLdcInsn(Type.getType("L" + className.replace('.', '/') + ";"));
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getClassLoader", "()Ljava/lang/ClassLoader;", false);
|
||||
mv.visitMethodInsn(INVOKESTATIC, AuthlibLogInterceptor.class.getName().replace('.', '/'), "onClassLoading", "(Ljava/lang/ClassLoader;)V", false);
|
||||
modifiedCallback.run();
|
||||
}
|
||||
return mv;
|
||||
}
|
||||
|
|
|
@ -34,10 +34,12 @@ public class ClassTransformer implements ClassFileTransformer {
|
|||
private String className;
|
||||
private byte[] classBuffer;
|
||||
private ClassWriter pooledClassWriter;
|
||||
private ClassLoader classLoader;
|
||||
|
||||
public TransformHandle(String className, byte[] classBuffer) {
|
||||
public TransformHandle(ClassLoader classLoader, String className, byte[] classBuffer) {
|
||||
this.className = className;
|
||||
this.classBuffer = classBuffer;
|
||||
this.classLoader = classLoader;
|
||||
}
|
||||
|
||||
public void accept(TransformUnit unit) {
|
||||
|
@ -49,7 +51,7 @@ public class ClassTransformer implements ClassFileTransformer {
|
|||
pooledClassWriter = null;
|
||||
}
|
||||
|
||||
Optional<ClassVisitor> optionalVisitor = unit.transform(className, writer, () -> currentModified = true);
|
||||
Optional<ClassVisitor> optionalVisitor = unit.transform(classLoader, className, writer, () -> currentModified = true);
|
||||
if (optionalVisitor.isPresent()) {
|
||||
currentModified = false;
|
||||
ClassReader reader = new ClassReader(classBuffer);
|
||||
|
@ -96,7 +98,7 @@ public class ClassTransformer implements ClassFileTransformer {
|
|||
}
|
||||
}
|
||||
|
||||
TransformHandle handle = new TransformHandle(className, classfileBuffer);
|
||||
TransformHandle handle = new TransformHandle(loader, className, classfileBuffer);
|
||||
units.forEach(handle::accept);
|
||||
listeners.forEach(it -> it.onClassLoading(loader, className, handle.getFinalResult(), handle.getAppliedTransformers()));
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import moe.yushi.authlibinjector.util.Logging;
|
|||
public abstract class LdcTransformUnit implements TransformUnit {
|
||||
|
||||
@Override
|
||||
public Optional<ClassVisitor> transform(String className, ClassVisitor writer, Runnable modifiedCallback) {
|
||||
public Optional<ClassVisitor> transform(ClassLoader classLoader, String className, ClassVisitor writer, Runnable modifiedCallback) {
|
||||
return Optional.of(new ClassVisitor(ASM6, writer) {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,7 +21,7 @@ public class SkinWhitelistTransformUnit implements TransformUnit {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Optional<ClassVisitor> transform(String className, ClassVisitor writer, Runnable modifiedCallback) {
|
||||
public Optional<ClassVisitor> transform(ClassLoader classLoader, String className, ClassVisitor writer, Runnable modifiedCallback) {
|
||||
if ("com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService".equals(className)) {
|
||||
return Optional.of(new ClassVisitor(ASM6, writer) {
|
||||
|
||||
|
|
|
@ -5,6 +5,6 @@ import org.objectweb.asm.ClassVisitor;
|
|||
|
||||
public interface TransformUnit {
|
||||
|
||||
Optional<ClassVisitor> transform(String className, ClassVisitor writer, Runnable modifiedCallback);
|
||||
Optional<ClassVisitor> transform(ClassLoader classLoader, String className, ClassVisitor writer, Runnable modifiedCallback);
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public class YggdrasilKeyTransformUnit implements TransformUnit {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Optional<ClassVisitor> transform(String className, ClassVisitor writer, Runnable modifiedCallback) {
|
||||
public Optional<ClassVisitor> transform(ClassLoader classLoader, String className, ClassVisitor writer, Runnable modifiedCallback) {
|
||||
if ("com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService".equals(className)) {
|
||||
return Optional.of(new ClassVisitor(ASM6, writer) {
|
||||
|
||||
|
|
Loading…
Reference in a new issue