fix: support obfuscated clients via detection, Loader ASM relocation and remapper exclude

This commit is contained in:
xiaozhou233 committed 2026-08-20 11:34:25 +08:00
1 parent 6eb9ca8240
commit b3e7000bf0
7 files changed
+126 -12

No files matched your search

+1
View File
@@ -17,4 +17,5 @@ dependencies {
shadowJar {
archiveFileName = 'Loader.jar'
relocate 'org.objectweb.asm', 'cn.xiaozhou233.asm9'
}
@@ -0,0 +1,52 @@
package cn.xiaozhou233.orangex.loader;
public class Detector {
private static boolean classExists(String className) {
String resourceName = className.replace('.', '/') + ".class";
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null) {
classLoader = Detector.class.getClassLoader();
}
return classLoader.getResource(resourceName) != null;
}
public static DetectorType detect() {
// Lunar Client Detection
if (classExists("com.moonsworth.lunar.genesis.Genesis")) {
System.out.println("Lunar class found!");
return DetectorType.LUNAR;
}
System.out.println("Lunar class not found");
// Badlion Detection
if (classExists("net.badlion.client.Wrapper")) {
System.out.println("Badlion class found!");
return DetectorType.BADLION;
}
System.out.println("Badlion class not found");
// MCP Detection
if (classExists("net.minecraft.client.Minecraft")) {
System.out.println("MCP class found!");
return DetectorType.MCP;
}
System.out.println("MCP class not found");
// Vanilla Detection
if (classExists("ave")) {
System.out.println("Vanilla class found!");
return DetectorType.VANILLA;
}
System.out.println("Vanilla class not found");
return DetectorType.UNKNOWN;
}
}
@@ -0,0 +1,9 @@
package cn.xiaozhou233.orangex.loader;
public enum DetectorType {
BADLION,
LUNAR,
VANILLA,
MCP,
UNKNOWN
}
@@ -4,6 +4,7 @@ package cn.xiaozhou233.orangex.loader;
import cn.xiaozhou233.juiceagent.api.JuiceAgent;
import cn.xiaozhou233.juiceremapper.JuiceRemapper;
import javax.swing.*;
import java.io.File;
public class Loader {
@@ -31,17 +32,34 @@ public class Loader {
// Check Obfuscation
// Only Check MCP or Vanilla Obfuscation
try {
Class.forName("ave");
System.out.println("Obfuscation detected");
// Load JuiceRemapper Native
System.load(new File(userDir, "/.orangex/libremapper.dll").getAbsolutePath());
switch (Detector.detect()) {
case MCP:
break;
case VANILLA:
System.load(new File(userDir, "/.orangex/libremapper.dll").getAbsolutePath());
JuiceRemapper.init();
JuiceRemapper.addInclude("cn/xiaozhou233/orangex/");
JuiceRemapper.addExclude("cn/xiaozhou233/orangex/mixin/");
break;
case LUNAR:
break;
case BADLION:
System.load(new File(userDir, "/.orangex/libremapper.dll").getAbsolutePath());
JuiceRemapper.init();
JuiceRemapper.addInclude("cn/xiaozhou233/orangex/");
JuiceRemapper.addExclude("cn/xiaozhou233/orangex/mixin/");
break;
case UNKNOWN:
JOptionPane.showMessageDialog(
null,
"Inject Failed! Cause: Unknown Obfuscation",
"Unknown Obfuscation",
JOptionPane.ERROR_MESSAGE
);
throw new IllegalStateException("Unknown Obfuscation");
JuiceRemapper.init();
JuiceRemapper.addInclude("cn/xiaozhou233/orangex/");
JuiceRemapper.addExclude("cn/xiaozhou233/orangex/mixin");
} catch (ClassNotFoundException e) {
System.out.println("Obfuscation not detected");
}
@@ -1,6 +1,6 @@
package cn.xiaozhou233.orangex.mixin;
import cn.xiaozhou233.juiceremapper.utils.IOUtils;
import cn.xiaozhou233.orangex.utils.IOUtils;
import cn.xiaozhou233.orangex.mixin.impl.*;
import cn.xiaozhou233.orangex.utils.JuiceAgentFacade;
import cn.yapeteam.ymixin.Transformer;
@@ -71,7 +71,7 @@ public final class MixinManager {
transformer.transform().forEach((name, bytes) -> {
try {
Class<?> targetClass = Class.forName(name, false, cl);
boolean ok = JuiceAgentFacade.redefineClass(targetClass, bytes);
boolean ok = JuiceAgentFacade.retransformClass(targetClass, bytes);
if (!ok) {
throw new RuntimeException("Redefine failed: " + name);
}
@@ -0,0 +1,24 @@
package cn.xiaozhou233.orangex.utils;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class IOUtils {
public static byte[] toByteArray(InputStream input) throws IOException {
if (input == null) {
return new byte[0];
}
byte[] buffer = new byte[8192]; // 8KB buffer
int len;
ByteArrayOutputStream output = new ByteArrayOutputStream();
while ((len = input.read(buffer)) != -1) {
output.write(buffer, 0, len);
}
return output.toByteArray();
}
}
@@ -8,6 +8,7 @@ public final class JuiceAgentFacade {
private static final Method GET_CLASS_BYTES;
private static final Method REDEFINE_CLASS;
private static final Method GET_LOADED_CLASSES;
private static final Method RETRANSFORM_CLASS;
static {
try {
@@ -25,6 +26,7 @@ public final class JuiceAgentFacade {
int.class
);
GET_LOADED_CLASSES = JL.getMethod("getLoadedClasses");
RETRANSFORM_CLASS = JL.getMethod("retransformClass", Class.class, byte[].class, int.class);
} catch (Exception e) {
throw new RuntimeException("Failed to init JuiceFacade", e);
@@ -56,4 +58,12 @@ public final class JuiceAgentFacade {
throw new RuntimeException(e);
}
}
public static boolean retransformClass(Class<?> clazz, byte[] bytes) {
try {
return (boolean) RETRANSFORM_CLASS.invoke(null, clazz, bytes, bytes.length);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}