From 07c4e252dc3b8091784ca17a9d6c8398bb3772bb Mon Sep 17 00:00:00 2001 From: Haowei Wen Date: Sun, 13 Jun 2021 02:59:25 +0800 Subject: [PATCH 1/2] remove license-header.txt file --- license-header.txt | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 license-header.txt diff --git a/license-header.txt b/license-header.txt deleted file mode 100644 index 685a27e..0000000 --- a/license-header.txt +++ /dev/null @@ -1,14 +0,0 @@ -Copyright (C) 2021 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 . From 8e52c37eccd228e3e87abeea804174f6366a0640 Mon Sep 17 00:00:00 2001 From: Haowei Wen Date: Mon, 14 Jun 2021 05:56:38 +0800 Subject: [PATCH 2/2] fix #126 --- .../authlibinjector/AuthlibInjector.java | 4 +- .../support/ConcatenateURLTransformUnit.java | 81 +++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 src/main/java/moe/yushi/authlibinjector/transform/support/ConcatenateURLTransformUnit.java diff --git a/src/main/java/moe/yushi/authlibinjector/AuthlibInjector.java b/src/main/java/moe/yushi/authlibinjector/AuthlibInjector.java index d7da4c1..d5ab123 100644 --- a/src/main/java/moe/yushi/authlibinjector/AuthlibInjector.java +++ b/src/main/java/moe/yushi/authlibinjector/AuthlibInjector.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Haowei Wen and contributors + * Copyright (C) 2021 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 @@ -54,6 +54,7 @@ import moe.yushi.authlibinjector.transform.support.AuthServerNameInjector; import moe.yushi.authlibinjector.transform.support.AuthlibLogInterceptor; import moe.yushi.authlibinjector.transform.support.CitizensTransformer; +import moe.yushi.authlibinjector.transform.support.ConcatenateURLTransformUnit; import moe.yushi.authlibinjector.transform.support.ConstantURLTransformUnit; import moe.yushi.authlibinjector.transform.support.MC52974Workaround; import moe.yushi.authlibinjector.transform.support.MC52974_1710Workaround; @@ -266,6 +267,7 @@ private static ClassTransformer createTransformer(APIMetadata config) { transformer.units.add(new MainArgumentsTransformer()); transformer.units.add(new ConstantURLTransformUnit(urlProcessor)); transformer.units.add(new CitizensTransformer()); + transformer.units.add(new ConcatenateURLTransformUnit()); transformer.units.add(new SkinWhitelistTransformUnit()); SkinWhitelistTransformUnit.getWhitelistedDomains().addAll(config.getSkinDomains()); diff --git a/src/main/java/moe/yushi/authlibinjector/transform/support/ConcatenateURLTransformUnit.java b/src/main/java/moe/yushi/authlibinjector/transform/support/ConcatenateURLTransformUnit.java new file mode 100644 index 0000000..09070ef --- /dev/null +++ b/src/main/java/moe/yushi/authlibinjector/transform/support/ConcatenateURLTransformUnit.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2021 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.ARETURN; +import static org.objectweb.asm.Opcodes.ASM9; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Optional; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.MethodVisitor; +import moe.yushi.authlibinjector.transform.CallbackMethod; +import moe.yushi.authlibinjector.transform.CallbackSupport; +import moe.yushi.authlibinjector.transform.TransformContext; +import moe.yushi.authlibinjector.transform.TransformUnit; + +/** + * See + */ +public class ConcatenateURLTransformUnit implements TransformUnit { + + @CallbackMethod + public static URL concatenateURL(URL url, String query) { + try { + if (url.getQuery() != null && url.getQuery().length() > 0) { + return new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile() + "&" + query); + } else { + return new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile() + "?" + query); + } + } catch (MalformedURLException ex) { + throw new IllegalArgumentException("Could not concatenate given URL with GET arguments!", ex); + } + } + + @Override + public Optional transform(ClassLoader classLoader, String className, ClassVisitor writer, TransformContext ctx) { + if ("com.mojang.authlib.HttpAuthenticationService".equals(className)) { + return Optional.of(new ClassVisitor(ASM9, writer) { + @Override + public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) { + if ("concatenateURL".equals(name) && "(Ljava/net/URL;Ljava/lang/String;)Ljava/net/URL;".equals(descriptor)) { + ctx.markModified(); + MethodVisitor mv = super.visitMethod(access, name, descriptor, signature, exceptions); + mv.visitCode(); + mv.visitVarInsn(ALOAD, 0); + mv.visitVarInsn(ALOAD, 1); + CallbackSupport.invoke(ctx, mv, ConcatenateURLTransformUnit.class, "concatenateURL"); + mv.visitInsn(ARETURN); + 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 "ConcatenateURL Workaround"; + } +}