fix loader reloading
All checks were successful
/ Build BaseBand Loader (push) Successful in 2m4s

This commit is contained in:
Daniella / Tove 2024-10-14 01:46:04 +02:00
parent b534b92456
commit 34a9334eaf
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
3 changed files with 32 additions and 14 deletions

View file

@ -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<String, byte[]> 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);

View file

@ -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<String> names = new HashSet<>();
private final DataKeeper<Map<String, byte[]>> binaryKeeper;
private final DataKeeper<PermissionManager> 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<String, byte[]> data) {
public GameClassLoader(Map<String, byte[]> 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;
}

View file

@ -0,0 +1,18 @@
package de.com.baseband.launcher.classloader;
import java.util.HashMap;
public class SimpleClassLoader extends ClassLoader {
HashMap<String, byte[]> classes;
public SimpleClassLoader(HashMap<String, byte[]> 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);
}
}