This commit is contained in:
yushijinhun 2018-02-13 01:19:16 +08:00
parent dff095e2cd
commit 1731f0b0cb
No known key found for this signature in database
GPG key ID: 5BC167F73EA558E4
3 changed files with 15 additions and 7 deletions

View file

@ -22,15 +22,23 @@ public final class AuthlibInjector {
private static final String[] nonTransformablePackages = new String[] { "java.", "javax.", "com.sun.",
"com.oracle.", "jdk.", "sun.", "org.apache.", "com.google.", "oracle.", "com.oracle.", "com.paulscode.",
"io.netty.", "org.lwjgl.", "net.java.", "org.w3c.", "javassist.", "org.xml.", "org.jcp.", "paulscode.",
"com.ibm.", "joptsimple." };
"com.ibm.", "joptsimple.", "org.to2mbn.authlibinjector." };
private AuthlibInjector() {}
private static boolean booted = false;
public static void log(String message, Object... args) {
System.err.println("[authlib-injector] " + MessageFormat.format(message, args));
}
public static void bootstrap(Consumer<ClassFileTransformer> transformerRegistry) {
if (booted) {
log("already booted, skipping");
return;
}
booted = true;
Optional<InjectorConfig> optionalConfig = configure();
if (!optionalConfig.isPresent()) {
log("no config is found, exiting");

View file

@ -3,16 +3,12 @@ package org.to2mbn.authlibinjector.tweaker;
import static org.to2mbn.authlibinjector.AuthlibInjector.bootstrap;
import static org.to2mbn.authlibinjector.AuthlibInjector.log;
import java.io.File;
import java.lang.instrument.ClassFileTransformer;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.launchwrapper.ITweaker;
import net.minecraft.launchwrapper.LaunchClassLoader;
public class AuthlibInjectorTweaker implements ITweaker {
static List<ClassFileTransformer> transformers = new ArrayList<>();
@Override
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {}
@ -22,7 +18,7 @@ public class AuthlibInjectorTweaker implements ITweaker {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
try {
log("launched from tweaker");
bootstrap(transformers::add);
bootstrap(TweakerTransformerAdapter.transformers::add);
launchClassLoader.registerTransformer(TweakerTransformerAdapter.class.getName());
} finally {
Thread.currentThread().setContextClassLoader(originalCtxCl);

View file

@ -3,15 +3,19 @@ package org.to2mbn.authlibinjector.tweaker;
import static org.to2mbn.authlibinjector.AuthlibInjector.log;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.launchwrapper.IClassTransformer;
import net.minecraft.launchwrapper.Launch;
public class TweakerTransformerAdapter implements IClassTransformer {
public static List<ClassFileTransformer> transformers = new ArrayList<>();
@Override
public byte[] transform(String name, String transformedName, byte[] classBuffer) {
String internalClassName = name.replace('.', '/');
for (ClassFileTransformer transformer : AuthlibInjectorTweaker.transformers) {
for (ClassFileTransformer transformer : transformers) {
byte[] result = null;
try {
result = transformer.transform(Launch.classLoader, internalClassName, null, null, classBuffer);