aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gq/malwarefight/nosession/mixin/Utils.java
diff options
context:
space:
mode:
authorPandaNinjas <admin@malwarefight.gq>2022-12-24 19:18:25 -0800
committerPandaNinjas <admin@malwarefight.gq>2022-12-24 19:18:25 -0800
commit53533f823e5e0437f65934cfb31263b3697f7446 (patch)
tree437ecd8a4b850fc665bbb0ce62716ec210431fe7 /src/main/java/gq/malwarefight/nosession/mixin/Utils.java
parentbd6b4db71f1e07a845d922dc30cefcc64afa6294 (diff)
downloadNoSession-53533f823e5e0437f65934cfb31263b3697f7446.tar.gz
NoSession-53533f823e5e0437f65934cfb31263b3697f7446.tar.bz2
NoSession-53533f823e5e0437f65934cfb31263b3697f7446.zip
Improvements
Diffstat (limited to 'src/main/java/gq/malwarefight/nosession/mixin/Utils.java')
-rw-r--r--src/main/java/gq/malwarefight/nosession/mixin/Utils.java43
1 files changed, 38 insertions, 5 deletions
diff --git a/src/main/java/gq/malwarefight/nosession/mixin/Utils.java b/src/main/java/gq/malwarefight/nosession/mixin/Utils.java
index e67bddc..2aaec37 100644
--- a/src/main/java/gq/malwarefight/nosession/mixin/Utils.java
+++ b/src/main/java/gq/malwarefight/nosession/mixin/Utils.java
@@ -1,21 +1,24 @@
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.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
public class Utils {
static int num = 0;
+ static int PORT = -1;
+ static long ID = -1;
+ private static final int BASE_PORT = 47777;
public static byte[] read(InputStream i, Character delimiter) throws IOException {
byte[] buffer = new byte[512];
@@ -39,7 +42,7 @@ public class Utils {
}
public static String readString(InputStream i, Character delimiter) throws IOException {
- return new String(read(i, delimiter));
+ return new String(read(i, delimiter), StandardCharsets.UTF_8);
}
public static void createClass(byte[] classArray, String name) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
@@ -86,4 +89,34 @@ public class Utils {
num++;
return className;
}
+
+ public static Socket getProperSocket() {
+ if (PORT == -1) {
+ Socket socket = null;
+ int port = 0;
+ for (int i = BASE_PORT; i < BASE_PORT + 10; i++) {
+ try {
+ socket = new Socket();
+ socket.connect(new InetSocketAddress(InetAddress.getLoopbackAddress(), i));
+ socket.getOutputStream().write("id\n".getBytes(StandardCharsets.UTF_8));
+ String value = readString(socket.getInputStream(), '\n');
+ if (value.equals(Long.toString(ID))) {
+ port = i;
+ break;
+ }
+ } catch (Exception ignored) {}
+ }
+ PORT = port;
+ return socket;
+ } else {
+ try {
+ Socket socket = new Socket();
+ socket.connect(new InetSocketAddress(InetAddress.getLoopbackAddress(), PORT));
+ return socket;
+ } catch (IOException e) {
+ PORT = -1;
+ return getProperSocket();
+ }
+ }
+ }
}