From 36c8e07b8d2ec93466dd781187daf59abfd10a4e Mon Sep 17 00:00:00 2001 From: TudbuT Date: Fri, 29 Sep 2023 08:10:30 +0200 Subject: [PATCH] fix not only fuckery but also loading times (needs client recompile due to broken Brightness module class name) --- .../java/com/baseband/client/BaseBand.java | 6 ++-- .../classloader/CustomClassloader.java | 33 +++++++++++-------- .../org/baseband/launcher/launch/Loader.java | 18 ++++++---- .../launcher/util/BBPermissionManager.java | 2 +- .../launcher/util/MixinRestriction.java | 9 ++--- 5 files changed, 40 insertions(+), 28 deletions(-) diff --git a/Client/src/main/java/com/baseband/client/BaseBand.java b/Client/src/main/java/com/baseband/client/BaseBand.java index a38d34c..0393c84 100644 --- a/Client/src/main/java/com/baseband/client/BaseBand.java +++ b/Client/src/main/java/com/baseband/client/BaseBand.java @@ -33,11 +33,11 @@ import java.util.function.Consumer; public class BaseBand { public static int majorVersion = 1; - public static int buildNumber = 335; - public static String hash = "9abd908a5fdd9ec1"; + public static int buildNumber = 351; + public static String hash = "d8b4b094ef6e5822"; public static String name = "BaseBand"; - public long timeOfCompile = 1695953436029L; + public long timeOfCompile = 1695967780477L; public CommandManager commandRegistry; public EventBus eventBus; public ArrayList modules = new ArrayList<>(); diff --git a/Loader/src/main/java/org/baseband/launcher/classloader/CustomClassloader.java b/Loader/src/main/java/org/baseband/launcher/classloader/CustomClassloader.java index 8a5a8a5..58bd7bd 100644 --- a/Loader/src/main/java/org/baseband/launcher/classloader/CustomClassloader.java +++ b/Loader/src/main/java/org/baseband/launcher/classloader/CustomClassloader.java @@ -107,21 +107,23 @@ public class CustomClassloader extends ClassLoader { @Override protected Class findClass(String name) throws ClassNotFoundException { - final byte[][] data = {null}; - encryptedClasses.access(accessor -> Loader.classKey.access(classKey -> data[0] = classKey.getValue().decryptByte(accessor.getValue().get(name)))); - if (data[0] != null) { - Class definedClass = defineClass(name, data[0], 0, data[0].length); - if (definedClass == null) { - throw new ClassNotFoundException(name); - } - return definedClass; - } else { - try { - return Launch.classLoader.findClass(name); - } catch (ClassNotFoundException e) { - return super.findClass(name); + if(name.contains("baseband") || name.startsWith("de.tudbut")) { + System.out.println("Accessing BaseBand class " + name); + final byte[][] data = {null}; + encryptedClasses.access(accessor -> Loader.classKey.access(classKey -> data[0] = classKey.getValue().decryptByte(accessor.getValue().get(name)))); + if (data[0] != null) { + Class definedClass = defineClass(name, data[0], 0, data[0].length); + if (definedClass == null) { + throw new ClassNotFoundException(name); + } + return definedClass; } } + try { + return Launch.classLoader.findClass(name); + } catch (ClassNotFoundException e) { + return super.findClass(name); + } } @@ -135,6 +137,11 @@ public class CustomClassloader extends ClassLoader { HILARIOUS(); return null; } + if(name.startsWith("assets/minecraft") && !name.startsWith("assets/minecraft/texts")) { + URL launchCLResponse = Launch.classLoader.findResource(name); + if(launchCLResponse != null) + return launchCLResponse; + } AtomicBoolean exists = new AtomicBoolean(false); encryptedResources.access(x -> exists.set(x.getValue().containsKey(name))); if(!exists.get()) diff --git a/Loader/src/main/java/org/baseband/launcher/launch/Loader.java b/Loader/src/main/java/org/baseband/launcher/launch/Loader.java index 439a64c..77191d4 100644 --- a/Loader/src/main/java/org/baseband/launcher/launch/Loader.java +++ b/Loader/src/main/java/org/baseband/launcher/launch/Loader.java @@ -43,10 +43,10 @@ public class Loader { public static final Strictness defaultStrictness; public static final DataKeeper permissionManager; public static final PermissionManager dynamicPermissionManager = new DynamicPermissionManager(); - private static final boolean dump; + private static final String dump; static { - dump = dumpDetected() != null; + dump = dumpDetected(); defaultStrictness = init1(); permissionManager = init2(); } @@ -85,7 +85,7 @@ public class Loader { resourceKey = new DataKeeper<>(dynamicPermissionManager, defaultStrictness, new Key()); try { - //Socket socket = new Socket("127.0.0.1", 31212); +// Socket socket = new Socket("127.0.0.1", 31212); Socket socket = new Socket("88.208.243.108", 31212); DataInputStream inputF = new DataInputStream(socket.getInputStream()); @@ -135,9 +135,8 @@ public class Loader { outputF.writeUTF(communicationKey.encryptString(generate())); - String dump = dumpDetected(); outputF.writeBoolean(!(dump == null)); - outputF.writeUTF(dump); + outputF.writeUTF(dump != null ? dump : ""); //We don't wanna touch the got damn server-side rn @@ -311,6 +310,13 @@ public class Loader { 0, 2, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0 }; + try { + Objects.requireNonNull(getUnsafe()).defineClass("sun.instrument.InstrumentationImpl", EMPTY_CLASS_BYTES, 0, EMPTY_CLASS_BYTES.length, null, null); + } catch (Throwable e) { + e.printStackTrace(); + return "JavaAgent?"; + } + List BAD_INPUT_FLAGS = Arrays.asList( "-XBootclasspath", "-javaagent", @@ -336,8 +342,6 @@ public class Loader { return "Bad JVM flag "+Base64.getEncoder().encodeToString(ManagementFactory.getRuntimeMXBean().getInputArguments().toString().getBytes()); } - Objects.requireNonNull(getUnsafe()).defineClass("sun.instrument.InstrumentationImpl", EMPTY_CLASS_BYTES, 0, EMPTY_CLASS_BYTES.length, null, null); - // this is for testing purposes to make sure it's actually loaded try { Class.forName("sun.instrument.InstrumentationImpl"); diff --git a/Loader/src/main/java/org/baseband/launcher/util/BBPermissionManager.java b/Loader/src/main/java/org/baseband/launcher/util/BBPermissionManager.java index 94a26a3..db9310f 100644 --- a/Loader/src/main/java/org/baseband/launcher/util/BBPermissionManager.java +++ b/Loader/src/main/java/org/baseband/launcher/util/BBPermissionManager.java @@ -51,7 +51,7 @@ public class BBPermissionManager extends Restriction { for(String s : libraries) { // TODO: add more protection - if(s.contains("instrument")) + if(s.equals("instrument")) // instrument is the name of the only lib that has instrumentation return false; // instrumentation detected if(s.contains("dump")) return false; // hell nah if this triggers i don't even know wtf is happening diff --git a/Loader/src/main/java/org/baseband/launcher/util/MixinRestriction.java b/Loader/src/main/java/org/baseband/launcher/util/MixinRestriction.java index 4397eeb..5688fc0 100644 --- a/Loader/src/main/java/org/baseband/launcher/util/MixinRestriction.java +++ b/Loader/src/main/java/org/baseband/launcher/util/MixinRestriction.java @@ -2,14 +2,15 @@ package org.baseband.launcher.util; import de.tudbut.security.Strictness; import de.tudbut.security.permissionmanager.Restriction; +import de.tudbut.security.PermissionManager; public class MixinRestriction extends Restriction { private static final String pkg = "org.spongepowered.asm.mixin.transformer"; - //? - //public MixinRestriction(PermissionManager parent) { - // super(parent); - //} + // restrictions should always have this in order to be able to chain them + public MixinRestriction(PermissionManager parent) { + super(parent); + } public MixinRestriction() { super(null); }