Disable JndiLookup using log4j-patch
This commit is contained in:
@@ -63,18 +63,57 @@ public class MaintainTask extends Task<Version> {
|
|||||||
String mainClass = version.resolve(null).getMainClass();
|
String mainClass = version.resolve(null).getMainClass();
|
||||||
|
|
||||||
if (mainClass != null && mainClass.equals(LibraryAnalyzer.LAUNCH_WRAPPER_MAIN)) {
|
if (mainClass != null && mainClass.equals(LibraryAnalyzer.LAUNCH_WRAPPER_MAIN)) {
|
||||||
return maintainOptiFineLibrary(repository, maintainGameWithLaunchWrapper(unique(version), true), false);
|
version = maintainOptiFineLibrary(repository, maintainGameWithLaunchWrapper(unique(version), true), false);
|
||||||
} else if (mainClass != null && mainClass.equals(LibraryAnalyzer.MOD_LAUNCHER_MAIN)) {
|
} else if (mainClass != null && mainClass.equals(LibraryAnalyzer.MOD_LAUNCHER_MAIN)) {
|
||||||
// Forge 1.13 and OptiFine
|
// Forge 1.13 and OptiFine
|
||||||
return maintainOptiFineLibrary(repository, maintainGameWithCpwModLauncher(repository, unique(version)), true);
|
version = maintainOptiFineLibrary(repository, maintainGameWithCpwModLauncher(repository, unique(version)), true);
|
||||||
} else if (mainClass != null && mainClass.equals(LibraryAnalyzer.BOOTSTRAP_LAUNCHER_MAIN)) {
|
} else if (mainClass != null && mainClass.equals(LibraryAnalyzer.BOOTSTRAP_LAUNCHER_MAIN)) {
|
||||||
// Forge 1.17
|
// Forge 1.17
|
||||||
return maintainGameWithCpwBoostrapLauncher(repository, unique(version));
|
version = maintainGameWithCpwBoostrapLauncher(repository, unique(version));
|
||||||
} else {
|
} else {
|
||||||
// Vanilla Minecraft does not need maintain
|
// Vanilla Minecraft does not need maintain
|
||||||
// Fabric does not need maintain, nothing compatible with fabric now.
|
// Fabric does not need maintain, nothing compatible with fabric now.
|
||||||
return maintainOptiFineLibrary(repository, unique(version), false);
|
version = maintainOptiFineLibrary(repository, unique(version), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Library log4jPatch = null;
|
||||||
|
|
||||||
|
List<Library> libraries = version.getLibraries();
|
||||||
|
for (Library library : libraries) {
|
||||||
|
if (library.is("org.apache.logging.log4j", "log4j-core")) {
|
||||||
|
if (library.getVersion().startsWith("2.0-beta")) {
|
||||||
|
if ("2.0-beta9".equals(library.getVersion())) {
|
||||||
|
log4jPatch = new Library(new Artifact("org.glavo", "log4j-patch-beta9", "1.0"));
|
||||||
|
} else {
|
||||||
|
Logging.LOG.warning("Log4j " + library.getVersion() + " cannot be patched");
|
||||||
|
}
|
||||||
|
} else if (VersionNumber.VERSION_COMPARATOR.compare(library.getVersion(), "2.16") < 0) {
|
||||||
|
log4jPatch = new Library(new Artifact("org.glavo", "log4j-patch", "1.0"));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (log4jPatch != null) {
|
||||||
|
ArrayList<Library> patchedLibraries = new ArrayList<>(libraries.size() + 1);
|
||||||
|
patchedLibraries.add(log4jPatch);
|
||||||
|
patchedLibraries.addAll(libraries);
|
||||||
|
version = version.setLibraries(patchedLibraries);
|
||||||
|
|
||||||
|
Path log4jPatchPath = repository.getLibraryFile(version, log4jPatch).toPath();
|
||||||
|
String patchName = log4jPatch.getArtifactId() + "-" + log4jPatch.getVersion();
|
||||||
|
if (Files.notExists(log4jPatchPath)) {
|
||||||
|
try (InputStream input = MaintainTask.class.getResourceAsStream("/assets/game/" + patchName + ".jar")) {
|
||||||
|
Files.createDirectories(log4jPatchPath.getParent());
|
||||||
|
Files.copy(input, log4jPatchPath, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Logging.LOG.log(Level.WARNING, "Unable to unpack " + patchName, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Logging.LOG.info("Apply patch " + patchName + " to log4j");
|
||||||
|
}
|
||||||
|
|
||||||
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Version maintainPreservingPatches(GameRepository repository, Version version) {
|
public static Version maintainPreservingPatches(GameRepository repository, Version version) {
|
||||||
|
|||||||
@@ -2,4 +2,5 @@
|
|||||||
|
|
||||||
Copy from [Glavo/log4j-patch](https://github.com/Glavo/log4j-patch/).
|
Copy from [Glavo/log4j-patch](https://github.com/Glavo/log4j-patch/).
|
||||||
|
|
||||||
It is licensed under the WTFPL 2.0 license.
|
`org.apache.logging.log4j.core.lookup.JndiLookup` is licensed under the WTFPL 2.0 license,
|
||||||
|
and `org.apache.logging.log4j.core.lookup.Interpolator` is licensed under the Apache 2.0 license.
|
||||||
Reference in New Issue
Block a user