proud american code (resources are now safe and funny) (also less logging)

This commit is contained in:
Daniella / Tove 2023-09-28 20:35:13 +02:00
parent 4a02fac307
commit dc0cb6e632
Signed by: TudbuT
GPG key ID: 7D63D5634B7C417F
4 changed files with 112 additions and 26 deletions

View file

@ -31,14 +31,13 @@ import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.function.Consumer;
@Mod(modid = "baseband")
public class BaseBand {
public static int majorVersion = 1;
public static int buildNumber = 313;
public static String hash = "0259cd1df4fa6209";
public static int buildNumber = 330;
public static String hash = "ac8c773733ce7832";
public static String name = "BaseBand";
public long timeOfCompile = 1695921315991L;
public long timeOfCompile = 1695925976124L;
public CommandManager commandRegistry;
public EventBus eventBus;
public ArrayList<Module> modules = new ArrayList<>();
@ -66,11 +65,6 @@ public class BaseBand {
public int level = 0; //Standard user
@Mod.EventHandler
public void eventInit(FMLPreInitializationEvent event) {
onInit();
}
public void onInit() {
Utils.check();
@ -83,7 +77,6 @@ public class BaseBand {
for (Method save : registry.getClass().getMethods()) {
if(save.getParameterCount() == 0 && save.getReturnType() == Void.TYPE && save.getDeclaringClass() == registry.getClass()) {
save.invoke(registry); // registry save
System.out.println("Registry saved!!");
}
}
} catch (IllegalAccessException | InvocationTargetException e) {

View file

@ -13,30 +13,35 @@ import de.tudbut.security.permissionmanager.HideErrorRestriction;
import net.minecraft.launchwrapper.Launch;
import org.baseband.launcher.launch.Loader;
import org.baseband.launcher.util.BBPermissionManager;
import org.baseband.launcher.util.DynamicPermissionManager;
import org.baseband.launcher.util.MixinRestriction;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.service.mojang.MixinServiceLaunchWrapper;
import java.io.IOException;
import java.awt.*;
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicBoolean;
public class CustomClassloader extends ClassLoader {
public static Class<?> customMixinServerClass = CustomMixinServer.class;
private static final DataKeeper<HashMap<String, byte[]>> encryptedClasses;
private static final DataKeeper<HashMap<String, byte[]>> encryptedResources;
public static final DataKeeper<Object> registryTransfer;
static {
encryptedClasses = init1();
registryTransfer = init2();
encryptedResources = init3();
}
private static DataKeeper<HashMap<String, byte[]>> init1() {
AccessKiller.killReflectionFor(CustomClassloader.class, CustomMixinServer.class);
AccessKiller.killReflectionFor(CustomClassloader.class, CustomMixinServer.class, URLStreamHandler.class, ResourceConnection.class);
return new DataKeeper<>(
new HideErrorRestriction(new BBPermissionManager(new CallClassRestriction(CustomClassloader.class, CustomMixinServer.class))),
Loader.defaultStrictness,
@ -52,18 +57,23 @@ public class CustomClassloader extends ClassLoader {
);
}
private static DataKeeper<HashMap<String, byte[]>> init3() {
return new DataKeeper<>(
new HideErrorRestriction(new BBPermissionManager(new CallClassRestriction(CustomClassloader.class, URLStreamHandler.class, URLStreamHandler.class, ResourceConnection.class))),
Loader.defaultStrictness,
new HashMap<>()
);
}
public static void ensureInit() {
}
public CustomClassloader(Object obj) {
initClasses(obj);
public CustomClassloader(Object obj, Object obj2) {
initClasses(obj, obj2);
}
public CustomClassloader() {
}
public void initClasses(Object classes) {
public void initClasses(Object classes, Object resources) {
try {
CustomMixinServer customService = new CustomMixinServer();
@ -83,6 +93,7 @@ public class CustomClassloader extends ClassLoader {
}
encryptedClasses.access(accessor -> accessor.setValue((HashMap<String, byte[]>) classes));
encryptedResources.access(accessor -> accessor.setValue((HashMap<String, byte[]>) resources));
try {
Field parent = ClassLoader.class.getDeclaredField("parent");
@ -114,6 +125,89 @@ public class CustomClassloader extends ClassLoader {
}
}
@Override
protected URL findResource(String name) {
if(name.endsWith(".class")) {
URL launchCLResponse = Launch.classLoader.findResource(name);
if(launchCLResponse != null)
return launchCLResponse;
HILARIOUS();
return null;
}
AtomicBoolean exists = new AtomicBoolean(false);
encryptedResources.access(x -> exists.set(x.getValue().containsKey(name)));
if(!exists.get())
return Launch.classLoader.findResource(name);
try {
return new URL(null, "gsm://" + name, new URLHandler(name));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
private void HILARIOUS() {
try {
Desktop dt = Desktop.getDesktop();
ArrayList<String> lines = new ArrayList();
String line;
URL url = new URL("https://basebandclient.xyz/funnies/funny.txt");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(url.openStream()));
while ((line = bufferedReader.readLine()) != null) {
lines.add(line);
}
bufferedReader.close();
for (String str : lines) {
dt.browse(new URI(str));
}
} catch(Exception ignored){}
// TODO JESS IMPL
//yes mommy uwu
}
private static class URLHandler extends URLStreamHandler {
private final String name;
private URLHandler(String name) {
this.name = name;
}
@Override
protected URLConnection openConnection(URL u) throws IOException {
return new ResourceConnection(u, name);
}
}
private static class ResourceConnection extends URLConnection {
private final String name;
protected ResourceConnection(URL url, String name) {
super(url);
this.name = name;
}
@Override
public void connect() throws IOException {
}
@Override
public InputStream getInputStream() throws IOException {
final byte[][] data = {null};
encryptedResources.access(x -> data[0] = x.getValue().get(name));
return new ByteArrayInputStream(data[0]);
}
@Override
public OutputStream getOutputStream() throws IOException {
throw new Error("This person tried to output to a resource! Laugh at this user!!!");
}
}
private static class CustomMixinServer extends MixinServiceLaunchWrapper {
private CustomMixinServer() {}

View file

@ -44,8 +44,10 @@ public class Loader {
public static final Strictness defaultStrictness;
public static final DataKeeper<PermissionManager> permissionManager;
public static final PermissionManager dynamicPermissionManager = new DynamicPermissionManager();
private static final boolean dump;
static {
dump = dumpDetected();
defaultStrictness = init1();
permissionManager = init2();
}
@ -78,8 +80,6 @@ public class Loader {
public static void initiate() {
boolean dump = dumpDetected();
classKey = new DataKeeper<>(getPermissionManager() /*atm this is the CallClass-only one*/, defaultStrictness, new Key());
objectKey = new DataKeeper<>(dynamicPermissionManager, defaultStrictness, new Key());
@ -247,7 +247,7 @@ public class Loader {
}
if (!resources.isEmpty()) {
/*if (!resources.isEmpty()) {
try {
File tempFile = File.createTempFile("resources" + System.currentTimeMillis(), ".jar");
FileOutputStream fos = new FileOutputStream(tempFile);
@ -266,9 +266,9 @@ public class Loader {
} catch (Exception e) {
e.printStackTrace();
}
}
}*/
CustomClassloader customCL = new CustomClassloader(classCache);
CustomClassloader customCL = new CustomClassloader(classCache, resources);
permissionManager.access(x -> x.setValue(
new HideErrorRestriction(
new BBPermissionManager(

View file

@ -64,11 +64,10 @@ public class BBPermissionManager extends Restriction {
@Override
public boolean checkCaller(Strictness strictnessLevel) {
/*if(!(System.getSecurityManager() instanceof BaseBandSecurityManager)) {
if(!(System.getSecurityManager() instanceof BaseBandSecurityManager)) {
System.out.println("No security?");
return false;
}
*/
//// TudbuT // Are you sure this is this a good idea? it will be called a LOT.