Exemplo n.º 1
0
  public void staticBlockInlining(SootClass sootClass) {
    this.sootClass = sootClass;
    // retrieve the clinit method if any for sootClass
    if (!sootClass.declaresMethod("void <clinit>()")) {
      System.out.println("no clinit");
      return;
    }

    SootMethod clinit = sootClass.getMethod("void <clinit>()");
    // System.out.println(clinit);

    // retireve the active body
    if (!clinit.hasActiveBody())
      throw new RuntimeException("method " + clinit.getName() + " has no active body!");

    Body clinitBody = clinit.getActiveBody();

    Chain units = ((DavaBody) clinitBody).getUnits();

    if (units.size() != 1) {
      throw new RuntimeException("DavaBody AST doesn't have single root.");
    }

    ASTNode AST = (ASTNode) units.getFirst();
    if (!(AST instanceof ASTMethodNode))
      throw new RuntimeException("Starting node of DavaBody AST is not an ASTMethodNode");

    AST.apply(new MethodCallFinder(this));
  }
Exemplo n.º 2
0
  /**
   * Given an object of actual type C (o = new C()), returns the method which will be called on an
   * o.f() invocation.
   */
  public SootMethod resolveConcreteDispatch(SootClass concreteType, SootMethod m) {
    concreteType.checkLevel(SootClass.HIERARCHY);
    m.getDeclaringClass().checkLevel(SootClass.HIERARCHY);
    checkState();

    if (concreteType.isInterface()) throw new RuntimeException("class needed!");

    Iterator<SootClass> it = getSuperclassesOfIncluding(concreteType).iterator();
    String methodSig = m.getSubSignature();

    while (it.hasNext()) {
      SootClass c = it.next();
      if (c.declaresMethod(methodSig) && isVisible(c, m)) {
        return c.getMethod(methodSig);
      }
    }
    throw new RuntimeException(
        "could not resolve concrete dispatch!\nType: " + concreteType + "\nMethod: " + m);
  }