hook LicensingFacade

This commit is contained in:
novice.li 2024-04-01 22:07:03 +08:00
parent b10cceebf8
commit 292e1b8d88
3 changed files with 54 additions and 1 deletions

View File

@ -0,0 +1,38 @@
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.*;
public class LicensingFacadeTransformer implements MyTransformer {
@Override
public String getHookClassName() {
return "com/intellij/ui/LicensingFacade";
}
@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 ("getLicenseExpirationDate".equals(m.name)) {
InsnList list = new InsnList();
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/StackTraceRule", "hook", "()Ljava/util/Date;", false));
list.add(new InsnNode(DUP));
LabelNode labelNode = new LabelNode();
list.add(new JumpInsnNode(IFNULL,labelNode));
list.add(new InsnNode(ARETURN));
list.add(labelNode);
list.add(new InsnNode(POP));
m.instructions.insert(list);
}
}
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
node.accept(writer);
return writer.toByteArray();
}
}

View File

@ -19,6 +19,6 @@ public class PrivacyPlugin implements PluginEntry {
@Override @Override
public List<MyTransformer> getTransformers() { public List<MyTransformer> getTransformers() {
return Arrays.asList(new VMOptionsTransformer(),new PluginClassLoaderTransformer()); return Arrays.asList(new VMOptionsTransformer(),new PluginClassLoaderTransformer(),new LicensingFacadeTransformer());
} }
} }

View File

@ -1,5 +1,8 @@
package com.novitechie; package com.novitechie;
import java.util.Calendar;
import java.util.Date;
public class StackTraceRule { public class StackTraceRule {
public static boolean check() { public static boolean check() {
RuntimeException e = new RuntimeException(); RuntimeException e = new RuntimeException();
@ -10,4 +13,16 @@ public class StackTraceRule {
} }
return false; return false;
} }
public static Date hook() {
RuntimeException e = new RuntimeException();
for (StackTraceElement stackTraceElement : e.getStackTrace()) {
if (stackTraceElement.getFileName() == null) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, 180);
return calendar.getTime();
}
}
return null;
}
} }