commit
5194243b35
|
@ -0,0 +1,37 @@
|
|||
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 ("forName".equals(m.name)) {
|
||||
InsnList list = new InsnList();
|
||||
list.add(new VarInsnNode(ALOAD, 0));
|
||||
list.add(new MethodInsnNode(INVOKESTATIC, "com/novitechie/LoadClassRule", "check", "(Ljava/lang/String;)V", false));
|
||||
m.instructions.insert(list);
|
||||
}
|
||||
}
|
||||
ClassWriter writer = new SafeClassWriter(null, null, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||
node.accept(writer);
|
||||
return writer.toByteArray();
|
||||
}
|
||||
}
|
|
@ -5,5 +5,10 @@ public class LoadClassRule {
|
|||
if (name.startsWith("com.janetfilter")) {
|
||||
throw new ClassNotFoundException(name);
|
||||
}
|
||||
if (name.contains("jdk.internal.org.objectweb.asm.Type")) {
|
||||
if (StackTraceRule.check()) {
|
||||
throw new ClassNotFoundException(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue