Search in sources :

Example 46 with InstructionHandle

use of org.apache.bcel.generic.InstructionHandle in project candle-decompiler by bradsdavis.

the class StackClonePointListener method finish.

public void finish(VertexTraversalEvent<InstructionHandle> e) {
    InstructionHandle ih = e.getVertex();
    List<InstructionHandle> successors = igc.getSuccessors(ih);
    if (successors.size() > 1) {
        // duplicate the stack to all children...
        if (LOG.isDebugEnabled()) {
            LOG.debug("Must duplicate stack to all children: " + ih);
        }
        for (InstructionHandle successor : successors) {
            addExpressionStack(successor, (Stack) ic.getExpressions().clone());
        }
    }
}
Also used : InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 47 with InstructionHandle

use of org.apache.bcel.generic.InstructionHandle in project candle-decompiler by bradsdavis.

the class ClassIntermediateVisitor method writeGraph.

private void writeGraph(String name, InstructionGraphContext igc) {
    LOG.debug("Instruction Graph ======");
    File a = new File("/Users/bradsdavis/Projects/workspace/clzTest/" + name);
    Writer x;
    try {
        x = new FileWriter(a);
        DOTExporter<InstructionHandle, IntermediateEdge> f = new DOTExporter<InstructionHandle, IntermediateEdge>(new IntegerNameProvider<InstructionHandle>(), new InstructionLabelProvider(), new IntermediateEdgeProvider(), null, new InstructionEdgeAttributeProvider());
        f.export(x, igc.getGraph());
    } catch (IOException e) {
        e.printStackTrace();
    }
    LOG.debug("End Instruction Graph ======");
}
Also used : DOTExporter(org.jgrapht.ext.DOTExporter) InstructionLabelProvider(org.candle.decompiler.instruction.graph.vertex.InstructionLabelProvider) IntermediateEdgeProvider(org.candle.decompiler.intermediate.graph.edge.IntermediateEdgeProvider) FileWriter(java.io.FileWriter) InstructionEdgeAttributeProvider(org.candle.decompiler.instruction.graph.edge.InstructionEdgeAttributeProvider) IOException(java.io.IOException) File(java.io.File) IntermediateEdge(org.candle.decompiler.intermediate.graph.edge.IntermediateEdge) InstructionGraphWriter(org.candle.decompiler.instruction.graph.enhancer.InstructionGraphWriter) Writer(java.io.Writer) IntermediateGraphWriter(org.candle.decompiler.intermediate.graph.enhancer.IntermediateGraphWriter) FileWriter(java.io.FileWriter) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 48 with InstructionHandle

use of org.apache.bcel.generic.InstructionHandle in project candle-decompiler by bradsdavis.

the class IntermediateGraphFactory method visitMultiBranchIntermediate.

@Override
public void visitMultiBranchIntermediate(MultiBranchIntermediate line) {
    Select select = (Select) line.getInstruction().getInstruction();
    Set<Case> cases = new HashSet<Case>();
    InstructionHandle[] handles = select.getTargets();
    int[] matches = select.getMatchs();
    for (int i = 0, j = handles.length; i < j; i++) {
        InstructionHandle ih = handles[i];
        int match = matches[i];
        Resolved resolved = new Resolved(line.getInstruction(), BasicType.INT, "" + match);
        Case caseEntry = new Case(line.getInstruction(), ih, resolved);
        cases.add(caseEntry);
    }
    if (select.getTarget() != null) {
        DefaultCase defaultCase = new DefaultCase(line.getInstruction(), select.getTarget());
        line.setDefaultCase(defaultCase);
    }
    // now, create the graph.
    line.setCases(cases);
    // now, create the graph.
    igc.getGraph().addVertex(line);
    if (line.getDefaultCase() != null) {
        CaseIntermediate si = new CaseIntermediate(line.getInstruction(), line.getDefaultCase());
        igc.getGraph().addVertex(si);
        // add an edge.
        igc.getGraph().addEdge(line, si);
        // add edge from outcome to edge.
        LOG.debug(si);
        AbstractIntermediate target = ilc.getNext(line.getDefaultCase().getTarget().getPosition());
        LOG.debug("TargeT:" + target);
        igc.getGraph().addVertex(target);
        igc.getGraph().addEdge(si, target);
    }
    for (Case caseVal : line.getCases()) {
        CaseIntermediate si = new CaseIntermediate(line.getInstruction(), caseVal);
        igc.getGraph().addVertex(si);
        // add an edge.
        igc.getGraph().addEdge(line, si);
        // add edge from outcome to edge.
        AbstractIntermediate target = ilc.getNext(caseVal.getTarget().getPosition());
        igc.getGraph().addVertex(target);
        igc.getGraph().addEdge(si, target);
    }
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) DefaultCase(org.candle.decompiler.intermediate.expression.DefaultCase) Select(org.apache.bcel.generic.Select) CaseIntermediate(org.candle.decompiler.intermediate.code.CaseIntermediate) Resolved(org.candle.decompiler.intermediate.expression.Resolved) InstructionHandle(org.apache.bcel.generic.InstructionHandle) Case(org.candle.decompiler.intermediate.expression.Case) DefaultCase(org.candle.decompiler.intermediate.expression.DefaultCase) HashSet(java.util.HashSet)

Example 49 with InstructionHandle

use of org.apache.bcel.generic.InstructionHandle in project candle-decompiler by bradsdavis.

the class IntermediateLineContext method getNext.

public AbstractIntermediate getNext(AbstractIntermediate ai) {
    if (ai instanceof GoToIntermediate) {
        BranchHandle bh = (BranchHandle) ai.getInstruction();
        Integer position = bh.getTarget().getPosition();
        return getNext(position);
    }
    // otherwise, get it from the next position.
    InstructionHandle next = ai.getInstruction().getNext();
    // return either null, if next is null (last next).  Otherwise, send next position.
    return next == null ? null : getNext(next.getPosition());
}
Also used : GoToIntermediate(org.candle.decompiler.intermediate.code.GoToIntermediate) BranchHandle(org.apache.bcel.generic.BranchHandle) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 50 with InstructionHandle

use of org.apache.bcel.generic.InstructionHandle in project candle-decompiler by bradsdavis.

the class BackEdgeEnhancer method process.

@Override
public void process(InstructionHandle ih) {
    List<InstructionHandle> successors = Graphs.successorListOf(igc.getGraph(), ih);
    for (InstructionHandle successor : successors) {
        IntermediateEdge ie = igc.getGraph().getEdge(ih, successor);
        // color back...
        int t1 = ih.getPosition();
        int t2 = successor.getPosition();
        if (t2 < t1) {
            ie.setType(EdgeType.BACK);
        }
    }
}
Also used : IntermediateEdge(org.candle.decompiler.intermediate.graph.edge.IntermediateEdge) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Aggregations

InstructionHandle (org.apache.bcel.generic.InstructionHandle)103 InstructionList (org.apache.bcel.generic.InstructionList)26 MethodInfo (com.jopdesign.common.MethodInfo)20 CallString (com.jopdesign.common.code.CallString)20 Instruction (org.apache.bcel.generic.Instruction)13 MethodCode (com.jopdesign.common.MethodCode)12 ContextMap (com.jopdesign.dfa.framework.ContextMap)11 IntermediateEdge (org.candle.decompiler.intermediate.graph.edge.IntermediateEdge)11 Context (com.jopdesign.dfa.framework.Context)10 InvokeInstruction (org.apache.bcel.generic.InvokeInstruction)10 Iterator (java.util.Iterator)9 BranchInstruction (org.apache.bcel.generic.BranchInstruction)9 FieldInstruction (org.apache.bcel.generic.FieldInstruction)9 AbstractIntermediate (org.candle.decompiler.intermediate.code.AbstractIntermediate)9 ReturnInstruction (org.apache.bcel.generic.ReturnInstruction)8 InstructionFinder (org.apache.bcel.util.InstructionFinder)8 ClassInfo (com.jopdesign.common.ClassInfo)7 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 LinkedList (java.util.LinkedList)7