Skip to content

Commit

Permalink
Merge pull request #3 from anatawa12/master
Browse files Browse the repository at this point in the history
Add support for 1.7.10
  • Loading branch information
Rongmario authored Dec 10, 2021
2 parents 91c3ad0 + b70eeb0 commit 1246c36
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 87 deletions.
80 changes: 34 additions & 46 deletions ForgeMod/build.gradle
Original file line number Diff line number Diff line change
@@ -1,63 +1,51 @@
buildscript {
repositories {
jcenter()
maven { url = "https://files.minecraftforge.net/maven" }
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
}
}
apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
// It's not required to use ForgeGradle because re-obfuscation is not required for this.
// Re-obfuscation (reobf task) will work and required for minecraft's identifiers
// but this project doesn't use minecraft's classes so ForgeGradle is not required

apply plugin: 'java'

version = "1.0.0"
group = "zone.rong.nukejndilookupfromlog4j" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
group = "zone.rong.nukejndilookupfromlog4j"
archivesBaseName = "nukejndilookupfromlog4j"

sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
compileJava {
sourceCompatibility = targetCompatibility = '1.8'
sourceCompatibility = targetCompatibility = '1.8'

repositories {
maven { url = "https://files.minecraftforge.net/maven" }
maven { url = "https://libraries.minecraft.net/" }
}

minecraft {
version = "1.12.2-14.23.5.2847"
runDir = "run"

// the mappings can be changed at any time, and must be in the following format.
// snapshot_YYYYMMDD snapshot are built nightly.
// stable_# stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not always work.
// simply re-run your setup task after changing the mappings to update your workspace.
mappings = "stable_39"
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
sourceSets {
forge1122
forge1710
}

processResources {
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version

// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
// replace version and mcversion
expand 'version':project.version, 'mcversion':project.minecraft.version
}
// copy everything else except the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
dependencies {
// common dependencies
//noinspection GradlePackageUpdate // suppress IDEA
implementation "org.apache.logging.log4j:log4j-api:2.8.1"
//noinspection GradlePackageUpdate // suppress IDEA
implementation "org.apache.logging.log4j:log4j-core:2.8.1"
implementation "net.minecraft:launchwrapper:1.12"

// the dependency for forge 1.12.2 part
forge1122Implementation "net.minecraftforge:forge:1.12.2-14.23.5.2856:universal"
//noinspection GradlePackageUpdate // suppress IDEA
forge1122Implementation "com.google.guava:guava:21.0"

// the dependency for forge 1.7.10 part
forge1710Implementation "net.minecraftforge:forge:1.7.10-10.13.4.1614-1.7.10:universal"
//noinspection GradlePackageUpdate // suppress IDEA
forge1710Implementation "com.google.guava:guava:17.0"
}

jar {
from sourceSets.forge1122.output
from sourceSets.forge1710.output

manifest {
attributes([
"FMLCorePluginContainsFMLMod": true,
"FMLCorePlugin": 'zone.rong.nukejndilookupfromlog4j.NukeJndiLookupFromLog4j',
"ForceLoadAsMod": true
"TweakClass": 'zone.rong.nukejndilookupfromlog4j.tweaker.NukeJndiLookupFromLog4j',
])
}
}
Empty file modified ForgeMod/gradlew
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package zone.rong.nukejndilookupfromlog4j.supports;

import com.google.common.eventbus.EventBus;
import net.minecraftforge.fml.common.DummyModContainer;
import net.minecraftforge.fml.common.LoadController;
import net.minecraftforge.fml.common.ModMetadata;
import net.minecraftforge.fml.relauncher.FMLInjectionData;

@SuppressWarnings("unused") // used by reflection
public class Support1122 {
public static void runSupport() {
FMLInjectionData.containers.add(Container.class.getName());
}

public static class Container extends DummyModContainer {
public Container() {
super(new ModMetadata());
ModMetadata meta = this.getMetadata();
meta.modId = "nukejndilookupfromlog4j";
meta.name = "NukeJndiLookupFromLog4j";
meta.description = "Prevents a major vulnerability introduced by log4j from being abused.";
meta.version = "1.0.0";
meta.authorList.add("Rongmario");
meta.credits = "https://github.com/apache/logging-log4j2/pull/608";
}

@Override
public boolean registerBus(EventBus bus, LoadController controller) {
bus.register(this);
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package zone.rong.nukejndilookupfromlog4j.supports;

import com.google.common.eventbus.EventBus;
import cpw.mods.fml.common.DummyModContainer;
import cpw.mods.fml.common.LoadController;
import cpw.mods.fml.common.ModMetadata;
import cpw.mods.fml.relauncher.FMLInjectionData;

@SuppressWarnings("unused") // used by reflection
public class Support1710 {
public static void runSupport() {
FMLInjectionData.containers.add(Container.class.getName());
}

public static class Container extends DummyModContainer {
public Container() {
super(new ModMetadata());
ModMetadata meta = this.getMetadata();
meta.modId = "nukejndilookupfromlog4j";
meta.name = "NukeJndiLookupFromLog4j";
meta.description = "Prevents a major vulnerability introduced by log4j from being abused.";
meta.version = "1.0.0";
meta.authorList.add("Rongmario");
meta.credits = "https://github.com/apache/logging-log4j2/pull/608";
}

@Override
public boolean registerBus(EventBus bus, LoadController controller) {
bus.register(this);
return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package zone.rong.nukejndilookupfromlog4j;
package zone.rong.nukejndilookupfromlog4j.tweaker;

import com.google.common.eventbus.EventBus;
import net.minecraftforge.fml.common.DummyModContainer;
import net.minecraftforge.fml.common.LoadController;
import net.minecraftforge.fml.common.ModMetadata;
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
import net.minecraft.launchwrapper.ITweaker;
import net.minecraft.launchwrapper.Launch;
import net.minecraft.launchwrapper.LaunchClassLoader;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.impl.Log4jContextFactory;
Expand All @@ -13,17 +11,19 @@
import org.apache.logging.log4j.core.util.ShutdownCallbackRegistry;
import org.apache.logging.log4j.spi.LoggerContextFactory;

import javax.annotation.Nullable;
import java.io.File;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Proxy;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;

public class NukeJndiLookupFromLog4j implements IFMLLoadingPlugin {

@SuppressWarnings("unused") // used by reflection
public class NukeJndiLookupFromLog4j implements ITweaker {
private static final MethodHandle lookupsGetter;

static {
Expand Down Expand Up @@ -67,7 +67,7 @@ public NukeJndiLookupFromLog4j() throws ReflectiveOperationException {
// Capture any LoggerContexts created afterwards via proxying
Field factoryField = LogManager.class.getDeclaredField("factory");
factoryField.setAccessible(true);
factoryField.set(null, Proxy.newProxyInstance(LogManager.class.getClassLoader(), new Class[] { LoggerContextFactory.class, ShutdownCallbackRegistry.class }, (proxy, method, args) -> {
factoryField.set(null, Proxy.newProxyInstance(LogManager.class.getClassLoader(), factory.getClass().getInterfaces(), (proxy, method, args) -> {
Object result = method.invoke(factory, args);
if (result instanceof LoggerContext) {
nukeJndiLookup((LoggerContext) result);
Expand All @@ -77,48 +77,45 @@ public NukeJndiLookupFromLog4j() throws ReflectiveOperationException {
}

@Override
public String[] getASMTransformerClass() {
return new String[0];
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
}

@Override
public String getModContainerClass() {
return "zone.rong.nukejndilookupfromlog4j.NukeJndiLookupFromLog4j$Container";
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
if (classExists(classLoader, "net.minecraftforge.fml.relauncher.CoreModManager")) {
callSupport(classLoader, "Support1122");
} else if (classExists(classLoader, "cpw.mods.fml.relauncher.CoreModManager")) {
callSupport(classLoader, "Support1710");
} else {
throw new IllegalStateException("this version of minecraft is not supported!");
}
}

@Nullable
@Override
public String getSetupClass() {
return null;
private boolean classExists(LaunchClassLoader classLoader, String name) {
try {
classLoader.findClass(name);
return true;
} catch (ClassNotFoundException e) {
return false;
}
}

@Override
public void injectData(Map<String, Object> data) {}
private void callSupport(LaunchClassLoader classLoader, String name) {
try {
Class<?> supportClass = classLoader.findClass("zone.rong.nukejndilookupfromlog4j.supports." + name);
supportClass.getMethod("runSupport").invoke(null);
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException(e);
}
}

@Override
public String getAccessTransformerClass() {
public String getLaunchTarget() {
return null;
}

public static class Container extends DummyModContainer {

public Container() {
super(new ModMetadata());
ModMetadata meta = this.getMetadata();
meta.modId = "nukejndilookupfromlog4j";
meta.name = "NukeJndiLookupFromLog4j";
meta.description = "Prevents a major vulnerability introduced by log4j from being abused.";
meta.version = "1.0.0";
meta.authorList.add("Rongmario");
meta.credits = "https://github.com/apache/logging-log4j2/pull/608";
}

@Override
public boolean registerBus(EventBus bus, LoadController controller) {
bus.register(this);
return true;
}

@Override
public String[] getLaunchArguments() {
return new String[0];
}

}

0 comments on commit 1246c36

Please sign in to comment.