From fd51baf3f06141a151fde7ad1ecdd80b8093351f Mon Sep 17 00:00:00 2001 From: PandaNinjas Date: Wed, 1 Feb 2023 11:27:18 -0800 Subject: Amogus does not work --- .../gq/malwarefight/nosession/utils/Utils.java | 72 +++++++++++++--------- 1 file changed, 43 insertions(+), 29 deletions(-) (limited to 'src/main/java/gq/malwarefight/nosession/utils/Utils.java') diff --git a/src/main/java/gq/malwarefight/nosession/utils/Utils.java b/src/main/java/gq/malwarefight/nosession/utils/Utils.java index fbacb8f..ae0e273 100644 --- a/src/main/java/gq/malwarefight/nosession/utils/Utils.java +++ b/src/main/java/gq/malwarefight/nosession/utils/Utils.java @@ -109,43 +109,58 @@ public class Utils { f.set(null, value); } -// public static String processString(String s) { -// if (s.lastIndexOf("!") == -1) { -// return s; -// } -// } - - public static File getLibraryPathAsFile(Class c) throws URISyntaxException { - return new File(c.getProtectionDomain().getCodeSource().getLocation().getPath()); + public static String processString(String uri) { + try { + return uri.substring(uri.indexOf('/'), uri.lastIndexOf('!')); + } catch (Exception e) { + e.printStackTrace(); + return uri; + } } - public static String getLibraryPath(Class c) throws URISyntaxException { - - return getLibraryPathAsFile(c).getAbsolutePath(); + public static String getLibraryPath(Class c, boolean processString) throws URISyntaxException { + String uri = c.getProtectionDomain().getCodeSource().getLocation().toURI().toString(); + if (processString) { + uri = processString(uri); + } + return Paths.get(uri).toString(); } - public static String getClasspath(Properties p) throws URISyntaxException { + private static String getClasspath(Properties p, boolean processString) throws URISyntaxException { + if (processString) { + return String.join( + p.getProperty("path.separator"), + getLibraryPath(Utils.class, true), + getLibraryPath(YggdrasilAuthenticationService.class, true), + getLibraryPath(Gson.class, true), + getLibraryPath(LogManager.class, true), + getLibraryPath(Validate.class, true), + getLibraryPath(ForwardingMultimap.class, true), + getLibraryPath(Beta.class, true), + getLibraryPath(CharEncoding.class, true), + getLibraryPath(ByteOrderMark.class, true), + getLibraryPath(Logger.class, true), + getLibraryPath(Opcodes.class, true) + ); + } try { // try to be smart return String.join( p.getProperty("path.separator"), - getLibraryPath(Utils.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) + getLibraryPath(Utils.class, false), + getLibraryPath(YggdrasilAuthenticationService.class, false), + getLibraryPath(Gson.class, false), + getLibraryPath(LogManager.class, false), + getLibraryPath(Validate.class, false), + getLibraryPath(ForwardingMultimap.class, false), + getLibraryPath(Beta.class, false), + getLibraryPath(CharEncoding.class, false), + getLibraryPath(ByteOrderMark.class, false), + getLibraryPath(Logger.class, false), + getLibraryPath(Opcodes.class, false) ); } catch (URISyntaxException | IllegalArgumentException e) { - e.printStackTrace(); - // fallback to "dumb" method - RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); - return runtimeMXBean.getClassPath() + p.getProperty("path.separator") + getLibraryPath(Utils.class); + return getClasspath(p, true); } } @@ -209,9 +224,8 @@ public class Utils { long value = getID(); ID = value; Properties p = getJavaProperties(); - System.out.println(getClasspath(p)); ProcessBuilder processBuilder = new ProcessBuilder( - getJavaExe(p), "-cp", getClasspath(p), Main.class.getName(), Long.toString(value) + getJavaExe(p), "-cp", getClasspath(p, false), Main.class.getName(), Long.toString(value) ); processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT).redirectError(ProcessBuilder.Redirect.INHERIT); Process c = processBuilder.start(); -- cgit