diff --git a/src/me/nov/threadtear/security/VMExtraSecurity.java b/src/me/nov/threadtear/security/VMExtraSecurity.java deleted file mode 100644 index 0e57ff9..0000000 --- a/src/me/nov/threadtear/security/VMExtraSecurity.java +++ /dev/null @@ -1,52 +0,0 @@ -package me.nov.threadtear.security; - -import java.net.URL; - -import org.apache.commons.io.IOUtils; -import org.objectweb.asm.Opcodes; -import org.objectweb.asm.tree.*; - -import me.nov.threadtear.Threadtear; -import me.nov.threadtear.io.Conversion; - -public class VMExtraSecurity implements Opcodes { - public static InsnList rewriteSetAccessible0(String blockRegex) { - InsnList il = new InsnList(); - LabelNode jump = new LabelNode(); - il.add(new VarInsnNode(ALOAD, 0)); - il.add(new TypeInsnNode(INSTANCEOF, "java/lang/reflect/Member")); - il.add(new JumpInsnNode(IFEQ, jump)); - il.add(new VarInsnNode(ALOAD, 0)); - il.add(new TypeInsnNode(CHECKCAST, "java/lang/reflect/Member")); - il.add(new MethodInsnNode(INVOKEINTERFACE, "java/lang/reflect/Member", "getName", "()Ljava/lang/String;")); - il.add(new LdcInsnNode(blockRegex)); - il.add(new MethodInsnNode(INVOKEVIRTUAL, "java/lang/String", "matches", "(Ljava/lang/String;)Z")); - il.add(new JumpInsnNode(IFEQ, jump)); - il.add(new InsnNode(RETURN)); - il.add(jump); - il.add(new FrameNode(F_NEW, 2, new Object[] { "java/lang/reflect/AccessibleObject", INTEGER }, 0, null)); - il.add(new VarInsnNode(ALOAD, 0)); - il.add(new VarInsnNode(ILOAD, 1)); - il.add(new FieldInsnNode(PUTFIELD, "java/lang/reflect/AccessibleObject", "override", "Z")); - il.add(new InsnNode(RETURN)); - return il; - } - - public static ClassNode rewriteAccessibleObject() { - String classFile = "/java/lang/reflect/AccessibleObject.class"; - URL url = VMExtraSecurity.class.getResource(classFile); - try { - ClassNode loadedNode = Conversion.toNode(IOUtils.toByteArray(url)); - MethodNode setAccessible0 = loadedNode.methods.stream().filter(m -> m.name.equals("setAccessible0")).findFirst().get(); - setAccessible0.instructions = rewriteSetAccessible0("(me\\.nov|java\\.lang|sun\\.).*"); - setAccessible0.maxStack = 2; - setAccessible0.maxLocals = 2; - setAccessible0.tryCatchBlocks = null; - setAccessible0.localVariables = null; - return loadedNode; - } catch (Exception e) { - Threadtear.logger.error("Couldn't rewrite AccessibleObject, {}", e.toString()); - return null; - } - } -} diff --git a/src/me/nov/threadtear/security/VMSecurityManager.java b/src/me/nov/threadtear/security/VMSecurityManager.java index e35b2b1..b52a330 100644 --- a/src/me/nov/threadtear/security/VMSecurityManager.java +++ b/src/me/nov/threadtear/security/VMSecurityManager.java @@ -9,7 +9,7 @@ public class VMSecurityManager extends SecurityManager { private static boolean grantAll; - private static boolean checkReflection = true; + private static boolean checkReflection = false; @Override public void checkPermission(Permission perm) { diff --git a/src/me/nov/threadtear/vm/VM.java b/src/me/nov/threadtear/vm/VM.java index 36ffa64..d6b34ff 100644 --- a/src/me/nov/threadtear/vm/VM.java +++ b/src/me/nov/threadtear/vm/VM.java @@ -10,7 +10,6 @@ import me.nov.threadtear.Threadtear; import me.nov.threadtear.io.Conversion; -import me.nov.threadtear.security.VMExtraSecurity; import me.nov.threadtear.util.asm.*; public class VM extends ClassLoader implements Opcodes { @@ -59,15 +58,6 @@ public Class loadClass(String name, boolean resolve) throws ClassNotFoundExce if (name.contains("/")) throw new IllegalArgumentException(); if (name.matches(RT)) { - if (name.equals("java.lang.reflect.AccessibleObject")) { - if (loaded.containsKey(name)) { - return loaded.get(name); - } - Class acc = bytesToClass(name, Conversion.toBytecode0(VMExtraSecurity.rewriteAccessibleObject())); - Threadtear.logger.warning("Redefined java.lang.reflect.AccessibleObject for more security, a class called setAccessible(true)."); - loaded.put(name, acc); - return acc; - } return super.loadClass(name, resolve); } if (loaded.containsKey(name)) {