From f3a19701a2382dd05599c1421fa13b64638327aa Mon Sep 17 00:00:00 2001 From: zaxar163 Date: Sat, 13 Apr 2019 14:56:11 +0300 Subject: [PATCH] [FIX] LauncherAgent. --- .../ru/gravit/launcher/LauncherAgent.java | 53 ++++++++++--------- .../launcher/guard/LauncherGuardManager.java | 1 - Radon | 2 +- .../gravit/utils/command/CommandHandler.java | 2 - .../utils/command/basic/HelpCommand.java | 1 - .../java/ru/gravit/utils/helper/IOHelper.java | 5 +- .../ru/gravit/utils/helper/JarHelper.java | 4 +- 7 files changed, 31 insertions(+), 37 deletions(-) diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherAgent.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherAgent.java index 5df60e18..302c5b43 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherAgent.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherAgent.java @@ -6,6 +6,8 @@ import java.io.IOException; import java.io.InputStream; import java.lang.instrument.Instrumentation; +import java.util.ArrayList; +import java.util.List; import java.util.jar.JarFile; import org.objectweb.asm.ClassReader; @@ -43,42 +45,41 @@ public static void premain(String agentArgument, Instrumentation instrumentation if (trimmedArg.contains("r")) rt = false; } } - //if (rt || pb) replaceClasses(pb, rt); + /*if (rt || pb)*/ + replaceClasses(pb, rt); } public static boolean isStarted() { return isAgentStarted; } - - /** - * @author https://github.com/Konloch/JVM-Sandbox - * Replaces the Runtime class via instrumentation, transforms the class via ASM - */ + private static void replaceClasses(boolean pb, boolean rt) { java.awt.Robot.class.getName(); - for(Class c : inst.getAllLoadedClasses()) { - if(rt && c.getName().equals("java.lang.Runtime")) { - try { - inst.redefineClasses(new java.lang.instrument.ClassDefinition(java.lang.Runtime.class, transformClass(c.getName(), getClassFile(c)))); - } catch(Exception e) { - e.printStackTrace(); - } + List defs = new ArrayList<>(); + if(rt) { + try { + defs.add(new java.lang.instrument.ClassDefinition(java.lang.Runtime.class, transformClass(java.lang.Runtime.class.getName(), getClassFile(java.lang.Runtime.class)))); + } catch(Exception e) { + e.printStackTrace(); } - if(pb && c.getName().equals("java.lang.ProcessBuilder")) { - try { - inst.redefineClasses(new java.lang.instrument.ClassDefinition(java.lang.ProcessBuilder.class, transformClass(c.getName(), getClassFile(c)))); - } catch(Exception e) { - e.printStackTrace(); - } - } - if(c.getName().equals("java.awt.Robot")) { - try { - inst.redefineClasses(new java.lang.instrument.ClassDefinition(java.lang.ProcessBuilder.class, transformClass(c.getName(), getClassFile(c)))); - } catch(Exception e) { - e.printStackTrace(); - } + } + if(pb) { + try { + defs.add(new java.lang.instrument.ClassDefinition(java.lang.ProcessBuilder.class, transformClass(java.lang.ProcessBuilder.class.getName(), getClassFile(java.lang.ProcessBuilder.class)))); + } catch(Exception e) { + e.printStackTrace(); } } + try { + defs.add(new java.lang.instrument.ClassDefinition(java.awt.Robot.class, transformClass(java.awt.Robot.class.getName(), getClassFile(java.awt.Robot.class)))); + } catch(Exception e) { + e.printStackTrace(); + } + try { + inst.redefineClasses(defs.toArray(new java.lang.instrument.ClassDefinition[0])); + } catch(Exception e) { + e.printStackTrace(); + } } /** diff --git a/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherGuardManager.java b/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherGuardManager.java index ee9930d0..194e685f 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherGuardManager.java +++ b/Launcher/src/main/java/ru/gravit/launcher/guard/LauncherGuardManager.java @@ -2,7 +2,6 @@ import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherConfig; -import ru.gravit.launcher.client.ClientLauncher; import java.nio.file.Path; diff --git a/Radon b/Radon index e6974532..07581407 160000 --- a/Radon +++ b/Radon @@ -1 +1 @@ -Subproject commit e6974532efc7228a8b826a8cd9e1f1f7b609659f +Subproject commit 07581407e7b214b7dff8a256247dde62bba1697d diff --git a/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java b/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java index 19f890c2..e17840a9 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java +++ b/libLauncher/src/main/java/ru/gravit/utils/command/CommandHandler.java @@ -2,11 +2,9 @@ import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.LogHelper; -import ru.gravit.utils.helper.VerifyHelper; import java.io.IOException; import java.util.*; -import java.util.concurrent.ConcurrentHashMap; public abstract class CommandHandler implements Runnable { private final List categories = new ArrayList<>(); diff --git a/libLauncher/src/main/java/ru/gravit/utils/command/basic/HelpCommand.java b/libLauncher/src/main/java/ru/gravit/utils/command/basic/HelpCommand.java index fd7752c0..587d3caf 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/command/basic/HelpCommand.java +++ b/libLauncher/src/main/java/ru/gravit/utils/command/basic/HelpCommand.java @@ -6,7 +6,6 @@ import ru.gravit.utils.command.CommandHandler; import ru.gravit.utils.helper.LogHelper; -import java.util.Map; import java.util.Map.Entry; public final class HelpCommand extends Command { diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/IOHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/IOHelper.java index 64df21be..46b06276 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/IOHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/IOHelper.java @@ -578,16 +578,13 @@ public static Path resolveJavaBin(Path javaDir) { @LauncherAPI public static void setSocketFlags(Socket socket) throws SocketException { // Set socket flags - socket.setKeepAlive(false); // TODO To socket channels + socket.setKeepAlive(false); socket.setTcpNoDelay(false); socket.setReuseAddress(true); // Set socket options socket.setSoTimeout(SOCKET_TIMEOUT); socket.setTrafficClass(0b11100); - // Allow OS to adjust buffer sizes - // socket.setSendBufferSize(0x100000); - // socket.setReceiveBufferSize(0x100000); socket.setPerformancePreferences(1, 0, 2); } diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/JarHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/JarHelper.java index 686ed2dd..f5c144df 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/JarHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/JarHelper.java @@ -70,12 +70,12 @@ public static void jarMap(Path file, Map map, boolean overwrite) jarMap(inputStream, map,overwrite); } } - public static Map jarMap(Class clazz, boolean overwrite) throws IOException + public static Map jarMap(Class clazz, boolean overwrite) throws IOException { Path file = IOHelper.getCodeSource(clazz); return jarMap(file, overwrite); } - public static void jarMap(Class clazz, Map map, boolean overwrite) throws IOException + public static void jarMap(Class clazz, Map map, boolean overwrite) throws IOException { Path file = IOHelper.getCodeSource(clazz); jarMap(file, map, overwrite);