[FIX] LauncherAgent.

This commit is contained in:
zaxar163 2019-04-13 14:56:11 +03:00
parent d7a58ef42e
commit f3a19701a2
No known key found for this signature in database
GPG key ID: E3B309DD3852DE06
7 changed files with 31 additions and 37 deletions

View file

@ -6,6 +6,8 @@
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.lang.instrument.Instrumentation; import java.lang.instrument.Instrumentation;
import java.util.ArrayList;
import java.util.List;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassReader;
@ -43,41 +45,40 @@ public static void premain(String agentArgument, Instrumentation instrumentation
if (trimmedArg.contains("r")) rt = false; if (trimmedArg.contains("r")) rt = false;
} }
} }
//if (rt || pb) replaceClasses(pb, rt); /*if (rt || pb)*/
replaceClasses(pb, rt);
} }
public static boolean isStarted() { public static boolean isStarted() {
return isAgentStarted; 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) { private static void replaceClasses(boolean pb, boolean rt) {
java.awt.Robot.class.getName(); java.awt.Robot.class.getName();
for(Class<?> c : inst.getAllLoadedClasses()) { List<java.lang.instrument.ClassDefinition> defs = new ArrayList<>();
if(rt && c.getName().equals("java.lang.Runtime")) { if(rt) {
try { try {
inst.redefineClasses(new java.lang.instrument.ClassDefinition(java.lang.Runtime.class, transformClass(c.getName(), getClassFile(c)))); 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) { } catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
if(pb && c.getName().equals("java.lang.ProcessBuilder")) { if(pb) {
try { try {
inst.redefineClasses(new java.lang.instrument.ClassDefinition(java.lang.ProcessBuilder.class, transformClass(c.getName(), getClassFile(c)))); 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) { } catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
if(c.getName().equals("java.awt.Robot")) {
try { try {
inst.redefineClasses(new java.lang.instrument.ClassDefinition(java.lang.ProcessBuilder.class, transformClass(c.getName(), getClassFile(c)))); 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) { } catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} try {
inst.redefineClasses(defs.toArray(new java.lang.instrument.ClassDefinition[0]));
} catch(Exception e) {
e.printStackTrace();
} }
} }

View file

@ -2,7 +2,6 @@
import ru.gravit.launcher.Launcher; import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.client.ClientLauncher;
import java.nio.file.Path; import java.nio.file.Path;

2
Radon

@ -1 +1 @@
Subproject commit e6974532efc7228a8b826a8cd9e1f1f7b609659f Subproject commit 07581407e7b214b7dff8a256247dde62bba1697d

View file

@ -2,11 +2,9 @@
import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.CommonHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.VerifyHelper;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public abstract class CommandHandler implements Runnable { public abstract class CommandHandler implements Runnable {
private final List<Category> categories = new ArrayList<>(); private final List<Category> categories = new ArrayList<>();

View file

@ -6,7 +6,6 @@
import ru.gravit.utils.command.CommandHandler; import ru.gravit.utils.command.CommandHandler;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
public final class HelpCommand extends Command { public final class HelpCommand extends Command {

View file

@ -578,16 +578,13 @@ public static Path resolveJavaBin(Path javaDir) {
@LauncherAPI @LauncherAPI
public static void setSocketFlags(Socket socket) throws SocketException { public static void setSocketFlags(Socket socket) throws SocketException {
// Set socket flags // Set socket flags
socket.setKeepAlive(false); // TODO To socket channels socket.setKeepAlive(false);
socket.setTcpNoDelay(false); socket.setTcpNoDelay(false);
socket.setReuseAddress(true); socket.setReuseAddress(true);
// Set socket options // Set socket options
socket.setSoTimeout(SOCKET_TIMEOUT); socket.setSoTimeout(SOCKET_TIMEOUT);
socket.setTrafficClass(0b11100); socket.setTrafficClass(0b11100);
// Allow OS to adjust buffer sizes
// socket.setSendBufferSize(0x100000);
// socket.setReceiveBufferSize(0x100000);
socket.setPerformancePreferences(1, 0, 2); socket.setPerformancePreferences(1, 0, 2);
} }

View file

@ -70,12 +70,12 @@ public static void jarMap(Path file, Map<String, String> map, boolean overwrite)
jarMap(inputStream, map,overwrite); jarMap(inputStream, map,overwrite);
} }
} }
public static Map<String, String> jarMap(Class clazz, boolean overwrite) throws IOException public static Map<String, String> jarMap(Class<?> clazz, boolean overwrite) throws IOException
{ {
Path file = IOHelper.getCodeSource(clazz); Path file = IOHelper.getCodeSource(clazz);
return jarMap(file, overwrite); return jarMap(file, overwrite);
} }
public static void jarMap(Class clazz, Map<String, String> map, boolean overwrite) throws IOException public static void jarMap(Class<?> clazz, Map<String, String> map, boolean overwrite) throws IOException
{ {
Path file = IOHelper.getCodeSource(clazz); Path file = IOHelper.getCodeSource(clazz);
jarMap(file, map, overwrite); jarMap(file, map, overwrite);