mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-04-19 14:33:04 +03:00
[FEATURE] Фикс завершения работы через агент... Патчим класс форжового SM
This commit is contained in:
parent
ef1b61d258
commit
7fda7ebecd
5 changed files with 47 additions and 31 deletions
|
@ -6,6 +6,8 @@
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.patches.FMLPatcher;
|
||||||
|
import pro.gravit.launcher.utils.NativeJVMHalt;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
@ -31,10 +33,8 @@ public static void premain(String agentArgument, Instrumentation instrumentation
|
||||||
System.out.println("Launcher Agent");
|
System.out.println("Launcher Agent");
|
||||||
checkAgentStacktrace();
|
checkAgentStacktrace();
|
||||||
inst = instrumentation;
|
inst = instrumentation;
|
||||||
//SafeExitJVMLegacy.class.getName();
|
NativeJVMHalt.initFunc();
|
||||||
//SafeExitJVM.class.getName();
|
FMLPatcher.apply();
|
||||||
//NativeJVMHalt.class.getName();
|
|
||||||
//NativeJVMHalt.initFunc();
|
|
||||||
isAgentStarted = true;
|
isAgentStarted = true;
|
||||||
}
|
}
|
||||||
public static void checkAgentStacktrace()
|
public static void checkAgentStacktrace()
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package pro.gravit.launcher.patches;
|
||||||
|
|
||||||
|
import java.lang.instrument.ClassFileTransformer;
|
||||||
|
import java.lang.instrument.IllegalClassFormatException;
|
||||||
|
import java.security.ProtectionDomain;
|
||||||
|
|
||||||
|
import org.objectweb.asm.ClassReader;
|
||||||
|
import org.objectweb.asm.ClassWriter;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
|
import org.objectweb.asm.tree.InsnNode;
|
||||||
|
import org.objectweb.asm.tree.MethodNode;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.LauncherAgent;
|
||||||
|
|
||||||
|
public class FMLPatcher implements ClassFileTransformer {
|
||||||
|
@Override
|
||||||
|
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
|
||||||
|
ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
|
||||||
|
try {
|
||||||
|
if (className.startsWith("java") || className.startsWith("sun") || className.startsWith("com/sun") || className.startsWith("javafx")) return classfileBuffer;
|
||||||
|
ClassReader cr = new ClassReader(classfileBuffer);
|
||||||
|
if ("java/lang/SecurityManager".equals(cr.getSuperName()) && (className.contains("cpw") || className.contains("mods") || className.contains("forge"))) {
|
||||||
|
ClassNode cn = new ClassNode();
|
||||||
|
cr.accept(cn, ClassReader.EXPAND_FRAMES);
|
||||||
|
for (MethodNode m : cn.methods)
|
||||||
|
if (m.name.equals("checkPermission") && m.desc.equals("(Ljava/lang/String;)V")) {
|
||||||
|
m.instructions.clear();
|
||||||
|
m.instructions.insert(new InsnNode(Opcodes.RETURN));
|
||||||
|
}
|
||||||
|
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
||||||
|
cn.accept(cw);
|
||||||
|
return cw.toByteArray();
|
||||||
|
}
|
||||||
|
} catch (Throwable e) { }
|
||||||
|
return classfileBuffer;
|
||||||
|
}
|
||||||
|
public static void apply() {
|
||||||
|
LauncherAgent.inst.addTransformer(new FMLPatcher());
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import cpw.mods.fml.SafeExitJVMLegacy;
|
import cpw.mods.fml.SafeExitJVMLegacy;
|
||||||
import net.minecraftforge.fml.SafeExitJVM;
|
import net.minecraftforge.fml.SafeExitJVM;
|
||||||
|
import pro.gravit.utils.helper.JVMHelper;
|
||||||
|
|
||||||
public final class NativeJVMHalt {
|
public final class NativeJVMHalt {
|
||||||
public NativeJVMHalt(int haltCode) {
|
public NativeJVMHalt(int haltCode) {
|
||||||
|
@ -21,11 +22,7 @@ private boolean aaabBooleanC_D() {
|
||||||
public static void haltA(int code) {
|
public static void haltA(int code) {
|
||||||
NativeJVMHalt halt = new NativeJVMHalt(code);
|
NativeJVMHalt halt = new NativeJVMHalt(code);
|
||||||
try {
|
try {
|
||||||
SafeExitJVMLegacy.exit(code);
|
JVMHelper.RUNTIME.exit(code);
|
||||||
} catch (Throwable ignored) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
SafeExitJVM.exit(code);
|
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
}
|
}
|
||||||
halt.aaabbb38C_D();
|
halt.aaabbb38C_D();
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
package cpw.mods.fml;
|
|
||||||
|
|
||||||
import pro.gravit.utils.helper.JVMHelper;
|
|
||||||
|
|
||||||
// FMLSecurityManager запрещает делать System.exit из классов
|
|
||||||
// Не входящих в пакеты самого Forge
|
|
||||||
public class SafeExitJVMLegacy {
|
|
||||||
public static void exit(int code) {
|
|
||||||
JVMHelper.RUNTIME.halt(code);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
package net.minecraftforge.fml;
|
|
||||||
|
|
||||||
import pro.gravit.utils.helper.JVMHelper;
|
|
||||||
|
|
||||||
// FMLSecurityManager запрещает делать System.exit из классов
|
|
||||||
// Не входящих в пакеты самого Forge
|
|
||||||
public class SafeExitJVM {
|
|
||||||
public static void exit(int code) {
|
|
||||||
JVMHelper.RUNTIME.halt(code);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue