Java 类soot.jimple.toolkits.scalar.NopEliminator 实例源码

项目: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;
}
项目:JAADAS    文件:ReflectiveCallsInliner.java   
private void cleanup(Body b) {
    CopyPropagator.v().transform(b);
    DeadAssignmentEliminator.v().transform(b);
    UnusedLocalEliminator.v().transform(b);
    NopEliminator.v().transform(b);
}