feat: hook PluginManagerCore

This commit is contained in:
yelochick 2024-04-06 10:23:47 +08:00
parent 292e1b8d88
commit 852d5538bd
2 changed files with 57 additions and 2 deletions

View File

@ -0,0 +1,51 @@
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 PluginManagerCoreTransformer implements MyTransformer {
@Override
public String getHookClassName() {
return "com/intellij/ide/plugins/PluginManagerCore";
}
@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 ("isPluginInstalled".equals(m.name)) {
InsnList list = new InsnList();
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/StackTraceRule", "check", "()Z", false));
LabelNode labelNode = new LabelNode();
list.add(new JumpInsnNode(IFEQ, labelNode));
list.add(new InsnNode(ICONST_0));
list.add(new InsnNode(IRETURN));
list.add(labelNode);
m.instructions.insert(list);
} else if ("getPlugins".equals(m.name)) {
InsnList list = new InsnList();
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/StackTraceRule", "check", "()Z", false));
LabelNode labelNode = new LabelNode();
list.add(new JumpInsnNode(IFEQ, labelNode));
list.add(new InsnNode(ICONST_0));
list.add(new TypeInsnNode(ANEWARRAY, "java/lang/Object"));
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();
}
}

View File

@ -6,7 +6,7 @@ import com.janetfilter.core.plugin.PluginEntry;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
public class PrivacyPlugin implements PluginEntry { public class PrivacyPlugin implements PluginEntry {
@Override @Override
public String getName() { public String getName() {
return "PRIVACY"; return "PRIVACY";
@ -19,6 +19,10 @@ public class PrivacyPlugin implements PluginEntry {
@Override @Override
public List<MyTransformer> getTransformers() { public List<MyTransformer> getTransformers() {
return Arrays.asList(new VMOptionsTransformer(),new PluginClassLoaderTransformer(),new LicensingFacadeTransformer()); return Arrays.asList(
new VMOptionsTransformer(),
new PluginClassLoaderTransformer(),
new LicensingFacadeTransformer(),
new PluginManagerCoreTransformer());
} }
} }