aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gq/malwarefight/nosession/utils/Utils.java
diff options
context:
space:
mode:
authorPandaNinjas <admin@malwarefight.gq>2023-05-19 17:15:46 -0400
committerPandaNinjas <admin@malwarefight.gq>2023-05-19 17:15:46 -0400
commitd30a5775fab3f4e8968e4066a5e59a4b953d8870 (patch)
treeb530ea31755685193192230f5e570947caf2cba1 /src/main/java/gq/malwarefight/nosession/utils/Utils.java
parentca67ac4481ce308d42ab33defdee2e54e2ca82ab (diff)
downloadNoSession-d30a5775fab3f4e8968e4066a5e59a4b953d8870.tar.gz
NoSession-d30a5775fab3f4e8968e4066a5e59a4b953d8870.tar.bz2
NoSession-d30a5775fab3f4e8968e4066a5e59a4b953d8870.zip
stuff
Diffstat (limited to 'src/main/java/gq/malwarefight/nosession/utils/Utils.java')
-rw-r--r--src/main/java/gq/malwarefight/nosession/utils/Utils.java57
1 files changed, 31 insertions, 26 deletions
diff --git a/src/main/java/gq/malwarefight/nosession/utils/Utils.java b/src/main/java/gq/malwarefight/nosession/utils/Utils.java
index b34c0aa..d26d6f2 100644
--- a/src/main/java/gq/malwarefight/nosession/utils/Utils.java
+++ b/src/main/java/gq/malwarefight/nosession/utils/Utils.java
@@ -4,6 +4,7 @@ import com.google.common.annotations.Beta;
import com.google.common.collect.ForwardingMultimap;
import com.google.gson.Gson;
import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
+import gq.malwarefight.nosession.linux.libc.Libc;
import gq.malwarefight.tokenapp.Main;
import org.apache.commons.io.ByteOrderMark;
import org.apache.commons.lang3.CharEncoding;
@@ -13,27 +14,33 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.Opcodes;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.net.URISyntaxException;
+import java.net.*;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
-import java.util.Properties;
+import java.util.Scanner;
import java.util.UUID;
public class Utils {
public static int PORT = -1;
private static final int BASE_PORT = 47777;
+ public static void copy(InputStream i, OutputStream o) throws IOException {
+ byte[] buffer = new byte[16384];
+ int read;
+ while ((read = i.read(buffer)) > 0) {
+ o.write(buffer, 0, read);
+ }
+ i.close();
+ o.close();
+ }
+
public static byte[] read(InputStream i, Character delimiter) throws IOException {
byte[] buffer = new byte[512];
int index = 0;
@@ -112,7 +119,7 @@ public class Utils {
public static String processString(String uri) {
try {
- return uri.substring(uri.indexOf('/'), uri.lastIndexOf('!'));
+ return uri.substring(uri.indexOf(":") + 1, uri.lastIndexOf('!'));
} catch (Exception e) {
e.printStackTrace();
return uri;
@@ -124,16 +131,16 @@ public class Utils {
if (uri.endsWith(".class")) {
uri = processString(uri); // stupid reference to a class within a jar
}
- return new File(uri);
+ return new File(new URI(uri));
}
public static String getLibraryPath(Class<?> c) throws URISyntaxException {
return getLibraryPathAsFile(c).getAbsolutePath();
}
- private static String getClasspath(Properties p) throws URISyntaxException {
+ private static String getClasspath() throws URISyntaxException {
return String.join(
- p.getProperty("path.separator"),
+ System.getProperty("path.separator"),
getLibraryPath(Main.class),
getLibraryPath(YggdrasilAuthenticationService.class),
getLibraryPath(Gson.class),
@@ -148,23 +155,15 @@ public class Utils {
);
}
- public static Properties getJavaProperties() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
- Properties p = new Properties();
- Method m = System.class.getDeclaredMethod("initProperties", Properties.class);
- m.setAccessible(true);
- m.invoke(null, p);
- return p;
- }
-
/**
* Gets the java exe path
* @return the exe path
*/
- public static String getJavaExe(Properties p) {
+ public static String getJavaExe() {
try {
return Paths.get(String.join(
- p.getProperty("file.separator"),
- p.getProperty("java.home"),
+ System.getProperty("file.separator"),
+ System.getProperty("java.home"),
"bin",
"java" + (SystemUtils.IS_OS_WINDOWS ? ".exe" : "")
)).toFile().getAbsolutePath();
@@ -173,14 +172,20 @@ public class Utils {
}
}
- public static void setToken(String token) throws IOException, InvocationTargetException, NoSuchMethodException, IllegalAccessException, URISyntaxException {
- Properties p = getJavaProperties();
+ public static void setToken(String token) throws IOException, URISyntaxException {
ProcessBuilder processBuilder = new ProcessBuilder(
- getJavaExe(p), "-cp", getClasspath(p), Main.class.getName()
+ getJavaExe(), "-cp", getClasspath(), Main.class.getName()
);
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();
}
+ 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);
+ }
+
}