forked from MirrorHub/authlib-injector
66 lines
2.4 KiB
Java
66 lines
2.4 KiB
Java
/*
|
|
* Copyright (C) 2022 Haowei Wen <yushijinhun@gmail.com> 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 <https://www.gnu.org/licenses/>.
|
|
*/
|
|
package moe.yushi.authlibinjector.transform.support;
|
|
|
|
import static org.objectweb.asm.Opcodes.ASM9;
|
|
import static org.objectweb.asm.Opcodes.ICONST_1;
|
|
import static org.objectweb.asm.Opcodes.IRETURN;
|
|
import java.util.Optional;
|
|
import org.objectweb.asm.ClassVisitor;
|
|
import org.objectweb.asm.MethodVisitor;
|
|
import moe.yushi.authlibinjector.transform.TransformContext;
|
|
import moe.yushi.authlibinjector.transform.TransformUnit;
|
|
|
|
/**
|
|
* Hacks BungeeCord to bypass profile key signature validation.
|
|
* See https://github.com/SpigotMC/BungeeCord/commit/78ca16dfe3bf9a21d5c054a1884d4f5f198a62bc .
|
|
*/
|
|
public class BungeeCordProfileKeyTransformUnit implements TransformUnit {
|
|
|
|
@Override
|
|
public Optional<ClassVisitor> transform(ClassLoader classLoader, String className, ClassVisitor writer, TransformContext ctx) {
|
|
if ("net.md_5.bungee.EncryptionUtil".equals(className)) {
|
|
return Optional.of(new ClassVisitor(ASM9, writer) {
|
|
@Override
|
|
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
|
|
if ("check".equals(name) && "(Lnet/md_5/bungee/protocol/PlayerPublicKey;Ljava/util/UUID;)Z".equals(descriptor)) {
|
|
ctx.markModified();
|
|
|
|
MethodVisitor mv = super.visitMethod(access, name, descriptor, signature, exceptions);
|
|
mv.visitCode();
|
|
mv.visitInsn(ICONST_1);
|
|
mv.visitInsn(IRETURN);
|
|
mv.visitMaxs(-1, -1);
|
|
mv.visitEnd();
|
|
|
|
return null;
|
|
} else {
|
|
return super.visitMethod(access, name, descriptor, signature, exceptions);
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
return Optional.empty();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "BungeeCord Profile Key Transformer";
|
|
}
|
|
}
|