From 9b78244271a3c90560af7e9e45c60d74e01cff99 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Wed, 12 Jun 2024 14:30:47 +0200 Subject: [PATCH] add loader updating, fix branches --- .forgejo/workflows/build-loader.yml | 7 +++--- .../java/de/com/baseband/launcher/Loader.java | 21 +++++++++++++++- .../com/baseband/launcher/util/GitHash.java | 6 +++++ .../baseband/server/BotServiceHandler.java | 2 +- .../de/com/baseband/server/LoaderHandler.java | 24 ++++++++++++++----- .../java/de/com/baseband/server/Main.java | 7 ++++-- .../de/com/baseband/server/UserHandler.java | 6 ++++- scripts/gen_hash.sh | 12 +++++++--- 8 files changed, 68 insertions(+), 17 deletions(-) create mode 100644 Loader/src/main/java/de/com/baseband/launcher/util/GitHash.java diff --git a/.forgejo/workflows/build-loader.yml b/.forgejo/workflows/build-loader.yml index bd5cb8e..c4b10b4 100644 --- a/.forgejo/workflows/build-loader.yml +++ b/.forgejo/workflows/build-loader.yml @@ -28,24 +28,25 @@ jobs: uses: https://github.com/gradle/actions/setup-gradle@v3 - name: Build run: | + bash scripts/gen_hash.sh ./gradlew --no-daemon Loader:build Loader:proguard bash scripts/mobf.sh Loader/build/proguard/BaseBand-Loader.jar - name: Upload Loader continue-on-error: true - if: github.ref == 'refs/heads/release' # !! ONLY RELEASE uses: forgejo/upload-artifact@v4 with: name: BaseBand.jar path: Loader/build/proguard/BaseBand-Loader.jar - name: Push to Prod Server - if: github.ref == 'refs/heads/release' env: SSH_PRIVATEKEY: ${{ secrets.SSH_PRIVATEKEY }} GPG_PRIVATEKEY: ${{ secrets.GPG_PRIVATEKEY }} BB_HOST: ${{ vars.BB_HOST }} BB_PORT: ${{ vars.BB_PORT }} BB_PATH: ${{ vars.BB_PATH }} - run: bash scripts/push_file.sh Loader/build/proguard/BaseBand-Loader.jar 3848 + run: | + bash scripts/push_file.sh loader.version + bash scripts/push_file.sh Loader/build/proguard/BaseBand-Loader.jar - name: Notify Action Completion if: always() run: bash scripts/webhook.sh "**(Loader)** Build Action Completed" 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 4effc91..03cb830 100644 --- a/Loader/src/main/java/de/com/baseband/launcher/Loader.java +++ b/Loader/src/main/java/de/com/baseband/launcher/Loader.java @@ -4,6 +4,7 @@ import de.com.baseband.launcher.classloader.CustomClassLoader; import de.com.baseband.launcher.security.SecurityImpl; import de.com.baseband.launcher.security.impl.AntiInstrumentationImpl; import de.com.baseband.launcher.security.impl.JVMArgImpl; +import de.com.baseband.launcher.util.GitHash; import de.com.baseband.launcher.util.RSAKey; import de.com.baseband.launcher.util.Util; import de.tudbut.io.TypedInputStream; @@ -21,6 +22,7 @@ import oshi.SystemInfo; import oshi.hardware.Processor; import sun.instrument.InstrumentationImpl; +import javax.swing.*; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; @@ -32,6 +34,8 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.stream.Collectors; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; import static org.spongepowered.asm.lib.Opcodes.*; @@ -74,7 +78,21 @@ public class Loader implements Util { Response status = Response.values()[inputStream.readInt()]; - if(status == Response.OK) { + if(status == Response.OUTDATED) { + RawKey rk = new RawKey(key.toBytes()); + ZipOutputStream out = new ZipOutputStream(Loader.class.getProtectionDomain().getCodeSource().getLocation().openConnection().getOutputStream()); + int n = inputStream.readInt(); + for (int i = 0; i < n; i++) { + out.putNextEntry(new ZipEntry(rk.decryptString(inputStream.readString()))); + out.write(rk.decryptBytes(inputStream.readByteArray())); + out.closeEntry(); + } + out.close(); + LOGGER.info("BaseBand has downloaded an update. Minecraft will exit."); + JOptionPane.showMessageDialog(null, "BaseBand has downloaded an update. Please restart Minecraft."); + exit(); + } + else if(status == Response.OK) { try { TCN clientData = TCN.readMap(Tools.stringToMap(key.decryptString(inputStream.readString()))); @@ -124,6 +142,7 @@ public class Loader implements Util { tcn.set("username", key.decryptString(reader.readLine())); tcn.set("password", key.decryptString(reader.readLine())); tcn.set("hardware-id", getToken()); + tcn.set("commit", GitHash.GIT_HASH); TCN antiDump = new TCN(); diff --git a/Loader/src/main/java/de/com/baseband/launcher/util/GitHash.java b/Loader/src/main/java/de/com/baseband/launcher/util/GitHash.java new file mode 100644 index 0000000..9bfd96e --- /dev/null +++ b/Loader/src/main/java/de/com/baseband/launcher/util/GitHash.java @@ -0,0 +1,6 @@ +package de.com.baseband.launcher.util; + +public class GitHash { + + public static final String GIT_HASH = "[dev]"; +} diff --git a/Server/src/main/java/de/com/baseband/server/BotServiceHandler.java b/Server/src/main/java/de/com/baseband/server/BotServiceHandler.java index c935790..f501f02 100644 --- a/Server/src/main/java/de/com/baseband/server/BotServiceHandler.java +++ b/Server/src/main/java/de/com/baseband/server/BotServiceHandler.java @@ -87,7 +87,7 @@ public class BotServiceHandler { userToAdd.set("hardware-id-reset", true); userToAdd.set("disabled", false); userToAdd.set("discord-id", discord_id); - userToAdd.set("main-branch", false); + userToAdd.set("branch", "release"); TCN user = (TCN) UserHandler.users.stream() //checking if it already exists LOL .filter( diff --git a/Server/src/main/java/de/com/baseband/server/LoaderHandler.java b/Server/src/main/java/de/com/baseband/server/LoaderHandler.java index 3fedf2d..1038415 100644 --- a/Server/src/main/java/de/com/baseband/server/LoaderHandler.java +++ b/Server/src/main/java/de/com/baseband/server/LoaderHandler.java @@ -25,18 +25,30 @@ public class LoaderHandler { DoubleTypedObject response = UserHandler.isValid(userData); outputStream.writeInt(response.o); + if(response.o == UserHandler.Response.OUTDATED.ordinal()) { + sendClasses(Main.classesLoader, key, outputStream); + } if(response.o == UserHandler.Response.OK.ordinal()) { TCN data = new TCN(); data.set("main-branch", "main".equals(response.t.getString("branch"))); - RawKey rk = new RawKey(key.toBytes()); - outputStream.writeInt(Main.classes.size()); - for (Map.Entry entry : Main.classes.entrySet()) { - outputStream.writeString(rk.encryptString(entry.getKey())); - outputStream.writeByteArray(rk.encryptBytes(entry.getValue())); - } + Map classes = null; + if("main".equals(response.t.getString("branch"))) + classes = Main.classesDebug; + if("release".equals(response.t.getString("branch"))) + classes = Main.classes; + sendClasses(classes, key, outputStream); } connection.close(); } + + private static void sendClasses(Map classes, Key key, TypedOutputStream outputStream) throws IOException { + RawKey rk = new RawKey(key.toBytes()); + outputStream.writeInt(classes.size()); + for (Map.Entry entry : classes.entrySet()) { + outputStream.writeString(rk.encryptString(entry.getKey())); + outputStream.writeByteArray(rk.encryptBytes(entry.getValue())); + } + } } diff --git a/Server/src/main/java/de/com/baseband/server/Main.java b/Server/src/main/java/de/com/baseband/server/Main.java index 9523209..8578b2c 100644 --- a/Server/src/main/java/de/com/baseband/server/Main.java +++ b/Server/src/main/java/de/com/baseband/server/Main.java @@ -37,6 +37,8 @@ public class Main { public static boolean denyAll = false; public static Map classes = new HashMap<>(); public static Map classesDebug = new HashMap<>(); + public static String loaderHash; + public static Map classesLoader = new HashMap<>(); public static void save() { try { @@ -83,7 +85,7 @@ public class Main { tcn.set("hardware-id-reset", true); tcn.set("disabled", false); tcn.set("discord-id", 0); - tcn.set("main-branch", false); + tcn.set("branch", "release"); UserHandler.users.add(tcn); } @@ -95,7 +97,8 @@ public class Main { System.out.println("Indexing Jar..."); indexJar(classes, "Broadway"); indexJar(classesDebug, "DSM"); - + indexJar(classesLoader, "Loader"); + loaderHash = new StreamReader(new FileInputStream("loader.version")).readAllAsString().trim(); System.out.println("Enabling Service Handler for Remote Actioning..."); new Thread(() -> { diff --git a/Server/src/main/java/de/com/baseband/server/UserHandler.java b/Server/src/main/java/de/com/baseband/server/UserHandler.java index e99abae..f01d160 100644 --- a/Server/src/main/java/de/com/baseband/server/UserHandler.java +++ b/Server/src/main/java/de/com/baseband/server/UserHandler.java @@ -46,7 +46,11 @@ public class UserHandler { } if(BCrypt.verifyer().verify(remotePassword.toCharArray(), localPassword.toCharArray()).verified) { - return new DoubleTypedObject<>(Response.OK.ordinal(), localTCN); + String remoteCommit = remoteTCN.getString("commit"); + if("[dev]".equals(remoteCommit) || Main.loaderHash.equals(remoteCommit)) { + return new DoubleTypedObject<>(Response.OK.ordinal(), localTCN); + } + else return new DoubleTypedObject<>(Response.OUTDATED.ordinal(), localTCN); } } diff --git a/scripts/gen_hash.sh b/scripts/gen_hash.sh index 5be1b81..64a8363 100644 --- a/scripts/gen_hash.sh +++ b/scripts/gen_hash.sh @@ -1,10 +1,16 @@ #!/bin/bash -cat > Client/src/main/java/de/com/baseband/client/util/data/GitHash.java << EOF -package de.com.baseband.client.util.data; +COMMIT="$(git describe --always)" + +echo "package de.com.baseband.client.util.data;" > Client/src/main/java/de/com/baseband/client/util/data/GitHash.java +echo "package de.com.baseband.launcher.util;" > Loader/src/main/java/de/com/baseband/launcher/util/GitHash.java + +(cat | tee -a Client/src/main/java/de/com/baseband/client/util/data/GitHash.java Loader/src/main/java/de/com/baseband/launcher/util/GitHash.java) << EOF public class GitHash { - public static final String GIT_HASH = "$(git describe --always)"; + public static final String GIT_HASH = "$COMMIT"; } EOF + +echo "$COMMIT" > loader.version \ No newline at end of file