Java 类soot.jimple.internal.JGotoStmt 实例源码

项目:petablox    文件:DomP.java   
@Override
public String toFIString(Unit u) {       
    StringBuilder sb = new StringBuilder();
    boolean printId = Utils.buildBoolProperty("petablox.printrel.printID", false);
    if (printId) sb.append("(" + indexOf(u) + ")");
    String type;
    if(u instanceof JAssignStmt)
        type = "Assign";
    else if(u instanceof JBreakpointStmt)
        type = "Breakpoint";
    else if(u instanceof JGotoStmt)
        type = "Goto";
    else if(u instanceof JIfStmt) 
        type = "If";
    else if(u instanceof JIdentityStmt) 
        type = "Identity";
    else if(u instanceof JInvokeStmt) 
        type = "Invoke";
    else if(u instanceof JLookupSwitchStmt) 
        type = "LookupSwitch";
    else if(u instanceof JNopStmt)
        type = "Nop";
    else if(u instanceof JRetStmt) 
        type = "Return";
    else if(u instanceof JTableSwitchStmt) 
        type = "TablelSwitch";
    else if(u instanceof JThrowStmt) 
        type = "Throw";
    else
        type = "Other";
    sb.append(type);
    sb.append(": " + SootUtilities.getMethod(u).getName() + "@" + SootUtilities.getMethod(u).getDeclaringClass().getName());
    return sb.toString();
}
项目:JAADAS    文件:DefaultEntryPointCreator.java   
@Override
protected SootMethod createDummyMainInternal(SootMethod mainMethod) {
    Map<String, Set<String>> classMap =
            SootMethodRepresentationParser.v().parseClassNames(methodsToCall, false);

    // create new class:
    Body body = mainMethod.getActiveBody();
        LocalGenerator generator = new LocalGenerator(body);
    HashMap<String, Local> localVarsForClasses = new HashMap<String, Local>();

    // create constructors:
    for(String className : classMap.keySet()){
        SootClass createdClass = Scene.v().forceResolve(className, SootClass.BODIES);
        createdClass.setApplicationClass();

        Local localVal = generateClassConstructor(createdClass, body);
        if (localVal == null) {
            logger.warn("Cannot generate constructor for class: {}", createdClass);
            continue;
        }
        localVarsForClasses.put(className, localVal);
    }

    // add entrypoint calls
    int conditionCounter = 0;
    JNopStmt startStmt = new JNopStmt();
    JNopStmt endStmt = new JNopStmt();
    Value intCounter = generator.generateLocal(IntType.v());
    body.getUnits().add(startStmt);
    for (Entry<String, Set<String>> entry : classMap.entrySet()){
        Local classLocal = localVarsForClasses.get(entry.getKey());
        for (String method : entry.getValue()){
            SootMethodAndClass methodAndClass =
                    SootMethodRepresentationParser.v().parseSootMethodString(method);
            SootMethod currentMethod = findMethod(Scene.v().getSootClass(methodAndClass.getClassName()),
                    methodAndClass.getSubSignature());
            if (currentMethod == null) {
                logger.warn("Entry point not found: {}", method);
                continue;
            }

            JEqExpr cond = new JEqExpr(intCounter, IntConstant.v(conditionCounter));
            conditionCounter++;
            JNopStmt thenStmt = new JNopStmt();
            JIfStmt ifStmt = new JIfStmt(cond, thenStmt);
            body.getUnits().add(ifStmt);
            buildMethodCall(currentMethod, body, classLocal, generator);
            body.getUnits().add(thenStmt);
        }
    }
    body.getUnits().add(endStmt);
    JGotoStmt gotoStart = new JGotoStmt(startStmt);
    body.getUnits().add(gotoStart);

    body.getUnits().add(Jimple.v().newReturnVoidStmt());
    NopEliminator.v().transform(body);
    eliminateSelfLoops(body);
    return mainMethod;
}
项目:petablox    文件:VisitorHandler.java   
private void visitGotoInsts(JGotoStmt s) {
    if (gotoVisitors != null) {
        for (IGotoInstVisitor v : gotoVisitors)
            v.visit(s);
    }
}
项目:petablox    文件:RelGotoInst.java   
public void visit(JGotoStmt s) {
    add(s, s.getTarget());
}
项目:soot-inflow    文件:DefaultEntryPointCreator.java   
/**
 * Soot requires a main method, so we create a dummy method which calls all entry functions.
 * 
 * @param classMap
 *            the methods to call (signature as String)
 * @param createdClass
 *            the class which contains the methods
 * @return list of entryPoints
 */
@Override
protected SootMethod createDummyMainInternal(List<String> methods) {
    Map<String, List<String>> classMap =
            SootMethodRepresentationParser.v().parseClassNames(methods, false);

    // create new class:
        JimpleBody body = Jimple.v().newBody();
        SootMethod mainMethod = createEmptyMainMethod(body);

        LocalGenerator generator = new LocalGenerator(body);
    HashMap<String, Local> localVarsForClasses = new HashMap<String, Local>();

    // create constructors:
    for(String className : classMap.keySet()){
        SootClass createdClass = Scene.v().forceResolve(className, SootClass.BODIES);
        createdClass.setApplicationClass();

        Local localVal = generateClassConstructor(createdClass, body);
        if (localVal == null) {
            logger.warn("Cannot generate constructor for class: {}", createdClass);
            continue;
        }
        localVarsForClasses.put(className, localVal);
    }

    // add entrypoint calls
    int conditionCounter = 0;
    JNopStmt startStmt = new JNopStmt();
    JNopStmt endStmt = new JNopStmt();
    Value intCounter = generator.generateLocal(IntType.v());
    body.getUnits().add(startStmt);
    for (Entry<String, List<String>> entry : classMap.entrySet()){
        Local classLocal = localVarsForClasses.get(entry.getKey());
        for (String method : entry.getValue()){
            SootMethodAndClass methodAndClass =
                    SootMethodRepresentationParser.v().parseSootMethodString(method);
            SootMethod currentMethod = findMethod(Scene.v().getSootClass(methodAndClass.getClassName()),
                    methodAndClass.getSubSignature());
            if (currentMethod == null) {
                logger.warn("Entry point not found: {}", method);
                continue;
            }

            JEqExpr cond = new JEqExpr(intCounter, IntConstant.v(conditionCounter));
            conditionCounter++;
            JNopStmt thenStmt = new JNopStmt();
            JIfStmt ifStmt = new JIfStmt(cond, thenStmt);
            body.getUnits().add(ifStmt);
            buildMethodCall(currentMethod, body, classLocal, generator);
            body.getUnits().add(thenStmt);
        }
    }
    body.getUnits().add(endStmt);
    JGotoStmt gotoStart = new JGotoStmt(startStmt);
    body.getUnits().add(gotoStart);

    body.getUnits().add(Jimple.v().newReturnVoidStmt());
    return mainMethod;
}
项目:petablox    文件:IGotoInstVisitor.java   
public void visit(JGotoStmt s);