Пример #1
0
 @Override
 protected final Collection<Unit> getUnits() {
   Set<Unit> result = new HashSet<>();
   result.addAll(this.forwardEdges.keySet());
   this.forwardEdges.values().forEach(result::addAll);
   return result;
 }
Пример #2
0
  /**
   * Create a method conveniently. The method is added to the class "TestClass". Parameters can be
   * given as an (positional) array of local variables (the "identity statements", required by Soot
   * to map parameters to local variables, are inserted automatically)
   */
  public SootMethod makeMethod(
      int modifier, String name, List<Local> params, soot.Type retType, List<Unit> bodyStmts) {
    SootMethod m =
        new SootMethod(
            name, params.stream().map(Local::getType).collect(toList()), retType, modifier);
    this.testClass.addMethod(m);
    Body body = Jimple.v().newBody(m);
    m.setActiveBody(body);

    // set the statements for the body.. first the identity statements, then the bodyStmts
    if (!m.isStatic()) {
      body.getLocals().add(localThis);
      body.getUnits()
          .add(Jimple.v().newIdentityStmt(localThis, Jimple.v().newThisRef(testClass.getType())));
    }
    IntStream.range(0, params.size())
        .forEach(
            pos -> {
              Local l = params.get(pos);
              ParameterRef pr = Jimple.v().newParameterRef(l.getType(), pos);
              body.getUnits().add(Jimple.v().newIdentityStmt(l, pr));
            });
    body.getUnits().addAll(bodyStmts);

    // set the locals for the body
    Set<Local> locals =
        Stream.concat(
                params.stream(),
                body.getUseAndDefBoxes()
                    .stream()
                    .filter(b -> b.getValue() instanceof Local)
                    .map(b -> (Local) b.getValue()))
            .collect(toSet());
    locals.removeAll(body.getLocals());
    body.getLocals().addAll(locals);

    return m;
  }