newest
This commit is contained in:
parent
e7bc25928e
commit
f10a54011f
|
@ -1,37 +0,0 @@
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,14 +1,22 @@
|
||||||
package com.novitechie;
|
package com.novitechie;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class LoadClassRule {
|
public class LoadClassRule {
|
||||||
|
|
||||||
|
private static final List<String> PREVENT_LOAD_PACKAGES = new ArrayList<String>() {
|
||||||
|
{
|
||||||
|
add("com.novitechie");
|
||||||
|
add("com.janetfilter");
|
||||||
|
add("jdk.internal.org.objectweb.asm");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public static void check(String name) throws Exception {
|
public static void check(String name) throws Exception {
|
||||||
if (name.startsWith("com.janetfilter")) {
|
if (PREVENT_LOAD_PACKAGES.stream().anyMatch(name::startsWith)) {
|
||||||
throw new ClassNotFoundException(name);
|
throw new ClassNotFoundException(name);
|
||||||
}
|
}
|
||||||
if (name.contains("jdk.internal.org.objectweb.asm.Type")) {
|
|
||||||
if (StackTraceRule.check()) {
|
|
||||||
throw new ClassNotFoundException(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ public class PrivacyPlugin implements PluginEntry {
|
||||||
new VMOptionsTransformer(),
|
new VMOptionsTransformer(),
|
||||||
new PluginClassLoaderTransformer(),
|
new PluginClassLoaderTransformer(),
|
||||||
new LicensingFacadeTransformer(),
|
new LicensingFacadeTransformer(),
|
||||||
new PluginManagerCoreTransformer(),
|
new PluginManagerCoreTransformer());
|
||||||
new ClassTransformer());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,13 +29,13 @@
|
||||||
package com.novitechie;
|
package com.novitechie;
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
import jdk.internal.org.objectweb.asm.ClassReader;
|
import jdk.internal.org.objectweb.asm.ClassReader;
|
||||||
import jdk.internal.org.objectweb.asm.ClassWriter;
|
import jdk.internal.org.objectweb.asm.ClassWriter;
|
||||||
import jdk.internal.org.objectweb.asm.Opcodes;
|
import jdk.internal.org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -146,13 +146,13 @@ public class SafeClassWriter extends ClassWriter {
|
||||||
throws IOException {
|
throws IOException {
|
||||||
while (!"java/lang/Object".equals(type)) {
|
while (!"java/lang/Object".equals(type)) {
|
||||||
String[] itfs = info.getInterfaces();
|
String[] itfs = info.getInterfaces();
|
||||||
for (int i = 0; i < itfs.length; ++i) {
|
for (String s : itfs) {
|
||||||
if (itfs[i].equals(itf)) {
|
if (s.equals(itf)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < itfs.length; ++i) {
|
for (String s : itfs) {
|
||||||
if (typeImplements(itfs[i], typeInfo(itfs[i]), itf)) {
|
if (typeImplements(s, typeInfo(s), itf)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ public class StackTraceRule {
|
||||||
for (StackTraceElement stackTraceElement : stackTrace) {
|
for (StackTraceElement stackTraceElement : stackTrace) {
|
||||||
if (!PACKAGE_NAME_PATTERN.matcher(stackTraceElement.getMethodName()).matches()) {
|
if (!PACKAGE_NAME_PATTERN.matcher(stackTraceElement.getMethodName()).matches()) {
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.add(Calendar.DAY_OF_MONTH, 180);
|
calendar.add(Calendar.DAY_OF_MONTH, 30);
|
||||||
return calendar.getTime();
|
return calendar.getTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.novitechie;
|
package com.novitechie;
|
||||||
|
|
||||||
import com.janetfilter.core.plugin.MyTransformer;
|
import com.janetfilter.core.plugin.MyTransformer;
|
||||||
import jdk.internal.org.objectweb.asm.*;
|
import jdk.internal.org.objectweb.asm.ClassReader;
|
||||||
import jdk.internal.org.objectweb.asm.commons.AdviceAdapter;
|
import jdk.internal.org.objectweb.asm.ClassWriter;
|
||||||
import jdk.internal.org.objectweb.asm.tree.*;
|
import jdk.internal.org.objectweb.asm.tree.*;
|
||||||
|
|
||||||
import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
||||||
|
|
Loading…
Reference in New Issue