Merge pull request #2 from yelochick/main

feat: hook PluginManagerCore
This commit is contained in:
kangwei Li 2024-04-06 17:06:33 +08:00 committed by GitHub
commit 8be6cfa8ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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());
} }
} }