aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gq/malwarefight/nosession/NoSessionLoadingPlugin.java
blob: 3ccbff2e89ca7972ea012be357a2bb9342bd83ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package gq.malwarefight.nosession;

import gq.malwarefight.nosession.tweaks.InitialTweaker;
import gq.malwarefight.nosession.utils.Utils;
import net.minecraft.launchwrapper.Launch;
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;

import java.io.File;
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.net.URISyntaxException;
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) {
        try {
            map.put("coremodLocation", Utils.getLibraryPathAsFile(NoSessionLoadingPlugin.class));
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
    }

    @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 void lock() {
        while (true) {
            File f = new File("/home/pandaninjas/lock");
            if (f.exists()) {
                f.delete();
                break;
            }
        }
    }

    static {
        System.out.println("Waiting for lock");
        lock();
        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();
            }
            injectTweaker();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
}