feat: hook PluginManagerCore
This commit is contained in:
parent
292e1b8d88
commit
852d5538bd
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue