From 34a9334eafad9fb128c68b046a6c66aae95eceba Mon Sep 17 00:00:00 2001 From: TudbuT Date: Mon, 14 Oct 2024 01:46:04 +0200 Subject: [PATCH] fix loader reloading --- .../java/de/com/baseband/launcher/Loader.java | 16 ++++++++-------- ...omClassLoader.java => GameClassLoader.java} | 12 ++++++------ .../classloader/SimpleClassLoader.java | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 14 deletions(-) rename Loader/src/main/java/de/com/baseband/launcher/classloader/{CustomClassLoader.java => GameClassLoader.java} (96%) create mode 100644 Loader/src/main/java/de/com/baseband/launcher/classloader/SimpleClassLoader.java diff --git a/Loader/src/main/java/de/com/baseband/launcher/Loader.java b/Loader/src/main/java/de/com/baseband/launcher/Loader.java index bec4b54..bf86bec 100644 --- a/Loader/src/main/java/de/com/baseband/launcher/Loader.java +++ b/Loader/src/main/java/de/com/baseband/launcher/Loader.java @@ -1,7 +1,8 @@ package de.com.baseband.launcher; import de.com.baseband.clientboot.ClientBoot; -import de.com.baseband.launcher.classloader.CustomClassLoader; +import de.com.baseband.launcher.classloader.GameClassLoader; +import de.com.baseband.launcher.classloader.SimpleClassLoader; import de.com.baseband.launcher.security.SecurityImpl; import de.com.baseband.launcher.security.impl.AntiInstrumentationImpl; import de.com.baseband.launcher.security.impl.JVMArgImpl; @@ -70,12 +71,12 @@ public class Loader implements Util { } } - private static CustomClassLoader classLoader; + private static GameClassLoader classLoader; public static void run() { AccessKiller.killReflectionFor( - CustomClassLoader.class, - CustomClassLoader.CustomMixinServer.class); + GameClassLoader.class, + GameClassLoader.CustomMixinServer.class); AccessKiller.killFieldAccess(Loader.class); AccessKiller.killMethodAccess(Loader.class); @@ -337,7 +338,7 @@ public class Loader implements Util { } LOGGER.info("BaseBand downloaded: {} chunks.", data.size()); LOGGER.info("Booting BaseBand {} @ {}", clientData.getString("build-name"), new String(data.get("commit")).trim()); - classLoader = new CustomClassLoader(data); + classLoader = new GameClassLoader(data); downloadUpdated.unlock(); classLoader.inject(); classLoader.informClient(clientData); @@ -365,7 +366,7 @@ public class Loader implements Util { HashMap data = downloadFromSPL("https://download.baseband.com.de/download/client/" + options.getString("branch")); LOGGER.info("BaseBand downloaded: {} chunks.", data.size()); LOGGER.info("Booting BaseBand {} @ {}", options.getString("build-name"), new String(data.get("commit")).trim()); - classLoader = new CustomClassLoader(data); + classLoader = new GameClassLoader(data); classLoader.inject(); classLoader.informClient(options); } @@ -373,8 +374,7 @@ public class Loader implements Util { private static void splUpdate() { LOGGER.info("BaseBand is downloading a significant update..."); - CustomClassLoader loaderReloader = new CustomClassLoader(downloadFromSPL("https://download.baseband.com.de/download/loader")); - loaderReloader.inject(); + SimpleClassLoader loaderReloader = new SimpleClassLoader(downloadFromSPL("https://download.baseband.com.de/download/loader")); LOGGER.info("BaseBand has downloaded a significant update. Applying..."); try { loaderReloader.loadClass(Tweaker.class.getName()).getMethod("load").invoke(null); diff --git a/Loader/src/main/java/de/com/baseband/launcher/classloader/CustomClassLoader.java b/Loader/src/main/java/de/com/baseband/launcher/classloader/GameClassLoader.java similarity index 96% rename from Loader/src/main/java/de/com/baseband/launcher/classloader/CustomClassLoader.java rename to Loader/src/main/java/de/com/baseband/launcher/classloader/GameClassLoader.java index 576a38e..1772b12 100644 --- a/Loader/src/main/java/de/com/baseband/launcher/classloader/CustomClassLoader.java +++ b/Loader/src/main/java/de/com/baseband/launcher/classloader/GameClassLoader.java @@ -24,7 +24,7 @@ import java.util.Map; import static de.com.baseband.launcher.Loader.exit; -public class CustomClassLoader extends ClassLoader implements Util { +public class GameClassLoader extends ClassLoader implements Util { private final HashSet names = new HashSet<>(); private final DataKeeper> binaryKeeper; private final DataKeeper mixinPermissionManager; @@ -34,17 +34,17 @@ public class CustomClassLoader extends ClassLoader implements Util { try { Method m = Arrays.stream(Class.forName("java.lang.ClassLoader").getDeclaredClasses()).filter(x -> x.getSimpleName().equalsIgnoreCase("ParallelLoaders")).findFirst().get().getDeclaredMethod("register", Class.class); m.setAccessible(true); - m.invoke(null, CustomClassLoader.class); + m.invoke(null, GameClassLoader.class); LOGGER.info("Patched ClassLoader."); } catch (Exception e) { throw new RuntimeException("unable to patch ClassLoader", e); } } - public CustomClassLoader(Map data) { + public GameClassLoader(Map data) { names.addAll(data.keySet()); this.binaryKeeper = new DataKeeper<>( - new PermissionOR(new ClassLoaderRestriction(this), new CallClassRestriction(CustomClassLoader.class, CustomMixinServer.class)), + new PermissionOR(new ClassLoaderRestriction(this), new CallClassRestriction(GameClassLoader.class, CustomMixinServer.class)), StrictnessBuilder.create() .property("Restriction.ClassLoader.RestrictLambda", true) .property("Restriction.ClassLoader.MaxDistance", 5) @@ -191,9 +191,9 @@ public class CustomClassLoader extends ClassLoader implements Util { } public static class CustomMixinServer extends MixinServiceLaunchWrapper { - private final CustomClassLoader parent; + private final GameClassLoader parent; - public CustomMixinServer(CustomClassLoader parent) { + public CustomMixinServer(GameClassLoader parent) { this.parent = parent; } diff --git a/Loader/src/main/java/de/com/baseband/launcher/classloader/SimpleClassLoader.java b/Loader/src/main/java/de/com/baseband/launcher/classloader/SimpleClassLoader.java new file mode 100644 index 0000000..ff4f22a --- /dev/null +++ b/Loader/src/main/java/de/com/baseband/launcher/classloader/SimpleClassLoader.java @@ -0,0 +1,18 @@ +package de.com.baseband.launcher.classloader; + +import java.util.HashMap; + +public class SimpleClassLoader extends ClassLoader { + + HashMap classes; + + public SimpleClassLoader(HashMap classes) { + this.classes = classes; + } + + @Override + protected Class findClass(String name) { + byte[] b = classes.get(name.replace('.', '/') + ".class"); + return defineClass(name.replace('/', '.'), b, 0, b.length); + } +}