diff --git a/.gitignore b/.gitignore index 8e6c2eeb1..79ca4db4a 100644 --- a/.gitignore +++ b/.gitignore @@ -17,20 +17,23 @@ NVIDIA /build/ /HMCL/build/ /HMCLCore/build/ -/HMCLTransformerDiscoveryService/build/ +/minecraft/libraries/HMCLTransformerDiscoveryService/build/ +/minecraft/libraries/log4j-patch/build/ # idea .idea /out/ /HMCL/out/ /HMCLCore/out/ -/HMCLTransformerDiscoveryService/out/ +/minecraft/libraries/HMCLTransformerDiscoveryService/out/ +/minecraft/libraries/log4j-patch/out/ # eclipse /bin/ /HMCL/bin/ /HMCLCore/bin/ -/HMCLTransformerDiscoveryService/bin/ +/minecraft/libraries/HMCLTransformerDiscoveryService/bin/ +/minecraft/libraries/log4j-patch/bin/ .classpath .project .settings diff --git a/HMCL/build.gradle b/HMCL/build.gradle index 6b00f2b2f..7245ec490 100644 --- a/HMCL/build.gradle +++ b/HMCL/build.gradle @@ -129,7 +129,6 @@ shadowJar { exclude(dependency('com.google.code.gson:.*:.*')) exclude(dependency('com.github.steveice10:.*:.*')) exclude(dependency('libs:JFoenix:.*')) - exclude(project(":HMCLTransformerDiscoveryService")) } manifest { diff --git a/HMCLCore/build.gradle b/HMCLCore/build.gradle index 67c3f9c4b..1e2360c70 100644 --- a/HMCLCore/build.gradle +++ b/HMCLCore/build.gradle @@ -17,3 +17,11 @@ dependencies { api group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0' compileOnlyApi group: 'org.jetbrains', name: 'annotations', version: '16.0.3' } + +tasks.processResources { + dependsOn ':log4j-patch:jar' + + into('assets/game') { + from project(':log4j-patch').file("build/libs") + } +} diff --git a/HMCLTransformerDiscoveryService/src/main/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ITransformerDiscoveryService b/HMCLTransformerDiscoveryService/src/main/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ITransformerDiscoveryService deleted file mode 100644 index 82fc86968..000000000 --- a/HMCLTransformerDiscoveryService/src/main/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ITransformerDiscoveryService +++ /dev/null @@ -1 +0,0 @@ -org.jackhuang.hmcl.HMCLTransformerDiscoveryService diff --git a/HMCLTransformerDiscoveryService/build.gradle b/minecraft/libraries/HMCLTransformerDiscoveryService/build.gradle similarity index 77% rename from HMCLTransformerDiscoveryService/build.gradle rename to minecraft/libraries/HMCLTransformerDiscoveryService/build.gradle index 3860e35ae..413299664 100644 --- a/HMCLTransformerDiscoveryService/build.gradle +++ b/minecraft/libraries/HMCLTransformerDiscoveryService/build.gradle @@ -4,6 +4,11 @@ dependencies { compileOnly project.files("lib/modlauncher-4.1.0.jar") } +compileJava { + sourceCompatibility = 8 + targetCompatibility = 8 +} + jar { manifest { attributes 'Created-By': 'Copyright(c) 2013-2020 huangyuhui.', diff --git a/HMCLTransformerDiscoveryService/lib/modlauncher-4.1.0.jar b/minecraft/libraries/HMCLTransformerDiscoveryService/lib/modlauncher-4.1.0.jar similarity index 100% rename from HMCLTransformerDiscoveryService/lib/modlauncher-4.1.0.jar rename to minecraft/libraries/HMCLTransformerDiscoveryService/lib/modlauncher-4.1.0.jar diff --git a/HMCLTransformerDiscoveryService/src/main/java/org/jackhuang/hmcl/HMCLTransformerDiscoveryService.java b/minecraft/libraries/HMCLTransformerDiscoveryService/src/main/java/org/jackhuang/hmcl/HMCLTransformerDiscoveryService.java similarity index 100% rename from HMCLTransformerDiscoveryService/src/main/java/org/jackhuang/hmcl/HMCLTransformerDiscoveryService.java rename to minecraft/libraries/HMCLTransformerDiscoveryService/src/main/java/org/jackhuang/hmcl/HMCLTransformerDiscoveryService.java diff --git a/HMCLTransformerDiscoveryService/bin/main/META-INF/services/cpw.mods.modlauncher.serviceapi.ITransformerDiscoveryService b/minecraft/libraries/HMCLTransformerDiscoveryService/src/main/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ITransformerDiscoveryService similarity index 100% rename from HMCLTransformerDiscoveryService/bin/main/META-INF/services/cpw.mods.modlauncher.serviceapi.ITransformerDiscoveryService rename to minecraft/libraries/HMCLTransformerDiscoveryService/src/main/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ITransformerDiscoveryService diff --git a/minecraft/libraries/log4j-patch/LICENSE b/minecraft/libraries/log4j-patch/LICENSE new file mode 100644 index 000000000..4a87280f2 --- /dev/null +++ b/minecraft/libraries/log4j-patch/LICENSE @@ -0,0 +1,13 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. \ No newline at end of file diff --git a/minecraft/libraries/log4j-patch/README.md b/minecraft/libraries/log4j-patch/README.md new file mode 100644 index 000000000..d52884d7a --- /dev/null +++ b/minecraft/libraries/log4j-patch/README.md @@ -0,0 +1,5 @@ +# Log4j Patch + +Copy from [Glavo/log4j-patch](https://github.com/Glavo/log4j-patch/). + +It is licensed under the WTFPL 2.0 license. \ No newline at end of file diff --git a/minecraft/libraries/log4j-patch/build.gradle b/minecraft/libraries/log4j-patch/build.gradle new file mode 100644 index 000000000..022dafdf1 --- /dev/null +++ b/minecraft/libraries/log4j-patch/build.gradle @@ -0,0 +1,46 @@ +version '1.0' + +dependencies { + compileOnly group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.0-beta9' +} + +tasks.compileJava { + sourceCompatibility = 8 + targetCompatibility = 8 + + doLast { + FileTree tree = fileTree('build/classes/java/main') + tree.include '**/*.class' + tree.each { + RandomAccessFile rf = new RandomAccessFile(it, "rw") + rf.seek(7) // major version + rf.write(50) // java 6 + rf.close() + } + } +} + +task patchJar(type: Jar) { + dependsOn(tasks.compileJava) + + baseName = 'log4j-patch' + + from(sourceSets.main.output) { + include('**/JndiLookup.class') + } +} + +task patchBeta9Jar(type: Jar) { + dependsOn(tasks.compileJava) + + baseName = 'log4j-patch-beta9' + + from(sourceSets.main.output) { + include '**/Interpolator.class' + } +} + +tasks.jar { + enabled = false + dependsOn patchJar, patchBeta9Jar +} \ No newline at end of file diff --git a/minecraft/libraries/log4j-patch/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java b/minecraft/libraries/log4j-patch/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java new file mode 100644 index 000000000..8a65166de --- /dev/null +++ b/minecraft/libraries/log4j-patch/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.lookup; + +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.config.plugins.PluginManager; +import org.apache.logging.log4j.core.config.plugins.PluginType; +import org.apache.logging.log4j.status.StatusLogger; + +import java.util.HashMap; +import java.util.Map; + +/** + * The Interpolator is a StrLookup that acts as a proxy for all the other StrLookups. + */ +public class Interpolator implements StrLookup { + + private static final Logger LOGGER = StatusLogger.getLogger(); + + /** Constant for the prefix separator. */ + private static final char PREFIX_SEPARATOR = ':'; + + private final Map lookups = new HashMap(); + + private final StrLookup defaultLookup; + + @SuppressWarnings("deprecation") + public Interpolator(final StrLookup defaultLookup) { + this.defaultLookup = defaultLookup == null ? new MapLookup(new HashMap()) : defaultLookup; + final PluginManager manager = new PluginManager("Lookup"); + manager.collectPlugins(); + final Map> plugins = manager.getPlugins(); + + for (final Map.Entry> entry : plugins.entrySet()) { + @SuppressWarnings("unchecked") + final Class clazz = (Class) entry.getValue().getPluginClass(); + try { + lookups.put(entry.getKey(), clazz.newInstance()); + } catch (final Exception ex) { + LOGGER.error("Unable to create Lookup for " + entry.getKey(), ex); + } + } + } + + /** + * Create the default Interpolator using only Lookups that work without an event. + */ + public Interpolator() { + this.defaultLookup = new MapLookup(new HashMap()); + lookups.put("sys", new SystemPropertiesLookup()); + lookups.put("env", new EnvironmentLookup()); + // lookups.put("jndi", new JndiLookup()); + LOGGER.warn("log4j-patch works, JNDI lookup is disabled."); + + try { + if (Class.forName("javax.servlet.ServletContext") != null) { + lookups.put("web", new WebLookup()); + } + } catch (ClassNotFoundException ex) { + LOGGER.debug("ServletContext not present - WebLookup not added"); + } catch (Exception ex) { + LOGGER.error("Unable to locate ServletContext", ex); + } + } + + /** + * Resolves the specified variable. This implementation will try to extract + * a variable prefix from the given variable name (the first colon (':') is + * used as prefix separator). It then passes the name of the variable with + * the prefix stripped to the lookup object registered for this prefix. If + * no prefix can be found or if the associated lookup object cannot resolve + * this variable, the default lookup object will be used. + * + * @param var the name of the variable whose value is to be looked up + * @return the value of this variable or null if it cannot be + * resolved + */ + @Override + public String lookup(final String var) { + return lookup(null, var); + } + + /** + * Resolves the specified variable. This implementation will try to extract + * a variable prefix from the given variable name (the first colon (':') is + * used as prefix separator). It then passes the name of the variable with + * the prefix stripped to the lookup object registered for this prefix. If + * no prefix can be found or if the associated lookup object cannot resolve + * this variable, the default lookup object will be used. + * + * @param event The current LogEvent or null. + * @param var the name of the variable whose value is to be looked up + * @return the value of this variable or null if it cannot be + * resolved + */ + @Override + public String lookup(final LogEvent event, String var) { + if (var == null) { + return null; + } + + final int prefixPos = var.indexOf(PREFIX_SEPARATOR); + if (prefixPos >= 0) { + final String prefix = var.substring(0, prefixPos); + final String name = var.substring(prefixPos + 1); + final StrLookup lookup = lookups.get(prefix); + String value = null; + if (lookup != null) { + value = event == null ? lookup.lookup(name) : lookup.lookup(event, name); + } + + if (value != null) { + return value; + } + var = var.substring(prefixPos + 1); + } + if (defaultLookup != null) { + return event == null ? defaultLookup.lookup(var) : defaultLookup.lookup(event, var); + } + return null; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + for (final String name : lookups.keySet()) { + if (sb.length() == 0) { + sb.append("{"); + } else { + sb.append(", "); + } + + sb.append(name); + } + if (sb.length() > 0) { + sb.append("}"); + } + return sb.toString(); + } +} diff --git a/minecraft/libraries/log4j-patch/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java b/minecraft/libraries/log4j-patch/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java new file mode 100644 index 000000000..1e87e75ed --- /dev/null +++ b/minecraft/libraries/log4j-patch/src/main/java/org/apache/logging/log4j/core/lookup/JndiLookup.java @@ -0,0 +1,13 @@ +/* + * Copyright © 2021 Glavo + * This work is free. You can redistribute it and/or modify it under the + * terms of the Do What The Fuck You Want To Public License, Version 2, + * as published by Sam Hocevar. See http://www.wtfpl.net/ for more details. + */ +package org.apache.logging.log4j.core.lookup; + +public class JndiLookup { + public JndiLookup() { + throw new NoClassDefFoundError("JNDI lookup is disabled"); + } +} diff --git a/settings.gradle b/settings.gradle index 7a267504a..b7aabf891 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,3 +2,7 @@ rootProject.name = 'HMCL3' include ':HMCL' include ':HMCLCore' include ':HMCLTransformerDiscoveryService' +include ':log4j-patch' + +project(':HMCLTransformerDiscoveryService').projectDir = file('minecraft/libraries/HMCLTransformerDiscoveryService') +project(':log4j-patch').projectDir = file('minecraft/libraries/log4j-patch')