Search in sources :

Example 1 with IntermediateEdge

use of org.candle.decompiler.intermediate.graph.edge.IntermediateEdge in project candle-decompiler by bradsdavis.

the class IntermediateGraphWriter method process.

@Override
public void process() {
    if (directory == null) {
        return;
    }
    File a = new File(directory.getAbsolutePath() + File.separator + name);
    LOG.debug("Instruction Graph: " + a.getAbsolutePath());
    Writer x;
    try {
        x = new FileWriter(a);
        DOTExporter<AbstractIntermediate, IntermediateEdge> dot = new DOTExporter<AbstractIntermediate, IntermediateEdge>(new IntegerNameProvider<AbstractIntermediate>(), new IntermediateLabelProvider(), new IntermediateEdgeProvider(), new IntermediateVertexAttributeProvider(), new InstructionEdgeAttributeProvider());
        dot.export(x, igc.getGraph());
    } catch (IOException e) {
        e.printStackTrace();
    }
    LOG.debug("End Instruction Graph ======");
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) DOTExporter(org.jgrapht.ext.DOTExporter) IntermediateEdgeProvider(org.candle.decompiler.intermediate.graph.edge.IntermediateEdgeProvider) FileWriter(java.io.FileWriter) IOException(java.io.IOException) IntermediateEdge(org.candle.decompiler.intermediate.graph.edge.IntermediateEdge) IntermediateVertexAttributeProvider(org.candle.decompiler.intermediate.graph.IntermediateVertexAttributeProvider) IntermediateLabelProvider(org.candle.decompiler.intermediate.graph.IntermediateLabelProvider) InstructionEdgeAttributeProvider(org.candle.decompiler.instruction.graph.edge.InstructionEdgeAttributeProvider) File(java.io.File) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 2 with IntermediateEdge

use of org.candle.decompiler.intermediate.graph.edge.IntermediateEdge in project candle-decompiler by bradsdavis.

the class RetractDuplicateFinally method collectOffsets.

protected Set<Integer> collectOffsets(AbstractIntermediate line) {
    // this is the finally template.
    AbstractIntermediate first = igc.getSingleSuccessor(line);
    // now, store the instruction position.
    int position = first.getInstruction().getPosition();
    BreadthFirstIterator<AbstractIntermediate, IntermediateEdge> bfi = new BreadthFirstIterator<AbstractIntermediate, IntermediateEdge>(igc.getGraph(), first);
    Set<Integer> offsets = new TreeSet<Integer>();
    while (bfi.hasNext()) {
        AbstractIntermediate next = bfi.next();
        int nextPosition = next.getInstruction().getPosition();
        int offset = nextPosition - position;
        LOG.debug("Offset: " + offset);
        offsets.add(offset);
    }
    return offsets;
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) BreadthFirstIterator(org.jgrapht.traverse.BreadthFirstIterator) TreeSet(java.util.TreeSet) IntermediateEdge(org.candle.decompiler.intermediate.graph.edge.IntermediateEdge)

Example 3 with IntermediateEdge

use of org.candle.decompiler.intermediate.graph.edge.IntermediateEdge in project candle-decompiler by bradsdavis.

the class ConditionToWhileLoop method updateEdges.

protected void updateEdges(WhileIntermediate wi) {
    List<AbstractIntermediate> predecessors = igc.getPredecessors(wi);
    for (AbstractIntermediate predecessor : predecessors) {
        IntermediateEdge ie = igc.getGraph().getEdge(predecessor, wi);
        igc.validateBackEdge(ie);
    }
    List<AbstractIntermediate> successors = igc.getSuccessors(wi);
    for (AbstractIntermediate successor : successors) {
        IntermediateEdge ie = igc.getGraph().getEdge(wi, successor);
        igc.validateBackEdge(ie);
    }
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) IntermediateEdge(org.candle.decompiler.intermediate.graph.edge.IntermediateEdge)

Example 4 with IntermediateEdge

use of org.candle.decompiler.intermediate.graph.edge.IntermediateEdge in project candle-decompiler by bradsdavis.

the class GraphUtil method redirectPredecessors.

/**
 * Takes all parent of source, and redirects their output to the target.
 *
 * @param source
 * @param target
 */
public void redirectPredecessors(T source, T target) {
    List<T> predecessors = Graphs.predecessorListOf(this.graph, source);
    // remove edges between predecessor and source.
    for (T p : predecessors) {
        IntermediateEdge existing = graph.getEdge(p, source);
        redirectEnd(existing, target);
    }
}
Also used : IntermediateEdge(org.candle.decompiler.intermediate.graph.edge.IntermediateEdge)

Example 5 with IntermediateEdge

use of org.candle.decompiler.intermediate.graph.edge.IntermediateEdge in project candle-decompiler by bradsdavis.

the class ConditionEdgeEnhancer method process.

@Override
public void process(InstructionHandle ih) {
    if (ih instanceof BranchHandle) {
        // ok, now we need to replace existing successor edges appropriately.
        BranchHandle bh = (BranchHandle) ih;
        List<InstructionHandle> successors = igc.getSuccessors(ih);
        TreeSet<InstructionHandle> orderedSuccessors = new TreeSet<InstructionHandle>(new InstructionComparator());
        orderedSuccessors.addAll(successors);
        if (successors.size() == 2) {
            // lowest will be true condition....
            IntermediateEdge truePath = igc.getGraph().getEdge(ih, orderedSuccessors.first());
            ConditionEdge trueCondition = createConditionalEdge(truePath, true);
            igc.getGraph().removeEdge(truePath);
            igc.getGraph().addEdge(ih, orderedSuccessors.first(), trueCondition);
            // highest will be false condition....
            IntermediateEdge falsePath = igc.getGraph().getEdge(ih, orderedSuccessors.last());
            ConditionEdge falseCondition = createConditionalEdge(falsePath, false);
            igc.getGraph().removeEdge(falsePath);
            igc.getGraph().addEdge(ih, orderedSuccessors.last(), falseCondition);
        }
    }
}
Also used : InstructionComparator(org.candle.decompiler.instruction.graph.vertex.InstructionComparator) TreeSet(java.util.TreeSet) BranchHandle(org.apache.bcel.generic.BranchHandle) IntermediateEdge(org.candle.decompiler.intermediate.graph.edge.IntermediateEdge) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ConditionEdge(org.candle.decompiler.intermediate.graph.edge.ConditionEdge)

Aggregations

IntermediateEdge (org.candle.decompiler.intermediate.graph.edge.IntermediateEdge)19 InstructionHandle (org.apache.bcel.generic.InstructionHandle)11 AbstractIntermediate (org.candle.decompiler.intermediate.code.AbstractIntermediate)6 File (java.io.File)3 FileWriter (java.io.FileWriter)3 IOException (java.io.IOException)3 Writer (java.io.Writer)3 TreeSet (java.util.TreeSet)3 BranchHandle (org.apache.bcel.generic.BranchHandle)3 InstructionEdgeAttributeProvider (org.candle.decompiler.instruction.graph.edge.InstructionEdgeAttributeProvider)3 IntermediateEdgeProvider (org.candle.decompiler.intermediate.graph.edge.IntermediateEdgeProvider)3 DOTExporter (org.jgrapht.ext.DOTExporter)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 InstructionLabelProvider (org.candle.decompiler.instruction.graph.vertex.InstructionLabelProvider)2 GoToIntermediate (org.candle.decompiler.intermediate.code.GoToIntermediate)2 StatementIntermediate (org.candle.decompiler.intermediate.code.StatementIntermediate)2 ListenableDirectedGraph (org.jgrapht.graph.ListenableDirectedGraph)2 BreadthFirstIterator (org.jgrapht.traverse.BreadthFirstIterator)2 CodeExceptionGen (org.apache.bcel.generic.CodeExceptionGen)1