Compare commits
4 Commits
9823d58d00
...
6da7112443
Author | SHA1 | Date | |
---|---|---|---|
6da7112443 | |||
![]() |
3388fad6fc | ||
![]() |
73b82da0e6 | ||
![]() |
2fe0791b46 |
41
src/main/java/com/novitechie/ClassLoaderTransformer.java
Normal file
41
src/main/java/com/novitechie/ClassLoaderTransformer.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package com.novitechie;
|
||||||
|
|
||||||
|
import com.janetfilter.core.plugin.MyTransformer;
|
||||||
|
import jdk.internal.org.objectweb.asm.ClassReader;
|
||||||
|
import jdk.internal.org.objectweb.asm.ClassWriter;
|
||||||
|
import jdk.internal.org.objectweb.asm.tree.*;
|
||||||
|
|
||||||
|
import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author YeloChick
|
||||||
|
*/
|
||||||
|
public class ClassLoaderTransformer implements MyTransformer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHookClassName() {
|
||||||
|
return "java/lang/ClassLoader";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] transform(String className, byte[] classBytes, int order) throws Exception {
|
||||||
|
ClassReader reader = new ClassReader(classBytes);
|
||||||
|
ClassNode node = new ClassNode(ASM5);
|
||||||
|
reader.accept(node, 0);
|
||||||
|
for (MethodNode m : node.methods) {
|
||||||
|
if ("loadClass".equals(m.name)) {
|
||||||
|
InsnList list = new InsnList();
|
||||||
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/StackTraceRule", "check", "()Z", false));
|
||||||
|
LabelNode labelNode = new LabelNode();
|
||||||
|
list.add(new JumpInsnNode(IFEQ, labelNode));
|
||||||
|
list.add(new VarInsnNode(ALOAD, 1));
|
||||||
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/LoadClassRule", "check", "(Ljava/lang/String;)V", false));
|
||||||
|
list.add(labelNode);
|
||||||
|
m.instructions.insert(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ClassWriter writer = new SafeClassWriter(null, null, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||||
|
node.accept(writer);
|
||||||
|
return writer.toByteArray();
|
||||||
|
}
|
||||||
|
}
|
65
src/main/java/com/novitechie/ClassTransformer.java
Normal file
65
src/main/java/com/novitechie/ClassTransformer.java
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package com.novitechie;
|
||||||
|
|
||||||
|
import com.janetfilter.core.plugin.MyTransformer;
|
||||||
|
import jdk.internal.org.objectweb.asm.ClassReader;
|
||||||
|
import jdk.internal.org.objectweb.asm.ClassWriter;
|
||||||
|
import jdk.internal.org.objectweb.asm.tree.*;
|
||||||
|
|
||||||
|
import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author YeloChick
|
||||||
|
*/
|
||||||
|
public class ClassTransformer implements MyTransformer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHookClassName() {
|
||||||
|
return "java/lang/Class";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] transform(String className, byte[] classBytes, int order) throws Exception {
|
||||||
|
ClassReader reader = new ClassReader(classBytes);
|
||||||
|
ClassNode node = new ClassNode(ASM5);
|
||||||
|
reader.accept(node, 0);
|
||||||
|
for (MethodNode m : node.methods) {
|
||||||
|
if ("getResource".equals(m.name) && m.desc.equals("(Ljava/lang/String;)Ljava/net/URL;")) {
|
||||||
|
InsnList list = new InsnList();
|
||||||
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/StackTraceRule", "check", "()Z", false));
|
||||||
|
LabelNode labelNode = new LabelNode();
|
||||||
|
list.add(new JumpInsnNode(IFEQ, labelNode));
|
||||||
|
list.add(new VarInsnNode(ALOAD, 1));
|
||||||
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/ResourceRule", "check", "(Ljava/lang/String;)Z", false));
|
||||||
|
list.add(new JumpInsnNode(IFEQ, labelNode));
|
||||||
|
list.add(new InsnNode(ACONST_NULL));
|
||||||
|
list.add(new InsnNode(ARETURN));
|
||||||
|
list.add(labelNode);
|
||||||
|
m.instructions.insert(list);
|
||||||
|
} else if ("getResourceAsStream".equals(m.name) && m.desc.equals("(Ljava/lang/String;)Ljava/io/InputStream;")) {
|
||||||
|
InsnList list = new InsnList();
|
||||||
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/StackTraceRule", "check", "()Z", false));
|
||||||
|
LabelNode labelNode = new LabelNode();
|
||||||
|
list.add(new JumpInsnNode(IFEQ, labelNode));
|
||||||
|
list.add(new VarInsnNode(ALOAD, 1));
|
||||||
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/ResourceRule", "check", "(Ljava/lang/String;)Z", false));
|
||||||
|
list.add(new JumpInsnNode(IFEQ, labelNode));
|
||||||
|
list.add(new InsnNode(ACONST_NULL));
|
||||||
|
list.add(new InsnNode(ARETURN));
|
||||||
|
list.add(labelNode);
|
||||||
|
m.instructions.insert(list);
|
||||||
|
} else if ("getDeclaredMethod".equals(m.name)) {
|
||||||
|
InsnList list = new InsnList();
|
||||||
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/StackTraceRule", "check", "()Z", false));
|
||||||
|
LabelNode labelNode = new LabelNode();
|
||||||
|
list.add(new JumpInsnNode(IFEQ, labelNode));
|
||||||
|
list.add(new VarInsnNode(ALOAD, 1));
|
||||||
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/ClassRule", "checkMethod", "(Ljava/lang/String;)V", false));
|
||||||
|
list.add(labelNode);
|
||||||
|
m.instructions.insert(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||||
|
node.accept(writer);
|
||||||
|
return writer.toByteArray();
|
||||||
|
}
|
||||||
|
}
|
@ -21,10 +21,10 @@ public class LicensingFacadeTransformer implements MyTransformer {
|
|||||||
for (MethodNode m : node.methods) {
|
for (MethodNode m : node.methods) {
|
||||||
if ("getLicenseExpirationDate".equals(m.name)) {
|
if ("getLicenseExpirationDate".equals(m.name)) {
|
||||||
InsnList list = new InsnList();
|
InsnList list = new InsnList();
|
||||||
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/StackTraceRule", "hook", "()Ljava/util/Date;", false));
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/StackTraceRule", "hook", "()Ljava/util/Date;", false));
|
||||||
list.add(new InsnNode(DUP));
|
list.add(new InsnNode(DUP));
|
||||||
LabelNode labelNode = new LabelNode();
|
LabelNode labelNode = new LabelNode();
|
||||||
list.add(new JumpInsnNode(IFNULL,labelNode));
|
list.add(new JumpInsnNode(IFNULL, labelNode));
|
||||||
list.add(new InsnNode(ARETURN));
|
list.add(new InsnNode(ARETURN));
|
||||||
list.add(labelNode);
|
list.add(labelNode);
|
||||||
list.add(new InsnNode(POP));
|
list.add(new InsnNode(POP));
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
package com.novitechie;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class LoadClassRule {
|
|
||||||
|
|
||||||
private static final List<String> PREVENT_LOAD_PACKAGES = new ArrayList<String>() {
|
|
||||||
{
|
|
||||||
add("com.novitechie");
|
|
||||||
add("com.janetfilter");
|
|
||||||
add("jdk.internal.org.objectweb.asm");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public static void check(String name) throws Exception {
|
|
||||||
if (PREVENT_LOAD_PACKAGES.stream().anyMatch(name::startsWith)) {
|
|
||||||
throw new ClassNotFoundException(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -22,11 +22,11 @@ public class PluginClassLoaderTransformer implements MyTransformer {
|
|||||||
if ("loadClass".equals(m.name)) {
|
if ("loadClass".equals(m.name)) {
|
||||||
InsnList list = new InsnList();
|
InsnList list = new InsnList();
|
||||||
list.add(new VarInsnNode(ALOAD, 1));
|
list.add(new VarInsnNode(ALOAD, 1));
|
||||||
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/LoadClassRule", "check", "(Ljava/lang/String;)V", false));
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/LoadClassRule", "check", "(Ljava/lang/String;)V", false));
|
||||||
m.instructions.insert(list);
|
m.instructions.insert(list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ClassWriter writer = new SafeClassWriter(null,null,ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
ClassWriter writer = new SafeClassWriter(null, null, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||||
node.accept(writer);
|
node.accept(writer);
|
||||||
return writer.toByteArray();
|
return writer.toByteArray();
|
||||||
}
|
}
|
||||||
|
@ -23,23 +23,77 @@ public class PluginManagerCoreTransformer implements MyTransformer {
|
|||||||
ClassNode node = new ClassNode(ASM5);
|
ClassNode node = new ClassNode(ASM5);
|
||||||
reader.accept(node, 0);
|
reader.accept(node, 0);
|
||||||
for (MethodNode m : node.methods) {
|
for (MethodNode m : node.methods) {
|
||||||
if ("isPluginInstalled".equals(m.name)) {
|
if ("getPlugins".equals(m.name)) {
|
||||||
InsnList list = new InsnList();
|
InsnList list = new InsnList();
|
||||||
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/StackTraceRule", "check", "()Z", false));
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/StackTraceRule", "check", "()Z", false));
|
||||||
|
LabelNode L1 = new LabelNode();
|
||||||
|
LabelNode L2 = new LabelNode();
|
||||||
|
LabelNode L3 = new LabelNode();
|
||||||
|
LabelNode L4 = new LabelNode();
|
||||||
|
list.add(new JumpInsnNode(IFEQ, L1));
|
||||||
|
list.add(new FieldInsnNode(GETSTATIC, "com/intellij/ide/plugins/PluginManagerCore", "INSTANCE", "Lcom/intellij/ide/plugins/PluginManagerCore;"));
|
||||||
|
list.add(new MethodInsnNode(INVOKEVIRTUAL, "com/intellij/ide/plugins/PluginManagerCore", "getPluginSet", "()Lcom/intellij/ide/plugins/PluginSet;", false));
|
||||||
|
list.add(new FieldInsnNode(GETFIELD, "com/intellij/ide/plugins/PluginSet", "allPlugins", "Ljava/util/Set;"));
|
||||||
|
list.add(new VarInsnNode(ASTORE, 0));
|
||||||
|
list.add(new TypeInsnNode(NEW, "java/util/HashSet"));
|
||||||
|
list.add(new InsnNode(DUP));
|
||||||
|
list.add(new MethodInsnNode(INVOKESPECIAL, "java/util/HashSet", "<init>", "()V", false));
|
||||||
|
list.add(new VarInsnNode(ASTORE, 1));
|
||||||
|
list.add(new VarInsnNode(ALOAD, 0));
|
||||||
|
list.add(new MethodInsnNode(INVOKEINTERFACE, "java/util/Set", "iterator", "()Ljava/util/Iterator;", true));
|
||||||
|
list.add(new VarInsnNode(ASTORE, 2));
|
||||||
|
list.add(L3);
|
||||||
|
list.add(new VarInsnNode(ALOAD, 2));
|
||||||
|
list.add(new MethodInsnNode(INVOKEINTERFACE, "java/util/Iterator", "hasNext", "()Z", true));
|
||||||
|
list.add(new JumpInsnNode(IFEQ, L2));
|
||||||
|
list.add(new VarInsnNode(ALOAD, 2));
|
||||||
|
list.add(new MethodInsnNode(INVOKEINTERFACE, "java/util/Iterator", "next", "()Ljava/lang/Object;", true));
|
||||||
|
list.add(new TypeInsnNode(CHECKCAST, "com/intellij/ide/plugins/IdeaPluginDescriptor"));
|
||||||
|
list.add(new VarInsnNode(ASTORE, 3));
|
||||||
|
list.add(new VarInsnNode(ALOAD, 3));
|
||||||
|
list.add(new MethodInsnNode(INVOKEINTERFACE, "com/intellij/ide/plugins/IdeaPluginDescriptor", "getPluginId", "()Lcom/intellij/openapi/extensions/PluginId;", true));
|
||||||
|
list.add(new MethodInsnNode(INVOKEVIRTUAL, "com/intellij/openapi/extensions/PluginId", "getIdString", "()Ljava/lang/String;", false));
|
||||||
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/IdeaPluginRule", "check", "(Ljava/lang/String;)Z", false));
|
||||||
|
list.add(new JumpInsnNode(IFNE, L4));
|
||||||
|
list.add(new VarInsnNode(ALOAD, 1));
|
||||||
|
list.add(new VarInsnNode(ALOAD, 3));
|
||||||
|
list.add(new MethodInsnNode(INVOKEINTERFACE, "java/util/Set", "add", "(Ljava/lang/Object;)Z", true));
|
||||||
|
list.add(new InsnNode(POP));
|
||||||
|
list.add(L4);
|
||||||
|
list.add(new JumpInsnNode(GOTO, L3));
|
||||||
|
list.add(L2);
|
||||||
|
list.add(new VarInsnNode(ALOAD, 1));
|
||||||
|
list.add(new InsnNode(ICONST_0));
|
||||||
|
list.add(new TypeInsnNode(ANEWARRAY, "com/intellij/ide/plugins/IdeaPluginDescriptor"));
|
||||||
|
list.add(new MethodInsnNode(INVOKEINTERFACE, "java/util/Set", "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;", true));
|
||||||
|
list.add(new TypeInsnNode(CHECKCAST, "[Lcom/intellij/ide/plugins/IdeaPluginDescriptor;"));
|
||||||
|
list.add(new InsnNode(ARETURN));
|
||||||
|
list.add(L1);
|
||||||
|
m.instructions.insert(list);
|
||||||
|
} else if ("isPluginInstalled".equals(m.name)) {
|
||||||
|
InsnList list = new InsnList();
|
||||||
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/StackTraceRule", "check", "()Z", false));
|
||||||
LabelNode labelNode = new LabelNode();
|
LabelNode labelNode = new LabelNode();
|
||||||
list.add(new JumpInsnNode(IFEQ, labelNode));
|
list.add(new JumpInsnNode(IFEQ, labelNode));
|
||||||
|
list.add(new VarInsnNode(ALOAD, 0));
|
||||||
|
list.add(new MethodInsnNode(INVOKEVIRTUAL, "com/intellij/openapi/extensions/PluginId", "getIdString", "()Ljava/lang/String;", false));
|
||||||
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/IdeaPluginRule", "check", "(Ljava/lang/String;)Z", false));
|
||||||
|
list.add(new JumpInsnNode(IFEQ, labelNode));
|
||||||
list.add(new InsnNode(ICONST_0));
|
list.add(new InsnNode(ICONST_0));
|
||||||
list.add(new InsnNode(IRETURN));
|
list.add(new InsnNode(IRETURN));
|
||||||
list.add(labelNode);
|
list.add(labelNode);
|
||||||
m.instructions.insert(list);
|
m.instructions.insert(list);
|
||||||
} else if ("getPlugins".equals(m.name)) {
|
} else if ("isDisabled".equals(m.name)) {
|
||||||
InsnList list = new InsnList();
|
InsnList list = new InsnList();
|
||||||
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/StackTraceRule", "check", "()Z", false));
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/StackTraceRule", "check", "()Z", false));
|
||||||
LabelNode labelNode = new LabelNode();
|
LabelNode labelNode = new LabelNode();
|
||||||
list.add(new JumpInsnNode(IFEQ, labelNode));
|
list.add(new JumpInsnNode(IFEQ, labelNode));
|
||||||
list.add(new InsnNode(ICONST_0));
|
list.add(new VarInsnNode(ALOAD, 0));
|
||||||
list.add(new TypeInsnNode(ANEWARRAY, "java/lang/Object"));
|
list.add(new MethodInsnNode(INVOKEVIRTUAL, "com/intellij/openapi/extensions/PluginId", "getIdString", "()Ljava/lang/String;", false));
|
||||||
list.add(new InsnNode(ARETURN));
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/IdeaPluginRule", "check", "(Ljava/lang/String;)Z", false));
|
||||||
|
list.add(new JumpInsnNode(IFEQ, labelNode));
|
||||||
|
list.add(new InsnNode(ICONST_1));
|
||||||
|
list.add(new InsnNode(IRETURN));
|
||||||
list.add(labelNode);
|
list.add(labelNode);
|
||||||
m.instructions.insert(list);
|
m.instructions.insert(list);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,10 @@ public class PrivacyPlugin implements PluginEntry {
|
|||||||
new VMOptionsTransformer(),
|
new VMOptionsTransformer(),
|
||||||
new PluginClassLoaderTransformer(),
|
new PluginClassLoaderTransformer(),
|
||||||
new LicensingFacadeTransformer(),
|
new LicensingFacadeTransformer(),
|
||||||
new PluginManagerCoreTransformer());
|
new PluginManagerCoreTransformer(),
|
||||||
|
new RuntimeMXBeanTransformer(),
|
||||||
|
new SystemTransformer(),
|
||||||
|
new ClassTransformer(),
|
||||||
|
new ClassLoaderTransformer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
42
src/main/java/com/novitechie/RuntimeMXBeanTransformer.java
Normal file
42
src/main/java/com/novitechie/RuntimeMXBeanTransformer.java
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package com.novitechie;
|
||||||
|
|
||||||
|
import com.janetfilter.core.plugin.MyTransformer;
|
||||||
|
import jdk.internal.org.objectweb.asm.ClassReader;
|
||||||
|
import jdk.internal.org.objectweb.asm.ClassWriter;
|
||||||
|
import jdk.internal.org.objectweb.asm.tree.*;
|
||||||
|
|
||||||
|
import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author YeloChick
|
||||||
|
*/
|
||||||
|
public class RuntimeMXBeanTransformer implements MyTransformer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHookClassName() {
|
||||||
|
return "sun/management/RuntimeImpl";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] transform(String className, byte[] classBytes, int order) throws Exception {
|
||||||
|
ClassReader reader = new ClassReader(classBytes);
|
||||||
|
ClassNode node = new ClassNode(ASM5);
|
||||||
|
reader.accept(node, 0);
|
||||||
|
for (MethodNode m : node.methods) {
|
||||||
|
if ("getInputArguments".equals(m.name)) {
|
||||||
|
InsnList list = new InsnList();
|
||||||
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/StackTraceRule", "check", "()Z", false));
|
||||||
|
LabelNode labelNode = new LabelNode();
|
||||||
|
list.add(new JumpInsnNode(IFEQ, labelNode));
|
||||||
|
list.add(new LdcInsnNode(""));
|
||||||
|
list.add(new MethodInsnNode(INVOKESTATIC, "java/util/Collections", "singletonList", "(Ljava/lang/Object;)Ljava/util/List;", false));
|
||||||
|
list.add(new InsnNode(ARETURN));
|
||||||
|
list.add(labelNode);
|
||||||
|
m.instructions.insert(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ClassWriter writer = new SafeClassWriter(null, null, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||||
|
node.accept(writer);
|
||||||
|
return writer.toByteArray();
|
||||||
|
}
|
||||||
|
}
|
56
src/main/java/com/novitechie/SystemTransformer.java
Normal file
56
src/main/java/com/novitechie/SystemTransformer.java
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package com.novitechie;
|
||||||
|
|
||||||
|
import com.janetfilter.core.plugin.MyTransformer;
|
||||||
|
import jdk.internal.org.objectweb.asm.ClassReader;
|
||||||
|
import jdk.internal.org.objectweb.asm.ClassWriter;
|
||||||
|
import jdk.internal.org.objectweb.asm.tree.*;
|
||||||
|
|
||||||
|
import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author YeloChick
|
||||||
|
*/
|
||||||
|
public class SystemTransformer implements MyTransformer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHookClassName() {
|
||||||
|
return "java/lang/System";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] transform(String className, byte[] classBytes, int order) throws Exception {
|
||||||
|
ClassReader reader = new ClassReader(classBytes);
|
||||||
|
ClassNode node = new ClassNode(ASM5);
|
||||||
|
reader.accept(node, 0);
|
||||||
|
for (MethodNode m : node.methods) {
|
||||||
|
if ("getenv".equals(m.name) && m.desc.equals("(Ljava/lang/String;)Ljava/lang/String;")) {
|
||||||
|
InsnList list = new InsnList();
|
||||||
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/StackTraceRule", "check", "()Z", false));
|
||||||
|
LabelNode labelNode = new LabelNode();
|
||||||
|
list.add(new JumpInsnNode(IFEQ, labelNode));
|
||||||
|
list.add(new VarInsnNode(ALOAD, 0));
|
||||||
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/SystemRule", "checkEnv", "(Ljava/lang/String;)Z", false));
|
||||||
|
list.add(new JumpInsnNode(IFEQ, labelNode));
|
||||||
|
list.add(new InsnNode(ACONST_NULL));
|
||||||
|
list.add(new InsnNode(ARETURN));
|
||||||
|
list.add(labelNode);
|
||||||
|
m.instructions.insert(list);
|
||||||
|
} else if ("getProperty".equals(m.name) && (m.desc.equals("(Ljava/lang/String;)Ljava/lang/String;") || m.desc.equals("(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;"))) {
|
||||||
|
InsnList list = new InsnList();
|
||||||
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/StackTraceRule", "check", "()Z", false));
|
||||||
|
LabelNode labelNode = new LabelNode();
|
||||||
|
list.add(new JumpInsnNode(IFEQ, labelNode));
|
||||||
|
list.add(new VarInsnNode(ALOAD, 0));
|
||||||
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/SystemRule", "checkProperty", "(Ljava/lang/String;)Z", false));
|
||||||
|
list.add(new JumpInsnNode(IFEQ, labelNode));
|
||||||
|
list.add(new InsnNode(ACONST_NULL));
|
||||||
|
list.add(new InsnNode(ARETURN));
|
||||||
|
list.add(labelNode);
|
||||||
|
m.instructions.insert(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||||
|
node.accept(writer);
|
||||||
|
return writer.toByteArray();
|
||||||
|
}
|
||||||
|
}
|
@ -21,10 +21,10 @@ public class VMOptionsTransformer implements MyTransformer {
|
|||||||
for (MethodNode m : node.methods) {
|
for (MethodNode m : node.methods) {
|
||||||
if ("getUserOptionsFile".equals(m.name)) {
|
if ("getUserOptionsFile".equals(m.name)) {
|
||||||
InsnList list = new InsnList();
|
InsnList list = new InsnList();
|
||||||
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/StackTraceRule", "check", "()Z", false));
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/StackTraceRule", "check", "()Z", false));
|
||||||
LabelNode labelNode = new LabelNode();
|
LabelNode labelNode = new LabelNode();
|
||||||
list.add(new JumpInsnNode(IFEQ, labelNode));
|
list.add(new JumpInsnNode(IFEQ, labelNode));
|
||||||
list.add(new InsnNode(ACONST_NULL));
|
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/rules/VMOptionsRule", "hook", "()Ljava/nio/file/Path;", false));
|
||||||
list.add(new InsnNode(ARETURN));
|
list.add(new InsnNode(ARETURN));
|
||||||
list.add(labelNode);
|
list.add(labelNode);
|
||||||
m.instructions.insert(list);
|
m.instructions.insert(list);
|
||||||
|
31
src/main/java/com/novitechie/rules/ClassRule.java
Normal file
31
src/main/java/com/novitechie/rules/ClassRule.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package com.novitechie.rules;
|
||||||
|
|
||||||
|
import com.janetfilter.core.commons.DebugInfo;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author YeloChick
|
||||||
|
*/
|
||||||
|
public class ClassRule {
|
||||||
|
|
||||||
|
|
||||||
|
private static final List<String> PREVENT_LOAD_METHOD = new ArrayList<String>() {
|
||||||
|
{
|
||||||
|
add("findBootstrapClass");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static void checkMethod(String name) throws Exception {
|
||||||
|
if (PREVENT_LOAD_METHOD.stream().anyMatch(name::equals)) {
|
||||||
|
DebugInfo.output("======================LoadMethod: " + name);
|
||||||
|
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||||
|
DebugInfo.output("===========================stackTrace: ");
|
||||||
|
for (StackTraceElement stackTraceElement : stackTrace) {
|
||||||
|
DebugInfo.output(stackTraceElement.getClassName() + ":" + stackTraceElement.getMethodName());
|
||||||
|
}
|
||||||
|
throw new NoSuchMethodException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
34
src/main/java/com/novitechie/rules/IdeaPluginRule.java
Normal file
34
src/main/java/com/novitechie/rules/IdeaPluginRule.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package com.novitechie.rules;
|
||||||
|
|
||||||
|
import com.janetfilter.core.commons.DebugInfo;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author YeloChick
|
||||||
|
*/
|
||||||
|
public class IdeaPluginRule {
|
||||||
|
|
||||||
|
private static final List<String> PREVENT_LOAD_PLUGINS = new ArrayList<String>() {
|
||||||
|
{
|
||||||
|
add("io.zhile.research.ide-eval-resetter");
|
||||||
|
add("Nasller.License");
|
||||||
|
add("nasller");
|
||||||
|
add("manifold.ij");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static boolean check(String name) {
|
||||||
|
boolean f = PREVENT_LOAD_PLUGINS.stream().anyMatch(name::equals);
|
||||||
|
if (f) {
|
||||||
|
DebugInfo.output("======================LoadPlugin: " + name);
|
||||||
|
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||||
|
DebugInfo.output("===========================stackTrace: ");
|
||||||
|
for (StackTraceElement stackTraceElement : stackTrace) {
|
||||||
|
DebugInfo.output(stackTraceElement.getClassName() + ":" + stackTraceElement.getMethodName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
}
|
30
src/main/java/com/novitechie/rules/LoadClassRule.java
Normal file
30
src/main/java/com/novitechie/rules/LoadClassRule.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package com.novitechie.rules;
|
||||||
|
|
||||||
|
import com.janetfilter.core.commons.DebugInfo;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class LoadClassRule {
|
||||||
|
|
||||||
|
private static final List<String> PREVENT_LOAD_PACKAGES = new ArrayList<String>() {
|
||||||
|
{
|
||||||
|
// add("com.novitechie");
|
||||||
|
add("com.janetfilter");
|
||||||
|
add("jdk.internal.org.objectweb.asm");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static void check(String name) throws Exception {
|
||||||
|
if (PREVENT_LOAD_PACKAGES.stream().anyMatch(name::startsWith)) {
|
||||||
|
DebugInfo.output("======================LoadClass: " + name);
|
||||||
|
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||||
|
DebugInfo.output("===========================stackTrace: ");
|
||||||
|
for (StackTraceElement stackTraceElement : stackTrace) {
|
||||||
|
DebugInfo.output(stackTraceElement.getClassName() + ":" + stackTraceElement.getMethodName());
|
||||||
|
}
|
||||||
|
throw new ClassNotFoundException(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
33
src/main/java/com/novitechie/rules/ResourceRule.java
Normal file
33
src/main/java/com/novitechie/rules/ResourceRule.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package com.novitechie.rules;
|
||||||
|
|
||||||
|
import com.janetfilter.core.commons.DebugInfo;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author YeloChick
|
||||||
|
*/
|
||||||
|
public class ResourceRule {
|
||||||
|
|
||||||
|
private static final List<String> PREVENT_LOAD_RESOURCE = new ArrayList<String>() {
|
||||||
|
{
|
||||||
|
add("/6c81ec87e55d331c267262e892427a3d93d76683.txt");
|
||||||
|
add("/com/janetfilter");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static boolean check(String name) {
|
||||||
|
boolean f = PREVENT_LOAD_RESOURCE.stream().anyMatch(name::startsWith);
|
||||||
|
if (f) {
|
||||||
|
DebugInfo.output("======================LoadResource: " + name);
|
||||||
|
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||||
|
DebugInfo.output("===========================stackTrace: ");
|
||||||
|
for (StackTraceElement stackTraceElement : stackTrace) {
|
||||||
|
DebugInfo.output(stackTraceElement.getClassName() + ":" + stackTraceElement.getMethodName());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
package com.novitechie;
|
package com.novitechie.rules;
|
||||||
|
|
||||||
|
import com.janetfilter.core.commons.DebugInfo;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -23,7 +25,8 @@ public class StackTraceRule {
|
|||||||
for (StackTraceElement stackTraceElement : stackTrace) {
|
for (StackTraceElement stackTraceElement : stackTrace) {
|
||||||
if (!PACKAGE_NAME_PATTERN.matcher(stackTraceElement.getMethodName()).matches()) {
|
if (!PACKAGE_NAME_PATTERN.matcher(stackTraceElement.getMethodName()).matches()) {
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.add(Calendar.DAY_OF_MONTH, 30);
|
calendar.add(Calendar.DAY_OF_MONTH, 60);
|
||||||
|
DebugInfo.output("===========================getLicenseExpirationDate");
|
||||||
return calendar.getTime();
|
return calendar.getTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
55
src/main/java/com/novitechie/rules/SystemRule.java
Normal file
55
src/main/java/com/novitechie/rules/SystemRule.java
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
package com.novitechie.rules;
|
||||||
|
|
||||||
|
import com.janetfilter.core.commons.DebugInfo;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author YeloChick
|
||||||
|
*/
|
||||||
|
public class SystemRule {
|
||||||
|
|
||||||
|
private static final List<String> PREVENT_LOAD_ENV = new ArrayList<String>() {
|
||||||
|
{
|
||||||
|
add("_VM_OPTIONS");
|
||||||
|
add("JANF_DEBUG");
|
||||||
|
add("JANF_OUTPUT");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final List<String> PREVENT_LOAD_PROPERTY = new ArrayList<String>() {
|
||||||
|
{
|
||||||
|
add("janf.debug");
|
||||||
|
add("janf.output");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static boolean checkEnv(String name) {
|
||||||
|
boolean f = PREVENT_LOAD_ENV.stream().anyMatch(name::startsWith) || PREVENT_LOAD_ENV.stream().anyMatch(name::endsWith);
|
||||||
|
if (f) {
|
||||||
|
DebugInfo.output("======================LoadEnv: " + name);
|
||||||
|
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||||
|
DebugInfo.output("===========================stackTrace: ");
|
||||||
|
for (StackTraceElement stackTraceElement : stackTrace) {
|
||||||
|
DebugInfo.output(stackTraceElement.getClassName() + ":" + stackTraceElement.getMethodName());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkProperty(String name) {
|
||||||
|
boolean f = PREVENT_LOAD_PROPERTY.stream().anyMatch(name::equals);
|
||||||
|
if (f) {
|
||||||
|
DebugInfo.output("======================LoadProperty: " + name);
|
||||||
|
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
|
||||||
|
DebugInfo.output("===========================stackTrace: ");
|
||||||
|
for (StackTraceElement stackTraceElement : stackTrace) {
|
||||||
|
DebugInfo.output(stackTraceElement.getClassName() + ":" + stackTraceElement.getMethodName());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
29
src/main/java/com/novitechie/rules/VMOptionsRule.java
Normal file
29
src/main/java/com/novitechie/rules/VMOptionsRule.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package com.novitechie.rules;
|
||||||
|
|
||||||
|
import com.janetfilter.core.commons.DebugInfo;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author YeloChick
|
||||||
|
*/
|
||||||
|
public class VMOptionsRule {
|
||||||
|
|
||||||
|
public static Path hook() {
|
||||||
|
String tmpdir = System.getProperty("java.io.tmpdir");
|
||||||
|
File file = new File(tmpdir, "fake.vmoptions");
|
||||||
|
if (file.exists()) {
|
||||||
|
return file.toPath();
|
||||||
|
}
|
||||||
|
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||||
|
fos.write("# This file is created by plugin-privacy".getBytes());
|
||||||
|
return file.toPath();
|
||||||
|
} catch (IOException e) {
|
||||||
|
DebugInfo.output("create temp file error", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user