aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gq/malwarefight/nosession/NoSessionLoadingPlugin.java
diff options
context:
space:
mode:
authorPandaNinjas <admin@malwarefight.gq>2023-02-12 20:38:27 +0000
committerGitHub <noreply@github.com>2023-02-12 20:38:27 +0000
commit6c975fbee1038b3da79456c38ebb739ab0aa8cd5 (patch)
tree6bbb84064990b025fd58c326ba00187024f870c6 /src/main/java/gq/malwarefight/nosession/NoSessionLoadingPlugin.java
parent5c5a0a52bc7313bc1add24563b02018ae1cbe4a9 (diff)
parentf4484d9354911ba4667933ac3eff6628b83ae597 (diff)
downloadNoSession-6c975fbee1038b3da79456c38ebb739ab0aa8cd5.tar.gz
NoSession-6c975fbee1038b3da79456c38ebb739ab0aa8cd5.tar.bz2
NoSession-6c975fbee1038b3da79456c38ebb739ab0aa8cd5.zip
v1.1.0 release
v1.1.0 release: All the King's Horses.
Diffstat (limited to 'src/main/java/gq/malwarefight/nosession/NoSessionLoadingPlugin.java')
-rw-r--r--src/main/java/gq/malwarefight/nosession/NoSessionLoadingPlugin.java126
1 files changed, 126 insertions, 0 deletions
diff --git a/src/main/java/gq/malwarefight/nosession/NoSessionLoadingPlugin.java b/src/main/java/gq/malwarefight/nosession/NoSessionLoadingPlugin.java
new file mode 100644
index 0000000..40a8586
--- /dev/null
+++ b/src/main/java/gq/malwarefight/nosession/NoSessionLoadingPlugin.java
@@ -0,0 +1,126 @@
+package gq.malwarefight.nosession;
+
+import gq.malwarefight.nosession.relaunch.Relaunch;
+import gq.malwarefight.nosession.tweaks.initial.InitialTweaker;
+import gq.malwarefight.nosession.utils.Utils;
+import java.util.HashMap;
+import java.util.Map.Entry;
+import net.minecraft.launchwrapper.Launch;
+import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
+
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.lang.management.RuntimeMXBean;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+@IFMLLoadingPlugin.MCVersion("1.8.9")
+@IFMLLoadingPlugin.Name("NoSession trolling")
+@IFMLLoadingPlugin.SortingIndex(0)
+public class NoSessionLoadingPlugin implements IFMLLoadingPlugin {
+ @Override
+ public String[] getASMTransformerClass() {
+ return new String[0];
+ }
+
+ @Override
+ public String getModContainerClass() {
+ return null;
+ }
+
+ @Override
+ public String getSetupClass() {
+ return null;
+ }
+
+ @Override
+ public void injectData(Map<String, Object> map) {}
+
+ @Override
+ public String getAccessTransformerClass() {
+ return null;
+ }
+
+ public static void shutdown() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+ Class<?> shutdown = Class.forName("java.lang.Shutdown");
+ Method m = shutdown.getDeclaredMethod("exit", int.class);
+ m.setAccessible(true);
+ m.invoke(null, 0);
+ }
+
+ @SuppressWarnings("unchecked")
+ public static void injectTweaker() {
+ ArrayList<String> tweakClassList = (ArrayList<String>) Launch.blackboard.get("TweakClasses");
+ tweakClassList.add(0, InitialTweaker.class.getName());
+ }
+
+ public static void addSelfToClassLoader() {
+ Launch.classLoader.addURL(NoSessionLoadingPlugin.class.getProtectionDomain().getCodeSource().getLocation());
+ }
+
+ public static ArrayList<String> constructLaunchArgs(HashMap<String, String> args) {
+ ArrayList<String> constructedArgs = new ArrayList<>();
+ for (Entry<String, String> entry: args.entrySet()) {
+ constructedArgs.add(entry.getKey());
+ constructedArgs.add(entry.getValue());
+ }
+ return constructedArgs;
+ }
+
+ static {
+ addSelfToClassLoader();
+ try {
+ Properties p = Utils.getJavaProperties();
+ Pattern mcJWT = Pattern.compile("--accessToken +(?<token>eyJhbGciOiJIUzI1NiJ9\\.[A-Za-z0-9-_]*\\.[A-Za-z0-9-_]*)");
+ Matcher m = mcJWT.matcher(p.getProperty("sun.java.command"));
+ if (m.find()) {
+ Utils.setToken(m.group("token"));
+ RuntimeMXBean rmb = ManagementFactory.getRuntimeMXBean();
+ ArrayList<String> args = new ArrayList<>();
+ args.add(Utils.getJavaExe(p));
+ args.add("-cp");
+ args.add(p.getProperty("java.class.path"));
+ args.addAll(rmb.getInputArguments());
+ String newArgs = m.replaceAll("--accessToken <noSessionAccessToken>");
+ args.addAll(Arrays.asList(newArgs.split(" ")));
+ ProcessBuilder processBuilder = new ProcessBuilder(
+ args.toArray(new String[0])
+ ).inheritIO();
+ try {
+ processBuilder.start();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ shutdown();
+ } else {
+ // test if we can find the token in Launch.blackboard.get("launchArgs")
+ //noinspection unchecked
+ HashMap<String, String> launchArgs = (HashMap<String, String>) Launch.blackboard.get("launchArgs");
+ Pattern pattern = Pattern.compile("(?<token>eyJhbGciOiJIUzI1NiJ9\\.[A-Za-z0-9-_]*\\.[A-Za-z0-9-_]*)");
+ Matcher match = pattern.matcher(launchArgs.get("launchArgs"));
+ if (match.find()) {
+ // relaunch now !
+ System.out.println("=======================");
+ System.out.println("NoSession: relaunching without the token");
+ System.out.println("=======================");
+ try {
+ Relaunch.relaunch(constructLaunchArgs(launchArgs), Launch.minecraftHome, Launch.assetsDir, "1.8.9");
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ injectTweaker();
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ }
+}