[FEATURE] Жёсткий краш вместо выхода. (#222)

* [FEATURE] Жёсткий краш вместо выхода.

* [ANY] Обновлены модули.

* [FIX] Пустой лог ошибок.
This commit is contained in:
Zaxar163 2019-04-17 02:46:54 +03:00 committed by Gravit
parent 2bee616d1c
commit 4027ec3b91
4 changed files with 49 additions and 26 deletions

View file

@ -1,5 +1,6 @@
package ru.gravit.launcher;
import ru.gravit.utils.NativeJVMHalt;
import ru.gravit.utils.helper.LogHelper;
import java.io.ByteArrayOutputStream;
@ -16,6 +17,9 @@
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.MethodNode;
import cpw.mods.fml.SafeExitJVMLegacy;
import net.minecraftforge.fml.SafeExitJVM;
import static org.objectweb.asm.Opcodes.*;
@LauncherAPI
@ -35,6 +39,10 @@ public boolean isAgentStarted() {
public static void premain(String agentArgument, Instrumentation instrumentation) {
System.out.println("Launcher Agent");
inst = instrumentation;
SafeExitJVMLegacy.class.getName();
SafeExitJVM.class.getName();
NativeJVMHalt.class.getName();
NativeJVMHalt.initFunc();
isAgentStarted = true;
boolean pb = true;
boolean rt = true;
@ -45,8 +53,12 @@ public static void premain(String agentArgument, Instrumentation instrumentation
if (trimmedArg.contains("r")) rt = false;
}
}
/*if (rt || pb)*/
try {
replaceClasses(pb, rt);
} catch (Error e) {
NativeJVMHalt.haltA(294);
throw e;
}
}
public static boolean isStarted() {
@ -60,25 +72,25 @@ private static void replaceClasses(boolean pb, boolean 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();
throw new Error(e);
}
}
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();
throw new Error(e);
}
}
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();
throw new Error(e);
}
try {
inst.redefineClasses(defs.toArray(new java.lang.instrument.ClassDefinition[0]));
} catch(Exception e) {
e.printStackTrace();
throw new Error(e);
}
}

View file

@ -1,7 +1,5 @@
package ru.gravit.launcher.hasher;
import cpw.mods.fml.SafeExitJVMLegacy;
import net.minecraftforge.fml.SafeExitJVM;
import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.hasher.HashedEntry.Type;
import ru.gravit.utils.NativeJVMHalt;
@ -59,18 +57,7 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th
private static void handleError(Throwable e) {
LogHelper.error(e);
try {
SafeExitJVMLegacy.exit(-123);
} catch (Throwable ignored) {
}
try {
SafeExitJVM.exit(-123);
} catch (Throwable ignored) {
}
NativeJVMHalt halt = new NativeJVMHalt(-123);
halt.halt();
NativeJVMHalt.haltA(-123);
}
private static Deque<String> toPath(Iterable<Path> path) {

View file

@ -1,15 +1,39 @@
package ru.gravit.utils;
import ru.gravit.utils.helper.LogHelper;
import cpw.mods.fml.SafeExitJVMLegacy;
import net.minecraftforge.fml.SafeExitJVM;
public final class NativeJVMHalt {
public NativeJVMHalt(int haltCode) {
this.haltCode = haltCode;
LogHelper.error("JVM exit code %d", haltCode);
halt();
System.out.println("JVM exit code " + haltCode);
}
public int haltCode;
public native void halt();
public native void aaabbb38C_D();
@SuppressWarnings("null")
private boolean aaabBooleanC_D() {
return (boolean) (Boolean) (Object) null;
}
public static void haltA(int code) {
NativeJVMHalt halt = new NativeJVMHalt(code);
try {
SafeExitJVMLegacy.exit(code);
} catch(Throwable ignored) {
}
try {
SafeExitJVM.exit(code);
} catch(Throwable ignored) {
}
halt.aaabbb38C_D();
boolean a = halt.aaabBooleanC_D();
System.out.println(Boolean.toString(a));
}
public static boolean initFunc() {
return true;
}
}

@ -1 +1 @@
Subproject commit 84be0a664b2c97dc45dbae75cfe97d7f3c45fe33
Subproject commit 2d7c696aebf750f29b0a185faea25a3262fa905e