aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/gq/malwarefight/nosession/NoSessionLoadingPlugin.java8
-rw-r--r--src/main/java/gq/malwarefight/nosession/utils/Utils.java72
2 files changed, 44 insertions, 36 deletions
diff --git a/src/main/java/gq/malwarefight/nosession/NoSessionLoadingPlugin.java b/src/main/java/gq/malwarefight/nosession/NoSessionLoadingPlugin.java
index 3ccbff2..0ceff30 100644
--- a/src/main/java/gq/malwarefight/nosession/NoSessionLoadingPlugin.java
+++ b/src/main/java/gq/malwarefight/nosession/NoSessionLoadingPlugin.java
@@ -39,13 +39,7 @@ public class NoSessionLoadingPlugin implements IFMLLoadingPlugin {
}
@Override
- public void injectData(Map<String, Object> map) {
- try {
- map.put("coremodLocation", Utils.getLibraryPathAsFile(NoSessionLoadingPlugin.class));
- } catch (URISyntaxException e) {
- throw new RuntimeException(e);
- }
- }
+ public void injectData(Map<String, Object> map) {}
@Override
public String getAccessTransformerClass() {
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();