Search in sources :

Example 1 with Resolved

use of org.candle.decompiler.intermediate.expression.Resolved 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) HashSet(java.util.HashSet) Case(org.candle.decompiler.intermediate.expression.Case) DefaultCase(org.candle.decompiler.intermediate.expression.DefaultCase)

Example 2 with Resolved

use of org.candle.decompiler.intermediate.expression.Resolved in project candle-decompiler by bradsdavis.

the class MethodIntermediateVisitor method visitINSTANCEOF.

public void visitINSTANCEOF(INSTANCEOF instruction) {
    ConstantPoolGen cpg = context.getMethodGen().getConstantPool();
    String type = instruction.getLoadClassType(cpg).getClassName();
    //get the left, create the right
    Expression left = context.getExpressions().pop();
    Expression right = new Resolved(context.getCurrentInstruction(), Type.BOOLEAN, type);
    InstanceOf instanceOf = new InstanceOf(context.getCurrentInstruction(), left, right);
    context.getExpressions().push(instanceOf);
}
Also used : TypedExpression(org.candle.decompiler.intermediate.expression.TypedExpression) Expression(org.candle.decompiler.intermediate.expression.Expression) InstanceOf(org.candle.decompiler.intermediate.expression.InstanceOf) Resolved(org.candle.decompiler.intermediate.expression.Resolved)

Example 3 with Resolved

use of org.candle.decompiler.intermediate.expression.Resolved in project candle-decompiler by bradsdavis.

the class MethodIntermediateVisitor method visitLDC.

public void visitLDC(LDC instruction) {
    //load from constant pool.
    LOG.debug("Loading from constant pool" + instruction.getClass());
    MethodGen mg = context.getMethodGen();
    ConstantPoolGen cpg = mg.getConstantPool();
    StringBuilder resolvedValue = new StringBuilder();
    Type type = instruction.getType(cpg);
    if (Type.STRING == type) {
        resolvedValue.append("\"");
    }
    Object instructionValue = instruction.getValue(cpg);
    if (instructionValue instanceof ConstantClass) {
        String clzName = getClassName((ConstantClass) instructionValue, cpg.getConstantPool());
        resolvedValue.append(clzName);
    } else {
        resolvedValue.append(instructionValue.toString());
    }
    if (Type.STRING == type) {
        resolvedValue.append("\"");
    }
    Resolved resolved = new Resolved(context.getCurrentInstruction(), type, resolvedValue.toString());
    context.getExpressions().push(resolved);
}
Also used : OperationType(org.candle.decompiler.intermediate.expression.OperationType) ArithmeticType(org.candle.decompiler.intermediate.expression.ArithmeticType) Resolved(org.candle.decompiler.intermediate.expression.Resolved) ConstantClass(org.apache.bcel.classfile.ConstantClass)

Example 4 with Resolved

use of org.candle.decompiler.intermediate.expression.Resolved in project candle-decompiler by bradsdavis.

the class ExceptionEdgeEnhancer method addExceptionHandle.

private void addExceptionHandle(IntermediateEdge ie, CodeExceptionGen ceg) {
    ObjectType ot = ceg.getCatchType();
    Resolved resolved = null;
    if (ot == null) {
        resolved = new Resolved((InstructionHandle) ie.getTarget(), Type.THROWABLE, "e");
    } else {
        resolved = new Resolved((InstructionHandle) ie.getTarget(), ot, ot.toString());
    }
    ie.getAttributes().put(EXCEPTION_STACK_KEY, resolved);
}
Also used : ObjectType(org.apache.bcel.generic.ObjectType) Resolved(org.candle.decompiler.intermediate.expression.Resolved) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 5 with Resolved

use of org.candle.decompiler.intermediate.expression.Resolved in project candle-decompiler by bradsdavis.

the class MethodIntermediateVisitor method visitLCONST.

public void visitLCONST(LCONST instruction) {
    Resolved cons = new Resolved(context.getCurrentInstruction(), Type.LONG, instruction.getValue().toString());
    context.getExpressions().push(cons);
}
Also used : Resolved(org.candle.decompiler.intermediate.expression.Resolved)

Aggregations

Resolved (org.candle.decompiler.intermediate.expression.Resolved)20 Expression (org.candle.decompiler.intermediate.expression.Expression)11 TypedExpression (org.candle.decompiler.intermediate.expression.TypedExpression)10 ArithmeticType (org.candle.decompiler.intermediate.expression.ArithmeticType)4 OperationType (org.candle.decompiler.intermediate.expression.OperationType)4 ArrayList (java.util.ArrayList)2 ConstantClass (org.apache.bcel.classfile.ConstantClass)2 InstructionHandle (org.apache.bcel.generic.InstructionHandle)2 AbstractIntermediate (org.candle.decompiler.intermediate.code.AbstractIntermediate)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ObjectType (org.apache.bcel.generic.ObjectType)1 Select (org.apache.bcel.generic.Select)1 CaseIntermediate (org.candle.decompiler.intermediate.code.CaseIntermediate)1 StatementIntermediate (org.candle.decompiler.intermediate.code.StatementIntermediate)1 Assignment (org.candle.decompiler.intermediate.expression.Assignment)1 Case (org.candle.decompiler.intermediate.expression.Case)1 Cast (org.candle.decompiler.intermediate.expression.Cast)1 ConstantArray (org.candle.decompiler.intermediate.expression.ConstantArray)1 Declaration (org.candle.decompiler.intermediate.expression.Declaration)1