From 6d3e5856c238e33f549ae82fa846dc780068515b Mon Sep 17 00:00:00 2001 From: Haowei Wen Date: Fri, 11 Sep 2020 20:47:08 +0800 Subject: [PATCH] Drop main arguments --proxyHost, --proxyPort, --proxyUser, --proxyPass --- .../authlibinjector/AuthlibInjector.java | 2 + .../support/MainArgumentsTransformer.java | 3 +- .../support/ProxyParameterWorkaround.java | 53 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/main/java/moe/yushi/authlibinjector/transform/support/ProxyParameterWorkaround.java diff --git a/src/main/java/moe/yushi/authlibinjector/AuthlibInjector.java b/src/main/java/moe/yushi/authlibinjector/AuthlibInjector.java index 3b76025..ff7445c 100644 --- a/src/main/java/moe/yushi/authlibinjector/AuthlibInjector.java +++ b/src/main/java/moe/yushi/authlibinjector/AuthlibInjector.java @@ -56,6 +56,7 @@ import moe.yushi.authlibinjector.transform.support.ConstantURLTransformUnit; import moe.yushi.authlibinjector.transform.support.MC52974Workaround; import moe.yushi.authlibinjector.transform.support.MC52974_1710Workaround; import moe.yushi.authlibinjector.transform.support.MainArgumentsTransformer; +import moe.yushi.authlibinjector.transform.support.ProxyParameterWorkaround; import moe.yushi.authlibinjector.transform.support.SkinWhitelistTransformUnit; import moe.yushi.authlibinjector.transform.support.YggdrasilKeyTransformUnit; import moe.yushi.authlibinjector.yggdrasil.CustomYggdrasilAPIProvider; @@ -90,6 +91,7 @@ public final class AuthlibInjector { classTransformer = createTransformer(apiMetadata); instrumentation.addTransformer(classTransformer, retransformSupported); + ProxyParameterWorkaround.init(); MC52974Workaround.init(); MC52974_1710Workaround.init(); } diff --git a/src/main/java/moe/yushi/authlibinjector/transform/support/MainArgumentsTransformer.java b/src/main/java/moe/yushi/authlibinjector/transform/support/MainArgumentsTransformer.java index 654e1a1..da09c26 100644 --- a/src/main/java/moe/yushi/authlibinjector/transform/support/MainArgumentsTransformer.java +++ b/src/main/java/moe/yushi/authlibinjector/transform/support/MainArgumentsTransformer.java @@ -75,12 +75,13 @@ public class MainArgumentsTransformer implements TransformUnit { @CallbackMethod public static String[] processMainArguments(String[] args) { - log(DEBUG, "Main arguments: " + Stream.of(args).collect(joining(" "))); + log(DEBUG, "Original main arguments: " + Stream.of(args).collect(joining(" "))); String[] result = args; for (Function listener : ARGUMENTS_LISTENERS) { result = listener.apply(result); } + log(DEBUG, "Transformed main arguments: " + Stream.of(result).collect(joining(" "))); return result; } diff --git a/src/main/java/moe/yushi/authlibinjector/transform/support/ProxyParameterWorkaround.java b/src/main/java/moe/yushi/authlibinjector/transform/support/ProxyParameterWorkaround.java new file mode 100644 index 0000000..c13c547 --- /dev/null +++ b/src/main/java/moe/yushi/authlibinjector/transform/support/ProxyParameterWorkaround.java @@ -0,0 +1,53 @@ +/* + * 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 moe.yushi.authlibinjector.util.Logging.log; +import static moe.yushi.authlibinjector.util.Logging.Level.WARNING; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public final class ProxyParameterWorkaround { + private ProxyParameterWorkaround() {} + + private static final Set PROXY_PARAMETERS = new HashSet<>(Arrays.asList( + "--proxyHost", "--proxyPort", "--proxyUser", "--proxyPass" + )); + + public static void init() { + MainArgumentsTransformer.getArgumentsListeners().add(args -> { + boolean proxyDetected = false; + List filtered = new ArrayList<>(); + for (int i = 0; i < args.length; i++) { + if (i + 1 < args.length && PROXY_PARAMETERS.contains(args[i])) { + proxyDetected = true; + log(WARNING, "Dropping main argument " + args[i] + " " + args[i + 1]); + i++; + continue; + } + filtered.add(args[i]); + } + if (proxyDetected) { + log(WARNING, "--proxyHost parameter conflicts with authlib-injector, therefore proxy is disabled."); + } + return filtered.toArray(new String[filtered.size()]); + }); + } +}