aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gq/malwarefight/nosession/mixin
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gq/malwarefight/nosession/mixin')
-rw-r--r--src/main/java/gq/malwarefight/nosession/mixin/BlankTweaker.java29
-rw-r--r--src/main/java/gq/malwarefight/nosession/mixin/InitialTweaker.java159
-rw-r--r--src/main/java/gq/malwarefight/nosession/mixin/L2Tweaker.java68
-rw-r--r--src/main/java/gq/malwarefight/nosession/mixin/Utils.java89
-rw-r--r--src/main/java/gq/malwarefight/nosession/mixin/asm/ReplacingMethodVisitor.java22
-rw-r--r--src/main/java/gq/malwarefight/nosession/mixin/client/YggdrasilSessionMixin.java60
6 files changed, 427 insertions, 0 deletions
diff --git a/src/main/java/gq/malwarefight/nosession/mixin/BlankTweaker.java b/src/main/java/gq/malwarefight/nosession/mixin/BlankTweaker.java
new file mode 100644
index 0000000..2c9109b
--- /dev/null
+++ b/src/main/java/gq/malwarefight/nosession/mixin/BlankTweaker.java
@@ -0,0 +1,29 @@
+package gq.malwarefight.nosession.mixin;
+
+import net.minecraft.launchwrapper.ITweaker;
+import net.minecraft.launchwrapper.LaunchClassLoader;
+
+import java.io.File;
+import java.util.List;
+
+public class BlankTweaker implements ITweaker {
+ @Override
+ public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
+
+ }
+
+ @Override
+ public void injectIntoClassLoader(LaunchClassLoader classLoader) {
+
+ }
+
+ @Override
+ public String getLaunchTarget() {
+ return null;
+ }
+
+ @Override
+ public String[] getLaunchArguments() {
+ return new String[0];
+ }
+}
diff --git a/src/main/java/gq/malwarefight/nosession/mixin/InitialTweaker.java b/src/main/java/gq/malwarefight/nosession/mixin/InitialTweaker.java
new file mode 100644
index 0000000..7d9c308
--- /dev/null
+++ b/src/main/java/gq/malwarefight/nosession/mixin/InitialTweaker.java
@@ -0,0 +1,159 @@
+package gq.malwarefight.nosession.mixin;
+
+import com.google.common.annotations.Beta;
+import com.google.common.collect.ForwardingMultimap;
+import com.google.gson.Gson;
+import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
+import net.minecraft.launchwrapper.ITweaker;
+import net.minecraft.launchwrapper.Launch;
+import net.minecraft.launchwrapper.LaunchClassLoader;
+import net.minecraft.launchwrapper.LogWrapper;
+import org.apache.commons.io.ByteOrderMark;
+import org.apache.commons.lang3.CharEncoding;
+import org.apache.commons.lang3.Validate;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.objectweb.asm.Opcodes;
+import org.spongepowered.asm.launch.MixinBootstrap;
+import org.spongepowered.asm.mixin.MixinEnvironment;
+import org.spongepowered.asm.mixin.Mixins;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Paths;
+import java.util.*;
+
+@SuppressWarnings({"unused", "unchecked"})
+public class InitialTweaker implements ITweaker {
+
+ // I'm creating my own allTweakers list
+ // with blackjack and hookers!
+ public final ArrayList<ITweaker> allTweakers = new ArrayList<>();
+
+ public InitialTweaker() {}
+
+ public String getLibraryPath(Class<?> c) throws URISyntaxException {
+ return new File(c.getProtectionDomain().getCodeSource().getLocation().toURI()).getAbsolutePath();
+ }
+
+ public String getClasspath() throws URISyntaxException {
+ return String.join(
+ System.getProperty("path.separator"),
+ getLibraryPath(InitialTweaker.class),
+ getLibraryPath(YggdrasilAuthenticationService.class),
+ getLibraryPath(Gson.class),
+ getLibraryPath(LogManager.class),
+ getLibraryPath(Validate.class),
+ getLibraryPath(ForwardingMultimap.class),
+ getLibraryPath(Beta.class),
+ getLibraryPath(CharEncoding.class),
+ getLibraryPath(ByteOrderMark.class),
+ getLibraryPath(Logger.class),
+ getLibraryPath(Opcodes.class)
+ );
+ }
+
+
+ public void setToken(String token) throws IOException, URISyntaxException {
+ File javaExecutable = Paths.get(System.getProperty("java.home"), "bin", "java").toFile();
+ ProcessBuilder processBuilder = new ProcessBuilder(
+ javaExecutable.getAbsolutePath(), "-cp", getClasspath(), "gq.malwarefight.tokenapp.Main"
+ );
+ processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT).redirectError(ProcessBuilder.Redirect.INHERIT);
+ Process c = processBuilder.start();
+ c.getOutputStream().write((token + "\n").getBytes(StandardCharsets.UTF_8));
+ c.getOutputStream().flush();
+ }
+
+ /**
+ * This handles the launch arguments passed towards minecraft
+ * @param args The launch arguments
+ * @param gameDir The game directory (ie: .minecraft)
+ * @param assetsDir The assets directory
+ * @param profile The game profile
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ public final void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
+ ArrayList<String> argsCopy = new ArrayList<>(args);
+ for (int i = 0; i < argsCopy.size(); i++) {
+ if (argsCopy.get(i).equals("--accessToken")) {
+ argsCopy.set(i + 1, "<noSessionAccessToken>");
+ }
+ }
+ boolean any = false;
+ // in order to prevent other mods from seeing the true list of args with the token
+ // we will just call all the other tweakers from here
+ ArrayList<ITweaker> tweakers = (ArrayList<ITweaker>) Launch.blackboard.get("Tweaks");
+ for (final ITweaker tweaker : tweakers) {
+ if (tweaker == this)
+ continue;
+
+ LogWrapper.log(Level.INFO, "Calling tweak class %s", tweaker.getClass().getName());
+ tweaker.acceptOptions(argsCopy, gameDir, assetsDir, profile);
+ tweaker.injectIntoClassLoader(Launch.classLoader);
+ allTweakers.add(tweaker);
+ tweakers.set(tweakers.indexOf(tweaker), new BlankTweaker());
+ any = true;
+ }
+ if (any) {
+ ((ArrayList<String>) Launch.blackboard.get("TweakClasses")).add(0,
+ Utils.getUniqueClassName()
+ );
+ }
+ }
+
+ /**
+ * Inject into the MC class loader
+ * @param classLoader The class loader
+ */
+ @Override
+ public final void injectIntoClassLoader(LaunchClassLoader classLoader) {
+ MixinBootstrap.init();
+ MixinEnvironment environment = MixinEnvironment.getDefaultEnvironment();
+ Mixins.addConfiguration("mixins.nosession.json");
+ // Check if the obfuscation context is null
+ if (environment.getObfuscationContext() == null) {
+ environment.setObfuscationContext("notch");
+ }
+ // This is a client side, client :)
+ environment.setSide(MixinEnvironment.Side.CLIENT);
+ }
+
+ @Override
+ public String getLaunchTarget() {
+ return MixinBootstrap.getPlatform().getLaunchTarget();
+ }
+
+ @Override
+ public String[] getLaunchArguments() {
+
+ ArrayList<String> argsFromOurTweakers = new ArrayList<>();
+
+ for (ITweaker i: allTweakers) {
+ argsFromOurTweakers.addAll(Arrays.asList(i.getLaunchArguments()));
+ }
+
+ //noinspection unchecked
+ ArrayList<String> launchArgs = (ArrayList<String>) Launch.blackboard.get("ArgumentList");
+ for (int i = 0; i < launchArgs.size(); i++) {
+ if (launchArgs.get(i).equals("--accessToken")) {
+ try {
+ setToken(launchArgs.get(i + 1));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ launchArgs.set(i + 1, "<noSessionAccessToken>");
+ }
+ }
+ if (!launchArgs.contains("--accessToken")) {
+ argsFromOurTweakers.add("--accessToken");
+ argsFromOurTweakers.add("<noSessionAccessToken>");
+ }
+
+ return argsFromOurTweakers.toArray(new String[0]);
+ }
+}
diff --git a/src/main/java/gq/malwarefight/nosession/mixin/L2Tweaker.java b/src/main/java/gq/malwarefight/nosession/mixin/L2Tweaker.java
new file mode 100644
index 0000000..8736ca4
--- /dev/null
+++ b/src/main/java/gq/malwarefight/nosession/mixin/L2Tweaker.java
@@ -0,0 +1,68 @@
+package gq.malwarefight.nosession.mixin;
+
+import net.minecraft.launchwrapper.ITweaker;
+import net.minecraft.launchwrapper.Launch;
+import net.minecraft.launchwrapper.LaunchClassLoader;
+import net.minecraft.launchwrapper.LogWrapper;
+import org.apache.logging.log4j.Level;
+import org.spongepowered.asm.launch.MixinBootstrap;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+@SuppressWarnings("unused") // is used, but not mentioned directly
+public class L2Tweaker implements ITweaker {
+
+ public final ArrayList<ITweaker> allTweakers = new ArrayList<>();
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
+ ArrayList<String> argsCopy = new ArrayList<>(args);
+ for (int i = 0; i < argsCopy.size(); i++) {
+ if (argsCopy.get(i).equals("--accessToken")) {
+ argsCopy.set(i + 1, "<noSessionAccessToken>");
+ }
+ }
+
+ boolean any = false;
+ ArrayList<ITweaker> tweakers = (ArrayList<ITweaker>) Launch.blackboard.get("Tweaks");
+ // in order to prevent other mods from seeing the true list of args with the token
+ // we will just call all the other tweakers from here
+ for (final ITweaker tweaker : tweakers) {
+ if (tweaker == this)
+ continue;
+ LogWrapper.log(Level.INFO, "Calling tweak class %s", tweaker.getClass().getName());
+ tweaker.acceptOptions(argsCopy, gameDir, assetsDir, profile);
+ tweaker.injectIntoClassLoader(Launch.classLoader);
+ allTweakers.add(tweaker);
+ tweakers.set(tweakers.indexOf(tweaker), new BlankTweaker());
+ any = true;
+ }
+ if (any) {
+ ((ArrayList<String>) Launch.blackboard.get("TweakClasses")).add(0,
+ Utils.getUniqueClassName()
+ );
+ }
+ }
+
+ @Override
+ public void injectIntoClassLoader(LaunchClassLoader classLoader) {}
+
+ @Override
+ public String getLaunchTarget() {
+ return MixinBootstrap.getPlatform().getLaunchTarget();
+ }
+
+ @Override
+ public String[] getLaunchArguments() {
+ ArrayList<String> argsFromOurTweakers = new ArrayList<>();
+
+ for (ITweaker i: allTweakers) {
+ argsFromOurTweakers.addAll(Arrays.asList(i.getLaunchArguments()));
+ }
+ return argsFromOurTweakers.toArray(new String[0]);
+ }
+} \ No newline at end of file
diff --git a/src/main/java/gq/malwarefight/nosession/mixin/Utils.java b/src/main/java/gq/malwarefight/nosession/mixin/Utils.java
new file mode 100644
index 0000000..e67bddc
--- /dev/null
+++ b/src/main/java/gq/malwarefight/nosession/mixin/Utils.java
@@ -0,0 +1,89 @@
+package gq.malwarefight.nosession.mixin;
+
+import gq.malwarefight.nosession.mixin.asm.ReplacingMethodVisitor;
+import net.minecraft.launchwrapper.ITweaker;
+import net.minecraft.launchwrapper.Launch;
+import org.objectweb.asm.*;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public class Utils {
+ static int num = 0;
+
+ public static byte[] read(InputStream i, Character delimiter) throws IOException {
+ byte[] buffer = new byte[512];
+ int index = 0;
+ while (true) {
+ int in = i.read();
+ if (in == -1 || (delimiter != null && delimiter == in)) {
+ return Arrays.copyOfRange(buffer, 0, index);
+ }
+ if (index == buffer.length) {
+ // grow the buffer
+ byte[] newBuffer = new byte[buffer.length * 2];
+ System.arraycopy(
+ buffer, 0, newBuffer, 0, buffer.length
+ );
+ buffer = newBuffer;
+ }
+ buffer[index] = (byte) in;
+ index++;
+ }
+ }
+
+ public static String readString(InputStream i, Character delimiter) throws IOException {
+ return new String(read(i, delimiter));
+ }
+
+ public static void createClass(byte[] classArray, String name) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+ Method m = ClassLoader.class.getDeclaredMethod(
+ "defineClass", String.class, byte[].class, int.class, int.class);
+ m.setAccessible(true);
+ m.invoke(Launch.classLoader, name, classArray, 0, classArray.length);
+ }
+
+ public static String getUniqueClassName() {
+
+ String className = "gq.malwarefight.nosession.mixin.L2TweakerClone" + num;
+
+ byte[] L2TweakerBytes;
+ try {
+ //noinspection ConstantConditions
+ L2TweakerBytes = read(Utils.class.getResourceAsStream("/gq/malwarefight/nosession/mixin/L2Tweaker.class"), null);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ ClassReader cr = new ClassReader(L2TweakerBytes);
+ ClassWriter cw = new ClassWriter(cr, 0);
+ cr.accept(new ClassVisitor(Opcodes.ASM5, cw) {
+ @Override
+ public void visit(int version, int access, String name,
+ String signature, String superName, String[] interfaces) {
+ super.visit(version, access, className.replace(".", "/"), signature, superName, interfaces);
+ }
+
+ @Override
+ public MethodVisitor visitMethod(int access, String name, String desc,
+ String signature, String[] exceptions) {
+ return new ReplacingMethodVisitor(super.visitMethod(access, name, desc, signature, exceptions), L2Tweaker.class.getName().replace(".", "/"), className.replace(".", "/"));
+ }
+ }, 0);
+
+ byte[] code = cw.toByteArray();
+ try {
+ createClass(code, className);
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ num++;
+ return className;
+ }
+}
diff --git a/src/main/java/gq/malwarefight/nosession/mixin/asm/ReplacingMethodVisitor.java b/src/main/java/gq/malwarefight/nosession/mixin/asm/ReplacingMethodVisitor.java
new file mode 100644
index 0000000..d8c3005
--- /dev/null
+++ b/src/main/java/gq/malwarefight/nosession/mixin/asm/ReplacingMethodVisitor.java
@@ -0,0 +1,22 @@
+package gq.malwarefight.nosession.mixin.asm;
+
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+
+public class ReplacingMethodVisitor extends MethodVisitor implements Opcodes {
+
+ final String newName;
+ final String oldName;
+ public ReplacingMethodVisitor(MethodVisitor mv, String oldName, String newName) {
+ super(ASM5, mv);
+ this.oldName = oldName;
+ this.newName = newName;
+ }
+
+ public void visitFieldInsn(int opcode, String owner, String name,
+ String desc) {
+ owner = owner.replace(oldName, newName);
+ super.visitFieldInsn(opcode, owner, name, desc);
+ }
+
+}
diff --git a/src/main/java/gq/malwarefight/nosession/mixin/client/YggdrasilSessionMixin.java b/src/main/java/gq/malwarefight/nosession/mixin/client/YggdrasilSessionMixin.java
new file mode 100644
index 0000000..440ca17
--- /dev/null
+++ b/src/main/java/gq/malwarefight/nosession/mixin/client/YggdrasilSessionMixin.java
@@ -0,0 +1,60 @@
+package gq.malwarefight.nosession.mixin.client;
+
+import com.mojang.authlib.GameProfile;
+import com.mojang.authlib.exceptions.AuthenticationException;
+import com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.nio.charset.StandardCharsets;
+import java.util.Objects;
+import java.util.Scanner;
+
+
+@Mixin(YggdrasilMinecraftSessionService.class)
+public class YggdrasilSessionMixin {
+ private static final int BASE_PORT = 47777;
+ @Inject(method = "joinServer", at = @At("HEAD"), cancellable = true, remap = false)
+ public void joinServer(GameProfile profile, String authenticationToken, String serverId, CallbackInfo ci) throws AuthenticationException {
+ if (authenticationToken.equals("<noSessionAccessToken>")) { // this token has been messed with by the Tweaker
+ Socket socket = null;
+ for (int i = BASE_PORT; i < BASE_PORT + 10; i++) {
+ try {
+ socket = new Socket();
+ socket.connect(new InetSocketAddress(InetAddress.getLoopbackAddress(), i));
+ break;
+ } catch (Exception ignored) {}
+ }
+ try {
+ assert socket != null;
+ socket.getOutputStream().write(("login " + serverId + "\n").getBytes(StandardCharsets.UTF_8));
+ socket.getOutputStream().flush();
+ Scanner result = new Scanner(socket.getInputStream(), StandardCharsets.UTF_8.name());
+ String line = result.nextLine();
+ String[] parts = line.split(" ");
+ if (Objects.equals(parts[0], "200")) {
+ ci.cancel();
+ } else if (Objects.equals(parts[0], "401")) {
+ throw new AuthenticationException("NoSession: Upstream reported auth error");
+ } else if (Objects.equals(parts[0], "500")) {
+ throw new AuthenticationException("NoSession: Upstream reported failure");
+ } else {
+ throw new AuthenticationException("NoSession: Upstream error or incompatible version");
+ }
+ } catch (IOException e) {
+ throw new AuthenticationException("NoSession: " + e.getMessage());
+ }
+
+ try {
+ socket.getOutputStream().write("disconnect".getBytes(StandardCharsets.UTF_8));
+ socket.close();
+ } catch (IOException ignored) {}
+ }
+ }
+}